From 62577169d2464e21bbe5af2739e3c3891710a15d Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Fri, 6 Dec 2024 11:27:25 +0000 Subject: [PATCH] explicitly set fork_chain when sealing a block --- .../nimbus-consensus/src/collators.rs | 2 ++ .../nimbus-consensus/src/import_queue.rs | 34 ++++++------------- template/node/src/service.rs | 2 +- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/client/consensus/nimbus-consensus/src/collators.rs b/client/consensus/nimbus-consensus/src/collators.rs index ffaff8a5..7b73cce1 100644 --- a/client/consensus/nimbus-consensus/src/collators.rs +++ b/client/consensus/nimbus-consensus/src/collators.rs @@ -118,6 +118,8 @@ where block_import_params.state_action = sc_consensus::StateAction::ApplyChanges( sc_consensus::StorageChanges::Changes(storage_changes), ); + // The collator should follow the longest chain + block_import_params.fork_choice = Some(sc_consensus::ForkChoiceStrategy::LongestChain); let post_hash = block_import_params.post_hash(); diff --git a/client/consensus/nimbus-consensus/src/import_queue.rs b/client/consensus/nimbus-consensus/src/import_queue.rs index a3ab8daf..36389e92 100644 --- a/client/consensus/nimbus-consensus/src/import_queue.rs +++ b/client/consensus/nimbus-consensus/src/import_queue.rs @@ -200,10 +200,7 @@ pub fn import_queue( create_inherent_data_providers: CIDP, spawner: &impl sp_core::traits::SpawnEssentialNamed, registry: Option<&substrate_prometheus_endpoint::Registry>, - // Deprecated: Using a custom fork strategy for parachain at block - // import is no longer necessary. - // Context: https://github.com/paritytech/polkadot-sdk/issues/4333 - use_custom_fork_strategy: Option, + with_delayed_best_block: bool, ) -> ClientResult> where I: BlockImport + Send + Sync + 'static, @@ -217,15 +214,10 @@ where _marker: PhantomData, }; - let block_import_for_queue: sc_consensus::BoxBlockImport = match use_custom_fork_strategy - { - Some(parachain_context) => - { - #[allow(deprecated)] - Box::new(NimbusBlockImport::new(block_import, parachain_context)) - } - None => Box::new(block_import), - }; + let block_import_for_queue = Box::new(NimbusBlockImport::new( + block_import, + with_delayed_best_block, + )); Ok(BasicQueue::new( verifier, @@ -245,21 +237,17 @@ where /// /// There may be additional nimbus-specific logic here in the future, but for now it is /// only the conditional parachain logic -#[deprecated( - note = "Aura was using a custom fork strategy for parachain at block import, this is no longer necessary." -)] pub struct NimbusBlockImport { inner: I, - parachain_context: bool, + with_delayed_best_block: bool, } -#[allow(deprecated)] impl NimbusBlockImport { /// Create a new instance. - pub fn new(inner: I, parachain_context: bool) -> Self { + pub fn new(inner: I, with_delayed_best_block: bool) -> Self { Self { inner, - parachain_context, + with_delayed_best_block, } } } @@ -284,9 +272,9 @@ where &mut self, mut block_import_params: sc_consensus::BlockImportParams, ) -> Result { - // If we are in the parachain context, best block is determined by the relay chain - // except during initial sync - if self.parachain_context { + // Best block is determined by the relay chain, or if we are doing the initial sync + // we import all blocks as new best. + if self.with_delayed_best_block { block_import_params.fork_choice = Some(sc_consensus::ForkChoiceStrategy::Custom( block_import_params.origin == sp_consensus::BlockOrigin::NetworkInitialSync, )); diff --git a/template/node/src/service.rs b/template/node/src/service.rs index 2b0cd5bd..3b543d93 100644 --- a/template/node/src/service.rs +++ b/template/node/src/service.rs @@ -156,7 +156,7 @@ pub fn new_partial( }, &task_manager.spawn_essential_handle(), config.prometheus_registry().clone(), - None, + false, )?; Ok(PartialComponents {