Skip to content

Commit

Permalink
Update backlog population to use unconfirmed_set
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Mar 28, 2024
1 parent e71bb49 commit 775a8ae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 36 deletions.
40 changes: 9 additions & 31 deletions nano/node/backlog_population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#include <nano/node/backlog_population.hpp>
#include <nano/node/nodeconfig.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/store/account.hpp>
#include <nano/store/component.hpp>
#include <nano/store/confirmation_height.hpp>

nano::backlog_population::backlog_population (const config & config_a, nano::store::component & store_a, nano::stats & stats_a) :
nano::backlog_population::backlog_population (const config & config_a, nano::ledger & ledger, nano::stats & stats_a) :
config_m{ config_a },
store{ store_a },
ledger{ ledger },
stats{ stats_a }
{
}
Expand Down Expand Up @@ -90,22 +91,22 @@ void nano::backlog_population::populate_backlog (nano::unique_lock<nano::mutex>
lock.unlock ();

{
auto transaction = store.tx_begin_read ();
auto transaction = ledger.store.tx_begin_read ();

auto count = 0u;
auto i = store.account.begin (transaction, next);
auto const end = store.account.end ();
auto i = ledger.unconfirmed_set.account.begin ();
auto const end = ledger.unconfirmed_set.account.end ();
for (; i != end && count < chunk_size; ++i, ++count, ++total)
{
transaction.refresh_if_needed ();

stats.inc (nano::stat::type::backlog, nano::stat::detail::total);

auto const & account = i->first;
activate (transaction, account);
next = account.number () + 1;
stats.inc (nano::stat::type::backlog, nano::stat::detail::activated);
activate_callback.notify (transaction, account);
}
done = store.account.begin (transaction, next) == end;
done = ledger.unconfirmed_set.account.empty ();
}

lock.lock ();
Expand All @@ -114,26 +115,3 @@ void nano::backlog_population::populate_backlog (nano::unique_lock<nano::mutex>
condition.wait_for (lock, std::chrono::milliseconds{ 1000 / config_m.frequency });
}
}

void nano::backlog_population::activate (store::transaction const & transaction, nano::account const & account)
{
debug_assert (!activate_callback.empty ());

auto const maybe_account_info = store.account.get (transaction, account);
if (!maybe_account_info)
{
return;
}
auto const account_info = *maybe_account_info;

auto const maybe_conf_info = store.confirmation_height.get (transaction, account);
auto const conf_info = maybe_conf_info.value_or (nano::confirmation_height_info{});

// If conf info is empty then it means then it means nothing is confirmed yet
if (conf_info.height < account_info.block_count)
{
stats.inc (nano::stat::type::backlog, nano::stat::detail::activated);

activate_callback.notify (transaction, account);
}
}
7 changes: 3 additions & 4 deletions nano/node/backlog_population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

namespace nano::store
{
class component;
class transaction;
}
namespace nano
{
class account_info;
class election_scheduler;
class ledger;
class stats;

class backlog_population final
Expand All @@ -34,7 +34,7 @@ class backlog_population final
unsigned frequency;
};

backlog_population (const config &, store::component &, nano::stats &);
backlog_population (const config &, nano::ledger & ledger, nano::stats &);
~backlog_population ();

void start ();
Expand All @@ -54,7 +54,7 @@ class backlog_population final
callback_t activate_callback;

private: // Dependencies
nano::store::component & store;
nano::ledger & ledger;
nano::stats & stats;

config config_m;
Expand All @@ -64,7 +64,6 @@ class backlog_population final
bool predicate () const;

void populate_backlog (nano::unique_lock<nano::mutex> & lock);
void activate (store::transaction const &, nano::account const &);

/** 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. */
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
scheduler{ *scheduler_impl },
aggregator (config, stats, generator, final_generator, history, ledger, wallets, active),
wallets (wallets_store.init_error (), *this),
backlog{ nano::backlog_population_config (config), store, stats },
backlog{ nano::backlog_population_config (config), ledger, stats },
ascendboot{ config, block_processor, ledger, network, stats },
websocket{ config.websocket_config, observers, wallets, ledger, io_ctx, logger },
epoch_upgrader{ *this, ledger, store, network_params, logger },
Expand Down
2 changes: 2 additions & 0 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class write_transaction;

namespace nano
{
class backlog_population;
class block;
class block_delta;
enum class block_status;
Expand All @@ -41,6 +42,7 @@ class stats;

class ledger final
{
friend class backlog_population;
friend class block_check_context;
friend class ledger_view_unconfirmed;
template <typename T>
Expand Down

0 comments on commit 775a8ae

Please sign in to comment.