diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 7e1183ba..7f256615 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -1375,7 +1375,7 @@ namespace lmdb store.account.del (transaction, nano::dev::genesis->account ()); // Confirmation height for the account should be deleted - ASSERT_TRUE (mdb_get (store.env.tx (transaction), store.confirmation_height_handle, + ASSERT_TRUE (mdb_get (store.env.tx (transaction), store.confirmation_height_store.confirmation_height_handle, nano::mdb_val (nano::dev::genesis->account ()), value)); } @@ -2191,7 +2191,7 @@ namespace lmdb void modify_confirmation_height_to_v15 (nano::lmdb::store & store, nano::transaction const & transaction, nano::account const & account, uint64_t confirmation_height) { - auto status (mdb_put (store.env.tx (transaction), store.confirmation_height_handle, nano::mdb_val (account), nano::mdb_val (confirmation_height), 0)); + auto status (mdb_put (store.env.tx (transaction), store.confirmation_height_store.confirmation_height_handle, nano::mdb_val (account), nano::mdb_val (confirmation_height), 0)); ASSERT_EQ (status, 0); } } diff --git a/nano/node/lmdb/confirmation_height_store.hpp b/nano/node/lmdb/confirmation_height_store.hpp index 08d8daf6..ed814994 100644 --- a/nano/node/lmdb/confirmation_height_store.hpp +++ b/nano/node/lmdb/confirmation_height_store.hpp @@ -2,6 +2,8 @@ #include +#include + namespace nano { namespace lmdb @@ -24,6 +26,12 @@ namespace lmdb nano::store_iterator begin (nano::transaction const & transaction_a) const override; nano::store_iterator end () const override; void for_each_par (std::function, nano::store_iterator)> const & action_a) const override; + + /* + * Confirmation height of an account, and the hash for the block at that height + * nano::account -> uint64_t, nano::block_hash + */ + MDB_dbi confirmation_height_handle{ 0 }; }; } } diff --git a/nano/node/lmdb/lmdb.cpp b/nano/node/lmdb/lmdb.cpp index b03b74f4..ffa07f6d 100644 --- a/nano/node/lmdb/lmdb.cpp +++ b/nano/node/lmdb/lmdb.cpp @@ -216,7 +216,7 @@ void nano::lmdb::store::open_databases (bool & error_a, nano::transaction const error_a |= mdb_dbi_open (env.tx (transaction_a), "meta", flags, &meta_handle) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "peers", flags, &peer_store.peers_handle) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "pruned", flags, &pruned_store.pruned_handle) != 0; - error_a |= mdb_dbi_open (env.tx (transaction_a), "confirmation_height", flags, &confirmation_height_handle) != 0; + error_a |= mdb_dbi_open (env.tx (transaction_a), "confirmation_height", flags, &confirmation_height_store.confirmation_height_handle) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "accounts", flags, &account_store.accounts_v0_handle) != 0; account_store.accounts_handle = account_store.accounts_v0_handle; error_a |= mdb_dbi_open (env.tx (transaction_a), "pending", flags, &pending_store.pending_v0_handle) != 0; @@ -335,7 +335,7 @@ void nano::lmdb::store::upgrade_v14_to_v15 (nano::write_transaction & transactio release_assert (rep_block != nullptr); account_infos.emplace_back (account, nano::account_info{ account_info_v14.head, rep_block->representative (), account_info_v14.open_block, account_info_v14.balance, account_info_v14.modified, account_info_v14.block_count, i_account.from_first_database ? nano::epoch::epoch_0 : nano::epoch::epoch_1 }); // Move confirmation height from account_info database to its own table - mdb_put (env.tx (transaction_a), confirmation_height_handle, nano::mdb_val (account), nano::mdb_val (account_info_v14.confirmation_height), MDB_APPEND); + mdb_put (env.tx (transaction_a), confirmation_height_store.confirmation_height_handle, nano::mdb_val (account), nano::mdb_val (account_info_v14.confirmation_height), MDB_APPEND); i_account.from_first_database ? ++account_counters.after_v0 : ++account_counters.after_v1; } @@ -456,7 +456,7 @@ void nano::lmdb::store::upgrade_v16_to_v17 (nano::write_transaction const & tran // Set the confirmed frontier for each account in the confirmation height table std::vector> confirmation_height_infos; auto num = 0u; - for (nano::mdb_iterator i (transaction_a, confirmation_height_handle), n (nano::mdb_iterator{}); i != n; ++i, ++account_info_i, ++num) + for (nano::mdb_iterator i (transaction_a, confirmation_height_store.confirmation_height_handle), n (nano::mdb_iterator{}); i != n; ++i, ++account_info_i, ++num) { nano::account account (i->first); uint64_t confirmation_height (i->second); @@ -513,12 +513,12 @@ void nano::lmdb::store::upgrade_v16_to_v17 (nano::write_transaction const & tran } // Clear it then append - auto status (mdb_drop (env.tx (transaction_a), confirmation_height_handle, 0)); + auto status (mdb_drop (env.tx (transaction_a), confirmation_height_store.confirmation_height_handle, 0)); release_assert_success (status); for (auto const & confirmation_height_info_pair : confirmation_height_infos) { - mdb_put (env.tx (transaction_a), confirmation_height_handle, nano::mdb_val (confirmation_height_info_pair.first), nano::mdb_val (confirmation_height_info_pair.second), MDB_APPEND); + mdb_put (env.tx (transaction_a), confirmation_height_store.confirmation_height_handle, nano::mdb_val (confirmation_height_info_pair.first), nano::mdb_val (confirmation_height_info_pair.second), MDB_APPEND); } version.put (transaction_a, 17); @@ -879,7 +879,7 @@ MDB_dbi nano::lmdb::store::table_to_dbi (tables table_a) const case tables::pruned: return pruned_store.pruned_handle; case tables::confirmation_height: - return confirmation_height_handle; + return confirmation_height_store.confirmation_height_handle; case tables::final_votes: return final_votes_handle; default: @@ -916,7 +916,7 @@ bool nano::lmdb::store::copy_db (boost::filesystem::path const & destination_fil void nano::lmdb::store::rebuild_db (nano::write_transaction const & transaction_a) { // Tables with uint256_union key - std::vector tables = { account_store.accounts_handle, blocks_handle, pruned_store.pruned_handle, confirmation_height_handle }; + std::vector tables = { account_store.accounts_handle, blocks_handle, pruned_store.pruned_handle, confirmation_height_store.confirmation_height_handle }; for (auto const & table : tables) { MDB_dbi temp; diff --git a/nano/node/lmdb/lmdb.hpp b/nano/node/lmdb/lmdb.hpp index 5c11371b..3b0816df 100644 --- a/nano/node/lmdb/lmdb.hpp +++ b/nano/node/lmdb/lmdb.hpp @@ -148,12 +148,6 @@ namespace lmdb */ MDB_dbi meta_handle{ 0 }; - /* - * Confirmation height of an account, and the hash for the block at that height - * nano::account -> uint64_t, nano::block_hash - */ - MDB_dbi confirmation_height_handle{ 0 }; - /* * Contains block_sideband and block for all block types (legacy send/change/open/receive & state blocks) * nano::block_hash -> nano::block_sideband, nano::block @@ -257,6 +251,7 @@ namespace lmdb friend class mdb_block_store_upgrade_v15_v16_Test; friend class mdb_block_store_upgrade_v19_v20_Test; friend void modify_account_info_to_v14 (nano::lmdb::store &, nano::transaction const &, nano::account const &, uint64_t, nano::block_hash const &); + friend void modify_confirmation_height_to_v15 (nano::lmdb::store &, nano::transaction const &, nano::account const &, uint64_t); }; }