Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dynamic aura slot duration in lookahead collator #3211

Merged
merged 10 commits into from
Feb 13, 2024
60 changes: 33 additions & 27 deletions cumulus/client/consensus/aura/src/collators/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use sp_api::ProvideRuntimeApi;
use sp_application_crypto::AppPublic;
use sp_blockchain::HeaderBackend;
use sp_consensus::SyncOracle;
use sp_consensus_aura::{AuraApi, Slot, SlotDuration};
use sp_consensus_aura::{AuraApi, Slot};
use sp_core::crypto::Pair;
use sp_inherents::CreateInherentDataProviders;
use sp_keystore::KeystorePtr;
Expand Down Expand Up @@ -95,8 +95,6 @@ pub struct Params<BI, CIDP, Client, Backend, RClient, CHP, SO, Proposer, CS> {
pub para_id: ParaId,
/// A handle to the relay-chain client's "Overseer" or task orchestrator.
pub overseer_handle: OverseerHandle,
/// The length of slots in this chain.
pub slot_duration: SlotDuration,
/// The length of slots in the relay chain.
pub relay_chain_slot_duration: Duration,
/// The underlying block proposer this should call into.
Expand Down Expand Up @@ -214,26 +212,6 @@ where
},
};

let (slot_now, timestamp) = match consensus_common::relay_slot_and_timestamp(
&relay_parent_header,
params.relay_chain_slot_duration,
) {
None => continue,
Some((r_s, t)) => {
let our_slot = Slot::from_timestamp(t, params.slot_duration);
tracing::debug!(
target: crate::LOG_TARGET,
relay_slot = ?r_s,
para_slot = ?our_slot,
timestamp = ?t,
slot_duration = ?params.slot_duration,
relay_chain_slot_duration = ?params.relay_chain_slot_duration,
"Adjusted relay-chain slot to parachain slot"
);
(our_slot, t)
},
};

let parent_search_params = ParentSearchParams {
relay_parent,
para_id: params.para_id,
Expand Down Expand Up @@ -272,14 +250,39 @@ where
let para_client = &*params.para_client;
let keystore = &params.keystore;
let can_build_upon = |block_hash| {
can_build_upon::<_, _, P>(
let slot_duration = match sc_consensus_aura::standalone::slot_duration_at(
&*params.para_client,
block_hash,
) {
Ok(sd) => sd,
Err(err) => {
tracing::error!(target: crate::LOG_TARGET, ?err, "Failed to acquire parachain slot duration");
return None
},
};
tracing::debug!(target: crate::LOG_TARGET, ?slot_duration, ?block_hash, "Parachain slot duration acquired");
let (relay_slot, timestamp) = consensus_common::relay_slot_and_timestamp(
&relay_parent_header,
params.relay_chain_slot_duration,
)?;
let slot_now = Slot::from_timestamp(timestamp, slot_duration);
tracing::debug!(
target: crate::LOG_TARGET,
?relay_slot,
para_slot = ?slot_now,
?timestamp,
?slot_duration,
relay_chain_slot_duration = ?params.relay_chain_slot_duration,
"Adjusted relay-chain slot to parachain slot"
);
Some(can_build_upon::<_, _, P>(
slot_now,
timestamp,
block_hash,
included_block,
para_client,
&keystore,
)
))
};

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

tracing::debug!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ use frame_system::limits::{BlockLength, BlockWeights};
pub use parachains_common as common;
use parachains_common::{
impls::DealWithFees, message_queue::*, AccountId, BlockNumber, Hash, Header, Nonce, Signature,
AVERAGE_ON_INITIALIZE_RATIO, MINUTES, NORMAL_DISPATCH_RATIO,
AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO,
};
pub use parachains_common::{AuraId, Balance};
use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee};
use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee, time::*};
use xcm_config::CollatorSelectionUpdateOrigin;

#[cfg(any(feature = "std", test))]
Expand Down
4 changes: 2 additions & 2 deletions cumulus/parachains/runtimes/people/people-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use parachains_common::{
impls::DealWithFees,
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO,
HOURS, NORMAL_DISPATCH_RATIO,
NORMAL_DISPATCH_RATIO,
};
use polkadot_runtime_common::{identity_migrator, BlockHashCount, SlowAdjustingFeeUpdate};
use sp_api::impl_runtime_apis;
Expand All @@ -63,7 +63,7 @@ use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee};
use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee, time::*};
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use xcm::latest::prelude::BodyId;
use xcm_config::{
Expand Down
21 changes: 0 additions & 21 deletions cumulus/polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,6 @@ pub async fn start_rococo_parachain_node(
overseer_handle,
announce_block,
backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
client.clone(),
Expand Down Expand Up @@ -971,7 +969,6 @@ pub async fn start_rococo_parachain_node(
collator_key,
para_id,
overseer_handle,
slot_duration,
relay_chain_slot_duration,
proposer,
collator_service,
Expand Down Expand Up @@ -1435,8 +1432,6 @@ where
overseer_handle,
announce_block,
backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
client.clone(),
Expand Down Expand Up @@ -1467,7 +1462,6 @@ where
collator_key,
para_id,
overseer_handle,
slot_duration,
relay_chain_slot_duration,
proposer,
collator_service,
Expand Down Expand Up @@ -1737,14 +1731,6 @@ where
}

// Move to Aura consensus.
let slot_duration = match cumulus_client_consensus_aura::slot_duration(&*client) {
Ok(d) => d,
Err(e) => {
log::error!("Could not get Aura slot duration: {e}");
return
},
};

let proposer = Proposer::new(proposer_factory);

let params = AuraParams {
Expand All @@ -1761,7 +1747,6 @@ where
collator_key,
para_id,
overseer_handle,
slot_duration,
relay_chain_slot_duration,
proposer,
collator_service,
Expand Down Expand Up @@ -1832,8 +1817,6 @@ where
overseer_handle,
announce_block,
backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
client.clone(),
Expand Down Expand Up @@ -1864,7 +1847,6 @@ where
collator_key,
para_id,
overseer_handle,
slot_duration,
relay_chain_slot_duration,
proposer,
collator_service,
Expand Down Expand Up @@ -2141,8 +2123,6 @@ pub async fn start_contracts_rococo_node(
overseer_handle,
announce_block,
backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
client.clone(),
Expand Down Expand Up @@ -2173,7 +2153,6 @@ pub async fn start_contracts_rococo_node(
collator_key,
para_id,
overseer_handle,
slot_duration,
relay_chain_slot_duration,
proposer,
collator_service,
Expand Down
Loading