Optimize unnecessary db lookups
This commit is contained in:
parent
2dd6605829
commit
9702ecd936
6 changed files with 51 additions and 34 deletions
|
@ -364,6 +364,7 @@ enum class detail
|
|||
// backlog
|
||||
activated,
|
||||
activate_failed,
|
||||
activate_skip,
|
||||
|
||||
// active
|
||||
insert,
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
#include <nano/store/component.hpp>
|
||||
#include <nano/store/confirmation_height.hpp>
|
||||
|
||||
nano::backlog_population::backlog_population (const config & config_a, nano::ledger & ledger, nano::stats & stats_a) :
|
||||
nano::backlog_population::backlog_population (const config & config_a, nano::scheduler::component & schedulers, nano::ledger & ledger, nano::stats & stats_a) :
|
||||
config_m{ config_a },
|
||||
schedulers{ schedulers },
|
||||
ledger{ ledger },
|
||||
stats{ stats_a }
|
||||
{
|
||||
|
@ -119,8 +120,6 @@ void nano::backlog_population::populate_backlog (nano::unique_lock<nano::mutex>
|
|||
|
||||
void nano::backlog_population::activate (secure::transaction const & transaction, nano::account const & account)
|
||||
{
|
||||
debug_assert (!activate_callback.empty ());
|
||||
|
||||
auto const maybe_account_info = ledger.store.account.get (transaction, account);
|
||||
if (!maybe_account_info)
|
||||
{
|
||||
|
@ -137,5 +136,8 @@ void nano::backlog_population::activate (secure::transaction const & transaction
|
|||
stats.inc (nano::stat::type::backlog, nano::stat::detail::activated);
|
||||
|
||||
activate_callback.notify (transaction, account);
|
||||
|
||||
schedulers.optimistic.activate (account, account_info, conf_info);
|
||||
schedulers.priority.activate (transaction, account, account_info, conf_info);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <nano/lib/locks.hpp>
|
||||
#include <nano/lib/numbers.hpp>
|
||||
#include <nano/lib/observer_set.hpp>
|
||||
#include <nano/node/scheduler/component.hpp>
|
||||
#include <nano/secure/common.hpp>
|
||||
|
||||
#include <condition_variable>
|
||||
|
@ -34,7 +35,7 @@ public:
|
|||
unsigned frequency;
|
||||
};
|
||||
|
||||
backlog_population (const config &, ledger &, nano::stats &);
|
||||
backlog_population (const config &, nano::scheduler::component &, nano::ledger &, nano::stats &);
|
||||
~backlog_population ();
|
||||
|
||||
void start ();
|
||||
|
@ -54,6 +55,7 @@ public:
|
|||
callback_t activate_callback;
|
||||
|
||||
private: // Dependencies
|
||||
nano::scheduler::component & schedulers;
|
||||
nano::ledger & ledger;
|
||||
nano::stats & stats;
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
|
|||
aggregator_impl{ std::make_unique<nano::request_aggregator> (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) },
|
||||
aggregator{ *aggregator_impl },
|
||||
wallets (wallets_store.init_error (), *this),
|
||||
backlog{ nano::backlog_population_config (config), ledger, stats },
|
||||
backlog{ nano::backlog_population_config (config), scheduler, 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 },
|
||||
|
@ -232,11 +232,6 @@ 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) {
|
||||
scheduler.priority.activate (transaction, account);
|
||||
scheduler.optimistic.activate (transaction, account);
|
||||
});
|
||||
|
||||
vote_router.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) {
|
||||
if (source != nano::vote_source::cache)
|
||||
{
|
||||
|
|
|
@ -57,33 +57,46 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio
|
|||
node.store.confirmation_height.get (transaction, account, 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.block_successor (transaction, conf_info.frontier).value_or (0);
|
||||
auto block = node.ledger.any.block_get (transaction, hash);
|
||||
debug_assert (block != nullptr);
|
||||
if (node.ledger.dependents_confirmed (transaction, *block))
|
||||
{
|
||||
auto const balance = node.ledger.any.block_balance (transaction, hash).value ();
|
||||
auto const previous_balance = node.ledger.any.block_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.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 activate (transaction, account, *info, conf_info);
|
||||
}
|
||||
}
|
||||
|
||||
return true; // Activated
|
||||
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activate_skip);
|
||||
return false; // Not activated
|
||||
}
|
||||
|
||||
bool nano::scheduler::priority::activate (secure::transaction const & transaction, nano::account const & account, nano::account_info const & info, nano::confirmation_height_info const & conf_info)
|
||||
{
|
||||
debug_assert (conf_info.frontier != info.head);
|
||||
|
||||
auto hash = conf_info.height == 0 ? info.open_block : node.ledger.any.block_successor (transaction, conf_info.frontier).value_or (0);
|
||||
auto block = node.ledger.any.block_get (transaction, hash);
|
||||
release_assert (block != nullptr);
|
||||
|
||||
if (node.ledger.dependents_confirmed (transaction, *block))
|
||||
{
|
||||
auto const balance = node.ledger.any.block_balance (transaction, hash).value ();
|
||||
auto const previous_balance = node.ledger.any.block_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.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
|
||||
}
|
||||
|
||||
stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activate_failed);
|
||||
return false; // Not activated
|
||||
}
|
||||
|
||||
void nano::scheduler::priority::notify ()
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
namespace nano
|
||||
{
|
||||
class account_info;
|
||||
class confirmation_height_info;
|
||||
class block;
|
||||
class container_info_component;
|
||||
class node;
|
||||
|
@ -48,6 +50,8 @@ public:
|
|||
* @return true if account was activated
|
||||
*/
|
||||
bool activate (secure::transaction const &, nano::account const &);
|
||||
bool activate (secure::transaction const &, nano::account const &, nano::account_info const &, nano::confirmation_height_info const &);
|
||||
|
||||
void notify ();
|
||||
std::size_t size () const;
|
||||
bool empty () const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue