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

Feature/Improves stability in networks with faulty nodes #809

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
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