-
Notifications
You must be signed in to change notification settings - Fork 5
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
[1.0] Add test case to demonstrate the weak masking issue #622
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
669b2a5
Start implementing `weak_masking_issue` testcase.
greg7mdp f6cd0d8
Progress on `weak_masking_issue` testcase
greg7mdp e483160
Complete `weak_masking_issue` testcase.
greg7mdp 49c4100
Rename member variables.
greg7mdp e147d54
Fix some typos in comments.
greg7mdp a65d093
Add block comment
greg7mdp 20eae6d
Fix error in block diagram
greg7mdp ee51e5f
Address PR comments.
greg7mdp dbb250c
Merge branch 'release/1.0' of github.com:AntelopeIO/spring into gh_544
greg7mdp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ using namespace eosio::testing; | |
|
||
BOOST_AUTO_TEST_SUITE(savanna_misc_tests) | ||
|
||
// ------------------------------------------------------------------------------------ | ||
// Verify that we can restart a node from a snapshot without state or blocks (reversible | ||
// or not) | ||
// ------------------------------------------------------------------------------------ | ||
|
@@ -21,6 +22,7 @@ BOOST_FIXTURE_TEST_CASE(snapshot_startup_without_forkdb, savanna_cluster::cluste | |
|
||
} FC_LOG_AND_RETHROW() | ||
|
||
// ------------------------------------------------------------------------------------ | ||
// Verify that we cannot restart a node from a snapshot without state and blocks log, | ||
// but with a fork database | ||
// ------------------------------------------------------------------------------------ | ||
|
@@ -39,5 +41,112 @@ BOOST_FIXTURE_TEST_CASE(snapshot_startup_with_forkdb, savanna_cluster::cluster_t | |
} FC_LOG_AND_RETHROW() | ||
|
||
|
||
// ----------------------------------------------------------------------------------------------------- | ||
// Test case demonstrating the weak masking issue (see https://github.com/AntelopeIO/spring/issues/534) | ||
// Because the issue is fixed in spring https://github.com/AntelopeIO/spring/pull/537, test must pass | ||
// on all versions past that commit. | ||
// ----------------------------------------------------------------------------------------------------- | ||
/* | ||
S | ||
+------------------------------+ | ||
V | | ||
+-----+ S +-----+ S +-----+ no +-----+ W +-----+ S +-----+ | ||
A produces <----| b0 |<-----| b1 |<-----------| b3 |<-------+ b4 |<-----| b5 |<----| b6 |<------- | ||
+-----+ +-----+ +-----+ claim +-----+ +-----+ +-----+ | ||
^ | ||
| +-----+ | ||
D produces +--------------------| b2 | | ||
S +-----+ | ||
|
||
*/ | ||
BOOST_FIXTURE_TEST_CASE(weak_masking_issue, savanna_cluster::cluster_t) try { | ||
auto& A=_nodes[0]; auto& B=_nodes[1]; auto& C=_nodes[2]; auto& D=_nodes[3]; | ||
using vote_t = savanna_cluster::node_t::vote_t; | ||
//_debug_mode = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this commented out line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like having it here personally. |
||
|
||
auto b0 = A.produce_blocks(2); // receives strong votes from all finalizers | ||
print("b0", b0); | ||
|
||
// partition D out. D will be used to produce blocks on an alternative fork. | ||
// We will have 3 finalizers voting which is enough to reach QCs | ||
// ------------------------------------------------------------------------- | ||
const std::vector<size_t> partition {3}; | ||
set_partition(partition); | ||
|
||
auto b1 = A.produce_block(); // receives strong votes from 3 finalizers (D partitioned out) | ||
print("b1", b1); | ||
|
||
auto b2 = D.produce_block(_block_interval_us * 2); // produce a `later` block on D | ||
print("b2", b2); | ||
|
||
BOOST_REQUIRE_GT(b2->timestamp.slot, b1->timestamp.slot); | ||
|
||
const std::vector<size_t> tmp_partition {0}; // we temporarily separate A (before pushing b2) | ||
set_partitions({tmp_partition, partition}); // because we don't want A to see the block produced by D (b2) | ||
// otherwise it will switch forks and build its next block (b3) | ||
// on top of it | ||
|
||
push_block(1, b2); // push block to B and C, should receive weak votes | ||
BOOST_REQUIRE_EQUAL(B.last_vote, vote_t(b2, false)); | ||
BOOST_REQUIRE_EQUAL(C.last_vote, vote_t(b2, false)); | ||
BOOST_REQUIRE_EQUAL(A.last_vote, vote_t(b1, true));// A should not have seen b2, and therefore not voted on it | ||
|
||
BOOST_REQUIRE_EQUAL(qc_s(qc(b2)), qc_s(b0, true)); // b2 should include a strong qc on b0 | ||
|
||
|
||
set_partition(partition); // restore our original partition {A, B, C} and {D} | ||
|
||
signed_block_ptr b3; | ||
{ | ||
fc::scoped_set_value tmp(B.propagate_votes, false); // temporarily prevent B from broadcasting its votes) | ||
// so A won't receive them and form a QC on b3 | ||
|
||
b3 = A.produce_block(_block_interval_us * 2); // A will see its own strong vote on b3, and C's weak vote | ||
// (not a quorum) | ||
// because B doesn't propagate and D is partitioned away | ||
print("b3", b3); | ||
BOOST_REQUIRE_EQUAL(A.last_vote, vote_t(b3, true)); // A didn't vote on b2 so it can vote strong | ||
BOOST_REQUIRE_EQUAL(B.last_vote, vote_t(b3, false)); // but B and C have to vote weak. | ||
BOOST_REQUIRE_EQUAL(C.last_vote, vote_t(b3, false)); // C did vote, but we turned vote propagation off so | ||
// A will never see C's vote | ||
BOOST_REQUIRE_EQUAL(qc_s(qc(b3)), qc_s(b1, true)); // b3 should include a strong qc on b1 | ||
} | ||
|
||
BOOST_REQUIRE_EQUAL(A.lib_number, b0->block_num()); | ||
|
||
// Now B broadcasts its votes again, so | ||
auto b4 = A.produce_block(); // b4 should receive 3 weak votes from A, B and C | ||
// and should include a strong QC claim on b1 (repeated) | ||
// since we don't have enough votes to form a QC on b3 | ||
print("b4", b4); | ||
BOOST_REQUIRE_EQUAL(A.last_vote, vote_t(b4, true)); | ||
BOOST_REQUIRE_EQUAL(B.last_vote, vote_t(b4, false)); | ||
BOOST_REQUIRE_EQUAL(C.last_vote, vote_t(b4, false)); | ||
BOOST_REQUIRE_EQUAL(qc_claim(b3), qc_claim(b4)); // A didn't form a QC on b3, so b4 should repeat b3's claim | ||
BOOST_REQUIRE(!qc(b4)); // b4 should not have a QC extension (no new QC formed on b3) | ||
|
||
BOOST_REQUIRE_EQUAL(A.lib_number, b0->block_num()); | ||
|
||
auto b5 = A.produce_block(); // a weak QC was formed on b4 and is included in b5 | ||
// b5 should receive 3 strong votes (because it has a | ||
// weak QC on b4, which itself had a strong QC on b1. | ||
// Upon receiving a strong QC on b5, b4 will be final | ||
print("b5", b5); | ||
BOOST_REQUIRE_EQUAL(A.last_vote, vote_t(b5, true)); | ||
BOOST_REQUIRE_EQUAL(B.last_vote, vote_t(b5, true)); | ||
BOOST_REQUIRE_EQUAL(qc_s(qc(b5)), qc_s(b4, false)); // b5 should include a weak qc on b4 | ||
|
||
BOOST_REQUIRE_EQUAL(A.lib_number, b0->block_num()); | ||
|
||
auto b6 = A.produce_block(); // should include a strong QC on b5, b1 should be final | ||
print("b6", b6); | ||
BOOST_REQUIRE_EQUAL(qc_s(qc(b6)), qc_s(b5, true)); // b6 should include a strong qc on b5 | ||
|
||
BOOST_REQUIRE_EQUAL(A.last_vote, vote_t(b6, true)); | ||
BOOST_REQUIRE_EQUAL(B.last_vote, vote_t(b6, true)); | ||
|
||
BOOST_REQUIRE_EQUAL(A.lib_number, b4->block_num()); | ||
|
||
} FC_LOG_AND_RETHROW() | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is in debug mode, you can just print out the whole ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this
cout
, useilog
and then you can enable viaunittest -- --verbose
and you don't need the_debug_mode
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually like this better because I print only what is relevant for the test.