Skip to content

Commit

Permalink
Config improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Aug 5, 2024
1 parent 3396184 commit 8541e90
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 63 deletions.
29 changes: 0 additions & 29 deletions nano/core_test/bootstrap_ascending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,32 +266,3 @@ 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_rate_limit = 0x102;
config1.pull_count = 0x103;
config1.request_timeout = 0x104ms;
config1.throttle_coefficient = 0x105;
config1.throttle_wait = 0x106ms;
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_rate_limit, config2.database_rate_limit);
ASSERT_EQ (config1.pull_count, config2.pull_count);
ASSERT_EQ (config1.request_timeout, config2.request_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);
}
40 changes: 39 additions & 1 deletion nano/core_test/toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ TEST (toml, daemon_config_deserialize_defaults)
std::stringstream ss;
ss << R"toml(
[node]
[node.bootstrap_ascending]
[node.bootstrap_server]
[node.block_processor]
[node.diagnostics.txn_tracking]
[node.httpcallback]
Expand All @@ -128,7 +130,6 @@ TEST (toml, daemon_config_deserialize_defaults)
[node.websocket]
[node.lmdb]
[node.rocksdb]
[node.bootstrap_server]
[opencl]
[rpc]
[rpc.child_process]
Expand Down Expand Up @@ -265,6 +266,18 @@ TEST (toml, daemon_config_deserialize_defaults)
ASSERT_EQ (conf.node.vote_processor.threads, defaults.node.vote_processor.threads);
ASSERT_EQ (conf.node.vote_processor.batch_size, defaults.node.vote_processor.batch_size);

ASSERT_EQ (conf.node.bootstrap_ascending.enable, defaults.node.bootstrap_ascending.enable);
ASSERT_EQ (conf.node.bootstrap_ascending.enable_database_scan, defaults.node.bootstrap_ascending.enable_database_scan);
ASSERT_EQ (conf.node.bootstrap_ascending.enable_dependency_walker, defaults.node.bootstrap_ascending.enable_dependency_walker);
ASSERT_EQ (conf.node.bootstrap_ascending.requests_limit, defaults.node.bootstrap_ascending.requests_limit);
ASSERT_EQ (conf.node.bootstrap_ascending.database_rate_limit, defaults.node.bootstrap_ascending.database_rate_limit);
ASSERT_EQ (conf.node.bootstrap_ascending.pull_count, defaults.node.bootstrap_ascending.pull_count);
ASSERT_EQ (conf.node.bootstrap_ascending.request_timeout, defaults.node.bootstrap_ascending.request_timeout);
ASSERT_EQ (conf.node.bootstrap_ascending.throttle_coefficient, defaults.node.bootstrap_ascending.throttle_coefficient);
ASSERT_EQ (conf.node.bootstrap_ascending.throttle_wait, defaults.node.bootstrap_ascending.throttle_wait);
ASSERT_EQ (conf.node.bootstrap_ascending.block_wait_count, defaults.node.bootstrap_ascending.block_wait_count);
ASSERT_EQ (conf.node.bootstrap_ascending.max_requests, defaults.node.bootstrap_ascending.max_requests);

ASSERT_EQ (conf.node.bootstrap_server.max_queue, defaults.node.bootstrap_server.max_queue);
ASSERT_EQ (conf.node.bootstrap_server.threads, defaults.node.bootstrap_server.threads);
ASSERT_EQ (conf.node.bootstrap_server.batch_size, defaults.node.bootstrap_server.batch_size);
Expand Down Expand Up @@ -576,6 +589,19 @@ TEST (toml, daemon_config_deserialize_no_defaults)
threads = 999
batch_size = 999
[node.bootstrap_ascending]
enable = false
enable_database_scan = false
enable_dependency_walker = false
requests_limit = 999
database_rate_limit = 999
pull_count = 999
request_timeout = 999
throttle_coefficient = 999
throttle_wait = 999
block_wait_count = 999
max_requests = 999
[node.bootstrap_server]
max_queue = 999
threads = 999
Expand Down Expand Up @@ -740,6 +766,18 @@ TEST (toml, daemon_config_deserialize_no_defaults)
ASSERT_NE (conf.node.vote_processor.threads, defaults.node.vote_processor.threads);
ASSERT_NE (conf.node.vote_processor.batch_size, defaults.node.vote_processor.batch_size);

