aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp6
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.h3
-rw-r--r--src/blockchain_db/blockchain_db.cpp5
-rw-r--r--src/blockchain_db/blockchain_db.h2
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp26
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h2
-rw-r--r--src/cryptonote_core/blockchain.cpp10
-rw-r--r--src/cryptonote_core/blockchain.h3
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp22
-rw-r--r--src/cryptonote_core/hardfork.cpp2
-rw-r--r--src/wallet/wallet_rpc_server.cpp16
-rw-r--r--src/wallet/wallet_rpc_server.h1
12 files changed, 79 insertions, 19 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index 4799afebc..e37058a99 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -2200,8 +2200,14 @@ void BlockchainBDB::checkpoint_worker() const
LOG_PRINT_L0("Leaving BDB checkpoint thread.");
}
+bool BlockchainBDB::is_read_only() const
+{
+ return false;
+}
+
void BlockchainBDB::fixup()
{
+ LOG_PRINT_L3("BlockchainBDB::" << __func__);
// Always call parent as well
BlockchainDB::fixup();
}
diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h
index ce3da91e8..906b320c7 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.h
+++ b/src/blockchain_db/berkeleydb/db_bdb.h
@@ -405,6 +405,9 @@ private:
uint64_t get_output_global_index(const uint64_t& amount, const uint64_t& index);
void checkpoint_worker() const;
void check_open() const;
+
+ virtual bool is_read_only() const;
+
//
// fix up anything that may be wrong due to past bugs
virtual void fixup();
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index 4fa8cce26..0635f2000 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -199,6 +199,11 @@ void BlockchainDB::show_stats()
void BlockchainDB::fixup()
{
+ if (is_read_only()) {
+ LOG_PRINT_L1("Database is opened read only - skipping fixup check");
+ return;
+ }
+
// There was a bug that would cause key images for transactions without
// any outputs to not be added to the spent key image set. There are two
// instances of such transactions, in blocks 202612 and 685498.
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index 702de18b5..f6f50d2e9 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -503,6 +503,8 @@ public:
virtual void set_hard_fork_version(uint64_t height, uint8_t version) = 0;
virtual uint8_t get_hard_fork_version(uint64_t height) const = 0;
+ virtual bool is_read_only() const = 0;
+
// fix up anything that may be wrong due to past bugs
virtual void fixup();
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 325ed8b8c..9555318a5 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -130,13 +130,16 @@ private:
template<>
struct MDB_val_copy<const char*>: public MDB_val
{
- MDB_val_copy(const char *s) :
- data(strdup(s))
+ MDB_val_copy(const char *s):
+ size(strlen(s)+1), // include the NUL, makes it easier for compares
+ data(new char[size])
{
- mv_size = strlen(s) + 1; // include the NUL, makes it easier for compares
+ mv_size = size;
mv_data = data.get();
+ memcpy(mv_data, s, size);
}
private:
+ size_t size;
std::unique_ptr<char[]> data;
};
@@ -923,6 +926,8 @@ BlockchainLMDB::~BlockchainLMDB()
// batch transaction shouldn't be active at this point. If it is, consider it aborted.
if (m_batch_active)
batch_abort();
+ if (m_open)
+ close();
}
BlockchainLMDB::BlockchainLMDB(bool batch_transactions)
@@ -1153,6 +1158,7 @@ void BlockchainLMDB::close()
// FIXME: not yet thread safe!!! Use with care.
mdb_env_close(m_env);
+ m_open = false;
}
void BlockchainLMDB::sync()
@@ -2496,8 +2502,22 @@ uint8_t BlockchainLMDB::get_hard_fork_version(uint64_t height) const
return ret;
}
+bool BlockchainLMDB::is_read_only() const
+{
+ unsigned int flags;
+ auto result = mdb_env_get_flags(m_env, &flags);
+ if (result)
+ throw0(DB_ERROR(std::string("Error getting database environment info: ").append(mdb_strerror(result)).c_str()));
+
+ if (flags & MDB_RDONLY)
+ return true;
+
+ return false;
+}
+
void BlockchainLMDB::fixup()
{
+ LOG_PRINT_L3("BlockchainLMDB::" << __func__);
// Always call parent as well
BlockchainDB::fixup();
}
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index d1d3b942d..7332d64c6 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -266,6 +266,8 @@ private:
void check_open() const;
+ virtual bool is_read_only() const;
+
// fix up anything that may be wrong due to past bugs
virtual void fixup();
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 71a2b8841..141a42f49 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -490,7 +490,7 @@ block Blockchain::pop_block_from_blockchain()
}
}
}
- m_tx_pool.on_blockchain_dec(m_blocks.size()-1, get_tail_id());
+ m_tx_pool.on_blockchain_dec(m_db->height()-1, get_tail_id());
return popped_block;
}
@@ -499,11 +499,7 @@ bool Blockchain::reset_and_set_genesis_block(const block& b)
{
LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock);
- m_transactions.clear();
- m_blocks.clear();
- m_blocks_index.clear();
m_alternative_chains.clear();
- m_outputs.clear();
m_db->reset();
block_verification_context bvc = boost::value_initialized<block_verification_context>();
@@ -1251,7 +1247,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
{
// if block parent is not part of main chain or an alternate chain,
// we ignore it
- CHECK_AND_ASSERT_MES(parent_in_main, false, "internal error: broken imperative condition it_main_prev != m_blocks_index.end()");
+ CHECK_AND_ASSERT_MES(parent_in_main, false, "internal error: broken imperative condition: parent_in_main");
complete_timestamps_vector(m_db->get_block_height(b.prev_id), timestamps);
}
@@ -2113,6 +2109,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_bloc
if(have_tx_keyimg_as_spent(in_to_key.k_image))
{
LOG_PRINT_L1("Key image already spent in blockchain: " << epee::string_tools::pod_to_hex(in_to_key.k_image));
+ KILL_IOSERVICE();
return false;
}
@@ -2126,6 +2123,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_bloc
if(!itk->second)
{
LOG_PRINT_L1("Failed ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
+ KILL_IOSERVICE();
return false;
}
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 2f9287e81..bc167f489 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -195,8 +195,6 @@ namespace cryptonote
mutable epee::critical_section m_blockchain_lock; // TODO: add here reader/writer lock
// main chain
- blocks_container m_blocks; // height -> block_extended_info
- blocks_by_id_index m_blocks_index; // crypto::hash -> height
transactions_container m_transactions;
size_t m_current_block_cumul_sz_limit;
@@ -230,7 +228,6 @@ namespace cryptonote
// some invalid blocks
blocks_ext_by_hash m_invalid_blocks; // crypto::hash -> block_extended_info
- outputs_container m_outputs;
checkpoints m_checkpoints;
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 8a3b81205..2f6980aec 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -266,6 +266,28 @@ namespace cryptonote
LOG_PRINT_L0("Loading blockchain from folder " << folder.string() << " ...");
+ // check for blockchain.bin
+ bool old_blockchain_found = false;
+ try
+ {
+ const boost::filesystem::path old_files = folder.parent_path();
+ if (boost::filesystem::exists(folder.parent_path() / "blockchain.bin"))
+ {
+ LOG_PRINT_L0("Found old-style blockchain.bin in " << old_files.string());
+ LOG_PRINT_L0("Monero now uses a new format. You can either remove blockchain.bin to start syncing");
+ LOG_PRINT_L0("the blockchain anew, or use blockchain_export and blockchain_import to convert your");
+ LOG_PRINT_L0("existing blockchain.bin to the new format. See README.md for instructions.");
+ old_blockchain_found = true;
+ }
+ }
+ // folder might not be a directory, etc, etc
+ catch (...) {}
+
+ if (old_blockchain_found)
+ {
+ throw DB_ERROR("Database could not be opened");
+ }
+
const std::string filename = folder.string();
// temporarily default to fastest:async:1000
blockchain_db_sync_mode sync_mode = db_async;
diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp
index 14d731108..e8ac7be98 100644
--- a/src/cryptonote_core/hardfork.cpp
+++ b/src/cryptonote_core/hardfork.cpp
@@ -375,7 +375,7 @@ bool HardFork::get_voting_info(uint8_t version, uint32_t &window, uint32_t &vote
for (size_t n = version; n < 256; ++n)
votes += last_versions[n];
threshold = (window * heights[current_version].threshold + 99) / 100;
- assert((votes >= threshold) == enabled);
+ //assert((votes >= threshold) == enabled);
earliest_height = get_earliest_ideal_height_for_version(version);
voting = heights.back().version;
return enabled;
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index a1f48bd77..0c1ea48c1 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -57,6 +57,7 @@ namespace tools
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::run()
{
+ m_stop = false;
m_net_server.add_idle_handler([this](){
try {
m_wallet.refresh();
@@ -65,6 +66,14 @@ namespace tools
}
return true;
}, 20000);
+ m_net_server.add_idle_handler([this](){
+ if (m_stop.load(std::memory_order_relaxed))
+ {
+ send_stop_signal();
+ return false;
+ }
+ return true;
+ }, 500);
//DO NOT START THIS SERVER IN MORE THEN 1 THREADS WITHOUT REFACTORING
return epee::http_server_impl_base<wallet_rpc_server, connection_context>::run(1, true);
@@ -605,11 +614,6 @@ namespace tools
}
}
- if (!transfers_found)
- {
- return false;
- }
-
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -653,8 +657,8 @@ namespace tools
try
{
- send_stop_signal();
m_wallet.store();
+ m_stop.store(true, std::memory_order_relaxed);
}
catch (std::exception& e)
{
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index a7c5077e9..97b84fcb6 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -102,5 +102,6 @@ namespace tools
wallet2& m_wallet;
std::string m_port;
std::string m_bind_ip;
+ std::atomic<bool> m_stop;
};
}