diff --git a/operator/runtime/mainnet/src/configs/storagehub/mod.rs b/operator/runtime/mainnet/src/configs/storagehub/mod.rs index 9389d2c5..c683983d 100644 --- a/operator/runtime/mainnet/src/configs/storagehub/mod.rs +++ b/operator/runtime/mainnet/src/configs/storagehub/mod.rs @@ -12,7 +12,7 @@ use frame_support::pallet_prelude::DispatchClass; use frame_support::traits::AsEnsureOriginWithArg; use frame_support::{ parameter_types, - traits::{ConstU128, ConstU32, ConstU64}, + traits::{ConstU128, ConstU32, ConstU64, Randomness}, weights::Weight, }; use frame_system::pallet_prelude::BlockNumberFor; @@ -109,15 +109,21 @@ impl pallet_randomness::Config for Runtime { pub struct BabeDataGetter; impl pallet_randomness::GetBabeData for BabeDataGetter { fn get_epoch_index() -> u64 { - pallet_babe::Pallet::::current_epoch().epoch_index + pallet_babe::Pallet::::epoch_index() } fn get_epoch_randomness() -> Hash { - sp_core::H256::from(pallet_babe::Pallet::::current_epoch().randomness) + // We use `RandomnessFromOneEpochAgo` implementation of the `Randomness` trait here, which hashes the `NextRandomness` + // stored by the BABE pallet, and is valid for commitments until the last block of the last epoch (`_n`). The hashed + // received is the hash of `NextRandomness` concatenated with the `subject` parameter provided (in this case empty). + let (h, _n) = pallet_babe::RandomnessFromOneEpochAgo::::random(b""); + h } fn get_parent_randomness() -> Hash { - sp_core::H256::from( - pallet_babe::Pallet::::author_vrf_randomness().unwrap_or_default(), - ) + // We use `ParentBlockRandomness` implementation of the `Randomness` trait here, which hashes the `AuthorVrfRandomness` + // stored by the BABE pallet, and is valid for commitments until the parent block (`_n`). The hashed received is the + // hash of `AuthorVrfRandomness` concatenated with the `subject` parameter provided (in this case empty). + let (h_opt, _n) = pallet_babe::ParentBlockRandomness::::random(b""); + h_opt.unwrap_or_default() } } diff --git a/operator/runtime/stagenet/src/configs/storagehub/mod.rs b/operator/runtime/stagenet/src/configs/storagehub/mod.rs index 312040bc..c683983d 100644 --- a/operator/runtime/stagenet/src/configs/storagehub/mod.rs +++ b/operator/runtime/stagenet/src/configs/storagehub/mod.rs @@ -12,7 +12,7 @@ use frame_support::pallet_prelude::DispatchClass; use frame_support::traits::AsEnsureOriginWithArg; use frame_support::{ parameter_types, - traits::{ConstU128, ConstU32, ConstU64}, + traits::{ConstU128, ConstU32, ConstU64, Randomness}, weights::Weight, }; use frame_system::pallet_prelude::BlockNumberFor; @@ -109,13 +109,21 @@ impl pallet_randomness::Config for Runtime { pub struct BabeDataGetter; impl pallet_randomness::GetBabeData for BabeDataGetter { fn get_epoch_index() -> u64 { - pallet_babe::Pallet::::current_epoch().epoch_index + pallet_babe::Pallet::::epoch_index() } fn get_epoch_randomness() -> Hash { - sp_core::H256::from(pallet_babe::Pallet::::current_epoch().randomness) + // We use `RandomnessFromOneEpochAgo` implementation of the `Randomness` trait here, which hashes the `NextRandomness` + // stored by the BABE pallet, and is valid for commitments until the last block of the last epoch (`_n`). The hashed + // received is the hash of `NextRandomness` concatenated with the `subject` parameter provided (in this case empty). + let (h, _n) = pallet_babe::RandomnessFromOneEpochAgo::::random(b""); + h } fn get_parent_randomness() -> Hash { - sp_core::H256::from(pallet_babe::Pallet::::current_epoch().randomness) + // We use `ParentBlockRandomness` implementation of the `Randomness` trait here, which hashes the `AuthorVrfRandomness` + // stored by the BABE pallet, and is valid for commitments until the parent block (`_n`). The hashed received is the + // hash of `AuthorVrfRandomness` concatenated with the `subject` parameter provided (in this case empty). + let (h_opt, _n) = pallet_babe::ParentBlockRandomness::::random(b""); + h_opt.unwrap_or_default() } } diff --git a/operator/runtime/testnet/src/configs/storagehub/mod.rs b/operator/runtime/testnet/src/configs/storagehub/mod.rs index 312040bc..c683983d 100644 --- a/operator/runtime/testnet/src/configs/storagehub/mod.rs +++ b/operator/runtime/testnet/src/configs/storagehub/mod.rs @@ -12,7 +12,7 @@ use frame_support::pallet_prelude::DispatchClass; use frame_support::traits::AsEnsureOriginWithArg; use frame_support::{ parameter_types, - traits::{ConstU128, ConstU32, ConstU64}, + traits::{ConstU128, ConstU32, ConstU64, Randomness}, weights::Weight, }; use frame_system::pallet_prelude::BlockNumberFor; @@ -109,13 +109,21 @@ impl pallet_randomness::Config for Runtime { pub struct BabeDataGetter; impl pallet_randomness::GetBabeData for BabeDataGetter { fn get_epoch_index() -> u64 { - pallet_babe::Pallet::::current_epoch().epoch_index + pallet_babe::Pallet::::epoch_index() } fn get_epoch_randomness() -> Hash { - sp_core::H256::from(pallet_babe::Pallet::::current_epoch().randomness) + // We use `RandomnessFromOneEpochAgo` implementation of the `Randomness` trait here, which hashes the `NextRandomness` + // stored by the BABE pallet, and is valid for commitments until the last block of the last epoch (`_n`). The hashed + // received is the hash of `NextRandomness` concatenated with the `subject` parameter provided (in this case empty). + let (h, _n) = pallet_babe::RandomnessFromOneEpochAgo::::random(b""); + h } fn get_parent_randomness() -> Hash { - sp_core::H256::from(pallet_babe::Pallet::::current_epoch().randomness) + // We use `ParentBlockRandomness` implementation of the `Randomness` trait here, which hashes the `AuthorVrfRandomness` + // stored by the BABE pallet, and is valid for commitments until the parent block (`_n`). The hashed received is the + // hash of `AuthorVrfRandomness` concatenated with the `subject` parameter provided (in this case empty). + let (h_opt, _n) = pallet_babe::ParentBlockRandomness::::random(b""); + h_opt.unwrap_or_default() } }