Skip to content

Commit

Permalink
active_transactions.prioritize_chains timing fix (#2004)
Browse files Browse the repository at this point in the history
* Fix logic in prioritize_chains test
fix should_flush for tests

* Update active_transactions.cpp
  • Loading branch information
Russel Waters authored May 21, 2019
1 parent 317fce2 commit e89e960
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,26 @@ TEST (active_transactions, prioritize_chains)
auto & node1 = *system.add_node (node_config);
auto & wallet (*system.wallet (0));
nano::genesis genesis;
nano::keypair key1, key2;
nano::keypair key1, key2, key3;

auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - 10 * nano::xrb_ratio, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, system.work.generate (genesis.hash ())));
auto open1 (std::make_shared<nano::state_block> (key1.pub, 0, key1.pub, 10 * nano::xrb_ratio, send1->hash (), key1.prv, key1.pub, system.work.generate (key1.pub)));
auto send2 (std::make_shared<nano::state_block> (key1.pub, open1->hash (), key1.pub, nano::xrb_ratio * 9, key2.pub, key1.prv, key1.pub, system.work.generate (open1->hash ())));
auto send3 (std::make_shared<nano::state_block> (key1.pub, send2->hash (), key1.pub, nano::xrb_ratio * 8, key2.pub, key1.prv, key1.pub, system.work.generate (send2->hash ())));
auto send4 (std::make_shared<nano::state_block> (key1.pub, send3->hash (), key1.pub, nano::xrb_ratio * 7, key2.pub, key1.prv, key1.pub, system.work.generate (send3->hash ())));
auto send5 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, send1->hash (), nano::test_genesis_key.pub, nano::genesis_amount - 20 * nano::xrb_ratio, key2.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, system.work.generate (send1->hash ())));
auto send6 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, send5->hash (), nano::test_genesis_key.pub, nano::genesis_amount - 30 * nano::xrb_ratio, key3.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, system.work.generate (send5->hash ())));
auto open2 (std::make_shared<nano::state_block> (key2.pub, 0, key2.pub, 10 * nano::xrb_ratio, send5->hash (), key2.prv, key2.pub, system.work.generate (key2.pub, nano::difficulty::from_multiplier (50., node1.network_params.network.publish_threshold))));
uint64_t difficulty (0);
nano::work_validate (*open2, &difficulty);
uint64_t difficulty1 (0);
nano::work_validate (*open2, &difficulty1);
uint64_t difficulty2 (0);
nano::work_validate (*send6, &difficulty2);

node1.process_active (send1);
node1.process_active (open1);
node1.process_active (send5);
system.deadline_set (10s);
while (node1.active.size () != 2)
while (node1.active.size () != 3)
{
ASSERT_NO_ERROR (system.poll ());
}
Expand All @@ -242,19 +246,19 @@ TEST (active_transactions, prioritize_chains)
auto election (it->election);
election->confirm_once ();
it++;
;
}
}

node1.process_active (send2);
node1.process_active (send3);
node1.process_active (send4);
node1.process_active (send5);
node1.process_active (send6);

while (node1.active.size () != 4)
{
ASSERT_NO_ERROR (system.poll ());
}

bool done (false);
//wait for all to be long_unconfirmed
while (!done)
Expand All @@ -265,12 +269,14 @@ TEST (active_transactions, prioritize_chains)
}
ASSERT_NO_ERROR (system.poll ());
}
std::this_thread::sleep_for (1s);
node1.process_active (open2);
while (node1.active.size () != 4)
{
ASSERT_NO_ERROR (system.poll ());
}
//wait for all to be long_unconfirmed
done = false;
while (!done)
{
{
Expand All @@ -279,13 +285,18 @@ TEST (active_transactions, prioritize_chains)
}
ASSERT_NO_ERROR (system.poll ());
}
size_t seen (0);
{
auto it (node1.active.roots.get<1> ().begin ());
while (!node1.active.roots.empty () && it != node1.active.roots.get<1> ().end ())
{
ASSERT_NE (difficulty, it->difficulty);
if (it->difficulty == (difficulty1 || difficulty2))
{
seen++;
}
it++;
}
}
ASSERT_LT (seen, 2);
ASSERT_EQ (node1.active.size (), 4);
}
2 changes: 1 addition & 1 deletion nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ bool nano::active_transactions::should_flush ()
{
minimum_size = rate * 512;
}
if (roots.size () > minimum_size)
if (roots.size () >= minimum_size)
{
if (rate <= 10)
{
Expand Down

0 comments on commit e89e960

Please sign in to comment.