From 7149f764e4a790f9a619f26eeec37ab003859631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= <123550+andresilva@users.noreply.github.com> Date: Thu, 25 Mar 2021 09:49:40 +0000 Subject: [PATCH] rococo: use insecure parent hash randomness (#2701) --- polkadot/runtime/rococo/src/lib.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 5e7daa346d..3107ca1d9f 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -612,21 +612,17 @@ impl paras_registrar::Config for Runtime { type WeightInfo = paras_registrar::TestWeightInfo; } -// A wrapper around `babe::CurrentBlockRandomness` that does not return `Option`. -pub struct CurrentBlockRandomness; +/// An insecure randomness beacon that uses the parent block hash as random material. +/// +/// THIS SHOULD ONLY BE USED FOR TESTING PURPOSES. +pub struct ParentHashRandomness; -impl Randomness for CurrentBlockRandomness { +impl Randomness for ParentHashRandomness { fn random(subject: &[u8]) -> (Hash, BlockNumber) { - let (randomness, block_number) = - pallet_babe::CurrentBlockRandomness::::random(subject); - - let randomness = randomness.expect( - "only returns None when secondary VRF slots are not enabled; \ - secondary VRF slots are enbaled for rococo runtime; \ - qed.", - ); - - (randomness, block_number) + ( + (System::parent_hash(), subject).using_encoded(sp_io::hashing::blake2_256).into(), + System::block_number(), + ) } } @@ -640,7 +636,7 @@ impl auctions::Config for Runtime { type Leaser = Slots; type EndingPeriod = EndingPeriod; type SampleLength = SampleLength; - type Randomness = CurrentBlockRandomness; + type Randomness = ParentHashRandomness; type InitiateOrigin = EnsureRoot; type WeightInfo = auctions::TestWeightInfo; }