From 87f2358b3b475e5ef4c6ef6a9a5a2805c8bd013a Mon Sep 17 00:00:00 2001 From: iceseer Date: Fri, 26 Feb 2021 11:31:34 +0300 Subject: [PATCH 1/4] fixup! Signed-off-by: iceseer --- irohad/consensus/yac/impl/yac.cpp | 18 ++++++++++++++++-- irohad/consensus/yac/yac.hpp | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/irohad/consensus/yac/impl/yac.cpp b/irohad/consensus/yac/impl/yac.cpp index c568b58e924..975114614a0 100644 --- a/irohad/consensus/yac/impl/yac.cpp +++ b/irohad/consensus/yac/impl/yac.cpp @@ -183,7 +183,8 @@ namespace iroha { // ------|Private interface|------ - void Yac::votingStep(VoteMessage vote) { + void Yac::votingStep(VoteMessage vote, uint32_t attempt) { + log_->info("votingStep got vote: {}, attempt {}", vote, attempt); std::unique_lock lock(mutex_); auto committed = vote_storage_.isCommitted(vote.hash.vote_round); @@ -191,6 +192,17 @@ namespace iroha { return; } + /** + * 3 attempts to build and commit block before we think that round is + * freezed + */ + if (attempt == 3) { + vote.hash.vote_hashes.proposal_hash.clear(); + vote.hash.vote_hashes.block_hash.clear(); + vote.hash.block_signature.reset(); + vote = crypto_->getVote(vote.hash); + } + auto &cluster_order = getCurrentOrder(); const auto ¤t_leader = cluster_order.currentLeader(); @@ -200,7 +212,9 @@ namespace iroha { propagateStateDirectly(current_leader, {vote}); cluster_order.switchToNext(); lock.unlock(); - timer_->invokeAfterDelay([this, vote] { this->votingStep(vote); }); + + timer_->invokeAfterDelay( + [this, vote, attempt] { this->votingStep(vote, attempt + 1); }); } void Yac::closeRound() { diff --git a/irohad/consensus/yac/yac.hpp b/irohad/consensus/yac/yac.hpp index 795cc7f71f0..47d9a0c8197 100644 --- a/irohad/consensus/yac/yac.hpp +++ b/irohad/consensus/yac/yac.hpp @@ -77,7 +77,7 @@ namespace iroha { * Voting step is strategy of propagating vote * until commit/reject message received */ - void votingStep(VoteMessage vote); + void votingStep(VoteMessage vote, uint32_t attempt = 0); /** * Erase temporary data of current round From f0bda162cac34f64740a1ca7b787a6d9d1434428 Mon Sep 17 00:00:00 2001 From: iceseer Date: Mon, 1 Mar 2021 10:40:32 +0300 Subject: [PATCH 2/4] fixup! Signed-off-by: iceseer --- irohad/consensus/yac/impl/yac.cpp | 8 +++++++- irohad/consensus/yac/storage/yac_vote_storage.hpp | 10 +++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/irohad/consensus/yac/impl/yac.cpp b/irohad/consensus/yac/impl/yac.cpp index 975114614a0..6f411a0f26b 100644 --- a/irohad/consensus/yac/impl/yac.cpp +++ b/irohad/consensus/yac/impl/yac.cpp @@ -192,11 +192,17 @@ namespace iroha { return; } + enum { kRotatePeriod = 3 }; + + if (0 != attempt && 0 == (attempt % kRotatePeriod)) { + vote_storage_.remove(vote.hash.vote_round); + } + /** * 3 attempts to build and commit block before we think that round is * freezed */ - if (attempt == 3) { + if (attempt == kRotatePeriod) { vote.hash.vote_hashes.proposal_hash.clear(); vote.hash.vote_hashes.block_hash.clear(); vote.hash.block_signature.reset(); diff --git a/irohad/consensus/yac/storage/yac_vote_storage.hpp b/irohad/consensus/yac/storage/yac_vote_storage.hpp index fbaee797db9..fc1567aadd4 100644 --- a/irohad/consensus/yac/storage/yac_vote_storage.hpp +++ b/irohad/consensus/yac/storage/yac_vote_storage.hpp @@ -84,11 +84,6 @@ namespace iroha { findProposalStorage(const VoteMessage &msg, PeersNumberType peers_in_round); - /** - * Remove proposal storage by round - */ - void remove(const Round &round); - public: // --------| public api |-------- @@ -119,6 +114,11 @@ namespace iroha { */ bool isCommitted(const Round &round); + /** + * Remove proposal storage by round + */ + void remove(const Round &round); + /** * Method provide state of processing for concrete proposal/block * @param round, in which that proposal/block is being voted From 733b5f0948c00c18213db27c4acbbc52eec7f98d Mon Sep 17 00:00:00 2001 From: iceseer Date: Mon, 1 Mar 2021 15:01:57 +0300 Subject: [PATCH 3/4] fixup! Signed-off-by: iceseer --- irohad/consensus/yac/impl/yac.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irohad/consensus/yac/impl/yac.cpp b/irohad/consensus/yac/impl/yac.cpp index 6f411a0f26b..41a988bc627 100644 --- a/irohad/consensus/yac/impl/yac.cpp +++ b/irohad/consensus/yac/impl/yac.cpp @@ -192,7 +192,7 @@ namespace iroha { return; } - enum { kRotatePeriod = 3 }; + enum { kRotatePeriod = 10 }; if (0 != attempt && 0 == (attempt % kRotatePeriod)) { vote_storage_.remove(vote.hash.vote_round); From c2033d6f3a942230f3187e2df1ea8881994d17b1 Mon Sep 17 00:00:00 2001 From: iceseer Date: Wed, 3 Mar 2021 11:51:52 +0300 Subject: [PATCH 4/4] tests fixup! Signed-off-by: iceseer --- test/module/irohad/consensus/yac/yac_rainy_day_test.cpp | 2 +- test/module/irohad/consensus/yac/yac_simple_cold_case_test.cpp | 2 +- test/module/irohad/consensus/yac/yac_sunny_day_test.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/module/irohad/consensus/yac/yac_rainy_day_test.cpp b/test/module/irohad/consensus/yac/yac_rainy_day_test.cpp index 93039f0ac5f..34426bbb989 100644 --- a/test/module/irohad/consensus/yac/yac_rainy_day_test.cpp +++ b/test/module/irohad/consensus/yac/yac_rainy_day_test.cpp @@ -17,7 +17,7 @@ using ::testing::Return; using namespace iroha::consensus::yac; using namespace framework::test_subscriber; -static constexpr size_t kFixedRandomNumber = 24; +static constexpr size_t kFixedRandomNumber = 9; /** * @given yac consensus with 4 peers diff --git a/test/module/irohad/consensus/yac/yac_simple_cold_case_test.cpp b/test/module/irohad/consensus/yac/yac_simple_cold_case_test.cpp index 4ee8c5bb493..54340785e4c 100644 --- a/test/module/irohad/consensus/yac/yac_simple_cold_case_test.cpp +++ b/test/module/irohad/consensus/yac/yac_simple_cold_case_test.cpp @@ -29,7 +29,7 @@ using namespace framework::test_subscriber; using namespace std; using namespace shared_model::interface::types; -static constexpr size_t kRandomFixedNumber = 27; +static constexpr size_t kRandomFixedNumber = 9; /** * @given Yac and ordering over some peers diff --git a/test/module/irohad/consensus/yac/yac_sunny_day_test.cpp b/test/module/irohad/consensus/yac/yac_sunny_day_test.cpp index 541b2be660b..61ebcd321ba 100644 --- a/test/module/irohad/consensus/yac/yac_sunny_day_test.cpp +++ b/test/module/irohad/consensus/yac/yac_sunny_day_test.cpp @@ -19,7 +19,7 @@ using namespace iroha::consensus::yac; using namespace framework::test_subscriber; using namespace std; -static constexpr size_t kRandomFixedNumber = 42; +static constexpr size_t kRandomFixedNumber = 9; /** * @given yac & 4 peers