mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 07:01:02 +00:00
runtime: use babe as randomness source (#2504)
* runtime: use babe as randomness source * runtime: fix randomness api * bridges: fix random_seed * parachains: use mock TestRandomness from frame_support_test * parachains: use mock TestRandomness from frame_support_test * runtime: update randomness source in test-runtime * runtime: remove unused import * parachains: add todo to audit usage of randomness api * "Update Substrate" Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -262,9 +262,10 @@ mod tests {
|
||||
};
|
||||
use frame_system::limits;
|
||||
use frame_support::{
|
||||
traits::{Randomness, OnInitialize, OnFinalize},
|
||||
traits::{OnInitialize, OnFinalize},
|
||||
assert_ok, assert_noop, parameter_types,
|
||||
};
|
||||
use frame_support_test::TestRandomness;
|
||||
use keyring::Sr25519Keyring;
|
||||
use runtime_parachains::{
|
||||
initializer, configuration, inclusion, session_info, scheduler, dmp, ump, hrmp, shared,
|
||||
@@ -511,16 +512,8 @@ mod tests {
|
||||
|
||||
impl session_info::Config for Test { }
|
||||
|
||||
pub struct TestRandomness;
|
||||
|
||||
impl Randomness<H256> for TestRandomness {
|
||||
fn random(_subject: &[u8]) -> H256 {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl initializer::Config for Test {
|
||||
type Randomness = TestRandomness;
|
||||
type Randomness = TestRandomness<Self>;
|
||||
}
|
||||
|
||||
impl scheduler::Config for Test { }
|
||||
|
||||
@@ -54,7 +54,7 @@ pub trait Config: frame_system::Config {
|
||||
type LeasePeriod: Get<Self::BlockNumber>;
|
||||
|
||||
/// Something that provides randomness in the runtime.
|
||||
type Randomness: Randomness<Self::Hash>;
|
||||
type Randomness: Randomness<Self::Hash, Self::BlockNumber>;
|
||||
}
|
||||
|
||||
/// Parachain registration API.
|
||||
@@ -582,7 +582,8 @@ impl<T: Config> Module<T> {
|
||||
let ending_period = T::EndingPeriod::get();
|
||||
if early_end + ending_period == now {
|
||||
// Just ended!
|
||||
let offset = T::BlockNumber::decode(&mut T::Randomness::random_seed().as_ref())
|
||||
let (seed, _) = T::Randomness::random_seed();
|
||||
let offset = T::BlockNumber::decode(&mut seed.as_ref())
|
||||
.expect("secure hashes always bigger than block numbers; qed") % ending_period;
|
||||
let res = <Winning<T>>::get(offset).unwrap_or_default();
|
||||
let mut i = T::BlockNumber::zero();
|
||||
|
||||
Reference in New Issue
Block a user