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

Consistently add conflicting block to election #2652

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
24 changes: 24 additions & 0 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,30 @@ TEST (node, fork_publish)
ASSERT_TRUE (node0.expired ());
}

// Tests that an election gets started correctly from a fork
TEST (node, fork_publish_inactive)
{
nano::system system (1);
nano::genesis genesis;
nano::keypair key1;
nano::keypair key2;
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key1.pub, nano::genesis_amount - 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, nano::genesis_amount - 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, send1->block_work ()));
auto & node (*system.nodes[0]);
ASSERT_EQ (nano::process_result::progress, node.process (*send1).code);
ASSERT_EQ (nano::process_result::fork, node.process_local (send2).code);
auto election (node.active.election (send1->qualified_root ()));
ASSERT_NE (election, nullptr);
{
nano::lock_guard<std::mutex> guard (node.active.mutex);
auto & blocks (election->blocks);
ASSERT_NE (blocks.end (), blocks.find (send1->hash ()));
ASSERT_NE (blocks.end (), blocks.find (send2->hash ()));
ASSERT_NE (election->status.winner, send1);
ASSERT_NE (election->status.winner, send2);
}
}

TEST (node, fork_keep)
{
nano::system system (2);
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ void nano::node::process_fork (nano::transaction const & transaction_a, std::sha
auto root (block_a->root ());
if (!store.block_exists (transaction_a, block_a->type (), block_a->hash ()) && store.root_exists (transaction_a, block_a->root ()))
{
active.publish (block_a);
std::shared_ptr<nano::block> ledger_block (ledger.forked_block (transaction_a, *block_a));
if (ledger_block && !block_confirmed_or_being_confirmed (transaction_a, ledger_block->hash ()))
{
Expand Down Expand Up @@ -577,6 +576,7 @@ void nano::node::process_fork (nano::transaction const & transaction_a, std::sha
election.first->transition_active ();
}
}
active.publish (block_a);
}
}

Expand Down