Skip to content

Commit ec6bf5d

Browse files
Use dynamic aura slot duration in lookahead collator (#3211)
It's a follow-up of #2949. It enables the lookahead collator to dynamically adjust the aura slot size, which may change during the runtime upgrade. It also addressed a couple of issues with time constants I missed in the original PR. Good news: it works. The parachain successfully switches from sync backing with 12s slots to async backing with 6s slots. Bad news: during the transitional period of a single block in which the actual runtime upgrade is performed, it still gets the old slot duration of 12s (as it gets it from the best block), resulting in a runtime panic (logs follow). That doesn't affect the following block production of the parachain. Ideas on how to improve the situation are appreciated. <details> ``` 2024-02-05 12:59:36.373 INFO tokio-runtime-worker sc_basic_authorship::basic_authorship: [Parachain] 🙌 Starting consensus session on top of parent 0x6fd2d8f904f12c22531bfabf77b16dc84a6a29e45d9ae358aa6547fbf3f0438b 2024-02-05 12:59:36.373 ERROR tokio-runtime-worker runtime: [Parachain] panicked at /home/s0me0ne/wrk/parity/polkadot-sdk/cumulus/pallets/aura-ext/src/consensus_hook.rs:69:9: assertion `left == right` failed: slot number mismatch left: Slot(142261198) right: Slot(284522396) 2024-02-05 12:59:36.373 WARN tokio-runtime-worker sp_state_machine::overlayed_changes::changeset: [Parachain] 1 storage transactions are left open by the runtime. Those will be rolled back. 2024-02-05 12:59:36.373 WARN tokio-runtime-worker sp_state_machine::overlayed_changes::changeset: [Parachain] 1 storage transactions are left open by the runtime. Those will be rolled back. 2024-02-05 12:59:36.373 WARN tokio-runtime-worker basic-authorship: [Parachain] ❗ Inherent extrinsic returned unexpected error: Error at calling runtime api: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed WASM backtrace: error while executing at wasm backtrace: 0: 0x4e4a3b - <unknown>!rust_begin_unwind 1: 0x46cf57 - <unknown>!core::panicking::panic_fmt::h3c280dba88683724 2: 0x46d238 - <unknown>!core::panicking::assert_failed_inner::hebac5970933beb4d 3: 0x3d00fc - <unknown>!core::panicking::assert_failed::h640a47e2fb5dfb4b 4: 0xd0db3 - <unknown>!frame_support::storage::transactional::with_transaction::hcbc31515f81b2ee1 5: 0x34d654 - <unknown>!<cumulus_pallet_parachain_system::pallet::Call<T> as frame_support::traits::dispatch::UnfilteredDispatchable>::dispatch_bypass_filter::{{closure}}::hb7c2c9a11fa88301 6: 0x3547db - <unknown>!environmental::local_key::LocalKey<T>::with::h783f2605ae27d6d3 7: 0x7f454 - <unknown>!<asset_hub_rococo_runtime::RuntimeCall as frame_support::traits::dispatch::UnfilteredDispatchable>::dispatch_bypass_filter::h5e11a01ab97c06c7 8: 0x7f237 - <unknown>!<asset_hub_rococo_runtime::RuntimeCall as sp_runtime::traits::Dispatchable>::dispatch::h7f8ae4a8fede71ca 9: 0x26a0f3 - <unknown>!frame_executive::Executive<System,Block,Context,UnsignedValidator,AllPalletsWithSystem,COnRuntimeUpgrade>::apply_extrinsic::h75e524ff34738391 10: 0x282211 - <unknown>!BlockBuilder_apply_extrinsic. Dropping. 2024-02-05 12:59:36.374 ERROR tokio-runtime-worker runtime: [Parachain] panicked at /home/s0me0ne/wrk/parity/polkadot-sdk/substrate/frame/aura/src/lib.rs:416:9: assertion `left == right` failed: Timestamp slot must match `CurrentSlot` left: Slot(142261198) right: Slot(284522396) 2024-02-05 12:59:36.374 WARN tokio-runtime-worker sp_state_machine::overlayed_changes::changeset: [Parachain] 1 storage transactions are left open by the runtime. Those will be rolled back. 2024-02-05 12:59:36.374 WARN tokio-runtime-worker sp_state_machine::overlayed_changes::changeset: [Parachain] 1 storage transactions are left open by the runtime. Those will be rolled back. 2024-02-05 12:59:36.374 WARN tokio-runtime-worker basic-authorship: [Parachain] ❗ Inherent extrinsic returned unexpected error: Error at calling runtime api: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed WASM backtrace: error while executing at wasm backtrace: 0: 0x4e4a3b - <unknown>!rust_begin_unwind 1: 0x46cf57 - <unknown>!core::panicking::panic_fmt::h3c280dba88683724 2: 0x46d238 - <unknown>!core::panicking::assert_failed_inner::hebac5970933beb4d 3: 0x3d00fc - <unknown>!core::panicking::assert_failed::h640a47e2fb5dfb4b 4: 0x9ece6 - <unknown>!frame_support::storage::transactional::with_transaction::h26f75cb9f9462088 5: 0x356d7e - <unknown>!environmental::local_key::LocalKey<T>::with::hbcf2d4e17b48fdb5 6: 0x7f507 - <unknown>!<asset_hub_rococo_runtime::RuntimeCall as frame_support::traits::dispatch::UnfilteredDispatchable>::dispatch_bypass_filter::h5e11a01ab97c06c7 7: 0x7f237 - <unknown>!<asset_hub_rococo_runtime::RuntimeCall as sp_runtime::traits::Dispatchable>::dispatch::h7f8ae4a8fede71ca 8: 0x26a0f3 - <unknown>!frame_executive::Executive<System,Block,Context,UnsignedValidator,AllPalletsWithSystem,COnRuntimeUpgrade>::apply_extrinsic::h75e524ff34738391 9: 0x282211 - <unknown>!BlockBuilder_apply_extrinsic. Dropping. 2024-02-05 12:59:36.374 DEBUG tokio-runtime-worker runtime::xcmp-queue-migration: [Parachain] Lazy migration finished: item gone 2024-02-05 12:59:36.374 ERROR tokio-runtime-worker runtime: [Parachain] panicked at /home/s0me0ne/wrk/parity/polkadot-sdk/cumulus/pallets/parachain-system/src/lib.rs:265:18: set_validation_data inherent needs to be present in every block! 2024-02-05 12:59:36.374 ERROR tokio-runtime-worker aura::cumulus: [Parachain] err=Error { inner: Proposing Caused by: 0: Error at calling runtime api: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed WASM backtrace: error while executing at wasm backtrace: 0: 0x4e4a3b - <unknown>!rust_begin_unwind 1: 0x46cf57 - <unknown>!core::panicking::panic_fmt::h3c280dba88683724 2: 0x46da8b - <unknown>!core::option::expect_failed::hdf18d99c3adabca7 3: 0x2134cb - <unknown>!<cumulus_pallet_parachain_system::pallet::Pallet<T> as frame_support::traits::hooks::OnFinalize<<<<T as frame_system::pallet::Config>::Block as sp_runtime::traits::HeaderProvider>::HeaderT as sp_runtime::traits::Header>::Number>>::on_finalize::hf98aac39802896ba 4: 0x26a9d6 - <unknown>!frame_executive::Executive<System,Block,Context,UnsignedValidator,AllPalletsWithSystem,COnRuntimeUpgrade>::idle_and_finalize_hook::h32775c0df0749d92 5: 0x26ad9f - <unknown>!frame_executive::Executive<System,Block,Context,UnsignedValidator,AllPalletsWithSystem,COnRuntimeUpgrade>::finalize_block::h15e5a1a6b9ca8032 6: 0x2822bd - <unknown>!BlockBuilder_finalize_block 1: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed WASM backtrace: error while executing at wasm backtrace: 0: 0x4e4a3b - <unknown>!rust_begin_unwind 1: 0x46cf57 - <unknown>!core::panicking::panic_fmt::h3c280dba88683724 2: 0x46da8b - <unknown>!core::option::expect_failed::hdf18d99c3adabca7 3: 0x2134cb - <unknown>!<cumulus_pallet_parachain_system::pallet::Pallet<T> as frame_support::traits::hooks::OnFinalize<<<<T as frame_system::pallet::Config>::Block as sp_runtime::traits::HeaderProvider>::HeaderT as sp_runtime::traits::Header>::Number>>::on_finalize::hf98aac39802896ba 4: 0x26a9d6 - <unknown>!frame_executive::Executive<System,Block,Context,UnsignedValidator,AllPalletsWithSystem,COnRuntimeUpgrade>::idle_and_finalize_hook::h32775c0df0749d92 5: 0x26ad9f - <unknown>!frame_executive::Executive<System,Block,Context,UnsignedValidator,AllPalletsWithSystem,COnRuntimeUpgrade>::finalize_block::h15e5a1a6b9ca8032 6: 0x2822bd - <unknown>!BlockBuilder_finalize_block } ``` </details> --------- Co-authored-by: Bastian Köcher <git@kchr.de>
1 parent 349132f commit ec6bf5d

File tree

4 files changed

+37
-52
lines changed
  • cumulus

4 files changed

+37
-52
lines changed

cumulus/client/consensus/aura/src/collators/lookahead.rs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use sp_api::ProvideRuntimeApi;
5959
use sp_application_crypto::AppPublic;
6060
use sp_blockchain::HeaderBackend;
6161
use sp_consensus::SyncOracle;
62-
use sp_consensus_aura::{AuraApi, Slot, SlotDuration};
62+
use sp_consensus_aura::{AuraApi, Slot};
6363
use sp_core::crypto::Pair;
6464
use sp_inherents::CreateInherentDataProviders;
6565
use sp_keystore::KeystorePtr;
@@ -95,8 +95,6 @@ pub struct Params<BI, CIDP, Client, Backend, RClient, CHP, SO, Proposer, CS> {
9595
pub para_id: ParaId,
9696
/// A handle to the relay-chain client's "Overseer" or task orchestrator.
9797
pub overseer_handle: OverseerHandle,
98-
/// The length of slots in this chain.
99-
pub slot_duration: SlotDuration,
10098
/// The length of slots in the relay chain.
10199
pub relay_chain_slot_duration: Duration,
102100
/// The underlying block proposer this should call into.
@@ -214,26 +212,6 @@ where
214212
},
215213
};
216214

