Skip to content

Commit

Permalink
Update tick collator for async backing (#1497)
Browse files Browse the repository at this point in the history
This updates the tick runtime and polkadot-parachain collator to use
async backing.
  • Loading branch information
Sophia-Gold authored Nov 21, 2023
1 parent f5ad32e commit 50811d6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system
cumulus-pallet-xcm = { path = "../../../../pallets/xcm", default-features = false }
cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", 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-utility = { path = "../../../../primitives/utility", default-features = false }
parachains-common = { path = "../../../common", default-features = false }
Expand All @@ -70,6 +71,7 @@ std = [
"cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-ping/std",
"cumulus-primitives-aura/std",
"cumulus-primitives-core/std",
"cumulus-primitives-utility/std",
"frame-benchmarking?/std",
Expand Down
47 changes: 29 additions & 18 deletions cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
#[cfg(feature = "std")]
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 sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata;
use sp_runtime::{
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},
ApplyExtrinsicResult,
};
Expand Down Expand Up @@ -113,7 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
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;

Expand Down Expand Up @@ -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
/// by Operational extrinsics.
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(
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,
);

/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
/// 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
/// number of blocks authored per slot.
const BLOCK_PROCESSING_VELOCITY: u32 = 1;
const BLOCK_PROCESSING_VELOCITY: u32 = 2;
/// Relay chain slot duration, in milliseconds.
const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;

Expand Down Expand Up @@ -277,6 +277,13 @@ parameter_types! {
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 {
type WeightInfo = ();
type RuntimeEvent = RuntimeEvent;
Expand All @@ -287,13 +294,8 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedDmpWeight = ReservedDmpWeight;
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;
}

impl parachain_info::Config for Runtime {}
Expand Down Expand Up @@ -584,9 +586,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>;
}

construct_runtime! {
Expand Down Expand Up @@ -624,7 +626,7 @@ pub type Balance = u128;
/// Index of a transaction in the chain.
pub type Nonce = u32;
/// 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.
pub type BlockNumber = u32;
/// The address format for describing accounts.
Expand Down Expand Up @@ -751,7 +753,7 @@ 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> {
Expand Down Expand Up @@ -824,6 +826,15 @@ impl_runtime_apis! {
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! {
Expand Down
34 changes: 23 additions & 11 deletions cumulus/polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ where
CollatorPair,
OverseerHandle,
Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
Arc<ParachainBackend>,
) -> Result<(), sc_service::Error>,
{
let parachain_config = prepare_node_config(parachain_config);
Expand Down Expand Up @@ -723,6 +724,7 @@ where
collator_key.expect("Command line arguments do not allow this. qed"),
overseer_handle,
announce_block,
backend.clone(),
)?;
}

Expand Down Expand Up @@ -983,7 +985,8 @@ pub async fn start_rococo_parachain_node(
para_id,
collator_key,
overseer_handle,
announce_block| {
announce_block,
backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
Expand All @@ -1002,11 +1005,15 @@ pub async fn start_rococo_parachain_node(
client.clone(),
);

let params = BasicAuraParams {
let params = AuraParams {
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import,
para_client: client,
para_client: client.clone(),
para_backend: backend.clone(),
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,
keystore,
collator_key,
Expand All @@ -1016,12 +1023,10 @@ pub async fn start_rococo_parachain_node(
relay_chain_slot_duration,
proposer,
collator_service,
// Very limited proposal time.
authoring_duration: Duration::from_millis(500),
collation_request_receiver: None,
authoring_duration: Duration::from_millis(1500),
};

let fut = basic_aura::run::<
let fut = aura::run::<
Block,
sp_consensus_aura::sr25519::AuthorityPair,
_,
Expand All @@ -1031,6 +1036,8 @@ pub async fn start_rococo_parachain_node(
_,
_,
_,
_,
_,
>(params);
task_manager.spawn_essential_handle().spawn("aura", None, fut);

Expand Down Expand Up @@ -1376,7 +1383,8 @@ where
para_id,
collator_key,
overseer_handle,
announce_block| {
announce_block,
_backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
Expand Down Expand Up @@ -1471,7 +1479,8 @@ where
para_id,
collator_key,
overseer_handle,
announce_block| {
announce_block,
_backend| {
let relay_chain_interface2 = relay_chain_interface.clone();

let collator_service = CollatorService::new(
Expand Down Expand Up @@ -1642,7 +1651,7 @@ where
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())
},
sync_oracle,
keystore,
Expand Down Expand Up @@ -1713,6 +1722,7 @@ where
CollatorPair,
OverseerHandle,
Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
Arc<ParachainBackend>,
) -> Result<(), sc_service::Error>,
{
let parachain_config = prepare_node_config(parachain_config);
Expand Down Expand Up @@ -1845,6 +1855,7 @@ where
collator_key.expect("Command line arguments do not allow this. qed"),
overseer_handle,
announce_block,
backend.clone(),
)?;
}

Expand Down Expand Up @@ -1923,7 +1934,8 @@ pub async fn start_contracts_rococo_node(
para_id,
collator_key,
overseer_handle,
announce_block| {
announce_block,
_backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
Expand Down

0 comments on commit 50811d6

Please sign in to comment.