Skip to content

Commit

Permalink
Move bootstrap_ascending throttle class to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiago Silva committed Apr 6, 2023
1 parent 46b7af8 commit 1170407
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 42 deletions.
2 changes: 2 additions & 0 deletions nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 0 additions & 24 deletions nano/node/bootstrap_ascending/bootstrap_ascending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
20 changes: 2 additions & 18 deletions nano/node/bootstrap_ascending/bootstrap_ascending.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <nano/node/bootstrap/bootstrap_attempt.hpp>
#include <nano/node/bootstrap/bootstrap_config.hpp>
#include <nano/node/bootstrap/bootstrap_server.hpp>
#include <nano/node/bootstrap_ascending/throttle.hpp>

#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
Expand Down Expand Up @@ -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<bool> samples;
};

public:
bootstrap_ascending_service (nano::node_config &, nano::block_processor &, nano::ledger &, nano::network &, nano::stats &);
~bootstrap_ascending_service ();
Expand Down Expand Up @@ -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 {};
Expand Down
25 changes: 25 additions & 0 deletions nano/node/bootstrap_ascending/throttle.cpp
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;
}
}
23 changes: 23 additions & 0 deletions nano/node/bootstrap_ascending/throttle.hpp
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

0 comments on commit 1170407

Please sign in to comment.