Skip to content

Commit

Permalink
Use explicit dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Jul 20, 2022
1 parent 8b19067 commit 7866883
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
23 changes: 14 additions & 9 deletions nano/node/backlog_population.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include <nano/lib/threading.hpp>
#include <nano/node/backlog_population.hpp>
#include <nano/node/node.hpp>
#include <nano/node/election_scheduler.hpp>
#include <nano/node/nodeconfig.hpp>
#include <nano/secure/store.hpp>

nano::backlog_population::backlog_population (nano::node & node_a) :
node{ node_a }
nano::backlog_population::backlog_population (nano::node_config & config_a, nano::store & store_a, nano::election_scheduler & scheduler_a) :
config{ config_a },
store{ store_a },
scheduler{ scheduler_a }
{
}

Expand Down Expand Up @@ -53,15 +58,15 @@ void nano::backlog_population::run ()
nano::unique_lock<nano::mutex> lock{ mutex };
while (!stopped)
{
if (predicate () || (node.config.frontiers_confirmation != nano::frontiers_confirmation_mode::disabled))
if (predicate () || (config.frontiers_confirmation != nano::frontiers_confirmation_mode::disabled))
{
triggered = false;
lock.unlock ();
populate_backlog ();
lock.lock ();
}

auto delay = node.config.network_params.network.is_dev_network () ? std::chrono::seconds{ 1 } : std::chrono::duration_cast<std::chrono::seconds> (std::chrono::minutes{ 5 });
auto delay = config.network_params.network.is_dev_network () ? std::chrono::seconds{ 1 } : std::chrono::duration_cast<std::chrono::seconds> (std::chrono::minutes{ 5 });

condition.wait_for (lock, delay, [this] () {
return stopped || predicate ();
Expand All @@ -77,14 +82,14 @@ void nano::backlog_population::populate_backlog ()
uint64_t total = 0;
while (!stopped && !done)
{
auto transaction = node.store.tx_begin_read ();
auto transaction = store.tx_begin_read ();
auto count = 0;
for (auto i = node.store.account.begin (transaction, next), n = node.store.account.end (); !stopped && i != n && count < chunk_size; ++i, ++count, ++total)
for (auto i = store.account.begin (transaction, next), n = store.account.end (); !stopped && i != n && count < chunk_size; ++i, ++count, ++total)
{
auto const & account = i->first;
node.scheduler.activate (account, transaction);
scheduler.activate (account, transaction);
next = account.number () + 1;
}
done = node.store.account.begin (transaction, next) == node.store.account.end ();
done = store.account.begin (transaction, next) == store.account.end ();
}
}
13 changes: 9 additions & 4 deletions nano/node/backlog_population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

namespace nano
{
class node;
class node_config;
class store;
class election_scheduler;

class backlog_population final
{
public:
explicit backlog_population (nano::node & node);
explicit backlog_population (node_config & config, store & store, election_scheduler & scheduler);
~backlog_population ();

void start ();
Expand All @@ -27,13 +29,16 @@ class backlog_population final

void populate_backlog ();

nano::node & node;

bool triggered{ false };
std::atomic<bool> stopped{ false };

nano::condition_variable condition;
mutable nano::mutex mutex;
std::thread thread;

private: // Dependencies
node_config & config;
store & store;
election_scheduler & scheduler;
};
}
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, boost::filesystem::path co
scheduler{ *this },
aggregator (config, stats, active.generator, active.final_generator, history, ledger, wallets, active),
wallets (wallets_store.init_error (), *this),
backlog{ *this },
backlog{ config, store, scheduler },
startup_time (std::chrono::steady_clock::now ()),
node_seq (seq)
{
Expand Down

0 comments on commit 7866883

Please sign in to comment.