From 1b985c5d360dbea02845bd857fcc4aee72b6680d Mon Sep 17 00:00:00 2001 From: Dan Shields <35669742+NukeManDan@users.noreply.github.com> Date: Mon, 14 Mar 2022 18:34:34 -0600 Subject: [PATCH] Rococo to use BABE randomness, Westend & Rococo runtime synchronization in file format (#5082) * * Rococo to use BABE randomness * Westend & Rococo runtime syncronization in file format (starting) * explicit frame_support::weights::Weight --- polkadot/runtime/rococo/src/lib.rs | 52 +++++++---------------- polkadot/runtime/westend/src/lib.rs | 61 ++++++++++++--------------- polkadot/runtime/westend/src/tests.rs | 3 +- 3 files changed, 44 insertions(+), 72 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 57211d3e6f..be7c685a7f 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -24,7 +24,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion}; use frame_support::{ construct_runtime, parameter_types, - traits::{Contains, KeyOwnerProofSystem, Randomness}, + traits::{Contains, InstanceFilter, KeyOwnerProofSystem, OnRuntimeUpgrade}, PalletId, }; use frame_system::EnsureRoot; @@ -36,9 +36,9 @@ use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInf use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use primitives::v2::{ AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CommittedCandidateReceipt, - CoreState, GroupRotationInfo, Hash, Id, InboundDownwardMessage, InboundHrmpMessage, Moment, - Nonce, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, - SessionInfo as SessionInfoData, Signature, ValidationCode, ValidationCodeHash, ValidatorId, + CoreState, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, + Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, + ScrapedOnChainVotes, SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature, }; use runtime_common::{ @@ -51,7 +51,7 @@ use sp_core::{OpaqueMetadata, RuntimeDebug}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{ - self, AccountIdLookup, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT, Keccak256, + AccountIdLookup, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT, Keccak256, OpaqueKeys, SaturatedConversion, Verify, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, @@ -75,15 +75,9 @@ use bridge_runtime_common::messages::{ source::estimate_message_dispatch_and_delivery_fee, MessageBridge, }; -pub use pallet_balances::Call as BalancesCall; - -use polkadot_parachain::primitives::Id as ParaId; - /// Constant values used within the runtime. use rococo_runtime_constants::{currency::*, fee::*, time::*}; -use frame_support::traits::{InstanceFilter, OnRuntimeUpgrade}; - mod bridge_messages; mod validator_manager; mod weights; @@ -715,11 +709,6 @@ impl paras_registrar::Config for Runtime { type WeightInfo = paras_registrar::TestWeightInfo; } -/// 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 pallet_beefy::Config for Runtime { type BeefyId = BeefyId; } @@ -727,7 +716,7 @@ impl pallet_beefy::Config for Runtime { impl pallet_mmr::Config for Runtime { const INDEXING_PREFIX: &'static [u8] = b"mmr"; type Hashing = Keccak256; - type Hash = ::Output; + type Hash = ::Output; type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest; type WeightInfo = (); type LeafData = pallet_beefy_mmr::Pallet; @@ -913,17 +902,6 @@ impl pallet_bridge_messages::Config for Runt type MessageDispatch = crate::bridge_messages::FromWococoMessageDispatch; } -impl Randomness for ParentHashRandomness { - fn random(subject: &[u8]) -> (Hash, BlockNumber) { - ( - (System::parent_hash(), subject) - .using_encoded(sp_io::hashing::blake2_256) - .into(), - System::block_number(), - ) - } -} - parameter_types! { pub const EndingPeriod: BlockNumber = 1 * HOURS; pub const SampleLength: BlockNumber = 1; @@ -935,7 +913,7 @@ impl auctions::Config for Runtime { type Registrar = Registrar; type EndingPeriod = EndingPeriod; type SampleLength = SampleLength; - type Randomness = ParentHashRandomness; + type Randomness = pallet_babe::RandomnessFromOneEpochAgo; type InitiateOrigin = EnsureRoot; type WeightInfo = auctions::TestWeightInfo; } @@ -1201,7 +1179,7 @@ sp_api::impl_runtime_apis! { runtime_api_impl::availability_cores::() } - fn persisted_validation_data(para_id: Id, assumption: OccupiedCoreAssumption) + fn persisted_validation_data(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option> { runtime_api_impl::persisted_validation_data::(para_id, assumption) } @@ -1217,7 +1195,7 @@ sp_api::impl_runtime_apis! { } fn check_validation_outputs( - para_id: Id, + para_id: ParaId, outputs: primitives::v2::CandidateCommitments, ) -> bool { runtime_api_impl::check_validation_outputs::(para_id, outputs) @@ -1227,12 +1205,12 @@ sp_api::impl_runtime_apis! { runtime_api_impl::session_index_for_child::() } - fn validation_code(para_id: Id, assumption: OccupiedCoreAssumption) + fn validation_code(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option { runtime_api_impl::validation_code::(para_id, assumption) } - fn candidate_pending_availability(para_id: Id) -> Option> { + fn candidate_pending_availability(para_id: ParaId) -> Option> { runtime_api_impl::candidate_pending_availability::(para_id) } @@ -1247,17 +1225,17 @@ sp_api::impl_runtime_apis! { }) } - fn session_info(index: SessionIndex) -> Option { + fn session_info(index: SessionIndex) -> Option { runtime_api_impl::session_info::(index) } - fn dmq_contents(recipient: Id) -> Vec> { + fn dmq_contents(recipient: ParaId) -> Vec> { runtime_api_impl::dmq_contents::(recipient) } fn inbound_hrmp_channels_contents( - recipient: Id - ) -> BTreeMap>> { + recipient: ParaId + ) -> BTreeMap>> { runtime_api_impl::inbound_hrmp_channels_contents::(recipient) } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 0f29b07f36..bffcdb73b9 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -14,26 +14,37 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! The Polkadot runtime. This can be compiled with `#[no_std]`, ready for Wasm. +//! The Westend runtime. This can be compiled with `#[no_std]`, ready for Wasm. #![cfg_attr(not(feature = "std"), no_std)] // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] -use pallet_transaction_payment::CurrencyAdapter; +use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; +use beefy_primitives::crypto::AuthorityId as BeefyId; +use frame_support::{ + construct_runtime, parameter_types, + traits::{Contains, InstanceFilter, KeyOwnerProofSystem, OnRuntimeUpgrade}, + PalletId, +}; +use frame_system::EnsureRoot; +use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; +use pallet_im_online::sr25519::AuthorityId as ImOnlineId; +use pallet_mmr_primitives as mmr; +use pallet_session::historical as session_historical; +use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use primitives::v2::{ AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, - Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes, - SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, + Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, + ScrapedOnChainVotes, SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, + ValidatorIndex, ValidatorSignature, }; use runtime_common::{ assigned_slots, auctions, crowdloan, impl_runtime_weights, impls::ToAuthor, paras_registrar, paras_sudo_wrapper, slots, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate, }; -use sp_std::{collections::btree_map::BTreeMap, prelude::*}; - use runtime_parachains::{ configuration as parachains_configuration, disputes as parachains_disputes, dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion, @@ -42,21 +53,8 @@ use runtime_parachains::{ runtime_api_impl::v2 as parachains_runtime_api_impl, scheduler as parachains_scheduler, session_info as parachains_session_info, shared as parachains_shared, ump as parachains_ump, }; - -use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; -use beefy_primitives::crypto::AuthorityId as BeefyId; -use frame_support::{ - construct_runtime, parameter_types, - traits::{Contains, InstanceFilter, KeyOwnerProofSystem, OnRuntimeUpgrade}, - PalletId, RuntimeDebug, -}; -use frame_system::EnsureRoot; -use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; -use pallet_im_online::sr25519::AuthorityId as ImOnlineId; -use pallet_mmr_primitives as mmr; -use pallet_session::historical as session_historical; -use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; -use sp_core::OpaqueMetadata; +use scale_info::TypeInfo; +use sp_core::{OpaqueMetadata, RuntimeDebug}; use sp_runtime::{ create_runtime_str, curve::PiecewiseLinear, @@ -69,11 +67,11 @@ use sp_runtime::{ ApplyExtrinsicResult, KeyTypeId, Perbill, }; use sp_staking::SessionIndex; +use sp_std::{collections::btree_map::BTreeMap, prelude::*}; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -pub use pallet_balances::Call as BalancesCall; pub use pallet_election_provider_multi_phase::Call as EPMCall; #[cfg(feature = "std")] pub use pallet_staking::StakerStatus; @@ -84,13 +82,8 @@ pub use sp_runtime::BuildStorage; /// Constant values used within the runtime. use westend_runtime_constants::{currency::*, fee::*, time::*}; -// Weights used in the runtime -mod weights; - -// Voter bag threshold definitions. mod bag_thresholds; - -// XCM configurations. +mod weights; pub mod xcm_config; #[cfg(test)] @@ -171,7 +164,7 @@ impl frame_system::Config for Runtime { } parameter_types! { - pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * + pub MaximumSchedulerWeight: frame_support::weights::Weight = Perbill::from_percent(80) * BlockWeights::get().max_block; pub const MaxScheduledPerBlock: u32 = 50; pub const NoPreimagePostponement: Option = Some(10); @@ -704,7 +697,7 @@ parameter_types! { Decode, RuntimeDebug, MaxEncodedLen, - scale_info::TypeInfo, + TypeInfo, )] pub enum ProxyType { Any, @@ -1301,8 +1294,8 @@ sp_api::impl_runtime_apis! { } fn submit_pvf_check_statement( - stmt: primitives::v2::PvfCheckStatement, - signature: primitives::v2::ValidatorSignature, + stmt: PvfCheckStatement, + signature: ValidatorSignature, ) { parachains_runtime_api_impl::submit_pvf_check_statement::(stmt, signature) } @@ -1477,12 +1470,12 @@ sp_api::impl_runtime_apis! { #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { - fn on_runtime_upgrade() -> (Weight, Weight) { + fn on_runtime_upgrade() -> (frame_support::weights::Weight, frame_support::weights::Weight) { log::info!("try-runtime::on_runtime_upgrade westend."); let weight = Executive::try_runtime_upgrade().unwrap(); (weight, BlockWeights::get().max_block) } - fn execute_block_no_check(block: Block) -> Weight { + fn execute_block_no_check(block: Block) -> frame_support::weights::Weight { Executive::execute_block_no_check(block) } } diff --git a/polkadot/runtime/westend/src/tests.rs b/polkadot/runtime/westend/src/tests.rs index f0ab4f44e6..32a8e42e00 100644 --- a/polkadot/runtime/westend/src/tests.rs +++ b/polkadot/runtime/westend/src/tests.rs @@ -32,7 +32,8 @@ fn sample_size_is_sensible() { use runtime_common::auctions::WeightInfo; // Need to clean up all samples at the end of an auction. let samples: BlockNumber = EndingPeriod::get() / SampleLength::get(); - let max_weight: Weight = RocksDbWeight::get().reads_writes(samples.into(), samples.into()); + let max_weight: frame_support::weights::Weight = + RocksDbWeight::get().reads_writes(samples.into(), samples.into()); // Max sample cleanup should be no more than half the total block weight. assert!(max_weight * 2 < BlockWeights::get().max_block); assert!(