diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 468e2340e4..8d6804a113 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -916,10 +916,10 @@ TEST (block_store, pruned_random) nano::ledger_cache ledger_cache; auto transaction (store->tx_begin_write ()); store->initialize (transaction, genesis, ledger_cache); - store->pruned_put (transaction, hash1); + store->pruned.put (transaction, hash1); } auto transaction (store->tx_begin_read ()); - auto random_hash (store->pruned_random (transaction)); + auto random_hash (store->pruned.random (transaction)); ASSERT_EQ (hash1, random_hash); } @@ -1212,16 +1212,16 @@ TEST (block_store, pruned_blocks) auto transaction (store->tx_begin_write ()); // Confirm that the store is empty - ASSERT_FALSE (store->pruned_exists (transaction, hash1)); - ASSERT_EQ (store->pruned_count (transaction), 0); + ASSERT_FALSE (store->pruned.exists (transaction, hash1)); + ASSERT_EQ (store->pruned.count (transaction), 0); // Add one - store->pruned_put (transaction, hash1); - ASSERT_TRUE (store->pruned_exists (transaction, hash1)); + store->pruned.put (transaction, hash1); + ASSERT_TRUE (store->pruned.exists (transaction, hash1)); } // Confirm that it can be found - ASSERT_EQ (store->pruned_count (store->tx_begin_read ()), 1); + ASSERT_EQ (store->pruned.count (store->tx_begin_read ()), 1); // Add another one and check that it (and the existing one) can be found nano::open_block block2 (1, 2, key1.pub, key1.prv, key1.pub, 0); @@ -1229,37 +1229,37 @@ TEST (block_store, pruned_blocks) auto hash2 (block2.hash ()); { auto transaction (store->tx_begin_write ()); - store->pruned_put (transaction, hash2); - ASSERT_TRUE (store->pruned_exists (transaction, hash2)); // Check new pruned hash is here + store->pruned.put (transaction, hash2); + ASSERT_TRUE (store->pruned.exists (transaction, hash2)); // Check new pruned hash is here ASSERT_FALSE (store->block_exists (transaction, hash2)); - ASSERT_TRUE (store->pruned_exists (transaction, hash1)); // Check first pruned hash is still here + ASSERT_TRUE (store->pruned.exists (transaction, hash1)); // Check first pruned hash is still here ASSERT_FALSE (store->block_exists (transaction, hash1)); } - ASSERT_EQ (store->pruned_count (store->tx_begin_read ()), 2); + ASSERT_EQ (store->pruned.count (store->tx_begin_read ()), 2); // Delete the first one { auto transaction (store->tx_begin_write ()); - store->pruned_del (transaction, hash2); - ASSERT_FALSE (store->pruned_exists (transaction, hash2)); // Confirm it no longer exists + store->pruned.del (transaction, hash2); + ASSERT_FALSE (store->pruned.exists (transaction, hash2)); // Confirm it no longer exists ASSERT_FALSE (store->block_exists (transaction, hash2)); // true for block_exists store->block_put (transaction, hash2, block2); // Add corresponding block ASSERT_TRUE (store->block_exists (transaction, hash2)); - ASSERT_TRUE (store->pruned_exists (transaction, hash1)); // Check first pruned hash is still here + ASSERT_TRUE (store->pruned.exists (transaction, hash1)); // Check first pruned hash is still here ASSERT_FALSE (store->block_exists (transaction, hash1)); } - ASSERT_EQ (store->pruned_count (store->tx_begin_read ()), 1); + ASSERT_EQ (store->pruned.count (store->tx_begin_read ()), 1); // Delete original one { auto transaction (store->tx_begin_write ()); - store->pruned_del (transaction, hash1); - ASSERT_FALSE (store->pruned_exists (transaction, hash1)); + store->pruned.del (transaction, hash1); + ASSERT_FALSE (store->pruned.exists (transaction, hash1)); } - ASSERT_EQ (store->pruned_count (store->tx_begin_read ()), 0); + ASSERT_EQ (store->pruned.count (store->tx_begin_read ()), 0); } TEST (mdb_block_store, upgrade_v14_v15) @@ -1799,13 +1799,13 @@ TEST (mdb_block_store, upgrade_v19_v20) auto transaction (store.tx_begin_write ()); store.initialize (transaction, genesis, ledger.cache); // Delete pruned table - ASSERT_FALSE (mdb_drop (store.env.tx (transaction), store.pruned, 1)); + ASSERT_FALSE (mdb_drop (store.env.tx (transaction), store.pruned_handle, 1)); store.version_put (transaction, 19); } // Upgrading should create the table nano::mdb_store store (logger, path); ASSERT_FALSE (store.init_error ()); - ASSERT_NE (store.pruned, 0); + ASSERT_NE (store.pruned_handle, 0); // Version should be correct auto transaction (store.tx_begin_read ()); diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index a7401cba8d..6433dad4d4 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -443,9 +443,9 @@ TEST (bootstrap_processor, push_diamond_pruning) ASSERT_EQ (1, node1->ledger.pruning_action (transaction, open->hash (), 1)); ASSERT_TRUE (node1->store.block_exists (transaction, latest)); ASSERT_FALSE (node1->store.block_exists (transaction, send1->hash ())); - ASSERT_TRUE (node1->store.pruned_exists (transaction, send1->hash ())); + ASSERT_TRUE (node1->store.pruned.exists (transaction, send1->hash ())); ASSERT_FALSE (node1->store.block_exists (transaction, open->hash ())); - ASSERT_TRUE (node1->store.pruned_exists (transaction, open->hash ())); + ASSERT_TRUE (node1->store.pruned.exists (transaction, open->hash ())); ASSERT_TRUE (node1->store.block_exists (transaction, send2->hash ())); ASSERT_TRUE (node1->store.block_exists (transaction, receive->hash ())); ASSERT_EQ (2, node1->ledger.cache.pruned_count); diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 5692b66f3d..b8e4e15a4a 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -3433,7 +3433,7 @@ TEST (ledger, cache) { auto transaction (store->tx_begin_write ()); - ledger.store.pruned_put (transaction, open->hash ()); + ledger.store.pruned.put (transaction, open->hash ()); ++ledger.cache.pruned_count; } ++pruned_count; @@ -3474,7 +3474,7 @@ TEST (ledger, pruning_action) ledger.pruning = false; ASSERT_TRUE (ledger.block_or_pruned_exists (transaction, send1.hash ())); ledger.pruning = true; - ASSERT_TRUE (store->pruned_exists (transaction, send1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, send1.hash ())); ASSERT_TRUE (store->block_exists (transaction, genesis.hash ())); ASSERT_TRUE (store->block_exists (transaction, send2.hash ())); // Receiving pruned block @@ -3492,10 +3492,10 @@ TEST (ledger, pruning_action) // Middle block pruning ASSERT_TRUE (store->block_exists (transaction, send2.hash ())); ASSERT_EQ (1, ledger.pruning_action (transaction, send2.hash (), 1)); - ASSERT_TRUE (store->pruned_exists (transaction, send2.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, send2.hash ())); ASSERT_FALSE (store->block_exists (transaction, send2.hash ())); ASSERT_EQ (store->account.count (transaction), ledger.cache.account_count); - ASSERT_EQ (store->pruned_count (transaction), ledger.cache.pruned_count); + ASSERT_EQ (store->pruned.count (transaction), ledger.cache.pruned_count); ASSERT_EQ (store->block_count (transaction), ledger.cache.block_count - ledger.cache.pruned_count); } @@ -3523,16 +3523,16 @@ TEST (ledger, pruning_large_chain) ASSERT_TRUE (store->block_exists (transaction, receive.hash ())); last_hash = receive.hash (); } - ASSERT_EQ (0, store->pruned_count (transaction)); + ASSERT_EQ (0, store->pruned.count (transaction)); ASSERT_EQ (send_receive_pairs * 2 + 1, store->block_count (transaction)); // Pruning action ASSERT_EQ (send_receive_pairs * 2, ledger.pruning_action (transaction, last_hash, 5)); - ASSERT_TRUE (store->pruned_exists (transaction, last_hash)); + ASSERT_TRUE (store->pruned.exists (transaction, last_hash)); ASSERT_TRUE (store->block_exists (transaction, genesis.hash ())); ASSERT_FALSE (store->block_exists (transaction, last_hash)); - ASSERT_EQ (store->pruned_count (transaction), ledger.cache.pruned_count); + ASSERT_EQ (store->pruned.count (transaction), ledger.cache.pruned_count); ASSERT_EQ (store->block_count (transaction), ledger.cache.block_count - ledger.cache.pruned_count); - ASSERT_EQ (send_receive_pairs * 2, store->pruned_count (transaction)); + ASSERT_EQ (send_receive_pairs * 2, store->pruned.count (transaction)); ASSERT_EQ (1, store->block_count (transaction)); // Genesis } @@ -3559,9 +3559,9 @@ TEST (ledger, pruning_source_rollback) // Pruning action ASSERT_EQ (2, ledger.pruning_action (transaction, send1.hash (), 1)); ASSERT_FALSE (store->block_exists (transaction, send1.hash ())); - ASSERT_TRUE (store->pruned_exists (transaction, send1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, send1.hash ())); ASSERT_FALSE (store->block_exists (transaction, epoch1.hash ())); - ASSERT_TRUE (store->pruned_exists (transaction, epoch1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, epoch1.hash ())); ASSERT_TRUE (store->block_exists (transaction, genesis.hash ())); nano::pending_info info; ASSERT_FALSE (store->pending.get (transaction, nano::pending_key (nano::genesis_account, send1.hash ()), info)); @@ -3615,9 +3615,9 @@ TEST (ledger, pruning_source_rollback_legacy) // Pruning action ASSERT_EQ (2, ledger.pruning_action (transaction, send2.hash (), 1)); ASSERT_FALSE (store->block_exists (transaction, send2.hash ())); - ASSERT_TRUE (store->pruned_exists (transaction, send2.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, send2.hash ())); ASSERT_FALSE (store->block_exists (transaction, send1.hash ())); - ASSERT_TRUE (store->pruned_exists (transaction, send1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, send1.hash ())); ASSERT_TRUE (store->block_exists (transaction, genesis.hash ())); nano::pending_info info1; ASSERT_FALSE (store->pending.get (transaction, nano::pending_key (nano::genesis_account, send1.hash ()), info1)); @@ -3686,7 +3686,7 @@ TEST (ledger, pruning_process_error) // Pruning action for latest block (not valid action) ASSERT_EQ (1, ledger.pruning_action (transaction, send1.hash (), 1)); ASSERT_FALSE (store->block_exists (transaction, send1.hash ())); - ASSERT_TRUE (store->pruned_exists (transaction, send1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, send1.hash ())); // Attempt to process pruned block again ASSERT_EQ (nano::process_result::old, ledger.process (transaction, send1).code); // Attept to process new block after pruned @@ -3727,18 +3727,18 @@ TEST (ledger, pruning_legacy_blocks) ASSERT_EQ (1, ledger.pruning_action (transaction, open1.hash (), 1)); ASSERT_TRUE (store->block_exists (transaction, genesis.hash ())); ASSERT_FALSE (store->block_exists (transaction, send1.hash ())); - ASSERT_TRUE (store->pruned_exists (transaction, send1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, send1.hash ())); ASSERT_FALSE (store->block_exists (transaction, receive1.hash ())); - ASSERT_TRUE (store->pruned_exists (transaction, receive1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, receive1.hash ())); ASSERT_FALSE (store->block_exists (transaction, change1.hash ())); - ASSERT_TRUE (store->pruned_exists (transaction, change1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, change1.hash ())); ASSERT_TRUE (store->block_exists (transaction, send2.hash ())); ASSERT_FALSE (store->block_exists (transaction, open1.hash ())); - ASSERT_TRUE (store->pruned_exists (transaction, open1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, open1.hash ())); ASSERT_TRUE (store->block_exists (transaction, send3.hash ())); ASSERT_EQ (4, ledger.cache.pruned_count); ASSERT_EQ (7, ledger.cache.block_count); - ASSERT_EQ (store->pruned_count (transaction), ledger.cache.pruned_count); + ASSERT_EQ (store->pruned.count (transaction), ledger.cache.pruned_count); ASSERT_EQ (store->block_count (transaction), ledger.cache.block_count - ledger.cache.pruned_count); } @@ -3764,7 +3764,7 @@ TEST (ledger, pruning_safe_functions) ASSERT_EQ (1, ledger.pruning_action (transaction, send1.hash (), 1)); ASSERT_FALSE (store->block_exists (transaction, send1.hash ())); ASSERT_TRUE (ledger.block_or_pruned_exists (transaction, send1.hash ())); // true for pruned - ASSERT_TRUE (store->pruned_exists (transaction, send1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, send1.hash ())); ASSERT_TRUE (store->block_exists (transaction, genesis.hash ())); ASSERT_TRUE (store->block_exists (transaction, send2.hash ())); // Safe ledger actions @@ -3806,7 +3806,7 @@ TEST (ledger, hash_root_random) // Pruning action ASSERT_EQ (1, ledger.pruning_action (transaction, send1.hash (), 1)); ASSERT_FALSE (store->block_exists (transaction, send1.hash ())); - ASSERT_TRUE (store->pruned_exists (transaction, send1.hash ())); + ASSERT_TRUE (store->pruned.exists (transaction, send1.hash ())); ASSERT_TRUE (store->block_exists (transaction, genesis.hash ())); ASSERT_TRUE (store->block_exists (transaction, send2.hash ())); // Test random block including pruned @@ -3867,7 +3867,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb) store.peer_put (transaction, endpoint_key); store.pending.put (transaction, nano::pending_key (nano::genesis_account, send->hash ()), nano::pending_info (nano::genesis_account, 100, nano::epoch::epoch_0)); - store.pruned_put (transaction, send->hash ()); + store.pruned.put (transaction, send->hash ()); store.unchecked_put (transaction, nano::genesis_hash, send); store.version_put (transaction, version); send->sideband_set ({}); diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index e1b0e9d714..40f251c0bc 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -4742,7 +4742,7 @@ TEST (node, pruning_automatic) ASSERT_TIMELY (2s, node1.active.empty () && node1.block_confirmed (send2->hash ())); // Check pruning result ASSERT_TIMELY (3s, node1.ledger.cache.pruned_count == 1); - ASSERT_TIMELY (2s, node1.store.pruned_count (node1.store.tx_begin_read ()) == 1); // Transaction commit + ASSERT_TIMELY (2s, node1.store.pruned.count (node1.store.tx_begin_read ()) == 1); // Transaction commit ASSERT_EQ (1, node1.ledger.cache.pruned_count); ASSERT_EQ (3, node1.ledger.cache.block_count); ASSERT_TRUE (node1.ledger.block_or_pruned_exists (genesis.hash ())); diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index eba60533f3..70e003659a 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1437,7 +1437,7 @@ int main (int argc, char * const * argv) else { pruned_block = true; - if (!node->store.pruned_exists (transaction, block->previous ())) + if (!node->store.pruned.exists (transaction, block->previous ())) { print_error_message (boost::str (boost::format ("Pruned previous block does not exist %1%\n") % block->previous ().to_string ())); } @@ -1554,7 +1554,7 @@ int main (int argc, char * const * argv) } } } - else if (!node->store.pruned_exists (transaction, block->previous ())) + else if (!node->store.pruned.exists (transaction, block->previous ())) { print_error_message (boost::str (boost::format ("Previous pruned block does not exist %1%\n") % block->previous ().to_string ())); } @@ -1564,7 +1564,7 @@ int main (int argc, char * const * argv) print_error_message (boost::str (boost::format ("Incorrect sideband block details for block %1%\n") % hash.to_string ())); } // Check link epoch version - if (sideband.details.is_receive && (!node->ledger.pruning || !node->store.pruned_exists (transaction, block->link ().as_block_hash ()))) + if (sideband.details.is_receive && (!node->ledger.pruning || !node->store.pruned.exists (transaction, block->link ().as_block_hash ()))) { if (sideband.source_epoch != node->store.block_version (transaction, block->link ().as_block_hash ())) { @@ -1687,7 +1687,7 @@ int main (int argc, char * const * argv) bool pruned (false); if (block == nullptr) { - pruned = node->ledger.pruning && node->store.pruned_exists (transaction, key.hash); + pruned = node->ledger.pruning && node->store.pruned.exists (transaction, key.hash); if (!pruned) { print_error_message (boost::str (boost::format ("Pending block does not exist %1%\n") % key.hash.to_string ())); @@ -1697,7 +1697,7 @@ int main (int argc, char * const * argv) { // Check if pending destination is correct nano::account destination (0); - bool previous_pruned = node->ledger.pruning && node->store.pruned_exists (transaction, block->previous ()); + bool previous_pruned = node->ledger.pruning && node->store.pruned.exists (transaction, block->previous ()); if (previous_pruned) { block = node->store.block_get (transaction, key.hash); diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 782b249fe2..3a1eaf1e01 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -1310,7 +1310,7 @@ nano::inactive_cache_status nano::active_transactions::inactive_votes_bootstrap_ lock_a.lock (); insert_impl (lock_a, block); } - else if (!block && status.bootstrap_started && !previously_a.bootstrap_started && (!node.ledger.pruning || !node.store.pruned_exists (transaction, hash_a))) + else if (!block && status.bootstrap_started && !previously_a.bootstrap_started && (!node.ledger.pruning || !node.store.pruned.exists (transaction, hash_a))) { node.gap_cache.bootstrap_start (hash_a); } diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index f7237c1838..530267d5e8 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -89,7 +89,7 @@ void nano::confirmation_height_bounded::process (std::shared_ptr or if (!block) { - if (ledger.pruning && ledger.store.pruned_exists (transaction, current)) + if (ledger.pruning && ledger.store.pruned.exists (transaction, current)) { if (!receive_source_pairs.empty ()) { diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index 63bd7bc963..98274256ee 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -386,7 +386,7 @@ void nano::confirmation_height_unbounded::cement_blocks (nano::write_guard & sco if (!block) { - if (ledger.pruning && ledger.store.pruned_exists (transaction, pending.hash)) + if (ledger.pruning && ledger.store.pruned.exists (transaction, pending.hash)) { pending_writes.erase (pending_writes.begin ()); --pending_writes_size; diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index b11893db77..3212d6c6f8 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -3173,7 +3173,7 @@ void nano::json_handler::pruned_exists () auto transaction (node.store.tx_begin_read ()); if (node.ledger.pruning) { - auto exists (node.store.pruned_exists (transaction, hash)); + auto exists (node.store.pruned.exists (transaction, hash)); response_l.put ("exists", exists ? "1" : "0"); } else diff --git a/nano/node/lmdb/lmdb.cpp b/nano/node/lmdb/lmdb.cpp index 2c6829224f..7ca124bd9e 100644 --- a/nano/node/lmdb/lmdb.cpp +++ b/nano/node/lmdb/lmdb.cpp @@ -193,7 +193,7 @@ void nano::mdb_store::open_databases (bool & error_a, nano::transaction const & error_a |= mdb_dbi_open (env.tx (transaction_a), "online_weight", flags, &online_weight_handle) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "meta", flags, &meta) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "peers", flags, &peers) != 0; - error_a |= mdb_dbi_open (env.tx (transaction_a), "pruned", flags, &pruned) != 0; + error_a |= mdb_dbi_open (env.tx (transaction_a), "pruned", flags, &pruned_handle) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "confirmation_height", flags, &confirmation_height_handle) != 0; error_a |= mdb_dbi_open (env.tx (transaction_a), "accounts", flags, &accounts_v0) != 0; accounts = accounts_v0; @@ -744,7 +744,7 @@ void nano::mdb_store::upgrade_v18_to_v19 (nano::write_transaction const & transa void nano::mdb_store::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); + mdb_dbi_open (env.tx (transaction_a), "pruned", MDB_CREATE, &pruned_handle); version_put (transaction_a, 20); logger.always_log ("Finished creating new pruned table"); } @@ -874,7 +874,7 @@ MDB_dbi nano::mdb_store::table_to_dbi (tables table_a) const case tables::peers: return peers; case tables::pruned: - return pruned; + return pruned_handle; case tables::confirmation_height: return confirmation_height_handle; case tables::final_votes: @@ -913,7 +913,7 @@ bool nano::mdb_store::copy_db (boost::filesystem::path const & destination_file) void nano::mdb_store::rebuild_db (nano::write_transaction const & transaction_a) { // Tables with uint256_union key - std::vector tables = { accounts, blocks, pruned, confirmation_height_handle }; + std::vector tables = { accounts, blocks, pruned_handle, confirmation_height_handle }; for (auto const & table : tables) { MDB_dbi temp; diff --git a/nano/node/lmdb/lmdb.hpp b/nano/node/lmdb/lmdb.hpp index f05e6d65f5..604dc0abf3 100644 --- a/nano/node/lmdb/lmdb.hpp +++ b/nano/node/lmdb/lmdb.hpp @@ -172,7 +172,7 @@ class mdb_store : public block_store_partial * Pruned blocks hashes * nano::block_hash -> none */ - MDB_dbi pruned{ 0 }; + MDB_dbi pruned_handle{ 0 }; /* * Endpoints for peers diff --git a/nano/node/node.cpp b/nano/node/node.cpp index d82683f674..05336c4692 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -411,7 +411,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, boost::filesystem::path co } } - ledger.pruning = flags.enable_pruning || store.pruned_count (store.tx_begin_read ()) > 0; + ledger.pruning = flags.enable_pruning || store.pruned.count (store.tx_begin_read ()) > 0; if (ledger.pruning) { diff --git a/nano/secure/CMakeLists.txt b/nano/secure/CMakeLists.txt index 241a8929ef..81ef22cada 100644 --- a/nano/secure/CMakeLists.txt +++ b/nano/secure/CMakeLists.txt @@ -58,6 +58,7 @@ add_library( store/account_store_partial.hpp store/pending_store_partial.hpp store/online_weight_partial.hpp + store/pruned_store_partial.hpp store/confirmation_height_store_partial.hpp store/final_vote_store_partial.hpp) diff --git a/nano/secure/blockstore.cpp b/nano/secure/blockstore.cpp index 92f3d4b42c..bf8fd8f78c 100644 --- a/nano/secure/blockstore.cpp +++ b/nano/secure/blockstore.cpp @@ -105,11 +105,12 @@ bool nano::write_transaction::contains (nano::tables table_a) const return impl->contains (table_a); } -nano::block_store::block_store (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::confirmation_height_store & confirmation_height_store_a, nano::final_vote_store & final_vote_store_a) : +nano::block_store::block_store (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::confirmation_height_store & confirmation_height_store_a, nano::final_vote_store & final_vote_store_a) : frontier (frontier_store_a), account (account_store_a), pending (pending_store_a), online_weight (online_weight_store_a), + pruned (pruned_store_a), confirmation_height (confirmation_height_store_a), final_vote (final_vote_store_a) { diff --git a/nano/secure/blockstore.hpp b/nano/secure/blockstore.hpp index 4dff63060d..3207f380c1 100644 --- a/nano/secure/blockstore.hpp +++ b/nano/secure/blockstore.hpp @@ -685,6 +685,24 @@ class online_weight_store virtual void clear (nano::write_transaction const &) = 0; }; +/** + * Manages pruned storage and iteration + */ +class pruned_store +{ +public: + virtual void put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; + virtual void del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; + virtual bool exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; + virtual nano::block_hash random (nano::transaction const & transaction_a) = 0; + virtual size_t count (nano::transaction const & transaction_a) const = 0; + virtual void clear (nano::write_transaction const &) = 0; + virtual nano::store_iterator begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; + virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; + virtual nano::store_iterator end () const = 0; + virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; +}; + /** * Manages confirmation height storage and iteration */ @@ -728,7 +746,7 @@ class final_vote_store class block_store { public: - explicit block_store (nano::frontier_store &, nano::account_store &, nano::pending_store &, nano::online_weight_store &, nano::confirmation_height_store &, nano::final_vote_store &); + explicit block_store (nano::frontier_store &, nano::account_store &, nano::pending_store &, nano::online_weight_store &, nano::pruned_store &, nano::confirmation_height_store &, nano::final_vote_store &); virtual ~block_store () = default; virtual void initialize (nano::write_transaction const &, nano::genesis const &, nano::ledger_cache &) = 0; virtual void block_put (nano::write_transaction const &, nano::block_hash const &, nano::block const &) = 0; @@ -772,15 +790,7 @@ class block_store virtual void version_put (nano::write_transaction const &, int) = 0; virtual int version_get (nano::transaction const &) const = 0; - virtual void pruned_put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; - virtual void pruned_del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; - virtual bool pruned_exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; - virtual nano::block_hash pruned_random (nano::transaction const & transaction_a) = 0; - virtual size_t pruned_count (nano::transaction const & transaction_a) const = 0; - virtual void pruned_clear (nano::write_transaction const &) = 0; - virtual nano::store_iterator pruned_begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; - virtual nano::store_iterator pruned_begin (nano::transaction const & transaction_a) const = 0; - virtual nano::store_iterator pruned_end () const = 0; + pruned_store & pruned; virtual void peer_put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0; virtual void peer_del (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0; @@ -793,7 +803,6 @@ class block_store confirmation_height_store & confirmation_height; virtual void unchecked_for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; - virtual void pruned_for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; virtual void blocks_for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; virtual uint64_t block_account_height (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; diff --git a/nano/secure/blockstore_partial.hpp b/nano/secure/blockstore_partial.hpp index 4694469ef5..921679461d 100644 --- a/nano/secure/blockstore_partial.hpp +++ b/nano/secure/blockstore_partial.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -45,6 +46,7 @@ class block_store_partial : public block_store nano::account_store_partial account_store_partial; nano::pending_store_partial pending_store_partial; nano::online_weight_store_partial online_weight_store_partial; + nano::pruned_store_partial pruned_store_partial; nano::confirmation_height_store_partial confirmation_height_store_partial; nano::final_vote_store_partial final_vote_store_partial; @@ -59,15 +61,17 @@ class block_store_partial : public block_store friend class nano::account_store_partial; friend class nano::pending_store_partial; friend class nano::online_weight_store_partial; + friend class nano::pruned_store_partial; friend class nano::confirmation_height_store_partial; friend class nano::final_vote_store_partial; block_store_partial () : - block_store{ frontier_store_partial, account_store_partial, pending_store_partial, online_weight_store_partial, confirmation_height_store_partial, final_vote_store_partial }, + block_store{ frontier_store_partial, account_store_partial, pending_store_partial, online_weight_store_partial, pruned_store_partial, confirmation_height_store_partial, final_vote_store_partial }, frontier_store_partial{ *this }, account_store_partial{ *this }, pending_store_partial{ *this }, online_weight_store_partial{ *this }, + pruned_store_partial{ *this }, confirmation_height_store_partial{ *this }, final_vote_store_partial{ *this } { @@ -255,11 +259,6 @@ class block_store_partial : public block_store return nano::store_iterator (nullptr); } - nano::store_iterator pruned_end () const override - { - return nano::store_iterator (nullptr); - } - int version_get (nano::transaction const & transaction_a) const override { nano::uint256_union version_key (1); @@ -333,34 +332,6 @@ class block_store_partial : public block_store release_assert_success (*this, status); } - void pruned_put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override - { - auto status = put_key (transaction_a, tables::pruned, hash_a); - release_assert_success (*this, status); - } - - void pruned_del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override - { - auto status = del (transaction_a, tables::pruned, hash_a); - release_assert_success (*this, status); - } - - bool pruned_exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override - { - return exists (transaction_a, tables::pruned, nano::db_val (hash_a)); - } - - size_t pruned_count (nano::transaction const & transaction_a) const override - { - return count (transaction_a, tables::pruned); - } - - void pruned_clear (nano::write_transaction const & transaction_a) override - { - auto status = drop (transaction_a, tables::pruned); - release_assert_success (*this, status); - } - void peer_put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override { auto status = put_key (transaction_a, tables::peers, endpoint_a); @@ -413,19 +384,6 @@ class block_store_partial : public block_store return existing->second; } - nano::block_hash pruned_random (nano::transaction const & transaction_a) override - { - nano::block_hash random_hash; - nano::random_pool::generate_block (random_hash.bytes.data (), random_hash.bytes.size ()); - auto existing = make_iterator> (transaction_a, tables::pruned, nano::db_val (random_hash)); - auto end (nano::store_iterator> (nullptr)); - if (existing == end) - { - existing = make_iterator> (transaction_a, tables::pruned); - } - return existing != end ? existing->first : 0; - } - nano::store_iterator blocks_begin (nano::transaction const & transaction_a) const override { return make_iterator (transaction_a, tables::blocks); @@ -451,16 +409,6 @@ class block_store_partial : public block_store return make_iterator (transaction_a, tables::peers); } - nano::store_iterator pruned_begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override - { - return make_iterator (transaction_a, tables::pruned, nano::db_val (hash_a)); - } - - nano::store_iterator pruned_begin (nano::transaction const & transaction_a) const override - { - return make_iterator (transaction_a, tables::pruned); - } - size_t unchecked_count (nano::transaction const & transaction_a) override { return count (transaction_a, tables::unchecked); @@ -486,15 +434,6 @@ class block_store_partial : public block_store }); } - void pruned_for_each_par (std::function, nano::store_iterator)> const & action_a) const override - { - parallel_traversal ( - [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { - auto transaction (this->tx_begin_read ()); - action_a (transaction, this->pruned_begin (transaction, start), !is_last ? this->pruned_begin (transaction, end) : this->pruned_end ()); - }); - } - int const minimum_version{ 14 }; protected: diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 3975a04fa2..5d68de7bd0 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -783,7 +783,7 @@ void nano::ledger::initialize (nano::generate_cache const & generate_cache_a) } auto transaction (store.tx_begin_read ()); - cache.pruned_count = store.pruned_count (transaction); + cache.pruned_count = store.pruned.count (transaction); // Final votes requirement for confirmation canary block nano::confirmation_height_info confirmation_height_info; @@ -893,7 +893,7 @@ bool nano::ledger::block_or_pruned_exists (nano::block_hash const & hash_a) cons bool nano::ledger::block_or_pruned_exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const { - if (store.pruned_exists (transaction_a, hash_a)) + if (store.pruned.exists (transaction_a, hash_a)) { return true; } @@ -999,7 +999,7 @@ std::pair nano::ledger::hash_root_random (na // Pruned cache cannot guarantee that pruned blocks are already commited if (region < cache.pruned_count) { - hash = store.pruned_random (transaction_a); + hash = store.pruned.random (transaction_a); } if (hash.is_zero ()) { @@ -1323,7 +1323,7 @@ std::shared_ptr nano::ledger::forked_block (nano::transaction const bool nano::ledger::block_confirmed (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const { - if (store.pruned_exists (transaction_a, hash_a)) + if (store.pruned.exists (transaction_a, hash_a)) { return true; } @@ -1348,7 +1348,7 @@ uint64_t nano::ledger::pruning_action (nano::write_transaction & transaction_a, if (block != nullptr) { store.block_del (transaction_a, hash); - store.pruned_put (transaction_a, hash); + store.pruned.put (transaction_a, hash); hash = block->previous (); ++pruned_count; ++cache.pruned_count; @@ -1358,7 +1358,7 @@ uint64_t nano::ledger::pruning_action (nano::write_transaction & transaction_a, transaction_a.renew (); } } - else if (store.pruned_exists (transaction_a, hash)) + else if (store.pruned.exists (transaction_a, hash)) { hash = 0; } @@ -1481,12 +1481,12 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data } }); - store.pruned_for_each_par ( + store.pruned.for_each_par ( [&rocksdb_store] (nano::read_transaction const & /*unused*/, auto i, auto n) { for (; i != n; ++i) { auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::pruned })); - rocksdb_store->pruned_put (rocksdb_transaction, i->first); + rocksdb_store->pruned.put (rocksdb_transaction, i->first); } }); @@ -1517,7 +1517,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data // Compare counts error |= store.unchecked_count (lmdb_transaction) != rocksdb_store->unchecked_count (rocksdb_transaction); error |= store.peer_count (lmdb_transaction) != rocksdb_store->peer_count (rocksdb_transaction); - error |= store.pruned_count (lmdb_transaction) != rocksdb_store->pruned_count (rocksdb_transaction); + error |= store.pruned.count (lmdb_transaction) != rocksdb_store->pruned.count (rocksdb_transaction); error |= store.final_vote.count (lmdb_transaction) != rocksdb_store->final_vote.count (rocksdb_transaction); error |= store.online_weight.count (lmdb_transaction) != rocksdb_store->online_weight.count (rocksdb_transaction); error |= store.version_get (lmdb_transaction) != rocksdb_store->version_get (rocksdb_transaction); diff --git a/nano/secure/store/pruned_store_partial.hpp b/nano/secure/store/pruned_store_partial.hpp new file mode 100644 index 0000000000..910a6c756b --- /dev/null +++ b/nano/secure/store/pruned_store_partial.hpp @@ -0,0 +1,97 @@ +#pragma once + +#include + +namespace +{ +template +void parallel_traversal (std::function const & action); +} + +namespace nano +{ +template +class block_store_partial; + +template +void release_assert_success (block_store_partial const & block_store, const int status); + +template +class pruned_store_partial : public pruned_store +{ +private: + nano::block_store_partial & block_store; + + friend void release_assert_success (block_store_partial const & block_store, const int status); + +public: + explicit pruned_store_partial (nano::block_store_partial & block_store_a) : + block_store (block_store_a){}; + + void put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override + { + auto status = block_store.put_key (transaction_a, tables::pruned, hash_a); + release_assert_success (block_store, status); + } + + void del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) override + { + auto status = block_store.del (transaction_a, tables::pruned, hash_a); + release_assert_success (block_store, status); + } + + bool exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override + { + return block_store.exists (transaction_a, tables::pruned, nano::db_val (hash_a)); + } + + nano::block_hash random (nano::transaction const & transaction_a) override + { + nano::block_hash random_hash; + nano::random_pool::generate_block (random_hash.bytes.data (), random_hash.bytes.size ()); + auto existing = block_store.template make_iterator> (transaction_a, tables::pruned, nano::db_val (random_hash)); + auto end (nano::store_iterator> (nullptr)); + if (existing == end) + { + existing = block_store.template make_iterator> (transaction_a, tables::pruned); + } + return existing != end ? existing->first : 0; + } + + size_t count (nano::transaction const & transaction_a) const override + { + return block_store.count (transaction_a, tables::pruned); + } + + void clear (nano::write_transaction const & transaction_a) override + { + auto status = block_store.drop (transaction_a, tables::pruned); + release_assert_success (block_store, status); + } + + nano::store_iterator begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override + { + return block_store.template make_iterator (transaction_a, tables::pruned, nano::db_val (hash_a)); + } + + nano::store_iterator begin (nano::transaction const & transaction_a) const override + { + return block_store.template make_iterator (transaction_a, tables::pruned); + } + + nano::store_iterator end () const override + { + return nano::store_iterator (nullptr); + } + + void for_each_par (std::function, nano::store_iterator)> const & action_a) const override + { + parallel_traversal ( + [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { + auto transaction (this->block_store.tx_begin_read ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + }); + } +}; + +} \ No newline at end of file diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 468d8ca29b..51d91974ae 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -435,7 +435,7 @@ TEST (store, pruned_load) { nano::block_hash random_hash; nano::random_pool::generate_block (random_hash.bytes.data (), random_hash.bytes.size ()); - store->pruned_put (transaction, random_hash); + store->pruned.put (transaction, random_hash); } } if (!nano::using_rocksdb_in_tests ()) @@ -444,20 +444,20 @@ TEST (store, pruned_load) for (auto k (0); k < batch_size / 2; ++k) { auto hash (hashes.begin ()); - store->pruned_del (transaction, *hash); + store->pruned.del (transaction, *hash); hashes.erase (hash); } } } auto transaction (store->tx_begin_read ()); - ASSERT_EQ (expected_result, store->pruned_count (transaction)); + ASSERT_EQ (expected_result, store->pruned.count (transaction)); } // Reinitialize store { auto store = nano::make_store (logger, path); ASSERT_FALSE (store->init_error ()); auto transaction (store->tx_begin_read ()); - ASSERT_EQ (expected_result, store->pruned_count (transaction)); + ASSERT_EQ (expected_result, store->pruned.count (transaction)); } }