Moved the confirmation_height LMDB table handler to its store class

This commit is contained in:
Thiago Silva 2022-04-11 17:21:57 -03:00
commit 96c4bfc988
4 changed files with 18 additions and 15 deletions

View file

@ -1375,7 +1375,7 @@ namespace lmdb
store.account.del (transaction, nano::dev::genesis->account ()); store.account.del (transaction, nano::dev::genesis->account ());
// Confirmation height for the account should be deleted // 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)); 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) 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); ASSERT_EQ (status, 0);
} }
} }

View file

@ -2,6 +2,8 @@
#include <nano/secure/store.hpp> #include <nano/secure/store.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h>
namespace nano namespace nano
{ {
namespace lmdb namespace lmdb
@ -24,6 +26,12 @@ namespace lmdb
nano::store_iterator<nano::account, nano::confirmation_height_info> begin (nano::transaction const & transaction_a) const override; nano::store_iterator<nano::account, nano::confirmation_height_info> begin (nano::transaction const & transaction_a) const override;
nano::store_iterator<nano::account, nano::confirmation_height_info> end () const override; nano::store_iterator<nano::account, nano::confirmation_height_info> end () const override;
void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::account, nano::confirmation_height_info>, nano::store_iterator<nano::account, nano::confirmation_height_info>)> const & action_a) const override; void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::account, nano::confirmation_height_info>, nano::store_iterator<nano::account, nano::confirmation_height_info>)> 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 };
}; };
} }
} }

View file

@ -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), "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), "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), "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; 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; 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; 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); 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 }); 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 // 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; 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 // Set the confirmed frontier for each account in the confirmation height table
std::vector<std::pair<nano::account, nano::confirmation_height_info>> confirmation_height_infos; std::vector<std::pair<nano::account, nano::confirmation_height_info>> confirmation_height_infos;
auto num = 0u; auto num = 0u;
for (nano::mdb_iterator<nano::account, uint64_t> i (transaction_a, confirmation_height_handle), n (nano::mdb_iterator<nano::account, uint64_t>{}); i != n; ++i, ++account_info_i, ++num) for (nano::mdb_iterator<nano::account, uint64_t> i (transaction_a, confirmation_height_store.confirmation_height_handle), n (nano::mdb_iterator<nano::account, uint64_t>{}); i != n; ++i, ++account_info_i, ++num)
{ {
nano::account account (i->first); nano::account account (i->first);
uint64_t confirmation_height (i->second); 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 // 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); release_assert_success (status);
for (auto const & confirmation_height_info_pair : confirmation_height_infos) 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); version.put (transaction_a, 17);
@ -879,7 +879,7 @@ MDB_dbi nano::lmdb::store::table_to_dbi (tables table_a) const
case tables::pruned: case tables::pruned:
return pruned_store.pruned_handle; return pruned_store.pruned_handle;
case tables::confirmation_height: case tables::confirmation_height:
return confirmation_height_handle; return confirmation_height_store.confirmation_height_handle;
case tables::final_votes: case tables::final_votes:
return final_votes_handle; return final_votes_handle;
default: 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) void nano::lmdb::store::rebuild_db (nano::write_transaction const & transaction_a)
{ {
// Tables with uint256_union key // Tables with uint256_union key
std::vector<MDB_dbi> tables = { account_store.accounts_handle, blocks_handle, pruned_store.pruned_handle, confirmation_height_handle }; std::vector<MDB_dbi> tables = { account_store.accounts_handle, blocks_handle, pruned_store.pruned_handle, confirmation_height_store.confirmation_height_handle };
for (auto const & table : tables) for (auto const & table : tables)
{ {
MDB_dbi temp; MDB_dbi temp;

View file

@ -148,12 +148,6 @@ namespace lmdb
*/ */
MDB_dbi meta_handle{ 0 }; 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) * Contains block_sideband and block for all block types (legacy send/change/open/receive & state blocks)
* nano::block_hash -> nano::block_sideband, nano::block * 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_v15_v16_Test;
friend class mdb_block_store_upgrade_v19_v20_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_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);
}; };
} }