massa_node/
settings.rs

1// Copyright (c) 2022 MASSA LABS <info@massa.net>
2
3//! Build here the default node settings from the configuration file toml
4use 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    /// slot execution outputs channel capacity
42    pub broadcast_slot_execution_output_channel_capacity: usize,
43    /// slot execution traces channel capacity
44    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    /// wall-clock deadline for a query_state batch, in ms (`None` = no deadline)
52    #[serde(default)]
53    pub query_state_deadline_ms: Option<u64>,
54    /// slot execution info channel capacity
55    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/// Bootstrap configuration.
74#[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    /// Allocated time with which to manage the bootstrap process
95    pub bootstrap_timeout: MassaTime,
96}
97
98/// Factory settings
99#[derive(Debug, Deserialize, Clone)]
100pub struct FactorySettings {
101    /// Initial delay
102    pub initial_delay: MassaTime,
103    /// Staking wallet file
104    pub staking_wallet_path: PathBuf,
105    /// stop the production in case we are not connected to anyone
106    pub stop_production_when_zero_connections: bool,
107    /// warn if block production is delayed by more than the given time in milliseconds
108    pub block_delay_warn_threshold: MassaTime,
109    /// timeout for optional channel calls in block production (in milliseconds)
110    pub block_opt_channel_timeout: MassaTime,
111}
112
113/// Pool configuration, read from a file configuration
114#[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    /// endorsements channel capacity
128    pub endorsements_channel_capacity: usize,
129    /// operations channel capacity
130    pub operations_channel_capacity: usize,
131    /// denunciations channel capacity
132    pub denunciations_channel_capacity: usize,
133    /// broadcast endorsements channel capacity
134    pub broadcast_endorsements_channel_capacity: usize,
135    /// broadcast operations channel capacity
136    pub broadcast_operations_channel_capacity: usize,
137    /// operations minimum fees for block creator
138    pub minimal_fees: Amount,
139}
140
141/// API and server configuration, read from a file configuration.
142#[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    // whether to broadcast for blocks, endorsement and operations
161    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/// Consensus configuration
189/// Assumes `thread_count >= 1, t0_millis >= 1, t0_millis % thread_count == 0`
190#[derive(Debug, Deserialize, Clone)]
191pub struct ConsensusSettings {
192    /// Maximum number of blocks allowed in discarded blocks.
193    pub max_discarded_blocks: usize,
194    /// Maximum number of blocks allowed in `FutureIncomingBlocks`.
195    pub max_future_processing_blocks: usize,
196    /// Maximum number of blocks allowed in `DependencyWaitingBlocks`.
197    pub max_dependency_blocks: usize,
198    /// stats time span
199    pub stats_timespan: MassaTime,
200    /// force keep at least this number of final periods in RAM for each thread
201    pub force_keep_final_periods: u64,
202    /// force keep at least this number of final periods without operations in RAM for each thread
203    pub force_keep_final_periods_without_ops: u64,
204    /// old blocks are pruned every `block_db_prune_interval`
205    pub block_db_prune_interval: MassaTime,
206    /// blocks headers channel capacity
207    pub broadcast_blocks_headers_channel_capacity: usize,
208    /// blocks channel capacity
209    pub broadcast_blocks_channel_capacity: usize,
210    /// filled blocks channel capacity
211    pub broadcast_filled_blocks_channel_capacity: usize,
212}
213
214// TODO: Remove one date. Kept for retro compatibility.
215#[derive(Debug, Deserialize, Clone)]
216pub struct NetworkSettings {
217    /// Ip seen by others. If none the bind ip is used
218    pub routable_ip: Option<IpAddr>,
219}
220
221#[derive(Debug, Deserialize, Clone)]
222pub struct MetricsSettings {
223    /// enable prometheus metrics
224    pub enabled: bool,
225    /// port on which to listen for prometheus metrics
226    pub bind: SocketAddr,
227    /// interval at which to update metrics
228    pub tick_delay: MassaTime,
229}
230
231/// Protocol Configuration, read from toml user configuration file
232#[allow(dead_code)]
233#[derive(Debug, Deserialize, Clone)]
234pub struct ProtocolSettings {
235    /// after `ask_block_timeout` milliseconds we try to ask a block to another node
236    pub ask_block_timeout: MassaTime,
237    /// Max known blocks we keep during their propagation
238    pub max_blocks_kept_for_propagation: usize,
239    /// Time during which a block is expected to propagate
240    pub max_block_propagation_time: MassaTime,
241    /// Block propagation tick interval, useful for propagating blocks quickly to newly connected peers.
242    pub block_propagation_tick: MassaTime,
243    /// max known blocks our node keeps in its knowledge cache
244    pub max_known_blocks_size: usize,
245    /// max cache size for which blocks a foreign node knows about
246    pub max_node_known_blocks_size: usize,
247    /// max wanted blocks per node kept in memory
248    pub max_node_wanted_blocks_size: usize,
249    /// max known operations current node kept in memory
250    pub max_known_ops_size: usize,
251    /// size of the buffer of asked operations
252    pub asked_operations_buffer_capacity: usize,
253    /// max known operations of foreign nodes we keep in memory (by node)
254    pub max_node_known_ops_size: usize,
255    /// max known endorsements by our node that we kept in memory
256    pub max_known_endorsements_size: usize,
257    /// max known endorsements of foreign nodes we keep in memory (by node)
258    pub max_node_known_endorsements_size: usize,
259    /// we ask for the same block `max_simultaneous_ask_blocks_per_node` times at the same time
260    pub max_simultaneous_ask_blocks_per_node: usize,
261    /// Max wait time for sending a Network or Node event.
262    pub max_send_wait: MassaTime,
263    /// Maximum number of batches in the memory buffer.
264    /// Dismiss the new batches if overflow
265    pub operation_batch_buffer_capacity: usize,
266    /// Maximum number of operations in the announcement buffer.
267    /// Immediately announce if overflow.
268    pub operation_announcement_buffer_capacity: usize,
269    /// Start processing batches in the buffer each `operation_batch_proc_period` in millisecond
270    pub operation_batch_proc_period: MassaTime,
271    /// Interval at which operations are announced in batches.
272    pub operation_announcement_interval: MassaTime,
273    /// Maximum of operations sent in one message.
274    pub max_operations_per_message: u64,
275    /// MAx number of operations kept for propagation
276    pub max_ops_kept_for_propagation: usize,
277    /// Max number of endorsements merged into a single propagation round
278    pub max_endorsements_per_propagation_round: usize,
279    /// Time threshold after which operation are not propagated
280    pub max_operations_propagation_time: MassaTime,
281    /// Time threshold after which operation are not propagated
282    pub max_endorsements_propagation_time: MassaTime,
283    /// Path for initial peers
284    pub initial_peers_file: PathBuf,
285    /// Keypair
286    pub keypair_file: PathBuf,
287    /// Ip we are bind to listen to
288    pub bind: SocketAddr,
289    /// Ip seen by others. If none the bind ip is used
290    pub routable_ip: Option<IpAddr>,
291    /// Time threshold to have a connection to a node
292    pub connect_timeout: MassaTime,
293    /// Number of tester threads
294    pub thread_tester_count: u8,
295    /// Number of bytes we can read/write by seconds in a connection (must be a 10 multiple)
296    pub read_write_limit_bytes_per_second: u64,
297    /// try connection timer
298    pub try_connection_timer: MassaTime,
299    /// try connection timer for the same peer
300    pub try_connection_timer_same_peer: MassaTime,
301    /// periodically unban every peer
302    pub unban_everyone_timer: MassaTime,
303    /// Timeout connection
304    pub timeout_connection: MassaTime,
305    /// Message timeout
306    pub message_timeout: MassaTime,
307    /// Timeout for the tester operations
308    pub tester_timeout: MassaTime,
309    /// Nb in connections
310    pub max_in_connections: usize,
311    /// Peers limits per category
312    pub peers_categories: HashMap<String, PeerCategoryInfo>,
313    /// Limits for default category
314    pub default_category_info: PeerCategoryInfo,
315    /// Cooldown before testing again an old peer
316    pub test_oldest_peer_cooldown: MassaTime,
317    /// Rate limitation to apply to the data stream (per second)
318    pub rate_limit: u64,
319}
320
321/// gRPC settings
322/// the gRPC settings
323#[derive(Debug, Deserialize, Clone)]
324pub struct GrpcSettings {
325    /// whether to enable gRPC
326    pub enabled: bool,
327    /// whether to accept HTTP/1.1 requests
328    pub accept_http1: bool,
329    /// whether to enable CORS. Works only if `accept_http1` is true
330    pub enable_cors: bool,
331    /// whether to enable gRPC health service
332    pub enable_health: bool,
333    /// whether to enable gRPC reflection
334    pub enable_reflection: bool,
335    /// whether to enable TLS
336    pub enable_tls: bool,
337    /// whether to enable mTLS (requires `enable_tls` to be true)
338    pub enable_mtls: bool,
339    /// whether to generate a self-signed certificate if none is provided
340    pub generate_self_signed_certificates: bool,
341    /// Subject Alternative Names is an extension in X.509 certificates that allows a certificate to specify additional subject identifiers. It is used to support alternative names for a subject, other than its primary Common Name (CN), which is typically used to represent the primary domain name.
342    pub subject_alt_names: Vec<String>,
343    /// bind for the Massa gRPC API
344    pub bind: SocketAddr,
345    /// which compression encodings does the server accept for requests
346    pub accept_compressed: Option<String>,
347    /// which compression encodings might the server use for responses
348    pub send_compressed: Option<String>,
349    /// limits the maximum size of a decoded message. Defaults to 4MB
350    pub max_decoding_message_size: usize,
351    /// limits the maximum size of an encoded message. Defaults to 4MB
352    pub max_encoding_message_size: usize,
353    /// limits the maximum size of streaming channel
354    pub max_channel_size: usize,
355    /// set the concurrency limit applied to on requests inbound per connection. Defaults to 32
356    pub concurrency_limit_per_connection: usize,
357    /// set a timeout on for all request handlers
358    pub timeout: MassaTime,
359    /// sets the SETTINGS_INITIAL_WINDOW_SIZE spec option for HTTP2 stream-level flow control. Default is 65,535
360    pub initial_stream_window_size: Option<u32>,
361    /// sets the max connection-level flow control for HTTP2. Default is 65,535
362    pub initial_connection_window_size: Option<u32>,
363    /// sets the SETTINGS_MAX_CONCURRENT_STREAMS spec option for HTTP2 connections. Default is no limit (`None`)
364    pub max_concurrent_streams: Option<u32>,
365    /// max number of arguments per gRPC request
366    pub max_arguments: u64,
367    /// set whether TCP keepalive messages are enabled on accepted connections
368    pub tcp_keepalive: Option<MassaTime>,
369    /// set the value of `TCP_NODELAY` option for accepted connections. Enabled by default
370    pub tcp_nodelay: bool,
371    /// set whether HTTP2 Ping frames are enabled on accepted connections. Default is no HTTP2 keepalive (`None`)
372    pub http2_keepalive_interval: Option<MassaTime>,
373    /// sets a timeout for receiving an acknowledgement of the keepalive ping. Default is 20 seconds
374    pub http2_keepalive_timeout: Option<MassaTime>,
375    /// sets whether to use an adaptive flow control. Defaults to false
376    pub http2_adaptive_window: Option<bool>,
377    /// sets the maximum frame size to use for HTTP2(must be within 16,384 and 16,777,215). If not set, will default from underlying transport
378    pub max_frame_size: Option<u32>,
379    /// when looking for next draw we want to look at max `draw_lookahead_period_count`
380    pub draw_lookahead_period_count: u64,
381    /// max number of block ids that can be included in a single request
382    pub max_block_ids_per_request: u32,
383    /// max number of addresses that can be included in a single request
384    pub max_addresses_per_request: u32,
385    /// max number of slot ranges that can be included in a single request
386    pub max_slot_ranges_per_request: u32,
387    /// max number of endorsement ids that can be included in a single request
388    pub max_endorsement_ids_per_request: u32,
389    /// max number of operation ids that can be included in a single request
390    pub max_operation_ids_per_request: u32,
391    /// max op datastore entries per request
392    pub max_datastore_entries_per_request: u64,
393    /// max number of filters that can be included in a single request
394    pub max_filters_per_request: u32,
395    /// max number of query items that can be included in a single request
396    pub max_query_items_per_request: u32,
397    /// certificate authority root path
398    pub certificate_authority_root_path: PathBuf,
399    /// server certificate path
400    pub server_certificate_path: PathBuf,
401    /// server private key path
402    pub server_private_key_path: PathBuf,
403    /// client certificate authority root path
404    pub client_certificate_authority_root_path: PathBuf,
405    /// client certificate path
406    pub client_certificate_path: PathBuf,
407    /// client private key path
408    pub client_private_key_path: PathBuf,
409    /// Max keys returned by a datastore key query
410    pub max_datastore_keys_query: Option<u32>,
411    /// interval for check the connection stream
412    pub unidirectional_stream_interval_check: u64,
413}
414
415/// gRPC API settings.
416#[derive(Debug, Deserialize, Clone)]
417pub struct GrpcApiSettings {
418    /// Public server gRPC configuration.
419    pub public: GrpcSettings,
420    /// Private server gRPC configuration.
421    pub private: GrpcSettings,
422}
423
424#[derive(Debug, Deserialize, Clone)]
425pub struct VersioningSettings {
426    // Warn user to update its node if we reach this percentage for announced network versions
427    pub(crate) mip_stats_warn_announced_version: u32,
428}
429
430#[derive(Debug, Deserialize, Clone)]
431pub struct BlockDumpSettings {
432    /// Where to dump blocks
433    pub(crate) block_dump_folder_path: PathBuf,
434    #[cfg(feature = "dump-block")]
435    /// Number of blocks to keep
436    pub(crate) max_blocks: u64,
437}
438
439#[cfg(test)]
440#[test]
441fn test_load_node_config() {
442    let _ = *SETTINGS;
443}