8 #include <unordered_set> 10 #include <boost/assert.hpp> 11 #include <scale/scale.hpp> 19 namespace vrf_constants = crypto::constants::sr25519::vrf;
22 std::shared_ptr<crypto::VRFProvider> vrf_provider,
23 std::shared_ptr<consensus::babe::BabeConfigRepository> babe_config_repo,
24 std::shared_ptr<crypto::Hasher> hasher)
25 : vrf_provider_{std::move(vrf_provider)},
31 BOOST_ASSERT(babe_config_repo);
41 "FROM epoch {} with randomness {} TO epoch {} with randomness {}",
61 "Epoch must be initialized before this point");
70 "prepareTranscript (leadership): randomness {}, slot {}, epoch {}{}",
74 res.has_value() ?
" - SLOT LEADER" :
"");
83 "Epoch must be initialized before this point");
93 std::optional<primitives::AuthorityIndex>
98 if (0 == authorities_count) {
102 auto rand =
hasher_->blake2b_256(
103 scale::encode(std::tuple(randomness, slot)).value());
107 auto index = (rand_number % authorities_count)
108 .convert_to<primitives::AuthorityIndex>();
111 "Secondary author for slot {} has index {}. " 112 "({} authorities. Randomness: {})",
std::optional< crypto::VRFOutput > getSlotLeadership(primitives::BabeSlotNumber i) const override
std::shared_ptr< crypto::Hasher > hasher_
crypto::VRFOutput slotVrfSignature(primitives::BabeSlotNumber slot) const override
boost::multiprecision::uint256_t be_bytes_to_uint256(gsl::span< const uint8_t, 32 > bytes)
BabeLotteryImpl(std::shared_ptr< crypto::VRFProvider > vrf_provider, std::shared_ptr< consensus::babe::BabeConfigRepository > babe_config_repo, std::shared_ptr< crypto::Hasher > hasher)
std::optional< primitives::AuthorityIndex > secondarySlotAuthor(primitives::BabeSlotNumber slot, primitives::AuthorityListSize authorities_count, const Randomness &randomness) const override
SLBuffer< std::numeric_limits< size_t >::max()> Buffer
uint64_t AuthorityListSize
void changeEpoch(const EpochDescriptor &epoch, const Randomness &randomness, const Threshold &threshold, const crypto::Sr25519Keypair &keypair) override
crypto::Sr25519Keypair keypair_
std::shared_ptr< crypto::VRFProvider > vrf_provider_
Logger createLogger(const std::string &tag)
crypto::VRFThreshold Threshold
threshold, which must not be exceeded for the party to be a slot leader
primitives::Transcript & prepareTranscript(primitives::Transcript &transcript, const Randomness &randomness, BabeSlotNumber slot_number, EpochNumber epoch)
EpochDescriptor getEpoch() const override