diff --git a/nano/lib/constants.hpp b/nano/lib/constants.hpp index aeef2474e..4eaffde86 100644 --- a/nano/lib/constants.hpp +++ b/nano/lib/constants.hpp @@ -132,7 +132,6 @@ public: telemetry_cache_cutoff = 2000ms; telemetry_request_interval = 500ms; telemetry_broadcast_interval = 500ms; - optimistic_activation_delay = 2s; rep_crawler_normal_interval = 500ms; rep_crawler_warmup_interval = 500ms; } @@ -183,9 +182,6 @@ public: /** Telemetry data older than this value is considered stale */ std::chrono::milliseconds telemetry_cache_cutoff{ 1000 * 130 }; // 2 * `telemetry_broadcast_interval` + some margin - /** How much to delay activation of optimistic elections to avoid interfering with election scheduler */ - std::chrono::seconds optimistic_activation_delay{ 30 }; - std::chrono::milliseconds rep_crawler_normal_interval{ 1000 * 7 }; std::chrono::milliseconds rep_crawler_warmup_interval{ 1000 * 3 }; diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index cd38ab9ae..1ba7f764e 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -126,7 +126,7 @@ bool nano::scheduler::optimistic::predicate () const auto candidate = candidates.get ().begin (); debug_assert (candidate != candidates.get ().end ()); - return elapsed (candidate->timestamp, network_constants.optimistic_activation_delay); + return elapsed (candidate->timestamp, config.activation_delay); } void nano::scheduler::optimistic::run () @@ -136,7 +136,7 @@ void nano::scheduler::optimistic::run () { stats.inc (nano::stat::type::optimistic_scheduler, nano::stat::detail::loop); - condition.wait_for (lock, network_constants.optimistic_activation_delay / 2, [this] () { + condition.wait_for (lock, config.activation_delay / 2, [this] () { return stopped || predicate (); }); @@ -204,6 +204,7 @@ nano::error nano::scheduler::optimistic_config::deserialize (nano::tomlconfig & toml.get ("enable", enable); toml.get ("gap_threshold", gap_threshold); toml.get ("max_size", max_size); + toml.get_duration ("activation_delay", activation_delay); return toml.get_error (); } @@ -213,6 +214,7 @@ nano::error nano::scheduler::optimistic_config::serialize (nano::tomlconfig & to toml.put ("enable", enable, "Enable or disable optimistic elections\ntype:bool"); toml.put ("gap_threshold", gap_threshold, "Minimum difference between confirmation frontier and account frontier to become a candidate for optimistic confirmation\ntype:uint64"); toml.put ("max_size", max_size, "Maximum number of candidates stored in memory\ntype:uint64"); + toml.put ("activation_delay", activation_delay.count (), "How much to delay activation of optimistic elections to avoid interfering with election scheduler\ntype:milliseconds"); return toml.get_error (); } diff --git a/nano/node/scheduler/optimistic.hpp b/nano/node/scheduler/optimistic.hpp index 32557263d..6977c0ada 100644 --- a/nano/node/scheduler/optimistic.hpp +++ b/nano/node/scheduler/optimistic.hpp @@ -33,10 +33,13 @@ public: bool enable{ true }; /** Minimum difference between confirmation frontier and account frontier to become a candidate for optimistic confirmation */ - uint64_t gap_threshold{ 32 }; + uint64_t gap_threshold{ 16 }; /** Maximum number of candidates stored in memory */ std::size_t max_size{ 1024 * 4 }; + + /** How much to delay activation of optimistic elections to avoid interfering with election scheduler */ + std::chrono::milliseconds activation_delay{ 1s }; }; class optimistic final