diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index 24db988b..3ed11574 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -1118,7 +1118,7 @@ TEST (confirmation_height, conflict_rollback_cemented) .work (*system.work.generate (genesis_hash)) .build_shared (); ASSERT_EQ (nano::process_result::progress, node1->process (*fork1a).code); - ASSERT_TRUE (nano::test::confirm (*node1, { fork1a })); + nano::test::start_elections (system, *node1, { fork1a }, true); ASSERT_TIMELY (5s, nano::test::confirmed (*node1, { fork1a })); // create the other side of the fork on node2 diff --git a/nano/core_test/election.cpp b/nano/core_test/election.cpp index db862688..689bb21d 100644 --- a/nano/core_test/election.cpp +++ b/nano/core_test/election.cpp @@ -288,7 +288,7 @@ TEST (election, continuous_voting) .build_shared (); ASSERT_TRUE (nano::test::process (node1, { send1 })); - ASSERT_TIMELY (5s, nano::test::confirm (node1, { send1 })); + nano::test::start_elections (system, node1, { send1 }, true); ASSERT_TIMELY (5s, nano::test::confirmed (node1, { send1 })); node1.stats.clear (); diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 20f5ae31..e5a1abfc 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -2573,7 +2573,7 @@ TEST (node, vote_by_hash_bundle) } // Confirming last block will confirm whole chain and allow us to generate votes for those blocks later - ASSERT_TIMELY (5s, nano::test::confirm (node, { blocks.back () })); + nano::test::start_elections (system, node, { blocks.back () }, true); ASSERT_TIMELY (5s, nano::test::confirmed (node, { blocks.back () })); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -2752,7 +2752,7 @@ TEST (node, epoch_conflict_confirm) ASSERT_TRUE (nano::test::process (node1, { send, send2, open })); // Confirm open block in node1 to allow generating votes - ASSERT_TIMELY (5s, nano::test::confirm (node1, { open })); + nano::test::start_elections (system, node1, { open }, true); ASSERT_TIMELY (5s, nano::test::confirmed (node1, { open })); // Process initial blocks on node0 @@ -2766,7 +2766,7 @@ TEST (node, epoch_conflict_confirm) ASSERT_TIMELY (5s, nano::test::exists (node1, { change, epoch_open })); // Confirm initial blocks in node1 to allow generating votes later - ASSERT_TIMELY (5s, nano::test::confirm (node1, { change, epoch_open, send2 })); + nano::test::start_elections (system, node1, { change, epoch_open, send2 }, true); ASSERT_TIMELY (5s, nano::test::confirmed (node1, { change, epoch_open, send2 })); // Start elections for node0 for conflicting change and epoch_open blocks (those two blocks have the same root) @@ -3481,7 +3481,7 @@ TEST (node, rollback_vote_self) // Process and mark the first 2 blocks as confirmed to allow voting ASSERT_TRUE (nano::test::process (node, { send1, open })); - ASSERT_TIMELY (5s, nano::test::confirm (node, { send1, open })); + nano::test::start_elections (system, node, { send1, open }, true); ASSERT_TIMELY (5s, node.ledger.cache.cemented_count == 3); // wait until the rep weights have caught up with the weight transfer diff --git a/nano/core_test/optimistic_scheduler.cpp b/nano/core_test/optimistic_scheduler.cpp index 3236b90d..13bbac8b 100644 --- a/nano/core_test/optimistic_scheduler.cpp +++ b/nano/core_test/optimistic_scheduler.cpp @@ -24,7 +24,7 @@ TEST (optimistic_scheduler, activate_one) auto & [account, blocks] = chains.front (); // Confirm block towards at the beginning the chain, so gap between confirmation and account frontier is larger than `gap_threshold` - ASSERT_TRUE (nano::test::confirm (node, { blocks.at (11) })); + nano::test::start_elections (system, node, { blocks.at (11) }, true); ASSERT_TIMELY (5s, nano::test::confirmed (node, { blocks.at (11) })); // Ensure unconfirmed account head block gets activated @@ -93,7 +93,7 @@ TEST (optimistic_scheduler, under_gap_threshold) auto & [account, blocks] = chains.front (); // Confirm block towards the end of the chain, so gap between confirmation and account frontier is less than `gap_threshold` - ASSERT_TRUE (nano::test::confirm (node, { blocks.at (55) })); + nano::test::start_elections (system, node, { blocks.at (55) }, true); ASSERT_TIMELY (5s, nano::test::confirmed (node, { blocks.at (55) })); // Manually trigger backlog scan diff --git a/nano/rpc_test/receivable.cpp b/nano/rpc_test/receivable.cpp index 44da7493..5bbe4bab 100644 --- a/nano/rpc_test/receivable.cpp +++ b/nano/rpc_test/receivable.cpp @@ -144,7 +144,7 @@ TEST (rpc, receivable_unconfirmed) ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 0)); request.put ("include_only_confirmed", "false"); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1)); - nano::test::confirm (*node, { block1->hash () }); + nano::test::start_elections (system, *node, { block1->hash () }, true); ASSERT_TIMELY (5s, !node->active.active (*block1)); request.put ("include_only_confirmed", "true"); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1)); @@ -548,7 +548,7 @@ TEST (rpc, accounts_receivable_confirmed) ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 0)); request.put ("include_only_confirmed", "false"); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1)); - nano::test::confirm (*node, { block1->hash () }); + nano::test::start_elections (system, *node, { block1->hash () }, true); ASSERT_TIMELY (5s, !node->active.active (*block1)); request.put ("include_only_confirmed", "true"); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1)); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index e60bb70d..bcbb9710 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -1246,10 +1246,7 @@ TEST (rpc, history_pruning) ASSERT_TIMELY (5s, nano::test::exists (*node0, blocks)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); - // WORKAROUND: this is called repeatedly inside an assert timely because nano::test::confirm() - // uses block_processor.flush internally which can fail to flush - ASSERT_TIMELY (5s, nano::test::confirm (*node0, blocks)); - + nano::test::start_elections (system, *node0, blocks, true); ASSERT_TIMELY (5s, node0->block_confirmed (uchange->hash ())); nano::confirmation_height_info confirmation_height_info; node0->store.confirmation_height.get (node0->store.tx_begin_read (), nano::dev::genesis_key.pub, confirmation_height_info); @@ -5880,7 +5877,7 @@ TEST (rpc, block_confirmed) .work (*system.work.generate (latest)) .build_shared (); node->process_active (send); - ASSERT_TIMELY (5s, nano::test::confirm (*node, { send })); + nano::test::start_elections (system, *node, { send }, true); // Wait until the confirmation height has been set ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), send->hash ()) && !node->confirmation_height_processor.is_processing_block (send->hash ())); diff --git a/nano/slow_test/vote_cache.cpp b/nano/slow_test/vote_cache.cpp index e2044295..934c226b 100644 --- a/nano/slow_test/vote_cache.cpp +++ b/nano/slow_test/vote_cache.cpp @@ -38,7 +38,7 @@ nano::keypair setup_rep (nano::test::system & system, nano::node & node, nano::u .build_shared (); EXPECT_TRUE (nano::test::process (node, { send, open })); - EXPECT_TIMELY (5s, nano::test::confirm (node, { send, open })); + nano::test::start_elections (system, node, { send, open }, true); EXPECT_TIMELY (5s, nano::test::confirmed (node, { send, open })); return key; @@ -104,7 +104,7 @@ std::vector> setup_blocks (nano::test::system & sys EXPECT_TRUE (nano::test::process (node, receives)); // Confirm whole genesis chain at once - EXPECT_TIMELY (5s, nano::test::confirm (node, { sends.back () })); + nano::test::start_elections (system, node, { sends.back () }, true); EXPECT_TIMELY (5s, nano::test::confirmed (node, { sends })); std::cout << "setup_blocks done" << std::endl; diff --git a/nano/test_common/chains.cpp b/nano/test_common/chains.cpp index 0335fc1a..8e1a7215 100644 --- a/nano/test_common/chains.cpp +++ b/nano/test_common/chains.cpp @@ -35,7 +35,7 @@ nano::block_list_t nano::test::setup_chain (nano::test::system & system, nano::n if (confirm) { // Confirm whole chain at once - EXPECT_TIMELY (5s, nano::test::confirm (node, { blocks.back () })); + nano::test::start_elections (system, node, { blocks.back () }, true); EXPECT_TIMELY (5s, nano::test::confirmed (node, blocks)); } @@ -83,7 +83,7 @@ std::vector> nano::test::setup_chai if (confirm) { // Ensure blocks are in the ledger and confirmed - EXPECT_TIMELY (5s, nano::test::confirm (node, { send, open })); + nano::test::start_elections (system, node, { send, open }, true); EXPECT_TIMELY (5s, nano::test::confirmed (node, { send, open })); } @@ -142,7 +142,7 @@ nano::block_list_t nano::test::setup_independent_blocks (nano::test::system & sy } // Confirm whole genesis chain at once - EXPECT_TIMELY (5s, nano::test::confirm (node, { latest })); + nano::test::start_elections (system, node, { latest }, true); EXPECT_TIMELY (5s, nano::test::confirmed (node, { latest })); return blocks; @@ -179,7 +179,7 @@ nano::keypair nano::test::setup_rep (nano::test::system & system, nano::node & n .build_shared (); EXPECT_TRUE (nano::test::process (node, { send, open })); - EXPECT_TIMELY (5s, nano::test::confirm (node, { send, open })); + nano::test::start_elections (system, node, { send, open }, true); EXPECT_TIMELY (5s, nano::test::confirmed (node, { send, open })); return key; diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 0232f616..1f8aa1fd 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -80,38 +80,6 @@ bool nano::test::process_live (nano::node & node, std::vector hashes) -{ - // Finish processing all blocks - FIXME: block processor flush is broken and should be removed - node.block_processor.flush (); - for (auto & hash : hashes) - { - if (node.block_confirmed (hash)) - { - continue; - } - - auto disk_block = node.block (hash); - // A sideband is required to start an election - release_assert (disk_block != nullptr); - release_assert (disk_block->has_sideband ()); - // This only starts election - auto election = node.block_confirm (disk_block); - if (election == nullptr) - { - return false; - } - // Here we actually confirm the block - election->force_confirm (); - } - return true; -} - -bool nano::test::confirm (nano::node & node, std::vector> blocks) -{ - return confirm (node, blocks_to_hashes (blocks)); -} - bool nano::test::confirmed (nano::node & node, std::vector hashes) { for (auto & hash : hashes) diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 82ff0fdc..5e3793a5 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -332,18 +332,6 @@ namespace test * @return true if all blocks were successfully processed */ bool process_live (nano::node & node, std::vector> blocks); - /* - * Convenience function to confirm a list of blocks - * The actual confirmation will happen asynchronously, check for that with `nano::test::confirmed (..)` function - * @return true if successfully scheduled blocks to be confirmed - */ - bool confirm (nano::node & node, std::vector> blocks); - /* - * Convenience function to confirm a list of hashes - * The actual confirmation will happen asynchronously, check for that with `nano::test::confirmed (..)` function - * @return true if successfully scheduled blocks to be confirmed - */ - bool confirm (nano::node & node, std::vector hashes); /* * Convenience function to check whether a list of blocks is confirmed. * @return true if all blocks are confirmed, false otherwise