From 7a0fc443cb70da979b14ed97f54a71fb6dfc2905 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 13:50:45 +0000 Subject: [PATCH 01/13] Moving make_store files in to store directory. --- nano/core_test/block_store.cpp | 2 +- nano/core_test/bootstrap_ascending.cpp | 2 +- nano/core_test/confirmation_height.cpp | 2 +- nano/core_test/ledger.cpp | 2 +- nano/core_test/node.cpp | 2 +- nano/core_test/processor_service.cpp | 2 +- nano/node/CMakeLists.txt | 2 -- nano/node/node.cpp | 2 +- nano/qt_test/qt.cpp | 2 +- nano/secure/ledger.cpp | 2 +- nano/slow_test/node.cpp | 2 +- nano/store/CMakeLists.txt | 2 ++ nano/{node => store}/make_store.cpp | 2 +- nano/{node => store}/make_store.hpp | 0 nano/test_common/ledger.cpp | 2 +- 15 files changed, 14 insertions(+), 14 deletions(-) rename nano/{node => store}/make_store.cpp (96%) rename nano/{node => store}/make_store.hpp (100%) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index fd9a99e7d2..62e2c87256 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -5,12 +5,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include diff --git a/nano/core_test/bootstrap_ascending.cpp b/nano/core_test/bootstrap_ascending.cpp index fd3850ccee..c1577ac1a9 100644 --- a/nano/core_test/bootstrap_ascending.cpp +++ b/nano/core_test/bootstrap_ascending.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index 7a014447ef..9f9f42fbf3 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index db323513d5..8dbbece096 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -1,10 +1,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 0213b57880..afd86abc9d 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -1,11 +1,11 @@ #include #include -#include #include #include #include #include #include +#include #include #include #include diff --git a/nano/core_test/processor_service.cpp b/nano/core_test/processor_service.cpp index 42893a97d0..ba4c73c4fd 100644 --- a/nano/core_test/processor_service.cpp +++ b/nano/core_test/processor_service.cpp @@ -1,9 +1,9 @@ #include #include -#include #include #include #include +#include #include #include diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 769d6809cd..cf62d26016 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -114,8 +114,6 @@ add_library( ledger_walker.cpp logging.hpp logging.cpp - make_store.hpp - make_store.cpp network.hpp network.cpp nodeconfig.hpp diff --git a/nano/node/node.cpp b/nano/node/node.cpp index bb9d064e0a..39a8a749ef 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #include #include diff --git a/nano/qt_test/qt.cpp b/nano/qt_test/qt.cpp index 8e3dea40b7..47b4bf07d1 100644 --- a/nano/qt_test/qt.cpp +++ b/nano/qt_test/qt.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include #include #include diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index e7c7f1abf9..77e41be2ed 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -11,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 740383a83c..37c537b469 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -2,12 +2,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index 427e038082..d4d82d1b4b 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -27,6 +27,8 @@ add_library( lmdb/transaction_impl.hpp lmdb/version.hpp lmdb/wallet_value.hpp + make_store.hpp + make_store.cpp online_weight.hpp peer.hpp pending.hpp diff --git a/nano/node/make_store.cpp b/nano/store/make_store.cpp similarity index 96% rename from nano/node/make_store.cpp rename to nano/store/make_store.cpp index 7f24c649cf..e9fed5a265 100644 --- a/nano/node/make_store.cpp +++ b/nano/store/make_store.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include std::unique_ptr nano::make_store (nano::logger_mt & logger, std::filesystem::path const & path, nano::ledger_constants & constants, bool read_only, bool add_db_postfix, nano::rocksdb_config const & rocksdb_config, 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) diff --git a/nano/node/make_store.hpp b/nano/store/make_store.hpp similarity index 100% rename from nano/node/make_store.hpp rename to nano/store/make_store.hpp diff --git a/nano/test_common/ledger.cpp b/nano/test_common/ledger.cpp index a3337bc925..8bdc39d50f 100644 --- a/nano/test_common/ledger.cpp +++ b/nano/test_common/ledger.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include nano::test::context::ledger_context::ledger_context (std::deque> && blocks) : From ee427904c319ccf17447429a7288251ff3c2b59a Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 16:55:48 +0000 Subject: [PATCH 02/13] Move nano::write_database_queue in to nano::store --- nano/core_test/confirmation_height.cpp | 34 +++++++++---------- nano/core_test/node.cpp | 4 +-- nano/node/CMakeLists.txt | 2 -- nano/node/blockprocessor.cpp | 4 +-- nano/node/blockprocessor.hpp | 6 ++-- nano/node/confirmation_height_bounded.cpp | 12 +++---- nano/node/confirmation_height_bounded.hpp | 13 ++++--- nano/node/confirmation_height_processor.cpp | 8 ++--- nano/node/confirmation_height_processor.hpp | 4 +-- nano/node/confirmation_height_unbounded.cpp | 10 +++--- nano/node/confirmation_height_unbounded.hpp | 14 +++++--- nano/node/node.cpp | 2 +- nano/node/node.hpp | 4 +-- nano/rpc_test/rpc.cpp | 4 +-- nano/slow_test/node.cpp | 4 +-- nano/store/CMakeLists.txt | 4 ++- nano/{node => store}/write_database_queue.cpp | 24 ++++++------- nano/{node => store}/write_database_queue.hpp | 12 +++---- 18 files changed, 86 insertions(+), 79 deletions(-) rename nano/{node => store}/write_database_queue.cpp (69%) rename nano/{node => store}/write_database_queue.hpp (84%) diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index 9f9f42fbf3..b4e1dec8e3 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -1166,7 +1166,7 @@ TEST (confirmation_heightDeathTest, rollback_added_block) ASSERT_TRUE (!store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - nano::write_database_queue write_database_queue (false); + nano::store::write_database_queue write_database_queue (false); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key1; nano::block_builder builder; @@ -1258,7 +1258,7 @@ TEST (confirmation_heightDeathTest, modified_chain) ASSERT_TRUE (!store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - nano::write_database_queue write_database_queue (false); + nano::store::write_database_queue write_database_queue (false); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key1; nano::block_builder builder; @@ -1283,14 +1283,14 @@ TEST (confirmation_heightDeathTest, modified_chain) { // This reads the blocks in the account, but prevents any writes from occuring yet - auto scoped_write_guard = write_database_queue.wait (nano::writer::testing); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::testing); bounded_processor.process (send); } // Rollback the block and now try to write, the block no longer exists so should bail ledger.rollback (store->tx_begin_write (), send->hash ()); { - auto scoped_write_guard = write_database_queue.wait (nano::writer::confirmation_height); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::confirmation_height); ASSERT_DEATH_IF_SUPPORTED (bounded_processor.cement_blocks (scoped_write_guard), ""); } @@ -1302,14 +1302,14 @@ TEST (confirmation_heightDeathTest, modified_chain) { // This reads the blocks in the account, but prevents any writes from occuring yet - auto scoped_write_guard = write_database_queue.wait (nano::writer::testing); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::testing); unbounded_processor.process (send); } // Rollback the block and now try to write, the block no longer exists so should bail ledger.rollback (store->tx_begin_write (), send->hash ()); { - auto scoped_write_guard = write_database_queue.wait (nano::writer::confirmation_height); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::confirmation_height); ASSERT_DEATH_IF_SUPPORTED (unbounded_processor.cement_blocks (scoped_write_guard), ""); } } @@ -1336,7 +1336,7 @@ TEST (confirmation_heightDeathTest, modified_chain_account_removed) ASSERT_TRUE (!store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - nano::write_database_queue write_database_queue (false); + nano::store::write_database_queue write_database_queue (false); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key1; nano::block_builder builder; @@ -1372,14 +1372,14 @@ TEST (confirmation_heightDeathTest, modified_chain_account_removed) { // This reads the blocks in the account, but prevents any writes from occuring yet - auto scoped_write_guard = write_database_queue.wait (nano::writer::testing); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::testing); unbounded_processor.process (open); } // Rollback the block and now try to write, the send should be cemented but the account which the open block belongs no longer exists so should bail ledger.rollback (store->tx_begin_write (), open->hash ()); { - auto scoped_write_guard = write_database_queue.wait (nano::writer::confirmation_height); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::confirmation_height); ASSERT_DEATH_IF_SUPPORTED (unbounded_processor.cement_blocks (scoped_write_guard), ""); } @@ -1392,13 +1392,13 @@ TEST (confirmation_heightDeathTest, modified_chain_account_removed) { // This reads the blocks in the account, but prevents any writes from occuring yet - auto scoped_write_guard = write_database_queue.wait (nano::writer::testing); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::testing); bounded_processor.process (open); } // Rollback the block and now try to write, the send should be cemented but the account which the open block belongs no longer exists so should bail ledger.rollback (store->tx_begin_write (), open->hash ()); - auto scoped_write_guard = write_database_queue.wait (nano::writer::confirmation_height); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::confirmation_height); ASSERT_DEATH_IF_SUPPORTED (bounded_processor.cement_blocks (scoped_write_guard), ""); } } @@ -1508,7 +1508,7 @@ TEST (confirmation_height, callback_confirmed_history) node->block_processor.flush (); // The write guard prevents the confirmation height processor doing any writes - auto write_guard = node->write_database_queue.wait (nano::writer::testing); + auto write_guard = node->write_database_queue.wait (nano::store::writer::testing); // Confirm send1 auto election = node->active.election (send1->qualified_root ()); @@ -1521,13 +1521,13 @@ TEST (confirmation_height, callback_confirmed_history) auto transaction = node->store.tx_begin_read (); ASSERT_FALSE (node->ledger.block_confirmed (transaction, send->hash ())); - ASSERT_TIMELY (10s, node->write_database_queue.contains (nano::writer::confirmation_height)); + ASSERT_TIMELY (10s, node->write_database_queue.contains (nano::store::writer::confirmation_height)); // Confirm that no inactive callbacks have been called when the confirmation height processor has already iterated over it, waiting to write ASSERT_EQ (0, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); } - ASSERT_TIMELY (10s, !node->write_database_queue.contains (nano::writer::confirmation_height)); + ASSERT_TIMELY (10s, !node->write_database_queue.contains (nano::store::writer::confirmation_height)); auto transaction = node->store.tx_begin_read (); ASSERT_TRUE (node->ledger.block_confirmed (transaction, send->hash ())); @@ -2047,7 +2047,7 @@ TEST (confirmation_height, unbounded_block_cache_iteration) ASSERT_TRUE (!store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - nano::write_database_queue write_database_queue (false); + nano::store::write_database_queue write_database_queue (false); boost::latch initialized_latch{ 0 }; nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::logging logging; @@ -2081,7 +2081,7 @@ TEST (confirmation_height, unbounded_block_cache_iteration) timer.start (); { // Prevent conf height processor doing any writes, so that we can query is_processing_block correctly - auto write_guard = write_database_queue.wait (nano::writer::testing); + auto write_guard = write_database_queue.wait (nano::store::writer::testing); // Add the frontier block confirmation_height_processor.add (send1); @@ -2113,7 +2113,7 @@ TEST (confirmation_height, pruned_source) nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); ledger.pruning = true; - nano::write_database_queue write_database_queue (false); + nano::store::write_database_queue write_database_queue (false); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key1, key2; nano::block_builder builder; diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index afd86abc9d..7092911073 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -3102,7 +3102,7 @@ TEST (node, block_processor_half_full) .work (*node.work_generate_blocking (send2->hash ())) .build_shared (); // The write guard prevents block processor doing any writes - auto write_guard = node.write_database_queue.wait (nano::writer::testing); + auto write_guard = node.write_database_queue.wait (nano::store::writer::testing); node.block_processor.add (send1); ASSERT_FALSE (node.block_processor.half_full ()); node.block_processor.add (send2); @@ -3499,7 +3499,7 @@ TEST (node, rollback_vote_self) { // The write guard prevents the block processor from performing the rollback - auto write_guard = node.write_database_queue.wait (nano::writer::testing); + auto write_guard = node.write_database_queue.wait (nano::store::writer::testing); ASSERT_EQ (0, election->votes_with_weight ().size ()); // Vote with key to switch the winner diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index cf62d26016..0ddd358833 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -192,8 +192,6 @@ add_library( websocketconfig.cpp websocket_stream.hpp websocket_stream.cpp - write_database_queue.hpp - write_database_queue.cpp messages.hpp messages.cpp xorshift.hpp) diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 5fc10808dd..bdafc372c6 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -6,7 +6,7 @@ #include -nano::block_processor::block_processor (nano::node & node_a, nano::write_database_queue & write_database_queue_a) : +nano::block_processor::block_processor (nano::node & node_a, nano::store::write_database_queue & write_database_queue_a) : next_log (std::chrono::steady_clock::now ()), node (node_a), write_database_queue (write_database_queue_a), @@ -262,7 +262,7 @@ void nano::block_processor::add_impl (std::shared_ptr block) auto nano::block_processor::process_batch (nano::unique_lock & lock_a) -> std::deque { std::deque processed; - auto scoped_write_guard = write_database_queue.wait (nano::writer::process_batch); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::process_batch); auto transaction (node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::frontiers, tables::pending })); nano::timer timer_l; lock_a.lock (); diff --git a/nano/node/blockprocessor.hpp b/nano/node/blockprocessor.hpp index 465bc5f6fd..93f3569b8f 100644 --- a/nano/node/blockprocessor.hpp +++ b/nano/node/blockprocessor.hpp @@ -12,13 +12,13 @@ namespace nano::store { +class write_database_queue; class write_transaction; } namespace nano { class node; -class write_database_queue; /** * Processing blocks is a potentially long IO operation. @@ -27,7 +27,7 @@ class write_database_queue; class block_processor final { public: - explicit block_processor (nano::node &, nano::write_database_queue &); + explicit block_processor (nano::node &, nano::store::write_database_queue &); void stop (); void flush (); std::size_t size (); @@ -68,7 +68,7 @@ class block_processor final std::deque> forced; nano::condition_variable condition; nano::node & node; - nano::write_database_queue & write_database_queue; + nano::store::write_database_queue & write_database_queue; nano::mutex mutex{ mutex_identifier (mutexes::block_processor) }; nano::state_block_signature_verification state_block_signature_verification; std::thread processing_thread; diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index a2301f891d..ed2bf51603 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -2,17 +2,17 @@ #include #include #include -#include #include #include #include #include +#include #include #include -nano::confirmation_height_bounded::confirmation_height_bounded (nano::ledger & ledger_a, nano::write_database_queue & write_database_queue_a, std::chrono::milliseconds batch_separate_pending_min_time_a, nano::logging const & logging_a, nano::logger_mt & logger_a, std::atomic & stopped_a, uint64_t & batch_write_size_a, std::function> const &)> const & notify_observers_callback_a, std::function const & notify_block_already_cemented_observers_callback_a, std::function const & awaiting_processing_size_callback_a) : +nano::confirmation_height_bounded::confirmation_height_bounded (nano::ledger & ledger_a, nano::store::write_database_queue & write_database_queue_a, std::chrono::milliseconds batch_separate_pending_min_time_a, nano::logging const & logging_a, nano::logger_mt & logger_a, std::atomic & stopped_a, uint64_t & batch_write_size_a, std::function> const &)> const & notify_observers_callback_a, std::function const & notify_block_already_cemented_observers_callback_a, std::function const & awaiting_processing_size_callback_a) : ledger (ledger_a), write_database_queue (write_database_queue_a), batch_separate_pending_min_time (batch_separate_pending_min_time_a), @@ -204,14 +204,14 @@ void nano::confirmation_height_bounded::process (std::shared_ptr or if ((max_batch_write_size_reached || should_output || force_write) && !pending_writes.empty ()) { // If nothing is currently using the database write lock then write the cemented pending blocks otherwise continue iterating - if (write_database_queue.process (nano::writer::confirmation_height)) + if (write_database_queue.process (nano::store::writer::confirmation_height)) { auto scoped_write_guard = write_database_queue.pop (); cement_blocks (scoped_write_guard); } else if (force_write) { - auto scoped_write_guard = write_database_queue.wait (nano::writer::confirmation_height); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::confirmation_height); cement_blocks (scoped_write_guard); } } @@ -361,7 +361,7 @@ void nano::confirmation_height_bounded::prepare_iterated_blocks_for_cementing (p } } -void nano::confirmation_height_bounded::cement_blocks (nano::write_guard & scoped_write_guard_a) +void nano::confirmation_height_bounded::cement_blocks (nano::store::write_guard & scoped_write_guard_a) { // Will contain all blocks that have been cemented (bounded by batch_write_size) // and will get run through the cemented observer callback @@ -479,7 +479,7 @@ void nano::confirmation_height_bounded::cement_blocks (nano::write_guard & scope // Only aquire transaction if there are blocks left if (!(last_iteration && pending_writes.size () == 1)) { - scoped_write_guard_a = write_database_queue.wait (nano::writer::confirmation_height); + scoped_write_guard_a = write_database_queue.wait (nano::store::writer::confirmation_height); transaction.renew (); } cemented_batch_timer.restart (); diff --git a/nano/node/confirmation_height_bounded.hpp b/nano/node/confirmation_height_bounded.hpp index c176b41686..362c71e33e 100644 --- a/nano/node/confirmation_height_bounded.hpp +++ b/nano/node/confirmation_height_bounded.hpp @@ -8,22 +8,25 @@ #include +namespace nano::store +{ +class write_database_queue; +class write_guard; +} namespace nano { class ledger; class logging; class logger_mt; -class write_database_queue; -class write_guard; class confirmation_height_bounded final { public: - confirmation_height_bounded (nano::ledger &, nano::write_database_queue &, std::chrono::milliseconds batch_separate_pending_min_time, nano::logging const &, nano::logger_mt &, std::atomic & stopped, uint64_t & batch_write_size, std::function> const &)> const & cemented_callback, std::function const & already_cemented_callback, std::function const & awaiting_processing_size_query); + confirmation_height_bounded (nano::ledger &, nano::store::write_database_queue &, std::chrono::milliseconds batch_separate_pending_min_time, nano::logging const &, nano::logger_mt &, std::atomic & stopped, uint64_t & batch_write_size, std::function> const &)> const & cemented_callback, std::function const & already_cemented_callback, std::function const & awaiting_processing_size_query); bool pending_empty () const; void clear_process_vars (); void process (std::shared_ptr original_block); - void cement_blocks (nano::write_guard & scoped_write_guard_a); + void cement_blocks (nano::store::write_guard & scoped_write_guard_a); private: class top_and_next_hash final @@ -119,7 +122,7 @@ class confirmation_height_bounded final bool iterate (store::read_transaction const &, uint64_t, nano::block_hash const &, boost::circular_buffer_space_optimized &, nano::block_hash &, nano::block_hash const &, boost::circular_buffer_space_optimized &, nano::account const &); nano::ledger & ledger; - nano::write_database_queue & write_database_queue; + nano::store::write_database_queue & write_database_queue; std::chrono::milliseconds batch_separate_pending_min_time; nano::logging const & logging; nano::logger_mt & logger; diff --git a/nano/node/confirmation_height_processor.cpp b/nano/node/confirmation_height_processor.cpp index 6cf9772999..5243a9bb70 100644 --- a/nano/node/confirmation_height_processor.cpp +++ b/nano/node/confirmation_height_processor.cpp @@ -3,13 +3,13 @@ #include #include #include -#include #include #include +#include #include -nano::confirmation_height_processor::confirmation_height_processor (nano::ledger & ledger_a, nano::write_database_queue & write_database_queue_a, std::chrono::milliseconds batch_separate_pending_min_time_a, nano::logging const & logging_a, nano::logger_mt & logger_a, boost::latch & latch, confirmation_height_mode mode_a) : +nano::confirmation_height_processor::confirmation_height_processor (nano::ledger & ledger_a, nano::store::write_database_queue & write_database_queue_a, std::chrono::milliseconds batch_separate_pending_min_time_a, nano::logging const & logging_a, nano::logger_mt & logger_a, boost::latch & latch, confirmation_height_mode mode_a) : ledger (ledger_a), write_database_queue (write_database_queue_a), unbounded_processor ( @@ -105,7 +105,7 @@ void nano::confirmation_height_processor::run (confirmation_height_mode mode_a) { debug_assert (unbounded_processor.pending_empty ()); { - auto scoped_write_guard = write_database_queue.wait (nano::writer::confirmation_height); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::confirmation_height); bounded_processor.cement_blocks (scoped_write_guard); } lock_and_cleanup (); @@ -114,7 +114,7 @@ void nano::confirmation_height_processor::run (confirmation_height_mode mode_a) { debug_assert (bounded_processor.pending_empty ()); { - auto scoped_write_guard = write_database_queue.wait (nano::writer::confirmation_height); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::confirmation_height); unbounded_processor.cement_blocks (scoped_write_guard); } lock_and_cleanup (); diff --git a/nano/node/confirmation_height_processor.hpp b/nano/node/confirmation_height_processor.hpp index 88f2d1a15b..45a9dec4c1 100644 --- a/nano/node/confirmation_height_processor.hpp +++ b/nano/node/confirmation_height_processor.hpp @@ -30,7 +30,7 @@ class write_database_queue; class confirmation_height_processor final { public: - confirmation_height_processor (nano::ledger &, nano::write_database_queue &, std::chrono::milliseconds, nano::logging const &, nano::logger_mt &, boost::latch & initialized_latch, confirmation_height_mode = confirmation_height_mode::automatic); + confirmation_height_processor (nano::ledger &, nano::store::write_database_queue &, std::chrono::milliseconds, nano::logging const &, nano::logger_mt &, boost::latch & initialized_latch, confirmation_height_mode = confirmation_height_mode::automatic); ~confirmation_height_processor (); void pause (); void unpause (); @@ -95,7 +95,7 @@ class confirmation_height_processor final std::vector> block_already_cemented_observers; nano::ledger & ledger; - nano::write_database_queue & write_database_queue; + nano::store::write_database_queue & write_database_queue; /** The maximum amount of blocks to write at once. This is dynamically modified by the bounded processor based on previous write performance **/ uint64_t batch_write_size{ 16384 }; diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index 9a458b9c8c..b3f587e622 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -2,17 +2,17 @@ #include #include #include -#include #include #include #include #include +#include #include #include -nano::confirmation_height_unbounded::confirmation_height_unbounded (nano::ledger & ledger_a, nano::write_database_queue & write_database_queue_a, std::chrono::milliseconds batch_separate_pending_min_time_a, nano::logging const & logging_a, nano::logger_mt & logger_a, std::atomic & stopped_a, uint64_t & batch_write_size_a, std::function> const &)> const & notify_observers_callback_a, std::function const & notify_block_already_cemented_observers_callback_a, std::function const & awaiting_processing_size_callback_a) : +nano::confirmation_height_unbounded::confirmation_height_unbounded (nano::ledger & ledger_a, nano::store::write_database_queue & write_database_queue_a, std::chrono::milliseconds batch_separate_pending_min_time_a, nano::logging const & logging_a, nano::logger_mt & logger_a, std::atomic & stopped_a, uint64_t & batch_write_size_a, std::function> const &)> const & notify_observers_callback_a, std::function const & notify_block_already_cemented_observers_callback_a, std::function const & awaiting_processing_size_callback_a) : ledger (ledger_a), write_database_queue (write_database_queue_a), batch_separate_pending_min_time (batch_separate_pending_min_time_a), @@ -175,7 +175,7 @@ void nano::confirmation_height_unbounded::process (std::shared_ptr if ((max_write_size_reached || should_output || force_write) && !pending_writes.empty ()) { - if (write_database_queue.process (nano::writer::confirmation_height)) + if (write_database_queue.process (nano::store::writer::confirmation_height)) { auto scoped_write_guard = write_database_queue.pop (); cement_blocks (scoped_write_guard); @@ -183,7 +183,7 @@ void nano::confirmation_height_unbounded::process (std::shared_ptr else if (force_write) { // Unbounded processor has grown too large, force a write - auto scoped_write_guard = write_database_queue.wait (nano::writer::confirmation_height); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::confirmation_height); cement_blocks (scoped_write_guard); } } @@ -365,7 +365,7 @@ void nano::confirmation_height_unbounded::prepare_iterated_blocks_for_cementing } } -void nano::confirmation_height_unbounded::cement_blocks (nano::write_guard & scoped_write_guard_a) +void nano::confirmation_height_unbounded::cement_blocks (nano::store::write_guard & scoped_write_guard_a) { nano::timer cemented_batch_timer; std::vector> cemented_blocks; diff --git a/nano/node/confirmation_height_unbounded.hpp b/nano/node/confirmation_height_unbounded.hpp index 0af353e69a..b3c63dcf5d 100644 --- a/nano/node/confirmation_height_unbounded.hpp +++ b/nano/node/confirmation_height_unbounded.hpp @@ -9,22 +9,26 @@ #include #include +namespace nano::store +{ +class write_database_queue; +class write_guard; +} + namespace nano { class ledger; class logging; class logger_mt; -class write_database_queue; -class write_guard; class confirmation_height_unbounded final { public: - confirmation_height_unbounded (nano::ledger &, nano::write_database_queue &, std::chrono::milliseconds batch_separate_pending_min_time, nano::logging const &, nano::logger_mt &, std::atomic & stopped, uint64_t & batch_write_size, std::function> const &)> const & cemented_callback, std::function const & already_cemented_callback, std::function const & awaiting_processing_size_query); + confirmation_height_unbounded (nano::ledger &, nano::store::write_database_queue &, std::chrono::milliseconds batch_separate_pending_min_time, nano::logging const &, nano::logger_mt &, std::atomic & stopped, uint64_t & batch_write_size, std::function> const &)> const & cemented_callback, std::function const & already_cemented_callback, std::function const & awaiting_processing_size_query); bool pending_empty () const; void clear_process_vars (); void process (std::shared_ptr original_block); - void cement_blocks (nano::write_guard &); + void cement_blocks (nano::store::write_guard &); bool has_iterated_over_block (nano::block_hash const &) const; private: @@ -96,7 +100,7 @@ class confirmation_height_unbounded final void prepare_iterated_blocks_for_cementing (preparation_data &); nano::ledger & ledger; - nano::write_database_queue & write_database_queue; + nano::store::write_database_queue & write_database_queue; std::chrono::milliseconds batch_separate_pending_min_time; nano::logger_mt & logger; std::atomic & stopped; diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 39a8a749ef..71c887351c 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1077,7 +1077,7 @@ void nano::node::ledger_pruning (uint64_t const batch_size_a, bool bootstrap_wei transaction_write_count = 0; if (!pruning_targets.empty () && !stopped) { - auto scoped_write_guard = write_database_queue.wait (nano::writer::pruning); + auto scoped_write_guard = write_database_queue.wait (nano::store::writer::pruning); auto write_transaction (store.tx_begin_write ({ tables::blocks, tables::pruned })); while (!pruning_targets.empty () && transaction_write_count < batch_size_a && !stopped) { diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 8f54915d5d..80af14069a 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -37,9 +37,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -140,7 +140,7 @@ class node final : public std::enable_shared_from_this nano::telemetry_data local_telemetry () const; public: - nano::write_database_queue write_database_queue; + nano::store::write_database_queue write_database_queue; boost::asio::io_context & io_ctx; boost::latch node_initialized_latch; nano::node_config config; diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 5416292cb0..35f17afcbf 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -5238,7 +5238,7 @@ TEST (rpc, confirmation_height_currently_processing) // Begin process for confirming the block (and setting confirmation height) { // Write guard prevents the confirmation height processor writing the blocks, so that we can inspect contents during the response - auto write_guard = node->write_database_queue.wait (nano::writer::testing); + auto write_guard = node->write_database_queue.wait (nano::store::writer::testing); nano::test::start_election (system, *node, frontier->hash ()); ASSERT_TIMELY (5s, node->confirmation_height_processor.current () == frontier->hash ()); @@ -6934,4 +6934,4 @@ TEST (rpc, confirmation_info) ASSERT_EQ (1, representatives.size ()); ASSERT_EQ (0, response.get ("total_tally")); } -} \ No newline at end of file +} diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 37c537b469..6f3d98c616 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -1043,7 +1043,7 @@ TEST (confirmation_height, dynamic_algorithm_no_transition_while_pending) } { - auto write_guard = node->write_database_queue.wait (nano::writer::testing); + auto write_guard = node->write_database_queue.wait (nano::store::writer::testing); // To limit any data races we are not calling node.block_confirm node->confirmation_height_processor.add (state_blocks.back ()); @@ -1231,7 +1231,7 @@ TEST (confirmation_height, many_accounts_send_receive_self_no_elections) ASSERT_TRUE (!store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - nano::write_database_queue write_database_queue (false); + nano::store::write_database_queue write_database_queue (false); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; std::atomic stopped{ false }; boost::latch initialized_latch{ 0 }; diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index d4d82d1b4b..01ddfe5721 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -95,7 +95,9 @@ add_library( rocksdb/version.cpp transaction.cpp version.cpp - versioning.cpp) + versioning.cpp + write_database_queue.hpp + write_database_queue.cpp) target_link_libraries( nano_store diff --git a/nano/node/write_database_queue.cpp b/nano/store/write_database_queue.cpp similarity index 69% rename from nano/node/write_database_queue.cpp rename to nano/store/write_database_queue.cpp index 8bb42fe322..8953a2391e 100644 --- a/nano/node/write_database_queue.cpp +++ b/nano/store/write_database_queue.cpp @@ -1,15 +1,15 @@ #include #include -#include +#include #include -nano::write_guard::write_guard (std::function guard_finish_callback_a) : +nano::store::write_guard::write_guard (std::function guard_finish_callback_a) : guard_finish_callback (guard_finish_callback_a) { } -nano::write_guard::write_guard (nano::write_guard && write_guard_a) noexcept : +nano::store::write_guard::write_guard (nano::store::write_guard && write_guard_a) noexcept : guard_finish_callback (std::move (write_guard_a.guard_finish_callback)), owns (write_guard_a.owns) { @@ -17,7 +17,7 @@ nano::write_guard::write_guard (nano::write_guard && write_guard_a) noexcept : write_guard_a.guard_finish_callback = nullptr; } -nano::write_guard & nano::write_guard::operator= (nano::write_guard && write_guard_a) noexcept +nano::store::write_guard & nano::store::write_guard::operator= (nano::store::write_guard && write_guard_a) noexcept { owns = write_guard_a.owns; guard_finish_callback = std::move (write_guard_a.guard_finish_callback); @@ -27,7 +27,7 @@ nano::write_guard & nano::write_guard::operator= (nano::write_guard && write_gua return *this; } -nano::write_guard::~write_guard () +nano::store::write_guard::~write_guard () { if (owns) { @@ -35,12 +35,12 @@ nano::write_guard::~write_guard () } } -bool nano::write_guard::is_owned () const +bool nano::store::write_guard::is_owned () const { return owns; } -void nano::write_guard::release () +void nano::store::write_guard::release () { debug_assert (owns); if (owns) @@ -50,7 +50,7 @@ void nano::write_guard::release () owns = false; } -nano::write_database_queue::write_database_queue (bool use_noops_a) : +nano::store::write_database_queue::write_database_queue (bool use_noops_a) : guard_finish_callback ([use_noops_a, &queue = queue, &mutex = mutex, &cv = cv] () { if (!use_noops_a) { @@ -65,7 +65,7 @@ nano::write_database_queue::write_database_queue (bool use_noops_a) : { } -nano::write_guard nano::write_database_queue::wait (nano::writer writer) +nano::store::write_guard nano::store::write_database_queue::wait (nano::store::writer writer) { if (use_noops) { @@ -88,14 +88,14 @@ nano::write_guard nano::write_database_queue::wait (nano::writer writer) return write_guard (guard_finish_callback); } -bool nano::write_database_queue::contains (nano::writer writer) +bool nano::store::write_database_queue::contains (nano::store::writer writer) { debug_assert (!use_noops); nano::lock_guard guard (mutex); return std::find (queue.cbegin (), queue.cend (), writer) != queue.cend (); } -bool nano::write_database_queue::process (nano::writer writer) +bool nano::store::write_database_queue::process (nano::store::writer writer) { if (use_noops) { @@ -123,7 +123,7 @@ bool nano::write_database_queue::process (nano::writer writer) return result; } -nano::write_guard nano::write_database_queue::pop () +nano::store::write_guard nano::store::write_database_queue::pop () { return write_guard (guard_finish_callback); } diff --git a/nano/node/write_database_queue.hpp b/nano/store/write_database_queue.hpp similarity index 84% rename from nano/node/write_database_queue.hpp rename to nano/store/write_database_queue.hpp index 4443eca6cc..e0d55a9c73 100644 --- a/nano/node/write_database_queue.hpp +++ b/nano/store/write_database_queue.hpp @@ -6,7 +6,7 @@ #include #include -namespace nano +namespace nano::store { /** Distinct areas write locking is done, order is irrelevant */ enum class writer @@ -39,22 +39,22 @@ class write_database_queue final public: write_database_queue (bool use_noops_a); /** Blocks until we are at the head of the queue */ - write_guard wait (nano::writer writer); + write_guard wait (nano::store::writer writer); /** Returns true if this writer is now at the front of the queue */ - bool process (nano::writer writer); + bool process (nano::store::writer writer); /** Returns true if this writer is anywhere in the queue. Currently only used in tests */ - bool contains (nano::writer writer); + bool contains (nano::store::writer writer); /** Doesn't actually pop anything until the returned write_guard is out of scope */ write_guard pop (); private: - std::deque queue; + std::deque queue; nano::mutex mutex; nano::condition_variable cv; std::function guard_finish_callback; bool use_noops; }; -} +} // namespace nano::store From 93183abea7fe65d41ae429d021eae1862e56c36a Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 13:58:39 +0000 Subject: [PATCH 03/13] Renaming lmdb.hpp and rocksdb.hpp files to component.hpp to match their namespace/class. --- nano/core_test/block_store.cpp | 4 ++-- nano/core_test/ledger.cpp | 2 +- nano/node/node.cpp | 2 +- nano/node/wallet.hpp | 2 +- nano/store/CMakeLists.txt | 8 ++++---- nano/store/lmdb/account.cpp | 2 +- nano/store/lmdb/block.cpp | 2 +- nano/store/lmdb/{lmdb.cpp => component.cpp} | 2 +- nano/store/lmdb/{lmdb.hpp => component.hpp} | 0 nano/store/lmdb/confirmation_height.cpp | 2 +- nano/store/lmdb/final_vote.cpp | 2 +- nano/store/lmdb/frontier.cpp | 2 +- nano/store/lmdb/online_weight.cpp | 2 +- nano/store/lmdb/peer.cpp | 2 +- nano/store/lmdb/pending.cpp | 2 +- nano/store/lmdb/pruned.cpp | 2 +- nano/store/lmdb/version.cpp | 2 +- nano/store/make_store.cpp | 4 ++-- nano/store/rocksdb/account.cpp | 2 +- nano/store/rocksdb/block.cpp | 2 +- nano/store/rocksdb/{rocksdb.cpp => component.cpp} | 2 +- nano/store/rocksdb/{rocksdb.hpp => component.hpp} | 0 nano/store/rocksdb/confirmation_height.cpp | 2 +- nano/store/rocksdb/final_vote.cpp | 2 +- nano/store/rocksdb/frontier.cpp | 2 +- nano/store/rocksdb/online_weight.cpp | 2 +- nano/store/rocksdb/peer.cpp | 2 +- nano/store/rocksdb/pending.cpp | 2 +- nano/store/rocksdb/pruned.cpp | 2 +- nano/store/rocksdb/version.cpp | 2 +- 30 files changed, 33 insertions(+), 33 deletions(-) rename nano/store/lmdb/{lmdb.cpp => component.cpp} (99%) rename nano/store/lmdb/{lmdb.hpp => component.hpp} (100%) rename nano/store/rocksdb/{rocksdb.cpp => component.cpp} (99%) rename nano/store/rocksdb/{rocksdb.hpp => component.hpp} (100%) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 62e2c87256..8584b3bdfa 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -9,9 +9,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include #include diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 8dbbece096..a3f25bb22d 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 71c887351c..346e9b50d5 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index 40409f5e35..4a75b2aed4 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index 01ddfe5721..916a28e64a 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -11,12 +11,12 @@ add_library( frontier.hpp lmdb/account.hpp lmdb/block.hpp + lmdb/component.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 lmdb/iterator.hpp lmdb/transaction_impl.hpp @@ -35,6 +35,7 @@ add_library( pruned.hpp rocksdb/account.hpp rocksdb/block.hpp + rocksdb/component.hpp rocksdb/confirmation_height.hpp rocksdb/db_val.hpp rocksdb/final_vote.hpp @@ -44,7 +45,6 @@ add_library( rocksdb/peer.hpp rocksdb/pending.hpp rocksdb/pruned.hpp - rocksdb/rocksdb.hpp rocksdb/iterator.hpp rocksdb/transaction_impl.hpp rocksdb/version.hpp @@ -63,11 +63,11 @@ add_library( frontier.cpp lmdb/account.cpp lmdb/block.cpp + lmdb/component.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 lmdb/online_weight.cpp @@ -82,6 +82,7 @@ add_library( pruned.cpp rocksdb/account.cpp rocksdb/block.cpp + rocksdb/component.cpp rocksdb/confirmation_height.cpp rocksdb/db_val.cpp rocksdb/final_vote.cpp @@ -90,7 +91,6 @@ add_library( rocksdb/peer.cpp rocksdb/pending.cpp rocksdb/pruned.cpp - rocksdb/rocksdb.cpp rocksdb/transaction.cpp rocksdb/version.cpp transaction.cpp diff --git a/nano/store/lmdb/account.cpp b/nano/store/lmdb/account.cpp index 19a35c8e44..5591639419 100644 --- a/nano/store/lmdb/account.cpp +++ b/nano/store/lmdb/account.cpp @@ -1,7 +1,7 @@ #include #include +#include #include -#include nano::store::lmdb::account::account (nano::store::lmdb::component & store_a) : store (store_a){}; diff --git a/nano/store/lmdb/block.cpp b/nano/store/lmdb/block.cpp index e01d71fb21..cbd5ea4ebb 100644 --- a/nano/store/lmdb/block.cpp +++ b/nano/store/lmdb/block.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace nano::store::lmdb { diff --git a/nano/store/lmdb/lmdb.cpp b/nano/store/lmdb/component.cpp similarity index 99% rename from nano/store/lmdb/lmdb.cpp rename to nano/store/lmdb/component.cpp index 8834c38d01..3eeb953521 100644 --- a/nano/store/lmdb/lmdb.cpp +++ b/nano/store/lmdb/component.cpp @@ -1,8 +1,8 @@ #include #include #include +#include #include -#include #include #include #include diff --git a/nano/store/lmdb/lmdb.hpp b/nano/store/lmdb/component.hpp similarity index 100% rename from nano/store/lmdb/lmdb.hpp rename to nano/store/lmdb/component.hpp diff --git a/nano/store/lmdb/confirmation_height.cpp b/nano/store/lmdb/confirmation_height.cpp index 1ce01edab4..1e8147dc6b 100644 --- a/nano/store/lmdb/confirmation_height.cpp +++ b/nano/store/lmdb/confirmation_height.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include nano::store::lmdb::confirmation_height::confirmation_height (nano::store::lmdb::component & store) : store{ store } diff --git a/nano/store/lmdb/final_vote.cpp b/nano/store/lmdb/final_vote.cpp index 2ae93bd5a9..1e5c4513e9 100644 --- a/nano/store/lmdb/final_vote.cpp +++ b/nano/store/lmdb/final_vote.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include nano::store::lmdb::final_vote::final_vote (nano::store::lmdb::component & store) : store{ store } {}; diff --git a/nano/store/lmdb/frontier.cpp b/nano/store/lmdb/frontier.cpp index 8b694a3ef4..78be3d840a 100644 --- a/nano/store/lmdb/frontier.cpp +++ b/nano/store/lmdb/frontier.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include nano::store::lmdb::frontier::frontier (nano::store::lmdb::component & store) : store{ store } diff --git a/nano/store/lmdb/online_weight.cpp b/nano/store/lmdb/online_weight.cpp index 647aaf34da..7401063a3f 100644 --- a/nano/store/lmdb/online_weight.cpp +++ b/nano/store/lmdb/online_weight.cpp @@ -1,4 +1,4 @@ -#include +#include #include nano::store::lmdb::online_weight::online_weight (nano::store::lmdb::component & store_a) : diff --git a/nano/store/lmdb/peer.cpp b/nano/store/lmdb/peer.cpp index cb3de165c5..c3f9fb688a 100644 --- a/nano/store/lmdb/peer.cpp +++ b/nano/store/lmdb/peer.cpp @@ -1,4 +1,4 @@ -#include +#include #include nano::store::lmdb::peer::peer (nano::store::lmdb::component & store) : diff --git a/nano/store/lmdb/pending.cpp b/nano/store/lmdb/pending.cpp index 961b201829..48a178db7a 100644 --- a/nano/store/lmdb/pending.cpp +++ b/nano/store/lmdb/pending.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include nano::store::lmdb::pending::pending (nano::store::lmdb::component & store) : diff --git a/nano/store/lmdb/pruned.cpp b/nano/store/lmdb/pruned.cpp index 2be19c24f5..aebcf60b41 100644 --- a/nano/store/lmdb/pruned.cpp +++ b/nano/store/lmdb/pruned.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include nano::store::lmdb::pruned::pruned (nano::store::lmdb::component & store_a) : diff --git a/nano/store/lmdb/version.cpp b/nano/store/lmdb/version.cpp index f667dc4b9c..a871cb2568 100644 --- a/nano/store/lmdb/version.cpp +++ b/nano/store/lmdb/version.cpp @@ -1,4 +1,4 @@ -#include +#include #include nano::store::lmdb::version::version (nano::store::lmdb::component & store_a) : diff --git a/nano/store/make_store.cpp b/nano/store/make_store.cpp index e9fed5a265..13a7e60ce5 100644 --- a/nano/store/make_store.cpp +++ b/nano/store/make_store.cpp @@ -1,6 +1,6 @@ -#include +#include #include -#include +#include std::unique_ptr nano::make_store (nano::logger_mt & logger, std::filesystem::path const & path, nano::ledger_constants & constants, bool read_only, bool add_db_postfix, nano::rocksdb_config const & rocksdb_config, 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) { diff --git a/nano/store/rocksdb/account.cpp b/nano/store/rocksdb/account.cpp index 8ee01b98fe..4d1edb30c5 100644 --- a/nano/store/rocksdb/account.cpp +++ b/nano/store/rocksdb/account.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include nano::store::rocksdb::account::account (nano::store::rocksdb::component & store_a) : store (store_a){}; diff --git a/nano/store/rocksdb/block.cpp b/nano/store/rocksdb/block.cpp index fbf1ecf1f0..20b14f43f8 100644 --- a/nano/store/rocksdb/block.cpp +++ b/nano/store/rocksdb/block.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace nano { diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/component.cpp similarity index 99% rename from nano/store/rocksdb/rocksdb.cpp rename to nano/store/rocksdb/component.cpp index 054fec0a82..d72b042705 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/component.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include #include #include diff --git a/nano/store/rocksdb/rocksdb.hpp b/nano/store/rocksdb/component.hpp similarity index 100% rename from nano/store/rocksdb/rocksdb.hpp rename to nano/store/rocksdb/component.hpp diff --git a/nano/store/rocksdb/confirmation_height.cpp b/nano/store/rocksdb/confirmation_height.cpp index 380cd80e32..8c5044aab5 100644 --- a/nano/store/rocksdb/confirmation_height.cpp +++ b/nano/store/rocksdb/confirmation_height.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include nano::store::rocksdb::confirmation_height::confirmation_height (nano::store::rocksdb::component & store) : store{ store } diff --git a/nano/store/rocksdb/final_vote.cpp b/nano/store/rocksdb/final_vote.cpp index 121da33360..d440d2345f 100644 --- a/nano/store/rocksdb/final_vote.cpp +++ b/nano/store/rocksdb/final_vote.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include nano::store::rocksdb::final_vote::final_vote (nano::store::rocksdb::component & store) : store{ store } {}; diff --git a/nano/store/rocksdb/frontier.cpp b/nano/store/rocksdb/frontier.cpp index 6724b93363..d3745c7ac8 100644 --- a/nano/store/rocksdb/frontier.cpp +++ b/nano/store/rocksdb/frontier.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include nano::store::rocksdb::frontier::frontier (nano::store::rocksdb::component & store) : store{ store } diff --git a/nano/store/rocksdb/online_weight.cpp b/nano/store/rocksdb/online_weight.cpp index c6f7e1dacf..2029903b7b 100644 --- a/nano/store/rocksdb/online_weight.cpp +++ b/nano/store/rocksdb/online_weight.cpp @@ -1,5 +1,5 @@ +#include #include -#include nano::store::rocksdb::online_weight::online_weight (nano::store::rocksdb::component & store_a) : store{ store_a } diff --git a/nano/store/rocksdb/peer.cpp b/nano/store/rocksdb/peer.cpp index e837521605..53aafab5c1 100644 --- a/nano/store/rocksdb/peer.cpp +++ b/nano/store/rocksdb/peer.cpp @@ -1,5 +1,5 @@ +#include #include -#include nano::store::rocksdb::peer::peer (nano::store::rocksdb::component & store) : store{ store } {}; diff --git a/nano/store/rocksdb/pending.cpp b/nano/store/rocksdb/pending.cpp index f7e843f184..dcb38711c4 100644 --- a/nano/store/rocksdb/pending.cpp +++ b/nano/store/rocksdb/pending.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include nano::store::rocksdb::pending::pending (nano::store::rocksdb::component & store) : store{ store } {}; diff --git a/nano/store/rocksdb/pruned.cpp b/nano/store/rocksdb/pruned.cpp index 41d7fbb586..1414024ed1 100644 --- a/nano/store/rocksdb/pruned.cpp +++ b/nano/store/rocksdb/pruned.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include nano::store::rocksdb::pruned::pruned (nano::store::rocksdb::component & store_a) : store{ store_a } {}; diff --git a/nano/store/rocksdb/version.cpp b/nano/store/rocksdb/version.cpp index c1df2e0232..1f5a6a20e9 100644 --- a/nano/store/rocksdb/version.cpp +++ b/nano/store/rocksdb/version.cpp @@ -1,4 +1,4 @@ -#include +#include #include nano::store::rocksdb::version::version (nano::store::rocksdb::component & store_a) : From 08ec880a94fcbda9a4cc3a2f852755e1c894cecc Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 14:11:03 +0000 Subject: [PATCH 04/13] Moving voting related files in to their own subdirectory --- nano/core_test/request_aggregator.cpp | 2 +- nano/core_test/vote_cache.cpp | 4 ++-- nano/core_test/vote_processor.cpp | 2 +- nano/core_test/voting.cpp | 2 +- nano/node/CMakeLists.txt | 16 ++++++++-------- nano/node/active_transactions.hpp | 2 +- nano/node/node.hpp | 6 +++--- nano/node/nodeconfig.hpp | 2 +- nano/node/process_live_dispatcher.cpp | 2 +- nano/node/{vote_cache.cpp => voting/cache.cpp} | 4 ++-- nano/node/{vote_cache.hpp => voting/cache.hpp} | 0 .../{vote_processor.cpp => voting/processor.cpp} | 2 +- .../{vote_processor.hpp => voting/processor.hpp} | 0 nano/node/{ => voting}/request_aggregator.cpp | 4 ++-- nano/node/{ => voting}/request_aggregator.hpp | 0 nano/node/{ => voting}/voting.cpp | 4 ++-- nano/node/{ => voting}/voting.hpp | 0 nano/slow_test/vote_processor.cpp | 2 +- 18 files changed, 27 insertions(+), 27 deletions(-) rename nano/node/{vote_cache.cpp => voting/cache.cpp} (99%) rename nano/node/{vote_cache.hpp => voting/cache.hpp} (100%) rename nano/node/{vote_processor.cpp => voting/processor.cpp} (99%) rename nano/node/{vote_processor.hpp => voting/processor.hpp} (100%) rename nano/node/{ => voting}/request_aggregator.cpp (99%) rename nano/node/{ => voting}/request_aggregator.hpp (100%) rename nano/node/{ => voting}/voting.cpp (99%) rename nano/node/{ => voting}/voting.hpp (100%) diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index 344b6316b5..6041c87db0 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include #include #include #include diff --git a/nano/core_test/vote_cache.cpp b/nano/core_test/vote_cache.cpp index f94dda0679..e1daac7db4 100644 --- a/nano/core_test/vote_cache.cpp +++ b/nano/core_test/vote_cache.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -336,4 +336,4 @@ TEST (vote_cache, overfill_entry) vote_cache.vote (vote1->hashes.front (), vote1); } ASSERT_EQ (1, vote_cache.size ()); -} \ No newline at end of file +} diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index a444719b01..01b8aa9346 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index 4bc7e2a4df..67e64abec2 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 0ddd358833..d09975e252 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -138,8 +138,6 @@ add_library( process_live_dispatcher.hpp repcrawler.hpp repcrawler.cpp - request_aggregator.hpp - request_aggregator.cpp scheduler/bucket.cpp scheduler/bucket.hpp scheduler/buckets.cpp @@ -178,12 +176,14 @@ add_library( transport/transport.cpp unchecked_map.cpp unchecked_map.hpp - vote_cache.hpp - vote_cache.cpp - vote_processor.hpp - vote_processor.cpp - voting.hpp - voting.cpp + voting/cache.hpp + voting/cache.cpp + voting/processor.hpp + voting/processor.cpp + voting/request_aggregator.hpp + voting/request_aggregator.cpp + voting/voting.hpp + voting/voting.cpp wallet.hpp wallet.cpp websocket.hpp diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 36acd179e5..36e6d41497 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 80af14069a..50a61a0974 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -28,13 +28,13 @@ #include #include #include -#include #include #include #include #include -#include -#include +#include +#include +#include #include #include #include diff --git a/nano/node/nodeconfig.hpp b/nano/node/nodeconfig.hpp index 0cc4116270..f469cf4525 100644 --- a/nano/node/nodeconfig.hpp +++ b/nano/node/nodeconfig.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/node/process_live_dispatcher.cpp b/nano/node/process_live_dispatcher.cpp index c7a6d16dbf..c3fcc991f3 100644 --- a/nano/node/process_live_dispatcher.cpp +++ b/nano/node/process_live_dispatcher.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/node/vote_cache.cpp b/nano/node/voting/cache.cpp similarity index 99% rename from nano/node/vote_cache.cpp rename to nano/node/voting/cache.cpp index 4b3622ad44..96fe54db1c 100644 --- a/nano/node/vote_cache.cpp +++ b/nano/node/voting/cache.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include /* * entry @@ -225,4 +225,4 @@ nano::error nano::vote_cache_config::deserialize (nano::tomlconfig & toml) toml.get ("max_voters", max_voters); return toml.get_error (); -} \ No newline at end of file +} diff --git a/nano/node/vote_cache.hpp b/nano/node/voting/cache.hpp similarity index 100% rename from nano/node/vote_cache.hpp rename to nano/node/voting/cache.hpp diff --git a/nano/node/vote_processor.cpp b/nano/node/voting/processor.cpp similarity index 99% rename from nano/node/vote_processor.cpp rename to nano/node/voting/processor.cpp index fd6d5696cb..7836c38c7a 100644 --- a/nano/node/vote_processor.cpp +++ b/nano/node/voting/processor.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/node/vote_processor.hpp b/nano/node/voting/processor.hpp similarity index 100% rename from nano/node/vote_processor.hpp rename to nano/node/voting/processor.hpp diff --git a/nano/node/request_aggregator.cpp b/nano/node/voting/request_aggregator.cpp similarity index 99% rename from nano/node/request_aggregator.cpp rename to nano/node/voting/request_aggregator.cpp index cb84ba6045..ce2e39b69f 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/voting/request_aggregator.cpp @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/nano/node/request_aggregator.hpp b/nano/node/voting/request_aggregator.hpp similarity index 100% rename from nano/node/request_aggregator.hpp rename to nano/node/voting/request_aggregator.hpp diff --git a/nano/node/voting.cpp b/nano/node/voting/voting.cpp similarity index 99% rename from nano/node/voting.cpp rename to nano/node/voting/voting.cpp index b8f1dba707..4f64c0e92d 100644 --- a/nano/node/voting.cpp +++ b/nano/node/voting/voting.cpp @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/nano/node/voting.hpp b/nano/node/voting/voting.hpp similarity index 100% rename from nano/node/voting.hpp rename to nano/node/voting/voting.hpp diff --git a/nano/slow_test/vote_processor.cpp b/nano/slow_test/vote_processor.cpp index eaae35577d..320870e239 100644 --- a/nano/slow_test/vote_processor.cpp +++ b/nano/slow_test/vote_processor.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include From 55308a0f184a5aaaf78a4076c8280d483365d997 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 14:32:42 +0000 Subject: [PATCH 05/13] Extracting vote_spacing in to its own file. --- nano/node/CMakeLists.txt | 2 ++ nano/node/voting/spacing.cpp | 39 ++++++++++++++++++++++++++++++ nano/node/voting/spacing.hpp | 46 ++++++++++++++++++++++++++++++++++++ nano/node/voting/voting.cpp | 38 ----------------------------- nano/node/voting/voting.hpp | 31 +----------------------- 5 files changed, 88 insertions(+), 68 deletions(-) create mode 100644 nano/node/voting/spacing.cpp create mode 100644 nano/node/voting/spacing.hpp diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index d09975e252..76de76f284 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -182,6 +182,8 @@ add_library( voting/processor.cpp voting/request_aggregator.hpp voting/request_aggregator.cpp + voting/spacing.hpp + voting/spacing.cpp voting/voting.hpp voting/voting.cpp wallet.hpp diff --git a/nano/node/voting/spacing.cpp b/nano/node/voting/spacing.cpp new file mode 100644 index 0000000000..de44e528a1 --- /dev/null +++ b/nano/node/voting/spacing.cpp @@ -0,0 +1,39 @@ +#include + +void nano::vote_spacing::trim () +{ + recent.get ().erase (recent.get ().begin (), recent.get ().upper_bound (std::chrono::steady_clock::now () - delay)); +} + +bool nano::vote_spacing::votable (nano::root const & root_a, nano::block_hash const & hash_a) const +{ + bool result = true; + for (auto range = recent.get ().equal_range (root_a); result && range.first != range.second; ++range.first) + { + auto & item = *range.first; + result = hash_a == item.hash || item.time < std::chrono::steady_clock::now () - delay; + } + return result; +} + +void nano::vote_spacing::flag (nano::root const & root_a, nano::block_hash const & hash_a) +{ + trim (); + auto now = std::chrono::steady_clock::now (); + auto existing = recent.get ().find (root_a); + if (existing != recent.end ()) + { + recent.get ().modify (existing, [now] (entry & entry) { + entry.time = now; + }); + } + else + { + recent.insert ({ root_a, now, hash_a }); + } +} + +std::size_t nano::vote_spacing::size () const +{ + return recent.size (); +} diff --git a/nano/node/voting/spacing.hpp b/nano/node/voting/spacing.hpp new file mode 100644 index 0000000000..5895bd1a2f --- /dev/null +++ b/nano/node/voting/spacing.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include + +#include + +namespace mi = boost::multi_index; + +namespace nano +{ +class vote_spacing final +{ + class entry + { + public: + nano::root root; + std::chrono::steady_clock::time_point time; + nano::block_hash hash; + }; + + boost::multi_index_container, + mi::member>, + mi::ordered_non_unique, + mi::member>>> + recent; + std::chrono::milliseconds const delay; + void trim (); + +public: + vote_spacing (std::chrono::milliseconds const & delay) : + delay{ delay } + { + } + bool votable (nano::root const & root_a, nano::block_hash const & hash_a) const; + void flag (nano::root const & root_a, nano::block_hash const & hash_a); + std::size_t size () const; +}; +} // namespace nano diff --git a/nano/node/voting/voting.cpp b/nano/node/voting/voting.cpp index 4f64c0e92d..2100a1fa5d 100644 --- a/nano/node/voting/voting.cpp +++ b/nano/node/voting/voting.cpp @@ -12,44 +12,6 @@ #include -void nano::vote_spacing::trim () -{ - recent.get ().erase (recent.get ().begin (), recent.get ().upper_bound (std::chrono::steady_clock::now () - delay)); -} - -bool nano::vote_spacing::votable (nano::root const & root_a, nano::block_hash const & hash_a) const -{ - bool result = true; - for (auto range = recent.get ().equal_range (root_a); result && range.first != range.second; ++range.first) - { - auto & item = *range.first; - result = hash_a == item.hash || item.time < std::chrono::steady_clock::now () - delay; - } - return result; -} - -void nano::vote_spacing::flag (nano::root const & root_a, nano::block_hash const & hash_a) -{ - trim (); - auto now = std::chrono::steady_clock::now (); - auto existing = recent.get ().find (root_a); - if (existing != recent.end ()) - { - recent.get ().modify (existing, [now] (entry & entry) { - entry.time = now; - }); - } - else - { - recent.insert ({ root_a, now, hash_a }); - } -} - -std::size_t nano::vote_spacing::size () const -{ - return recent.size (); -} - bool nano::local_vote_history::consistency_check (nano::root const & root_a) const { auto & history_by_root (history.get ()); diff --git a/nano/node/voting/voting.hpp b/nano/node/voting/voting.hpp index 13f113b106..35a60aa454 100644 --- a/nano/node/voting/voting.hpp +++ b/nano/node/voting/voting.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -32,36 +33,6 @@ namespace transport class channel; } -class vote_spacing final -{ - class entry - { - public: - nano::root root; - std::chrono::steady_clock::time_point time; - nano::block_hash hash; - }; - - boost::multi_index_container, - mi::member>, - mi::ordered_non_unique, - mi::member>>> - recent; - std::chrono::milliseconds const delay; - void trim (); - -public: - vote_spacing (std::chrono::milliseconds const & delay) : - delay{ delay } - { - } - bool votable (nano::root const & root_a, nano::block_hash const & hash_a) const; - void flag (nano::root const & root_a, nano::block_hash const & hash_a); - std::size_t size () const; -}; - class local_vote_history final { class local_vote final From a4723d9f968a21868882325691c00f77c67aaa25 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 14:54:15 +0000 Subject: [PATCH 06/13] Moving local_vote_history in to its own file. --- nano/node/CMakeLists.txt | 2 + nano/node/active_transactions.hpp | 1 + nano/node/node.hpp | 1 + nano/node/voting/history.cpp | 113 ++++++++++++++++++++++++ nano/node/voting/history.hpp | 69 +++++++++++++++ nano/node/voting/request_aggregator.cpp | 1 + nano/node/voting/voting.cpp | 113 +----------------------- nano/node/voting/voting.hpp | 58 +----------- 8 files changed, 189 insertions(+), 169 deletions(-) create mode 100644 nano/node/voting/history.cpp create mode 100644 nano/node/voting/history.hpp diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 76de76f284..2561effdf0 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -178,6 +178,8 @@ add_library( unchecked_map.hpp voting/cache.hpp voting/cache.cpp + voting/history.hpp + voting/history.cpp voting/processor.hpp voting/processor.cpp voting/request_aggregator.hpp diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 36e6d41497..6005e984a7 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -53,6 +53,7 @@ class recently_confirmed_cache final // clang-format off class tag_root {}; class tag_hash {}; + class tag_sequence {}; using ordered_recent_confirmations = boost::multi_index_container #include #include +#include #include #include #include diff --git a/nano/node/voting/history.cpp b/nano/node/voting/history.cpp new file mode 100644 index 0000000000..72fd1609ee --- /dev/null +++ b/nano/node/voting/history.cpp @@ -0,0 +1,113 @@ +#include + +bool nano::local_vote_history::consistency_check (nano::root const & root_a) const +{ + auto & history_by_root (history.get ()); + auto const range (history_by_root.equal_range (root_a)); + // All cached votes for a root must be for the same hash, this is actively enforced in local_vote_history::add + auto consistent_same = std::all_of (range.first, range.second, [hash = range.first->hash] (auto const & info_a) { return info_a.hash == hash; }); + std::vector accounts; + std::transform (range.first, range.second, std::back_inserter (accounts), [] (auto const & info_a) { return info_a.vote->account; }); + std::sort (accounts.begin (), accounts.end ()); + // All cached votes must be unique by account, this is actively enforced in local_vote_history::add + auto consistent_unique = accounts.size () == std::unique (accounts.begin (), accounts.end ()) - accounts.begin (); + auto result = consistent_same && consistent_unique; + debug_assert (result); + return result; +} + +void nano::local_vote_history::add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a) +{ + nano::lock_guard guard{ mutex }; + clean (); + auto add_vote (true); + auto & history_by_root (history.get ()); + // Erase any vote that is not for this hash, or duplicate by account, and if new timestamp is higher + auto range (history_by_root.equal_range (root_a)); + for (auto i (range.first); i != range.second;) + { + if (i->hash != hash_a || (vote_a->account == i->vote->account && i->vote->timestamp () <= vote_a->timestamp ())) + { + i = history_by_root.erase (i); + } + else if (vote_a->account == i->vote->account && i->vote->timestamp () > vote_a->timestamp ()) + { + add_vote = false; + ++i; + } + else + { + ++i; + } + } + // Do not add new vote to cache if representative account is same and timestamp is lower + if (add_vote) + { + auto result (history_by_root.emplace (root_a, hash_a, vote_a)); + (void)result; + debug_assert (result.second); + } + debug_assert (consistency_check (root_a)); +} + +void nano::local_vote_history::erase (nano::root const & root_a) +{ + nano::lock_guard guard{ mutex }; + auto & history_by_root (history.get ()); + auto range (history_by_root.equal_range (root_a)); + history_by_root.erase (range.first, range.second); +} + +std::vector> nano::local_vote_history::votes (nano::root const & root_a) const +{ + nano::lock_guard guard{ mutex }; + std::vector> result; + auto range (history.get ().equal_range (root_a)); + std::transform (range.first, range.second, std::back_inserter (result), [] (auto const & entry) { return entry.vote; }); + return result; +} + +std::vector> nano::local_vote_history::votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a) const +{ + nano::lock_guard guard{ mutex }; + std::vector> result; + auto range (history.get ().equal_range (root_a)); + // clang-format off + nano::transform_if (range.first, range.second, std::back_inserter (result), + [&hash_a, is_final_a](auto const & entry) { return entry.hash == hash_a && (!is_final_a || entry.vote->timestamp () == std::numeric_limits::max ()); }, + [](auto const & entry) { return entry.vote; }); + // clang-format on + return result; +} + +bool nano::local_vote_history::exists (nano::root const & root_a) const +{ + nano::lock_guard guard{ mutex }; + return history.get ().find (root_a) != history.get ().end (); +} + +void nano::local_vote_history::clean () +{ + debug_assert (constants.max_cache > 0); + auto & history_by_sequence (history.get ()); + while (history_by_sequence.size () > constants.max_cache) + { + history_by_sequence.erase (history_by_sequence.begin ()); + } +} + +std::size_t nano::local_vote_history::size () const +{ + nano::lock_guard guard{ mutex }; + return history.size (); +} + +std::unique_ptr nano::collect_container_info (nano::local_vote_history & history, std::string const & name) +{ + std::size_t history_count = history.size (); + auto sizeof_element = sizeof (decltype (history.history)::value_type); + auto composite = std::make_unique (name); + /* This does not currently loop over each element inside the cache to get the sizes of the votes inside history*/ + composite->add_component (std::make_unique (container_info{ "history", history_count, sizeof_element })); + return composite; +} diff --git a/nano/node/voting/history.hpp b/nano/node/voting/history.hpp new file mode 100644 index 0000000000..9e7d7eaf53 --- /dev/null +++ b/nano/node/voting/history.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace mi = boost::multi_index; + +namespace nano +{ +class vote; +class voting_constants; +class local_vote_history final +{ + class local_vote final + { + public: + local_vote (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a) : + root (root_a), + hash (hash_a), + vote (vote_a) + { + } + nano::root root; + nano::block_hash hash; + std::shared_ptr vote; + }; + +public: + local_vote_history (nano::voting_constants const & constants) : + constants{ constants } + { + } + void add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a); + void erase (nano::root const & root_a); + + std::vector> votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a = false) const; + bool exists (nano::root const &) const; + std::size_t size () const; + +private: + // clang-format off + boost::multi_index_container, + mi::member>, + mi::sequenced>>> + history; + // clang-format on + + nano::voting_constants const & constants; + void clean (); + std::vector> votes (nano::root const & root_a) const; + // Only used in Debug + bool consistency_check (nano::root const &) const; + mutable nano::mutex mutex; + + friend std::unique_ptr collect_container_info (local_vote_history & history, std::string const & name); + friend class local_vote_history_basic_Test; +}; + +std::unique_ptr collect_container_info (local_vote_history & history, std::string const & name); +} // namespace nano diff --git a/nano/node/voting/request_aggregator.cpp b/nano/node/voting/request_aggregator.cpp index ce2e39b69f..f1ae441270 100644 --- a/nano/node/voting/request_aggregator.cpp +++ b/nano/node/voting/request_aggregator.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/voting/voting.cpp b/nano/node/voting/voting.cpp index 2100a1fa5d..f01cef7290 100644 --- a/nano/node/voting/voting.cpp +++ b/nano/node/voting/voting.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -12,118 +13,6 @@ #include -bool nano::local_vote_history::consistency_check (nano::root const & root_a) const -{ - auto & history_by_root (history.get ()); - auto const range (history_by_root.equal_range (root_a)); - // All cached votes for a root must be for the same hash, this is actively enforced in local_vote_history::add - auto consistent_same = std::all_of (range.first, range.second, [hash = range.first->hash] (auto const & info_a) { return info_a.hash == hash; }); - std::vector accounts; - std::transform (range.first, range.second, std::back_inserter (accounts), [] (auto const & info_a) { return info_a.vote->account; }); - std::sort (accounts.begin (), accounts.end ()); - // All cached votes must be unique by account, this is actively enforced in local_vote_history::add - auto consistent_unique = accounts.size () == std::unique (accounts.begin (), accounts.end ()) - accounts.begin (); - auto result = consistent_same && consistent_unique; - debug_assert (result); - return result; -} - -void nano::local_vote_history::add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a) -{ - nano::lock_guard guard{ mutex }; - clean (); - auto add_vote (true); - auto & history_by_root (history.get ()); - // Erase any vote that is not for this hash, or duplicate by account, and if new timestamp is higher - auto range (history_by_root.equal_range (root_a)); - for (auto i (range.first); i != range.second;) - { - if (i->hash != hash_a || (vote_a->account == i->vote->account && i->vote->timestamp () <= vote_a->timestamp ())) - { - i = history_by_root.erase (i); - } - else if (vote_a->account == i->vote->account && i->vote->timestamp () > vote_a->timestamp ()) - { - add_vote = false; - ++i; - } - else - { - ++i; - } - } - // Do not add new vote to cache if representative account is same and timestamp is lower - if (add_vote) - { - auto result (history_by_root.emplace (root_a, hash_a, vote_a)); - (void)result; - debug_assert (result.second); - } - debug_assert (consistency_check (root_a)); -} - -void nano::local_vote_history::erase (nano::root const & root_a) -{ - nano::lock_guard guard{ mutex }; - auto & history_by_root (history.get ()); - auto range (history_by_root.equal_range (root_a)); - history_by_root.erase (range.first, range.second); -} - -std::vector> nano::local_vote_history::votes (nano::root const & root_a) const -{ - nano::lock_guard guard{ mutex }; - std::vector> result; - auto range (history.get ().equal_range (root_a)); - std::transform (range.first, range.second, std::back_inserter (result), [] (auto const & entry) { return entry.vote; }); - return result; -} - -std::vector> nano::local_vote_history::votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a) const -{ - nano::lock_guard guard{ mutex }; - std::vector> result; - auto range (history.get ().equal_range (root_a)); - // clang-format off - nano::transform_if (range.first, range.second, std::back_inserter (result), - [&hash_a, is_final_a](auto const & entry) { return entry.hash == hash_a && (!is_final_a || entry.vote->timestamp () == std::numeric_limits::max ()); }, - [](auto const & entry) { return entry.vote; }); - // clang-format on - return result; -} - -bool nano::local_vote_history::exists (nano::root const & root_a) const -{ - nano::lock_guard guard{ mutex }; - return history.get ().find (root_a) != history.get ().end (); -} - -void nano::local_vote_history::clean () -{ - debug_assert (constants.max_cache > 0); - auto & history_by_sequence (history.get ()); - while (history_by_sequence.size () > constants.max_cache) - { - history_by_sequence.erase (history_by_sequence.begin ()); - } -} - -std::size_t nano::local_vote_history::size () const -{ - nano::lock_guard guard{ mutex }; - return history.size (); -} - -std::unique_ptr nano::collect_container_info (nano::local_vote_history & history, std::string const & name) -{ - std::size_t history_count = history.size (); - auto sizeof_element = sizeof (decltype (history.history)::value_type); - auto composite = std::make_unique (name); - /* This does not currently loop over each element inside the cache to get the sizes of the votes inside history*/ - composite->add_component (std::make_unique (container_info{ "history", history_count, sizeof_element })); - return composite; -} - nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::local_vote_history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a) : config (config_a), ledger (ledger_a), diff --git a/nano/node/voting/voting.hpp b/nano/node/voting/voting.hpp index 35a60aa454..ae16e6d0ba 100644 --- a/nano/node/voting/voting.hpp +++ b/nano/node/voting/voting.hpp @@ -8,12 +8,6 @@ #include #include -#include -#include -#include -#include -#include - #include #include #include @@ -23,6 +17,7 @@ namespace mi = boost::multi_index; namespace nano { class ledger; +class local_vote_history; class network; class node_config; class stats; @@ -33,57 +28,6 @@ namespace transport class channel; } -class local_vote_history final -{ - class local_vote final - { - public: - local_vote (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a) : - root (root_a), - hash (hash_a), - vote (vote_a) - { - } - nano::root root; - nano::block_hash hash; - std::shared_ptr vote; - }; - -public: - local_vote_history (nano::voting_constants const & constants) : - constants{ constants } - { - } - void add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a); - void erase (nano::root const & root_a); - - std::vector> votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a = false) const; - bool exists (nano::root const &) const; - std::size_t size () const; - -private: - // clang-format off - boost::multi_index_container, - mi::member>, - mi::sequenced>>> - history; - // clang-format on - - nano::voting_constants const & constants; - void clean (); - std::vector> votes (nano::root const & root_a) const; - // Only used in Debug - bool consistency_check (nano::root const &) const; - mutable nano::mutex mutex; - - friend std::unique_ptr collect_container_info (local_vote_history & history, std::string const & name); - friend class local_vote_history_basic_Test; -}; - -std::unique_ptr collect_container_info (local_vote_history & history, std::string const & name); - class vote_generator final { private: From 7ad090fc67e56f6265ae002d8fa1f0a9f401bd33 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 15:44:21 +0000 Subject: [PATCH 07/13] Renaming nano::local_vote_history to nano::voting::history --- nano/core_test/voting.cpp | 2 +- nano/node/node.hpp | 2 +- nano/node/voting/history.cpp | 36 ++++++++++++------------- nano/node/voting/history.hpp | 18 ++++++++----- nano/node/voting/request_aggregator.cpp | 2 +- nano/node/voting/request_aggregator.hpp | 9 ++++--- nano/node/voting/voting.cpp | 2 +- nano/node/voting/voting.hpp | 9 ++++--- 8 files changed, 45 insertions(+), 35 deletions(-) diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index 67e64abec2..81271d6f0b 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -11,7 +11,7 @@ namespace nano { TEST (local_vote_history, basic) { - nano::local_vote_history history{ nano::dev::network_params.voting }; + nano::voting::history history{ nano::dev::network_params.voting }; ASSERT_FALSE (history.exists (1)); ASSERT_FALSE (history.exists (2)); ASSERT_TRUE (history.votes (1).empty ()); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 383e53e46f..78563d5ddc 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -176,7 +176,7 @@ class node final : public std::enable_shared_from_this unsigned warmed_up; nano::block_processor block_processor; nano::block_arrival block_arrival; - nano::local_vote_history history; + nano::voting::history history; nano::keypair node_id; nano::block_uniquer block_uniquer; nano::vote_uniquer vote_uniquer; diff --git a/nano/node/voting/history.cpp b/nano/node/voting/history.cpp index 72fd1609ee..4dd04c6a19 100644 --- a/nano/node/voting/history.cpp +++ b/nano/node/voting/history.cpp @@ -1,8 +1,8 @@ #include -bool nano::local_vote_history::consistency_check (nano::root const & root_a) const +bool nano::voting::history::consistency_check (nano::root const & root_a) const { - auto & history_by_root (history.get ()); + auto & history_by_root (history_m.get ()); auto const range (history_by_root.equal_range (root_a)); // All cached votes for a root must be for the same hash, this is actively enforced in local_vote_history::add auto consistent_same = std::all_of (range.first, range.second, [hash = range.first->hash] (auto const & info_a) { return info_a.hash == hash; }); @@ -16,12 +16,12 @@ bool nano::local_vote_history::consistency_check (nano::root const & root_a) con return result; } -void nano::local_vote_history::add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a) +void nano::voting::history::add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a) { nano::lock_guard guard{ mutex }; clean (); auto add_vote (true); - auto & history_by_root (history.get ()); + auto & history_by_root (history_m.get ()); // Erase any vote that is not for this hash, or duplicate by account, and if new timestamp is higher auto range (history_by_root.equal_range (root_a)); for (auto i (range.first); i != range.second;) @@ -50,28 +50,28 @@ void nano::local_vote_history::add (nano::root const & root_a, nano::block_hash debug_assert (consistency_check (root_a)); } -void nano::local_vote_history::erase (nano::root const & root_a) +void nano::voting::history::erase (nano::root const & root_a) { nano::lock_guard guard{ mutex }; - auto & history_by_root (history.get ()); + auto & history_by_root (history_m.get ()); auto range (history_by_root.equal_range (root_a)); history_by_root.erase (range.first, range.second); } -std::vector> nano::local_vote_history::votes (nano::root const & root_a) const +std::vector> nano::voting::history::votes (nano::root const & root_a) const { nano::lock_guard guard{ mutex }; std::vector> result; - auto range (history.get ().equal_range (root_a)); + auto range (history_m.get ().equal_range (root_a)); std::transform (range.first, range.second, std::back_inserter (result), [] (auto const & entry) { return entry.vote; }); return result; } -std::vector> nano::local_vote_history::votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a) const +std::vector> nano::voting::history::votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a) const { nano::lock_guard guard{ mutex }; std::vector> result; - auto range (history.get ().equal_range (root_a)); + auto range (history_m.get ().equal_range (root_a)); // clang-format off nano::transform_if (range.first, range.second, std::back_inserter (result), [&hash_a, is_final_a](auto const & entry) { return entry.hash == hash_a && (!is_final_a || entry.vote->timestamp () == std::numeric_limits::max ()); }, @@ -80,32 +80,32 @@ std::vector> nano::local_vote_history::votes (nano:: return result; } -bool nano::local_vote_history::exists (nano::root const & root_a) const +bool nano::voting::history::exists (nano::root const & root_a) const { nano::lock_guard guard{ mutex }; - return history.get ().find (root_a) != history.get ().end (); + return history_m.get ().find (root_a) != history_m.get ().end (); } -void nano::local_vote_history::clean () +void nano::voting::history::clean () { debug_assert (constants.max_cache > 0); - auto & history_by_sequence (history.get ()); + auto & history_by_sequence (history_m.get ()); while (history_by_sequence.size () > constants.max_cache) { history_by_sequence.erase (history_by_sequence.begin ()); } } -std::size_t nano::local_vote_history::size () const +std::size_t nano::voting::history::size () const { nano::lock_guard guard{ mutex }; - return history.size (); + return history_m.size (); } -std::unique_ptr nano::collect_container_info (nano::local_vote_history & history, std::string const & name) +std::unique_ptr nano::voting::collect_container_info (nano::voting::history & history, std::string const & name) { std::size_t history_count = history.size (); - auto sizeof_element = sizeof (decltype (history.history)::value_type); + auto sizeof_element = sizeof (decltype (history.history_m)::value_type); auto composite = std::make_unique (name); /* This does not currently loop over each element inside the cache to get the sizes of the votes inside history*/ composite->add_component (std::make_unique (container_info{ "history", history_count, sizeof_element })); diff --git a/nano/node/voting/history.hpp b/nano/node/voting/history.hpp index 9e7d7eaf53..8e503e8bc2 100644 --- a/nano/node/voting/history.hpp +++ b/nano/node/voting/history.hpp @@ -14,9 +14,13 @@ namespace mi = boost::multi_index; namespace nano { +class local_vote_history_basic_Test; class vote; class voting_constants; -class local_vote_history final +} +namespace nano::voting +{ +class history final { class local_vote final { @@ -33,7 +37,7 @@ class local_vote_history final }; public: - local_vote_history (nano::voting_constants const & constants) : + history (nano::voting_constants const & constants) : constants{ constants } { } @@ -51,7 +55,7 @@ class local_vote_history final mi::hashed_non_unique, mi::member>, mi::sequenced>>> - history; + history_m; // clang-format on nano::voting_constants const & constants; @@ -61,9 +65,9 @@ class local_vote_history final bool consistency_check (nano::root const &) const; mutable nano::mutex mutex; - friend std::unique_ptr collect_container_info (local_vote_history & history, std::string const & name); - friend class local_vote_history_basic_Test; + friend std::unique_ptr collect_container_info (history & history, std::string const & name); + friend class nano::local_vote_history_basic_Test; }; -std::unique_ptr collect_container_info (local_vote_history & history, std::string const & name); -} // namespace nano +std::unique_ptr collect_container_info (history & history, std::string const & name); +} // namespace nano::voting diff --git a/nano/node/voting/request_aggregator.cpp b/nano/node/voting/request_aggregator.cpp index f1ae441270..f0c1c7a9eb 100644 --- a/nano/node/voting/request_aggregator.cpp +++ b/nano/node/voting/request_aggregator.cpp @@ -11,7 +11,7 @@ #include #include -nano::request_aggregator::request_aggregator (nano::node_config const & config_a, nano::stats & stats_a, nano::vote_generator & generator_a, nano::vote_generator & final_generator_a, nano::local_vote_history & history_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::active_transactions & active_a) : +nano::request_aggregator::request_aggregator (nano::node_config const & config_a, nano::stats & stats_a, nano::vote_generator & generator_a, nano::vote_generator & final_generator_a, nano::voting::history & history_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::active_transactions & active_a) : config{ config_a }, max_delay (config_a.network_params.network.is_dev_network () ? 50 : 300), small_delay (config_a.network_params.network.is_dev_network () ? 10 : 50), diff --git a/nano/node/voting/request_aggregator.hpp b/nano/node/voting/request_aggregator.hpp index 657b7b56f3..ba1dc53197 100644 --- a/nano/node/voting/request_aggregator.hpp +++ b/nano/node/voting/request_aggregator.hpp @@ -16,11 +16,14 @@ namespace mi = boost::multi_index; +namespace nano::voting +{ +class history; +} namespace nano { class active_transactions; class ledger; -class local_vote_history; class node_config; class stats; class vote_generator; @@ -61,7 +64,7 @@ class request_aggregator final // clang-format on public: - request_aggregator (nano::node_config const & config, nano::stats & stats_a, nano::vote_generator &, nano::vote_generator &, nano::local_vote_history &, nano::ledger &, nano::wallets &, nano::active_transactions &); + request_aggregator (nano::node_config const & config, nano::stats & stats_a, nano::vote_generator &, nano::vote_generator &, nano::voting::history &, nano::ledger &, nano::wallets &, nano::active_transactions &); /** Add a new request by \p channel_a for hashes \p hashes_roots_a */ void add (std::shared_ptr const & channel_a, std::vector> const & hashes_roots_a); @@ -84,7 +87,7 @@ class request_aggregator final void reply_action (std::shared_ptr const & vote_a, std::shared_ptr const & channel_a) const; nano::stats & stats; - nano::local_vote_history & local_votes; + nano::voting::history & local_votes; nano::ledger & ledger; nano::wallets & wallets; nano::active_transactions & active; diff --git a/nano/node/voting/voting.cpp b/nano/node/voting/voting.cpp index f01cef7290..9b696e6055 100644 --- a/nano/node/voting/voting.cpp +++ b/nano/node/voting/voting.cpp @@ -13,7 +13,7 @@ #include -nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::local_vote_history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a) : +nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::voting::history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a) : config (config_a), ledger (ledger_a), wallets (wallets_a), diff --git a/nano/node/voting/voting.hpp b/nano/node/voting/voting.hpp index ae16e6d0ba..76630bb3c2 100644 --- a/nano/node/voting/voting.hpp +++ b/nano/node/voting/voting.hpp @@ -14,10 +14,13 @@ namespace mi = boost::multi_index; +namespace nano::voting +{ +class history; +} namespace nano { class ledger; -class local_vote_history; class network; class node_config; class stats; @@ -36,7 +39,7 @@ class vote_generator final using queue_entry_t = std::pair; public: - vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::local_vote_history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a); + vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::voting::history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a); ~vote_generator (); /** Queue items for vote generation, or broadcast votes already in cache */ @@ -69,7 +72,7 @@ class vote_generator final nano::ledger & ledger; nano::wallets & wallets; nano::vote_processor & vote_processor; - nano::local_vote_history & history; + nano::voting::history & history; nano::vote_spacing spacing; nano::network & network; nano::stats & stats; From e45381b8dbc3e99d68eba1057160dccc126528fb Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 16:12:57 +0000 Subject: [PATCH 08/13] Renaming nano::vote_cache to nano::voting::cache --- nano/core_test/vote_cache.cpp | 40 ++++++++++---------- nano/node/node.hpp | 2 +- nano/node/nodeconfig.hpp | 2 +- nano/node/process_live_dispatcher.cpp | 2 +- nano/node/process_live_dispatcher.hpp | 9 +++-- nano/node/scheduler/hinted.cpp | 4 +- nano/node/scheduler/hinted.hpp | 9 +++-- nano/node/voting/cache.cpp | 54 +++++++++++++-------------- nano/node/voting/cache.hpp | 14 +++---- 9 files changed, 71 insertions(+), 65 deletions(-) diff --git a/nano/core_test/vote_cache.cpp b/nano/core_test/vote_cache.cpp index e1daac7db4..c51a299696 100644 --- a/nano/core_test/vote_cache.cpp +++ b/nano/core_test/vote_cache.cpp @@ -36,8 +36,8 @@ nano::keypair create_rep (nano::uint128_t weight) TEST (vote_cache, construction) { - nano::vote_cache_config cfg; - nano::vote_cache vote_cache{ cfg }; + nano::voting::cache_config cfg; + nano::voting::cache vote_cache{ cfg }; ASSERT_EQ (0, vote_cache.size ()); ASSERT_TRUE (vote_cache.empty ()); auto hash1 = nano::test::random_hash (); @@ -49,8 +49,8 @@ TEST (vote_cache, construction) */ TEST (vote_cache, insert_one_hash) { - nano::vote_cache_config cfg; - nano::vote_cache vote_cache{ cfg }; + nano::voting::cache_config cfg; + nano::voting::cache vote_cache{ cfg }; vote_cache.rep_weight_query = rep_weight_query (); auto rep1 = create_rep (7); auto hash1 = nano::test::random_hash (); @@ -79,8 +79,8 @@ TEST (vote_cache, insert_one_hash) */ TEST (vote_cache, insert_one_hash_many_votes) { - nano::vote_cache_config cfg; - nano::vote_cache vote_cache{ cfg }; + nano::voting::cache_config cfg; + nano::voting::cache vote_cache{ cfg }; vote_cache.rep_weight_query = rep_weight_query (); auto hash1 = nano::test::random_hash (); auto rep1 = create_rep (7); @@ -114,8 +114,8 @@ TEST (vote_cache, insert_one_hash_many_votes) */ TEST (vote_cache, insert_many_hashes_many_votes) { - nano::vote_cache_config cfg; - nano::vote_cache vote_cache{ cfg }; + nano::voting::cache_config cfg; + nano::voting::cache vote_cache{ cfg }; vote_cache.rep_weight_query = rep_weight_query (); // There will be 3 random hashes to vote for auto hash1 = nano::test::random_hash (); @@ -194,8 +194,8 @@ TEST (vote_cache, insert_many_hashes_many_votes) */ TEST (vote_cache, insert_duplicate) { - nano::vote_cache_config cfg; - nano::vote_cache vote_cache{ cfg }; + nano::voting::cache_config cfg; + nano::voting::cache vote_cache{ cfg }; vote_cache.rep_weight_query = rep_weight_query (); auto hash1 = nano::test::random_hash (); auto rep1 = create_rep (9); @@ -211,8 +211,8 @@ TEST (vote_cache, insert_duplicate) */ TEST (vote_cache, insert_newer) { - nano::vote_cache_config cfg; - nano::vote_cache vote_cache{ cfg }; + nano::voting::cache_config cfg; + nano::voting::cache vote_cache{ cfg }; vote_cache.rep_weight_query = rep_weight_query (); auto hash1 = nano::test::random_hash (); auto rep1 = create_rep (9); @@ -236,8 +236,8 @@ TEST (vote_cache, insert_newer) */ TEST (vote_cache, insert_older) { - nano::vote_cache_config cfg; - nano::vote_cache vote_cache{ cfg }; + nano::voting::cache_config cfg; + nano::voting::cache vote_cache{ cfg }; vote_cache.rep_weight_query = rep_weight_query (); auto hash1 = nano::test::random_hash (); auto rep1 = create_rep (9); @@ -259,8 +259,8 @@ TEST (vote_cache, insert_older) */ TEST (vote_cache, erase) { - nano::vote_cache_config cfg; - nano::vote_cache vote_cache{ cfg }; + nano::voting::cache_config cfg; + nano::voting::cache vote_cache{ cfg }; vote_cache.rep_weight_query = rep_weight_query (); auto hash1 = nano::test::random_hash (); auto hash2 = nano::test::random_hash (); @@ -299,9 +299,9 @@ TEST (vote_cache, erase) TEST (vote_cache, overfill) { // Create a vote cache with max size set to 1024 - nano::vote_cache_config cfg; + nano::voting::cache_config cfg; cfg.max_size = 1024; - nano::vote_cache vote_cache{ cfg }; + nano::voting::cache vote_cache{ cfg }; vote_cache.rep_weight_query = rep_weight_query (); const int count = 16 * 1024; for (int n = 0; n < count; ++n) @@ -324,8 +324,8 @@ TEST (vote_cache, overfill) */ TEST (vote_cache, overfill_entry) { - nano::vote_cache_config cfg; - nano::vote_cache vote_cache{ cfg }; + nano::voting::cache_config cfg; + nano::voting::cache vote_cache{ cfg }; vote_cache.rep_weight_query = rep_weight_query (); const int count = 1024; auto hash1 = nano::test::random_hash (); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 78563d5ddc..0bfbdaafe2 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -181,7 +181,7 @@ class node final : public std::enable_shared_from_this nano::block_uniquer block_uniquer; nano::vote_uniquer vote_uniquer; nano::confirmation_height_processor confirmation_height_processor; - nano::vote_cache vote_cache; + nano::voting::cache vote_cache; nano::vote_generator generator; nano::vote_generator final_generator; nano::active_transactions active; diff --git a/nano/node/nodeconfig.hpp b/nano/node/nodeconfig.hpp index f469cf4525..43c6779faf 100644 --- a/nano/node/nodeconfig.hpp +++ b/nano/node/nodeconfig.hpp @@ -125,7 +125,7 @@ class node_config unsigned backlog_scan_batch_size{ 10 * 1000 }; /** Number of times per second to run backlog population batches. Number of accounts per single batch is `backlog_scan_batch_size / backlog_scan_frequency` */ unsigned backlog_scan_frequency{ 10 }; - nano::vote_cache_config vote_cache; + nano::voting::cache_config vote_cache; public: std::string serialize_frontiers_confirmation (nano::frontiers_confirmation_mode) const; diff --git a/nano/node/process_live_dispatcher.cpp b/nano/node/process_live_dispatcher.cpp index c3fcc991f3..3be93b94fd 100644 --- a/nano/node/process_live_dispatcher.cpp +++ b/nano/node/process_live_dispatcher.cpp @@ -8,7 +8,7 @@ #include #include -nano::process_live_dispatcher::process_live_dispatcher (nano::ledger & ledger, nano::scheduler::priority & scheduler, nano::vote_cache & vote_cache, nano::websocket_server & websocket) : +nano::process_live_dispatcher::process_live_dispatcher (nano::ledger & ledger, nano::scheduler::priority & scheduler, nano::voting::cache & vote_cache, nano::websocket_server & websocket) : ledger{ ledger }, scheduler{ scheduler }, vote_cache{ vote_cache }, diff --git a/nano/node/process_live_dispatcher.hpp b/nano/node/process_live_dispatcher.hpp index ec30d94913..cb0033c3c3 100644 --- a/nano/node/process_live_dispatcher.hpp +++ b/nano/node/process_live_dispatcher.hpp @@ -4,11 +4,14 @@ namespace nano::store { class transaction; } +namespace nano::voting +{ +class cache; +} namespace nano { class ledger; -class vote_cache; class websocket_server; class block_processor; class process_return; @@ -23,7 +26,7 @@ namespace scheduler class process_live_dispatcher { public: - process_live_dispatcher (nano::ledger &, nano::scheduler::priority &, nano::vote_cache &, nano::websocket_server &); + process_live_dispatcher (nano::ledger &, nano::scheduler::priority &, nano::voting::cache &, nano::websocket_server &); void connect (nano::block_processor & block_processor); private: @@ -33,7 +36,7 @@ class process_live_dispatcher nano::ledger & ledger; nano::scheduler::priority & scheduler; - nano::vote_cache & vote_cache; + nano::voting::cache & vote_cache; nano::websocket_server & websocket; }; } diff --git a/nano/node/scheduler/hinted.cpp b/nano/node/scheduler/hinted.cpp index 13a36d91bd..219e9e4f65 100644 --- a/nano/node/scheduler/hinted.cpp +++ b/nano/node/scheduler/hinted.cpp @@ -7,7 +7,7 @@ * hinted */ -nano::scheduler::hinted::hinted (hinted_config const & config_a, nano::node & node_a, nano::vote_cache & vote_cache_a, nano::active_transactions & active_a, nano::online_reps & online_reps_a, nano::stats & stats_a) : +nano::scheduler::hinted::hinted (hinted_config const & config_a, nano::node & node_a, nano::voting::cache & vote_cache_a, nano::active_transactions & active_a, nano::online_reps & online_reps_a, nano::stats & stats_a) : config{ config_a }, node{ node_a }, vote_cache{ vote_cache_a }, @@ -246,4 +246,4 @@ nano::error nano::scheduler::hinted_config::deserialize (nano::tomlconfig & toml } return toml.get_error (); -} \ No newline at end of file +} diff --git a/nano/node/scheduler/hinted.hpp b/nano/node/scheduler/hinted.hpp index a18d11dcb8..e52fbc8704 100644 --- a/nano/node/scheduler/hinted.hpp +++ b/nano/node/scheduler/hinted.hpp @@ -20,9 +20,12 @@ namespace nano class node; class node_config; class active_transactions; -class vote_cache; class online_reps; } +namespace nano::voting +{ +class cache; +} namespace nano::scheduler { @@ -46,7 +49,7 @@ class hinted_config final class hinted final { public: - hinted (hinted_config const &, nano::node &, nano::vote_cache &, nano::active_transactions &, nano::online_reps &, nano::stats &); + hinted (hinted_config const &, nano::node &, nano::voting::cache &, nano::active_transactions &, nano::online_reps &, nano::stats &); ~hinted (); void start (); @@ -68,7 +71,7 @@ class hinted final private: // Dependencies nano::node & node; - nano::vote_cache & vote_cache; + nano::voting::cache & vote_cache; nano::active_transactions & active; nano::online_reps & online_reps; nano::stats & stats; diff --git a/nano/node/voting/cache.cpp b/nano/node/voting/cache.cpp index 96fe54db1c..b846a21738 100644 --- a/nano/node/voting/cache.cpp +++ b/nano/node/voting/cache.cpp @@ -6,12 +6,12 @@ * entry */ -nano::vote_cache::entry::entry (const nano::block_hash & hash) : +nano::voting::cache::entry::entry (const nano::block_hash & hash) : hash_m{ hash } { } -bool nano::vote_cache::entry::vote (const nano::account & representative, const uint64_t & timestamp, const nano::uint128_t & rep_weight, std::size_t max_voters) +bool nano::voting::cache::entry::vote (const nano::account & representative, const uint64_t & timestamp, const nano::uint128_t & rep_weight, std::size_t max_voters) { auto existing = std::find_if (voters_m.begin (), voters_m.end (), [&representative] (auto const & item) { return item.representative == representative; }); if (existing != voters_m.end ()) @@ -53,7 +53,7 @@ bool nano::vote_cache::entry::vote (const nano::account & representative, const } } -std::size_t nano::vote_cache::entry::fill (std::shared_ptr const & election) const +std::size_t nano::voting::cache::entry::fill (std::shared_ptr const & election) const { std::size_t inserted = 0; for (const auto & entry : voters_m) @@ -67,27 +67,27 @@ std::size_t nano::vote_cache::entry::fill (std::shared_ptr const return inserted; } -std::size_t nano::vote_cache::entry::size () const +std::size_t nano::voting::cache::entry::size () const { return voters_m.size (); } -nano::block_hash nano::vote_cache::entry::hash () const +nano::block_hash nano::voting::cache::entry::hash () const { return hash_m; } -nano::uint128_t nano::vote_cache::entry::tally () const +nano::uint128_t nano::voting::cache::entry::tally () const { return tally_m; } -nano::uint128_t nano::vote_cache::entry::final_tally () const +nano::uint128_t nano::voting::cache::entry::final_tally () const { return final_tally_m; } -std::vector nano::vote_cache::entry::voters () const +std::vector nano::voting::cache::entry::voters () const { return voters_m; } @@ -96,12 +96,12 @@ std::vector nano::vote_cache::entry::voter * vote_cache */ -nano::vote_cache::vote_cache (vote_cache_config const & config_a) : +nano::voting::cache::cache (cache_config const & config_a) : config{ config_a } { } -void nano::vote_cache::vote (const nano::block_hash & hash, const std::shared_ptr vote) +void nano::voting::cache::vote (const nano::block_hash & hash, const std::shared_ptr vote) { auto const representative = vote->account; auto const timestamp = vote->timestamp (); @@ -109,7 +109,7 @@ void nano::vote_cache::vote (const nano::block_hash & hash, const std::shared_pt nano::unique_lock lock{ mutex }; - auto & cache_by_hash = cache.get (); + auto & cache_by_hash = cache_m.get (); if (auto existing = cache_by_hash.find (hash); existing != cache_by_hash.end ()) { cache_by_hash.modify (existing, [this, &representative, ×tamp, &rep_weight] (entry & ent) { @@ -121,33 +121,33 @@ void nano::vote_cache::vote (const nano::block_hash & hash, const std::shared_pt entry cache_entry{ hash }; cache_entry.vote (representative, timestamp, rep_weight, config.max_voters); - cache.get ().insert (cache_entry); + cache_m.get ().insert (cache_entry); // When cache overflown remove the oldest entry - if (cache.size () > config.max_size) + if (cache_m.size () > config.max_size) { - cache.get ().pop_front (); + cache_m.get ().pop_front (); } } } -bool nano::vote_cache::empty () const +bool nano::voting::cache::empty () const { nano::lock_guard lock{ mutex }; - return cache.empty (); + return cache_m.empty (); } -std::size_t nano::vote_cache::size () const +std::size_t nano::voting::cache::size () const { nano::lock_guard lock{ mutex }; - return cache.size (); + return cache_m.size (); } -std::optional nano::vote_cache::find (const nano::block_hash & hash) const +std::optional nano::voting::cache::find (const nano::block_hash & hash) const { nano::lock_guard lock{ mutex }; - auto & cache_by_hash = cache.get (); + auto & cache_by_hash = cache_m.get (); if (auto existing = cache_by_hash.find (hash); existing != cache_by_hash.end ()) { return *existing; @@ -155,12 +155,12 @@ std::optional nano::vote_cache::find (const nano::block return {}; } -bool nano::vote_cache::erase (const nano::block_hash & hash) +bool nano::voting::cache::erase (const nano::block_hash & hash) { nano::lock_guard lock{ mutex }; bool result = false; - auto & cache_by_hash = cache.get (); + auto & cache_by_hash = cache_m.get (); if (auto existing = cache_by_hash.find (hash); existing != cache_by_hash.end ()) { cache_by_hash.erase (existing); @@ -169,13 +169,13 @@ bool nano::vote_cache::erase (const nano::block_hash & hash) return result; } -std::vector nano::vote_cache::top (const nano::uint128_t & min_tally) const +std::vector nano::voting::cache::top (const nano::uint128_t & min_tally) const { std::vector results; { nano::lock_guard lock{ mutex }; - for (auto & entry : cache.get ()) + for (auto & entry : cache_m.get ()) { if (entry.tally () < min_tally) { @@ -200,7 +200,7 @@ std::vector nano::vote_cache::top (const nano::uint return results; } -std::unique_ptr nano::vote_cache::collect_container_info (const std::string & name) +std::unique_ptr nano::voting::cache::collect_container_info (const std::string & name) { auto composite = std::make_unique (name); composite->add_component (std::make_unique (container_info{ "cache", size (), sizeof (ordered_cache::value_type) })); @@ -211,7 +211,7 @@ std::unique_ptr nano::vote_cache::collect_contai * vote_cache_config */ -nano::error nano::vote_cache_config::serialize (nano::tomlconfig & toml) const +nano::error nano::voting::cache_config::serialize (nano::tomlconfig & toml) const { toml.put ("max_size", max_size, "Maximum number of blocks to cache votes for. \ntype:uint64"); toml.put ("max_voters", max_voters, "Maximum number of voters to cache per block. \ntype:uint64"); @@ -219,7 +219,7 @@ nano::error nano::vote_cache_config::serialize (nano::tomlconfig & toml) const return toml.get_error (); } -nano::error nano::vote_cache_config::deserialize (nano::tomlconfig & toml) +nano::error nano::voting::cache_config::deserialize (nano::tomlconfig & toml) { toml.get ("max_size", max_size); toml.get ("max_voters", max_voters); diff --git a/nano/node/voting/cache.hpp b/nano/node/voting/cache.hpp index a076981f7f..a4001c63fb 100644 --- a/nano/node/voting/cache.hpp +++ b/nano/node/voting/cache.hpp @@ -27,9 +27,9 @@ class election; class vote; } -namespace nano +namespace nano::voting { -class vote_cache_config final +class cache_config final { public: nano::error deserialize (nano::tomlconfig & toml); @@ -40,7 +40,7 @@ class vote_cache_config final std::size_t max_voters{ 128 }; }; -class vote_cache final +class cache final { public: /** @@ -83,7 +83,7 @@ class vote_cache final }; public: - explicit vote_cache (vote_cache_config const &); + explicit cache (cache_config const &); /** * Adds a new vote to cache @@ -127,7 +127,7 @@ class vote_cache final std::function rep_weight_query{ [] (nano::account const & rep) { debug_assert (false); return 0; } }; private: - vote_cache_config const & config; + cache_config const & config; // clang-format off class tag_sequenced {}; @@ -145,8 +145,8 @@ class vote_cache final mi::const_mem_fun, std::greater<>> // DESC >>; // clang-format on - ordered_cache cache; + ordered_cache cache_m; mutable nano::mutex mutex; }; -} \ No newline at end of file +} // namespace nano::voting From cd99ef3170cac660d65abfeabb7a58226150c801 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 16:21:49 +0000 Subject: [PATCH 09/13] Renaming nano::vote_processor to nano::voting::processor --- nano/node/node.hpp | 2 +- nano/node/voting/processor.cpp | 24 ++++++++++++------------ nano/node/voting/processor.hpp | 16 ++++++++++------ nano/node/voting/voting.cpp | 2 +- nano/node/voting/voting.hpp | 6 +++--- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 0bfbdaafe2..aa7ea428c1 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -172,7 +172,7 @@ class node final : public std::enable_shared_from_this nano::port_mapping port_mapping; nano::online_reps online_reps; nano::rep_crawler rep_crawler; - nano::vote_processor vote_processor; + nano::voting::processor vote_processor; unsigned warmed_up; nano::block_processor block_processor; nano::block_arrival block_arrival; diff --git a/nano/node/voting/processor.cpp b/nano/node/voting/processor.cpp index 7836c38c7a..cdad2d6e84 100644 --- a/nano/node/voting/processor.cpp +++ b/nano/node/voting/processor.cpp @@ -17,7 +17,7 @@ #include using namespace std::chrono_literals; -nano::vote_processor::vote_processor (nano::signature_checker & checker_a, nano::active_transactions & active_a, nano::node_observers & observers_a, nano::stats & stats_a, nano::node_config & config_a, nano::node_flags & flags_a, nano::logger_mt & logger_a, nano::online_reps & online_reps_a, nano::rep_crawler & rep_crawler_a, nano::ledger & ledger_a, nano::network_params & network_params_a) : +nano::voting::processor::processor (nano::signature_checker & checker_a, nano::active_transactions & active_a, nano::node_observers & observers_a, nano::stats & stats_a, nano::node_config & config_a, nano::node_flags & flags_a, nano::logger_mt & logger_a, nano::online_reps & online_reps_a, nano::rep_crawler & rep_crawler_a, nano::ledger & ledger_a, nano::network_params & network_params_a) : checker (checker_a), active (active_a), observers (observers_a), @@ -43,7 +43,7 @@ nano::vote_processor::vote_processor (nano::signature_checker & checker_a, nano: condition.wait (lock, [&started = started] { return started; }); } -void nano::vote_processor::process_loop () +void nano::voting::processor::process_loop () { nano::timer elapsed; bool log_this_iteration; @@ -90,7 +90,7 @@ void nano::vote_processor::process_loop () } } -bool nano::vote_processor::vote (std::shared_ptr const & vote_a, std::shared_ptr const & channel_a) +bool nano::voting::processor::vote (std::shared_ptr const & vote_a, std::shared_ptr const & channel_a) { debug_assert (channel_a != nullptr); bool process (false); @@ -132,7 +132,7 @@ bool nano::vote_processor::vote (std::shared_ptr const & vote_a, std return !process; } -void nano::vote_processor::verify_votes (decltype (votes) const & votes_a) +void nano::voting::processor::verify_votes (decltype (votes) const & votes_a) { auto size (votes_a.size ()); std::vector messages; @@ -167,7 +167,7 @@ void nano::vote_processor::verify_votes (decltype (votes) const & votes_a) } } -nano::vote_code nano::vote_processor::vote_blocking (std::shared_ptr const & vote_a, std::shared_ptr const & channel_a, bool validated) +nano::vote_code nano::voting::processor::vote_blocking (std::shared_ptr const & vote_a, std::shared_ptr const & channel_a, bool validated) { auto result (nano::vote_code::invalid); if (validated || !vote_a->validate ()) @@ -202,7 +202,7 @@ nano::vote_code nano::vote_processor::vote_blocking (std::shared_ptr return result; } -void nano::vote_processor::stop () +void nano::voting::processor::stop () { { nano::lock_guard lock{ mutex }; @@ -215,7 +215,7 @@ void nano::vote_processor::stop () } } -void nano::vote_processor::flush () +void nano::voting::processor::flush () { nano::unique_lock lock{ mutex }; auto const cutoff = total_processed.load (std::memory_order_relaxed) + votes.size (); @@ -229,24 +229,24 @@ void nano::vote_processor::flush () } } -std::size_t nano::vote_processor::size () +std::size_t nano::voting::processor::size () { nano::lock_guard guard{ mutex }; return votes.size (); } -bool nano::vote_processor::empty () +bool nano::voting::processor::empty () { nano::lock_guard guard{ mutex }; return votes.empty (); } -bool nano::vote_processor::half_full () +bool nano::voting::processor::half_full () { return size () >= max_votes / 2; } -void nano::vote_processor::calculate_weights () +void nano::voting::processor::calculate_weights () { nano::unique_lock lock{ mutex }; if (!stopped) @@ -276,7 +276,7 @@ void nano::vote_processor::calculate_weights () } } -std::unique_ptr nano::collect_container_info (vote_processor & vote_processor, std::string const & name) +std::unique_ptr nano::voting::collect_container_info (processor & vote_processor, std::string const & name) { std::size_t votes_count; std::size_t representatives_1_count; diff --git a/nano/node/voting/processor.hpp b/nano/node/voting/processor.hpp index 0ffb39dd00..9687e2ce34 100644 --- a/nano/node/voting/processor.hpp +++ b/nano/node/voting/processor.hpp @@ -13,6 +13,7 @@ namespace nano { class signature_checker; class active_transactions; +class vote_processor_weights_Test; namespace store { class component; @@ -32,11 +33,14 @@ namespace transport { class channel; } +} // namespace nano -class vote_processor final +namespace nano::voting +{ +class processor final { public: - vote_processor (nano::signature_checker & checker_a, nano::active_transactions & active_a, nano::node_observers & observers_a, nano::stats & stats_a, nano::node_config & config_a, nano::node_flags & flags_a, nano::logger_mt & logger_a, nano::online_reps & online_reps_a, nano::rep_crawler & rep_crawler_a, nano::ledger & ledger_a, nano::network_params & network_params_a); + processor (nano::signature_checker & checker_a, nano::active_transactions & active_a, nano::node_observers & observers_a, nano::stats & stats_a, nano::node_config & config_a, nano::node_flags & flags_a, nano::logger_mt & logger_a, nano::online_reps & online_reps_a, nano::rep_crawler & rep_crawler_a, nano::ledger & ledger_a, nano::network_params & network_params_a); /** Returns false if the vote was processed */ bool vote (std::shared_ptr const &, std::shared_ptr const &); @@ -78,9 +82,9 @@ class vote_processor final bool stopped; std::thread thread; - friend std::unique_ptr collect_container_info (vote_processor & vote_processor, std::string const & name); - friend class vote_processor_weights_Test; + friend std::unique_ptr collect_container_info (processor & vote_processor, std::string const & name); + friend class nano::vote_processor_weights_Test; }; -std::unique_ptr collect_container_info (vote_processor & vote_processor, std::string const & name); -} +std::unique_ptr collect_container_info (processor & vote_processor, std::string const & name); +} // nano::voting diff --git a/nano/node/voting/voting.cpp b/nano/node/voting/voting.cpp index 9b696e6055..189ca80997 100644 --- a/nano/node/voting/voting.cpp +++ b/nano/node/voting/voting.cpp @@ -13,7 +13,7 @@ #include -nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::voting::history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a) : +nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::voting::processor & vote_processor_a, nano::voting::history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a) : config (config_a), ledger (ledger_a), wallets (wallets_a), diff --git a/nano/node/voting/voting.hpp b/nano/node/voting/voting.hpp index 76630bb3c2..942cde617f 100644 --- a/nano/node/voting/voting.hpp +++ b/nano/node/voting/voting.hpp @@ -17,6 +17,7 @@ namespace mi = boost::multi_index; namespace nano::voting { class history; +class processor; } namespace nano { @@ -24,7 +25,6 @@ class ledger; class network; class node_config; class stats; -class vote_processor; class wallets; namespace transport { @@ -39,7 +39,7 @@ class vote_generator final using queue_entry_t = std::pair; public: - vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::voting::history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a); + vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::voting::processor & vote_processor_a, nano::voting::history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a); ~vote_generator (); /** Queue items for vote generation, or broadcast votes already in cache */ @@ -71,7 +71,7 @@ class vote_generator final nano::node_config const & config; nano::ledger & ledger; nano::wallets & wallets; - nano::vote_processor & vote_processor; + nano::voting::processor & vote_processor; nano::voting::history & history; nano::vote_spacing spacing; nano::network & network; From ba468de3c1d1aebd0b6ebe2fe5b42ce9e8a9c00b Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 16:23:16 +0000 Subject: [PATCH 10/13] Renaming voting.hpp to generator.hpp since it only holds the generator class. --- nano/core_test/voting.cpp | 2 +- nano/node/CMakeLists.txt | 4 ++-- nano/node/active_transactions.hpp | 2 +- nano/node/voting/{voting.cpp => generator.cpp} | 2 +- nano/node/voting/{voting.hpp => generator.hpp} | 0 nano/node/voting/request_aggregator.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename nano/node/voting/{voting.cpp => generator.cpp} (99%) rename nano/node/voting/{voting.hpp => generator.hpp} (100%) diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index 81271d6f0b..8ff85771d0 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 2561effdf0..61d0be880f 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -180,14 +180,14 @@ add_library( voting/cache.cpp voting/history.hpp voting/history.cpp + voting/generator.hpp + voting/generator.cpp voting/processor.hpp voting/processor.cpp voting/request_aggregator.hpp voting/request_aggregator.cpp voting/spacing.hpp voting/spacing.cpp - voting/voting.hpp - voting/voting.cpp wallet.hpp wallet.cpp websocket.hpp diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 6005e984a7..d04dfb2407 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/node/voting/voting.cpp b/nano/node/voting/generator.cpp similarity index 99% rename from nano/node/voting/voting.cpp rename to nano/node/voting/generator.cpp index 189ca80997..ee50440acd 100644 --- a/nano/node/voting/voting.cpp +++ b/nano/node/voting/generator.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/node/voting/voting.hpp b/nano/node/voting/generator.hpp similarity index 100% rename from nano/node/voting/voting.hpp rename to nano/node/voting/generator.hpp diff --git a/nano/node/voting/request_aggregator.cpp b/nano/node/voting/request_aggregator.cpp index f0c1c7a9eb..7bfdb4835e 100644 --- a/nano/node/voting/request_aggregator.cpp +++ b/nano/node/voting/request_aggregator.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include From 5db6bac1994a54e8ba0ffb61bcc15f5f1dc70764 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 16:34:01 +0000 Subject: [PATCH 11/13] Renaming nano::vote_generator to nano::voting::generator --- nano/node/node.hpp | 5 ++-- nano/node/voting/generator.cpp | 32 ++++++++++++------------- nano/node/voting/generator.hpp | 15 +++++++----- nano/node/voting/request_aggregator.cpp | 4 ++-- nano/node/voting/request_aggregator.hpp | 8 +++---- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/nano/node/node.hpp b/nano/node/node.hpp index aa7ea428c1..010583529b 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -182,8 +183,8 @@ class node final : public std::enable_shared_from_this nano::vote_uniquer vote_uniquer; nano::confirmation_height_processor confirmation_height_processor; nano::voting::cache vote_cache; - nano::vote_generator generator; - nano::vote_generator final_generator; + nano::voting::generator generator; + nano::voting::generator final_generator; nano::active_transactions active; private: // Placed here to maintain initialization order diff --git a/nano/node/voting/generator.cpp b/nano/node/voting/generator.cpp index ee50440acd..d682463029 100644 --- a/nano/node/voting/generator.cpp +++ b/nano/node/voting/generator.cpp @@ -4,16 +4,16 @@ #include #include #include +#include #include #include -#include #include #include #include #include -nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::voting::processor & vote_processor_a, nano::voting::history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a) : +nano::voting::generator::generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::voting::processor & vote_processor_a, nano::voting::history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a) : config (config_a), ledger (ledger_a), wallets (wallets_a), @@ -30,12 +30,12 @@ nano::vote_generator::vote_generator (nano::node_config const & config_a, nano:: }; } -nano::vote_generator::~vote_generator () +nano::voting::generator::~generator () { stop (); } -void nano::vote_generator::process (store::write_transaction const & transaction, nano::root const & root_a, nano::block_hash const & hash_a) +void nano::voting::generator::process (store::write_transaction const & transaction, nano::root const & root_a, nano::block_hash const & hash_a) { bool should_vote = false; if (is_final) @@ -61,7 +61,7 @@ void nano::vote_generator::process (store::write_transaction const & transaction } } -void nano::vote_generator::start () +void nano::voting::generator::start () { debug_assert (!thread.joinable ()); thread = std::thread ([this] () { run (); }); @@ -69,7 +69,7 @@ void nano::vote_generator::start () vote_generation_queue.start (); } -void nano::vote_generator::stop () +void nano::voting::generator::stop () { vote_generation_queue.stop (); @@ -85,12 +85,12 @@ void nano::vote_generator::stop () } } -void nano::vote_generator::add (const root & root, const block_hash & hash) +void nano::voting::generator::add (const root & root, const block_hash & hash) { vote_generation_queue.add (std::make_pair (root, hash)); } -void nano::vote_generator::process_batch (std::deque & batch) +void nano::voting::generator::process_batch (std::deque & batch) { auto transaction = ledger.store.tx_begin_write ({ tables::final_votes }); @@ -100,7 +100,7 @@ void nano::vote_generator::process_batch (std::deque & batch) } } -std::size_t nano::vote_generator::generate (std::vector> const & blocks_a, std::shared_ptr const & channel_a) +std::size_t nano::voting::generator::generate (std::vector> const & blocks_a, std::shared_ptr const & channel_a) { request_t::first_type req_candidates; { @@ -125,13 +125,13 @@ std::size_t nano::vote_generator::generate (std::vector const &, std::shared_ptr const &)> action_a) +void nano::voting::generator::set_reply_action (std::function const &, std::shared_ptr const &)> action_a) { release_assert (!reply_action); reply_action = action_a; } -void nano::vote_generator::broadcast (nano::unique_lock & lock_a) +void nano::voting::generator::broadcast (nano::unique_lock & lock_a) { debug_assert (lock_a.owns_lock ()); @@ -167,7 +167,7 @@ void nano::vote_generator::broadcast (nano::unique_lock & lock_a) } } -void nano::vote_generator::reply (nano::unique_lock & lock_a, request_t && request_a) +void nano::voting::generator::reply (nano::unique_lock & lock_a, request_t && request_a) { lock_a.unlock (); auto i (request_a.first.cbegin ()); @@ -207,7 +207,7 @@ void nano::vote_generator::reply (nano::unique_lock & lock_a, reque lock_a.lock (); } -void nano::vote_generator::vote (std::vector const & hashes_a, std::vector const & roots_a, std::function const &)> const & action_a) +void nano::voting::generator::vote (std::vector const & hashes_a, std::vector const & roots_a, std::function const &)> const & action_a) { debug_assert (hashes_a.size () == roots_a.size ()); std::vector> votes_l; @@ -227,14 +227,14 @@ void nano::vote_generator::vote (std::vector const & hashes_a, } } -void nano::vote_generator::broadcast_action (std::shared_ptr const & vote_a) const +void nano::voting::generator::broadcast_action (std::shared_ptr const & vote_a) const { network.flood_vote_pr (vote_a); network.flood_vote (vote_a, 2.0f); vote_processor.vote (vote_a, std::make_shared (network.node, network.node)); } -void nano::vote_generator::run () +void nano::voting::generator::run () { nano::thread_role::set (nano::thread_role::name::voting); nano::unique_lock lock{ mutex }; @@ -265,7 +265,7 @@ void nano::vote_generator::run () } } -std::unique_ptr nano::collect_container_info (nano::vote_generator & vote_generator, std::string const & name) +std::unique_ptr nano::voting::collect_container_info (nano::voting::generator & vote_generator, std::string const & name) { std::size_t candidates_count = 0; std::size_t requests_count = 0; diff --git a/nano/node/voting/generator.hpp b/nano/node/voting/generator.hpp index 942cde617f..d722f94818 100644 --- a/nano/node/voting/generator.hpp +++ b/nano/node/voting/generator.hpp @@ -30,8 +30,11 @@ namespace transport { class channel; } +} // namespace nano -class vote_generator final +namespace nano::voting +{ +class generator final { private: using candidate_t = std::pair; @@ -39,8 +42,8 @@ class vote_generator final using queue_entry_t = std::pair; public: - vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::voting::processor & vote_processor_a, nano::voting::history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a); - ~vote_generator (); + generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::voting::processor & vote_processor_a, nano::voting::history & history_a, nano::network & network_a, nano::stats & stats_a, bool is_final_a); + ~generator (); /** Queue items for vote generation, or broadcast votes already in cache */ void add (nano::root const &, nano::block_hash const &); @@ -90,8 +93,8 @@ class vote_generator final std::atomic stopped{ false }; std::thread thread; - friend std::unique_ptr collect_container_info (vote_generator & vote_generator, std::string const & name); + friend std::unique_ptr collect_container_info (generator & vote_generator, std::string const & name); }; -std::unique_ptr collect_container_info (vote_generator & generator, std::string const & name); -} +std::unique_ptr collect_container_info (generator & generator, std::string const & name); +} // namespace nano::voting diff --git a/nano/node/voting/request_aggregator.cpp b/nano/node/voting/request_aggregator.cpp index 7bfdb4835e..f0c2a62364 100644 --- a/nano/node/voting/request_aggregator.cpp +++ b/nano/node/voting/request_aggregator.cpp @@ -4,14 +4,14 @@ #include #include #include +#include #include #include -#include #include #include #include -nano::request_aggregator::request_aggregator (nano::node_config const & config_a, nano::stats & stats_a, nano::vote_generator & generator_a, nano::vote_generator & final_generator_a, nano::voting::history & history_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::active_transactions & active_a) : +nano::request_aggregator::request_aggregator (nano::node_config const & config_a, nano::stats & stats_a, nano::voting::generator & generator_a, nano::voting::generator & final_generator_a, nano::voting::history & history_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::active_transactions & active_a) : config{ config_a }, max_delay (config_a.network_params.network.is_dev_network () ? 50 : 300), small_delay (config_a.network_params.network.is_dev_network () ? 10 : 50), diff --git a/nano/node/voting/request_aggregator.hpp b/nano/node/voting/request_aggregator.hpp index ba1dc53197..b592155a8e 100644 --- a/nano/node/voting/request_aggregator.hpp +++ b/nano/node/voting/request_aggregator.hpp @@ -18,6 +18,7 @@ namespace mi = boost::multi_index; namespace nano::voting { +class generator; class history; } namespace nano @@ -26,7 +27,6 @@ class active_transactions; class ledger; class node_config; class stats; -class vote_generator; class wallets; /** @@ -64,7 +64,7 @@ class request_aggregator final // clang-format on public: - request_aggregator (nano::node_config const & config, nano::stats & stats_a, nano::vote_generator &, nano::vote_generator &, nano::voting::history &, nano::ledger &, nano::wallets &, nano::active_transactions &); + request_aggregator (nano::node_config const & config, nano::stats & stats_a, nano::voting::generator &, nano::voting::generator &, nano::voting::history &, nano::ledger &, nano::wallets &, nano::active_transactions &); /** Add a new request by \p channel_a for hashes \p hashes_roots_a */ void add (std::shared_ptr const & channel_a, std::vector> const & hashes_roots_a); @@ -91,8 +91,8 @@ class request_aggregator final nano::ledger & ledger; nano::wallets & wallets; nano::active_transactions & active; - nano::vote_generator & generator; - nano::vote_generator & final_generator; + nano::voting::generator & generator; + nano::voting::generator & final_generator; // clang-format off boost::multi_index_container Date: Wed, 1 Nov 2023 16:41:20 +0000 Subject: [PATCH 12/13] Renaming nano::request_aggregator to nano::voting::aggregator --- nano/core_test/request_aggregator.cpp | 2 +- nano/node/CMakeLists.txt | 4 ++-- nano/node/node.hpp | 4 ++-- ...{request_aggregator.cpp => aggregator.cpp} | 22 +++++++++---------- ...{request_aggregator.hpp => aggregator.hpp} | 13 ++++++----- 5 files changed, 24 insertions(+), 21 deletions(-) rename nano/node/voting/{request_aggregator.cpp => aggregator.cpp} (92%) rename nano/node/voting/{request_aggregator.hpp => aggregator.hpp} (91%) diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index 6041c87db0..b487e0a3e6 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 61d0be880f..35fa8f5522 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -176,6 +176,8 @@ add_library( transport/transport.cpp unchecked_map.cpp unchecked_map.hpp + voting/aggregator.hpp + voting/aggregator.cpp voting/cache.hpp voting/cache.cpp voting/history.hpp @@ -184,8 +186,6 @@ add_library( voting/generator.cpp voting/processor.hpp voting/processor.cpp - voting/request_aggregator.hpp - voting/request_aggregator.cpp voting/spacing.hpp voting/spacing.cpp wallet.hpp diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 010583529b..d5398ed507 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -32,11 +32,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -192,7 +192,7 @@ class node final : public std::enable_shared_from_this public: nano::scheduler::component & scheduler; - nano::request_aggregator aggregator; + nano::voting::aggregator aggregator; nano::wallets wallets; nano::backlog_population backlog; nano::bootstrap_ascending::service ascendboot; diff --git a/nano/node/voting/request_aggregator.cpp b/nano/node/voting/aggregator.cpp similarity index 92% rename from nano/node/voting/request_aggregator.cpp rename to nano/node/voting/aggregator.cpp index f0c2a62364..95b89979b5 100644 --- a/nano/node/voting/request_aggregator.cpp +++ b/nano/node/voting/aggregator.cpp @@ -4,14 +4,14 @@ #include #include #include +#include #include #include -#include #include #include #include -nano::request_aggregator::request_aggregator (nano::node_config const & config_a, nano::stats & stats_a, nano::voting::generator & generator_a, nano::voting::generator & final_generator_a, nano::voting::history & history_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::active_transactions & active_a) : +nano::voting::aggregator::aggregator (nano::node_config const & config_a, nano::stats & stats_a, nano::voting::generator & generator_a, nano::voting::generator & final_generator_a, nano::voting::history & history_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::active_transactions & active_a) : config{ config_a }, max_delay (config_a.network_params.network.is_dev_network () ? 50 : 300), small_delay (config_a.network_params.network.is_dev_network () ? 10 : 50), @@ -35,7 +35,7 @@ nano::request_aggregator::request_aggregator (nano::node_config const & config_a condition.wait (lock, [&started = started] { return started; }); } -void nano::request_aggregator::add (std::shared_ptr const & channel_a, std::vector> const & hashes_roots_a) +void nano::voting::aggregator::add (std::shared_ptr const & channel_a, std::vector> const & hashes_roots_a) { debug_assert (wallets.reps ().voting > 0); bool error = true; @@ -71,7 +71,7 @@ void nano::request_aggregator::add (std::shared_ptr co stats.inc (nano::stat::type::aggregator, !error ? nano::stat::detail::aggregator_accepted : nano::stat::detail::aggregator_dropped); } -void nano::request_aggregator::run () +void nano::voting::aggregator::run () { nano::thread_role::set (nano::thread_role::name::request_aggregator); nano::unique_lock lock{ mutex }; @@ -125,7 +125,7 @@ void nano::request_aggregator::run () } } -void nano::request_aggregator::stop () +void nano::voting::aggregator::stop () { { nano::lock_guard guard{ mutex }; @@ -138,24 +138,24 @@ void nano::request_aggregator::stop () } } -std::size_t nano::request_aggregator::size () +std::size_t nano::voting::aggregator::size () { nano::unique_lock lock{ mutex }; return requests.size (); } -bool nano::request_aggregator::empty () +bool nano::voting::aggregator::empty () { return size () == 0; } -void nano::request_aggregator::reply_action (std::shared_ptr const & vote_a, std::shared_ptr const & channel_a) const +void nano::voting::aggregator::reply_action (std::shared_ptr const & vote_a, std::shared_ptr const & channel_a) const { nano::confirm_ack confirm{ config.network_params.network, vote_a }; channel_a->send (confirm); } -void nano::request_aggregator::erase_duplicates (std::vector> & requests_a) const +void nano::voting::aggregator::erase_duplicates (std::vector> & requests_a) const { std::sort (requests_a.begin (), requests_a.end (), [] (auto const & pair1, auto const & pair2) { return pair1.first < pair2.first; @@ -166,7 +166,7 @@ void nano::request_aggregator::erase_duplicates (std::vector>, std::vector>> nano::request_aggregator::aggregate (std::vector> const & requests_a, std::shared_ptr & channel_a) const +std::pair>, std::vector>> nano::voting::aggregator::aggregate (std::vector> const & requests_a, std::shared_ptr & channel_a) const { auto transaction (ledger.store.tx_begin_read ()); std::vector> to_generate; @@ -311,7 +311,7 @@ std::pair>, std::vector nano::collect_container_info (nano::request_aggregator & aggregator, std::string const & name) +std::unique_ptr nano::voting::collect_container_info (nano::voting::aggregator & aggregator, std::string const & name) { auto pools_count = aggregator.size (); auto sizeof_element = sizeof (decltype (aggregator.requests)::value_type); diff --git a/nano/node/voting/request_aggregator.hpp b/nano/node/voting/aggregator.hpp similarity index 91% rename from nano/node/voting/request_aggregator.hpp rename to nano/node/voting/aggregator.hpp index b592155a8e..beb114e5c7 100644 --- a/nano/node/voting/request_aggregator.hpp +++ b/nano/node/voting/aggregator.hpp @@ -28,7 +28,10 @@ class ledger; class node_config; class stats; class wallets; +} +namespace nano::voting +{ /** * Pools together confirmation requests, separately for each endpoint. * Requests are added from network messages, and aggregated to minimize bandwidth and vote generation. Example: @@ -37,7 +40,7 @@ class wallets; * * The aggregator will reply with the two cached votes * Votes are generated for uncached hashes. */ -class request_aggregator final +class aggregator final { /** * Holds a buffer of incoming requests from an endpoint. @@ -64,7 +67,7 @@ class request_aggregator final // clang-format on public: - request_aggregator (nano::node_config const & config, nano::stats & stats_a, nano::voting::generator &, nano::voting::generator &, nano::voting::history &, nano::ledger &, nano::wallets &, nano::active_transactions &); + aggregator (nano::node_config const & config, nano::stats & stats_a, nano::voting::generator &, nano::voting::generator &, nano::voting::history &, nano::ledger &, nano::wallets &, nano::active_transactions &); /** Add a new request by \p channel_a for hashes \p hashes_roots_a */ void add (std::shared_ptr const & channel_a, std::vector> const & hashes_roots_a); @@ -110,7 +113,7 @@ class request_aggregator final nano::mutex mutex{ mutex_identifier (mutexes::request_aggregator) }; std::thread thread; - friend std::unique_ptr collect_container_info (request_aggregator &, std::string const &); + friend std::unique_ptr collect_container_info (aggregator &, std::string const &); }; -std::unique_ptr collect_container_info (request_aggregator &, std::string const &); -} +std::unique_ptr collect_container_info (aggregator &, std::string const &); +} // namespace nano::voting From d8371cf7280edc4536def083507d4ad108572928 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 1 Nov 2023 16:44:36 +0000 Subject: [PATCH 13/13] Rename nano::vote_spacing to nano::voting::spacing --- nano/core_test/voting.cpp | 4 ++-- nano/node/voting/generator.hpp | 2 +- nano/node/voting/spacing.cpp | 8 ++++---- nano/node/voting/spacing.hpp | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index 8ff85771d0..1b8dc6c043 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -105,7 +105,7 @@ TEST (vote_generator, multiple_representatives) TEST (vote_spacing, basic) { - nano::vote_spacing spacing{ std::chrono::milliseconds{ 100 } }; + nano::voting::spacing spacing{ std::chrono::milliseconds{ 100 } }; nano::root root1{ 1 }; nano::root root2{ 2 }; nano::block_hash hash3{ 3 }; @@ -124,7 +124,7 @@ TEST (vote_spacing, basic) TEST (vote_spacing, prune) { auto length = std::chrono::milliseconds{ 100 }; - nano::vote_spacing spacing{ length }; + nano::voting::spacing spacing{ length }; nano::root root1{ 1 }; nano::root root2{ 2 }; nano::block_hash hash3{ 3 }; diff --git a/nano/node/voting/generator.hpp b/nano/node/voting/generator.hpp index d722f94818..e5546d6a71 100644 --- a/nano/node/voting/generator.hpp +++ b/nano/node/voting/generator.hpp @@ -76,7 +76,7 @@ class generator final nano::wallets & wallets; nano::voting::processor & vote_processor; nano::voting::history & history; - nano::vote_spacing spacing; + nano::voting::spacing spacing; nano::network & network; nano::stats & stats; diff --git a/nano/node/voting/spacing.cpp b/nano/node/voting/spacing.cpp index de44e528a1..c98d1de69e 100644 --- a/nano/node/voting/spacing.cpp +++ b/nano/node/voting/spacing.cpp @@ -1,11 +1,11 @@ #include -void nano::vote_spacing::trim () +void nano::voting::spacing::trim () { recent.get ().erase (recent.get ().begin (), recent.get ().upper_bound (std::chrono::steady_clock::now () - delay)); } -bool nano::vote_spacing::votable (nano::root const & root_a, nano::block_hash const & hash_a) const +bool nano::voting::spacing::votable (nano::root const & root_a, nano::block_hash const & hash_a) const { bool result = true; for (auto range = recent.get ().equal_range (root_a); result && range.first != range.second; ++range.first) @@ -16,7 +16,7 @@ bool nano::vote_spacing::votable (nano::root const & root_a, nano::block_hash co return result; } -void nano::vote_spacing::flag (nano::root const & root_a, nano::block_hash const & hash_a) +void nano::voting::spacing::flag (nano::root const & root_a, nano::block_hash const & hash_a) { trim (); auto now = std::chrono::steady_clock::now (); @@ -33,7 +33,7 @@ void nano::vote_spacing::flag (nano::root const & root_a, nano::block_hash const } } -std::size_t nano::vote_spacing::size () const +std::size_t nano::voting::spacing::size () const { return recent.size (); } diff --git a/nano/node/voting/spacing.hpp b/nano/node/voting/spacing.hpp index 5895bd1a2f..86a44237e3 100644 --- a/nano/node/voting/spacing.hpp +++ b/nano/node/voting/spacing.hpp @@ -12,9 +12,9 @@ namespace mi = boost::multi_index; -namespace nano +namespace nano::voting { -class vote_spacing final +class spacing final { class entry { @@ -35,7 +35,7 @@ class vote_spacing final void trim (); public: - vote_spacing (std::chrono::milliseconds const & delay) : + spacing (std::chrono::milliseconds const & delay) : delay{ delay } { }