Rewrite optimistic scheduler in terms of ledger sets and add ledger set height(account) overload.

This commit is contained in:
Colin LeMahieu 2024-03-21 14:36:37 +00:00
commit 95121403a2
No known key found for this signature in database
GPG key ID: 43708520C8DFB938
6 changed files with 16 additions and 15 deletions

View file

@ -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);

View file

@ -136,6 +136,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);
}
}

View file

@ -50,7 +50,7 @@ public:
/**
* 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

View file

@ -221,9 +221,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) {

View file

@ -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 };

View file

@ -60,7 +60,7 @@ public:
/**
* 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
@ -70,7 +70,7 @@ public:
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 ();