Minimize work validation calls (#2577)
With this PR there should only be one work_validate call per block until it is processed (then more are done to get the difficulty, a future PR will also remove the need for those).
This commit is contained in:
parent
6db4625783
commit
75b2d2ea8f
3 changed files with 25 additions and 22 deletions
|
@ -580,7 +580,9 @@ std::pair<std::shared_ptr<nano::election>, bool> nano::active_transactions::inse
|
|||
auto hash (block_a->hash ());
|
||||
result.first = nano::make_shared<nano::election> (node, block_a, skip_delay_a, confirmation_action_a);
|
||||
uint64_t difficulty (0);
|
||||
release_assert (!nano::work_validate (*block_a, &difficulty));
|
||||
auto error (nano::work_validate (*block_a, &difficulty));
|
||||
(void)error;
|
||||
debug_assert (!error);
|
||||
roots.get<tag_root> ().emplace (nano::conflict_info{ root, difficulty, difficulty, result.first });
|
||||
blocks.emplace (hash, result.first);
|
||||
adjust_difficulty (hash);
|
||||
|
|
|
@ -67,32 +67,25 @@ void nano::block_processor::add (std::shared_ptr<nano::block> block_a, uint64_t
|
|||
|
||||
void nano::block_processor::add (nano::unchecked_info const & info_a)
|
||||
{
|
||||
if (!nano::work_validate (*info_a.block))
|
||||
debug_assert (!nano::work_validate (*info_a.block));
|
||||
{
|
||||
auto hash (info_a.block->hash ());
|
||||
auto filter_hash (filter_item (hash, info_a.block->block_signature ()));
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
if (blocks_filter.find (filter_hash) == blocks_filter.end ())
|
||||
{
|
||||
auto hash (info_a.block->hash ());
|
||||
auto filter_hash (filter_item (hash, info_a.block->block_signature ()));
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
if (blocks_filter.find (filter_hash) == blocks_filter.end ())
|
||||
if (info_a.verified == nano::signature_verification::unknown && (info_a.block->type () == nano::block_type::state || info_a.block->type () == nano::block_type::open || !info_a.account.is_zero ()))
|
||||
{
|
||||
if (info_a.verified == nano::signature_verification::unknown && (info_a.block->type () == nano::block_type::state || info_a.block->type () == nano::block_type::open || !info_a.account.is_zero ()))
|
||||
{
|
||||
state_blocks.push_back (info_a);
|
||||
}
|
||||
else
|
||||
{
|
||||
blocks.push_back (info_a);
|
||||
}
|
||||
blocks_filter.insert (filter_hash);
|
||||
state_blocks.push_back (info_a);
|
||||
}
|
||||
else
|
||||
{
|
||||
blocks.push_back (info_a);
|
||||
}
|
||||
blocks_filter.insert (filter_hash);
|
||||
}
|
||||
condition.notify_all ();
|
||||
}
|
||||
else
|
||||
{
|
||||
node.logger.try_log ("nano::block_processor::add called for hash ", info_a.block->hash ().to_string (), " with invalid work ", nano::to_string_hex (info_a.block->block_work ()));
|
||||
debug_assert (false && "nano::block_processor::add called with invalid work");
|
||||
}
|
||||
condition.notify_all ();
|
||||
}
|
||||
|
||||
void nano::block_processor::force (std::shared_ptr<nano::block> block_a)
|
||||
|
|
|
@ -2002,7 +2002,15 @@ wallet (wallet_a)
|
|||
{
|
||||
show_label_ok (*status);
|
||||
this->status->setText ("");
|
||||
this->wallet.node.process_active (std::move (block_l));
|
||||
if (!nano::work_validate (*block_l))
|
||||
{
|
||||
this->wallet.node.process_active (std::move (block_l));
|
||||
}
|
||||
else
|
||||
{
|
||||
show_label_error (*status);
|
||||
this->status->setText ("Invalid work");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue