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

Omni-node: add solochain with manual consensus logic #5027

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

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

16 changes: 4 additions & 12 deletions cumulus/client/consensus/relay-chain/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@

use std::{marker::PhantomData, sync::Arc};

use cumulus_client_consensus_common::ParachainBlockImportMarker;

use sc_consensus::{
import_queue::{BasicQueue, Verifier as VerifierT},
BlockImport, BlockImportParams,
BlockImportParams, BoxBlockImport,
};
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::Result as ClientResult;
use sp_consensus::error::Error as ConsensusError;
use sp_inherents::{CreateInherentDataProviders, InherentDataProvider};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};

Expand Down Expand Up @@ -109,24 +106,19 @@ where
}

/// Start an import queue for a Cumulus collator that does not uses any special authoring logic.
pub fn import_queue<Client, Block: BlockT, I, CIDP>(
pub fn import_queue<Client, Block: BlockT, CIDP>(
client: Arc<Client>,
block_import: I,
block_import: BoxBlockImport<Block>,
create_inherent_data_providers: CIDP,
spawner: &impl sp_core::traits::SpawnEssentialNamed,
registry: Option<&prometheus_endpoint::Registry>,
) -> ClientResult<BasicQueue<Block>>
where
I: BlockImport<Block, Error = ConsensusError>
+ ParachainBlockImportMarker
+ Send
+ Sync
+ 'static,
Client: ProvideRuntimeApi<Block> + Send + Sync + 'static,
<Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
CIDP: CreateInherentDataProviders<Block, ()> + 'static,
{
let verifier = Verifier::new(client, create_inherent_data_providers);

Ok(BasicQueue::new(verifier, Box::new(block_import), None, spawner, registry))
Ok(BasicQueue::new(verifier, block_import, None, spawner, registry))
}
5 changes: 5 additions & 0 deletions cumulus/polkadot-parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ sp-core = { workspace = true, default-features = true }
sp-session = { workspace = true, default-features = true }
frame-try-runtime = { optional = true, workspace = true, default-features = true }
sc-consensus = { workspace = true, default-features = true }
sc-consensus-manual-seal = { workspace = true, default-features = true }
sp-tracing = { workspace = true, default-features = true }
frame-support = { workspace = true, default-features = true }
sc-cli = { workspace = true, default-features = true }
sc-client-api = { workspace = true, default-features = true }
sc-client-db = { workspace = true, default-features = true }
sc-executor = { workspace = true, default-features = true }
sc-service = { workspace = true, default-features = true }
sc-telemetry = { workspace = true, default-features = true }
Expand All @@ -78,6 +80,7 @@ sc-chain-spec = { workspace = true, default-features = true }
sc-rpc = { workspace = true, default-features = true }
sp-version = { workspace = true, default-features = true }
sc-tracing = { workspace = true, default-features = true }
sc-offchain = { workspace = true, default-features = true }
sp-offchain = { workspace = true, default-features = true }
frame-system-rpc-runtime-api = { workspace = true, default-features = true }
pallet-transaction-payment = { workspace = true, default-features = true }
Expand Down Expand Up @@ -112,6 +115,7 @@ cumulus-client-service = { workspace = true, default-features = true }
cumulus-primitives-aura = { workspace = true, default-features = true }
cumulus-primitives-core = { workspace = true, default-features = true }
cumulus-relay-chain-interface = { workspace = true, default-features = true }
futures-timer = "3.0.3"

[build-dependencies]
substrate-build-script-utils = { workspace = true, default-features = true }
Expand Down Expand Up @@ -147,6 +151,7 @@ runtime-benchmarks = [
"polkadot-primitives/runtime-benchmarks",
"polkadot-service/runtime-benchmarks",
"rococo-parachain-runtime/runtime-benchmarks",
"sc-client-db/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
Expand Down
9 changes: 6 additions & 3 deletions cumulus/polkadot-parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ use crate::{
chain_spec,
chain_spec::GenericChainSpec,
cli::{Cli, RelayChainCli, Subcommand},
common::NodeExtraArgs,
common::{
parachain::{aura::new_aura_node_spec, DynParachainNodeSpec},
NodeExtraArgs,
},
fake_runtime_api::{
asset_hub_polkadot_aura::RuntimeApi as AssetHubPolkadotRuntimeApi,
aura::RuntimeApi as AuraRuntimeApi,
},
service::{new_aura_node_spec, DynNodeSpec, ShellNode},
service::ShellNode,
};
#[cfg(feature = "runtime-benchmarks")]
use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions;
Expand Down Expand Up @@ -389,7 +392,7 @@ impl SubstrateCli for RelayChainCli {
fn new_node_spec(
config: &sc_service::Configuration,
extra_args: NodeExtraArgs,
) -> std::result::Result<Box<dyn DynNodeSpec>, sc_cli::Error> {
) -> std::result::Result<Box<dyn DynParachainNodeSpec>, sc_cli::Error> {
Ok(match config.chain_spec.runtime()? {
Runtime::AssetHubPolkadot =>
new_aura_node_spec::<AssetHubPolkadotRuntimeApi, AssetHubPolkadotAuraId>(extra_args),
Expand Down
163 changes: 163 additions & 0 deletions cumulus/polkadot-parachain/src/common/command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use crate::common::{NodeSpec, NodeSpecProvider};
use cumulus_client_cli::ExportGenesisHeadCommand;
use frame_benchmarking_cli::BlockCmd;
#[cfg(any(feature = "runtime-benchmarks"))]
use frame_benchmarking_cli::StorageCmd;
use sc_cli::{CheckBlockCmd, ExportBlocksCmd, ExportStateCmd, ImportBlocksCmd, RevertCmd};
use sc_service::{Configuration, TaskManager};
use sp_runtime::traits::NumberFor;
use std::{fmt::Debug, future::Future, pin::Pin, str::FromStr};

type SyncCmdResult = sc_cli::Result<()>;

type AsyncCmdResult<'a> =
sc_cli::Result<(Pin<Box<dyn Future<Output = SyncCmdResult> + 'a>>, TaskManager)>;

pub trait NodeCommandRunner {
fn prepare_check_block_cmd(
self: Box<Self>,
config: Configuration,
cmd: &CheckBlockCmd,
) -> AsyncCmdResult<'_>;

fn prepare_export_blocks_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportBlocksCmd,
) -> AsyncCmdResult<'_>;

fn prepare_export_state_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportStateCmd,
) -> AsyncCmdResult<'_>;

fn prepare_import_blocks_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ImportBlocksCmd,
) -> AsyncCmdResult<'_>;

fn prepare_revert_cmd(
self: Box<Self>,
config: Configuration,
cmd: &RevertCmd,
) -> AsyncCmdResult<'_>;

fn run_export_genesis_head_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportGenesisHeadCommand,
) -> SyncCmdResult;

fn run_benchmark_block_cmd(
self: Box<Self>,
config: Configuration,
cmd: &BlockCmd,
) -> SyncCmdResult;

#[cfg(any(feature = "runtime-benchmarks"))]
fn run_benchmark_storage_cmd(
self: Box<Self>,
config: Configuration,
cmd: &StorageCmd,
) -> SyncCmdResult;
}

impl<T> NodeCommandRunner for T
where
T: NodeSpecProvider,
<NumberFor<<T::NodeSpec as NodeSpec>::Block> as FromStr>::Err: Debug,
{
fn prepare_check_block_cmd(
self: Box<Self>,
config: Configuration,
cmd: &CheckBlockCmd,
) -> AsyncCmdResult<'_> {
let partial = T::NodeSpec::new_partial(&config).map_err(sc_cli::Error::Service)?;
Ok((Box::pin(cmd.run(partial.client, partial.import_queue)), partial.task_manager))
}

fn prepare_export_blocks_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportBlocksCmd,
) -> AsyncCmdResult<'_> {
let partial = T::NodeSpec::new_partial(&config).map_err(sc_cli::Error::Service)?;
Ok((Box::pin(cmd.run(partial.client, config.database)), partial.task_manager))
}

fn prepare_export_state_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportStateCmd,
) -> AsyncCmdResult<'_> {
let partial = T::NodeSpec::new_partial(&config).map_err(sc_cli::Error::Service)?;
Ok((Box::pin(cmd.run(partial.client, config.chain_spec)), partial.task_manager))
}