217-
let (slot_now, timestamp) = match consensus_common::relay_slot_and_timestamp(
218-
&relay_parent_header,
219-
params.relay_chain_slot_duration,
220-
) {
221-
None => continue,
222-
Some((r_s, t)) => {
223-
let our_slot = Slot::from_timestamp(t, params.slot_duration);
224-
tracing::debug!(
225-
target: crate::LOG_TARGET,
226-
relay_slot = ?r_s,
227-
para_slot = ?our_slot,
228-
timestamp = ?t,
229-
slot_duration = ?params.slot_duration,
230-
relay_chain_slot_duration = ?params.relay_chain_slot_duration,
231-
"Adjusted relay-chain slot to parachain slot"
232-
);
233-
(our_slot, t)
234-
},
235-
};
236-
237215
let parent_search_params = ParentSearchParams {
238216
relay_parent,
239217
para_id: params.para_id,
@@ -272,14 +250,39 @@ where
272250
let para_client = &*params.para_client;
273251
let keystore = &params.keystore;
274252
let can_build_upon = |block_hash| {
275-
can_build_upon::<_, _, P>(
253+
let slot_duration = match sc_consensus_aura::standalone::slot_duration_at(
254+
&*params.para_client,
255+
block_hash,
256+
) {
257+
Ok(sd) => sd,
258+
Err(err) => {
259+
tracing::error!(target: crate::LOG_TARGET, ?err, "Failed to acquire parachain slot duration");
260+
return None
261+
},
262+
};
263+
tracing::debug!(target: crate::LOG_TARGET, ?slot_duration, ?block_hash, "Parachain slot duration acquired");
264+
let (relay_slot, timestamp) = consensus_common::relay_slot_and_timestamp(
265+
&relay_parent_header,
266+
params.relay_chain_slot_duration,
267+
)?;
268+
let slot_now = Slot::from_timestamp(timestamp, slot_duration);
269+
tracing::debug!(
270+
target: crate::LOG_TARGET,
271+
?relay_slot,
272+
para_slot = ?slot_now,
273+
?timestamp,
274+
?slot_duration,
275+
relay_chain_slot_duration = ?params.relay_chain_slot_duration,
276+
"Adjusted relay-chain slot to parachain slot"
277+
);
278+
Some(can_build_upon::<_, _, P>(
276279
slot_now,
277280
timestamp,
278281
block_hash,
279282
included_block,
280283
para_client,
281284
&keystore,
282-
)
285+
))
283286
};
284287

285288
// Sort by depth, ascending, to choose the longest chain.
@@ -301,9 +304,12 @@ where
301304
// This needs to change to support elastic scaling, but for continuously
302305
// scheduled chains this ensures that the backlog will grow steadily.
303306
for n_built in 0..2 {
304-
let slot_claim = match can_build_upon(parent_hash).await {
307+
let slot_claim = match can_build_upon(parent_hash) {
308+
Some(fut) => match fut.await {
309+
None => break,
310+
Some(c) => c,
311+
},
305312
None => break,
306-
Some(c) => c,
307313
};
308314

309315
tracing::debug!(

cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ use frame_system::limits::{BlockLength, BlockWeights};
5858
pub use parachains_common as common;
5959
use parachains_common::{
6060
impls::DealWithFees, message_queue::*, AccountId, BlockNumber, Hash, Header, Nonce, Signature,
61-
AVERAGE_ON_INITIALIZE_RATIO, MINUTES, NORMAL_DISPATCH_RATIO,
61+
AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO,
6262
};
6363
pub use parachains_common::{AuraId, Balance};
64-
use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee};
64+
use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee, time::*};
6565
use xcm_config::CollatorSelectionUpdateOrigin;
6666

6767
#[cfg(any(feature = "std", test))]

cumulus/parachains/runtimes/people/people-rococo/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use parachains_common::{
4444
impls::DealWithFees,
4545
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
4646
AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO,
47-
HOURS, NORMAL_DISPATCH_RATIO,
47+
NORMAL_DISPATCH_RATIO,
4848
};
4949
use polkadot_runtime_common::{identity_migrator, BlockHashCount, SlowAdjustingFeeUpdate};
5050
use sp_api::impl_runtime_apis;
@@ -63,7 +63,7 @@ use sp_std::prelude::*;
6363
#[cfg(feature = "std")]
6464
use sp_version::NativeVersion;
6565
use sp_version::RuntimeVersion;
66-
use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee};
66+
use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee, time::*};
6767
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
6868
use xcm::latest::prelude::BodyId;
6969
use xcm_config::{

cumulus/polkadot-parachain/src/service.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,6 @@ pub async fn start_rococo_parachain_node(
939939
overseer_handle,
940940
announce_block,
941941
backend| {
942-
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
943-
944942
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
945943
task_manager.spawn_handle(),
946944
client.clone(),
@@ -971,7 +969,6 @@ pub async fn start_rococo_parachain_node(
971969
collator_key,
972970
para_id,
973971
overseer_handle,
974-
slot_duration,
975972
relay_chain_slot_duration,
976973
proposer,
977974
collator_service,
@@ -1435,8 +1432,6 @@ where
14351432
overseer_handle,
14361433
announce_block,
14371434
backend| {
1438-
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
1439-
14401435
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
14411436
task_manager.spawn_handle(),
14421437
client.clone(),
@@ -1467,7 +1462,6 @@ where
14671462
collator_key,
14681463
para_id,
14691464
overseer_handle,
1470-
slot_duration,
14711465
relay_chain_slot_duration,
14721466
proposer,
14731467
collator_service,
@@ -1737,14 +1731,6 @@ where
17371731
}
17381732

17391733
// Move to Aura consensus.
1740-
let slot_duration = match cumulus_client_consensus_aura::slot_duration(&*client) {
1741-
Ok(d) => d,
1742-
Err(e) => {
1743-
log::error!("Could not get Aura slot duration: {e}");
1744-
return
1745-
},
1746-
};
1747-
17481734
let proposer = Proposer::new(proposer_factory);
17491735

17501736
let params = AuraParams {
@@ -1761,7 +1747,6 @@ where
17611747
collator_key,
17621748
para_id,
17631749
overseer_handle,
1764-
slot_duration,
17651750
relay_chain_slot_duration,
17661751
proposer,
17671752
collator_service,
@@ -1832,8 +1817,6 @@ where
18321817
overseer_handle,
18331818
announce_block,
18341819
backend| {
1835-
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
1836-
18371820
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
18381821
task_manager.spawn_handle(),
18391822
client.clone(),
@@ -1864,7 +1847,6 @@ where
18641847
collator_key,
18651848
para_id,
18661849
overseer_handle,
1867-
slot_duration,
18681850
relay_chain_slot_duration,
18691851
proposer,
18701852
collator_service,
@@ -2141,8 +2123,6 @@ pub async fn start_contracts_rococo_node(
21412123
overseer_handle,
21422124
announce_block,
21432125
backend| {
2144-
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
2145-
21462126
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
21472127
task_manager.spawn_handle(),
21482128
client.clone(),
@@ -2173,7 +2153,6 @@ pub async fn start_contracts_rococo_node(
21732153
collator_key,
21742154
para_id,
21752155
overseer_handle,
2176-
slot_duration,
21772156
relay_chain_slot_duration,
21782157
proposer,
21792158
collator_service,

0 commit comments

Comments
 (0)