From e66683fa60930f1ebc42b46a60ee48199c1dedbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 2 Sep 2024 21:24:03 +0200 Subject: [PATCH 01/14] Rework backlog population config --- nano/core_test/toml.cpp | 22 +++++++++++++-------- nano/node/backlog_population.cpp | 34 ++++++++++++++++++++++++++------ nano/node/backlog_population.hpp | 32 ++++++++++++++++-------------- nano/node/node.cpp | 11 +---------- nano/node/node.hpp | 1 - nano/node/nodeconfig.cpp | 27 ++++++++++++++++++++----- nano/node/nodeconfig.hpp | 6 ++---- 7 files changed, 84 insertions(+), 49 deletions(-) diff --git a/nano/core_test/toml.cpp b/nano/core_test/toml.cpp index ce861da1d8..0f7258c9bb 100644 --- a/nano/core_test/toml.cpp +++ b/nano/core_test/toml.cpp @@ -116,6 +116,7 @@ TEST (toml, daemon_config_deserialize_defaults) std::stringstream ss; ss << R"toml( [node] + [node.backlog_population] [node.bootstrap_ascending] [node.bootstrap_server] [node.block_processor] @@ -197,8 +198,9 @@ TEST (toml, daemon_config_deserialize_defaults) ASSERT_EQ (conf.node.max_queued_requests, defaults.node.max_queued_requests); ASSERT_EQ (conf.node.request_aggregator_threads, defaults.node.request_aggregator_threads); ASSERT_EQ (conf.node.max_unchecked_blocks, defaults.node.max_unchecked_blocks); - ASSERT_EQ (conf.node.backlog_scan_batch_size, defaults.node.backlog_scan_batch_size); - ASSERT_EQ (conf.node.backlog_scan_frequency, defaults.node.backlog_scan_frequency); + ASSERT_EQ (conf.node.backlog_population.enable, defaults.node.backlog_population.enable); + ASSERT_EQ (conf.node.backlog_population.batch_size, defaults.node.backlog_population.batch_size); + ASSERT_EQ (conf.node.backlog_population.frequency, defaults.node.backlog_population.frequency); ASSERT_EQ (conf.node.enable_upnp, defaults.node.enable_upnp); ASSERT_EQ (conf.node.websocket_config.enabled, defaults.node.websocket_config.enabled); @@ -462,10 +464,13 @@ TEST (toml, daemon_config_deserialize_no_defaults) request_aggregator_threads = 999 max_unchecked_blocks = 999 frontiers_confirmation = "always" - backlog_scan_batch_size = 999 - backlog_scan_frequency = 999 enable_upnp = false + [node.backlog_population] + enable = false + batch_size = 999 + frequency = 999 + [node.block_processor] max_peer_queue = 999 max_system_queue = 999 @@ -700,8 +705,9 @@ TEST (toml, daemon_config_deserialize_no_defaults) ASSERT_NE (conf.node.work_threads, defaults.node.work_threads); ASSERT_NE (conf.node.max_queued_requests, defaults.node.max_queued_requests); ASSERT_NE (conf.node.request_aggregator_threads, defaults.node.request_aggregator_threads); - ASSERT_NE (conf.node.backlog_scan_batch_size, defaults.node.backlog_scan_batch_size); - ASSERT_NE (conf.node.backlog_scan_frequency, defaults.node.backlog_scan_frequency); + ASSERT_NE (conf.node.backlog_population.enable, defaults.node.backlog_population.enable); + ASSERT_NE (conf.node.backlog_population.batch_size, defaults.node.backlog_population.batch_size); + ASSERT_NE (conf.node.backlog_population.frequency, defaults.node.backlog_population.frequency); ASSERT_NE (conf.node.enable_upnp, defaults.node.enable_upnp); ASSERT_NE (conf.node.websocket_config.enabled, defaults.node.websocket_config.enabled); @@ -1090,7 +1096,7 @@ TEST (toml, merge_config_files) ss << R"toml( [node] active_elections.size = 999 - # backlog_scan_batch_size = 7777 + # background_threads = 7777 [node.bootstrap_ascending] block_processor_threshold = 33333 old_entry = 34 @@ -1114,7 +1120,7 @@ TEST (toml, merge_config_files) ASSERT_NE (merged_config.node.active_elections.size, default_config.node.active_elections.size); ASSERT_EQ (merged_config.node.active_elections.size, 999); - ASSERT_NE (merged_config.node.backlog_scan_batch_size, 7777); + ASSERT_NE (merged_config.node.background_threads, 7777); ASSERT_EQ (merged_config.node.bootstrap_ascending.block_processor_threshold, 33333); ASSERT_TRUE (merged_config_string.find ("old_entry") == std::string::npos); } \ No newline at end of file diff --git a/nano/node/backlog_population.cpp b/nano/node/backlog_population.cpp index 89965282fb..cb121dcb61 100644 --- a/nano/node/backlog_population.cpp +++ b/nano/node/backlog_population.cpp @@ -8,8 +8,8 @@ #include #include -nano::backlog_population::backlog_population (const config & config_a, nano::scheduler::component & schedulers, nano::ledger & ledger, nano::stats & stats_a) : - config_m{ config_a }, +nano::backlog_population::backlog_population (backlog_population_config const & config_a, nano::scheduler::component & schedulers, nano::ledger & ledger, nano::stats & stats_a) : + config{ config_a }, schedulers{ schedulers }, ledger{ ledger }, stats{ stats_a } @@ -58,7 +58,7 @@ void nano::backlog_population::notify () bool nano::backlog_population::predicate () const { - return triggered || config_m.enabled; + return triggered || config.enable; } void nano::backlog_population::run () @@ -82,9 +82,9 @@ void nano::backlog_population::run () void nano::backlog_population::populate_backlog (nano::unique_lock & lock) { - debug_assert (config_m.frequency > 0); + debug_assert (config.frequency > 0); - const auto chunk_size = config_m.batch_size / config_m.frequency; + const auto chunk_size = config.batch_size / config.frequency; auto done = false; nano::account next = 0; uint64_t total = 0; @@ -121,7 +121,7 @@ void nano::backlog_population::populate_backlog (nano::unique_lock lock.lock (); // Give the rest of the node time to progress without holding database lock - condition.wait_for (lock, std::chrono::milliseconds{ 1000 / config_m.frequency }); + condition.wait_for (lock, std::chrono::milliseconds{ 1000 / config.frequency }); } } @@ -141,3 +141,25 @@ void nano::backlog_population::activate (secure::transaction const & transaction schedulers.priority.activate (transaction, account, account_info, conf_info); } } + +/* + * backlog_population_config + */ + +nano::error nano::backlog_population_config::serialize (nano::tomlconfig & toml) const +{ + toml.put ("enable", enable, "Control if ongoing backlog population is enabled. If not, backlog population can still be triggered by RPC \ntype:bool"); + toml.put ("batch_size", batch_size, "Number of accounts per second to process when doing backlog population scan. Increasing this value will help unconfirmed frontiers get into election prioritization queue faster, however it will also increase resource usage. \ntype:uint"); + toml.put ("frequency", frequency, "Backlog scan divides the scan into smaller batches, number of which is controlled by this value. Higher frequency helps to utilize resources more uniformly, however it also introduces more overhead. The resulting number of accounts per single batch is `backlog_scan_batch_size / backlog_scan_frequency` \ntype:uint"); + + return toml.get_error (); +} + +nano::error nano::backlog_population_config::deserialize (nano::tomlconfig & toml) +{ + toml.get ("enable", enable); + toml.get ("batch_size", batch_size); + toml.get ("frequency", frequency); + + return toml.get_error (); +} diff --git a/nano/node/backlog_population.hpp b/nano/node/backlog_population.hpp index 01ec3debe3..37123f4ba9 100644 --- a/nano/node/backlog_population.hpp +++ b/nano/node/backlog_population.hpp @@ -20,22 +20,25 @@ class election_scheduler; class ledger; class stats; -class backlog_population final +class backlog_population_config final { public: - struct config - { - /** Control if ongoing backlog population is enabled. If not, backlog population can still be triggered by RPC */ - bool enabled; - - /** Number of accounts per second to process. Number of accounts per single batch is this value divided by `frequency` */ - unsigned batch_size; + nano::error deserialize (nano::tomlconfig &); + nano::error serialize (nano::tomlconfig &) const; - /** Number of batches to run per second. Batches run in 1 second / `frequency` intervals */ - unsigned frequency; - }; +public: + /** Control if ongoing backlog population is enabled. If not, backlog population can still be triggered by RPC */ + bool enable{ true }; + /** Number of accounts per second to process. Number of accounts per single batch is this value divided by `frequency` */ + unsigned batch_size{ 10 * 1000 }; + /** Number of batches to run per second. Batches run in 1 second / `frequency` intervals */ + unsigned frequency{ 10 }; +}; - backlog_population (const config &, nano::scheduler::component &, nano::ledger &, nano::stats &); +class backlog_population final +{ +public: + backlog_population (backlog_population_config const &, nano::scheduler::component &, nano::ledger &, nano::stats &); ~backlog_population (); void start (); @@ -55,19 +58,18 @@ class backlog_population final callback_t activate_callback; private: // Dependencies + backlog_population_config const & config; nano::scheduler::component & schedulers; nano::ledger & ledger; nano::stats & stats; - config config_m; - private: void run (); bool predicate () const; - void populate_backlog (nano::unique_lock & lock); void activate (secure::transaction const &, nano::account const &, nano::account_info const &); +private: /** This is a manual trigger, the ongoing backlog population does not use this. * It can be triggered even when backlog population (frontiers confirmation) is disabled. */ bool triggered{ false }; diff --git a/nano/node/node.cpp b/nano/node/node.cpp index adeb925acb..79546af427 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -58,15 +58,6 @@ extern std::size_t nano_bootstrap_weights_beta_size; * configs */ -nano::backlog_population::config nano::backlog_population_config (const nano::node_config & config) -{ - nano::backlog_population::config cfg{}; - cfg.enabled = config.frontiers_confirmation != nano::frontiers_confirmation_mode::disabled; - cfg.frequency = config.backlog_scan_frequency; - cfg.batch_size = config.backlog_scan_batch_size; - return cfg; -} - nano::outbound_bandwidth_limiter::config nano::outbound_bandwidth_limiter_config (const nano::node_config & config) { outbound_bandwidth_limiter::config cfg{}; @@ -218,7 +209,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy aggregator_impl{ std::make_unique (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) }, aggregator{ *aggregator_impl }, wallets (wallets_store.init_error (), *this), - backlog{ nano::backlog_population_config (config), scheduler, ledger, stats }, + backlog{ config.backlog_population, scheduler, ledger, stats }, ascendboot_impl{ std::make_unique (config, block_processor, ledger, network, stats, logger) }, ascendboot{ *ascendboot_impl }, websocket{ config.websocket_config, observers, wallets, ledger, io_ctx, logger }, diff --git a/nano/node/node.hpp b/nano/node/node.hpp index c24ca6a290..e607244179 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -73,7 +73,6 @@ namespace rocksdb namespace nano { // Configs -backlog_population::config backlog_population_config (node_config const &); outbound_bandwidth_limiter::config outbound_bandwidth_limiter_config (node_config const &); class node final : public std::enable_shared_from_this diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index 9449df5ca9..7ddf340ed0 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -143,8 +143,6 @@ nano::error nano::node_config::serialize_toml (nano::tomlconfig & toml) const toml.put ("request_aggregator_threads", request_aggregator_threads, "Number of threads to dedicate to request aggregator. Defaults to using all cpu threads, up to a maximum of 4"); toml.put ("max_unchecked_blocks", max_unchecked_blocks, "Maximum number of unchecked blocks to store in memory. Defaults to 65536. \ntype:uint64,[0..]"); toml.put ("rep_crawler_weight_minimum", rep_crawler_weight_minimum.to_string_dec (), "Rep crawler minimum weight, if this is less than minimum principal weight then this is taken as the minimum weight a rep must have to be tracked. If you want to track all reps set this to 0. If you do not want this to influence anything then set it to max value. This is only useful for debugging or for people who really know what they are doing.\ntype:string,amount,raw"); - toml.put ("backlog_scan_batch_size", backlog_scan_batch_size, "Number of accounts per second to process when doing backlog population scan. Increasing this value will help unconfirmed frontiers get into election prioritization queue faster, however it will also increase resource usage. \ntype:uint"); - toml.put ("backlog_scan_frequency", backlog_scan_frequency, "Backlog scan divides the scan into smaller batches, number of which is controlled by this value. Higher frequency helps to utilize resources more uniformly, however it also introduces more overhead. The resulting number of accounts per single batch is `backlog_scan_batch_size / backlog_scan_frequency` \ntype:uint"); toml.put ("enable_upnp", enable_upnp, "Enable or disable automatic UPnP port forwarding. This feature only works if the node is directly connected to a router (not inside a docker container, etc.).\ntype:bool"); auto work_peers_l (toml.create_array ("work_peers", "A list of \"address:port\" entries to identify work peers.")); @@ -182,6 +180,10 @@ nano::error nano::node_config::serialize_toml (nano::tomlconfig & toml) const callback_l.put ("target", callback_target, "Callback target path.\ntype:string,uri"); toml.put_child ("httpcallback", callback_l); + /* + * Subconfigs + */ + nano::tomlconfig websocket_l; websocket_config.serialize_toml (websocket_l); toml.put_child ("websocket", websocket_l); @@ -258,6 +260,10 @@ nano::error nano::node_config::serialize_toml (nano::tomlconfig & toml) const monitor.serialize (monitor_l); toml.put_child ("monitor", monitor_l); + nano::tomlconfig backlog_population_l; + backlog_population.serialize (backlog_population_l); + toml.put_child ("backlog_population", backlog_population_l); + return toml.get_error (); } @@ -273,6 +279,10 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) callback_l.get ("target", callback_target); } + /* + * Subconfigs + */ + if (toml.has_key ("websocket")) { auto websocket_config_l (toml.get_required_child ("websocket")); @@ -387,6 +397,16 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) monitor.deserialize (config_l); } + if (toml.has_key ("backlog_population")) + { + auto config_l = toml.get_required_child ("backlog_population"); + backlog_population.deserialize (config_l); + } + + /* + * Values + */ + if (toml.has_key ("work_peers")) { work_peers.clear (); @@ -553,9 +573,6 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) frontiers_confirmation = deserialize_frontiers_confirmation (frontiers_confirmation_l); } - toml.get ("backlog_scan_batch_size", backlog_scan_batch_size); - toml.get ("backlog_scan_frequency", backlog_scan_frequency); - toml.get ("enable_upnp", enable_upnp); if (toml.has_key ("experimental")) diff --git a/nano/node/nodeconfig.hpp b/nano/node/nodeconfig.hpp index 90b04298d0..10f6732361 100644 --- a/nano/node/nodeconfig.hpp +++ b/nano/node/nodeconfig.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -143,10 +144,6 @@ class node_config nano::rocksdb_config rocksdb_config; nano::lmdb_config lmdb_config; nano::frontiers_confirmation_mode frontiers_confirmation{ nano::frontiers_confirmation_mode::automatic }; - /** Number of accounts per second to process when doing backlog population scan */ - 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 }; bool enable_upnp{ true }; nano::vote_cache_config vote_cache; nano::rep_crawler_config rep_crawler; @@ -161,6 +158,7 @@ class node_config nano::local_block_broadcaster_config local_block_broadcaster; nano::confirming_set_config confirming_set; nano::monitor_config monitor; + nano::backlog_population_config backlog_population; public: std::string serialize_frontiers_confirmation (nano::frontiers_confirmation_mode) const; From fd0a99945993e5b91514de86b8e11cf6935584e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:52:46 +0200 Subject: [PATCH 02/14] Remove `frontiers_confirmation_mode` --- nano/core_test/CMakeLists.txt | 1 - nano/core_test/active_elections.cpp | 24 +++---- nano/core_test/backlog.cpp | 28 ++++++++ nano/core_test/bootstrap.cpp | 48 ++++++------- nano/core_test/confirming_set.cpp | 6 +- nano/core_test/election.cpp | 10 +-- nano/core_test/election_scheduler.cpp | 2 +- nano/core_test/frontiers_confirmation.cpp | 84 ----------------------- nano/core_test/ledger.cpp | 4 +- nano/core_test/ledger_confirm.cpp | 8 +-- nano/core_test/node.cpp | 46 ++++++------- nano/core_test/optimistic_scheduler.cpp | 2 +- nano/core_test/request_aggregator.cpp | 14 ++-- nano/core_test/toml.cpp | 18 ----- nano/core_test/vote_processor.cpp | 14 ++-- nano/core_test/voting.cpp | 4 +- nano/core_test/wallet.cpp | 2 +- nano/core_test/wallets.cpp | 2 +- nano/nano_node/entry.cpp | 1 - nano/node/nodeconfig.cpp | 46 ------------- nano/node/nodeconfig.hpp | 13 ---- nano/rpc_test/receivable.cpp | 4 +- nano/rpc_test/rpc.cpp | 8 +-- nano/slow_test/node.cpp | 18 ++--- nano/slow_test/vote_cache.cpp | 4 +- 25 files changed, 138 insertions(+), 273 deletions(-) delete mode 100644 nano/core_test/frontiers_confirmation.cpp diff --git a/nano/core_test/CMakeLists.txt b/nano/core_test/CMakeLists.txt index b53c4a4deb..e5b47c9e43 100644 --- a/nano/core_test/CMakeLists.txt +++ b/nano/core_test/CMakeLists.txt @@ -23,7 +23,6 @@ add_executable( enums.cpp epochs.cpp fair_queue.cpp - frontiers_confirmation.cpp ipc.cpp ledger.cpp ledger_confirm.cpp diff --git a/nano/core_test/active_elections.cpp b/nano/core_test/active_elections.cpp index fd94659a50..2c6bbc6824 100644 --- a/nano/core_test/active_elections.cpp +++ b/nano/core_test/active_elections.cpp @@ -166,7 +166,7 @@ TEST (active_elections, DISABLED_keep_local) // Bound to 2, won't drop wallet created transactions, but good to test dropping remote node_config.active_elections.size = 2; // Disable frontier confirmation to allow the test to finish before - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node = *system.add_node (node_config); auto & wallet (*system.wallet (0)); @@ -326,7 +326,7 @@ TEST (inactive_votes_cache, existing_vote) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node = *system.add_node (node_config); nano::block_hash latest (node.latest (nano::dev::genesis_key.pub)); nano::keypair key; @@ -380,7 +380,7 @@ TEST (inactive_votes_cache, multiple_votes) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node = *system.add_node (node_config); nano::keypair key1; nano::block_builder builder; @@ -433,7 +433,7 @@ TEST (inactive_votes_cache, election_start) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; node_config.priority_scheduler.enabled = false; node_config.optimistic_scheduler.enabled = false; auto & node = *system.add_node (node_config); @@ -539,7 +539,7 @@ TEST (active_elections, vote_replays) nano::test::system system; nano::node_config node_config = system.default_config (); node_config.enable_voting = false; - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node = *system.add_node (node_config); nano::keypair key; nano::state_block_builder builder; @@ -695,7 +695,7 @@ TEST (active_elections, republish_winner) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 = *system.add_node (node_config); node_config.peering_port = system.get_available_port (); auto & node2 = *system.add_node (node_config); @@ -761,7 +761,7 @@ TEST (active_elections, fork_filter_cleanup) nano::test::system system{}; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 = *system.add_node (node_config); nano::keypair key{}; @@ -842,7 +842,7 @@ TEST (active_elections, fork_replacement_tally) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 (*system.add_node (node_config)); size_t const reps_count = 20; @@ -999,7 +999,7 @@ TEST (active_elections, confirmation_consistency) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node = *system.add_node (node_config); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); for (unsigned i = 0; i < 10; ++i) @@ -1091,7 +1091,7 @@ TEST (active_elections, activate_account_chain) nano::test::system system; nano::node_flags flags; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto & node = *system.add_node (config, flags); nano::keypair key; @@ -1183,7 +1183,7 @@ TEST (active_elections, activate_inactive) nano::test::system system; nano::node_flags flags; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto & node = *system.add_node (config, flags); nano::keypair key; @@ -1331,7 +1331,7 @@ TEST (active_elections, limit_vote_hinted_elections) nano::test::system system; nano::node_config config = system.default_config (); const int aec_limit = 10; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; config.optimistic_scheduler.enabled = false; config.active_elections.size = aec_limit; config.active_elections.hinted_limit_percentage = 10; // Should give us a limit of 1 hinted election diff --git a/nano/core_test/backlog.cpp b/nano/core_test/backlog.cpp index 543547b1a1..9af36e8e22 100644 --- a/nano/core_test/backlog.cpp +++ b/nano/core_test/backlog.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -46,3 +47,30 @@ TEST (backlog, population) ASSERT_TIMELY (5s, all_activated ()); } + +/* + * Ensures that elections are activated without live traffic + */ +TEST (backlog, election_activation) +{ + nano::test::system system; + nano::node_config node_config = system.default_config (); + auto & node = *system.add_node (node_config); + nano::keypair key; + nano::block_builder builder; + auto send = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (nano::dev::genesis->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) + .link (key.pub) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*node.work_generate_blocking (nano::dev::genesis->hash ())) + .build (); + { + auto transaction = node.ledger.tx_begin_write (); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (transaction, send)); + } + ASSERT_TIMELY_EQ (5s, node.active.size (), 1); +} \ No newline at end of file diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index 58836e3677..70834a6e12 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -305,7 +305,7 @@ TEST (bootstrap_processor, process_one) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; node_config.enable_voting = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; @@ -327,7 +327,7 @@ TEST (bootstrap_processor, process_two) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; auto node0 (system.add_node (config, node_flags)); @@ -348,7 +348,7 @@ TEST (bootstrap_processor, process_state) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; auto node0 (system.add_node (config, node_flags)); @@ -392,7 +392,7 @@ TEST (bootstrap_processor, process_new) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; nano::keypair key2; @@ -430,7 +430,7 @@ TEST (bootstrap_processor, pull_diamond) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; auto node0 (system.add_node (config, node_flags)); @@ -482,7 +482,7 @@ TEST (bootstrap_processor, DISABLED_pull_requeue_network_error) // Bootstrap attempt stopped before requeue & then cannot be found in attempts list nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; auto node1 (system.add_node (config, node_flags)); @@ -574,7 +574,7 @@ TEST (bootstrap_processor, push_diamond) ASSERT_EQ (nano::block_status::progress, node1->process (receive)); nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags flags; flags.disable_ongoing_bootstrap = true; flags.disable_ascending_bootstrap = true; @@ -587,7 +587,7 @@ TEST (bootstrap_processor, push_diamond_pruning) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags0; node_flags0.disable_ascending_bootstrap = true; node_flags0.disable_ongoing_bootstrap = true; @@ -678,7 +678,7 @@ TEST (bootstrap_processor, push_one) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto node0 (system.add_node (config)); nano::keypair key1; auto node1 = system.make_disconnected_node (); @@ -700,7 +700,7 @@ TEST (bootstrap_processor, lazy_hash) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; auto node0 (system.add_node (config, node_flags)); @@ -774,7 +774,7 @@ TEST (bootstrap_processor, lazy_hash_bootstrap_id) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; auto node0 (system.add_node (config, node_flags)); @@ -848,7 +848,7 @@ TEST (bootstrap_processor, lazy_hash_pruning) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; config.enable_voting = false; // Remove after allowing pruned voting nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; @@ -994,7 +994,7 @@ TEST (bootstrap_processor, lazy_max_pull_count) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; auto node0 (system.add_node (config, node_flags)); @@ -1095,7 +1095,7 @@ TEST (bootstrap_processor, lazy_unclear_state_link) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_legacy_bootstrap = true; @@ -1163,7 +1163,7 @@ TEST (bootstrap_processor, lazy_unclear_state_link_not_existing) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_legacy_bootstrap = true; @@ -1221,7 +1221,7 @@ TEST (bootstrap_processor, lazy_destinations) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_legacy_bootstrap = true; @@ -1299,7 +1299,7 @@ TEST (bootstrap_processor, lazy_pruning_missing_block) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; config.enable_voting = false; // Remove after allowing pruned voting nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; @@ -1406,7 +1406,7 @@ TEST (bootstrap_processor, lazy_cancel) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; auto node0 (system.add_node (config, node_flags)); @@ -1440,7 +1440,7 @@ TEST (bootstrap_processor, wallet_lazy_frontier) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_legacy_bootstrap = true; @@ -1520,7 +1520,7 @@ TEST (bootstrap_processor, wallet_lazy_pending) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_legacy_bootstrap = true; @@ -1584,7 +1584,7 @@ TEST (bootstrap_processor, multiple_attempts) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; auto node1 = system.add_node (config, node_flags); @@ -1945,7 +1945,7 @@ TEST (bulk, genesis) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_lazy_bootstrap = true; @@ -1971,7 +1971,7 @@ TEST (bulk, offline_send) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_lazy_bootstrap = true; @@ -2010,7 +2010,7 @@ TEST (bulk, genesis_pruning) { nano::test::system system; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; config.enable_voting = false; // Remove after allowing pruned voting nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; diff --git a/nano/core_test/confirming_set.cpp b/nano/core_test/confirming_set.cpp index 31ca879511..47b8eaf7ee 100644 --- a/nano/core_test/confirming_set.cpp +++ b/nano/core_test/confirming_set.cpp @@ -73,7 +73,7 @@ TEST (confirmation_callback, observer_callbacks) nano::test::system system; nano::node_flags node_flags; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config, node_flags); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -122,7 +122,7 @@ TEST (confirmation_callback, confirmed_history) node_flags.force_use_write_queue = true; node_flags.disable_ascending_bootstrap = true; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config, node_flags); nano::block_hash latest (node->latest (nano::dev::genesis_key.pub)); @@ -196,7 +196,7 @@ TEST (confirmation_callback, dependent_election) nano::node_flags node_flags; node_flags.force_use_write_queue = true; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config, node_flags); nano::block_hash latest (node->latest (nano::dev::genesis_key.pub)); diff --git a/nano/core_test/election.cpp b/nano/core_test/election.cpp index 0ad811ab4f..200f84ffbb 100644 --- a/nano/core_test/election.cpp +++ b/nano/core_test/election.cpp @@ -36,7 +36,7 @@ TEST (election, quorum_minimum_flip_success) nano::node_config node_config = system.default_config (); node_config.online_weight_minimum = nano::dev::constants.genesis_amount; - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 = *system.add_node (node_config); auto const latest_hash = nano::dev::genesis->hash (); @@ -86,7 +86,7 @@ TEST (election, quorum_minimum_flip_fail) nano::test::system system; nano::node_config node_config = system.default_config (); node_config.online_weight_minimum = nano::dev::constants.genesis_amount; - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node = *system.add_node (node_config); nano::state_block_builder builder; @@ -137,7 +137,7 @@ TEST (election, quorum_minimum_confirm_success) nano::test::system system; nano::node_config node_config = system.default_config (); node_config.online_weight_minimum = nano::dev::constants.genesis_amount; - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 = *system.add_node (node_config); nano::keypair key1; nano::block_builder builder; @@ -167,7 +167,7 @@ TEST (election, quorum_minimum_confirm_fail) nano::test::system system; nano::node_config node_config = system.default_config (); node_config.online_weight_minimum = nano::dev::constants.genesis_amount; - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 = *system.add_node (node_config); nano::block_builder builder; @@ -205,7 +205,7 @@ TEST (election, quorum_minimum_update_weight_before_quorum_checks) nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 = *system.add_node (node_config); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); diff --git a/nano/core_test/election_scheduler.cpp b/nano/core_test/election_scheduler.cpp index 114f2028ef..a4c5b7fd05 100644 --- a/nano/core_test/election_scheduler.cpp +++ b/nano/core_test/election_scheduler.cpp @@ -178,7 +178,7 @@ TEST (election_scheduler, no_vacancy) nano::node_config config = system.default_config (); config.active_elections.size = 1; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto & node = *system.add_node (config); nano::state_block_builder builder{}; diff --git a/nano/core_test/frontiers_confirmation.cpp b/nano/core_test/frontiers_confirmation.cpp deleted file mode 100644 index 89c19752b9..0000000000 --- a/nano/core_test/frontiers_confirmation.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -using namespace std::chrono_literals; - -TEST (frontiers_confirmation, mode) -{ - nano::keypair key; - nano::block_builder builder; - nano::node_flags node_flags; - // Always mode - { - nano::test::system system; - nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::always; - auto node = system.add_node (node_config, node_flags); - auto send = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (key.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*node->work_generate_blocking (nano::dev::genesis->hash ())) - .build (); - { - auto transaction = node->ledger.tx_begin_write (); - ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); - } - ASSERT_TIMELY_EQ (5s, node->active.size (), 1); - } - // Auto mode - { - nano::test::system system; - nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::automatic; - auto node = system.add_node (node_config, node_flags); - auto send = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (key.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*node->work_generate_blocking (nano::dev::genesis->hash ())) - .build (); - { - auto transaction = node->ledger.tx_begin_write (); - ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); - } - ASSERT_TIMELY_EQ (5s, node->active.size (), 1); - } - // Disabled mode - { - nano::test::system system; - nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; - auto node = system.add_node (node_config, node_flags); - auto send = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (key.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*node->work_generate_blocking (nano::dev::genesis->hash ())) - .build (); - { - auto transaction = node->ledger.tx_begin_write (); - ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); - } - system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); - std::this_thread::sleep_for (std::chrono::seconds (1)); - ASSERT_EQ (0, node->active.size ()); - } -} diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 1156ad11a8..e3c29610c3 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -1017,7 +1017,7 @@ TEST (votes, add_existing) nano::test::system system; nano::node_config node_config = system.default_config (); node_config.online_weight_minimum = nano::dev::constants.genesis_amount; - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 = *system.add_node (node_config); nano::keypair key1; nano::block_builder builder; @@ -4266,7 +4266,7 @@ TEST (ledger, unchecked_epoch_invalid) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 (*system.add_node (node_config)); nano::keypair destination; nano::block_builder builder; diff --git a/nano/core_test/ledger_confirm.cpp b/nano/core_test/ledger_confirm.cpp index 5729369a06..65f351bacc 100644 --- a/nano/core_test/ledger_confirm.cpp +++ b/nano/core_test/ledger_confirm.cpp @@ -58,7 +58,7 @@ TEST (ledger_confirm, multiple_accounts) nano::test::system system; nano::node_flags node_flags; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config, node_flags); nano::keypair key1; nano::keypair key2; @@ -232,7 +232,7 @@ TEST (ledger_confirm, send_receive_between_2_accounts) nano::test::system system; nano::node_flags node_flags; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config, node_flags); nano::keypair key1; nano::block_hash latest (node->latest (nano::dev::genesis_key.pub)); @@ -361,7 +361,7 @@ TEST (ledger_confirm, send_receive_self) nano::test::system system; nano::node_flags node_flags; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config, node_flags); nano::block_hash latest (node->latest (nano::dev::genesis_key.pub)); @@ -449,7 +449,7 @@ TEST (ledger_confirm, all_block_types) nano::test::system system; nano::node_flags node_flags; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config, node_flags); nano::block_hash latest (node->latest (nano::dev::genesis_key.pub)); nano::keypair key1; diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index f48fe70c79..7a3ea364bb 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -261,7 +261,7 @@ TEST (node, auto_bootstrap) { nano::test::system system; nano::node_config config (system.get_available_port ()); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_lazy_bootstrap = true; @@ -290,7 +290,7 @@ TEST (node, auto_bootstrap_reverse) { nano::test::system system; nano::node_config config (system.get_available_port ()); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_lazy_bootstrap = true; @@ -311,7 +311,7 @@ TEST (node, auto_bootstrap_age) { nano::test::system system; nano::node_config config (system.get_available_port ()); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_lazy_bootstrap = true; @@ -384,7 +384,7 @@ TEST (node, search_receivable_confirmed) { nano::test::system system; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config); nano::keypair key2; system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -413,7 +413,7 @@ TEST (node, search_receivable_pruned) { nano::test::system system; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node1 = system.add_node (node_config); nano::node_flags node_flags; node_flags.enable_pruning = true; @@ -733,7 +733,7 @@ TEST (node, fork_multi_flip) nano::test::system system; nano::node_flags node_flags; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 (*system.add_node (node_config, node_flags, type)); node_config.peering_port = system.get_available_port (); auto & node2 (*system.add_node (node_config, node_flags, type)); @@ -785,7 +785,7 @@ TEST (node, fork_bootstrap_flip) { nano::test::system system; nano::node_config config0{ system.get_available_port () }; - config0.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config0.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_lazy_bootstrap = true; @@ -1193,7 +1193,7 @@ TEST (node, DISABLED_broadcast_elected) nano::node_flags node_flags; nano::test::system system; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node0 = system.add_node (node_config, node_flags, type); node_config.peering_port = system.get_available_port (); auto node1 = system.add_node (node_config, node_flags, type); @@ -1320,7 +1320,7 @@ TEST (node, rep_self_vote) nano::test::system system; nano::node_config node_config (system.get_available_port ()); node_config.online_weight_minimum = std::numeric_limits::max (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node0 = system.add_node (node_config); nano::keypair rep_big; nano::block_builder builder; @@ -1415,10 +1415,10 @@ TEST (node, DISABLED_bootstrap_bulk_push) nano::test::system system0; nano::test::system system1; nano::node_config config0 (system.get_available_port ()); - config0.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config0.backlog_population.enable = false; auto node0 (system0.add_node (config0)); nano::node_config config1 (system.get_available_port ()); - config1.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config1.backlog_population.enable = false; auto node1 (system1.add_node (config1)); nano::keypair key0; // node0 knows about send0 but node1 doesn't. @@ -1823,7 +1823,7 @@ TEST (node, DISABLED_local_votes_cache) { nano::test::system system; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; node_config.receive_minimum = nano::dev::constants.genesis_amount; auto & node (*system.add_node (node_config)); nano::state_block_builder builder; @@ -1907,7 +1907,7 @@ TEST (node, DISABLED_local_votes_cache_batch) { nano::test::system system; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node (*system.add_node (node_config)); ASSERT_GE (node.network_params.voting.max_cache, 2); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -1981,7 +1981,7 @@ TEST (node, DISABLED_local_votes_cache_generate_new_vote) { nano::test::system system; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node (*system.add_node (node_config)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -2035,7 +2035,7 @@ TEST (node, DISABLED_local_votes_cache_fork) node_flags.disable_legacy_bootstrap = true; node_flags.disable_wallet_bootstrap = true; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node1 (*system.add_node (node_config, node_flags)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); auto send1 = nano::state_block_builder () @@ -2284,7 +2284,7 @@ TEST (node, epoch_conflict_confirm) { nano::test::system system; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node0 = *system.add_node (node_config); node_config.peering_port = system.get_available_port (); auto & node1 = *system.add_node (node_config); @@ -2792,7 +2792,7 @@ TEST (node, bidirectional_tcp) node_flags.disable_lazy_bootstrap = true; node_flags.disable_wallet_bootstrap = true; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node1 = system.add_node (node_config, node_flags); node_config.peering_port = system.get_available_port (); node_config.tcp_incoming_connections_max = 0; // Disable incoming TCP connections for node 2 @@ -2985,7 +2985,7 @@ TEST (node, rollback_gap_source) { nano::test::system system; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node = *system.add_node (node_config); nano::state_block_builder builder; nano::keypair key; @@ -3053,7 +3053,7 @@ TEST (node, dependency_graph) { nano::test::system system; nano::node_config config (system.get_available_port ()); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto & node = *system.add_node (config); nano::state_block_builder builder; @@ -3251,10 +3251,10 @@ TEST (node, dependency_graph_frontier) { nano::test::system system; nano::node_config config (system.get_available_port ()); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto & node1 = *system.add_node (config); config.peering_port = system.get_available_port (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::always; + config.backlog_population.enable = true; auto & node2 = *system.add_node (config); nano::state_block_builder builder; @@ -3418,9 +3418,9 @@ TEST (node, deferred_dependent_elections) { nano::test::system system; nano::node_config node_config_1{ system.get_available_port () }; - node_config_1.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config_1.backlog_population.enable = false; nano::node_config node_config_2{ system.get_available_port () }; - node_config_2.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config_2.backlog_population.enable = false; nano::node_flags flags; flags.disable_request_loop = true; auto & node = *system.add_node (node_config_1, flags); diff --git a/nano/core_test/optimistic_scheduler.cpp b/nano/core_test/optimistic_scheduler.cpp index f138579f8d..25d0771db3 100644 --- a/nano/core_test/optimistic_scheduler.cpp +++ b/nano/core_test/optimistic_scheduler.cpp @@ -85,7 +85,7 @@ TEST (optimistic_scheduler, under_gap_threshold) { nano::test::system system{}; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto & node = *system.add_node (config); // Must be smaller than optimistic scheduler `gap_threshold` diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index 5cc40202bb..aa54ba5262 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -20,7 +20,7 @@ TEST (request_aggregator, one) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node (*system.add_node (node_config)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); nano::block_builder builder; @@ -70,7 +70,7 @@ TEST (request_aggregator, one_update) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node (*system.add_node (node_config)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); nano::keypair key1; @@ -136,7 +136,7 @@ TEST (request_aggregator, two) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node (*system.add_node (node_config)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); nano::keypair key1; @@ -207,7 +207,7 @@ TEST (request_aggregator, two_endpoints) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; nano::node_flags node_flags; node_flags.disable_rep_crawler = true; auto & node1 (*system.add_node (node_config, node_flags)); @@ -265,7 +265,7 @@ TEST (request_aggregator, split) size_t max_vbh = nano::network::confirm_ack_hashes_max; nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node (*system.add_node (node_config)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); std::vector> request; @@ -315,7 +315,7 @@ TEST (request_aggregator, channel_max_queue) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; node_config.request_aggregator.max_queue = 0; auto & node (*system.add_node (node_config)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -345,7 +345,7 @@ TEST (request_aggregator, DISABLED_unique) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node (*system.add_node (node_config)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); nano::block_builder builder; diff --git a/nano/core_test/toml.cpp b/nano/core_test/toml.cpp index 0f7258c9bb..a4b904eb0f 100644 --- a/nano/core_test/toml.cpp +++ b/nano/core_test/toml.cpp @@ -678,7 +678,6 @@ TEST (toml, daemon_config_deserialize_no_defaults) ASSERT_NE (conf.node.io_threads, defaults.node.io_threads); ASSERT_NE (conf.node.max_work_generate_multiplier, defaults.node.max_work_generate_multiplier); ASSERT_NE (conf.node.max_unchecked_blocks, defaults.node.max_unchecked_blocks); - ASSERT_NE (conf.node.frontiers_confirmation, defaults.node.frontiers_confirmation); ASSERT_NE (conf.node.network_threads, defaults.node.network_threads); ASSERT_NE (conf.node.background_threads, defaults.node.background_threads); ASSERT_NE (conf.node.secondary_work_peers, defaults.node.secondary_work_peers); @@ -915,23 +914,6 @@ TEST (toml, daemon_config_deserialize_errors) ASSERT_EQ (toml.get_error ().get_message (), "max_work_generate_multiplier must be greater than or equal to 1"); } - - { - std::stringstream ss; - ss << R"toml( - [node] - frontiers_confirmation = "randomstring" - )toml"; - - nano::tomlconfig toml; - toml.read (ss); - nano::daemon_config conf; - conf.deserialize_toml (toml); - - ASSERT_EQ (toml.get_error ().get_message (), "frontiers_confirmation value is invalid (available: always, auto, disabled)"); - ASSERT_EQ (conf.node.frontiers_confirmation, nano::frontiers_confirmation_mode::invalid); - } - { std::stringstream ss; ss << R"toml( diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index 24e845bb53..3f656794e8 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -19,7 +19,7 @@ TEST (vote_processor, codes) nano::test::system system; auto node_config = system.default_config (); // Disable all election schedulers - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; node_config.hinted_scheduler.enabled = false; node_config.optimistic_scheduler.enabled = false; auto & node = *system.add_node (node_config); @@ -157,10 +157,10 @@ TEST (vote_processor, no_broadcast_local) flags.disable_request_loop = true; nano::node_config config1, config2; config1.representative_vote_weight_minimum = 0; - config1.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config1.backlog_population.enable = false; auto & node (*system.add_node (config1, flags)); config2.representative_vote_weight_minimum = 0; - config2.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config2.backlog_population.enable = false; config2.peering_port = system.get_available_port (); system.add_node (config2, flags); nano::block_builder builder; @@ -212,10 +212,10 @@ TEST (vote_processor, local_broadcast_without_a_representative) flags.disable_request_loop = true; nano::node_config config1, config2; config1.representative_vote_weight_minimum = 0; - config1.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config1.backlog_population.enable = false; auto & node (*system.add_node (config1, flags)); config2.representative_vote_weight_minimum = 0; - config2.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config2.backlog_population.enable = false; config2.peering_port = system.get_available_port (); system.add_node (config2, flags); nano::block_builder builder; @@ -261,9 +261,9 @@ TEST (vote_processor, no_broadcast_local_with_a_principal_representative) nano::node_flags flags; flags.disable_request_loop = true; nano::node_config config1, config2; - config1.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config1.backlog_population.enable = false; auto & node (*system.add_node (config1, flags)); - config2.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config2.backlog_population.enable = false; config2.peering_port = system.get_available_port (); system.add_node (config2, flags); nano::block_builder builder; diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index 458eb54d34..06241a13af 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -145,7 +145,7 @@ TEST (vote_spacing, prune) TEST (vote_spacing, vote_generator) { nano::node_config config; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; config.active_elections.hinted_limit_percentage = 0; // Disable election hinting nano::test::system system; nano::node_flags node_flags; @@ -189,7 +189,7 @@ TEST (vote_spacing, vote_generator) TEST (vote_spacing, rapid) { nano::node_config config; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; config.active_elections.hinted_limit_percentage = 0; // Disable election hinting nano::test::system system; nano::node_flags node_flags; diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index 951e9d0878..a2fe0639f4 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -1149,7 +1149,7 @@ TEST (wallet, search_receivable) nano::test::system system; nano::node_config config = system.default_config (); config.enable_voting = false; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags flags; flags.disable_search_pending = true; auto & node (*system.add_node (config, flags)); diff --git a/nano/core_test/wallets.cpp b/nano/core_test/wallets.cpp index d87e38b788..71caf12ad1 100644 --- a/nano/core_test/wallets.cpp +++ b/nano/core_test/wallets.cpp @@ -195,7 +195,7 @@ TEST (wallets, search_receivable) nano::test::system system; nano::node_config config = system.default_config (); config.enable_voting = false; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags flags; flags.disable_search_pending = true; auto & node (*system.add_node (config, flags)); diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 0fc201d6e3..7ab0f3820e 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1278,7 +1278,6 @@ int main (int argc, char * const * argv) } else { - config2.frontiers_confirmation = daemon_config.node.frontiers_confirmation; config2.active_elections.size = daemon_config.node.active_elections.size; } diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index 7ddf340ed0..ee2d8b3c8d 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -138,7 +138,6 @@ nano::error nano::node_config::serialize_toml (nano::tomlconfig & toml) const toml.put ("confirming_set_batch_time", confirming_set_batch_time.count (), "Maximum time the confirming set will hold the database write transaction.\ntype:milliseconds"); toml.put ("backup_before_upgrade", backup_before_upgrade, "Backup the ledger database before performing upgrades.\nWarning: uses more disk storage and increases startup time when upgrading.\ntype:bool"); toml.put ("max_work_generate_multiplier", max_work_generate_multiplier, "Maximum allowed difficulty multiplier for work generation.\ntype:double,[1..]"); - toml.put ("frontiers_confirmation", serialize_frontiers_confirmation (frontiers_confirmation), "Mode controlling frontier confirmation rate.\ntype:string,{auto,always,disabled}"); toml.put ("max_queued_requests", max_queued_requests, "Limit for number of queued confirmation requests for one channel, after which new requests are dropped until the queue drops below this value.\ntype:uint32"); toml.put ("request_aggregator_threads", request_aggregator_threads, "Number of threads to dedicate to request aggregator. Defaults to using all cpu threads, up to a maximum of 4"); toml.put ("max_unchecked_blocks", max_unchecked_blocks, "Maximum number of unchecked blocks to store in memory. Defaults to 65536. \ntype:uint64,[0..]"); @@ -567,12 +566,6 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) toml.get_error ().set ("rep_crawler_weight_minimum contains an invalid decimal amount"); } - if (toml.has_key ("frontiers_confirmation")) - { - auto frontiers_confirmation_l (toml.get ("frontiers_confirmation")); - frontiers_confirmation = deserialize_frontiers_confirmation (frontiers_confirmation_l); - } - toml.get ("enable_upnp", enable_upnp); if (toml.has_key ("experimental")) @@ -615,10 +608,6 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) { toml.get_error ().set ("max_work_generate_multiplier must be greater than or equal to 1"); } - if (frontiers_confirmation == nano::frontiers_confirmation_mode::invalid) - { - toml.get_error ().set ("frontiers_confirmation value is invalid (available: always, auto, disabled)"); - } if (block_processor_batch_max_time < network_params.node.process_confirmed_interval) { toml.get_error ().set ((boost::format ("block_processor_batch_max_time value must be equal or larger than %1%ms") % network_params.node.process_confirmed_interval.count ()).str ()); @@ -640,41 +629,6 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) return toml.get_error (); } -std::string nano::node_config::serialize_frontiers_confirmation (nano::frontiers_confirmation_mode mode_a) const -{ - switch (mode_a) - { - case nano::frontiers_confirmation_mode::always: - return "always"; - case nano::frontiers_confirmation_mode::automatic: - return "auto"; - case nano::frontiers_confirmation_mode::disabled: - return "disabled"; - default: - return "auto"; - } -} - -nano::frontiers_confirmation_mode nano::node_config::deserialize_frontiers_confirmation (std::string const & string_a) -{ - if (string_a == "always") - { - return nano::frontiers_confirmation_mode::always; - } - else if (string_a == "auto") - { - return nano::frontiers_confirmation_mode::automatic; - } - else if (string_a == "disabled") - { - return nano::frontiers_confirmation_mode::disabled; - } - else - { - return nano::frontiers_confirmation_mode::invalid; - } -} - void nano::node_config::deserialize_address (std::string const & entry_a, std::vector> & container_a) const { auto port_position (entry_a.rfind (':')); diff --git a/nano/node/nodeconfig.hpp b/nano/node/nodeconfig.hpp index 10f6732361..6f9ec2d802 100644 --- a/nano/node/nodeconfig.hpp +++ b/nano/node/nodeconfig.hpp @@ -41,16 +41,6 @@ namespace nano { class tomlconfig; -enum class frontiers_confirmation_mode : uint8_t -{ - always, // Always confirm frontiers - automatic, // Always mode if node contains representative with at least 50% of principal weight, less frequest requests if not - disabled, // Do not confirm frontiers - invalid -}; - -class message_processor_config; - /** * Node configuration */ @@ -143,7 +133,6 @@ class node_config uint64_t max_pruning_depth{ 0 }; nano::rocksdb_config rocksdb_config; nano::lmdb_config lmdb_config; - nano::frontiers_confirmation_mode frontiers_confirmation{ nano::frontiers_confirmation_mode::automatic }; bool enable_upnp{ true }; nano::vote_cache_config vote_cache; nano::rep_crawler_config rep_crawler; @@ -161,8 +150,6 @@ class node_config nano::backlog_population_config backlog_population; public: - std::string serialize_frontiers_confirmation (nano::frontiers_confirmation_mode) const; - nano::frontiers_confirmation_mode deserialize_frontiers_confirmation (std::string const &); /** Entry is ignored if it cannot be parsed as a valid address:port */ void deserialize_address (std::string const &, std::vector> &) const; diff --git a/nano/rpc_test/receivable.cpp b/nano/rpc_test/receivable.cpp index 289797ace4..9199a14619 100644 --- a/nano/rpc_test/receivable.cpp +++ b/nano/rpc_test/receivable.cpp @@ -133,7 +133,7 @@ TEST (rpc, receivable_unconfirmed) { nano::test::system system; nano::node_config config; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto node = add_ipc_enabled_node (system, config); auto chain = nano::test::setup_chain (system, *node, 1, nano::dev::genesis_key, false); auto block1 = chain[0]; @@ -530,7 +530,7 @@ TEST (rpc, accounts_receivable_confirmed) { nano::test::system system; nano::node_config config; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto node = add_ipc_enabled_node (system, config); auto chain = nano::test::setup_chain (system, *node, 1, nano::dev::genesis_key, false); auto block1 = chain[0]; diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 90b17c57c7..1f37473756 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -3031,7 +3031,7 @@ TEST (rpc, accounts_balances_unopened_account_with_receivables) { nano::test::system system; nano::node_config config; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto node = add_ipc_enabled_node (system, config); // send a 1 raw to the unopened account which will have receivables @@ -3335,7 +3335,7 @@ TEST (rpc, pending_exists) { nano::test::system system; nano::node_config config; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto node = add_ipc_enabled_node (system, config); nano::keypair key1; system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -3394,7 +3394,7 @@ TEST (rpc, wallet_receivable) { nano::test::system system; nano::node_config config; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto node = add_ipc_enabled_node (system, config); nano::keypair key1; system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -4458,7 +4458,7 @@ TEST (rpc, populate_backlog) nano::test::system system; nano::node_config node_config = system.default_config (); // Disable automatic backlog population - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = add_ipc_enabled_node (system, node_config); // Create and process a block that won't get automatically scheduled for confirmation diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index b84cb4eb87..9efbd3b4b0 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -640,7 +640,7 @@ TEST (confirmation_height, many_accounts_single_confirmation) nano::test::system system; nano::node_config node_config = system.default_config (); node_config.online_weight_minimum = 100; - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -724,7 +724,7 @@ TEST (confirmation_height, many_accounts_many_confirmations) nano::test::system system; nano::node_config node_config = system.default_config (); node_config.online_weight_minimum = 100; - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -799,7 +799,7 @@ TEST (confirmation_height, long_chains) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config); nano::keypair key1; system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -945,7 +945,7 @@ TEST (confirmation_height, dynamic_algorithm) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config); nano::keypair key; system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -994,7 +994,7 @@ TEST (confirmation_height, many_accounts_send_receive_self) nano::test::system system; nano::node_config node_config = system.default_config (); node_config.online_weight_minimum = 100; - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; node_config.active_elections.size = 400000; nano::node_flags node_flags; auto node = system.add_node (node_config); @@ -1413,7 +1413,7 @@ TEST (telemetry, under_load) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; nano::node_flags node_flags; auto node = system.add_node (node_config, node_flags); node_config.peering_port = system.get_available_port (); @@ -1774,7 +1774,7 @@ TEST (node, mass_block_new) { nano::test::system system; nano::node_config node_config = system.default_config (); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto & node = *system.add_node (node_config); node.network_params.network.aec_loop_interval_ms = 500; @@ -2036,7 +2036,7 @@ TEST (node, wallet_create_block_confirm_conflicts) nano::test::system system; nano::block_builder builder; nano::node_config node_config (system.get_available_port ()); - node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + node_config.backlog_population.enable = false; auto node = system.add_node (node_config); auto const num_blocks = 10000; @@ -2107,7 +2107,7 @@ TEST (system, block_sequence) config.peering_port = system.get_available_port (); // config.bandwidth_limit = 16 * 1024; config.enable_voting = true; - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; nano::node_flags flags; flags.disable_max_peers_per_ip = true; flags.disable_ongoing_bootstrap = true; diff --git a/nano/slow_test/vote_cache.cpp b/nano/slow_test/vote_cache.cpp index 929b6f64c3..7ef639208b 100644 --- a/nano/slow_test/vote_cache.cpp +++ b/nano/slow_test/vote_cache.cpp @@ -134,7 +134,7 @@ TEST (vote_cache, perf_singlethreaded) nano::test::system system; nano::node_flags flags; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto & node = *system.add_node (config, flags); const int rep_count = 50; @@ -193,7 +193,7 @@ TEST (vote_cache, perf_multithreaded) nano::test::system system; nano::node_flags flags; nano::node_config config = system.default_config (); - config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; + config.backlog_population.enable = false; auto & node = *system.add_node (config, flags); const int thread_count = 12; From 96f8a30846eeff719004a97a06815fe7820632d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:22:01 +0200 Subject: [PATCH 03/14] Uniform indentation --- nano/lib/rate_limiting.hpp | 87 ++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/nano/lib/rate_limiting.hpp b/nano/lib/rate_limiting.hpp index 2c392963e4..33adb52e9c 100644 --- a/nano/lib/rate_limiting.hpp +++ b/nano/lib/rate_limiting.hpp @@ -4,61 +4,58 @@ #include #include -namespace nano -{ /* Namespace for shaping (egress) and policing (ingress) rate limiting algorithms */ -namespace rate +namespace nano::rate +{ +/** + * Token bucket based rate limiting. This is suitable for rate limiting ipc/api calls + * and network traffic, while allowing short bursts. + * + * Tokens are refilled at N tokens per second and there's a bucket capacity to limit + * bursts. + * + * A bucket has low overhead and can be instantiated for various purposes, such as one + * bucket per session, or one for bandwidth limiting. A token can represent bytes, + * messages, or the cost of API invocations. + */ +class token_bucket { +public: /** - * Token bucket based rate limiting. This is suitable for rate limiting ipc/api calls - * and network traffic, while allowing short bursts. - * - * Tokens are refilled at N tokens per second and there's a bucket capacity to limit - * bursts. - * - * A bucket has low overhead and can be instantiated for various purposes, such as one - * bucket per session, or one for bandwidth limiting. A token can represent bytes, - * messages, or the cost of API invocations. + * Set up a token bucket. + * @param max_token_count Maximum number of tokens in this bucket, which limits bursts. + * @param refill_rate Token refill rate, which limits the long term rate (tokens per seconds) */ - class token_bucket - { - public: - /** - * Set up a token bucket. - * @param max_token_count Maximum number of tokens in this bucket, which limits bursts. - * @param refill_rate Token refill rate, which limits the long term rate (tokens per seconds) - */ - token_bucket (std::size_t max_token_count, std::size_t refill_rate); + token_bucket (std::size_t max_token_count, std::size_t refill_rate); - /** - * Determine if an operation of cost \p tokens_required is possible, and deduct from the - * bucket if that's the case. - * The default cost is 1 token, but resource intensive operations may request - * more tokens to be available. - */ - bool try_consume (unsigned tokens_required = 1); + /** + * Determine if an operation of cost \p tokens_required is possible, and deduct from the + * bucket if that's the case. + * The default cost is 1 token, but resource intensive operations may request + * more tokens to be available. + */ + bool try_consume (unsigned tokens_required = 1); - /** Returns the largest burst observed */ - std::size_t largest_burst () const; + /** Returns the largest burst observed */ + std::size_t largest_burst () const; - /** Update the max_token_count and/or refill_rate_a parameters */ - void reset (std::size_t max_token_count, std::size_t refill_rate); + /** Update the max_token_count and/or refill_rate_a parameters */ + void reset (std::size_t max_token_count, std::size_t refill_rate); - private: - void refill (); +private: + void refill (); - private: - std::size_t max_token_count; - std::size_t refill_rate; +private: + std::size_t max_token_count; + std::size_t refill_rate; - std::size_t current_size{ 0 }; - /** The minimum observed bucket size, from which the largest burst can be derived */ - std::size_t smallest_size{ 0 }; - std::chrono::steady_clock::time_point last_refill; + std::size_t current_size{ 0 }; + /** The minimum observed bucket size, from which the largest burst can be derived */ + std::size_t smallest_size{ 0 }; + std::chrono::steady_clock::time_point last_refill; - mutable nano::mutex mutex; + mutable nano::mutex mutex; - static std::size_t constexpr unlimited_rate_sentinel{ static_cast (1e9) }; - }; -} + static std::size_t constexpr unlimited_rate_sentinel{ static_cast (1e9) }; +}; } From 07637c8953df2740430780be62b4c03b0e08567d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:38:43 +0200 Subject: [PATCH 04/14] Rename to `rate_limiter` --- nano/node/bandwidth_limiter.cpp | 10 +++++----- nano/node/bandwidth_limiter.hpp | 10 +++++----- nano/node/bootstrap_ascending/service.hpp | 2 +- nano/node/local_block_broadcaster.hpp | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nano/node/bandwidth_limiter.cpp b/nano/node/bandwidth_limiter.cpp index 344cb6a129..347fa4b2e1 100644 --- a/nano/node/bandwidth_limiter.cpp +++ b/nano/node/bandwidth_limiter.cpp @@ -2,20 +2,20 @@ #include /* - * bandwidth_limiter + * rate_limiter */ -nano::bandwidth_limiter::bandwidth_limiter (std::size_t limit_a, double burst_ratio_a) : +nano::rate_limiter::rate_limiter (std::size_t limit_a, double burst_ratio_a) : bucket (static_cast (limit_a * burst_ratio_a), limit_a) { } -bool nano::bandwidth_limiter::should_pass (std::size_t message_size_a) +bool nano::rate_limiter::should_pass (std::size_t message_size_a) { return bucket.try_consume (nano::narrow_cast (message_size_a)); } -void nano::bandwidth_limiter::reset (std::size_t limit_a, double burst_ratio_a) +void nano::rate_limiter::reset (std::size_t limit_a, double burst_ratio_a) { bucket.reset (static_cast (limit_a * burst_ratio_a), limit_a); } @@ -31,7 +31,7 @@ nano::outbound_bandwidth_limiter::outbound_bandwidth_limiter (nano::outbound_ban { } -nano::bandwidth_limiter & nano::outbound_bandwidth_limiter::select_limiter (nano::bandwidth_limit_type type) +nano::rate_limiter & nano::outbound_bandwidth_limiter::select_limiter (nano::bandwidth_limit_type type) { switch (type) { diff --git a/nano/node/bandwidth_limiter.hpp b/nano/node/bandwidth_limiter.hpp index 5cb13f0eba..edd6c328bb 100644 --- a/nano/node/bandwidth_limiter.hpp +++ b/nano/node/bandwidth_limiter.hpp @@ -21,11 +21,11 @@ nano::bandwidth_limit_type to_bandwidth_limit_type (nano::transport::traffic_typ /** * Class that tracks and manages bandwidth limits for IO operations */ -class bandwidth_limiter final +class rate_limiter final { public: // initialize with limit 0 = unbounded - bandwidth_limiter (std::size_t limit, double burst_ratio); + rate_limiter (std::size_t limit, double burst_ratio); bool should_pass (std::size_t buffer_size); void reset (std::size_t limit, double burst_ratio); @@ -64,13 +64,13 @@ class outbound_bandwidth_limiter final /** * Returns reference to limiter corresponding to the limit type */ - bandwidth_limiter & select_limiter (bandwidth_limit_type); + nano::rate_limiter & select_limiter (bandwidth_limit_type); private: const config config_m; private: - bandwidth_limiter limiter_standard; - bandwidth_limiter limiter_bootstrap; + nano::rate_limiter limiter_standard; + nano::rate_limiter limiter_bootstrap; }; } \ No newline at end of file diff --git a/nano/node/bootstrap_ascending/service.hpp b/nano/node/bootstrap_ascending/service.hpp index 7506f48b09..d829719986 100644 --- a/nano/node/bootstrap_ascending/service.hpp +++ b/nano/node/bootstrap_ascending/service.hpp @@ -181,7 +181,7 @@ namespace bootstrap_ascending // Requests for accounts from database have much lower hitrate and could introduce strain on the network // A separate (lower) limiter ensures that we always reserve resources for querying accounts from priority queue - nano::bandwidth_limiter database_limiter; + nano::rate_limiter database_limiter; nano::interval sync_dependencies_interval; diff --git a/nano/node/local_block_broadcaster.hpp b/nano/node/local_block_broadcaster.hpp index e86af05a9e..47a443acf5 100644 --- a/nano/node/local_block_broadcaster.hpp +++ b/nano/node/local_block_broadcaster.hpp @@ -112,7 +112,7 @@ class local_block_broadcaster final private: bool enabled{ false }; - nano::bandwidth_limiter limiter; + nano::rate_limiter limiter; nano::interval cleanup_interval; std::atomic stopped{ false }; From 87aeef274d9bfa3c464d5240b493b75e72d7c572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:42:15 +0200 Subject: [PATCH 05/14] Move to `rate_limiting.hpp` --- nano/lib/rate_limiting.cpp | 23 +++++++++++++++++++++++ nano/lib/rate_limiting.hpp | 16 ++++++++++++++++ nano/node/bandwidth_limiter.cpp | 19 ------------------- nano/node/bandwidth_limiter.hpp | 13 ------------- nano/node/bootstrap_ascending/service.hpp | 3 +-- nano/node/local_block_broadcaster.hpp | 2 +- 6 files changed, 41 insertions(+), 35 deletions(-) diff --git a/nano/lib/rate_limiting.cpp b/nano/lib/rate_limiting.cpp index de6d0fde57..268e8b5e9c 100644 --- a/nano/lib/rate_limiting.cpp +++ b/nano/lib/rate_limiting.cpp @@ -4,6 +4,10 @@ #include +/* + * token_bucket + */ + nano::rate::token_bucket::token_bucket (std::size_t max_token_count_a, std::size_t refill_rate_a) { reset (max_token_count_a, refill_rate_a); @@ -62,3 +66,22 @@ void nano::rate::token_bucket::reset (std::size_t max_token_count_a, std::size_t refill_rate = refill_rate_a; last_refill = std::chrono::steady_clock::now (); } + +/* + * rate_limiter + */ + +nano::rate_limiter::rate_limiter (std::size_t limit_a, double burst_ratio_a) : + bucket (static_cast (limit_a * burst_ratio_a), limit_a) +{ +} + +bool nano::rate_limiter::should_pass (std::size_t message_size_a) +{ + return bucket.try_consume (nano::narrow_cast (message_size_a)); +} + +void nano::rate_limiter::reset (std::size_t limit_a, double burst_ratio_a) +{ + bucket.reset (static_cast (limit_a * burst_ratio_a), limit_a); +} \ No newline at end of file diff --git a/nano/lib/rate_limiting.hpp b/nano/lib/rate_limiting.hpp index 33adb52e9c..f027d70839 100644 --- a/nano/lib/rate_limiting.hpp +++ b/nano/lib/rate_limiting.hpp @@ -59,3 +59,19 @@ class token_bucket static std::size_t constexpr unlimited_rate_sentinel{ static_cast (1e9) }; }; } + +namespace nano +{ +class rate_limiter final +{ +public: + // initialize with limit 0 = unbounded + rate_limiter (std::size_t limit, double burst_ratio); + + bool should_pass (std::size_t buffer_size); + void reset (std::size_t limit, double burst_ratio); + +private: + nano::rate::token_bucket bucket; +}; +} \ No newline at end of file diff --git a/nano/node/bandwidth_limiter.cpp b/nano/node/bandwidth_limiter.cpp index 347fa4b2e1..14a79ecb1d 100644 --- a/nano/node/bandwidth_limiter.cpp +++ b/nano/node/bandwidth_limiter.cpp @@ -1,25 +1,6 @@ #include #include -/* - * rate_limiter - */ - -nano::rate_limiter::rate_limiter (std::size_t limit_a, double burst_ratio_a) : - bucket (static_cast (limit_a * burst_ratio_a), limit_a) -{ -} - -bool nano::rate_limiter::should_pass (std::size_t message_size_a) -{ - return bucket.try_consume (nano::narrow_cast (message_size_a)); -} - -void nano::rate_limiter::reset (std::size_t limit_a, double burst_ratio_a) -{ - bucket.reset (static_cast (limit_a * burst_ratio_a), limit_a); -} - /* * outbound_bandwidth_limiter */ diff --git a/nano/node/bandwidth_limiter.hpp b/nano/node/bandwidth_limiter.hpp index edd6c328bb..6203f1ed9b 100644 --- a/nano/node/bandwidth_limiter.hpp +++ b/nano/node/bandwidth_limiter.hpp @@ -21,19 +21,6 @@ nano::bandwidth_limit_type to_bandwidth_limit_type (nano::transport::traffic_typ /** * Class that tracks and manages bandwidth limits for IO operations */ -class rate_limiter final -{ -public: - // initialize with limit 0 = unbounded - rate_limiter (std::size_t limit, double burst_ratio); - - bool should_pass (std::size_t buffer_size); - void reset (std::size_t limit, double burst_ratio); - -private: - nano::rate::token_bucket bucket; -}; - class outbound_bandwidth_limiter final { public: // Config diff --git a/nano/node/bootstrap_ascending/service.hpp b/nano/node/bootstrap_ascending/service.hpp index d829719986..a31461a7f1 100644 --- a/nano/node/bootstrap_ascending/service.hpp +++ b/nano/node/bootstrap_ascending/service.hpp @@ -4,8 +4,7 @@ #include #include #include -#include -#include +#include #include #include #include diff --git a/nano/node/local_block_broadcaster.hpp b/nano/node/local_block_broadcaster.hpp index 47a443acf5..1583e7d382 100644 --- a/nano/node/local_block_broadcaster.hpp +++ b/nano/node/local_block_broadcaster.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include From 7eb72ccd463a3d07f7912bf87e380ff04397afb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:48:23 +0200 Subject: [PATCH 06/14] Rename to `bandwidth_limiter` --- nano/node/bandwidth_limiter.cpp | 10 +++++----- nano/node/bandwidth_limiter.hpp | 4 ++-- nano/node/node.cpp | 6 +++--- nano/node/node.hpp | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nano/node/bandwidth_limiter.cpp b/nano/node/bandwidth_limiter.cpp index 14a79ecb1d..5450590ab1 100644 --- a/nano/node/bandwidth_limiter.cpp +++ b/nano/node/bandwidth_limiter.cpp @@ -2,17 +2,17 @@ #include /* - * outbound_bandwidth_limiter + * bandwidth_limiter */ -nano::outbound_bandwidth_limiter::outbound_bandwidth_limiter (nano::outbound_bandwidth_limiter::config config_a) : +nano::bandwidth_limiter::bandwidth_limiter (nano::bandwidth_limiter::config config_a) : config_m{ config_a }, limiter_standard (config_m.standard_limit, config_m.standard_burst_ratio), limiter_bootstrap{ config_m.bootstrap_limit, config_m.bootstrap_burst_ratio } { } -nano::rate_limiter & nano::outbound_bandwidth_limiter::select_limiter (nano::bandwidth_limit_type type) +nano::rate_limiter & nano::bandwidth_limiter::select_limiter (nano::bandwidth_limit_type type) { switch (type) { @@ -27,13 +27,13 @@ nano::rate_limiter & nano::outbound_bandwidth_limiter::select_limiter (nano::ban return limiter_standard; } -bool nano::outbound_bandwidth_limiter::should_pass (std::size_t buffer_size, nano::bandwidth_limit_type type) +bool nano::bandwidth_limiter::should_pass (std::size_t buffer_size, nano::bandwidth_limit_type type) { auto & limiter = select_limiter (type); return limiter.should_pass (buffer_size); } -void nano::outbound_bandwidth_limiter::reset (std::size_t limit, double burst_ratio, nano::bandwidth_limit_type type) +void nano::bandwidth_limiter::reset (std::size_t limit, double burst_ratio, nano::bandwidth_limit_type type) { auto & limiter = select_limiter (type); limiter.reset (limit, burst_ratio); diff --git a/nano/node/bandwidth_limiter.hpp b/nano/node/bandwidth_limiter.hpp index 6203f1ed9b..4ccdbc5d46 100644 --- a/nano/node/bandwidth_limiter.hpp +++ b/nano/node/bandwidth_limiter.hpp @@ -21,7 +21,7 @@ nano::bandwidth_limit_type to_bandwidth_limit_type (nano::transport::traffic_typ /** * Class that tracks and manages bandwidth limits for IO operations */ -class outbound_bandwidth_limiter final +class bandwidth_limiter final { public: // Config struct config @@ -35,7 +35,7 @@ class outbound_bandwidth_limiter final }; public: - explicit outbound_bandwidth_limiter (config); + explicit bandwidth_limiter (config); /** * Check whether packet falls withing bandwidth limits and should be allowed diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 79546af427..ff3675f769 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -58,9 +58,9 @@ extern std::size_t nano_bootstrap_weights_beta_size; * configs */ -nano::outbound_bandwidth_limiter::config nano::outbound_bandwidth_limiter_config (const nano::node_config & config) +nano::bandwidth_limiter::config nano::bandwidth_limiter_config (const nano::node_config & config) { - outbound_bandwidth_limiter::config cfg{}; + bandwidth_limiter::config cfg{}; cfg.standard_limit = config.bandwidth_limit; cfg.standard_burst_ratio = config.bandwidth_limit_burst_ratio; cfg.bootstrap_limit = config.bootstrap_bandwidth_limit; @@ -159,7 +159,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy wallets_store (*wallets_store_impl), ledger_impl{ std::make_unique (store, stats, network_params.ledger, flags_a.generate_cache, config_a.representative_vote_weight_minimum.number ()) }, ledger{ *ledger_impl }, - outbound_limiter{ outbound_bandwidth_limiter_config (config) }, + outbound_limiter{ bandwidth_limiter_config (config) }, message_processor_impl{ std::make_unique (config.message_processor, *this) }, message_processor{ *message_processor_impl }, // empty `config.peering_port` means the user made no port choice at all; diff --git a/nano/node/node.hpp b/nano/node/node.hpp index e607244179..11a096920d 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -73,7 +73,7 @@ namespace rocksdb namespace nano { // Configs -outbound_bandwidth_limiter::config outbound_bandwidth_limiter_config (node_config const &); +bandwidth_limiter::config bandwidth_limiter_config (node_config const &); class node final : public std::enable_shared_from_this { @@ -169,7 +169,7 @@ class node final : public std::enable_shared_from_this nano::wallets_store & wallets_store; std::unique_ptr ledger_impl; nano::ledger & ledger; - nano::outbound_bandwidth_limiter outbound_limiter; + nano::bandwidth_limiter outbound_limiter; std::unique_ptr message_processor_impl; nano::message_processor & message_processor; nano::network network; From 4d5664a1e18945d626395ce2d76b330824584c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:15:23 +0200 Subject: [PATCH 07/14] Use `nano::transport::traffic_type` for bandwidth limiter selection --- nano/node/bandwidth_limiter.cpp | 32 ++++++++-------------------- nano/node/bandwidth_limiter.hpp | 21 ++++-------------- nano/node/transport/channel.cpp | 2 +- nano/node/transport/traffic_type.hpp | 3 +-- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/nano/node/bandwidth_limiter.cpp b/nano/node/bandwidth_limiter.cpp index 5450590ab1..45730c671e 100644 --- a/nano/node/bandwidth_limiter.cpp +++ b/nano/node/bandwidth_limiter.cpp @@ -7,49 +7,35 @@ nano::bandwidth_limiter::bandwidth_limiter (nano::bandwidth_limiter::config config_a) : config_m{ config_a }, - limiter_standard (config_m.standard_limit, config_m.standard_burst_ratio), + limiter_generic{ config_m.standard_limit, config_m.standard_burst_ratio }, limiter_bootstrap{ config_m.bootstrap_limit, config_m.bootstrap_burst_ratio } { } -nano::rate_limiter & nano::bandwidth_limiter::select_limiter (nano::bandwidth_limit_type type) +nano::rate_limiter & nano::bandwidth_limiter::select_limiter (nano::transport::traffic_type type) { switch (type) { - case bandwidth_limit_type::bootstrap: + case nano::transport::traffic_type::bootstrap: return limiter_bootstrap; - case bandwidth_limit_type::standard: + case nano::transport::traffic_type::generic: + return limiter_generic; break; default: - debug_assert (false); + debug_assert (false, "missing traffic type"); break; } - return limiter_standard; + return limiter_generic; } -bool nano::bandwidth_limiter::should_pass (std::size_t buffer_size, nano::bandwidth_limit_type type) +bool nano::bandwidth_limiter::should_pass (std::size_t buffer_size, nano::transport::traffic_type type) { auto & limiter = select_limiter (type); return limiter.should_pass (buffer_size); } -void nano::bandwidth_limiter::reset (std::size_t limit, double burst_ratio, nano::bandwidth_limit_type type) +void nano::bandwidth_limiter::reset (std::size_t limit, double burst_ratio, nano::transport::traffic_type type) { auto & limiter = select_limiter (type); limiter.reset (limit, burst_ratio); -} - -nano::bandwidth_limit_type nano::to_bandwidth_limit_type (const nano::transport::traffic_type & traffic_type) -{ - switch (traffic_type) - { - case nano::transport::traffic_type::generic: - return nano::bandwidth_limit_type::standard; - break; - case nano::transport::traffic_type::bootstrap: - return nano::bandwidth_limit_type::bootstrap; - break; - } - debug_assert (false); - return {}; } \ No newline at end of file diff --git a/nano/node/bandwidth_limiter.hpp b/nano/node/bandwidth_limiter.hpp index 4ccdbc5d46..c0834b31e3 100644 --- a/nano/node/bandwidth_limiter.hpp +++ b/nano/node/bandwidth_limiter.hpp @@ -5,19 +5,6 @@ namespace nano { -/** - * Enumeration for different bandwidth limits for different traffic types - */ -enum class bandwidth_limit_type -{ - /** For all message */ - standard, - /** For bootstrap (asc_pull_ack, asc_pull_req) traffic */ - bootstrap -}; - -nano::bandwidth_limit_type to_bandwidth_limit_type (nano::transport::traffic_type const &); - /** * Class that tracks and manages bandwidth limits for IO operations */ @@ -41,23 +28,23 @@ class bandwidth_limiter final * Check whether packet falls withing bandwidth limits and should be allowed * @return true if OK, false if needs to be dropped */ - bool should_pass (std::size_t buffer_size, bandwidth_limit_type); + bool should_pass (std::size_t buffer_size, nano::transport::traffic_type type); /** * Reset limits of selected limiter type to values passed in arguments */ - void reset (std::size_t limit, double burst_ratio, bandwidth_limit_type = bandwidth_limit_type::standard); + void reset (std::size_t limit, double burst_ratio, nano::transport::traffic_type type = nano::transport::traffic_type::generic); private: /** * Returns reference to limiter corresponding to the limit type */ - nano::rate_limiter & select_limiter (bandwidth_limit_type); + nano::rate_limiter & select_limiter (nano::transport::traffic_type type); private: const config config_m; private: - nano::rate_limiter limiter_standard; + nano::rate_limiter limiter_generic; nano::rate_limiter limiter_bootstrap; }; } \ No newline at end of file diff --git a/nano/node/transport/channel.cpp b/nano/node/transport/channel.cpp index e2a422cd41..1837044490 100644 --- a/nano/node/transport/channel.cpp +++ b/nano/node/transport/channel.cpp @@ -19,7 +19,7 @@ void nano::transport::channel::send (nano::message & message_a, std::function Date: Mon, 9 Sep 2024 21:53:52 +0200 Subject: [PATCH 08/14] Rework bandwidth limiter config --- nano/node/bandwidth_limiter.cpp | 21 +++++++++++++++++---- nano/node/bandwidth_limiter.hpp | 29 ++++++++++++++++------------- nano/node/node.cpp | 16 +--------------- nano/node/node.hpp | 3 --- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/nano/node/bandwidth_limiter.cpp b/nano/node/bandwidth_limiter.cpp index 45730c671e..ade752051e 100644 --- a/nano/node/bandwidth_limiter.cpp +++ b/nano/node/bandwidth_limiter.cpp @@ -1,14 +1,15 @@ #include #include +#include /* * bandwidth_limiter */ -nano::bandwidth_limiter::bandwidth_limiter (nano::bandwidth_limiter::config config_a) : - config_m{ config_a }, - limiter_generic{ config_m.standard_limit, config_m.standard_burst_ratio }, - limiter_bootstrap{ config_m.bootstrap_limit, config_m.bootstrap_burst_ratio } +nano::bandwidth_limiter::bandwidth_limiter (nano::node_config const & node_config_a) : + config{ node_config_a }, + limiter_generic{ config.generic_limit, config.generic_burst_ratio }, + limiter_bootstrap{ config.bootstrap_limit, config.bootstrap_burst_ratio } { } @@ -38,4 +39,16 @@ void nano::bandwidth_limiter::reset (std::size_t limit, double burst_ratio, nano { auto & limiter = select_limiter (type); limiter.reset (limit, burst_ratio); +} + +/* + * bandwidth_limiter_config + */ + +nano::bandwidth_limiter_config::bandwidth_limiter_config (nano::node_config const & node_config) : + generic_limit{ node_config.bandwidth_limit }, + generic_burst_ratio{ node_config.bandwidth_limit_burst_ratio }, + bootstrap_limit{ node_config.bootstrap_bandwidth_limit }, + bootstrap_burst_ratio{ node_config.bootstrap_bandwidth_burst_ratio } +{ } \ No newline at end of file diff --git a/nano/node/bandwidth_limiter.hpp b/nano/node/bandwidth_limiter.hpp index c0834b31e3..1bd9e58339 100644 --- a/nano/node/bandwidth_limiter.hpp +++ b/nano/node/bandwidth_limiter.hpp @@ -1,28 +1,31 @@ #pragma once #include +#include #include namespace nano { +class bandwidth_limiter_config final +{ +public: + explicit bandwidth_limiter_config (nano::node_config const &); + +public: + std::size_t generic_limit; + double generic_burst_ratio; + + std::size_t bootstrap_limit; + double bootstrap_burst_ratio; +}; + /** * Class that tracks and manages bandwidth limits for IO operations */ class bandwidth_limiter final { -public: // Config - struct config - { - // standard - std::size_t standard_limit; - double standard_burst_ratio; - // bootstrap - std::size_t bootstrap_limit; - double bootstrap_burst_ratio; - }; - public: - explicit bandwidth_limiter (config); + explicit bandwidth_limiter (nano::node_config const &); /** * Check whether packet falls withing bandwidth limits and should be allowed @@ -41,7 +44,7 @@ class bandwidth_limiter final nano::rate_limiter & select_limiter (nano::transport::traffic_type type); private: - const config config_m; + bandwidth_limiter_config const config; private: nano::rate_limiter limiter_generic; diff --git a/nano/node/node.cpp b/nano/node/node.cpp index ff3675f769..30a088143a 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -54,20 +54,6 @@ extern unsigned char nano_bootstrap_weights_beta[]; extern std::size_t nano_bootstrap_weights_beta_size; } -/* - * configs - */ - -nano::bandwidth_limiter::config nano::bandwidth_limiter_config (const nano::node_config & config) -{ - bandwidth_limiter::config cfg{}; - cfg.standard_limit = config.bandwidth_limit; - cfg.standard_burst_ratio = config.bandwidth_limit_burst_ratio; - cfg.bootstrap_limit = config.bootstrap_bandwidth_limit; - cfg.bootstrap_burst_ratio = config.bootstrap_bandwidth_burst_ratio; - return cfg; -} - /* * node */ @@ -159,7 +145,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy wallets_store (*wallets_store_impl), ledger_impl{ std::make_unique (store, stats, network_params.ledger, flags_a.generate_cache, config_a.representative_vote_weight_minimum.number ()) }, ledger{ *ledger_impl }, - outbound_limiter{ bandwidth_limiter_config (config) }, + outbound_limiter{ config }, message_processor_impl{ std::make_unique (config.message_processor, *this) }, message_processor{ *message_processor_impl }, // empty `config.peering_port` means the user made no port choice at all; diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 11a096920d..15d6e96e47 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -72,9 +72,6 @@ namespace rocksdb namespace nano { -// Configs -bandwidth_limiter::config bandwidth_limiter_config (node_config const &); - class node final : public std::enable_shared_from_this { public: From f45835c6109dc80bc49cc9fff8c1dfafc22fc612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:25:51 +0200 Subject: [PATCH 09/14] Use unique ptr for `backlog_population` --- nano/node/node.cpp | 4 +++- nano/node/node.hpp | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 30a088143a..eb3d42e2ed 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -195,7 +196,8 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy aggregator_impl{ std::make_unique (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) }, aggregator{ *aggregator_impl }, wallets (wallets_store.init_error (), *this), - backlog{ config.backlog_population, scheduler, ledger, stats }, + backlog_impl{ std::make_unique (config.backlog_population, scheduler, ledger, stats) }, + backlog{ *backlog_impl }, ascendboot_impl{ std::make_unique (config, block_processor, ledger, network, stats, logger) }, ascendboot{ *ascendboot_impl }, websocket{ config.websocket_config, observers, wallets, ledger, io_ctx, logger }, diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 15d6e96e47..1f44b8031b 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -41,6 +40,7 @@ namespace nano { class active_elections; +class backlog_population; class confirming_set; class message_processor; class monitor; @@ -208,7 +208,8 @@ class node final : public std::enable_shared_from_this std::unique_ptr aggregator_impl; nano::request_aggregator & aggregator; nano::wallets wallets; - nano::backlog_population backlog; + std::unique_ptr backlog_impl; + nano::backlog_population & backlog; std::unique_ptr ascendboot_impl; nano::bootstrap_ascending::service & ascendboot; nano::websocket_server websocket; From 6a01a97f651018dfb9d4f5ef0cec92885cd8c2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:28:35 +0200 Subject: [PATCH 10/14] Use unique ptr for `bandwidth_limiter` --- nano/node/node.cpp | 4 +++- nano/node/node.hpp | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index eb3d42e2ed..493506cf33 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -146,7 +147,8 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy wallets_store (*wallets_store_impl), ledger_impl{ std::make_unique (store, stats, network_params.ledger, flags_a.generate_cache, config_a.representative_vote_weight_minimum.number ()) }, ledger{ *ledger_impl }, - outbound_limiter{ config }, + outbound_limiter_impl{ std::make_unique (config) }, + outbound_limiter{ *outbound_limiter_impl }, message_processor_impl{ std::make_unique (config.message_processor, *this) }, message_processor{ *message_processor_impl }, // empty `config.peering_port` means the user made no port choice at all; diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 1f44b8031b..4cfb7db7d1 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -41,6 +40,7 @@ namespace nano { class active_elections; class backlog_population; +class bandwidth_limiter; class confirming_set; class message_processor; class monitor; @@ -166,7 +166,8 @@ class node final : public std::enable_shared_from_this nano::wallets_store & wallets_store; std::unique_ptr ledger_impl; nano::ledger & ledger; - nano::bandwidth_limiter outbound_limiter; + std::unique_ptr outbound_limiter_impl; + nano::bandwidth_limiter & outbound_limiter; std::unique_ptr message_processor_impl; nano::message_processor & message_processor; nano::network network; From e8d125877ec591ff9d0d83a9f307de5e226717de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:38:41 +0200 Subject: [PATCH 11/14] Rework telemetry config --- nano/node/node.cpp | 2 +- nano/node/telemetry.cpp | 8 ++++---- nano/node/telemetry.hpp | 30 +++++++++++++++--------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 493506cf33..89cd4f321d 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -155,7 +155,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy // otherwise, any value is considered, with `0` having the special meaning of 'let the OS pick a port instead' // network (*this, config.peering_port.has_value () ? *config.peering_port : 0), - telemetry{ nano::telemetry::config{ config, flags }, *this, network, observers, network_params, stats }, + telemetry{ flags, *this, network, observers, network_params, stats }, bootstrap_initiator (*this), bootstrap_server{ config.bootstrap_server, store, ledger, network_params.network, stats }, // BEWARE: `bootstrap` takes `network.port` instead of `config.peering_port` because when the user doesn't specify diff --git a/nano/node/telemetry.cpp b/nano/node/telemetry.cpp index 9016b73d1e..1c756a3866 100644 --- a/nano/node/telemetry.cpp +++ b/nano/node/telemetry.cpp @@ -18,8 +18,8 @@ using namespace std::chrono_literals; -nano::telemetry::telemetry (const config & config_a, nano::node & node_a, nano::network & network_a, nano::node_observers & observers_a, nano::network_params & network_params_a, nano::stats & stats_a) : - config_m{ config_a }, +nano::telemetry::telemetry (nano::node_flags const & flags_a, nano::node & node_a, nano::network & network_a, nano::node_observers & observers_a, nano::network_params & network_params_a, nano::stats & stats_a) : + config{ flags_a }, node{ node_a }, network{ network_a }, observers{ observers_a }, @@ -150,7 +150,7 @@ bool nano::telemetry::request_predicate () const { return true; } - if (config_m.enable_ongoing_requests) + if (config.enable_ongoing_requests) { return last_request + network_params.network.telemetry_request_interval < std::chrono::steady_clock::now (); } @@ -161,7 +161,7 @@ bool nano::telemetry::broadcast_predicate () const { debug_assert (!mutex.try_lock ()); - if (config_m.enable_ongoing_broadcasts) + if (config.enable_ongoing_broadcasts) { return last_broadcast + network_params.network.telemetry_broadcast_interval < std::chrono::steady_clock::now (); } diff --git a/nano/node/telemetry.hpp b/nano/node/telemetry.hpp index 3d99458ee9..be3542fa65 100644 --- a/nano/node/telemetry.hpp +++ b/nano/node/telemetry.hpp @@ -32,6 +32,19 @@ namespace transport class channel; } +class telemetry_config final +{ +public: + bool enable_ongoing_requests{ false }; // TODO: No longer used, remove + bool enable_ongoing_broadcasts{ true }; + +public: + explicit telemetry_config (nano::node_flags const & flags) : + enable_ongoing_broadcasts{ !flags.disable_providing_telemetry_metrics } + { + } +}; + /** * This class periodically broadcasts and requests telemetry from peers. * Those intervals are configurable via `telemetry_request_interval` & `telemetry_broadcast_interval` network constants @@ -43,19 +56,7 @@ namespace transport class telemetry { public: - struct config - { - bool enable_ongoing_requests{ false }; - bool enable_ongoing_broadcasts{ true }; - - config (nano::node_config const & config, nano::node_flags const & flags) : - enable_ongoing_broadcasts{ !flags.disable_providing_telemetry_metrics } - { - } - }; - -public: - telemetry (config const &, nano::node &, nano::network &, nano::node_observers &, nano::network_params &, nano::stats &); + telemetry (nano::node_flags const &, nano::node &, nano::network &, nano::node_observers &, nano::network_params &, nano::stats &); ~telemetry (); void start (); @@ -87,14 +88,13 @@ class telemetry std::unique_ptr collect_container_info (std::string const & name); private: // Dependencies + telemetry_config const config; nano::node & node; nano::network & network; nano::node_observers & observers; nano::network_params & network_params; nano::stats & stats; - const config config_m; - private: struct entry { From 431964cd265b82e067569eb32374fba4b1491a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:43:13 +0200 Subject: [PATCH 12/14] Use unique ptr for `telemetry` --- nano/core_test/websocket.cpp | 1 + nano/node/message_processor.cpp | 1 + nano/node/node.cpp | 3 ++- nano/node/node.hpp | 5 +++-- nano/rpc_test/rpc.cpp | 1 + nano/slow_test/node.cpp | 1 + 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index f62c2e9682..883d92c717 100644 --- a/nano/core_test/websocket.cpp +++ b/nano/core_test/websocket.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/message_processor.cpp b/nano/node/message_processor.cpp index 4e82a23ee2..f48542c304 100644 --- a/nano/node/message_processor.cpp +++ b/nano/node/message_processor.cpp @@ -2,6 +2,7 @@ #include #include #include +#include nano::message_processor::message_processor (message_processor_config const & config_a, nano::node & node_a) : config{ config_a }, diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 89cd4f321d..3bcaa939fd 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -155,7 +155,8 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy // otherwise, any value is considered, with `0` having the special meaning of 'let the OS pick a port instead' // network (*this, config.peering_port.has_value () ? *config.peering_port : 0), - telemetry{ flags, *this, network, observers, network_params, stats }, + telemetry_impl{ std::make_unique (flags, *this, network, observers, network_params, stats) }, + telemetry{ *telemetry_impl }, bootstrap_initiator (*this), bootstrap_server{ config.bootstrap_server, store, ledger, network_params.network, stats }, // BEWARE: `bootstrap` takes `network.port` instead of `config.peering_port` because when the user doesn't specify diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 4cfb7db7d1..d51137d5c5 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -45,6 +44,7 @@ class confirming_set; class message_processor; class monitor; class node; +class telemetry; class vote_processor; class vote_cache_processor; class vote_router; @@ -171,7 +171,8 @@ class node final : public std::enable_shared_from_this std::unique_ptr message_processor_impl; nano::message_processor & message_processor; nano::network network; - nano::telemetry telemetry; + std::unique_ptr telemetry_impl; + nano::telemetry & telemetry; nano::bootstrap_initiator bootstrap_initiator; nano::bootstrap_server bootstrap_server; std::unique_ptr tcp_listener_impl; diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 1f37473756..daecb52a9e 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 9efbd3b4b0..09c2f22fbb 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include From 536ae7a91f73c9a9605a350ef2f35a4ba61acf6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:18:08 +0200 Subject: [PATCH 13/14] Move mutex to `rate_limiter` --- nano/lib/rate_limiting.cpp | 6 ++---- nano/lib/rate_limiting.hpp | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/nano/lib/rate_limiting.cpp b/nano/lib/rate_limiting.cpp index 268e8b5e9c..2a4715c9ab 100644 --- a/nano/lib/rate_limiting.cpp +++ b/nano/lib/rate_limiting.cpp @@ -16,7 +16,6 @@ nano::rate::token_bucket::token_bucket (std::size_t max_token_count_a, std::size bool nano::rate::token_bucket::try_consume (unsigned tokens_required_a) { debug_assert (tokens_required_a <= 1e9); - nano::lock_guard guard{ mutex }; refill (); bool possible = current_size >= tokens_required_a; if (possible) @@ -48,14 +47,11 @@ void nano::rate::token_bucket::refill () std::size_t nano::rate::token_bucket::largest_burst () const { - nano::lock_guard guard{ mutex }; return max_token_count - smallest_size; } void nano::rate::token_bucket::reset (std::size_t max_token_count_a, std::size_t refill_rate_a) { - nano::lock_guard guard{ mutex }; - // A token count of 0 indicates unlimited capacity. We use 1e9 as // a sentinel, allowing largest burst to still be computed. if (max_token_count_a == 0 || refill_rate_a == 0) @@ -78,10 +74,12 @@ nano::rate_limiter::rate_limiter (std::size_t limit_a, double burst_ratio_a) : bool nano::rate_limiter::should_pass (std::size_t message_size_a) { + nano::lock_guard guard{ mutex }; return bucket.try_consume (nano::narrow_cast (message_size_a)); } void nano::rate_limiter::reset (std::size_t limit_a, double burst_ratio_a) { + nano::lock_guard guard{ mutex }; bucket.reset (static_cast (limit_a * burst_ratio_a), limit_a); } \ No newline at end of file diff --git a/nano/lib/rate_limiting.hpp b/nano/lib/rate_limiting.hpp index f027d70839..f672467872 100644 --- a/nano/lib/rate_limiting.hpp +++ b/nano/lib/rate_limiting.hpp @@ -54,8 +54,6 @@ class token_bucket std::size_t smallest_size{ 0 }; std::chrono::steady_clock::time_point last_refill; - mutable nano::mutex mutex; - static std::size_t constexpr unlimited_rate_sentinel{ static_cast (1e9) }; }; } @@ -73,5 +71,6 @@ class rate_limiter final private: nano::rate::token_bucket bucket; + mutable nano::mutex mutex; }; } \ No newline at end of file From e7810db8d02845100aa27e81f5ceb66c4db7db56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:21:50 +0200 Subject: [PATCH 14/14] Move functions in the node source file --- nano/node/node.cpp | 114 ++++++++++++++++++++++----------------------- nano/node/node.hpp | 9 ++-- 2 files changed, 63 insertions(+), 60 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 3bcaa939fd..182d1cd5ef 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -60,63 +60,6 @@ extern std::size_t nano_bootstrap_weights_beta_size; * node */ -void nano::node::keepalive (std::string const & address_a, uint16_t port_a) -{ - auto node_l (shared_from_this ()); - network.resolver.async_resolve (boost::asio::ip::tcp::resolver::query (address_a, std::to_string (port_a)), [node_l, address_a, port_a] (boost::system::error_code const & ec, boost::asio::ip::tcp::resolver::iterator i_a) { - if (!ec) - { - for (auto i (i_a), n (boost::asio::ip::tcp::resolver::iterator{}); i != n; ++i) - { - auto endpoint (nano::transport::map_endpoint_to_v6 (i->endpoint ())); - std::weak_ptr node_w (node_l); - auto channel (node_l->network.find_channel (endpoint)); - if (!channel) - { - node_l->network.tcp_channels.start_tcp (endpoint); - } - else - { - node_l->network.send_keepalive (channel); - } - } - } - else - { - node_l->logger.error (nano::log::type::node, "Error resolving address for keepalive: {}:{} ({})", address_a, port_a, ec.message ()); - } - }); -} - -nano::keypair nano::load_or_create_node_id (std::filesystem::path const & application_path) -{ - auto node_private_key_path = application_path / "node_id_private.key"; - std::ifstream ifs (node_private_key_path.c_str ()); - if (ifs.good ()) - { - nano::default_logger ().info (nano::log::type::init, "Reading node id from: '{}'", node_private_key_path.string ()); - - std::string node_private_key; - ifs >> node_private_key; - release_assert (node_private_key.size () == 64); - nano::keypair kp = nano::keypair (node_private_key); - return kp; - } - else - { - // no node_id found, generate new one - nano::default_logger ().info (nano::log::type::init, "Generating a new node id, saving to: '{}'", node_private_key_path.string ()); - - nano::keypair kp; - std::ofstream ofs (node_private_key_path.c_str (), std::ofstream::out | std::ofstream::trunc); - ofs << kp.prv.to_string () << std::endl - << std::flush; - ofs.close (); - release_assert (!ofs.fail ()); - return kp; - } -} - nano::node::node (std::shared_ptr io_ctx_a, uint16_t peering_port_a, std::filesystem::path const & application_path_a, nano::work_pool & work_a, nano::node_flags flags_a, unsigned seq) : node (io_ctx_a, application_path_a, nano::node_config (peering_port_a), work_a, flags_a, seq) { @@ -554,6 +497,34 @@ bool nano::node::copy_with_compaction (std::filesystem::path const & destination return store.copy_db (destination); } +void nano::node::keepalive (std::string const & address_a, uint16_t port_a) +{ + auto node_l (shared_from_this ()); + network.resolver.async_resolve (boost::asio::ip::tcp::resolver::query (address_a, std::to_string (port_a)), [node_l, address_a, port_a] (boost::system::error_code const & ec, boost::asio::ip::tcp::resolver::iterator i_a) { + if (!ec) + { + for (auto i (i_a), n (boost::asio::ip::tcp::resolver::iterator{}); i != n; ++i) + { + auto endpoint (nano::transport::map_endpoint_to_v6 (i->endpoint ())); + std::weak_ptr node_w (node_l); + auto channel (node_l->network.find_channel (endpoint)); + if (!channel) + { + node_l->network.tcp_channels.start_tcp (endpoint); + } + else + { + node_l->network.send_keepalive (channel); + } + } + } + else + { + node_l->logger.error (nano::log::type::node, "Error resolving address for keepalive: {}:{} ({})", address_a, port_a, ec.message ()); + } + }); +} + std::unique_ptr nano::collect_container_info (node & node, std::string const & name) { auto composite = std::make_unique (name); @@ -1356,3 +1327,32 @@ std::string nano::node::make_logger_identifier (const nano::keypair & node_id) // Node identifier consists of first 10 characters of node id return node_id.pub.to_node_id ().substr (0, 10); } + +nano::keypair nano::load_or_create_node_id (std::filesystem::path const & application_path) +{ + auto node_private_key_path = application_path / "node_id_private.key"; + std::ifstream ifs (node_private_key_path.c_str ()); + if (ifs.good ()) + { + nano::default_logger ().info (nano::log::type::init, "Reading node id from: '{}'", node_private_key_path.string ()); + + std::string node_private_key; + ifs >> node_private_key; + release_assert (node_private_key.size () == 64); + nano::keypair kp = nano::keypair (node_private_key); + return kp; + } + else + { + // no node_id found, generate new one + nano::default_logger ().info (nano::log::type::init, "Generating a new node id, saving to: '{}'", node_private_key_path.string ()); + + nano::keypair kp; + std::ofstream ofs (node_private_key_path.c_str (), std::ofstream::out | std::ofstream::trunc); + ofs << kp.prv.to_string () << std::endl + << std::flush; + ofs.close (); + release_assert (!ofs.fail ()); + return kp; + } +} \ No newline at end of file diff --git a/nano/node/node.hpp b/nano/node/node.hpp index d51137d5c5..b31578a190 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -80,16 +80,19 @@ class node final : public std::enable_shared_from_this ~node (); public: + void start (); + void stop (); + + std::shared_ptr shared (); + template void background (T action_a) { io_ctx.post (action_a); } + bool copy_with_compaction (std::filesystem::path const &); void keepalive (std::string const &, uint16_t); - void start (); - void stop (); - std::shared_ptr shared (); int store_version (); void process_confirmed (nano::election_status const &, uint64_t = 0); void process_active (std::shared_ptr const &);