kaspa_consensus_core/config/
mod.rs1pub mod bps;
2pub mod constants;
3pub mod genesis;
4pub mod params;
5
6use kaspa_utils::networking::{ContextualNetAddress, NetAddress};
7
8#[cfg(feature = "devnet-prealloc")]
9use crate::utxo::utxo_collection::UtxoCollection;
10#[cfg(feature = "devnet-prealloc")]
11use std::sync::Arc;
12
13use std::ops::Deref;
14
15use {
16 constants::perf::{PerfParams, PERF_PARAMS},
17 params::Params,
18};
19
20#[derive(Clone, Debug)]
24pub struct Config {
25 pub params: Params,
27 pub perf: PerfParams,
29
30 pub process_genesis: bool,
34
35 pub is_archival: bool,
37
38 pub enable_sanity_checks: bool,
40
41 pub utxoindex: bool,
44
45 pub unsafe_rpc: bool,
47
48 pub enable_unsynced_mining: bool,
51
52 pub enable_mainnet_mining: bool,
54
55 pub user_agent_comments: Vec<String>,
56
57 pub p2p_listen_address: ContextualNetAddress,
59
60 pub externalip: Option<NetAddress>,
61
62 pub block_template_cache_lifetime: Option<u64>,
63
64 #[cfg(feature = "devnet-prealloc")]
65 pub initial_utxo_set: Arc<UtxoCollection>,
66
67 pub disable_upnp: bool,
68
69 pub ram_scale: f64,
71}
72
73impl Config {
74 pub fn new(params: Params) -> Self {
75 Self::with_perf(params, PERF_PARAMS)
76 }
77
78 pub fn with_perf(params: Params, perf: PerfParams) -> Self {
79 Self {
80 params,
81 perf,
82 process_genesis: true,
83 is_archival: false,
84 enable_sanity_checks: false,
85 utxoindex: false,
86 unsafe_rpc: false,
87 enable_unsynced_mining: false,
88 enable_mainnet_mining: false,
89 user_agent_comments: Default::default(),
90 externalip: None,
91 p2p_listen_address: ContextualNetAddress::unspecified(),
92 block_template_cache_lifetime: None,
93
94 #[cfg(feature = "devnet-prealloc")]
95 initial_utxo_set: Default::default(),
96 disable_upnp: false,
97 ram_scale: 1.0,
98 }
99 }
100
101 pub fn to_builder(&self) -> ConfigBuilder {
102 ConfigBuilder { config: self.clone() }
103 }
104}
105
106impl AsRef<Params> for Config {
107 fn as_ref(&self) -> &Params {
108 &self.params
109 }
110}
111
112impl Deref for Config {
113 type Target = Params;
114
115 fn deref(&self) -> &Self::Target {
116 &self.params
117 }
118}
119
120pub struct ConfigBuilder {
121 config: Config,
122}
123
124impl ConfigBuilder {
125 pub fn new(params: Params) -> Self {
126 Self { config: Config::new(params) }
127 }
128
129 pub fn set_perf_params(mut self, perf: PerfParams) -> Self {
130 self.config.perf = perf;
131 self
132 }
133
134 pub fn adjust_perf_params_to_consensus_params(mut self) -> Self {
135 self.config.perf.adjust_to_consensus_params(&self.config.params);
136 self
137 }
138
139 pub fn edit_consensus_params<F>(mut self, edit_func: F) -> Self
140 where
141 F: Fn(&mut Params),
142 {
143 edit_func(&mut self.config.params);
144 self
145 }
146
147 pub fn apply_args<F>(mut self, edit_func: F) -> Self
148 where
149 F: Fn(&mut Config),
150 {
151 edit_func(&mut self.config);
152 self
153 }
154
155 pub fn skip_proof_of_work(mut self) -> Self {
156 self.config.params.skip_proof_of_work = true;
157 self
158 }
159
160 pub fn set_archival(mut self) -> Self {
161 self.config.is_archival = true;
162 self
163 }
164
165 pub fn enable_sanity_checks(mut self) -> Self {
166 self.config.enable_sanity_checks = true;
167 self
168 }
169
170 pub fn skip_adding_genesis(mut self) -> Self {
171 self.config.process_genesis = false;
172 self
173 }
174
175 pub fn build(self) -> Config {
176 self.config
177 }
178}