diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 385829766c..42106adcbd 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -1397,6 +1397,42 @@ TEST (mdb_block_store, upgrade_v21_v22) // Testing the upgrade code worked check_correct_state (); } + +TEST (mdb_block_store, upgrade_v23_v24) +{ + if (nano::rocksdb_config::using_rocksdb_in_tests ()) + { + // Direct lmdb operations are used to simulate the old ledger format so this test will not work on RocksDB + GTEST_SKIP (); + } + + auto path (nano::unique_path () / "data.ldb"); + nano::logger 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 frontiers_handle{ 0 }; + ASSERT_EQ (MDB_NOTFOUND, mdb_dbi_open (store.env.tx (transaction), "frontiers", 0, &frontiers_handle)); + }; + + // Testing current version doesn't contain the frontiers table + check_correct_state (); + + // Setting the database to its 23st version state + { + nano::store::lmdb::component store (logger, path, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + store.version.put (transaction, 23); + MDB_dbi frontiers_handle{ 0 }; + ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "frontiers", MDB_CREATE, &frontiers_handle)); + ASSERT_EQ (store.version.get (transaction), 23); + } + + // Testing the upgrade code worked + check_correct_state (); +} } namespace nano::store::rocksdb diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 8d8e0c0e40..af04a99be2 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -5502,7 +5502,6 @@ TEST (ledger, migrate_lmdb_to_rocksdb) store.confirmation_height.put (transaction, nano::dev::genesis_key.pub, { 2, send->hash () }); store.online_weight.put (transaction, 100, nano::amount (2)); - store.frontier.put (transaction, nano::block_hash (2), nano::account (5)); store.peer.put (transaction, endpoint_key); store.pending.put (transaction, nano::pending_key (nano::dev::genesis_key.pub, send->hash ()), nano::pending_info (nano::dev::genesis_key.pub, 100, nano::epoch::epoch_0)); diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 3a7471d8db..5e1e4b8cda 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -284,7 +284,7 @@ auto nano::block_processor::process_batch (nano::unique_lock & lock processed_batch_t processed; auto scoped_write_guard = write_database_queue.wait (nano::writer::process_batch); - auto transaction (node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::frontiers, tables::pending, tables::rep_weights })); + auto transaction (node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights })); nano::timer timer_l; lock_a.lock (); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index da3a2f0e08..c21f9818dc 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -385,7 +385,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy if (!is_initialized && !flags.read_only) { - auto const transaction (store.tx_begin_write ({ tables::accounts, tables::blocks, tables::confirmation_height, tables::frontiers, tables::rep_weights })); + auto const transaction (store.tx_begin_write ({ tables::accounts, tables::blocks, tables::confirmation_height, tables::rep_weights })); // Store was empty meaning we just created it, add the genesis block store.initialize (transaction, ledger.cache, ledger.constants); } @@ -596,7 +596,7 @@ void nano::node::process_active (std::shared_ptr const & incoming) nano::block_status nano::node::process (std::shared_ptr block) { - auto const transaction = store.tx_begin_write ({ tables::accounts, tables::blocks, tables::frontiers, tables::pending, tables::rep_weights }); + auto const transaction = store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights }); return process (transaction, block); } diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index f245400ee7..1f2f373a02 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -59,8 +58,6 @@ class rollback_visitor : public nano::block_visitor nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.balance (transaction, block_a.hashables.previous).value (), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); ledger.update_account (transaction, pending.value ().source, *info, new_info); ledger.store.block.del (transaction, hash); - ledger.store.frontier.del (transaction, hash); - ledger.store.frontier.put (transaction, block_a.hashables.previous, pending.value ().source); ledger.store.block.successor_clear (transaction, block_a.hashables.previous); ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::send); } @@ -79,8 +76,6 @@ class rollback_visitor : public nano::block_visitor ledger.update_account (transaction, destination_account, *info, new_info); ledger.store.block.del (transaction, hash); ledger.store.pending.put (transaction, nano::pending_key (destination_account, block_a.hashables.source), { source_account.value_or (0), amount, nano::epoch::epoch_0 }); - ledger.store.frontier.del (transaction, hash); - ledger.store.frontier.put (transaction, block_a.hashables.previous, destination_account); ledger.store.block.successor_clear (transaction, block_a.hashables.previous); ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::receive); } @@ -95,7 +90,6 @@ class rollback_visitor : public nano::block_visitor ledger.update_account (transaction, destination_account, new_info, new_info); ledger.store.block.del (transaction, hash); ledger.store.pending.put (transaction, nano::pending_key (destination_account, block_a.hashables.source), { source_account.value_or (0), amount, nano::epoch::epoch_0 }); - ledger.store.frontier.del (transaction, hash); ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::open); } void change_block (nano::change_block const & block_a) override @@ -113,8 +107,6 @@ class rollback_visitor : public nano::block_visitor ledger.store.block.del (transaction, hash); nano::account_info new_info (block_a.hashables.previous, representative, info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); ledger.update_account (transaction, account, *info, new_info); - ledger.store.frontier.del (transaction, hash); - ledger.store.frontier.put (transaction, block_a.hashables.previous, account); ledger.store.block.successor_clear (transaction, block_a.hashables.previous); ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::change); } @@ -174,10 +166,6 @@ class rollback_visitor : public nano::block_visitor if (previous != nullptr) { ledger.store.block.successor_clear (transaction, block_a.hashables.previous); - if (previous->type () < nano::block_type::state) - { - ledger.store.frontier.put (transaction, block_a.hashables.previous, block_a.hashables.account); - } } else { @@ -371,10 +359,6 @@ void ledger_processor::state_block_impl (nano::state_block & block_a) nano::account_info new_info (hash, block_a.hashables.representative, info.open_block.is_zero () ? hash : info.open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch); ledger.update_account (transaction, block_a.hashables.account, info, new_info); - if (!ledger.store.frontier.get (transaction, info.head).is_zero ()) - { - ledger.store.frontier.del (transaction, info.head); - } } } } @@ -441,10 +425,6 @@ void ledger_processor::epoch_block_impl (nano::state_block & block_a) ledger.store.block.put (transaction, hash, block_a); nano::account_info new_info (hash, block_a.hashables.representative, info.open_block.is_zero () ? hash : info.open_block, info.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch); ledger.update_account (transaction, block_a.hashables.account, info, new_info); - if (!ledger.store.frontier.get (transaction, info.head).is_zero ()) - { - ledger.store.frontier.del (transaction, info.head); - } } } } @@ -489,8 +469,6 @@ void ledger_processor::change_block (nano::change_block & block_a) ledger.cache.rep_weights.representation_add_dual (transaction, block_a.hashables.representative, balance.number (), info->representative, 0 - balance.number ()); nano::account_info new_info (hash, block_a.hashables.representative, info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0); ledger.update_account (transaction, account, *info, new_info); - ledger.store.frontier.del (transaction, block_a.hashables.previous); - ledger.store.frontier.put (transaction, hash, account); ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::change); } } @@ -539,8 +517,6 @@ void ledger_processor::send_block (nano::send_block & block_a) nano::account_info new_info (hash, info->representative, info->open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0); ledger.update_account (transaction, account, *info, new_info); ledger.store.pending.put (transaction, nano::pending_key (block_a.hashables.destination, hash), { account, amount, nano::epoch::epoch_0 }); - ledger.store.frontier.del (transaction, block_a.hashables.previous); - ledger.store.frontier.put (transaction, hash, account); ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::send); } } @@ -607,8 +583,6 @@ void ledger_processor::receive_block (nano::receive_block & block_a) nano::account_info new_info (hash, info->representative, info->open_block, new_balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0); ledger.update_account (transaction, account, *info, new_info); ledger.cache.rep_weights.representation_add (transaction, info->representative, pending.value ().amount.number ()); - ledger.store.frontier.del (transaction, block_a.hashables.previous); - ledger.store.frontier.put (transaction, hash, account); ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::receive); } } @@ -669,7 +643,6 @@ void ledger_processor::open_block (nano::open_block & block_a) nano::account_info new_info (hash, block_a.representative_field ().value (), hash, pending.value ().amount.number (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0); ledger.update_account (transaction, block_a.hashables.account, info, new_info); ledger.cache.rep_weights.representation_add (transaction, block_a.representative_field ().value (), pending.value ().amount.number ()); - ledger.store.frontier.put (transaction, hash, block_a.hashables.account); ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::open); } } @@ -1498,15 +1471,6 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p } }); - store.frontier.for_each_par ( - [&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) { - for (; i != n; ++i) - { - auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::frontiers })); - rocksdb_store->frontier.put (rocksdb_transaction, i->first, i->second); - } - }); - store.pruned.for_each_par ( [&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) { for (; i != n; ++i) diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index 9ea6c5c739..794f6c0535 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -9,13 +9,11 @@ add_library( iterator.hpp iterator_impl.hpp final.hpp - frontier.hpp lmdb/account.hpp lmdb/block.hpp lmdb/confirmation_height.hpp lmdb/db_val.hpp lmdb/final_vote.hpp - lmdb/frontier.hpp lmdb/iterator.hpp lmdb/lmdb.hpp lmdb/lmdb_env.hpp @@ -38,7 +36,6 @@ add_library( rocksdb/confirmation_height.hpp rocksdb/db_val.hpp rocksdb/final_vote.hpp - rocksdb/frontier.hpp rocksdb/iterator.hpp rocksdb/online_weight.hpp rocksdb/peer.hpp @@ -61,13 +58,11 @@ add_library( iterator.cpp iterator_impl.cpp final.cpp - frontier.cpp lmdb/account.cpp lmdb/block.cpp lmdb/confirmation_height.cpp lmdb/db_val.cpp lmdb/final_vote.cpp - lmdb/frontier.cpp lmdb/lmdb.cpp lmdb/lmdb_env.cpp lmdb/transaction.cpp @@ -87,7 +82,6 @@ add_library( rocksdb/confirmation_height.cpp rocksdb/db_val.cpp rocksdb/final_vote.cpp - rocksdb/frontier.cpp rocksdb/online_weight.cpp rocksdb/peer.cpp rocksdb/pending.cpp diff --git a/nano/store/component.cpp b/nano/store/component.cpp index 28fc4933c5..5d8c8bec20 100644 --- a/nano/store/component.cpp +++ b/nano/store/component.cpp @@ -5,12 +5,10 @@ #include #include #include -#include #include -nano::store::component::component (nano::store::block & block_store_a, nano::store::frontier & frontier_store_a, nano::store::account & account_store_a, nano::store::pending & pending_store_a, nano::store::online_weight & online_weight_store_a, nano::store::pruned & pruned_store_a, nano::store::peer & peer_store_a, nano::store::confirmation_height & confirmation_height_store_a, nano::store::final_vote & final_vote_store_a, nano::store::version & version_store_a, nano::store::rep_weight & rep_weight_a) : +nano::store::component::component (nano::store::block & block_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, nano::store::rep_weight & rep_weight_a) : block (block_store_a), - frontier (frontier_store_a), account (account_store_a), pending (pending_store_a), online_weight (online_weight_store_a), @@ -40,5 +38,4 @@ void nano::store::component::initialize (store::write_transaction const & transa ++ledger_cache_a.account_count; rep_weight.put (transaction_a, constants.genesis->account (), std::numeric_limits::max ()); ledger_cache_a.rep_weights.representation_put (constants.genesis->account (), std::numeric_limits::max ()); - frontier.put (transaction_a, hash_l, constants.genesis->account ()); } diff --git a/nano/store/component.hpp b/nano/store/component.hpp index ac5103e92c..9ba94029af 100644 --- a/nano/store/component.hpp +++ b/nano/store/component.hpp @@ -21,7 +21,6 @@ namespace store class block; class confirmation_height; class final_vote; - class frontier; class online_weight; class peer; class pending; @@ -45,7 +44,6 @@ namespace store // clang-format off explicit component ( nano::store::block &, - nano::store::frontier &, nano::store::account &, nano::store::pending &, nano::store::online_weight&, @@ -67,12 +65,11 @@ namespace store virtual std::string error_string (int status) const = 0; store::block & block; - store::frontier & frontier; store::account & account; store::pending & pending; store::rep_weight & rep_weight; static int constexpr version_minimum{ 21 }; - static int constexpr version_current{ 23 }; + static int constexpr version_current{ 24 }; public: store::online_weight & online_weight; diff --git a/nano/store/frontier.cpp b/nano/store/frontier.cpp deleted file mode 100644 index 2d12551d59..0000000000 --- a/nano/store/frontier.cpp +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/nano/store/frontier.hpp b/nano/store/frontier.hpp deleted file mode 100644 index b4d504d416..0000000000 --- a/nano/store/frontier.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include -#include - -#include - -namespace nano -{ -class block_hash; -} -namespace nano::store -{ -/** - * Manages frontier storage and iteration - */ -class frontier -{ -public: - virtual void put (store::write_transaction const &, nano::block_hash const &, nano::account const &) = 0; - virtual nano::account get (store::transaction const &, nano::block_hash const &) const = 0; - virtual void del (store::write_transaction const &, nano::block_hash const &) = 0; - virtual iterator begin (store::transaction const &) const = 0; - virtual iterator begin (store::transaction const &, nano::block_hash const &) const = 0; - virtual iterator end () const = 0; - virtual void for_each_par (std::function, store::iterator)> const & action_a) const = 0; -}; -} // namespace nano::store diff --git a/nano/store/lmdb/frontier.cpp b/nano/store/lmdb/frontier.cpp deleted file mode 100644 index 8b694a3ef4..0000000000 --- a/nano/store/lmdb/frontier.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include - -nano::store::lmdb::frontier::frontier (nano::store::lmdb::component & store) : - store{ store } -{ -} - -void nano::store::lmdb::frontier::put (store::write_transaction const & transaction, nano::block_hash const & hash, nano::account const & account) -{ - auto status = store.put (transaction, tables::frontiers, hash, account); - store.release_assert_success (status); -} - -nano::account nano::store::lmdb::frontier::get (store::transaction const & transaction, nano::block_hash const & hash) const -{ - store::db_val value; - auto status = store.get (transaction, tables::frontiers, hash, value); - release_assert (store.success (status) || store.not_found (status)); - nano::account result{}; - if (store.success (status)) - { - result = static_cast (value); - } - return result; -} - -void nano::store::lmdb::frontier::del (store::write_transaction const & transaction, nano::block_hash const & hash) -{ - auto status = store.del (transaction, tables::frontiers, hash); - store.release_assert_success (status); -} - -nano::store::iterator nano::store::lmdb::frontier::begin (store::transaction const & transaction) const -{ - return store.make_iterator (transaction, tables::frontiers); -} - -nano::store::iterator nano::store::lmdb::frontier::begin (store::transaction const & transaction, nano::block_hash const & hash) const -{ - return store.make_iterator (transaction, tables::frontiers, store::db_val (hash)); -} - -nano::store::iterator nano::store::lmdb::frontier::end () const -{ - return store::iterator (nullptr); -} - -void nano::store::lmdb::frontier::for_each_par (std::function, store::iterator)> const & action_a) const -{ - parallel_traversal ( - [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { - auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); - }); -} diff --git a/nano/store/lmdb/frontier.hpp b/nano/store/lmdb/frontier.hpp deleted file mode 100644 index 95205d4cd0..0000000000 --- a/nano/store/lmdb/frontier.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include - -#include - -namespace nano::store::lmdb -{ -class component; -} -namespace nano::store::lmdb -{ -class frontier : public nano::store::frontier -{ -private: - nano::store::lmdb::component & store; - -public: - frontier (nano::store::lmdb::component & store); - void put (store::write_transaction const &, nano::block_hash const &, nano::account const &) override; - nano::account get (store::transaction const &, nano::block_hash const &) const override; - void del (store::write_transaction const &, nano::block_hash const &) override; - store::iterator begin (store::transaction const &) const override; - store::iterator begin (store::transaction const &, nano::block_hash const &) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; - - /** - * Maps head block to owning account - * nano::block_hash -> nano::account - */ - MDB_dbi frontiers_handle{ 0 }; -}; -} // namespace nano::store::lmdb diff --git a/nano/store/lmdb/lmdb.cpp b/nano/store/lmdb/lmdb.cpp index 179c14b407..122bf55a98 100644 --- a/nano/store/lmdb/lmdb.cpp +++ b/nano/store/lmdb/lmdb.cpp @@ -18,7 +18,6 @@ nano::store::lmdb::component::component (nano::logger & logger_a, std::filesyste // clang-format off nano::store::component{ block_store, - frontier_store, account_store, pending_store, online_weight_store, @@ -31,7 +30,6 @@ nano::store::lmdb::component::component (nano::logger & logger_a, std::filesyste }, // clang-format on block_store{ *this }, - frontier_store{ *this }, account_store{ *this }, pending_store{ *this }, online_weight_store{ *this }, @@ -196,7 +194,6 @@ nano::store::lmdb::txn_callbacks nano::store::lmdb::component::create_txn_callba void nano::store::lmdb::component::open_databases (bool & error_a, store::transaction const & transaction_a, unsigned flags) { - error_a |= mdb_dbi_open (env.tx (transaction_a), "frontiers", flags, &frontier_store.frontiers_handle) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "online_weight", flags, &online_weight_store.online_weight_handle) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "meta", flags, &version_store.meta_handle) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "peers", flags, &peer_store.peers_handle) != 0; @@ -229,6 +226,9 @@ bool nano::store::lmdb::component::do_upgrades (store::write_transaction & trans upgrade_v22_to_v23 (transaction_a); [[fallthrough]]; case 23: + upgrade_v23_to_v24 (transaction_a); + [[fallthrough]]; + case 24: break; default: logger.critical (nano::log::type::lmdb, "The version of the ledger ({}) is too high for this node", version_l); @@ -283,6 +283,17 @@ void nano::store::lmdb::component::upgrade_v22_to_v23 (store::write_transaction logger.info (nano::log::type::lmdb, "Upgrading database from v22 to v23 completed"); } +void nano::store::lmdb::component::upgrade_v23_to_v24 (store::write_transaction const & transaction_a) +{ + logger.info (nano::log::type::lmdb, "Upgrading database from v23 to v24..."); + + MDB_dbi frontiers_handle{ 0 }; + release_assert (!mdb_dbi_open (env.tx (transaction_a), "frontiers", MDB_CREATE, &frontiers_handle)); + release_assert (!mdb_drop (env.tx (transaction_a), frontiers_handle, 1)); // del = 1, to delete it from the environment and close the DB handle. + version.put (transaction_a, 24); + logger.info (nano::log::type::lmdb, "Upgrading database from v23 to v24 completed"); +} + /** Takes a filepath, appends '_backup_' to the end (but before any extension) and saves that file in the same directory */ void nano::store::lmdb::component::create_backup_file (nano::store::lmdb::env & env_a, std::filesystem::path const & filepath_a, nano::logger & logger) { @@ -360,8 +371,6 @@ MDB_dbi nano::store::lmdb::component::table_to_dbi (tables table_a) const { switch (table_a) { - case tables::frontiers: - return frontier_store.frontiers_handle; case tables::accounts: return account_store.accounts_handle; case tables::blocks: diff --git a/nano/store/lmdb/lmdb.hpp b/nano/store/lmdb/lmdb.hpp index c763818863..8cf9d94bc3 100644 --- a/nano/store/lmdb/lmdb.hpp +++ b/nano/store/lmdb/lmdb.hpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -45,7 +44,6 @@ class component : public nano::store::component 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; @@ -57,7 +55,6 @@ class component : public nano::store::component 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; @@ -117,6 +114,7 @@ class component : public nano::store::component bool do_upgrades (store::write_transaction &, nano::ledger_constants & constants, bool &); void upgrade_v21_to_v22 (store::write_transaction const &); void upgrade_v22_to_v23 (store::write_transaction const &); + void upgrade_v23_to_v24 (store::write_transaction const &); void open_databases (bool &, store::transaction const &, unsigned); diff --git a/nano/store/rocksdb/frontier.cpp b/nano/store/rocksdb/frontier.cpp deleted file mode 100644 index 6724b93363..0000000000 --- a/nano/store/rocksdb/frontier.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include - -nano::store::rocksdb::frontier::frontier (nano::store::rocksdb::component & store) : - store{ store } -{ -} - -void nano::store::rocksdb::frontier::put (store::write_transaction const & transaction, nano::block_hash const & block, nano::account const & account) -{ - auto status = store.put (transaction, tables::frontiers, block, account); - store.release_assert_success (status); -} - -nano::account nano::store::rocksdb::frontier::get (store::transaction const & transaction, nano::block_hash const & hash) const -{ - db_val value; - auto status = store.get (transaction, tables::frontiers, hash, value); - release_assert (store.success (status) || store.not_found (status)); - nano::account result{}; - if (store.success (status)) - { - result = static_cast (value); - } - return result; -} - -void nano::store::rocksdb::frontier::del (store::write_transaction const & transaction, nano::block_hash const & hash) -{ - auto status = store.del (transaction, tables::frontiers, hash); - store.release_assert_success (status); -} - -nano::store::iterator nano::store::rocksdb::frontier::begin (store::transaction const & transaction) const -{ - return store.make_iterator (transaction, tables::frontiers); -} - -nano::store::iterator nano::store::rocksdb::frontier::begin (store::transaction const & transaction, nano::block_hash const & hash) const -{ - return store.make_iterator (transaction, tables::frontiers, hash); -} - -nano::store::iterator nano::store::rocksdb::frontier::end () const -{ - return nano::store::iterator (nullptr); -} - -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) { - auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); - }); -} diff --git a/nano/store/rocksdb/frontier.hpp b/nano/store/rocksdb/frontier.hpp deleted file mode 100644 index edc0e15b49..0000000000 --- a/nano/store/rocksdb/frontier.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include -#include - -namespace nano::store::rocksdb -{ -class component; -} -namespace nano::store::rocksdb -{ -class frontier : public nano::store::frontier -{ -public: - frontier (nano::store::rocksdb::component & store); - void put (store::write_transaction const &, nano::block_hash const &, nano::account const &) override; - nano::account get (store::transaction const &, nano::block_hash const &) const override; - void del (store::write_transaction const &, nano::block_hash const &) override; - store::iterator begin (store::transaction const &) const override; - store::iterator begin (store::transaction const &, nano::block_hash const &) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; - -private: - nano::store::rocksdb::component & store; -}; -} // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index f13cdb76ba..d9fb4e3164 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -39,7 +39,6 @@ nano::store::rocksdb::component::component (nano::logger & logger_a, std::filesy // clang-format off nano::store::component{ block_store, - frontier_store, account_store, pending_store, online_weight_store, @@ -52,7 +51,6 @@ nano::store::rocksdb::component::component (nano::logger & logger_a, std::filesy }, // clang-format on block_store{ *this }, - frontier_store{ *this }, account_store{ *this }, pending_store{ *this }, online_weight_store{ *this }, @@ -164,7 +162,6 @@ nano::store::rocksdb::component::component (nano::logger & logger_a, std::filesy 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 }, { "accounts", tables::accounts }, { "blocks", tables::blocks }, { "pending", tables::pending }, @@ -248,6 +245,9 @@ bool nano::store::rocksdb::component::do_upgrades (store::write_transaction cons upgrade_v22_to_v23 (transaction_a); [[fallthrough]]; case 23: + upgrade_v23_to_v24 (transaction_a); + [[fallthrough]]; + case 24: break; default: logger.critical (nano::log::type::rocksdb, "The version of the ledger ({}) is too high for this node", version_l); @@ -316,6 +316,31 @@ void nano::store::rocksdb::component::upgrade_v22_to_v23 (store::write_transacti logger.info (nano::log::type::rocksdb, "Upgrading database from v22 to v23 completed"); } +void nano::store::rocksdb::component::upgrade_v23_to_v24 (store::write_transaction const & transaction_a) +{ + logger.info (nano::log::type::rocksdb, "Upgrading database from v23 to v24..."); + + if (column_family_exists ("frontiers")) + { + auto const unchecked_handle = get_column_family ("frontiers"); + db->DropColumnFamily (unchecked_handle); + db->DestroyColumnFamilyHandle (unchecked_handle); + std::erase_if (handles, [unchecked_handle] (auto & handle) { + if (handle.get () == unchecked_handle) + { + // The handle resource is deleted by RocksDB. + [[maybe_unused]] auto ptr = handle.release (); + return true; + } + return false; + }); + logger.debug (nano::log::type::rocksdb, "Finished removing frontiers table"); + } + + version.put (transaction_a, 24); + logger.info (nano::log::type::rocksdb, "Upgrading database from v23 to v24 completed"); +} + 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)); @@ -531,8 +556,6 @@ rocksdb::ColumnFamilyHandle * nano::store::rocksdb::component::table_to_column_f { switch (table_a) { - case tables::frontiers: - return get_column_family ("frontiers"); case tables::accounts: return get_column_family ("accounts"); case tables::blocks: @@ -904,7 +927,7 @@ void nano::store::rocksdb::component::on_flush (::rocksdb::FlushJobInfo 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, tables::rep_weights }; + return std::vector{ tables::accounts, tables::blocks, tables::confirmation_height, tables::final_votes, tables::meta, tables::online_weight, tables::peers, tables::pending, tables::pruned, tables::vote, tables::rep_weights }; } bool nano::store::rocksdb::component::copy_db (std::filesystem::path const & destination_path) diff --git a/nano/store/rocksdb/rocksdb.hpp b/nano/store/rocksdb/rocksdb.hpp index f6c2d683b8..8a71cf2b12 100644 --- a/nano/store/rocksdb/rocksdb.hpp +++ b/nano/store/rocksdb/rocksdb.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -46,7 +45,6 @@ class component : public nano::store::component 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; @@ -59,7 +57,6 @@ class component : public nano::store::component 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; @@ -155,6 +152,7 @@ class component : public nano::store::component bool do_upgrades (store::write_transaction const &); void upgrade_v21_to_v22 (store::write_transaction const &); void upgrade_v22_to_v23 (store::write_transaction const &); + void upgrade_v23_to_v24 (store::write_transaction const &); void construct_column_family_mutexes (); ::rocksdb::Options get_db_options (); diff --git a/nano/store/tables.hpp b/nano/store/tables.hpp index cf53a0f914..13b073b76f 100644 --- a/nano/store/tables.hpp +++ b/nano/store/tables.hpp @@ -12,7 +12,6 @@ enum class tables confirmation_height, default_unused, // RocksDB only final_votes, - frontiers, meta, online_weight, peers, diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 62f15f82af..75f26546f4 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -65,7 +65,7 @@ nano::account nano::test::random_account () bool nano::test::process (nano::node & node, std::vector> blocks) { - auto const transaction = node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::frontiers, tables::pending, tables::rep_weights }); + auto const transaction = node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights }); for (auto & block : blocks) { auto result = node.process (transaction, block);