From 17c9611f7309ba89b4621c9d354fa8f2cae07e59 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Wed, 17 Jul 2024 17:37:37 +0200 Subject: [PATCH 01/11] update client/runtime --- Cargo.lock | 4 ++ Cargo.toml | 1 + bin/collator/Cargo.toml | 1 + bin/collator/src/parachain/service.rs | 48 +++++++++++------ runtime/astar/Cargo.toml | 6 ++- runtime/astar/src/lib.rs | 69 ++++++++++++------------ runtime/local/Cargo.toml | 2 + runtime/local/src/lib.rs | 13 ++--- runtime/shibuya/Cargo.toml | 6 ++- runtime/shibuya/src/lib.rs | 75 +++++++++++++-------------- runtime/shiden/Cargo.toml | 6 ++- runtime/shiden/src/lib.rs | 74 +++++++++++++------------- 12 files changed, 169 insertions(+), 136 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51dda062d9..b5aef43733 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -623,6 +623,7 @@ dependencies = [ "cumulus-client-consensus-relay-chain", "cumulus-client-network", "cumulus-client-service", + "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", "cumulus-relay-chain-inprocess-interface", @@ -761,6 +762,7 @@ dependencies = [ "cumulus-pallet-parachain-system", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", + "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", @@ -14224,6 +14226,7 @@ dependencies = [ "cumulus-pallet-parachain-system", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", + "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", @@ -14345,6 +14348,7 @@ dependencies = [ "cumulus-pallet-parachain-system", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", + "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", diff --git a/Cargo.toml b/Cargo.toml index b2c464e763..aab6e1d73e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -227,6 +227,7 @@ cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk", cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } +cumulus-primitives-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } cumulus-primitives-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } diff --git a/bin/collator/Cargo.toml b/bin/collator/Cargo.toml index f9838a2871..242a971c8d 100644 --- a/bin/collator/Cargo.toml +++ b/bin/collator/Cargo.toml @@ -116,6 +116,7 @@ cumulus-client-consensus-proposer = { workspace = true } cumulus-client-consensus-relay-chain = { workspace = true } cumulus-client-network = { workspace = true } cumulus-client-service = { workspace = true } +cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true, features = ["std"] } cumulus-primitives-parachain-inherent = { workspace = true } cumulus-relay-chain-inprocess-interface = { workspace = true } diff --git a/bin/collator/src/parachain/service.rs b/bin/collator/src/parachain/service.rs index fecd80e122..86d78b4e0e 100644 --- a/bin/collator/src/parachain/service.rs +++ b/bin/collator/src/parachain/service.rs @@ -20,21 +20,24 @@ use astar_primitives::*; use cumulus_client_cli::CollatorOptions; -use cumulus_client_consensus_aura::collators::basic as basic_aura; +use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams}; use cumulus_client_consensus_common::ParachainBlockImport; use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier; use cumulus_client_service::{ prepare_node_config, start_relay_chain_tasks, BuildNetworkParams, DARecoveryProfile, StartRelayChainTasksParams, }; -use cumulus_primitives_core::ParaId; +use cumulus_primitives_aura::AuraUnincludedSegmentApi; +use cumulus_primitives_core::{ + relay_chain::{CollatorPair, ValidationCode}, + ParaId, +}; use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain; use cumulus_relay_chain_interface::{RelayChainInterface, RelayChainResult}; use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node_with_rpc; use fc_consensus::FrontierBlockImport; use fc_rpc_core::types::{FeeHistoryCache, FilterPool}; use futures::StreamExt; -use polkadot_service::CollatorPair; use sc_client_api::BlockchainEvents; use sc_consensus::{import_queue::BasicQueue, ImportQueue}; use sc_executor::NativeElseWasmExecutor; @@ -351,6 +354,7 @@ where ) -> Result, sc_service::Error>, SC: FnOnce( Arc>>, + Arc>, ParachainBlockImport< Block, FrontierBlockImport< @@ -562,6 +566,7 @@ where if is_authority { start_consensus( client.clone(), + backend.clone(), parachain_block_import, prometheus_registry.as_ref(), telemetry.map(|t| t.handle()), @@ -1066,6 +1071,7 @@ where /// Start collating with the `shell` runtime while waiting for an upgrade to an Aura compatible runtime. fn start_aura_consensus_fallback( client: Arc>>, + backend: Arc>, parachain_block_import: ParachainBlockImport< Block, FrontierBlockImport< @@ -1104,6 +1110,7 @@ where + sp_block_builder::BlockBuilder + fp_rpc::EthereumRuntimeRPCApi + AuraApi + + AuraUnincludedSegmentApi + cumulus_primitives_core::CollectCollationInfo, sc_client_api::StateBackendFor, Block>: sc_client_api::StateBackend, @@ -1171,9 +1178,6 @@ where } // Move to Aura consensus. - let slot_duration = - cumulus_client_consensus_aura::slot_duration(&*client).expect("aura is present; qed"); - let announce_block = { let sync_service = sync_oracle.clone(); Arc::new(move |hash, data| sync_service.announce_block(hash, data)) @@ -1186,23 +1190,28 @@ where client.clone(), ); - basic_aura::run::(basic_aura::Params { + aura::run::(AuraParams { create_inherent_data_providers: move |_, ()| async move { Ok(()) }, block_import: parachain_block_import.clone(), para_client: client.clone(), + para_backend: backend, relay_client: relay_chain_interface.clone(), + code_hash_provider: move |block_hash| { + client + .code_at(block_hash) + .ok() + .map(|c| ValidationCode::from(c).hash()) + }, sync_oracle: sync_oracle.clone(), keystore, collator_key, para_id, overseer_handle, - slot_duration, relay_chain_slot_duration: Duration::from_secs(6), proposer: cumulus_client_consensus_proposer::Proposer::new(proposer_factory), collator_service, - // We got around 500ms for proposing - authoring_duration: Duration::from_millis(500), - collation_request_receiver: Some(request_stream), + authoring_duration: Duration::from_millis(2000), + reinitialize: true, }) .await }); @@ -1215,6 +1224,7 @@ where fn start_aura_consensus( client: Arc>>, + backend: Arc>, parachain_block_import: ParachainBlockImport< Block, FrontierBlockImport< @@ -1253,6 +1263,7 @@ where + sp_block_builder::BlockBuilder + fp_rpc::EthereumRuntimeRPCApi + AuraApi + + AuraUnincludedSegmentApi + cumulus_primitives_core::CollectCollationInfo, sc_client_api::StateBackendFor, Block>: sc_client_api::StateBackend, @@ -1287,23 +1298,28 @@ where client.clone(), ); - let fut = basic_aura::run::(basic_aura::Params { + let fut = aura::run::(AuraParams { create_inherent_data_providers: move |_, ()| async move { Ok(()) }, block_import: parachain_block_import.clone(), para_client: client.clone(), + para_backend: backend, relay_client: relay_chain_interface.clone(), + code_hash_provider: move |block_hash| { + client + .code_at(block_hash) + .ok() + .map(|c| ValidationCode::from(c).hash()) + }, sync_oracle: sync_oracle.clone(), keystore, collator_key, para_id, overseer_handle, - slot_duration: cumulus_client_consensus_aura::slot_duration(&*client)?, relay_chain_slot_duration: Duration::from_secs(6), proposer: cumulus_client_consensus_proposer::Proposer::new(proposer_factory), collator_service, - // We got around 500ms for proposing - authoring_duration: Duration::from_millis(500), - collation_request_receiver: None, + authoring_duration: Duration::from_millis(2000), + reinitialize: false, }); task_manager diff --git a/runtime/astar/Cargo.toml b/runtime/astar/Cargo.toml index 4b823f9646..6029cd4b2f 100644 --- a/runtime/astar/Cargo.toml +++ b/runtime/astar/Cargo.toml @@ -73,9 +73,10 @@ pallet-xcm-benchmarks = { workspace = true, optional = true } # cumulus dependencies cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-dmp-queue = { workspace = true } -cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true, features = ["parameterized-consensus-hook"] } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } @@ -203,6 +204,7 @@ std = [ "polkadot-parachain/std", "polkadot-primitives/std", "polkadot-runtime-common/std", + "cumulus-primitives-aura/std", "cumulus-primitives-core/std", "cumulus-primitives-utility/std", "cumulus-primitives-timestamp/std", @@ -339,6 +341,8 @@ evm-tracing = [ "moonbeam-rpc-primitives-txpool", ] +experimental = ["pallet-aura/experimental"] + # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. metadata-hash = ["substrate-wasm-builder?/metadata-hash"] diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index b860540ab9..3f818c0a6d 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -22,7 +22,6 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] -use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use cumulus_primitives_core::AggregateMessageOrigin; use frame_support::{ construct_runtime, @@ -30,8 +29,8 @@ use frame_support::{ genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ - AsEnsureOriginWithArg, ConstBool, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance, - InstanceFilter, Nothing, OnFinalize, OnUnbalanced, Randomness, WithdrawReasons, + AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, Contains, Currency, FindAuthor, Get, + Imbalance, InstanceFilter, Nothing, OnFinalize, OnUnbalanced, Randomness, WithdrawReasons, }, weights::{ constants::{ @@ -131,11 +130,21 @@ pub const fn contracts_deposit(items: u32, bytes: u32) -> Balance { /// Change this to adjust the block time. pub const MILLISECS_PER_BLOCK: u64 = 12000; +pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; // Time is measured by number of blocks. pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); pub const HOURS: BlockNumber = MINUTES * 60; pub const DAYS: BlockNumber = HOURS * 24; +/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the +/// relay chain. +pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; +/// How many parachain blocks are processed by the relay chain per parent. Limits the number of +/// blocks authored per slot. +pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; +/// Relay chain slot duration, in milliseconds. +pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; + // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); @@ -461,23 +470,28 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedDmpWeight = ReservedDmpWeight; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; - type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type CheckAssociatedRelayNumber = + cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; + type ConsensusHook = ConsensusHook; type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } -impl parachain_info::Config for Runtime {} +type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< + Runtime, + RELAY_CHAIN_SLOT_DURATION_MILLIS, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, +>; -parameter_types! { - pub const MaxAuthorities: u32 = 250; -} +impl parachain_info::Config for Runtime {} impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); - type MaxAuthorities = MaxAuthorities; - // Should be only enabled (`true`) when async backing is enabled - // otherwise set to `false` + type MaxAuthorities = ConstU32<250>; type AllowMultipleBlocksPerSlot = ConstBool; + #[cfg(feature = "experimental")] + type SlotDuration = ConstU64; } impl cumulus_pallet_aura_ext::Config for Runtime {} @@ -1387,7 +1401,7 @@ impl_runtime_apis! { impl sp_consensus_aura::AuraApi 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 { @@ -1395,6 +1409,15 @@ impl_runtime_apis! { } } + impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { + fn can_build_upon( + included_hash: ::Hash, + slot: cumulus_primitives_aura::Slot, + ) -> bool { + ConsensusHook::can_build_upon(included_hash, slot) + } + } + impl sp_block_builder::BlockBuilder for Runtime { fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { Executive::apply_extrinsic(extrinsic) @@ -2185,29 +2208,7 @@ impl_runtime_apis! { } } -struct CheckInherents; - -impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { - fn check_inherents( - block: &Block, - relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, - ) -> sp_inherents::CheckInherentsResult { - let relay_chain_slot = relay_state_proof - .read_slot() - .expect("Could not read the relay chain slot from the proof"); - let inherent_data = - cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( - relay_chain_slot, - sp_std::time::Duration::from_secs(6), - ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); - inherent_data.check_extrinsics(block) - } -} - cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, - CheckInherents = CheckInherents, } diff --git a/runtime/local/Cargo.toml b/runtime/local/Cargo.toml index 41fad4bb88..91b3cd388a 100644 --- a/runtime/local/Cargo.toml +++ b/runtime/local/Cargo.toml @@ -276,6 +276,8 @@ evm-tracing = [ "moonbeam-rpc-primitives-txpool", ] +experimental = ["pallet-aura/experimental"] + # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. metadata-hash = ["substrate-wasm-builder?/metadata-hash"] diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index 23558e9095..4bd75abf2e 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -265,16 +265,13 @@ impl frame_system::Config for Runtime { type PostTransactions = (); } -parameter_types! { - pub const MaxAuthorities: u32 = 50; - pub const AllowMultipleBlocksPerSlot: bool = false; -} - impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); type MaxAuthorities = ConstU32<50>; - type AllowMultipleBlocksPerSlot = AllowMultipleBlocksPerSlot; + type AllowMultipleBlocksPerSlot = ConstBool; + #[cfg(feature = "experimental")] + type SlotDuration = ConstU64; } impl pallet_grandpa::Config for Runtime { @@ -284,7 +281,7 @@ impl pallet_grandpa::Config for Runtime { type EquivocationReportSystem = (); type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = ConstU32<50>; type MaxSetIdSessionEntries = ConstU64<0>; type MaxNominators = ConstU32<0>; } @@ -1371,7 +1368,7 @@ impl_runtime_apis! { impl sp_consensus_aura::AuraApi 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 { diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index 0b89a19b23..6277d7fe28 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -79,9 +79,10 @@ pallet-vesting = { workspace = true } # cumulus dependencies cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-dmp-queue = { workspace = true } -cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true, features = ["parameterized-consensus-hook"] } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } @@ -233,6 +234,7 @@ std = [ "polkadot-parachain/std", "polkadot-primitives/std", "polkadot-runtime-common/std", + "cumulus-primitives-aura/std", "cumulus-primitives-core/std", "cumulus-primitives-utility/std", "cumulus-primitives-timestamp/std", @@ -386,6 +388,8 @@ evm-tracing = [ "moonbeam-rpc-primitives-txpool", ] +experimental = ["pallet-aura/experimental"] + # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. metadata-hash = ["substrate-wasm-builder?/metadata-hash"] diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 47b925d259..b575d42ab8 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -22,7 +22,6 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 512. #![recursion_limit = "512"] -use cumulus_pallet_parachain_system::AnyRelayNumber; use cumulus_primitives_core::AggregateMessageOrigin; use frame_support::{ construct_runtime, @@ -32,9 +31,9 @@ use frame_support::{ traits::{ fungible::HoldConsideration, tokens::{PayFromAccount, UnityAssetBalanceConversion}, - AsEnsureOriginWithArg, ConstU128, ConstU32, Contains, Currency, EqualPrivilegeOnly, - FindAuthor, Get, Imbalance, InstanceFilter, LinearStoragePrice, Nothing, OnFinalize, - OnUnbalanced, WithdrawReasons, + AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, Contains, Currency, + EqualPrivilegeOnly, FindAuthor, Get, Imbalance, InstanceFilter, LinearStoragePrice, + Nothing, OnFinalize, OnUnbalanced, WithdrawReasons, }, weights::{ constants::{ @@ -58,7 +57,7 @@ use pallet_transaction_payment::{ use parity_scale_codec::{Compact, Decode, Encode, MaxEncodedLen}; use polkadot_runtime_common::BlockHashCount; use sp_api::impl_runtime_apis; -use sp_core::{ConstBool, OpaqueMetadata, H160, H256, U256}; +use sp_core::{OpaqueMetadata, H160, H256, U256}; use sp_inherents::{CheckInherentsResult, InherentData}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, @@ -144,11 +143,21 @@ pub const fn contracts_deposit(items: u32, bytes: u32) -> Balance { /// Change this to adjust the block time. pub const MILLISECS_PER_BLOCK: u64 = 12000; +pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; // Time is measured by number of blocks. pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); pub const HOURS: BlockNumber = MINUTES * 60; pub const DAYS: BlockNumber = HOURS * 24; +/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the +/// relay chain. +pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; +/// How many parachain blocks are processed by the relay chain per parent. Limits the number of +/// blocks authored per slot. +pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; +/// Relay chain slot duration, in milliseconds. +pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; + impl AddressToAssetId for Runtime { fn address_to_asset_id(address: H160) -> Option { let mut data = [0u8; 16]; @@ -538,24 +547,27 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; // Shibuya is subject to relay changes so we don't enforce increasing relay number - type CheckAssociatedRelayNumber = AnyRelayNumber; + type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::AnyRelayNumber; + type ConsensusHook = ConsensusHook; type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } -impl parachain_info::Config for Runtime {} +type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< + Runtime, + RELAY_CHAIN_SLOT_DURATION_MILLIS, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, +>; -parameter_types! { - pub const MaxAuthorities: u32 = 250; - // Should be only enabled (`true`) when async backing is enabled - // otherwise set to `false` - pub const AllowMultipleBlocksPerSlot: bool = false; -} +impl parachain_info::Config for Runtime {} impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); - type MaxAuthorities = MaxAuthorities; - type AllowMultipleBlocksPerSlot = AllowMultipleBlocksPerSlot; + type MaxAuthorities = ConstU32<250>; + type AllowMultipleBlocksPerSlot = ConstBool; + #[cfg(feature = "experimental")] + type SlotDuration = ConstU64; } impl cumulus_pallet_aura_ext::Config for Runtime {} @@ -1749,7 +1761,7 @@ impl_runtime_apis! { impl sp_consensus_aura::AuraApi 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 { @@ -1757,6 +1769,15 @@ impl_runtime_apis! { } } + impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { + fn can_build_upon( + included_hash: ::Hash, + slot: cumulus_primitives_aura::Slot, + ) -> bool { + ConsensusHook::can_build_upon(included_hash, slot) + } + } + impl sp_block_builder::BlockBuilder for Runtime { fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { Executive::apply_extrinsic(extrinsic) @@ -2547,29 +2568,7 @@ impl_runtime_apis! { } } -struct CheckInherents; - -impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { - fn check_inherents( - block: &Block, - relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, - ) -> sp_inherents::CheckInherentsResult { - let relay_chain_slot = relay_state_proof - .read_slot() - .expect("Could not read the relay chain slot from the proof"); - let inherent_data = - cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( - relay_chain_slot, - sp_std::time::Duration::from_secs(6), - ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); - inherent_data.check_extrinsics(block) - } -} - cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, - CheckInherents = CheckInherents, } diff --git a/runtime/shiden/Cargo.toml b/runtime/shiden/Cargo.toml index 058640c8ee..c2e70fbaf5 100644 --- a/runtime/shiden/Cargo.toml +++ b/runtime/shiden/Cargo.toml @@ -75,9 +75,10 @@ pallet-xcm-benchmarks = { workspace = true, optional = true } # cumulus dependencies cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-dmp-queue = { workspace = true } -cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true, features = ["parameterized-consensus-hook"] } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } @@ -207,6 +208,7 @@ std = [ "polkadot-parachain/std", "polkadot-primitives/std", "polkadot-runtime-common/std", + "cumulus-primitives-aura/std", "cumulus-primitives-core/std", "cumulus-primitives-utility/std", "cumulus-primitives-timestamp/std", @@ -344,6 +346,8 @@ evm-tracing = [ "moonbeam-rpc-primitives-txpool", ] +experimental = ["pallet-aura/experimental"] + # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. metadata-hash = ["substrate-wasm-builder?/metadata-hash"] diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index d171fd0752..59af67af1a 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -22,7 +22,6 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] -use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use cumulus_primitives_core::AggregateMessageOrigin; use frame_support::{ construct_runtime, @@ -30,8 +29,8 @@ use frame_support::{ genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ - AsEnsureOriginWithArg, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance, - InstanceFilter, Nothing, OnFinalize, OnUnbalanced, WithdrawReasons, + AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, Contains, Currency, FindAuthor, Get, + Imbalance, InstanceFilter, Nothing, OnFinalize, OnUnbalanced, WithdrawReasons, }, weights::{ constants::{ @@ -55,7 +54,7 @@ use pallet_transaction_payment::{ use parity_scale_codec::{Compact, Decode, Encode, MaxEncodedLen}; use polkadot_runtime_common::BlockHashCount; use sp_api::impl_runtime_apis; -use sp_core::{ConstBool, OpaqueMetadata, H160, H256, U256}; +use sp_core::{OpaqueMetadata, H160, H256, U256}; use sp_inherents::{CheckInherentsResult, InherentData}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, @@ -133,11 +132,21 @@ pub const fn contracts_deposit(items: u32, bytes: u32) -> Balance { /// Change this to adjust the block time. pub const MILLISECS_PER_BLOCK: u64 = 12000; +pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; // Time is measured by number of blocks. pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); pub const HOURS: BlockNumber = MINUTES * 60; pub const DAYS: BlockNumber = HOURS * 24; +/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the +/// relay chain. +pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; +/// How many parachain blocks are processed by the relay chain per parent. Limits the number of +/// blocks authored per slot. +pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; +/// Relay chain slot duration, in milliseconds. +pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; + // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); @@ -500,24 +509,28 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedDmpWeight = ReservedDmpWeight; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; - type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type CheckAssociatedRelayNumber = + cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; + type ConsensusHook = ConsensusHook; type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } -impl parachain_info::Config for Runtime {} +type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< + Runtime, + RELAY_CHAIN_SLOT_DURATION_MILLIS, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, +>; -parameter_types! { - pub const MaxAuthorities: u32 = 250; - // Should be only enabled (`true`) when async backing is enabled - // otherwise set to `false` - pub const AllowMultipleBlocksPerSlot: bool = false; -} +impl parachain_info::Config for Runtime {} impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); - type MaxAuthorities = MaxAuthorities; - type AllowMultipleBlocksPerSlot = AllowMultipleBlocksPerSlot; + type MaxAuthorities = ConstU32<250>; + type AllowMultipleBlocksPerSlot = ConstBool; + #[cfg(feature = "experimental")] + type SlotDuration = ConstU64; } impl cumulus_pallet_aura_ext::Config for Runtime {} @@ -1391,7 +1404,7 @@ impl_runtime_apis! { impl sp_consensus_aura::AuraApi 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 { @@ -1399,6 +1412,15 @@ impl_runtime_apis! { } } + impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { + fn can_build_upon( + included_hash: ::Hash, + slot: cumulus_primitives_aura::Slot, + ) -> bool { + ConsensusHook::can_build_upon(included_hash, slot) + } + } + impl sp_block_builder::BlockBuilder for Runtime { fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { Executive::apply_extrinsic(extrinsic) @@ -2191,29 +2213,7 @@ impl_runtime_apis! { } } -struct CheckInherents; - -impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { - fn check_inherents( - block: &Block, - relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, - ) -> sp_inherents::CheckInherentsResult { - let relay_chain_slot = relay_state_proof - .read_slot() - .expect("Could not read the relay chain slot from the proof"); - let inherent_data = - cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( - relay_chain_slot, - sp_std::time::Duration::from_secs(6), - ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); - inherent_data.check_extrinsics(block) - } -} - cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, - CheckInherents = CheckInherents, } From 98c1669638be2e3189d6cc14d3bca9485530fda5 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Wed, 17 Jul 2024 22:41:56 +0200 Subject: [PATCH 02/11] fix feature --- bin/collator/src/parachain/service.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/collator/src/parachain/service.rs b/bin/collator/src/parachain/service.rs index 86d78b4e0e..a92eaf5325 100644 --- a/bin/collator/src/parachain/service.rs +++ b/bin/collator/src/parachain/service.rs @@ -566,7 +566,7 @@ where if is_authority { start_consensus( client.clone(), - backend.clone(), + backend, parachain_block_import, prometheus_registry.as_ref(), telemetry.map(|t| t.handle()), @@ -659,6 +659,7 @@ where ) -> Result, sc_service::Error>, SC: FnOnce( Arc>>, + Arc>, ParachainBlockImport< Block, FrontierBlockImport< @@ -902,6 +903,7 @@ where if is_authority { start_consensus( client.clone(), + backend, parachain_block_import, prometheus_registry.as_ref(), telemetry.map(|t| t.handle()), From 6ac7234e116f5db8161ec7afa1022faf59d339c4 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Tue, 30 Jul 2024 15:12:15 +0200 Subject: [PATCH 03/11] handle transition to async-backing --- bin/collator/src/parachain/service.rs | 61 ++++++++++++++++----------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/bin/collator/src/parachain/service.rs b/bin/collator/src/parachain/service.rs index a92eaf5325..f5b33b3595 100644 --- a/bin/collator/src/parachain/service.rs +++ b/bin/collator/src/parachain/service.rs @@ -957,11 +957,9 @@ where sc_client_api::StateBackend, Executor: sc_executor::NativeExecutionDispatch + 'static, { - let client2 = client.clone(); + let verifier_client = client.clone(); let aura_verifier = move || { - let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client2).unwrap(); - Box::new(cumulus_client_consensus_aura::build_verifier::< AuraPair, _, @@ -969,17 +967,24 @@ where _, >( cumulus_client_consensus_aura::BuildVerifierParams { - client: client2.clone(), - create_inherent_data_providers: move |_, _| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = - sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); - - Ok((slot, timestamp)) + client: verifier_client.clone(), + create_inherent_data_providers: move |parent_hash, _| { + let cidp_client = verifier_client.clone(); + async move { + let slot_duration = cumulus_client_consensus_aura::slot_duration_at( + &*cidp_client, + parent_hash, + )?; + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); + + Ok((slot, timestamp)) + } }, telemetry: telemetry_handle, }, @@ -1041,8 +1046,7 @@ where sc_client_api::StateBackend, Executor: sc_executor::NativeExecutionDispatch + 'static, { - let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; - + let cidp_client = client.clone(); cumulus_client_consensus_aura::import_queue::< AuraPair, _, @@ -1053,16 +1057,23 @@ where >(cumulus_client_consensus_aura::ImportQueueParams { block_import, client, - create_inherent_data_providers: move |_, _| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = - sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); + create_inherent_data_providers: move |parent_hash, _| { + let cidp_client = cidp_client.clone(); + async move { + let slot_duration = sc_consensus_aura::standalone::slot_duration_at( + &*cidp_client, + parent_hash, + )?; + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); - Ok((slot, timestamp)) + Ok((slot, timestamp)) + } }, registry: config.prometheus_registry(), spawner: &task_manager.spawn_essential_handle(), From a2073771a064fcab29234ac0a45f663d27c5b7f7 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Tue, 30 Jul 2024 17:03:15 +0200 Subject: [PATCH 04/11] fix after merge --- bin/collator/src/parachain/service.rs | 43 +++++++++++++-------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/bin/collator/src/parachain/service.rs b/bin/collator/src/parachain/service.rs index d94b155101..efb3d3efef 100644 --- a/bin/collator/src/parachain/service.rs +++ b/bin/collator/src/parachain/service.rs @@ -960,35 +960,32 @@ where let verifier_client = client.clone(); let aura_verifier = move || { - Box::new(cumulus_client_consensus_aura::build_verifier::< - AuraPair, - _, - _, - _, - >(sc_consensus_aura::BuildVerifierParams { - client: verifier_client.clone(), - create_inherent_data_providers: move |parent_hash, _| { - let cidp_client = verifier_client.clone(); - async move { - let slot_duration = cumulus_client_consensus_aura::slot_duration_at( - &*cidp_client, - parent_hash, - )?; - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = + Box::new(sc_consensus_aura::build_verifier::( + sc_consensus_aura::BuildVerifierParams { + client: verifier_client.clone(), + create_inherent_data_providers: move |parent_hash, _| { + let cidp_client = verifier_client.clone(); + async move { + let slot_duration = cumulus_client_consensus_aura::slot_duration_at( + &*cidp_client, + parent_hash, + )?; + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( *timestamp, slot_duration, ); - Ok((slot, timestamp)) - } + Ok((slot, timestamp)) + } + }, + telemetry: telemetry_handle, + check_for_equivocation: sc_consensus_aura::CheckForEquivocation::Yes, + compatibility_mode: sc_consensus_aura::CompatibilityMode::None, }, - telemetry: telemetry_handle, - check_for_equivocation: sc_consensus_aura::CheckForEquivocation::Yes, - compatibility_mode: sc_consensus_aura::CompatibilityMode::None, - })) as Box<_> + )) as Box<_> }; let relay_chain_verifier = Box::new(RelayChainVerifier::new(client.clone(), |_, _| async { From 2a222a5bd17f8a38b246c91def924348b7bea47e Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Wed, 31 Jul 2024 12:57:34 +0200 Subject: [PATCH 05/11] update zombinet config to test async backing --- third-party/zombienet/single_parachain.toml | 68 ++++++++++++++------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/third-party/zombienet/single_parachain.toml b/third-party/zombienet/single_parachain.toml index fb592d5e8b..d6c39d3b34 100644 --- a/third-party/zombienet/single_parachain.toml +++ b/third-party/zombienet/single_parachain.toml @@ -5,24 +5,32 @@ timeout = 1000 [relaychain] default_command = "./polkadot" -default_args = [ "-l=parachain=debug,xcm=trace" ] +default_args = ["-l=parachain=debug,xcm=trace"] chain = "rococo-local" - [[relaychain.nodes]] - name = "alice" - validator = true +[relaychain.genesis.runtimeGenesis.patch.configuration.config.async_backing_params] +max_candidate_depth = 3 +allowed_ancestry_len = 2 - [[relaychain.nodes]] - name = "bob" - validator = true +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] +lookahead = 2 - [[relaychain.nodes]] - name = "charlie" - validator = true +[[relaychain.nodes]] +name = "alice" +validator = true +ws_port = 9933 - [[relaychain.nodes]] - name = "dave" - validator = true +[[relaychain.nodes]] +name = "bob" +validator = true + +[[relaychain.nodes]] +name = "charlie" +validator = true + +[[relaychain.nodes]] +name = "dave" +validator = true [[parachains]] # Right now this has to be 2000 but soon we might be able to use arbitrary para-id @@ -31,13 +39,29 @@ id = 2000 chain = "shibuya-dev" cumulus_based = true - [[parachains.collators]] - name = "collator1" - command = "./astar-collator" - args = [ "-l=xcm=trace", "--enable-evm-rpc" ] - +[[parachains.collators]] +name = "collator1" +command = "./astar-collator" +args = ["-l=xcm=trace,parachain=debug", "--enable-evm-rpc"] +ws_port = 9944 + +[[parachains.collators]] +name = "collator2" +command = "./astar-collator" +args = ["--enable-evm-rpc"] +ws_port = 9945 + +[[parachains.collators]] +name = "collator3" +command = "./astar-collator" +ws_port = 9946 + +[[parachains.collators]] +name = "collator4" +command = "./astar-collator" +ws_port = 9947 - [[parachains.collators]] - name = "collator2" - command = "./astar-collator" - args = [ "--enable-evm-rpc" ] +[[parachains.collators]] +name = "collator5" +command = "./astar-collator" +ws_port = 9948 From f371fd6226c749f228a1d42716ddfc2c347deae6 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Wed, 31 Jul 2024 18:51:08 +0200 Subject: [PATCH 06/11] simplify shell to aura --- bin/collator/src/parachain/service.rs | 42 ++++++++++----------- bin/collator/src/parachain/shell_upgrade.rs | 41 +++----------------- 2 files changed, 24 insertions(+), 59 deletions(-) diff --git a/bin/collator/src/parachain/service.rs b/bin/collator/src/parachain/service.rs index efb3d3efef..e144d4181e 100644 --- a/bin/collator/src/parachain/service.rs +++ b/bin/collator/src/parachain/service.rs @@ -959,34 +959,30 @@ where { let verifier_client = client.clone(); - let aura_verifier = move || { - Box::new(sc_consensus_aura::build_verifier::( - sc_consensus_aura::BuildVerifierParams { - client: verifier_client.clone(), - create_inherent_data_providers: move |parent_hash, _| { - let cidp_client = verifier_client.clone(); - async move { - let slot_duration = cumulus_client_consensus_aura::slot_duration_at( - &*cidp_client, - parent_hash, - )?; - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = + let aura_verifier = cumulus_client_consensus_aura::build_verifier::( + cumulus_client_consensus_aura::BuildVerifierParams { + client: verifier_client.clone(), + create_inherent_data_providers: move |parent_hash, _| { + let cidp_client = verifier_client.clone(); + async move { + let slot_duration = cumulus_client_consensus_aura::slot_duration_at( + &*cidp_client, + parent_hash, + )?; + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( *timestamp, slot_duration, ); - Ok((slot, timestamp)) - } - }, - telemetry: telemetry_handle, - check_for_equivocation: sc_consensus_aura::CheckForEquivocation::Yes, - compatibility_mode: sc_consensus_aura::CompatibilityMode::None, + Ok((slot, timestamp)) + } }, - )) as Box<_> - }; + telemetry: telemetry_handle, + }, + ); let relay_chain_verifier = Box::new(RelayChainVerifier::new(client.clone(), |_, _| async { Ok(()) @@ -995,7 +991,7 @@ where let verifier = Verifier { client, relay_chain_verifier, - aura_verifier: BuildOnAccess::Uninitialized(Some(Box::new(aura_verifier))), + aura_verifier: Box::new(aura_verifier), }; let registry = config.prometheus_registry(); diff --git a/bin/collator/src/parachain/shell_upgrade.rs b/bin/collator/src/parachain/shell_upgrade.rs index 212cd2d79f..55ccd068a5 100644 --- a/bin/collator/src/parachain/shell_upgrade.rs +++ b/bin/collator/src/parachain/shell_upgrade.rs @@ -22,7 +22,7 @@ use cumulus_primitives_core::relay_chain::PersistedValidationData; use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; use fc_rpc::pending::ConsensusDataProvider; use sc_client_api::{AuxStore, UsageProvider}; -use sc_consensus::{import_queue::Verifier as VerifierT, BlockImportParams, ForkChoiceStrategy}; +use sc_consensus::{import_queue::Verifier as VerifierT, BlockImportParams}; use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_consensus_aura::{ digests::CompatibleDigestItem, @@ -37,27 +37,9 @@ use sp_runtime::{ use sp_timestamp::TimestampInherentData; use std::{marker::PhantomData, sync::Arc}; -pub enum BuildOnAccess { - Uninitialized(Option R + Send + Sync>>), - Initialized(R), -} - -impl BuildOnAccess { - fn get_mut(&mut self) -> &mut R { - loop { - match self { - Self::Uninitialized(f) => { - *self = Self::Initialized((f.take().unwrap())()); - } - Self::Initialized(ref mut r) => return r, - } - } - } -} - pub struct Verifier { pub client: Arc, - pub aura_verifier: BuildOnAccess>>, + pub aura_verifier: Box>, pub relay_chain_verifier: Box>, } @@ -69,28 +51,15 @@ where { async fn verify( &mut self, - mut block_import: BlockImportParams, + block_import: BlockImportParams, ) -> Result, String> { - // Skip checks that include execution, if being told so or when importing only state. - // - // This is done for example when gap syncing and it is expected that the block after the gap - // was checked/chosen properly, e.g. by warp syncing to this block using a finality proof. - // Or when we are importing state only and can not verify the seal. - if block_import.with_state() || block_import.state_action.skip_execution_checks() { - // When we are importing only the state of a block, it will be the best block. - block_import.fork_choice = Some(ForkChoiceStrategy::Custom(block_import.with_state())); - return Ok(block_import); - } - - let block_hash = *block_import.header.parent_hash(); - if self .client .runtime_api() - .has_api::>(block_hash) + .has_api::>(*block_import.header.parent_hash()) .unwrap_or(false) { - self.aura_verifier.get_mut().verify(block_import).await + self.aura_verifier.verify(block_import).await } else { self.relay_chain_verifier.verify(block_import).await } From 53697bac488d32aad612ba12279490688dd51d7f Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Thu, 1 Aug 2024 13:28:51 +0200 Subject: [PATCH 07/11] reduce parachains --- third-party/zombienet/single_parachain.toml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/third-party/zombienet/single_parachain.toml b/third-party/zombienet/single_parachain.toml index d6c39d3b34..9f4a890b02 100644 --- a/third-party/zombienet/single_parachain.toml +++ b/third-party/zombienet/single_parachain.toml @@ -55,13 +55,3 @@ ws_port = 9945 name = "collator3" command = "./astar-collator" ws_port = 9946 - -[[parachains.collators]] -name = "collator4" -command = "./astar-collator" -ws_port = 9947 - -[[parachains.collators]] -name = "collator5" -command = "./astar-collator" -ws_port = 9948 From ce06b875c468fa3c48fb62f19c7740ae7d535cee Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Sun, 4 Aug 2024 20:50:50 +0200 Subject: [PATCH 08/11] remove experimental feature --- runtime/astar/Cargo.toml | 2 -- runtime/astar/src/lib.rs | 6 ++---- runtime/local/Cargo.toml | 2 -- runtime/local/src/lib.rs | 2 -- runtime/shibuya/Cargo.toml | 2 -- runtime/shibuya/src/lib.rs | 4 +--- runtime/shiden/Cargo.toml | 2 -- runtime/shiden/src/lib.rs | 6 ++---- 8 files changed, 5 insertions(+), 21 deletions(-) diff --git a/runtime/astar/Cargo.toml b/runtime/astar/Cargo.toml index 800d60d544..5c3df5d917 100644 --- a/runtime/astar/Cargo.toml +++ b/runtime/astar/Cargo.toml @@ -341,8 +341,6 @@ evm-tracing = [ "moonbeam-rpc-primitives-txpool", ] -experimental = ["pallet-aura/experimental"] - # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. metadata-hash = ["substrate-wasm-builder?/metadata-hash"] diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index 3f818c0a6d..a9f264b8c1 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -29,8 +29,8 @@ use frame_support::{ genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ - AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, Contains, Currency, FindAuthor, Get, - Imbalance, InstanceFilter, Nothing, OnFinalize, OnUnbalanced, Randomness, WithdrawReasons, + AsEnsureOriginWithArg, ConstBool, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance, + InstanceFilter, Nothing, OnFinalize, OnUnbalanced, Randomness, WithdrawReasons, }, weights::{ constants::{ @@ -490,8 +490,6 @@ impl pallet_aura::Config for Runtime { type DisabledValidators = (); type MaxAuthorities = ConstU32<250>; type AllowMultipleBlocksPerSlot = ConstBool; - #[cfg(feature = "experimental")] - type SlotDuration = ConstU64; } impl cumulus_pallet_aura_ext::Config for Runtime {} diff --git a/runtime/local/Cargo.toml b/runtime/local/Cargo.toml index 2dbfd1fea6..1ac76bd3f9 100644 --- a/runtime/local/Cargo.toml +++ b/runtime/local/Cargo.toml @@ -276,8 +276,6 @@ evm-tracing = [ "moonbeam-rpc-primitives-txpool", ] -experimental = ["pallet-aura/experimental"] - # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. metadata-hash = ["substrate-wasm-builder?/metadata-hash"] diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index 4bd75abf2e..030daa7280 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -270,8 +270,6 @@ impl pallet_aura::Config for Runtime { type DisabledValidators = (); type MaxAuthorities = ConstU32<50>; type AllowMultipleBlocksPerSlot = ConstBool; - #[cfg(feature = "experimental")] - type SlotDuration = ConstU64; } impl pallet_grandpa::Config for Runtime { diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index 81ff9dbd23..35dd3e2dae 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -388,8 +388,6 @@ evm-tracing = [ "moonbeam-rpc-primitives-txpool", ] -experimental = ["pallet-aura/experimental"] - # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. metadata-hash = ["substrate-wasm-builder?/metadata-hash"] diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index b575d42ab8..ed8503cb9e 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -31,7 +31,7 @@ use frame_support::{ traits::{ fungible::HoldConsideration, tokens::{PayFromAccount, UnityAssetBalanceConversion}, - AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, Contains, Currency, + AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, Contains, Currency, EqualPrivilegeOnly, FindAuthor, Get, Imbalance, InstanceFilter, LinearStoragePrice, Nothing, OnFinalize, OnUnbalanced, WithdrawReasons, }, @@ -566,8 +566,6 @@ impl pallet_aura::Config for Runtime { type DisabledValidators = (); type MaxAuthorities = ConstU32<250>; type AllowMultipleBlocksPerSlot = ConstBool; - #[cfg(feature = "experimental")] - type SlotDuration = ConstU64; } impl cumulus_pallet_aura_ext::Config for Runtime {} diff --git a/runtime/shiden/Cargo.toml b/runtime/shiden/Cargo.toml index d671814b0d..56fddfdeef 100644 --- a/runtime/shiden/Cargo.toml +++ b/runtime/shiden/Cargo.toml @@ -346,8 +346,6 @@ evm-tracing = [ "moonbeam-rpc-primitives-txpool", ] -experimental = ["pallet-aura/experimental"] - # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. metadata-hash = ["substrate-wasm-builder?/metadata-hash"] diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index 59af67af1a..8fa2b6030b 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -29,8 +29,8 @@ use frame_support::{ genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ - AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, Contains, Currency, FindAuthor, Get, - Imbalance, InstanceFilter, Nothing, OnFinalize, OnUnbalanced, WithdrawReasons, + AsEnsureOriginWithArg, ConstBool, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance, + InstanceFilter, Nothing, OnFinalize, OnUnbalanced, WithdrawReasons, }, weights::{ constants::{ @@ -529,8 +529,6 @@ impl pallet_aura::Config for Runtime { type DisabledValidators = (); type MaxAuthorities = ConstU32<250>; type AllowMultipleBlocksPerSlot = ConstBool; - #[cfg(feature = "experimental")] - type SlotDuration = ConstU64; } impl cumulus_pallet_aura_ext::Config for Runtime {} From a9d65b7100c789facce825d1366b3df167d4ecae Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Mon, 5 Aug 2024 12:59:23 +0200 Subject: [PATCH 09/11] fix integration tests --- tests/integration/src/setup.rs | 43 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/tests/integration/src/setup.rs b/tests/integration/src/setup.rs index a6d08bb828..a11b7a5a3b 100644 --- a/tests/integration/src/setup.rs +++ b/tests/integration/src/setup.rs @@ -245,11 +245,9 @@ impl ExtBuilder { pallet_dapp_staking_v3::Safeguard::::put(false); // Ensure the initial state is set for the first block - assert_ok!(Timestamp::set( - RuntimeOrigin::none(), - ::MinimumPeriod::get() - )); AllPalletsWithSystem::on_initialize(1); + set_timestamp(); + set_validation_data(); }); ext } @@ -265,15 +263,23 @@ pub fn new_test_ext() -> sp_io::TestExternalities { .build() } +fn set_timestamp() { + assert_ok!(Timestamp::set( + RuntimeOrigin::none(), + pallet_timestamp::Now::::get() + SLOT_DURATION + )); +} + fn set_validation_data() { let block_number = System::block_number(); let para_id = ::SelfParaId::get(); + let parent_head = HeadData(b"deadbeef".into()); let sproof_builder = RelayStateSproofBuilder { para_id, + included_para_head: Some(parent_head.clone()), ..Default::default() }; - let parent_head = HeadData(System::parent_hash().encode()); let (relay_parent_storage_root, relay_chain_state) = sproof_builder.into_state_root_and_proof(); let para_inherent_data = ParachainInherentData { validation_data: PersistedValidationData { @@ -295,21 +301,30 @@ fn set_validation_data() { pub fn run_to_block(n: BlockNumber) { while System::block_number() < n { - set_validation_data(); - let block_number = System::block_number(); + + // finalize block + AllPalletsWithSystem::on_idle(block_number, Weight::MAX.div(2)); AllPalletsWithSystem::on_finalize(block_number); - System::set_block_number(block_number + 1); - assert_ok!(Timestamp::set( - RuntimeOrigin::none(), - pallet_timestamp::Now::::get() - + ::MinimumPeriod::get() - + 1 + // Mock some storage to make consensus hook happy + sp_io::storage::clear(&frame_support::storage::storage_prefix( + b"ParachainSystem", + b"UnincludedSegment", )); + if let Some((slot, _authored)) = AuraExt::slot_info() { + sp_io::storage::set( + &frame_support::storage::storage_prefix(b"AuraExt", b"SlotInfo"), + &(slot, 0u32).encode(), + ); + } + // initialize block + System::set_block_number(block_number + 1); AllPalletsWithSystem::on_initialize(block_number + 1); - AllPalletsWithSystem::on_idle(block_number + 1, Weight::MAX); + // apply inherent + set_timestamp(); + set_validation_data(); } } From b215afc3c52366a17e55eb98e58baec702ecd527 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Tue, 6 Aug 2024 11:48:53 +0200 Subject: [PATCH 10/11] revert to strictlyIncrease for now --- runtime/astar/src/lib.rs | 3 +-- runtime/shiden/src/lib.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index a9f264b8c1..21922b03a2 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -470,8 +470,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedDmpWeight = ReservedDmpWeight; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; - type CheckAssociatedRelayNumber = - cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; + type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; type ConsensusHook = ConsensusHook; type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index 8fa2b6030b..6432aaf765 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -509,8 +509,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedDmpWeight = ReservedDmpWeight; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; - type CheckAssociatedRelayNumber = - cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; + type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; type ConsensusHook = ConsensusHook; type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } From 9f06d1c5f48479f7ab3f528eb283737c4f2871b4 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Tue, 6 Aug 2024 11:54:21 +0200 Subject: [PATCH 11/11] update authoring_duration to 1.5s --- bin/collator/src/parachain/service.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/collator/src/parachain/service.rs b/bin/collator/src/parachain/service.rs index e144d4181e..9c111102f4 100644 --- a/bin/collator/src/parachain/service.rs +++ b/bin/collator/src/parachain/service.rs @@ -1211,7 +1211,7 @@ where relay_chain_slot_duration: Duration::from_secs(6), proposer: cumulus_client_consensus_proposer::Proposer::new(proposer_factory), collator_service, - authoring_duration: Duration::from_millis(2000), + authoring_duration: Duration::from_millis(1500), reinitialize: true, }) .await @@ -1319,7 +1319,7 @@ where relay_chain_slot_duration: Duration::from_secs(6), proposer: cumulus_client_consensus_proposer::Proposer::new(proposer_factory), collator_service, - authoring_duration: Duration::from_millis(2000), + authoring_duration: Duration::from_millis(1500), reinitialize: false, });