diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index e298cc755e..15782b4f6a 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, 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::store::lmdb::component & store, nano::transaction const & transaction, nano::account const & account, uint64_t confirmation_height); +void write_sideband_v14 (nano::store::lmdb::component & store_a, nano::transaction & transaction_a, nano::block const & block_a, MDB_dbi db_a); +void write_sideband_v15 (nano::store::lmdb::component & store_a, nano::transaction & transaction_a, nano::block const & block_a); +void write_block_w_sideband_v18 (nano::store::lmdb::component & store_a, MDB_dbi database, nano::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::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 ()); - // 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, + // 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)); - 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); + } - // 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::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::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::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); + + // 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::mdb_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::mdb_val (nano::dev::genesis->account ()), nano::mdb_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::mdb_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::mdb_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::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 + 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::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); + 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::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)); + + // 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 (); - } + // 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")); - }; + 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")); + }; - // Testing current version doesn't contain the unchecked table - check_correct_state (); + // Testing current version doesn't contain the unchecked table + check_correct_state (); - // Setting the database to its 21st version state - { - nano::rocksdb::store store (logger, path, nano::dev::constants); + // Setting the database to its 21st version state + { + nano::store::rocksdb::component store (logger, path, nano::dev::constants); - // 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); + // 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); - // The new column family was created successfully, and 'new_cf_handle' now points to it. - ASSERT_TRUE (status.ok ()); + // The new column family was created successfully, and 'new_cf_handle' now points to it. + ASSERT_TRUE (status.ok ()); - // 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 (); + // 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 @@ -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, nano::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::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::mdb_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, nano::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::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::mdb_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, nano::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::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::mdb_val (block_a.hash ()), &val, 0)); + store_a.del (transaction_a, nano::tables::blocks, nano::mdb_val (block_a.hash ())); +} + +void modify_account_info_to_v14 (nano::store::lmdb::component & store, nano::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::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); +} + +void modify_confirmation_height_to_v15 (nano::store::lmdb::component & 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); } } 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..287a7dca52 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -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/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/wallet.cpp b/nano/node/wallet.cpp index 370900ec15..201443fb42 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -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) { @@ -1698,7 +1698,7 @@ void nano::wallets::ongoing_compute_reps () void nano::wallets::split_if_needed (nano::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 ()) diff --git a/nano/store/account.cpp b/nano/store/account.cpp index d08002c148..c78c5a72fa 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 (nano::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..8ecc2d6e29 100644 --- a/nano/store/account.hpp +++ b/nano/store/account.hpp @@ -13,12 +13,12 @@ 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; diff --git a/nano/store/block.hpp b/nano/store/block.hpp index 6c851a9f57..456b26d22f 100644 --- a/nano/store/block.hpp +++ b/nano/store/block.hpp @@ -13,12 +13,12 @@ class read_transaction; class transaction; class write_transaction; } -namespace nano +namespace nano::store { /** * 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; diff --git a/nano/store/component.cpp b/nano/store/component.cpp index 4cf5e76513..97d3365927 100644 --- a/nano/store/component.cpp +++ b/nano/store/component.cpp @@ -112,16 +112,16 @@ bool nano::write_transaction::contains (nano::tables table_a) const // 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::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), diff --git a/nano/store/component.hpp b/nano/store/component.hpp index 06ef90cb2b..2364b01392 100644 --- a/nano/store/component.hpp +++ b/nano/store/component.hpp @@ -501,17 +501,20 @@ class write_transaction final : public transaction std::unique_ptr impl; }; -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 { @@ -526,16 +529,16 @@ 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; @@ -547,20 +550,20 @@ namespace store 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; diff --git a/nano/store/confirmation_height.cpp b/nano/store/confirmation_height.cpp index 1398f73108..01da7a0417 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 (nano::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..63fabda29c 100644 --- a/nano/store/confirmation_height.hpp +++ b/nano/store/confirmation_height.hpp @@ -13,12 +13,12 @@ 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; diff --git a/nano/store/final.hpp b/nano/store/final.hpp index b51cbe4cf9..de3b3ecf6f 100644 --- a/nano/store/final.hpp +++ b/nano/store/final.hpp @@ -13,12 +13,12 @@ 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; diff --git a/nano/store/frontier.hpp b/nano/store/frontier.hpp index 56eb8d2563..41ce84dc84 100644 --- a/nano/store/frontier.hpp +++ b/nano/store/frontier.hpp @@ -13,12 +13,12 @@ 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; diff --git a/nano/store/lmdb/account.cpp b/nano/store/lmdb/account.cpp index e890cae690..45a6486608 100644 --- a/nano/store/lmdb/account.cpp +++ b/nano/store/lmdb/account.cpp @@ -2,16 +2,16 @@ #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 (nano::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 (nano::transaction const & transaction, nano::account const & account, nano::account_info & info) { nano::mdb_val value; auto status1 (store.get (transaction, tables::accounts, account, value)); @@ -25,44 +25,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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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); } -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, 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/lmdb/account.hpp b/nano/store/lmdb/account.hpp index d15c2ce887..484d32d085 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 (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; + + /** * 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..f12afe606f 100644 --- a/nano/store/lmdb/block.cpp +++ b/nano/store/lmdb/block.cpp @@ -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 (nano::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; @@ -19,14 +19,14 @@ class block_predecessor_mdb_set : public nano::block_visitor 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; + 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 (nano::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,14 +41,14 @@ 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 (nano::write_transaction const & transaction_a, std::vector const & data, nano::block_hash const & hash_a) { nano::mdb_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 (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const { nano::mdb_val value; block_raw_get (transaction_a, hash_a, value); @@ -69,7 +69,7 @@ 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 (nano::write_transaction const & transaction, nano::block_hash const & hash) { nano::mdb_val value; block_raw_get (transaction, hash, value); @@ -80,7 +80,7 @@ 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 (nano::transaction const & transaction, nano::block_hash const & hash) const { nano::mdb_val value; block_raw_get (transaction, hash, value); @@ -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 (nano::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 (nano::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 (nano::transaction const & transaction, nano::block_hash const & hash) { nano::mdb_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 (nano::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 (nano::transaction const & transaction) const { 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 (nano::transaction const & transaction, nano::block_hash const & hash) const { 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); } -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, 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) { @@ -156,24 +155,24 @@ 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::block_predecessor_mdb_set::block_predecessor_mdb_set (nano::write_transaction const & transaction_a, nano::store::lmdb::block & block_store_a) : transaction{ transaction_a }, block_store{ block_store_a } { diff --git a/nano/store/lmdb/block.hpp b/nano/store/lmdb/block.hpp index cab61eadca..3d5c89d93e 100644 --- a/nano/store/lmdb/block.hpp +++ b/nano/store/lmdb/block.hpp @@ -8,88 +8,99 @@ namespace nano { using mdb_val = db_val; 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 nano::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 (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 get_no_sideband (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::account account (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + nano::account account_calculated (nano::block const & block_a) const 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; + nano::uint128_t balance (nano::transaction const & transaction_a, nano::block_hash const & hash_a) override; + nano::uint128_t balance_calculated (std::shared_ptr const & block_a) const override; + nano::epoch version (nano::transaction const & transaction_a, nano::block_hash const & hash_a) override; + void for_each_par (std::function, nano::store_iterator)> const & action_a) const override; + // Converts a block hash to a block height + uint64_t account_height (nano::transaction const & transaction_a, nano::block_hash const & hash_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 (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); +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/confirmation_height.cpp b/nano/store/lmdb/confirmation_height.cpp index 97617bf463..bcdca2f07a 100644 --- a/nano/store/lmdb/confirmation_height.cpp +++ b/nano/store/lmdb/confirmation_height.cpp @@ -2,18 +2,18 @@ #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 (nano::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 (nano::transaction const & transaction, nano::account const & account, nano::confirmation_height_info & confirmation_height_info) { nano::mdb_val value; auto status = store.get (transaction, tables::confirmation_height, account, value); @@ -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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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); } -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, 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/lmdb/confirmation_height.hpp b/nano/store/lmdb/confirmation_height.hpp index ff29a4eae8..718ded122f 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 (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; - /* + /* * 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/final_vote.cpp b/nano/store/lmdb/final_vote.cpp index 9e6f14e94f..7dfb2a1229 100644 --- a/nano/store/lmdb/final_vote.cpp +++ b/nano/store/lmdb/final_vote.cpp @@ -2,10 +2,10 @@ #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 (nano::write_transaction const & transaction, nano::qualified_root const & root, nano::block_hash const & hash) { nano::mdb_val value; auto status = store.get (transaction, tables::final_votes, root, value); @@ -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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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); } -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, nano::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..c88d9ba11c 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 (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; - /** + /** * 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..07c7d7aa5e 100644 --- a/nano/store/lmdb/frontier.cpp +++ b/nano/store/lmdb/frontier.cpp @@ -2,18 +2,18 @@ #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 (nano::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 (nano::transaction const & transaction, nano::block_hash const & hash) const { nano::db_val value; auto status = store.get (transaction, tables::frontiers, hash, value); @@ -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 (nano::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 (nano::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 (nano::transaction const & transaction, nano::block_hash const & hash) const { return store.make_iterator (transaction, tables::frontiers, nano::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); } -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, 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/lmdb/frontier.hpp b/nano/store/lmdb/frontier.hpp index b8af5b2f23..feb36842e5 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 (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; - /** + /** * 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/lmdb.cpp b/nano/store/lmdb/lmdb.cpp index a91ba1af79..1933afdb88 100644 --- a/nano/store/lmdb/lmdb.cpp +++ b/nano/store/lmdb/lmdb.cpp @@ -40,7 +40,7 @@ void mdb_val::convert_buffer_to_value () } } -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, @@ -125,7 +125,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"; @@ -160,12 +160,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)); @@ -178,22 +178,22 @@ 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::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::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::mdb_txn_callbacks nano::store::lmdb::component::create_txn_callbacks () const { nano::mdb_txn_callbacks mdb_txn_callbacks; if (txn_tracking_enabled) @@ -208,7 +208,7 @@ nano::mdb_txn_callbacks nano::lmdb::store::create_txn_callbacks () const 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, nano::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; @@ -258,7 +258,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 (nano::write_transaction & transaction_a, nano::ledger_constants & constants, bool & needs_vacuuming) { auto error (false); auto version_l = version.get (transaction_a); @@ -317,7 +317,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 (nano::write_transaction & transaction_a) { logger.always_log ("Preparing v14 to v15 database upgrade..."); @@ -435,7 +435,7 @@ void nano::lmdb::store::upgrade_v14_to_v15 (nano::write_transaction & transactio 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 (nano::write_transaction const & transaction_a) { // Representation table is no longer used debug_assert (account_store.representation_handle != 0); @@ -448,7 +448,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 (nano::write_transaction const & transaction_a) { logger.always_log ("Preparing v16 to v17 database upgrade..."); @@ -527,7 +527,7 @@ void nano::lmdb::store::upgrade_v16_to_v17 (nano::write_transaction const & tran 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 (nano::write_transaction const & transaction_a, nano::ledger_constants & constants) { logger.always_log ("Preparing v17 to v18 database upgrade..."); @@ -590,7 +590,7 @@ 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 (nano::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)); @@ -766,7 +766,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 (nano::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); @@ -774,7 +774,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 (nano::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); @@ -782,7 +782,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 (nano::write_transaction const & transaction_a) { logger.always_log ("Preparing v21 to v22 database upgrade..."); MDB_dbi unchecked_handle{ 0 }; @@ -793,7 +793,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::mdb_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 (""); @@ -823,7 +823,7 @@ 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 (nano::transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a) const { nano::mdb_val junk; auto status = get (transaction_a, table_a, key_a, junk); @@ -831,37 +831,37 @@ bool nano::lmdb::store::exists (nano::transaction const & transaction_a, tables 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 (nano::transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a, nano::mdb_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 (nano::write_transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a, nano::mdb_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 (nano::write_transaction const & transaction_a, tables table_a, nano::mdb_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 (nano::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 (nano::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 (nano::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 (nano::transaction const & transaction_a, MDB_dbi db_a) const { MDB_stat stats; auto status (mdb_stat (env.tx (transaction_a), db_a, &stats)); @@ -869,7 +869,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) { @@ -899,32 +899,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 (nano::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 }; @@ -974,12 +974,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 (nano::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)); @@ -997,7 +997,7 @@ 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::mdb_val nano::store::lmdb::component::block_raw_get_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const { nano::mdb_val result; // Table lookups are ordered by match probability @@ -1016,7 +1016,7 @@ 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 (nano::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); @@ -1065,12 +1065,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 (nano::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); } -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 (nano::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)); @@ -1090,7 +1090,7 @@ 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::mdb_val nano::store::lmdb::component::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::mdb_val result; // Table lookups are ordered by match probability @@ -1109,7 +1109,7 @@ 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 (nano::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); @@ -1165,7 +1165,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 (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::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)); @@ -1186,18 +1186,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 6ada0789e0..b158a45dea 100644 --- a/nano/store/lmdb/lmdb.hpp +++ b/nano/store/lmdb/lmdb.hpp @@ -39,167 +39,168 @@ using mdb_val = db_val; class logging_mt; class transaction; -namespace lmdb +template <> +void * mdb_val::data () const; +template <> +std::size_t mdb_val::size () const; +template <> +mdb_val::db_val (std::size_t size_a, void * data_a); +template <> +void mdb_val::convert_buffer_to_value (); +} + +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); + 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; + + 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 { - 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; + return nano::store_iterator (std::make_unique> (transaction_a, table_to_dbi (table_a), nano::mdb_val{}, direction_asc)); + } - 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; - - 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 + nano::store_iterator make_iterator (nano::transaction const & transaction_a, tables table_a, nano::mdb_val const & key) const + { + return nano::store_iterator (std::make_unique> (transaction_a, table_to_dbi (table_a), key)); + } + + 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; + nano::uint128_t block_balance_v18 (nano::transaction const & transaction_a, nano::block_hash const & hash_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)) { - 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::mdb_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 (nano::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 }; }; -} -template <> -void * mdb_val::data () const; -template <> -std::size_t mdb_val::size () const; -template <> -mdb_val::db_val (std::size_t size_a, void * data_a); -template <> -void mdb_val::convert_buffer_to_value (); -} + 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 &, nano::transaction &, nano::block const &, MDB_dbi); + friend void write_sideband_v15 (nano::store::lmdb::component &, nano::transaction &, nano::block const &); + friend void modify_account_info_to_v14 (nano::store::lmdb::component &, nano::transaction const &, nano::account const &, uint64_t, nano::block_hash const &); + friend void modify_confirmation_height_to_v15 (nano::store::lmdb::component &, nano::transaction const &, nano::account const &, uint64_t); +}; +} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/online_weight.cpp b/nano/store/lmdb/online_weight.cpp index 0807f5e39b..53f89c56b8 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 (nano::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 (nano::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 (nano::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 (nano::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); } -size_t nano::lmdb::online_weight_store::count (nano::transaction const & transaction) const +size_t nano::store::lmdb::online_weight::count (nano::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 (nano::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..c1e819c6b8 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 (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; - /** + /** * 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..320e5906eb 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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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); } diff --git a/nano/store/lmdb/peer.hpp b/nano/store/lmdb/peer.hpp index 83fd1ee785..526c1c5d31 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 (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; - /* + /* * 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..874a5915a9 100644 --- a/nano/store/lmdb/pending.cpp +++ b/nano/store/lmdb/pending.cpp @@ -2,22 +2,22 @@ #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 (nano::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 (nano::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 (nano::transaction const & transaction, nano::pending_key const & key, nano::pending_info & pending_a) { nano::mdb_val value; auto status1 = store.get (transaction, tables::pending, key, value); @@ -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 (nano::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 (nano::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 (nano::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 (nano::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); } -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, nano::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..53f9abdc34 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 (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; - /** + /** * 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..aa6690fc23 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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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); } -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, 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/lmdb/pruned.hpp b/nano/store/lmdb/pruned.hpp index 0ad8f07e5b..21fc7080fb 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 (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; - /** + /** * 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/version.cpp b/nano/store/lmdb/version.cpp index be80c52885..7a634b7f03 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 (nano::write_transaction const & transaction_a, int version) { nano::uint256_union version_key{ 1 }; nano::uint256_union version_value (version); @@ -12,7 +12,7 @@ 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 (nano::transaction const & transaction_a) const { nano::uint256_union version_key{ 1 }; nano::mdb_val data; diff --git a/nano/store/lmdb/version.hpp b/nano/store/lmdb/version.hpp index ff9b723564..977eb16513 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 (nano::write_transaction const & transaction_a, int version_a) override; + int get (nano::transaction const & transaction_a) const override; +}; +} // namespace nano::store::lmdb diff --git a/nano/store/online_weight.hpp b/nano/store/online_weight.hpp index ee65a9b02e..89e01fd410 100644 --- a/nano/store/online_weight.hpp +++ b/nano/store/online_weight.hpp @@ -13,12 +13,12 @@ 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; diff --git a/nano/store/peer.hpp b/nano/store/peer.hpp index 64d36796af..21a866a087 100644 --- a/nano/store/peer.hpp +++ b/nano/store/peer.hpp @@ -13,12 +13,12 @@ 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; diff --git a/nano/store/pending.hpp b/nano/store/pending.hpp index 8944d2cb76..5ae1b00944 100644 --- a/nano/store/pending.hpp +++ b/nano/store/pending.hpp @@ -13,12 +13,12 @@ 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; diff --git a/nano/store/pruned.hpp b/nano/store/pruned.hpp index f9b48a22c9..c7d84c5d86 100644 --- a/nano/store/pruned.hpp +++ b/nano/store/pruned.hpp @@ -13,12 +13,12 @@ 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; diff --git a/nano/store/rocksdb/account.cpp b/nano/store/rocksdb/account.cpp index 2cf5e6d094..e4a3299883 100644 --- a/nano/store/rocksdb/account.cpp +++ b/nano/store/rocksdb/account.cpp @@ -2,16 +2,16 @@ #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 (nano::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 (nano::transaction const & transaction, nano::account const & account, nano::account_info & info) { nano::rocksdb_val value; auto status1 (store.get (transaction, tables::accounts, account, value)); @@ -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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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); } -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, 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/account.hpp b/nano/store/rocksdb/account.hpp index dfac80e1d0..78d91ab5bc 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 (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; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/block.cpp b/nano/store/rocksdb/block.cpp index 69e0118513..0125c6ca6c 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 (nano::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; @@ -19,14 +19,14 @@ class block_predecessor_rocksdb_set : public nano::block_visitor 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; + 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 (nano::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,14 +41,14 @@ 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 (nano::write_transaction const & transaction_a, std::vector const & data, nano::block_hash const & hash_a) { nano::rocksdb_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 (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const { nano::rocksdb_val value; block_raw_get (transaction_a, hash_a, value); @@ -69,7 +69,7 @@ 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 (nano::write_transaction const & transaction, nano::block_hash const & hash) { nano::rocksdb_val value; block_raw_get (transaction, hash, value); @@ -80,7 +80,7 @@ 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 (nano::transaction const & transaction, nano::block_hash const & hash) const { nano::rocksdb_val value; block_raw_get (transaction, hash, value); @@ -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 (nano::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 (nano::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 (nano::transaction const & transaction, nano::block_hash const & hash) { nano::rocksdb_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 (nano::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 (nano::transaction const & transaction) const { 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 (nano::transaction const & transaction, nano::block_hash const & hash) const { 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); } -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, 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) { @@ -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 (nano::write_transaction const & transaction_a, nano::store::rocksdb::block & block_store_a) : transaction{ transaction_a }, block_store{ block_store_a } { diff --git a/nano/store/rocksdb/block.hpp b/nano/store/rocksdb/block.hpp index 05c38f7d51..81b9f13cb1 100644 --- a/nano/store/rocksdb/block.hpp +++ b/nano/store/rocksdb/block.hpp @@ -8,34 +8,45 @@ namespace nano { using rocksdb_val = db_val<::rocksdb::Slice>; 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 (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 get_no_sideband (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::account account (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + nano::account account_calculated (nano::block const & block_a) const 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; + nano::uint128_t balance (nano::transaction const & transaction_a, nano::block_hash const & hash_a) override; + nano::uint128_t balance_calculated (std::shared_ptr const & block_a) const override; + nano::epoch version (nano::transaction const & transaction_a, nano::block_hash const & hash_a) override; + void for_each_par (std::function, nano::store_iterator)> const & action_a) const override; + // Converts a block hash to a block height + uint64_t account_height (nano::transaction const & transaction_a, nano::block_hash const & hash_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 (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); +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/confirmation_height.cpp b/nano/store/rocksdb/confirmation_height.cpp index 0ac8d61118..a9b527329e 100644 --- a/nano/store/rocksdb/confirmation_height.cpp +++ b/nano/store/rocksdb/confirmation_height.cpp @@ -2,18 +2,18 @@ #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 (nano::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 (nano::transaction const & transaction, nano::account const & account, nano::confirmation_height_info & confirmation_height_info) { nano::rocksdb_val value; auto status = store.get (transaction, tables::confirmation_height, account, value); @@ -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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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); } -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, 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/confirmation_height.hpp b/nano/store/rocksdb/confirmation_height.hpp index abb4668ba4..55891e8efb 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 (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; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/final_vote.cpp b/nano/store/rocksdb/final_vote.cpp index eb03e75fec..4f2853aae6 100644 --- a/nano/store/rocksdb/final_vote.cpp +++ b/nano/store/rocksdb/final_vote.cpp @@ -2,10 +2,10 @@ #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 (nano::write_transaction const & transaction, nano::qualified_root const & root, nano::block_hash const & hash) { nano::rocksdb_val value; auto status = store.get (transaction, tables::final_votes, root, value); @@ -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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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); } -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, nano::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..183ecc9fa3 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 (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; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/frontier.cpp b/nano/store/rocksdb/frontier.cpp index 51c02815e7..2ae6643553 100644 --- a/nano/store/rocksdb/frontier.cpp +++ b/nano/store/rocksdb/frontier.cpp @@ -2,18 +2,18 @@ #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 (nano::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 (nano::transaction const & transaction, nano::block_hash const & hash) const { nano::db_val<::rocksdb::Slice> value; auto status = store.get (transaction, tables::frontiers, hash, value); @@ -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 (nano::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 (nano::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 (nano::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); } -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..4299cff5be 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 (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; - private: - nano::rocksdb::store & store; - }; -} -} +private: + nano::store::rocksdb::component & store; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/online_weight.cpp b/nano/store/rocksdb/online_weight.cpp index f8f88ea1ca..25f0441613 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 (nano::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 (nano::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 (nano::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 (nano::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); } -size_t nano::rocksdb::online_weight_store::count (nano::transaction const & transaction) const +size_t nano::store::rocksdb::online_weight::count (nano::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 (nano::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..c84ad784f8 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 (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; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/peer.cpp b/nano/store/rocksdb/peer.cpp index 22d620ecc3..4b8bcc3991 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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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); } diff --git a/nano/store/rocksdb/peer.hpp b/nano/store/rocksdb/peer.hpp index 16dbabf543..da1eb9cf91 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 (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; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/pending.cpp b/nano/store/rocksdb/pending.cpp index 935f368b1f..f934167069 100644 --- a/nano/store/rocksdb/pending.cpp +++ b/nano/store/rocksdb/pending.cpp @@ -2,22 +2,22 @@ #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 (nano::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 (nano::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 (nano::transaction const & transaction, nano::pending_key const & key, nano::pending_info & pending) { nano::rocksdb_val value; auto status1 = store.get (transaction, tables::pending, key, value); @@ -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 (nano::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 (nano::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 (nano::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 (nano::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); } -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, nano::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..9a8711f518 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 (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; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/pruned.cpp b/nano/store/rocksdb/pruned.cpp index 6024682d19..49055332a6 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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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 (nano::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); } -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, 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/pruned.hpp b/nano/store/rocksdb/pruned.hpp index 29c03d7766..687b20e4c1 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 (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; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index d7c74dd145..f9388d2e90 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -62,7 +62,7 @@ void rocksdb_val::convert_buffer_to_value () } } -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, @@ -183,7 +183,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 }, @@ -202,7 +202,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; @@ -233,7 +233,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 (nano::write_transaction const & transaction_a) { bool error_l{ false }; auto version_l = version.get (transaction_a); @@ -275,7 +275,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 (nano::write_transaction const & transaction_a) { logger.always_log ("Preparing v21 to v22 database upgrade..."); if (column_family_exists ("unchecked")) @@ -297,14 +297,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; @@ -336,7 +336,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 (); @@ -416,7 +416,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) @@ -427,7 +427,7 @@ 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::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; release_assert (optimistic_db != nullptr); @@ -447,17 +447,17 @@ nano::write_transaction nano::rocksdb::store::tx_begin_write (std::vector (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{} }, @@ -466,7 +466,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; @@ -484,7 +484,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) { @@ -494,7 +494,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) { @@ -503,7 +503,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) { @@ -535,7 +535,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 (nano::transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a) const { ::rocksdb::PinnableSlice slice; ::rocksdb::Status status; @@ -553,7 +553,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 (nano::write_transaction const & transaction_a, tables table_a, nano::rocksdb_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 @@ -562,7 +562,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. @@ -577,18 +577,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 (nano::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 (nano::transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a, nano::rocksdb_val & value_a) const { ::rocksdb::ReadOptions options; ::rocksdb::PinnableSlice slice; @@ -612,29 +612,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 (nano::write_transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a, nano::rocksdb_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 (nano::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. @@ -695,7 +695,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 (nano::write_transaction const & transaction_a, tables table_a) { debug_assert (transaction_a.contains (table_a)); auto col = table_to_column_family (table_a); @@ -722,7 +722,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 (); @@ -740,7 +740,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 ()) { @@ -748,7 +748,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; @@ -790,7 +790,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; @@ -819,7 +819,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). @@ -829,7 +829,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); @@ -843,7 +843,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); @@ -859,7 +859,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 ()) @@ -868,12 +868,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; { @@ -937,23 +937,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 (nano::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; @@ -1000,28 +1000,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 d13bb30f0c..944851d934 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); + + 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 { - 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 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: - 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 (nano::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 (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 rocksdb_block_store_upgrade_v21_v22_Test; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/version.cpp b/nano/store/rocksdb/version.cpp index 0f7d0039ac..05f221f37b 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 (nano::write_transaction const & transaction_a, int version) { nano::uint256_union version_key{ 1 }; nano::uint256_union version_value (version); @@ -12,7 +12,7 @@ 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 (nano::transaction const & transaction_a) const { nano::uint256_union version_key{ 1 }; nano::rocksdb_val data; diff --git a/nano/store/rocksdb/version.hpp b/nano/store/rocksdb/version.hpp index 4aaf0e0d5f..29b9455dac 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 (nano::write_transaction const & transaction_a, int version_a) override; + int get (nano::transaction const & transaction_a) const override; +}; +} // namespace nano::store::rocksdb diff --git a/nano/store/version.hpp b/nano/store/version.hpp index 192cb032a8..b2fb205f86 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; }; - } // namespace nano::store