Skip to content

Commit

Permalink
Rewrite optimistic scheduler in terms of ledger sets and add ledger s…
Browse files Browse the repository at this point in the history
…et height(account) overload.
  • Loading branch information
clemahieu committed Apr 17, 2024
1 parent 2ca9061 commit 108834f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion nano/core_test/backlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST (backlog, population)
nano::test::system system{};
auto & node = *system.add_node ();

node.backlog.activate_callback.add ([&] (nano::secure::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::secure::transaction const & transaction, nano::account const & account) {
nano::lock_guard<nano::mutex> lock{ mutex };

activated.insert (account);
Expand Down
2 changes: 1 addition & 1 deletion nano/node/backlog_population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ void nano::backlog_population::activate (secure::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);
}
}
2 changes: 1 addition & 1 deletion nano/node/backlog_population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class backlog_population final
/**
* Callback called for each backlogged account
*/
using callback_t = nano::observer_set<secure::transaction const &, nano::account const &, nano::account_info const &, nano::confirmation_height_info const &>;
using callback_t = nano::observer_set<secure::transaction const &, nano::account const &>;
callback_t activate_callback;

private: // Dependencies
Expand Down
4 changes: 2 additions & 2 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
return ledger.weight (rep);
};

backlog.activate_callback.add ([this] (secure::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] (secure::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<nano::vote> const & vote, nano::vote_source source, std::unordered_map<nano::block_hash, nano::vote_code> const & results) {
Expand Down
17 changes: 9 additions & 8 deletions nano/node/scheduler/optimistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::secure::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.account_height (transaction, account);
auto confirmed_height = ledger.confirmed.account_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::secure::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<nano::mutex> lock{ mutex };
Expand Down
4 changes: 2 additions & 2 deletions nano/node/scheduler/optimistic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::secure::transaction const & transaction, nano::account const & account);

/**
* Notify about changes in AEC vacancy
Expand All @@ -70,7 +70,7 @@ class optimistic final
std::unique_ptr<container_info_component> 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::secure::transaction const & transaction, nano::account const & account) const;

bool predicate () const;
void run ();
Expand Down

0 comments on commit 108834f

Please sign in to comment.