ASSERT_NE (conf.node.bootstrap_ascending.enable, defaults.node.bootstrap_ascending.enable);
ASSERT_NE (conf.node.bootstrap_ascending.enable_database_scan, defaults.node.bootstrap_ascending.enable_database_scan);
ASSERT_NE (conf.node.bootstrap_ascending.enable_dependency_walker, defaults.node.bootstrap_ascending.enable_dependency_walker);
ASSERT_NE (conf.node.bootstrap_ascending.requests_limit, defaults.node.bootstrap_ascending.requests_limit);
ASSERT_NE (conf.node.bootstrap_ascending.database_rate_limit, defaults.node.bootstrap_ascending.database_rate_limit);
ASSERT_NE (conf.node.bootstrap_ascending.pull_count, defaults.node.bootstrap_ascending.pull_count);
ASSERT_NE (conf.node.bootstrap_ascending.request_timeout, defaults.node.bootstrap_ascending.request_timeout);
ASSERT_NE (conf.node.bootstrap_ascending.throttle_coefficient, defaults.node.bootstrap_ascending.throttle_coefficient);
ASSERT_NE (conf.node.bootstrap_ascending.throttle_wait, defaults.node.bootstrap_ascending.throttle_wait);
ASSERT_NE (conf.node.bootstrap_ascending.block_wait_count, defaults.node.bootstrap_ascending.block_wait_count);
ASSERT_NE (conf.node.bootstrap_ascending.max_requests, defaults.node.bootstrap_ascending.max_requests);

