Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove useless NimbusBlockImport #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 1 addition & 58 deletions client/consensus/nimbus-consensus/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ 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,
) -> ClientResult<BasicQueue<Block>>
where
I: BlockImport<Block, Error = ConsensusError> + Send + Sync + 'static,
Expand All @@ -216,65 +215,9 @@ where

Ok(BasicQueue::new(
verifier,
Box::new(NimbusBlockImport::new(block_import, parachain)),
Box::new(block_import),
None,
spawner,
registry,
))
}

/// Nimbus specific block import.
///
/// Nimbus supports both parachain and non-parachain contexts. In the parachain
/// context, new blocks should not be imported as best. Cumulus's ParachainBlockImport
/// handles this correctly, but does not work in non-parachain contexts.
/// This block import has a field indicating whether we should apply parachain rules or not.
///
/// There may be additional nimbus-specific logic here in the future, but for now it is
/// only the conditional parachain logic
pub struct NimbusBlockImport<I> {
inner: I,
parachain_context: bool,
}

impl<I> NimbusBlockImport<I> {
/// Create a new instance.
pub fn new(inner: I, parachain_context: bool) -> Self {
Self {
inner,
parachain_context,
}
}
}

#[async_trait::async_trait]
impl<Block, I> BlockImport<Block> for NimbusBlockImport<I>
where
Block: BlockT,
I: BlockImport<Block> + Send,
{
type Error = I::Error;

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

async fn import_block(
&mut self,
mut block_import_params: sc_consensus::BlockImportParams<Block>,
) -> Result<sc_consensus::ImportResult, Self::Error> {
// If we are in the parachain context, best block is determined by the relay chain
// except during initial sync
if self.parachain_context {
block_import_params.fork_choice = Some(sc_consensus::ForkChoiceStrategy::Custom(
block_import_params.origin == sp_consensus::BlockOrigin::NetworkInitialSync,
));
}

// Now continue on to the rest of the import pipeline.
self.inner.import_block(block_import_params).await
}
}
8 changes: 4 additions & 4 deletions template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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 @@ -173,7 +173,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 @@ -203,7 +203,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 @@ -217,7 +217,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
6 changes: 2 additions & 4 deletions template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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 @@ -156,7 +155,6 @@ pub fn new_partial(
},
&task_manager.spawn_essential_handle(),
config.prometheus_registry().clone(),
parachain,
)?;

Ok(PartialComponents {
Expand Down Expand Up @@ -209,7 +207,7 @@ async fn start_node_impl(
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient>)> {
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 @@ -416,7 +414,7 @@ pub fn start_instant_seal_node(config: Configuration) -> Result<TaskManager, sc_
select_chain,
transaction_pool,
other: (_, mut telemetry, _),
} = new_partial(&config, false)?;
} = new_partial(&config)?;

let net_config = FullNetworkConfiguration::new(&config.network);

Expand Down