Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use make_final_vote function #4407

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ TEST (active_transactions, inactive_votes_cache)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (latest))
.build_shared ();
auto vote (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> (1, send->hash ())));
auto vote = nano::test::make_final_vote (nano::dev::genesis_key, { send });
node.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 1);
node.process_active (send);
Expand Down Expand Up @@ -314,7 +314,7 @@ TEST (active_transactions, inactive_votes_cache_fork)
.work (*system.work.generate (latest))
.build_shared ();

auto const vote = 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> (1, send1->hash ()));
auto const vote = nano::test::make_final_vote (nano::dev::genesis_key, { send1 });
node.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 1);

Expand Down Expand Up @@ -580,15 +580,15 @@ TEST (active_transactions, vote_replays)
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 () }));
auto vote_send1 = nano::test::make_final_vote (nano::dev::genesis_key, { send1 });
ASSERT_EQ (nano::vote_code::vote, node.active.vote (vote_send1));
ASSERT_EQ (2, node.active.size ());
ASSERT_EQ (nano::vote_code::replay, node.active.vote (vote_send1));
// Wait until the election is removed, at which point the vote is still a replay since it's been recently confirmed
ASSERT_TIMELY_EQ (3s, node.active.size (), 1);
ASSERT_EQ (nano::vote_code::replay, node.active.vote (vote_send1));
// Open new account
auto vote_open1 (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>{ open1->hash () }));
auto vote_open1 = nano::test::make_final_vote (nano::dev::genesis_key, { open1 });
ASSERT_EQ (nano::vote_code::vote, node.active.vote (vote_open1));
ASSERT_EQ (nano::vote_code::replay, node.active.vote (vote_open1));
ASSERT_TIMELY (3s, node.active.empty ());
Expand All @@ -608,7 +608,7 @@ TEST (active_transactions, vote_replays)
node.process_active (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 vote1_send2 = nano::test::make_final_vote (nano::dev::genesis_key, { send2 });
auto vote2_send2 (std::make_shared<nano::vote> (key.pub, key.prv, 0, 0, std::vector<nano::block_hash>{ send2->hash () }));
ASSERT_EQ (nano::vote_code::vote, node.active.vote (vote2_send2));
ASSERT_EQ (1, node.active.size ());
Expand Down Expand Up @@ -750,7 +750,7 @@ TEST (active_transactions, republish_winner)
node1.block_processor.flush ();
auto election = node1.active.election (fork->qualified_root ());
ASSERT_NE (nullptr, election);
auto vote = 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>{ fork->hash () });
auto vote = nano::test::make_final_vote (nano::dev::genesis_key, { fork });
node1.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node1, node1));
node1.vote_processor.flush ();
node1.block_processor.flush ();
Expand Down Expand Up @@ -882,7 +882,7 @@ TEST (active_transactions, fork_replacement_tally)
.build_shared ();
node1.process_active (open);
// Confirmation
auto vote (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>{ send->hash (), open->hash () }));
RickiNano marked this conversation as resolved.
Show resolved Hide resolved
auto vote = nano::test::make_final_vote (nano::dev::genesis_key, { send, open });
node1.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node1, node1));
}
ASSERT_TIMELY_EQ (5s, node1.ledger.cache.cemented_count, 1 + 2 * reps_count);
Expand Down Expand Up @@ -1082,7 +1082,7 @@ TEST (active_transactions, conflicting_block_vote_existing_election)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build_shared ();
auto vote_fork (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>{ fork->hash () }));
auto vote_fork = nano::test::make_final_vote (nano::dev::genesis_key, { fork });

ASSERT_EQ (nano::process_result::progress, node.process_local (send).value ().code);
ASSERT_TIMELY_EQ (5s, 1, node.active.size ());
Expand Down
6 changes: 3 additions & 3 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,7 @@ TEST (node, vote_republish)
ASSERT_FALSE (node1.block (send2->hash ()));

// the vote causes the election to reach quorum and for the vote (and block?) to be published from node1 to node2
auto vote (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 vote = nano::test::make_final_vote (nano::dev::genesis_key, { send2 });
node1.vote_processor.vote (vote, std::make_shared<nano::transport::fake::channel> (node1));

// FIXME: there is a race condition here, if the vote arrives before the block then the vote is wasted and the test fails
Expand Down Expand Up @@ -2637,7 +2637,7 @@ TEST (node, vote_by_hash_republish)
// construct a vote for send2 in order to overturn send1
std::vector<nano::block_hash> vote_blocks;
vote_blocks.push_back (send2->hash ());
auto vote = std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, vote_blocks);
auto vote = nano::test::make_final_vote (nano::dev::genesis_key, { vote_blocks });
node1.vote_processor.vote (vote, std::make_shared<nano::transport::fake::channel> (node1));

// send2 should win on both nodes
Expand Down Expand Up @@ -3150,7 +3150,7 @@ TEST (node, confirm_back)
ASSERT_EQ (3, node.active.size ());
std::vector<nano::block_hash> vote_blocks;
vote_blocks.push_back (send2->hash ());
auto vote (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, vote_blocks));
auto vote = nano::test::make_final_vote (nano::dev::genesis_key, { vote_blocks });
node.vote_processor.vote_blocking (vote, std::make_shared<nano::transport::fake::channel> (node));
ASSERT_TIMELY (10s, node.active.empty ());
}
Expand Down
Loading