fn prepare_import_blocks_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ImportBlocksCmd,
) -> AsyncCmdResult<'_> {
let partial = T::NodeSpec::new_partial(&config).map_err(sc_cli::Error::Service)?;
Ok((Box::pin(cmd.run(partial.client, partial.import_queue)), partial.task_manager))
}

fn prepare_revert_cmd(
self: Box<Self>,
config: Configuration,
cmd: &RevertCmd,
) -> AsyncCmdResult<'_> {
let partial = T::NodeSpec::new_partial(&config).map_err(sc_cli::Error::Service)?;
Ok((Box::pin(cmd.run(partial.client, partial.backend, None)), partial.task_manager))
}

fn run_export_genesis_head_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportGenesisHeadCommand,
) -> SyncCmdResult {
let partial = T::NodeSpec::new_partial(&config).map_err(sc_cli::Error::Service)?;
cmd.run(partial.client)
}

fn run_benchmark_block_cmd(
self: Box<Self>,
config: Configuration,
cmd: &BlockCmd,
) -> SyncCmdResult {
let partial = T::NodeSpec::new_partial(&config).map_err(sc_cli::Error::Service)?;
cmd.run(partial.client)
}

#[cfg(any(feature = "runtime-benchmarks"))]
fn run_benchmark_storage_cmd(
self: Box<Self>,
config: Configuration,
cmd: &StorageCmd,
) -> SyncCmdResult {
let partial = T::NodeSpec::new_partial(&config).map_err(sc_cli::Error::Service)?;
let db = partial.backend.expose_db();
let storage = partial.backend.expose_storage();

cmd.run(config, partial.client, db, storage)
}
}
Loading
Loading