Skip to content

Commit

Permalink
Merge pull request #1172 from interlay/fix/genesis-slot
Browse files Browse the repository at this point in the history
fix: only adjust kintsugi mainnet slot duration
  • Loading branch information
gregdhill authored Aug 10, 2023
2 parents f77d5b1 + 20e2494 commit 700fcc9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 71 deletions.
2 changes: 1 addition & 1 deletion parachain/runtime/interlay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("interlay-parachain"),
impl_name: create_runtime_str!("interlay-parachain"),
authoring_version: 1,
spec_version: 1025000,
spec_version: 1025001,
impl_version: 1,
transaction_version: 4,
apis: RUNTIME_API_VERSIONS,
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtime/kintsugi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kintsugi-parachain"),
impl_name: create_runtime_str!("kintsugi-parachain"),
authoring_version: 1,
spec_version: 1025000,
spec_version: 1025001,
impl_version: 1,
transaction_version: 4,
apis: RUNTIME_API_VERSIONS,
Expand Down
48 changes: 1 addition & 47 deletions parachain/src/eth.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
use crate::service::{FullBackend, FullClient};
use cumulus_client_consensus_common::ParachainBlockImportMarker;
pub use fc_consensus::FrontierBlockImport;
use fc_rpc::{EthTask, OverrideHandle};
pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool};
use fp_rpc::EthereumRuntimeRPCApi;
use futures::{future, prelude::*};
use primitives::Block;
use sc_client_api::{BlockchainEvents, StateBackendFor};
use sc_consensus::{BlockCheckParams, BlockImport as BlockImportT, BlockImportParams, ImportResult};
use sc_executor::NativeExecutionDispatch;
use sc_network_sync::SyncingService;
use sc_service::{error::Error as ServiceError, BasePath, Configuration, TaskManager};
use sc_transaction_pool::{ChainApi, Pool};
use sp_api::{ConstructRuntimeApi, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_consensus::Error as ConsensusError;
use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
use std::{
collections::BTreeMap,
Expand Down Expand Up @@ -200,7 +196,7 @@ pub async fn spawn_frontier_tasks<RuntimeApi, Executor>(
overrides.clone(),
Arc::new(b),
3,
0,
0, // TODO: update when deployed
fc_mapping_sync::SyncStrategy::Normal,
sync,
pubsub_notification_sinks,
Expand Down Expand Up @@ -248,48 +244,6 @@ pub async fn spawn_frontier_tasks<RuntimeApi, Executor>(
);
}

#[derive(Clone)]
pub struct BlockImport<B: BlockT, I: BlockImportT<B>, C>(FrontierBlockImport<B, I, C>);

impl<B, I, C> BlockImport<B, I, C>
where
B: BlockT,
I: BlockImportT<B, Transaction = sp_api::TransactionFor<C, B>>,
I::Error: Into<ConsensusError>,
C: ProvideRuntimeApi<B>,
C::Api: BlockBuilderApi<B> + EthereumRuntimeRPCApi<B>,
{
pub fn new(inner: I, client: Arc<C>) -> Self {
Self(FrontierBlockImport::new(inner, client))
}
}

#[async_trait::async_trait]
impl<B, I, C> BlockImportT<B> for BlockImport<B, I, C>
where
B: BlockT,
I: BlockImportT<B, Transaction = sp_api::TransactionFor<C, B>> + Send + Sync,
I::Error: Into<ConsensusError>,
C: ProvideRuntimeApi<B> + Send + Sync,
C::Api: BlockBuilderApi<B> + EthereumRuntimeRPCApi<B>,
{
type Error = ConsensusError;
type Transaction = sp_api::TransactionFor<C, B>;

async fn check_block(&mut self, block: BlockCheckParams<B>) -> Result<ImportResult, Self::Error> {
self.0.check_block(block).await
}

async fn import_block(
&mut self,
block: BlockImportParams<B, Self::Transaction>,
) -> Result<ImportResult, Self::Error> {
self.0.import_block(block).await
}
}

impl<B: BlockT, I: BlockImportT<B>, C> ParachainBlockImportMarker for BlockImport<B, I, C> {}

pub fn new_eth_deps<C, P, A: ChainApi, CT>(
client: Arc<C>,
transaction_pool: Arc<P>,
Expand Down
45 changes: 23 additions & 22 deletions parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use substrate_prometheus_endpoint::Registry;

// Frontier imports
use crate::eth::{
new_eth_deps, new_frontier_partial, open_frontier_backend, spawn_frontier_tasks, BlockImport as EthBlockImport,
EthCompatRuntimeApiCollection, EthConfiguration, FrontierBackend, FrontierPartialComponents,
new_eth_deps, new_frontier_partial, open_frontier_backend, spawn_frontier_tasks, EthCompatRuntimeApiCollection,
EthConfiguration, FrontierBackend, FrontierPartialComponents,
};

macro_rules! new_runtime_executor {
Expand Down Expand Up @@ -189,6 +189,12 @@ type MaybeFullSelectChain = Option<LongestChain<FullBackend, Block>>;
type ParachainBlockImport<RuntimeApi, ExecutorDispatch> =
TParachainBlockImport<Block, Arc<FullClient<RuntimeApi, ExecutorDispatch>>, FullBackend>;

// 0x9af9a64e6e4da8e3073901c3ff0cc4c3aad9563786d89daf6ad820b6e14a0b8b
const KINTSUGI_GENESIS_HASH: H256 = H256([
154, 249, 166, 78, 110, 77, 168, 227, 7, 57, 1, 195, 255, 12, 196, 195, 170, 217, 86, 55, 134, 216, 157, 175, 106,
216, 32, 182, 225, 74, 11, 139,
]);

fn import_slot_duration<C>(client: &C) -> SlotDuration
where
C: sc_client_api::backend::AuxStore
Expand All @@ -197,18 +203,19 @@ where
+ 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)
}
if client.usage_info().chain.genesis_hash == KINTSUGI_GENESIS_HASH
&& 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)
} else {
// 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(),
sc_consensus_aura::slot_duration(&*client).unwrap()
}
}

