Skip to content

Commit 90500a3

Browse files
Introduce frontier backend configuration
1 parent bd7b194 commit 90500a3

File tree

6 files changed

+39
-17
lines changed

6 files changed

+39
-17
lines changed

crates/humanode-peer/src/cli/config.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,19 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider {
5252
max_stored_filters: params.max_stored_filters,
5353
fee_history_limit: params.fee_history_limit,
5454
execute_gas_limit_multiplier: params.execute_gas_limit_multiplier,
55-
frontier_backend_type: params.frontier_backend_type,
56-
frontier_sql_backend_pool_size: params.frontier_sql_backend_pool_size,
57-
frontier_sql_backend_num_ops_timeout: params.frontier_sql_backend_num_ops_timeout,
58-
frontier_sql_backend_thread_count: params.frontier_sql_backend_thread_count,
59-
frontier_sql_backend_cache_size: params.frontier_sql_backend_cache_size,
6055
});
6156

57+
let frontier_backend =
58+
self.frontier_backend()
59+
.map(|params| configuration::FrontierBackend {
60+
frontier_backend_type: params.frontier_backend_type,
61+
frontier_sql_backend_pool_size: params.frontier_sql_backend_pool_size,
62+
frontier_sql_backend_num_ops_timeout: params
63+
.frontier_sql_backend_num_ops_timeout,
64+
frontier_sql_backend_thread_count: params.frontier_sql_backend_thread_count,
65+
frontier_sql_backend_cache_size: params.frontier_sql_backend_cache_size,
66+
});
67+
6268
let time_warp = self.time_warp_params().and_then(|params| {
6369
params
6470
.time_warp_fork_timestamp
@@ -76,6 +82,7 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider {
7682
substrate,
7783
bioauth_flow,
7884
ethereum_rpc,
85+
frontier_backend,
7986
time_warp,
8087
})
8188
}
@@ -90,6 +97,11 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider {
9097
None
9198
}
9299

100+
/// Provide the Frontier backend params.
101+
fn frontier_backend(&self) -> Option<&params::FrontierBackendParams> {
102+
None
103+
}
104+
93105
/// Provide the time warp related params, if available.
94106
fn time_warp_params(&self) -> Option<&params::TimeWarpParams> {
95107
None

crates/humanode-peer/src/cli/params.rs

+4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ pub struct EthereumRpcParams {
7575
/// block.gas_limit * execute_gas_limit_multiplier.
7676
#[arg(long, default_value = "10")]
7777
pub execute_gas_limit_multiplier: u64,
78+
}
7879

80+
/// Shared CLI parameters used to configure Frontier backend.
81+
#[derive(Debug, clap::Parser, Clone)]
82+
pub struct FrontierBackendParams {
7983
/// Sets the frontier backend type (KeyValue or Sql).
8084
#[arg(long, value_enum, ignore_case = true, default_value_t = FrontierBackendType::default())]
8185
pub frontier_backend_type: FrontierBackendType,

crates/humanode-peer/src/cli/run.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ pub async fn run() -> sc_cli::Result<()> {
231231
runner.sync_run(|config| {
232232
let partial = service::new_partial(&config)?;
233233
let frontier_backend = match partial.other.4 {
234-
fc_db::Backend::KeyValue(kv) => Arc::new(kv),
235-
_ => panic!("Only fc_db::Backend::KeyValue supported"),
234+
fc_db::Backend::KeyValue(kv_fb) => Arc::new(kv_fb),
235+
_ => panic!("Only fc_db::Backend::KeyValue supported for FrontierDb command"),
236236
};
237237
cmd.run(partial.client, frontier_backend)
238238
})

crates/humanode-peer/src/configuration.rs

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pub struct Configuration {
2121
/// Ethereum RPC configuration.
2222
pub ethereum_rpc: Option<EthereumRpc>,
2323

24+
/// Frontier backend configuration.
25+
pub frontier_backend: Option<FrontierBackend>,
26+
2427
/// Time warp mode configuration.
2528
/// If not defined, time warp mode isn't enabled.
2629
pub time_warp: Option<TimeWarp>,
@@ -72,7 +75,10 @@ pub struct EthereumRpc {
7275
/// When using eth_call/eth_estimateGas, the maximum allowed gas limit will be
7376
/// block.gas_limit * execute_gas_limit_multiplier.
7477
pub execute_gas_limit_multiplier: u64,
78+
}
7579

80+
/// Frontier backend configuration parameters.
81+
pub struct FrontierBackend {
7682
/// Sets the frontier backend type (KeyValue or Sql).
7783
pub frontier_backend_type: FrontierBackendType,
7884

crates/humanode-peer/src/service/frontier.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use sc_client_api::backend::Backend;
99
use sc_service::{BasePath, Configuration};
1010

1111
use super::{FrontierBackend, FullClient};
12-
use crate::configuration::{EthereumRpc, FrontierBackendType};
12+
use crate::configuration::{self, FrontierBackendType};
1313

1414
/// Create frontier dir.
1515
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 {
2727
pub fn frontier_backend(
2828
config: &Configuration,
2929
client: Arc<FullClient>,
30-
eth_rpc: &Option<EthereumRpc>,
30+
frontier_backend: &Option<configuration::FrontierBackend>,
3131
eth_overrides: Arc<OverrideHandle<Block>>,
3232
) -> FrontierBackend {
3333
let key_value_frontier_backend = FrontierBackend::KeyValue(
@@ -39,8 +39,8 @@ pub fn frontier_backend(
3939
.unwrap(),
4040
);
4141

42-
if let Some(eth_rpc) = eth_rpc {
43-
match eth_rpc.frontier_backend_type {
42+
if let Some(fb) = frontier_backend {
43+
match fb.frontier_backend_type {
4444
FrontierBackendType::KeyValue => key_value_frontier_backend,
4545
FrontierBackendType::Sql => {
4646
let db_path = db_config_dir(config).join("sql");
@@ -53,11 +53,11 @@ pub fn frontier_backend(
5353
.to_str()
5454
.unwrap(),
5555
create_if_missing: true,
56-
thread_count: eth_rpc.frontier_sql_backend_thread_count,
57-
cache_size: eth_rpc.frontier_sql_backend_cache_size,
56+
thread_count: fb.frontier_sql_backend_thread_count,
57+
cache_size: fb.frontier_sql_backend_cache_size,
5858
}),
59-
eth_rpc.frontier_sql_backend_pool_size,
60-
std::num::NonZeroU32::new(eth_rpc.frontier_sql_backend_num_ops_timeout),
59+
fb.frontier_sql_backend_pool_size,
60+
std::num::NonZeroU32::new(fb.frontier_sql_backend_num_ops_timeout),
6161
Arc::clone(&eth_overrides),
6262
))
6363
.unwrap_or_else(|err| panic!("failed creating sql backend: {:?}", err));

crates/humanode-peer/src/service/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn new_partial(
110110
let Configuration {
111111
substrate: config,
112112
time_warp: time_warp_config,
113-
ethereum_rpc: eth_rpc,
113+
frontier_backend: fronter_backend_config,
114114
..
115115
} = config;
116116

@@ -173,7 +173,7 @@ pub fn new_partial(
173173
let frontier_backend = frontier::frontier_backend(
174174
config,
175175
Arc::clone(&client),
176-
eth_rpc,
176+
fronter_backend_config,
177177
fc_storage::overrides_handle(Arc::clone(&client)),
178178
);
179179
let frontier_block_import = FrontierBlockImport::new(babe_block_import, Arc::clone(&client));

0 commit comments

Comments
 (0)