-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
polkadot-parachain: Add omni-node variant with u64 block number (#5269)
Related to #4787 The main changes in this PR are the following: - making the NodeSpec logic generic on the Block type - adding an omni-node variant with u64 block number Apart from this, the PR also moves some of the logic in `service.rs` to the `common` subfolder The omni-node variant with u64 block number is not used yet. We have to either expose the option in the CLI or to read the block number from the chain spec somehow. Will do it in a future PR.
- Loading branch information
Showing
18 changed files
with
1,109 additions
and
1,061 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/command.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// 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::spec::NodeSpec; | ||
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 std::{future::Future, pin::Pin}; | ||
|
||
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: NodeSpec, | ||
{ | ||
fn prepare_check_block_cmd( | ||
self: Box<Self>, | ||
config: Configuration, | ||
cmd: &CheckBlockCmd, | ||
) -> AsyncCmdResult<'_> { | ||
let partial = T::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::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::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::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::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::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::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::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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.