diff --git a/nano/core_test/backlog.cpp b/nano/core_test/backlog.cpp index 26d5680a88..b9351b6f26 100644 --- a/nano/core_test/backlog.cpp +++ b/nano/core_test/backlog.cpp @@ -21,7 +21,7 @@ TEST (backlog, population) nano::test::system system{}; auto & node = *system.add_node (); - node.backlog.activate_callback.add ([&] (nano::store::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { + node.backlog.activate_callback.add ([&] (nano::store::transaction const & transaction, nano::account const & account) { nano::lock_guard lock{ mutex }; activated.insert (account); diff --git a/nano/node/backlog_population.cpp b/nano/node/backlog_population.cpp index f459b50697..524e9d83d0 100644 --- a/nano/node/backlog_population.cpp +++ b/nano/node/backlog_population.cpp @@ -134,6 +134,6 @@ void nano::backlog_population::activate (store::transaction const & transaction, { stats.inc (nano::stat::type::backlog, nano::stat::detail::activated); - activate_callback.notify (transaction, account, account_info, conf_info); + activate_callback.notify (transaction, account); } } diff --git a/nano/node/backlog_population.hpp b/nano/node/backlog_population.hpp index 7bc1a6d00e..a81f3b3058 100644 --- a/nano/node/backlog_population.hpp +++ b/nano/node/backlog_population.hpp @@ -50,7 +50,7 @@ class backlog_population final /** * Callback called for each backlogged account */ - using callback_t = nano::observer_set; + using callback_t = nano::observer_set; callback_t activate_callback; private: // Dependencies diff --git a/nano/node/node.cpp b/nano/node/node.cpp index ed0f53bc77..096cbbe95c 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -215,9 +215,9 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy return ledger.weight (rep); }; - backlog.activate_callback.add ([this] (store::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { + backlog.activate_callback.add ([this] (store::transaction const & transaction, nano::account const & account) { scheduler.priority.activate (account, transaction); - scheduler.optimistic.activate (account, account_info, conf_info); + scheduler.optimistic.activate (transaction, account); }); active.vote_processed.add ([this] (std::shared_ptr const & vote, nano::vote_source source, std::unordered_map const & results) { diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index bb8683d1db..2a4550112b 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -55,30 +55,31 @@ void nano::scheduler::optimistic::notify () condition.notify_all (); } -bool nano::scheduler::optimistic::activate_predicate (const nano::account_info & account_info, const nano::confirmation_height_info & conf_info) const +bool nano::scheduler::optimistic::activate_predicate (nano::store::transaction const & transaction, nano::account const & account) const { - // Chain with a big enough gap between account frontier and confirmation frontier - if (account_info.block_count - conf_info.height > config.gap_threshold) + auto unconfirmed_height = ledger.any.height (transaction, account); + auto confirmed_height = ledger.confirmed.height (transaction, account); + // Account with nothing confirmed yet + if (confirmed_height == 0) { return true; } - // Account with nothing confirmed yet - if (conf_info.height == 0) + // Chain with a big enough gap between account frontier and confirmation frontier + if (unconfirmed_height - confirmed_height > config.gap_threshold) { return true; } return false; } -bool nano::scheduler::optimistic::activate (const nano::account & account, const nano::account_info & account_info, const nano::confirmation_height_info & conf_info) +bool nano::scheduler::optimistic::activate (nano::store::transaction const & transaction, nano::account const & account) { if (!config.enabled) { return false; } - debug_assert (account_info.block_count >= conf_info.height); - if (activate_predicate (account_info, conf_info)) + if (activate_predicate (transaction, account)) { { nano::lock_guard lock{ mutex }; diff --git a/nano/node/scheduler/optimistic.hpp b/nano/node/scheduler/optimistic.hpp index 547bd7e8c1..9e2ae23f56 100644 --- a/nano/node/scheduler/optimistic.hpp +++ b/nano/node/scheduler/optimistic.hpp @@ -60,7 +60,7 @@ class optimistic final /** * Called from backlog population to process accounts with unconfirmed blocks */ - bool activate (nano::account const &, nano::account_info const &, nano::confirmation_height_info const &); + bool activate (nano::store::transaction const & transaction, nano::account const & account); /** * Notify about changes in AEC vacancy @@ -70,7 +70,7 @@ class optimistic final std::unique_ptr collect_container_info (std::string const & name) const; private: - bool activate_predicate (nano::account_info const &, nano::confirmation_height_info const &) const; + bool activate_predicate (nano::store::transaction const & transaction, nano::account const & account) const; bool predicate () const; void run ();