diff --git a/nano/core_test/toml.cpp b/nano/core_test/toml.cpp index 9e2a5cbe83..b29519ba6a 100644 --- a/nano/core_test/toml.cpp +++ b/nano/core_test/toml.cpp @@ -245,6 +245,7 @@ TEST (toml, daemon_config_deserialize_defaults) ASSERT_EQ (conf.node.optimistic_scheduler.gap_threshold, defaults.node.optimistic_scheduler.gap_threshold); ASSERT_EQ (conf.node.optimistic_scheduler.max_size, defaults.node.optimistic_scheduler.max_size); + ASSERT_EQ (conf.node.hinted_scheduler.enabled, defaults.node.hinted_scheduler.enabled); ASSERT_EQ (conf.node.hinted_scheduler.hinting_threshold_percent, defaults.node.hinted_scheduler.hinting_threshold_percent); ASSERT_EQ (conf.node.hinted_scheduler.check_interval.count (), defaults.node.hinted_scheduler.check_interval.count ()); ASSERT_EQ (conf.node.hinted_scheduler.block_cooldown.count (), defaults.node.hinted_scheduler.block_cooldown.count ()); @@ -516,6 +517,7 @@ TEST (toml, daemon_config_deserialize_no_defaults) max_size = 999 [node.hinted_scheduler] + enabled = false hinting_threshold = 99 check_interval = 999 block_cooldown = 999 @@ -667,6 +669,7 @@ TEST (toml, daemon_config_deserialize_no_defaults) ASSERT_NE (conf.node.optimistic_scheduler.gap_threshold, defaults.node.optimistic_scheduler.gap_threshold); ASSERT_NE (conf.node.optimistic_scheduler.max_size, defaults.node.optimistic_scheduler.max_size); + ASSERT_NE (conf.node.hinted_scheduler.enabled, defaults.node.hinted_scheduler.enabled); ASSERT_NE (conf.node.hinted_scheduler.hinting_threshold_percent, defaults.node.hinted_scheduler.hinting_threshold_percent); ASSERT_NE (conf.node.hinted_scheduler.check_interval.count (), defaults.node.hinted_scheduler.check_interval.count ()); ASSERT_NE (conf.node.hinted_scheduler.block_cooldown.count (), defaults.node.hinted_scheduler.block_cooldown.count ()); diff --git a/nano/node/scheduler/hinted.cpp b/nano/node/scheduler/hinted.cpp index a6f976864f..0d971aa1e8 100644 --- a/nano/node/scheduler/hinted.cpp +++ b/nano/node/scheduler/hinted.cpp @@ -30,6 +30,11 @@ void nano::scheduler::hinted::start () { debug_assert (!thread.joinable ()); + if (!config.enabled) + { + return; + } + thread = std::thread{ [this] () { nano::thread_role::set (nano::thread_role::name::scheduler_hinted); run (); @@ -254,6 +259,7 @@ nano::scheduler::hinted_config::hinted_config (nano::network_constants const & n nano::error nano::scheduler::hinted_config::serialize (nano::tomlconfig & toml) const { + toml.put ("enable", enabled, "Enable or disable hinted elections\ntype:bool"); toml.put ("hinting_threshold", hinting_threshold_percent, "Percentage of online weight needed to start a hinted election. \ntype:uint32,[0,100]"); toml.put ("check_interval", check_interval.count (), "Interval between scans of the vote cache for possible hinted elections. \ntype:milliseconds"); toml.put ("block_cooldown", block_cooldown.count (), "Cooldown period for blocks that failed to start an election. \ntype:milliseconds"); @@ -264,6 +270,7 @@ nano::error nano::scheduler::hinted_config::serialize (nano::tomlconfig & toml) nano::error nano::scheduler::hinted_config::deserialize (nano::tomlconfig & toml) { + toml.get ("enabled", enabled); toml.get ("hinting_threshold", hinting_threshold_percent); auto check_interval_l = check_interval.count (); diff --git a/nano/node/scheduler/hinted.hpp b/nano/node/scheduler/hinted.hpp index 4bb30cd9ae..9e8fd425ac 100644 --- a/nano/node/scheduler/hinted.hpp +++ b/nano/node/scheduler/hinted.hpp @@ -36,6 +36,7 @@ class hinted_config final nano::error serialize (nano::tomlconfig & toml) const; public: + bool enabled{ true }; std::chrono::milliseconds check_interval{ 1000 }; std::chrono::milliseconds block_cooldown{ 10000 }; unsigned hinting_threshold_percent{ 10 }; diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index a11e1540e3..cda2866651 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -25,13 +25,13 @@ nano::scheduler::optimistic::~optimistic () void nano::scheduler::optimistic::start () { + debug_assert (!thread.joinable ()); + if (!config.enabled) { return; } - debug_assert (!thread.joinable ()); - thread = std::thread{ [this] () { nano::thread_role::set (nano::thread_role::name::scheduler_optimistic); run ();