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

Prevent getting stuck in block processor flush #2675

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
7 changes: 5 additions & 2 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3193,6 +3193,7 @@ TEST (node, block_processor_signatures)

/*
* State blocks go through a different signature path, ensure invalidly signed state blocks are rejected
* This test can freeze if the wake conditions in block_processor::flush are off, for that reason this is done async here
*/
TEST (node, block_processor_reject_state)
{
Expand All @@ -3204,12 +3205,14 @@ TEST (node, block_processor_reject_state)
send1->signature.bytes[0] ^= 1;
ASSERT_FALSE (node.ledger.block_exists (send1->hash ()));
node.process_active (send1);
node.block_processor.flush ();
auto flushed = std::async (std::launch::async, [&node] { node.block_processor.flush (); });
ASSERT_NE (std::future_status::timeout, flushed.wait_for (5s));
ASSERT_FALSE (node.ledger.block_exists (send1->hash ()));
auto send2 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - 2 * nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
node.work_generate_blocking (*send2);
node.process_active (send2);
node.block_processor.flush ();
auto flushed2 = std::async (std::launch::async, [&node] { node.block_processor.flush (); });
ASSERT_NE (std::future_status::timeout, flushed2.wait_for (5s));
ASSERT_TRUE (node.ledger.block_exists (send2->hash ()));
}

Expand Down
10 changes: 10 additions & 0 deletions nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ state_block_signature_verification (node.checker, node.ledger.network_params.led
state_block_signature_verification.blocks_verified_callback = [this](std::deque<nano::unchecked_info> & items, std::vector<int> const & verifications, std::vector<nano::block_hash> const & hashes, std::vector<nano::signature> const & blocks_signatures) {
this->process_verified_state_blocks (items, verifications, hashes, blocks_signatures);
};
state_block_signature_verification.transition_inactive_callback = [this]() {
if (this->flushing)
{
{
// Prevent a race with condition.wait in block_processor::flush
nano::lock_guard<std::mutex> guard (this->mutex);
}
this->condition.notify_all ();
}
};
}

nano::block_processor::~block_processor ()
Expand Down
3 changes: 3 additions & 0 deletions nano/node/state_block_signature_verification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ void nano::state_block_signature_verification::run (uint64_t state_block_signatu
lk.lock ();
}
active = false;
lk.unlock ();
transition_inactive_callback ();
lk.lock ();
}
else
{
Expand Down
1 change: 1 addition & 0 deletions nano/node/state_block_signature_verification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class state_block_signature_verification
bool is_active ();

std::function<void(std::deque<nano::unchecked_info> &, std::vector<int> const &, std::vector<nano::block_hash> const &, std::vector<nano::signature> const &)> blocks_verified_callback;
std::function<void()> transition_inactive_callback;

private:
nano::signature_checker & signature_checker;
Expand Down