diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/blockchain_db/berkeleydb/db_bdb.cpp | 6 | ||||
-rw-r--r-- | src/blockchain_db/berkeleydb/db_bdb.h | 3 | ||||
-rw-r--r-- | src/blockchain_db/blockchain_db.cpp | 5 | ||||
-rw-r--r-- | src/blockchain_db/blockchain_db.h | 2 | ||||
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.cpp | 14 | ||||
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.h | 2 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 8 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.h | 3 | ||||
-rw-r--r-- | src/cryptonote_core/hardfork.cpp | 4 |
9 files changed, 36 insertions, 11 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 0fd18bc18..9555318a5 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -2502,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 02cb348d6..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); } 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/hardfork.cpp b/src/cryptonote_core/hardfork.cpp index 9bd4a337c..e8ac7be98 100644 --- a/src/cryptonote_core/hardfork.cpp +++ b/src/cryptonote_core/hardfork.cpp @@ -210,7 +210,7 @@ bool HardFork::reorganize_from_block_height(uint64_t height) last_versions[n] = 0; const uint64_t rescan_height = height >= (window_size - 1) ? height - (window_size -1) : 0; const uint8_t start_version = height == 0 ? original_version : db.get_hard_fork_version(height); - while (heights[current_fork_index].version > start_version) { + while (current_fork_index > 0 && heights[current_fork_index].version > start_version) { db.set_hard_fork_starting_height(heights[current_fork_index].version, std::numeric_limits<uint64_t>::max()); --current_fork_index; } @@ -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; |