-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move bootstrap_ascending throttle class to its own file
- Loading branch information
Thiago Silva
committed
Apr 6, 2023
1 parent
46b7af8
commit 1170407
Showing
5 changed files
with
52 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <nano/node/bootstrap_ascending/throttle.hpp> | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <boost/circular_buffer.hpp> | ||
|
||
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<bool> samples; | ||
}; | ||
} // nano::boostrap_ascending |