Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ impl CliConfiguration for ApiVersionsCmd {
}
}

impl CliConfigurationExt for ApiVersionsCmd {}
impl CliConfigurationExt for ApiVersionsCmd {

}
74 changes: 74 additions & 0 deletions crates/humanode-peer/src/cli/command/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//! Humanode peer commands.

use super::substrate_cmd_adapter;

pub mod bioauth;
pub mod ethereum;
pub mod run;

/// The root command.
#[derive(Debug, clap::Parser)]
pub struct Command {
/// Additional subcommands.
#[clap(subcommand)]
pub subcommand: Option<Subcommand>,

/// The `run` command used to run a node.
#[clap(flatten)]
pub run: run::RunCmd,
}

/// The subcommands.
#[derive(Debug, clap::Subcommand)]
pub enum Subcommand {
/// Key management cli utilities.
// The key subcommand is a special snowflake, because it doesn't implement the Substrate CLI
// config.
#[clap(subcommand)]
Key(sc_cli::KeySubcommand),

/// Build a chain specification.
BuildSpec(
substrate_cmd_adapter::Cmd<sc_cli::BuildSpecCmd, substrate_cmd_adapter::NoExtraParams>,
),

/// Validate blocks.
CheckBlock(
substrate_cmd_adapter::Cmd<sc_cli::CheckBlockCmd, substrate_cmd_adapter::NoExtraParams>,
),

/// Export blocks.
ExportBlocks(
substrate_cmd_adapter::Cmd<sc_cli::ExportBlocksCmd, substrate_cmd_adapter::NoExtraParams>,
),

/// Export the state of a given block into a chain spec.
ExportState(
substrate_cmd_adapter::Cmd<sc_cli::ExportStateCmd, substrate_cmd_adapter::NoExtraParams>,
),

/// Import blocks.
ImportBlocks(
substrate_cmd_adapter::Cmd<sc_cli::ImportBlocksCmd, substrate_cmd_adapter::NoExtraParams>,
),

/// Remove the whole chain.
PurgeChain(
substrate_cmd_adapter::Cmd<sc_cli::PurgeChainCmd, substrate_cmd_adapter::NoExtraParams>,
),

/// Revert the chain to a previous state.
Revert(substrate_cmd_adapter::Cmd<sc_cli::RevertCmd, substrate_cmd_adapter::NoExtraParams>),

/// Biometric authentication related subcommands.
#[clap(subcommand)]
Bioauth(bioauth::BioauthCmd),

/// Ethereum related subcommands.
#[clap(subcommand)]
Ethereum(ethereum::EthereumCmd),

/// Benchmarking utilities.
#[clap(subcommand)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The "default" command implementation, used when no subcommands are provided.

use super::{params, CliConfigurationExt, SubstrateCliConfigurationProvider};
use crate::cli::{params, CliConfigurationExt, SubstrateCliConfigurationProvider};

/// The `run` command used to run a node.
/// Expands the [`sc_cli::RunCmd`] with Humanode options.
Expand All @@ -17,6 +17,10 @@ pub struct RunCmd {
#[allow(missing_docs, clippy::missing_docs_in_private_items)]
#[clap(flatten)]
pub evm_params: params::EvmParams,

#[allow(missing_docs, clippy::missing_docs_in_private_items)]
#[clap(flatten)]
pub ethereum_rpc_params: params::EthereumRpcParams,
}

impl SubstrateCliConfigurationProvider for RunCmd {
Expand All @@ -35,4 +39,8 @@ impl CliConfigurationExt for RunCmd {
fn evm_params(&self) -> Option<&params::EvmParams> {
Some(&self.evm_params)
}

fn ethereum_rpc_params(&self) -> Option<&params::EthereumRpcParams> {
Some(&self.ethereum_rpc_params)
}
}
28 changes: 21 additions & 7 deletions crates/humanode-peer/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,26 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider {
}
});

let evm = self.evm_params().map(|params| configuration::Evm {
max_past_logs: params.max_past_logs,
max_stored_filters: params.max_stored_filters,
target_gas_price: params.target_gas_price,
fee_history_limit: params.fee_history_limit,
});
let evm = {
let params = self.evm_params();
configuration::Evm {
target_gas_price: params.map(|p| p.target_gas_price).unwrap_or(1),
}
};

let ethereum_rpc = self
.ethereum_rpc_params()
.map(|params| configuration::EthereumRpc {
max_past_logs: params.max_past_logs,
max_stored_filters: params.max_stored_filters,
fee_history_limit: params.fee_history_limit,
});

Ok(Configuration {
substrate,
bioauth_flow,
evm,
ethereum_rpc,
})
}

Expand All @@ -63,10 +72,15 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider {
None
}

/// Provide the evm params, if available.
/// Provide the EVM params.
fn evm_params(&self) -> Option<&params::EvmParams> {
None
}

/// Provide the Ethereum RPC params.
fn ethereum_rpc_params(&self) -> Option<&params::EthereumRpcParams> {
None
}
}

/// Indirect relation to the [`sc_cli::CliConfiguration`] for any type.
Expand Down
7 changes: 3 additions & 4 deletions crates/humanode-peer/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
//! Command line interface.

mod command;
mod config;
mod init;
mod params;
mod root;
mod run;
mod run_cmd;
mod runner;
mod subcommand;
mod substrate_cmd_adapter;
mod utils;

