dncurrency/nano/node/backlog_population.hpp
Piotr Wójcik 82c4c10f7e
Add populate_backlog rpc command (#3860)
* Add `populate_backlog` rpc

* Add `populate_backlog` rpc tests

* Only allow `populate_backlog` RPC under enable_control

* Extract backlog population logic to separate class and run it on a dedicated thread

* Delay backlog population initial start

* Move triggered to start of the loop

* Use explicit dependencies

* Move delay assignment outside the loop and make it constant.

* Document backlog_population::triggered and thread members

It is not immediately obvious that the trigger can be used even when
backlog population is disabled and that it is used for manual triggering
mainly.

* Improve code readability

* Rename store to store_m to avoid compilation problem on gcc

* Document intention of notify function

* Break backlog_population's dependency on nodeconfig

Introduce the class nano::backlog_population::config to hold the
configuration items and not need access to nano::nodeconfig.

* Fix for compilation problem.

* Move to namespace

Co-authored-by: Dimitrios Siganos <dimitris@siganos.org>
2022-07-21 00:20:22 +02:00

58 lines
1.3 KiB
C++

#pragma once
#include <nano/lib/locks.hpp>
#include <atomic>
#include <condition_variable>
#include <thread>
namespace nano
{
class store;
class election_scheduler;
class backlog_population final
{
public:
struct config
{
bool ongoing_backlog_population_enabled;
unsigned int delay_between_runs_in_seconds;
};
explicit backlog_population (const config & config_a, store & store, election_scheduler & scheduler);
~backlog_population ();
void start ();
void stop ();
void trigger ();
/** Other components call this to notify us about external changes, so we can check our predicate. */
void notify ();
private:
void run ();
bool predicate () const;
void populate_backlog ();
/** This is a manual trigger, the ongoing backlog population does not use this.
* It can be triggered even when backlog population (frontiers confirmation) is disabled. */
bool triggered{ false };
std::atomic<bool> stopped{ false };
nano::condition_variable condition;
mutable nano::mutex mutex;
/** Thread that runs the backlog implementation logic. The thread always runs, even if
* backlog population is disabled, so that it can service a manual trigger (e.g. via RPC). */
std::thread thread;
config config_m;
private: // Dependencies
store & store_m;
election_scheduler & scheduler;
};
}