mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 03:31:05 +00:00
more clear randomness API for BABE (#8180)
* more clear randomness API for BABE * babe: move randomness utilities to its own file * node: use babe::RandomnessFromOneEpochAgo in random_seed implementation * frame-support: annotate randomness trait with block number * pallet-randomness-collective-flip: fix for new randomness trait * pallet-society: fix randomness usage * pallet-lottery: fix randomness usage * pallet-contracts: fix randomness usage * pallet-babe: fix randomness usage we need to track when the current and previous epoch started so that we know the block number by each existing on-chain was known * node: fix random_seed * node-template: fix random_seed * frame-support: extend docs * babe: add test for epoch starting block number tracking * babe: fix epoch randomness docs * frame: add todos for dealing with randomness api changes Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
committed by
GitHub
parent
f3d4355a20
commit
e2960c383e
@@ -283,7 +283,7 @@ pub trait Config<I=DefaultInstance>: system::Config {
|
||||
type Currency: ReservableCurrency<Self::AccountId>;
|
||||
|
||||
/// Something that provides randomness in the runtime.
|
||||
type Randomness: Randomness<Self::Hash>;
|
||||
type Randomness: Randomness<Self::Hash, Self::BlockNumber>;
|
||||
|
||||
/// The minimum amount of a deposit required for a bid to be made.
|
||||
type CandidateDeposit: Get<BalanceOf<Self, I>>;
|
||||
@@ -1309,7 +1309,9 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
|
||||
let mut pot = <Pot<T, I>>::get();
|
||||
|
||||
// we'll need a random seed here.
|
||||
let seed = T::Randomness::random(phrase);
|
||||
// TODO: deal with randomness freshness
|
||||
// https://github.com/paritytech/substrate/issues/8312
|
||||
let (seed, _) = T::Randomness::random(phrase);
|
||||
// seed needs to be guaranteed to be 32 bytes.
|
||||
let seed = <[u8; 32]>::decode(&mut TrailingZeroInput::new(seed.as_ref()))
|
||||
.expect("input is padded with zeroes; qed");
|
||||
@@ -1565,7 +1567,9 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
|
||||
// Start a new defender rotation
|
||||
let phrase = b"society_challenge";
|
||||
// we'll need a random seed here.
|
||||
let seed = T::Randomness::random(phrase);
|
||||
// TODO: deal with randomness freshness
|
||||
// https://github.com/paritytech/substrate/issues/8312
|
||||
let (seed, _) = T::Randomness::random(phrase);
|
||||
// seed needs to be guaranteed to be 32 bytes.
|
||||
let seed = <[u8; 32]>::decode(&mut TrailingZeroInput::new(seed.as_ref()))
|
||||
.expect("input is padded with zeroes; qed");
|
||||
|
||||
Reference in New Issue
Block a user