Skip to content

Commit

Permalink
fix: hardcode past slot duration or read from chain
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
  • Loading branch information
gregdhill committed Jul 12, 2023
1 parent 93bfb2a commit 5ab7a74
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dex-stable-rpc-runtime-api = { path = "../crates/dex-stable/rpc/runtime-api" }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sc-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
Expand Down
34 changes: 31 additions & 3 deletions parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use sc_network_sync::SyncingService;
use sc_service::{Configuration, PartialComponents, RpcHandlers, TFullBackend, TFullClient, TaskManager};
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
use sp_api::ConstructRuntimeApi;
use sp_consensus_aura::sr25519::{AuthorityId as AuraId, AuthorityPair as AuraPair};
use sp_consensus_aura::{
sr25519::{AuthorityId as AuraId, AuthorityPair as AuraPair},
SlotDuration,
};
use sp_keystore::KeystorePtr;
use sp_runtime::traits::BlakeTwo256;
use std::{sync::Arc, time::Duration};
Expand Down Expand Up @@ -163,6 +166,29 @@ type MaybeFullSelectChain = Option<LongestChain<FullBackend, Block>>;
type ParachainBlockImport<RuntimeApi, ExecutorDispatch> =
TParachainBlockImport<Block, Arc<FullClient<RuntimeApi, ExecutorDispatch>>, FullBackend>;

fn import_slot_duration<C>(client: &C) -> SlotDuration
where
C: sc_client_api::backend::AuxStore
+ sp_api::ProvideRuntimeApi<Block>
+ sc_client_api::UsageProvider<Block>
+ sp_api::CallApiAt<Block>,
C::Api: sp_consensus_aura::AuraApi<Block, AuraId>,
{
match client.runtime_version_at(client.usage_info().chain.best_hash) {
Ok(x) if x.spec_name.starts_with("kintsugi") && client.usage_info().chain.best_number < 1983993 => {
// the kintsugi runtime was misconfigured at genesis to use a slot duration of 6s
// which stalled collators when we upgraded to polkadot-v0.9.16 and subsequently
// broke mainnet when we introduced the aura timestamp hook, collators should only
// switch when syncing after the (failed) 1.20.0 upgrade
SlotDuration::from_millis(6000)
}
// this is pallet_timestamp::MinimumPeriod * 2 at the current height
// on kintsugi we increased MinimumPeriod from 3_000 to 6_000 at 16_593
// but the interlay runtime has always used 6_000
_ => sc_consensus_aura::slot_duration(&*client).unwrap(),
}
}

/// Starts a `ServiceBuilder` for a full service.
///
/// Use this macro if you don't actually need the full service, but just the builder in order to
Expand Down Expand Up @@ -243,13 +269,15 @@ where
registry,
)
} else {
let slot_duration = import_slot_duration(&*client);

cumulus_client_consensus_aura::import_queue::<AuraPair, _, _, _, _, _>(
cumulus_client_consensus_aura::ImportQueueParams {
block_import: ParachainBlockImport::new(client.clone(), backend.clone()),
client: client.clone(),
create_inherent_data_providers: move |_parent: sp_core::H256, _| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
let slot_duration = sp_consensus_aura::SlotDuration::from_millis(12000);

let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
Expand Down Expand Up @@ -497,7 +525,7 @@ where
sync_oracle,
keystore,
force_authoring| {
let slot_duration = sp_consensus_aura::SlotDuration::from_millis(12000);
let slot_duration = import_slot_duration(&*client);

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
Expand Down

0 comments on commit 5ab7a74

Please sign in to comment.