aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db
diff options
context:
space:
mode:
authorwarptangent <warptangent@tutanota.com>2016-02-18 06:38:44 -0800
committerwarptangent <warptangent@tutanota.com>2016-02-18 06:38:56 -0800
commit57e75fa33faba71c7cba17eeaa72bb780a95bc4c (patch)
treee0f5e5ec7d03a96cb74cee248bdd155dbda79c40 /src/blockchain_db
parentBlockchainBDB: Support blockchain_import --drop-hard-fork command (diff)
downloadmonero-57e75fa33faba71c7cba17eeaa72bb780a95bc4c.tar.xz
BlockchainBDB: Check if hard fork subdbs need reset
See f7e337e6254c1c4115a8430964a6f6b54305b3ae for LMDB equivalent.
Diffstat (limited to 'src/blockchain_db')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index 93ad6c587..d44e14f5b 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -2210,7 +2210,56 @@ uint64_t BlockchainBDB::get_hard_fork_starting_height(uint8_t version) const
void BlockchainBDB::check_hard_fork_info()
{
- /* FIXME: Some other time */
+ LOG_PRINT_L3("BlockchainBDB::" << __func__);
+ check_open();
+
+ if (m_hf_versions == nullptr)
+ {
+ LOG_PRINT_L0("hf versions DB not open, so not checking");
+ return;
+ }
+
+ DB_BTREE_STAT* db_stat1, * db_stat2;
+
+ // DB_FAST_STAT can apparently cause an incorrect number of records
+ // to be returned. The flag should be set to 0 instead if this proves
+ // to be the case.
+
+ // Set txn to NULL and DB_FAST_STAT to zero (0) for reliability.
+ m_blocks->stat(NULL, &db_stat1, 0);
+ m_hf_versions->stat(NULL, &db_stat2, 0);
+ if (db_stat1->bt_nkeys != db_stat2->bt_nkeys)
+ {
+ LOG_PRINT_L0("num blocks " << db_stat1->bt_nkeys << " != " << "num hf_versions " << db_stat2->bt_nkeys << " - will clear the two hard fork DBs");
+
+ bdb_txn_safe txn;
+ bdb_txn_safe* txn_ptr = &txn;
+ if (m_write_txn)
+ txn_ptr = m_write_txn;
+ else
+ {
+ if (m_env->txn_begin(NULL, txn, 0))
+ throw0(DB_ERROR("Failed to create a transaction for the db"));
+ }
+
+ try
+ {
+ uint32_t count;
+ m_hf_starting_heights->truncate(*txn_ptr, &count, 0);
+ LOG_PRINT_L0("hf_starting_heights count: " << count);
+ m_hf_versions->truncate(*txn_ptr, &count, 0);
+ LOG_PRINT_L0("hf_versions count: " << count);
+
+ if (!m_write_txn)
+ txn.commit();
+ }
+ catch (const std::exception& e)
+ {
+ throw0(DB_ERROR(std::string("Failed to clear two hard fork DBs: ").append(e.what()).c_str()));
+ }
+ }
+ delete db_stat1;
+ delete db_stat2;
}
void BlockchainBDB::drop_hard_fork_info()