Skip to content

Commit

Permalink
GH-3 Fix tests now that duplicates are not signaled
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Apr 12, 2024
1 parent ae02196 commit a6e4de8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
17 changes: 10 additions & 7 deletions unittests/finality_test_cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ finality_test_cluster::finality_test_cluster() {
}
}

eosio::chain::vote_status finality_test_cluster::wait_on_vote(uint32_t connection_id) {
eosio::chain::vote_status finality_test_cluster::wait_on_vote(uint32_t connection_id, bool duplicate) {
// wait for this node's vote to be processed
// duplicates are not signaled
size_t retrys = 200;
while ( (last_connection_vote != connection_id) && --retrys) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
if (last_connection_vote != connection_id) {
if (!duplicate && last_connection_vote != connection_id) {
FC_ASSERT(false, "Never received vote");
} else if (duplicate && last_connection_vote == connection_id) {
FC_ASSERT(false, "Duplicate should not have been signaled");
}
return last_vote_status;
return duplicate ? eosio::chain::vote_status::duplicate : last_vote_status.load();
}

// node0 produces a block and pushes it to node1 and node2
Expand All @@ -68,8 +71,8 @@ void finality_test_cluster::produce_and_push_block() {
}

// send node1's vote identified by "vote_index" in the collected votes
eosio::chain::vote_status finality_test_cluster::process_node1_vote(uint32_t vote_index, vote_mode mode) {
return process_vote( node1, vote_index, mode );
eosio::chain::vote_status finality_test_cluster::process_node1_vote(uint32_t vote_index, vote_mode mode, bool duplicate) {
return process_vote( node1, vote_index, mode, duplicate );
}

// send node1's latest vote
Expand Down Expand Up @@ -203,7 +206,7 @@ void finality_test_cluster::setup_node(node_info& node, eosio::chain::account_na
}

// send a vote to node0
eosio::chain::vote_status finality_test_cluster::process_vote(node_info& node, size_t vote_index, vote_mode mode) {
eosio::chain::vote_status finality_test_cluster::process_vote(node_info& node, size_t vote_index, vote_mode mode, bool duplicate) {
std::unique_lock g(node.votes_mtx);
FC_ASSERT( vote_index < node.votes.size(), "out of bound index in process_vote" );
auto& vote = node.votes[vote_index];
Expand All @@ -222,7 +225,7 @@ eosio::chain::vote_status finality_test_cluster::process_vote(node_info& node, s
static uint32_t connection_id = 0;
node0.node.control->process_vote_message( ++connection_id, vote );
if (eosio::chain::block_header::num_from_id(vote->block_id) > node0.node.control->last_irreversible_block_num())
return wait_on_vote(connection_id);
return wait_on_vote(connection_id, duplicate);
return eosio::chain::vote_status::unknown_block;
}

Expand Down
6 changes: 3 additions & 3 deletions unittests/finality_test_cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class finality_test_cluster {
void produce_and_push_block();

// send node1's vote identified by "index" in the collected votes
eosio::chain::vote_status process_node1_vote(uint32_t vote_index, vote_mode mode = vote_mode::strong);
eosio::chain::vote_status process_node1_vote(uint32_t vote_index, vote_mode mode = vote_mode::strong, bool duplicate = false);

// send node1's latest vote
eosio::chain::vote_status process_node1_vote(vote_mode mode = vote_mode::strong);
Expand Down Expand Up @@ -100,10 +100,10 @@ class finality_test_cluster {
bool lib_advancing(node_info& node);

// send "vote_index" vote on node to node0
eosio::chain::vote_status process_vote(node_info& node, size_t vote_index, vote_mode mode);
eosio::chain::vote_status process_vote(node_info& node, size_t vote_index, vote_mode mode, bool duplicate = false);

// send the latest vote on "node_index" node to node0
eosio::chain::vote_status process_vote(node_info& node, vote_mode mode);

eosio::chain::vote_status wait_on_vote(uint32_t connection_id);
eosio::chain::vote_status wait_on_vote(uint32_t connection_id, bool duplicate);
};
8 changes: 4 additions & 4 deletions unittests/finality_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ BOOST_AUTO_TEST_CASE(delayed_strong_weak_lost_vote) { try {
BOOST_REQUIRE(!cluster.node1_lib_advancing());

// The delayed vote arrives
cluster.process_node1_vote(delayed_index);
cluster.process_node1_vote(delayed_index, finality_test_cluster::vote_mode::strong, true);
cluster.produce_and_push_block();
BOOST_REQUIRE(!cluster.node2_lib_advancing());
BOOST_REQUIRE(!cluster.node1_lib_advancing());
Expand All @@ -481,9 +481,9 @@ BOOST_AUTO_TEST_CASE(duplicate_votes) { try {

cluster.produce_and_push_block();
for (auto i = 0; i < 5; ++i) {
cluster.process_node1_vote(i);
cluster.process_node1_vote(i, finality_test_cluster::vote_mode::strong);
// vote again to make it duplicate
BOOST_REQUIRE(cluster.process_node1_vote(i) == eosio::chain::vote_status::duplicate);
BOOST_REQUIRE(cluster.process_node1_vote(i, finality_test_cluster::vote_mode::strong, true) == eosio::chain::vote_status::duplicate);
cluster.produce_and_push_block();

// verify duplicate votes do not affect LIB advancing
Expand Down Expand Up @@ -511,7 +511,7 @@ BOOST_AUTO_TEST_CASE(unknown_proposal_votes) { try {

// process the original vote. LIB should advance
cluster.produce_and_push_block();
cluster.process_node1_vote(0);
cluster.process_node1_vote(0, finality_test_cluster::vote_mode::strong, true);

BOOST_REQUIRE(cluster.produce_blocks_and_verify_lib_advancing());
} FC_LOG_AND_RETHROW() }
Expand Down

0 comments on commit a6e4de8

Please sign in to comment.