Skip to content

Commit

Permalink
remove useless NimbusBlockImport (#43)
Browse files Browse the repository at this point in the history
* remove useless NimbusBlockImport

* fix format

* remove use of new_with_delayed_best_block from template

* keep but deprecate old behaviour

---------

Co-authored-by: Éloïs <[email protected]>
  • Loading branch information
RomarQ and librelois committed Nov 22, 2024
1 parent f32e403 commit 5456422
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
22 changes: 20 additions & 2 deletions client/consensus/nimbus-consensus/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ pub fn import_queue<Client, Block: BlockT, I, CIDP>(
create_inherent_data_providers: CIDP,
spawner: &impl sp_core::traits::SpawnEssentialNamed,
registry: Option<&substrate_prometheus_endpoint::Registry>,
parachain: bool,
// 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<bool>,
) -> ClientResult<BasicQueue<Block>>
where
I: BlockImport<Block, Error = ConsensusError> + Send + Sync + 'static,
Expand All @@ -214,9 +217,19 @@ where
_marker: PhantomData,
};

let block_import_for_queue: sc_consensus::BoxBlockImport<Block> = match use_custom_fork_strategy
{
Some(parachain_context) =>
{
#[allow(deprecated)]
Box::new(NimbusBlockImport::new(block_import, parachain_context))
}
None => Box::new(block_import),
};

Ok(BasicQueue::new(
verifier,
Box::new(NimbusBlockImport::new(block_import, parachain)),
block_import_for_queue,
None,
spawner,
registry,
Expand All @@ -232,11 +245,15 @@ 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<I> {
inner: I,
parachain_context: bool,
}

#[allow(deprecated)]
impl<I> NimbusBlockImport<I> {
/// Create a new instance.
pub fn new(inner: I, parachain_context: bool) -> Self {
Expand All @@ -247,6 +264,7 @@ impl<I> NimbusBlockImport<I> {
}
}

#[allow(deprecated)]
#[async_trait::async_trait]
impl<Block, I> BlockImport<Block> for NimbusBlockImport<I>
where
Expand Down
8 changes: 4 additions & 4 deletions template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ macro_rules! construct_async_run {
runner.async_run(|$config| {
let $components = new_partial(
// We default to the non-parachain import queue and select chain.
&$config, false,
&$config,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
Expand Down Expand Up @@ -172,7 +172,7 @@ pub fn run() -> Result<()> {
Some(Subcommand::ExportGenesisState(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| {
let partials = new_partial(&config, false)?;
let partials = new_partial(&config)?;

cmd.run(partials.client)
})
Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn run() -> Result<()> {
}
}
BenchmarkCmd::Block(cmd) => runner.sync_run(|config| {
let partials = new_partial(&config, false)?;
let partials = new_partial(&config)?;
cmd.run(partials.client)
}),
#[cfg(not(feature = "runtime-benchmarks"))]
Expand All @@ -216,7 +216,7 @@ pub fn run() -> Result<()> {
}
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
let partials = new_partial(&config, false)?;
let partials = new_partial(&config)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();

Expand Down
11 changes: 4 additions & 7 deletions template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ type ParachainBlockImport = TParachainBlockImport<Block, Arc<ParachainClient>, P
/// be able to perform chain operations.
pub fn new_partial(
config: &Configuration,
parachain: bool,
) -> Result<
PartialComponents<
ParachainClient,
Expand Down Expand Up @@ -145,9 +144,7 @@ pub fn new_partial(
client.clone(),
);

// `new_with_delayed_best_block` is now necessary: https://github.com/paritytech/polkadot-sdk/pull/2001
let block_import =
ParachainBlockImport::new_with_delayed_best_block(client.clone(), backend.clone());
let block_import = ParachainBlockImport::new(client.clone(), backend.clone());

let import_queue = nimbus_consensus::import_queue(
client.clone(),
Expand All @@ -159,7 +156,7 @@ pub fn new_partial(
},
&task_manager.spawn_essential_handle(),
config.prometheus_registry().clone(),
parachain,
None,
)?;

Ok(PartialComponents {
Expand Down Expand Up @@ -215,7 +212,7 @@ where
{
let parachain_config = prepare_node_config(parachain_config);

let params = new_partial(&parachain_config, true)?;
let params = new_partial(&parachain_config)?;
let (block_import, mut telemetry, telemetry_worker_handle) = params.other;

let client = params.client.clone();
Expand Down Expand Up @@ -441,7 +438,7 @@ where
select_chain,
transaction_pool,
other: (_, mut telemetry, _),
} = new_partial(&config, false)?;
} = new_partial(&config)?;

let net_config = FullNetworkConfiguration::<_, _, N>::new(&config.network);

Expand Down

0 comments on commit 5456422

Please sign in to comment.