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
This commit is contained in:
Dan Shields
2022-03-14 18:34:34 -06:00
committed by GitHub
parent 474a2c02c4
commit 1b985c5d36
3 changed files with 44 additions and 72 deletions
+15 -37
View File
@@ -24,7 +24,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion}; use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion};
use frame_support::{ use frame_support::{
construct_runtime, parameter_types, construct_runtime, parameter_types,
traits::{Contains, KeyOwnerProofSystem, Randomness}, traits::{Contains, InstanceFilter, KeyOwnerProofSystem, OnRuntimeUpgrade},
PalletId, PalletId,
}; };
use frame_system::EnsureRoot; use frame_system::EnsureRoot;
@@ -36,9 +36,9 @@ use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInf
use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use primitives::v2::{ use primitives::v2::{
AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CommittedCandidateReceipt, AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CommittedCandidateReceipt,
CoreState, GroupRotationInfo, Hash, Id, InboundDownwardMessage, InboundHrmpMessage, Moment, CoreState, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
Nonce, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement,
SessionInfo as SessionInfoData, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ScrapedOnChainVotes, SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId,
ValidatorIndex, ValidatorSignature, ValidatorIndex, ValidatorSignature,
}; };
use runtime_common::{ use runtime_common::{
@@ -51,7 +51,7 @@ use sp_core::{OpaqueMetadata, RuntimeDebug};
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys,
traits::{ traits::{
self, AccountIdLookup, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT, Keccak256, AccountIdLookup, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT, Keccak256,
OpaqueKeys, SaturatedConversion, Verify, OpaqueKeys, SaturatedConversion, Verify,
}, },
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
@@ -75,15 +75,9 @@ use bridge_runtime_common::messages::{
source::estimate_message_dispatch_and_delivery_fee, MessageBridge, 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. /// Constant values used within the runtime.
use rococo_runtime_constants::{currency::*, fee::*, time::*}; use rococo_runtime_constants::{currency::*, fee::*, time::*};
use frame_support::traits::{InstanceFilter, OnRuntimeUpgrade};
mod bridge_messages; mod bridge_messages;
mod validator_manager; mod validator_manager;
mod weights; mod weights;
@@ -715,11 +709,6 @@ impl paras_registrar::Config for Runtime {
type WeightInfo = paras_registrar::TestWeightInfo; 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 { impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId; type BeefyId = BeefyId;
} }
@@ -727,7 +716,7 @@ impl pallet_beefy::Config for Runtime {
impl pallet_mmr::Config for Runtime { impl pallet_mmr::Config for Runtime {
const INDEXING_PREFIX: &'static [u8] = b"mmr"; const INDEXING_PREFIX: &'static [u8] = b"mmr";
type Hashing = Keccak256; type Hashing = Keccak256;
type Hash = <Keccak256 as traits::Hash>::Output; type Hash = <Keccak256 as sp_runtime::traits::Hash>::Output;
type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest<Runtime>; type OnNewRoot = pallet_beefy_mmr::DepositBeefyDigest<Runtime>;
type WeightInfo = (); type WeightInfo = ();
type LeafData = pallet_beefy_mmr::Pallet<Runtime>; type LeafData = pallet_beefy_mmr::Pallet<Runtime>;
@@ -913,17 +902,6 @@ impl pallet_bridge_messages::Config<AtRococoWithWococoMessagesInstance> for Runt
type MessageDispatch = crate::bridge_messages::FromWococoMessageDispatch; type MessageDispatch = crate::bridge_messages::FromWococoMessageDispatch;
} }
impl Randomness<Hash, BlockNumber> 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! { parameter_types! {
pub const EndingPeriod: BlockNumber = 1 * HOURS; pub const EndingPeriod: BlockNumber = 1 * HOURS;
pub const SampleLength: BlockNumber = 1; pub const SampleLength: BlockNumber = 1;
@@ -935,7 +913,7 @@ impl auctions::Config for Runtime {
type Registrar = Registrar; type Registrar = Registrar;
type EndingPeriod = EndingPeriod; type EndingPeriod = EndingPeriod;
type SampleLength = SampleLength; type SampleLength = SampleLength;
type Randomness = ParentHashRandomness; type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
type InitiateOrigin = EnsureRoot<AccountId>; type InitiateOrigin = EnsureRoot<AccountId>;
type WeightInfo = auctions::TestWeightInfo; type WeightInfo = auctions::TestWeightInfo;
} }
@@ -1201,7 +1179,7 @@ sp_api::impl_runtime_apis! {
runtime_api_impl::availability_cores::<Runtime>() runtime_api_impl::availability_cores::<Runtime>()
} }
fn persisted_validation_data(para_id: Id, assumption: OccupiedCoreAssumption) fn persisted_validation_data(para_id: ParaId, assumption: OccupiedCoreAssumption)
-> Option<PersistedValidationData<Hash, BlockNumber>> { -> Option<PersistedValidationData<Hash, BlockNumber>> {
runtime_api_impl::persisted_validation_data::<Runtime>(para_id, assumption) runtime_api_impl::persisted_validation_data::<Runtime>(para_id, assumption)
} }
@@ -1217,7 +1195,7 @@ sp_api::impl_runtime_apis! {
} }
fn check_validation_outputs( fn check_validation_outputs(
para_id: Id, para_id: ParaId,
outputs: primitives::v2::CandidateCommitments, outputs: primitives::v2::CandidateCommitments,
) -> bool { ) -> bool {
runtime_api_impl::check_validation_outputs::<Runtime>(para_id, outputs) runtime_api_impl::check_validation_outputs::<Runtime>(para_id, outputs)
@@ -1227,12 +1205,12 @@ sp_api::impl_runtime_apis! {
runtime_api_impl::session_index_for_child::<Runtime>() runtime_api_impl::session_index_for_child::<Runtime>()
} }
fn validation_code(para_id: Id, assumption: OccupiedCoreAssumption) fn validation_code(para_id: ParaId, assumption: OccupiedCoreAssumption)
-> Option<ValidationCode> { -> Option<ValidationCode> {
runtime_api_impl::validation_code::<Runtime>(para_id, assumption) runtime_api_impl::validation_code::<Runtime>(para_id, assumption)
} }
fn candidate_pending_availability(para_id: Id) -> Option<CommittedCandidateReceipt<Hash>> { fn candidate_pending_availability(para_id: ParaId) -> Option<CommittedCandidateReceipt<Hash>> {
runtime_api_impl::candidate_pending_availability::<Runtime>(para_id) runtime_api_impl::candidate_pending_availability::<Runtime>(para_id)
} }
@@ -1247,17 +1225,17 @@ sp_api::impl_runtime_apis! {
}) })
} }
fn session_info(index: SessionIndex) -> Option<SessionInfoData> { fn session_info(index: SessionIndex) -> Option<SessionInfo> {
runtime_api_impl::session_info::<Runtime>(index) runtime_api_impl::session_info::<Runtime>(index)
} }
fn dmq_contents(recipient: Id) -> Vec<InboundDownwardMessage<BlockNumber>> { fn dmq_contents(recipient: ParaId) -> Vec<InboundDownwardMessage<BlockNumber>> {
runtime_api_impl::dmq_contents::<Runtime>(recipient) runtime_api_impl::dmq_contents::<Runtime>(recipient)
} }
fn inbound_hrmp_channels_contents( fn inbound_hrmp_channels_contents(
recipient: Id recipient: ParaId
) -> BTreeMap<Id, Vec<InboundHrmpMessage<BlockNumber>>> { ) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>> {
runtime_api_impl::inbound_hrmp_channels_contents::<Runtime>(recipient) runtime_api_impl::inbound_hrmp_channels_contents::<Runtime>(recipient)
} }
+27 -34
View File
@@ -14,26 +14,37 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. // along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! 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)] #![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "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 parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use primitives::v2::{ use primitives::v2::{
AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CommittedCandidateReceipt, AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CommittedCandidateReceipt,
CoreState, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, CoreState, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, ScrapedOnChainVotes, Moment, Nonce, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement,
SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ScrapedOnChainVotes, SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId,
ValidatorIndex, ValidatorSignature,
}; };
use runtime_common::{ use runtime_common::{
assigned_slots, auctions, crowdloan, impl_runtime_weights, impls::ToAuthor, paras_registrar, assigned_slots, auctions, crowdloan, impl_runtime_weights, impls::ToAuthor, paras_registrar,
paras_sudo_wrapper, slots, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate, paras_sudo_wrapper, slots, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate,
}; };
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
use runtime_parachains::{ use runtime_parachains::{
configuration as parachains_configuration, disputes as parachains_disputes, configuration as parachains_configuration, disputes as parachains_disputes,
dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion, 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, 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, session_info as parachains_session_info, shared as parachains_shared, ump as parachains_ump,
}; };
use scale_info::TypeInfo;
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use sp_core::{OpaqueMetadata, RuntimeDebug};
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 sp_runtime::{ use sp_runtime::{
create_runtime_str, create_runtime_str,
curve::PiecewiseLinear, curve::PiecewiseLinear,
@@ -69,11 +67,11 @@ use sp_runtime::{
ApplyExtrinsicResult, KeyTypeId, Perbill, ApplyExtrinsicResult, KeyTypeId, Perbill,
}; };
use sp_staking::SessionIndex; use sp_staking::SessionIndex;
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
use sp_version::NativeVersion; use sp_version::NativeVersion;
use sp_version::RuntimeVersion; use sp_version::RuntimeVersion;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall; pub use pallet_election_provider_multi_phase::Call as EPMCall;
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub use pallet_staking::StakerStatus; pub use pallet_staking::StakerStatus;
@@ -84,13 +82,8 @@ pub use sp_runtime::BuildStorage;
/// Constant values used within the runtime. /// Constant values used within the runtime.
use westend_runtime_constants::{currency::*, fee::*, time::*}; use westend_runtime_constants::{currency::*, fee::*, time::*};
// Weights used in the runtime
mod weights;
// Voter bag threshold definitions.
mod bag_thresholds; mod bag_thresholds;
mod weights;
// XCM configurations.
pub mod xcm_config; pub mod xcm_config;
#[cfg(test)] #[cfg(test)]
@@ -171,7 +164,7 @@ impl frame_system::Config for Runtime {
} }
parameter_types! { parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * pub MaximumSchedulerWeight: frame_support::weights::Weight = Perbill::from_percent(80) *
BlockWeights::get().max_block; BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50; pub const MaxScheduledPerBlock: u32 = 50;
pub const NoPreimagePostponement: Option<u32> = Some(10); pub const NoPreimagePostponement: Option<u32> = Some(10);
@@ -704,7 +697,7 @@ parameter_types! {
Decode, Decode,
RuntimeDebug, RuntimeDebug,
MaxEncodedLen, MaxEncodedLen,
scale_info::TypeInfo, TypeInfo,
)] )]
pub enum ProxyType { pub enum ProxyType {
Any, Any,
@@ -1301,8 +1294,8 @@ sp_api::impl_runtime_apis! {
} }
fn submit_pvf_check_statement( fn submit_pvf_check_statement(
stmt: primitives::v2::PvfCheckStatement, stmt: PvfCheckStatement,
signature: primitives::v2::ValidatorSignature, signature: ValidatorSignature,
) { ) {
parachains_runtime_api_impl::submit_pvf_check_statement::<Runtime>(stmt, signature) parachains_runtime_api_impl::submit_pvf_check_statement::<Runtime>(stmt, signature)
} }
@@ -1477,12 +1470,12 @@ sp_api::impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime { impl frame_try_runtime::TryRuntime<Block> 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."); log::info!("try-runtime::on_runtime_upgrade westend.");
let weight = Executive::try_runtime_upgrade().unwrap(); let weight = Executive::try_runtime_upgrade().unwrap();
(weight, BlockWeights::get().max_block) (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) Executive::execute_block_no_check(block)
} }
} }
+2 -1
View File
@@ -32,7 +32,8 @@ fn sample_size_is_sensible() {
use runtime_common::auctions::WeightInfo; use runtime_common::auctions::WeightInfo;
// Need to clean up all samples at the end of an auction. // Need to clean up all samples at the end of an auction.
let samples: BlockNumber = EndingPeriod::get() / SampleLength::get(); 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. // Max sample cleanup should be no more than half the total block weight.
assert!(max_weight * 2 < BlockWeights::get().max_block); assert!(max_weight * 2 < BlockWeights::get().max_block);
assert!( assert!(