Consistently add conflicting block to election (#2652)
* Add conflicting block after creating the election * Add a test ensuring correct behavior
This commit is contained in:
parent
142996cdbe
commit
b276aff086
2 changed files with 25 additions and 1 deletions
|
|
@ -1256,6 +1256,30 @@ TEST (node, fork_publish)
|
||||||
ASSERT_TRUE (node0.expired ());
|
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)
|
TEST (node, fork_keep)
|
||||||
{
|
{
|
||||||
nano::system system (2);
|
nano::system system (2);
|
||||||
|
|
|
||||||
|
|
@ -532,7 +532,6 @@ void nano::node::process_fork (nano::transaction const & transaction_a, std::sha
|
||||||
auto root (block_a->root ());
|
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 ()))
|
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));
|
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 ()))
|
if (ledger_block && !block_confirmed_or_being_confirmed (transaction_a, ledger_block->hash ()))
|
||||||
{
|
{
|
||||||
|
|
@ -562,6 +561,7 @@ void nano::node::process_fork (nano::transaction const & transaction_a, std::sha
|
||||||
election.election->transition_active ();
|
election.election->transition_active ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
active.publish (block_a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue