Skip to content

Commit 17c9611

Browse files
committed
update client/runtime
1 parent 150b11c commit 17c9611

File tree

12 files changed

+169
-136
lines changed

12 files changed

+169
-136
lines changed

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk",
227227
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
228228
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
229229
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
230+
cumulus-primitives-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
230231
cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
231232
cumulus-primitives-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
232233
cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }

bin/collator/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ cumulus-client-consensus-proposer = { workspace = true }
116116
cumulus-client-consensus-relay-chain = { workspace = true }
117117
cumulus-client-network = { workspace = true }
118118
cumulus-client-service = { workspace = true }
119+
cumulus-primitives-aura = { workspace = true }
119120
cumulus-primitives-core = { workspace = true, features = ["std"] }
120121
cumulus-primitives-parachain-inherent = { workspace = true }
121122
cumulus-relay-chain-inprocess-interface = { workspace = true }

bin/collator/src/parachain/service.rs

+32-16
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,24 @@
2020
2121
use astar_primitives::*;
2222
use cumulus_client_cli::CollatorOptions;
23-
use cumulus_client_consensus_aura::collators::basic as basic_aura;
23+
use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams};
2424
use cumulus_client_consensus_common::ParachainBlockImport;
2525
use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier;
2626
use cumulus_client_service::{
2727
prepare_node_config, start_relay_chain_tasks, BuildNetworkParams, DARecoveryProfile,
2828
StartRelayChainTasksParams,
2929
};
30-
use cumulus_primitives_core::ParaId;
30+
use cumulus_primitives_aura::AuraUnincludedSegmentApi;
31+
use cumulus_primitives_core::{
32+
relay_chain::{CollatorPair, ValidationCode},
33+
ParaId,
34+
};
3135
use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;
3236
use cumulus_relay_chain_interface::{RelayChainInterface, RelayChainResult};
3337
use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node_with_rpc;
3438
use fc_consensus::FrontierBlockImport;
3539
use fc_rpc_core::types::{FeeHistoryCache, FilterPool};
3640
use futures::StreamExt;
37-
use polkadot_service::CollatorPair;
3841
use sc_client_api::BlockchainEvents;
3942
use sc_consensus::{import_queue::BasicQueue, ImportQueue};
4043
use sc_executor::NativeElseWasmExecutor;
@@ -351,6 +354,7 @@ where
351354
) -> Result<sc_consensus::DefaultImportQueue<Block>, sc_service::Error>,
352355
SC: FnOnce(
353356
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
357+
Arc<TFullBackend<Block>>,
354358
ParachainBlockImport<
355359
Block,
356360
FrontierBlockImport<
@@ -562,6 +566,7 @@ where
562566
if is_authority {
563567
start_consensus(
564568
client.clone(),
569+
backend.clone(),
565570
parachain_block_import,
566571
prometheus_registry.as_ref(),
567572
telemetry.map(|t| t.handle()),
@@ -1066,6 +1071,7 @@ where
10661071
/// Start collating with the `shell` runtime while waiting for an upgrade to an Aura compatible runtime.
10671072
fn start_aura_consensus_fallback<RuntimeApi, Executor>(
10681073
client: Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
1074+
backend: Arc<TFullBackend<Block>>,
10691075
parachain_block_import: ParachainBlockImport<
10701076
Block,
10711077
FrontierBlockImport<
@@ -1104,6 +1110,7 @@ where
11041110
+ sp_block_builder::BlockBuilder<Block>
11051111
+ fp_rpc::EthereumRuntimeRPCApi<Block>
11061112
+ AuraApi<Block, AuraId>
1113+
+ AuraUnincludedSegmentApi<Block>
11071114
+ cumulus_primitives_core::CollectCollationInfo<Block>,
11081115
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>:
11091116
sc_client_api::StateBackend<BlakeTwo256>,
@@ -1171,9 +1178,6 @@ where
11711178
}
11721179

11731180
// Move to Aura consensus.
1174-
let slot_duration =
1175-
cumulus_client_consensus_aura::slot_duration(&*client).expect("aura is present; qed");
1176-
11771181
let announce_block = {
11781182
let sync_service = sync_oracle.clone();
11791183
Arc::new(move |hash, data| sync_service.announce_block(hash, data))
@@ -1186,23 +1190,28 @@ where
11861190
client.clone(),
11871191
);
11881192

1189-
basic_aura::run::<Block, AuraPair, _, _, _, _, _, _, _>(basic_aura::Params {
1193+
aura::run::<Block, AuraPair, _, _, _, _, _, _, _, _, _>(AuraParams {
11901194
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
11911195
block_import: parachain_block_import.clone(),
11921196
para_client: client.clone(),
1197+
para_backend: backend,
11931198
relay_client: relay_chain_interface.clone(),
1199+
code_hash_provider: move |block_hash| {
1200+
client
1201+
.code_at(block_hash)
1202+
.ok()
1203+
.map(|c| ValidationCode::from(c).hash())
1204+
},
11941205
sync_oracle: sync_oracle.clone(),
11951206
keystore,
11961207
collator_key,
11971208
para_id,
11981209
overseer_handle,
1199-
slot_duration,
12001210
relay_chain_slot_duration: Duration::from_secs(6),
12011211
proposer: cumulus_client_consensus_proposer::Proposer::new(proposer_factory),
12021212
collator_service,
1203-
// We got around 500ms for proposing
1204-
authoring_duration: Duration::from_millis(500),
1205-
collation_request_receiver: Some(request_stream),
1213+
authoring_duration: Duration::from_millis(2000),
1214+
reinitialize: true,
12061215
})
12071216
.await
12081217
});
@@ -1215,6 +1224,7 @@ where
12151224

12161225
fn start_aura_consensus<RuntimeApi, Executor>(
12171226
client: Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
1227+
backend: Arc<TFullBackend<Block>>,
12181228
parachain_block_import: ParachainBlockImport<
12191229
Block,
12201230
FrontierBlockImport<
@@ -1253,6 +1263,7 @@ where
12531263
+ sp_block_builder::BlockBuilder<Block>
12541264
+ fp_rpc::EthereumRuntimeRPCApi<Block>
12551265
+ AuraApi<Block, AuraId>
1266+
+ AuraUnincludedSegmentApi<Block>
12561267
+ cumulus_primitives_core::CollectCollationInfo<Block>,
12571268
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>:
12581269
sc_client_api::StateBackend<BlakeTwo256>,
@@ -1287,23 +1298,28 @@ where
12871298
client.clone(),
12881299
);
12891300

1290-
let fut = basic_aura::run::<Block, AuraPair, _, _, _, _, _, _, _>(basic_aura::Params {
1301+
let fut = aura::run::<Block, AuraPair, _, _, _, _, _, _, _, _, _>(AuraParams {
12911302
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
12921303
block_import: parachain_block_import.clone(),
12931304
para_client: client.clone(),
1305+
para_backend: backend,
12941306
relay_client: relay_chain_interface.clone(),
1307+
code_hash_provider: move |block_hash| {
1308+
client
1309+
.code_at(block_hash)
1310+
.ok()
1311+
.map(|c| ValidationCode::from(c).hash())
1312+
},
12951313
sync_oracle: sync_oracle.clone(),
12961314
keystore,
12971315
collator_key,
12981316
para_id,
12991317
overseer_handle,
1300-
slot_duration: cumulus_client_consensus_aura::slot_duration(&*client)?,
13011318
relay_chain_slot_duration: Duration::from_secs(6),
13021319
proposer: cumulus_client_consensus_proposer::Proposer::new(proposer_factory),
13031320
collator_service,
1304-
// We got around 500ms for proposing
1305-
authoring_duration: Duration::from_millis(500),
1306-
collation_request_receiver: None,
1321+
authoring_duration: Duration::from_millis(2000),
1322+
reinitialize: false,
13071323
});
13081324

13091325
task_manager

runtime/astar/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ pallet-xcm-benchmarks = { workspace = true, optional = true }
7373
# cumulus dependencies
7474
cumulus-pallet-aura-ext = { workspace = true }
7575
cumulus-pallet-dmp-queue = { workspace = true }
76-
cumulus-pallet-parachain-system = { workspace = true }
76+
cumulus-pallet-parachain-system = { workspace = true, features = ["parameterized-consensus-hook"] }
7777
cumulus-pallet-xcm = { workspace = true }
7878
cumulus-pallet-xcmp-queue = { workspace = true }
79+
cumulus-primitives-aura = { workspace = true }
7980
cumulus-primitives-core = { workspace = true }
8081
cumulus-primitives-timestamp = { workspace = true }
8182
cumulus-primitives-utility = { workspace = true }
@@ -203,6 +204,7 @@ std = [
203204
"polkadot-parachain/std",
204205
"polkadot-primitives/std",
205206
"polkadot-runtime-common/std",
207+
"cumulus-primitives-aura/std",
206208
"cumulus-primitives-core/std",
207209
"cumulus-primitives-utility/std",
208210
"cumulus-primitives-timestamp/std",
@@ -339,6 +341,8 @@ evm-tracing = [
339341
"moonbeam-rpc-primitives-txpool",
340342
]
341343

344+
experimental = ["pallet-aura/experimental"]
345+
342346
# Enable metadata hash generation at compile time for the `CheckMetadataHash` extension.
343347
metadata-hash = ["substrate-wasm-builder?/metadata-hash"]
344348

runtime/astar/src/lib.rs

+35-34
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@
2222
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
2323
#![recursion_limit = "256"]
2424

25-
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
2625
use cumulus_primitives_core::AggregateMessageOrigin;
2726
use frame_support::{
2827
construct_runtime,
2928
dispatch::DispatchClass,
3029
genesis_builder_helper::{build_config, create_default_config},
3130
parameter_types,
3231
traits::{
33-
AsEnsureOriginWithArg, ConstBool, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance,
34-
InstanceFilter, Nothing, OnFinalize, OnUnbalanced, Randomness, WithdrawReasons,
32+
AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, Contains, Currency, FindAuthor, Get,
33+
Imbalance, InstanceFilter, Nothing, OnFinalize, OnUnbalanced, Randomness, WithdrawReasons,
3534
},
3635
weights::{
3736
constants::{
@@ -131,11 +130,21 @@ pub const fn contracts_deposit(items: u32, bytes: u32) -> Balance {
131130

132131
/// Change this to adjust the block time.
133132
pub const MILLISECS_PER_BLOCK: u64 = 12000;
133+
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
134134
// Time is measured by number of blocks.
135135
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
136136
pub const HOURS: BlockNumber = MINUTES * 60;
137137
pub const DAYS: BlockNumber = HOURS * 24;
138138

139+
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the
140+
/// relay chain.
141+
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
142+
/// How many parachain blocks are processed by the relay chain per parent. Limits the number of
143+
/// blocks authored per slot.
144+
pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
145+
/// Relay chain slot duration, in milliseconds.
146+
pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
147+
139148
// Make the WASM binary available.
140149
#[cfg(feature = "std")]
141150
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
@@ -461,23 +470,28 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
461470
type ReservedDmpWeight = ReservedDmpWeight;
462471
type XcmpMessageHandler = XcmpQueue;
463472
type ReservedXcmpWeight = ReservedXcmpWeight;
464-
type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases;
473+
type CheckAssociatedRelayNumber =
474+
cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
475+
type ConsensusHook = ConsensusHook;
465476
type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight<Runtime>;
466477
}
467478

468-
impl parachain_info::Config for Runtime {}
479+
type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
480+
Runtime,
481+
RELAY_CHAIN_SLOT_DURATION_MILLIS,
482+
BLOCK_PROCESSING_VELOCITY,
483+
UNINCLUDED_SEGMENT_CAPACITY,
484+
>;
469485

470-
parameter_types! {
471-
pub const MaxAuthorities: u32 = 250;
472-
}
486+
impl parachain_info::Config for Runtime {}
473487

474488
impl pallet_aura::Config for Runtime {
475489
type AuthorityId = AuraId;
476490
type DisabledValidators = ();
477-
type MaxAuthorities = MaxAuthorities;
478-
// Should be only enabled (`true`) when async backing is enabled
479-
// otherwise set to `false`
491+
type MaxAuthorities = ConstU32<250>;
480492
type AllowMultipleBlocksPerSlot = ConstBool<false>;
493+
#[cfg(feature = "experimental")]
494+
type SlotDuration = ConstU64<SLOT_DURATION>;
481495
}
482496

483497
impl cumulus_pallet_aura_ext::Config for Runtime {}
@@ -1387,14 +1401,23 @@ impl_runtime_apis! {
13871401

13881402
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
13891403
fn slot_duration() -> sp_consensus_aura::SlotDuration {
1390-
sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
1404+
sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
13911405
}
13921406

13931407
fn authorities() -> Vec<AuraId> {
13941408
Aura::authorities().into_inner()
13951409
}
13961410
}
13971411

1412+
impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
1413+
fn can_build_upon(
1414+
included_hash: <Block as BlockT>::Hash,
1415+
slot: cumulus_primitives_aura::Slot,
1416+
) -> bool {
1417+
ConsensusHook::can_build_upon(included_hash, slot)
1418+
}
1419+
}
1420+
13981421
impl sp_block_builder::BlockBuilder<Block> for Runtime {
13991422
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
14001423
Executive::apply_extrinsic(extrinsic)
@@ -2185,29 +2208,7 @@ impl_runtime_apis! {
21852208
}
21862209
}
21872210

2188-
struct CheckInherents;
2189-
2190-
impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {
2191-
fn check_inherents(
2192-
block: &Block,
2193-
relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,
2194-
) -> sp_inherents::CheckInherentsResult {
2195-
let relay_chain_slot = relay_state_proof
2196-
.read_slot()
2197-
.expect("Could not read the relay chain slot from the proof");
2198-
let inherent_data =
2199-
cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(
2200-
relay_chain_slot,
2201-
sp_std::time::Duration::from_secs(6),
2202-
)
2203-
.create_inherent_data()
2204-
.expect("Could not create the timestamp inherent data");
2205-
inherent_data.check_extrinsics(block)
2206-
}
2207-
}
2208-
22092211
cumulus_pallet_parachain_system::register_validate_block! {
22102212
Runtime = Runtime,
22112213
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
2212-
CheckInherents = CheckInherents,
22132214
}

runtime/local/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ evm-tracing = [
276276
"moonbeam-rpc-primitives-txpool",
277277
]
278278

279+
experimental = ["pallet-aura/experimental"]
280+
279281
# Enable metadata hash generation at compile time for the `CheckMetadataHash` extension.
280282
metadata-hash = ["substrate-wasm-builder?/metadata-hash"]
281283

0 commit comments

Comments
 (0)