This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
Ordering Service: on request proposal strategy #2215
Open
muratovv
wants to merge
23
commits into
develop
Choose a base branch
from
feature/os_on_request_proposal_strategy
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
bdb80e8
Some state of work
muratovv a92e8c6
Fix minor issues
muratovv 94da0f2
fix test
muratovv e7f9843
Fix interfaces in OS
muratovv d1dd2dd
fix irohad compilation
muratovv a16c936
fix kick out strategy tests
muratovv 023fede
Revert interface of on demand connection factory
muratovv be546f2
Fix reasons adding to answer validator
muratovv 3b835eb
Fix mocks regarding new interface and fix some module tests
muratovv c29f107
Clean up branch
muratovv 35043b0
Move onProposal from OS to Server
lebdron 85d7ab0
Refactor proposal strategy interface
lebdron d33bd4f
Remove peers from OS interface
lebdron 3b31d3f
Remove OsSide interface
lebdron 8429805
Rename public key fields
lebdron 981f1fa
Make Answer usage consistent with shared model
lebdron 13141ce
Simplify method calls in OS
lebdron 6a1164d
Remove initial round from OS
lebdron f6f1427
Simplify OS test
lebdron 09554ef
Revert torii_transport_command_test
lebdron 6d0a640
Merge branch 'develop' into feature/os_on_request_proposal_strategy
lebdron 07652ad
Fix proto schema
lebdron c02883f
Fix hasMajority
lebdron 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
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
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
59 changes: 59 additions & 0 deletions
59
irohad/ordering/impl/kick_out_proposal_creation_strategy.cpp
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "ordering/impl/kick_out_proposal_creation_strategy.hpp" | ||
|
||
#include <algorithm> | ||
#include "interfaces/common_objects/peer.hpp" | ||
|
||
using namespace iroha::ordering; | ||
|
||
KickOutProposalCreationStrategy::KickOutProposalCreationStrategy( | ||
std::shared_ptr<SupermajorityCheckerType> majority_checker) | ||
: majority_checker_(majority_checker) {} | ||
|
||
void KickOutProposalCreationStrategy::onCollaborationOutcome( | ||
const PeerList &peers) { | ||
std::lock_guard<std::mutex> guard(mutex_); | ||
RoundCollectionType last_requested; | ||
for (const auto &peer : peers) { | ||
auto iter = last_requested_.find(peer.hex()); | ||
if (iter != last_requested_.end()) { | ||
last_requested.insert(*iter); | ||
} else { | ||
last_requested.insert({peer.hex(), RoundType{0, 0}}); | ||
} | ||
} | ||
last_requested_ = last_requested; | ||
} | ||
|
||
bool KickOutProposalCreationStrategy::shouldCreateRound(RoundType round) { | ||
uint64_t counter = 0; | ||
{ | ||
std::lock_guard<std::mutex> guard(mutex_); | ||
counter = std::count_if( | ||
last_requested_.begin(), | ||
last_requested_.end(), | ||
[&round](const auto &elem) { return elem.second >= round; }); | ||
} | ||
|
||
auto has_majority = | ||
majority_checker_->hasMajority(counter, last_requested_.size()); | ||
return not has_majority; | ||
} | ||
|
||
boost::optional<ProposalCreationStrategy::RoundType> | ||
KickOutProposalCreationStrategy::onProposal(const PeerType &who, | ||
RoundType requested_round) { | ||
{ | ||
std::lock_guard<std::mutex> guard(mutex_); | ||
auto iter = last_requested_.find(who.hex()); | ||
if (iter != last_requested_.end() and iter->second < requested_round) { | ||
iter->second = requested_round; | ||
} | ||
} | ||
|
||
return boost::none; | ||
} |
Oops, something went wrong.
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.
Discussed offline: need to rename the method