mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27:58 +00:00
Add a feature to create automatically a random temporary directory for base path & remove Clone (#6221)
* Initial commit Forked at:4adac40c07Parent branch: origin/master * Add a feature to create automatically a temporary directory for base path * doc fix and todos * use parking_lot instead * use refcell instead since we stay in the main thread * remove Clone derives * add test * solving dependency issue * clarifying doc * conflict argument with base-path * WIP Forked at:4adac40c07Parent branch: origin/master * revert dep deletion * fixing test and making base_path optional * hold basepath while the service is running * fixes * Update client/cli/src/params/shared_params.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/Cargo.toml Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/cli/src/commands/mod.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/config.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * WIP Forked at:4adac40c07Parent branch: origin/master * improve doc Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -27,7 +27,7 @@ use structopt::StructOpt;
|
||||
use std::io::Write;
|
||||
|
||||
/// The `build-spec` command used to build a specification.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct BuildSpecCmd {
|
||||
/// Force raw genesis storage output.
|
||||
#[structopt(long = "raw")]
|
||||
|
||||
@@ -25,7 +25,7 @@ use std::{fmt::Debug, str::FromStr};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `check-block` command used to validate blocks.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct CheckBlockCmd {
|
||||
/// Block hash or number
|
||||
#[structopt(value_name = "HASH or NUMBER")]
|
||||
|
||||
@@ -31,7 +31,7 @@ use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `export-blocks` command used to export blocks.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct ExportBlocksCmd {
|
||||
/// Output file name or stdout if unspecified.
|
||||
#[structopt(parse(from_os_str))]
|
||||
|
||||
@@ -27,7 +27,7 @@ use structopt::StructOpt;
|
||||
|
||||
/// The `export-state` command used to export the state of a given block into
|
||||
/// a chain spec.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct ExportStateCmd {
|
||||
/// Block hash or number.
|
||||
#[structopt(value_name = "HASH or NUMBER")]
|
||||
@@ -59,7 +59,7 @@ impl ExportStateCmd {
|
||||
{
|
||||
info!("Exporting raw state...");
|
||||
let mut input_spec = config.chain_spec.cloned_box();
|
||||
let block_id = self.input.clone().map(|b| b.parse()).transpose()?;
|
||||
let block_id = self.input.as_ref().map(|b| b.parse()).transpose()?;
|
||||
let raw_state = builder(config)?.export_raw_state(block_id)?;
|
||||
input_spec.set_storage(raw_state);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `import-blocks` command used to import blocks.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct ImportBlocksCmd {
|
||||
/// Input file or stdin if unspecified.
|
||||
#[structopt(parse(from_os_str))]
|
||||
|
||||
@@ -27,11 +27,11 @@ mod run_cmd;
|
||||
pub use self::build_spec_cmd::BuildSpecCmd;
|
||||
pub use self::check_block_cmd::CheckBlockCmd;
|
||||
pub use self::export_blocks_cmd::ExportBlocksCmd;
|
||||
pub use self::export_state_cmd::ExportStateCmd;
|
||||
pub use self::import_blocks_cmd::ImportBlocksCmd;
|
||||
pub use self::purge_chain_cmd::PurgeChainCmd;
|
||||
pub use self::revert_cmd::RevertCmd;
|
||||
pub use self::run_cmd::RunCmd;
|
||||
pub use self::export_state_cmd::ExportStateCmd;
|
||||
use std::fmt::Debug;
|
||||
use structopt::StructOpt;
|
||||
|
||||
@@ -40,7 +40,7 @@ use structopt::StructOpt;
|
||||
/// The core commands are split into multiple subcommands and `Run` is the default subcommand. From
|
||||
/// the CLI user perspective, it is not visible that `Run` is a subcommand. So, all parameters of
|
||||
/// `Run` are exported as main executable parameters.
|
||||
#[derive(Debug, Clone, StructOpt)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub enum Subcommand {
|
||||
/// Build a spec.json file, outputs to stdout.
|
||||
BuildSpec(BuildSpecCmd),
|
||||
@@ -162,7 +162,7 @@ macro_rules! substrate_cli_subcommands {
|
||||
}
|
||||
}
|
||||
|
||||
fn base_path(&self) -> $crate::Result<::std::option::Option<::std::path::PathBuf>> {
|
||||
fn base_path(&self) -> $crate::Result<::std::option::Option<sc_service::config::BasePath>> {
|
||||
match self {
|
||||
$($enum::$variant(cmd) => cmd.base_path()),*
|
||||
}
|
||||
@@ -409,4 +409,3 @@ macro_rules! substrate_cli_subcommands {
|
||||
substrate_cli_subcommands!(
|
||||
Subcommand => BuildSpec, ExportBlocks, ImportBlocks, CheckBlock, Revert, PurgeChain, ExportState
|
||||
);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ use std::io::{self, Write};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `purge-chain` command used to remove the whole chain.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct PurgeChainCmd {
|
||||
/// Skip interactive prompt by answering yes automatically.
|
||||
#[structopt(short = "y")]
|
||||
|
||||
@@ -25,7 +25,7 @@ use std::fmt::Debug;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `revert` command used revert the chain to a previous state.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct RevertCmd {
|
||||
/// Number of blocks to revert.
|
||||
#[structopt(default_value = "256")]
|
||||
|
||||
@@ -21,13 +21,13 @@ use crate::error::{Error, Result};
|
||||
use crate::params::ImportParams;
|
||||
use crate::params::KeystoreParams;
|
||||
use crate::params::NetworkParams;
|
||||
use crate::params::OffchainWorkerParams;
|
||||
use crate::params::SharedParams;
|
||||
use crate::params::TransactionPoolParams;
|
||||
use crate::params::OffchainWorkerParams;
|
||||
use crate::CliConfiguration;
|
||||
use regex::Regex;
|
||||
use sc_service::{
|
||||
config::{MultiaddrWithPeerId, PrometheusConfig, TransactionPoolOptions},
|
||||
config::{BasePath, MultiaddrWithPeerId, PrometheusConfig, TransactionPoolOptions},
|
||||
ChainSpec, Role,
|
||||
};
|
||||
use sc_telemetry::TelemetryEndpoints;
|
||||
@@ -35,7 +35,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `run` command used to run a node.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct RunCmd {
|
||||
/// Enable validator mode.
|
||||
///
|
||||
@@ -250,6 +250,16 @@ pub struct RunCmd {
|
||||
conflicts_with_all = &[ "sentry", "public-addr" ]
|
||||
)]
|
||||
pub sentry_nodes: Vec<MultiaddrWithPeerId>,
|
||||
|
||||
/// Run a temporary node.
|
||||
///
|
||||
/// A temporary directory will be created to store the configuration and will be deleted
|
||||
/// at the end of the process.
|
||||
///
|
||||
/// Note: the directory is random per process execution. This directory is used as base path
|
||||
/// which includes: database, node key and keystore.
|
||||
#[structopt(long, conflicts_with = "base-path")]
|
||||
pub tmp: bool,
|
||||
}
|
||||
|
||||
impl RunCmd {
|
||||
@@ -446,6 +456,14 @@ impl CliConfiguration for RunCmd {
|
||||
fn max_runtime_instances(&self) -> Result<Option<usize>> {
|
||||
Ok(self.max_runtime_instances.map(|x| x.min(256)))
|
||||
}
|
||||
|
||||
fn base_path(&self) -> Result<Option<BasePath>> {
|
||||
Ok(if self.tmp {
|
||||
Some(BasePath::new_temp_dir()?)
|
||||
} else {
|
||||
self.shared_params().base_path()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Check whether a node name is considered as valid.
|
||||
|
||||
Reference in New Issue
Block a user