diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 9c31be98c6..f3c46996af 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -56,6 +56,8 @@ add_library( bootstrap/bootstrap_server.cpp bootstrap_ascending/bootstrap_ascending.hpp bootstrap_ascending/bootstrap_ascending.cpp + bootstrap_ascending/throttle.hpp + bootstrap_ascending/throttle.cpp cli.hpp cli.cpp common.hpp diff --git a/nano/node/bootstrap_ascending/bootstrap_ascending.cpp b/nano/node/bootstrap_ascending/bootstrap_ascending.cpp index 0bd3e44b15..016b9bf7d1 100644 --- a/nano/node/bootstrap_ascending/bootstrap_ascending.cpp +++ b/nano/node/bootstrap_ascending/bootstrap_ascending.cpp @@ -13,30 +13,6 @@ using namespace std::chrono_literals; -nano::bootstrap_ascending_service::throttle::throttle (size_t count) : - successes{ count }, - samples{ count, true } -{ -} - -bool nano::bootstrap_ascending_service::throttle::throttled () const -{ - return successes == 0; -} - -void nano::bootstrap_ascending_service::throttle::add (bool sample) -{ - if (samples.front ()) - { - --successes; - } - samples.push_back (sample); - if (sample) - { - ++successes; - } -} - /* * database_iterator */ diff --git a/nano/node/bootstrap_ascending/bootstrap_ascending.hpp b/nano/node/bootstrap_ascending/bootstrap_ascending.hpp index 9134be6d3f..7b2c8fce9f 100644 --- a/nano/node/bootstrap_ascending/bootstrap_ascending.hpp +++ b/nano/node/bootstrap_ascending/bootstrap_ascending.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -36,23 +37,6 @@ class bootstrap_ascending_service { using id_t = uint64_t; - // Class used to throttle the ascending bootstrapper once it reaches a steady state - // Tracks verify_result samples and signals throttling if no tracked samples have gotten results - class throttle - { - public: - // Initialized with all true samples - explicit throttle (size_t size); - bool throttled () const; - void add (bool success); - - private: - // Rolling count of true samples in the sample buffer - size_t successes; - // Circular buffer that tracks sample results. True when something was retrieved, false otherwise - boost::circular_buffer samples; - }; - public: bootstrap_ascending_service (nano::node_config &, nano::block_processor &, nano::ledger &, nano::network &, nano::stats &); ~bootstrap_ascending_service (); @@ -312,7 +296,7 @@ class bootstrap_ascending_service private: account_sets accounts; buffered_iterator iterator; - throttle throttle; + nano::bootstrap_ascending::throttle throttle; // clang-format off class tag_sequenced {}; diff --git a/nano/node/bootstrap_ascending/throttle.cpp b/nano/node/bootstrap_ascending/throttle.cpp new file mode 100644 index 0000000000..5cfbaeb581 --- /dev/null +++ b/nano/node/bootstrap_ascending/throttle.cpp @@ -0,0 +1,25 @@ +#include + +nano::bootstrap_ascending::throttle::throttle (std::size_t count) : + successes{ count }, + samples{ count, true } +{ +} + +bool nano::bootstrap_ascending::throttle::throttled () const +{ + return successes == 0; +} + +void nano::bootstrap_ascending::throttle::add (bool sample) +{ + if (samples.front ()) + { + --successes; + } + samples.push_back (sample); + if (sample) + { + ++successes; + } +} \ No newline at end of file diff --git a/nano/node/bootstrap_ascending/throttle.hpp b/nano/node/bootstrap_ascending/throttle.hpp new file mode 100644 index 0000000000..68eef8716a --- /dev/null +++ b/nano/node/bootstrap_ascending/throttle.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace nano::bootstrap_ascending +{ +// Class used to throttle the ascending bootstrapper once it reaches a steady state +// Tracks verify_result samples and signals throttling if no tracked samples have gotten results +class throttle +{ +public: + // Initialized with all true samples + explicit throttle (std::size_t size); + bool throttled () const; + void add (bool success); + +private: + // Rolling count of true samples in the sample buffer + std::size_t successes; + // Circular buffer that tracks sample results. True when something was retrieved, false otherwise + boost::circular_buffer samples; +}; +} // nano::boostrap_ascending