forest/cli_shared/cli/
config.rs1use super::client::Client;
5use crate::db::db_engine::DbConfig;
6use crate::libp2p::Libp2pConfig;
7use crate::shim::clock::ChainEpoch;
8use crate::shim::econ::TokenAmount;
9use crate::utils::misc::env::is_env_set_and_truthy;
10use crate::{chain_sync::SyncConfig, networks::NetworkChain};
11use serde::{Deserialize, Serialize};
12use std::path::PathBuf;
13
14const FOREST_CHAIN_INDEXER_ENABLED: &str = "FOREST_CHAIN_INDEXER_ENABLED";
15
16#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
18#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
19pub struct DaemonConfig {
20 pub user: Option<String>,
21 pub group: Option<String>,
22 pub umask: u16,
23 pub stdout: PathBuf,
24 pub stderr: PathBuf,
25 pub work_dir: PathBuf,
26 pub pid_file: Option<PathBuf>,
27}
28
29impl Default for DaemonConfig {
30 fn default() -> Self {
31 Self {
32 user: None,
33 group: None,
34 umask: 0o027,
35 stdout: "forest.out".into(),
36 stderr: "forest.err".into(),
37 work_dir: ".".into(),
38 pid_file: None,
39 }
40 }
41}
42
43#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
45#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
46pub struct EventsConfig {
47 #[cfg_attr(test, arbitrary(gen(|g| u32::arbitrary(g) as _)))]
48 pub max_filter_results: usize,
49 pub max_filter_height_range: ChainEpoch,
50}
51
52impl Default for EventsConfig {
53 fn default() -> Self {
54 Self {
55 max_filter_results: 10000,
56 max_filter_height_range: 2880,
57 }
58 }
59}
60
61#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
63#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
64pub struct FevmConfig {
65 #[cfg_attr(test, arbitrary(gen(|g| u32::arbitrary(g) as _)))]
66 pub eth_trace_filter_max_results: usize,
67}
68
69impl Default for FevmConfig {
70 fn default() -> Self {
71 Self {
72 eth_trace_filter_max_results: 500,
73 }
74 }
75}
76
77#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
78#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
79pub struct ChainIndexerConfig {
80 pub enable_indexer: bool,
82 pub gc_retention_epochs: Option<u32>,
84}
85
86impl Default for ChainIndexerConfig {
87 fn default() -> Self {
88 Self {
89 enable_indexer: is_env_set_and_truthy(FOREST_CHAIN_INDEXER_ENABLED).unwrap_or(false),
90 gc_retention_epochs: None,
91 }
92 }
93}
94
95#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
96#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
97pub struct FeeConfig {
98 #[serde(with = "crate::lotus_json")]
100 pub max_fee: TokenAmount,
101}
102
103impl Default for FeeConfig {
104 fn default() -> Self {
105 Self {
107 max_fee: TokenAmount::from_atto(70_000_000_000_000_000u64), }
109 }
110}
111
112#[derive(Serialize, Deserialize, PartialEq, Default, Debug, Clone)]
113#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
114#[serde(default)]
115pub struct Config {
116 pub chain: NetworkChain,
117 pub client: Client,
118 pub parity_db: crate::db::parity_db_config::ParityDbConfig,
119 pub network: Libp2pConfig,
120 pub sync: SyncConfig,
121 pub daemon: DaemonConfig,
122 pub events: EventsConfig,
123 pub fevm: FevmConfig,
124 pub fee: FeeConfig,
125 pub chain_indexer: ChainIndexerConfig,
126}
127
128impl Config {
129 pub fn db_config(&self) -> &DbConfig {
130 &self.parity_db
131 }
132
133 pub fn chain(&self) -> &NetworkChain {
134 &self.chain
135 }
136}
137
138#[cfg(test)]
139mod test {
140 use quickcheck_macros::quickcheck;
141
142 use super::*;
143
144 #[quickcheck]
145 fn test_config_all_params_under_section(config: Config) {
146 let serialized_config =
147 toml::to_string(&config).expect("could not serialize the configuration");
148 assert_eq!(
149 serialized_config
150 .trim_start()
151 .chars()
152 .next()
153 .expect("configuration empty"),
154 '['
155 )
156 }
157}