Expand Down Expand Up @@ -306,7 +313,7 @@ where
let import_queue = if instant_seal {
// instant sealing
sc_consensus_manual_seal::import_queue(
Box::new(EthBlockImport::new(client.clone(), client.clone())),
Box::new(client.clone()),
&task_manager.spawn_essential_handle(),
registry,
)
Expand All @@ -315,10 +322,7 @@ where

cumulus_client_consensus_aura::import_queue::<AuraPair, _, _, _, _, _>(
cumulus_client_consensus_aura::ImportQueueParams {
block_import: EthBlockImport::new(
ParachainBlockImport::new(client.clone(), backend.clone()),
client.clone(),
),
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();
Expand Down Expand Up @@ -391,7 +395,7 @@ where
CT: fp_rpc::ConvertTransaction<<Block as BlockT>::Extrinsic> + Clone + Default + Send + Sync + 'static,
BIC: FnOnce(
Arc<FullClient<RuntimeApi, Executor>>,
EthBlockImport<Block, ParachainBlockImport<RuntimeApi, Executor>, FullClient<RuntimeApi, Executor>>,
ParachainBlockImport<RuntimeApi, Executor>,
Option<&Registry>,
Option<TelemetryHandle>,
&TaskManager,
Expand Down Expand Up @@ -537,10 +541,7 @@ where
if validator {
let parachain_consensus = build_consensus(
client.clone(),
EthBlockImport::new(
ParachainBlockImport::new(client.clone(), backend.clone()),
client.clone(),
),
ParachainBlockImport::new(client.clone(), backend.clone()),
prometheus_registry.as_ref(),
telemetry.as_ref().map(|t| t.handle()),
&task_manager,
Expand Down Expand Up @@ -753,7 +754,7 @@ where
let client_for_cidp = client.clone();

let authorship_future = sc_consensus_manual_seal::run_manual_seal(sc_consensus_manual_seal::ManualSealParams {
block_import: EthBlockImport::new(client.clone(), client.clone()),
block_import: client.clone(),
env: proposer_factory,
client: client.clone(),
pool: transaction_pool.clone(),
Expand Down

0 comments on commit 700fcc9

Please sign in to comment.