Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable async backing on all testnet system chains #2949

Merged
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
277268d
PHASE 1!
mrcnski Dec 28, 2023
8876b0e
PHASE 2!
mrcnski Dec 29, 2023
d386c02
PHASE 3!
mrcnski Dec 29, 2023
c12c82a
Fix MAXIMUM_BLOCK_WEIGHT
mrcnski Dec 29, 2023
f1b811d
Parametrize SlotDurations for system parachain tests (because of `moc…
bkontur Jan 8, 2024
5350101
Add start_asset_hub_lookahead_node
mrcnski Jan 11, 2024
c07d887
Merge remote-tracking branch 'refs/remotes/origin/mrcnski/async-backi…
mrcnski Jan 11, 2024
1f07f6a
Address a couple comments, remove some TODOs
mrcnski Jan 12, 2024
e7b57b8
Add CollationGenerationMessage::Reinitialize
mrcnski Jan 15, 2024
1ee2ced
Fix CI
mrcnski Jan 15, 2024
25073e9
Add prdoc
mrcnski Jan 15, 2024
bc48f64
Fix CI (for real)
mrcnski Jan 15, 2024
d4894cf
Merge branch 'master' into mrcnski/async-backing-on-asset-hub-rococo
mrcnski Jan 16, 2024
ed50660
[WIP]
mrcnski Jan 16, 2024
fbd58e4
Merge branch 'mrcnski/async-backing-on-asset-hub-rococo' into mrcnski…
mrcnski Jan 16, 2024
0672994
Fix CI (again)
mrcnski Jan 16, 2024
ff9538f
Enable async backing on all testnet system chains
mrcnski Jan 16, 2024
23bb3bc
Enable async backing on contracts-rococo
mrcnski Jan 16, 2024
7b0ec8b
Fix CI
mrcnski Jan 17, 2024
42f5d1b
Introduce `BlockWeightsForAsyncBacking` and `MAXIMUM_BLOCK_WEIGHT_FOR…
bkontur Jan 18, 2024
c6e85bd
Update polkadot/node/subsystem-types/src/messages.rs
mrcnski Jan 18, 2024
6b767f0
Update cumulus/polkadot-parachain/src/service.rs
mrcnski Jan 18, 2024
57442d7
Update cumulus/polkadot-parachain/src/command.rs
mrcnski Jan 18, 2024
f5cd6fa
Remove some pub exports
mrcnski Jan 18, 2024
eb79b66
Fix CI (definitely for real)
mrcnski Jan 18, 2024
deea060
Fix re-exports
mrcnski Jan 19, 2024
3388f5f
Merge branch 'master' into mrcnski/async-backing-on-asset-hub-rococo
mrcnski Jan 19, 2024
9ff3316
fmt
mrcnski Jan 19, 2024
8f79188
Merge branch 'master' into mrcnski/async-backing-on-asset-hub-rococo
mrcnski Jan 21, 2024
359968b
Bump BLOCK_PROCESSING_VELOCITY
mrcnski Jan 21, 2024
a34c909
Merge branch 'mrcnski/async-backing-on-asset-hub-rococo' into mrcnski…
mrcnski Jan 21, 2024
7591656
Fix compile errors after merge
mrcnski Jan 21, 2024
9c133d0
Merge branch 'master' into mrcnski/enable-async-backing-on-testnet-sy…
mrcnski Jan 22, 2024
1c20f57
Merge branch 'master' into mrcnski/enable-async-backing-on-testnet-sy…
mrcnski Jan 22, 2024
424a19e
Merge remote-tracking branch 'refs/remotes/origin/mrcnski/enable-asyn…
mrcnski Jan 22, 2024
b018a38
Add prdoc!
mrcnski Jan 22, 2024
efe15ff
Fix velocity constant
mrcnski Jan 23, 2024
ac8fcb2
Merge branch 'master' into mrcnski/enable-async-backing-on-testnet-sy…
mrcnski Jan 23, 2024
f758b5a
Fix PR description
s0me0ne-unkn0wn Jan 28, 2024
7ea5306
Merge branch 'master' into mrcnski/enable-async-backing-on-testnet-sy…
s0me0ne-unkn0wn Jan 28, 2024
e1d812f
Merge branch 'master' into mrcnski/enable-async-backing-on-testnet-sy…
s0me0ne-unkn0wn Jan 29, 2024
077e377
Merge remote-tracking branch 'origin/master' into mrcnski/enable-asyn…
s0me0ne-unkn0wn Feb 1, 2024
6de532d
Move constants to, well, constants
s0me0ne-unkn0wn Feb 1, 2024
7834080
Remove stale comment
s0me0ne-unkn0wn Feb 1, 2024
0bc314f
Merge remote-tracking branch 'origin/master' into mrcnski/enable-asyn…
s0me0ne-unkn0wn Feb 1, 2024
a12ee76
add missing doc
svyatonik Feb 1, 2024
f2dba7a
Remove stale code
s0me0ne-unkn0wn Feb 1, 2024
f5c060d
Merge remote-tracking branch 'origin/mrcnski/enable-async-backing-on-…
s0me0ne-unkn0wn Feb 1, 2024
71aef4a
Move time constants
s0me0ne-unkn0wn Feb 1, 2024
771602e
Fix tests
s0me0ne-unkn0wn Feb 1, 2024
9de5256
Fix feature propagation
s0me0ne-unkn0wn Feb 1, 2024
ab0097b
Fix benchmarking?
s0me0ne-unkn0wn Feb 1, 2024
5db7a7e
Fix coretime smoke test
bkchr Feb 2, 2024
42ac088
Ensure we return from the script
bkchr Feb 2, 2024
8bf9c79
Fix `new_session` benchmark in `pallet_collator_selection` (#3189)
georgepisaltu Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions bridges/primitives/chain-bridge-hub-cumulus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(constants::WEIGHT_REF_TI
.saturating_div(2)
.set_proof_size(polkadot_primitives::MAX_POV_SIZE as u64);

/// We allow for 2 seconds of compute with a 6 second average block.
const MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING: Weight = Weight::from_parts(
constants::WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
polkadot_primitives::MAX_POV_SIZE as u64,
);
bkchr marked this conversation as resolved.
Show resolved Hide resolved

/// All cumulus bridge hubs assume that about 5 percent of the block weight is consumed by
/// `on_initialize` handlers. This is used to limit the maximal weight of a single extrinsic.
///
Expand Down Expand Up @@ -96,6 +102,26 @@ parameter_types! {
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();

/// Weight limit of the Cumulus-based bridge hub blocks when async backing is enabled.
pub BlockWeightsForAsyncBacking: limits::BlockWeights = limits::BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING);
// Operational transactions have an extra reserved space, so that they
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING,
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
}

/// Public key of the chain account that may be used to verify signatures.
Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/chain-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Chain for BridgeHubRococo {
}

fn max_extrinsic_weight() -> Weight {
BlockWeights::get()
BlockWeightsForAsyncBacking::get()
.get(DispatchClass::Normal)
.max_extrinsic
.unwrap_or(Weight::MAX)
Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/chain-bridge-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Chain for BridgeHubWestend {
}

fn max_extrinsic_weight() -> Weight {
BlockWeights::get()
BlockWeightsForAsyncBacking::get()
.get(DispatchClass::Normal)
.max_extrinsic
.unwrap_or(Weight::MAX)
Expand Down
24 changes: 1 addition & 23 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use frame_support::{
ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter,
TransformOrigin,
},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight},
weights::{ConstantMultiplier, Weight},
BoundedVec, PalletId,
};
use frame_system::{
Expand Down Expand Up @@ -140,28 +140,6 @@ 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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use asset_hub_rococo_runtime::{
AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection,
ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase,
MetadataDepositPerByte, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, SessionKeys,
ToWestendXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue, SLOT_DURATION,
ToWestendXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue,
};
use asset_test_utils::{
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys,
Expand All @@ -50,9 +50,7 @@ use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance}
use sp_consensus_aura::SlotDuration;
use sp_runtime::traits::MaybeEquivalence;
use std::convert::Into;
use testnet_parachains_constants::rococo::{
consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, currency::UNITS, fee::WeightToFee,
};
use testnet_parachains_constants::rococo::{consensus::*, currency::UNITS, fee::WeightToFee};
use xcm::latest::prelude::{Assets as XcmAssets, *};
use xcm_builder::V4V3LocationConverter;
use xcm_executor::traits::{JustTry, WeightTrader};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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 }
Expand Down Expand Up @@ -175,6 +176,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",
Expand Down
42 changes: 28 additions & 14 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use assets_common::{
AssetIdForTrustBackedAssetsConvert,
};
use codec::{Decode, Encode, MaxEncodedLen};
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use frame_support::{
construct_runtime, derive_impl,
Expand All @@ -58,7 +58,7 @@ use pallet_xcm::EnsureXcm;
use parachains_common::{
impls::DealWithFees, message_queue::*, 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,
DAYS, HOURS, NORMAL_DISPATCH_RATIO,
};
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
Expand Down Expand Up @@ -171,6 +171,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>;
}
Expand Down Expand Up @@ -604,15 +607,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,
>;

impl parachain_info::Config for Runtime {}

parameter_types! {
Expand Down Expand Up @@ -697,9 +702,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! {
Expand Down Expand Up @@ -980,7 +985,7 @@ impl frame_support::traits::OnRuntimeUpgrade for DeleteUndecodableStorage {
},
Err(e) => {
log::error!("Failed to destroy undecodable NFT item: {:?}", e);
return <Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, writes)
return <Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, writes);
},
}

Expand All @@ -992,7 +997,7 @@ impl frame_support::traits::OnRuntimeUpgrade for DeleteUndecodableStorage {
},
Err(e) => {
log::error!("Failed to destroy undecodable NFT item: {:?}", e);
return <Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, writes)
return <Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, writes);
},
}

Expand Down Expand Up @@ -1090,14 +1095,23 @@ 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> {
Aura::authorities().into_inner()
}
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ cumulus-pallet-xcm = { path = "../../../../pallets/xcm", default-features = fals
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 }
Expand Down Expand Up @@ -153,6 +154,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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ mod tests {
>(AssertCompleteBridgeConstants {
this_chain_constants: AssertChainConstants {
block_length: bp_bridge_hub_rococo::BlockLength::get(),
block_weights: bp_bridge_hub_rococo::BlockWeights::get(),
block_weights: bp_bridge_hub_rococo::BlockWeightsForAsyncBacking::get(),
},
messages_pallet_constants: AssertBridgeMessagesPalletConstants {
max_unrewarded_relayers_in_bridged_confirmation_tx:
Expand Down
Loading
Loading