From 90500a355c86c6b30f03b82474bf491fd616d74b Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Mon, 11 Dec 2023 16:29:02 +0300 Subject: [PATCH] Introduce frontier backend configuration --- crates/humanode-peer/src/cli/config.rs | 22 +++++++++++++++----- crates/humanode-peer/src/cli/params.rs | 4 ++++ crates/humanode-peer/src/cli/run.rs | 4 ++-- crates/humanode-peer/src/configuration.rs | 6 ++++++ crates/humanode-peer/src/service/frontier.rs | 16 +++++++------- crates/humanode-peer/src/service/mod.rs | 4 ++-- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/crates/humanode-peer/src/cli/config.rs b/crates/humanode-peer/src/cli/config.rs index df539ded1..27706267e 100644 --- a/crates/humanode-peer/src/cli/config.rs +++ b/crates/humanode-peer/src/cli/config.rs @@ -52,13 +52,19 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider { max_stored_filters: params.max_stored_filters, fee_history_limit: params.fee_history_limit, execute_gas_limit_multiplier: params.execute_gas_limit_multiplier, - frontier_backend_type: params.frontier_backend_type, - frontier_sql_backend_pool_size: params.frontier_sql_backend_pool_size, - frontier_sql_backend_num_ops_timeout: params.frontier_sql_backend_num_ops_timeout, - frontier_sql_backend_thread_count: params.frontier_sql_backend_thread_count, - frontier_sql_backend_cache_size: params.frontier_sql_backend_cache_size, }); + let frontier_backend = + self.frontier_backend() + .map(|params| configuration::FrontierBackend { + frontier_backend_type: params.frontier_backend_type, + frontier_sql_backend_pool_size: params.frontier_sql_backend_pool_size, + frontier_sql_backend_num_ops_timeout: params + .frontier_sql_backend_num_ops_timeout, + frontier_sql_backend_thread_count: params.frontier_sql_backend_thread_count, + frontier_sql_backend_cache_size: params.frontier_sql_backend_cache_size, + }); + let time_warp = self.time_warp_params().and_then(|params| { params .time_warp_fork_timestamp @@ -76,6 +82,7 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider { substrate, bioauth_flow, ethereum_rpc, + frontier_backend, time_warp, }) } @@ -90,6 +97,11 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider { None } + /// Provide the Frontier backend params. + fn frontier_backend(&self) -> Option<¶ms::FrontierBackendParams> { + None + } + /// Provide the time warp related params, if available. fn time_warp_params(&self) -> Option<¶ms::TimeWarpParams> { None diff --git a/crates/humanode-peer/src/cli/params.rs b/crates/humanode-peer/src/cli/params.rs index 9f0c4ea00..30d858e1c 100644 --- a/crates/humanode-peer/src/cli/params.rs +++ b/crates/humanode-peer/src/cli/params.rs @@ -75,7 +75,11 @@ pub struct EthereumRpcParams { /// block.gas_limit * execute_gas_limit_multiplier. #[arg(long, default_value = "10")] pub execute_gas_limit_multiplier: u64, +} +/// Shared CLI parameters used to configure Frontier backend. +#[derive(Debug, clap::Parser, Clone)] +pub struct FrontierBackendParams { /// Sets the frontier backend type (KeyValue or Sql). #[arg(long, value_enum, ignore_case = true, default_value_t = FrontierBackendType::default())] pub frontier_backend_type: FrontierBackendType, diff --git a/crates/humanode-peer/src/cli/run.rs b/crates/humanode-peer/src/cli/run.rs index fd986bace..896cbd461 100644 --- a/crates/humanode-peer/src/cli/run.rs +++ b/crates/humanode-peer/src/cli/run.rs @@ -231,8 +231,8 @@ pub async fn run() -> sc_cli::Result<()> { runner.sync_run(|config| { let partial = service::new_partial(&config)?; let frontier_backend = match partial.other.4 { - fc_db::Backend::KeyValue(kv) => Arc::new(kv), - _ => panic!("Only fc_db::Backend::KeyValue supported"), + fc_db::Backend::KeyValue(kv_fb) => Arc::new(kv_fb), + _ => panic!("Only fc_db::Backend::KeyValue supported for FrontierDb command"), }; cmd.run(partial.client, frontier_backend) }) diff --git a/crates/humanode-peer/src/configuration.rs b/crates/humanode-peer/src/configuration.rs index d75b47f28..479ffe1b2 100644 --- a/crates/humanode-peer/src/configuration.rs +++ b/crates/humanode-peer/src/configuration.rs @@ -21,6 +21,9 @@ pub struct Configuration { /// Ethereum RPC configuration. pub ethereum_rpc: Option, + /// Frontier backend configuration. + pub frontier_backend: Option, + /// Time warp mode configuration. /// If not defined, time warp mode isn't enabled. pub time_warp: Option, @@ -72,7 +75,10 @@ pub struct EthereumRpc { /// When using eth_call/eth_estimateGas, the maximum allowed gas limit will be /// block.gas_limit * execute_gas_limit_multiplier. pub execute_gas_limit_multiplier: u64, +} +/// Frontier backend configuration parameters. +pub struct FrontierBackend { /// Sets the frontier backend type (KeyValue or Sql). pub frontier_backend_type: FrontierBackendType, diff --git a/crates/humanode-peer/src/service/frontier.rs b/crates/humanode-peer/src/service/frontier.rs index 74f9ed0ea..dcdd8abca 100644 --- a/crates/humanode-peer/src/service/frontier.rs +++ b/crates/humanode-peer/src/service/frontier.rs @@ -9,7 +9,7 @@ use sc_client_api::backend::Backend; use sc_service::{BasePath, Configuration}; use super::{FrontierBackend, FullClient}; -use crate::configuration::{EthereumRpc, FrontierBackendType}; +use crate::configuration::{self, FrontierBackendType}; /// Create frontier dir. fn db_config_dir(config: &sc_service::Configuration) -> std::path::PathBuf { @@ -27,7 +27,7 @@ fn db_config_dir(config: &sc_service::Configuration) -> std::path::PathBuf { pub fn frontier_backend( config: &Configuration, client: Arc, - eth_rpc: &Option, + frontier_backend: &Option, eth_overrides: Arc>, ) -> FrontierBackend { let key_value_frontier_backend = FrontierBackend::KeyValue( @@ -39,8 +39,8 @@ pub fn frontier_backend( .unwrap(), ); - if let Some(eth_rpc) = eth_rpc { - match eth_rpc.frontier_backend_type { + if let Some(fb) = frontier_backend { + match fb.frontier_backend_type { FrontierBackendType::KeyValue => key_value_frontier_backend, FrontierBackendType::Sql => { let db_path = db_config_dir(config).join("sql"); @@ -53,11 +53,11 @@ pub fn frontier_backend( .to_str() .unwrap(), create_if_missing: true, - thread_count: eth_rpc.frontier_sql_backend_thread_count, - cache_size: eth_rpc.frontier_sql_backend_cache_size, + thread_count: fb.frontier_sql_backend_thread_count, + cache_size: fb.frontier_sql_backend_cache_size, }), - eth_rpc.frontier_sql_backend_pool_size, - std::num::NonZeroU32::new(eth_rpc.frontier_sql_backend_num_ops_timeout), + fb.frontier_sql_backend_pool_size, + std::num::NonZeroU32::new(fb.frontier_sql_backend_num_ops_timeout), Arc::clone(ð_overrides), )) .unwrap_or_else(|err| panic!("failed creating sql backend: {:?}", err)); diff --git a/crates/humanode-peer/src/service/mod.rs b/crates/humanode-peer/src/service/mod.rs index 516eef6b1..ce92c2a81 100644 --- a/crates/humanode-peer/src/service/mod.rs +++ b/crates/humanode-peer/src/service/mod.rs @@ -110,7 +110,7 @@ pub fn new_partial( let Configuration { substrate: config, time_warp: time_warp_config, - ethereum_rpc: eth_rpc, + frontier_backend: fronter_backend_config, .. } = config; @@ -173,7 +173,7 @@ pub fn new_partial( let frontier_backend = frontier::frontier_backend( config, Arc::clone(&client), - eth_rpc, + fronter_backend_config, fc_storage::overrides_handle(Arc::clone(&client)), ); let frontier_block_import = FrontierBlockImport::new(babe_block_import, Arc::clone(&client));