Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. All Rights Reserved.
3 : * SPDX-License-Identifier: Apache-2.0
4 : */
5 :
6 : #ifndef IROHA_SUPERMAJORITY_CHECKER_KF1_HPP
7 : #define IROHA_SUPERMAJORITY_CHECKER_KF1_HPP
8 :
9 : #include "consensus/yac/supermajority_checker.hpp"
10 :
11 : namespace iroha {
12 : namespace consensus {
13 : namespace yac {
14 :
15 : /**
16 : * A generic implementation of N = K * f + 1 supermajority checker.
17 : * N is the amount of peers in the network, f is the number of tolerated
18 : * faulty peers, and K is a free parameter. Supermajority is achieved when
19 : * at least N - f peers agree. For the networks of arbitrary peers amount
20 : * Na the tolerated number of faulty peers is (Na - 1) % K.
21 : *
22 : * @param agreed - the number of peers agreed on the state
23 : * @param all - the total number of peers in the network
24 : * @param k - the free parameter of the model
25 : *
26 : * @return whether supermajority is achieved by the agreed peers
27 : */
28 : inline bool checkKfPlus1Supermajority(PeersNumberType agreed,
29 : PeersNumberType all,
30 : unsigned int k) {
31 4136 : if (agreed > all) {
32 2 : return false;
33 : }
34 4134 : return agreed * k >= (k - 1) * (all - 1) + k;
35 4136 : }
36 :
37 : } // namespace yac
38 : } // namespace consensus
39 : } // namespace iroha
40 :
41 : #endif // IROHA_SUPERMAJORITY_CHECKER_KF1_HPP
|