Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. All Rights Reserved.
3 : * SPDX-License-Identifier: Apache-2.0
4 : */
5 :
6 : #include "consensus/yac/impl/supermajority_checker_cft.hpp"
7 :
8 : #include <boost/range/algorithm/max_element.hpp>
9 : #include <boost/range/numeric.hpp>
10 : #include "consensus/yac/impl/supermajority_checker_kf1.hpp"
11 :
12 : namespace iroha {
13 : namespace consensus {
14 : namespace yac {
15 :
16 : bool SupermajorityCheckerCft::hasSupermajority(
17 : PeersNumberType agreed, PeersNumberType all) const {
18 18 : return checkKfPlus1Supermajority(
19 18 : agreed, all, detail::kSupermajorityCheckerKfPlus1Cft);
20 : }
21 :
22 : bool SupermajorityCheckerCft::canHaveSupermajority(
23 : const VoteGroups &votes, PeersNumberType all) const {
24 14 : const PeersNumberType largest_group =
25 14 : boost::empty(votes) ? 0 : *boost::max_element(votes);
26 14 : const PeersNumberType voted = boost::accumulate(votes, 0);
27 14 : const PeersNumberType not_voted = all - voted;
28 :
29 14 : return hasSupermajority(largest_group + not_voted, all);
30 0 : }
31 :
32 : } // namespace yac
33 : } // namespace consensus
34 : } // namespace iroha
|