Skip to content

Commit

Permalink
Rewrite priority scheduler in terms of ledger sets.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Apr 7, 2024
1 parent 7c4b239 commit 06e3d71
Showing 1 changed file with 25 additions and 33 deletions.
58 changes: 25 additions & 33 deletions nano/node/scheduler/priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,34 @@ void nano::scheduler::priority::stop ()
nano::join_or_pass (thread);
}

bool nano::scheduler::priority::activate (nano::account const & account_a, store::transaction const & transaction)
bool nano::scheduler::priority::activate (nano::account const & account, store::transaction const & transaction)
{
debug_assert (!account_a.is_zero ());
auto info = node.ledger.any.get (transaction, account_a);
if (info)
debug_assert (!account.is_zero ());
auto head = node.ledger.confirmed.head (transaction, account);
if (node.ledger.any.head (transaction, account) == head)
{
nano::confirmation_height_info conf_info;
node.store.confirmation_height.get (transaction, account_a, conf_info);
if (conf_info.height < info->block_count)
{
debug_assert (conf_info.frontier != info->head);
auto hash = conf_info.height == 0 ? info->open_block : node.ledger.any.successor (transaction, conf_info.frontier).value_or (0);
auto block = node.ledger.any.get (transaction, hash);
debug_assert (block != nullptr);
if (node.ledger.dependents_confirmed (transaction, *block))
{
auto const balance = node.ledger.any.balance (transaction, hash).value ();
auto const previous_balance = node.ledger.any.balance (transaction, conf_info.frontier).value_or (0);
auto const balance_priority = std::max (balance, previous_balance);

node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated);
node.logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated,
nano::log::arg{ "account", account_a.to_account () }, // TODO: Convert to lazy eval
nano::log::arg{ "block", block },
nano::log::arg{ "time", info->modified },
nano::log::arg{ "priority", balance_priority });

nano::lock_guard<nano::mutex> lock{ mutex };
buckets->push (info->modified, block, balance_priority);
notify ();

return true; // Activated
}
}
return false;
}
auto block = node.ledger.any.get (transaction, node.ledger.any.successor (transaction, { head.is_zero () ? static_cast<nano::uint256_union> (account) : head, head }).value ());
if (!node.ledger.dependents_confirmed (transaction, *block))
{
return false;
}
return false; // Not activated
auto const balance_priority = std::max (block->balance ().number (), node.ledger.confirmed.balance (transaction, head).value_or (0));
auto const time_priority = !head.is_zero () ? node.ledger.confirmed.get (transaction, head)->sideband ().timestamp : nano::seconds_since_epoch (); // New accounts get current timestamp i.e. lowest priority

node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated);
node.logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated,
nano::log::arg{ "account", account.to_account () }, // TODO: Convert to lazy eval
nano::log::arg{ "block", block },
nano::log::arg{ "time", time_priority },
nano::log::arg{ "priority", balance_priority });

nano::lock_guard<nano::mutex> lock{ mutex };
buckets->push (time_priority, block, balance_priority);
notify ();

return true; // Activated
}

void nano::scheduler::priority::notify ()
Expand Down

0 comments on commit 06e3d71

Please sign in to comment.