diff --git a/node/src/service.rs b/node/src/service.rs index 5c372736..7fcb71e1 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -15,8 +15,10 @@ use cumulus_client_service::{ }; use cumulus_primitives_core::{ relay_chain::{CollatorPair, ValidationCode}, - ParaId, + GetCoreSelectorApi, ParaId, }; + +use cumulus_client_consensus_aura::collators::slot_based::{self, SlotBasedBlockImport}; use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface}; // Substrate Imports @@ -84,8 +86,14 @@ type ParachainClient = TFullClient; -type ParachainBlockImport = - TParachainBlockImport>, ParachainBackend>; +// type ParachainBlockImport = +// TParachainBlockImport>, ParachainBackend>; + +pub type ParachainBlockImport = TParachainBlockImport< + Block, + SlotBasedBlockImport>, ParachainClient>, + ParachainBackend, +>; /// Starts a `ServiceBuilder` for a full service. /// @@ -102,7 +110,12 @@ pub fn new_partial( (), sc_consensus::DefaultImportQueue, sc_transaction_pool::TransactionPoolHandle>, - (ParachainBlockImport, Option, Option), + ( + ParachainBlockImport, + Option, + Option, + slot_based::SlotBasedBlockImportHandle, + ), >, sc_service::Error, > @@ -176,7 +189,9 @@ where .build(), ); - let block_import = ParachainBlockImport::::new(client.clone(), backend.clone()); + let (block_import, slot_based_handle) = + slot_based::SlotBasedBlockImport::new(client.clone(), client.clone()); + let block_import = ParachainBlockImport::new(block_import, backend.clone()); let import_queue = build_import_queue( client.clone(), @@ -194,7 +209,7 @@ where task_manager, transaction_pool, select_chain: (), - other: (block_import, telemetry, telemetry_worker_handle), + other: (block_import, telemetry, telemetry_worker_handle, slot_based_handle), }) } @@ -221,6 +236,7 @@ where + sp_session::SessionKeys + sp_api::ApiExt + sp_offchain::OffchainWorkerApi + + GetCoreSelectorApi + sp_block_builder::BlockBuilder + cumulus_primitives_aura::AuraUnincludedSegmentApi + cumulus_primitives_core::CollectCollationInfo @@ -243,6 +259,7 @@ where Arc>, Arc, ParachainBlockImport, + slot_based::SlotBasedBlockImportHandle, Option<&Registry>, Option, &TaskManager, @@ -261,7 +278,7 @@ where let parachain_config = prepare_node_config(parachain_config); let params = new_partial::(¶chain_config, build_import_queue)?; - let (block_import, mut telemetry, telemetry_worker_handle) = params.other; + let (block_import, mut telemetry, telemetry_worker_handle, slot_based_handle) = params.other; let prometheus_registry = parachain_config.prometheus_registry().cloned(); let net_config = sc_network::config::FullNetworkConfiguration::<_, _, Net>::new( ¶chain_config.network, @@ -410,6 +427,7 @@ where client.clone(), backend.clone(), block_import, + slot_based_handle, prometheus_registry.as_ref(), telemetry.as_ref().map(|t| t.handle()), &task_manager, @@ -473,6 +491,7 @@ fn start_consensus( client: Arc>, backend: Arc, block_import: ParachainBlockImport, + slot_based_handle: slot_based::SlotBasedBlockImportHandle, prometheus_registry: Option<&Registry>, telemetry: Option, task_manager: &TaskManager, @@ -484,7 +503,7 @@ fn start_consensus( relay_chain_slot_duration: Duration, para_id: ParaId, collator_key: CollatorPair, - overseer_handle: OverseerHandle, + _overseer_handle: OverseerHandle, announce_block: Arc>) + Send + Sync>, max_pov_percentage: Option, ) -> Result<(), sc_service::Error> @@ -492,6 +511,7 @@ where RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_api::Metadata + + GetCoreSelectorApi + sp_session::SessionKeys + sp_api::ApiExt + sp_offchain::OffchainWorkerApi @@ -502,10 +522,6 @@ where + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi + substrate_frame_rpc_system::AccountNonceApi, { - // NOTE: because we use Aura here explicitly, we can use `CollatorSybilResistance::Resistant` - // when starting the network. - use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams}; - let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), @@ -523,31 +539,31 @@ where client.clone(), ); - let params = AuraParams { + let params = slot_based::Params { create_inherent_data_providers: move |_, ()| async move { Ok(()) }, block_import, para_client: client.clone(), - para_backend: backend, + para_backend: backend.clone(), relay_client: relay_chain_interface, code_hash_provider: move |block_hash| { - client.code_at(block_hash).ok().map(ValidationCode).map(|c| c.hash()) + client.code_at(block_hash).ok().map(|c| ValidationCode::from(c).hash()) }, keystore, collator_key, - para_id, - overseer_handle, relay_chain_slot_duration, + para_id, proposer, collator_service, authoring_duration: Duration::from_millis(2000), reinitialize: false, + slot_offset: Duration::from_secs(1), + block_import_handle: slot_based_handle, + spawner: task_manager.spawn_handle(), + export_pov: None, max_pov_percentage, }; - let fut = aura::run::( - params, - ); - task_manager.spawn_essential_handle().spawn("aura", None, fut); + slot_based::run::::Pair, _, _, _, _, _, _, _, _, _>(params); Ok(()) } @@ -573,6 +589,7 @@ where + cumulus_primitives_aura::AuraUnincludedSegmentApi + cumulus_primitives_core::CollectCollationInfo + sp_consensus_aura::AuraApi::Pair as Pair>::Public> + + GetCoreSelectorApi + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi + substrate_frame_rpc_system::AccountNonceApi, { diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index 4c44de94..75c21396 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -13,7 +13,9 @@ extern crate alloc; pub use fee::WeightToFee; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::{AggregateMessageOrigin, AssetId, ParaId}; +use cumulus_primitives_core::{ + AggregateMessageOrigin, AssetId, ClaimQueueOffset, CoreSelector, ParaId, +}; use frame_support::traits::fungible::Balanced; use frame_support::traits::{ fungible, AsEnsureOriginWithArg, InstanceFilter, OnUnbalanced, WithdrawReasons, @@ -1321,6 +1323,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() + } + } + impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION diff --git a/runtime/testnet/Cargo.toml b/runtime/testnet/Cargo.toml index 635469e7..4553dfe5 100644 --- a/runtime/testnet/Cargo.toml +++ b/runtime/testnet/Cargo.toml @@ -86,7 +86,7 @@ xcm-runtime-apis = { workspace = true, default-features = false } # Cumulus cumulus-primitives-aura = { workspace = true, default-features = false } cumulus-pallet-aura-ext = { workspace = true, default-features = false } -cumulus-pallet-parachain-system = { workspace = true, default-features = false } +cumulus-pallet-parachain-system = { workspace = true, default-features = false, features=["experimental-ump-signals"] } cumulus-pallet-session-benchmarking = { workspace = true, default-features = false } cumulus-pallet-xcm = { workspace = true, default-features = false } cumulus-pallet-xcmp-queue = { workspace = true, default-features = false } diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index 82e24f1f..e3a334c0 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -13,7 +13,9 @@ use core::marker::PhantomData; pub use fee::WeightToFee; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::{AggregateMessageOrigin, AssetId, ParaId}; +use cumulus_primitives_core::{ + AggregateMessageOrigin, AssetId, ClaimQueueOffset, CoreSelector, ParaId, +}; #[cfg(feature = "runtime-benchmarks")] use pallet_treasury::ArgumentsFactory; @@ -480,10 +482,10 @@ parameter_types! { /// Maximum number of blocks simultaneously accepted by the Runtime, not yet included /// into the relay chain. -const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3; +const UNINCLUDED_SEGMENT_CAPACITY: u32 = 7; /// 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; +const BLOCK_PROCESSING_VELOCITY: u32 = 3; /// Relay chain slot duration, in milliseconds. const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; @@ -499,7 +501,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; type WeightInfo = weights::cumulus_pallet_parachain_system::WeightInfo; - type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; + type SelectCore = cumulus_pallet_parachain_system::LookaheadCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -1326,6 +1328,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() + } + } + impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION