Skip to content

Commit

Permalink
Feature/Improves stability in networks with faulty nodes (#809)
Browse files Browse the repository at this point in the history
* fixup!

Signed-off-by: iceseer <[email protected]>

* fixup!

Signed-off-by: iceseer <[email protected]>

* fixup!

Signed-off-by: iceseer <[email protected]>

* tests fixup!

Signed-off-by: iceseer <[email protected]>
Signed-off-by: Alexander Lednev <[email protected]>
  • Loading branch information
iceseer authored Mar 3, 2021
1 parent bff3f83 commit 16d4377
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
24 changes: 22 additions & 2 deletions irohad/consensus/yac/impl/yac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,32 @@ 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<std::mutex> lock(mutex_);

auto committed = vote_storage_.isCommitted(vote.hash.vote_round);
if (committed) {
return;
}

enum { kRotatePeriod = 10 };

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 == kRotatePeriod) {
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 &current_leader = cluster_order.currentLeader();
Expand All @@ -200,7 +218,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() {
Expand Down
10 changes: 5 additions & 5 deletions irohad/consensus/yac/storage/yac_vote_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 |--------

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion irohad/consensus/yac/yac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/module/irohad/consensus/yac/yac_rainy_day_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/module/irohad/consensus/yac/yac_sunny_day_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 16d4377

Please sign in to comment.