ASSERT_NE (conf.node.bootstrap_server.max_queue, defaults.node.bootstrap_server.max_queue);
ASSERT_NE (conf.node.bootstrap_server.threads, defaults.node.bootstrap_server.threads);
ASSERT_NE (conf.node.bootstrap_server.batch_size, defaults.node.bootstrap_server.batch_size);
Expand Down
2 changes: 1 addition & 1 deletion nano/lib/tomlconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class tomlconfig : public nano::configbase
template <typename Duration>
tomlconfig & get_duration (std::string const & key, Duration & target)
{
uint64_t value;
uint64_t value = target.count ();
get (key, value);
target = Duration{ value };
return *this;
Expand Down
14 changes: 12 additions & 2 deletions nano/node/bootstrap/bootstrap_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ nano::error nano::account_sets_config::serialize (nano::tomlconfig & toml) const
*/
nano::error nano::bootstrap_ascending_config::deserialize (nano::tomlconfig & toml)
{
toml.get ("enable", enable);
toml.get ("enable_database_scan", enable_database_scan);
toml.get ("enable_dependency_walker", enable_dependency_walker);

toml.get ("requests_limit", requests_limit);
toml.get ("database_rate_limit", database_rate_limit);
toml.get ("pull_count", pull_count);
toml.get_duration ("timeout", request_timeout);
toml.get_duration ("request_timeout", request_timeout);
toml.get ("throttle_coefficient", throttle_coefficient);
toml.get_duration ("throttle_wait", throttle_wait);
toml.get ("block_wait_count", block_wait_count);
toml.get ("max_requests", max_requests);

if (toml.has_key ("account_sets"))
{
Expand All @@ -48,13 +53,18 @@ nano::error nano::bootstrap_ascending_config::deserialize (nano::tomlconfig & to

nano::error nano::bootstrap_ascending_config::serialize (nano::tomlconfig & toml) const
{
toml.put ("enable", enable, "Enable or disable the ascending bootstrap. Disabling it is not recommended and will prevent the node from syncing.\ntype:bool");
toml.put ("enable_database_scan", enable_database_scan, "Enable or disable the 'database scan` strategy for the ascending bootstrap.\ntype:bool");
toml.put ("enable_dependency_walker", enable_dependency_walker, "Enable or disable the 'dependency walker` strategy for the ascending bootstrap.\ntype:bool");

toml.put ("requests_limit", requests_limit, "Request limit to ascending bootstrap after which requests will be dropped.\nNote: changing to unlimited (0) is not recommended.\ntype:uint64");
toml.put ("database_rate_limit", database_rate_limit, "Rate limit on scanning accounts and pending entries from database.\nNote: changing to unlimited (0) is not recommended as this operation competes for resources on querying the database.\ntype:uint64");
toml.put ("pull_count", pull_count, "Number of requested blocks for ascending bootstrap request.\ntype:uint64");
toml.put ("timeout", request_timeout.count (), "Timeout in milliseconds for incoming ascending bootstrap messages to be processed.\ntype:milliseconds");
toml.put ("request_timeout", request_timeout.count (), "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.count (), "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");
toml.put ("max_requests", max_requests, "Maximum total number of in flight requests.\ntype:uint64");

nano::tomlconfig account_sets_l;
account_sets.serialize (account_sets_l);
Expand Down
14 changes: 10 additions & 4 deletions nano/node/bootstrap/bootstrap_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class account_sets_config final
nano::error deserialize (nano::tomlconfig & toml);
nano::error serialize (nano::tomlconfig & toml) const;

public:
std::size_t consideration_count{ 4 };
std::size_t priorities_max{ 256 * 1024 };
std::size_t blocking_max{ 256 * 1024 };
Expand All @@ -28,14 +29,19 @@ class bootstrap_ascending_config final
nano::error deserialize (nano::tomlconfig & toml);
nano::error serialize (nano::tomlconfig & toml) const;

public:
bool enable{ true };
bool enable_database_scan{ true };
bool enable_dependency_walker{ true };

// Maximum number of un-responded requests per channel
std::size_t requests_limit{ 64 };
std::size_t database_rate_limit{ 1024 };
std::size_t pull_count{ nano::bootstrap_server::max_blocks };
std::size_t requests_limit{ 64 }; // TODO: => channel_requests_limit
std::size_t database_rate_limit{ 1024 }; // TODO: Adjust for live network (lower)
std::size_t pull_count{ nano::bootstrap_server::max_blocks }; // TODO: => max_pull_count & use in requests
std::chrono::milliseconds request_timeout{ 1000 * 5 };
std::size_t throttle_coefficient{ 8 * 1024 };
std::chrono::milliseconds throttle_wait{ 100 };
std::size_t block_wait_count{ 1000 };
std::size_t block_wait_count{ 1000 }; // TODO: Block processor threshold
std::size_t max_requests{ 1024 * 16 }; // TODO: Adjust for live network

nano::account_sets_config account_sets;
Expand Down
57 changes: 35 additions & 22 deletions nano/node/bootstrap_ascending/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ using namespace std::chrono_literals;
* bootstrap_ascending
*/

nano::bootstrap_ascending::service::service (nano::node_config const & config_a, nano::block_processor & block_processor_a, nano::ledger & ledger_a, nano::network & network_a, nano::stats & stat_a) :
config{ config_a },
network_consts{ config.network_params.network },
nano::bootstrap_ascending::service::service (nano::node_config const & node_config_a, nano::block_processor & block_processor_a, nano::ledger & ledger_a, nano::network & network_a, nano::stats & stat_a, nano::logger & logger_a) :
config{ node_config_a.bootstrap_ascending },
network_constants{ node_config_a.network_params.network },
block_processor{ block_processor_a },
ledger{ ledger_a },
network{ network_a },
stats{ stat_a },
accounts{ config.bootstrap_ascending.account_sets, stats },
logger{ logger_a },
accounts{ config.account_sets, stats },
iterator{ ledger },
throttle{ compute_throttle_size () },
scoring{ config.bootstrap_ascending, config.network_params.network },
database_limiter{ config.bootstrap_ascending.database_rate_limit, 1.0 }
scoring{ config, node_config_a.network_params.network },
database_limiter{ config.database_rate_limit, 1.0 }
{
// TODO: This is called from a very congested blockprocessor thread. Offload this work to a dedicated processing thread
block_processor.batch_processed.add ([this] (auto const & batch) {
Expand All @@ -47,7 +48,7 @@ nano::bootstrap_ascending::service::service (nano::node_config const & config_a,
condition.notify_all ();
});

accounts.priority_set (config.network_params.ledger.genesis->account_field ().value ());
accounts.priority_set (node_config_a.network_params.ledger.genesis->account_field ().value ());
}

nano::bootstrap_ascending::service::~service ()
Expand All @@ -66,20 +67,32 @@ void nano::bootstrap_ascending::service::start ()
debug_assert (!dependencies_thread.joinable ());
debug_assert (!timeout_thread.joinable ());

if (!config.enable)
{
logger.warn (nano::log::type::bootstrap, "Ascending bootstrap is disabled");
return;
}

priorities_thread = std::thread ([this] () {
nano::thread_role::set (nano::thread_role::name::ascending_bootstrap);
run_priorities ();
});

database_thread = std::thread ([this] () {
nano::thread_role::set (nano::thread_role::name::ascending_bootstrap);
run_database ();
});
if (config.enable_database_scan)
{
database_thread = std::thread ([this] () {
nano::thread_role::set (nano::thread_role::name::ascending_bootstrap);
run_database ();
});
}

dependencies_thread = std::thread ([this] () {
nano::thread_role::set (nano::thread_role::name::ascending_bootstrap);
run_dependencies ();
});
if (config.enable_dependency_walker)
{
dependencies_thread = std::thread ([this] () {
nano::thread_role::set (nano::thread_role::name::ascending_bootstrap);
run_dependencies ();
});
}

timeout_thread = std::thread ([this] () {
nano::thread_role::set (nano::thread_role::name::ascending_bootstrap);
Expand Down Expand Up @@ -112,7 +125,7 @@ void nano::bootstrap_ascending::service::send (std::shared_ptr<nano::transport::
tags.get<tag_id> ().insert (tag);
}

nano::asc_pull_req request{ network_consts };
nano::asc_pull_req request{ network_constants };
request.id = tag.id;

switch (tag.type)
Expand Down Expand Up @@ -231,22 +244,22 @@ void nano::bootstrap_ascending::service::wait (std::function<bool ()> const & pr
while (!stopped && !predicate ())
{
condition.wait_for (lock, interval);
interval = std::min (interval * 2, config.bootstrap_ascending.throttle_wait);
interval = std::min (interval * 2, config.throttle_wait);
}
}

void nano::bootstrap_ascending::service::wait_tags ()
{
wait ([this] () {
debug_assert (!mutex.try_lock ());
return tags.size () < config.bootstrap_ascending.max_requests;
return tags.size () < config.max_requests;
});
}

void nano::bootstrap_ascending::service::wait_blockprocessor ()
{
wait ([this] () {
return block_processor.size (nano::block_source::bootstrap) < config.bootstrap_ascending.block_wait_count;
return block_processor.size (nano::block_source::bootstrap) < config.block_wait_count;
});
}

Expand Down Expand Up @@ -534,7 +547,7 @@ void nano::bootstrap_ascending::service::cleanup_and_sync ()

throttle.resize (compute_throttle_size ());

auto const cutoff = std::chrono::steady_clock::now () - config.bootstrap_ascending.request_timeout;
auto const cutoff = std::chrono::steady_clock::now () - config.request_timeout;
auto should_timeout = [cutoff] (async_tag const & tag) {
return tag.timestamp < cutoff;
};
Expand Down Expand Up @@ -615,7 +628,7 @@ void nano::bootstrap_ascending::service::process (nano::asc_pull_ack const & mes

// Track bootstrap request response time
stats.inc (nano::stat::type::bootstrap_ascending_reply, to_stat_detail (tag.type));
stats.sample (nano::stat::sample::bootstrap_tag_duration, nano::log::milliseconds_delta (tag.timestamp), { 0, config.bootstrap_ascending.request_timeout.count () });
stats.sample (nano::stat::sample::bootstrap_tag_duration, nano::log::milliseconds_delta (tag.timestamp), { 0, config.request_timeout.count () });

scoring.received_message (channel);

Expand Down Expand Up @@ -800,7 +813,7 @@ auto nano::bootstrap_ascending::service::info () const -> nano::bootstrap_ascend

std::size_t nano::bootstrap_ascending::service::compute_throttle_size () const
{
std::size_t size_new = config.bootstrap_ascending.throttle_coefficient * static_cast<size_t> (std::log (ledger.account_count ()));
std::size_t size_new = config.throttle_coefficient * static_cast<size_t> (std::log (ledger.account_count ()));
return std::max (size_new, 16ul);
}

Expand Down
7 changes: 4 additions & 3 deletions nano/node/bootstrap_ascending/service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace bootstrap_ascending
class service
{
public:
service (nano::node_config const &, nano::block_processor &, nano::ledger &, nano::network &, nano::stats &);
service (nano::node_config const &, nano::block_processor &, nano::ledger &, nano::network &, nano::stats &, nano::logger &);
~service ();

void start ();
Expand All @@ -63,12 +63,13 @@ namespace bootstrap_ascending
nano::bootstrap_ascending::account_sets::info_t info () const;

private: // Dependencies
nano::node_config const & config;
nano::network_constants const & network_consts;
bootstrap_ascending_config const & config;
nano::network_constants const & network_constants;
nano::block_processor & block_processor;
nano::ledger & ledger;
nano::network & network;
nano::stats & stats;
nano::logger & logger;

public: // Tag
enum class query_type
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
aggregator{ *aggregator_impl },
wallets (wallets_store.init_error (), *this),
backlog{ nano::backlog_population_config (config), scheduler, ledger, stats },
ascendboot_impl{ std::make_unique<nano::bootstrap_ascending::service> (config, block_processor, ledger, network, stats) },
ascendboot_impl{ std::make_unique<nano::bootstrap_ascending::service> (config, block_processor, ledger, network, stats, logger) },
ascendboot{ *ascendboot_impl },
websocket{ config.websocket_config, observers, wallets, ledger, io_ctx, logger },
epoch_upgrader{ *this, ledger, store, network_params, logger },
Expand Down

0 comments on commit 8541e90

Please sign in to comment.