Skip to content

Commit

Permalink
Introduce frontier backend configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Dec 11, 2023
1 parent bd7b194 commit 90500a3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
22 changes: 17 additions & 5 deletions crates/humanode-peer/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -76,6 +82,7 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider {
substrate,
bioauth_flow,
ethereum_rpc,
frontier_backend,
time_warp,
})
}
Expand All @@ -90,6 +97,11 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider {
None
}

/// Provide the Frontier backend params.
fn frontier_backend(&self) -> Option<&params::FrontierBackendParams> {
None
}

/// Provide the time warp related params, if available.
fn time_warp_params(&self) -> Option<&params::TimeWarpParams> {
None
Expand Down
4 changes: 4 additions & 0 deletions crates/humanode-peer/src/cli/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/humanode-peer/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
6 changes: 6 additions & 0 deletions crates/humanode-peer/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub struct Configuration {
/// Ethereum RPC configuration.
pub ethereum_rpc: Option<EthereumRpc>,

/// Frontier backend configuration.
pub frontier_backend: Option<FrontierBackend>,

/// Time warp mode configuration.
/// If not defined, time warp mode isn't enabled.
pub time_warp: Option<TimeWarp>,
Expand Down Expand Up @@ -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,

Expand Down
16 changes: 8 additions & 8 deletions crates/humanode-peer/src/service/frontier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,7 +27,7 @@ fn db_config_dir(config: &sc_service::Configuration) -> std::path::PathBuf {
pub fn frontier_backend(
config: &Configuration,
client: Arc<FullClient>,
eth_rpc: &Option<EthereumRpc>,
frontier_backend: &Option<configuration::FrontierBackend>,
eth_overrides: Arc<OverrideHandle<Block>>,
) -> FrontierBackend {
let key_value_frontier_backend = FrontierBackend::KeyValue(
Expand All @@ -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");
Expand All @@ -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(&eth_overrides),
))
.unwrap_or_else(|err| panic!("failed creating sql backend: {:?}", err));
Expand Down
4 changes: 2 additions & 2 deletions crates/humanode-peer/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 90500a3

Please sign in to comment.