LCOV - code coverage report
Current view: top level - irohad/consensus/yac/impl - supermajority_checker_kf1.hpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 4 4 100.0 %
Date: 2019-03-07 14:46:43 Functions: 1 1 100.0 %

          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

Generated by: LCOV version 1.13