Enable async backing on asset-hub-rococo (#2826)

The goal is to move all system chains on Rococo (+ other testnets?) to
use async backing.

Starting with `asset-hub-rococo` to get feedback, before I do the rest.

## Related

Example: https://github.com/paritytech/polkadot-sdk/pull/1619/
Guide:
https://github.com/w3f/polkadot-wiki/blob/master/docs/maintain/maintain-guides-async-backing.md

---------

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Dónal Murray <donal.murray@parity.io>
This commit is contained in:
Marcin S
2024-01-22 11:29:13 +01:00
committed by GitHub
parent e2caa813bf
commit d53534c49e
22 changed files with 366 additions and 49 deletions
@@ -77,6 +77,7 @@ cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system
cumulus-pallet-session-benchmarking = { path = "../../../../pallets/session-benchmarking", default-features = false }
cumulus-pallet-xcm = { path = "../../../../pallets/xcm", default-features = false }
cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", default-features = false, features = ["bridging"] }
cumulus-primitives-aura = { path = "../../../../primitives/aura", default-features = false }
cumulus-primitives-core = { path = "../../../../primitives/core", default-features = false }
cumulus-primitives-utility = { path = "../../../../primitives/utility", default-features = false }
pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false }
@@ -188,6 +189,7 @@ std = [
"cumulus-pallet-session-benchmarking/std",
"cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-primitives-aura/std",
"cumulus-primitives-core/std",
"cumulus-primitives-utility/std",
"frame-benchmarking?/std",
@@ -33,7 +33,7 @@ use assets_common::{
matching::{FromNetwork, FromSiblingParachain},
AssetIdForTrustBackedAssetsConvert,
};
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::AggregateMessageOrigin;
use parachains_common::rococo::snowbridge::EthereumNetwork;
use sp_api::impl_runtime_apis;
@@ -62,7 +62,7 @@ use frame_support::{
ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter,
TransformOrigin,
},
weights::{ConstantMultiplier, Weight},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight},
BoundedVec, PalletId,
};
use frame_system::{
@@ -71,14 +71,13 @@ use frame_system::{
};
use pallet_asset_conversion_tx_payment::AssetConversionAdapter;
use pallet_nfts::PalletFeatures;
pub use parachains_common as common;
use parachains_common::{
impls::DealWithFees,
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
rococo::{consensus::*, currency::*, fee::WeightToFee},
AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, CollectionId, Hash,
Header, ItemId, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS,
MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
NORMAL_DISPATCH_RATIO,
};
use sp_runtime::{Perbill, RuntimeDebug};
use xcm_config::{
@@ -141,6 +140,28 @@ pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}
/// We allow for 2 seconds of compute with a 6 second average block.
const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
);
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
/// into the relay chain.
const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
/// How many parachain blocks are processed by the relay chain per parent. Limits the
/// number of blocks authored per slot.
const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// This determines the average expected block time that we are targeting.
/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
/// up by `pallet_aura` to implement `fn slot_duration()`.
///
/// Change this to adjust the block time.
pub const MILLISECS_PER_BLOCK: u64 = 6000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
@@ -189,6 +210,9 @@ impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
#[cfg(feature = "experimental")]
type MinimumPeriod = ConstU64<0>;
#[cfg(not(feature = "experimental"))]
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
}
@@ -630,15 +654,17 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type OutboundXcmpMessageSource = XcmpQueue;
type XcmpMessageHandler = XcmpQueue;
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases;
type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Runtime,
RELAY_CHAIN_SLOT_DURATION_MILLIS,
BLOCK_PROCESSING_VELOCITY,
UNINCLUDED_SEGMENT_CAPACITY,
>;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
}
type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Runtime,
RELAY_CHAIN_SLOT_DURATION_MILLIS,
BLOCK_PROCESSING_VELOCITY,
UNINCLUDED_SEGMENT_CAPACITY,
>;
parameter_types! {
pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block;
}
@@ -722,9 +748,9 @@ impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
type MaxAuthorities = ConstU32<100_000>;
type AllowMultipleBlocksPerSlot = ConstBool<false>;
type AllowMultipleBlocksPerSlot = ConstBool<true>;
#[cfg(feature = "experimental")]
type SlotDuration = pallet_aura::MinimumPeriodTimesTwo<Self>;
type SlotDuration = ConstU64<SLOT_DURATION>;
}
parameter_types! {
@@ -1067,7 +1093,7 @@ mod benches {
impl_runtime_apis! {
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
}
fn authorities() -> Vec<AuraId> {
@@ -1075,6 +1101,15 @@ impl_runtime_apis! {
}
}
impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
fn can_build_upon(
included_hash: <Block as BlockT>::Hash,
slot: cumulus_primitives_aura::Slot,
) -> bool {
ConsensusHook::can_build_upon(included_hash, slot)
}
}
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
@@ -28,10 +28,11 @@ use asset_hub_rococo_runtime::{
AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection,
ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase,
MetadataDepositPerByte, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, SessionKeys,
ToWestendXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue,
ToWestendXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue, SLOT_DURATION,
};
use asset_test_utils::{
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder,
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys,
ExtBuilder, SlotDurations,
};
use codec::{Decode, Encode};
use cumulus_primitives_utility::ChargeWeightInFungibles;
@@ -46,9 +47,10 @@ use frame_support::{
weights::{Weight, WeightToFee as WeightToFeeT},
};
use parachains_common::{
rococo::{currency::UNITS, fee::WeightToFee},
rococo::{consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, currency::UNITS, fee::WeightToFee},
AccountId, AssetIdForTrustBackedAssets, AuraId, Balance,
};
use sp_consensus_aura::SlotDuration;
use sp_runtime::traits::MaybeEquivalence;
use std::convert::Into;
use xcm::latest::prelude::{Assets as XcmAssets, *};
@@ -78,6 +80,13 @@ fn collator_session_keys() -> CollatorSessionKeys<Runtime> {
CollatorSessionKeys::default().add(collator_session_key(ALICE))
}
fn slot_durations() -> SlotDurations {
SlotDurations {
relay: SlotDuration::from_millis(RELAY_CHAIN_SLOT_DURATION_MILLIS.into()),
para: SlotDuration::from_millis(SLOT_DURATION),
}
}
#[test]
fn test_buy_and_refund_weight_in_native() {
ExtBuilder::<Runtime>::default()
@@ -892,6 +901,7 @@ asset_test_utils::include_teleports_for_native_asset_works!(
WeightToFee,
ParachainSystem,
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
@@ -912,6 +922,7 @@ asset_test_utils::include_teleports_for_foreign_assets_works!(
ForeignCreatorsSovereignAccountOf,
ForeignAssetsInstance,
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
@@ -1023,6 +1034,7 @@ fn limited_reserve_transfer_assets_for_native_asset_over_bridge_works(
LocationToAccountId,
>(
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
AccountId::from(ALICE),
Box::new(|runtime_event_encoded: Vec<u8>| {
@@ -1194,6 +1206,7 @@ mod asset_hub_rococo_tests {
LocationToAccountId,
>(
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
AccountId::from(ALICE),
Box::new(|runtime_event_encoded: Vec<u8>| {
@@ -55,7 +55,6 @@ use frame_system::{
use pallet_asset_conversion_tx_payment::AssetConversionAdapter;
use pallet_nfts::{DestroyWitness, PalletFeatures};
use pallet_xcm::EnsureXcm;
pub use parachains_common as common;
use parachains_common::{
impls::DealWithFees,
message_queue::*,
@@ -32,7 +32,8 @@ use asset_hub_westend_runtime::{
};
pub use asset_hub_westend_runtime::{AssetConversion, AssetDeposit, CollatorSelection, System};
use asset_test_utils::{
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder,
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys,
ExtBuilder, SlotDurations,
};
use codec::{Decode, Encode};
use cumulus_primitives_utility::ChargeWeightInFungibles;
@@ -47,9 +48,10 @@ use frame_support::{
weights::{Weight, WeightToFee as WeightToFeeT},
};
use parachains_common::{
westend::{currency::UNITS, fee::WeightToFee},
AccountId, AssetIdForTrustBackedAssets, AuraId, Balance,
westend::{consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, currency::UNITS, fee::WeightToFee},
AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, SLOT_DURATION,
};
use sp_consensus_aura::SlotDuration;
use sp_runtime::traits::MaybeEquivalence;
use std::convert::Into;
use xcm::latest::prelude::{Assets as XcmAssets, *};
@@ -79,6 +81,13 @@ fn collator_session_keys() -> CollatorSessionKeys<Runtime> {
CollatorSessionKeys::default().add(collator_session_key(ALICE))
}
fn slot_durations() -> SlotDurations {
SlotDurations {
relay: SlotDuration::from_millis(RELAY_CHAIN_SLOT_DURATION_MILLIS.into()),
para: SlotDuration::from_millis(SLOT_DURATION),
}
}
#[test]
fn test_buy_and_refund_weight_in_native() {
ExtBuilder::<Runtime>::default()
@@ -895,6 +904,7 @@ asset_test_utils::include_teleports_for_native_asset_works!(
WeightToFee,
ParachainSystem,
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
@@ -915,6 +925,7 @@ asset_test_utils::include_teleports_for_foreign_assets_works!(
ForeignCreatorsSovereignAccountOf,
ForeignAssetsInstance,
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
@@ -1041,6 +1052,7 @@ fn limited_reserve_transfer_assets_for_native_asset_to_asset_hub_rococo_works()
LocationToAccountId,
>(
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
AccountId::from(ALICE),
Box::new(|runtime_event_encoded: Vec<u8>| {
@@ -1208,6 +1220,7 @@ fn reserve_transfer_native_asset_to_non_teleport_para_works() {
LocationToAccountId,
>(
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
AccountId::from(ALICE),
Box::new(|runtime_event_encoded: Vec<u8>| {
@@ -31,7 +31,7 @@ use frame_system::pallet_prelude::BlockNumberFor;
use parachains_common::{AccountId, Balance};
use parachains_runtimes_test_utils::{
assert_metadata, assert_total, mock_open_hrmp_channel, AccountIdOf, BalanceOf,
CollatorSessionKeys, ExtBuilder, ValidatorIdOf, XcmReceivedFrom,
CollatorSessionKeys, ExtBuilder, SlotDurations, ValidatorIdOf, XcmReceivedFrom,
};
use sp_runtime::{
traits::{MaybeEquivalence, StaticLookup, Zero},
@@ -57,6 +57,7 @@ pub fn teleports_for_native_asset_works<
HrmpChannelOpener,
>(
collator_session_keys: CollatorSessionKeys<Runtime>,
slot_durations: SlotDurations,
existential_deposit: BalanceOf<Runtime>,
target_account: AccountIdOf<Runtime>,
unwrap_pallet_xcm_event: Box<dyn Fn(Vec<u8>) -> Option<pallet_xcm::Event<Runtime>>>,
@@ -205,6 +206,7 @@ pub fn teleports_for_native_asset_works<
None,
included_head.clone(),
&alice,
&slot_durations,
));
// check balances
@@ -257,6 +259,7 @@ pub fn teleports_for_native_asset_works<
Some((runtime_para_id, other_para_id)),
included_head,
&alice,
&slot_durations,
),
Err(DispatchError::Module(sp_runtime::ModuleError {
index: 31,
@@ -288,6 +291,7 @@ macro_rules! include_teleports_for_native_asset_works(
$weight_to_fee:path,
$hrmp_channel_opener:path,
$collator_session_key:expr,
$slot_durations:expr,
$existential_deposit:expr,
$unwrap_pallet_xcm_event:expr,
$runtime_para_id:expr
@@ -306,6 +310,7 @@ macro_rules! include_teleports_for_native_asset_works(
$hrmp_channel_opener
>(
$collator_session_key,
$slot_durations,
$existential_deposit,
target_account,
$unwrap_pallet_xcm_event,
@@ -328,6 +333,7 @@ pub fn teleports_for_foreign_assets_works<
ForeignAssetsPalletInstance,
>(
collator_session_keys: CollatorSessionKeys<Runtime>,
slot_durations: SlotDurations,
target_account: AccountIdOf<Runtime>,
existential_deposit: BalanceOf<Runtime>,
asset_owner: AccountIdOf<Runtime>,
@@ -592,6 +598,7 @@ pub fn teleports_for_foreign_assets_works<
Some((runtime_para_id, foreign_para_id)),
included_head,
&alice,
&slot_durations,
));
// check balances
@@ -644,6 +651,7 @@ macro_rules! include_teleports_for_foreign_assets_works(
$sovereign_account_of:path,
$assets_pallet_instance:path,
$collator_session_key:expr,
$slot_durations:expr,
$existential_deposit:expr,
$unwrap_pallet_xcm_event:expr,
$unwrap_xcmp_queue_event:expr
@@ -666,6 +674,7 @@ macro_rules! include_teleports_for_foreign_assets_works(
$assets_pallet_instance
>(
$collator_session_key,
$slot_durations,
target_account,
$existential_deposit,
asset_owner,
@@ -1397,6 +1406,7 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works<
LocationToAccountId,
>(
collator_session_keys: CollatorSessionKeys<Runtime>,
slot_durations: SlotDurations,
existential_deposit: BalanceOf<Runtime>,
alice_account: AccountIdOf<Runtime>,
unwrap_pallet_xcm_event: Box<dyn Fn(Vec<u8>) -> Option<pallet_xcm::Event<Runtime>>>,
@@ -1470,6 +1480,7 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works<
other_para_id.into(),
included_head,
&alice,
&slot_durations,
);
// we calculate exact delivery fees _after_ sending the message by weighing the sent
@@ -27,7 +27,7 @@ use frame_system::pallet_prelude::BlockNumberFor;
use parachains_common::{AccountId, Balance};
use parachains_runtimes_test_utils::{
mock_open_hrmp_channel, AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, RuntimeHelper,
ValidatorIdOf, XcmReceivedFrom,
SlotDurations, ValidatorIdOf, XcmReceivedFrom,
};
use sp_runtime::{traits::StaticLookup, Saturating};
use sp_std::ops::Mul;
@@ -52,6 +52,7 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works<
LocationToAccountId,
>(
collator_session_keys: CollatorSessionKeys<Runtime>,
slot_durations: SlotDurations,
existential_deposit: BalanceOf<Runtime>,
alice_account: AccountIdOf<Runtime>,
unwrap_pallet_xcm_event: Box<dyn Fn(Vec<u8>) -> Option<pallet_xcm::Event<Runtime>>>,
@@ -125,6 +126,7 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works<
local_bridge_hub_para_id.into(),
included_head,
&alice,
&slot_durations,
);
// we calculate exact delivery fees _after_ sending the message by weighing the sent