pub use command::*;
pub use config::*;
pub use params::*;
pub use root::*;
pub use run::*;
pub use run_cmd::*;
pub use runner::*;
pub use subcommand::*;
14 changes: 9 additions & 5 deletions crates/humanode-peer/src/cli/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ pub struct BioauthFlowParams {
pub robonode_url: Option<String>,
}

/// Shared CLI parameters used to configure evm.
/// Shared CLI parameters used to configure EVM.
#[derive(Debug, clap::Parser, Clone)]
pub struct EvmParams {
/// The dynamic-fee pallet target gas price set by block author.
#[clap(long, default_value = "1")]
pub target_gas_price: u64,
}

/// Shared CLI parameters used to configure Ethereum RPC.
#[derive(Debug, clap::Parser, Clone)]
pub struct EthereumRpcParams {
/// Maximum number of logs to keep from the latest block;
/// it is not possible to query logs older than this amount from the latest block in the past.
#[clap(long, default_value = "10000")]
Expand All @@ -63,10 +71,6 @@ pub struct EvmParams {
#[clap(long, default_value = "500")]
pub max_stored_filters: usize,

/// The dynamic-fee pallet target gas price set by block author.
#[clap(long, default_value = "1")]
pub target_gas_price: u64,

/// Maximum fee history cache size.
#[clap(long, default_value = "2048")]
pub fee_history_limit: u64,
Expand Down
12 changes: 3 additions & 9 deletions crates/humanode-peer/src/cli/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};

use super::{CliConfigurationExt, Runner, Subcommand};
use super::{CliConfigurationExt, Runner};
use crate::chain_spec;

/// The root of the CLI commands hierarchy.
#[derive(Debug, clap::Parser)]
pub struct Root {
/// Additional subcommands.
#[clap(subcommand)]
pub subcommand: Option<Subcommand>,

/// The `run` command used to run a node.
#[allow(missing_docs)]
#[clap(flatten)]
pub run: super::RunCmd,
pub command: super::command::Command,
}

impl SubstrateCli for Root {
Expand Down Expand Up @@ -74,5 +70,3 @@ impl Root {
Runner::new(self, command)
}
}

impl CliConfigurationExt for sc_cli::RunCmd {}
34 changes: 24 additions & 10 deletions crates/humanode-peer/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ use crate::service;
pub async fn run() -> sc_cli::Result<()> {
let root: Root = sc_cli::SubstrateCli::from_args();

match &root.subcommand {
match &root.command.subcommand {
Some(Subcommand::Key(cmd)) => cmd.run(&root),
Some(Subcommand::BuildSpec(cmd)) => {
let runner = root.create_humanode_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.substrate.chain_spec, config.substrate.network))
runner.sync_run(|config| {
cmd.base
.run(config.substrate.chain_spec, config.substrate.network)
})
}
Some(Subcommand::CheckBlock(cmd)) => {
let runner = root.create_humanode_runner(cmd)?;
Expand All @@ -29,7 +32,7 @@ pub async fn run() -> sc_cli::Result<()> {
import_queue,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, import_queue), task_manager))
Ok((cmd.base.run(client, import_queue), task_manager))
})
.await
}
Expand All @@ -42,7 +45,10 @@ pub async fn run() -> sc_cli::Result<()> {
task_manager,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, config.substrate.database), task_manager))
Ok((
cmd.base.run(client, config.substrate.database),
task_manager,
))
})
.await
}
Expand All @@ -55,7 +61,10 @@ pub async fn run() -> sc_cli::Result<()> {
task_manager,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, config.substrate.chain_spec), task_manager))
Ok((
cmd.base.run(client, config.substrate.chain_spec),
task_manager,
))
})
.await
}
Expand All @@ -69,13 +78,13 @@ pub async fn run() -> sc_cli::Result<()> {
import_queue,
..
} = service::new_partial(&config)?;
Ok((cmd.run(client, import_queue), task_manager))
Ok((cmd.base.run(client, import_queue), task_manager))
})
.await
}
Some(Subcommand::PurgeChain(cmd)) => {
let runner = root.create_humanode_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.substrate.database))
runner.sync_run(|config| cmd.base.run(config.substrate.database))
}
Some(Subcommand::Revert(cmd)) => {
let runner = root.create_humanode_runner(cmd)?;
Expand All @@ -92,7 +101,10 @@ pub async fn run() -> sc_cli::Result<()> {
sc_finality_grandpa::revert(client, blocks)?;
Ok(())
});
Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
Ok((
cmd.base.run(client, backend, Some(aux_revert)),
task_manager,
))
})
.await
}
Expand Down Expand Up @@ -139,7 +151,7 @@ pub async fn run() -> sc_cli::Result<()> {
if !cfg!(feature = "runtime-benchmarks") {
return Err(
"Runtime benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
You can enable it with `--features runtime-benchmarks`."
.into(),
);
}
Expand All @@ -166,7 +178,7 @@ pub async fn run() -> sc_cli::Result<()> {
})
}
None => {
let runner = root.create_humanode_runner(&root.run)?;
let runner = root.create_humanode_runner(&root.command.run)?;
sc_cli::print_node_infos::<Root>(&runner.config().substrate);
runner
.run_node(|config| async move {
Expand All @@ -178,3 +190,5 @@ pub async fn run() -> sc_cli::Result<()> {
}
}
}

impl super::CliConfigurationExt for frame_benchmarking_cli::BenchmarkCmd {}
Loading