Update tick collator for async backing (#1497)

This updates the tick runtime and polkadot-parachain collator to use
async backing.
This commit is contained in:
Sophia Gold
2023-11-21 11:34:05 -05:00
committed by GitHub
parent f5ad32e406
commit 50811d6b42
4 changed files with 55 additions and 29 deletions
Generated
+1
View File
@@ -14530,6 +14530,7 @@ dependencies = [
"cumulus-pallet-xcm", "cumulus-pallet-xcm",
"cumulus-pallet-xcmp-queue", "cumulus-pallet-xcmp-queue",
"cumulus-ping", "cumulus-ping",
"cumulus-primitives-aura",
"cumulus-primitives-core", "cumulus-primitives-core",
"cumulus-primitives-utility", "cumulus-primitives-utility",
"frame-benchmarking", "frame-benchmarking",
@@ -52,6 +52,7 @@ cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system
cumulus-pallet-xcm = { path = "../../../../pallets/xcm", default-features = false } cumulus-pallet-xcm = { path = "../../../../pallets/xcm", default-features = false }
cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", default-features = false } cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", default-features = false }
cumulus-ping = { path = "../../../pallets/ping", default-features = false } cumulus-ping = { path = "../../../pallets/ping", default-features = false }
cumulus-primitives-aura = { path = "../../../../primitives/aura", default-features = false }
cumulus-primitives-core = { path = "../../../../primitives/core", default-features = false } cumulus-primitives-core = { path = "../../../../primitives/core", default-features = false }
cumulus-primitives-utility = { path = "../../../../primitives/utility", default-features = false } cumulus-primitives-utility = { path = "../../../../primitives/utility", default-features = false }
parachains-common = { path = "../../../common", default-features = false } parachains-common = { path = "../../../common", default-features = false }
@@ -70,6 +71,7 @@ std = [
"cumulus-pallet-xcm/std", "cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std", "cumulus-pallet-xcmp-queue/std",
"cumulus-ping/std", "cumulus-ping/std",
"cumulus-primitives-aura/std",
"cumulus-primitives-core/std", "cumulus-primitives-core/std",
"cumulus-primitives-utility/std", "cumulus-primitives-utility/std",
"frame-benchmarking?/std", "frame-benchmarking?/std",
@@ -22,13 +22,13 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
use sp_api::impl_runtime_apis; use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata; use sp_core::OpaqueMetadata;
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT}, traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, Hash as HashT},
transaction_validity::{TransactionSource, TransactionValidity}, transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, ApplyExtrinsicResult,
}; };
@@ -113,7 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
state_version: 0, state_version: 0,
}; };
pub const MILLISECS_PER_BLOCK: u64 = 12000; pub const MILLISECS_PER_BLOCK: u64 = 6000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
@@ -143,18 +143,18 @@ const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used /// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
/// by Operational extrinsics. /// by Operational extrinsics.
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for .5 seconds of compute with a 12 second average block time. /// We allow for 2 seconds of compute with a 6 second average block time.
const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64, cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
); );
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included /// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
/// into the relay chain. /// into the relay chain.
const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
/// How many parachain blocks are processed by the relay chain per parent. Limits the /// How many parachain blocks are processed by the relay chain per parent. Limits the
/// number of blocks authored per slot. /// number of blocks authored per slot.
const BLOCK_PROCESSING_VELOCITY: u32 = 1; const BLOCK_PROCESSING_VELOCITY: u32 = 2;
/// Relay chain slot duration, in milliseconds. /// Relay chain slot duration, in milliseconds.
const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
@@ -277,6 +277,13 @@ parameter_types! {
pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
} }
type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Runtime,
RELAY_CHAIN_SLOT_DURATION_MILLIS,
BLOCK_PROCESSING_VELOCITY,
UNINCLUDED_SEGMENT_CAPACITY,
>;
impl cumulus_pallet_parachain_system::Config for Runtime { impl cumulus_pallet_parachain_system::Config for Runtime {
type WeightInfo = (); type WeightInfo = ();
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
@@ -287,13 +294,8 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedDmpWeight = ReservedDmpWeight; type ReservedDmpWeight = ReservedDmpWeight;
type XcmpMessageHandler = XcmpQueue; type XcmpMessageHandler = XcmpQueue;
type ReservedXcmpWeight = ReservedXcmpWeight; type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< type ConsensusHook = ConsensusHook;
Runtime,
RELAY_CHAIN_SLOT_DURATION_MILLIS,
BLOCK_PROCESSING_VELOCITY,
UNINCLUDED_SEGMENT_CAPACITY,
>;
} }
impl parachain_info::Config for Runtime {} impl parachain_info::Config for Runtime {}
@@ -584,9 +586,9 @@ impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId; type AuthorityId = AuraId;
type DisabledValidators = (); type DisabledValidators = ();
type MaxAuthorities = ConstU32<100_000>; type MaxAuthorities = ConstU32<100_000>;
type AllowMultipleBlocksPerSlot = ConstBool<false>; type AllowMultipleBlocksPerSlot = ConstBool<true>;
#[cfg(feature = "experimental")] #[cfg(feature = "experimental")]
type SlotDuration = pallet_aura::MinimumPeriodTimesTwo<Self>; type SlotDuration = ConstU64<SLOT_DURATION>;
} }
construct_runtime! { construct_runtime! {
@@ -624,7 +626,7 @@ pub type Balance = u128;
/// Index of a transaction in the chain. /// Index of a transaction in the chain.
pub type Nonce = u32; pub type Nonce = u32;
/// A hash of some data used by the chain. /// A hash of some data used by the chain.
pub type Hash = sp_core::H256; pub type Hash = <BlakeTwo256 as HashT>::Output;
/// An index to a block. /// An index to a block.
pub type BlockNumber = u32; pub type BlockNumber = u32;
/// The address format for describing accounts. /// The address format for describing accounts.
@@ -751,7 +753,7 @@ impl_runtime_apis! {
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime { impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration { 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> { fn authorities() -> Vec<AuraId> {
@@ -824,6 +826,15 @@ impl_runtime_apis! {
build_config::<RuntimeGenesisConfig>(config) build_config::<RuntimeGenesisConfig>(config)
} }
} }
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)
}
}
} }
cumulus_pallet_parachain_system::register_validate_block! { cumulus_pallet_parachain_system::register_validate_block! {
+23 -11
View File
@@ -590,6 +590,7 @@ where
CollatorPair, CollatorPair,
OverseerHandle, OverseerHandle,
Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>, Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
Arc<ParachainBackend>,
) -> Result<(), sc_service::Error>, ) -> Result<(), sc_service::Error>,
{ {
let parachain_config = prepare_node_config(parachain_config); let parachain_config = prepare_node_config(parachain_config);
@@ -723,6 +724,7 @@ where
collator_key.expect("Command line arguments do not allow this. qed"), collator_key.expect("Command line arguments do not allow this. qed"),
overseer_handle, overseer_handle,
announce_block, announce_block,
backend.clone(),
)?; )?;
} }
@@ -983,7 +985,8 @@ pub async fn start_rococo_parachain_node(
para_id, para_id,
collator_key, collator_key,
overseer_handle, overseer_handle,
announce_block| { announce_block,
backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
@@ -1002,11 +1005,15 @@ pub async fn start_rococo_parachain_node(
client.clone(), client.clone(),
); );
let params = BasicAuraParams { let params = AuraParams {
create_inherent_data_providers: move |_, ()| async move { Ok(()) }, create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import, block_import,
para_client: client, para_client: client.clone(),
para_backend: backend.clone(),
relay_client: relay_chain_interface, relay_client: relay_chain_interface,
code_hash_provider: move |block_hash| {
client.code_at(block_hash).ok().map(|c| ValidationCode::from(c).hash())
},
sync_oracle, sync_oracle,
keystore, keystore,
collator_key, collator_key,
@@ -1016,12 +1023,10 @@ pub async fn start_rococo_parachain_node(
relay_chain_slot_duration, relay_chain_slot_duration,
proposer, proposer,
collator_service, collator_service,
// Very limited proposal time. authoring_duration: Duration::from_millis(1500),
authoring_duration: Duration::from_millis(500),
collation_request_receiver: None,
}; };
let fut = basic_aura::run::< let fut = aura::run::<
Block, Block,
sp_consensus_aura::sr25519::AuthorityPair, sp_consensus_aura::sr25519::AuthorityPair,
_, _,
@@ -1031,6 +1036,8 @@ pub async fn start_rococo_parachain_node(
_, _,
_, _,
_, _,
_,
_,
>(params); >(params);
task_manager.spawn_essential_handle().spawn("aura", None, fut); task_manager.spawn_essential_handle().spawn("aura", None, fut);
@@ -1376,7 +1383,8 @@ where
para_id, para_id,
collator_key, collator_key,
overseer_handle, overseer_handle,
announce_block| { announce_block,
_backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
@@ -1471,7 +1479,8 @@ where
para_id, para_id,
collator_key, collator_key,
overseer_handle, overseer_handle,
announce_block| { announce_block,
_backend| {
let relay_chain_interface2 = relay_chain_interface.clone(); let relay_chain_interface2 = relay_chain_interface.clone();
let collator_service = CollatorService::new( let collator_service = CollatorService::new(
@@ -1642,7 +1651,7 @@ where
para_backend: backend.clone(), para_backend: backend.clone(),
relay_client: relay_chain_interface, relay_client: relay_chain_interface,
code_hash_provider: move |block_hash| { 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())
}, },
sync_oracle, sync_oracle,
keystore, keystore,
@@ -1713,6 +1722,7 @@ where
CollatorPair, CollatorPair,
OverseerHandle, OverseerHandle,
Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>, Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
Arc<ParachainBackend>,
) -> Result<(), sc_service::Error>, ) -> Result<(), sc_service::Error>,
{ {
let parachain_config = prepare_node_config(parachain_config); let parachain_config = prepare_node_config(parachain_config);
@@ -1845,6 +1855,7 @@ where
collator_key.expect("Command line arguments do not allow this. qed"), collator_key.expect("Command line arguments do not allow this. qed"),
overseer_handle, overseer_handle,
announce_block, announce_block,
backend.clone(),
)?; )?;
} }
@@ -1923,7 +1934,8 @@ pub async fn start_contracts_rococo_node(
para_id, para_id,
collator_key, collator_key,
overseer_handle, overseer_handle,
announce_block| { announce_block,
_backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(