Return error code from nano::test::start_election (#4277)
This commit is contained in:
parent
b6d5d01256
commit
d29032a839
14 changed files with 45 additions and 39 deletions
|
@ -556,7 +556,7 @@ TEST (active_transactions, vote_replays)
|
|||
ASSERT_NE (nullptr, open1);
|
||||
node.process_active (send1);
|
||||
node.process_active (open1);
|
||||
nano::test::start_elections (system, node, { send1, open1 });
|
||||
ASSERT_TRUE (nano::test::start_elections (system, node, { send1, open1 }));
|
||||
ASSERT_EQ (2, node.active.size ());
|
||||
// First vote is not a replay and confirms the election, second vote should be a replay since the election has confirmed but not yet removed
|
||||
auto vote_send1 (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, std::vector<nano::block_hash>{ send1->hash () }));
|
||||
|
@ -585,7 +585,7 @@ TEST (active_transactions, vote_replays)
|
|||
.build_shared ();
|
||||
ASSERT_NE (nullptr, send2);
|
||||
node.process_active (send2);
|
||||
nano::test::start_elections (system, node, { send2 });
|
||||
ASSERT_TRUE (nano::test::start_elections (system, node, { send2 }));
|
||||
ASSERT_EQ (1, node.active.size ());
|
||||
auto vote1_send2 (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, std::vector<nano::block_hash>{ send2->hash () }));
|
||||
auto vote2_send2 (std::make_shared<nano::vote> (key.pub, key.prv, 0, 0, std::vector<nano::block_hash>{ send2->hash () }));
|
||||
|
@ -1280,7 +1280,7 @@ TEST (active_transactions, list_active)
|
|||
|
||||
ASSERT_EQ (nano::process_result::progress, node.process (*open).code);
|
||||
|
||||
nano::test::start_elections (system, node, { send, send2, open });
|
||||
ASSERT_TRUE (nano::test::start_elections (system, node, { send, send2, open }));
|
||||
ASSERT_EQ (3, node.active.size ());
|
||||
ASSERT_EQ (1, node.active.list_active (1).size ());
|
||||
ASSERT_EQ (2, node.active.list_active (2).size ());
|
||||
|
|
|
@ -939,7 +939,7 @@ TEST (bootstrap_processor, lazy_hash_pruning)
|
|||
node1->process_active (change2);
|
||||
ASSERT_TIMELY (5s, node1->block (change2->hash ()) != nullptr);
|
||||
// Confirm last block to prune previous
|
||||
nano::test::start_elections (system, *node1, { send1, receive1, change1, change2 }, true);
|
||||
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, receive1, change1, change2 }, true));
|
||||
ASSERT_TIMELY (5s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (receive1->hash ()) && node1->block_confirmed (change1->hash ()) && node1->block_confirmed (change2->hash ()) && node1->active.empty ());
|
||||
ASSERT_EQ (5, node1->ledger.cache.block_count);
|
||||
ASSERT_EQ (5, node1->ledger.cache.cemented_count);
|
||||
|
@ -1321,7 +1321,7 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
|
|||
node1->process_active (state_open);
|
||||
ASSERT_TIMELY (5s, node1->block (state_open->hash ()) != nullptr);
|
||||
// Confirm last block to prune previous
|
||||
nano::test::start_elections (system, *node1, { send1, send2, open, state_open }, true);
|
||||
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, send2, open, state_open }, true));
|
||||
ASSERT_TIMELY (5s, node1->block_confirmed (send2->hash ()) && node1->block_confirmed (open->hash ()) && node1->block_confirmed (state_open->hash ()));
|
||||
ASSERT_EQ (5, node1->ledger.cache.block_count);
|
||||
ASSERT_EQ (5, node1->ledger.cache.cemented_count);
|
||||
|
@ -1878,7 +1878,7 @@ TEST (frontier_req, confirmed_frontier)
|
|||
ASSERT_EQ (receive2->hash (), request5->frontier);
|
||||
|
||||
// Confirm account before genesis (confirmed only)
|
||||
nano::test::start_elections (system, *node1, { send1, receive1 }, true);
|
||||
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, receive1 }, true));
|
||||
ASSERT_TIMELY (5s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (receive1->hash ()));
|
||||
auto connection6 (std::make_shared<nano::transport::tcp_server> (std::make_shared<nano::transport::socket> (*node1, nano::transport::socket::endpoint_type_t::server), node1));
|
||||
auto req6 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
|
||||
|
@ -1893,7 +1893,7 @@ TEST (frontier_req, confirmed_frontier)
|
|||
ASSERT_EQ (receive1->hash (), request6->frontier);
|
||||
|
||||
// Confirm account after genesis (confirmed only)
|
||||
nano::test::start_elections (system, *node1, { send2, receive2 }, true);
|
||||
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send2, receive2 }, true));
|
||||
ASSERT_TIMELY (5s, node1->block_confirmed (send2->hash ()) && node1->block_confirmed (receive2->hash ()));
|
||||
auto connection7 (std::make_shared<nano::transport::tcp_server> (std::make_shared<nano::transport::socket> (*node1, nano::transport::socket::endpoint_type_t::server), node1));
|
||||
auto req7 = std::make_unique<nano::frontier_req> (nano::dev::network_params.network);
|
||||
|
|
|
@ -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);
|
||||
nano::test::start_elections (system, *node1, { fork1a }, true);
|
||||
ASSERT_TRUE (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
|
||||
|
|
|
@ -286,7 +286,7 @@ TEST (election, continuous_voting)
|
|||
.build_shared ();
|
||||
|
||||
ASSERT_TRUE (nano::test::process (node1, { send1 }));
|
||||
nano::test::start_elections (system, node1, { send1 }, true);
|
||||
ASSERT_TRUE (nano::test::start_elections (system, node1, { send1 }, true));
|
||||
ASSERT_TIMELY (5s, nano::test::confirmed (node1, { send1 }));
|
||||
|
||||
node1.stats.clear ();
|
||||
|
|
|
@ -1103,7 +1103,7 @@ TEST (votes, DISABLED_add_old_different_account)
|
|||
node1.work_generate_blocking (*send2);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.process (*send2).code);
|
||||
nano::test::start_elections (system, node1, { send1, send2 });
|
||||
ASSERT_TRUE (nano::test::start_elections (system, node1, { send1, send2 }));
|
||||
auto election1 = node1.active.election (send1->qualified_root ());
|
||||
ASSERT_NE (nullptr, election1);
|
||||
auto election2 = node1.active.election (send2->qualified_root ());
|
||||
|
@ -4092,7 +4092,7 @@ TEST (ledger, block_hash_account_conflict)
|
|||
ASSERT_EQ (nano::process_result::progress, node1.process (*receive1).code);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.process (*send2).code);
|
||||
ASSERT_EQ (nano::process_result::progress, node1.process (*open_epoch1).code);
|
||||
nano::test::start_elections (system, node1, { send1, receive1, send2, open_epoch1 });
|
||||
ASSERT_TRUE (nano::test::start_elections (system, node1, { send1, receive1, send2, open_epoch1 }));
|
||||
auto election1 = node1.active.election (send1->qualified_root ());
|
||||
ASSERT_NE (nullptr, election1);
|
||||
auto election2 = node1.active.election (receive1->qualified_root ());
|
||||
|
|
|
@ -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
|
||||
nano::test::start_elections (system, node, { blocks.back () }, true);
|
||||
ASSERT_TRUE (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
|
||||
nano::test::start_elections (system, node1, { open }, true);
|
||||
ASSERT_TRUE (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
|
||||
nano::test::start_elections (system, node1, { change, epoch_open, send2 }, true);
|
||||
ASSERT_TRUE (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)
|
||||
|
@ -3147,7 +3147,7 @@ TEST (node, confirm_back)
|
|||
node.process_active (open);
|
||||
node.process_active (send2);
|
||||
ASSERT_TIMELY (5s, node.block (send2->hash ()) != nullptr);
|
||||
nano::test::start_elections (system, node, { send1, open, send2 });
|
||||
ASSERT_TRUE (nano::test::start_elections (system, node, { send1, open, send2 }));
|
||||
ASSERT_EQ (3, node.active.size ());
|
||||
std::vector<nano::block_hash> vote_blocks;
|
||||
vote_blocks.push_back (send2->hash ());
|
||||
|
@ -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 }));
|
||||
nano::test::start_elections (system, node, { send1, open }, true);
|
||||
ASSERT_TRUE (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
|
||||
|
|
|
@ -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`
|
||||
nano::test::start_elections (system, node, { blocks.at (11) }, true);
|
||||
ASSERT_TRUE (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`
|
||||
nano::test::start_elections (system, node, { blocks.at (55) }, true);
|
||||
ASSERT_TRUE (nano::test::start_elections (system, node, { blocks.at (55) }, true));
|
||||
ASSERT_TIMELY (5s, nano::test::confirmed (node, { blocks.at (55) }));
|
||||
|
||||
// Manually trigger backlog scan
|
||||
|
|
|
@ -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::start_elections (system, *node, { block1->hash () }, true);
|
||||
ASSERT_TRUE (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::start_elections (system, *node, { block1->hash () }, true);
|
||||
ASSERT_TRUE (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));
|
||||
|
|
|
@ -1246,7 +1246,7 @@ TEST (rpc, history_pruning)
|
|||
ASSERT_TIMELY (5s, nano::test::exists (*node0, blocks));
|
||||
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
|
||||
|
||||
nano::test::start_elections (system, *node0, blocks, true);
|
||||
ASSERT_TRUE (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);
|
||||
|
@ -5877,7 +5877,7 @@ TEST (rpc, block_confirmed)
|
|||
.work (*system.work.generate (latest))
|
||||
.build_shared ();
|
||||
node->process_active (send);
|
||||
nano::test::start_elections (system, *node, { send }, true);
|
||||
ASSERT_TRUE (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 ()));
|
||||
|
@ -6879,7 +6879,7 @@ TEST (rpc, confirmation_active)
|
|||
.build_shared ();
|
||||
node1->process_active (send1);
|
||||
node1->process_active (send2);
|
||||
nano::test::start_elections (system, *node1, { send1, send2 });
|
||||
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, send2 }));
|
||||
ASSERT_EQ (2, node1->active.size ());
|
||||
auto election (node1->active.election (send1->qualified_root ()));
|
||||
ASSERT_NE (nullptr, election);
|
||||
|
|
|
@ -2110,9 +2110,9 @@ TEST (node, aggressive_flooding)
|
|||
ASSERT_EQ (node1.latest (nano::dev::genesis_key.pub), node_wallet.first->latest (nano::dev::genesis_key.pub));
|
||||
ASSERT_EQ (genesis_blocks.back ()->hash (), node_wallet.first->latest (nano::dev::genesis_key.pub));
|
||||
// Confirm blocks for rep crawler & receiving
|
||||
nano::test::start_elections (system, *node_wallet.first, { genesis_blocks.back () }, true);
|
||||
ASSERT_TRUE (nano::test::start_elections (system, *node_wallet.first, { genesis_blocks.back () }, true));
|
||||
}
|
||||
nano::test::start_elections (system, node1, { genesis_blocks.back () }, true);
|
||||
ASSERT_TRUE (nano::test::start_elections (system, node1, { genesis_blocks.back () }, true));
|
||||
|
||||
// Wait until all genesis blocks are received
|
||||
auto all_received = [&nodes_wallets] () {
|
||||
|
|
|
@ -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 }));
|
||||
nano::test::start_elections (system, node, { send, open }, true);
|
||||
EXPECT_TRUE (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<std::shared_ptr<nano::block>> setup_blocks (nano::test::system & sys
|
|||
EXPECT_TRUE (nano::test::process (node, receives));
|
||||
|
||||
// Confirm whole genesis chain at once
|
||||
nano::test::start_elections (system, node, { sends.back () }, true);
|
||||
EXPECT_TRUE (nano::test::start_elections (system, node, { sends.back () }, true));
|
||||
EXPECT_TIMELY (5s, nano::test::confirmed (node, { sends }));
|
||||
|
||||
std::cout << "setup_blocks done" << std::endl;
|
||||
|
|
|
@ -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
|
||||
nano::test::start_elections (system, node, { blocks.back () }, true);
|
||||
EXPECT_TRUE (nano::test::start_elections (system, node, { blocks.back () }, true));
|
||||
EXPECT_TIMELY (5s, nano::test::confirmed (node, blocks));
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ std::vector<std::pair<nano::account, nano::block_list_t>> nano::test::setup_chai
|
|||
if (confirm)
|
||||
{
|
||||
// Ensure blocks are in the ledger and confirmed
|
||||
nano::test::start_elections (system, node, { send, open }, true);
|
||||
EXPECT_TRUE (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
|
||||
nano::test::start_elections (system, node, { latest }, true);
|
||||
EXPECT_TRUE (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 }));
|
||||
nano::test::start_elections (system, node, { send, open }, true);
|
||||
EXPECT_TRUE (nano::test::start_elections (system, node, { send, open }, true));
|
||||
EXPECT_TIMELY (5s, nano::test::confirmed (node, { send, open }));
|
||||
|
||||
return key;
|
||||
|
|
|
@ -222,20 +222,24 @@ std::shared_ptr<nano::election> nano::test::start_election (nano::test::system &
|
|||
return election;
|
||||
}
|
||||
|
||||
void nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector<nano::block_hash> const & hashes_a, bool const forced_a)
|
||||
bool nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector<nano::block_hash> const & hashes_a, bool const forced_a)
|
||||
{
|
||||
for (auto const & hash_l : hashes_a)
|
||||
{
|
||||
auto election = nano::test::start_election (system_a, node_a, hash_l);
|
||||
release_assert (election);
|
||||
if (!election)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (forced_a)
|
||||
{
|
||||
election->force_confirm ();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector<std::shared_ptr<nano::block>> const & blocks_a, bool const forced_a)
|
||||
bool nano::test::start_elections (nano::test::system & system_a, nano::node & node_a, std::vector<std::shared_ptr<nano::block>> const & blocks_a, bool const forced_a)
|
||||
{
|
||||
nano::test::start_elections (system_a, node_a, blocks_to_hashes (blocks_a), forced_a);
|
||||
return nano::test::start_elections (system_a, node_a, blocks_to_hashes (blocks_a), forced_a);
|
||||
}
|
||||
|
|
|
@ -407,14 +407,16 @@ namespace test
|
|||
/*
|
||||
* Call start_election for every block identified in the hash vector.
|
||||
* Optionally, force confirm the election if forced_a is set.
|
||||
* NOTE: Each election is given 5 seconds to complete, if it does not complete in 5 seconds, it will assert.
|
||||
* @return true if all elections were successfully started
|
||||
* NOTE: Each election is given 5 seconds to complete, if it does not complete in 5 seconds, it will return an error
|
||||
*/
|
||||
void start_elections (nano::test::system &, nano::node &, std::vector<nano::block_hash> const &, bool const forced_a = false);
|
||||
[[nodiscard]] bool start_elections (nano::test::system &, nano::node &, std::vector<nano::block_hash> const &, bool const forced_a = false);
|
||||
/*
|
||||
* Call start_election for every block in the vector.
|
||||
* Optionally, force confirm the election if forced_a is set.
|
||||
* NOTE: Each election is given 5 seconds to complete, if it does not complete in 5 seconds, it will assert.
|
||||
* @return true if all elections were successfully started
|
||||
* NOTE: Each election is given 5 seconds to complete, if it does not complete in 5 seconds, it will return an error.
|
||||
*/
|
||||
void start_elections (nano::test::system &, nano::node &, std::vector<std::shared_ptr<nano::block>> const &, bool const forced_a = false);
|
||||
[[nodiscard]] bool start_elections (nano::test::system &, nano::node &, std::vector<std::shared_ptr<nano::block>> const &, bool const forced_a = false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue