From 122e94503a8ca03faa7af4ab398a725247804ca0 Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Tue, 21 Jun 2022 20:22:58 +0400 Subject: [PATCH] Refactor the cli parameters handling --- .../bioauth/api_versions.rs | 4 +- .../bioauth/authurl.rs | 0 .../bioauth/key/generate.rs | 0 .../bioauth/key/insert.rs | 0 .../bioauth/key/inspect.rs | 0 .../bioauth/key/list.rs | 0 .../bioauth/key/mod.rs | 0 .../{subcommand => command}/bioauth/mod.rs | 0 .../ethereum/generate.rs | 0 .../ethereum/inspect.rs | 0 .../{subcommand => command}/ethereum/mod.rs | 0 .../{subcommand => command}/ethereum/utils.rs | 0 crates/humanode-peer/src/cli/command/mod.rs | 74 ++++++++++++ .../src/cli/{run_cmd.rs => command/run.rs} | 10 +- crates/humanode-peer/src/cli/config.rs | 28 +++-- crates/humanode-peer/src/cli/mod.rs | 7 +- crates/humanode-peer/src/cli/params.rs | 14 ++- crates/humanode-peer/src/cli/root.rs | 12 +- crates/humanode-peer/src/cli/run.rs | 34 ++++-- .../humanode-peer/src/cli/subcommand/mod.rs | 59 ---------- .../src/cli/substrate_cmd_adapter.rs | 106 ++++++++++++++++++ crates/humanode-peer/src/configuration.rs | 16 ++- crates/humanode-peer/src/service/mod.rs | 17 ++- 23 files changed, 270 insertions(+), 111 deletions(-) rename crates/humanode-peer/src/cli/{subcommand => command}/bioauth/api_versions.rs (94%) rename crates/humanode-peer/src/cli/{subcommand => command}/bioauth/authurl.rs (100%) rename crates/humanode-peer/src/cli/{subcommand => command}/bioauth/key/generate.rs (100%) rename crates/humanode-peer/src/cli/{subcommand => command}/bioauth/key/insert.rs (100%) rename crates/humanode-peer/src/cli/{subcommand => command}/bioauth/key/inspect.rs (100%) rename crates/humanode-peer/src/cli/{subcommand => command}/bioauth/key/list.rs (100%) rename crates/humanode-peer/src/cli/{subcommand => command}/bioauth/key/mod.rs (100%) rename crates/humanode-peer/src/cli/{subcommand => command}/bioauth/mod.rs (100%) rename crates/humanode-peer/src/cli/{subcommand => command}/ethereum/generate.rs (100%) rename crates/humanode-peer/src/cli/{subcommand => command}/ethereum/inspect.rs (100%) rename crates/humanode-peer/src/cli/{subcommand => command}/ethereum/mod.rs (100%) rename crates/humanode-peer/src/cli/{subcommand => command}/ethereum/utils.rs (100%) create mode 100644 crates/humanode-peer/src/cli/command/mod.rs rename crates/humanode-peer/src/cli/{run_cmd.rs => command/run.rs} (75%) delete mode 100644 crates/humanode-peer/src/cli/subcommand/mod.rs create mode 100644 crates/humanode-peer/src/cli/substrate_cmd_adapter.rs diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/api_versions.rs b/crates/humanode-peer/src/cli/command/bioauth/api_versions.rs similarity index 94% rename from crates/humanode-peer/src/cli/subcommand/bioauth/api_versions.rs rename to crates/humanode-peer/src/cli/command/bioauth/api_versions.rs index 7a07bff96..628571a70 100644 --- a/crates/humanode-peer/src/cli/subcommand/bioauth/api_versions.rs +++ b/crates/humanode-peer/src/cli/command/bioauth/api_versions.rs @@ -32,4 +32,6 @@ impl CliConfiguration for ApiVersionsCmd { } } -impl CliConfigurationExt for ApiVersionsCmd {} +impl CliConfigurationExt for ApiVersionsCmd { + +} diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/authurl.rs b/crates/humanode-peer/src/cli/command/bioauth/authurl.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/bioauth/authurl.rs rename to crates/humanode-peer/src/cli/command/bioauth/authurl.rs diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/key/generate.rs b/crates/humanode-peer/src/cli/command/bioauth/key/generate.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/bioauth/key/generate.rs rename to crates/humanode-peer/src/cli/command/bioauth/key/generate.rs diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/key/insert.rs b/crates/humanode-peer/src/cli/command/bioauth/key/insert.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/bioauth/key/insert.rs rename to crates/humanode-peer/src/cli/command/bioauth/key/insert.rs diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/key/inspect.rs b/crates/humanode-peer/src/cli/command/bioauth/key/inspect.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/bioauth/key/inspect.rs rename to crates/humanode-peer/src/cli/command/bioauth/key/inspect.rs diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/key/list.rs b/crates/humanode-peer/src/cli/command/bioauth/key/list.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/bioauth/key/list.rs rename to crates/humanode-peer/src/cli/command/bioauth/key/list.rs diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/key/mod.rs b/crates/humanode-peer/src/cli/command/bioauth/key/mod.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/bioauth/key/mod.rs rename to crates/humanode-peer/src/cli/command/bioauth/key/mod.rs diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/mod.rs b/crates/humanode-peer/src/cli/command/bioauth/mod.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/bioauth/mod.rs rename to crates/humanode-peer/src/cli/command/bioauth/mod.rs diff --git a/crates/humanode-peer/src/cli/subcommand/ethereum/generate.rs b/crates/humanode-peer/src/cli/command/ethereum/generate.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/ethereum/generate.rs rename to crates/humanode-peer/src/cli/command/ethereum/generate.rs diff --git a/crates/humanode-peer/src/cli/subcommand/ethereum/inspect.rs b/crates/humanode-peer/src/cli/command/ethereum/inspect.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/ethereum/inspect.rs rename to crates/humanode-peer/src/cli/command/ethereum/inspect.rs diff --git a/crates/humanode-peer/src/cli/subcommand/ethereum/mod.rs b/crates/humanode-peer/src/cli/command/ethereum/mod.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/ethereum/mod.rs rename to crates/humanode-peer/src/cli/command/ethereum/mod.rs diff --git a/crates/humanode-peer/src/cli/subcommand/ethereum/utils.rs b/crates/humanode-peer/src/cli/command/ethereum/utils.rs similarity index 100% rename from crates/humanode-peer/src/cli/subcommand/ethereum/utils.rs rename to crates/humanode-peer/src/cli/command/ethereum/utils.rs diff --git a/crates/humanode-peer/src/cli/command/mod.rs b/crates/humanode-peer/src/cli/command/mod.rs new file mode 100644 index 000000000..07d75a19c --- /dev/null +++ b/crates/humanode-peer/src/cli/command/mod.rs @@ -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, + + /// 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, + ), + + /// Validate blocks. + CheckBlock( + substrate_cmd_adapter::Cmd, + ), + + /// Export blocks. + ExportBlocks( + substrate_cmd_adapter::Cmd, + ), + + /// Export the state of a given block into a chain spec. + ExportState( + substrate_cmd_adapter::Cmd, + ), + + /// Import blocks. + ImportBlocks( + substrate_cmd_adapter::Cmd, + ), + + /// Remove the whole chain. + PurgeChain( + substrate_cmd_adapter::Cmd, + ), + + /// Revert the chain to a previous state. + Revert(substrate_cmd_adapter::Cmd), + + /// 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), +} diff --git a/crates/humanode-peer/src/cli/run_cmd.rs b/crates/humanode-peer/src/cli/command/run.rs similarity index 75% rename from crates/humanode-peer/src/cli/run_cmd.rs rename to crates/humanode-peer/src/cli/command/run.rs index 35e19f2bc..82b8df08a 100644 --- a/crates/humanode-peer/src/cli/run_cmd.rs +++ b/crates/humanode-peer/src/cli/command/run.rs @@ -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. @@ -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 { @@ -35,4 +39,8 @@ impl CliConfigurationExt for RunCmd { fn evm_params(&self) -> Option<¶ms::EvmParams> { Some(&self.evm_params) } + + fn ethereum_rpc_params(&self) -> Option<¶ms::EthereumRpcParams> { + Some(&self.ethereum_rpc_params) + } } diff --git a/crates/humanode-peer/src/cli/config.rs b/crates/humanode-peer/src/cli/config.rs index 54f7deb55..958ff1a83 100644 --- a/crates/humanode-peer/src/cli/config.rs +++ b/crates/humanode-peer/src/cli/config.rs @@ -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, }) } @@ -63,10 +72,15 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider { None } - /// Provide the evm params, if available. + /// Provide the EVM params. fn evm_params(&self) -> Option<¶ms::EvmParams> { None } + + /// Provide the Ethereum RPC params. + fn ethereum_rpc_params(&self) -> Option<¶ms::EthereumRpcParams> { + None + } } /// Indirect relation to the [`sc_cli::CliConfiguration`] for any type. diff --git a/crates/humanode-peer/src/cli/mod.rs b/crates/humanode-peer/src/cli/mod.rs index 995befd89..75f990f31 100644 --- a/crates/humanode-peer/src/cli/mod.rs +++ b/crates/humanode-peer/src/cli/mod.rs @@ -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::*; diff --git a/crates/humanode-peer/src/cli/params.rs b/crates/humanode-peer/src/cli/params.rs index ec095ca11..25b41bae5 100644 --- a/crates/humanode-peer/src/cli/params.rs +++ b/crates/humanode-peer/src/cli/params.rs @@ -51,9 +51,17 @@ pub struct BioauthFlowParams { pub robonode_url: Option, } -/// 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")] @@ -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, diff --git a/crates/humanode-peer/src/cli/root.rs b/crates/humanode-peer/src/cli/root.rs index ca3a2c216..8518d10d4 100644 --- a/crates/humanode-peer/src/cli/root.rs +++ b/crates/humanode-peer/src/cli/root.rs @@ -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, - - /// 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 { @@ -74,5 +70,3 @@ impl Root { Runner::new(self, command) } } - -impl CliConfigurationExt for sc_cli::RunCmd {} diff --git a/crates/humanode-peer/src/cli/run.rs b/crates/humanode-peer/src/cli/run.rs index 2d716cf7b..c61954516 100644 --- a/crates/humanode-peer/src/cli/run.rs +++ b/crates/humanode-peer/src/cli/run.rs @@ -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)?; @@ -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 } @@ -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 } @@ -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 } @@ -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)?; @@ -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 } @@ -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(), ); } @@ -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::(&runner.config().substrate); runner .run_node(|config| async move { @@ -178,3 +190,5 @@ pub async fn run() -> sc_cli::Result<()> { } } } + +impl super::CliConfigurationExt for frame_benchmarking_cli::BenchmarkCmd {} diff --git a/crates/humanode-peer/src/cli/subcommand/mod.rs b/crates/humanode-peer/src/cli/subcommand/mod.rs deleted file mode 100644 index b834c9d57..000000000 --- a/crates/humanode-peer/src/cli/subcommand/mod.rs +++ /dev/null @@ -1,59 +0,0 @@ -//! Humanode peer subcommands. -//! The `substrate` built-in commands are embedded as-is, additional commands are introduced as -//! nested `mod`s in this `mod`. - -use super::CliConfigurationExt; - -pub mod bioauth; -pub mod ethereum; - -/// Humanode peer subcommands. -#[derive(Debug, clap::Subcommand)] -pub enum Subcommand { - /// Key management cli utilities - #[clap(subcommand)] - Key(sc_cli::KeySubcommand), - - /// Build a chain specification. - BuildSpec(sc_cli::BuildSpecCmd), - - /// Validate blocks. - CheckBlock(sc_cli::CheckBlockCmd), - - /// Export blocks. - ExportBlocks(sc_cli::ExportBlocksCmd), - - /// Export the state of a given block into a chain spec. - ExportState(sc_cli::ExportStateCmd), - - /// Import blocks. - ImportBlocks(sc_cli::ImportBlocksCmd), - - /// Remove the whole chain. - PurgeChain(sc_cli::PurgeChainCmd), - - /// Revert the chain to a previous state. - Revert(sc_cli::RevertCmd), - - /// Biometric authentication related subcommands. - #[clap(subcommand)] - Bioauth(bioauth::BioauthCmd), - - /// Ethereum related subcommands. - #[clap(subcommand)] - Ethereum(ethereum::EthereumCmd), - - /// The custom benchmark subcommmand benchmarking runtime pallets. - #[clap(name = "benchmark", about = "Benchmark runtime pallets.")] - #[clap(subcommand)] - Benchmark(frame_benchmarking_cli::BenchmarkCmd), -} - -impl CliConfigurationExt for sc_cli::BuildSpecCmd {} -impl CliConfigurationExt for sc_cli::CheckBlockCmd {} -impl CliConfigurationExt for sc_cli::ExportBlocksCmd {} -impl CliConfigurationExt for sc_cli::ExportStateCmd {} -impl CliConfigurationExt for sc_cli::ImportBlocksCmd {} -impl CliConfigurationExt for sc_cli::PurgeChainCmd {} -impl CliConfigurationExt for sc_cli::RevertCmd {} -impl CliConfigurationExt for frame_benchmarking_cli::BenchmarkCmd {} diff --git a/crates/humanode-peer/src/cli/substrate_cmd_adapter.rs b/crates/humanode-peer/src/cli/substrate_cmd_adapter.rs new file mode 100644 index 000000000..9ca49b61c --- /dev/null +++ b/crates/humanode-peer/src/cli/substrate_cmd_adapter.rs @@ -0,0 +1,106 @@ +//! An adapter to allow passing additional params to the substrate commands and subcommands. + +use super::params; +use crate::cli::{CliConfigurationExt, SubstrateCliConfigurationProvider}; + +/// The commands adapter. +#[derive(Debug, clap::Parser)] +pub struct Cmd +where + B: clap::Args + sc_cli::CliConfiguration, + E: clap::Args, +{ + /// The base parameter. + #[clap(flatten)] + pub base: B, + + /// The extension. + #[clap(flatten)] + pub extra: E, +} + +/// The subcommand adapter. +#[derive(Debug, clap::Parser)] +pub struct Subcommand +where + B: clap::Subcommand + sc_cli::CliConfiguration, + E: clap::Args, +{ + /// The base parameter. + #[clap(subcommand)] + pub base: B, + + /// The extension. + #[clap(flatten)] + pub extra: E, +} + +impl SubstrateCliConfigurationProvider for Cmd +where + B: clap::Args + sc_cli::CliConfiguration, + E: clap::Args, +{ + type SubstrateCliConfiguration = B; + + fn substrate_cli_configuration(&self) -> &Self::SubstrateCliConfiguration { + &self.base + } +} + +impl SubstrateCliConfigurationProvider for Subcommand +where + B: clap::Subcommand + sc_cli::CliConfiguration, + E: clap::Args, +{ + type SubstrateCliConfiguration = B; + + fn substrate_cli_configuration(&self) -> &Self::SubstrateCliConfiguration { + &self.base + } +} + +#[derive(Debug, clap::Parser)] +pub struct NoExtraParams; + +impl CliConfigurationExt for Cmd where B: clap::Args + sc_cli::CliConfiguration {} +impl CliConfigurationExt for Subcommand where + B: clap::Subcommand + sc_cli::CliConfiguration +{ +} + +#[derive(Debug, clap::Parser)] +pub struct ExtraEvmParams { + #[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 CliConfigurationExt for Cmd +where + B: clap::Args + sc_cli::CliConfiguration, +{ + fn evm_params(&self) -> Option<¶ms::EvmParams> { + Some(&self.extra.evm_params) + } + + fn ethereum_rpc_params(&self) -> Option<¶ms::EthereumRpcParams> { + Some(&self.extra.ethereum_rpc_params) + } +} + +impl CliConfigurationExt for Subcommand +where + B: clap::Subcommand + sc_cli::CliConfiguration, +{ + fn evm_params(&self) -> Option<¶ms::EvmParams> { + Some(&self.extra.evm_params) + } + + fn ethereum_rpc_params(&self) -> Option<¶ms::EthereumRpcParams> { + Some(&self.extra.ethereum_rpc_params) + } +} diff --git a/crates/humanode-peer/src/configuration.rs b/crates/humanode-peer/src/configuration.rs index c7fc34bbd..6a3bd6246 100644 --- a/crates/humanode-peer/src/configuration.rs +++ b/crates/humanode-peer/src/configuration.rs @@ -15,8 +15,11 @@ pub struct Configuration { /// always required. pub bioauth_flow: Option, - /// EVM configuration, - pub evm: Option, + /// EVM configuration. + pub evm: Evm, + + /// Ethereum RPC configuration. + pub ethereum_rpc: Option, } /// Bioauth flow configuration parameters. @@ -50,6 +53,12 @@ impl BioauthFlow { /// EVM configuration parameters. pub struct Evm { + /// The dynamic-fee pallet target gas price set by block author. + pub target_gas_price: u64, +} + +/// Ethereum RPC configuration parameters. +pub struct EthereumRpc { /// Maximum number of blocks to keep the log information available /// for querying via the RPC (from the latest block). pub max_past_logs: u32, @@ -57,9 +66,6 @@ pub struct Evm { /// Maximum number of stored filters. pub max_stored_filters: usize, - /// The dynamic-fee pallet target gas price set by block author. - pub target_gas_price: u64, - /// Maximum fee history cache size. pub fee_history_limit: u64, } diff --git a/crates/humanode-peer/src/service/mod.rs b/crates/humanode-peer/src/service/mod.rs index 6ae1bdb91..0b313dd42 100644 --- a/crates/humanode-peer/src/service/mod.rs +++ b/crates/humanode-peer/src/service/mod.rs @@ -112,10 +112,6 @@ pub fn new_partial( .. } = config; - let evm_config = evm_config - .as_ref() - .ok_or_else(|| ServiceError::Other("evm config is not set".into()))?; - let telemetry = config .telemetry_endpoints .clone() @@ -241,7 +237,8 @@ pub async fn new_full(config: Configuration) -> Result Result Result = Some(Arc::new(Mutex::new(BTreeMap::new()))); let eth_fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new())); - let eth_fee_history_limit = evm_config.fee_history_limit; + let eth_fee_history_limit = ethereum_rpc_config.fee_history_limit; let eth_overrides = humanode_rpc::overrides_handle(Arc::clone(&client)); let proposer_factory = sc_basic_authorship::ProposerFactory::new( @@ -356,7 +353,7 @@ pub async fn new_full(config: Configuration) -> Result Result