From 1ebcec3ce25e30a3afa07bc778f7caaef6e77f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 21 Mar 2024 17:55:22 +0100 Subject: [PATCH] Config option for disabling hinted scheduler (#4512) --- nano/core_test/toml.cpp | 3 +++ nano/node/scheduler/hinted.cpp | 7 +++++++ nano/node/scheduler/hinted.hpp | 1 + nano/node/scheduler/optimistic.cpp | 4 ++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/nano/core_test/toml.cpp b/nano/core_test/toml.cpp index 9e2a5cbe..b29519ba 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 a6f97686..0d971aa1 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 4bb30cd9..9e8fd425 100644 --- a/nano/node/scheduler/hinted.hpp +++ b/nano/node/scheduler/hinted.hpp @@ -36,6 +36,7 @@ public: 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 a11e1540..cda28666 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 ();