1use std::{collections::HashMap, path::PathBuf};
5
6use massa_bootstrap::IpType;
7use massa_models::{amount::Amount, config::build_massa_settings, node::NodeId};
8use massa_protocol_exports::PeerCategoryInfo;
9use massa_time::MassaTime;
10use serde::Deserialize;
11use std::net::{IpAddr, SocketAddr};
12
13lazy_static::lazy_static! {
14 pub static ref SETTINGS: Settings = build_massa_settings("massa-node", "MASSA_NODE");
15}
16
17#[derive(Debug, Deserialize, Clone)]
18pub struct LoggingSettings {
19 pub level: usize,
20}
21
22#[derive(Debug, Deserialize, Clone)]
23pub struct CliSettings {
24 pub approved_community_charter_file_path: PathBuf,
25}
26
27#[derive(Clone, Debug, Deserialize)]
28pub struct ExecutionSettings {
29 pub max_final_events: usize,
30 pub readonly_queue_length: usize,
31 pub readonly_starvation_timeout: MassaTime,
32 pub readonly_queue_timeout: MassaTime,
33 pub cursor_delay: MassaTime,
34 pub stats_time_window_duration: MassaTime,
35 pub max_read_only_gas: u64,
36 pub abi_gas_costs_file: PathBuf,
37 pub hd_cache_path: PathBuf,
38 pub lru_cache_size: u32,
39 pub hd_cache_size: usize,
40 pub snip_amount: usize,
41 pub broadcast_slot_execution_output_channel_capacity: usize,
43 pub broadcast_slot_execution_traces_channel_capacity: usize,
45 pub execution_traces_limit: usize,
46 pub event_cache_path: PathBuf,
47 pub event_cache_size: usize,
48 pub event_snip_amount: usize,
49 pub max_event_per_query: usize,
50 pub max_event_keys_scanned_per_query: u64,
51 #[serde(default)]
53 pub query_state_deadline_ms: Option<u64>,
54 pub broadcast_slot_execution_info_channel_capacity: usize,
56}
57
58#[derive(Clone, Debug, Deserialize)]
59pub struct SelectionSettings {
60 pub initial_rolls_path: PathBuf,
61}
62
63#[derive(Clone, Debug, Deserialize)]
64pub struct LedgerSettings {
65 pub initial_ledger_path: PathBuf,
66 pub disk_ledger_path: PathBuf,
67 pub final_history_length: usize,
68 pub initial_deferred_credits_path: Option<PathBuf>,
69 pub ledger_backup_periods_interval: u64,
70 pub max_ledger_backups: u64,
71}
72
73#[derive(Debug, Deserialize, Clone)]
75pub struct BootstrapSettings {
76 pub bootstrap_list: Vec<(SocketAddr, NodeId)>,
77 pub bootstrap_protocol: IpType,
78 pub bootstrap_whitelist_path: PathBuf,
79 pub bootstrap_blacklist_path: PathBuf,
80 pub bind: Option<SocketAddr>,
81 pub connect_timeout: MassaTime,
82 pub read_timeout: MassaTime,
83 pub write_timeout: MassaTime,
84 pub read_error_timeout: MassaTime,
85 pub write_error_timeout: MassaTime,
86 pub retry_delay: MassaTime,
87 pub max_ping: MassaTime,
88 pub max_clock_delta: MassaTime,
89 pub cache_duration: MassaTime,
90 pub max_simultaneous_bootstraps: u32,
91 pub per_ip_min_interval: MassaTime,
92 pub ip_list_max_size: usize,
93 pub rate_limit: u64,
94 pub bootstrap_timeout: MassaTime,
96}
97
98#[derive(Debug, Deserialize, Clone)]
100pub struct FactorySettings {
101 pub initial_delay: MassaTime,
103 pub staking_wallet_path: PathBuf,
105 pub stop_production_when_zero_connections: bool,
107 pub block_delay_warn_threshold: MassaTime,
109 pub block_opt_channel_timeout: MassaTime,
111}
112
113#[allow(dead_code)]
115#[derive(Debug, Deserialize, Clone)]
116pub struct PoolSettings {
117 pub max_operation_pool_size: usize,
118 pub max_operation_pool_excess_items: usize,
119 pub operation_max_future_start_delay: MassaTime,
120 pub operation_pool_refresh_interval: MassaTime,
121 pub operation_pool_swap_interval: MassaTime,
122 pub endorsement_pool_swap_interval: MassaTime,
123 pub denunciation_pool_refresh_interval: MassaTime,
124 pub denunciation_pool_swap_interval: MassaTime,
125 pub max_endorsements_pool_size_per_thread: usize,
126 pub max_item_return_count: usize,
127 pub endorsements_channel_capacity: usize,
129 pub operations_channel_capacity: usize,
131 pub denunciations_channel_capacity: usize,
133 pub broadcast_endorsements_channel_capacity: usize,
135 pub broadcast_operations_channel_capacity: usize,
137 pub minimal_fees: Amount,
139}
140
141#[derive(Debug, Deserialize, Clone)]
143pub struct APISettings {
144 pub draw_lookahead_period_count: u64,
145 pub bind_private: SocketAddr,
146 pub bind_public: SocketAddr,
147 pub bind_api: SocketAddr,
148 pub max_arguments: u64,
149 pub openrpc_spec_path: PathBuf,
150 pub max_request_body_size: u32,
151 pub max_response_body_size: u32,
152 pub max_connections: u32,
153 pub max_subscriptions_per_connection: u32,
154 pub max_log_length: u32,
155 pub allow_hosts: Vec<String>,
156 pub batch_request_limit: u32,
157 pub ping_interval: MassaTime,
158 pub enable_http: bool,
159 pub enable_ws: bool,
160 pub enable_broadcast: bool,
162 pub deferred_credits_delta: MassaTime,
163 pub max_datastore_keys_query: Option<u32>,
164 pub max_addresses_datastore_keys_query: Option<u32>,
165 pub pool_api_timeout: MassaTime,
166}
167
168#[derive(Debug, Deserialize, Clone)]
169pub struct Settings {
170 pub logging: LoggingSettings,
171 pub protocol: ProtocolSettings,
172 pub consensus: ConsensusSettings,
173 pub api: APISettings,
174 pub network: NetworkSettings,
175 pub bootstrap: BootstrapSettings,
176 pub pool: PoolSettings,
177 pub execution: ExecutionSettings,
178 pub ledger: LedgerSettings,
179 pub selector: SelectionSettings,
180 pub factory: FactorySettings,
181 pub grpc: GrpcApiSettings,
182 pub metrics: MetricsSettings,
183 pub versioning: VersioningSettings,
184 pub block_dump: BlockDumpSettings,
185 pub cli: CliSettings,
186}
187
188#[derive(Debug, Deserialize, Clone)]
191pub struct ConsensusSettings {
192 pub max_discarded_blocks: usize,
194 pub max_future_processing_blocks: usize,
196 pub max_dependency_blocks: usize,
198 pub stats_timespan: MassaTime,
200 pub force_keep_final_periods: u64,
202 pub force_keep_final_periods_without_ops: u64,
204 pub block_db_prune_interval: MassaTime,
206 pub broadcast_blocks_headers_channel_capacity: usize,
208 pub broadcast_blocks_channel_capacity: usize,
210 pub broadcast_filled_blocks_channel_capacity: usize,
212}
213
214#[derive(Debug, Deserialize, Clone)]
216pub struct NetworkSettings {
217 pub routable_ip: Option<IpAddr>,
219}
220
221#[derive(Debug, Deserialize, Clone)]
222pub struct MetricsSettings {
223 pub enabled: bool,
225 pub bind: SocketAddr,
227 pub tick_delay: MassaTime,
229}
230
231#[allow(dead_code)]
233#[derive(Debug, Deserialize, Clone)]
234pub struct ProtocolSettings {
235 pub ask_block_timeout: MassaTime,
237 pub max_blocks_kept_for_propagation: usize,
239 pub max_block_propagation_time: MassaTime,
241 pub block_propagation_tick: MassaTime,
243 pub max_known_blocks_size: usize,
245 pub max_node_known_blocks_size: usize,
247 pub max_node_wanted_blocks_size: usize,
249 pub max_known_ops_size: usize,
251 pub asked_operations_buffer_capacity: usize,
253 pub max_node_known_ops_size: usize,
255 pub max_known_endorsements_size: usize,
257 pub max_node_known_endorsements_size: usize,
259 pub max_simultaneous_ask_blocks_per_node: usize,
261 pub max_send_wait: MassaTime,
263 pub operation_batch_buffer_capacity: usize,
266 pub operation_announcement_buffer_capacity: usize,
269 pub operation_batch_proc_period: MassaTime,
271 pub operation_announcement_interval: MassaTime,
273 pub max_operations_per_message: u64,
275 pub max_ops_kept_for_propagation: usize,
277 pub max_endorsements_per_propagation_round: usize,
279 pub max_operations_propagation_time: MassaTime,
281 pub max_endorsements_propagation_time: MassaTime,
283 pub initial_peers_file: PathBuf,
285 pub keypair_file: PathBuf,
287 pub bind: SocketAddr,
289 pub routable_ip: Option<IpAddr>,
291 pub connect_timeout: MassaTime,
293 pub thread_tester_count: u8,
295 pub read_write_limit_bytes_per_second: u64,
297 pub try_connection_timer: MassaTime,
299 pub try_connection_timer_same_peer: MassaTime,
301 pub unban_everyone_timer: MassaTime,
303 pub timeout_connection: MassaTime,
305 pub message_timeout: MassaTime,
307 pub tester_timeout: MassaTime,
309 pub max_in_connections: usize,
311 pub peers_categories: HashMap<String, PeerCategoryInfo>,
313 pub default_category_info: PeerCategoryInfo,
315 pub test_oldest_peer_cooldown: MassaTime,
317 pub rate_limit: u64,
319}
320
321#[derive(Debug, Deserialize, Clone)]
324pub struct GrpcSettings {
325 pub enabled: bool,
327 pub accept_http1: bool,
329 pub enable_cors: bool,
331 pub enable_health: bool,
333 pub enable_reflection: bool,
335 pub enable_tls: bool,
337 pub enable_mtls: bool,
339 pub generate_self_signed_certificates: bool,
341 pub subject_alt_names: Vec<String>,
343 pub bind: SocketAddr,
345 pub accept_compressed: Option<String>,
347 pub send_compressed: Option<String>,
349 pub max_decoding_message_size: usize,
351 pub max_encoding_message_size: usize,
353 pub max_channel_size: usize,
355 pub concurrency_limit_per_connection: usize,
357 pub timeout: MassaTime,
359 pub initial_stream_window_size: Option<u32>,
361 pub initial_connection_window_size: Option<u32>,
363 pub max_concurrent_streams: Option<u32>,
365 pub max_arguments: u64,
367 pub tcp_keepalive: Option<MassaTime>,
369 pub tcp_nodelay: bool,
371 pub http2_keepalive_interval: Option<MassaTime>,
373 pub http2_keepalive_timeout: Option<MassaTime>,
375 pub http2_adaptive_window: Option<bool>,
377 pub max_frame_size: Option<u32>,
379 pub draw_lookahead_period_count: u64,
381 pub max_block_ids_per_request: u32,
383 pub max_addresses_per_request: u32,
385 pub max_slot_ranges_per_request: u32,
387 pub max_endorsement_ids_per_request: u32,
389 pub max_operation_ids_per_request: u32,
391 pub max_datastore_entries_per_request: u64,
393 pub max_filters_per_request: u32,
395 pub max_query_items_per_request: u32,
397 pub certificate_authority_root_path: PathBuf,
399 pub server_certificate_path: PathBuf,
401 pub server_private_key_path: PathBuf,
403 pub client_certificate_authority_root_path: PathBuf,
405 pub client_certificate_path: PathBuf,
407 pub client_private_key_path: PathBuf,
409 pub max_datastore_keys_query: Option<u32>,
411 pub unidirectional_stream_interval_check: u64,
413}
414
415#[derive(Debug, Deserialize, Clone)]
417pub struct GrpcApiSettings {
418 pub public: GrpcSettings,
420 pub private: GrpcSettings,
422}
423
424#[derive(Debug, Deserialize, Clone)]
425pub struct VersioningSettings {
426 pub(crate) mip_stats_warn_announced_version: u32,
428}
429
430#[derive(Debug, Deserialize, Clone)]
431pub struct BlockDumpSettings {
432 pub(crate) block_dump_folder_path: PathBuf,
434 #[cfg(feature = "dump-block")]
435 pub(crate) max_blocks: u64,
437}
438
439#[cfg(test)]
440#[test]
441fn test_load_node_config() {
442 let _ = *SETTINGS;
443}