Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize work validation calls #2577

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 13 additions & 20 deletions nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion nano/qt/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down