parachain-template: Simplify it (#3801)

Also while doing this, move slot duration fetching into the AURA code.
This commit is contained in:
Bastian Köcher
2024-04-09 11:43:42 +02:00
committed by GitHub
parent 9d6c0f446a
commit 22b95a8a55
6 changed files with 125 additions and 165 deletions
@@ -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;
@@ -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.
@@ -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,
)
@@ -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)>,
@@ -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,
@@ -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>,
@@ -240,7 +244,6 @@ where
client,
create_inherent_data_providers,
defender: NaiveEquivocationDefender::default(),
slot_duration,
telemetry,
_phantom: std::marker::PhantomData,
};