Skip to content

Commit

Permalink
parachain-template: Simplify it (#3801)
Browse files Browse the repository at this point in the history
Also while doing this, move slot duration fetching into the AURA code.
  • Loading branch information
bkchr authored Apr 9, 2024
1 parent 9d6c0f4 commit 22b95a8
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 165 deletions.
11 changes: 7 additions & 4 deletions cumulus/client/consensus/aura/src/collators/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use sp_api::{CallApiAt, ProvideRuntimeApi};
use sp_application_crypto::AppPublic;
use sp_blockchain::HeaderBackend;
use sp_consensus::SyncOracle;
use sp_consensus_aura::{AuraApi, SlotDuration};
use sp_consensus_aura::AuraApi;
use sp_core::crypto::Pair;
use sp_inherents::CreateInherentDataProviders;
use sp_keystore::KeystorePtr;
Expand Down Expand Up @@ -74,8 +74,6 @@ pub struct Params<BI, CIDP, Client, RClient, 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 @@ -197,11 +195,16 @@ where
Ok(Some(h)) => h,
};

let slot_duration = match params.para_client.runtime_api().slot_duration(parent_hash) {
Ok(d) => d,
Err(e) => reject_with_error!(e),
};

let claim = match collator_util::claim_slot::<_, _, P>(
&*params.para_client,
parent_hash,
&relay_parent_header,
params.slot_duration,
slot_duration,
params.relay_chain_slot_duration,
&params.keystore,
)
Expand Down
11 changes: 7 additions & 4 deletions cumulus/client/consensus/aura/src/equivocation_import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ impl NaiveEquivocationDefender {
struct Verifier<P, Client, Block, CIDP> {
client: Arc<Client>,
create_inherent_data_providers: CIDP,
slot_duration: SlotDuration,
defender: NaiveEquivocationDefender,
telemetry: Option<TelemetryHandle>,
_phantom: std::marker::PhantomData<fn() -> (Block, P)>,
Expand Down Expand Up @@ -110,7 +109,13 @@ where
format!("Could not fetch authorities at {:?}: {}", parent_hash, e)
})?;

let slot_now = slot_now(self.slot_duration);
let slot_duration = self
.client
.runtime_api()
.slot_duration(parent_hash)
.map_err(|e| e.to_string())?;

let slot_now = slot_now(slot_duration);
let res = aura_internal::check_header_slot_and_seal::<Block, P>(
slot_now,
block_params.header,
Expand Down Expand Up @@ -218,7 +223,6 @@ pub fn fully_verifying_import_queue<P, Client, Block: BlockT, I, CIDP>(
client: Arc<Client>,
block_import: I,
create_inherent_data_providers: CIDP,
slot_duration: SlotDuration,
spawner: &impl sp_core::traits::SpawnEssentialNamed,
registry: Option<&substrate_prometheus_endpoint::Registry>,
telemetry: Option<TelemetryHandle>,
Expand All @@ -240,7 +244,6 @@ where
client,
create_inherent_data_providers,
defender: NaiveEquivocationDefender::default(),
slot_duration,
telemetry,
_phantom: std::marker::PhantomData,
};
Expand Down
13 changes: 0 additions & 13 deletions cumulus/polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,6 @@ pub async fn start_generic_aura_node<Net: NetworkBackend<Block, Hash>>(
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 All @@ -746,7 +744,6 @@ pub async fn start_generic_aura_node<Net: NetworkBackend<Block, Hash>>(
collator_key,
para_id,
overseer_handle,
slot_duration,
relay_chain_slot_duration,
proposer,
collator_service,
Expand Down Expand Up @@ -892,15 +889,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 = BasicAuraParams {
Expand All @@ -913,7 +901,6 @@ where
collator_key,
para_id,
overseer_handle,
slot_duration,
relay_chain_slot_duration,
proposer,
collator_service,
Expand Down
10 changes: 10 additions & 0 deletions prdoc/pr_3801.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: "Remove `slot_duration` from `aura::collators::basic::Params`"

doc:
- audience: Node Dev
description: |
Removes the `slot_duration` parameter from the `aura::collators::basic::Params`.
The `slot_duration` will now be fetched from the runtime using the `Aura` runtime api.

crates:
- name: cumulus-client-consensus-aura
7 changes: 0 additions & 7 deletions templates/parachain/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use sc_cli::{
NetworkParams, Result, SharedParams, SubstrateCli,
};
use sc_service::config::{BasePath, PrometheusConfig};
use sp_runtime::traits::AccountIdConversion;

use crate::{
chain_spec,
Expand Down Expand Up @@ -241,17 +240,11 @@ pub fn run() -> Result<()> {

let id = ParaId::from(para_id);

let parachain_account =
AccountIdConversion::<polkadot_primitives::AccountId>::into_account_truncating(
&id,
);

let tokio_handle = config.tokio_handle.clone();
let polkadot_config =
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
.map_err(|err| format!("Relay chain argument error: {}", err))?;

info!("Parachain Account: {parachain_account}");
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });

crate::service::start_parachain_node(
Expand Down
Loading

0 comments on commit 22b95a8

Please sign in to comment.