Revert changes to nano::scheduler::priority::activate
This commit is contained in:
parent
eb141ba940
commit
8c3cf40860
3 changed files with 35 additions and 20 deletions
|
@ -62,6 +62,11 @@ class amount : public uint128_union
|
|||
{
|
||||
public:
|
||||
using uint128_union::uint128_union;
|
||||
|
||||
operator nano::uint128_t () const
|
||||
{
|
||||
return number ();
|
||||
}
|
||||
};
|
||||
class raw_key;
|
||||
|
||||
|
|
|
@ -363,6 +363,7 @@ enum class detail
|
|||
|
||||
// backlog
|
||||
activated,
|
||||
activate_failed,
|
||||
|
||||
// active
|
||||
insert,
|
||||
|
|
|
@ -50,29 +50,38 @@ void nano::scheduler::priority::stop ()
|
|||
bool nano::scheduler::priority::activate (secure::transaction const & transaction, nano::account const & account)
|
||||
{
|
||||
debug_assert (!account.is_zero ());
|
||||
auto head = node.ledger.confirmed.account_head (transaction, account);
|
||||
if (node.ledger.any.account_head (transaction, account) == head)
|
||||
auto info = node.ledger.any.account_get (transaction, account);
|
||||
if (info)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auto block = node.ledger.any.block_get (transaction, node.ledger.any.block_successor (transaction, { head.is_zero () ? static_cast<nano::uint256_union> (account) : head, head }).value ());
|
||||
if (!node.ledger.dependents_confirmed (transaction, *block))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auto const balance_priority = std::max (block->balance ().number (), node.ledger.confirmed.block_balance (transaction, head).value_or (0).number ());
|
||||
auto const time_priority = !head.is_zero () ? node.ledger.confirmed.block_get (transaction, head)->sideband ().timestamp : nano::seconds_since_epoch (); // New accounts get current timestamp i.e. lowest priority
|
||||
nano::confirmation_height_info conf_info;
|
||||
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", time_priority },
|
||||
nano::log::arg{ "priority", balance_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", info->modified },
|
||||
nano::log::arg{ "priority", balance_priority });
|
||||
|
||||
nano::lock_guard<nano::mutex> lock{ mutex };
|
||||
buckets->push (time_priority, block, balance_priority);
|
||||
notify ();
|
||||
{
|
||||
nano::lock_guard<nano::mutex> lock{ mutex };
|
||||
buckets->push (info->modified, block, balance_priority);
|
||||
}
|
||||
notify ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true; // Activated
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue