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))]
46#[serde(default)]
47pub struct EventsConfig {
48 #[cfg_attr(test, arbitrary(gen(|g| u32::arbitrary(g) as _)))]
61 pub max_filter_results: usize,
62 pub max_filter_height_range: ChainEpoch,
64 pub filter_ttl_secs: u64,
67}
68
69impl Default for EventsConfig {
70 fn default() -> Self {
71 Self {
72 max_filter_results: 10000,
73 max_filter_height_range: 2880,
74 filter_ttl_secs: 3600,
75 }
76 }
77}
78
79#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
81#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
82pub struct FevmConfig {
83 #[cfg_attr(test, arbitrary(gen(|g| u32::arbitrary(g) as _)))]
84 pub eth_trace_filter_max_results: usize,
85}
86
87impl Default for FevmConfig {
88 fn default() -> Self {
89 Self {
90 eth_trace_filter_max_results: 500,
91 }
92 }
93}
94
95#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
96#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
97pub struct ChainIndexerConfig {
98 pub enable_indexer: bool,
100 pub gc_retention_epochs: Option<u32>,
102}
103
104impl Default for ChainIndexerConfig {
105 fn default() -> Self {
106 Self {
107 enable_indexer: is_env_set_and_truthy(FOREST_CHAIN_INDEXER_ENABLED).unwrap_or(true),
108 gc_retention_epochs: None,
109 }
110 }
111}
112
113#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone)]
114#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
115pub struct FeeConfig {
116 #[serde(with = "crate::lotus_json")]
118 pub max_fee: TokenAmount,
119}
120
121impl Default for FeeConfig {
122 fn default() -> Self {
123 Self {
125 max_fee: TokenAmount::from_atto(70_000_000_000_000_000u64), }
127 }
128}
129
130#[derive(Serialize, Deserialize, PartialEq, Default, Debug, Clone)]
131#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
132#[serde(default)]
133pub struct Config {
134 pub chain: NetworkChain,
135 pub client: Client,
136 pub parity_db: crate::db::parity_db_config::ParityDbConfig,
137 pub network: Libp2pConfig,
138 pub sync: SyncConfig,
139 pub daemon: DaemonConfig,
140 pub events: EventsConfig,
141 pub fevm: FevmConfig,
142 pub fee: FeeConfig,
143 pub chain_indexer: ChainIndexerConfig,
144}
145
146impl Config {
147 pub fn db_config(&self) -> &DbConfig {
148 &self.parity_db
149 }
150
151 pub fn chain(&self) -> &NetworkChain {
152 &self.chain
153 }
154}
155
156#[cfg(test)]
157mod test {
158 use quickcheck_macros::quickcheck;
159
160 use super::*;
161
162 #[quickcheck]
163 fn test_config_all_params_under_section(config: Config) {
164 let serialized_config =
165 toml::to_string(&config).expect("could not serialize the configuration");
166 assert_eq!(
167 serialized_config
168 .trim_start()
169 .chars()
170 .next()
171 .expect("configuration empty"),
172 '['
173 )
174 }
175}