Kagome
Polkadot Runtime Engine in C++17
threshold_util.cpp
Go to the documentation of this file.
1 
7 
8 #include <boost/range/adaptors.hpp>
9 #include <boost/range/numeric.hpp>
10 
11 namespace kagome::consensus {
12 
13  Threshold calculateThreshold(const std::pair<uint64_t, uint64_t> &ratio,
14  const primitives::AuthorityList &authorities,
15  primitives::AuthorityIndex authority_index) {
16  double float_point_ratio = double(ratio.first) / ratio.second;
17 
18  using boost::adaptors::transformed;
19  double theta = double(authorities[authority_index].weight)
20  / boost::accumulate(
21  authorities | transformed([](const auto &authority) {
22  return authority.weight;
23  }),
24  0.);
25 
26  using namespace boost::multiprecision; // NOLINT
27  cpp_rational p_rat(1. - pow(1. - float_point_ratio, theta));
28  static const auto a = (uint256_t{1} << 128);
29  return Threshold{a * numerator(p_rat) / denominator(p_rat)};
30  }
31 
32 } // namespace kagome::consensus
uint32_t AuthorityIndex
Definition: authority.hpp:36
boost::multiprecision::uint256_t uint256_t
Definition: mp_utils.hpp:15
Threshold calculateThreshold(const std::pair< uint64_t, uint64_t > &ratio, const primitives::AuthorityList &authorities, primitives::AuthorityIndex authority_index)
crypto::VRFThreshold Threshold
threshold, which must not be exceeded for the party to be a slot leader
Definition: common.hpp:33