From 40cc5aed81aaa399921ce95f7aeeeec9471ee11a Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 18 Sep 2023 22:33:29 +0100 Subject: [PATCH] Rename classes to be under namespace nano::store --- nano/core_test/backlog.cpp | 2 +- nano/core_test/block_store.cpp | 1844 +++++++++---------- nano/core_test/confirmation_height.cpp | 2 +- nano/core_test/gap_cache.cpp | 1 + nano/core_test/ledger.cpp | 6 +- nano/core_test/wallet.cpp | 38 +- nano/nano_node/entry.cpp | 10 +- nano/node/active_transactions.cpp | 2 +- nano/node/active_transactions.hpp | 2 +- nano/node/backlog_population.cpp | 2 +- nano/node/backlog_population.hpp | 15 +- nano/node/blockprocessor.cpp | 6 +- nano/node/blockprocessor.hpp | 11 +- nano/node/bootstrap/bootstrap.cpp | 2 +- nano/node/bootstrap/bootstrap.hpp | 7 +- nano/node/bootstrap/bootstrap_attempt.cpp | 2 +- nano/node/bootstrap/bootstrap_attempt.hpp | 7 +- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 2 +- nano/node/bootstrap/bootstrap_server.cpp | 12 +- nano/node/bootstrap/bootstrap_server.hpp | 17 +- nano/node/bootstrap_ascending/iterators.cpp | 2 +- nano/node/bootstrap_ascending/iterators.hpp | 85 +- nano/node/bootstrap_ascending/service.cpp | 2 +- nano/node/bootstrap_ascending/service.hpp | 2 +- nano/node/cli.cpp | 4 +- nano/node/confirmation_height_bounded.cpp | 4 +- nano/node/confirmation_height_bounded.hpp | 6 +- nano/node/confirmation_height_unbounded.cpp | 4 +- nano/node/confirmation_height_unbounded.hpp | 4 +- nano/node/json_handler.cpp | 14 +- nano/node/json_handler.hpp | 6 +- nano/node/ledger_walker.cpp | 2 +- nano/node/ledger_walker.hpp | 8 +- nano/node/make_store.cpp | 4 +- nano/node/node.cpp | 10 +- nano/node/node.hpp | 8 +- nano/node/online_reps.cpp | 2 +- nano/node/online_reps.hpp | 2 +- nano/node/process_live_dispatcher.cpp | 4 +- nano/node/process_live_dispatcher.hpp | 10 +- nano/node/scheduler/optimistic.cpp | 2 +- nano/node/scheduler/optimistic.hpp | 2 +- nano/node/scheduler/priority.cpp | 2 +- nano/node/scheduler/priority.hpp | 2 +- nano/node/voting.cpp | 2 +- nano/node/voting.hpp | 2 +- nano/node/wallet.cpp | 176 +- nano/node/wallet.hpp | 122 +- nano/secure/ledger.cpp | 114 +- nano/secure/ledger.hpp | 86 +- nano/slow_test/node.cpp | 2 +- nano/store/CMakeLists.txt | 2 + nano/store/account.cpp | 2 +- nano/store/account.hpp | 26 +- nano/store/block.hpp | 30 +- nano/store/component.cpp | 17 +- nano/store/component.hpp | 75 +- nano/store/confirmation_height.cpp | 2 +- nano/store/confirmation_height.hpp | 28 +- nano/store/db_val.hpp | 28 +- nano/store/final.hpp | 24 +- nano/store/frontier.hpp | 18 +- nano/store/iterator.hpp | 24 +- nano/store/iterator_impl.hpp | 18 +- nano/store/lmdb/account.cpp | 27 +- nano/store/lmdb/account.hpp | 64 +- nano/store/lmdb/block.cpp | 75 +- nano/store/lmdb/block.hpp | 97 +- nano/store/lmdb/confirmation_height.cpp | 28 +- nano/store/lmdb/confirmation_height.hpp | 48 +- nano/store/lmdb/db_val.cpp | 11 +- nano/store/lmdb/db_val.hpp | 4 +- nano/store/lmdb/final_vote.cpp | 26 +- nano/store/lmdb/final_vote.hpp | 48 +- nano/store/lmdb/frontier.cpp | 22 +- nano/store/lmdb/frontier.hpp | 42 +- nano/store/lmdb/iterator.hpp | 93 +- nano/store/lmdb/lmdb.cpp | 234 +-- nano/store/lmdb/lmdb.hpp | 285 +-- nano/store/lmdb/lmdb_env.cpp | 18 +- nano/store/lmdb/lmdb_env.hpp | 20 +- nano/store/lmdb/online_weight.cpp | 18 +- nano/store/lmdb/online_weight.hpp | 37 +- nano/store/lmdb/peer.cpp | 18 +- nano/store/lmdb/peer.hpp | 38 +- nano/store/lmdb/pending.cpp | 24 +- nano/store/lmdb/pending.hpp | 54 +- nano/store/lmdb/pruned.cpp | 24 +- nano/store/lmdb/pruned.hpp | 44 +- nano/store/lmdb/transaction.cpp | 34 +- nano/store/lmdb/transaction_impl.hpp | 48 +- nano/store/lmdb/version.cpp | 8 +- nano/store/lmdb/version.hpp | 24 +- nano/store/lmdb/wallet_value.cpp | 6 +- nano/store/lmdb/wallet_value.hpp | 4 +- nano/store/online_weight.hpp | 18 +- nano/store/peer.hpp | 18 +- nano/store/pending.hpp | 22 +- nano/store/pruned.hpp | 24 +- nano/store/rocksdb/account.cpp | 26 +- nano/store/rocksdb/account.hpp | 44 +- nano/store/rocksdb/block.cpp | 62 +- nano/store/rocksdb/block.hpp | 59 +- nano/store/rocksdb/confirmation_height.cpp | 28 +- nano/store/rocksdb/confirmation_height.hpp | 44 +- nano/store/rocksdb/db_val.cpp | 11 +- nano/store/rocksdb/db_val.hpp | 4 +- nano/store/rocksdb/final_vote.cpp | 26 +- nano/store/rocksdb/final_vote.hpp | 44 +- nano/store/rocksdb/frontier.cpp | 20 +- nano/store/rocksdb/frontier.hpp | 38 +- nano/store/rocksdb/iterator.hpp | 50 +- nano/store/rocksdb/online_weight.cpp | 18 +- nano/store/rocksdb/online_weight.hpp | 38 +- nano/store/rocksdb/peer.cpp | 18 +- nano/store/rocksdb/peer.hpp | 38 +- nano/store/rocksdb/pending.cpp | 24 +- nano/store/rocksdb/pending.hpp | 38 +- nano/store/rocksdb/pruned.cpp | 24 +- nano/store/rocksdb/pruned.hpp | 44 +- nano/store/rocksdb/rocksdb.cpp | 108 +- nano/store/rocksdb/rocksdb.hpp | 272 +-- nano/store/rocksdb/transaction.cpp | 34 +- nano/store/rocksdb/transaction_impl.hpp | 14 +- nano/store/rocksdb/version.cpp | 8 +- nano/store/rocksdb/version.hpp | 24 +- nano/store/transaction.cpp | 22 +- nano/store/transaction.hpp | 12 +- nano/store/version.hpp | 9 +- nano/store/versioning.cpp | 30 +- nano/store/versioning.hpp | 10 +- nano/test_common/system.cpp | 6 +- nano/test_common/system.hpp | 4 +- 133 files changed, 2916 insertions(+), 2919 deletions(-) diff --git a/nano/core_test/backlog.cpp b/nano/core_test/backlog.cpp index 0ad651d864..facbf0b538 100644 --- a/nano/core_test/backlog.cpp +++ b/nano/core_test/backlog.cpp @@ -20,7 +20,7 @@ TEST (backlog, population) nano::test::system system{}; auto & node = *system.add_node (); - node.backlog.activate_callback.add ([&] (nano::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { + node.backlog.activate_callback.add ([&] (nano::store::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { nano::lock_guard lock{ mutex }; activated.insert (account); diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index e298cc755e..0de4bad673 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -25,16 +27,13 @@ using namespace std::chrono_literals; -namespace nano -{ -namespace lmdb +namespace nano::store::lmdb { - void modify_account_info_to_v14 (nano::lmdb::store & store, nano::transaction const & transaction_a, nano::account const & account_a, uint64_t confirmation_height, nano::block_hash const & rep_block); - void modify_confirmation_height_to_v15 (nano::lmdb::store & store, nano::transaction const & transaction, nano::account const & account, uint64_t confirmation_height); - void write_sideband_v14 (nano::lmdb::store & store_a, nano::transaction & transaction_a, nano::block const & block_a, MDB_dbi db_a); - void write_sideband_v15 (nano::lmdb::store & store_a, nano::transaction & transaction_a, nano::block const & block_a); - void write_block_w_sideband_v18 (nano::lmdb::store & store_a, MDB_dbi database, nano::write_transaction & transaction_a, nano::block const & block_a); -} +void modify_account_info_to_v14 (nano::store::lmdb::component & store, store::transaction const & transaction_a, nano::account const & account_a, uint64_t confirmation_height, nano::block_hash const & rep_block); +void modify_confirmation_height_to_v15 (nano::store::lmdb::component & store, store::transaction const & transaction, nano::account const & account, uint64_t confirmation_height); +void write_sideband_v14 (nano::store::lmdb::component & store_a, store::transaction & transaction_a, nano::block const & block_a, MDB_dbi db_a); +void write_sideband_v15 (nano::store::lmdb::component & store_a, store::transaction & transaction_a, nano::block const & block_a); +void write_block_w_sideband_v18 (nano::store::lmdb::component & store_a, MDB_dbi database, store::write_transaction & transaction_a, nano::block const & block_a); } TEST (block_store, construction) @@ -628,60 +627,57 @@ TEST (block_store, latest_find) ASSERT_EQ (second, find3); } -namespace nano +namespace nano::store::lmdb { -namespace lmdb +TEST (mdb_block_store, supported_version_upgrades) { - TEST (mdb_block_store, supported_version_upgrades) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { - if (nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in rocksdb mode - GTEST_SKIP (); - } - // Check that upgrading from an unsupported version is not supported - auto path (nano::unique_path () / "data.ldb"); - nano::logger_mt logger; - { - nano::lmdb::store store (logger, path, nano::dev::constants); - nano::stats stats; - nano::ledger ledger (store, stats, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - store.initialize (transaction, ledger.cache, nano::dev::constants); - // Lower the database to the max version unsupported for upgrades - store.version.put (transaction, store.version_minimum - 1); - } + // Don't test this in rocksdb mode + GTEST_SKIP (); + } + // Check that upgrading from an unsupported version is not supported + auto path (nano::unique_path () / "data.ldb"); + nano::logger_mt logger; + { + nano::store::lmdb::component store (logger, path, nano::dev::constants); + nano::stats stats; + nano::ledger ledger (store, stats, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + store.initialize (transaction, ledger.cache, nano::dev::constants); + // Lower the database to the max version unsupported for upgrades + store.version.put (transaction, store.version_minimum - 1); + } - // Upgrade should fail - { - nano::lmdb::store store (logger, path, nano::dev::constants); - ASSERT_TRUE (store.init_error ()); - } + // Upgrade should fail + { + nano::store::lmdb::component store (logger, path, nano::dev::constants); + ASSERT_TRUE (store.init_error ()); + } - auto path1 (nano::unique_path () / "data.ldb"); - // Now try with the minimum version - { - nano::lmdb::store store (logger, path1, nano::dev::constants); - nano::stats stats; - nano::ledger ledger (store, stats, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - store.initialize (transaction, ledger.cache, nano::dev::constants); - // Lower the database version to the minimum version supported for upgrade. - store.version.put (transaction, store.version_minimum); - store.confirmation_height.del (transaction, nano::dev::genesis->account ()); - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "accounts_v1", MDB_CREATE, - &store.account_store.accounts_v1_handle)); - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "open", MDB_CREATE, &store.block_store.open_blocks_handle)); - modify_account_info_to_v14 (store, transaction, nano::dev::genesis->account (), 1, - nano::dev::genesis->hash ()); - write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); - } + auto path1 (nano::unique_path () / "data.ldb"); + // Now try with the minimum version + { + nano::store::lmdb::component store (logger, path1, nano::dev::constants); + nano::stats stats; + nano::ledger ledger (store, stats, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + store.initialize (transaction, ledger.cache, nano::dev::constants); + // Lower the database version to the minimum version supported for upgrade. + store.version.put (transaction, store.version_minimum); + store.confirmation_height.del (transaction, nano::dev::genesis->account ()); + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "accounts_v1", MDB_CREATE, + &store.account_store.accounts_v1_handle)); + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "open", MDB_CREATE, &store.block_store.open_blocks_handle)); + modify_account_info_to_v14 (store, transaction, nano::dev::genesis->account (), 1, + nano::dev::genesis->hash ()); + write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); + } - // Upgrade should work - { - nano::lmdb::store store (logger, path1, nano::dev::constants); - ASSERT_FALSE (store.init_error ()); - } + // Upgrade should work + { + nano::store::lmdb::component store (logger, path1, nano::dev::constants); + ASSERT_FALSE (store.init_error ()); } } } @@ -694,7 +690,7 @@ TEST (mdb_block_store, bad_path) GTEST_SKIP (); } nano::logger_mt logger; - nano::lmdb::store store (logger, boost::filesystem::path ("///"), nano::dev::constants); + nano::store::lmdb::component store (logger, boost::filesystem::path ("///"), nano::dev::constants); ASSERT_TRUE (store.init_error ()); } @@ -1013,7 +1009,7 @@ TEST (mdb_block_store, sideband_height) nano::keypair key1; nano::keypair key2; nano::keypair key3; - nano::lmdb::store store (logger, nano::unique_path () / "data.ldb", nano::dev::constants); + nano::store::lmdb::component store (logger, nano::unique_path () / "data.ldb", nano::dev::constants); ASSERT_FALSE (store.init_error ()); nano::stats stats; nano::ledger ledger (store, stats, nano::dev::constants); @@ -1371,896 +1367,893 @@ TEST (block_store, pruned_blocks) ASSERT_EQ (store->pruned.count (store->tx_begin_read ()), 0); } -namespace nano +namespace nano::store::lmdb { -namespace lmdb +TEST (mdb_block_store, upgrade_v14_v15) { - TEST (mdb_block_store, upgrade_v14_v15) + if (nano::rocksdb_config::using_rocksdb_in_tests ()) + { + // Don't test this in rocksdb mode + GTEST_SKIP (); + } + // Extract confirmation height to a separate database + auto path (nano::unique_path () / "data.ldb"); + nano::block_builder builder; + nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; + auto send = builder + .send () + .previous (nano::dev::genesis->hash ()) + .destination (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (nano::dev::genesis->hash ())) + .build (); + auto epoch = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (send->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) + .link (nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_1)) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (send->hash ())) + .build (); + auto state_send = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (epoch->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) + .link (nano::dev::genesis_key.pub) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (epoch->hash ())) + .build (); { - if (nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in rocksdb mode - GTEST_SKIP (); - } - // Extract confirmation height to a separate database - auto path (nano::unique_path () / "data.ldb"); - nano::block_builder builder; - nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; - auto send = builder - .send () - .previous (nano::dev::genesis->hash ()) - .destination (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (nano::dev::genesis->hash ())) - .build (); - auto epoch = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (send->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_1)) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (send->hash ())) - .build (); - auto state_send = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (epoch->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) - .link (nano::dev::genesis_key.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (epoch->hash ())) - .build (); - { - nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); - nano::stats stats; - nano::ledger ledger (store, stats, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - store.initialize (transaction, ledger.cache, nano::dev::constants); - auto account_info = ledger.account_info (transaction, nano::dev::genesis->account ()); - ASSERT_TRUE (account_info); - nano::confirmation_height_info confirmation_height_info; - ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (), - confirmation_height_info)); - ASSERT_EQ (confirmation_height_info.height, 1); - ASSERT_EQ (confirmation_height_info.frontier, nano::dev::genesis->hash ()); - // These databases get removed after an upgrade, so readd them - ASSERT_FALSE ( - mdb_dbi_open (store.env.tx (transaction), "state_v1", MDB_CREATE, &store.block_store.state_blocks_v1_handle)); - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "accounts_v1", MDB_CREATE, - &store.account_store.accounts_v1_handle)); - ASSERT_FALSE ( - mdb_dbi_open (store.env.tx (transaction), "pending_v1", MDB_CREATE, &store.pending_store.pending_v1_handle)); - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "open", MDB_CREATE, &store.block_store.open_blocks_handle)); - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "send", MDB_CREATE, &store.block_store.send_blocks_handle)); - ASSERT_FALSE ( - mdb_dbi_open (store.env.tx (transaction), "state_blocks", MDB_CREATE, - &store.block_store.state_blocks_handle)); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *epoch).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send).code); - // Lower the database to the previous version - store.version.put (transaction, 14); - store.confirmation_height.del (transaction, nano::dev::genesis->account ()); - modify_account_info_to_v14 (store, transaction, nano::dev::genesis->account (), - confirmation_height_info.height, state_send->hash ()); - - store.pending.del (transaction, nano::pending_key (nano::dev::genesis->account (), state_send->hash ())); - - write_sideband_v14 (store, transaction, *state_send, store.block_store.state_blocks_v1_handle); - write_sideband_v14 (store, transaction, *epoch, store.block_store.state_blocks_v1_handle); - write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); - write_block_w_sideband_v18 (store, store.block_store.send_blocks_handle, transaction, *send); - - // Remove from blocks table - store.block.del (transaction, state_send->hash ()); - store.block.del (transaction, epoch->hash ()); - - // Turn pending into v14 - ASSERT_FALSE (mdb_put (store.env.tx (transaction), store.pending_store.pending_v0_handle, - nano::mdb_val (nano::pending_key (nano::dev::genesis_key.pub, send->hash ())), - nano::mdb_val ( - nano::pending_info_v14 (nano::dev::genesis->account (), nano::Gxrb_ratio, - nano::epoch::epoch_0)), - 0)); - ASSERT_FALSE (mdb_put (store.env.tx (transaction), store.pending_store.pending_v1_handle, - nano::mdb_val (nano::pending_key (nano::dev::genesis_key.pub, state_send->hash ())), - nano::mdb_val ( - nano::pending_info_v14 (nano::dev::genesis->account (), nano::Gxrb_ratio, - nano::epoch::epoch_1)), - 0)); - - // This should fail as sizes are no longer correct for account_info - nano::mdb_val value; - ASSERT_FALSE (mdb_get (store.env.tx (transaction), store.account_store.accounts_v1_handle, - nano::mdb_val (nano::dev::genesis->account ()), value)); - nano::account_info info; - ASSERT_NE (value.size (), info.db_size ()); - 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_store.confirmation_height_handle, - nano::mdb_val (nano::dev::genesis->account ()), value)); - } - - // Now do the upgrade nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); - ASSERT_FALSE (store.init_error ()); - auto transaction (store.tx_begin_read ()); - - // Size of account_info should now equal that set in db - nano::mdb_val value; - ASSERT_FALSE (mdb_get (store.env.tx (transaction), store.account_store.accounts_handle, - nano::mdb_val (nano::dev::genesis->account ()), value)); - nano::account_info info (value); - ASSERT_EQ (value.size (), info.db_size ()); - - // Confirmation height should exist + nano::store::lmdb::component store (logger, path, nano::dev::constants); + nano::stats stats; + nano::ledger ledger (store, stats, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + store.initialize (transaction, ledger.cache, nano::dev::constants); + auto account_info = ledger.account_info (transaction, nano::dev::genesis->account ()); + ASSERT_TRUE (account_info); nano::confirmation_height_info confirmation_height_info; - ASSERT_FALSE ( - store.confirmation_height.get (transaction, nano::dev::genesis->account (), + ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (), confirmation_height_info)); ASSERT_EQ (confirmation_height_info.height, 1); ASSERT_EQ (confirmation_height_info.frontier, nano::dev::genesis->hash ()); + // These databases get removed after an upgrade, so readd them + ASSERT_FALSE ( + mdb_dbi_open (store.env.tx (transaction), "state_v1", MDB_CREATE, &store.block_store.state_blocks_v1_handle)); + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "accounts_v1", MDB_CREATE, + &store.account_store.accounts_v1_handle)); + ASSERT_FALSE ( + mdb_dbi_open (store.env.tx (transaction), "pending_v1", MDB_CREATE, &store.pending_store.pending_v1_handle)); + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "open", MDB_CREATE, &store.block_store.open_blocks_handle)); + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "send", MDB_CREATE, &store.block_store.send_blocks_handle)); + ASSERT_FALSE ( + mdb_dbi_open (store.env.tx (transaction), "state_blocks", MDB_CREATE, + &store.block_store.state_blocks_handle)); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *epoch).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send).code); + // Lower the database to the previous version + store.version.put (transaction, 14); + store.confirmation_height.del (transaction, nano::dev::genesis->account ()); + modify_account_info_to_v14 (store, transaction, nano::dev::genesis->account (), + confirmation_height_info.height, state_send->hash ()); + + store.pending.del (transaction, nano::pending_key (nano::dev::genesis->account (), state_send->hash ())); + + write_sideband_v14 (store, transaction, *state_send, store.block_store.state_blocks_v1_handle); + write_sideband_v14 (store, transaction, *epoch, store.block_store.state_blocks_v1_handle); + write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); + write_block_w_sideband_v18 (store, store.block_store.send_blocks_handle, transaction, *send); + + // Remove from blocks table + store.block.del (transaction, state_send->hash ()); + store.block.del (transaction, epoch->hash ()); + + // Turn pending into v14 + ASSERT_FALSE (mdb_put (store.env.tx (transaction), store.pending_store.pending_v0_handle, + nano::store::lmdb::db_val (nano::pending_key (nano::dev::genesis_key.pub, send->hash ())), + nano::store::lmdb::db_val ( + nano::store::pending_info_v14 (nano::dev::genesis->account (), nano::Gxrb_ratio, + nano::epoch::epoch_0)), + 0)); + ASSERT_FALSE (mdb_put (store.env.tx (transaction), store.pending_store.pending_v1_handle, + nano::store::lmdb::db_val (nano::pending_key (nano::dev::genesis_key.pub, state_send->hash ())), + nano::store::lmdb::db_val ( + nano::store::pending_info_v14 (nano::dev::genesis->account (), nano::Gxrb_ratio, + nano::epoch::epoch_1)), + 0)); + + // This should fail as sizes are no longer correct for account_info + nano::store::lmdb::db_val value; + ASSERT_FALSE (mdb_get (store.env.tx (transaction), store.account_store.accounts_v1_handle, + nano::store::lmdb::db_val (nano::dev::genesis->account ()), value)); + nano::account_info info; + ASSERT_NE (value.size (), info.db_size ()); + store.account.del (transaction, nano::dev::genesis->account ()); - // accounts_v1, state_blocks_v1 & pending_v1 tables should be deleted - auto error_get_accounts_v1 (mdb_get (store.env.tx (transaction), store.account_store.accounts_v1_handle, - nano::mdb_val (nano::dev::genesis->account ()), value)); - ASSERT_NE (error_get_accounts_v1, MDB_SUCCESS); - auto error_get_pending_v1 (mdb_get (store.env.tx (transaction), store.pending_store.pending_v1_handle, nano::mdb_val (nano::pending_key (nano::dev::genesis_key.pub, state_send->hash ())), value)); - ASSERT_NE (error_get_pending_v1, MDB_SUCCESS); - auto error_get_state_v1 ( - mdb_get (store.env.tx (transaction), store.block_store.state_blocks_v1_handle, nano::mdb_val (state_send->hash ()), - value)); - ASSERT_NE (error_get_state_v1, MDB_SUCCESS); - - // Check that the epochs are set correctly for the sideband, accounts and pending entries - auto block = store.block.get (transaction, state_send->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); - block = store.block.get (transaction, send->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_0); - ASSERT_EQ (info.epoch (), nano::epoch::epoch_1); - nano::pending_info pending_info; - store.pending.get (transaction, nano::pending_key (nano::dev::genesis_key.pub, send->hash ()), pending_info); - ASSERT_EQ (pending_info.epoch, nano::epoch::epoch_0); - store.pending.get (transaction, nano::pending_key (nano::dev::genesis_key.pub, state_send->hash ()), - pending_info); - ASSERT_EQ (pending_info.epoch, nano::epoch::epoch_1); + // Confirmation height for the account should be deleted + ASSERT_TRUE (mdb_get (store.env.tx (transaction), store.confirmation_height_store.confirmation_height_handle, + nano::store::lmdb::db_val (nano::dev::genesis->account ()), value)); + } - // Version should be correct - ASSERT_LT (14, store.version.get (transaction)); + // Now do the upgrade + nano::logger_mt logger; + nano::store::lmdb::component store (logger, path, nano::dev::constants); + ASSERT_FALSE (store.init_error ()); + auto transaction (store.tx_begin_read ()); + + // Size of account_info should now equal that set in db + nano::store::lmdb::db_val value; + ASSERT_FALSE (mdb_get (store.env.tx (transaction), store.account_store.accounts_handle, + nano::store::lmdb::db_val (nano::dev::genesis->account ()), value)); + nano::account_info info (value); + ASSERT_EQ (value.size (), info.db_size ()); + + // Confirmation height should exist + nano::confirmation_height_info confirmation_height_info; + ASSERT_FALSE ( + store.confirmation_height.get (transaction, nano::dev::genesis->account (), + confirmation_height_info)); + ASSERT_EQ (confirmation_height_info.height, 1); + ASSERT_EQ (confirmation_height_info.frontier, nano::dev::genesis->hash ()); + + // accounts_v1, state_blocks_v1 & pending_v1 tables should be deleted + auto error_get_accounts_v1 (mdb_get (store.env.tx (transaction), store.account_store.accounts_v1_handle, + nano::store::lmdb::db_val (nano::dev::genesis->account ()), value)); + ASSERT_NE (error_get_accounts_v1, MDB_SUCCESS); + auto error_get_pending_v1 (mdb_get (store.env.tx (transaction), store.pending_store.pending_v1_handle, nano::store::lmdb::db_val (nano::pending_key (nano::dev::genesis_key.pub, state_send->hash ())), value)); + ASSERT_NE (error_get_pending_v1, MDB_SUCCESS); + auto error_get_state_v1 ( + mdb_get (store.env.tx (transaction), store.block_store.state_blocks_v1_handle, nano::store::lmdb::db_val (state_send->hash ()), + value)); + ASSERT_NE (error_get_state_v1, MDB_SUCCESS); + + // Check that the epochs are set correctly for the sideband, accounts and pending entries + auto block = store.block.get (transaction, state_send->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); + block = store.block.get (transaction, send->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_0); + ASSERT_EQ (info.epoch (), nano::epoch::epoch_1); + nano::pending_info pending_info; + store.pending.get (transaction, nano::pending_key (nano::dev::genesis_key.pub, send->hash ()), pending_info); + ASSERT_EQ (pending_info.epoch, nano::epoch::epoch_0); + store.pending.get (transaction, nano::pending_key (nano::dev::genesis_key.pub, state_send->hash ()), + pending_info); + ASSERT_EQ (pending_info.epoch, nano::epoch::epoch_1); + + // Version should be correct + ASSERT_LT (14, store.version.get (transaction)); +} + +TEST (mdb_block_store, upgrade_v15_v16) +{ + if (nano::rocksdb_config::using_rocksdb_in_tests ()) + { + // Don't test this in rocksdb mode + GTEST_SKIP (); + } + auto path (nano::unique_path () / "data.ldb"); + nano::store::lmdb::db_val value; + { + nano::logger_mt logger; + nano::store::lmdb::component store (logger, path, nano::dev::constants); + nano::stats stats; + nano::ledger ledger (store, stats, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + store.initialize (transaction, ledger.cache, nano::dev::constants); + // The representation table should get removed after, so readd it so that we can later confirm this actually happens + auto txn = store.env.tx (transaction); + ASSERT_FALSE ( + mdb_dbi_open (txn, "representation", MDB_CREATE, &store.account_store.representation_handle)); + auto weight = ledger.cache.rep_weights.representation_get (nano::dev::genesis->account ()); + ASSERT_EQ (MDB_SUCCESS, mdb_put (txn, store.account_store.representation_handle, nano::store::lmdb::db_val (nano::dev::genesis->account ()), nano::store::lmdb::db_val (nano::uint128_union (weight)), 0)); + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "open", MDB_CREATE, &store.block_store.open_blocks_handle)); + write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); + // Lower the database to the previous version + store.version.put (transaction, 15); + // Confirm the rep weight exists in the database + ASSERT_EQ (MDB_SUCCESS, mdb_get (store.env.tx (transaction), store.account_store.representation_handle, nano::store::lmdb::db_val (nano::dev::genesis->account ()), value)); + store.confirmation_height.del (transaction, nano::dev::genesis->account ()); } - TEST (mdb_block_store, upgrade_v15_v16) + // Now do the upgrade + nano::logger_mt logger; + nano::store::lmdb::component store (logger, path, nano::dev::constants); + ASSERT_FALSE (store.init_error ()); + auto transaction (store.tx_begin_read ()); + + // The representation table should now be deleted + auto error_get_representation (mdb_get (store.env.tx (transaction), store.account_store.representation_handle, + nano::store::lmdb::db_val (nano::dev::genesis->account ()), value)); + ASSERT_NE (MDB_SUCCESS, error_get_representation); + ASSERT_EQ (store.account_store.representation_handle, 0); + + // Version should be correct + ASSERT_LT (15, store.version.get (transaction)); +} + +TEST (mdb_block_store, upgrade_v16_v17) +{ + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { - if (nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in rocksdb mode - GTEST_SKIP (); - } + // Don't test this in rocksdb mode + GTEST_SKIP (); + } + nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; + nano::block_builder builder; + auto block1 = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (nano::dev::genesis->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) + .link (nano::dev::genesis_key.pub) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (nano::dev::genesis->hash ())) + .build (); + auto block2 = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (block1->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio - 1) + .link (nano::dev::genesis_key.pub) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (block1->hash ())) + .build (); + auto block3 = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (block2->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio - 2) + .link (nano::dev::genesis_key.pub) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (block2->hash ())) + .build (); + + auto code = [&block1, &block2, &block3] (auto confirmation_height, nano::block_hash const & expected_cemented_frontier) { auto path (nano::unique_path () / "data.ldb"); - nano::mdb_val value; + nano::store::lmdb::db_val value; { nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); + nano::store::lmdb::component store (logger, path, nano::dev::constants); nano::stats stats; nano::ledger ledger (store, stats, nano::dev::constants); auto transaction (store.tx_begin_write ()); store.initialize (transaction, ledger.cache, nano::dev::constants); - // The representation table should get removed after, so readd it so that we can later confirm this actually happens - auto txn = store.env.tx (transaction); - ASSERT_FALSE ( - mdb_dbi_open (txn, "representation", MDB_CREATE, &store.account_store.representation_handle)); - auto weight = ledger.cache.rep_weights.representation_get (nano::dev::genesis->account ()); - ASSERT_EQ (MDB_SUCCESS, mdb_put (txn, store.account_store.representation_handle, nano::mdb_val (nano::dev::genesis->account ()), nano::mdb_val (nano::uint128_union (weight)), 0)); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *block1).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *block2).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *block3).code); + modify_confirmation_height_to_v15 (store, transaction, nano::dev::genesis->account (), confirmation_height); + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "open", MDB_CREATE, &store.block_store.open_blocks_handle)); write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "state_blocks", MDB_CREATE, &store.block_store.state_blocks_handle)); + write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *block1); + write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *block2); + write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *block3); + // Lower the database to the previous version - store.version.put (transaction, 15); - // Confirm the rep weight exists in the database - ASSERT_EQ (MDB_SUCCESS, mdb_get (store.env.tx (transaction), store.account_store.representation_handle, nano::mdb_val (nano::dev::genesis->account ()), value)); - store.confirmation_height.del (transaction, nano::dev::genesis->account ()); + store.version.put (transaction, 16); } // Now do the upgrade nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); + nano::store::lmdb::component store (logger, path, nano::dev::constants); ASSERT_FALSE (store.init_error ()); auto transaction (store.tx_begin_read ()); - // The representation table should now be deleted - auto error_get_representation (mdb_get (store.env.tx (transaction), store.account_store.representation_handle, - nano::mdb_val (nano::dev::genesis->account ()), value)); - ASSERT_NE (MDB_SUCCESS, error_get_representation); - ASSERT_EQ (store.account_store.representation_handle, 0); + nano::confirmation_height_info confirmation_height_info; + ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (), confirmation_height_info)); + ASSERT_EQ (confirmation_height_info.height, confirmation_height); + + // Check confirmation height frontier is correct + ASSERT_EQ (confirmation_height_info.frontier, expected_cemented_frontier); // Version should be correct - ASSERT_LT (15, store.version.get (transaction)); - } + ASSERT_LT (16, store.version.get (transaction)); + }; + + code (0, nano::block_hash (0)); + code (1, nano::dev::genesis->hash ()); + code (2, block1->hash ()); + code (3, block2->hash ()); + code (4, block3->hash ()); +} - TEST (mdb_block_store, upgrade_v16_v17) +TEST (mdb_block_store, upgrade_v17_v18) +{ + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { - if (nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in rocksdb mode - GTEST_SKIP (); - } - nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; - nano::block_builder builder; - auto block1 = builder + // Don't test this in rocksdb mode + GTEST_SKIP (); + } + auto path (nano::unique_path () / "data.ldb"); + nano::block_builder builder; + nano::keypair key1; + nano::keypair key2; + nano::keypair key3; + nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; + auto send_zero = builder + .send () + .previous (nano::dev::genesis->hash ()) + .destination (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (nano::dev::genesis->hash ())) + .build (); + auto state_receive_zero = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (send_zero->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount) + .link (send_zero->hash ()) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (send_zero->hash ())) + .build (); + auto epoch = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (state_receive_zero->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount) + .link (nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_1)) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (state_receive_zero->hash ())) + .build (); + auto state_send = builder .state () .account (nano::dev::genesis_key.pub) - .previous (nano::dev::genesis->hash ()) + .previous (epoch->hash ()) .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (nano::dev::genesis->hash ())) - .build (); - auto block2 = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (block1->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio - 1) - .link (nano::dev::genesis_key.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (block1->hash ())) - .build (); - auto block3 = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (block2->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio - 2) - .link (nano::dev::genesis_key.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (block2->hash ())) + .work (*pool.generate (epoch->hash ())) .build (); - - auto code = [&block1, &block2, &block3] (auto confirmation_height, nano::block_hash const & expected_cemented_frontier) { - auto path (nano::unique_path () / "data.ldb"); - nano::mdb_val value; - { - nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); - nano::stats stats; - nano::ledger ledger (store, stats, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - store.initialize (transaction, ledger.cache, nano::dev::constants); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *block1).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *block2).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *block3).code); - modify_confirmation_height_to_v15 (store, transaction, nano::dev::genesis->account (), confirmation_height); - - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "open", MDB_CREATE, &store.block_store.open_blocks_handle)); - write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "state_blocks", MDB_CREATE, &store.block_store.state_blocks_handle)); - write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *block1); - write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *block2); - write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *block3); - - // Lower the database to the previous version - store.version.put (transaction, 16); - } - - // Now do the upgrade - nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); - ASSERT_FALSE (store.init_error ()); - auto transaction (store.tx_begin_read ()); - - nano::confirmation_height_info confirmation_height_info; - ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (), confirmation_height_info)); - ASSERT_EQ (confirmation_height_info.height, confirmation_height); - - // Check confirmation height frontier is correct - ASSERT_EQ (confirmation_height_info.frontier, expected_cemented_frontier); - - // Version should be correct - ASSERT_LT (16, store.version.get (transaction)); - }; - - code (0, nano::block_hash (0)); - code (1, nano::dev::genesis->hash ()); - code (2, block1->hash ()); - code (3, block2->hash ()); - code (4, block3->hash ()); - } - - TEST (mdb_block_store, upgrade_v17_v18) - { - if (nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in rocksdb mode - GTEST_SKIP (); - } - auto path (nano::unique_path () / "data.ldb"); - nano::block_builder builder; - nano::keypair key1; - nano::keypair key2; - nano::keypair key3; - nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; - auto send_zero = builder - .send () - .previous (nano::dev::genesis->hash ()) - .destination (nano::dev::genesis_key.pub) + auto state_receive = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (state_send->hash ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) + .link (state_send->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (nano::dev::genesis->hash ())) + .work (*pool.generate (state_send->hash ())) .build (); - auto state_receive_zero = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (send_zero->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount) - .link (send_zero->hash ()) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (send_zero->hash ())) - .build (); - auto epoch = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (state_receive_zero->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount) - .link (nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_1)) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (state_receive_zero->hash ())) - .build (); - auto state_send = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (epoch->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis_key.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (epoch->hash ())) - .build (); - auto state_receive = builder + auto state_change = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (state_receive->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount) + .link (0) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (state_receive->hash ())) + .build (); + auto state_send_change = builder .state () .account (nano::dev::genesis_key.pub) - .previous (state_send->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount) - .link (state_send->hash ()) + .previous (state_change->hash ()) + .representative (key1.pub) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) + .link (key1.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (state_send->hash ())) + .work (*pool.generate (state_change->hash ())) .build (); - auto state_change = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (state_receive->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount) - .link (0) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (state_receive->hash ())) - .build (); - auto state_send_change = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (state_change->hash ()) - .representative (key1.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (key1.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (state_change->hash ())) - .build (); - auto epoch_first = builder - .state () - .account (key1.pub) - .previous (0) - .representative (0) - .balance (0) - .link (nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_2)) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (key1.pub)) - .build (); - auto state_receive2 = builder - .state () - .account (key1.pub) - .previous (epoch_first->hash ()) - .representative (key1.pub) - .balance (nano::Gxrb_ratio) - .link (state_send_change->hash ()) - .sign (key1.prv, key1.pub) - .work (*pool.generate (epoch_first->hash ())) - .build (); - auto state_send2 = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (state_send_change->hash ()) - .representative (key1.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) - .link (key2.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (state_send_change->hash ())) - .build (); - auto state_open = builder + auto epoch_first = builder + .state () + .account (key1.pub) + .previous (0) + .representative (0) + .balance (0) + .link (nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_2)) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (key1.pub)) + .build (); + auto state_receive2 = builder .state () - .account (key2.pub) - .previous (0) - .representative (key2.pub) + .account (key1.pub) + .previous (epoch_first->hash ()) + .representative (key1.pub) .balance (nano::Gxrb_ratio) - .link (state_send2->hash ()) - .sign (key2.prv, key2.pub) - .work (*pool.generate (key2.pub)) + .link (state_send_change->hash ()) + .sign (key1.prv, key1.pub) + .work (*pool.generate (epoch_first->hash ())) .build (); - auto state_send_epoch_link = builder - .state () - .account (key2.pub) - .previous (state_open->hash ()) - .representative (key2.pub) - .balance (0) - .link (nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_2)) - .sign (key2.prv, key2.pub) - .work (*pool.generate (state_open->hash ())) - .build (); - { - nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - nano::stats stats; - nano::ledger ledger (store, stats, nano::dev::constants); - store.initialize (transaction, ledger.cache, nano::dev::constants); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send_zero).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_receive_zero).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *epoch).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_receive).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_change).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send_change).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *epoch_first).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_receive2).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send2).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_open).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send_epoch_link).code); - - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "open", MDB_CREATE, &store.block_store.open_blocks_handle)); - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "send", MDB_CREATE, &store.block_store.send_blocks_handle)); - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "state_blocks", MDB_CREATE, &store.block_store.state_blocks_handle)); - - // Downgrade the store - store.version.put (transaction, 17); - - write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_receive); - write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *epoch_first); - write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_send2); - write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_send_epoch_link); - write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); - write_block_w_sideband_v18 (store, store.block_store.send_blocks_handle, transaction, *send_zero); - - // Replace with the previous sideband version for state blocks - // The upgrade can resume after upgrading some blocks, test this by only downgrading some of them - write_sideband_v15 (store, transaction, *state_receive_zero); - write_sideband_v15 (store, transaction, *epoch); - write_sideband_v15 (store, transaction, *state_send); - write_sideband_v15 (store, transaction, *state_change); - write_sideband_v15 (store, transaction, *state_send_change); - write_sideband_v15 (store, transaction, *state_receive2); - write_sideband_v15 (store, transaction, *state_open); - - store.block.del (transaction, state_receive_zero->hash ()); - store.block.del (transaction, epoch->hash ()); - store.block.del (transaction, state_send->hash ()); - store.block.del (transaction, state_change->hash ()); - store.block.del (transaction, state_send_change->hash ()); - store.block.del (transaction, state_receive2->hash ()); - store.block.del (transaction, state_open->hash ()); - } - - // Now do the upgrade - nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); - ASSERT_FALSE (store.init_error ()); - auto transaction (store.tx_begin_read ()); + auto state_send2 = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (state_send_change->hash ()) + .representative (key1.pub) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) + .link (key2.pub) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (state_send_change->hash ())) + .build (); + auto state_open = builder + .state () + .account (key2.pub) + .previous (0) + .representative (key2.pub) + .balance (nano::Gxrb_ratio) + .link (state_send2->hash ()) + .sign (key2.prv, key2.pub) + .work (*pool.generate (key2.pub)) + .build (); + auto state_send_epoch_link = builder + .state () + .account (key2.pub) + .previous (state_open->hash ()) + .representative (key2.pub) + .balance (0) + .link (nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_2)) + .sign (key2.prv, key2.pub) + .work (*pool.generate (state_open->hash ())) + .build (); + { + nano::logger_mt logger; + nano::store::lmdb::component store (logger, path, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + nano::stats stats; + nano::ledger ledger (store, stats, nano::dev::constants); + store.initialize (transaction, ledger.cache, nano::dev::constants); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send_zero).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_receive_zero).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *epoch).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_receive).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_change).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send_change).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *epoch_first).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_receive2).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send2).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_open).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send_epoch_link).code); + + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "open", MDB_CREATE, &store.block_store.open_blocks_handle)); + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "send", MDB_CREATE, &store.block_store.send_blocks_handle)); + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "state_blocks", MDB_CREATE, &store.block_store.state_blocks_handle)); + + // Downgrade the store + store.version.put (transaction, 17); + + write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_receive); + write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *epoch_first); + write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_send2); + write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_send_epoch_link); + write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); + write_block_w_sideband_v18 (store, store.block_store.send_blocks_handle, transaction, *send_zero); + + // Replace with the previous sideband version for state blocks + // The upgrade can resume after upgrading some blocks, test this by only downgrading some of them + write_sideband_v15 (store, transaction, *state_receive_zero); + write_sideband_v15 (store, transaction, *epoch); + write_sideband_v15 (store, transaction, *state_send); + write_sideband_v15 (store, transaction, *state_change); + write_sideband_v15 (store, transaction, *state_send_change); + write_sideband_v15 (store, transaction, *state_receive2); + write_sideband_v15 (store, transaction, *state_open); + + store.block.del (transaction, state_receive_zero->hash ()); + store.block.del (transaction, epoch->hash ()); + store.block.del (transaction, state_send->hash ()); + store.block.del (transaction, state_change->hash ()); + store.block.del (transaction, state_send_change->hash ()); + store.block.del (transaction, state_receive2->hash ()); + store.block.del (transaction, state_open->hash ()); + } - // Size of state block should equal that set in db (no change) - nano::mdb_val value; - ASSERT_FALSE (mdb_get (store.env.tx (transaction), store.block_store.blocks_handle, nano::mdb_val (state_send->hash ()), value)); - ASSERT_EQ (value.size (), sizeof (nano::block_type) + nano::state_block::size + nano::block_sideband::size (nano::block_type::state)); + // Now do the upgrade + nano::logger_mt logger; + nano::store::lmdb::component store (logger, path, nano::dev::constants); + ASSERT_FALSE (store.init_error ()); + auto transaction (store.tx_begin_read ()); - // Check that sidebands are correctly populated - { - // Non-state unaffected - auto block = store.block.get (transaction, send_zero->hash ()); - ASSERT_NE (block, nullptr); - // All defaults - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_0); - ASSERT_FALSE (block->sideband ().details.is_epoch); - ASSERT_FALSE (block->sideband ().details.is_send); - ASSERT_FALSE (block->sideband ().details.is_receive); - } - { - // State receive from old zero send - auto block = store.block.get (transaction, state_receive_zero->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_0); - ASSERT_FALSE (block->sideband ().details.is_epoch); - ASSERT_FALSE (block->sideband ().details.is_send); - ASSERT_TRUE (block->sideband ().details.is_receive); - } - { - // Epoch - auto block = store.block.get (transaction, epoch->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); - ASSERT_TRUE (block->sideband ().details.is_epoch); - ASSERT_FALSE (block->sideband ().details.is_send); - ASSERT_FALSE (block->sideband ().details.is_receive); - } - { - // State send - auto block = store.block.get (transaction, state_send->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); - ASSERT_FALSE (block->sideband ().details.is_epoch); - ASSERT_TRUE (block->sideband ().details.is_send); - ASSERT_FALSE (block->sideband ().details.is_receive); - } - { - // State receive - auto block = store.block.get (transaction, state_receive->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); - ASSERT_FALSE (block->sideband ().details.is_epoch); - ASSERT_FALSE (block->sideband ().details.is_send); - ASSERT_TRUE (block->sideband ().details.is_receive); - } - { - // State change - auto block = store.block.get (transaction, state_change->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); - ASSERT_FALSE (block->sideband ().details.is_epoch); - ASSERT_FALSE (block->sideband ().details.is_send); - ASSERT_FALSE (block->sideband ().details.is_receive); - } - { - // State send + change - auto block = store.block.get (transaction, state_send_change->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); - ASSERT_FALSE (block->sideband ().details.is_epoch); - ASSERT_TRUE (block->sideband ().details.is_send); - ASSERT_FALSE (block->sideband ().details.is_receive); - } - { - // Epoch on unopened account - auto block = store.block.get (transaction, epoch_first->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_2); - ASSERT_TRUE (block->sideband ().details.is_epoch); - ASSERT_FALSE (block->sideband ().details.is_send); - ASSERT_FALSE (block->sideband ().details.is_receive); - } - { - // State open following epoch - auto block = store.block.get (transaction, state_receive2->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_2); - ASSERT_FALSE (block->sideband ().details.is_epoch); - ASSERT_FALSE (block->sideband ().details.is_send); - ASSERT_TRUE (block->sideband ().details.is_receive); - } - { - // Another state send - auto block = store.block.get (transaction, state_send2->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); - ASSERT_FALSE (block->sideband ().details.is_epoch); - ASSERT_TRUE (block->sideband ().details.is_send); - ASSERT_FALSE (block->sideband ().details.is_receive); - } - { - // State open - auto block = store.block.get (transaction, state_open->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); - ASSERT_FALSE (block->sideband ().details.is_epoch); - ASSERT_FALSE (block->sideband ().details.is_send); - ASSERT_TRUE (block->sideband ().details.is_receive); - } - { - // State send to an epoch link - auto block = store.block.get (transaction, state_send_epoch_link->hash ()); - ASSERT_NE (block, nullptr); - ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); - ASSERT_FALSE (block->sideband ().details.is_epoch); - ASSERT_TRUE (block->sideband ().details.is_send); - ASSERT_FALSE (block->sideband ().details.is_receive); - } - // Version should be correct - ASSERT_LT (17, store.version.get (transaction)); + // Size of state block should equal that set in db (no change) + nano::store::lmdb::db_val value; + ASSERT_FALSE (mdb_get (store.env.tx (transaction), store.block_store.blocks_handle, nano::store::lmdb::db_val (state_send->hash ()), value)); + ASSERT_EQ (value.size (), sizeof (nano::block_type) + nano::state_block::size + nano::block_sideband::size (nano::block_type::state)); + + // Check that sidebands are correctly populated + { + // Non-state unaffected + auto block = store.block.get (transaction, send_zero->hash ()); + ASSERT_NE (block, nullptr); + // All defaults + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_0); + ASSERT_FALSE (block->sideband ().details.is_epoch); + ASSERT_FALSE (block->sideband ().details.is_send); + ASSERT_FALSE (block->sideband ().details.is_receive); + } + { + // State receive from old zero send + auto block = store.block.get (transaction, state_receive_zero->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_0); + ASSERT_FALSE (block->sideband ().details.is_epoch); + ASSERT_FALSE (block->sideband ().details.is_send); + ASSERT_TRUE (block->sideband ().details.is_receive); + } + { + // Epoch + auto block = store.block.get (transaction, epoch->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); + ASSERT_TRUE (block->sideband ().details.is_epoch); + ASSERT_FALSE (block->sideband ().details.is_send); + ASSERT_FALSE (block->sideband ().details.is_receive); + } + { + // State send + auto block = store.block.get (transaction, state_send->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); + ASSERT_FALSE (block->sideband ().details.is_epoch); + ASSERT_TRUE (block->sideband ().details.is_send); + ASSERT_FALSE (block->sideband ().details.is_receive); } + { + // State receive + auto block = store.block.get (transaction, state_receive->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); + ASSERT_FALSE (block->sideband ().details.is_epoch); + ASSERT_FALSE (block->sideband ().details.is_send); + ASSERT_TRUE (block->sideband ().details.is_receive); + } + { + // State change + auto block = store.block.get (transaction, state_change->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); + ASSERT_FALSE (block->sideband ().details.is_epoch); + ASSERT_FALSE (block->sideband ().details.is_send); + ASSERT_FALSE (block->sideband ().details.is_receive); + } + { + // State send + change + auto block = store.block.get (transaction, state_send_change->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); + ASSERT_FALSE (block->sideband ().details.is_epoch); + ASSERT_TRUE (block->sideband ().details.is_send); + ASSERT_FALSE (block->sideband ().details.is_receive); + } + { + // Epoch on unopened account + auto block = store.block.get (transaction, epoch_first->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_2); + ASSERT_TRUE (block->sideband ().details.is_epoch); + ASSERT_FALSE (block->sideband ().details.is_send); + ASSERT_FALSE (block->sideband ().details.is_receive); + } + { + // State open following epoch + auto block = store.block.get (transaction, state_receive2->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_2); + ASSERT_FALSE (block->sideband ().details.is_epoch); + ASSERT_FALSE (block->sideband ().details.is_send); + ASSERT_TRUE (block->sideband ().details.is_receive); + } + { + // Another state send + auto block = store.block.get (transaction, state_send2->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); + ASSERT_FALSE (block->sideband ().details.is_epoch); + ASSERT_TRUE (block->sideband ().details.is_send); + ASSERT_FALSE (block->sideband ().details.is_receive); + } + { + // State open + auto block = store.block.get (transaction, state_open->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); + ASSERT_FALSE (block->sideband ().details.is_epoch); + ASSERT_FALSE (block->sideband ().details.is_send); + ASSERT_TRUE (block->sideband ().details.is_receive); + } + { + // State send to an epoch link + auto block = store.block.get (transaction, state_send_epoch_link->hash ()); + ASSERT_NE (block, nullptr); + ASSERT_EQ (block->sideband ().details.epoch, nano::epoch::epoch_1); + ASSERT_FALSE (block->sideband ().details.is_epoch); + ASSERT_TRUE (block->sideband ().details.is_send); + ASSERT_FALSE (block->sideband ().details.is_receive); + } + // Version should be correct + ASSERT_LT (17, store.version.get (transaction)); +} - TEST (mdb_block_store, upgrade_v18_v19) +TEST (mdb_block_store, upgrade_v18_v19) +{ + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { - if (nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in rocksdb mode - GTEST_SKIP (); - } - auto path (nano::unique_path () / "data.ldb"); - nano::keypair key1; - nano::block_builder builder; - nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; - auto send = builder - .send () - .previous (nano::dev::genesis->hash ()) - .destination (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (nano::dev::genesis->hash ())) - .build (); - auto receive = builder - .receive () - .previous (send->hash ()) - .source (send->hash ()) + // Don't test this in rocksdb mode + GTEST_SKIP (); + } + auto path (nano::unique_path () / "data.ldb"); + nano::keypair key1; + nano::block_builder builder; + nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; + auto send = builder + .send () + .previous (nano::dev::genesis->hash ()) + .destination (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (nano::dev::genesis->hash ())) + .build (); + auto receive = builder + .receive () + .previous (send->hash ()) + .source (send->hash ()) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (send->hash ())) + .build (); + auto change = builder + .change () + .previous (receive->hash ()) + .representative (0) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*pool.generate (receive->hash ())) + .build (); + auto state_epoch = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (change->hash ()) + .representative (0) + .balance (nano::dev::constants.genesis_amount) + .link (nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_1)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (send->hash ())) + .work (*pool.generate (change->hash ())) .build (); - auto change = builder - .change () - .previous (receive->hash ()) + auto state_send = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (state_epoch->hash ()) .representative (0) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) + .link (key1.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (receive->hash ())) + .work (*pool.generate (state_epoch->hash ())) .build (); - auto state_epoch = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (change->hash ()) - .representative (0) - .balance (nano::dev::constants.genesis_amount) - .link (nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_1)) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (change->hash ())) - .build (); - auto state_send = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (state_epoch->hash ()) - .representative (0) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (key1.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (state_epoch->hash ())) - .build (); - auto state_open = builder - .state () - .account (key1.pub) - .previous (0) - .representative (0) - .balance (nano::Gxrb_ratio) - .link (state_send->hash ()) - .sign (key1.prv, key1.pub) - .work (*pool.generate (key1.pub)) - .build (); - { - nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); - nano::stats stats; - nano::ledger ledger (store, stats, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - store.initialize (transaction, ledger.cache, nano::dev::constants); - - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *receive).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *change).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_epoch).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send).code); - ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_open).code); - - // These tables need to be re-opened and populated so that an upgrade can be done - auto txn = store.env.tx (transaction); - ASSERT_FALSE (mdb_dbi_open (txn, "open", MDB_CREATE, &store.block_store.open_blocks_handle)); - ASSERT_FALSE (mdb_dbi_open (txn, "receive", MDB_CREATE, &store.block_store.receive_blocks_handle)); - ASSERT_FALSE (mdb_dbi_open (txn, "send", MDB_CREATE, &store.block_store.send_blocks_handle)); - ASSERT_FALSE (mdb_dbi_open (txn, "change", MDB_CREATE, &store.block_store.change_blocks_handle)); - ASSERT_FALSE (mdb_dbi_open (txn, "state_blocks", MDB_CREATE, &store.block_store.state_blocks_handle)); - - // Modify blocks back to the old tables - write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); - write_block_w_sideband_v18 (store, store.block_store.send_blocks_handle, transaction, *send); - write_block_w_sideband_v18 (store, store.block_store.receive_blocks_handle, transaction, *receive); - write_block_w_sideband_v18 (store, store.block_store.change_blocks_handle, transaction, *change); - write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_epoch); - write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_send); - write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_open); - - store.version.put (transaction, 18); - } - - // Now do the upgrade + auto state_open = builder + .state () + .account (key1.pub) + .previous (0) + .representative (0) + .balance (nano::Gxrb_ratio) + .link (state_send->hash ()) + .sign (key1.prv, key1.pub) + .work (*pool.generate (key1.pub)) + .build (); + { nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); - ASSERT_FALSE (store.init_error ()); - auto transaction (store.tx_begin_read ()); + nano::store::lmdb::component store (logger, path, nano::dev::constants); + nano::stats stats; + nano::ledger ledger (store, stats, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + store.initialize (transaction, ledger.cache, nano::dev::constants); + + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *receive).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *change).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_epoch).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_send).code); + ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *state_open).code); + + // These tables need to be re-opened and populated so that an upgrade can be done + auto txn = store.env.tx (transaction); + ASSERT_FALSE (mdb_dbi_open (txn, "open", MDB_CREATE, &store.block_store.open_blocks_handle)); + ASSERT_FALSE (mdb_dbi_open (txn, "receive", MDB_CREATE, &store.block_store.receive_blocks_handle)); + ASSERT_FALSE (mdb_dbi_open (txn, "send", MDB_CREATE, &store.block_store.send_blocks_handle)); + ASSERT_FALSE (mdb_dbi_open (txn, "change", MDB_CREATE, &store.block_store.change_blocks_handle)); + ASSERT_FALSE (mdb_dbi_open (txn, "state_blocks", MDB_CREATE, &store.block_store.state_blocks_handle)); + + // Modify blocks back to the old tables + write_block_w_sideband_v18 (store, store.block_store.open_blocks_handle, transaction, *nano::dev::genesis); + write_block_w_sideband_v18 (store, store.block_store.send_blocks_handle, transaction, *send); + write_block_w_sideband_v18 (store, store.block_store.receive_blocks_handle, transaction, *receive); + write_block_w_sideband_v18 (store, store.block_store.change_blocks_handle, transaction, *change); + write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_epoch); + write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_send); + write_block_w_sideband_v18 (store, store.block_store.state_blocks_handle, transaction, *state_open); + + store.version.put (transaction, 18); + } - // These tables should be deleted - ASSERT_EQ (store.block_store.send_blocks_handle, 0); - ASSERT_EQ (store.block_store.receive_blocks_handle, 0); - ASSERT_EQ (store.block_store.change_blocks_handle, 0); - ASSERT_EQ (store.block_store.open_blocks_handle, 0); - ASSERT_EQ (store.block_store.state_blocks_handle, 0); - - // Confirm these blocks all exist after the upgrade - ASSERT_TRUE (store.block.get (transaction, send->hash ())); - ASSERT_TRUE (store.block.get (transaction, receive->hash ())); - ASSERT_TRUE (store.block.get (transaction, change->hash ())); - ASSERT_TRUE (store.block.get (transaction, nano::dev::genesis->hash ())); - auto state_epoch_disk (store.block.get (transaction, state_epoch->hash ())); - ASSERT_NE (nullptr, state_epoch_disk); - ASSERT_EQ (nano::epoch::epoch_1, state_epoch_disk->sideband ().details.epoch); - ASSERT_EQ (nano::epoch::epoch_0, state_epoch_disk->sideband ().source_epoch); // Not used for epoch state blocks - ASSERT_TRUE (store.block.get (transaction, state_send->hash ())); - auto state_send_disk (store.block.get (transaction, state_send->hash ())); - ASSERT_NE (nullptr, state_send_disk); - ASSERT_EQ (nano::epoch::epoch_1, state_send_disk->sideband ().details.epoch); - ASSERT_EQ (nano::epoch::epoch_0, state_send_disk->sideband ().source_epoch); // Not used for send state blocks - ASSERT_TRUE (store.block.get (transaction, state_open->hash ())); - auto state_open_disk (store.block.get (transaction, state_open->hash ())); - ASSERT_NE (nullptr, state_open_disk); - ASSERT_EQ (nano::epoch::epoch_1, state_open_disk->sideband ().details.epoch); - ASSERT_EQ (nano::epoch::epoch_1, state_open_disk->sideband ().source_epoch); - - ASSERT_EQ (7, store.count (transaction, store.block_store.blocks_handle)); + // Now do the upgrade + nano::logger_mt logger; + nano::store::lmdb::component store (logger, path, nano::dev::constants); + ASSERT_FALSE (store.init_error ()); + auto transaction (store.tx_begin_read ()); - // Version should be correct - ASSERT_LT (18, store.version.get (transaction)); - } + // These tables should be deleted + ASSERT_EQ (store.block_store.send_blocks_handle, 0); + ASSERT_EQ (store.block_store.receive_blocks_handle, 0); + ASSERT_EQ (store.block_store.change_blocks_handle, 0); + ASSERT_EQ (store.block_store.open_blocks_handle, 0); + ASSERT_EQ (store.block_store.state_blocks_handle, 0); + + // Confirm these blocks all exist after the upgrade + ASSERT_TRUE (store.block.get (transaction, send->hash ())); + ASSERT_TRUE (store.block.get (transaction, receive->hash ())); + ASSERT_TRUE (store.block.get (transaction, change->hash ())); + ASSERT_TRUE (store.block.get (transaction, nano::dev::genesis->hash ())); + auto state_epoch_disk (store.block.get (transaction, state_epoch->hash ())); + ASSERT_NE (nullptr, state_epoch_disk); + ASSERT_EQ (nano::epoch::epoch_1, state_epoch_disk->sideband ().details.epoch); + ASSERT_EQ (nano::epoch::epoch_0, state_epoch_disk->sideband ().source_epoch); // Not used for epoch state blocks + ASSERT_TRUE (store.block.get (transaction, state_send->hash ())); + auto state_send_disk (store.block.get (transaction, state_send->hash ())); + ASSERT_NE (nullptr, state_send_disk); + ASSERT_EQ (nano::epoch::epoch_1, state_send_disk->sideband ().details.epoch); + ASSERT_EQ (nano::epoch::epoch_0, state_send_disk->sideband ().source_epoch); // Not used for send state blocks + ASSERT_TRUE (store.block.get (transaction, state_open->hash ())); + auto state_open_disk (store.block.get (transaction, state_open->hash ())); + ASSERT_NE (nullptr, state_open_disk); + ASSERT_EQ (nano::epoch::epoch_1, state_open_disk->sideband ().details.epoch); + ASSERT_EQ (nano::epoch::epoch_1, state_open_disk->sideband ().source_epoch); + + ASSERT_EQ (7, store.count (transaction, store.block_store.blocks_handle)); + + // Version should be correct + ASSERT_LT (18, store.version.get (transaction)); +} - TEST (mdb_block_store, upgrade_v19_v20) +TEST (mdb_block_store, upgrade_v19_v20) +{ + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { - if (nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in rocksdb mode - GTEST_SKIP (); - } - auto path (nano::unique_path () / "data.ldb"); - nano::logger_mt logger; - nano::stats stats; - { - nano::lmdb::store store (logger, path, nano::dev::constants); - nano::ledger ledger (store, stats, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - store.initialize (transaction, ledger.cache, nano::dev::constants); - // Delete pruned table - ASSERT_FALSE (mdb_drop (store.env.tx (transaction), store.pruned_store.pruned_handle, 1)); - store.version.put (transaction, 19); - } - // Upgrading should create the table - nano::lmdb::store store (logger, path, nano::dev::constants); - ASSERT_FALSE (store.init_error ()); - ASSERT_NE (store.pruned_store.pruned_handle, 0); - - // Version should be correct - auto transaction (store.tx_begin_read ()); - ASSERT_LT (19, store.version.get (transaction)); + // Don't test this in rocksdb mode + GTEST_SKIP (); } - - TEST (mdb_block_store, upgrade_v20_v21) + auto path (nano::unique_path () / "data.ldb"); + nano::logger_mt logger; + nano::stats stats; { - if (nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in rocksdb mode - GTEST_SKIP (); - } - auto path (nano::unique_path () / "data.ldb"); - nano::logger_mt logger; - nano::stats stats; - { - nano::lmdb::store store (logger, path, nano::dev::constants); - nano::ledger ledger (store, stats, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - store.initialize (transaction, ledger.cache, ledger.constants); - // Delete pruned table - ASSERT_FALSE (mdb_drop (store.env.tx (transaction), store.final_vote_store.final_votes_handle, 1)); - store.version.put (transaction, 20); - } - // Upgrading should create the table - nano::lmdb::store store (logger, path, nano::dev::constants); - ASSERT_FALSE (store.init_error ()); - ASSERT_NE (store.final_vote_store.final_votes_handle, 0); - - // Version should be correct - auto transaction (store.tx_begin_read ()); - ASSERT_LT (19, store.version.get (transaction)); + nano::store::lmdb::component store (logger, path, nano::dev::constants); + nano::ledger ledger (store, stats, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + store.initialize (transaction, ledger.cache, nano::dev::constants); + // Delete pruned table + ASSERT_FALSE (mdb_drop (store.env.tx (transaction), store.pruned_store.pruned_handle, 1)); + store.version.put (transaction, 19); } + // Upgrading should create the table + nano::store::lmdb::component store (logger, path, nano::dev::constants); + ASSERT_FALSE (store.init_error ()); + ASSERT_NE (store.pruned_store.pruned_handle, 0); + + // Version should be correct + auto transaction (store.tx_begin_read ()); + ASSERT_LT (19, store.version.get (transaction)); +} - TEST (mdb_block_store, upgrade_v21_v22) +TEST (mdb_block_store, upgrade_v20_v21) +{ + if (nano::rocksdb_config::using_rocksdb_in_tests ()) { - if (nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in rocksdb mode - GTEST_SKIP (); - } + // Don't test this in rocksdb mode + GTEST_SKIP (); + } + auto path (nano::unique_path () / "data.ldb"); + nano::logger_mt logger; + nano::stats stats; + { + nano::store::lmdb::component store (logger, path, nano::dev::constants); + nano::ledger ledger (store, stats, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + store.initialize (transaction, ledger.cache, ledger.constants); + // Delete pruned table + ASSERT_FALSE (mdb_drop (store.env.tx (transaction), store.final_vote_store.final_votes_handle, 1)); + store.version.put (transaction, 20); + } + // Upgrading should create the table + nano::store::lmdb::component store (logger, path, nano::dev::constants); + ASSERT_FALSE (store.init_error ()); + ASSERT_NE (store.final_vote_store.final_votes_handle, 0); - auto path (nano::unique_path () / "data.ldb"); - nano::logger_mt logger; - nano::stats stats; - auto const check_correct_state = [&] () { - nano::lmdb::store store (logger, path, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - ASSERT_EQ (store.version.get (transaction), store.version_current); - MDB_dbi unchecked_handle{ 0 }; - ASSERT_EQ (MDB_NOTFOUND, mdb_dbi_open (store.env.tx (transaction), "unchecked", 0, &unchecked_handle)); - }; + // Version should be correct + auto transaction (store.tx_begin_read ()); + ASSERT_LT (19, store.version.get (transaction)); +} - // Testing current version doesn't contain the unchecked table - check_correct_state (); +TEST (mdb_block_store, upgrade_v21_v22) +{ + if (nano::rocksdb_config::using_rocksdb_in_tests ()) + { + // Don't test this in rocksdb mode + GTEST_SKIP (); + } - // Setting the database to its 21st version state - { - nano::lmdb::store store (logger, path, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - store.version.put (transaction, 21); - MDB_dbi unchecked_handle{ 0 }; - ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "unchecked", MDB_CREATE, &unchecked_handle)); - ASSERT_EQ (store.version.get (transaction), 21); - } + auto path (nano::unique_path () / "data.ldb"); + nano::logger_mt logger; + nano::stats stats; + auto const check_correct_state = [&] () { + nano::store::lmdb::component store (logger, path, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + ASSERT_EQ (store.version.get (transaction), store.version_current); + MDB_dbi unchecked_handle{ 0 }; + ASSERT_EQ (MDB_NOTFOUND, mdb_dbi_open (store.env.tx (transaction), "unchecked", 0, &unchecked_handle)); + }; - // Testing the upgrade code worked - check_correct_state (); + // Testing current version doesn't contain the unchecked table + check_correct_state (); + + // Setting the database to its 21st version state + { + nano::store::lmdb::component store (logger, path, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + store.version.put (transaction, 21); + MDB_dbi unchecked_handle{ 0 }; + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "unchecked", MDB_CREATE, &unchecked_handle)); + ASSERT_EQ (store.version.get (transaction), 21); } + + // Testing the upgrade code worked + check_correct_state (); +} } -namespace rocksdb +namespace nano::store::rocksdb { - TEST (rocksdb_block_store, upgrade_v21_v22) +TEST (rocksdb_block_store, upgrade_v21_v22) +{ + if (!nano::rocksdb_config::using_rocksdb_in_tests ()) { - if (!nano::rocksdb_config::using_rocksdb_in_tests ()) - { - // Don't test this in LMDB mode - GTEST_SKIP (); - } - - auto const path = nano::unique_path () / "rocksdb"; - nano::logger_mt logger; - nano::stats stats; - auto const check_correct_state = [&] () { - nano::rocksdb::store store (logger, path, nano::dev::constants); - auto transaction (store.tx_begin_write ()); - ASSERT_EQ (store.version.get (transaction), store.version_current); - ASSERT_FALSE (store.column_family_exists ("unchecked")); - }; + // Don't test this in LMDB mode + GTEST_SKIP (); + } - // Testing current version doesn't contain the unchecked table - check_correct_state (); + auto const path = nano::unique_path () / "rocksdb"; + nano::logger_mt logger; + nano::stats stats; + auto const check_correct_state = [&] () { + nano::store::rocksdb::component store (logger, path, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + ASSERT_EQ (store.version.get (transaction), store.version_current); + ASSERT_FALSE (store.column_family_exists ("unchecked")); + }; - // Setting the database to its 21st version state - { - nano::rocksdb::store store (logger, path, nano::dev::constants); + // Testing current version doesn't contain the unchecked table + check_correct_state (); - // Create a column family for "unchecked" - ::rocksdb::ColumnFamilyOptions new_cf_options; - ::rocksdb::ColumnFamilyHandle * new_cf_handle; - ::rocksdb::Status status = store.db->CreateColumnFamily (new_cf_options, "unchecked", &new_cf_handle); - store.handles.emplace_back (new_cf_handle); + // Setting the database to its 21st version state + { + nano::store::rocksdb::component store (logger, path, nano::dev::constants); - // The new column family was created successfully, and 'new_cf_handle' now points to it. - ASSERT_TRUE (status.ok ()); + // Create a column family for "unchecked" + ::rocksdb::ColumnFamilyOptions new_cf_options; + ::rocksdb::ColumnFamilyHandle * new_cf_handle; + ::rocksdb::Status status = store.db->CreateColumnFamily (new_cf_options, "unchecked", &new_cf_handle); + store.handles.emplace_back (new_cf_handle); - // Rollback the database version number. - auto transaction (store.tx_begin_write ()); - store.version.put (transaction, 21); - ASSERT_EQ (store.version.get (transaction), 21); - } + // The new column family was created successfully, and 'new_cf_handle' now points to it. + ASSERT_TRUE (status.ok ()); - // Testing the upgrade code worked - check_correct_state (); + // Rollback the database version number. + auto transaction (store.tx_begin_write ()); + store.version.put (transaction, 21); + ASSERT_EQ (store.version.get (transaction), 21); } + + // Testing the upgrade code worked + check_correct_state (); } } @@ -2289,7 +2282,7 @@ TEST (mdb_block_store, upgrade_backup) { nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants); + nano::store::lmdb::component store (logger, path, nano::dev::constants); auto transaction (store.tx_begin_write ()); store.version.put (transaction, 14); } @@ -2297,7 +2290,7 @@ TEST (mdb_block_store, upgrade_backup) // Now do the upgrade and confirm that backup is saved nano::logger_mt logger; - nano::lmdb::store store (logger, path, nano::dev::constants, nano::txn_tracking_config{}, std::chrono::seconds (5), nano::lmdb_config{}, true); + nano::store::lmdb::component store (logger, path, nano::dev::constants, nano::txn_tracking_config{}, std::chrono::seconds (5), nano::lmdb_config{}, true); ASSERT_FALSE (store.init_error ()); auto transaction (store.tx_begin_read ()); ASSERT_LT (14, store.version.get (transaction)); @@ -2455,10 +2448,10 @@ TEST (block_store, rocksdb_force_test_env_variable) auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants); - auto mdb_cast = dynamic_cast (store.get ()); + auto mdb_cast = dynamic_cast (store.get ()); if (value && boost::lexical_cast (value) == 1) { - ASSERT_NE (boost::polymorphic_downcast (store.get ()), nullptr); + ASSERT_NE (boost::polymorphic_downcast (store.get ()), nullptr); } else { @@ -2478,7 +2471,7 @@ TEST (rocksdb_block_store, tombstone_count) } nano::test::system system; nano::logger_mt logger; - auto store = std::make_unique (logger, nano::unique_path () / "rocksdb", nano::dev::constants); + auto store = std::make_unique (logger, nano::unique_path () / "rocksdb", nano::dev::constants); ASSERT_TRUE (!store->init_error ()); nano::block_builder builder; auto block = builder @@ -2492,7 +2485,7 @@ TEST (rocksdb_block_store, tombstone_count) // Enqueues a block to be saved in the database nano::account account{ 1 }; store->account.put (store->tx_begin_write (), account, nano::account_info{}); - auto check_block_is_listed = [&] (nano::transaction const & transaction_a) { + auto check_block_is_listed = [&] (store::transaction const & transaction_a) { return store->account.exists (transaction_a, account); }; // Waits for the block to get saved @@ -2504,78 +2497,75 @@ TEST (rocksdb_block_store, tombstone_count) } } -namespace nano +namespace nano::store::lmdb { -namespace lmdb +void write_sideband_v14 (nano::store::lmdb::component & store_a, store::transaction & transaction_a, nano::block const & block_a, MDB_dbi db_a) { - void write_sideband_v14 (nano::lmdb::store & store_a, nano::transaction & transaction_a, nano::block const & block_a, MDB_dbi db_a) - { - auto block = store_a.block.get (transaction_a, block_a.hash ()); - ASSERT_NE (block, nullptr); + auto block = store_a.block.get (transaction_a, block_a.hash ()); + ASSERT_NE (block, nullptr); - nano::block_sideband_v14 sideband_v14 (block->type (), block->sideband ().account, block->sideband ().successor, block->sideband ().balance, block->sideband ().timestamp, block->sideband ().height); - std::vector data; - { - nano::vectorstream stream (data); - block_a.serialize (stream); - sideband_v14.serialize (stream); - } - - MDB_val val{ data.size (), data.data () }; - ASSERT_FALSE (mdb_put (store_a.env.tx (transaction_a), block->sideband ().details.epoch == nano::epoch::epoch_0 ? store_a.block_store.state_blocks_v0_handle : store_a.block_store.state_blocks_v1_handle, nano::mdb_val (block_a.hash ()), &val, 0)); - } - - void write_sideband_v15 (nano::lmdb::store & store_a, nano::transaction & transaction_a, nano::block const & block_a) + nano::store::block_sideband_v14 sideband_v14 (block->type (), block->sideband ().account, block->sideband ().successor, block->sideband ().balance, block->sideband ().timestamp, block->sideband ().height); + std::vector data; { - auto block = store_a.block.get (transaction_a, block_a.hash ()); - ASSERT_NE (block, nullptr); + nano::vectorstream stream (data); + block_a.serialize (stream); + sideband_v14.serialize (stream); + } - ASSERT_LE (block->sideband ().details.epoch, nano::epoch::max); - // Simulated by writing 0 on every of the most significant bits, leaving out epoch only, as if pre-upgrade - nano::block_sideband_v18 sideband_v15 (block->sideband ().account, block->sideband ().successor, block->sideband ().balance, block->sideband ().timestamp, block->sideband ().height, block->sideband ().details.epoch, false, false, false); - std::vector data; - { - nano::vectorstream stream (data); - block_a.serialize (stream); - sideband_v15.serialize (stream, block_a.type ()); - } + MDB_val val{ data.size (), data.data () }; + ASSERT_FALSE (mdb_put (store_a.env.tx (transaction_a), block->sideband ().details.epoch == nano::epoch::epoch_0 ? store_a.block_store.state_blocks_v0_handle : store_a.block_store.state_blocks_v1_handle, nano::store::lmdb::db_val (block_a.hash ()), &val, 0)); +} - MDB_val val{ data.size (), data.data () }; - ASSERT_FALSE (mdb_put (store_a.env.tx (transaction_a), store_a.block_store.state_blocks_handle, nano::mdb_val (block_a.hash ()), &val, 0)); - } +void write_sideband_v15 (nano::store::lmdb::component & store_a, store::transaction & transaction_a, nano::block const & block_a) +{ + auto block = store_a.block.get (transaction_a, block_a.hash ()); + ASSERT_NE (block, nullptr); - void write_block_w_sideband_v18 (nano::lmdb::store & store_a, MDB_dbi database, nano::write_transaction & transaction_a, nano::block const & block_a) + ASSERT_LE (block->sideband ().details.epoch, nano::epoch::max); + // Simulated by writing 0 on every of the most significant bits, leaving out epoch only, as if pre-upgrade + nano::store::block_sideband_v18 sideband_v15 (block->sideband ().account, block->sideband ().successor, block->sideband ().balance, block->sideband ().timestamp, block->sideband ().height, block->sideband ().details.epoch, false, false, false); + std::vector data; { - auto block = store_a.block.get (transaction_a, block_a.hash ()); - ASSERT_NE (block, nullptr); - auto new_sideband (block->sideband ()); - nano::block_sideband_v18 sideband_v18 (new_sideband.account, new_sideband.successor, new_sideband.balance, new_sideband.height, new_sideband.timestamp, new_sideband.details.epoch, new_sideband.details.is_send, new_sideband.details.is_receive, new_sideband.details.is_epoch); + nano::vectorstream stream (data); + block_a.serialize (stream); + sideband_v15.serialize (stream, block_a.type ()); + } - std::vector data; - { - nano::vectorstream stream (data); - block->serialize (stream); - sideband_v18.serialize (stream, block->type ()); - } + MDB_val val{ data.size (), data.data () }; + ASSERT_FALSE (mdb_put (store_a.env.tx (transaction_a), store_a.block_store.state_blocks_handle, nano::store::lmdb::db_val (block_a.hash ()), &val, 0)); +} - MDB_val val{ data.size (), data.data () }; - ASSERT_FALSE (mdb_put (store_a.env.tx (transaction_a), database, nano::mdb_val (block_a.hash ()), &val, 0)); - store_a.del (transaction_a, nano::tables::blocks, nano::mdb_val (block_a.hash ())); - } +void write_block_w_sideband_v18 (nano::store::lmdb::component & store_a, MDB_dbi database, store::write_transaction & transaction_a, nano::block const & block_a) +{ + auto block = store_a.block.get (transaction_a, block_a.hash ()); + ASSERT_NE (block, nullptr); + auto new_sideband (block->sideband ()); + nano::store::block_sideband_v18 sideband_v18 (new_sideband.account, new_sideband.successor, new_sideband.balance, new_sideband.height, new_sideband.timestamp, new_sideband.details.epoch, new_sideband.details.is_send, new_sideband.details.is_receive, new_sideband.details.is_epoch); - void modify_account_info_to_v14 (nano::lmdb::store & store, nano::transaction const & transaction, nano::account const & account, uint64_t confirmation_height, nano::block_hash const & rep_block) + std::vector data; { - nano::account_info info; - ASSERT_FALSE (store.account.get (transaction, account, info)); - nano::account_info_v14 account_info_v14 (info.head, rep_block, info.open_block, info.balance, info.modified, info.block_count, confirmation_height, info.epoch ()); - auto status (mdb_put (store.env.tx (transaction), info.epoch () == nano::epoch::epoch_0 ? store.account_store.accounts_v0_handle : store.account_store.accounts_v1_handle, nano::mdb_val (account), nano::mdb_val (account_info_v14), 0)); - ASSERT_EQ (status, 0); + nano::vectorstream stream (data); + block->serialize (stream); + sideband_v18.serialize (stream, block->type ()); } - 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_store.confirmation_height_handle, nano::mdb_val (account), nano::mdb_val (confirmation_height), 0)); - ASSERT_EQ (status, 0); - } + MDB_val val{ data.size (), data.data () }; + ASSERT_FALSE (mdb_put (store_a.env.tx (transaction_a), database, nano::store::lmdb::db_val (block_a.hash ()), &val, 0)); + store_a.del (transaction_a, nano::tables::blocks, nano::store::lmdb::db_val (block_a.hash ())); +} + +void modify_account_info_to_v14 (nano::store::lmdb::component & store, store::transaction const & transaction, nano::account const & account, uint64_t confirmation_height, nano::block_hash const & rep_block) +{ + nano::account_info info; + ASSERT_FALSE (store.account.get (transaction, account, info)); + nano::store::account_info_v14 account_info_v14 (info.head, rep_block, info.open_block, info.balance, info.modified, info.block_count, confirmation_height, info.epoch ()); + auto status (mdb_put (store.env.tx (transaction), info.epoch () == nano::epoch::epoch_0 ? store.account_store.accounts_v0_handle : store.account_store.accounts_v1_handle, nano::store::lmdb::db_val (account), nano::store::lmdb::db_val (account_info_v14), 0)); + ASSERT_EQ (status, 0); +} + +void modify_confirmation_height_to_v15 (nano::store::lmdb::component & store, store::transaction const & transaction, nano::account const & account, uint64_t confirmation_height) +{ + auto status (mdb_put (store.env.tx (transaction), store.confirmation_height_store.confirmation_height_handle, nano::store::lmdb::db_val (account), nano::store::lmdb::db_val (confirmation_height), 0)); + ASSERT_EQ (status, 0); } } diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index c78a579fc8..7a014447ef 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -391,7 +391,7 @@ TEST (confirmation_height, gap_bootstrap) // Receive 2 comes in on the live network, however the chain has not been finished so it gets added to unchecked node1.process_active (receive2); // Waits for the unchecked_map to process the 4 blocks added to the block_processor, saving them in the unchecked table - auto check_block_is_listed = [&] (nano::transaction const & transaction_a, nano::block_hash const & block_hash_a) { + auto check_block_is_listed = [&] (nano::store::transaction const & transaction_a, nano::block_hash const & block_hash_a) { return !node1.unchecked.get (block_hash_a).empty (); }; ASSERT_TIMELY (5s, check_block_is_listed (node1.store.tx_begin_read (), receive2->previous ())); diff --git a/nano/core_test/gap_cache.cpp b/nano/core_test/gap_cache.cpp index e0554f61ab..70e1b0ac94 100644 --- a/nano/core_test/gap_cache.cpp +++ b/nano/core_test/gap_cache.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index ecfbe22751..b2d08ba9cf 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -4495,7 +4495,7 @@ TEST (ledger, unchecked_receive) node1.work_generate_blocking (*receive1); node1.block_processor.add (send1); node1.block_processor.add (receive1); - auto check_block_is_listed = [&] (nano::transaction const & transaction_a, nano::block_hash const & block_hash_a) { + auto check_block_is_listed = [&] (nano::store::transaction const & transaction_a, nano::block_hash const & block_hash_a) { return !node1.unchecked.get (block_hash_a).empty (); }; // Previous block for receive1 is unknown, signature cannot be validated @@ -5543,7 +5543,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb) nano::logger_mt logger{}; boost::asio::ip::address_v6 address (boost::asio::ip::make_address_v6 ("::ffff:127.0.0.1")); uint16_t port = 100; - nano::lmdb::store store{ logger, path / "data.ldb", nano::dev::constants }; + nano::store::lmdb::component store{ logger, path / "data.ldb", nano::dev::constants }; nano::ledger ledger{ store, system.stats, nano::dev::constants }; nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; @@ -5583,7 +5583,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb) auto error = ledger.migrate_lmdb_to_rocksdb (path); ASSERT_FALSE (error); - nano::rocksdb::store rocksdb_store{ logger, path / "rocksdb", nano::dev::constants }; + nano::store::rocksdb::component rocksdb_store{ logger, path / "rocksdb", nano::dev::constants }; auto rocksdb_transaction (rocksdb_store.tx_begin_read ()); nano::pending_info pending_info{}; diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index ef50e24088..6aad11bc15 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -15,7 +15,7 @@ unsigned constexpr nano::wallet_store::version_current; TEST (wallet, no_special_keys_accounts) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -36,7 +36,7 @@ TEST (wallet, no_special_keys_accounts) TEST (wallet, no_key) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -51,7 +51,7 @@ TEST (wallet, no_key) TEST (wallet, fetch_locked) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -73,7 +73,7 @@ TEST (wallet, fetch_locked) TEST (wallet, retrieval) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -95,7 +95,7 @@ TEST (wallet, retrieval) TEST (wallet, empty_iteration) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -109,7 +109,7 @@ TEST (wallet, empty_iteration) TEST (wallet, one_item_iteration) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -131,7 +131,7 @@ TEST (wallet, one_item_iteration) TEST (wallet, two_item_iteration) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); nano::keypair key1; nano::keypair key2; @@ -270,7 +270,7 @@ TEST (wallet, spend_no_previous) TEST (wallet, find_none) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -283,7 +283,7 @@ TEST (wallet, find_none) TEST (wallet, find_existing) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -302,7 +302,7 @@ TEST (wallet, find_existing) TEST (wallet, rekey) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -374,7 +374,7 @@ TEST (account, encode_fail) TEST (wallet, hash_password) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -423,7 +423,7 @@ TEST (fan, change) TEST (wallet, reopen_default_password) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); auto transaction (env.tx_begin_write ()); ASSERT_FALSE (init); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -459,7 +459,7 @@ TEST (wallet, reopen_default_password) TEST (wallet, representative) { auto error (false); - nano::mdb_env env (error, nano::unique_path ()); + nano::store::lmdb::env env (error, nano::unique_path ()); ASSERT_FALSE (error); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -480,7 +480,7 @@ TEST (wallet, representative) TEST (wallet, serialize_json_empty) { auto error (false); - nano::mdb_env env (error, nano::unique_path ()); + nano::store::lmdb::env env (error, nano::unique_path ()); ASSERT_FALSE (error); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -505,7 +505,7 @@ TEST (wallet, serialize_json_empty) TEST (wallet, serialize_json_one) { auto error (false); - nano::mdb_env env (error, nano::unique_path ()); + nano::store::lmdb::env env (error, nano::unique_path ()); ASSERT_FALSE (error); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -534,7 +534,7 @@ TEST (wallet, serialize_json_one) TEST (wallet, serialize_json_password) { auto error (false); - nano::mdb_env env (error, nano::unique_path ()); + nano::store::lmdb::env env (error, nano::unique_path ()); ASSERT_FALSE (error); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -567,7 +567,7 @@ TEST (wallet, serialize_json_password) TEST (wallet_store, move) { auto error (false); - nano::mdb_env env (error, nano::unique_path ()); + nano::store::lmdb::env env (error, nano::unique_path ()); ASSERT_FALSE (error); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -725,7 +725,7 @@ TEST (wallet, insert_locked) TEST (wallet, deterministic_keys) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; @@ -768,7 +768,7 @@ TEST (wallet, deterministic_keys) TEST (wallet, reseed) { bool init; - nano::mdb_env env (init, nano::unique_path ()); + nano::store::lmdb::env env (init, nano::unique_path ()); ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index ae1dcb795f..ab21ab03c5 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -308,7 +308,7 @@ int main (int argc, char * const * argv) for (; i != end; ++i) { nano::block_hash hash = i->first; - nano::block_w_sideband sideband = i->second; + nano::store::block_w_sideband sideband = i->second; std::shared_ptr b = sideband.block; std::cout << hash.to_string () << std::endl << b->to_json (); @@ -1408,7 +1408,7 @@ int main (int argc, char * const * argv) } }; - auto check_account = [&print_error_message, &silent, &count, &block_count] (std::shared_ptr const & node, nano::read_transaction const & transaction, nano::account const & account, nano::account_info const & info) { + auto check_account = [&print_error_message, &silent, &count, &block_count] (std::shared_ptr const & node, nano::store::read_transaction const & transaction, nano::account const & account, nano::account_info const & info) { ++count; if (!silent && (count % 20000) == 0) { @@ -1682,7 +1682,7 @@ int main (int argc, char * const * argv) finished = false; std::deque> pending; - auto check_pending = [&print_error_message, &silent, &count] (std::shared_ptr const & node, nano::read_transaction const & transaction, nano::pending_key const & key, nano::pending_info const & info) { + auto check_pending = [&print_error_message, &silent, &count] (std::shared_ptr const & node, nano::store::read_transaction const & transaction, nano::pending_key const & key, nano::pending_info const & info) { ++count; if (!silent && (count % 500000) == 0) { @@ -1916,7 +1916,7 @@ int main (int argc, char * const * argv) nano::locked>> opened_account_versions_shared (epoch_count); using opened_account_versions_t = decltype (opened_account_versions_shared)::value_type; node->store.account.for_each_par ( - [&opened_account_versions_shared, epoch_count] (nano::read_transaction const & /*unused*/, nano::store_iterator i, nano::store_iterator n) { + [&opened_account_versions_shared, epoch_count] (nano::store::read_transaction const & /*unused*/, nano::store::iterator i, nano::store::iterator n) { // First cache locally opened_account_versions_t opened_account_versions_l (epoch_count); for (; i != n; ++i) @@ -1953,7 +1953,7 @@ int main (int argc, char * const * argv) nano::locked>> unopened_highest_pending_shared; using unopened_highest_pending_t = decltype (unopened_highest_pending_shared)::value_type; node->store.pending.for_each_par ( - [&unopened_highest_pending_shared, &opened_accounts] (nano::read_transaction const & /*unused*/, nano::store_iterator i, nano::store_iterator n) { + [&unopened_highest_pending_shared, &opened_accounts] (nano::store::read_transaction const & /*unused*/, nano::store::iterator i, nano::store::iterator n) { // First cache locally unopened_highest_pending_t unopened_highest_pending_l; for (; i != n; ++i) diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index cab66d9acf..05972cdc66 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -624,7 +624,7 @@ bool nano::active_transactions::publish (std::shared_ptr const & bl } // Returns the type of election status requiring callbacks calling later -boost::optional nano::active_transactions::confirm_block (nano::transaction const & transaction_a, std::shared_ptr const & block_a) +boost::optional nano::active_transactions::confirm_block (store::transaction const & transaction_a, std::shared_ptr const & block_a) { auto const hash = block_a->hash (); std::shared_ptr election = nullptr; diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 865da63be0..2b598e2b00 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -161,7 +161,7 @@ class active_transactions final bool empty () const; std::size_t size () const; bool publish (std::shared_ptr const &); - boost::optional confirm_block (nano::transaction const &, std::shared_ptr const &); + boost::optional confirm_block (store::transaction const &, std::shared_ptr const &); void block_cemented_callback (std::shared_ptr const &); void block_already_cemented_callback (nano::block_hash const &); diff --git a/nano/node/backlog_population.cpp b/nano/node/backlog_population.cpp index 3ab5a939a2..0aac0b0392 100644 --- a/nano/node/backlog_population.cpp +++ b/nano/node/backlog_population.cpp @@ -111,7 +111,7 @@ void nano::backlog_population::populate_backlog (nano::unique_lock } } -void nano::backlog_population::activate (nano::transaction const & transaction, nano::account const & account) +void nano::backlog_population::activate (store::transaction const & transaction, nano::account const & account) { debug_assert (!activate_callback.empty ()); diff --git a/nano/node/backlog_population.hpp b/nano/node/backlog_population.hpp index 7d678dd1a5..842ac98dbc 100644 --- a/nano/node/backlog_population.hpp +++ b/nano/node/backlog_population.hpp @@ -9,13 +9,14 @@ #include #include +namespace nano::store +{ +class component; +class transaction; +} namespace nano { class stats; -namespace store -{ - class component; -} class election_scheduler; class backlog_population final @@ -33,7 +34,7 @@ class backlog_population final unsigned frequency; }; - backlog_population (const config &, nano::store::component &, nano::stats &); + backlog_population (const config &, store::component &, nano::stats &); ~backlog_population (); void start (); @@ -49,7 +50,7 @@ class backlog_population final /** * Callback called for each backlogged account */ - using callback_t = nano::observer_set; + using callback_t = nano::observer_set; callback_t activate_callback; private: // Dependencies @@ -63,7 +64,7 @@ class backlog_population final bool predicate () const; void populate_backlog (nano::unique_lock & lock); - void activate (nano::transaction const &, nano::account const &); + void activate (store::transaction const &, nano::account const &); /** This is a manual trigger, the ongoing backlog population does not use this. * It can be triggered even when backlog population (frontiers confirmation) is disabled. */ diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 9a844337c8..5fc10808dd 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -121,7 +121,7 @@ std::optional nano::block_processor::add_blocking (std::sh return result; } -void nano::block_processor::rollback_competitor (nano::write_transaction const & transaction, nano::block const & block) +void nano::block_processor::rollback_competitor (store::write_transaction const & transaction, nano::block const & block) { auto hash = block.hash (); auto successor = node.ledger.successor (transaction, block.qualified_root ()); @@ -314,7 +314,7 @@ auto nano::block_processor::process_batch (nano::unique_lock & lock return processed; } -nano::process_return nano::block_processor::process_one (nano::write_transaction const & transaction_a, std::shared_ptr block, bool const forced_a) +nano::process_return nano::block_processor::process_one (store::write_transaction const & transaction_a, std::shared_ptr block, bool const forced_a) { nano::process_return result; auto hash (block->hash ()); @@ -460,7 +460,7 @@ nano::process_return nano::block_processor::process_one (nano::write_transaction return result; } -void nano::block_processor::queue_unchecked (nano::write_transaction const & transaction_a, nano::hash_or_account const & hash_or_account_a) +void nano::block_processor::queue_unchecked (store::write_transaction const & transaction_a, nano::hash_or_account const & hash_or_account_a) { node.unchecked.trigger (hash_or_account_a); node.gap_cache.erase (hash_or_account_a.hash); diff --git a/nano/node/blockprocessor.hpp b/nano/node/blockprocessor.hpp index 1a8c84c48d..5c2c6b9cbf 100644 --- a/nano/node/blockprocessor.hpp +++ b/nano/node/blockprocessor.hpp @@ -10,6 +10,11 @@ #include #include +namespace nano::store +{ +class write_transaction; +} + namespace nano { class node; @@ -53,9 +58,9 @@ class block_processor final private: // Roll back block in the ledger that conflicts with 'block' - void rollback_competitor (nano::write_transaction const & transaction, nano::block const & block); - nano::process_return process_one (nano::write_transaction const &, std::shared_ptr block, bool const = false); - void queue_unchecked (nano::write_transaction const &, nano::hash_or_account const &); + void rollback_competitor (store::write_transaction const & transaction, nano::block const & block); + nano::process_return process_one (store::write_transaction const &, std::shared_ptr block, bool const = false); + void queue_unchecked (store::write_transaction const &, nano::hash_or_account const &); std::deque process_batch (nano::unique_lock &); void process_verified_state_blocks (std::deque &, std::vector const &, std::vector const &, std::vector const &); void add_impl (std::shared_ptr block); diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 67b43f9042..f0d5004d1d 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -166,7 +166,7 @@ bool nano::bootstrap_initiator::in_progress () return !attempts_list.empty (); } -void nano::bootstrap_initiator::block_processed (nano::transaction const & tx, nano::process_return const & result, nano::block const & block) +void nano::bootstrap_initiator::block_processed (store::transaction const & tx, nano::process_return const & result, nano::block const & block) { nano::lock_guard lock{ mutex }; for (auto & i : attempts_list) diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 5b6f62ef36..016cf547aa 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -14,6 +14,11 @@ namespace mi = boost::multi_index; +namespace nano::store +{ +class transaction; +} + namespace nano { class node; @@ -101,7 +106,7 @@ class bootstrap_initiator final void notify_listeners (bool); void add_observer (std::function const &); bool in_progress (); - void block_processed (nano::transaction const & tx, nano::process_return const & result, nano::block const & block); + void block_processed (store::transaction const & tx, nano::process_return const & result, nano::block const & block); std::shared_ptr connections; std::shared_ptr new_attempt (); bool has_new_attempts (); diff --git a/nano/node/bootstrap/bootstrap_attempt.cpp b/nano/node/bootstrap/bootstrap_attempt.cpp index 8924da58d7..4656ad5f4f 100644 --- a/nano/node/bootstrap/bootstrap_attempt.cpp +++ b/nano/node/bootstrap/bootstrap_attempt.cpp @@ -135,6 +135,6 @@ bool nano::bootstrap_attempt::process_block (std::shared_ptr const return stop_pull; } -void nano::bootstrap_attempt::block_processed (nano::transaction const & tx, nano::process_return const & result, nano::block const & block) +void nano::bootstrap_attempt::block_processed (store::transaction const & tx, nano::process_return const & result, nano::block const & block) { } diff --git a/nano/node/bootstrap/bootstrap_attempt.hpp b/nano/node/bootstrap/bootstrap_attempt.hpp index fca94ac62d..fa9ed15e61 100644 --- a/nano/node/bootstrap/bootstrap_attempt.hpp +++ b/nano/node/bootstrap/bootstrap_attempt.hpp @@ -5,6 +5,11 @@ #include #include +namespace nano::store +{ +class transaction; +} + namespace nano { class node; @@ -29,7 +34,7 @@ class bootstrap_attempt : public std::enable_shared_from_this char const * mode_text (); virtual bool process_block (std::shared_ptr const &, nano::account const &, uint64_t, nano::bulk_pull::count_t, bool, unsigned); virtual void get_information (boost::property_tree::ptree &) = 0; - virtual void block_processed (nano::transaction const & tx, nano::process_return const & result, nano::block const & block); + virtual void block_processed (store::transaction const & tx, nano::process_return const & result, nano::block const & block); nano::mutex next_log_mutex; std::chrono::steady_clock::time_point next_log{ std::chrono::steady_clock::now () }; std::atomic pulling{ 0 }; diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index 8af9bfe1e6..5c0daa4602 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -796,7 +796,7 @@ std::pair, std::unique_ptrstore.tx_begin_read ()); auto stream (node->store.pending.begin (stream_transaction, current_key)); - if (stream == nano::store_iterator (nullptr)) + if (stream == store::iterator (nullptr)) { break; } diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index bb6dcf3000..5bfc959220 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -152,12 +152,12 @@ void nano::bootstrap_server::process_batch (std::deque & batch) } } -nano::asc_pull_ack nano::bootstrap_server::process (nano::transaction const & transaction, const nano::asc_pull_req & message) +nano::asc_pull_ack nano::bootstrap_server::process (store::transaction const & transaction, const nano::asc_pull_req & message) { return std::visit ([this, &transaction, &message] (auto && request) { return process (transaction, message.id, request); }, message.payload); } -nano::asc_pull_ack nano::bootstrap_server::process (const nano::transaction &, nano::asc_pull_req::id_t id, const nano::empty_payload & request) +nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction &, nano::asc_pull_req::id_t id, const nano::empty_payload & request) { // Empty payload should never be possible, but return empty response anyway debug_assert (false, "missing payload"); @@ -171,7 +171,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (const nano::transaction &, n * Blocks response */ -nano::asc_pull_ack nano::bootstrap_server::process (nano::transaction const & transaction, nano::asc_pull_req::id_t id, nano::asc_pull_req::blocks_payload const & request) +nano::asc_pull_ack nano::bootstrap_server::process (store::transaction const & transaction, nano::asc_pull_req::id_t id, nano::asc_pull_req::blocks_payload const & request) { const std::size_t count = std::min (static_cast (request.count), max_blocks); @@ -201,7 +201,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (nano::transaction const & tr return prepare_empty_blocks_response (id); } -nano::asc_pull_ack nano::bootstrap_server::prepare_response (nano::transaction const & transaction, nano::asc_pull_req::id_t id, nano::block_hash start_block, std::size_t count) +nano::asc_pull_ack nano::bootstrap_server::prepare_response (store::transaction const & transaction, nano::asc_pull_req::id_t id, nano::block_hash start_block, std::size_t count) { debug_assert (count <= max_blocks); @@ -233,7 +233,7 @@ nano::asc_pull_ack nano::bootstrap_server::prepare_empty_blocks_response (nano:: return response; } -std::vector> nano::bootstrap_server::prepare_blocks (nano::transaction const & transaction, nano::block_hash start_block, std::size_t count) const +std::vector> nano::bootstrap_server::prepare_blocks (store::transaction const & transaction, nano::block_hash start_block, std::size_t count) const { debug_assert (count <= max_blocks); @@ -256,7 +256,7 @@ std::vector> nano::bootstrap_server::prepare_blocks * Account info response */ -nano::asc_pull_ack nano::bootstrap_server::process (const nano::transaction & transaction, nano::asc_pull_req::id_t id, const nano::asc_pull_req::account_info_payload & request) +nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction & transaction, nano::asc_pull_req::id_t id, const nano::asc_pull_req::account_info_payload & request) { nano::asc_pull_ack response{ network_constants }; response.id = id; diff --git a/nano/node/bootstrap/bootstrap_server.hpp b/nano/node/bootstrap/bootstrap_server.hpp index 2958e16332..98fd3823f9 100644 --- a/nano/node/bootstrap/bootstrap_server.hpp +++ b/nano/node/bootstrap/bootstrap_server.hpp @@ -7,6 +7,11 @@ #include #include +namespace nano::store +{ +class transaction; +} + namespace nano { class ledger; @@ -46,23 +51,23 @@ class bootstrap_server final private: void process_batch (std::deque & batch); - nano::asc_pull_ack process (nano::transaction const &, nano::asc_pull_req const & message); + nano::asc_pull_ack process (store::transaction const &, nano::asc_pull_req const & message); void respond (nano::asc_pull_ack &, std::shared_ptr &); - nano::asc_pull_ack process (nano::transaction const &, nano::asc_pull_req::id_t id, nano::empty_payload const & request); + nano::asc_pull_ack process (store::transaction const &, nano::asc_pull_req::id_t id, nano::empty_payload const & request); /* * Blocks response */ - nano::asc_pull_ack process (nano::transaction const &, nano::asc_pull_req::id_t id, nano::asc_pull_req::blocks_payload const & request); - nano::asc_pull_ack prepare_response (nano::transaction const &, nano::asc_pull_req::id_t id, nano::block_hash start_block, std::size_t count); + nano::asc_pull_ack process (store::transaction const &, nano::asc_pull_req::id_t id, nano::asc_pull_req::blocks_payload const & request); + nano::asc_pull_ack prepare_response (store::transaction const &, nano::asc_pull_req::id_t id, nano::block_hash start_block, std::size_t count); nano::asc_pull_ack prepare_empty_blocks_response (nano::asc_pull_req::id_t id); - std::vector> prepare_blocks (nano::transaction const &, nano::block_hash start_block, std::size_t count) const; + std::vector> prepare_blocks (store::transaction const &, nano::block_hash start_block, std::size_t count) const; /* * Account info response */ - nano::asc_pull_ack process (nano::transaction const &, nano::asc_pull_req::id_t id, nano::asc_pull_req::account_info_payload const & request); + nano::asc_pull_ack process (store::transaction const &, nano::asc_pull_req::id_t id, nano::asc_pull_req::account_info_payload const & request); /* * Checks if the request should be dropped early on diff --git a/nano/node/bootstrap_ascending/iterators.cpp b/nano/node/bootstrap_ascending/iterators.cpp index 9f29f98bd8..d35c682567 100644 --- a/nano/node/bootstrap_ascending/iterators.cpp +++ b/nano/node/bootstrap_ascending/iterators.cpp @@ -20,7 +20,7 @@ nano::account nano::bootstrap_ascending::database_iterator::operator* () const return current; } -void nano::bootstrap_ascending::database_iterator::next (nano::transaction & tx) +void nano::bootstrap_ascending::database_iterator::next (store::transaction & tx) { switch (table) { diff --git a/nano/node/bootstrap_ascending/iterators.hpp b/nano/node/bootstrap_ascending/iterators.hpp index 82fdb60b15..58d7c6c690 100644 --- a/nano/node/bootstrap_ascending/iterators.hpp +++ b/nano/node/bootstrap_ascending/iterators.hpp @@ -4,56 +4,53 @@ #include -namespace nano +namespace nano::store { -namespace store -{ - class component; -} +class component; class transaction; +} -namespace bootstrap_ascending +namespace nano::bootstrap_ascending { - class database_iterator +class database_iterator +{ +public: + enum class table_type { - public: - enum class table_type - { - account, - pending - }; - - explicit database_iterator (nano::store::component & store, table_type); - nano::account operator* () const; - void next (nano::transaction & tx); - - private: - nano::store::component & store; - nano::account current{ 0 }; - const table_type table; + account, + pending }; - class buffered_iterator - { - public: - explicit buffered_iterator (nano::store::component & store); - nano::account operator* () const; - nano::account next (); - // Indicates if a full ledger iteration has taken place e.g. warmed up - bool warmup () const; + explicit database_iterator (nano::store::component & store, table_type); + nano::account operator* () const; + void next (nano::store::transaction & tx); - private: - void fill (); +private: + nano::store::component & store; + nano::account current{ 0 }; + const table_type table; +}; - private: - nano::store::component & store; - std::deque buffer; - bool warmup_m{ true }; - - database_iterator accounts_iterator; - database_iterator pending_iterator; - - static std::size_t constexpr size = 1024; - }; -} // nano -} // bootstrap_ascending +class buffered_iterator +{ +public: + explicit buffered_iterator (nano::store::component & store); + nano::account operator* () const; + nano::account next (); + // Indicates if a full ledger iteration has taken place e.g. warmed up + bool warmup () const; + +private: + void fill (); + +private: + nano::store::component & store; + std::deque buffer; + bool warmup_m{ true }; + + database_iterator accounts_iterator; + database_iterator pending_iterator; + + static std::size_t constexpr size = 1024; +}; +} // nano::bootstrap_ascending diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index e7d2117931..52b9b317b9 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -125,7 +125,7 @@ std::size_t nano::bootstrap_ascending::service::score_size () const - Marks an account as blocked if the result code is gap source as there is no reason request additional blocks for this account until the dependency is resolved - Marks an account as forwarded if it has been recently referenced by a block that has been inserted. */ -void nano::bootstrap_ascending::service::inspect (nano::transaction const & tx, nano::process_return const & result, nano::block const & block) +void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, nano::process_return const & result, nano::block const & block) { auto const hash = block.hash (); diff --git a/nano/node/bootstrap_ascending/service.hpp b/nano/node/bootstrap_ascending/service.hpp index 0da4ee6dee..0a83f3c9cf 100644 --- a/nano/node/bootstrap_ascending/service.hpp +++ b/nano/node/bootstrap_ascending/service.hpp @@ -89,7 +89,7 @@ namespace bootstrap_ascending private: /* Inspects a block that has been processed by the block processor */ - void inspect (nano::transaction const &, nano::process_return const & result, nano::block const & block); + void inspect (store::transaction const &, nano::process_return const & result, nano::block const & block); void throttle_if_needed (nano::unique_lock & lock); void run (); diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 0f9979d40c..b3b63447ed 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -11,7 +11,7 @@ namespace { -void reset_confirmation_heights (nano::write_transaction const & transaction, nano::ledger_constants & constants, nano::store::component & store); +void reset_confirmation_heights (nano::store::write_transaction const & transaction, nano::ledger_constants & constants, nano::store::component & store); bool is_using_rocksdb (boost::filesystem::path const & data_path, boost::program_options::variables_map const & vm, std::error_code & ec); } @@ -1316,7 +1316,7 @@ std::unique_ptr nano::default_inactive_node (boost::filesys namespace { -void reset_confirmation_heights (nano::write_transaction const & transaction, nano::ledger_constants & constants, nano::store::component & store) +void reset_confirmation_heights (nano::store::write_transaction const & transaction, nano::ledger_constants & constants, nano::store::component & store) { // First do a clean sweep store.confirmation_height.clear (transaction); diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index cec0958410..a2301f891d 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -224,7 +224,7 @@ void nano::confirmation_height_bounded::process (std::shared_ptr or debug_assert (checkpoints.empty ()); } -nano::block_hash nano::confirmation_height_bounded::get_least_unconfirmed_hash_from_top_level (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a, uint64_t & block_height_a) +nano::block_hash nano::confirmation_height_bounded::get_least_unconfirmed_hash_from_top_level (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a, uint64_t & block_height_a) { nano::block_hash least_unconfirmed_hash = hash_a; if (confirmation_height_info_a.height != 0) @@ -248,7 +248,7 @@ nano::block_hash nano::confirmation_height_bounded::get_least_unconfirmed_hash_f return least_unconfirmed_hash; } -bool nano::confirmation_height_bounded::iterate (nano::read_transaction const & transaction_a, uint64_t bottom_height_a, nano::block_hash const & bottom_hash_a, boost::circular_buffer_space_optimized & checkpoints_a, nano::block_hash & top_most_non_receive_block_hash_a, nano::block_hash const & top_level_hash_a, boost::circular_buffer_space_optimized & receive_source_pairs_a, nano::account const & account_a) +bool nano::confirmation_height_bounded::iterate (store::read_transaction const & transaction_a, uint64_t bottom_height_a, nano::block_hash const & bottom_hash_a, boost::circular_buffer_space_optimized & checkpoints_a, nano::block_hash & top_most_non_receive_block_hash_a, nano::block_hash const & top_level_hash_a, boost::circular_buffer_space_optimized & receive_source_pairs_a, nano::account const & account_a) { bool reached_target = false; bool hit_receive = false; diff --git a/nano/node/confirmation_height_bounded.hpp b/nano/node/confirmation_height_bounded.hpp index 768f1e73fe..accf2aa34c 100644 --- a/nano/node/confirmation_height_bounded.hpp +++ b/nano/node/confirmation_height_bounded.hpp @@ -90,7 +90,7 @@ class confirmation_height_bounded final class preparation_data final { public: - nano::transaction const & transaction; + store::transaction const & transaction; nano::block_hash const & top_most_non_receive_block_hash; bool already_cemented; boost::circular_buffer_space_optimized & checkpoints; @@ -115,9 +115,9 @@ class confirmation_height_bounded final nano::timer timer; top_and_next_hash get_next_block (boost::optional const &, boost::circular_buffer_space_optimized const &, boost::circular_buffer_space_optimized const & receive_source_pairs, boost::optional &, nano::block const & original_block); - nano::block_hash get_least_unconfirmed_hash_from_top_level (nano::transaction const &, nano::block_hash const &, nano::account const &, nano::confirmation_height_info const &, uint64_t &); + nano::block_hash get_least_unconfirmed_hash_from_top_level (store::transaction const &, nano::block_hash const &, nano::account const &, nano::confirmation_height_info const &, uint64_t &); void prepare_iterated_blocks_for_cementing (preparation_data &); - bool iterate (nano::read_transaction const &, uint64_t, nano::block_hash const &, boost::circular_buffer_space_optimized &, nano::block_hash &, nano::block_hash const &, boost::circular_buffer_space_optimized &, nano::account const &); + bool iterate (store::read_transaction const &, uint64_t, nano::block_hash const &, boost::circular_buffer_space_optimized &, nano::block_hash &, nano::block_hash const &, boost::circular_buffer_space_optimized &, nano::account const &); nano::ledger & ledger; nano::write_database_queue & write_database_queue; diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index e443a96a8f..9a458b9c8c 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -193,7 +193,7 @@ void nano::confirmation_height_unbounded::process (std::shared_ptr } while ((!receive_source_pairs.empty () || current != original_block->hash ()) && !stopped); } -void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_sources_for_account (uint64_t block_height_a, uint64_t confirmation_height_a, std::shared_ptr const & block_a, nano::block_hash const & hash_a, nano::account const & account_a, nano::read_transaction const & transaction_a, std::vector & receive_source_pairs_a, std::vector & block_callback_data_a, std::vector & orig_block_callback_data_a, std::shared_ptr original_block) +void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_sources_for_account (uint64_t block_height_a, uint64_t confirmation_height_a, std::shared_ptr const & block_a, nano::block_hash const & hash_a, nano::account const & account_a, store::read_transaction const & transaction_a, std::vector & receive_source_pairs_a, std::vector & block_callback_data_a, std::vector & orig_block_callback_data_a, std::shared_ptr original_block) { debug_assert (block_a->hash () == hash_a); auto hash (hash_a); @@ -438,7 +438,7 @@ void nano::confirmation_height_unbounded::cement_blocks (nano::write_guard & sco timer.restart (); } -std::shared_ptr nano::confirmation_height_unbounded::get_block_and_sideband (nano::block_hash const & hash_a, nano::transaction const & transaction_a) +std::shared_ptr nano::confirmation_height_unbounded::get_block_and_sideband (nano::block_hash const & hash_a, store::transaction const & transaction_a) { nano::lock_guard guard (block_cache_mutex); auto block_cache_it = block_cache.find (hash_a); diff --git a/nano/node/confirmation_height_unbounded.hpp b/nano/node/confirmation_height_unbounded.hpp index accf34097d..61dbc75598 100644 --- a/nano/node/confirmation_height_unbounded.hpp +++ b/nano/node/confirmation_height_unbounded.hpp @@ -66,7 +66,7 @@ class confirmation_height_unbounded final // This allows the load and stores to use relaxed atomic memory ordering. std::unordered_map confirmed_iterated_pairs; nano::relaxed_atomic_integral confirmed_iterated_pairs_size{ 0 }; - std::shared_ptr get_block_and_sideband (nano::block_hash const &, nano::transaction const &); + std::shared_ptr get_block_and_sideband (nano::block_hash const &, store::transaction const &); std::deque pending_writes; nano::relaxed_atomic_integral pending_writes_size{ 0 }; std::unordered_map> implicit_receive_cemented_mapping; @@ -93,7 +93,7 @@ class confirmation_height_unbounded final std::vector const & orig_block_callback_data; }; - void collect_unconfirmed_receive_and_sources_for_account (uint64_t, uint64_t, std::shared_ptr const &, nano::block_hash const &, nano::account const &, nano::read_transaction const &, std::vector &, std::vector &, std::vector &, std::shared_ptr original_block); + void collect_unconfirmed_receive_and_sources_for_account (uint64_t, uint64_t, std::shared_ptr const &, nano::block_hash const &, nano::account const &, store::read_transaction const &, std::vector &, std::vector &, std::vector &, std::shared_ptr original_block); void prepare_iterated_blocks_for_cementing (preparation_data &); nano::ledger & ledger; diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 738b64ad49..3e6683da74 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -23,7 +23,7 @@ void construct_json (nano::container_info_component * component, boost::property using ipc_json_handler_no_arg_func_map = std::unordered_map>; ipc_json_handler_no_arg_func_map create_ipc_json_handler_no_arg_func_map (); auto ipc_json_handler_no_arg_funcs = create_ipc_json_handler_no_arg_func_map (); -bool block_confirmed (nano::node & node, nano::transaction & transaction, nano::block_hash const & hash, bool include_active, bool include_only_confirmed); +bool block_confirmed (nano::node & node, nano::store::transaction & transaction, nano::block_hash const & hash, bool include_active, bool include_only_confirmed); char const * epoch_as_string (nano::epoch); } @@ -204,7 +204,7 @@ std::shared_ptr nano::json_handler::wallet_impl () return nullptr; } -bool nano::json_handler::wallet_locked_impl (nano::transaction const & transaction_a, std::shared_ptr const & wallet_a) +bool nano::json_handler::wallet_locked_impl (store::transaction const & transaction_a, std::shared_ptr const & wallet_a) { bool result (false); if (!ec) @@ -218,7 +218,7 @@ bool nano::json_handler::wallet_locked_impl (nano::transaction const & transacti return result; } -bool nano::json_handler::wallet_account_impl (nano::transaction const & transaction_a, std::shared_ptr const & wallet_a, nano::account const & account_a) +bool nano::json_handler::wallet_account_impl (store::transaction const & transaction_a, std::shared_ptr const & wallet_a, nano::account const & account_a) { bool result (false); if (!ec) @@ -257,7 +257,7 @@ nano::account nano::json_handler::account_impl (std::string account_text, std::e return result; } -nano::account_info nano::json_handler::account_info_impl (nano::transaction const & transaction_a, nano::account const & account_a) +nano::account_info nano::json_handler::account_info_impl (store::transaction const & transaction_a, nano::account const & account_a) { nano::account_info result; if (!ec) @@ -2377,7 +2377,7 @@ namespace class history_visitor : public nano::block_visitor { public: - history_visitor (nano::json_handler & handler_a, bool raw_a, nano::transaction & transaction_a, boost::property_tree::ptree & tree_a, nano::block_hash const & hash_a, std::vector const & accounts_filter_a) : + history_visitor (nano::json_handler & handler_a, bool raw_a, nano::store::transaction & transaction_a, boost::property_tree::ptree & tree_a, nano::block_hash const & hash_a, std::vector const & accounts_filter_a) : handler (handler_a), raw (raw_a), transaction (transaction_a), @@ -2569,7 +2569,7 @@ class history_visitor : public nano::block_visitor } nano::json_handler & handler; bool raw; - nano::transaction & transaction; + nano::store::transaction & transaction; boost::property_tree::ptree & tree; nano::block_hash const & hash; std::vector const & accounts_filter; @@ -5448,7 +5448,7 @@ ipc_json_handler_no_arg_func_map create_ipc_json_handler_no_arg_func_map () } /** Due to the asynchronous nature of updating confirmation heights, it can also be necessary to check active roots */ -bool block_confirmed (nano::node & node, nano::transaction & transaction, nano::block_hash const & hash, bool include_active, bool include_only_confirmed) +bool block_confirmed (nano::node & node, nano::store::transaction & transaction, nano::block_hash const & hash, bool include_active, bool include_only_confirmed) { bool is_confirmed = false; if (include_active && !include_only_confirmed) diff --git a/nano/node/json_handler.hpp b/nano/node/json_handler.hpp index 60a257e3ab..cb7da62c72 100644 --- a/nano/node/json_handler.hpp +++ b/nano/node/json_handler.hpp @@ -155,10 +155,10 @@ class json_handler : public std::enable_shared_from_this std::string action; boost::property_tree::ptree response_l; std::shared_ptr wallet_impl (); - bool wallet_locked_impl (nano::transaction const &, std::shared_ptr const &); - bool wallet_account_impl (nano::transaction const &, std::shared_ptr const &, nano::account const &); + bool wallet_locked_impl (store::transaction const &, std::shared_ptr const &); + bool wallet_account_impl (store::transaction const &, std::shared_ptr const &, nano::account const &); nano::account account_impl (std::string = "", std::error_code = nano::error_common::bad_account_number); - nano::account_info account_info_impl (nano::transaction const &, nano::account const &); + nano::account_info account_info_impl (store::transaction const &, nano::account const &); nano::amount amount_impl (); std::shared_ptr block_impl (bool = true); nano::block_hash hash_impl (std::string = "hash"); diff --git a/nano/node/ledger_walker.cpp b/nano/node/ledger_walker.cpp index 7c58592af4..075cd1728e 100644 --- a/nano/node/ledger_walker.cpp +++ b/nano/node/ledger_walker.cpp @@ -170,7 +170,7 @@ void nano::ledger_walker::clear_queue () decltype (blocks_to_walk){}.swap (blocks_to_walk); } -std::shared_ptr nano::ledger_walker::dequeue_block (nano::transaction const & transaction_a) +std::shared_ptr nano::ledger_walker::dequeue_block (store::transaction const & transaction_a) { auto block = ledger.store.block.get (transaction_a, blocks_to_walk.top ()); blocks_to_walk.pop (); diff --git a/nano/node/ledger_walker.hpp b/nano/node/ledger_walker.hpp index 6458d8acdc..5492767da7 100644 --- a/nano/node/ledger_walker.hpp +++ b/nano/node/ledger_walker.hpp @@ -14,11 +14,15 @@ #include +namespace nano::store +{ +class transaction; +} + namespace nano { class block; class ledger; -class transaction; /** Walks the ledger starting from a start block and applying a depth-first search algorithm */ class ledger_walker final @@ -55,7 +59,7 @@ class ledger_walker final bool add_to_walked_blocks (nano::block_hash const & block_hash_a); bool add_to_walked_blocks_disk (nano::block_hash const & block_hash_a); void clear_queue (); - std::shared_ptr dequeue_block (nano::transaction const & transaction_a); + std::shared_ptr dequeue_block (store::transaction const & transaction_a); friend class ledger_walker_genesis_account_longer_Test; }; diff --git a/nano/node/make_store.cpp b/nano/node/make_store.cpp index bb577acc9b..55b7fa83d2 100644 --- a/nano/node/make_store.cpp +++ b/nano/node/make_store.cpp @@ -8,8 +8,8 @@ std::unique_ptr nano::make_store (nano::logger_mt & logg { if (rocksdb_config.enable) { - return std::make_unique (logger, add_db_postfix ? path / "rocksdb" : path, constants, rocksdb_config, read_only); + return std::make_unique (logger, add_db_postfix ? path / "rocksdb" : path, constants, rocksdb_config, read_only); } - return std::make_unique (logger, add_db_postfix ? path / "data.ldb" : path, constants, txn_tracking_config_a, block_processor_batch_max_time_a, lmdb_config_a, backup_before_upgrade); + return std::make_unique (logger, add_db_postfix ? path / "data.ldb" : path, constants, txn_tracking_config_a, block_processor_batch_max_time_a, lmdb_config_a, backup_before_upgrade); } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 34c6c43b03..049e940c69 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -222,7 +222,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, boost::filesystem::path co return ledger.weight (rep); }; - backlog.activate_callback.add ([this] (nano::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { + backlog.activate_callback.add ([this] (store::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { scheduler.priority.activate (account, transaction); scheduler.optimistic.activate (account, account_info, conf_info); }); @@ -594,7 +594,7 @@ void nano::node::process_active (std::shared_ptr const & incoming) block_processor.add (incoming); } -[[nodiscard]] nano::process_return nano::node::process (nano::write_transaction const & transaction, nano::block & block) +[[nodiscard]] nano::process_return nano::node::process (store::write_transaction const & transaction, nano::block & block) { return ledger.process (transaction, block); } @@ -1300,7 +1300,7 @@ void nano::node::ongoing_online_weight_calculation () ongoing_online_weight_calculation_queue (); } -void nano::node::receive_confirmed (nano::transaction const & block_transaction_a, nano::block_hash const & hash_a, nano::account const & destination_a) +void nano::node::receive_confirmed (store::transaction const & block_transaction_a, nano::block_hash const & hash_a, nano::account const & destination_a) { nano::unique_lock lk{ wallets.mutex }; auto wallets_l = wallets.get_wallets (); @@ -1334,7 +1334,7 @@ void nano::node::receive_confirmed (nano::transaction const & block_transaction_ } } -void nano::node::process_confirmed_data (nano::transaction const & transaction_a, std::shared_ptr const & block_a, nano::block_hash const & hash_a, nano::account & account_a, nano::uint128_t & amount_a, bool & is_state_send_a, bool & is_state_epoch_a, nano::account & pending_account_a) +void nano::node::process_confirmed_data (store::transaction const & transaction_a, std::shared_ptr const & block_a, nano::block_hash const & hash_a, nano::account & account_a, nano::uint128_t & amount_a, bool & is_state_send_a, bool & is_state_epoch_a, nano::account & pending_account_a) { // Faster account calculation account_a = block_a->account (); @@ -1463,7 +1463,7 @@ void nano::node::bootstrap_block (const nano::block_hash & hash) } /** Convenience function to easily return the confirmation height of an account. */ -uint64_t nano::node::get_confirmation_height (nano::transaction const & transaction_a, nano::account & account_a) +uint64_t nano::node::get_confirmation_height (store::transaction const & transaction_a, nano::account & account_a) { nano::confirmation_height_info info; store.confirmation_height.get (transaction_a, account_a, info); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index b114c06ee2..870562dc55 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -87,8 +87,8 @@ class node final : public std::enable_shared_from_this void stop (); std::shared_ptr shared (); int store_version (); - void receive_confirmed (nano::transaction const & block_transaction_a, nano::block_hash const & hash_a, nano::account const & destination_a); - void process_confirmed_data (nano::transaction const &, std::shared_ptr const &, nano::block_hash const &, nano::account &, nano::uint128_t &, bool &, bool &, nano::account &); + void receive_confirmed (store::transaction const & block_transaction_a, nano::block_hash const & hash_a, nano::account const & destination_a); + void process_confirmed_data (store::transaction const &, std::shared_ptr const &, nano::block_hash const &, nano::account &, nano::uint128_t &, bool &, bool &, nano::account &); void process_confirmed (nano::election_status const &, uint64_t = 0); void process_active (std::shared_ptr const &); std::optional process_local (std::shared_ptr const &); @@ -131,7 +131,7 @@ class node final : public std::enable_shared_from_this bool online () const; bool init_error () const; std::pair get_bootstrap_weights () const; - uint64_t get_confirmation_height (nano::transaction const &, nano::account &); + uint64_t get_confirmation_height (store::transaction const &, nano::account &); /* * Attempts to bootstrap block. This is the best effort, there is no guarantee that the block will be bootstrapped. */ @@ -222,7 +222,7 @@ class node final : public std::enable_shared_from_this Transaction is comitted before function return */ [[nodiscard]] nano::process_return process (nano::block & block); - [[nodiscard]] nano::process_return process (nano::write_transaction const &, nano::block & block); + [[nodiscard]] nano::process_return process (store::write_transaction const &, nano::block & block); nano::block_hash latest (nano::account const &); nano::uint128_t balance (nano::account const &); diff --git a/nano/node/online_reps.cpp b/nano/node/online_reps.cpp index 370aaa6790..3fdd2442dd 100644 --- a/nano/node/online_reps.cpp +++ b/nano/node/online_reps.cpp @@ -65,7 +65,7 @@ nano::uint128_t nano::online_reps::calculate_online () const return current; } -nano::uint128_t nano::online_reps::calculate_trend (nano::transaction & transaction_a) const +nano::uint128_t nano::online_reps::calculate_trend (store::transaction & transaction_a) const { std::vector items; items.reserve (config.network_params.node.max_weight_samples + 1); diff --git a/nano/node/online_reps.hpp b/nano/node/online_reps.hpp index add5328a03..ea9e6aea11 100644 --- a/nano/node/online_reps.hpp +++ b/nano/node/online_reps.hpp @@ -51,7 +51,7 @@ class online_reps final class tag_account { }; - nano::uint128_t calculate_trend (nano::transaction &) const; + nano::uint128_t calculate_trend (store::transaction &) const; nano::uint128_t calculate_online () const; mutable nano::mutex mutex; nano::ledger & ledger; diff --git a/nano/node/process_live_dispatcher.cpp b/nano/node/process_live_dispatcher.cpp index 361bba21bb..fa23af6370 100644 --- a/nano/node/process_live_dispatcher.cpp +++ b/nano/node/process_live_dispatcher.cpp @@ -28,7 +28,7 @@ void nano::process_live_dispatcher::connect (nano::block_processor & block_proce }); } -void nano::process_live_dispatcher::inspect (nano::process_return const & result, nano::block const & block, nano::transaction const & transaction) +void nano::process_live_dispatcher::inspect (nano::process_return const & result, nano::block const & block, store::transaction const & transaction) { switch (result.code) { @@ -40,7 +40,7 @@ void nano::process_live_dispatcher::inspect (nano::process_return const & result } } -void nano::process_live_dispatcher::process_live (nano::block const & block, nano::transaction const & transaction) +void nano::process_live_dispatcher::process_live (nano::block const & block, store::transaction const & transaction) { // Start collecting quorum on block if (ledger.dependents_confirmed (transaction, block)) diff --git a/nano/node/process_live_dispatcher.hpp b/nano/node/process_live_dispatcher.hpp index 23206544d1..c07525a0ff 100644 --- a/nano/node/process_live_dispatcher.hpp +++ b/nano/node/process_live_dispatcher.hpp @@ -1,5 +1,10 @@ #pragma once +namespace nano::store +{ +class transaction; +} + namespace nano { class ledger; @@ -8,7 +13,6 @@ class websocket_server; class block_processor; class process_return; class block; -class transaction; namespace scheduler { @@ -24,8 +28,8 @@ class process_live_dispatcher private: // Block_processor observer - void inspect (nano::process_return const & result, nano::block const & block, nano::transaction const & transaction); - void process_live (nano::block const & block, nano::transaction const & transaction); + void inspect (nano::process_return const & result, nano::block const & block, store::transaction const & transaction); + void process_live (nano::block const & block, store::transaction const & transaction); nano::ledger & ledger; nano::scheduler::priority & scheduler; diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index a00fa4d96c..b47ddb9fdf 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -144,7 +144,7 @@ void nano::scheduler::optimistic::run () } } -void nano::scheduler::optimistic::run_one (nano::transaction const & transaction, entry const & candidate) +void nano::scheduler::optimistic::run_one (store::transaction const & transaction, entry const & candidate) { auto block = ledger.head_block (transaction, candidate.account); if (block) diff --git a/nano/node/scheduler/optimistic.hpp b/nano/node/scheduler/optimistic.hpp index 3c16c72059..8794789e79 100644 --- a/nano/node/scheduler/optimistic.hpp +++ b/nano/node/scheduler/optimistic.hpp @@ -70,7 +70,7 @@ class optimistic final bool predicate () const; void run (); - void run_one (nano::transaction const &, entry const & candidate); + void run_one (store::transaction const &, entry const & candidate); private: // Dependencies optimistic_config const & config; diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index e4bd01392e..c75c5b0976 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -35,7 +35,7 @@ void nano::scheduler::priority::stop () nano::join_or_pass (thread); } -bool nano::scheduler::priority::activate (nano::account const & account_a, nano::transaction const & transaction) +bool nano::scheduler::priority::activate (nano::account const & account_a, store::transaction const & transaction) { debug_assert (!account_a.is_zero ()); auto info = node.ledger.account_info (transaction, account_a); diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index 13b32b950b..30bf33ad31 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -36,7 +36,7 @@ class priority final * Activates the first unconfirmed block of \p account_a * @return true if account was activated */ - bool activate (nano::account const &, nano::transaction const &); + bool activate (nano::account const &, store::transaction const &); void notify (); std::size_t size () const; bool empty () const; diff --git a/nano/node/voting.cpp b/nano/node/voting.cpp index fc59290fcc..b8f1dba707 100644 --- a/nano/node/voting.cpp +++ b/nano/node/voting.cpp @@ -184,7 +184,7 @@ nano::vote_generator::~vote_generator () stop (); } -void nano::vote_generator::process (nano::write_transaction const & transaction, nano::root const & root_a, nano::block_hash const & hash_a) +void nano::vote_generator::process (store::write_transaction const & transaction, nano::root const & root_a, nano::block_hash const & hash_a) { bool should_vote = false; if (is_final) diff --git a/nano/node/voting.hpp b/nano/node/voting.hpp index 7cde662d3c..13f113b106 100644 --- a/nano/node/voting.hpp +++ b/nano/node/voting.hpp @@ -144,7 +144,7 @@ class vote_generator final * Check if block is eligible for vote generation, then generates a vote or broadcasts votes already in cache * @param transaction : needs `tables::final_votes` lock */ - void process (nano::write_transaction const &, nano::root const &, nano::block_hash const &); + void process (store::write_transaction const &, nano::root const &, nano::block_hash const &); private: std::function const &, std::shared_ptr &)> reply_action; // must be set only during initialization by using set_reply_action diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 7f94064d9a..8f2ec7e0ca 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -15,19 +15,19 @@ #include -nano::uint256_union nano::wallet_store::check (nano::transaction const & transaction_a) +nano::uint256_union nano::wallet_store::check (store::transaction const & transaction_a) { nano::wallet_value value (entry_get_raw (transaction_a, nano::wallet_store::check_special)); return value.key; } -nano::uint256_union nano::wallet_store::salt (nano::transaction const & transaction_a) +nano::uint256_union nano::wallet_store::salt (store::transaction const & transaction_a) { nano::wallet_value value (entry_get_raw (transaction_a, nano::wallet_store::salt_special)); return value.key; } -void nano::wallet_store::wallet_key (nano::raw_key & prv_a, nano::transaction const & transaction_a) +void nano::wallet_store::wallet_key (nano::raw_key & prv_a, store::transaction const & transaction_a) { nano::lock_guard lock{ mutex }; nano::raw_key wallet_l; @@ -37,7 +37,7 @@ void nano::wallet_store::wallet_key (nano::raw_key & prv_a, nano::transaction co prv_a.decrypt (wallet_l, password_l, salt (transaction_a).owords[0]); } -void nano::wallet_store::seed (nano::raw_key & prv_a, nano::transaction const & transaction_a) +void nano::wallet_store::seed (nano::raw_key & prv_a, store::transaction const & transaction_a) { nano::wallet_value value (entry_get_raw (transaction_a, nano::wallet_store::seed_special)); nano::raw_key password_l; @@ -45,7 +45,7 @@ void nano::wallet_store::seed (nano::raw_key & prv_a, nano::transaction const & prv_a.decrypt (value.key, password_l, salt (transaction_a).owords[seed_iv_index]); } -void nano::wallet_store::seed_set (nano::transaction const & transaction_a, nano::raw_key const & prv_a) +void nano::wallet_store::seed_set (store::transaction const & transaction_a, nano::raw_key const & prv_a) { nano::raw_key password_l; wallet_key (password_l, transaction_a); @@ -55,7 +55,7 @@ void nano::wallet_store::seed_set (nano::transaction const & transaction_a, nano deterministic_clear (transaction_a); } -nano::public_key nano::wallet_store::deterministic_insert (nano::transaction const & transaction_a) +nano::public_key nano::wallet_store::deterministic_insert (store::transaction const & transaction_a) { auto index (deterministic_index_get (transaction_a)); auto prv = deterministic_key (transaction_a, index); @@ -75,7 +75,7 @@ nano::public_key nano::wallet_store::deterministic_insert (nano::transaction con return result; } -nano::public_key nano::wallet_store::deterministic_insert (nano::transaction const & transaction_a, uint32_t const index) +nano::public_key nano::wallet_store::deterministic_insert (store::transaction const & transaction_a, uint32_t const index) { auto prv = deterministic_key (transaction_a, index); nano::public_key result (nano::pub_key (prv)); @@ -86,7 +86,7 @@ nano::public_key nano::wallet_store::deterministic_insert (nano::transaction con return result; } -nano::raw_key nano::wallet_store::deterministic_key (nano::transaction const & transaction_a, uint32_t index_a) +nano::raw_key nano::wallet_store::deterministic_key (store::transaction const & transaction_a, uint32_t index_a) { debug_assert (valid_password (transaction_a)); nano::raw_key seed_l; @@ -94,20 +94,20 @@ nano::raw_key nano::wallet_store::deterministic_key (nano::transaction const & t return nano::deterministic_key (seed_l, index_a); } -uint32_t nano::wallet_store::deterministic_index_get (nano::transaction const & transaction_a) +uint32_t nano::wallet_store::deterministic_index_get (store::transaction const & transaction_a) { nano::wallet_value value (entry_get_raw (transaction_a, nano::wallet_store::deterministic_index_special)); return static_cast (value.key.number () & static_cast (-1)); } -void nano::wallet_store::deterministic_index_set (nano::transaction const & transaction_a, uint32_t index_a) +void nano::wallet_store::deterministic_index_set (store::transaction const & transaction_a, uint32_t index_a) { nano::raw_key index_l (index_a); nano::wallet_value value (index_l, 0); entry_put_raw (transaction_a, nano::wallet_store::deterministic_index_special, value); } -void nano::wallet_store::deterministic_clear (nano::transaction const & transaction_a) +void nano::wallet_store::deterministic_clear (store::transaction const & transaction_a) { nano::uint256_union key (0); for (auto i (begin (transaction_a)), n (end ()); i != n;) @@ -131,7 +131,7 @@ void nano::wallet_store::deterministic_clear (nano::transaction const & transact deterministic_index_set (transaction_a, 0); } -bool nano::wallet_store::valid_password (nano::transaction const & transaction_a) +bool nano::wallet_store::valid_password (store::transaction const & transaction_a) { nano::raw_key zero; zero.clear (); @@ -143,7 +143,7 @@ bool nano::wallet_store::valid_password (nano::transaction const & transaction_a return ok; } -bool nano::wallet_store::attempt_password (nano::transaction const & transaction_a, std::string const & password_a) +bool nano::wallet_store::attempt_password (store::transaction const & transaction_a, std::string const & password_a) { bool result = false; { @@ -166,7 +166,7 @@ bool nano::wallet_store::attempt_password (nano::transaction const & transaction return result; } -bool nano::wallet_store::rekey (nano::transaction const & transaction_a, std::string const & password_a) +bool nano::wallet_store::rekey (store::transaction const & transaction_a, std::string const & password_a) { nano::lock_guard lock{ mutex }; bool result (false); @@ -193,7 +193,7 @@ bool nano::wallet_store::rekey (nano::transaction const & transaction_a, std::st return result; } -void nano::wallet_store::derive_key (nano::raw_key & prv_a, nano::transaction const & transaction_a, std::string const & password_a) +void nano::wallet_store::derive_key (nano::raw_key & prv_a, store::transaction const & transaction_a, std::string const & password_a) { auto salt_l (salt (transaction_a)); kdf.phs (prv_a, password_a, salt_l); @@ -255,7 +255,7 @@ int const nano::wallet_store::special_count (7); std::size_t const nano::wallet_store::check_iv_index (0); std::size_t const nano::wallet_store::seed_iv_index (1); -nano::wallet_store::wallet_store (bool & init_a, nano::kdf & kdf_a, nano::transaction & transaction_a, nano::account representative_a, unsigned fanout_a, std::string const & wallet_a, std::string const & json_a) : +nano::wallet_store::wallet_store (bool & init_a, nano::kdf & kdf_a, store::transaction & transaction_a, nano::account representative_a, unsigned fanout_a, std::string const & wallet_a, std::string const & json_a) : password (0, fanout_a), wallet_key_mem (0, fanout_a), kdf (kdf_a) @@ -265,7 +265,7 @@ nano::wallet_store::wallet_store (bool & init_a, nano::kdf & kdf_a, nano::transa if (!init_a) { MDB_val junk; - debug_assert (mdb_get (tx (transaction_a), handle, nano::mdb_val (version_special), &junk) == MDB_NOTFOUND); + debug_assert (mdb_get (tx (transaction_a), handle, nano::store::lmdb::db_val (version_special), &junk) == MDB_NOTFOUND); boost::property_tree::ptree wallet_l; std::stringstream istream (json_a); try @@ -298,11 +298,11 @@ nano::wallet_store::wallet_store (bool & init_a, nano::kdf & kdf_a, nano::transa init_a = true; } } - init_a |= mdb_get (tx (transaction_a), handle, nano::mdb_val (version_special), &junk) != 0; - init_a |= mdb_get (tx (transaction_a), handle, nano::mdb_val (wallet_key_special), &junk) != 0; - init_a |= mdb_get (tx (transaction_a), handle, nano::mdb_val (salt_special), &junk) != 0; - init_a |= mdb_get (tx (transaction_a), handle, nano::mdb_val (check_special), &junk) != 0; - init_a |= mdb_get (tx (transaction_a), handle, nano::mdb_val (representative_special), &junk) != 0; + init_a |= mdb_get (tx (transaction_a), handle, nano::store::lmdb::db_val (version_special), &junk) != 0; + init_a |= mdb_get (tx (transaction_a), handle, nano::store::lmdb::db_val (wallet_key_special), &junk) != 0; + init_a |= mdb_get (tx (transaction_a), handle, nano::store::lmdb::db_val (salt_special), &junk) != 0; + init_a |= mdb_get (tx (transaction_a), handle, nano::store::lmdb::db_val (check_special), &junk) != 0; + init_a |= mdb_get (tx (transaction_a), handle, nano::store::lmdb::db_val (representative_special), &junk) != 0; nano::raw_key key; key.clear (); password.value_set (key); @@ -311,7 +311,7 @@ nano::wallet_store::wallet_store (bool & init_a, nano::kdf & kdf_a, nano::transa } } -nano::wallet_store::wallet_store (bool & init_a, nano::kdf & kdf_a, nano::transaction & transaction_a, nano::account representative_a, unsigned fanout_a, std::string const & wallet_a) : +nano::wallet_store::wallet_store (bool & init_a, nano::kdf & kdf_a, store::transaction & transaction_a, nano::account representative_a, unsigned fanout_a, std::string const & wallet_a) : password (0, fanout_a), wallet_key_mem (0, fanout_a), kdf (kdf_a) @@ -322,7 +322,7 @@ nano::wallet_store::wallet_store (bool & init_a, nano::kdf & kdf_a, nano::transa { int version_status; MDB_val version_value; - version_status = mdb_get (tx (transaction_a), handle, nano::mdb_val (version_special), &version_value); + version_status = mdb_get (tx (transaction_a), handle, nano::store::lmdb::db_val (version_special), &version_value); if (version_status == MDB_NOTFOUND) { version_put (transaction_a, version_current); @@ -361,7 +361,7 @@ nano::wallet_store::wallet_store (bool & init_a, nano::kdf & kdf_a, nano::transa wallet_key_mem.value_set (key); } -std::vector nano::wallet_store::accounts (nano::transaction const & transaction_a) +std::vector nano::wallet_store::accounts (store::transaction const & transaction_a) { std::vector result; for (auto i (begin (transaction_a)), n (end ()); i != n; ++i) @@ -372,7 +372,7 @@ std::vector nano::wallet_store::accounts (nano::transaction const return result; } -void nano::wallet_store::initialize (nano::transaction const & transaction_a, bool & init_a, std::string const & path_a) +void nano::wallet_store::initialize (store::transaction const & transaction_a, bool & init_a, std::string const & path_a) { debug_assert (strlen (path_a.c_str ()) == path_a.size ()); auto error (0); @@ -382,25 +382,25 @@ void nano::wallet_store::initialize (nano::transaction const & transaction_a, bo init_a = error != 0; } -bool nano::wallet_store::is_representative (nano::transaction const & transaction_a) +bool nano::wallet_store::is_representative (store::transaction const & transaction_a) { return exists (transaction_a, representative (transaction_a)); } -void nano::wallet_store::representative_set (nano::transaction const & transaction_a, nano::account const & representative_a) +void nano::wallet_store::representative_set (store::transaction const & transaction_a, nano::account const & representative_a) { nano::raw_key rep; rep.bytes = representative_a.bytes; entry_put_raw (transaction_a, nano::wallet_store::representative_special, nano::wallet_value (rep, 0)); } -nano::account nano::wallet_store::representative (nano::transaction const & transaction_a) +nano::account nano::wallet_store::representative (store::transaction const & transaction_a) { nano::wallet_value value (entry_get_raw (transaction_a, nano::wallet_store::representative_special)); return reinterpret_cast (value.key); } -nano::public_key nano::wallet_store::insert_adhoc (nano::transaction const & transaction_a, nano::raw_key const & prv) +nano::public_key nano::wallet_store::insert_adhoc (store::transaction const & transaction_a, nano::raw_key const & prv) { debug_assert (valid_password (transaction_a)); nano::public_key pub (nano::pub_key (prv)); @@ -412,7 +412,7 @@ nano::public_key nano::wallet_store::insert_adhoc (nano::transaction const & tra return pub; } -bool nano::wallet_store::insert_watch (nano::transaction const & transaction_a, nano::account const & pub_a) +bool nano::wallet_store::insert_watch (store::transaction const & transaction_a, nano::account const & pub_a) { bool error (!valid_public_key (pub_a)); if (!error) @@ -422,18 +422,18 @@ bool nano::wallet_store::insert_watch (nano::transaction const & transaction_a, return error; } -void nano::wallet_store::erase (nano::transaction const & transaction_a, nano::account const & pub) +void nano::wallet_store::erase (store::transaction const & transaction_a, nano::account const & pub) { - auto status (mdb_del (tx (transaction_a), handle, nano::mdb_val (pub), nullptr)); + auto status (mdb_del (tx (transaction_a), handle, nano::store::lmdb::db_val (pub), nullptr)); (void)status; debug_assert (status == 0); } -nano::wallet_value nano::wallet_store::entry_get_raw (nano::transaction const & transaction_a, nano::account const & pub_a) +nano::wallet_value nano::wallet_store::entry_get_raw (store::transaction const & transaction_a, nano::account const & pub_a) { nano::wallet_value result; - nano::mdb_val value; - auto status (mdb_get (tx (transaction_a), handle, nano::mdb_val (pub_a), value)); + nano::store::lmdb::db_val value; + auto status (mdb_get (tx (transaction_a), handle, nano::store::lmdb::db_val (pub_a), value)); if (status == 0) { result = nano::wallet_value (value); @@ -446,9 +446,9 @@ nano::wallet_value nano::wallet_store::entry_get_raw (nano::transaction const & return result; } -void nano::wallet_store::entry_put_raw (nano::transaction const & transaction_a, nano::account const & pub_a, nano::wallet_value const & entry_a) +void nano::wallet_store::entry_put_raw (store::transaction const & transaction_a, nano::account const & pub_a, nano::wallet_value const & entry_a) { - auto status (mdb_put (tx (transaction_a), handle, nano::mdb_val (pub_a), nano::mdb_val (sizeof (entry_a), const_cast (&entry_a)), 0)); + auto status (mdb_put (tx (transaction_a), handle, nano::store::lmdb::db_val (pub_a), nano::store::lmdb::db_val (sizeof (entry_a), const_cast (&entry_a)), 0)); (void)status; debug_assert (status == 0); } @@ -476,7 +476,7 @@ nano::key_type nano::wallet_store::key_type (nano::wallet_value const & value_a) return result; } -bool nano::wallet_store::fetch (nano::transaction const & transaction_a, nano::account const & pub, nano::raw_key & prv) +bool nano::wallet_store::fetch (store::transaction const & transaction_a, nano::account const & pub, nano::raw_key & prv) { auto result (false); if (valid_password (transaction_a)) @@ -534,15 +534,15 @@ bool nano::wallet_store::valid_public_key (nano::public_key const & pub) return pub.number () >= special_count; } -bool nano::wallet_store::exists (nano::transaction const & transaction_a, nano::public_key const & pub) +bool nano::wallet_store::exists (store::transaction const & transaction_a, nano::public_key const & pub) { return valid_public_key (pub) && find (transaction_a, pub) != end (); } -void nano::wallet_store::serialize_json (nano::transaction const & transaction_a, std::string & string_a) +void nano::wallet_store::serialize_json (store::transaction const & transaction_a, std::string & string_a) { boost::property_tree::ptree tree; - for (nano::store_iterator i (std::make_unique> (transaction_a, handle)), n (nullptr); i != n; ++i) + for (store::iterator i (std::make_unique> (transaction_a, handle)), n (nullptr); i != n; ++i) { tree.put (i->first.to_string (), i->second.key.to_string ()); } @@ -551,7 +551,7 @@ void nano::wallet_store::serialize_json (nano::transaction const & transaction_a string_a = ostream.str (); } -void nano::wallet_store::write_backup (nano::transaction const & transaction_a, boost::filesystem::path const & path_a) +void nano::wallet_store::write_backup (store::transaction const & transaction_a, boost::filesystem::path const & path_a) { std::ofstream backup_file; backup_file.open (path_a.string ()); @@ -567,7 +567,7 @@ void nano::wallet_store::write_backup (nano::transaction const & transaction_a, } } -bool nano::wallet_store::move (nano::transaction const & transaction_a, nano::wallet_store & other_a, std::vector const & keys) +bool nano::wallet_store::move (store::transaction const & transaction_a, nano::wallet_store & other_a, std::vector const & keys) { debug_assert (valid_password (transaction_a)); debug_assert (other_a.valid_password (transaction_a)); @@ -586,7 +586,7 @@ bool nano::wallet_store::move (nano::transaction const & transaction_a, nano::wa return result; } -bool nano::wallet_store::import (nano::transaction const & transaction_a, nano::wallet_store & other_a) +bool nano::wallet_store::import (store::transaction const & transaction_a, nano::wallet_store & other_a) { debug_assert (valid_password (transaction_a)); debug_assert (other_a.valid_password (transaction_a)); @@ -612,7 +612,7 @@ bool nano::wallet_store::import (nano::transaction const & transaction_a, nano:: return result; } -bool nano::wallet_store::work_get (nano::transaction const & transaction_a, nano::public_key const & pub_a, uint64_t & work_a) +bool nano::wallet_store::work_get (store::transaction const & transaction_a, nano::public_key const & pub_a, uint64_t & work_a) { auto result (false); auto entry (entry_get_raw (transaction_a, pub_a)); @@ -627,7 +627,7 @@ bool nano::wallet_store::work_get (nano::transaction const & transaction_a, nano return result; } -void nano::wallet_store::work_put (nano::transaction const & transaction_a, nano::public_key const & pub_a, uint64_t work_a) +void nano::wallet_store::work_put (store::transaction const & transaction_a, nano::public_key const & pub_a, uint64_t work_a) { auto entry (entry_get_raw (transaction_a, pub_a)); debug_assert (!entry.key.is_zero ()); @@ -635,7 +635,7 @@ void nano::wallet_store::work_put (nano::transaction const & transaction_a, nano entry_put_raw (transaction_a, pub_a, entry); } -unsigned nano::wallet_store::version (nano::transaction const & transaction_a) +unsigned nano::wallet_store::version (store::transaction const & transaction_a) { nano::wallet_value value (entry_get_raw (transaction_a, nano::wallet_store::version_special)); auto entry (value.key); @@ -643,7 +643,7 @@ unsigned nano::wallet_store::version (nano::transaction const & transaction_a) return result; } -void nano::wallet_store::version_put (nano::transaction const & transaction_a, unsigned version_a) +void nano::wallet_store::version_put (store::transaction const & transaction_a, unsigned version_a) { nano::raw_key entry (version_a); entry_put_raw (transaction_a, nano::wallet_store::version_special, nano::wallet_value (entry, 0)); @@ -657,14 +657,14 @@ void nano::kdf::phs (nano::raw_key & result_a, std::string const & password_a, n (void)success; } -nano::wallet::wallet (bool & init_a, nano::transaction & transaction_a, nano::wallets & wallets_a, std::string const & wallet_a) : +nano::wallet::wallet (bool & init_a, store::transaction & transaction_a, nano::wallets & wallets_a, std::string const & wallet_a) : lock_observer ([] (bool, bool) {}), store (init_a, wallets_a.kdf, transaction_a, wallets_a.node.config.random_representative (), wallets_a.node.config.password_fanout, wallet_a), wallets (wallets_a) { } -nano::wallet::wallet (bool & init_a, nano::transaction & transaction_a, nano::wallets & wallets_a, std::string const & wallet_a, std::string const & json) : +nano::wallet::wallet (bool & init_a, store::transaction & transaction_a, nano::wallets & wallets_a, std::string const & wallet_a, std::string const & json) : lock_observer ([] (bool, bool) {}), store (init_a, wallets_a.kdf, transaction_a, wallets_a.node.config.random_representative (), wallets_a.node.config.password_fanout, wallet_a, json), wallets (wallets_a) @@ -693,7 +693,7 @@ void nano::wallet::enter_initial_password () } } -bool nano::wallet::enter_password (nano::transaction const & transaction_a, std::string const & password_a) +bool nano::wallet::enter_password (store::transaction const & transaction_a, std::string const & password_a) { auto result (store.attempt_password (transaction_a, password_a)); if (!result) @@ -712,7 +712,7 @@ bool nano::wallet::enter_password (nano::transaction const & transaction_a, std: return result; } -nano::public_key nano::wallet::deterministic_insert (nano::transaction const & transaction_a, bool generate_work_a) +nano::public_key nano::wallet::deterministic_insert (store::transaction const & transaction_a, bool generate_work_a) { nano::public_key key{}; if (store.valid_password (transaction_a)) @@ -779,7 +779,7 @@ nano::public_key nano::wallet::insert_adhoc (nano::raw_key const & key_a, bool g return key; } -bool nano::wallet::insert_watch (nano::transaction const & transaction_a, nano::public_key const & pub_a) +bool nano::wallet::insert_watch (store::transaction const & transaction_a, nano::public_key const & pub_a) { return store.insert_watch (transaction_a, pub_a); } @@ -820,7 +820,7 @@ void nano::wallet::serialize (std::string & json_a) store.serialize_json (transaction, json_a); } -void nano::wallet_store::destroy (nano::transaction const & transaction_a) +void nano::wallet_store::destroy (store::transaction const & transaction_a) { auto status (mdb_drop (tx (transaction_a), handle, 1)); (void)status; @@ -932,10 +932,10 @@ std::shared_ptr nano::wallet::change_action (nano::account const & std::shared_ptr nano::wallet::send_action (nano::account const & source_a, nano::account const & account_a, nano::uint128_t const & amount_a, uint64_t work_a, bool generate_work_a, boost::optional id_a) { - boost::optional id_mdb_val; + boost::optional id_mdb_val; if (id_a) { - id_mdb_val = nano::mdb_val (id_a->size (), const_cast (id_a->data ())); + id_mdb_val = nano::store::lmdb::db_val (id_a->size (), const_cast (id_a->data ())); } auto prepare_send = [&id_mdb_val, &wallets = this->wallets, &store = this->store, &source_a, &amount_a, &work_a, &account_a] (auto const & transaction) { @@ -947,7 +947,7 @@ std::shared_ptr nano::wallet::send_action (nano::account const & so details.is_send = true; if (id_mdb_val) { - nano::mdb_val result; + nano::store::lmdb::db_val result; auto status (mdb_get (wallets.env.tx (transaction), wallets.node.wallets.send_action_ids, *id_mdb_val, result)); if (status == 0) { @@ -988,7 +988,7 @@ std::shared_ptr nano::wallet::send_action (nano::account const & so details.epoch = info->epoch (); if (id_mdb_val && block != nullptr) { - auto status (mdb_put (wallets.env.tx (transaction), wallets.node.wallets.send_action_ids, *id_mdb_val, nano::mdb_val (block->hash ()), 0)); + auto status (mdb_put (wallets.env.tx (transaction), wallets.node.wallets.send_action_ids, *id_mdb_val, nano::store::lmdb::db_val (block->hash ()), 0)); if (status != 0) { block = nullptr; @@ -1125,7 +1125,7 @@ void nano::wallet::send_async (nano::account const & source_a, nano::account con } // Update work for account if latest root is root_a -void nano::wallet::work_update (nano::transaction const & transaction_a, nano::account const & account_a, nano::root const & root_a, uint64_t work_a) +void nano::wallet::work_update (store::transaction const & transaction_a, nano::account const & account_a, nano::root const & root_a, uint64_t work_a) { debug_assert (!wallets.node.network_params.work.validate_entry (nano::work_version::work_1, root_a, work_a)); debug_assert (store.exists (transaction_a, account_a)); @@ -1161,7 +1161,7 @@ void nano::wallet::work_ensure (nano::account const & account_a, nano::root cons }); } -bool nano::wallet::search_receivable (nano::transaction const & wallet_transaction_a) +bool nano::wallet::search_receivable (store::transaction const & wallet_transaction_a) { auto result (!store.valid_password (wallet_transaction_a)); if (!result) @@ -1211,7 +1211,7 @@ bool nano::wallet::search_receivable (nano::transaction const & wallet_transacti return result; } -void nano::wallet::init_free_accounts (nano::transaction const & transaction_a) +void nano::wallet::init_free_accounts (store::transaction const & transaction_a) { free_accounts.clear (); for (auto i (store.begin (transaction_a)), n (store.end ()); i != n; ++i) @@ -1220,7 +1220,7 @@ void nano::wallet::init_free_accounts (nano::transaction const & transaction_a) } } -uint32_t nano::wallet::deterministic_check (nano::transaction const & transaction_a, uint32_t index) +uint32_t nano::wallet::deterministic_check (store::transaction const & transaction_a, uint32_t index) { auto block_transaction (wallets.node.store.tx_begin_read ()); for (uint32_t i (index + 1), n (index + 64); i < n; ++i) @@ -1250,7 +1250,7 @@ uint32_t nano::wallet::deterministic_check (nano::transaction const & transactio return index; } -nano::public_key nano::wallet::change_seed (nano::transaction const & transaction_a, nano::raw_key const & prv_a, uint32_t count) +nano::public_key nano::wallet::change_seed (store::transaction const & transaction_a, nano::raw_key const & prv_a, uint32_t count) { store.seed_set (transaction_a, prv_a); auto account = deterministic_insert (transaction_a); @@ -1266,7 +1266,7 @@ nano::public_key nano::wallet::change_seed (nano::transaction const & transactio return account; } -void nano::wallet::deterministic_restore (nano::transaction const & transaction_a) +void nano::wallet::deterministic_restore (store::transaction const & transaction_a) { auto index (store.deterministic_index_get (transaction_a)); auto new_index (deterministic_check (transaction_a, index)); @@ -1348,8 +1348,8 @@ nano::wallets::wallets (bool error_a, nano::node & node_a) : release_assert (status == 0); std::string beginning (nano::uint256_union (0).to_string ()); std::string end ((nano::uint256_union (nano::uint256_t (0) - nano::uint256_t (1))).to_string ()); - nano::store_iterator, nano::no_value> i (std::make_unique, nano::no_value>> (transaction, handle, nano::mdb_val (beginning.size (), const_cast (beginning.c_str ())))); - nano::store_iterator, nano::no_value> n (std::make_unique, nano::no_value>> (transaction, handle, nano::mdb_val (end.size (), const_cast (end.c_str ())))); + store::iterator, nano::no_value> i (std::make_unique, nano::no_value>> (transaction, handle, nano::store::lmdb::db_val (beginning.size (), const_cast (beginning.c_str ())))); + store::iterator, nano::no_value> n (std::make_unique, nano::no_value>> (transaction, handle, nano::store::lmdb::db_val (end.size (), const_cast (end.c_str ())))); for (; i != n; ++i) { nano::wallet_id id; @@ -1387,7 +1387,7 @@ nano::wallets::wallets (bool error_a, nano::node & node_a) : char const * store_path; mdb_env_get_path (env, &store_path); boost::filesystem::path const path (store_path); - nano::lmdb::store::create_backup_file (env, path, node_a.logger); + nano::store::lmdb::component::create_backup_file (env, path, node_a.logger); } for (auto & item : items) { @@ -1477,8 +1477,8 @@ void nano::wallets::reload () std::unordered_set stored_items; std::string beginning (nano::uint256_union (0).to_string ()); std::string end ((nano::uint256_union (nano::uint256_t (0) - nano::uint256_t (1))).to_string ()); - nano::store_iterator, nano::no_value> i (std::make_unique, nano::no_value>> (transaction, handle, nano::mdb_val (beginning.size (), const_cast (beginning.c_str ())))); - nano::store_iterator, nano::no_value> n (std::make_unique, nano::no_value>> (transaction, handle, nano::mdb_val (end.size (), const_cast (end.c_str ())))); + store::iterator, nano::no_value> i (std::make_unique, nano::no_value>> (transaction, handle, nano::store::lmdb::db_val (beginning.size (), const_cast (beginning.c_str ())))); + store::iterator, nano::no_value> n (std::make_unique, nano::no_value>> (transaction, handle, nano::store::lmdb::db_val (end.size (), const_cast (end.c_str ())))); for (; i != n; ++i) { nano::wallet_id id; @@ -1574,7 +1574,7 @@ void nano::wallets::foreach_representative (std::function lock{ mutex }; auto result (false); @@ -1607,17 +1607,17 @@ void nano::wallets::start () } }; } -nano::write_transaction nano::wallets::tx_begin_write () +nano::store::write_transaction nano::wallets::tx_begin_write () { return env.tx_begin_write (); } -nano::read_transaction nano::wallets::tx_begin_read () +nano::store::read_transaction nano::wallets::tx_begin_read () { return env.tx_begin_read (); } -void nano::wallets::clear_send_ids (nano::transaction const & transaction_a) +void nano::wallets::clear_send_ids (store::transaction const & transaction_a) { auto status (mdb_drop (env.tx (transaction_a), send_action_ids, 0)); (void)status; @@ -1696,9 +1696,9 @@ void nano::wallets::ongoing_compute_reps () }); } -void nano::wallets::split_if_needed (nano::transaction & transaction_destination, nano::store::component & store_a) +void nano::wallets::split_if_needed (store::transaction & transaction_destination, nano::store::component & store_a) { - auto store_l = dynamic_cast (&store_a); + auto store_l = dynamic_cast (&store_a); if (store_l != nullptr) { if (items.empty ()) @@ -1706,8 +1706,8 @@ void nano::wallets::split_if_needed (nano::transaction & transaction_destination std::string beginning (nano::uint256_union (0).to_string ()); std::string end ((nano::uint256_union (nano::uint256_t (0) - nano::uint256_t (1))).to_string ()); - auto get_store_it = [&handle = handle] (nano::transaction const & transaction_source, std::string const & hash) { - return nano::store_iterator, nano::no_value> (std::make_unique, nano::no_value>> (transaction_source, handle, nano::mdb_val (hash.size (), const_cast (hash.c_str ())))); + auto get_store_it = [&handle = handle] (store::transaction const & transaction_source, std::string const & hash) { + return store::iterator, nano::no_value> (std::make_unique, nano::no_value>> (transaction_source, handle, nano::store::lmdb::db_val (hash.size (), const_cast (hash.c_str ())))); }; // First do a read pass to check if there are any wallets that need extracting (to save holding a write lock and potentially being blocked) @@ -1779,22 +1779,22 @@ std::unordered_map> nano::wallets nano::uint128_t const nano::wallets::generate_priority = std::numeric_limits::max (); nano::uint128_t const nano::wallets::high_priority = std::numeric_limits::max () - 1; -nano::store_iterator nano::wallet_store::begin (nano::transaction const & transaction_a) +nano::store::iterator nano::wallet_store::begin (store::transaction const & transaction_a) { - nano::store_iterator result (std::make_unique> (transaction_a, handle, nano::mdb_val (nano::account (special_count)))); + store::iterator result (std::make_unique> (transaction_a, handle, nano::store::lmdb::db_val (nano::account (special_count)))); return result; } -nano::store_iterator nano::wallet_store::begin (nano::transaction const & transaction_a, nano::account const & key) +nano::store::iterator nano::wallet_store::begin (store::transaction const & transaction_a, nano::account const & key) { - nano::store_iterator result (std::make_unique> (transaction_a, handle, nano::mdb_val (key))); + store::iterator result (std::make_unique> (transaction_a, handle, nano::store::lmdb::db_val (key))); return result; } -nano::store_iterator nano::wallet_store::find (nano::transaction const & transaction_a, nano::account const & key) +nano::store::iterator nano::wallet_store::find (store::transaction const & transaction_a, nano::account const & key) { auto result (begin (transaction_a, key)); - nano::store_iterator end (nullptr); + store::iterator end (nullptr); if (result != end) { if (result->first == key) @@ -1813,12 +1813,12 @@ nano::store_iterator nano::wallet_store::find return result; } -nano::store_iterator nano::wallet_store::end () +nano::store::iterator nano::wallet_store::end () { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } nano::mdb_wallets_store::mdb_wallets_store (boost::filesystem::path const & path_a, nano::lmdb_config const & lmdb_config_a) : - environment (error, path_a, nano::mdb_env::options::make ().set_config (lmdb_config_a).override_config_sync (nano::lmdb_config::sync_strategy::always).override_config_map_size (1ULL * 1024 * 1024 * 1024)) + environment (error, path_a, nano::store::lmdb::env::options::make ().set_config (lmdb_config_a).override_config_sync (nano::lmdb_config::sync_strategy::always).override_config_map_size (1ULL * 1024 * 1024 * 1024)) { } @@ -1827,7 +1827,7 @@ bool nano::mdb_wallets_store::init_error () const return error; } -MDB_txn * nano::wallet_store::tx (nano::transaction const & transaction_a) const +MDB_txn * nano::wallet_store::tx (store::transaction const & transaction_a) const { return static_cast (transaction_a.get_handle ()); } diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index 8a23f11d93..c585ae2995 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -52,50 +52,50 @@ enum class key_type class wallet_store final { public: - wallet_store (bool &, nano::kdf &, nano::transaction &, nano::account, unsigned, std::string const &); - wallet_store (bool &, nano::kdf &, nano::transaction &, nano::account, unsigned, std::string const &, std::string const &); - std::vector accounts (nano::transaction const &); - void initialize (nano::transaction const &, bool &, std::string const &); - nano::uint256_union check (nano::transaction const &); - bool rekey (nano::transaction const &, std::string const &); - bool valid_password (nano::transaction const &); + wallet_store (bool &, nano::kdf &, store::transaction &, nano::account, unsigned, std::string const &); + wallet_store (bool &, nano::kdf &, store::transaction &, nano::account, unsigned, std::string const &, std::string const &); + std::vector accounts (store::transaction const &); + void initialize (store::transaction const &, bool &, std::string const &); + nano::uint256_union check (store::transaction const &); + bool rekey (store::transaction const &, std::string const &); + bool valid_password (store::transaction const &); bool valid_public_key (nano::public_key const &); - bool attempt_password (nano::transaction const &, std::string const &); - void wallet_key (nano::raw_key &, nano::transaction const &); - void seed (nano::raw_key &, nano::transaction const &); - void seed_set (nano::transaction const &, nano::raw_key const &); + bool attempt_password (store::transaction const &, std::string const &); + void wallet_key (nano::raw_key &, store::transaction const &); + void seed (nano::raw_key &, store::transaction const &); + void seed_set (store::transaction const &, nano::raw_key const &); nano::key_type key_type (nano::wallet_value const &); - nano::public_key deterministic_insert (nano::transaction const &); - nano::public_key deterministic_insert (nano::transaction const &, uint32_t const); - nano::raw_key deterministic_key (nano::transaction const &, uint32_t); - uint32_t deterministic_index_get (nano::transaction const &); - void deterministic_index_set (nano::transaction const &, uint32_t); - void deterministic_clear (nano::transaction const &); - nano::uint256_union salt (nano::transaction const &); - bool is_representative (nano::transaction const &); - nano::account representative (nano::transaction const &); - void representative_set (nano::transaction const &, nano::account const &); - nano::public_key insert_adhoc (nano::transaction const &, nano::raw_key const &); - bool insert_watch (nano::transaction const &, nano::account const &); - void erase (nano::transaction const &, nano::account const &); - nano::wallet_value entry_get_raw (nano::transaction const &, nano::account const &); - void entry_put_raw (nano::transaction const &, nano::account const &, nano::wallet_value const &); - bool fetch (nano::transaction const &, nano::account const &, nano::raw_key &); - bool exists (nano::transaction const &, nano::account const &); - void destroy (nano::transaction const &); - nano::store_iterator find (nano::transaction const &, nano::account const &); - nano::store_iterator begin (nano::transaction const &, nano::account const &); - nano::store_iterator begin (nano::transaction const &); - nano::store_iterator end (); - void derive_key (nano::raw_key &, nano::transaction const &, std::string const &); - void serialize_json (nano::transaction const &, std::string &); - void write_backup (nano::transaction const &, boost::filesystem::path const &); - bool move (nano::transaction const &, nano::wallet_store &, std::vector const &); - bool import (nano::transaction const &, nano::wallet_store &); - bool work_get (nano::transaction const &, nano::public_key const &, uint64_t &); - void work_put (nano::transaction const &, nano::public_key const &, uint64_t); - unsigned version (nano::transaction const &); - void version_put (nano::transaction const &, unsigned); + nano::public_key deterministic_insert (store::transaction const &); + nano::public_key deterministic_insert (store::transaction const &, uint32_t const); + nano::raw_key deterministic_key (store::transaction const &, uint32_t); + uint32_t deterministic_index_get (store::transaction const &); + void deterministic_index_set (store::transaction const &, uint32_t); + void deterministic_clear (store::transaction const &); + nano::uint256_union salt (store::transaction const &); + bool is_representative (store::transaction const &); + nano::account representative (store::transaction const &); + void representative_set (store::transaction const &, nano::account const &); + nano::public_key insert_adhoc (store::transaction const &, nano::raw_key const &); + bool insert_watch (store::transaction const &, nano::account const &); + void erase (store::transaction const &, nano::account const &); + nano::wallet_value entry_get_raw (store::transaction const &, nano::account const &); + void entry_put_raw (store::transaction const &, nano::account const &, nano::wallet_value const &); + bool fetch (store::transaction const &, nano::account const &, nano::raw_key &); + bool exists (store::transaction const &, nano::account const &); + void destroy (store::transaction const &); + store::iterator find (store::transaction const &, nano::account const &); + store::iterator begin (store::transaction const &, nano::account const &); + store::iterator begin (store::transaction const &); + store::iterator end (); + void derive_key (nano::raw_key &, store::transaction const &, std::string const &); + void serialize_json (store::transaction const &, std::string &); + void write_backup (store::transaction const &, boost::filesystem::path const &); + bool move (store::transaction const &, nano::wallet_store &, std::vector const &); + bool import (store::transaction const &, nano::wallet_store &); + bool work_get (store::transaction const &, nano::public_key const &, uint64_t &); + void work_put (store::transaction const &, nano::public_key const &, uint64_t); + unsigned version (store::transaction const &); + void version_put (store::transaction const &, unsigned); nano::fan password; nano::fan wallet_key_mem; static unsigned const version_1 = 1; @@ -118,7 +118,7 @@ class wallet_store final std::recursive_mutex mutex; private: - MDB_txn * tx (nano::transaction const &) const; + MDB_txn * tx (store::transaction const &) const; }; // A wallet is a set of account keys encrypted by a common encryption key class wallet final : public std::enable_shared_from_this @@ -128,13 +128,13 @@ class wallet final : public std::enable_shared_from_this std::shared_ptr receive_action (nano::block_hash const &, nano::account const &, nano::uint128_union const &, nano::account const &, uint64_t = 0, bool = true); std::shared_ptr send_action (nano::account const &, nano::account const &, nano::uint128_t const &, uint64_t = 0, bool = true, boost::optional = {}); bool action_complete (std::shared_ptr const &, nano::account const &, bool const, nano::block_details const &); - wallet (bool &, nano::transaction &, nano::wallets &, std::string const &); - wallet (bool &, nano::transaction &, nano::wallets &, std::string const &, std::string const &); + wallet (bool &, store::transaction &, nano::wallets &, std::string const &); + wallet (bool &, store::transaction &, nano::wallets &, std::string const &, std::string const &); void enter_initial_password (); - bool enter_password (nano::transaction const &, std::string const &); + bool enter_password (store::transaction const &, std::string const &); nano::public_key insert_adhoc (nano::raw_key const &, bool = true); - bool insert_watch (nano::transaction const &, nano::public_key const &); - nano::public_key deterministic_insert (nano::transaction const &, bool = true); + bool insert_watch (store::transaction const &, nano::public_key const &); + nano::public_key deterministic_insert (store::transaction const &, bool = true); nano::public_key deterministic_insert (uint32_t, bool = true); nano::public_key deterministic_insert (bool = true); bool exists (nano::public_key const &); @@ -147,15 +147,15 @@ class wallet final : public std::enable_shared_from_this nano::block_hash send_sync (nano::account const &, nano::account const &, nano::uint128_t const &); void send_async (nano::account const &, nano::account const &, nano::uint128_t const &, std::function const &)> const &, uint64_t = 0, bool = true, boost::optional = {}); void work_cache_blocking (nano::account const &, nano::root const &); - void work_update (nano::transaction const &, nano::account const &, nano::root const &, uint64_t); + void work_update (store::transaction const &, nano::account const &, nano::root const &, uint64_t); // Schedule work generation after a few seconds void work_ensure (nano::account const &, nano::root const &); - bool search_receivable (nano::transaction const &); - void init_free_accounts (nano::transaction const &); - uint32_t deterministic_check (nano::transaction const & transaction_a, uint32_t index); + bool search_receivable (store::transaction const &); + void init_free_accounts (store::transaction const &); + uint32_t deterministic_check (store::transaction const & transaction_a, uint32_t index); /** Changes the wallet seed and returns the first account */ - nano::public_key change_seed (nano::transaction const & transaction_a, nano::raw_key const & prv_a, uint32_t count = 0); - void deterministic_restore (nano::transaction const & transaction_a); + nano::public_key change_seed (store::transaction const & transaction_a, nano::raw_key const & prv_a, uint32_t count = 0); + void deterministic_restore (store::transaction const & transaction_a); bool live (); std::unordered_set free_accounts; std::function lock_observer; @@ -205,15 +205,15 @@ class wallets final void do_wallet_actions (); void queue_wallet_action (nano::uint128_t const &, std::shared_ptr const &, std::function); void foreach_representative (std::function const &); - bool exists (nano::transaction const &, nano::account const &); + bool exists (store::transaction const &, nano::account const &); void start (); void stop (); - void clear_send_ids (nano::transaction const &); + void clear_send_ids (store::transaction const &); nano::wallet_representatives reps () const; bool check_rep (nano::account const &, nano::uint128_t const &, bool const = true); void compute_reps (); void ongoing_compute_reps (); - void split_if_needed (nano::transaction &, nano::store::component &); + void split_if_needed (store::transaction &, nano::store::component &); void move_table (std::string const &, MDB_txn *, MDB_txn *); std::unordered_map> get_wallets (); nano::network_params & network_params; @@ -228,16 +228,16 @@ class wallets final MDB_dbi handle; MDB_dbi send_action_ids; nano::node & node; - nano::mdb_env & env; + nano::store::lmdb::env & env; std::atomic stopped; std::thread thread; static nano::uint128_t const generate_priority; static nano::uint128_t const high_priority; /** Start read-write transaction */ - nano::write_transaction tx_begin_write (); + store::write_transaction tx_begin_write (); /** Start read-only transaction */ - nano::read_transaction tx_begin_read (); + store::read_transaction tx_begin_read (); private: mutable nano::mutex reps_cache_mutex; @@ -256,7 +256,7 @@ class mdb_wallets_store final : public wallets_store { public: mdb_wallets_store (boost::filesystem::path const &, nano::lmdb_config const & lmdb_config_a = nano::lmdb_config{}); - nano::mdb_env environment; + nano::store::lmdb::env environment; bool init_error () const override; bool error{ false }; }; diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index de98c67e88..a42d29401a 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -29,7 +29,7 @@ namespace class rollback_visitor : public nano::block_visitor { public: - rollback_visitor (nano::write_transaction const & transaction_a, nano::ledger & ledger_a, std::vector> & list_a) : + rollback_visitor (nano::store::write_transaction const & transaction_a, nano::ledger & ledger_a, std::vector> & list_a) : transaction (transaction_a), ledger (ledger_a), list (list_a) @@ -184,7 +184,7 @@ class rollback_visitor : public nano::block_visitor } ledger.store.block.del (transaction, hash); } - nano::write_transaction const & transaction; + nano::store::write_transaction const & transaction; nano::ledger & ledger; std::vector> & list; bool error{ false }; @@ -193,7 +193,7 @@ class rollback_visitor : public nano::block_visitor class ledger_processor : public nano::mutable_block_visitor { public: - ledger_processor (nano::ledger &, nano::write_transaction const &); + ledger_processor (nano::ledger &, nano::store::write_transaction const &); virtual ~ledger_processor () = default; void send_block (nano::send_block &) override; void receive_block (nano::receive_block &) override; @@ -203,7 +203,7 @@ class ledger_processor : public nano::mutable_block_visitor void state_block_impl (nano::state_block &); void epoch_block_impl (nano::state_block &); nano::ledger & ledger; - nano::write_transaction const & transaction; + nano::store::write_transaction const & transaction; nano::process_return result; private: @@ -684,7 +684,7 @@ void ledger_processor::open_block (nano::open_block & block_a) } } -ledger_processor::ledger_processor (nano::ledger & ledger_a, nano::write_transaction const & transaction_a) : +ledger_processor::ledger_processor (nano::ledger & ledger_a, nano::store::write_transaction const & transaction_a) : ledger (ledger_a), transaction (transaction_a) { @@ -696,7 +696,7 @@ ledger_processor::ledger_processor (nano::ledger & ledger_a, nano::write_transac class representative_visitor final : public nano::block_visitor { public: - representative_visitor (nano::transaction const & transaction_a, nano::store::component & store_a); + representative_visitor (nano::store::transaction const & transaction_a, nano::store::component & store_a); ~representative_visitor () = default; void compute (nano::block_hash const & hash_a); void send_block (nano::send_block const & block_a) override; @@ -704,13 +704,13 @@ class representative_visitor final : public nano::block_visitor void open_block (nano::open_block const & block_a) override; void change_block (nano::change_block const & block_a) override; void state_block (nano::state_block const & block_a) override; - nano::transaction const & transaction; + nano::store::transaction const & transaction; nano::store::component & store; nano::block_hash current; nano::block_hash result; }; -representative_visitor::representative_visitor (nano::transaction const & transaction_a, nano::store::component & store_a) : +representative_visitor::representative_visitor (nano::store::transaction const & transaction_a, nano::store::component & store_a) : transaction (transaction_a), store (store_a), result (0) @@ -771,7 +771,7 @@ void nano::ledger::initialize (nano::generate_cache const & generate_cache_a) if (generate_cache_a.reps || generate_cache_a.account_count || generate_cache_a.block_count) { store.account.for_each_par ( - [this] (nano::read_transaction const & /*unused*/, nano::store_iterator i, nano::store_iterator n) { + [this] (store::read_transaction const & /*unused*/, store::iterator i, store::iterator n) { uint64_t block_count_l{ 0 }; uint64_t account_count_l{ 0 }; decltype (this->cache.rep_weights) rep_weights_l; @@ -791,7 +791,7 @@ void nano::ledger::initialize (nano::generate_cache const & generate_cache_a) if (generate_cache_a.cemented_count) { store.confirmation_height.for_each_par ( - [this] (nano::read_transaction const & /*unused*/, nano::store_iterator i, nano::store_iterator n) { + [this] (store::read_transaction const & /*unused*/, store::iterator i, store::iterator n) { uint64_t cemented_count_l (0); for (; i != n; ++i) { @@ -835,7 +835,7 @@ nano::uint128_t nano::ledger::balance (nano::block const & block) } // Balance for account containing hash -nano::uint128_t nano::ledger::balance (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::uint128_t nano::ledger::balance (store::transaction const & transaction, nano::block_hash const & hash) const { if (hash.is_zero ()) { @@ -846,7 +846,7 @@ nano::uint128_t nano::ledger::balance (nano::transaction const & transaction, na return balance (*block); } -nano::uint128_t nano::ledger::balance_safe (nano::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const +nano::uint128_t nano::ledger::balance_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const { nano::uint128_t result (0); if (pruning && !hash_a.is_zero () && !store.block.exists (transaction_a, hash_a)) @@ -862,7 +862,7 @@ nano::uint128_t nano::ledger::balance_safe (nano::transaction const & transactio } // Balance for an account by account number -nano::uint128_t nano::ledger::account_balance (nano::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) +nano::uint128_t nano::ledger::account_balance (store::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) { nano::uint128_t result (0); if (only_confirmed_a) @@ -884,7 +884,7 @@ nano::uint128_t nano::ledger::account_balance (nano::transaction const & transac return result; } -nano::uint128_t nano::ledger::account_receivable (nano::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) +nano::uint128_t nano::ledger::account_receivable (store::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) { nano::uint128_t result (0); nano::account end (account_a.number () + 1); @@ -906,7 +906,7 @@ nano::uint128_t nano::ledger::account_receivable (nano::transaction const & tran return result; } -std::optional nano::ledger::pending_info (nano::transaction const & transaction, nano::pending_key const & key) const +std::optional nano::ledger::pending_info (store::transaction const & transaction, nano::pending_key const & key) const { nano::pending_info result; if (!store.pending.get (transaction, key, result)) @@ -916,7 +916,7 @@ std::optional nano::ledger::pending_info (nano::transaction return std::nullopt; } -nano::process_return nano::ledger::process (nano::write_transaction const & transaction_a, nano::block & block_a) +nano::process_return nano::ledger::process (store::write_transaction const & transaction_a, nano::block & block_a) { debug_assert (!constants.work.validate_entry (block_a) || constants.genesis == nano::dev::genesis); ledger_processor processor (*this, transaction_a); @@ -928,14 +928,14 @@ nano::process_return nano::ledger::process (nano::write_transaction const & tran return processor.result; } -nano::block_hash nano::ledger::representative (nano::transaction const & transaction_a, nano::block_hash const & hash_a) +nano::block_hash nano::ledger::representative (store::transaction const & transaction_a, nano::block_hash const & hash_a) { auto result (representative_calculated (transaction_a, hash_a)); debug_assert (result.is_zero () || store.block.exists (transaction_a, result)); return result; } -nano::block_hash nano::ledger::representative_calculated (nano::transaction const & transaction_a, nano::block_hash const & hash_a) +nano::block_hash nano::ledger::representative_calculated (store::transaction const & transaction_a, nano::block_hash const & hash_a) { representative_visitor visitor (transaction_a, store); visitor.compute (hash_a); @@ -947,7 +947,7 @@ bool nano::ledger::block_or_pruned_exists (nano::block_hash const & hash_a) cons return block_or_pruned_exists (store.tx_begin_read (), hash_a); } -bool nano::ledger::block_or_pruned_exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const +bool nano::ledger::block_or_pruned_exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) const { if (store.pruned.exists (transaction_a, hash_a)) { @@ -956,7 +956,7 @@ bool nano::ledger::block_or_pruned_exists (nano::transaction const & transaction return store.block.exists (transaction_a, hash_a); } -bool nano::ledger::root_exists (nano::transaction const & transaction_a, nano::root const & root_a) +bool nano::ledger::root_exists (store::transaction const & transaction_a, nano::root const & root_a) { return store.block.exists (transaction_a, root_a.as_block_hash ()) || store.account.exists (transaction_a, root_a.as_account ()); } @@ -978,7 +978,7 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a) return result; } -bool nano::ledger::is_send (nano::transaction const & transaction_a, nano::block const & block_a) const +bool nano::ledger::is_send (store::transaction const & transaction_a, nano::block const & block_a) const { if (block_a.type () != nano::block_type::state) { @@ -1010,7 +1010,7 @@ bool nano::ledger::is_send (nano::transaction const & transaction_a, nano::block return result; } -nano::account const & nano::ledger::block_destination (nano::transaction const & transaction_a, nano::block const & block_a) +nano::account const & nano::ledger::block_destination (store::transaction const & transaction_a, nano::block const & block_a) { nano::send_block const * send_block (dynamic_cast (&block_a)); nano::state_block const * state_block (dynamic_cast (&block_a)); @@ -1026,7 +1026,7 @@ nano::account const & nano::ledger::block_destination (nano::transaction const & return nano::account::null (); } -nano::block_hash nano::ledger::block_source (nano::transaction const & transaction_a, nano::block const & block_a) +nano::block_hash nano::ledger::block_source (store::transaction const & transaction_a, nano::block const & block_a) { /* * block_source() requires that the previous block of the block @@ -1046,7 +1046,7 @@ nano::block_hash nano::ledger::block_source (nano::transaction const & transacti return result; } -std::pair nano::ledger::hash_root_random (nano::transaction const & transaction_a) const +std::pair nano::ledger::hash_root_random (store::transaction const & transaction_a) const { nano::block_hash hash (0); nano::root root (0); @@ -1097,7 +1097,7 @@ nano::uint128_t nano::ledger::weight (nano::account const & account_a) } // Rollback blocks until `block_a' doesn't exist or it tries to penetrate the confirmation height -bool nano::ledger::rollback (nano::write_transaction const & transaction_a, nano::block_hash const & block_a, std::vector> & list_a) +bool nano::ledger::rollback (store::write_transaction const & transaction_a, nano::block_hash const & block_a, std::vector> & list_a) { debug_assert (store.block.exists (transaction_a, block_a)); auto account_l (account (transaction_a, block_a)); @@ -1129,7 +1129,7 @@ bool nano::ledger::rollback (nano::write_transaction const & transaction_a, nano return error; } -bool nano::ledger::rollback (nano::write_transaction const & transaction_a, nano::block_hash const & block_a) +bool nano::ledger::rollback (store::write_transaction const & transaction_a, nano::block_hash const & block_a) { std::vector> rollback_list; return rollback (transaction_a, block_a, rollback_list); @@ -1147,14 +1147,14 @@ nano::account nano::ledger::account (nano::block const & block) const return result; } -nano::account nano::ledger::account (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::account nano::ledger::account (store::transaction const & transaction, nano::block_hash const & hash) const { auto block = store.block.get (transaction, hash); debug_assert (block != nullptr); return account (*block); } -nano::account nano::ledger::account_safe (nano::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const +nano::account nano::ledger::account_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const { if (!pruning) { @@ -1175,7 +1175,7 @@ nano::account nano::ledger::account_safe (nano::transaction const & transaction_ } } -nano::account nano::ledger::account_safe (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::account nano::ledger::account_safe (store::transaction const & transaction, nano::block_hash const & hash) const { auto block = store.block.get (transaction, hash); if (block) @@ -1188,19 +1188,19 @@ nano::account nano::ledger::account_safe (nano::transaction const & transaction, } } -std::optional nano::ledger::account_info (nano::transaction const & transaction, nano::account const & account) const +std::optional nano::ledger::account_info (store::transaction const & transaction, nano::account const & account) const { return store.account.get (transaction, account); } // Return amount decrease or increase for block -nano::uint128_t nano::ledger::amount (nano::transaction const & transaction_a, nano::account const & account_a) +nano::uint128_t nano::ledger::amount (store::transaction const & transaction_a, nano::account const & account_a) { release_assert (account_a == constants.genesis->account ()); return nano::dev::constants.genesis_amount; } -nano::uint128_t nano::ledger::amount (nano::transaction const & transaction_a, nano::block_hash const & hash_a) +nano::uint128_t nano::ledger::amount (store::transaction const & transaction_a, nano::block_hash const & hash_a) { auto block (store.block.get (transaction_a, hash_a)); auto block_balance (balance (transaction_a, hash_a)); @@ -1208,7 +1208,7 @@ nano::uint128_t nano::ledger::amount (nano::transaction const & transaction_a, n return block_balance > previous_balance ? block_balance - previous_balance : previous_balance - block_balance; } -nano::uint128_t nano::ledger::amount_safe (nano::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const +nano::uint128_t nano::ledger::amount_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const { auto block (store.block.get (transaction_a, hash_a)); debug_assert (block); @@ -1219,14 +1219,14 @@ nano::uint128_t nano::ledger::amount_safe (nano::transaction const & transaction } // Return latest block for account -nano::block_hash nano::ledger::latest (nano::transaction const & transaction_a, nano::account const & account_a) +nano::block_hash nano::ledger::latest (store::transaction const & transaction_a, nano::account const & account_a) { auto info = account_info (transaction_a, account_a); return !info ? 0 : info->head; } // Return latest root for account, account number if there are no blocks for this account. -nano::root nano::ledger::latest_root (nano::transaction const & transaction_a, nano::account const & account_a) +nano::root nano::ledger::latest_root (store::transaction const & transaction_a, nano::account const & account_a) { auto info = account_info (transaction_a, account_a); if (!info) @@ -1252,7 +1252,7 @@ void nano::ledger::dump_account_chain (nano::account const & account_a, std::ost } } -bool nano::ledger::could_fit (nano::transaction const & transaction_a, nano::block const & block_a) const +bool nano::ledger::could_fit (store::transaction const & transaction_a, nano::block const & block_a) const { auto dependencies (dependent_blocks (transaction_a, block_a)); return std::all_of (dependencies.begin (), dependencies.end (), [this, &transaction_a] (nano::block_hash const & hash_a) { @@ -1260,7 +1260,7 @@ bool nano::ledger::could_fit (nano::transaction const & transaction_a, nano::blo }); } -bool nano::ledger::dependents_confirmed (nano::transaction const & transaction_a, nano::block const & block_a) const +bool nano::ledger::dependents_confirmed (store::transaction const & transaction_a, nano::block const & block_a) const { auto dependencies (dependent_blocks (transaction_a, block_a)); return std::all_of (dependencies.begin (), dependencies.end (), [this, &transaction_a] (nano::block_hash const & hash_a) { @@ -1281,7 +1281,7 @@ bool nano::ledger::is_epoch_link (nano::link const & link_a) const class dependent_block_visitor : public nano::block_visitor { public: - dependent_block_visitor (nano::ledger const & ledger_a, nano::transaction const & transaction_a) : + dependent_block_visitor (nano::ledger const & ledger_a, nano::store::transaction const & transaction_a) : ledger (ledger_a), transaction (transaction_a), result ({ 0, 0 }) @@ -1318,11 +1318,11 @@ class dependent_block_visitor : public nano::block_visitor } } nano::ledger const & ledger; - nano::transaction const & transaction; + nano::store::transaction const & transaction; std::array result; }; -std::array nano::ledger::dependent_blocks (nano::transaction const & transaction_a, nano::block const & block_a) const +std::array nano::ledger::dependent_blocks (store::transaction const & transaction_a, nano::block const & block_a) const { dependent_block_visitor visitor (*this, transaction_a); block_a.visit (visitor); @@ -1333,7 +1333,7 @@ std::array nano::ledger::dependent_blocks (nano::transactio * The send block hash is not checked in any way, it is assumed to be correct. * @return Return the receive block on success and null on failure */ -std::shared_ptr nano::ledger::find_receive_block_by_send_hash (nano::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash) +std::shared_ptr nano::ledger::find_receive_block_by_send_hash (store::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash) { std::shared_ptr result; debug_assert (send_block_hash != 0); @@ -1387,7 +1387,7 @@ nano::link const & nano::ledger::epoch_link (nano::epoch epoch_a) const return constants.epochs.link (epoch_a); } -void nano::ledger::update_account (nano::write_transaction const & transaction_a, nano::account const & account_a, nano::account_info const & old_a, nano::account_info const & new_a) +void nano::ledger::update_account (store::write_transaction const & transaction_a, nano::account const & account_a, nano::account_info const & old_a, nano::account_info const & new_a) { if (!new_a.head.is_zero ()) { @@ -1411,7 +1411,7 @@ void nano::ledger::update_account (nano::write_transaction const & transaction_a } } -std::shared_ptr nano::ledger::successor (nano::transaction const & transaction_a, nano::qualified_root const & root_a) +std::shared_ptr nano::ledger::successor (store::transaction const & transaction_a, nano::qualified_root const & root_a) { nano::block_hash successor (0); auto get_from_previous = false; @@ -1445,7 +1445,7 @@ std::shared_ptr nano::ledger::successor (nano::transaction const & return result; } -std::shared_ptr nano::ledger::forked_block (nano::transaction const & transaction_a, nano::block const & block_a) +std::shared_ptr nano::ledger::forked_block (store::transaction const & transaction_a, nano::block const & block_a) { debug_assert (!store.block.exists (transaction_a, block_a.hash ())); auto root (block_a.root ()); @@ -1461,7 +1461,7 @@ std::shared_ptr nano::ledger::forked_block (nano::transaction const return result; } -std::shared_ptr nano::ledger::head_block (nano::transaction const & transaction, nano::account const & account) +std::shared_ptr nano::ledger::head_block (store::transaction const & transaction, nano::account const & account) { auto info = store.account.get (transaction, account); if (info) @@ -1471,7 +1471,7 @@ std::shared_ptr nano::ledger::head_block (nano::transaction const & return nullptr; } -bool nano::ledger::block_confirmed (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const +bool nano::ledger::block_confirmed (store::transaction const & transaction_a, nano::block_hash const & hash_a) const { if (store.pruned.exists (transaction_a, hash_a)) { @@ -1488,7 +1488,7 @@ bool nano::ledger::block_confirmed (nano::transaction const & transaction_a, nan return false; } -uint64_t nano::ledger::pruning_action (nano::write_transaction & transaction_a, nano::block_hash const & hash_a, uint64_t const batch_size_a) +uint64_t nano::ledger::pruning_action (store::write_transaction & transaction_a, nano::block_hash const & hash_a, uint64_t const batch_size_a) { uint64_t pruned_count (0); nano::block_hash hash (hash_a); @@ -1526,7 +1526,7 @@ std::multimap> nano::ledger::unc nano::locked>> result; using result_t = decltype (result)::value_type; - store.account.for_each_par ([this, &result] (nano::read_transaction const & transaction_a, nano::store_iterator i, nano::store_iterator n) { + store.account.for_each_par ([this, &result] (store::read_transaction const & transaction_a, store::iterator i, store::iterator n) { result_t unconfirmed_frontiers_l; for (; i != n; ++i) { @@ -1571,7 +1571,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data if (!rocksdb_store->init_error ()) { store.block.for_each_par ( - [&rocksdb_store] (nano::read_transaction const & /*unused*/, auto i, auto n) { + [&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) { for (; i != n; ++i) { auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::blocks })); @@ -1587,7 +1587,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data }); store.pending.for_each_par ( - [&rocksdb_store] (nano::read_transaction const & /*unused*/, auto i, auto n) { + [&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) { for (; i != n; ++i) { auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::pending })); @@ -1596,7 +1596,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data }); store.confirmation_height.for_each_par ( - [&rocksdb_store] (nano::read_transaction const & /*unused*/, auto i, auto n) { + [&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) { for (; i != n; ++i) { auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::confirmation_height })); @@ -1605,7 +1605,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data }); store.account.for_each_par ( - [&rocksdb_store] (nano::read_transaction const & /*unused*/, auto i, auto n) { + [&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) { for (; i != n; ++i) { auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::accounts })); @@ -1614,7 +1614,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data }); store.frontier.for_each_par ( - [&rocksdb_store] (nano::read_transaction const & /*unused*/, auto i, auto n) { + [&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) { for (; i != n; ++i) { auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::frontiers })); @@ -1623,7 +1623,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data }); store.pruned.for_each_par ( - [&rocksdb_store] (nano::read_transaction const & /*unused*/, auto i, auto n) { + [&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) { for (; i != n; ++i) { auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::pruned })); @@ -1632,7 +1632,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data }); store.final_vote.for_each_par ( - [&rocksdb_store] (nano::read_transaction const & /*unused*/, auto i, auto n) { + [&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) { for (; i != n; ++i) { auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::final_votes })); @@ -1699,7 +1699,7 @@ nano::epoch nano::ledger::version (nano::block const & block) return nano::epoch::epoch_0; } -nano::epoch nano::ledger::version (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::epoch nano::ledger::version (store::transaction const & transaction, nano::block_hash const & hash) const { auto block = store.block.get (transaction, hash); if (block == nullptr) @@ -1709,7 +1709,7 @@ nano::epoch nano::ledger::version (nano::transaction const & transaction, nano:: return version (*block); } -uint64_t nano::ledger::height (nano::transaction const & transaction, nano::block_hash const & hash) const +uint64_t nano::ledger::height (store::transaction const & transaction, nano::block_hash const & hash) const { auto block = store.block.get (transaction, hash); return block->sideband ().height; diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index f26ed66961..d66e20241e 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -6,14 +6,16 @@ #include -namespace nano -{ -namespace store +namespace nano::store { - class component; +class component; +class transaction; +class write_transaction; } + +namespace nano +{ class stats; -class write_transaction; // map of vote weight per block, ordered greater first using tally_t = std::map, std::greater>; @@ -35,64 +37,64 @@ class ledger final * Return account containing hash, expects that block hash exists in ledger */ nano::account account (nano::block const & block) const; - nano::account account (nano::transaction const &, nano::block_hash const &) const; - std::optional account_info (nano::transaction const & transaction, nano::account const & account) const; + nano::account account (store::transaction const &, nano::block_hash const &) const; + std::optional account_info (store::transaction const & transaction, nano::account const & account) const; /** * For non-prunning nodes same as `ledger::account()` * For prunning nodes ensures that block hash exists, otherwise returns zero account */ - nano::account account_safe (nano::transaction const &, nano::block_hash const &, bool &) const; + nano::account account_safe (store::transaction const &, nano::block_hash const &, bool &) const; /** * Return account containing hash, returns zero account if account can not be found */ - nano::account account_safe (nano::transaction const &, nano::block_hash const &) const; - nano::uint128_t amount (nano::transaction const &, nano::account const &); - nano::uint128_t amount (nano::transaction const &, nano::block_hash const &); + nano::account account_safe (store::transaction const &, nano::block_hash const &) const; + nano::uint128_t amount (store::transaction const &, nano::account const &); + nano::uint128_t amount (store::transaction const &, nano::block_hash const &); /** Safe for previous block, but block hash_a must exist */ - nano::uint128_t amount_safe (nano::transaction const &, nano::block_hash const & hash_a, bool &) const; + nano::uint128_t amount_safe (store::transaction const &, nano::block_hash const & hash_a, bool &) const; static nano::uint128_t balance (nano::block const & block); - nano::uint128_t balance (nano::transaction const &, nano::block_hash const &) const; - nano::uint128_t balance_safe (nano::transaction const &, nano::block_hash const &, bool &) const; - nano::uint128_t account_balance (nano::transaction const &, nano::account const &, bool = false); - nano::uint128_t account_receivable (nano::transaction const &, nano::account const &, bool = false); + nano::uint128_t balance (store::transaction const &, nano::block_hash const &) const; + nano::uint128_t balance_safe (store::transaction const &, nano::block_hash const &, bool &) const; + nano::uint128_t account_balance (store::transaction const &, nano::account const &, bool = false); + nano::uint128_t account_receivable (store::transaction const &, nano::account const &, bool = false); nano::uint128_t weight (nano::account const &); - std::shared_ptr successor (nano::transaction const &, nano::qualified_root const &); - std::shared_ptr forked_block (nano::transaction const &, nano::block const &); - std::shared_ptr head_block (nano::transaction const &, nano::account const &); - bool block_confirmed (nano::transaction const &, nano::block_hash const &) const; - nano::block_hash latest (nano::transaction const &, nano::account const &); - nano::root latest_root (nano::transaction const &, nano::account const &); - nano::block_hash representative (nano::transaction const &, nano::block_hash const &); - nano::block_hash representative_calculated (nano::transaction const &, nano::block_hash const &); + std::shared_ptr successor (store::transaction const &, nano::qualified_root const &); + std::shared_ptr forked_block (store::transaction const &, nano::block const &); + std::shared_ptr head_block (store::transaction const &, nano::account const &); + bool block_confirmed (store::transaction const &, nano::block_hash const &) const; + nano::block_hash latest (store::transaction const &, nano::account const &); + nano::root latest_root (store::transaction const &, nano::account const &); + nano::block_hash representative (store::transaction const &, nano::block_hash const &); + nano::block_hash representative_calculated (store::transaction const &, nano::block_hash const &); bool block_or_pruned_exists (nano::block_hash const &) const; - bool block_or_pruned_exists (nano::transaction const &, nano::block_hash const &) const; - bool root_exists (nano::transaction const &, nano::root const &); + bool block_or_pruned_exists (store::transaction const &, nano::block_hash const &) const; + bool root_exists (store::transaction const &, nano::root const &); std::string block_text (char const *); std::string block_text (nano::block_hash const &); - bool is_send (nano::transaction const &, nano::block const &) const; - nano::account const & block_destination (nano::transaction const &, nano::block const &); - nano::block_hash block_source (nano::transaction const &, nano::block const &); - std::pair hash_root_random (nano::transaction const &) const; - std::optional pending_info (nano::transaction const & transaction, nano::pending_key const & key) const; - nano::process_return process (nano::write_transaction const &, nano::block &); - bool rollback (nano::write_transaction const &, nano::block_hash const &, std::vector> &); - bool rollback (nano::write_transaction const &, nano::block_hash const &); - void update_account (nano::write_transaction const &, nano::account const &, nano::account_info const &, nano::account_info const &); - uint64_t pruning_action (nano::write_transaction &, nano::block_hash const &, uint64_t const); + bool is_send (store::transaction const &, nano::block const &) const; + nano::account const & block_destination (store::transaction const &, nano::block const &); + nano::block_hash block_source (store::transaction const &, nano::block const &); + std::pair hash_root_random (store::transaction const &) const; + std::optional pending_info (store::transaction const & transaction, nano::pending_key const & key) const; + nano::process_return process (store::write_transaction const &, nano::block &); + bool rollback (store::write_transaction const &, nano::block_hash const &, std::vector> &); + bool rollback (store::write_transaction const &, nano::block_hash const &); + void update_account (store::write_transaction const &, nano::account const &, nano::account_info const &, nano::account_info const &); + uint64_t pruning_action (store::write_transaction &, nano::block_hash const &, uint64_t const); void dump_account_chain (nano::account const &, std::ostream & = std::cout); - bool could_fit (nano::transaction const &, nano::block const &) const; - bool dependents_confirmed (nano::transaction const &, nano::block const &) const; + bool could_fit (store::transaction const &, nano::block const &) const; + bool dependents_confirmed (store::transaction const &, nano::block const &) const; bool is_epoch_link (nano::link const &) const; - std::array dependent_blocks (nano::transaction const &, nano::block const &) const; - std::shared_ptr find_receive_block_by_send_hash (nano::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash); + std::array dependent_blocks (store::transaction const &, nano::block const &) const; + std::shared_ptr find_receive_block_by_send_hash (store::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash); nano::account const & epoch_signer (nano::link const &) const; nano::link const & epoch_link (nano::epoch) const; std::multimap> unconfirmed_frontiers () const; bool migrate_lmdb_to_rocksdb (boost::filesystem::path const &) const; bool bootstrap_weight_reached () const; static nano::epoch version (nano::block const & block); - nano::epoch version (nano::transaction const & transaction, nano::block_hash const & hash) const; - uint64_t height (nano::transaction const & transaction, nano::block_hash const & hash) const; + nano::epoch version (store::transaction const & transaction, nano::block_hash const & hash) const; + uint64_t height (store::transaction const & transaction, nano::block_hash const & hash) const; static nano::uint128_t const unit; nano::ledger_constants & constants; nano::store::component & store; diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 5cdc56baab..740383a83c 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -1017,7 +1017,7 @@ TEST (confirmation_height, dynamic_algorithm_no_transition_while_pending) std::vector> state_blocks; auto const num_blocks = nano::confirmation_height::unbounded_cutoff - 2; - auto add_block_to_genesis_chain = [&] (nano::write_transaction & transaction) { + auto add_block_to_genesis_chain = [&] (store::write_transaction & transaction) { static int num = 0; nano::block_builder builder; auto send = builder diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index aa48a3926b..f494624998 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -15,6 +15,7 @@ add_library( lmdb/db_val.hpp lmdb/final_vote.hpp lmdb/frontier.hpp + lmdb/iterator.hpp lmdb/lmdb.hpp lmdb/lmdb_env.hpp lmdb/iterator.hpp @@ -42,6 +43,7 @@ add_library( rocksdb/pending.hpp rocksdb/pruned.hpp rocksdb/rocksdb.hpp + rocksdb/iterator.hpp rocksdb/transaction_impl.hpp rocksdb/version.hpp tables.hpp diff --git a/nano/store/account.cpp b/nano/store/account.cpp index d08002c148..a3bb7a1970 100644 --- a/nano/store/account.cpp +++ b/nano/store/account.cpp @@ -1,6 +1,6 @@ #include -std::optional nano::account_store::get (nano::transaction const & transaction, nano::account const & account) +std::optional nano::store::account::get (store::transaction const & transaction, nano::account const & account) { nano::account_info info; bool error = get (transaction, account, info); diff --git a/nano/store/account.hpp b/nano/store/account.hpp index ad5da11e0b..1b6a35aa3c 100644 --- a/nano/store/account.hpp +++ b/nano/store/account.hpp @@ -13,24 +13,24 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { /** * Manages account storage and iteration */ -class account_store +class account { public: - virtual void put (nano::write_transaction const &, nano::account const &, nano::account_info const &) = 0; - virtual bool get (nano::transaction const &, nano::account const &, nano::account_info &) = 0; - std::optional get (nano::transaction const &, nano::account const &); - virtual void del (nano::write_transaction const &, nano::account const &) = 0; - virtual bool exists (nano::transaction const &, nano::account const &) = 0; - virtual size_t count (nano::transaction const &) = 0; - virtual nano::store_iterator begin (nano::transaction const &, nano::account const &) const = 0; - virtual nano::store_iterator begin (nano::transaction const &) const = 0; - virtual nano::store_iterator rbegin (nano::transaction const &) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const &) const = 0; + virtual void put (store::write_transaction const &, nano::account const &, nano::account_info const &) = 0; + virtual bool get (store::transaction const &, nano::account const &, nano::account_info &) = 0; + std::optional get (store::transaction const &, nano::account const &); + virtual void del (store::write_transaction const &, nano::account const &) = 0; + virtual bool exists (store::transaction const &, nano::account const &) = 0; + virtual size_t count (store::transaction const &) = 0; + virtual iterator begin (store::transaction const &, nano::account const &) const = 0; + virtual iterator begin (store::transaction const &) const = 0; + virtual iterator rbegin (store::transaction const &) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function, iterator)> const &) const = 0; }; } // namespace nano::store diff --git a/nano/store/block.hpp b/nano/store/block.hpp index b0059c96c3..459720886f 100644 --- a/nano/store/block.hpp +++ b/nano/store/block.hpp @@ -14,7 +14,7 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { class block_w_sideband { @@ -25,21 +25,21 @@ class block_w_sideband /** * Manages block storage and iteration */ -class block_store +class block { public: - virtual void put (nano::write_transaction const &, nano::block_hash const &, nano::block const &) = 0; - virtual void raw_put (nano::write_transaction const &, std::vector const &, nano::block_hash const &) = 0; - virtual nano::block_hash successor (nano::transaction const &, nano::block_hash const &) const = 0; - virtual void successor_clear (nano::write_transaction const &, nano::block_hash const &) = 0; - virtual std::shared_ptr get (nano::transaction const &, nano::block_hash const &) const = 0; - virtual std::shared_ptr random (nano::transaction const &) = 0; - virtual void del (nano::write_transaction const &, nano::block_hash const &) = 0; - virtual bool exists (nano::transaction const &, nano::block_hash const &) = 0; - virtual uint64_t count (nano::transaction const &) = 0; - virtual nano::store_iterator begin (nano::transaction const &, nano::block_hash const &) const = 0; - virtual nano::store_iterator begin (nano::transaction const &) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; + virtual void put (store::write_transaction const &, nano::block_hash const &, nano::block const &) = 0; + virtual void raw_put (store::write_transaction const &, std::vector const &, nano::block_hash const &) = 0; + virtual nano::block_hash successor (store::transaction const &, nano::block_hash const &) const = 0; + virtual void successor_clear (store::write_transaction const &, nano::block_hash const &) = 0; + virtual std::shared_ptr get (store::transaction const &, nano::block_hash const &) const = 0; + virtual std::shared_ptr random (store::transaction const &) = 0; + virtual void del (store::write_transaction const &, nano::block_hash const &) = 0; + virtual bool exists (store::transaction const &, nano::block_hash const &) = 0; + virtual uint64_t count (store::transaction const &) = 0; + virtual iterator begin (store::transaction const &, nano::block_hash const &) const = 0; + virtual iterator begin (store::transaction const &) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function, iterator)> const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/component.cpp b/nano/store/component.cpp index 03cd6716c2..cd68dc2a09 100644 --- a/nano/store/component.cpp +++ b/nano/store/component.cpp @@ -5,19 +5,7 @@ #include #include -// clang-format off -nano::store::component::component ( - nano::block_store & block_store_a, - nano::frontier_store & frontier_store_a, - nano::account_store & account_store_a, - nano::pending_store & pending_store_a, - nano::online_weight_store & online_weight_store_a, - nano::pruned_store & pruned_store_a, - nano::peer_store & peer_store_a, - nano::confirmation_height_store & confirmation_height_store_a, - nano::final_vote_store & final_vote_store_a, - nano::version_store & version_store_a -) : +nano::store::component::component (nano::store::block & block_store_a, nano::store::frontier & frontier_store_a, nano::store::account & account_store_a, nano::store::pending & pending_store_a, nano::store::online_weight & online_weight_store_a, nano::store::pruned & pruned_store_a, nano::store::peer & peer_store_a, nano::store::confirmation_height & confirmation_height_store_a, nano::store::final_vote & final_vote_store_a, nano::store::version & version_store_a) : block (block_store_a), frontier (frontier_store_a), account (account_store_a), @@ -30,13 +18,12 @@ nano::store::component::component ( version (version_store_a) { } -// clang-format on /** * If using a different store version than the latest then you may need * to modify some of the objects in the store to be appropriate for the version before an upgrade. */ -void nano::store::component::initialize (nano::write_transaction const & transaction_a, nano::ledger_cache & ledger_cache_a, nano::ledger_constants & constants) +void nano::store::component::initialize (store::write_transaction const & transaction_a, nano::ledger_cache & ledger_cache_a, nano::ledger_constants & constants) { debug_assert (constants.genesis->has_sideband ()); debug_assert (account.begin (transaction_a) == account.end ()); diff --git a/nano/store/component.hpp b/nano/store/component.hpp index e5ee585c0d..14bd7f21f2 100644 --- a/nano/store/component.hpp +++ b/nano/store/component.hpp @@ -15,17 +15,20 @@ namespace nano { -class account_store; -class block_store; -class confirmation_height_store; -class final_vote_store; -class frontier_store; +namespace store +{ + class account; + class block; + class confirmation_height; + class final_vote; + class frontier; + class online_weight; + class peer; + class pending; + class pruned; + class version; +} class ledger_cache; -class online_weight_store; -class peer_store; -class pending_store; -class pruned_store; -class version_store; namespace store { @@ -40,46 +43,46 @@ namespace store public: // clang-format off explicit component ( - nano::block_store &, - nano::frontier_store &, - nano::account_store &, - nano::pending_store &, - nano::online_weight_store &, - nano::pruned_store &, - nano::peer_store &, - nano::confirmation_height_store &, - nano::final_vote_store &, - nano::version_store & + nano::store::block &, + nano::store::frontier &, + nano::store::account &, + nano::store::pending &, + nano::store::online_weight&, + nano::store::pruned &, + nano::store::peer &, + nano::store::confirmation_height &, + nano::store::final_vote &, + nano::store::version & ); // clang-format on virtual ~component () = default; - void initialize (nano::write_transaction const & transaction_a, nano::ledger_cache & ledger_cache_a, nano::ledger_constants & constants); - virtual uint64_t count (nano::transaction const & transaction_a, tables table_a) const = 0; - virtual int drop (nano::write_transaction const & transaction_a, tables table_a) = 0; + void initialize (write_transaction const & transaction_a, nano::ledger_cache & ledger_cache_a, nano::ledger_constants & constants); + virtual uint64_t count (store::transaction const & transaction_a, tables table_a) const = 0; + virtual int drop (write_transaction const & transaction_a, tables table_a) = 0; virtual bool not_found (int status) const = 0; virtual bool success (int status) const = 0; virtual int status_code_not_found () const = 0; virtual std::string error_string (int status) const = 0; - block_store & block; - frontier_store & frontier; - account_store & account; - pending_store & pending; + store::block & block; + store::frontier & frontier; + store::account & account; + store::pending & pending; static int constexpr version_minimum{ 14 }; static int constexpr version_current{ 22 }; public: - online_weight_store & online_weight; - pruned_store & pruned; - peer_store & peer; - confirmation_height_store & confirmation_height; - final_vote_store & final_vote; - version_store & version; + store::online_weight & online_weight; + store::pruned & pruned; + store::peer & peer; + store::confirmation_height & confirmation_height; + store::final_vote & final_vote; + store::version & version; virtual unsigned max_block_write_batch_num () const = 0; virtual bool copy_db (boost::filesystem::path const & destination) = 0; - virtual void rebuild_db (nano::write_transaction const & transaction_a) = 0; + virtual void rebuild_db (write_transaction const & transaction_a) = 0; /** Not applicable to all sub-classes */ virtual void serialize_mdb_tracker (boost::property_tree::ptree &, std::chrono::milliseconds, std::chrono::milliseconds){}; @@ -88,10 +91,10 @@ namespace store virtual bool init_error () const = 0; /** Start read-write transaction */ - virtual nano::write_transaction tx_begin_write (std::vector const & tables_to_lock = {}, std::vector const & tables_no_lock = {}) = 0; + virtual write_transaction tx_begin_write (std::vector const & tables_to_lock = {}, std::vector const & tables_no_lock = {}) = 0; /** Start read-only transaction */ - virtual nano::read_transaction tx_begin_read () const = 0; + virtual read_transaction tx_begin_read () const = 0; virtual std::string vendor_get () const = 0; }; diff --git a/nano/store/confirmation_height.cpp b/nano/store/confirmation_height.cpp index 1398f73108..dae07d69c7 100644 --- a/nano/store/confirmation_height.cpp +++ b/nano/store/confirmation_height.cpp @@ -1,6 +1,6 @@ #include -std::optional nano::confirmation_height_store::get (nano::transaction const & transaction, nano::account const & account) +std::optional nano::store::confirmation_height::get (store::transaction const & transaction, nano::account const & account) { nano::confirmation_height_info info; bool error = get (transaction, account, info); diff --git a/nano/store/confirmation_height.hpp b/nano/store/confirmation_height.hpp index 2a35fb0785..07588c491e 100644 --- a/nano/store/confirmation_height.hpp +++ b/nano/store/confirmation_height.hpp @@ -13,31 +13,31 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { /** * Manages confirmation height storage and iteration */ -class confirmation_height_store +class confirmation_height { public: - virtual void put (nano::write_transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a) = 0; + virtual void put (store::write_transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a) = 0; /** Retrieves confirmation height info relating to an account. * The parameter confirmation_height_info_a is always written. * On error, the confirmation height and frontier hash are set to 0. * Ruturns true on error, false on success. */ - virtual bool get (nano::transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info & confirmation_height_info_a) = 0; - std::optional get (nano::transaction const & transaction_a, nano::account const & account_a); - virtual bool exists (nano::transaction const & transaction_a, nano::account const & account_a) const = 0; - virtual void del (nano::write_transaction const & transaction_a, nano::account const & account_a) = 0; - virtual uint64_t count (nano::transaction const & transaction_a) = 0; - virtual void clear (nano::write_transaction const &, nano::account const &) = 0; - virtual void clear (nano::write_transaction const &) = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a, nano::account const & account_a) const = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const &) const = 0; + virtual bool get (store::transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info & confirmation_height_info_a) = 0; + std::optional get (store::transaction const & transaction_a, nano::account const & account_a); + virtual bool exists (store::transaction const & transaction_a, nano::account const & account_a) const = 0; + virtual void del (store::write_transaction const & transaction_a, nano::account const & account_a) = 0; + virtual uint64_t count (store::transaction const & transaction_a) = 0; + virtual void clear (store::write_transaction const &, nano::account const &) = 0; + virtual void clear (store::write_transaction const &) = 0; + virtual iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const = 0; + virtual iterator begin (store::transaction const & transaction_a) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function, iterator)> const &) const = 0; }; } // namespace nano::store diff --git a/nano/store/db_val.hpp b/nano/store/db_val.hpp index 08da3834e3..182a8a18da 100644 --- a/nano/store/db_val.hpp +++ b/nano/store/db_val.hpp @@ -8,7 +8,7 @@ #include -namespace nano +namespace nano::store { /** * Encapsulates database specific container @@ -57,8 +57,8 @@ class db_val { } - db_val (nano::account_info_v14 const & val_a) : - db_val (val_a.db_size (), const_cast (&val_a)) + db_val (account_info_v14 const & val_a) : + db_val (val_a.db_size (), const_cast (&val_a)) { } @@ -68,10 +68,10 @@ class db_val static_assert (std::is_standard_layout::value, "Standard layout is required"); } - db_val (nano::pending_info_v14 const & val_a) : - db_val (val_a.db_size (), const_cast (&val_a)) + db_val (pending_info_v14 const & val_a) : + db_val (val_a.db_size (), const_cast (&val_a)) { - static_assert (std::is_standard_layout::value, "Standard layout is required"); + static_assert (std::is_standard_layout::value, "Standard layout is required"); } db_val (nano::pending_key const & val_a) : @@ -131,15 +131,15 @@ class db_val return result; } - explicit operator nano::account_info_v14 () const + explicit operator account_info_v14 () const { - nano::account_info_v14 result; + account_info_v14 result; debug_assert (size () == result.db_size ()); std::copy (reinterpret_cast (data ()), reinterpret_cast (data ()) + result.db_size (), reinterpret_cast (&result)); return result; } - explicit operator nano::block_info () const + explicit operator block_info () const { nano::block_info result; debug_assert (size () == sizeof (result)); @@ -148,9 +148,9 @@ class db_val return result; } - explicit operator nano::pending_info_v14 () const + explicit operator pending_info_v14 () const { - nano::pending_info_v14 result; + pending_info_v14 result; debug_assert (size () == result.db_size ()); std::copy (reinterpret_cast (data ()), reinterpret_cast (data ()) + result.db_size (), reinterpret_cast (&result)); return result; @@ -253,7 +253,7 @@ class db_val explicit operator block_w_sideband () const { nano::bufferstream stream (reinterpret_cast (data ()), size ()); - nano::block_w_sideband block_w_sideband; + nano::store::block_w_sideband block_w_sideband; block_w_sideband.block = (nano::deserialize_block (stream)); auto error = block_w_sideband.sideband.deserialize (stream, block_w_sideband.block->type ()); release_assert (!error); @@ -265,7 +265,7 @@ class db_val { nano::bufferstream stream (reinterpret_cast (data ()), size ()); auto error (false); - nano::state_block_w_sideband_v14 block_w_sideband; + state_block_w_sideband_v14 block_w_sideband; block_w_sideband.state_block = std::make_shared (error, stream); debug_assert (!error); @@ -378,4 +378,4 @@ class db_val return result; } }; -} // namespace nano +} // namespace nano::store diff --git a/nano/store/final.hpp b/nano/store/final.hpp index b51cbe4cf9..da7bc990c6 100644 --- a/nano/store/final.hpp +++ b/nano/store/final.hpp @@ -13,23 +13,23 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { /** * Manages final vote storage and iteration */ -class final_vote_store +class final_vote { public: - virtual bool put (nano::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) = 0; - virtual std::vector get (nano::transaction const & transaction_a, nano::root const & root_a) = 0; - virtual void del (nano::write_transaction const & transaction_a, nano::root const & root_a) = 0; - virtual size_t count (nano::transaction const & transaction_a) const = 0; - virtual void clear (nano::write_transaction const &, nano::root const &) = 0; - virtual void clear (nano::write_transaction const &) = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; + virtual bool put (store::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) = 0; + virtual std::vector get (store::transaction const & transaction_a, nano::root const & root_a) = 0; + virtual void del (store::write_transaction const & transaction_a, nano::root const & root_a) = 0; + virtual size_t count (store::transaction const & transaction_a) const = 0; + virtual void clear (store::write_transaction const &, nano::root const &) = 0; + virtual void clear (store::write_transaction const &) = 0; + virtual store::iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0; + virtual store::iterator begin (store::transaction const & transaction_a) const = 0; + virtual store::iterator end () const = 0; + virtual void for_each_par (std::function, store::iterator)> const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/frontier.hpp b/nano/store/frontier.hpp index 56eb8d2563..0405cf9fbe 100644 --- a/nano/store/frontier.hpp +++ b/nano/store/frontier.hpp @@ -13,20 +13,20 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { /** * Manages frontier storage and iteration */ -class frontier_store +class frontier { public: - virtual void put (nano::write_transaction const &, nano::block_hash const &, nano::account const &) = 0; - virtual nano::account get (nano::transaction const &, nano::block_hash const &) const = 0; - virtual void del (nano::write_transaction const &, nano::block_hash const &) = 0; - virtual nano::store_iterator begin (nano::transaction const &) const = 0; - virtual nano::store_iterator begin (nano::transaction const &, nano::block_hash const &) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; + virtual void put (store::write_transaction const &, nano::block_hash const &, nano::account const &) = 0; + virtual nano::account get (store::transaction const &, nano::block_hash const &) const = 0; + virtual void del (store::write_transaction const &, nano::block_hash const &) = 0; + virtual iterator begin (store::transaction const &) const = 0; + virtual iterator begin (store::transaction const &, nano::block_hash const &) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function, store::iterator)> const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/iterator.hpp b/nano/store/iterator.hpp index bf88b5861c..00f2ab7f93 100644 --- a/nano/store/iterator.hpp +++ b/nano/store/iterator.hpp @@ -4,62 +4,62 @@ #include -namespace nano +namespace nano::store { /** * Iterates the key/value pairs of a transaction */ template -class store_iterator final +class iterator final { public: - store_iterator (std::nullptr_t) + iterator (std::nullptr_t) { } - store_iterator (std::unique_ptr> impl_a) : + iterator (std::unique_ptr> impl_a) : impl (std::move (impl_a)) { impl->fill (current); } - store_iterator (nano::store_iterator && other_a) : + iterator (iterator && other_a) : current (std::move (other_a.current)), impl (std::move (other_a.impl)) { } - nano::store_iterator & operator++ () + iterator & operator++ () { ++*impl; impl->fill (current); return *this; } - nano::store_iterator & operator-- () + iterator & operator-- () { --*impl; impl->fill (current); return *this; } - nano::store_iterator & operator= (nano::store_iterator && other_a) noexcept + iterator & operator= (iterator && other_a) noexcept { impl = std::move (other_a.impl); current = std::move (other_a.current); return *this; } - nano::store_iterator & operator= (nano::store_iterator const &) = delete; + iterator & operator= (iterator const &) = delete; std::pair * operator-> () { return ¤t; } - bool operator== (nano::store_iterator const & other_a) const + bool operator== (iterator const & other_a) const { return (impl == nullptr && other_a.impl == nullptr) || (impl != nullptr && *impl == other_a.impl.get ()) || (other_a.impl != nullptr && *other_a.impl == impl.get ()); } - bool operator!= (nano::store_iterator const & other_a) const + bool operator!= (iterator const & other_a) const { return !(*this == other_a); } private: std::pair current; - std::unique_ptr> impl; + std::unique_ptr> impl; }; } // namespace nano::store diff --git a/nano/store/iterator_impl.hpp b/nano/store/iterator_impl.hpp index 16e958ef14..0f873e976b 100644 --- a/nano/store/iterator_impl.hpp +++ b/nano/store/iterator_impl.hpp @@ -2,24 +2,24 @@ #include -namespace nano +namespace nano::store { template -class store_iterator_impl +class iterator_impl { public: - virtual ~store_iterator_impl () = default; - virtual nano::store_iterator_impl & operator++ () = 0; - virtual nano::store_iterator_impl & operator-- () = 0; - virtual bool operator== (nano::store_iterator_impl const & other_a) const = 0; + virtual ~iterator_impl () = default; + virtual iterator_impl & operator++ () = 0; + virtual iterator_impl & operator-- () = 0; + virtual bool operator== (iterator_impl const & other_a) const = 0; virtual bool is_end_sentinal () const = 0; virtual void fill (std::pair &) const = 0; - nano::store_iterator_impl & operator= (nano::store_iterator_impl const &) = delete; - bool operator== (nano::store_iterator_impl const * other_a) const + iterator_impl & operator= (iterator_impl const &) = delete; + bool operator== (iterator_impl const * other_a) const { return (other_a != nullptr && *this == *other_a) || (other_a == nullptr && is_end_sentinal ()); } - bool operator!= (nano::store_iterator_impl const & other_a) const + bool operator!= (iterator_impl const & other_a) const { return !(*this == other_a); } diff --git a/nano/store/lmdb/account.cpp b/nano/store/lmdb/account.cpp index e890cae690..19a35c8e44 100644 --- a/nano/store/lmdb/account.cpp +++ b/nano/store/lmdb/account.cpp @@ -1,19 +1,20 @@ #include #include +#include #include -nano::lmdb::account_store::account_store (nano::lmdb::store & store_a) : +nano::store::lmdb::account::account (nano::store::lmdb::component & store_a) : store (store_a){}; -void nano::lmdb::account_store::put (nano::write_transaction const & transaction, nano::account const & account, nano::account_info const & info) +void nano::store::lmdb::account::put (store::write_transaction const & transaction, nano::account const & account, nano::account_info const & info) { auto status = store.put (transaction, tables::accounts, account, info); store.release_assert_success (status); } -bool nano::lmdb::account_store::get (nano::transaction const & transaction, nano::account const & account, nano::account_info & info) +bool nano::store::lmdb::account::get (store::transaction const & transaction, nano::account const & account, nano::account_info & info) { - nano::mdb_val value; + nano::store::lmdb::db_val value; auto status1 (store.get (transaction, tables::accounts, account, value)); release_assert (store.success (status1) || store.not_found (status1)); bool result (true); @@ -25,44 +26,44 @@ bool nano::lmdb::account_store::get (nano::transaction const & transaction, nano return result; } -void nano::lmdb::account_store::del (nano::write_transaction const & transaction_a, nano::account const & account_a) +void nano::store::lmdb::account::del (store::write_transaction const & transaction_a, nano::account const & account_a) { auto status = store.del (transaction_a, tables::accounts, account_a); store.release_assert_success (status); } -bool nano::lmdb::account_store::exists (nano::transaction const & transaction_a, nano::account const & account_a) +bool nano::store::lmdb::account::exists (store::transaction const & transaction_a, nano::account const & account_a) { auto iterator (begin (transaction_a, account_a)); return iterator != end () && nano::account (iterator->first) == account_a; } -size_t nano::lmdb::account_store::count (nano::transaction const & transaction_a) +size_t nano::store::lmdb::account::count (store::transaction const & transaction_a) { return store.count (transaction_a, tables::accounts); } -nano::store_iterator nano::lmdb::account_store::begin (nano::transaction const & transaction, nano::account const & account) const +nano::store::iterator nano::store::lmdb::account::begin (store::transaction const & transaction, nano::account const & account) const { return store.make_iterator (transaction, tables::accounts, account); } -nano::store_iterator nano::lmdb::account_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::lmdb::account::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::accounts); } -nano::store_iterator nano::lmdb::account_store::rbegin (nano::transaction const & transaction_a) const +nano::store::iterator nano::store::lmdb::account::rbegin (store::transaction const & transaction_a) const { return store.make_iterator (transaction_a, tables::accounts, false); } -nano::store_iterator nano::lmdb::account_store::end () const +nano::store::iterator nano::store::lmdb::account::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::lmdb::account_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::lmdb::account::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/account.hpp b/nano/store/lmdb/account.hpp index d15c2ce887..9c3284b482 100644 --- a/nano/store/lmdb/account.hpp +++ b/nano/store/lmdb/account.hpp @@ -4,52 +4,52 @@ #include -namespace nano +namespace nano::store::lmdb { -namespace lmdb +class component; +} +namespace nano::store::lmdb +{ +class account : public nano::store::account { - class store; - class account_store : public nano::account_store - { - private: - nano::lmdb::store & store; - - public: - explicit account_store (nano::lmdb::store & store_a); - void put (nano::write_transaction const & transaction, nano::account const & account, nano::account_info const & info) override; - bool get (nano::transaction const & transaction_a, nano::account const & account_a, nano::account_info & info_a) override; - void del (nano::write_transaction const & transaction_a, nano::account const & account_a) override; - bool exists (nano::transaction const & transaction_a, nano::account const & account_a) override; - size_t count (nano::transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::account const & account_a) const override; - nano::store_iterator begin (nano::transaction const & transaction_a) const override; - nano::store_iterator rbegin (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; - - /** +private: + nano::store::lmdb::component & store; + +public: + explicit account (nano::store::lmdb::component & store_a); + void put (store::write_transaction const & transaction, nano::account const & account, nano::account_info const & info) override; + bool get (store::transaction const & transaction_a, nano::account const & account_a, nano::account_info & info_a) override; + void del (store::write_transaction const & transaction_a, nano::account const & account_a) override; + bool exists (store::transaction const & transaction_a, nano::account const & account_a) override; + size_t count (store::transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator rbegin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; + + /** * Maps account v1 to account information, head, rep, open, balance, timestamp and block count. (Removed) * nano::account -> nano::block_hash, nano::block_hash, nano::block_hash, nano::amount, uint64_t, uint64_t */ - MDB_dbi accounts_v0_handle{ 0 }; + MDB_dbi accounts_v0_handle{ 0 }; - /** + /** * Maps account v0 to account information, head, rep, open, balance, timestamp and block count. (Removed) * nano::account -> nano::block_hash, nano::block_hash, nano::block_hash, nano::amount, uint64_t, uint64_t */ - MDB_dbi accounts_v1_handle{ 0 }; + MDB_dbi accounts_v1_handle{ 0 }; - /** + /** * Maps account v0 to account information, head, rep, open, balance, timestamp, block count and epoch * nano::account -> nano::block_hash, nano::block_hash, nano::block_hash, nano::amount, uint64_t, uint64_t, nano::epoch */ - MDB_dbi accounts_handle{ 0 }; + MDB_dbi accounts_handle{ 0 }; - /** + /** * Representative weights. (Removed) * nano::account -> nano::uint128_t */ - MDB_dbi representation_handle{ 0 }; - }; -} -} + MDB_dbi representation_handle{ 0 }; +}; +} // amespace nano::store::lmdb diff --git a/nano/store/lmdb/block.cpp b/nano/store/lmdb/block.cpp index affb70e8af..e01d71fb21 100644 --- a/nano/store/lmdb/block.cpp +++ b/nano/store/lmdb/block.cpp @@ -2,7 +2,7 @@ #include #include -namespace nano +namespace nano::store::lmdb { /** * Fill in our predecessors @@ -10,7 +10,7 @@ namespace nano class block_predecessor_mdb_set : public nano::block_visitor { public: - block_predecessor_mdb_set (nano::write_transaction const & transaction_a, nano::lmdb::block_store & block_store_a); + block_predecessor_mdb_set (store::write_transaction const & transaction_a, nano::store::lmdb::block & block_store_a); virtual ~block_predecessor_mdb_set () = default; void fill_value (nano::block const & block_a); void send_block (nano::send_block const & block_a) override; @@ -18,15 +18,15 @@ class block_predecessor_mdb_set : public nano::block_visitor void open_block (nano::open_block const & block_a) override; void change_block (nano::change_block const & block_a) override; void state_block (nano::state_block const & block_a) override; - nano::write_transaction const & transaction; - nano::lmdb::block_store & block_store; + store::write_transaction const & transaction; + nano::store::lmdb::block & block_store; }; } -nano::lmdb::block_store::block_store (nano::lmdb::store & store_a) : +nano::store::lmdb::block::block (nano::store::lmdb::component & store_a) : store{ store_a } {}; -void nano::lmdb::block_store::put (nano::write_transaction const & transaction, nano::block_hash const & hash, nano::block const & block) +void nano::store::lmdb::block::put (store::write_transaction const & transaction, nano::block_hash const & hash, nano::block const & block) { debug_assert (block.sideband ().successor.is_zero () || exists (transaction, block.sideband ().successor)); std::vector vector; @@ -41,16 +41,16 @@ void nano::lmdb::block_store::put (nano::write_transaction const & transaction, debug_assert (block.previous ().is_zero () || successor (transaction, block.previous ()) == hash); } -void nano::lmdb::block_store::raw_put (nano::write_transaction const & transaction_a, std::vector const & data, nano::block_hash const & hash_a) +void nano::store::lmdb::block::raw_put (store::write_transaction const & transaction_a, std::vector const & data, nano::block_hash const & hash_a) { - nano::mdb_val value{ data.size (), (void *)data.data () }; + nano::store::lmdb::db_val value{ data.size (), (void *)data.data () }; auto status = store.put (transaction_a, tables::blocks, hash_a, value); store.release_assert_success (status); } -nano::block_hash nano::lmdb::block_store::successor (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const +nano::block_hash nano::store::lmdb::block::successor (store::transaction const & transaction_a, nano::block_hash const & hash_a) const { - nano::mdb_val value; + nano::store::lmdb::db_val value; block_raw_get (transaction_a, hash_a, value); nano::block_hash result; if (value.size () != 0) @@ -69,9 +69,9 @@ nano::block_hash nano::lmdb::block_store::successor (nano::transaction const & t return result; } -void nano::lmdb::block_store::successor_clear (nano::write_transaction const & transaction, nano::block_hash const & hash) +void nano::store::lmdb::block::successor_clear (store::write_transaction const & transaction, nano::block_hash const & hash) { - nano::mdb_val value; + nano::store::lmdb::db_val value; block_raw_get (transaction, hash, value); debug_assert (value.size () != 0); auto type = block_type_from_raw (value.data ()); @@ -80,9 +80,9 @@ void nano::lmdb::block_store::successor_clear (nano::write_transaction const & t raw_put (transaction, data, hash); } -std::shared_ptr nano::lmdb::block_store::get (nano::transaction const & transaction, nano::block_hash const & hash) const +std::shared_ptr nano::store::lmdb::block::get (store::transaction const & transaction, nano::block_hash const & hash) const { - nano::mdb_val value; + nano::store::lmdb::db_val value; block_raw_get (transaction, hash, value); std::shared_ptr result; if (value.size () != 0) @@ -101,7 +101,7 @@ std::shared_ptr nano::lmdb::block_store::get (nano::transaction con return result; } -std::shared_ptr nano::lmdb::block_store::random (nano::transaction const & transaction) +std::shared_ptr nano::store::lmdb::block::random (store::transaction const & transaction) { nano::block_hash hash; nano::random_pool::generate_block (hash.bytes.data (), hash.bytes.size ()); @@ -114,40 +114,39 @@ std::shared_ptr nano::lmdb::block_store::random (nano::transaction return existing->second.block; } -void nano::lmdb::block_store::del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) +void nano::store::lmdb::block::del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) { auto status = store.del (transaction_a, tables::blocks, hash_a); store.release_assert_success (status); } -bool nano::lmdb::block_store::exists (nano::transaction const & transaction, nano::block_hash const & hash) +bool nano::store::lmdb::block::exists (store::transaction const & transaction, nano::block_hash const & hash) { - nano::mdb_val junk; + nano::store::lmdb::db_val junk; block_raw_get (transaction, hash, junk); return junk.size () != 0; } -uint64_t nano::lmdb::block_store::count (nano::transaction const & transaction_a) +uint64_t nano::store::lmdb::block::count (store::transaction const & transaction_a) { return store.count (transaction_a, tables::blocks); } - -nano::store_iterator nano::lmdb::block_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::lmdb::block::begin (store::transaction const & transaction) const { - return store.make_iterator (transaction, tables::blocks); + return store.make_iterator (transaction, tables::blocks); } -nano::store_iterator nano::lmdb::block_store::begin (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::store::iterator nano::store::lmdb::block::begin (store::transaction const & transaction, nano::block_hash const & hash) const { - return store.make_iterator (transaction, tables::blocks, hash); + return store.make_iterator (transaction, tables::blocks, hash); } -nano::store_iterator nano::lmdb::block_store::end () const +nano::store::iterator nano::store::lmdb::block::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::lmdb::block_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::lmdb::block::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { @@ -156,32 +155,32 @@ void nano::lmdb::block_store::for_each_par (std::function ((reinterpret_cast (data_a))[0]); } -nano::block_predecessor_mdb_set::block_predecessor_mdb_set (nano::write_transaction const & transaction_a, nano::lmdb::block_store & block_store_a) : +nano::store::lmdb::block_predecessor_mdb_set::block_predecessor_mdb_set (store::write_transaction const & transaction_a, nano::store::lmdb::block & block_store_a) : transaction{ transaction_a }, block_store{ block_store_a } { } -void nano::block_predecessor_mdb_set::fill_value (nano::block const & block_a) +void nano::store::lmdb::block_predecessor_mdb_set::fill_value (nano::block const & block_a) { auto hash = block_a.hash (); - nano::mdb_val value; + nano::store::lmdb::db_val value; block_store.block_raw_get (transaction, block_a.previous (), value); debug_assert (value.size () != 0); auto type = block_store.block_type_from_raw (value.data ()); @@ -189,23 +188,23 @@ void nano::block_predecessor_mdb_set::fill_value (nano::block const & block_a) std::copy (hash.bytes.begin (), hash.bytes.end (), data.begin () + block_store.block_successor_offset (transaction, value.size (), type)); block_store.raw_put (transaction, data, block_a.previous ()); } -void nano::block_predecessor_mdb_set::send_block (nano::send_block const & block_a) +void nano::store::lmdb::block_predecessor_mdb_set::send_block (nano::send_block const & block_a) { fill_value (block_a); } -void nano::block_predecessor_mdb_set::receive_block (nano::receive_block const & block_a) +void nano::store::lmdb::block_predecessor_mdb_set::receive_block (nano::receive_block const & block_a) { fill_value (block_a); } -void nano::block_predecessor_mdb_set::open_block (nano::open_block const & block_a) +void nano::store::lmdb::block_predecessor_mdb_set::open_block (nano::open_block const & block_a) { // Open blocks don't have a predecessor } -void nano::block_predecessor_mdb_set::change_block (nano::change_block const & block_a) +void nano::store::lmdb::block_predecessor_mdb_set::change_block (nano::change_block const & block_a) { fill_value (block_a); } -void nano::block_predecessor_mdb_set::state_block (nano::state_block const & block_a) +void nano::store::lmdb::block_predecessor_mdb_set::state_block (nano::state_block const & block_a) { if (!block_a.previous ().is_zero ()) { diff --git a/nano/store/lmdb/block.hpp b/nano/store/lmdb/block.hpp index cb1df35109..0dfdb3362f 100644 --- a/nano/store/lmdb/block.hpp +++ b/nano/store/lmdb/block.hpp @@ -5,91 +5,94 @@ #include -namespace nano +namespace nano::store::lmdb { class block_predecessor_mdb_set; -namespace lmdb +} +namespace nano::store::lmdb +{ +class component; +} +namespace nano::store::lmdb { - class store; - class block_store : public nano::block_store - { - friend class nano::block_predecessor_mdb_set; - nano::lmdb::store & store; +class block : public nano::store::block +{ + friend class block_predecessor_mdb_set; + nano::store::lmdb::component & store; - public: - explicit block_store (nano::lmdb::store & store_a); - void put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a, nano::block const & block_a) override; - void raw_put (nano::write_transaction const & transaction_a, std::vector const & data, nano::block_hash const & hash_a) override; - nano::block_hash successor (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - void successor_clear (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; - std::shared_ptr get (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - std::shared_ptr random (nano::transaction const & transaction_a) override; - void del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; - bool exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) override; - uint64_t count (nano::transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a) const override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - nano::store_iterator end () const override; - void for_each_par (std::function, nano::store_iterator)> const & action_a) const override; +public: + explicit block (nano::store::lmdb::component & store_a); + void put (store::write_transaction const & transaction_a, nano::block_hash const & hash_a, nano::block const & block_a) override; + void raw_put (store::write_transaction const & transaction_a, std::vector const & data, nano::block_hash const & hash_a) override; + nano::block_hash successor (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + void successor_clear (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; + std::shared_ptr get (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + std::shared_ptr random (store::transaction const & transaction_a) override; + void del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; + bool exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) override; + uint64_t count (store::transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; - /** + /** * Maps block hash to send block. (Removed) * nano::block_hash -> nano::send_block */ - MDB_dbi send_blocks_handle{ 0 }; + MDB_dbi send_blocks_handle{ 0 }; - /** + /** * Maps block hash to receive block. (Removed) * nano::block_hash -> nano::receive_block */ - MDB_dbi receive_blocks_handle{ 0 }; + MDB_dbi receive_blocks_handle{ 0 }; - /** + /** * Maps block hash to open block. (Removed) * nano::block_hash -> nano::open_block */ - MDB_dbi open_blocks_handle{ 0 }; + MDB_dbi open_blocks_handle{ 0 }; - /** + /** * Maps block hash to change block. (Removed) * nano::block_hash -> nano::change_block */ - MDB_dbi change_blocks_handle{ 0 }; + MDB_dbi change_blocks_handle{ 0 }; - /** + /** * Maps block hash to v0 state block. (Removed) * nano::block_hash -> nano::state_block */ - MDB_dbi state_blocks_v0_handle{ 0 }; + MDB_dbi state_blocks_v0_handle{ 0 }; - /** + /** * Maps block hash to v1 state block. (Removed) * nano::block_hash -> nano::state_block */ - MDB_dbi state_blocks_v1_handle{ 0 }; + MDB_dbi state_blocks_v1_handle{ 0 }; - /** + /** * Maps block hash to state block. (Removed) * nano::block_hash -> nano::state_block */ - MDB_dbi state_blocks_handle{ 0 }; + MDB_dbi state_blocks_handle{ 0 }; - /** + /** * Meta information about block store, such as versions. * nano::uint256_union (arbitrary key) -> blob */ - MDB_dbi meta_handle{ 0 }; + MDB_dbi meta_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 */ - MDB_dbi blocks_handle{ 0 }; + MDB_dbi blocks_handle{ 0 }; - protected: - void block_raw_get (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::mdb_val & value) const; - size_t block_successor_offset (nano::transaction const & transaction_a, size_t entry_size_a, nano::block_type type_a) const; - static nano::block_type block_type_from_raw (void * data_a); - }; -} -} +protected: + void block_raw_get (store::transaction const & transaction_a, nano::block_hash const & hash_a, db_val & value) const; + size_t block_successor_offset (store::transaction const & transaction_a, size_t entry_size_a, nano::block_type type_a) const; + static nano::block_type block_type_from_raw (void * data_a); +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/confirmation_height.cpp b/nano/store/lmdb/confirmation_height.cpp index 97617bf463..1ce01edab4 100644 --- a/nano/store/lmdb/confirmation_height.cpp +++ b/nano/store/lmdb/confirmation_height.cpp @@ -2,20 +2,20 @@ #include #include -nano::lmdb::confirmation_height_store::confirmation_height_store (nano::lmdb::store & store) : +nano::store::lmdb::confirmation_height::confirmation_height (nano::store::lmdb::component & store) : store{ store } { } -void nano::lmdb::confirmation_height_store::put (nano::write_transaction const & transaction, nano::account const & account, nano::confirmation_height_info const & confirmation_height_info) +void nano::store::lmdb::confirmation_height::put (store::write_transaction const & transaction, nano::account const & account, nano::confirmation_height_info const & confirmation_height_info) { auto status = store.put (transaction, tables::confirmation_height, account, confirmation_height_info); store.release_assert_success (status); } -bool nano::lmdb::confirmation_height_store::get (nano::transaction const & transaction, nano::account const & account, nano::confirmation_height_info & confirmation_height_info) +bool nano::store::lmdb::confirmation_height::get (store::transaction const & transaction, nano::account const & account, nano::confirmation_height_info & confirmation_height_info) { - nano::mdb_val value; + nano::store::lmdb::db_val value; auto status = store.get (transaction, tables::confirmation_height, account, value); release_assert (store.success (status) || store.not_found (status)); bool result (true); @@ -33,48 +33,48 @@ bool nano::lmdb::confirmation_height_store::get (nano::transaction const & trans return result; } -bool nano::lmdb::confirmation_height_store::exists (nano::transaction const & transaction, nano::account const & account) const +bool nano::store::lmdb::confirmation_height::exists (store::transaction const & transaction, nano::account const & account) const { return store.exists (transaction, tables::confirmation_height, account); } -void nano::lmdb::confirmation_height_store::del (nano::write_transaction const & transaction, nano::account const & account) +void nano::store::lmdb::confirmation_height::del (store::write_transaction const & transaction, nano::account const & account) { auto status = store.del (transaction, tables::confirmation_height, account); store.release_assert_success (status); } -uint64_t nano::lmdb::confirmation_height_store::count (nano::transaction const & transaction_a) +uint64_t nano::store::lmdb::confirmation_height::count (store::transaction const & transaction_a) { return store.count (transaction_a, tables::confirmation_height); } -void nano::lmdb::confirmation_height_store::clear (nano::write_transaction const & transaction_a, nano::account const & account_a) +void nano::store::lmdb::confirmation_height::clear (store::write_transaction const & transaction_a, nano::account const & account_a) { del (transaction_a, account_a); } -void nano::lmdb::confirmation_height_store::clear (nano::write_transaction const & transaction_a) +void nano::store::lmdb::confirmation_height::clear (store::write_transaction const & transaction_a) { store.drop (transaction_a, nano::tables::confirmation_height); } -nano::store_iterator nano::lmdb::confirmation_height_store::begin (nano::transaction const & transaction, nano::account const & account) const +nano::store::iterator nano::store::lmdb::confirmation_height::begin (store::transaction const & transaction, nano::account const & account) const { return store.make_iterator (transaction, tables::confirmation_height, account); } -nano::store_iterator nano::lmdb::confirmation_height_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::lmdb::confirmation_height::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::confirmation_height); } -nano::store_iterator nano::lmdb::confirmation_height_store::end () const +nano::store::iterator nano::store::lmdb::confirmation_height::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::lmdb::confirmation_height_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::lmdb::confirmation_height::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/confirmation_height.hpp b/nano/store/lmdb/confirmation_height.hpp index ff29a4eae8..738c8482c6 100644 --- a/nano/store/lmdb/confirmation_height.hpp +++ b/nano/store/lmdb/confirmation_height.hpp @@ -4,34 +4,34 @@ #include -namespace nano +namespace nano::store::lmdb { -namespace lmdb +class component; +} +namespace nano::store::lmdb +{ +class confirmation_height : public nano::store::confirmation_height { - class store; - class confirmation_height_store : public nano::confirmation_height_store - { - nano::lmdb::store & store; + nano::store::lmdb::component & store; - public: - explicit confirmation_height_store (nano::lmdb::store & store_a); - void put (nano::write_transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a) override; - bool get (nano::transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info & confirmation_height_info_a) override; - bool exists (nano::transaction const & transaction_a, nano::account const & account_a) const override; - void del (nano::write_transaction const & transaction_a, nano::account const & account_a) override; - uint64_t count (nano::transaction const & transaction_a) override; - void clear (nano::write_transaction const & transaction_a, nano::account const & account_a) override; - void clear (nano::write_transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::account const & account_a) const override; - 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; +public: + explicit confirmation_height (nano::store::lmdb::component & store_a); + void put (store::write_transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a) override; + bool get (store::transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info & confirmation_height_info_a) override; + bool exists (store::transaction const & transaction_a, nano::account const & account_a) const override; + void del (store::write_transaction const & transaction_a, nano::account const & account_a) override; + uint64_t count (store::transaction const & transaction_a) override; + void clear (store::write_transaction const & transaction_a, nano::account const & account_a) override; + void clear (store::write_transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + void for_each_par (std::function, 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 }; - }; -} -} + MDB_dbi confirmation_height_handle{ 0 }; +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/db_val.cpp b/nano/store/lmdb/db_val.cpp index c0a100abb6..7896bbaa5e 100644 --- a/nano/store/lmdb/db_val.cpp +++ b/nano/store/lmdb/db_val.cpp @@ -1,28 +1,25 @@ #include -namespace nano -{ template <> -void * mdb_val::data () const +void * nano::store::lmdb::db_val::data () const { return value.mv_data; } template <> -std::size_t mdb_val::size () const +std::size_t nano::store::lmdb::db_val::size () const { return value.mv_size; } template <> -mdb_val::db_val (std::size_t size_a, void * data_a) : +nano::store::lmdb::db_val::db_val (std::size_t size_a, void * data_a) : value ({ size_a, data_a }) { } template <> -void mdb_val::convert_buffer_to_value () +void nano::store::lmdb::db_val::convert_buffer_to_value () { value = { buffer->size (), const_cast (buffer->data ()) }; } -} diff --git a/nano/store/lmdb/db_val.hpp b/nano/store/lmdb/db_val.hpp index 5638103c18..3b4966f5c7 100644 --- a/nano/store/lmdb/db_val.hpp +++ b/nano/store/lmdb/db_val.hpp @@ -4,7 +4,7 @@ #include -namespace nano +namespace nano::store::lmdb { -using mdb_val = db_val; +using db_val = store::db_val; } diff --git a/nano/store/lmdb/final_vote.cpp b/nano/store/lmdb/final_vote.cpp index 9e6f14e94f..2ae93bd5a9 100644 --- a/nano/store/lmdb/final_vote.cpp +++ b/nano/store/lmdb/final_vote.cpp @@ -2,12 +2,12 @@ #include #include -nano::lmdb::final_vote_store::final_vote_store (nano::lmdb::store & store) : +nano::store::lmdb::final_vote::final_vote (nano::store::lmdb::component & store) : store{ store } {}; -bool nano::lmdb::final_vote_store::put (nano::write_transaction const & transaction, nano::qualified_root const & root, nano::block_hash const & hash) +bool nano::store::lmdb::final_vote::put (store::write_transaction const & transaction, nano::qualified_root const & root, nano::block_hash const & hash) { - nano::mdb_val value; + nano::store::lmdb::db_val value; auto status = store.get (transaction, tables::final_votes, root, value); release_assert (store.success (status) || store.not_found (status)); bool result (true); @@ -23,7 +23,7 @@ bool nano::lmdb::final_vote_store::put (nano::write_transaction const & transact return result; } -std::vector nano::lmdb::final_vote_store::get (nano::transaction const & transaction, nano::root const & root_a) +std::vector nano::store::lmdb::final_vote::get (store::transaction const & transaction, nano::root const & root_a) { std::vector result; nano::qualified_root key_start{ root_a.raw, 0 }; @@ -34,7 +34,7 @@ std::vector nano::lmdb::final_vote_store::get (nano::transacti return result; } -void nano::lmdb::final_vote_store::del (nano::write_transaction const & transaction, nano::root const & root) +void nano::store::lmdb::final_vote::del (store::write_transaction const & transaction, nano::root const & root) { std::vector final_vote_qualified_roots; for (auto i = begin (transaction, nano::qualified_root{ root.raw, 0 }), n = end (); i != n && nano::qualified_root{ i->first }.root () == root; ++i) @@ -49,37 +49,37 @@ void nano::lmdb::final_vote_store::del (nano::write_transaction const & transact } } -size_t nano::lmdb::final_vote_store::count (nano::transaction const & transaction_a) const +size_t nano::store::lmdb::final_vote::count (store::transaction const & transaction_a) const { return store.count (transaction_a, tables::final_votes); } -void nano::lmdb::final_vote_store::clear (nano::write_transaction const & transaction_a, nano::root const & root_a) +void nano::store::lmdb::final_vote::clear (store::write_transaction const & transaction_a, nano::root const & root_a) { del (transaction_a, root_a); } -void nano::lmdb::final_vote_store::clear (nano::write_transaction const & transaction_a) +void nano::store::lmdb::final_vote::clear (store::write_transaction const & transaction_a) { store.drop (transaction_a, nano::tables::final_votes); } -nano::store_iterator nano::lmdb::final_vote_store::begin (nano::transaction const & transaction, nano::qualified_root const & root) const +nano::store::iterator nano::store::lmdb::final_vote::begin (store::transaction const & transaction, nano::qualified_root const & root) const { return store.make_iterator (transaction, tables::final_votes, root); } -nano::store_iterator nano::lmdb::final_vote_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::lmdb::final_vote::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::final_votes); } -nano::store_iterator nano::lmdb::final_vote_store::end () const +nano::store::iterator nano::store::lmdb::final_vote::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::lmdb::final_vote_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::lmdb::final_vote::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint512_t const & start, nano::uint512_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/final_vote.hpp b/nano/store/lmdb/final_vote.hpp index 40bdfdb406..b7c06c62fd 100644 --- a/nano/store/lmdb/final_vote.hpp +++ b/nano/store/lmdb/final_vote.hpp @@ -4,34 +4,34 @@ #include -namespace nano +namespace nano::store::lmdb { -namespace lmdb +class component; +} +namespace nano::store::lmdb +{ +class final_vote : public nano::store::final_vote { - class store; - class final_vote_store : public nano::final_vote_store - { - private: - nano::lmdb::store & store; +private: + nano::store::lmdb::component & store; - public: - explicit final_vote_store (nano::lmdb::store & store); - bool put (nano::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) override; - std::vector get (nano::transaction const & transaction_a, nano::root const & root_a) override; - void del (nano::write_transaction const & transaction_a, nano::root const & root_a) override; - size_t count (nano::transaction const & transaction_a) const override; - void clear (nano::write_transaction const & transaction_a, nano::root const & root_a) override; - void clear (nano::write_transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::qualified_root const & root_a) const override; - 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; +public: + explicit final_vote (nano::store::lmdb::component & store); + bool put (store::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) override; + std::vector get (store::transaction const & transaction_a, nano::root const & root_a) override; + void del (store::write_transaction const & transaction_a, nano::root const & root_a) override; + size_t count (store::transaction const & transaction_a) const override; + void clear (store::write_transaction const & transaction_a, nano::root const & root_a) override; + void clear (store::write_transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; - /** + /** * Maps root to block hash for generated final votes. * nano::qualified_root -> nano::block_hash */ - MDB_dbi final_votes_handle{ 0 }; - }; -} -} + MDB_dbi final_votes_handle{ 0 }; +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/frontier.cpp b/nano/store/lmdb/frontier.cpp index ed541b7b1d..8b694a3ef4 100644 --- a/nano/store/lmdb/frontier.cpp +++ b/nano/store/lmdb/frontier.cpp @@ -2,20 +2,20 @@ #include #include -nano::lmdb::frontier_store::frontier_store (nano::lmdb::store & store) : +nano::store::lmdb::frontier::frontier (nano::store::lmdb::component & store) : store{ store } { } -void nano::lmdb::frontier_store::put (nano::write_transaction const & transaction, nano::block_hash const & hash, nano::account const & account) +void nano::store::lmdb::frontier::put (store::write_transaction const & transaction, nano::block_hash const & hash, nano::account const & account) { auto status = store.put (transaction, tables::frontiers, hash, account); store.release_assert_success (status); } -nano::account nano::lmdb::frontier_store::get (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::account nano::store::lmdb::frontier::get (store::transaction const & transaction, nano::block_hash const & hash) const { - nano::db_val value; + store::db_val value; auto status = store.get (transaction, tables::frontiers, hash, value); release_assert (store.success (status) || store.not_found (status)); nano::account result{}; @@ -26,28 +26,28 @@ nano::account nano::lmdb::frontier_store::get (nano::transaction const & transac return result; } -void nano::lmdb::frontier_store::del (nano::write_transaction const & transaction, nano::block_hash const & hash) +void nano::store::lmdb::frontier::del (store::write_transaction const & transaction, nano::block_hash const & hash) { auto status = store.del (transaction, tables::frontiers, hash); store.release_assert_success (status); } -nano::store_iterator nano::lmdb::frontier_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::lmdb::frontier::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::frontiers); } -nano::store_iterator nano::lmdb::frontier_store::begin (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::store::iterator nano::store::lmdb::frontier::begin (store::transaction const & transaction, nano::block_hash const & hash) const { - return store.make_iterator (transaction, tables::frontiers, nano::db_val (hash)); + return store.make_iterator (transaction, tables::frontiers, store::db_val (hash)); } -nano::store_iterator nano::lmdb::frontier_store::end () const +nano::store::iterator nano::store::lmdb::frontier::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::lmdb::frontier_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::lmdb::frontier::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/frontier.hpp b/nano/store/lmdb/frontier.hpp index b8af5b2f23..6bf71068bf 100644 --- a/nano/store/lmdb/frontier.hpp +++ b/nano/store/lmdb/frontier.hpp @@ -4,31 +4,31 @@ #include -namespace nano +namespace nano::store::lmdb { -namespace lmdb +class component; +} +namespace nano::store::lmdb +{ +class frontier : public nano::store::frontier { - class store; - class frontier_store : public nano::frontier_store - { - private: - nano::lmdb::store & store; +private: + nano::store::lmdb::component & store; - public: - frontier_store (nano::lmdb::store & store); - void put (nano::write_transaction const &, nano::block_hash const &, nano::account const &) override; - nano::account get (nano::transaction const &, nano::block_hash const &) const override; - void del (nano::write_transaction const &, nano::block_hash const &) override; - nano::store_iterator begin (nano::transaction const &) const override; - nano::store_iterator begin (nano::transaction const &, nano::block_hash const &) const override; - nano::store_iterator end () const override; - void for_each_par (std::function, nano::store_iterator)> const & action_a) const override; +public: + frontier (nano::store::lmdb::component & store); + void put (store::write_transaction const &, nano::block_hash const &, nano::account const &) override; + nano::account get (store::transaction const &, nano::block_hash const &) const override; + void del (store::write_transaction const &, nano::block_hash const &) override; + store::iterator begin (store::transaction const &) const override; + store::iterator begin (store::transaction const &, nano::block_hash const &) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; - /** + /** * Maps head block to owning account * nano::block_hash -> nano::account */ - MDB_dbi frontiers_handle{ 0 }; - }; -} -} + MDB_dbi frontiers_handle{ 0 }; +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/iterator.hpp b/nano/store/lmdb/iterator.hpp index bf1fe9b32a..9a9addf3ff 100644 --- a/nano/store/lmdb/iterator.hpp +++ b/nano/store/lmdb/iterator.hpp @@ -3,16 +3,17 @@ #include #include #include +#include #include -namespace nano +namespace nano::store::lmdb { template -class mdb_iterator : public store_iterator_impl +class iterator : public iterator_impl { public: - mdb_iterator (nano::transaction const & transaction_a, MDB_dbi db_a, MDB_val const & val_a = MDB_val{}, bool const direction_asc = true) + iterator (store::transaction const & transaction_a, MDB_dbi db_a, MDB_val const & val_a = MDB_val{}, bool const direction_asc = true) { auto status (mdb_cursor_open (tx (transaction_a), db_a, &cursor)); release_assert (status == 0); @@ -42,18 +43,18 @@ class mdb_iterator : public store_iterator_impl } } - mdb_iterator () = default; + iterator () = default; - mdb_iterator (nano::mdb_iterator && other_a) + iterator (nano::store::lmdb::iterator && other_a) { cursor = other_a.cursor; other_a.cursor = nullptr; current = other_a.current; } - mdb_iterator (nano::mdb_iterator const &) = delete; + iterator (nano::store::lmdb::iterator const &) = delete; - ~mdb_iterator () + ~iterator () { if (cursor != nullptr) { @@ -61,7 +62,7 @@ class mdb_iterator : public store_iterator_impl } } - nano::store_iterator_impl & operator++ () override + store::iterator_impl & operator++ () override { debug_assert (cursor != nullptr); auto status (mdb_cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_NEXT)); @@ -77,7 +78,7 @@ class mdb_iterator : public store_iterator_impl return *this; } - nano::store_iterator_impl & operator-- () override + store::iterator_impl & operator-- () override { debug_assert (cursor != nullptr); auto status (mdb_cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_PREV)); @@ -93,14 +94,14 @@ class mdb_iterator : public store_iterator_impl return *this; } - std::pair, nano::db_val> * operator-> () + std::pair, store::db_val> * operator-> () { return ¤t; } - bool operator== (nano::mdb_iterator const & base_a) const + bool operator== (nano::store::lmdb::iterator const & base_a) const { - auto const other_a (boost::polymorphic_downcast const *> (&base_a)); + auto const other_a (boost::polymorphic_downcast const *> (&base_a)); auto result (current.first.data () == other_a->current.first.data ()); debug_assert (!result || (current.first.size () == other_a->current.first.size ())); debug_assert (!result || (current.second.data () == other_a->current.second.data ())); @@ -108,9 +109,9 @@ class mdb_iterator : public store_iterator_impl return result; } - bool operator== (nano::store_iterator_impl const & base_a) const override + bool operator== (store::iterator_impl const & base_a) const override { - auto const other_a (boost::polymorphic_downcast const *> (&base_a)); + auto const other_a (boost::polymorphic_downcast const *> (&base_a)); auto result (current.first.data () == other_a->current.first.data ()); debug_assert (!result || (current.first.size () == other_a->current.first.size ())); debug_assert (!result || (current.second.data () == other_a->current.second.data ())); @@ -143,12 +144,12 @@ class mdb_iterator : public store_iterator_impl } void clear () { - current.first = nano::db_val (); - current.second = nano::db_val (); + current.first = store::db_val (); + current.second = store::db_val (); debug_assert (is_end_sentinal ()); } - nano::mdb_iterator & operator= (nano::mdb_iterator && other_a) + nano::store::lmdb::iterator & operator= (nano::store::lmdb::iterator && other_a) { if (cursor != nullptr) { @@ -161,12 +162,12 @@ class mdb_iterator : public store_iterator_impl return *this; } - nano::store_iterator_impl & operator= (nano::store_iterator_impl const &) = delete; + store::iterator_impl & operator= (store::iterator_impl const &) = delete; MDB_cursor * cursor{ nullptr }; - std::pair, nano::db_val> current; + std::pair, store::db_val> current; private: - MDB_txn * tx (nano::transaction const & transaction_a) const + MDB_txn * tx (store::transaction const & transaction_a) const { return static_cast (transaction_a.get_handle ()); } @@ -176,66 +177,66 @@ class mdb_iterator : public store_iterator_impl * Iterates the key/value pairs of two stores merged together */ template -class mdb_merge_iterator : public store_iterator_impl +class merge_iterator : public iterator_impl { public: - mdb_merge_iterator (nano::transaction const & transaction_a, MDB_dbi db1_a, MDB_dbi db2_a) : - impl1 (std::make_unique> (transaction_a, db1_a)), - impl2 (std::make_unique> (transaction_a, db2_a)) + merge_iterator (store::transaction const & transaction_a, MDB_dbi db1_a, MDB_dbi db2_a) : + impl1 (std::make_unique> (transaction_a, db1_a)), + impl2 (std::make_unique> (transaction_a, db2_a)) { } - mdb_merge_iterator () : - impl1 (std::make_unique> ()), - impl2 (std::make_unique> ()) + merge_iterator () : + impl1 (std::make_unique> ()), + impl2 (std::make_unique> ()) { } - mdb_merge_iterator (nano::transaction const & transaction_a, MDB_dbi db1_a, MDB_dbi db2_a, MDB_val const & val_a) : - impl1 (std::make_unique> (transaction_a, db1_a, val_a)), - impl2 (std::make_unique> (transaction_a, db2_a, val_a)) + merge_iterator (store::transaction const & transaction_a, MDB_dbi db1_a, MDB_dbi db2_a, MDB_val const & val_a) : + impl1 (std::make_unique> (transaction_a, db1_a, val_a)), + impl2 (std::make_unique> (transaction_a, db2_a, val_a)) { } - mdb_merge_iterator (nano::mdb_merge_iterator && other_a) + merge_iterator (merge_iterator && other_a) { impl1 = std::move (other_a.impl1); impl2 = std::move (other_a.impl2); } - mdb_merge_iterator (nano::mdb_merge_iterator const &) = delete; + merge_iterator (merge_iterator const &) = delete; - nano::store_iterator_impl & operator++ () override + store::iterator_impl & operator++ () override { ++least_iterator (); return *this; } - nano::store_iterator_impl & operator-- () override + store::iterator_impl & operator-- () override { --least_iterator (); return *this; } - std::pair, nano::db_val> * operator-> () + std::pair, store::db_val> * operator-> () { return least_iterator ().operator-> (); } - bool operator== (nano::mdb_merge_iterator const & other) const + bool operator== (merge_iterator const & other) const { return *impl1 == *other.impl1 && *impl2 == *other.impl2; } - bool operator!= (nano::mdb_merge_iterator const & base_a) const + bool operator!= (merge_iterator const & base_a) const { return !(*this == base_a); } - bool operator== (nano::store_iterator_impl const & base_a) const override + bool operator== (store::iterator_impl const & base_a) const override { - debug_assert ((dynamic_cast const *> (&base_a) != nullptr) && "Incompatible iterator comparison"); - auto & other (static_cast const &> (base_a)); + debug_assert ((dynamic_cast const *> (&base_a) != nullptr) && "Incompatible iterator comparison"); + auto & other (static_cast const &> (base_a)); return *this == other; } @@ -264,15 +265,15 @@ class mdb_merge_iterator : public store_iterator_impl value_a.second = U (); } } - nano::mdb_merge_iterator & operator= (nano::mdb_merge_iterator &&) = default; - nano::mdb_merge_iterator & operator= (nano::mdb_merge_iterator const &) = delete; + merge_iterator & operator= (merge_iterator &&) = default; + merge_iterator & operator= (merge_iterator const &) = delete; mutable bool from_first_database{ false }; private: - nano::mdb_iterator & least_iterator () const + nano::store::lmdb::iterator & least_iterator () const { - nano::mdb_iterator * result; + nano::store::lmdb::iterator * result; if (impl1->is_end_sentinal ()) { result = impl2.get (); @@ -307,7 +308,7 @@ class mdb_merge_iterator : public store_iterator_impl return *result; } - std::unique_ptr> impl1; - std::unique_ptr> impl2; + std::unique_ptr> impl1; + std::unique_ptr> impl2; }; } diff --git a/nano/store/lmdb/lmdb.cpp b/nano/store/lmdb/lmdb.cpp index ae84e0bb51..10bdff18cd 100644 --- a/nano/store/lmdb/lmdb.cpp +++ b/nano/store/lmdb/lmdb.cpp @@ -13,7 +13,7 @@ #include -nano::lmdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path const & path_a, nano::ledger_constants & constants, nano::txn_tracking_config const & txn_tracking_config_a, std::chrono::milliseconds block_processor_batch_max_time_a, nano::lmdb_config const & lmdb_config_a, bool backup_before_upgrade_a) : +nano::store::lmdb::component::component (nano::logger_mt & logger_a, boost::filesystem::path const & path_a, nano::ledger_constants & constants, nano::txn_tracking_config const & txn_tracking_config_a, std::chrono::milliseconds block_processor_batch_max_time_a, nano::lmdb_config const & lmdb_config_a, bool backup_before_upgrade_a) : // clang-format off nano::store::component{ block_store, @@ -39,7 +39,7 @@ nano::lmdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path co final_vote_store{ *this }, version_store{ *this }, logger (logger_a), - env (error, path_a, nano::mdb_env::options::make ().set_config (lmdb_config_a).set_use_no_mem_init (true)), + env (error, path_a, nano::store::lmdb::env::options::make ().set_config (lmdb_config_a).set_use_no_mem_init (true)), mdb_txn_tracker (logger_a, txn_tracking_config_a, block_processor_batch_max_time_a), txn_tracking_enabled (txn_tracking_config_a.enable) { @@ -98,7 +98,7 @@ nano::lmdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path co } } -bool nano::lmdb::store::vacuum_after_upgrade (boost::filesystem::path const & path_a, nano::lmdb_config const & lmdb_config_a) +bool nano::store::lmdb::component::vacuum_after_upgrade (boost::filesystem::path const & path_a, nano::lmdb_config const & lmdb_config_a) { // Vacuum the database. This is not a required step and may actually fail if there isn't enough storage space. auto vacuum_path = path_a.parent_path () / "vacuumed.ldb"; @@ -115,7 +115,7 @@ bool nano::lmdb::store::vacuum_after_upgrade (boost::filesystem::path const & pa boost::filesystem::rename (vacuum_path, path_a); // Set up the environment again - auto options = nano::mdb_env::options::make () + auto options = nano::store::lmdb::env::options::make () .set_config (lmdb_config_a) .set_use_no_mem_init (true); env.init (error, path_a, options); @@ -133,12 +133,12 @@ bool nano::lmdb::store::vacuum_after_upgrade (boost::filesystem::path const & pa return vacuum_success; } -void nano::lmdb::store::serialize_mdb_tracker (boost::property_tree::ptree & json, std::chrono::milliseconds min_read_time, std::chrono::milliseconds min_write_time) +void nano::store::lmdb::component::serialize_mdb_tracker (boost::property_tree::ptree & json, std::chrono::milliseconds min_read_time, std::chrono::milliseconds min_write_time) { mdb_txn_tracker.serialize_json (json, min_read_time, min_write_time); } -void nano::lmdb::store::serialize_memory_stats (boost::property_tree::ptree & json) +void nano::store::lmdb::component::serialize_memory_stats (boost::property_tree::ptree & json) { MDB_stat stats; auto status (mdb_env_stat (env.environment, &stats)); @@ -151,37 +151,37 @@ void nano::lmdb::store::serialize_memory_stats (boost::property_tree::ptree & js json.put ("page_size", stats.ms_psize); } -nano::write_transaction nano::lmdb::store::tx_begin_write (std::vector const &, std::vector const &) +nano::store::write_transaction nano::store::lmdb::component::tx_begin_write (std::vector const &, std::vector const &) { return env.tx_begin_write (create_txn_callbacks ()); } -nano::read_transaction nano::lmdb::store::tx_begin_read () const +nano::store::read_transaction nano::store::lmdb::component::tx_begin_read () const { return env.tx_begin_read (create_txn_callbacks ()); } -std::string nano::lmdb::store::vendor_get () const +std::string nano::store::lmdb::component::vendor_get () const { return boost::str (boost::format ("LMDB %1%.%2%.%3%") % MDB_VERSION_MAJOR % MDB_VERSION_MINOR % MDB_VERSION_PATCH); } -nano::mdb_txn_callbacks nano::lmdb::store::create_txn_callbacks () const +nano::store::lmdb::txn_callbacks nano::store::lmdb::component::create_txn_callbacks () const { - nano::mdb_txn_callbacks mdb_txn_callbacks; + nano::store::lmdb::txn_callbacks mdb_txn_callbacks; if (txn_tracking_enabled) { - mdb_txn_callbacks.txn_start = ([&mdb_txn_tracker = mdb_txn_tracker] (nano::transaction_impl const * transaction_impl) { + mdb_txn_callbacks.txn_start = ([&mdb_txn_tracker = mdb_txn_tracker] (store::transaction_impl const * transaction_impl) { mdb_txn_tracker.add (transaction_impl); }); - mdb_txn_callbacks.txn_end = ([&mdb_txn_tracker = mdb_txn_tracker] (nano::transaction_impl const * transaction_impl) { + mdb_txn_callbacks.txn_end = ([&mdb_txn_tracker = mdb_txn_tracker] (store::transaction_impl const * transaction_impl) { mdb_txn_tracker.erase (transaction_impl); }); } return mdb_txn_callbacks; } -void nano::lmdb::store::open_databases (bool & error_a, nano::transaction const & transaction_a, unsigned flags) +void nano::store::lmdb::component::open_databases (bool & error_a, store::transaction const & transaction_a, unsigned flags) { error_a |= mdb_dbi_open (env.tx (transaction_a), "frontiers", flags, &frontier_store.frontiers_handle) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "online_weight", flags, &online_weight_store.online_weight_handle) != 0; @@ -231,7 +231,7 @@ void nano::lmdb::store::open_databases (bool & error_a, nano::transaction const } } -bool nano::lmdb::store::do_upgrades (nano::write_transaction & transaction_a, nano::ledger_constants & constants, bool & needs_vacuuming) +bool nano::store::lmdb::component::do_upgrades (store::write_transaction & transaction_a, nano::ledger_constants & constants, bool & needs_vacuuming) { auto error (false); auto version_l = version.get (transaction_a); @@ -290,7 +290,7 @@ bool nano::lmdb::store::do_upgrades (nano::write_transaction & transaction_a, na return error; } -void nano::lmdb::store::upgrade_v14_to_v15 (nano::write_transaction & transaction_a) +void nano::store::lmdb::component::upgrade_v14_to_v15 (store::write_transaction & transaction_a) { logger.always_log ("Preparing v14 to v15 database upgrade..."); @@ -298,19 +298,19 @@ void nano::lmdb::store::upgrade_v14_to_v15 (nano::write_transaction & transactio upgrade_counters account_counters (count (transaction_a, account_store.accounts_v0_handle), count (transaction_a, account_store.accounts_v1_handle)); account_infos.reserve (account_counters.before_v0 + account_counters.before_v1); - nano::mdb_merge_iterator i_account (transaction_a, account_store.accounts_v0_handle, account_store.accounts_v1_handle); - nano::mdb_merge_iterator n_account{}; + nano::store::lmdb::merge_iterator i_account (transaction_a, account_store.accounts_v0_handle, account_store.accounts_v1_handle); + nano::store::lmdb::merge_iterator n_account{}; for (; i_account != n_account; ++i_account) { nano::account account (i_account->first); - nano::account_info_v14 account_info_v14 (i_account->second); + nano::store::account_info_v14 account_info_v14 (i_account->second); // Upgrade rep block to representative account auto rep_block = block_get_v14 (transaction_a, account_info_v14.rep_block); 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_store.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::store::lmdb::db_val (account), nano::store::lmdb::db_val (account_info_v14.confirmation_height), MDB_APPEND); i_account.from_first_database ? ++account_counters.after_v0 : ++account_counters.after_v1; } @@ -324,7 +324,7 @@ void nano::lmdb::store::upgrade_v14_to_v15 (nano::write_transaction & transactio for (auto const & account_account_info_pair : account_infos) { auto const & account_info (account_account_info_pair.second); - mdb_put (env.tx (transaction_a), account_store.accounts_handle, nano::mdb_val (account_account_info_pair.first), nano::mdb_val (account_info), MDB_APPEND); + mdb_put (env.tx (transaction_a), account_store.accounts_handle, nano::store::lmdb::db_val (account_account_info_pair.first), nano::store::lmdb::db_val (account_info), MDB_APPEND); } logger.always_log ("Epoch merge upgrade: Finished accounts, now doing state blocks"); @@ -337,16 +337,16 @@ void nano::lmdb::store::upgrade_v14_to_v15 (nano::write_transaction & transactio upgrade_counters state_counters (count (transaction_a, block_store.state_blocks_v0_handle), count (transaction_a, block_store.state_blocks_v1_handle)); - nano::mdb_merge_iterator i_state (transaction_a, block_store.state_blocks_v0_handle, block_store.state_blocks_v1_handle); - nano::mdb_merge_iterator n_state{}; + nano::store::lmdb::merge_iterator i_state (transaction_a, block_store.state_blocks_v0_handle, block_store.state_blocks_v1_handle); + nano::store::lmdb::merge_iterator n_state{}; auto num = 0u; for (; i_state != n_state; ++i_state, ++num) { nano::block_hash hash (i_state->first); - nano::state_block_w_sideband_v14 state_block_w_sideband_v14 (i_state->second); + nano::store::state_block_w_sideband_v14 state_block_w_sideband_v14 (i_state->second); auto & sideband_v14 = state_block_w_sideband_v14.sideband; - nano::block_sideband_v18 sideband (sideband_v14.account, sideband_v14.successor, sideband_v14.balance, sideband_v14.height, sideband_v14.timestamp, i_state.from_first_database ? nano::epoch::epoch_0 : nano::epoch::epoch_1, false, false, false); + nano::store::block_sideband_v18 sideband (sideband_v14.account, sideband_v14.successor, sideband_v14.balance, sideband_v14.height, sideband_v14.timestamp, i_state.from_first_database ? nano::epoch::epoch_0 : nano::epoch::epoch_1, false, false, false); // Write these out std::vector data; @@ -356,8 +356,8 @@ void nano::lmdb::store::upgrade_v14_to_v15 (nano::write_transaction & transactio sideband.serialize (stream, sideband_v14.type); } - nano::mdb_val value{ data.size (), (void *)data.data () }; - auto s = mdb_put (env.tx (transaction_a), state_blocks_new, nano::mdb_val (hash), value, MDB_APPEND); + nano::store::lmdb::db_val value{ data.size (), (void *)data.data () }; + auto s = mdb_put (env.tx (transaction_a), state_blocks_new, nano::store::lmdb::db_val (hash), value, MDB_APPEND); release_assert_success (s); // Every so often output to the log to indicate progress @@ -384,11 +384,11 @@ void nano::lmdb::store::upgrade_v14_to_v15 (nano::write_transaction & transactio std::vector> pending_infos; pending_infos.reserve (pending_counters.before_v0 + pending_counters.before_v1); - nano::mdb_merge_iterator i_pending (transaction_a, pending_store.pending_v0_handle, pending_store.pending_v1_handle); - nano::mdb_merge_iterator n_pending{}; + nano::store::lmdb::merge_iterator i_pending (transaction_a, pending_store.pending_v0_handle, pending_store.pending_v1_handle); + nano::store::lmdb::merge_iterator n_pending{}; for (; i_pending != n_pending; ++i_pending) { - nano::pending_info_v14 info (i_pending->second); + nano::store::pending_info_v14 info (i_pending->second); pending_infos.emplace_back (nano::pending_key (i_pending->first), nano::pending_info{ info.source, info.amount, i_pending.from_first_database ? nano::epoch::epoch_0 : nano::epoch::epoch_1 }); i_pending.from_first_database ? ++pending_counters.after_v0 : ++pending_counters.after_v1; } @@ -401,14 +401,14 @@ void nano::lmdb::store::upgrade_v14_to_v15 (nano::write_transaction & transactio for (auto const & pending_key_pending_info_pair : pending_infos) { - mdb_put (env.tx (transaction_a), pending_store.pending_handle, nano::mdb_val (pending_key_pending_info_pair.first), nano::mdb_val (pending_key_pending_info_pair.second), MDB_APPEND); + mdb_put (env.tx (transaction_a), pending_store.pending_handle, nano::store::lmdb::db_val (pending_key_pending_info_pair.first), nano::store::lmdb::db_val (pending_key_pending_info_pair.second), MDB_APPEND); } version.put (transaction_a, 15); logger.always_log ("Finished epoch merge upgrade"); } -void nano::lmdb::store::upgrade_v15_to_v16 (nano::write_transaction const & transaction_a) +void nano::store::lmdb::component::upgrade_v15_to_v16 (store::write_transaction const & transaction_a) { // Representation table is no longer used debug_assert (account_store.representation_handle != 0); @@ -421,7 +421,7 @@ void nano::lmdb::store::upgrade_v15_to_v16 (nano::write_transaction const & tran version.put (transaction_a, 16); } -void nano::lmdb::store::upgrade_v16_to_v17 (nano::write_transaction const & transaction_a) +void nano::store::lmdb::component::upgrade_v16_to_v17 (store::write_transaction const & transaction_a) { logger.always_log ("Preparing v16 to v17 database upgrade..."); @@ -431,7 +431,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_store.confirmation_height_handle), n (nano::mdb_iterator{}); i != n; ++i, ++account_info_i, ++num) + for (nano::store::lmdb::iterator i (transaction_a, confirmation_height_store.confirmation_height_handle), n (nano::store::lmdb::iterator{}); i != n; ++i, ++account_info_i, ++num) { nano::account account (i->first); uint64_t confirmation_height (i->second); @@ -493,23 +493,23 @@ void nano::lmdb::store::upgrade_v16_to_v17 (nano::write_transaction const & tran for (auto const & confirmation_height_info_pair : confirmation_height_infos) { - 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); + mdb_put (env.tx (transaction_a), confirmation_height_store.confirmation_height_handle, nano::store::lmdb::db_val (confirmation_height_info_pair.first), nano::store::lmdb::db_val (confirmation_height_info_pair.second), MDB_APPEND); } version.put (transaction_a, 17); logger.always_log ("Finished upgrading confirmation height frontiers"); } -void nano::lmdb::store::upgrade_v17_to_v18 (nano::write_transaction const & transaction_a, nano::ledger_constants & constants) +void nano::store::lmdb::component::upgrade_v17_to_v18 (store::write_transaction const & transaction_a, nano::ledger_constants & constants) { logger.always_log ("Preparing v17 to v18 database upgrade..."); auto count_pre (count (transaction_a, block_store.state_blocks_handle)); auto num = 0u; - for (nano::mdb_iterator> state_i (transaction_a, block_store.state_blocks_handle), state_n{}; state_i != state_n; ++state_i, ++num) + for (nano::store::lmdb::iterator> state_i (transaction_a, block_store.state_blocks_handle), state_n{}; state_i != state_n; ++state_i, ++num) { - nano::block_w_sideband_v18 block_w_sideband (state_i->second); + nano::store::block_w_sideband_v18 block_w_sideband (state_i->second); auto & block (block_w_sideband.block); auto & sideband (block_w_sideband.sideband); @@ -536,7 +536,7 @@ void nano::lmdb::store::upgrade_v17_to_v18 (nano::write_transaction const & tran is_receive = true; } - nano::block_sideband_v18 new_sideband (sideband.account, sideband.successor, sideband.balance, sideband.height, sideband.timestamp, sideband.details.epoch, is_send, is_receive, is_epoch); + nano::store::block_sideband_v18 new_sideband (sideband.account, sideband.successor, sideband.balance, sideband.height, sideband.timestamp, sideband.details.epoch, is_send, is_receive, is_epoch); // Write these out std::vector data; { @@ -544,7 +544,7 @@ void nano::lmdb::store::upgrade_v17_to_v18 (nano::write_transaction const & tran block->serialize (stream); new_sideband.serialize (stream, block->type ()); } - nano::mdb_val value{ data.size (), (void *)data.data () }; + nano::store::lmdb::db_val value{ data.size (), (void *)data.data () }; auto s = mdb_cursor_put (state_i.cursor, state_i->first, value, MDB_CURRENT); release_assert_success (s); @@ -563,33 +563,33 @@ void nano::lmdb::store::upgrade_v17_to_v18 (nano::write_transaction const & tran logger.always_log ("Finished upgrading the sideband"); } -void nano::lmdb::store::upgrade_v18_to_v19 (nano::write_transaction const & transaction_a) +void nano::store::lmdb::component::upgrade_v18_to_v19 (store::write_transaction const & transaction_a) { logger.always_log ("Preparing v18 to v19 database upgrade..."); auto count_pre (count (transaction_a, block_store.state_blocks_handle) + count (transaction_a, block_store.send_blocks_handle) + count (transaction_a, block_store.receive_blocks_handle) + count (transaction_a, block_store.change_blocks_handle) + count (transaction_a, block_store.open_blocks_handle)); // Combine in order of likeliness of counts - std::map legacy_open_receive_change_blocks; + std::map legacy_open_receive_change_blocks; - for (auto i (nano::store_iterator> (std::make_unique>> (transaction_a, block_store.change_blocks_handle))), n (nano::store_iterator> (nullptr)); i != n; ++i) + for (auto i (store::iterator> (std::make_unique>> (transaction_a, block_store.change_blocks_handle))), n (store::iterator> (nullptr)); i != n; ++i) { - nano::block_sideband_v18 const & old_sideband (i->second.sideband); + nano::store::block_sideband_v18 const & old_sideband (i->second.sideband); nano::block_sideband new_sideband (old_sideband.account, old_sideband.successor, old_sideband.balance, old_sideband.height, old_sideband.timestamp, nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0); - legacy_open_receive_change_blocks[i->first] = { nano::block_w_sideband{ i->second.block, new_sideband } }; + legacy_open_receive_change_blocks[i->first] = { nano::store::block_w_sideband{ i->second.block, new_sideband } }; } - for (auto i (nano::store_iterator> (std::make_unique>> (transaction_a, block_store.open_blocks_handle))), n (nano::store_iterator> (nullptr)); i != n; ++i) + for (auto i (store::iterator> (std::make_unique>> (transaction_a, block_store.open_blocks_handle))), n (store::iterator> (nullptr)); i != n; ++i) { - nano::block_sideband_v18 const & old_sideband (i->second.sideband); + nano::store::block_sideband_v18 const & old_sideband (i->second.sideband); nano::block_sideband new_sideband (old_sideband.account, old_sideband.successor, old_sideband.balance, old_sideband.height, old_sideband.timestamp, nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0); - legacy_open_receive_change_blocks[i->first] = { nano::block_w_sideband{ i->second.block, new_sideband } }; + legacy_open_receive_change_blocks[i->first] = { nano::store::block_w_sideband{ i->second.block, new_sideband } }; } - for (auto i (nano::store_iterator> (std::make_unique>> (transaction_a, block_store.receive_blocks_handle))), n (nano::store_iterator> (nullptr)); i != n; ++i) + for (auto i (store::iterator> (std::make_unique>> (transaction_a, block_store.receive_blocks_handle))), n (store::iterator> (nullptr)); i != n; ++i) { - nano::block_sideband_v18 const & old_sideband (i->second.sideband); + nano::store::block_sideband_v18 const & old_sideband (i->second.sideband); nano::block_sideband new_sideband (old_sideband.account, old_sideband.successor, old_sideband.balance, old_sideband.height, old_sideband.timestamp, nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0); - legacy_open_receive_change_blocks[i->first] = { nano::block_w_sideband{ i->second.block, new_sideband } }; + legacy_open_receive_change_blocks[i->first] = { nano::store::block_w_sideband{ i->second.block, new_sideband } }; } release_assert (!mdb_drop (env.tx (transaction_a), block_store.receive_blocks_handle, 1)); @@ -614,8 +614,8 @@ void nano::lmdb::store::upgrade_v18_to_v19 (nano::write_transaction const & tran legacy_block.second.sideband.serialize (stream, legacy_block.second.block->type ()); } - nano::mdb_val value{ data.size (), (void *)data.data () }; - auto s = mdb_put (env.tx (transaction_a), temp_legacy_open_receive_change_blocks, nano::mdb_val (legacy_block.first), value, MDB_APPEND); + nano::store::lmdb::db_val value{ data.size (), (void *)data.data () }; + auto s = mdb_put (env.tx (transaction_a), temp_legacy_open_receive_change_blocks, nano::store::lmdb::db_val (legacy_block.first), value, MDB_APPEND); release_assert_success (s); } } @@ -627,7 +627,7 @@ void nano::lmdb::store::upgrade_v18_to_v19 (nano::write_transaction const & tran { mdb_dbi_open (env.tx (transaction_a), "temp_legacy_send_blocks", MDB_CREATE, &temp_legacy_send_blocks); - for (auto i (nano::store_iterator> (std::make_unique>> (transaction_a, block_store.send_blocks_handle))), n (nano::store_iterator> (nullptr)); i != n; ++i) + for (auto i (store::iterator> (std::make_unique>> (transaction_a, block_store.send_blocks_handle))), n (store::iterator> (nullptr)); i != n; ++i) { auto const & block_w_sideband_v18 (i->second); @@ -638,8 +638,8 @@ void nano::lmdb::store::upgrade_v18_to_v19 (nano::write_transaction const & tran block_w_sideband_v18.sideband.serialize (stream, nano::block_type::send); // Equal to new version for legacy blocks } - nano::mdb_val value{ data.size (), (void *)data.data () }; - auto s = mdb_put (env.tx (transaction_a), temp_legacy_send_blocks, nano::mdb_val (i->first), value, MDB_APPEND); + nano::store::lmdb::db_val value{ data.size (), (void *)data.data () }; + auto s = mdb_put (env.tx (transaction_a), temp_legacy_send_blocks, nano::store::lmdb::db_val (i->first), value, MDB_APPEND); release_assert_success (s); } } @@ -653,11 +653,11 @@ void nano::lmdb::store::upgrade_v18_to_v19 (nano::write_transaction const & tran { mdb_dbi_open (env.tx (transaction_a), "temp_legacy_send_open_receive_change_blocks", MDB_CREATE, &temp_legacy_send_open_receive_change_blocks); - nano::mdb_merge_iterator i (transaction_a, temp_legacy_open_receive_change_blocks, temp_legacy_send_blocks); - nano::mdb_merge_iterator n{}; + nano::store::lmdb::merge_iterator i (transaction_a, temp_legacy_open_receive_change_blocks, temp_legacy_send_blocks); + nano::store::lmdb::merge_iterator n{}; for (; i != n; ++i) { - auto s = mdb_put (env.tx (transaction_a), temp_legacy_send_open_receive_change_blocks, nano::mdb_val (i->first), nano::mdb_val (i->second), MDB_APPEND); + auto s = mdb_put (env.tx (transaction_a), temp_legacy_send_open_receive_change_blocks, nano::store::lmdb::db_val (i->first), nano::store::lmdb::db_val (i->second), MDB_APPEND); release_assert_success (s); } @@ -674,10 +674,10 @@ void nano::lmdb::store::upgrade_v18_to_v19 (nano::write_transaction const & tran auto type_state (nano::block_type::state); mdb_dbi_open (env.tx (transaction_a), "temp_state_blocks", MDB_CREATE, &temp_state_blocks); - for (auto i (nano::store_iterator> (std::make_unique>> (transaction_a, block_store.state_blocks_handle))), n (nano::store_iterator> (nullptr)); i != n; ++i) + for (auto i (store::iterator> (std::make_unique>> (transaction_a, block_store.state_blocks_handle))), n (store::iterator> (nullptr)); i != n; ++i) { auto const & block_w_sideband_v18 (i->second); - nano::block_sideband_v18 const & old_sideband (block_w_sideband_v18.sideband); + nano::store::block_sideband_v18 const & old_sideband (block_w_sideband_v18.sideband); nano::epoch source_epoch (nano::epoch::epoch_0); // Source block v18 epoch if (old_sideband.details.is_receive) @@ -688,7 +688,7 @@ void nano::lmdb::store::upgrade_v18_to_v19 (nano::write_transaction const & tran nano::bufferstream stream (reinterpret_cast (db_val.get ().data ()), db_val.get ().size ()); auto source_block (nano::deserialize_block (stream, type_state)); release_assert (source_block != nullptr); - nano::block_sideband_v18 source_sideband; + nano::store::block_sideband_v18 source_sideband; auto error (source_sideband.deserialize (stream, type_state)); release_assert (!error); source_epoch = source_sideband.details.epoch; @@ -703,8 +703,8 @@ void nano::lmdb::store::upgrade_v18_to_v19 (nano::write_transaction const & tran new_sideband.serialize (stream, nano::block_type::state); } - nano::mdb_val value{ data.size (), (void *)data.data () }; - auto s = mdb_put (env.tx (transaction_a), temp_state_blocks, nano::mdb_val (i->first), value, MDB_APPEND); + nano::store::lmdb::db_val value{ data.size (), (void *)data.data () }; + auto s = mdb_put (env.tx (transaction_a), temp_state_blocks, nano::store::lmdb::db_val (i->first), value, MDB_APPEND); release_assert_success (s); } } @@ -715,12 +715,12 @@ void nano::lmdb::store::upgrade_v18_to_v19 (nano::write_transaction const & tran logger.always_log ("Merging all legacy blocks with state blocks"); // Merge all legacy blocks with state blocks into the final table - nano::mdb_merge_iterator i (transaction_a, temp_legacy_send_open_receive_change_blocks, temp_state_blocks); - nano::mdb_merge_iterator n{}; + nano::store::lmdb::merge_iterator i (transaction_a, temp_legacy_send_open_receive_change_blocks, temp_state_blocks); + nano::store::lmdb::merge_iterator n{}; mdb_dbi_open (env.tx (transaction_a), "blocks", MDB_CREATE, &block_store.blocks_handle); for (; i != n; ++i) { - auto s = mdb_put (env.tx (transaction_a), block_store.blocks_handle, nano::mdb_val (i->first), nano::mdb_val (i->second), MDB_APPEND); + auto s = mdb_put (env.tx (transaction_a), block_store.blocks_handle, nano::store::lmdb::db_val (i->first), nano::store::lmdb::db_val (i->second), MDB_APPEND); release_assert_success (s); } @@ -739,7 +739,7 @@ void nano::lmdb::store::upgrade_v18_to_v19 (nano::write_transaction const & tran logger.always_log ("Finished upgrading all blocks to new blocks database"); } -void nano::lmdb::store::upgrade_v19_to_v20 (nano::write_transaction const & transaction_a) +void nano::store::lmdb::component::upgrade_v19_to_v20 (store::write_transaction const & transaction_a) { logger.always_log ("Preparing v19 to v20 database upgrade..."); mdb_dbi_open (env.tx (transaction_a), "pruned", MDB_CREATE, &pruned_store.pruned_handle); @@ -747,7 +747,7 @@ void nano::lmdb::store::upgrade_v19_to_v20 (nano::write_transaction const & tran logger.always_log ("Finished creating new pruned table"); } -void nano::lmdb::store::upgrade_v20_to_v21 (nano::write_transaction const & transaction_a) +void nano::store::lmdb::component::upgrade_v20_to_v21 (store::write_transaction const & transaction_a) { logger.always_log ("Preparing v20 to v21 database upgrade..."); mdb_dbi_open (env.tx (transaction_a), "final_votes", MDB_CREATE, &final_vote_store.final_votes_handle); @@ -755,7 +755,7 @@ void nano::lmdb::store::upgrade_v20_to_v21 (nano::write_transaction const & tran logger.always_log ("Finished creating new final_vote table"); } -void nano::lmdb::store::upgrade_v21_to_v22 (nano::write_transaction const & transaction_a) +void nano::store::lmdb::component::upgrade_v21_to_v22 (store::write_transaction const & transaction_a) { logger.always_log ("Preparing v21 to v22 database upgrade..."); MDB_dbi unchecked_handle{ 0 }; @@ -766,7 +766,7 @@ void nano::lmdb::store::upgrade_v21_to_v22 (nano::write_transaction const & tran } /** Takes a filepath, appends '_backup_' to the end (but before any extension) and saves that file in the same directory */ -void nano::lmdb::store::create_backup_file (nano::mdb_env & env_a, boost::filesystem::path const & filepath_a, nano::logger_mt & logger_a) +void nano::store::lmdb::component::create_backup_file (nano::store::lmdb::env & env_a, boost::filesystem::path const & filepath_a, nano::logger_mt & logger_a) { auto extension = filepath_a.extension (); auto filename_without_extension = filepath_a.filename ().replace_extension (""); @@ -796,45 +796,45 @@ void nano::lmdb::store::create_backup_file (nano::mdb_env & env_a, boost::filesy } } -bool nano::lmdb::store::exists (nano::transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a) const +bool nano::store::lmdb::component::exists (store::transaction const & transaction_a, tables table_a, nano::store::lmdb::db_val const & key_a) const { - nano::mdb_val junk; + nano::store::lmdb::db_val junk; auto status = get (transaction_a, table_a, key_a, junk); release_assert (status == MDB_SUCCESS || status == MDB_NOTFOUND); return (status == MDB_SUCCESS); } -int nano::lmdb::store::get (nano::transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a, nano::mdb_val & value_a) const +int nano::store::lmdb::component::get (store::transaction const & transaction_a, tables table_a, nano::store::lmdb::db_val const & key_a, nano::store::lmdb::db_val & value_a) const { return mdb_get (env.tx (transaction_a), table_to_dbi (table_a), key_a, value_a); } -int nano::lmdb::store::put (nano::write_transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a, nano::mdb_val const & value_a) const +int nano::store::lmdb::component::put (store::write_transaction const & transaction_a, tables table_a, nano::store::lmdb::db_val const & key_a, nano::store::lmdb::db_val const & value_a) const { return (mdb_put (env.tx (transaction_a), table_to_dbi (table_a), key_a, value_a, 0)); } -int nano::lmdb::store::del (nano::write_transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a) const +int nano::store::lmdb::component::del (store::write_transaction const & transaction_a, tables table_a, nano::store::lmdb::db_val const & key_a) const { return (mdb_del (env.tx (transaction_a), table_to_dbi (table_a), key_a, nullptr)); } -int nano::lmdb::store::drop (nano::write_transaction const & transaction_a, tables table_a) +int nano::store::lmdb::component::drop (store::write_transaction const & transaction_a, tables table_a) { return clear (transaction_a, table_to_dbi (table_a)); } -int nano::lmdb::store::clear (nano::write_transaction const & transaction_a, MDB_dbi handle_a) +int nano::store::lmdb::component::clear (store::write_transaction const & transaction_a, MDB_dbi handle_a) { return mdb_drop (env.tx (transaction_a), handle_a, 0); } -uint64_t nano::lmdb::store::count (nano::transaction const & transaction_a, tables table_a) const +uint64_t nano::store::lmdb::component::count (store::transaction const & transaction_a, tables table_a) const { return count (transaction_a, table_to_dbi (table_a)); } -uint64_t nano::lmdb::store::count (nano::transaction const & transaction_a, MDB_dbi db_a) const +uint64_t nano::store::lmdb::component::count (store::transaction const & transaction_a, MDB_dbi db_a) const { MDB_stat stats; auto status (mdb_stat (env.tx (transaction_a), db_a, &stats)); @@ -842,7 +842,7 @@ uint64_t nano::lmdb::store::count (nano::transaction const & transaction_a, MDB_ return (stats.ms_entries); } -MDB_dbi nano::lmdb::store::table_to_dbi (tables table_a) const +MDB_dbi nano::store::lmdb::component::table_to_dbi (tables table_a) const { switch (table_a) { @@ -872,32 +872,32 @@ MDB_dbi nano::lmdb::store::table_to_dbi (tables table_a) const } } -bool nano::lmdb::store::not_found (int status) const +bool nano::store::lmdb::component::not_found (int status) const { return (status_code_not_found () == status); } -bool nano::lmdb::store::success (int status) const +bool nano::store::lmdb::component::success (int status) const { return (MDB_SUCCESS == status); } -int nano::lmdb::store::status_code_not_found () const +int nano::store::lmdb::component::status_code_not_found () const { return MDB_NOTFOUND; } -std::string nano::lmdb::store::error_string (int status) const +std::string nano::store::lmdb::component::error_string (int status) const { return mdb_strerror (status); } -bool nano::lmdb::store::copy_db (boost::filesystem::path const & destination_file) +bool nano::store::lmdb::component::copy_db (boost::filesystem::path const & destination_file) { return !mdb_env_copy2 (env.environment, destination_file.string ().c_str (), MDB_CP_COMPACT); } -void nano::lmdb::store::rebuild_db (nano::write_transaction const & transaction_a) +void nano::store::lmdb::component::rebuild_db (store::write_transaction const & transaction_a) { // Tables with uint256_union key std::vector tables = { account_store.accounts_handle, block_store.blocks_handle, pruned_store.pruned_handle, confirmation_height_store.confirmation_height_handle }; @@ -906,18 +906,18 @@ void nano::lmdb::store::rebuild_db (nano::write_transaction const & transaction_ MDB_dbi temp; mdb_dbi_open (env.tx (transaction_a), "temp_table", MDB_CREATE, &temp); // Copy all values to temporary table - for (auto i (nano::store_iterator (std::make_unique> (transaction_a, table))), n (nano::store_iterator (nullptr)); i != n; ++i) + for (auto i (store::iterator (std::make_unique> (transaction_a, table))), n (store::iterator (nullptr)); i != n; ++i) { - auto s = mdb_put (env.tx (transaction_a), temp, nano::mdb_val (i->first), i->second, MDB_APPEND); + auto s = mdb_put (env.tx (transaction_a), temp, nano::store::lmdb::db_val (i->first), i->second, MDB_APPEND); release_assert_success (s); } release_assert (count (transaction_a, table) == count (transaction_a, temp)); // Clear existing table mdb_drop (env.tx (transaction_a), table, 0); // Put values from copy - for (auto i (nano::store_iterator (std::make_unique> (transaction_a, temp))), n (nano::store_iterator (nullptr)); i != n; ++i) + for (auto i (store::iterator (std::make_unique> (transaction_a, temp))), n (store::iterator (nullptr)); i != n; ++i) { - auto s = mdb_put (env.tx (transaction_a), table, nano::mdb_val (i->first), i->second, MDB_APPEND); + auto s = mdb_put (env.tx (transaction_a), table, nano::store::lmdb::db_val (i->first), i->second, MDB_APPEND); release_assert_success (s); } release_assert (count (transaction_a, table) == count (transaction_a, temp)); @@ -929,17 +929,17 @@ void nano::lmdb::store::rebuild_db (nano::write_transaction const & transaction_ MDB_dbi temp; mdb_dbi_open (env.tx (transaction_a), "temp_table", MDB_CREATE, &temp); // Copy all values to temporary table - for (auto i (nano::store_iterator (std::make_unique> (transaction_a, pending_store.pending_handle))), n (nano::store_iterator (nullptr)); i != n; ++i) + for (auto i (store::iterator (std::make_unique> (transaction_a, pending_store.pending_handle))), n (store::iterator (nullptr)); i != n; ++i) { - auto s = mdb_put (env.tx (transaction_a), temp, nano::mdb_val (i->first), nano::mdb_val (i->second), MDB_APPEND); + auto s = mdb_put (env.tx (transaction_a), temp, nano::store::lmdb::db_val (i->first), nano::store::lmdb::db_val (i->second), MDB_APPEND); release_assert_success (s); } release_assert (count (transaction_a, pending_store.pending_handle) == count (transaction_a, temp)); mdb_drop (env.tx (transaction_a), pending_store.pending_handle, 0); // Put values from copy - for (auto i (nano::store_iterator (std::make_unique> (transaction_a, temp))), n (nano::store_iterator (nullptr)); i != n; ++i) + for (auto i (store::iterator (std::make_unique> (transaction_a, temp))), n (store::iterator (nullptr)); i != n; ++i) { - auto s = mdb_put (env.tx (transaction_a), pending_store.pending_handle, nano::mdb_val (i->first), nano::mdb_val (i->second), MDB_APPEND); + auto s = mdb_put (env.tx (transaction_a), pending_store.pending_handle, nano::store::lmdb::db_val (i->first), nano::store::lmdb::db_val (i->second), MDB_APPEND); release_assert_success (s); } release_assert (count (transaction_a, pending_store.pending_handle) == count (transaction_a, temp)); @@ -947,12 +947,12 @@ void nano::lmdb::store::rebuild_db (nano::write_transaction const & transaction_ } } -bool nano::lmdb::store::init_error () const +bool nano::store::lmdb::component::init_error () const { return error; } -std::shared_ptr nano::lmdb::store::block_get_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const +std::shared_ptr nano::store::lmdb::component::block_get_v18 (store::transaction const & transaction_a, nano::block_hash const & hash_a) const { nano::block_type type; auto value (block_raw_get_v18 (transaction_a, hash_a, type)); @@ -962,7 +962,7 @@ std::shared_ptr nano::lmdb::store::block_get_v18 (nano::transaction nano::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); result = nano::deserialize_block (stream, type); release_assert (result != nullptr); - nano::block_sideband_v18 sideband; + nano::store::block_sideband_v18 sideband; auto error = (sideband.deserialize (stream, type)); release_assert (!error); result->sideband_set (nano::block_sideband (sideband.account, sideband.successor, sideband.balance, sideband.height, sideband.timestamp, sideband.details.epoch, sideband.details.is_send, sideband.details.is_receive, sideband.details.is_epoch, nano::epoch::epoch_0)); @@ -970,9 +970,9 @@ std::shared_ptr nano::lmdb::store::block_get_v18 (nano::transaction return result; } -nano::mdb_val nano::lmdb::store::block_raw_get_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const +nano::store::lmdb::db_val nano::store::lmdb::component::block_raw_get_v18 (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const { - nano::mdb_val result; + nano::store::lmdb::db_val result; // Table lookups are ordered by match probability nano::block_type block_types[]{ nano::block_type::state, nano::block_type::send, nano::block_type::receive, nano::block_type::open, nano::block_type::change }; for (auto current_type : block_types) @@ -989,10 +989,10 @@ nano::mdb_val nano::lmdb::store::block_raw_get_v18 (nano::transaction const & tr return result; } -boost::optional nano::lmdb::store::block_raw_get_by_type_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const +boost::optional nano::store::lmdb::component::block_raw_get_by_type_v18 (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const { - nano::mdb_val value; - nano::mdb_val hash (hash_a); + nano::store::lmdb::db_val value; + nano::store::lmdb::db_val hash (hash_a); int status = status_code_not_found (); switch (type_a) { @@ -1029,7 +1029,7 @@ boost::optional nano::lmdb::store::block_raw_get_by_type_v18 (nan } release_assert (success (status) || not_found (status)); - boost::optional result; + boost::optional result; if (success (status)) { result = value; @@ -1038,12 +1038,12 @@ boost::optional nano::lmdb::store::block_raw_get_by_type_v18 (nan } // All the v14 functions below are only needed during upgrades -std::size_t nano::lmdb::store::block_successor_offset_v14 (nano::transaction const & transaction_a, std::size_t entry_size_a, nano::block_type type_a) const +std::size_t nano::store::lmdb::component::block_successor_offset_v14 (store::transaction const & transaction_a, std::size_t entry_size_a, nano::block_type type_a) const { - return entry_size_a - nano::block_sideband_v14::size (type_a); + return entry_size_a - nano::store::block_sideband_v14::size (type_a); } -nano::block_hash nano::lmdb::store::block_successor_v14 (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const +nano::block_hash nano::store::lmdb::component::block_successor_v14 (store::transaction const & transaction_a, nano::block_hash const & hash_a) const { nano::block_type type; auto value (block_raw_get_v14 (transaction_a, hash_a, type)); @@ -1063,9 +1063,9 @@ nano::block_hash nano::lmdb::store::block_successor_v14 (nano::transaction const return result; } -nano::mdb_val nano::lmdb::store::block_raw_get_v14 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a, bool * is_state_v1) const +nano::store::lmdb::db_val nano::store::lmdb::component::block_raw_get_v14 (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a, bool * is_state_v1) const { - nano::mdb_val result; + nano::store::lmdb::db_val result; // Table lookups are ordered by match probability nano::block_type block_types[]{ nano::block_type::state, nano::block_type::send, nano::block_type::receive, nano::block_type::open, nano::block_type::change }; for (auto current_type : block_types) @@ -1082,10 +1082,10 @@ nano::mdb_val nano::lmdb::store::block_raw_get_v14 (nano::transaction const & tr return result; } -boost::optional nano::lmdb::store::block_raw_get_by_type_v14 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a, bool * is_state_v1) const +boost::optional nano::store::lmdb::component::block_raw_get_by_type_v14 (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a, bool * is_state_v1) const { - nano::mdb_val value; - nano::mdb_val hash (hash_a); + nano::store::lmdb::db_val value; + nano::store::lmdb::db_val hash (hash_a); int status = status_code_not_found (); switch (type_a) { @@ -1130,7 +1130,7 @@ boost::optional nano::lmdb::store::block_raw_get_by_type_v14 (nan } release_assert (success (status) || not_found (status)); - boost::optional result; + boost::optional result; if (success (status)) { result = value; @@ -1138,7 +1138,7 @@ boost::optional nano::lmdb::store::block_raw_get_by_type_v14 (nan return result; } -std::shared_ptr nano::lmdb::store::block_get_v14 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_sideband_v14 * sideband_a, bool * is_state_v1) const +std::shared_ptr nano::store::lmdb::component::block_get_v14 (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::store::block_sideband_v14 * sideband_a, bool * is_state_v1) const { nano::block_type type; auto value (block_raw_get_v14 (transaction_a, hash_a, type, is_state_v1)); @@ -1159,18 +1159,18 @@ std::shared_ptr nano::lmdb::store::block_get_v14 (nano::transaction return result; } -nano::lmdb::store::upgrade_counters::upgrade_counters (uint64_t count_before_v0, uint64_t count_before_v1) : +nano::store::lmdb::component::upgrade_counters::upgrade_counters (uint64_t count_before_v0, uint64_t count_before_v1) : before_v0 (count_before_v0), before_v1 (count_before_v1) { } -bool nano::lmdb::store::upgrade_counters::are_equal () const +bool nano::store::lmdb::component::upgrade_counters::are_equal () const { return (before_v0 == after_v0) && (before_v1 == after_v1); } -unsigned nano::lmdb::store::max_block_write_batch_num () const +unsigned nano::store::lmdb::component::max_block_write_batch_num () const { return std::numeric_limits::max (); } diff --git a/nano/store/lmdb/lmdb.hpp b/nano/store/lmdb/lmdb.hpp index 77c72dc199..2aec49e264 100644 --- a/nano/store/lmdb/lmdb.hpp +++ b/nano/store/lmdb/lmdb.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -38,158 +39,160 @@ namespace nano class logging_mt; class transaction; -namespace lmdb +} + +namespace nano::store::lmdb { - /** +/** * mdb implementation of the block store */ - class store : public nano::store::component +class component : public nano::store::component +{ +private: + nano::store::lmdb::account account_store; + nano::store::lmdb::block block_store; + nano::store::lmdb::confirmation_height confirmation_height_store; + nano::store::lmdb::final_vote final_vote_store; + nano::store::lmdb::frontier frontier_store; + nano::store::lmdb::online_weight online_weight_store; + nano::store::lmdb::peer peer_store; + nano::store::lmdb::pending pending_store; + nano::store::lmdb::pruned pruned_store; + nano::store::lmdb::version version_store; + + friend class nano::store::lmdb::account; + friend class nano::store::lmdb::block; + friend class nano::store::lmdb::confirmation_height; + friend class nano::store::lmdb::final_vote; + friend class nano::store::lmdb::frontier; + friend class nano::store::lmdb::online_weight; + friend class nano::store::lmdb::peer; + friend class nano::store::lmdb::pending; + friend class nano::store::lmdb::pruned; + friend class nano::store::lmdb::version; + +public: + component (nano::logger_mt &, boost::filesystem::path const &, nano::ledger_constants & constants, nano::txn_tracking_config const & txn_tracking_config_a = nano::txn_tracking_config{}, std::chrono::milliseconds block_processor_batch_max_time_a = std::chrono::milliseconds (5000), nano::lmdb_config const & lmdb_config_a = nano::lmdb_config{}, bool backup_before_upgrade = false); + store::write_transaction tx_begin_write (std::vector const & tables_requiring_lock = {}, std::vector const & tables_no_lock = {}) override; + store::read_transaction tx_begin_read () const override; + + std::string vendor_get () const override; + + void serialize_mdb_tracker (boost::property_tree::ptree &, std::chrono::milliseconds, std::chrono::milliseconds) override; + + static void create_backup_file (nano::store::lmdb::env &, boost::filesystem::path const &, nano::logger_mt &); + + void serialize_memory_stats (boost::property_tree::ptree &) override; + + unsigned max_block_write_batch_num () const override; + +private: + nano::logger_mt & logger; + bool error{ false }; + +public: + nano::store::lmdb::env env; + + bool exists (store::transaction const & transaction_a, tables table_a, nano::store::lmdb::db_val const & key_a) const; + + int get (store::transaction const & transaction_a, tables table_a, nano::store::lmdb::db_val const & key_a, nano::store::lmdb::db_val & value_a) const; + int put (store::write_transaction const & transaction_a, tables table_a, nano::store::lmdb::db_val const & key_a, nano::store::lmdb::db_val const & value_a) const; + int del (store::write_transaction const & transaction_a, tables table_a, nano::store::lmdb::db_val const & key_a) const; + + bool copy_db (boost::filesystem::path const & destination_file) override; + void rebuild_db (store::write_transaction const & transaction_a) override; + + template + store::iterator make_iterator (store::transaction const & transaction_a, tables table_a, bool const direction_asc = true) const { - private: - nano::lmdb::account_store account_store; - nano::lmdb::block_store block_store; - nano::lmdb::confirmation_height_store confirmation_height_store; - nano::lmdb::final_vote_store final_vote_store; - nano::lmdb::frontier_store frontier_store; - nano::lmdb::online_weight_store online_weight_store; - nano::lmdb::peer_store peer_store; - nano::lmdb::pending_store pending_store; - nano::lmdb::pruned_store pruned_store; - nano::lmdb::version_store version_store; - - friend class nano::lmdb::account_store; - friend class nano::lmdb::block_store; - friend class nano::lmdb::confirmation_height_store; - friend class nano::lmdb::final_vote_store; - friend class nano::lmdb::frontier_store; - friend class nano::lmdb::online_weight_store; - friend class nano::lmdb::peer_store; - friend class nano::lmdb::pending_store; - friend class nano::lmdb::pruned_store; - friend class nano::lmdb::version_store; - - public: - store (nano::logger_mt &, boost::filesystem::path const &, nano::ledger_constants & constants, nano::txn_tracking_config const & txn_tracking_config_a = nano::txn_tracking_config{}, std::chrono::milliseconds block_processor_batch_max_time_a = std::chrono::milliseconds (5000), nano::lmdb_config const & lmdb_config_a = nano::lmdb_config{}, bool backup_before_upgrade = false); - nano::write_transaction tx_begin_write (std::vector const & tables_requiring_lock = {}, std::vector const & tables_no_lock = {}) override; - nano::read_transaction tx_begin_read () const override; - - std::string vendor_get () const override; - - void serialize_mdb_tracker (boost::property_tree::ptree &, std::chrono::milliseconds, std::chrono::milliseconds) override; - - static void create_backup_file (nano::mdb_env &, boost::filesystem::path const &, nano::logger_mt &); - - void serialize_memory_stats (boost::property_tree::ptree &) override; - - unsigned max_block_write_batch_num () const override; - - private: - nano::logger_mt & logger; - bool error{ false }; - - public: - nano::mdb_env env; - - bool exists (nano::transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a) const; - - int get (nano::transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a, nano::mdb_val & value_a) const; - int put (nano::write_transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a, nano::mdb_val const & value_a) const; - int del (nano::write_transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a) const; + return store::iterator (std::make_unique> (transaction_a, table_to_dbi (table_a), nano::store::lmdb::db_val{}, direction_asc)); + } - bool copy_db (boost::filesystem::path const & destination_file) override; - void rebuild_db (nano::write_transaction const & transaction_a) override; - - template - nano::store_iterator make_iterator (nano::transaction const & transaction_a, tables table_a, bool const direction_asc = true) const - { - return nano::store_iterator (std::make_unique> (transaction_a, table_to_dbi (table_a), nano::mdb_val{}, direction_asc)); - } - - template - nano::store_iterator make_iterator (nano::transaction const & transaction_a, tables table_a, nano::mdb_val const & key) const + template + store::iterator make_iterator (store::transaction const & transaction_a, tables table_a, nano::store::lmdb::db_val const & key) const + { + return store::iterator (std::make_unique> (transaction_a, table_to_dbi (table_a), key)); + } + + bool init_error () const override; + + uint64_t count (store::transaction const &, MDB_dbi) const; + std::string error_string (int status) const override; + + // These are only use in the upgrade process. + std::shared_ptr block_get_v14 (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::store::block_sideband_v14 * sideband_a = nullptr, bool * is_state_v1 = nullptr) const; + std::size_t block_successor_offset_v14 (store::transaction const & transaction_a, std::size_t entry_size_a, nano::block_type type_a) const; + nano::block_hash block_successor_v14 (store::transaction const & transaction_a, nano::block_hash const & hash_a) const; + nano::store::lmdb::db_val block_raw_get_v14 (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a, bool * is_state_v1 = nullptr) const; + boost::optional block_raw_get_by_type_v14 (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a, bool * is_state_v1) const; + +private: + bool do_upgrades (store::write_transaction &, nano::ledger_constants & constants, bool &); + void upgrade_v14_to_v15 (store::write_transaction &); + void upgrade_v15_to_v16 (store::write_transaction const &); + void upgrade_v16_to_v17 (store::write_transaction const &); + void upgrade_v17_to_v18 (store::write_transaction const &, nano::ledger_constants & constants); + void upgrade_v18_to_v19 (store::write_transaction const &); + void upgrade_v19_to_v20 (store::write_transaction const &); + void upgrade_v20_to_v21 (store::write_transaction const &); + void upgrade_v21_to_v22 (store::write_transaction const &); + + std::shared_ptr block_get_v18 (store::transaction const & transaction_a, nano::block_hash const & hash_a) const; + nano::store::lmdb::db_val block_raw_get_v18 (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const; + boost::optional block_raw_get_by_type_v18 (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const; + nano::uint128_t block_balance_v18 (store::transaction const & transaction_a, nano::block_hash const & hash_a) const; + + void open_databases (bool &, store::transaction const &, unsigned); + + int drop (store::write_transaction const & transaction_a, tables table_a) override; + int clear (store::write_transaction const & transaction_a, MDB_dbi handle_a); + + bool not_found (int status) const override; + bool success (int status) const override; + void release_assert_success (int const status) const + { + if (!success (status)) { - return nano::store_iterator (std::make_unique> (transaction_a, table_to_dbi (table_a), key)); + release_assert (false, error_string (status)); } + } + int status_code_not_found () const override; - bool init_error () const override; - - uint64_t count (nano::transaction const &, MDB_dbi) const; - std::string error_string (int status) const override; - - // These are only use in the upgrade process. - std::shared_ptr block_get_v14 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_sideband_v14 * sideband_a = nullptr, bool * is_state_v1 = nullptr) const; - std::size_t block_successor_offset_v14 (nano::transaction const & transaction_a, std::size_t entry_size_a, nano::block_type type_a) const; - nano::block_hash block_successor_v14 (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const; - nano::mdb_val block_raw_get_v14 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a, bool * is_state_v1 = nullptr) const; - boost::optional block_raw_get_by_type_v14 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a, bool * is_state_v1) const; - - private: - bool do_upgrades (nano::write_transaction &, nano::ledger_constants & constants, bool &); - void upgrade_v14_to_v15 (nano::write_transaction &); - void upgrade_v15_to_v16 (nano::write_transaction const &); - void upgrade_v16_to_v17 (nano::write_transaction const &); - void upgrade_v17_to_v18 (nano::write_transaction const &, nano::ledger_constants & constants); - void upgrade_v18_to_v19 (nano::write_transaction const &); - void upgrade_v19_to_v20 (nano::write_transaction const &); - void upgrade_v20_to_v21 (nano::write_transaction const &); - void upgrade_v21_to_v22 (nano::write_transaction const &); - - std::shared_ptr block_get_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const; - nano::mdb_val block_raw_get_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const; - boost::optional block_raw_get_by_type_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const; - - void open_databases (bool &, nano::transaction const &, unsigned); - - int drop (nano::write_transaction const & transaction_a, tables table_a) override; - int clear (nano::write_transaction const & transaction_a, MDB_dbi handle_a); - - bool not_found (int status) const override; - bool success (int status) const override; - void release_assert_success (int const status) const - { - if (!success (status)) - { - release_assert (false, error_string (status)); - } - } - int status_code_not_found () const override; + MDB_dbi table_to_dbi (tables table_a) const; - MDB_dbi table_to_dbi (tables table_a) const; + mutable nano::mdb_txn_tracker mdb_txn_tracker; + nano::store::lmdb::txn_callbacks create_txn_callbacks () const; + bool txn_tracking_enabled; - mutable nano::mdb_txn_tracker mdb_txn_tracker; - nano::mdb_txn_callbacks create_txn_callbacks () const; - bool txn_tracking_enabled; + uint64_t count (store::transaction const & transaction_a, tables table_a) const override; - uint64_t count (nano::transaction const & transaction_a, tables table_a) const override; + bool vacuum_after_upgrade (boost::filesystem::path const & path_a, nano::lmdb_config const & lmdb_config_a); - bool vacuum_after_upgrade (boost::filesystem::path const & path_a, nano::lmdb_config const & lmdb_config_a); + class upgrade_counters + { + public: + upgrade_counters (uint64_t count_before_v0, uint64_t count_before_v1); + bool are_equal () const; - class upgrade_counters - { - public: - upgrade_counters (uint64_t count_before_v0, uint64_t count_before_v1); - bool are_equal () const; - - uint64_t before_v0; - uint64_t before_v1; - uint64_t after_v0{ 0 }; - uint64_t after_v1{ 0 }; - }; - - friend class mdb_block_store_supported_version_upgrades_Test; - friend class mdb_block_store_upgrade_v14_v15_Test; - friend class mdb_block_store_upgrade_v15_v16_Test; - friend class mdb_block_store_upgrade_v16_v17_Test; - friend class mdb_block_store_upgrade_v17_v18_Test; - friend class mdb_block_store_upgrade_v18_v19_Test; - friend class mdb_block_store_upgrade_v19_v20_Test; - friend class mdb_block_store_upgrade_v20_v21_Test; - friend class mdb_block_store_upgrade_v21_v22_Test; - friend class block_store_DISABLED_change_dupsort_Test; - friend void write_sideband_v14 (nano::lmdb::store &, nano::transaction &, nano::block const &, MDB_dbi); - friend void write_sideband_v15 (nano::lmdb::store &, nano::transaction &, nano::block 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); + uint64_t before_v0; + uint64_t before_v1; + uint64_t after_v0{ 0 }; + uint64_t after_v1{ 0 }; }; -} -} + + friend class mdb_block_store_supported_version_upgrades_Test; + friend class mdb_block_store_upgrade_v14_v15_Test; + friend class mdb_block_store_upgrade_v15_v16_Test; + friend class mdb_block_store_upgrade_v16_v17_Test; + friend class mdb_block_store_upgrade_v17_v18_Test; + friend class mdb_block_store_upgrade_v18_v19_Test; + friend class mdb_block_store_upgrade_v19_v20_Test; + friend class mdb_block_store_upgrade_v20_v21_Test; + friend class mdb_block_store_upgrade_v21_v22_Test; + friend class block_store_DISABLED_change_dupsort_Test; + friend void write_sideband_v14 (nano::store::lmdb::component &, store::transaction &, nano::block const &, MDB_dbi); + friend void write_sideband_v15 (nano::store::lmdb::component &, store::transaction &, nano::block const &); + friend void modify_account_info_to_v14 (nano::store::lmdb::component &, store::transaction const &, nano::account const &, uint64_t, nano::block_hash const &); + friend void modify_confirmation_height_to_v15 (nano::store::lmdb::component &, store::transaction const &, nano::account const &, uint64_t); +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/lmdb_env.cpp b/nano/store/lmdb/lmdb_env.cpp index fc666d1f26..b34289e7f1 100644 --- a/nano/store/lmdb/lmdb_env.cpp +++ b/nano/store/lmdb/lmdb_env.cpp @@ -2,12 +2,12 @@ #include -nano::mdb_env::mdb_env (bool & error_a, boost::filesystem::path const & path_a, nano::mdb_env::options options_a) +nano::store::lmdb::env::env (bool & error_a, boost::filesystem::path const & path_a, nano::store::lmdb::env::options options_a) { init (error_a, path_a, options_a); } -void nano::mdb_env::init (bool & error_a, boost::filesystem::path const & path_a, nano::mdb_env::options options_a) +void nano::store::lmdb::env::init (bool & error_a, boost::filesystem::path const & path_a, nano::store::lmdb::env::options options_a) { boost::system::error_code error_mkdir, error_chmod; if (path_a.has_parent_path ()) @@ -78,7 +78,7 @@ void nano::mdb_env::init (bool & error_a, boost::filesystem::path const & path_a } } -nano::mdb_env::~mdb_env () +nano::store::lmdb::env::~env () { if (environment != nullptr) { @@ -88,22 +88,22 @@ nano::mdb_env::~mdb_env () } } -nano::mdb_env::operator MDB_env * () const +nano::store::lmdb::env::operator MDB_env * () const { return environment; } -nano::read_transaction nano::mdb_env::tx_begin_read (mdb_txn_callbacks mdb_txn_callbacks) const +nano::store::read_transaction nano::store::lmdb::env::tx_begin_read (store::lmdb::txn_callbacks mdb_txn_callbacks) const { - return nano::read_transaction{ std::make_unique (*this, mdb_txn_callbacks) }; + return store::read_transaction{ std::make_unique (*this, mdb_txn_callbacks) }; } -nano::write_transaction nano::mdb_env::tx_begin_write (mdb_txn_callbacks mdb_txn_callbacks) const +nano::store::write_transaction nano::store::lmdb::env::tx_begin_write (store::lmdb::txn_callbacks mdb_txn_callbacks) const { - return nano::write_transaction{ std::make_unique (*this, mdb_txn_callbacks) }; + return store::write_transaction{ std::make_unique (*this, mdb_txn_callbacks) }; } -MDB_txn * nano::mdb_env::tx (nano::transaction const & transaction_a) const +MDB_txn * nano::store::lmdb::env::tx (store::transaction const & transaction_a) const { return static_cast (transaction_a.get_handle ()); } diff --git a/nano/store/lmdb/lmdb_env.hpp b/nano/store/lmdb/lmdb_env.hpp index f02e9a4dda..21634509db 100644 --- a/nano/store/lmdb/lmdb_env.hpp +++ b/nano/store/lmdb/lmdb_env.hpp @@ -4,18 +4,18 @@ #include #include -namespace nano +namespace nano::store::lmdb { /** * RAII wrapper for MDB_env */ -class mdb_env final +class env final { public: /** Environment options, most of which originates from the config file. */ class options final { - friend class mdb_env; + friend class env; public: static options make () @@ -54,13 +54,13 @@ class mdb_env final nano::lmdb_config config; }; - mdb_env (bool &, boost::filesystem::path const &, nano::mdb_env::options options_a = nano::mdb_env::options::make ()); - void init (bool &, boost::filesystem::path const &, nano::mdb_env::options options_a = nano::mdb_env::options::make ()); - ~mdb_env (); + env (bool &, boost::filesystem::path const &, env::options options_a = env::options::make ()); + void init (bool &, boost::filesystem::path const &, env::options options_a = env::options::make ()); + ~env (); operator MDB_env * () const; - nano::read_transaction tx_begin_read (mdb_txn_callbacks txn_callbacks = mdb_txn_callbacks{}) const; - nano::write_transaction tx_begin_write (mdb_txn_callbacks txn_callbacks = mdb_txn_callbacks{}) const; - MDB_txn * tx (nano::transaction const & transaction_a) const; + store::read_transaction tx_begin_read (txn_callbacks callbacks = txn_callbacks{}) const; + store::write_transaction tx_begin_write (txn_callbacks callbacks = txn_callbacks{}) const; + MDB_txn * tx (store::transaction const & transaction_a) const; MDB_env * environment; }; -} +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/online_weight.cpp b/nano/store/lmdb/online_weight.cpp index 0807f5e39b..647aaf34da 100644 --- a/nano/store/lmdb/online_weight.cpp +++ b/nano/store/lmdb/online_weight.cpp @@ -1,44 +1,44 @@ #include #include -nano::lmdb::online_weight_store::online_weight_store (nano::lmdb::store & store_a) : +nano::store::lmdb::online_weight::online_weight (nano::store::lmdb::component & store_a) : store{ store_a } { } -void nano::lmdb::online_weight_store::put (nano::write_transaction const & transaction, uint64_t time, nano::amount const & amount) +void nano::store::lmdb::online_weight::put (store::write_transaction const & transaction, uint64_t time, nano::amount const & amount) { auto status = store.put (transaction, tables::online_weight, time, amount); store.release_assert_success (status); } -void nano::lmdb::online_weight_store::del (nano::write_transaction const & transaction, uint64_t time) +void nano::store::lmdb::online_weight::del (store::write_transaction const & transaction, uint64_t time) { auto status = store.del (transaction, tables::online_weight, time); store.release_assert_success (status); } -nano::store_iterator nano::lmdb::online_weight_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::lmdb::online_weight::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::online_weight); } -nano::store_iterator nano::lmdb::online_weight_store::rbegin (nano::transaction const & transaction) const +nano::store::iterator nano::store::lmdb::online_weight::rbegin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::online_weight, false); } -nano::store_iterator nano::lmdb::online_weight_store::end () const +nano::store::iterator nano::store::lmdb::online_weight::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -size_t nano::lmdb::online_weight_store::count (nano::transaction const & transaction) const +size_t nano::store::lmdb::online_weight::count (store::transaction const & transaction) const { return store.count (transaction, tables::online_weight); } -void nano::lmdb::online_weight_store::clear (nano::write_transaction const & transaction) +void nano::store::lmdb::online_weight::clear (store::write_transaction const & transaction) { auto status = store.drop (transaction, tables::online_weight); store.release_assert_success (status); diff --git a/nano/store/lmdb/online_weight.hpp b/nano/store/lmdb/online_weight.hpp index 9a1c527f53..df70dfb9d0 100644 --- a/nano/store/lmdb/online_weight.hpp +++ b/nano/store/lmdb/online_weight.hpp @@ -4,30 +4,27 @@ #include -namespace nano +namespace nano::store::lmdb { -namespace lmdb +class online_weight : public nano::store::online_weight { - class online_weight_store : public nano::online_weight_store - { - private: - nano::lmdb::store & store; +private: + nano::store::lmdb::component & store; - public: - explicit online_weight_store (nano::lmdb::store & store_a); - void put (nano::write_transaction const & transaction_a, uint64_t time_a, nano::amount const & amount_a) override; - void del (nano::write_transaction const & transaction_a, uint64_t time_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a) const override; - nano::store_iterator rbegin (nano::transaction const & transaction_a) const override; - nano::store_iterator end () const override; - size_t count (nano::transaction const & transaction_a) const override; - void clear (nano::write_transaction const & transaction_a) override; +public: + explicit online_weight (nano::store::lmdb::component & store_a); + void put (store::write_transaction const & transaction_a, uint64_t time_a, nano::amount const & amount_a) override; + void del (store::write_transaction const & transaction_a, uint64_t time_a) override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator rbegin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + size_t count (store::transaction const & transaction_a) const override; + void clear (store::write_transaction const & transaction_a) override; - /** + /** * Samples of online vote weight * uint64_t -> nano::amount */ - MDB_dbi online_weight_handle{ 0 }; - }; -} -} + MDB_dbi online_weight_handle{ 0 }; +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/peer.cpp b/nano/store/lmdb/peer.cpp index c51eced207..cb3de165c5 100644 --- a/nano/store/lmdb/peer.cpp +++ b/nano/store/lmdb/peer.cpp @@ -1,43 +1,43 @@ #include #include -nano::lmdb::peer_store::peer_store (nano::lmdb::store & store) : +nano::store::lmdb::peer::peer (nano::store::lmdb::component & store) : store{ store } {}; -void nano::lmdb::peer_store::put (nano::write_transaction const & transaction, nano::endpoint_key const & endpoint) +void nano::store::lmdb::peer::put (store::write_transaction const & transaction, nano::endpoint_key const & endpoint) { auto status = store.put (transaction, tables::peers, endpoint, nullptr); store.release_assert_success (status); } -void nano::lmdb::peer_store::del (nano::write_transaction const & transaction, nano::endpoint_key const & endpoint) +void nano::store::lmdb::peer::del (store::write_transaction const & transaction, nano::endpoint_key const & endpoint) { auto status = store.del (transaction, tables::peers, endpoint); store.release_assert_success (status); } -bool nano::lmdb::peer_store::exists (nano::transaction const & transaction, nano::endpoint_key const & endpoint) const +bool nano::store::lmdb::peer::exists (store::transaction const & transaction, nano::endpoint_key const & endpoint) const { return store.exists (transaction, tables::peers, endpoint); } -size_t nano::lmdb::peer_store::count (nano::transaction const & transaction) const +size_t nano::store::lmdb::peer::count (store::transaction const & transaction) const { return store.count (transaction, tables::peers); } -void nano::lmdb::peer_store::clear (nano::write_transaction const & transaction) +void nano::store::lmdb::peer::clear (store::write_transaction const & transaction) { auto status = store.drop (transaction, tables::peers); store.release_assert_success (status); } -nano::store_iterator nano::lmdb::peer_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::lmdb::peer::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::peers); } -nano::store_iterator nano::lmdb::peer_store::end () const +nano::store::iterator nano::store::lmdb::peer::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } diff --git a/nano/store/lmdb/peer.hpp b/nano/store/lmdb/peer.hpp index 83fd1ee785..7519908eee 100644 --- a/nano/store/lmdb/peer.hpp +++ b/nano/store/lmdb/peer.hpp @@ -4,31 +4,27 @@ #include -namespace nano +namespace nano::store::lmdb { -namespace lmdb +class peer : public nano::store::peer { - class store; - class peer_store : public nano::peer_store - { - private: - nano::lmdb::store & store; +private: + nano::store::lmdb::component & store; - public: - explicit peer_store (nano::lmdb::store & store_a); - void put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override; - void del (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override; - bool exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const override; - size_t count (nano::transaction const & transaction_a) const override; - void clear (nano::write_transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a) const override; - nano::store_iterator end () const override; +public: + explicit peer (nano::store::lmdb::component & store_a); + void put (store::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override; + void del (store::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override; + bool exists (store::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const override; + size_t count (store::transaction const & transaction_a) const override; + void clear (store::write_transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator end () const override; - /* + /* * Endpoints for peers * nano::endpoint_key -> no_value */ - MDB_dbi peers_handle{ 0 }; - }; -} -} + MDB_dbi peers_handle{ 0 }; +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/pending.cpp b/nano/store/lmdb/pending.cpp index 351747d4dd..961b201829 100644 --- a/nano/store/lmdb/pending.cpp +++ b/nano/store/lmdb/pending.cpp @@ -2,24 +2,24 @@ #include #include -nano::lmdb::pending_store::pending_store (nano::lmdb::store & store) : +nano::store::lmdb::pending::pending (nano::store::lmdb::component & store) : store{ store } {}; -void nano::lmdb::pending_store::put (nano::write_transaction const & transaction, nano::pending_key const & key, nano::pending_info const & pending) +void nano::store::lmdb::pending::put (store::write_transaction const & transaction, nano::pending_key const & key, nano::pending_info const & pending) { auto status = store.put (transaction, tables::pending, key, pending); store.release_assert_success (status); } -void nano::lmdb::pending_store::del (nano::write_transaction const & transaction, nano::pending_key const & key) +void nano::store::lmdb::pending::del (store::write_transaction const & transaction, nano::pending_key const & key) { auto status = store.del (transaction, tables::pending, key); store.release_assert_success (status); } -bool nano::lmdb::pending_store::get (nano::transaction const & transaction, nano::pending_key const & key, nano::pending_info & pending_a) +bool nano::store::lmdb::pending::get (store::transaction const & transaction, nano::pending_key const & key, nano::pending_info & pending_a) { - nano::mdb_val value; + nano::store::lmdb::db_val value; auto status1 = store.get (transaction, tables::pending, key, value); release_assert (store.success (status1) || store.not_found (status1)); bool result (true); @@ -31,34 +31,34 @@ bool nano::lmdb::pending_store::get (nano::transaction const & transaction, nano return result; } -bool nano::lmdb::pending_store::exists (nano::transaction const & transaction_a, nano::pending_key const & key_a) +bool nano::store::lmdb::pending::exists (store::transaction const & transaction_a, nano::pending_key const & key_a) { auto iterator (begin (transaction_a, key_a)); return iterator != end () && nano::pending_key (iterator->first) == key_a; } -bool nano::lmdb::pending_store::any (nano::transaction const & transaction_a, nano::account const & account_a) +bool nano::store::lmdb::pending::any (store::transaction const & transaction_a, nano::account const & account_a) { auto iterator (begin (transaction_a, nano::pending_key (account_a, 0))); return iterator != end () && nano::pending_key (iterator->first).account == account_a; } -nano::store_iterator nano::lmdb::pending_store::begin (nano::transaction const & transaction_a, nano::pending_key const & key_a) const +nano::store::iterator nano::store::lmdb::pending::begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const { return store.make_iterator (transaction_a, tables::pending, key_a); } -nano::store_iterator nano::lmdb::pending_store::begin (nano::transaction const & transaction_a) const +nano::store::iterator nano::store::lmdb::pending::begin (store::transaction const & transaction_a) const { return store.make_iterator (transaction_a, tables::pending); } -nano::store_iterator nano::lmdb::pending_store::end () const +nano::store::iterator nano::store::lmdb::pending::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::lmdb::pending_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::lmdb::pending::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint512_t const & start, nano::uint512_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/pending.hpp b/nano/store/lmdb/pending.hpp index 86fd1c1e5b..7b39a9132c 100644 --- a/nano/store/lmdb/pending.hpp +++ b/nano/store/lmdb/pending.hpp @@ -4,45 +4,45 @@ #include -namespace nano +namespace nano::store::lmdb { -namespace lmdb +class component; +} +namespace nano::store::lmdb +{ +class pending : public nano::store::pending { - class store; - class pending_store : public nano::pending_store - { - private: - nano::lmdb::store & store; +private: + nano::store::lmdb::component & store; - public: - explicit pending_store (nano::lmdb::store & store_a); - void put (nano::write_transaction const & transaction_a, nano::pending_key const & key_a, nano::pending_info const & pending_info_a) override; - void del (nano::write_transaction const & transaction_a, nano::pending_key const & key_a) override; - bool get (nano::transaction const & transaction_a, nano::pending_key const & key_a, nano::pending_info & pending_a) override; - bool exists (nano::transaction const & transaction_a, nano::pending_key const & key_a) override; - bool any (nano::transaction const & transaction_a, nano::account const & account_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::pending_key const & key_a) const override; - 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; +public: + explicit pending (nano::store::lmdb::component & store_a); + void put (store::write_transaction const & transaction_a, nano::pending_key const & key_a, nano::pending_info const & pending_info_a) override; + void del (store::write_transaction const & transaction_a, nano::pending_key const & key_a) override; + bool get (store::transaction const & transaction_a, nano::pending_key const & key_a, nano::pending_info & pending_a) override; + bool exists (store::transaction const & transaction_a, nano::pending_key const & key_a) override; + bool any (store::transaction const & transaction_a, nano::account const & account_a) override; + store::iterator begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; - /** + /** * Maps min_version 0 (destination account, pending block) to (source account, amount). (Removed) * nano::account, nano::block_hash -> nano::account, nano::amount */ - MDB_dbi pending_v0_handle{ 0 }; + MDB_dbi pending_v0_handle{ 0 }; - /** + /** * Maps min_version 1 (destination account, pending block) to (source account, amount). (Removed) * nano::account, nano::block_hash -> nano::account, nano::amount */ - MDB_dbi pending_v1_handle{ 0 }; + MDB_dbi pending_v1_handle{ 0 }; - /** + /** * Maps (destination account, pending block) to (source account, amount, version). (Removed) * nano::account, nano::block_hash -> nano::account, nano::amount, nano::epoch */ - MDB_dbi pending_handle{ 0 }; - }; -} -} + MDB_dbi pending_handle{ 0 }; +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/pruned.cpp b/nano/store/lmdb/pruned.cpp index 7865a031ec..2be19c24f5 100644 --- a/nano/store/lmdb/pruned.cpp +++ b/nano/store/lmdb/pruned.cpp @@ -2,27 +2,27 @@ #include #include -nano::lmdb::pruned_store::pruned_store (nano::lmdb::store & store_a) : +nano::store::lmdb::pruned::pruned (nano::store::lmdb::component & store_a) : store{ store_a } {}; -void nano::lmdb::pruned_store::put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) +void nano::store::lmdb::pruned::put (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) { auto status = store.put (transaction_a, tables::pruned, hash_a, nullptr); store.release_assert_success (status); } -void nano::lmdb::pruned_store::del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) +void nano::store::lmdb::pruned::del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) { auto status = store.del (transaction_a, tables::pruned, hash_a); store.release_assert_success (status); } -bool nano::lmdb::pruned_store::exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const +bool nano::store::lmdb::pruned::exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) const { return store.exists (transaction_a, tables::pruned, hash_a); } -nano::block_hash nano::lmdb::pruned_store::random (nano::transaction const & transaction) +nano::block_hash nano::store::lmdb::pruned::random (store::transaction const & transaction) { nano::block_hash random_hash; nano::random_pool::generate_block (random_hash.bytes.data (), random_hash.bytes.size ()); @@ -34,33 +34,33 @@ nano::block_hash nano::lmdb::pruned_store::random (nano::transaction const & tra return existing != end () ? existing->first : 0; } -size_t nano::lmdb::pruned_store::count (nano::transaction const & transaction_a) const +size_t nano::store::lmdb::pruned::count (store::transaction const & transaction_a) const { return store.count (transaction_a, tables::pruned); } -void nano::lmdb::pruned_store::clear (nano::write_transaction const & transaction_a) +void nano::store::lmdb::pruned::clear (store::write_transaction const & transaction_a) { auto status = store.drop (transaction_a, tables::pruned); store.release_assert_success (status); } -nano::store_iterator nano::lmdb::pruned_store::begin (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::store::iterator nano::store::lmdb::pruned::begin (store::transaction const & transaction, nano::block_hash const & hash) const { return store.make_iterator (transaction, tables::pruned, hash); } -nano::store_iterator nano::lmdb::pruned_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::lmdb::pruned::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::pruned); } -nano::store_iterator nano::lmdb::pruned_store::end () const +nano::store::iterator nano::store::lmdb::pruned::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::lmdb::pruned_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::lmdb::pruned::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/pruned.hpp b/nano/store/lmdb/pruned.hpp index 0ad8f07e5b..d0c3c5d075 100644 --- a/nano/store/lmdb/pruned.hpp +++ b/nano/store/lmdb/pruned.hpp @@ -4,34 +4,30 @@ #include -namespace nano +namespace nano::store::lmdb { -namespace lmdb +class pruned : public nano::store::pruned { - class store; - class pruned_store : public nano::pruned_store - { - private: - nano::lmdb::store & store; +private: + nano::store::lmdb::component & store; - public: - explicit pruned_store (nano::lmdb::store & store_a); - void put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; - void del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; - bool exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - nano::block_hash random (nano::transaction const & transaction_a) override; - size_t count (nano::transaction const & transaction_a) const override; - void clear (nano::write_transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - 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; +public: + explicit pruned (nano::store::lmdb::component & store_a); + void put (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; + void del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; + bool exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + nano::block_hash random (store::transaction const & transaction_a) override; + size_t count (store::transaction const & transaction_a) const override; + void clear (store::write_transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; - /** + /** * Pruned blocks hashes * nano::block_hash -> none */ - MDB_dbi pruned_handle{ 0 }; - }; -} -} + MDB_dbi pruned_handle{ 0 }; +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/transaction.cpp b/nano/store/lmdb/transaction.cpp index 40ef653c35..ad18863934 100644 --- a/nano/store/lmdb/transaction.cpp +++ b/nano/store/lmdb/transaction.cpp @@ -20,7 +20,7 @@ namespace class matches_txn final { public: - explicit matches_txn (nano::transaction_impl const * transaction_impl_a) : + explicit matches_txn (nano::store::transaction_impl const * transaction_impl_a) : transaction_impl (transaction_impl_a) { } @@ -31,11 +31,11 @@ class matches_txn final } private: - nano::transaction_impl const * transaction_impl; + nano::store::transaction_impl const * transaction_impl; }; } -nano::read_mdb_txn::read_mdb_txn (nano::mdb_env const & environment_a, nano::mdb_txn_callbacks txn_callbacks_a) : +nano::store::lmdb::read_transaction_impl::read_transaction_impl (nano::store::lmdb::env const & environment_a, nano::store::lmdb::txn_callbacks txn_callbacks_a) : txn_callbacks (txn_callbacks_a) { auto status (mdb_txn_begin (environment_a, nullptr, MDB_RDONLY, &handle)); @@ -43,7 +43,7 @@ nano::read_mdb_txn::read_mdb_txn (nano::mdb_env const & environment_a, nano::mdb txn_callbacks.txn_start (this); } -nano::read_mdb_txn::~read_mdb_txn () +nano::store::lmdb::read_transaction_impl::~read_transaction_impl () { // This uses commit rather than abort, as it is needed when opening databases with a read only transaction auto status (mdb_txn_commit (handle)); @@ -51,37 +51,37 @@ nano::read_mdb_txn::~read_mdb_txn () txn_callbacks.txn_end (this); } -void nano::read_mdb_txn::reset () +void nano::store::lmdb::read_transaction_impl::reset () { mdb_txn_reset (handle); txn_callbacks.txn_end (this); } -void nano::read_mdb_txn::renew () +void nano::store::lmdb::read_transaction_impl::renew () { auto status (mdb_txn_renew (handle)); release_assert (status == 0); txn_callbacks.txn_start (this); } -void * nano::read_mdb_txn::get_handle () const +void * nano::store::lmdb::read_transaction_impl::get_handle () const { return handle; } -nano::write_mdb_txn::write_mdb_txn (nano::mdb_env const & environment_a, nano::mdb_txn_callbacks txn_callbacks_a) : +nano::store::lmdb::write_transaction_impl::write_transaction_impl (nano::store::lmdb::env const & environment_a, nano::store::lmdb::txn_callbacks txn_callbacks_a) : env (environment_a), txn_callbacks (txn_callbacks_a) { renew (); } -nano::write_mdb_txn::~write_mdb_txn () +nano::store::lmdb::write_transaction_impl::~write_transaction_impl () { commit (); } -void nano::write_mdb_txn::commit () +void nano::store::lmdb::write_transaction_impl::commit () { if (active) { @@ -95,7 +95,7 @@ void nano::write_mdb_txn::commit () } } -void nano::write_mdb_txn::renew () +void nano::store::lmdb::write_transaction_impl::renew () { auto status (mdb_txn_begin (env, nullptr, 0, &handle)); release_assert (status == MDB_SUCCESS, mdb_strerror (status)); @@ -103,12 +103,12 @@ void nano::write_mdb_txn::renew () active = true; } -void * nano::write_mdb_txn::get_handle () const +void * nano::store::lmdb::write_transaction_impl::get_handle () const { return handle; } -bool nano::write_mdb_txn::contains (nano::tables table_a) const +bool nano::store::lmdb::write_transaction_impl::contains (nano::tables table_a) const { // LMDB locks on every write return true; @@ -196,7 +196,7 @@ void nano::mdb_txn_tracker::log_if_held_long_enough (nano::mdb_txn_stats const & } } -void nano::mdb_txn_tracker::add (nano::transaction_impl const * transaction_impl) +void nano::mdb_txn_tracker::add (store::transaction_impl const * transaction_impl) { nano::lock_guard guard (mutex); debug_assert (std::find_if (stats.cbegin (), stats.cend (), matches_txn (transaction_impl)) == stats.cend ()); @@ -204,7 +204,7 @@ void nano::mdb_txn_tracker::add (nano::transaction_impl const * transaction_impl } /** Can be called without error if transaction does not exist */ -void nano::mdb_txn_tracker::erase (nano::transaction_impl const * transaction_impl) +void nano::mdb_txn_tracker::erase (store::transaction_impl const * transaction_impl) { nano::unique_lock lk (mutex); auto it = std::find_if (stats.begin (), stats.end (), matches_txn (transaction_impl)); @@ -217,7 +217,7 @@ void nano::mdb_txn_tracker::erase (nano::transaction_impl const * transaction_im } } -nano::mdb_txn_stats::mdb_txn_stats (nano::transaction_impl const * transaction_impl) : +nano::mdb_txn_stats::mdb_txn_stats (store::transaction_impl const * transaction_impl) : transaction_impl (transaction_impl), thread_name (nano::thread_role::get_string ()), stacktrace (std::make_shared ()) @@ -227,5 +227,5 @@ nano::mdb_txn_stats::mdb_txn_stats (nano::transaction_impl const * transaction_i bool nano::mdb_txn_stats::is_write () const { - return (dynamic_cast (transaction_impl) != nullptr); + return (dynamic_cast (transaction_impl) != nullptr); } diff --git a/nano/store/lmdb/transaction_impl.hpp b/nano/store/lmdb/transaction_impl.hpp index c44ea31a85..cdeff1404e 100644 --- a/nano/store/lmdb/transaction_impl.hpp +++ b/nano/store/lmdb/transaction_impl.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -11,51 +12,58 @@ namespace nano { -class transaction_impl; class logger_mt; -class mdb_env; +} +namespace nano::store::lmdb +{ +class env; +} -class mdb_txn_callbacks +namespace nano::store::lmdb +{ +class txn_callbacks { public: - std::function txn_start{ [] (nano::transaction_impl const *) {} }; - std::function txn_end{ [] (nano::transaction_impl const *) {} }; + std::function txn_start{ [] (store::transaction_impl const *) {} }; + std::function txn_end{ [] (store::transaction_impl const *) {} }; }; - -class read_mdb_txn final : public read_transaction_impl +class read_transaction_impl final : public store::read_transaction_impl { public: - read_mdb_txn (nano::mdb_env const &, mdb_txn_callbacks mdb_txn_callbacks); - ~read_mdb_txn (); + read_transaction_impl (nano::store::lmdb::env const &, txn_callbacks mdb_txn_callbacks); + ~read_transaction_impl (); void reset () override; void renew () override; void * get_handle () const override; MDB_txn * handle; - mdb_txn_callbacks txn_callbacks; + lmdb::txn_callbacks txn_callbacks; }; -class write_mdb_txn final : public write_transaction_impl +class write_transaction_impl final : public store::write_transaction_impl { public: - write_mdb_txn (nano::mdb_env const &, mdb_txn_callbacks mdb_txn_callbacks); - ~write_mdb_txn (); + write_transaction_impl (nano::store::lmdb::env const &, txn_callbacks mdb_txn_callbacks); + ~write_transaction_impl (); void commit () override; void renew () override; void * get_handle () const override; bool contains (nano::tables table_a) const override; MDB_txn * handle; - nano::mdb_env const & env; - mdb_txn_callbacks txn_callbacks; + nano::store::lmdb::env const & env; + lmdb::txn_callbacks txn_callbacks; bool active{ true }; }; +} // namespace nano +namespace nano +{ class mdb_txn_stats { public: - mdb_txn_stats (nano::transaction_impl const * transaction_impl_a); + mdb_txn_stats (store::transaction_impl const * transaction_impl_a); bool is_write () const; nano::timer timer; - nano::transaction_impl const * transaction_impl; + store::transaction_impl const * transaction_impl; std::string thread_name; // Smart pointer so that we don't need the full definition which causes min/max issues on Windows @@ -67,8 +75,8 @@ class mdb_txn_tracker public: mdb_txn_tracker (nano::logger_mt & logger_a, nano::txn_tracking_config const & txn_tracking_config_a, std::chrono::milliseconds block_processor_batch_max_time_a); void serialize_json (boost::property_tree::ptree & json, std::chrono::milliseconds min_read_time, std::chrono::milliseconds min_write_time); - void add (nano::transaction_impl const * transaction_impl); - void erase (nano::transaction_impl const * transaction_impl); + void add (store::transaction_impl const * transaction_impl); + void erase (store::transaction_impl const * transaction_impl); private: nano::mutex mutex; @@ -79,4 +87,4 @@ class mdb_txn_tracker void log_if_held_long_enough (nano::mdb_txn_stats const & mdb_txn_stats) const; }; -} +} // namespace nano diff --git a/nano/store/lmdb/version.cpp b/nano/store/lmdb/version.cpp index be80c52885..f667dc4b9c 100644 --- a/nano/store/lmdb/version.cpp +++ b/nano/store/lmdb/version.cpp @@ -1,10 +1,10 @@ #include #include -nano::lmdb::version_store::version_store (nano::lmdb::store & store_a) : +nano::store::lmdb::version::version (nano::store::lmdb::component & store_a) : store{ store_a } {}; -void nano::lmdb::version_store::put (nano::write_transaction const & transaction_a, int version) +void nano::store::lmdb::version::put (store::write_transaction const & transaction_a, int version) { nano::uint256_union version_key{ 1 }; nano::uint256_union version_value (version); @@ -12,10 +12,10 @@ void nano::lmdb::version_store::put (nano::write_transaction const & transaction store.release_assert_success (status); } -int nano::lmdb::version_store::get (nano::transaction const & transaction_a) const +int nano::store::lmdb::version::get (store::transaction const & transaction_a) const { nano::uint256_union version_key{ 1 }; - nano::mdb_val data; + nano::store::lmdb::db_val data; auto status = store.get (transaction_a, tables::meta, version_key, data); int result = store.version_minimum; if (store.success (status)) diff --git a/nano/store/lmdb/version.hpp b/nano/store/lmdb/version.hpp index ff9b723564..ea7ba6bf3c 100644 --- a/nano/store/lmdb/version.hpp +++ b/nano/store/lmdb/version.hpp @@ -2,20 +2,16 @@ #include -namespace nano +namespace nano::store::lmdb { -namespace lmdb +class version : public nano::store::version { - class store; - class version_store : public nano::version_store - { - protected: - nano::lmdb::store & store; +protected: + nano::store::lmdb::component & store; - public: - explicit version_store (nano::lmdb::store & store_a); - void put (nano::write_transaction const & transaction_a, int version_a) override; - int get (nano::transaction const & transaction_a) const override; - }; -} -} +public: + explicit version (nano::store::lmdb::component & store_a); + void put (store::write_transaction const & transaction_a, int version_a) override; + int get (store::transaction const & transaction_a) const override; +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/wallet_value.cpp b/nano/store/lmdb/wallet_value.cpp index 8aabe272ab..60aefabe25 100644 --- a/nano/store/lmdb/wallet_value.cpp +++ b/nano/store/lmdb/wallet_value.cpp @@ -1,6 +1,6 @@ #include -nano::wallet_value::wallet_value (nano::db_val const & val_a) +nano::wallet_value::wallet_value (nano::store::db_val const & val_a) { debug_assert (val_a.size () == sizeof (*this)); std::copy (reinterpret_cast (val_a.data ()), reinterpret_cast (val_a.data ()) + sizeof (key), key.chars.begin ()); @@ -13,8 +13,8 @@ nano::wallet_value::wallet_value (nano::raw_key const & key_a, uint64_t work_a) { } -nano::db_val nano::wallet_value::val () const +nano::store::db_val nano::wallet_value::val () const { static_assert (sizeof (*this) == sizeof (key) + sizeof (work), "Class not packed"); - return nano::db_val (sizeof (*this), const_cast (this)); + return nano::store::db_val (sizeof (*this), const_cast (this)); } diff --git a/nano/store/lmdb/wallet_value.hpp b/nano/store/lmdb/wallet_value.hpp index f5e70e54f7..d272ae96d4 100644 --- a/nano/store/lmdb/wallet_value.hpp +++ b/nano/store/lmdb/wallet_value.hpp @@ -11,9 +11,9 @@ class wallet_value { public: wallet_value () = default; - wallet_value (nano::db_val const &); + wallet_value (store::db_val const &); wallet_value (nano::raw_key const &, uint64_t); - nano::db_val val () const; + store::db_val val () const; nano::raw_key key; uint64_t work; }; diff --git a/nano/store/online_weight.hpp b/nano/store/online_weight.hpp index ee65a9b02e..260e085297 100644 --- a/nano/store/online_weight.hpp +++ b/nano/store/online_weight.hpp @@ -13,20 +13,20 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { /** * Manages online weight storage and iteration */ -class online_weight_store +class online_weight { public: - virtual void put (nano::write_transaction const &, uint64_t, nano::amount const &) = 0; - virtual void del (nano::write_transaction const &, uint64_t) = 0; - virtual nano::store_iterator begin (nano::transaction const &) const = 0; - virtual nano::store_iterator rbegin (nano::transaction const &) const = 0; - virtual nano::store_iterator end () const = 0; - virtual size_t count (nano::transaction const &) const = 0; - virtual void clear (nano::write_transaction const &) = 0; + virtual void put (store::write_transaction const &, uint64_t, nano::amount const &) = 0; + virtual void del (store::write_transaction const &, uint64_t) = 0; + virtual store::iterator begin (store::transaction const &) const = 0; + virtual store::iterator rbegin (store::transaction const &) const = 0; + virtual store::iterator end () const = 0; + virtual size_t count (store::transaction const &) const = 0; + virtual void clear (store::write_transaction const &) = 0; }; } // namespace nano::store diff --git a/nano/store/peer.hpp b/nano/store/peer.hpp index 64d36796af..149b4b3b18 100644 --- a/nano/store/peer.hpp +++ b/nano/store/peer.hpp @@ -13,20 +13,20 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { /** * Manages peer storage and iteration */ -class peer_store +class peer { public: - virtual void put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0; - virtual void del (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0; - virtual bool exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const = 0; - virtual size_t count (nano::transaction const & transaction_a) const = 0; - virtual void clear (nano::write_transaction const & transaction_a) = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; - virtual nano::store_iterator end () const = 0; + virtual void put (store::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0; + virtual void del (store::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0; + virtual bool exists (store::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const = 0; + virtual size_t count (store::transaction const & transaction_a) const = 0; + virtual void clear (store::write_transaction const & transaction_a) = 0; + virtual store::iterator begin (store::transaction const & transaction_a) const = 0; + virtual store::iterator end () const = 0; }; } // namespace nano::store diff --git a/nano/store/pending.hpp b/nano/store/pending.hpp index 8944d2cb76..7c11283494 100644 --- a/nano/store/pending.hpp +++ b/nano/store/pending.hpp @@ -13,22 +13,22 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { /** * Manages pending storage and iteration */ -class pending_store +class pending { public: - virtual void put (nano::write_transaction const &, nano::pending_key const &, nano::pending_info const &) = 0; - virtual void del (nano::write_transaction const &, nano::pending_key const &) = 0; - virtual bool get (nano::transaction const &, nano::pending_key const &, nano::pending_info &) = 0; - virtual bool exists (nano::transaction const &, nano::pending_key const &) = 0; - virtual bool any (nano::transaction const &, nano::account const &) = 0; - virtual nano::store_iterator begin (nano::transaction const &, nano::pending_key const &) const = 0; - virtual nano::store_iterator begin (nano::transaction const &) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; + virtual void put (store::write_transaction const &, nano::pending_key const &, nano::pending_info const &) = 0; + virtual void del (store::write_transaction const &, nano::pending_key const &) = 0; + virtual bool get (store::transaction const &, nano::pending_key const &, nano::pending_info &) = 0; + virtual bool exists (store::transaction const &, nano::pending_key const &) = 0; + virtual bool any (store::transaction const &, nano::account const &) = 0; + virtual store::iterator begin (store::transaction const &, nano::pending_key const &) const = 0; + virtual store::iterator begin (store::transaction const &) const = 0; + virtual store::iterator end () const = 0; + virtual void for_each_par (std::function, store::iterator)> const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/pruned.hpp b/nano/store/pruned.hpp index f9b48a22c9..cab488577f 100644 --- a/nano/store/pruned.hpp +++ b/nano/store/pruned.hpp @@ -13,23 +13,23 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { /** * Manages pruned storage and iteration */ -class pruned_store +class pruned { public: - virtual void put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; - virtual void del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; - virtual bool exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; - virtual nano::block_hash random (nano::transaction const & transaction_a) = 0; - virtual size_t count (nano::transaction const & transaction_a) const = 0; - virtual void clear (nano::write_transaction const &) = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; + virtual void put (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; + virtual void del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; + virtual bool exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; + virtual nano::block_hash random (store::transaction const & transaction_a) = 0; + virtual size_t count (store::transaction const & transaction_a) const = 0; + virtual void clear (store::write_transaction const &) = 0; + virtual store::iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; + virtual store::iterator begin (store::transaction const & transaction_a) const = 0; + virtual store::iterator end () const = 0; + virtual void for_each_par (std::function, store::iterator)> const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/rocksdb/account.cpp b/nano/store/rocksdb/account.cpp index 2cf5e6d094..8ee01b98fe 100644 --- a/nano/store/rocksdb/account.cpp +++ b/nano/store/rocksdb/account.cpp @@ -2,18 +2,18 @@ #include #include -nano::rocksdb::account_store::account_store (nano::rocksdb::store & store_a) : +nano::store::rocksdb::account::account (nano::store::rocksdb::component & store_a) : store (store_a){}; -void nano::rocksdb::account_store::put (nano::write_transaction const & transaction, nano::account const & account, nano::account_info const & info) +void nano::store::rocksdb::account::put (store::write_transaction const & transaction, nano::account const & account, nano::account_info const & info) { auto status = store.put (transaction, tables::accounts, account, info); store.release_assert_success (status); } -bool nano::rocksdb::account_store::get (nano::transaction const & transaction, nano::account const & account, nano::account_info & info) +bool nano::store::rocksdb::account::get (store::transaction const & transaction, nano::account const & account, nano::account_info & info) { - nano::rocksdb_val value; + nano::store::rocksdb::db_val value; auto status1 (store.get (transaction, tables::accounts, account, value)); release_assert (store.success (status1) || store.not_found (status1)); bool result (true); @@ -25,44 +25,44 @@ bool nano::rocksdb::account_store::get (nano::transaction const & transaction, n return result; } -void nano::rocksdb::account_store::del (nano::write_transaction const & transaction_a, nano::account const & account_a) +void nano::store::rocksdb::account::del (store::write_transaction const & transaction_a, nano::account const & account_a) { auto status = store.del (transaction_a, tables::accounts, account_a); store.release_assert_success (status); } -bool nano::rocksdb::account_store::exists (nano::transaction const & transaction_a, nano::account const & account_a) +bool nano::store::rocksdb::account::exists (store::transaction const & transaction_a, nano::account const & account_a) { auto iterator (begin (transaction_a, account_a)); return iterator != end () && nano::account (iterator->first) == account_a; } -size_t nano::rocksdb::account_store::count (nano::transaction const & transaction_a) +size_t nano::store::rocksdb::account::count (store::transaction const & transaction_a) { return store.count (transaction_a, tables::accounts); } -nano::store_iterator nano::rocksdb::account_store::begin (nano::transaction const & transaction, nano::account const & account) const +nano::store::iterator nano::store::rocksdb::account::begin (store::transaction const & transaction, nano::account const & account) const { return store.make_iterator (transaction, tables::accounts, account); } -nano::store_iterator nano::rocksdb::account_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::rocksdb::account::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::accounts); } -nano::store_iterator nano::rocksdb::account_store::rbegin (nano::transaction const & transaction_a) const +nano::store::iterator nano::store::rocksdb::account::rbegin (store::transaction const & transaction_a) const { return store.make_iterator (transaction_a, tables::accounts, false); } -nano::store_iterator nano::rocksdb::account_store::end () const +nano::store::iterator nano::store::rocksdb::account::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::rocksdb::account_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::rocksdb::account::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/account.hpp b/nano/store/rocksdb/account.hpp index dfac80e1d0..df5752b4fc 100644 --- a/nano/store/rocksdb/account.hpp +++ b/nano/store/rocksdb/account.hpp @@ -2,28 +2,28 @@ #include -namespace nano +namespace nano::store::rocksdb { -namespace rocksdb +class component; +} +namespace nano::store::rocksdb +{ +class account : public nano::store::account { - class store; - class account_store : public nano::account_store - { - private: - nano::rocksdb::store & store; +private: + nano::store::rocksdb::component & store; - public: - explicit account_store (nano::rocksdb::store & store_a); - void put (nano::write_transaction const & transaction, nano::account const & account, nano::account_info const & info) override; - bool get (nano::transaction const & transaction_a, nano::account const & account_a, nano::account_info & info_a) override; - void del (nano::write_transaction const & transaction_a, nano::account const & account_a) override; - bool exists (nano::transaction const & transaction_a, nano::account const & account_a) override; - size_t count (nano::transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::account const & account_a) const override; - nano::store_iterator begin (nano::transaction const & transaction_a) const override; - nano::store_iterator rbegin (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; - }; -} -} +public: + explicit account (nano::store::rocksdb::component & store_a); + void put (store::write_transaction const & transaction, nano::account const & account, nano::account_info const & info) override; + bool get (store::transaction const & transaction_a, nano::account const & account_a, nano::account_info & info_a) override; + void del (store::write_transaction const & transaction_a, nano::account const & account_a) override; + bool exists (store::transaction const & transaction_a, nano::account const & account_a) override; + size_t count (store::transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator rbegin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/block.cpp b/nano/store/rocksdb/block.cpp index 69e0118513..fbf1ecf1f0 100644 --- a/nano/store/rocksdb/block.cpp +++ b/nano/store/rocksdb/block.cpp @@ -10,7 +10,7 @@ namespace nano class block_predecessor_rocksdb_set : public nano::block_visitor { public: - block_predecessor_rocksdb_set (nano::write_transaction const & transaction_a, nano::rocksdb::block_store & block_store_a); + block_predecessor_rocksdb_set (store::write_transaction const & transaction_a, nano::store::rocksdb::block & block_store_a); virtual ~block_predecessor_rocksdb_set () = default; void fill_value (nano::block const & block_a); void send_block (nano::send_block const & block_a) override; @@ -18,15 +18,15 @@ class block_predecessor_rocksdb_set : public nano::block_visitor void open_block (nano::open_block const & block_a) override; void change_block (nano::change_block const & block_a) override; void state_block (nano::state_block const & block_a) override; - nano::write_transaction const & transaction; - nano::rocksdb::block_store & block_store; + store::write_transaction const & transaction; + nano::store::rocksdb::block & block_store; }; } -nano::rocksdb::block_store::block_store (nano::rocksdb::store & store_a) : +nano::store::rocksdb::block::block (nano::store::rocksdb::component & store_a) : store{ store_a } {}; -void nano::rocksdb::block_store::put (nano::write_transaction const & transaction, nano::block_hash const & hash, nano::block const & block) +void nano::store::rocksdb::block::put (store::write_transaction const & transaction, nano::block_hash const & hash, nano::block const & block) { debug_assert (block.sideband ().successor.is_zero () || exists (transaction, block.sideband ().successor)); std::vector vector; @@ -41,16 +41,16 @@ void nano::rocksdb::block_store::put (nano::write_transaction const & transactio debug_assert (block.previous ().is_zero () || successor (transaction, block.previous ()) == hash); } -void nano::rocksdb::block_store::raw_put (nano::write_transaction const & transaction_a, std::vector const & data, nano::block_hash const & hash_a) +void nano::store::rocksdb::block::raw_put (store::write_transaction const & transaction_a, std::vector const & data, nano::block_hash const & hash_a) { - nano::rocksdb_val value{ data.size (), (void *)data.data () }; + nano::store::rocksdb::db_val value{ data.size (), (void *)data.data () }; auto status = store.put (transaction_a, tables::blocks, hash_a, value); store.release_assert_success (status); } -nano::block_hash nano::rocksdb::block_store::successor (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const +nano::block_hash nano::store::rocksdb::block::successor (store::transaction const & transaction_a, nano::block_hash const & hash_a) const { - nano::rocksdb_val value; + nano::store::rocksdb::db_val value; block_raw_get (transaction_a, hash_a, value); nano::block_hash result; if (value.size () != 0) @@ -69,9 +69,9 @@ nano::block_hash nano::rocksdb::block_store::successor (nano::transaction const return result; } -void nano::rocksdb::block_store::successor_clear (nano::write_transaction const & transaction, nano::block_hash const & hash) +void nano::store::rocksdb::block::successor_clear (store::write_transaction const & transaction, nano::block_hash const & hash) { - nano::rocksdb_val value; + nano::store::rocksdb::db_val value; block_raw_get (transaction, hash, value); debug_assert (value.size () != 0); auto type = block_type_from_raw (value.data ()); @@ -80,9 +80,9 @@ void nano::rocksdb::block_store::successor_clear (nano::write_transaction const raw_put (transaction, data, hash); } -std::shared_ptr nano::rocksdb::block_store::get (nano::transaction const & transaction, nano::block_hash const & hash) const +std::shared_ptr nano::store::rocksdb::block::get (store::transaction const & transaction, nano::block_hash const & hash) const { - nano::rocksdb_val value; + nano::store::rocksdb::db_val value; block_raw_get (transaction, hash, value); std::shared_ptr result; if (value.size () != 0) @@ -100,8 +100,7 @@ std::shared_ptr nano::rocksdb::block_store::get (nano::transaction } return result; } - -std::shared_ptr nano::rocksdb::block_store::random (nano::transaction const & transaction) +std::shared_ptr nano::store::rocksdb::block::random (store::transaction const & transaction) { nano::block_hash hash; nano::random_pool::generate_block (hash.bytes.data (), hash.bytes.size ()); @@ -114,40 +113,39 @@ std::shared_ptr nano::rocksdb::block_store::random (nano::transacti return existing->second.block; } -void nano::rocksdb::block_store::del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) +void nano::store::rocksdb::block::del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) { auto status = store.del (transaction_a, tables::blocks, hash_a); store.release_assert_success (status); } -bool nano::rocksdb::block_store::exists (nano::transaction const & transaction, nano::block_hash const & hash) +bool nano::store::rocksdb::block::exists (store::transaction const & transaction, nano::block_hash const & hash) { - nano::rocksdb_val junk; + nano::store::rocksdb::db_val junk; block_raw_get (transaction, hash, junk); return junk.size () != 0; } -uint64_t nano::rocksdb::block_store::count (nano::transaction const & transaction_a) +uint64_t nano::store::rocksdb::block::count (store::transaction const & transaction_a) { return store.count (transaction_a, tables::blocks); } - -nano::store_iterator nano::rocksdb::block_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::rocksdb::block::begin (store::transaction const & transaction) const { - return store.make_iterator (transaction, tables::blocks); + return store.make_iterator (transaction, tables::blocks); } -nano::store_iterator nano::rocksdb::block_store::begin (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::store::iterator nano::store::rocksdb::block::begin (store::transaction const & transaction, nano::block_hash const & hash) const { - return store.make_iterator (transaction, tables::blocks, hash); + return store.make_iterator (transaction, tables::blocks, hash); } -nano::store_iterator nano::rocksdb::block_store::end () const +nano::store::iterator nano::store::rocksdb::block::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::rocksdb::block_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::rocksdb::block::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { @@ -156,24 +154,24 @@ void nano::rocksdb::block_store::for_each_par (std::function ((reinterpret_cast (data_a))[0]); } -nano::block_predecessor_rocksdb_set::block_predecessor_rocksdb_set (nano::write_transaction const & transaction_a, nano::rocksdb::block_store & block_store_a) : +nano::block_predecessor_rocksdb_set::block_predecessor_rocksdb_set (store::write_transaction const & transaction_a, nano::store::rocksdb::block & block_store_a) : transaction{ transaction_a }, block_store{ block_store_a } { @@ -181,7 +179,7 @@ nano::block_predecessor_rocksdb_set::block_predecessor_rocksdb_set (nano::write_ void nano::block_predecessor_rocksdb_set::fill_value (nano::block const & block_a) { auto hash = block_a.hash (); - nano::rocksdb_val value; + nano::store::rocksdb::db_val value; block_store.block_raw_get (transaction, block_a.previous (), value); debug_assert (value.size () != 0); auto type = block_store.block_type_from_raw (value.data ()); diff --git a/nano/store/rocksdb/block.hpp b/nano/store/rocksdb/block.hpp index 21264bd679..6ecf26fd62 100644 --- a/nano/store/rocksdb/block.hpp +++ b/nano/store/rocksdb/block.hpp @@ -6,34 +6,37 @@ namespace nano { class block_predecessor_rocksdb_set; -namespace rocksdb +} +namespace nano::store::rocksdb +{ +class component; +} +namespace nano::store::rocksdb { - class store; - class block_store : public nano::block_store - { - friend class nano::block_predecessor_rocksdb_set; - nano::rocksdb::store & store; +class block : public nano::store::block +{ + friend class nano::block_predecessor_rocksdb_set; + nano::store::rocksdb::component & store; - public: - explicit block_store (nano::rocksdb::store & store_a); - void put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a, nano::block const & block_a) override; - void raw_put (nano::write_transaction const & transaction_a, std::vector const & data, nano::block_hash const & hash_a) override; - nano::block_hash successor (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - void successor_clear (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; - std::shared_ptr get (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - std::shared_ptr random (nano::transaction const & transaction_a) override; - void del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; - bool exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) override; - uint64_t count (nano::transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a) const override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - nano::store_iterator end () const override; - void for_each_par (std::function, nano::store_iterator)> const & action_a) const override; +public: + explicit block (nano::store::rocksdb::component & store_a); + void put (store::write_transaction const & transaction_a, nano::block_hash const & hash_a, nano::block const & block_a) override; + void raw_put (store::write_transaction const & transaction_a, std::vector const & data, nano::block_hash const & hash_a) override; + nano::block_hash successor (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + void successor_clear (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; + std::shared_ptr get (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + std::shared_ptr random (store::transaction const & transaction_a) override; + void del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; + bool exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) override; + uint64_t count (store::transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; - protected: - void block_raw_get (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::rocksdb_val & value) const; - size_t block_successor_offset (nano::transaction const & transaction_a, size_t entry_size_a, nano::block_type type_a) const; - static nano::block_type block_type_from_raw (void * data_a); - }; -} -} +protected: + void block_raw_get (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::store::rocksdb::db_val & value) const; + size_t block_successor_offset (store::transaction const & transaction_a, size_t entry_size_a, nano::block_type type_a) const; + static nano::block_type block_type_from_raw (void * data_a); +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/confirmation_height.cpp b/nano/store/rocksdb/confirmation_height.cpp index 0ac8d61118..380cd80e32 100644 --- a/nano/store/rocksdb/confirmation_height.cpp +++ b/nano/store/rocksdb/confirmation_height.cpp @@ -2,20 +2,20 @@ #include #include -nano::rocksdb::confirmation_height_store::confirmation_height_store (nano::rocksdb::store & store) : +nano::store::rocksdb::confirmation_height::confirmation_height (nano::store::rocksdb::component & store) : store{ store } { } -void nano::rocksdb::confirmation_height_store::put (nano::write_transaction const & transaction, nano::account const & account, nano::confirmation_height_info const & confirmation_height_info) +void nano::store::rocksdb::confirmation_height::put (store::write_transaction const & transaction, nano::account const & account, nano::confirmation_height_info const & confirmation_height_info) { auto status = store.put (transaction, tables::confirmation_height, account, confirmation_height_info); store.release_assert_success (status); } -bool nano::rocksdb::confirmation_height_store::get (nano::transaction const & transaction, nano::account const & account, nano::confirmation_height_info & confirmation_height_info) +bool nano::store::rocksdb::confirmation_height::get (store::transaction const & transaction, nano::account const & account, nano::confirmation_height_info & confirmation_height_info) { - nano::rocksdb_val value; + nano::store::rocksdb::db_val value; auto status = store.get (transaction, tables::confirmation_height, account, value); release_assert (store.success (status) || store.not_found (status)); bool result (true); @@ -33,48 +33,48 @@ bool nano::rocksdb::confirmation_height_store::get (nano::transaction const & tr return result; } -bool nano::rocksdb::confirmation_height_store::exists (nano::transaction const & transaction, nano::account const & account) const +bool nano::store::rocksdb::confirmation_height::exists (store::transaction const & transaction, nano::account const & account) const { return store.exists (transaction, tables::confirmation_height, account); } -void nano::rocksdb::confirmation_height_store::del (nano::write_transaction const & transaction, nano::account const & account) +void nano::store::rocksdb::confirmation_height::del (store::write_transaction const & transaction, nano::account const & account) { auto status = store.del (transaction, tables::confirmation_height, account); store.release_assert_success (status); } -uint64_t nano::rocksdb::confirmation_height_store::count (nano::transaction const & transaction) +uint64_t nano::store::rocksdb::confirmation_height::count (store::transaction const & transaction) { return store.count (transaction, tables::confirmation_height); } -void nano::rocksdb::confirmation_height_store::clear (nano::write_transaction const & transaction, nano::account const & account) +void nano::store::rocksdb::confirmation_height::clear (store::write_transaction const & transaction, nano::account const & account) { del (transaction, account); } -void nano::rocksdb::confirmation_height_store::clear (nano::write_transaction const & transaction) +void nano::store::rocksdb::confirmation_height::clear (store::write_transaction const & transaction) { store.drop (transaction, nano::tables::confirmation_height); } -nano::store_iterator nano::rocksdb::confirmation_height_store::begin (nano::transaction const & transaction, nano::account const & account) const +nano::store::iterator nano::store::rocksdb::confirmation_height::begin (store::transaction const & transaction, nano::account const & account) const { return store.make_iterator (transaction, tables::confirmation_height, account); } -nano::store_iterator nano::rocksdb::confirmation_height_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::rocksdb::confirmation_height::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::confirmation_height); } -nano::store_iterator nano::rocksdb::confirmation_height_store::end () const +nano::store::iterator nano::store::rocksdb::confirmation_height::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::rocksdb::confirmation_height_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::rocksdb::confirmation_height::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/confirmation_height.hpp b/nano/store/rocksdb/confirmation_height.hpp index abb4668ba4..95d7300468 100644 --- a/nano/store/rocksdb/confirmation_height.hpp +++ b/nano/store/rocksdb/confirmation_height.hpp @@ -2,28 +2,28 @@ #include -namespace nano +namespace nano::store::rocksdb { -namespace rocksdb +class component; +} +namespace nano::store::rocksdb +{ +class confirmation_height : public nano::store::confirmation_height { - class store; - class confirmation_height_store : public nano::confirmation_height_store - { - nano::rocksdb::store & store; + nano::store::rocksdb::component & store; - public: - explicit confirmation_height_store (nano::rocksdb::store & store_a); - void put (nano::write_transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a) override; - bool get (nano::transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info & confirmation_height_info_a) override; - bool exists (nano::transaction const & transaction_a, nano::account const & account_a) const override; - void del (nano::write_transaction const & transaction_a, nano::account const & account_a) override; - uint64_t count (nano::transaction const & transaction_a) override; - void clear (nano::write_transaction const & transaction_a, nano::account const & account_a) override; - void clear (nano::write_transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::account const & account_a) const override; - 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; - }; -} -} +public: + explicit confirmation_height (nano::store::rocksdb::component & store_a); + void put (store::write_transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a) override; + bool get (store::transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info & confirmation_height_info_a) override; + bool exists (store::transaction const & transaction_a, nano::account const & account_a) const override; + void del (store::write_transaction const & transaction_a, nano::account const & account_a) override; + uint64_t count (store::transaction const & transaction_a) override; + void clear (store::write_transaction const & transaction_a, nano::account const & account_a) override; + void clear (store::write_transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/db_val.cpp b/nano/store/rocksdb/db_val.cpp index 2c56704321..e31654bbad 100644 --- a/nano/store/rocksdb/db_val.cpp +++ b/nano/store/rocksdb/db_val.cpp @@ -1,28 +1,25 @@ #include -namespace nano -{ template <> -void * rocksdb_val::data () const +void * nano::store::rocksdb::db_val::data () const { return (void *)value.data (); } template <> -std::size_t rocksdb_val::size () const +std::size_t nano::store::rocksdb::db_val::size () const { return value.size (); } template <> -rocksdb_val::db_val (std::size_t size_a, void * data_a) : +nano::store::rocksdb::db_val::db_val (std::size_t size_a, void * data_a) : value (static_cast (data_a), size_a) { } template <> -void rocksdb_val::convert_buffer_to_value () +void nano::store::rocksdb::db_val::convert_buffer_to_value () { value = ::rocksdb::Slice (reinterpret_cast (buffer->data ()), buffer->size ()); } -} diff --git a/nano/store/rocksdb/db_val.hpp b/nano/store/rocksdb/db_val.hpp index c1dd18d295..9c1085ee57 100644 --- a/nano/store/rocksdb/db_val.hpp +++ b/nano/store/rocksdb/db_val.hpp @@ -4,7 +4,7 @@ #include -namespace nano +namespace nano::store::rocksdb { -using rocksdb_val = db_val<::rocksdb::Slice>; +using db_val = store::db_val<::rocksdb::Slice>; } diff --git a/nano/store/rocksdb/final_vote.cpp b/nano/store/rocksdb/final_vote.cpp index eb03e75fec..121da33360 100644 --- a/nano/store/rocksdb/final_vote.cpp +++ b/nano/store/rocksdb/final_vote.cpp @@ -2,12 +2,12 @@ #include #include -nano::rocksdb::final_vote_store::final_vote_store (nano::rocksdb::store & store) : +nano::store::rocksdb::final_vote::final_vote (nano::store::rocksdb::component & store) : store{ store } {}; -bool nano::rocksdb::final_vote_store::put (nano::write_transaction const & transaction, nano::qualified_root const & root, nano::block_hash const & hash) +bool nano::store::rocksdb::final_vote::put (store::write_transaction const & transaction, nano::qualified_root const & root, nano::block_hash const & hash) { - nano::rocksdb_val value; + nano::store::rocksdb::db_val value; auto status = store.get (transaction, tables::final_votes, root, value); release_assert (store.success (status) || store.not_found (status)); bool result (true); @@ -23,7 +23,7 @@ bool nano::rocksdb::final_vote_store::put (nano::write_transaction const & trans return result; } -std::vector nano::rocksdb::final_vote_store::get (nano::transaction const & transaction, nano::root const & root_a) +std::vector nano::store::rocksdb::final_vote::get (store::transaction const & transaction, nano::root const & root_a) { std::vector result; nano::qualified_root key_start{ root_a.raw, 0 }; @@ -34,7 +34,7 @@ std::vector nano::rocksdb::final_vote_store::get (nano::transa return result; } -void nano::rocksdb::final_vote_store::del (nano::write_transaction const & transaction, nano::root const & root) +void nano::store::rocksdb::final_vote::del (store::write_transaction const & transaction, nano::root const & root) { std::vector final_vote_qualified_roots; for (auto i = begin (transaction, nano::qualified_root{ root.raw, 0 }), n = end (); i != n && nano::qualified_root{ i->first }.root () == root; ++i) @@ -49,37 +49,37 @@ void nano::rocksdb::final_vote_store::del (nano::write_transaction const & trans } } -size_t nano::rocksdb::final_vote_store::count (nano::transaction const & transaction_a) const +size_t nano::store::rocksdb::final_vote::count (store::transaction const & transaction_a) const { return store.count (transaction_a, tables::final_votes); } -void nano::rocksdb::final_vote_store::clear (nano::write_transaction const & transaction_a, nano::root const & root_a) +void nano::store::rocksdb::final_vote::clear (store::write_transaction const & transaction_a, nano::root const & root_a) { del (transaction_a, root_a); } -void nano::rocksdb::final_vote_store::clear (nano::write_transaction const & transaction_a) +void nano::store::rocksdb::final_vote::clear (store::write_transaction const & transaction_a) { store.drop (transaction_a, nano::tables::final_votes); } -nano::store_iterator nano::rocksdb::final_vote_store::begin (nano::transaction const & transaction, nano::qualified_root const & root) const +nano::store::iterator nano::store::rocksdb::final_vote::begin (store::transaction const & transaction, nano::qualified_root const & root) const { return store.make_iterator (transaction, tables::final_votes, root); } -nano::store_iterator nano::rocksdb::final_vote_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::rocksdb::final_vote::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::final_votes); } -nano::store_iterator nano::rocksdb::final_vote_store::end () const +nano::store::iterator nano::store::rocksdb::final_vote::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::rocksdb::final_vote_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::rocksdb::final_vote::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint512_t const & start, nano::uint512_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/final_vote.hpp b/nano/store/rocksdb/final_vote.hpp index 10b8a4ede0..d730ec08b8 100644 --- a/nano/store/rocksdb/final_vote.hpp +++ b/nano/store/rocksdb/final_vote.hpp @@ -2,28 +2,28 @@ #include -namespace nano +namespace nano::store::rocksdb { -namespace rocksdb +class component; +} +namespace nano::store::rocksdb +{ +class final_vote : public nano::store::final_vote { - class store; - class final_vote_store : public nano::final_vote_store - { - private: - nano::rocksdb::store & store; +private: + nano::store::rocksdb::component & store; - public: - explicit final_vote_store (nano::rocksdb::store & store); - bool put (nano::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) override; - std::vector get (nano::transaction const & transaction_a, nano::root const & root_a) override; - void del (nano::write_transaction const & transaction_a, nano::root const & root_a) override; - size_t count (nano::transaction const & transaction_a) const override; - void clear (nano::write_transaction const & transaction_a, nano::root const & root_a) override; - void clear (nano::write_transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::qualified_root const & root_a) const override; - 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; - }; -} -} +public: + explicit final_vote (nano::store::rocksdb::component & store); + bool put (store::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) override; + std::vector get (store::transaction const & transaction_a, nano::root const & root_a) override; + void del (store::write_transaction const & transaction_a, nano::root const & root_a) override; + size_t count (store::transaction const & transaction_a) const override; + void clear (store::write_transaction const & transaction_a, nano::root const & root_a) override; + void clear (store::write_transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/frontier.cpp b/nano/store/rocksdb/frontier.cpp index 51c02815e7..6724b93363 100644 --- a/nano/store/rocksdb/frontier.cpp +++ b/nano/store/rocksdb/frontier.cpp @@ -2,20 +2,20 @@ #include #include -nano::rocksdb::frontier_store::frontier_store (nano::rocksdb::store & store) : +nano::store::rocksdb::frontier::frontier (nano::store::rocksdb::component & store) : store{ store } { } -void nano::rocksdb::frontier_store::put (nano::write_transaction const & transaction, nano::block_hash const & block, nano::account const & account) +void nano::store::rocksdb::frontier::put (store::write_transaction const & transaction, nano::block_hash const & block, nano::account const & account) { auto status = store.put (transaction, tables::frontiers, block, account); store.release_assert_success (status); } -nano::account nano::rocksdb::frontier_store::get (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::account nano::store::rocksdb::frontier::get (store::transaction const & transaction, nano::block_hash const & hash) const { - nano::db_val<::rocksdb::Slice> value; + db_val value; auto status = store.get (transaction, tables::frontiers, hash, value); release_assert (store.success (status) || store.not_found (status)); nano::account result{}; @@ -26,28 +26,28 @@ nano::account nano::rocksdb::frontier_store::get (nano::transaction const & tran return result; } -void nano::rocksdb::frontier_store::del (nano::write_transaction const & transaction, nano::block_hash const & hash) +void nano::store::rocksdb::frontier::del (store::write_transaction const & transaction, nano::block_hash const & hash) { auto status = store.del (transaction, tables::frontiers, hash); store.release_assert_success (status); } -nano::store_iterator nano::rocksdb::frontier_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::rocksdb::frontier::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::frontiers); } -nano::store_iterator nano::rocksdb::frontier_store::begin (nano::transaction const & transaction, nano::block_hash const & hash) const +nano::store::iterator nano::store::rocksdb::frontier::begin (store::transaction const & transaction, nano::block_hash const & hash) const { return store.make_iterator (transaction, tables::frontiers, hash); } -nano::store_iterator nano::rocksdb::frontier_store::end () const +nano::store::iterator nano::store::rocksdb::frontier::end () const { - return nano::store_iterator (nullptr); + return nano::store::iterator (nullptr); } -void nano::rocksdb::frontier_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::rocksdb::frontier::for_each_par (std::function, nano::store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/frontier.hpp b/nano/store/rocksdb/frontier.hpp index e6b68ae95c..edc0e15b49 100644 --- a/nano/store/rocksdb/frontier.hpp +++ b/nano/store/rocksdb/frontier.hpp @@ -3,25 +3,25 @@ #include #include -namespace nano +namespace nano::store::rocksdb { -namespace rocksdb +class component; +} +namespace nano::store::rocksdb +{ +class frontier : public nano::store::frontier { - class store; - class frontier_store : public nano::frontier_store - { - public: - frontier_store (nano::rocksdb::store & store); - void put (nano::write_transaction const &, nano::block_hash const &, nano::account const &) override; - nano::account get (nano::transaction const &, nano::block_hash const &) const override; - void del (nano::write_transaction const &, nano::block_hash const &) override; - nano::store_iterator begin (nano::transaction const &) const override; - nano::store_iterator begin (nano::transaction const &, nano::block_hash const &) const override; - nano::store_iterator end () const override; - void for_each_par (std::function, nano::store_iterator)> const & action_a) const override; +public: + frontier (nano::store::rocksdb::component & store); + void put (store::write_transaction const &, nano::block_hash const &, nano::account const &) override; + nano::account get (store::transaction const &, nano::block_hash const &) const override; + void del (store::write_transaction const &, nano::block_hash const &) override; + store::iterator begin (store::transaction const &) const override; + store::iterator begin (store::transaction const &, nano::block_hash const &) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; - private: - nano::rocksdb::store & store; - }; -} -} +private: + nano::store::rocksdb::component & store; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/iterator.hpp b/nano/store/rocksdb/iterator.hpp index 8732a36678..0351367828 100644 --- a/nano/store/rocksdb/iterator.hpp +++ b/nano/store/rocksdb/iterator.hpp @@ -1,7 +1,9 @@ #pragma once #include -#include +#include +#include +#include #include #include @@ -11,29 +13,27 @@ namespace { -inline bool is_read (nano::transaction const & transaction_a) +inline bool is_read (nano::store::transaction const & transaction_a) { - return (dynamic_cast (&transaction_a) != nullptr); + return (dynamic_cast (&transaction_a) != nullptr); } -inline rocksdb::ReadOptions & snapshot_options (nano::transaction const & transaction_a) +inline rocksdb::ReadOptions & snapshot_options (nano::store::transaction const & transaction_a) { debug_assert (is_read (transaction_a)); return *static_cast (transaction_a.get_handle ()); } } -namespace nano +namespace nano::store::rocksdb { -using rocksdb_val = db_val<::rocksdb::Slice>; - template -class rocksdb_iterator : public store_iterator_impl +class iterator : public iterator_impl { public: - rocksdb_iterator () = default; + iterator () = default; - rocksdb_iterator (::rocksdb::DB * db, nano::transaction const & transaction_a, ::rocksdb::ColumnFamilyHandle * handle_a, rocksdb_val const * val_a, bool const direction_asc) + iterator (::rocksdb::DB * db, store::transaction const & transaction_a, ::rocksdb::ColumnFamilyHandle * handle_a, db_val const * val_a, bool const direction_asc) { // Don't fill the block cache for any blocks read as a result of an iterator if (is_read (transaction_a)) @@ -73,21 +73,21 @@ class rocksdb_iterator : public store_iterator_impl } } - rocksdb_iterator (::rocksdb::DB * db, nano::transaction const & transaction_a, ::rocksdb::ColumnFamilyHandle * handle_a) : - rocksdb_iterator (db, transaction_a, handle_a, nullptr) + iterator (::rocksdb::DB * db, store::transaction const & transaction_a, ::rocksdb::ColumnFamilyHandle * handle_a) : + iterator (db, transaction_a, handle_a, nullptr) { } - rocksdb_iterator (nano::rocksdb_iterator && other_a) + iterator (nano::store::rocksdb::iterator && other_a) { cursor = other_a.cursor; other_a.cursor = nullptr; current = other_a.current; } - rocksdb_iterator (nano::rocksdb_iterator const &) = delete; + iterator (nano::store::rocksdb::iterator const &) = delete; - nano::store_iterator_impl & operator++ () override + store::iterator_impl & operator++ () override { cursor->Next (); if (cursor->Valid ()) @@ -108,7 +108,7 @@ class rocksdb_iterator : public store_iterator_impl return *this; } - nano::store_iterator_impl & operator-- () override + store::iterator_impl & operator-- () override { cursor->Prev (); if (cursor->Valid ()) @@ -129,14 +129,14 @@ class rocksdb_iterator : public store_iterator_impl return *this; } - std::pair * operator-> () + std::pair * operator-> () { return ¤t; } - bool operator== (nano::store_iterator_impl const & base_a) const override + bool operator== (store::iterator_impl const & base_a) const override { - auto const other_a (boost::polymorphic_downcast const *> (&base_a)); + auto const other_a (boost::polymorphic_downcast const *> (&base_a)); if (!current.first.data () && !other_a->current.first.data ()) { @@ -182,23 +182,23 @@ class rocksdb_iterator : public store_iterator_impl } void clear () { - current.first = nano::rocksdb_val{}; - current.second = nano::rocksdb_val{}; + current.first = nano::store::rocksdb::db_val{}; + current.second = nano::store::rocksdb::db_val{}; debug_assert (is_end_sentinal ()); } - nano::rocksdb_iterator & operator= (nano::rocksdb_iterator && other_a) + nano::store::rocksdb::iterator & operator= (nano::store::rocksdb::iterator && other_a) { cursor = std::move (other_a.cursor); current = other_a.current; return *this; } - nano::store_iterator_impl & operator= (nano::store_iterator_impl const &) = delete; + store::iterator_impl & operator= (store::iterator_impl const &) = delete; std::unique_ptr<::rocksdb::Iterator> cursor; - std::pair current; + std::pair current; private: - ::rocksdb::Transaction * tx (nano::transaction const & transaction_a) const + ::rocksdb::Transaction * tx (store::transaction const & transaction_a) const { return static_cast<::rocksdb::Transaction *> (transaction_a.get_handle ()); } diff --git a/nano/store/rocksdb/online_weight.cpp b/nano/store/rocksdb/online_weight.cpp index f8f88ea1ca..c6f7e1dacf 100644 --- a/nano/store/rocksdb/online_weight.cpp +++ b/nano/store/rocksdb/online_weight.cpp @@ -1,44 +1,44 @@ #include #include -nano::rocksdb::online_weight_store::online_weight_store (nano::rocksdb::store & store_a) : +nano::store::rocksdb::online_weight::online_weight (nano::store::rocksdb::component & store_a) : store{ store_a } { } -void nano::rocksdb::online_weight_store::put (nano::write_transaction const & transaction, uint64_t time, nano::amount const & amount) +void nano::store::rocksdb::online_weight::put (store::write_transaction const & transaction, uint64_t time, nano::amount const & amount) { auto status = store.put (transaction, tables::online_weight, time, amount); store.release_assert_success (status); } -void nano::rocksdb::online_weight_store::del (nano::write_transaction const & transaction, uint64_t time) +void nano::store::rocksdb::online_weight::del (store::write_transaction const & transaction, uint64_t time) { auto status = store.del (transaction, tables::online_weight, time); store.release_assert_success (status); } -nano::store_iterator nano::rocksdb::online_weight_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::rocksdb::online_weight::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::online_weight); } -nano::store_iterator nano::rocksdb::online_weight_store::rbegin (nano::transaction const & transaction) const +nano::store::iterator nano::store::rocksdb::online_weight::rbegin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::online_weight, false); } -nano::store_iterator nano::rocksdb::online_weight_store::end () const +nano::store::iterator nano::store::rocksdb::online_weight::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -size_t nano::rocksdb::online_weight_store::count (nano::transaction const & transaction) const +size_t nano::store::rocksdb::online_weight::count (store::transaction const & transaction) const { return store.count (transaction, tables::online_weight); } -void nano::rocksdb::online_weight_store::clear (nano::write_transaction const & transaction) +void nano::store::rocksdb::online_weight::clear (store::write_transaction const & transaction) { auto status = store.drop (transaction, tables::online_weight); store.release_assert_success (status); diff --git a/nano/store/rocksdb/online_weight.hpp b/nano/store/rocksdb/online_weight.hpp index ab4325328b..68718f3e0b 100644 --- a/nano/store/rocksdb/online_weight.hpp +++ b/nano/store/rocksdb/online_weight.hpp @@ -2,25 +2,25 @@ #include -namespace nano +namespace nano::store::rocksdb { -namespace rocksdb +class component; +} +namespace nano::store::rocksdb +{ +class online_weight : public nano::store::online_weight { - class store; - class online_weight_store : public nano::online_weight_store - { - private: - nano::rocksdb::store & store; +private: + nano::store::rocksdb::component & store; - public: - explicit online_weight_store (nano::rocksdb::store & store_a); - void put (nano::write_transaction const & transaction_a, uint64_t time_a, nano::amount const & amount_a) override; - void del (nano::write_transaction const & transaction_a, uint64_t time_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a) const override; - nano::store_iterator rbegin (nano::transaction const & transaction_a) const override; - nano::store_iterator end () const override; - size_t count (nano::transaction const & transaction_a) const override; - void clear (nano::write_transaction const & transaction_a) override; - }; -} -} +public: + explicit online_weight (nano::store::rocksdb::component & store_a); + void put (store::write_transaction const & transaction_a, uint64_t time_a, nano::amount const & amount_a) override; + void del (store::write_transaction const & transaction_a, uint64_t time_a) override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator rbegin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + size_t count (store::transaction const & transaction_a) const override; + void clear (store::write_transaction const & transaction_a) override; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/peer.cpp b/nano/store/rocksdb/peer.cpp index 22d620ecc3..e837521605 100644 --- a/nano/store/rocksdb/peer.cpp +++ b/nano/store/rocksdb/peer.cpp @@ -1,43 +1,43 @@ #include #include -nano::rocksdb::peer_store::peer_store (nano::rocksdb::store & store) : +nano::store::rocksdb::peer::peer (nano::store::rocksdb::component & store) : store{ store } {}; -void nano::rocksdb::peer_store::put (nano::write_transaction const & transaction, nano::endpoint_key const & endpoint) +void nano::store::rocksdb::peer::put (store::write_transaction const & transaction, nano::endpoint_key const & endpoint) { auto status = store.put (transaction, tables::peers, endpoint, nullptr); store.release_assert_success (status); } -void nano::rocksdb::peer_store::del (nano::write_transaction const & transaction, nano::endpoint_key const & endpoint) +void nano::store::rocksdb::peer::del (store::write_transaction const & transaction, nano::endpoint_key const & endpoint) { auto status = store.del (transaction, tables::peers, endpoint); store.release_assert_success (status); } -bool nano::rocksdb::peer_store::exists (nano::transaction const & transaction, nano::endpoint_key const & endpoint) const +bool nano::store::rocksdb::peer::exists (store::transaction const & transaction, nano::endpoint_key const & endpoint) const { return store.exists (transaction, tables::peers, endpoint); } -size_t nano::rocksdb::peer_store::count (nano::transaction const & transaction) const +size_t nano::store::rocksdb::peer::count (store::transaction const & transaction) const { return store.count (transaction, tables::peers); } -void nano::rocksdb::peer_store::clear (nano::write_transaction const & transaction) +void nano::store::rocksdb::peer::clear (store::write_transaction const & transaction) { auto status = store.drop (transaction, tables::peers); store.release_assert_success (status); } -nano::store_iterator nano::rocksdb::peer_store::begin (nano::transaction const & transaction) const +nano::store::iterator nano::store::rocksdb::peer::begin (store::transaction const & transaction) const { return store.make_iterator (transaction, tables::peers); } -nano::store_iterator nano::rocksdb::peer_store::end () const +nano::store::iterator nano::store::rocksdb::peer::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } diff --git a/nano/store/rocksdb/peer.hpp b/nano/store/rocksdb/peer.hpp index 16dbabf543..3c6473701a 100644 --- a/nano/store/rocksdb/peer.hpp +++ b/nano/store/rocksdb/peer.hpp @@ -2,25 +2,25 @@ #include -namespace nano +namespace nano::store::rocksdb { -namespace rocksdb +class component; +} +namespace nano::store::rocksdb +{ +class peer : public nano::store::peer { - class store; - class peer_store : public nano::peer_store - { - private: - nano::rocksdb::store & store; +private: + nano::store::rocksdb::component & store; - public: - explicit peer_store (nano::rocksdb::store & store_a); - void put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override; - void del (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override; - bool exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const override; - size_t count (nano::transaction const & transaction_a) const override; - void clear (nano::write_transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a) const override; - nano::store_iterator end () const override; - }; -} -} +public: + explicit peer (nano::store::rocksdb::component & store_a); + void put (store::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override; + void del (store::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override; + bool exists (store::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const override; + size_t count (store::transaction const & transaction_a) const override; + void clear (store::write_transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator end () const override; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/pending.cpp b/nano/store/rocksdb/pending.cpp index 935f368b1f..f7e843f184 100644 --- a/nano/store/rocksdb/pending.cpp +++ b/nano/store/rocksdb/pending.cpp @@ -2,24 +2,24 @@ #include #include -nano::rocksdb::pending_store::pending_store (nano::rocksdb::store & store) : +nano::store::rocksdb::pending::pending (nano::store::rocksdb::component & store) : store{ store } {}; -void nano::rocksdb::pending_store::put (nano::write_transaction const & transaction, nano::pending_key const & key, nano::pending_info const & pending) +void nano::store::rocksdb::pending::put (store::write_transaction const & transaction, nano::pending_key const & key, nano::pending_info const & pending) { auto status = store.put (transaction, tables::pending, key, pending); store.release_assert_success (status); } -void nano::rocksdb::pending_store::del (nano::write_transaction const & transaction, nano::pending_key const & key) +void nano::store::rocksdb::pending::del (store::write_transaction const & transaction, nano::pending_key const & key) { auto status = store.del (transaction, tables::pending, key); store.release_assert_success (status); } -bool nano::rocksdb::pending_store::get (nano::transaction const & transaction, nano::pending_key const & key, nano::pending_info & pending) +bool nano::store::rocksdb::pending::get (store::transaction const & transaction, nano::pending_key const & key, nano::pending_info & pending) { - nano::rocksdb_val value; + nano::store::rocksdb::db_val value; auto status1 = store.get (transaction, tables::pending, key, value); release_assert (store.success (status1) || store.not_found (status1)); bool result (true); @@ -31,34 +31,34 @@ bool nano::rocksdb::pending_store::get (nano::transaction const & transaction, n return result; } -bool nano::rocksdb::pending_store::exists (nano::transaction const & transaction_a, nano::pending_key const & key_a) +bool nano::store::rocksdb::pending::exists (store::transaction const & transaction_a, nano::pending_key const & key_a) { auto iterator (begin (transaction_a, key_a)); return iterator != end () && nano::pending_key (iterator->first) == key_a; } -bool nano::rocksdb::pending_store::any (nano::transaction const & transaction_a, nano::account const & account_a) +bool nano::store::rocksdb::pending::any (store::transaction const & transaction_a, nano::account const & account_a) { auto iterator (begin (transaction_a, nano::pending_key (account_a, 0))); return iterator != end () && nano::pending_key (iterator->first).account == account_a; } -nano::store_iterator nano::rocksdb::pending_store::begin (nano::transaction const & transaction_a, nano::pending_key const & key_a) const +nano::store::iterator nano::store::rocksdb::pending::begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const { return store.template make_iterator (transaction_a, tables::pending, key_a); } -nano::store_iterator nano::rocksdb::pending_store::begin (nano::transaction const & transaction_a) const +nano::store::iterator nano::store::rocksdb::pending::begin (store::transaction const & transaction_a) const { return store.template make_iterator (transaction_a, tables::pending); } -nano::store_iterator nano::rocksdb::pending_store::end () const +nano::store::iterator nano::store::rocksdb::pending::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::rocksdb::pending_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::rocksdb::pending::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint512_t const & start, nano::uint512_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/pending.hpp b/nano/store/rocksdb/pending.hpp index afd773b02f..76a5f67d6d 100644 --- a/nano/store/rocksdb/pending.hpp +++ b/nano/store/rocksdb/pending.hpp @@ -2,27 +2,23 @@ #include -namespace nano +namespace nano::store::rocksdb { -namespace rocksdb +class pending : public nano::store::pending { - class store; - class pending_store : public nano::pending_store - { - private: - nano::rocksdb::store & store; +private: + nano::store::rocksdb::component & store; - public: - explicit pending_store (nano::rocksdb::store & store_a); - void put (nano::write_transaction const & transaction_a, nano::pending_key const & key_a, nano::pending_info const & pending_info_a) override; - void del (nano::write_transaction const & transaction_a, nano::pending_key const & key_a) override; - bool get (nano::transaction const & transaction_a, nano::pending_key const & key_a, nano::pending_info & pending_a) override; - bool exists (nano::transaction const & transaction_a, nano::pending_key const & key_a) override; - bool any (nano::transaction const & transaction_a, nano::account const & account_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::pending_key const & key_a) const override; - 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; - }; -} -} +public: + explicit pending (nano::store::rocksdb::component & store_a); + void put (store::write_transaction const & transaction_a, nano::pending_key const & key_a, nano::pending_info const & pending_info_a) override; + void del (store::write_transaction const & transaction_a, nano::pending_key const & key_a) override; + bool get (store::transaction const & transaction_a, nano::pending_key const & key_a, nano::pending_info & pending_a) override; + bool exists (store::transaction const & transaction_a, nano::pending_key const & key_a) override; + bool any (store::transaction const & transaction_a, nano::account const & account_a) override; + store::iterator begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/pruned.cpp b/nano/store/rocksdb/pruned.cpp index 6024682d19..41d7fbb586 100644 --- a/nano/store/rocksdb/pruned.cpp +++ b/nano/store/rocksdb/pruned.cpp @@ -2,27 +2,27 @@ #include #include -nano::rocksdb::pruned_store::pruned_store (nano::rocksdb::store & store_a) : +nano::store::rocksdb::pruned::pruned (nano::store::rocksdb::component & store_a) : store{ store_a } {}; -void nano::rocksdb::pruned_store::put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) +void nano::store::rocksdb::pruned::put (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) { auto status = store.put (transaction_a, tables::pruned, hash_a, nullptr); store.release_assert_success (status); } -void nano::rocksdb::pruned_store::del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) +void nano::store::rocksdb::pruned::del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) { auto status = store.del (transaction_a, tables::pruned, hash_a); store.release_assert_success (status); } -bool nano::rocksdb::pruned_store::exists (nano::transaction const & transaction, nano::block_hash const & hash_a) const +bool nano::store::rocksdb::pruned::exists (store::transaction const & transaction, nano::block_hash const & hash_a) const { return store.exists (transaction, tables::pruned, hash_a); } -nano::block_hash nano::rocksdb::pruned_store::random (nano::transaction const & transaction) +nano::block_hash nano::store::rocksdb::pruned::random (store::transaction const & transaction) { nano::block_hash random_hash; nano::random_pool::generate_block (random_hash.bytes.data (), random_hash.bytes.size ()); @@ -34,33 +34,33 @@ nano::block_hash nano::rocksdb::pruned_store::random (nano::transaction const & return existing != end () ? existing->first : 0; } -size_t nano::rocksdb::pruned_store::count (nano::transaction const & transaction_a) const +size_t nano::store::rocksdb::pruned::count (store::transaction const & transaction_a) const { return store.count (transaction_a, tables::pruned); } -void nano::rocksdb::pruned_store::clear (nano::write_transaction const & transaction_a) +void nano::store::rocksdb::pruned::clear (store::write_transaction const & transaction_a) { auto status = store.drop (transaction_a, tables::pruned); store.release_assert_success (status); } -nano::store_iterator nano::rocksdb::pruned_store::begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const +nano::store::iterator nano::store::rocksdb::pruned::begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const { return store.make_iterator (transaction_a, tables::pruned, hash_a); } -nano::store_iterator nano::rocksdb::pruned_store::begin (nano::transaction const & transaction_a) const +nano::store::iterator nano::store::rocksdb::pruned::begin (store::transaction const & transaction_a) const { return store.make_iterator (transaction_a, tables::pruned); } -nano::store_iterator nano::rocksdb::pruned_store::end () const +nano::store::iterator nano::store::rocksdb::pruned::end () const { - return nano::store_iterator (nullptr); + return store::iterator (nullptr); } -void nano::rocksdb::pruned_store::for_each_par (std::function, nano::store_iterator)> const & action_a) const +void nano::store::rocksdb::pruned::for_each_par (std::function, store::iterator)> const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/pruned.hpp b/nano/store/rocksdb/pruned.hpp index 29c03d7766..aa5db1fbab 100644 --- a/nano/store/rocksdb/pruned.hpp +++ b/nano/store/rocksdb/pruned.hpp @@ -2,28 +2,28 @@ #include -namespace nano +namespace nano::store::rocksdb { -namespace rocksdb +class component; +} +namespace nano::store::rocksdb +{ +class pruned : public nano::store::pruned { - class store; - class pruned_store : public nano::pruned_store - { - private: - nano::rocksdb::store & store; +private: + nano::store::rocksdb::component & store; - public: - explicit pruned_store (nano::rocksdb::store & store_a); - void put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; - void del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; - bool exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - nano::block_hash random (nano::transaction const & transaction_a) override; - size_t count (nano::transaction const & transaction_a) const override; - void clear (nano::write_transaction const & transaction_a) override; - nano::store_iterator begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - 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; - }; -} -} +public: + explicit pruned (nano::store::rocksdb::component & store_a); + void put (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; + void del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; + bool exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + nano::block_hash random (store::transaction const & transaction_a) override; + size_t count (store::transaction const & transaction_a) const override; + void clear (store::write_transaction const & transaction_a) override; + store::iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + store::iterator begin (store::transaction const & transaction_a) const override; + store::iterator end () const override; + void for_each_par (std::function, store::iterator)> const & action_a) const override; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index 204157b650..9b2aa7eb8a 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -35,7 +35,7 @@ class event_listener : public rocksdb::EventListener }; } -nano::rocksdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path const & path_a, nano::ledger_constants & constants, nano::rocksdb_config const & rocksdb_config_a, bool open_read_only_a) : +nano::store::rocksdb::component::component (nano::logger_mt & logger_a, boost::filesystem::path const & path_a, nano::ledger_constants & constants, nano::rocksdb_config const & rocksdb_config_a, bool open_read_only_a) : // clang-format off nano::store::component{ block_store, @@ -156,7 +156,7 @@ nano::rocksdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path } } -std::unordered_map nano::rocksdb::store::create_cf_name_table_map () const +std::unordered_map nano::store::rocksdb::component::create_cf_name_table_map () const { std::unordered_map map{ { ::rocksdb::kDefaultColumnFamilyName.c_str (), tables::default_unused }, { "frontiers", tables::frontiers }, @@ -175,7 +175,7 @@ std::unordered_map nano::rocksdb::store::create_cf_n return map; } -void nano::rocksdb::store::open (bool & error_a, boost::filesystem::path const & path_a, bool open_read_only_a, ::rocksdb::Options const & options_a, std::vector<::rocksdb::ColumnFamilyDescriptor> column_families) +void nano::store::rocksdb::component::open (bool & error_a, boost::filesystem::path const & path_a, bool open_read_only_a, ::rocksdb::Options const & options_a, std::vector<::rocksdb::ColumnFamilyDescriptor> column_families) { // auto options = get_db_options (); ::rocksdb::Status s; @@ -206,7 +206,7 @@ void nano::rocksdb::store::open (bool & error_a, boost::filesystem::path const & error_a |= !s.ok (); } -bool nano::rocksdb::store::do_upgrades (nano::write_transaction const & transaction_a) +bool nano::store::rocksdb::component::do_upgrades (store::write_transaction const & transaction_a) { bool error_l{ false }; auto version_l = version.get (transaction_a); @@ -248,7 +248,7 @@ bool nano::rocksdb::store::do_upgrades (nano::write_transaction const & transact return error_l; } -void nano::rocksdb::store::upgrade_v21_to_v22 (nano::write_transaction const & transaction_a) +void nano::store::rocksdb::component::upgrade_v21_to_v22 (store::write_transaction const & transaction_a) { logger.always_log ("Preparing v21 to v22 database upgrade..."); if (column_family_exists ("unchecked")) @@ -270,14 +270,14 @@ void nano::rocksdb::store::upgrade_v21_to_v22 (nano::write_transaction const & t logger.always_log ("Finished removing unchecked table"); } -void nano::rocksdb::store::generate_tombstone_map () +void nano::store::rocksdb::component::generate_tombstone_map () { tombstone_map.emplace (std::piecewise_construct, std::forward_as_tuple (nano::tables::blocks), std::forward_as_tuple (0, 25000)); tombstone_map.emplace (std::piecewise_construct, std::forward_as_tuple (nano::tables::accounts), std::forward_as_tuple (0, 25000)); tombstone_map.emplace (std::piecewise_construct, std::forward_as_tuple (nano::tables::pending), std::forward_as_tuple (0, 25000)); } -rocksdb::ColumnFamilyOptions nano::rocksdb::store::get_common_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a, unsigned long long memtable_size_bytes_a) const +rocksdb::ColumnFamilyOptions nano::store::rocksdb::component::get_common_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a, unsigned long long memtable_size_bytes_a) const { ::rocksdb::ColumnFamilyOptions cf_options; cf_options.table_factory = table_factory_a; @@ -309,7 +309,7 @@ rocksdb::ColumnFamilyOptions nano::rocksdb::store::get_common_cf_options (std::s return cf_options; } -rocksdb::ColumnFamilyOptions nano::rocksdb::store::get_cf_options (std::string const & cf_name_a) const +rocksdb::ColumnFamilyOptions nano::store::rocksdb::component::get_cf_options (std::string const & cf_name_a) const { ::rocksdb::ColumnFamilyOptions cf_options; auto const memtable_size_bytes = base_memtable_size_bytes (); @@ -389,7 +389,7 @@ rocksdb::ColumnFamilyOptions nano::rocksdb::store::get_cf_options (std::string c return cf_options; } -std::vector nano::rocksdb::store::create_column_families () +std::vector nano::store::rocksdb::component::create_column_families () { std::vector<::rocksdb::ColumnFamilyDescriptor> column_families; for (auto & [cf_name, table] : cf_name_table_map) @@ -400,37 +400,37 @@ std::vector nano::rocksdb::store::create_column return column_families; } -nano::write_transaction nano::rocksdb::store::tx_begin_write (std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a) +nano::store::write_transaction nano::store::rocksdb::component::tx_begin_write (std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a) { - std::unique_ptr txn; + std::unique_ptr txn; release_assert (optimistic_db != nullptr); if (tables_requiring_locks_a.empty () && tables_no_locks_a.empty ()) { // Use all tables if none are specified - txn = std::make_unique (optimistic_db, all_tables (), tables_no_locks_a, write_lock_mutexes); + txn = std::make_unique (optimistic_db, all_tables (), tables_no_locks_a, write_lock_mutexes); } else { - txn = std::make_unique (optimistic_db, tables_requiring_locks_a, tables_no_locks_a, write_lock_mutexes); + txn = std::make_unique (optimistic_db, tables_requiring_locks_a, tables_no_locks_a, write_lock_mutexes); } // Tables must be kept in alphabetical order. These can be used for mutex locking, so order is important to prevent deadlocking debug_assert (std::is_sorted (tables_requiring_locks_a.begin (), tables_requiring_locks_a.end ())); - return nano::write_transaction{ std::move (txn) }; + return store::write_transaction{ std::move (txn) }; } -nano::read_transaction nano::rocksdb::store::tx_begin_read () const +nano::store::read_transaction nano::store::rocksdb::component::tx_begin_read () const { - return nano::read_transaction{ std::make_unique (db.get ()) }; + return store::read_transaction{ std::make_unique (db.get ()) }; } -std::string nano::rocksdb::store::vendor_get () const +std::string nano::store::rocksdb::component::vendor_get () const { return boost::str (boost::format ("RocksDB %1%.%2%.%3%") % ROCKSDB_MAJOR % ROCKSDB_MINOR % ROCKSDB_PATCH); } -std::vector<::rocksdb::ColumnFamilyDescriptor> nano::rocksdb::store::get_single_column_family (std::string cf_name) const +std::vector<::rocksdb::ColumnFamilyDescriptor> nano::store::rocksdb::component::get_single_column_family (std::string cf_name) const { std::vector<::rocksdb::ColumnFamilyDescriptor> minimum_cf_set{ { ::rocksdb::kDefaultColumnFamilyName, ::rocksdb::ColumnFamilyOptions{} }, @@ -439,7 +439,7 @@ std::vector<::rocksdb::ColumnFamilyDescriptor> nano::rocksdb::store::get_single_ return minimum_cf_set; } -std::vector<::rocksdb::ColumnFamilyDescriptor> nano::rocksdb::store::get_current_column_families (std::string const & path_a, ::rocksdb::Options const & options_a) const +std::vector<::rocksdb::ColumnFamilyDescriptor> nano::store::rocksdb::component::get_current_column_families (std::string const & path_a, ::rocksdb::Options const & options_a) const { std::vector<::rocksdb::ColumnFamilyDescriptor> column_families; @@ -457,7 +457,7 @@ std::vector<::rocksdb::ColumnFamilyDescriptor> nano::rocksdb::store::get_current return column_families; } -rocksdb::ColumnFamilyHandle * nano::rocksdb::store::get_column_family (char const * name) const +rocksdb::ColumnFamilyHandle * nano::store::rocksdb::component::get_column_family (char const * name) const { auto & handles_l = handles; auto iter = std::find_if (handles_l.begin (), handles_l.end (), [name] (auto & handle) { @@ -467,7 +467,7 @@ rocksdb::ColumnFamilyHandle * nano::rocksdb::store::get_column_family (char cons return (*iter).get (); } -bool nano::rocksdb::store::column_family_exists (char const * name) const +bool nano::store::rocksdb::component::column_family_exists (char const * name) const { auto & handles_l = handles; auto iter = std::find_if (handles_l.begin (), handles_l.end (), [name] (auto & handle) { @@ -476,7 +476,7 @@ bool nano::rocksdb::store::column_family_exists (char const * name) const return (iter != handles_l.end ()); } -rocksdb::ColumnFamilyHandle * nano::rocksdb::store::table_to_column_family (tables table_a) const +rocksdb::ColumnFamilyHandle * nano::store::rocksdb::component::table_to_column_family (tables table_a) const { switch (table_a) { @@ -508,7 +508,7 @@ rocksdb::ColumnFamilyHandle * nano::rocksdb::store::table_to_column_family (tabl } } -bool nano::rocksdb::store::exists (nano::transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a) const +bool nano::store::rocksdb::component::exists (store::transaction const & transaction_a, tables table_a, nano::store::rocksdb::db_val const & key_a) const { ::rocksdb::PinnableSlice slice; ::rocksdb::Status status; @@ -526,7 +526,7 @@ bool nano::rocksdb::store::exists (nano::transaction const & transaction_a, tabl return (status.ok ()); } -int nano::rocksdb::store::del (nano::write_transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a) +int nano::store::rocksdb::component::del (store::write_transaction const & transaction_a, tables table_a, nano::store::rocksdb::db_val const & key_a) { debug_assert (transaction_a.contains (table_a)); // RocksDB does not report not_found status, it is a pre-condition that the key exists @@ -535,7 +535,7 @@ int nano::rocksdb::store::del (nano::write_transaction const & transaction_a, ta return tx (transaction_a)->Delete (table_to_column_family (table_a), key_a).code (); } -void nano::rocksdb::store::flush_tombstones_check (tables table_a) +void nano::store::rocksdb::component::flush_tombstones_check (tables table_a) { // Update the number of deletes for some tables, and force a flush if there are too many tombstones // as it can affect read performance. @@ -550,18 +550,18 @@ void nano::rocksdb::store::flush_tombstones_check (tables table_a) } } -void nano::rocksdb::store::flush_table (nano::tables table_a) +void nano::store::rocksdb::component::flush_table (nano::tables table_a) { db->Flush (::rocksdb::FlushOptions{}, table_to_column_family (table_a)); } -rocksdb::Transaction * nano::rocksdb::store::tx (nano::transaction const & transaction_a) const +rocksdb::Transaction * nano::store::rocksdb::component::tx (store::transaction const & transaction_a) const { debug_assert (!is_read (transaction_a)); return static_cast<::rocksdb::Transaction *> (transaction_a.get_handle ()); } -int nano::rocksdb::store::get (nano::transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a, nano::rocksdb_val & value_a) const +int nano::store::rocksdb::component::get (store::transaction const & transaction_a, tables table_a, nano::store::rocksdb::db_val const & key_a, nano::store::rocksdb::db_val & value_a) const { ::rocksdb::ReadOptions options; ::rocksdb::PinnableSlice slice; @@ -585,29 +585,29 @@ int nano::rocksdb::store::get (nano::transaction const & transaction_a, tables t return status.code (); } -int nano::rocksdb::store::put (nano::write_transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a, nano::rocksdb_val const & value_a) +int nano::store::rocksdb::component::put (store::write_transaction const & transaction_a, tables table_a, nano::store::rocksdb::db_val const & key_a, nano::store::rocksdb::db_val const & value_a) { debug_assert (transaction_a.contains (table_a)); auto txn = tx (transaction_a); return txn->Put (table_to_column_family (table_a), key_a, value_a).code (); } -bool nano::rocksdb::store::not_found (int status) const +bool nano::store::rocksdb::component::not_found (int status) const { return (status_code_not_found () == status); } -bool nano::rocksdb::store::success (int status) const +bool nano::store::rocksdb::component::success (int status) const { return (static_cast (::rocksdb::Status::Code::kOk) == status); } -int nano::rocksdb::store::status_code_not_found () const +int nano::store::rocksdb::component::status_code_not_found () const { return static_cast (::rocksdb::Status::Code::kNotFound); } -uint64_t nano::rocksdb::store::count (nano::transaction const & transaction_a, tables table_a) const +uint64_t nano::store::rocksdb::component::count (store::transaction const & transaction_a, tables table_a) const { uint64_t sum = 0; // Peers/online weight are small enough that they can just be iterated to get accurate counts. @@ -668,7 +668,7 @@ uint64_t nano::rocksdb::store::count (nano::transaction const & transaction_a, t return sum; } -int nano::rocksdb::store::drop (nano::write_transaction const & transaction_a, tables table_a) +int nano::store::rocksdb::component::drop (store::write_transaction const & transaction_a, tables table_a) { debug_assert (transaction_a.contains (table_a)); auto col = table_to_column_family (table_a); @@ -682,7 +682,7 @@ int nano::rocksdb::store::drop (nano::write_transaction const & transaction_a, t int status = 0; for (auto i = peer.begin (transaction_a), n = peer.end (); i != n; ++i) { - status = del (transaction_a, tables::peers, nano::rocksdb_val (i->first)); + status = del (transaction_a, tables::peers, nano::store::rocksdb::db_val (i->first)); release_assert (success (status)); } return status; @@ -695,7 +695,7 @@ int nano::rocksdb::store::drop (nano::write_transaction const & transaction_a, t return status; } -int nano::rocksdb::store::clear (::rocksdb::ColumnFamilyHandle * column_family) +int nano::store::rocksdb::component::clear (::rocksdb::ColumnFamilyHandle * column_family) { // Dropping completely removes the column auto name = column_family->GetName (); @@ -713,7 +713,7 @@ int nano::rocksdb::store::clear (::rocksdb::ColumnFamilyHandle * column_family) return status.code (); } -void nano::rocksdb::store::construct_column_family_mutexes () +void nano::store::rocksdb::component::construct_column_family_mutexes () { for (auto table : all_tables ()) { @@ -721,7 +721,7 @@ void nano::rocksdb::store::construct_column_family_mutexes () } } -rocksdb::Options nano::rocksdb::store::get_db_options () +rocksdb::Options nano::store::rocksdb::component::get_db_options () { ::rocksdb::Options db_options; db_options.create_if_missing = true; @@ -763,7 +763,7 @@ rocksdb::Options nano::rocksdb::store::get_db_options () return db_options; } -rocksdb::BlockBasedTableOptions nano::rocksdb::store::get_active_table_options (std::size_t lru_size) const +rocksdb::BlockBasedTableOptions nano::store::rocksdb::component::get_active_table_options (std::size_t lru_size) const { ::rocksdb::BlockBasedTableOptions table_options; @@ -792,7 +792,7 @@ rocksdb::BlockBasedTableOptions nano::rocksdb::store::get_active_table_options ( return table_options; } -rocksdb::BlockBasedTableOptions nano::rocksdb::store::get_small_table_options () const +rocksdb::BlockBasedTableOptions nano::store::rocksdb::component::get_small_table_options () const { ::rocksdb::BlockBasedTableOptions table_options; // Improve point lookup performance be using the data block hash index (uses about 5% more space). @@ -802,7 +802,7 @@ rocksdb::BlockBasedTableOptions nano::rocksdb::store::get_small_table_options () return table_options; } -rocksdb::ColumnFamilyOptions nano::rocksdb::store::get_small_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a) const +rocksdb::ColumnFamilyOptions nano::store::rocksdb::component::get_small_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a) const { auto const memtable_size_bytes = 10000; auto cf_options = get_common_cf_options (table_factory_a, memtable_size_bytes); @@ -816,7 +816,7 @@ rocksdb::ColumnFamilyOptions nano::rocksdb::store::get_small_cf_options (std::sh return cf_options; } -::rocksdb::ColumnFamilyOptions nano::rocksdb::store::get_active_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a, unsigned long long memtable_size_bytes_a) const +::rocksdb::ColumnFamilyOptions nano::store::rocksdb::component::get_active_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a, unsigned long long memtable_size_bytes_a) const { auto cf_options = get_common_cf_options (table_factory_a, memtable_size_bytes_a); @@ -832,7 +832,7 @@ ::rocksdb::ColumnFamilyOptions nano::rocksdb::store::get_active_cf_options (std: return cf_options; } -void nano::rocksdb::store::on_flush (::rocksdb::FlushJobInfo const & flush_job_info_a) +void nano::store::rocksdb::component::on_flush (::rocksdb::FlushJobInfo const & flush_job_info_a) { // Reset appropriate tombstone counters if (auto it = tombstone_map.find (cf_name_table_map[flush_job_info_a.cf_name.c_str ()]); it != tombstone_map.end ()) @@ -841,12 +841,12 @@ void nano::rocksdb::store::on_flush (::rocksdb::FlushJobInfo const & flush_job_i } } -std::vector nano::rocksdb::store::all_tables () const +std::vector nano::store::rocksdb::component::all_tables () const { return std::vector{ tables::accounts, tables::blocks, tables::confirmation_height, tables::final_votes, tables::frontiers, tables::meta, tables::online_weight, tables::peers, tables::pending, tables::pruned, tables::vote }; } -bool nano::rocksdb::store::copy_db (boost::filesystem::path const & destination_path) +bool nano::store::rocksdb::component::copy_db (boost::filesystem::path const & destination_path) { std::unique_ptr<::rocksdb::BackupEngine> backup_engine; { @@ -910,23 +910,23 @@ bool nano::rocksdb::store::copy_db (boost::filesystem::path const & destination_ // Open it so that it flushes all WAL files if (status.ok ()) { - nano::rocksdb::store rocksdb_store{ logger, destination_path.string (), constants, rocksdb_config, false }; + nano::store::rocksdb::component rocksdb_store{ logger, destination_path.string (), constants, rocksdb_config, false }; return !rocksdb_store.init_error (); } return false; } -void nano::rocksdb::store::rebuild_db (nano::write_transaction const & transaction_a) +void nano::store::rocksdb::component::rebuild_db (store::write_transaction const & transaction_a) { // Not available for RocksDB } -bool nano::rocksdb::store::init_error () const +bool nano::store::rocksdb::component::init_error () const { return error; } -void nano::rocksdb::store::serialize_memory_stats (boost::property_tree::ptree & json) +void nano::store::rocksdb::component::serialize_memory_stats (boost::property_tree::ptree & json) { uint64_t val; @@ -973,28 +973,28 @@ void nano::rocksdb::store::serialize_memory_stats (boost::property_tree::ptree & json.put ("block-cache-usage", val); } -unsigned long long nano::rocksdb::store::blocks_memtable_size_bytes () const +unsigned long long nano::store::rocksdb::component::blocks_memtable_size_bytes () const { return base_memtable_size_bytes (); } -unsigned long long nano::rocksdb::store::base_memtable_size_bytes () const +unsigned long long nano::store::rocksdb::component::base_memtable_size_bytes () const { return 1024ULL * 1024 * rocksdb_config.memory_multiplier * base_memtable_size; } // This is a ratio of the blocks memtable size to keep total write transaction commit size down. -unsigned nano::rocksdb::store::max_block_write_batch_num () const +unsigned nano::store::rocksdb::component::max_block_write_batch_num () const { return max_block_write_batch_num_m; } -std::string nano::rocksdb::store::error_string (int status) const +std::string nano::store::rocksdb::component::error_string (int status) const { return std::to_string (status); } -nano::rocksdb::store::tombstone_info::tombstone_info (uint64_t num_since_last_flush_a, uint64_t const max_a) : +nano::store::rocksdb::component::tombstone_info::tombstone_info (uint64_t num_since_last_flush_a, uint64_t const max_a) : num_since_last_flush (num_since_last_flush_a), max (max_a) { diff --git a/nano/store/rocksdb/rocksdb.hpp b/nano/store/rocksdb/rocksdb.hpp index 39c03b5c20..59484937e2 100644 --- a/nano/store/rocksdb/rocksdb.hpp +++ b/nano/store/rocksdb/rocksdb.hpp @@ -29,152 +29,152 @@ namespace nano class logging_mt; class rocksdb_config; class rocksdb_block_store_tombstone_count_Test; +} -namespace rocksdb +namespace nano::store::rocksdb { - class rocksdb_block_store_upgrade_v21_v22_Test; +class rocksdb_block_store_upgrade_v21_v22_Test; - /** +/** * rocksdb implementation of the block store */ - class store : public nano::store::component +class component : public nano::store::component +{ +private: + nano::store::rocksdb::account account_store; + nano::store::rocksdb::block block_store; + nano::store::rocksdb::confirmation_height confirmation_height_store; + nano::store::rocksdb::final_vote final_vote_store; + nano::store::rocksdb::frontier frontier_store; + nano::store::rocksdb::online_weight online_weight_store; + nano::store::rocksdb::peer peer_store; + nano::store::rocksdb::pending pending_store; + nano::store::rocksdb::pruned pruned_store; + nano::store::rocksdb::version version_store; + +public: + friend class nano::store::rocksdb::account; + friend class nano::store::rocksdb::block; + friend class nano::store::rocksdb::confirmation_height; + friend class nano::store::rocksdb::final_vote; + friend class nano::store::rocksdb::frontier; + friend class nano::store::rocksdb::online_weight; + friend class nano::store::rocksdb::peer; + friend class nano::store::rocksdb::pending; + friend class nano::store::rocksdb::pruned; + friend class nano::store::rocksdb::version; + + explicit component (nano::logger_mt &, boost::filesystem::path const &, nano::ledger_constants & constants, nano::rocksdb_config const & = nano::rocksdb_config{}, bool open_read_only = false); + + store::write_transaction tx_begin_write (std::vector const & tables_requiring_lock = {}, std::vector const & tables_no_lock = {}) override; + store::read_transaction tx_begin_read () const override; + + std::string vendor_get () const override; + + uint64_t count (store::transaction const & transaction_a, tables table_a) const override; + + bool exists (store::transaction const & transaction_a, tables table_a, nano::store::rocksdb::db_val const & key_a) const; + int get (store::transaction const & transaction_a, tables table_a, nano::store::rocksdb::db_val const & key_a, nano::store::rocksdb::db_val & value_a) const; + int put (store::write_transaction const & transaction_a, tables table_a, nano::store::rocksdb::db_val const & key_a, nano::store::rocksdb::db_val const & value_a); + int del (store::write_transaction const & transaction_a, tables table_a, nano::store::rocksdb::db_val const & key_a); + + void serialize_memory_stats (boost::property_tree::ptree &) override; + + bool copy_db (boost::filesystem::path const & destination) override; + void rebuild_db (store::write_transaction const & transaction_a) override; + + unsigned max_block_write_batch_num () const override; + + template + store::iterator make_iterator (store::transaction const & transaction_a, tables table_a, bool const direction_asc = true) const { - private: - nano::rocksdb::account_store account_store; - nano::rocksdb::block_store block_store; - nano::rocksdb::confirmation_height_store confirmation_height_store; - nano::rocksdb::final_vote_store final_vote_store; - nano::rocksdb::frontier_store frontier_store; - nano::rocksdb::online_weight_store online_weight_store; - nano::rocksdb::peer_store peer_store; - nano::rocksdb::pending_store pending_store; - nano::rocksdb::pruned_store pruned_store; - nano::rocksdb::version_store version_store; + return store::iterator (std::make_unique> (db.get (), transaction_a, table_to_column_family (table_a), nullptr, direction_asc)); + } + template + store::iterator make_iterator (store::transaction const & transaction_a, tables table_a, nano::store::rocksdb::db_val const & key) const + { + return store::iterator (std::make_unique> (db.get (), transaction_a, table_to_column_family (table_a), &key, true)); + } + + bool init_error () const override; + + std::string error_string (int status) const override; + +private: + bool error{ false }; + nano::logger_mt & logger; + nano::ledger_constants & constants; + // Optimistic transactions are used in write mode + ::rocksdb::OptimisticTransactionDB * optimistic_db = nullptr; + std::unique_ptr<::rocksdb::DB> db; + std::vector> handles; + std::shared_ptr<::rocksdb::TableFactory> small_table_factory; + std::unordered_map write_lock_mutexes; + nano::rocksdb_config rocksdb_config; + unsigned const max_block_write_batch_num_m; + + class tombstone_info + { public: - friend class nano::rocksdb::account_store; - friend class nano::rocksdb::block_store; - friend class nano::rocksdb::confirmation_height_store; - friend class nano::rocksdb::final_vote_store; - friend class nano::rocksdb::frontier_store; - friend class nano::rocksdb::online_weight_store; - friend class nano::rocksdb::peer_store; - friend class nano::rocksdb::pending_store; - friend class nano::rocksdb::pruned_store; - friend class nano::rocksdb::version_store; - - explicit store (nano::logger_mt &, boost::filesystem::path const &, nano::ledger_constants & constants, nano::rocksdb_config const & = nano::rocksdb_config{}, bool open_read_only = false); - - nano::write_transaction tx_begin_write (std::vector const & tables_requiring_lock = {}, std::vector const & tables_no_lock = {}) override; - nano::read_transaction tx_begin_read () const override; - - std::string vendor_get () const override; - - uint64_t count (nano::transaction const & transaction_a, tables table_a) const override; - - bool exists (nano::transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a) const; - int get (nano::transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a, nano::rocksdb_val & value_a) const; - int put (nano::write_transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a, nano::rocksdb_val const & value_a); - int del (nano::write_transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a); - - void serialize_memory_stats (boost::property_tree::ptree &) override; - - bool copy_db (boost::filesystem::path const & destination) override; - void rebuild_db (nano::write_transaction const & transaction_a) override; - - unsigned max_block_write_batch_num () const override; - - template - nano::store_iterator make_iterator (nano::transaction const & transaction_a, tables table_a, bool const direction_asc = true) const - { - return nano::store_iterator (std::make_unique> (db.get (), transaction_a, table_to_column_family (table_a), nullptr, direction_asc)); - } - - template - nano::store_iterator make_iterator (nano::transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key) const - { - return nano::store_iterator (std::make_unique> (db.get (), transaction_a, table_to_column_family (table_a), &key, true)); - } - - bool init_error () const override; - - std::string error_string (int status) const override; - - private: - bool error{ false }; - nano::logger_mt & logger; - nano::ledger_constants & constants; - // Optimistic transactions are used in write mode - ::rocksdb::OptimisticTransactionDB * optimistic_db = nullptr; - std::unique_ptr<::rocksdb::DB> db; - std::vector> handles; - std::shared_ptr<::rocksdb::TableFactory> small_table_factory; - std::unordered_map write_lock_mutexes; - nano::rocksdb_config rocksdb_config; - unsigned const max_block_write_batch_num_m; - - class tombstone_info - { - public: - tombstone_info (uint64_t, uint64_t const); - std::atomic num_since_last_flush; - uint64_t const max; - }; + tombstone_info (uint64_t, uint64_t const); + std::atomic num_since_last_flush; + uint64_t const max; + }; - std::unordered_map tombstone_map; - std::unordered_map cf_name_table_map; + std::unordered_map tombstone_map; + std::unordered_map cf_name_table_map; - ::rocksdb::Transaction * tx (nano::transaction const & transaction_a) const; - std::vector all_tables () const; + ::rocksdb::Transaction * tx (store::transaction const & transaction_a) const; + std::vector all_tables () const; - bool not_found (int status) const override; - bool success (int status) const override; - void release_assert_success (int const status) const + bool not_found (int status) const override; + bool success (int status) const override; + void release_assert_success (int const status) const + { + if (!success (status)) { - if (!success (status)) - { - release_assert (false, error_string (status)); - } + release_assert (false, error_string (status)); } - int status_code_not_found () const override; - int drop (nano::write_transaction const &, tables) override; - - std::vector<::rocksdb::ColumnFamilyDescriptor> get_single_column_family (std::string cf_name) const; - std::vector<::rocksdb::ColumnFamilyDescriptor> get_current_column_families (std::string const & path_a, ::rocksdb::Options const & options_a) const; - ::rocksdb::ColumnFamilyHandle * get_column_family (char const * name) const; - bool column_family_exists (char const * name) const; - ::rocksdb::ColumnFamilyHandle * table_to_column_family (tables table_a) const; - int clear (::rocksdb::ColumnFamilyHandle * column_family); - - void open (bool & error_a, boost::filesystem::path const & path_a, bool open_read_only_a, ::rocksdb::Options const & options_a, std::vector<::rocksdb::ColumnFamilyDescriptor> column_families); - - bool do_upgrades (nano::write_transaction const &); - void upgrade_v21_to_v22 (nano::write_transaction const &); - - void construct_column_family_mutexes (); - ::rocksdb::Options get_db_options (); - ::rocksdb::ColumnFamilyOptions get_common_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a, unsigned long long memtable_size_bytes_a) const; - ::rocksdb::ColumnFamilyOptions get_active_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a, unsigned long long memtable_size_bytes_a) const; - ::rocksdb::ColumnFamilyOptions get_small_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a) const; - ::rocksdb::BlockBasedTableOptions get_active_table_options (std::size_t lru_size) const; - ::rocksdb::BlockBasedTableOptions get_small_table_options () const; - ::rocksdb::ColumnFamilyOptions get_cf_options (std::string const & cf_name_a) const; - - void on_flush (::rocksdb::FlushJobInfo const &); - void flush_table (nano::tables table_a); - void flush_tombstones_check (nano::tables table_a); - void generate_tombstone_map (); - std::unordered_map create_cf_name_table_map () const; - - std::vector<::rocksdb::ColumnFamilyDescriptor> create_column_families (); - unsigned long long base_memtable_size_bytes () const; - unsigned long long blocks_memtable_size_bytes () const; - - constexpr static int base_memtable_size = 16; - constexpr static int base_block_cache_size = 8; - - friend class nano::rocksdb_block_store_tombstone_count_Test; - friend class nano::rocksdb::rocksdb_block_store_upgrade_v21_v22_Test; - }; -} // namespace rocksdb -} // namespace nano + } + int status_code_not_found () const override; + int drop (store::write_transaction const &, tables) override; + + std::vector<::rocksdb::ColumnFamilyDescriptor> get_single_column_family (std::string cf_name) const; + std::vector<::rocksdb::ColumnFamilyDescriptor> get_current_column_families (std::string const & path_a, ::rocksdb::Options const & options_a) const; + ::rocksdb::ColumnFamilyHandle * get_column_family (char const * name) const; + bool column_family_exists (char const * name) const; + ::rocksdb::ColumnFamilyHandle * table_to_column_family (tables table_a) const; + int clear (::rocksdb::ColumnFamilyHandle * column_family); + + void open (bool & error_a, boost::filesystem::path const & path_a, bool open_read_only_a, ::rocksdb::Options const & options_a, std::vector<::rocksdb::ColumnFamilyDescriptor> column_families); + + bool do_upgrades (store::write_transaction const &); + void upgrade_v21_to_v22 (store::write_transaction const &); + + void construct_column_family_mutexes (); + ::rocksdb::Options get_db_options (); + ::rocksdb::ColumnFamilyOptions get_common_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a, unsigned long long memtable_size_bytes_a) const; + ::rocksdb::ColumnFamilyOptions get_active_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a, unsigned long long memtable_size_bytes_a) const; + ::rocksdb::ColumnFamilyOptions get_small_cf_options (std::shared_ptr<::rocksdb::TableFactory> const & table_factory_a) const; + ::rocksdb::BlockBasedTableOptions get_active_table_options (std::size_t lru_size) const; + ::rocksdb::BlockBasedTableOptions get_small_table_options () const; + ::rocksdb::ColumnFamilyOptions get_cf_options (std::string const & cf_name_a) const; + + void on_flush (::rocksdb::FlushJobInfo const &); + void flush_table (nano::tables table_a); + void flush_tombstones_check (nano::tables table_a); + void generate_tombstone_map (); + std::unordered_map create_cf_name_table_map () const; + + std::vector<::rocksdb::ColumnFamilyDescriptor> create_column_families (); + unsigned long long base_memtable_size_bytes () const; + unsigned long long blocks_memtable_size_bytes () const; + + constexpr static int base_memtable_size = 16; + constexpr static int base_block_cache_size = 8; + + friend class nano::rocksdb_block_store_tombstone_count_Test; + friend class rocksdb_block_store_upgrade_v21_v22_Test; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/transaction.cpp b/nano/store/rocksdb/transaction.cpp index a4b3a361d7..0974eeca62 100644 --- a/nano/store/rocksdb/transaction.cpp +++ b/nano/store/rocksdb/transaction.cpp @@ -1,6 +1,6 @@ #include -nano::read_rocksdb_txn::read_rocksdb_txn (rocksdb::DB * db_a) : +nano::store::rocksdb::read_transaction_impl::read_transaction_impl (::rocksdb::DB * db_a) : db (db_a) { if (db_a) @@ -9,12 +9,12 @@ nano::read_rocksdb_txn::read_rocksdb_txn (rocksdb::DB * db_a) : } } -nano::read_rocksdb_txn::~read_rocksdb_txn () +nano::store::rocksdb::read_transaction_impl::~read_transaction_impl () { reset (); } -void nano::read_rocksdb_txn::reset () +void nano::store::rocksdb::read_transaction_impl::reset () { if (db) { @@ -22,36 +22,36 @@ void nano::read_rocksdb_txn::reset () } } -void nano::read_rocksdb_txn::renew () +void nano::store::rocksdb::read_transaction_impl::renew () { options.snapshot = db->GetSnapshot (); } -void * nano::read_rocksdb_txn::get_handle () const +void * nano::store::rocksdb::read_transaction_impl::get_handle () const { return (void *)&options; } -nano::write_rocksdb_txn::write_rocksdb_txn (rocksdb::OptimisticTransactionDB * db_a, std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a, std::unordered_map & mutexes_a) : +nano::store::rocksdb::write_transaction_impl::write_transaction_impl (::rocksdb::OptimisticTransactionDB * db_a, std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a, std::unordered_map & mutexes_a) : db (db_a), tables_requiring_locks (tables_requiring_locks_a), tables_no_locks (tables_no_locks_a), mutexes (mutexes_a) { lock (); - rocksdb::OptimisticTransactionOptions txn_options; + ::rocksdb::OptimisticTransactionOptions txn_options; txn_options.set_snapshot = true; - txn = db->BeginTransaction (rocksdb::WriteOptions (), txn_options); + txn = db->BeginTransaction (::rocksdb::WriteOptions (), txn_options); } -nano::write_rocksdb_txn::~write_rocksdb_txn () +nano::store::rocksdb::write_transaction_impl::~write_transaction_impl () { commit (); delete txn; unlock (); } -void nano::write_rocksdb_txn::commit () +void nano::store::rocksdb::write_transaction_impl::commit () { if (active) { @@ -74,20 +74,20 @@ void nano::write_rocksdb_txn::commit () } } -void nano::write_rocksdb_txn::renew () +void nano::store::rocksdb::write_transaction_impl::renew () { - rocksdb::OptimisticTransactionOptions txn_options; + ::rocksdb::OptimisticTransactionOptions txn_options; txn_options.set_snapshot = true; - db->BeginTransaction (rocksdb::WriteOptions (), txn_options, txn); + db->BeginTransaction (::rocksdb::WriteOptions (), txn_options, txn); active = true; } -void * nano::write_rocksdb_txn::get_handle () const +void * nano::store::rocksdb::write_transaction_impl::get_handle () const { return txn; } -void nano::write_rocksdb_txn::lock () +void nano::store::rocksdb::write_transaction_impl::lock () { for (auto table : tables_requiring_locks) { @@ -95,7 +95,7 @@ void nano::write_rocksdb_txn::lock () } } -void nano::write_rocksdb_txn::unlock () +void nano::store::rocksdb::write_transaction_impl::unlock () { for (auto table : tables_requiring_locks) { @@ -103,7 +103,7 @@ void nano::write_rocksdb_txn::unlock () } } -bool nano::write_rocksdb_txn::contains (nano::tables table_a) const +bool nano::store::rocksdb::write_transaction_impl::contains (nano::tables table_a) const { return (std::find (tables_requiring_locks.begin (), tables_requiring_locks.end (), table_a) != tables_requiring_locks.end ()) || (std::find (tables_no_locks.begin (), tables_no_locks.end (), table_a) != tables_no_locks.end ()); } diff --git a/nano/store/rocksdb/transaction_impl.hpp b/nano/store/rocksdb/transaction_impl.hpp index c7894581d2..ce3f531f94 100644 --- a/nano/store/rocksdb/transaction_impl.hpp +++ b/nano/store/rocksdb/transaction_impl.hpp @@ -7,13 +7,13 @@ #include #include -namespace nano +namespace nano::store::rocksdb { -class read_rocksdb_txn final : public read_transaction_impl +class read_transaction_impl final : public store::read_transaction_impl { public: - read_rocksdb_txn (::rocksdb::DB * db); - ~read_rocksdb_txn (); + read_transaction_impl (::rocksdb::DB * db); + ~read_transaction_impl (); void reset () override; void renew () override; void * get_handle () const override; @@ -23,11 +23,11 @@ class read_rocksdb_txn final : public read_transaction_impl ::rocksdb::ReadOptions options; }; -class write_rocksdb_txn final : public write_transaction_impl +class write_transaction_impl final : public store::write_transaction_impl { public: - write_rocksdb_txn (::rocksdb::OptimisticTransactionDB * db_a, std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a, std::unordered_map & mutexes_a); - ~write_rocksdb_txn (); + write_transaction_impl (::rocksdb::OptimisticTransactionDB * db_a, std::vector const & tables_requiring_locks_a, std::vector const & tables_no_locks_a, std::unordered_map & mutexes_a); + ~write_transaction_impl (); void commit () override; void renew () override; void * get_handle () const override; diff --git a/nano/store/rocksdb/version.cpp b/nano/store/rocksdb/version.cpp index 0f7d0039ac..c1df2e0232 100644 --- a/nano/store/rocksdb/version.cpp +++ b/nano/store/rocksdb/version.cpp @@ -1,10 +1,10 @@ #include #include -nano::rocksdb::version_store::version_store (nano::rocksdb::store & store_a) : +nano::store::rocksdb::version::version (nano::store::rocksdb::component & store_a) : store{ store_a } {}; -void nano::rocksdb::version_store::put (nano::write_transaction const & transaction_a, int version) +void nano::store::rocksdb::version::put (store::write_transaction const & transaction_a, int version) { nano::uint256_union version_key{ 1 }; nano::uint256_union version_value (version); @@ -12,10 +12,10 @@ void nano::rocksdb::version_store::put (nano::write_transaction const & transact store.release_assert_success (status); } -int nano::rocksdb::version_store::get (nano::transaction const & transaction_a) const +int nano::store::rocksdb::version::get (store::transaction const & transaction_a) const { nano::uint256_union version_key{ 1 }; - nano::rocksdb_val data; + nano::store::rocksdb::db_val data; auto status = store.get (transaction_a, tables::meta, version_key, data); int result = store.version_minimum; if (store.success (status)) diff --git a/nano/store/rocksdb/version.hpp b/nano/store/rocksdb/version.hpp index 4aaf0e0d5f..a5250b241c 100644 --- a/nano/store/rocksdb/version.hpp +++ b/nano/store/rocksdb/version.hpp @@ -2,20 +2,16 @@ #include -namespace nano +namespace nano::store::rocksdb { -namespace rocksdb +class version : public nano::store::version { - class store; - class version_store : public nano::version_store - { - protected: - nano::rocksdb::store & store; +protected: + nano::store::rocksdb::component & store; - public: - explicit version_store (nano::rocksdb::store & store_a); - void put (nano::write_transaction const & transaction_a, int version_a) override; - int get (nano::transaction const & transaction_a) const override; - }; -} -} +public: + explicit version (nano::store::rocksdb::component & store_a); + void put (store::write_transaction const & transaction_a, int version_a) override; + int get (store::transaction const & transaction_a) const override; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/transaction.cpp b/nano/store/transaction.cpp index ed822381d1..7d30d403a0 100644 --- a/nano/store/transaction.cpp +++ b/nano/store/transaction.cpp @@ -2,33 +2,33 @@ #include #include -nano::read_transaction::read_transaction (std::unique_ptr read_transaction_impl) : +nano::store::read_transaction::read_transaction (std::unique_ptr read_transaction_impl) : impl (std::move (read_transaction_impl)) { } -void * nano::read_transaction::get_handle () const +void * nano::store::read_transaction::get_handle () const { return impl->get_handle (); } -void nano::read_transaction::reset () const +void nano::store::read_transaction::reset () const { impl->reset (); } -void nano::read_transaction::renew () const +void nano::store::read_transaction::renew () const { impl->renew (); } -void nano::read_transaction::refresh () const +void nano::store::read_transaction::refresh () const { reset (); renew (); } -nano::write_transaction::write_transaction (std::unique_ptr write_transaction_impl) : +nano::store::write_transaction::write_transaction (std::unique_ptr write_transaction_impl) : impl (std::move (write_transaction_impl)) { /* @@ -37,28 +37,28 @@ nano::write_transaction::write_transaction (std::unique_ptrget_handle (); } -void nano::write_transaction::commit () +void nano::store::write_transaction::commit () { impl->commit (); } -void nano::write_transaction::renew () +void nano::store::write_transaction::renew () { impl->renew (); } -void nano::write_transaction::refresh () +void nano::store::write_transaction::refresh () { impl->commit (); impl->renew (); } -bool nano::write_transaction::contains (nano::tables table_a) const +bool nano::store::write_transaction::contains (nano::tables table_a) const { return impl->contains (table_a); } diff --git a/nano/store/transaction.hpp b/nano/store/transaction.hpp index e8c46415b3..5061886907 100644 --- a/nano/store/transaction.hpp +++ b/nano/store/transaction.hpp @@ -4,7 +4,7 @@ #include -namespace nano +namespace nano::store { class transaction_impl { @@ -42,14 +42,14 @@ class transaction class read_transaction final : public transaction { public: - explicit read_transaction (std::unique_ptr read_transaction_impl); + explicit read_transaction (std::unique_ptr read_transaction_impl); void * get_handle () const override; void reset () const; void renew () const; void refresh () const; private: - std::unique_ptr impl; + std::unique_ptr impl; }; /** @@ -59,7 +59,7 @@ class read_transaction final : public transaction class write_transaction final : public transaction { public: - explicit write_transaction (std::unique_ptr write_transaction_impl); + explicit write_transaction (std::unique_ptr write_transaction_impl); void * get_handle () const override; void commit (); void renew (); @@ -67,6 +67,6 @@ class write_transaction final : public transaction bool contains (nano::tables table_a) const; private: - std::unique_ptr impl; + std::unique_ptr impl; }; -} // namespace nano +} // namespace nano::store diff --git a/nano/store/version.hpp b/nano/store/version.hpp index 192cb032a8..46089dcc8f 100644 --- a/nano/store/version.hpp +++ b/nano/store/version.hpp @@ -12,16 +12,15 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { /** * Manages version storage */ -class version_store +class version { public: - virtual void put (nano::write_transaction const &, int) = 0; - virtual int get (nano::transaction const &) const = 0; + virtual void put (store::write_transaction const &, int) = 0; + virtual int get (store::transaction const &) const = 0; }; - } // namespace nano::store diff --git a/nano/store/versioning.cpp b/nano/store/versioning.cpp index 58a40271b6..ddf7c965bd 100644 --- a/nano/store/versioning.cpp +++ b/nano/store/versioning.cpp @@ -4,14 +4,14 @@ #include -nano::pending_info_v14::pending_info_v14 (nano::account const & source_a, nano::amount const & amount_a, nano::epoch epoch_a) : +nano::store::pending_info_v14::pending_info_v14 (nano::account const & source_a, nano::amount const & amount_a, nano::epoch epoch_a) : source (source_a), amount (amount_a), epoch (epoch_a) { } -bool nano::pending_info_v14::deserialize (nano::stream & stream_a) +bool nano::store::pending_info_v14::deserialize (nano::stream & stream_a) { auto error (false); try @@ -27,17 +27,17 @@ bool nano::pending_info_v14::deserialize (nano::stream & stream_a) return error; } -size_t nano::pending_info_v14::db_size () const +size_t nano::store::pending_info_v14::db_size () const { return sizeof (source) + sizeof (amount); } -bool nano::pending_info_v14::operator== (nano::pending_info_v14 const & other_a) const +bool nano::store::pending_info_v14::operator== (nano::store::pending_info_v14 const & other_a) const { return source == other_a.source && amount == other_a.amount && epoch == other_a.epoch; } -nano::account_info_v14::account_info_v14 (nano::block_hash const & head_a, nano::block_hash const & rep_block_a, nano::block_hash const & open_block_a, nano::amount const & balance_a, uint64_t modified_a, uint64_t block_count_a, uint64_t confirmation_height_a, nano::epoch epoch_a) : +nano::store::account_info_v14::account_info_v14 (nano::block_hash const & head_a, nano::block_hash const & rep_block_a, nano::block_hash const & open_block_a, nano::amount const & balance_a, uint64_t modified_a, uint64_t block_count_a, uint64_t confirmation_height_a, nano::epoch epoch_a) : head (head_a), rep_block (rep_block_a), open_block (open_block_a), @@ -49,7 +49,7 @@ nano::account_info_v14::account_info_v14 (nano::block_hash const & head_a, nano: { } -size_t nano::account_info_v14::db_size () const +size_t nano::store::account_info_v14::db_size () const { debug_assert (reinterpret_cast (this) == reinterpret_cast (&head)); debug_assert (reinterpret_cast (&head) + sizeof (head) == reinterpret_cast (&rep_block)); @@ -61,7 +61,7 @@ size_t nano::account_info_v14::db_size () const return sizeof (head) + sizeof (rep_block) + sizeof (open_block) + sizeof (balance) + sizeof (modified) + sizeof (block_count) + sizeof (confirmation_height); } -nano::block_sideband_v14::block_sideband_v14 (nano::block_type type_a, nano::account const & account_a, nano::block_hash const & successor_a, nano::amount const & balance_a, uint64_t height_a, uint64_t timestamp_a) : +nano::store::block_sideband_v14::block_sideband_v14 (nano::block_type type_a, nano::account const & account_a, nano::block_hash const & successor_a, nano::amount const & balance_a, uint64_t height_a, uint64_t timestamp_a) : type (type_a), successor (successor_a), account (account_a), @@ -71,7 +71,7 @@ nano::block_sideband_v14::block_sideband_v14 (nano::block_type type_a, nano::acc { } -size_t nano::block_sideband_v14::size (nano::block_type type_a) +size_t nano::store::block_sideband_v14::size (nano::block_type type_a) { size_t result (0); result += sizeof (successor); @@ -91,7 +91,7 @@ size_t nano::block_sideband_v14::size (nano::block_type type_a) return result; } -void nano::block_sideband_v14::serialize (nano::stream & stream_a) const +void nano::store::block_sideband_v14::serialize (nano::stream & stream_a) const { nano::write (stream_a, successor.bytes); if (type != nano::block_type::state && type != nano::block_type::open) @@ -109,7 +109,7 @@ void nano::block_sideband_v14::serialize (nano::stream & stream_a) const nano::write (stream_a, boost::endian::native_to_big (timestamp)); } -bool nano::block_sideband_v14::deserialize (nano::stream & stream_a) +bool nano::store::block_sideband_v14::deserialize (nano::stream & stream_a) { bool result (false); try @@ -143,7 +143,7 @@ bool nano::block_sideband_v14::deserialize (nano::stream & stream_a) return result; } -nano::block_sideband_v18::block_sideband_v18 (nano::account const & account_a, nano::block_hash const & successor_a, nano::amount const & balance_a, uint64_t height_a, uint64_t timestamp_a, nano::block_details const & details_a) : +nano::store::block_sideband_v18::block_sideband_v18 (nano::account const & account_a, nano::block_hash const & successor_a, nano::amount const & balance_a, uint64_t height_a, uint64_t timestamp_a, nano::block_details const & details_a) : successor (successor_a), account (account_a), balance (balance_a), @@ -153,7 +153,7 @@ nano::block_sideband_v18::block_sideband_v18 (nano::account const & account_a, n { } -nano::block_sideband_v18::block_sideband_v18 (nano::account const & account_a, nano::block_hash const & successor_a, nano::amount const & balance_a, uint64_t height_a, uint64_t timestamp_a, nano::epoch epoch_a, bool is_send, bool is_receive, bool is_epoch) : +nano::store::block_sideband_v18::block_sideband_v18 (nano::account const & account_a, nano::block_hash const & successor_a, nano::amount const & balance_a, uint64_t height_a, uint64_t timestamp_a, nano::epoch epoch_a, bool is_send, bool is_receive, bool is_epoch) : successor (successor_a), account (account_a), balance (balance_a), @@ -163,7 +163,7 @@ nano::block_sideband_v18::block_sideband_v18 (nano::account const & account_a, n { } -size_t nano::block_sideband_v18::size (nano::block_type type_a) +size_t nano::store::block_sideband_v18::size (nano::block_type type_a) { size_t result (0); result += sizeof (successor); @@ -188,7 +188,7 @@ size_t nano::block_sideband_v18::size (nano::block_type type_a) return result; } -void nano::block_sideband_v18::serialize (nano::stream & stream_a, nano::block_type type_a) const +void nano::store::block_sideband_v18::serialize (nano::stream & stream_a, nano::block_type type_a) const { nano::write (stream_a, successor.bytes); if (type_a != nano::block_type::state && type_a != nano::block_type::open) @@ -210,7 +210,7 @@ void nano::block_sideband_v18::serialize (nano::stream & stream_a, nano::block_t } } -bool nano::block_sideband_v18::deserialize (nano::stream & stream_a, nano::block_type type_a) +bool nano::store::block_sideband_v18::deserialize (nano::stream & stream_a, nano::block_type type_a) { bool result (false); try diff --git a/nano/store/versioning.hpp b/nano/store/versioning.hpp index 45a3ad885e..635a5deb55 100644 --- a/nano/store/versioning.hpp +++ b/nano/store/versioning.hpp @@ -5,7 +5,7 @@ struct MDB_val; -namespace nano +namespace nano::store { class pending_info_v14 final { @@ -14,7 +14,7 @@ class pending_info_v14 final pending_info_v14 (nano::account const &, nano::amount const &, nano::epoch); size_t db_size () const; bool deserialize (nano::stream &); - bool operator== (nano::pending_info_v14 const &) const; + bool operator== (pending_info_v14 const &) const; nano::account source{}; nano::amount amount{ 0 }; nano::epoch epoch{ nano::epoch::epoch_0 }; @@ -53,7 +53,7 @@ class state_block_w_sideband_v14 { public: std::shared_ptr state_block; - nano::block_sideband_v14 sideband; + block_sideband_v14 sideband; }; class block_sideband_v18 final { @@ -77,6 +77,6 @@ class block_w_sideband_v18 { public: std::shared_ptr block; - nano::block_sideband_v18 sideband; + block_sideband_v18 sideband; }; -} +} // namespace nano::store diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 4ab1044402..044813fd69 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -203,7 +203,7 @@ std::shared_ptr nano::test::system::wallet (size_t index_a) return nodes[index_a]->wallets.items.begin ()->second; } -nano::account nano::test::system::account (nano::transaction const & transaction_a, size_t index_a) +nano::account nano::test::system::account (store::transaction const & transaction_a, size_t index_a) { auto wallet_l (wallet (index_a)); auto keys (wallet_l->store.begin (transaction_a)); @@ -451,7 +451,7 @@ nano::account nano::test::system::get_random_account (std::vector return result; } -nano::uint128_t nano::test::system::get_random_amount (nano::transaction const & transaction_a, nano::node & node_a, nano::account const & account_a) +nano::uint128_t nano::test::system::get_random_amount (store::transaction const & transaction_a, nano::node & node_a, nano::account const & account_a) { nano::uint128_t balance (node_a.ledger.account_balance (transaction_a, account_a)); nano::uint128_union random_amount; @@ -468,7 +468,7 @@ void nano::test::system::generate_send_existing (nano::node & node_a, std::vecto nano::account account; random_pool::generate_block (account.bytes.data (), sizeof (account.bytes)); auto transaction (node_a.store.tx_begin_read ()); - nano::store_iterator entry (node_a.store.account.begin (transaction, account)); + store::iterator entry (node_a.store.account.begin (transaction, account)); if (entry == node_a.store.account.end ()) { entry = node_a.store.account.begin (transaction); diff --git a/nano/test_common/system.hpp b/nano/test_common/system.hpp index b85f07fc8c..e03532ccef 100644 --- a/nano/test_common/system.hpp +++ b/nano/test_common/system.hpp @@ -30,7 +30,7 @@ namespace test void generate_usage_traffic (uint32_t, uint32_t, size_t); void generate_usage_traffic (uint32_t, uint32_t); nano::account get_random_account (std::vector &); - nano::uint128_t get_random_amount (nano::transaction const &, nano::node &, nano::account const &); + nano::uint128_t get_random_amount (store::transaction const &, nano::node &, nano::account const &); void generate_rollback (nano::node &, std::vector &); void generate_change_known (nano::node &, std::vector &); void generate_change_unknown (nano::node &, std::vector &); @@ -39,7 +39,7 @@ namespace test void generate_send_existing (nano::node &, std::vector &); std::unique_ptr upgrade_genesis_epoch (nano::node &, nano::epoch const); std::shared_ptr wallet (size_t); - nano::account account (nano::transaction const &, size_t); + nano::account account (store::transaction const &, size_t); /** Generate work with difficulty between \p min_difficulty_a (inclusive) and \p max_difficulty_a (exclusive) */ uint64_t work_generate_limited (nano::block_hash const & root_a, uint64_t min_difficulty_a, uint64_t max_difficulty_a); /**