Skip to content

Commit 464d5b3

Browse files
authored
feat: add cmd to init default config (#1382)
1 parent 03c2e74 commit 464d5b3

15 files changed

Lines changed: 455 additions & 169 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fendermint/app/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ prometheus_exporter = { workspace = true }
2828
prost = { workspace = true }
2929
rand_chacha = { workspace = true }
3030
serde = { workspace = true }
31+
toml = { workspace = true }
3132
serde_json = { workspace = true }
3233
serde_with = { workspace = true }
3334
tendermint = { workspace = true }
@@ -68,8 +69,8 @@ fendermint_vm_snapshot = { path = "../vm/snapshot" }
6869
fendermint_vm_topdown = { path = "../vm/topdown" }
6970

7071
# .car file wrapped in a crate
71-
actors-builtin-car = { path = "../actors-builtin-car"}
72-
actors-custom-car = { path = "../actors-custom-car"}
72+
actors-builtin-car = { path = "../actors-builtin-car" }
73+
actors-custom-car = { path = "../actors-custom-car" }
7374

7475

7576
fvm = { workspace = true }

fendermint/app/config/default.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ builtin_actors_bundle = "bundle.car"
1515
custom_actors_bundle = "custom_actors_bundle.car"
1616
# Where to reach CometBFT for queries or broadcasting transactions.
1717
tendermint_rpc_url = "http://127.0.0.1:26657"
18+
# Where to reach CometBFT for subscriptions.
19+
tendermint_websocket_url = "ws://127.0.0.1:26657/websocket"
1820
# Block height where we should gracefully stop the node to perform maintenance or
1921
# with planning for an upcoming coordinated upgrade. Set to 0 to never halt.
2022
halt_height = 0
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
// Copyright 2022-2024 Protocol Labs
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4-
use clap::Args;
4+
use clap::{Args, Subcommand};
55

66
#[derive(Args, Debug)]
7-
pub struct ConfigArgs;
7+
pub struct DisplayConfigArgs;
8+
9+
#[derive(Args, Debug)]
10+
pub struct InitConfigArgs;
11+
12+
#[derive(Subcommand, Debug)]
13+
pub enum ConfigCommands {
14+
/// Create a new default config file
15+
Init(InitConfigArgs),
16+
/// Display the current config
17+
Display(DisplayConfigArgs),
18+
}
19+
20+
#[derive(Args, Debug)]
21+
pub struct ConfigArgs {
22+
#[command(subcommand)]
23+
pub command: ConfigCommands,
24+
}

fendermint/app/settings/src/eth.rs

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

44
use fvm_shared::econ::TokenAmount;
5-
use ipc_provider::config::deserialize::{
6-
deserialize_cors_headers, deserialize_cors_methods, deserialize_cors_origins,
5+
use ipc_provider::config::serialize::{
6+
vec_to_allow_headers, vec_to_allow_methods, vec_to_allow_origin,
77
};
8-
use serde::Deserialize;
8+
use serde::de::Error as DeError;
9+
use serde::{Deserialize, Deserializer, Serialize};
910
use serde_with::{serde_as, DurationSeconds};
1011
use std::time::Duration;
1112
use tower_http::cors::{AllowHeaders, AllowMethods, AllowOrigin};
@@ -16,7 +17,7 @@ use crate::{IsHumanReadable, MetricsSettings, SocketAddress};
1617

1718
/// Ethereum API facade settings.
1819
#[serde_as]
19-
#[derive(Debug, Deserialize, Clone)]
20+
#[derive(Debug, Deserialize, Serialize, Clone)]
2021
pub struct EthSettings {
2122
pub listen: SocketAddress,
2223
#[serde_as(as = "DurationSeconds<u64>")]
@@ -29,8 +30,36 @@ pub struct EthSettings {
2930
pub tracing: TracingSettings,
3031
}
3132

33+
impl Default for EthSettings {
34+
fn default() -> Self {
35+
EthSettings {
36+
filter_timeout: Duration::from_secs(300),
37+
cache_capacity: 1000000,
38+
max_nonce_gap: 10,
39+
gas: GasOpt {
40+
min_gas_premium: TokenAmount::from_atto(100000),
41+
num_blocks_max_prio_fee: 10,
42+
max_fee_hist_size: 1024,
43+
},
44+
listen: SocketAddress {
45+
host: "127.0.0.1".into(),
46+
port: 8545,
47+
},
48+
metrics: MetricsSettings {
49+
enabled: true,
50+
listen: SocketAddress {
51+
host: "127.0.0.1".into(),
52+
port: 9185,
53+
},
54+
},
55+
cors: CorsOpt::default(),
56+
tracing: TracingSettings::default(),
57+
}
58+
}
59+
}
60+
3261
#[serde_as]
33-
#[derive(Debug, Clone, Deserialize)]
62+
#[derive(Debug, Clone, Serialize, Deserialize)]
3463
pub struct GasOpt {
3564
/// Minimum gas fee in atto.
3665
#[serde_as(as = "IsHumanReadable")]
@@ -40,12 +69,55 @@ pub struct GasOpt {
4069
}
4170

4271
#[serde_as]
43-
#[derive(Debug, Clone, Deserialize)]
72+
#[derive(Debug, Clone, Serialize, Default)]
4473
pub struct CorsOpt {
45-
#[serde(deserialize_with = "deserialize_cors_origins")]
74+
#[serde(default, rename = "allowed_origins")]
75+
pub temp_origins: Vec<String>,
76+
#[serde(default, rename = "allowed_methods")]
77+
pub temp_methods: Vec<String>,
78+
#[serde(default, rename = "allowed_headers")]
79+
pub temp_headers: Vec<String>,
80+
81+
// Runtime representations, skipped during (de)serialization.
82+
#[serde(skip)]
4683
pub allowed_origins: AllowOrigin,
47-
#[serde(deserialize_with = "deserialize_cors_methods")]
84+
#[serde(skip)]
4885
pub allowed_methods: AllowMethods,
49-
#[serde(deserialize_with = "deserialize_cors_headers")]
86+
#[serde(skip)]
5087
pub allowed_headers: AllowHeaders,
5188
}
89+
90+
impl<'de> Deserialize<'de> for CorsOpt {
91+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
92+
where
93+
D: Deserializer<'de>,
94+
{
95+
#[derive(Deserialize)]
96+
struct Temp {
97+
#[serde(default, rename = "allowed_origins")]
98+
allowed_origins: Vec<String>,
99+
#[serde(default, rename = "allowed_methods")]
100+
allowed_methods: Vec<String>,
101+
#[serde(default, rename = "allowed_headers")]
102+
allowed_headers: Vec<String>,
103+
}
104+
105+
let temp = Temp::deserialize(deserializer)?;
106+
107+
let allowed_origins =
108+
vec_to_allow_origin(temp.allowed_origins.clone()).map_err(D::Error::custom)?;
109+
let allowed_methods =
110+
vec_to_allow_methods(temp.allowed_methods.clone()).map_err(D::Error::custom)?;
111+
let allowed_headers =
112+
vec_to_allow_headers(temp.allowed_headers.clone()).map_err(D::Error::custom)?;
113+
114+
Ok(CorsOpt {
115+
temp_origins: temp.allowed_origins,
116+
temp_methods: temp.allowed_methods,
117+
temp_headers: temp.allowed_headers,
118+
allowed_origins,
119+
allowed_methods,
120+
allowed_headers,
121+
})
122+
}
123+
}

fendermint/app/settings/src/fvm.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,20 @@
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

44
use fvm_shared::econ::TokenAmount;
5-
use serde::Deserialize;
5+
use serde::{Deserialize, Serialize};
66
use serde_with::serde_as;
77

88
use crate::IsHumanReadable;
99

1010
#[serde_as]
11-
#[derive(Debug, Deserialize, Clone)]
11+
#[derive(Debug, Deserialize, Serialize, Clone)]
1212
pub struct FvmSettings {
1313
/// Overestimation rate applied to gas estimations to ensure that the
1414
/// message goes through
1515
pub gas_overestimation_rate: f64,
1616
/// Gas search step increase used to find the optimal gas limit.
1717
/// It determines how fine-grained we want the gas estimation to be.
1818
pub gas_search_step: f64,
19-
/// Indicate whether transactions should be fully executed during the checks performed
20-
/// when they are added to the mempool, or just the most basic ones are performed.
21-
///
22-
/// Enabling this option is required to fully support "pending" queries in the Ethereum API,
23-
/// otherwise only the nonces and balances are projected into a partial state.
24-
pub exec_in_check: bool,
2519

2620
/// Gas fee used when broadcasting transactions.
2721
#[serde_as(as = "IsHumanReadable")]
@@ -30,3 +24,14 @@ pub struct FvmSettings {
3024
#[serde_as(as = "IsHumanReadable")]
3125
pub gas_premium: TokenAmount,
3226
}
27+
28+
impl Default for FvmSettings {
29+
fn default() -> Self {
30+
FvmSettings {
31+
gas_overestimation_rate: 1.25,
32+
gas_search_step: 1.25,
33+
gas_fee_cap: TokenAmount::from_atto(0),
34+
gas_premium: TokenAmount::from_atto(0),
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)