Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
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
101 changes: 51 additions & 50 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion bin/node-template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ pub fn run() -> sc_cli::Result<()> {
match &cli.subcommand {
Some(subcommand) => {
let runner = cli.create_runner(subcommand)?;
runner.run_subcommand(subcommand, |config| Ok(new_full_start!(config).0))
runner.run_subcommand(subcommand, |config| {
let (builder, _, _) = new_full_start!(config);
Ok(builder.to_chain_ops_parts())
})
}
None => {
let runner = cli.create_runner(&cli.run)?;
Expand Down
6 changes: 4 additions & 2 deletions bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ pub fn run() -> Result<()> {
}
Some(Subcommand::Base(subcommand)) => {
let runner = cli.create_runner(subcommand)?;

runner.run_subcommand(subcommand, |config| Ok(new_full_start!(config).0))
runner.run_subcommand(subcommand, |config| {
let (builder, _, _, _) = new_full_start!(config);
Ok(builder.to_chain_ops_parts())
})
}
}
}
1 change: 1 addition & 0 deletions client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ structopt = "0.3.8"
sc-tracing = { version = "2.0.0-rc4", path = "../tracing" }
chrono = "0.4.10"
parity-util-mem = { version = "0.6.1", default-features = false, features = ["primitive-types"] }
serde = "1.0.111"

[target.'cfg(not(target_os = "unknown"))'.dependencies]
rpassword = "4.0.1"
Expand Down
11 changes: 7 additions & 4 deletions client/cli/src/commands/build_spec_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::params::SharedParams;
use crate::CliConfiguration;
use log::info;
use sc_network::config::build_multiaddr;
use sc_service::{config::MultiaddrWithPeerId, Configuration};
use sc_service::{config::{MultiaddrWithPeerId, NetworkConfiguration}, ChainSpec};
use structopt::StructOpt;
use std::io::Write;

Expand Down Expand Up @@ -51,13 +51,16 @@ pub struct BuildSpecCmd {

impl BuildSpecCmd {
/// Run the build-spec command
pub fn run(&self, config: Configuration) -> error::Result<()> {
pub fn run(
&self,
mut spec: Box<dyn ChainSpec>,
network_config: NetworkConfiguration,
) -> error::Result<()> {
info!("Building chain spec");
let mut spec = config.chain_spec;
let raw_output = self.raw;

if spec.boot_nodes().is_empty() && !self.disable_default_bootnode {
let keys = config.network.node_key.into_keypair()?;
let keys = network_config.node_key.into_keypair()?;
let peer_id = keys.public().into_peer_id();
let addr = MultiaddrWithPeerId {
multiaddr: build_multiaddr![Ip4([127, 0, 0, 1]), Tcp(30333u16)],
Expand Down
26 changes: 13 additions & 13 deletions client/cli/src/commands/check_block_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
use crate::{
CliConfiguration, error, params::{ImportParams, SharedParams, BlockNumberOrHash},
};
use sc_service::{Configuration, ServiceBuilderCommand};
use sp_runtime::traits::{Block as BlockT, NumberFor};
use std::{fmt::Debug, str::FromStr};
use sc_client_api::{BlockBackend, UsageProvider};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::{fmt::Debug, str::FromStr, sync::Arc};
use structopt::StructOpt;

/// The `check-block` command used to validate blocks.
Expand All @@ -48,21 +48,21 @@ pub struct CheckBlockCmd {

impl CheckBlockCmd {
/// Run the check-block command
pub async fn run<B, BC, BB>(
pub async fn run<B, C, IQ>(
&self,
config: Configuration,
builder: B,
client: Arc<C>,
import_queue: IQ,
) -> error::Result<()>
where
B: FnOnce(Configuration) -> Result<BC, sc_service::error::Error>,
BC: ServiceBuilderCommand<Block = BB> + Unpin,
BB: BlockT + Debug,
<NumberFor<BB> as FromStr>::Err: std::fmt::Debug,
BB::Hash: FromStr,
<BB::Hash as FromStr>::Err: std::fmt::Debug,
B: BlockT + for<'de> serde::Deserialize<'de>,
C: BlockBackend<B> + UsageProvider<B> + Send + Sync + 'static,
IQ: sc_service::ImportQueue<B> + 'static,
B::Hash: FromStr,
<B::Hash as FromStr>::Err: Debug,
<<B::Header as HeaderT>::Number as FromStr>::Err: Debug,
{
let start = std::time::Instant::now();
builder(config)?.check_block(self.input.parse()?).await?;
sc_service::chain_ops::check_block(client, import_queue, self.input.parse()?).await?;
println!("Completed in {} ms.", start.elapsed().as_millis());

Ok(())
Expand Down
24 changes: 12 additions & 12 deletions client/cli/src/commands/export_blocks_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ use crate::params::{BlockNumber, DatabaseParams, PruningParams, SharedParams};
use crate::CliConfiguration;
use log::info;
use sc_service::{
config::DatabaseConfig, Configuration, ServiceBuilderCommand,
config::DatabaseConfig, chain_ops::export_blocks,
};
use sc_client_api::{BlockBackend, UsageProvider};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::fmt::Debug;
use std::fs;
use std::io;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
use structopt::StructOpt;

/// The `export-blocks` command used to export blocks.
Expand Down Expand Up @@ -68,19 +71,17 @@ pub struct ExportBlocksCmd {

impl ExportBlocksCmd {
/// Run the export-blocks command
pub async fn run<B, BC, BB>(
pub async fn run<B, C>(
&self,
config: Configuration,
builder: B,
client: Arc<C>,
database_config: DatabaseConfig,
) -> error::Result<()>
where
B: FnOnce(Configuration) -> Result<BC, sc_service::error::Error>,
BC: ServiceBuilderCommand<Block = BB> + Unpin,
BB: sp_runtime::traits::Block + Debug,
<<<BB as BlockT>::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug,
<BB as BlockT>::Hash: std::str::FromStr,
B: BlockT,
C: BlockBackend<B> + UsageProvider<B> + 'static,
<<B::Header as HeaderT>::Number as FromStr>::Err: Debug,
{
if let DatabaseConfig::RocksDb { ref path, .. } = &config.database {
if let DatabaseConfig::RocksDb { ref path, .. } = database_config {
info!("DB path: {}", path.display());
}

Expand All @@ -94,8 +95,7 @@ impl ExportBlocksCmd {
None => Box::new(io::stdout()),
};

builder(config)?
.export_blocks(file, from.into(), to, binary)
export_blocks(client, file, from.into(), to, binary)
.await
.map_err(Into::into)
}
Expand Down
27 changes: 13 additions & 14 deletions client/cli/src/commands/export_state_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use crate::{
CliConfiguration, error, params::{PruningParams, SharedParams, BlockNumberOrHash},
};
use log::info;
use sc_service::{Configuration, ServiceBuilderCommand};
use sp_runtime::traits::{Block as BlockT, NumberFor};
use std::{fmt::Debug, str::FromStr, io::Write};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::{fmt::Debug, str::FromStr, io::Write, sync::Arc};
use structopt::StructOpt;
use sc_client_api::{StorageProvider, UsageProvider};

/// The `export-state` command used to export the state of a given block into
/// a chain spec.
Expand All @@ -44,23 +44,22 @@ pub struct ExportStateCmd {

impl ExportStateCmd {
/// Run the `export-state` command
pub fn run<B, BC, BB>(
pub async fn run<B, BA, C>(
&self,
config: Configuration,
builder: B,
client: Arc<C>,
mut input_spec: Box<dyn sc_service::ChainSpec>,
) -> error::Result<()>
where
B: FnOnce(Configuration) -> Result<BC, sc_service::error::Error>,
BC: ServiceBuilderCommand<Block = BB> + Unpin,
BB: BlockT + Debug,
<NumberFor<BB> as FromStr>::Err: std::fmt::Debug,
BB::Hash: FromStr,
<BB::Hash as FromStr>::Err: std::fmt::Debug,
B: BlockT,
C: UsageProvider<B> + StorageProvider<B, BA>,
BA: sc_client_api::backend::Backend<B>,
B::Hash: FromStr,
<B::Hash as FromStr>::Err: Debug,
<<B::Header as HeaderT>::Number as FromStr>::Err: Debug,
{
info!("Exporting raw state...");
let mut input_spec = config.chain_spec.cloned_box();
let block_id = self.input.as_ref().map(|b| b.parse()).transpose()?;
let raw_state = builder(config)?.export_raw_state(block_id)?;
let raw_state = sc_service::chain_ops::export_raw_state(client, block_id)?;
input_spec.set_storage(raw_state);

info!("Generating new chain spec...");
Expand Down
23 changes: 11 additions & 12 deletions client/cli/src/commands/import_blocks_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ use crate::error;
use crate::params::ImportParams;
use crate::params::SharedParams;
use crate::CliConfiguration;
use sc_service::{Configuration, ServiceBuilderCommand};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use sc_service::chain_ops::import_blocks;
use sp_runtime::traits::Block as BlockT;
use std::fmt::Debug;
use std::fs;
use std::io::{self, Read, Seek};
use std::path::PathBuf;
use std::sync::Arc;
use structopt::StructOpt;
use sc_client_api::UsageProvider;

/// The `import-blocks` command used to import blocks.
#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -61,17 +63,15 @@ impl<T: Read + Seek> ReadPlusSeek for T {}

impl ImportBlocksCmd {
/// Run the import-blocks command
pub async fn run<B, BC, BB>(
pub async fn run<B, C, IQ>(
&self,
config: Configuration,
builder: B,
client: Arc<C>,
import_queue: IQ,
) -> error::Result<()>
where
B: FnOnce(Configuration) -> Result<BC, sc_service::error::Error>,
BC: ServiceBuilderCommand<Block = BB> + Unpin,
BB: sp_runtime::traits::Block + Debug,
<<<BB as BlockT>::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug,
<BB as BlockT>::Hash: std::str::FromStr,
C: UsageProvider<B> + Send + Sync + 'static,
B: BlockT + for<'de> serde::Deserialize<'de>,
IQ: sc_service::ImportQueue<B> + 'static,
{
let file: Box<dyn ReadPlusSeek + Send> = match &self.input {
Some(filename) => Box::new(fs::File::open(filename)?),
Expand All @@ -82,8 +82,7 @@ impl ImportBlocksCmd {
}
};

builder(config)?
.import_blocks(file, false, self.binary)
import_blocks(client, import_queue, file, false, self.binary)
.await
.map_err(Into::into)
}
Expand Down
6 changes: 3 additions & 3 deletions client/cli/src/commands/purge_chain_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::error;
use crate::params::{DatabaseParams, SharedParams};
use crate::CliConfiguration;
use sc_service::Configuration;
use sc_service::DatabaseConfig;
use std::fmt::Debug;
use std::fs;
use std::io::{self, Write};
Expand All @@ -43,8 +43,8 @@ pub struct PurgeChainCmd {

impl PurgeChainCmd {
/// Run the purge command
pub fn run(&self, config: Configuration) -> error::Result<()> {
let db_path = config.database.path()
pub fn run(&self, database_config: DatabaseConfig) -> error::Result<()> {
let db_path = database_config.path()
.ok_or_else(||
error::Error::Input("Cannot purge custom database implementation".into())
)?;
Expand Down
22 changes: 14 additions & 8 deletions client/cli/src/commands/revert_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
use crate::error;
use crate::params::{BlockNumber, PruningParams, SharedParams};
use crate::CliConfiguration;
use sc_service::{Configuration, ServiceBuilderCommand};
use sc_service::chain_ops::revert_chain;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::fmt::Debug;
use std::str::FromStr;
use std::sync::Arc;
use structopt::StructOpt;
use sc_client_api::{Backend, UsageProvider};

/// The `revert` command used revert the chain to a previous state.
#[derive(Debug, StructOpt)]
Expand All @@ -42,16 +45,19 @@ pub struct RevertCmd {

impl RevertCmd {
/// Run the revert command
pub fn run<B, BC, BB>(&self, config: Configuration, builder: B) -> error::Result<()>
pub async fn run<B, BA, C>(
&self,
client: Arc<C>,
backend: Arc<BA>,
) -> error::Result<()>
where
B: FnOnce(Configuration) -> Result<BC, sc_service::error::Error>,
BC: ServiceBuilderCommand<Block = BB> + Unpin,
BB: sp_runtime::traits::Block + Debug,
<<<BB as BlockT>::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug,
<BB as BlockT>::Hash: std::str::FromStr,
B: BlockT,
BA: Backend<B>,
C: UsageProvider<B>,
<<<B as BlockT>::Header as HeaderT>::Number as FromStr>::Err: Debug,
{
let blocks = self.num.parse()?;
builder(config)?.revert_chain(blocks)?;
revert_chain(client, backend, blocks)?;

Ok(())
}
Expand Down
Loading