Skip to content

Commit

Permalink
Fix active_transactions.confirm_frontier (#4386)
Browse files Browse the repository at this point in the history
The main problem was that the bootstrap processes could sync the block
before the test tried to insert it and it woudl fail because the block
was already there. The main problem I fixed was to disable the bootstrap
processes. I also improved it overall and made it more readable.
  • Loading branch information
dsiganos authored Jan 25, 2024
1 parent 6f996b2 commit 4fbae94
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,43 @@ namespace nano
TEST (active_transactions, confirm_frontier)
{
nano::test::system system;
nano::node_flags node_flags;
node_flags.disable_request_loop = true;
// Voting node
auto & node1 = *system.add_node (node_flags);
nano::node_flags node_flags2;

// send 100 raw from genesis to a random account
nano::state_block_builder builder;
auto send = builder
.account (nano::dev::genesis_key.pub)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - 100)
.link (nano::public_key ())
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build_shared ();

{
// Voting node
nano::node_flags node_flags;
node_flags.disable_request_loop = true;
node_flags.disable_ongoing_bootstrap = true;
node_flags.disable_ascending_bootstrap = true;
auto & node1 = *system.add_node (node_flags);
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);

// we cannot use the same block instance on 2 different nodes, so make a copy
auto send_copy = builder.make_block ().from (*send).build_shared ();
ASSERT_TRUE (nano::test::process (node1, { send_copy }));
ASSERT_TRUE (nano::test::start_elections (system, node1, { send_copy }));
ASSERT_TIMELY (5s, nano::test::confirmed (node1, { send_copy }));
}

// The rep crawler would otherwise request confirmations in order to find representatives
nano::node_flags node_flags2;
node_flags2.disable_ongoing_bootstrap = true;
node_flags2.disable_ascending_bootstrap = true;
node_flags2.disable_rep_crawler = true;
// start node2 later so that we do not get the gossip traffic
auto & node2 = *system.add_node (node_flags2);

// Add key to node1
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
// Add representative to disabled rep crawler
auto peers (node2.network.random_set (1));
ASSERT_FALSE (peers.empty ());
Expand All @@ -123,25 +149,13 @@ TEST (active_transactions, confirm_frontier)
node2.rep_crawler.probable_reps.emplace (nano::dev::genesis_key.pub, *peers.begin ());
}

nano::state_block_builder builder;
auto send = builder
.account (nano::dev::genesis_key.pub)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - 100)
.link (nano::public_key ())
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build_shared ();
auto send_copy = builder.make_block ().from (*send).build_shared ();
ASSERT_EQ (nano::process_result::progress, node1.process (*send).code);
node1.confirmation_height_processor.add (send);
ASSERT_TIMELY (5s, node1.ledger.block_confirmed (node1.store.tx_begin_read (), send->hash ()));
ASSERT_EQ (nano::process_result::progress, node2.process (*send_copy).code);
ASSERT_EQ (nano::process_result::progress, node2.process (*send).code);
ASSERT_TIMELY (5s, !node2.active.empty ());

// Save election to check request count afterwards
auto election2 = node2.active.election (send->qualified_root ());
ASSERT_NE (nullptr, election2);
std::shared_ptr<nano::election> election2;
ASSERT_TIMELY (5s, election2 = node2.active.election (send->qualified_root ()));
ASSERT_TIMELY (5s, nano::test::confirmed (node2, { send }));
ASSERT_TIMELY_EQ (5s, node2.ledger.cache.cemented_count, 2);
ASSERT_TIMELY (5s, node2.active.empty ());
ASSERT_GT (election2->confirmation_request_count, 0u);
Expand Down

0 comments on commit 4fbae94

Please sign in to comment.