diff --git a/nano/core_test/bootstrap_ascending.cpp b/nano/core_test/bootstrap_ascending.cpp index fd3850cc..f90e5d2a 100644 --- a/nano/core_test/bootstrap_ascending.cpp +++ b/nano/core_test/bootstrap_ascending.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -6,6 +7,8 @@ #include +#include + using namespace std::chrono_literals; namespace @@ -251,3 +254,32 @@ TEST (bootstrap_ascending, trace_base) // std::cerr << "node1: " << node1.network.endpoint () << std::endl; ASSERT_TIMELY (10s, node1.block (receive1->hash ()) != nullptr); } + +TEST (bootstrap_ascending, config_serialization) +{ + nano::bootstrap_ascending_config config1; + config1.requests_limit = 0x101; + config1.database_requests_limit = 0x102; + config1.pull_count = 0x103; + config1.timeout = 0x104; + config1.throttle_coefficient = 0x105; + config1.throttle_wait = 0x106; + config1.block_wait_count = 0x107; + nano::tomlconfig toml1; + ASSERT_FALSE (config1.serialize (toml1)); + std::stringstream stream1; + toml1.write (stream1); + auto string = stream1.str (); + std::stringstream stream2{ string }; + nano::tomlconfig toml2; + toml2.read (stream2); + nano::bootstrap_ascending_config config2; + ASSERT_FALSE (config2.deserialize (toml2)); + ASSERT_EQ (config1.requests_limit, config2.requests_limit); + ASSERT_EQ (config1.database_requests_limit, config2.database_requests_limit); + ASSERT_EQ (config1.pull_count, config2.pull_count); + ASSERT_EQ (config1.timeout, config2.timeout); + ASSERT_EQ (config1.throttle_coefficient, config2.throttle_coefficient); + ASSERT_EQ (config1.throttle_wait, config2.throttle_wait); + ASSERT_EQ (config1.block_wait_count, config2.block_wait_count); +} diff --git a/nano/node/bootstrap/bootstrap_config.cpp b/nano/node/bootstrap/bootstrap_config.cpp index 819cd64b..762fb14d 100644 --- a/nano/node/bootstrap/bootstrap_config.cpp +++ b/nano/node/bootstrap/bootstrap_config.cpp @@ -35,6 +35,7 @@ nano::error nano::bootstrap_ascending_config::deserialize (nano::tomlconfig & to toml.get ("timeout", timeout); toml.get ("throttle_coefficient", throttle_coefficient); toml.get ("throttle_wait", throttle_wait); + toml.get ("block_wait_count", block_wait_count); if (toml.has_key ("account_sets")) { @@ -53,6 +54,7 @@ nano::error nano::bootstrap_ascending_config::serialize (nano::tomlconfig & toml toml.put ("timeout", timeout, "Timeout in milliseconds for incoming ascending bootstrap messages to be processed.\ntype:milliseconds"); toml.put ("throttle_coefficient", throttle_coefficient, "Scales the number of samples to track for bootstrap throttling.\ntype:uint64"); toml.put ("throttle_wait", throttle_wait, "Length of time to wait between requests when throttled.\ntype:milliseconds"); + toml.put ("block_wait_count", block_wait_count, "Asending bootstrap will wait while block processor has more than this many blocks queued.\ntype:uint64"); nano::tomlconfig account_sets_l; account_sets.serialize (account_sets_l); diff --git a/nano/node/bootstrap/bootstrap_config.hpp b/nano/node/bootstrap/bootstrap_config.hpp index 89e7f27f..9b618580 100644 --- a/nano/node/bootstrap/bootstrap_config.hpp +++ b/nano/node/bootstrap/bootstrap_config.hpp @@ -33,6 +33,7 @@ public: nano::millis_t timeout{ 1000 * 3 }; std::size_t throttle_coefficient{ 16 }; nano::millis_t throttle_wait{ 100 }; + std::size_t block_wait_count{ 1000 }; nano::account_sets_config account_sets; }; diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index facea3f9..76e2aac3 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -194,9 +194,9 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, void nano::bootstrap_ascending::service::wait_blockprocessor () { nano::unique_lock lock{ mutex }; - while (!stopped && block_processor.half_full ()) + while (!stopped && block_processor.size () > config.bootstrap_ascending.block_wait_count) { - condition.wait_for (lock, 500ms, [this] () { return stopped; }); // Blockprocessor is relatively slow, sleeping here instead of using conditions + condition.wait_for (lock, std::chrono::milliseconds{ config.bootstrap_ascending.throttle_wait }, [this] () { return stopped; }); // Blockprocessor is relatively slow, sleeping here instead of using conditions } } @@ -206,7 +206,7 @@ std::shared_ptr nano::bootstrap_ascending::service::wa nano::unique_lock lock{ mutex }; while (!stopped && !(channel = scoring.channel ())) { - condition.wait_for (lock, 100ms, [this] () { return stopped; }); + condition.wait_for (lock, std::chrono::milliseconds{ config.bootstrap_ascending.throttle_wait }, [this] () { return stopped; }); } return channel; } @@ -512,6 +512,8 @@ std::unique_ptr nano::bootstrap_ascending::servi auto composite = std::make_unique (name); composite->add_component (std::make_unique (container_info{ "tags", tags.size (), sizeof (decltype (tags)::value_type) })); + composite->add_component (std::make_unique (container_info{ "throttle", throttle.size (), 0 })); + composite->add_component (std::make_unique (container_info{ "throttle_successes", throttle.successes (), 0 })); composite->add_component (accounts.collect_container_info ("accounts")); return composite; }