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 cursor_delay: MassaTime,
33    pub stats_time_window_duration: MassaTime,
34    pub max_read_only_gas: u64,
35    pub abi_gas_costs_file: PathBuf,
36    pub hd_cache_path: PathBuf,
37    pub lru_cache_size: u32,
38    pub hd_cache_size: usize,
39    pub snip_amount: usize,
40    /// slot execution outputs channel capacity
41    pub broadcast_slot_execution_output_channel_capacity: usize,
42    /// slot execution traces channel capacity
43    pub broadcast_slot_execution_traces_channel_capacity: usize,
44    pub execution_traces_limit: usize,
45    pub event_cache_path: PathBuf,
46    pub event_cache_size: usize,
47    pub event_snip_amount: usize,
48    pub max_event_per_query: usize,
49    /// wall-clock deadline for a query_state batch, in ms (`None` = no deadline)
50    #[serde(default)]
51    pub query_state_deadline_ms: Option<u64>,
52    /// slot execution info channel capacity
53    pub broadcast_slot_execution_info_channel_capacity: usize,
54}
55
56#[derive(Clone, Debug, Deserialize)]
57pub struct SelectionSettings {
58    pub initial_rolls_path: PathBuf,
59}
60
61#[derive(Clone, Debug, Deserialize)]
62pub struct LedgerSettings {
63    pub initial_ledger_path: PathBuf,
64    pub disk_ledger_path: PathBuf,
65    pub final_history_length: usize,
66    pub initial_deferred_credits_path: Option<PathBuf>,
67    pub ledger_backup_periods_interval: u64,
68    pub max_ledger_backups: u64,
69}
70
71/// Bootstrap configuration.
72#[derive(Debug, Deserialize, Clone)]
73pub struct BootstrapSettings {
74    pub bootstrap_list: Vec<(SocketAddr, NodeId)>,
75    pub bootstrap_protocol: IpType,
76    pub bootstrap_whitelist_path: PathBuf,
77    pub bootstrap_blacklist_path: PathBuf,
78    pub bind: Option<SocketAddr>,
79    pub connect_timeout: MassaTime,
80    pub read_timeout: MassaTime,
81    pub write_timeout: MassaTime,
82    pub read_error_timeout: MassaTime,
83    pub write_error_timeout: MassaTime,
84    pub retry_delay: MassaTime,
85    pub max_ping: MassaTime,
86    pub max_clock_delta: MassaTime,
87    pub cache_duration: MassaTime,
88    pub max_simultaneous_bootstraps: u32,
89    pub per_ip_min_interval: MassaTime,
90    pub ip_list_max_size: usize,
91    pub rate_limit: u64,
92    /// Allocated time with which to manage the bootstrap process
93    pub bootstrap_timeout: MassaTime,
94}
95
96/// Factory settings
97#[derive(Debug, Deserialize, Clone)]
98pub struct FactorySettings {
99    /// Initial delay
100    pub initial_delay: MassaTime,
101    /// Staking wallet file
102    pub staking_wallet_path: PathBuf,
103    /// stop the production in case we are not connected to anyone
104    pub stop_production_when_zero_connections: bool,
105    /// warn if block production is delayed by more than the given time in milliseconds
106    pub block_delay_warn_threshold: MassaTime,
107    /// timeout for optional channel calls in block production (in milliseconds)
108    pub block_opt_channel_timeout: MassaTime,
109}
110
111/// Pool configuration, read from a file configuration
112#[allow(dead_code)]
113#[derive(Debug, Deserialize, Clone)]
114pub struct PoolSettings {
115    pub max_operation_pool_size: usize,
116    pub max_operation_pool_excess_items: usize,
117    pub operation_max_future_start_delay: MassaTime,
118    pub operation_pool_refresh_interval: MassaTime,
119    pub operation_pool_swap_interval: MassaTime,
120    pub endorsement_pool_swap_interval: MassaTime,
121    pub denunciation_pool_refresh_interval: MassaTime,
122    pub denunciation_pool_swap_interval: MassaTime,
123    pub max_endorsements_pool_size_per_thread: usize,
124    pub max_item_return_count: usize,
125    /// endorsements channel capacity
126    pub endorsements_channel_capacity: usize,
127    /// operations channel capacity
128    pub operations_channel_capacity: usize,
129    /// denunciations channel capacity
130    pub denunciations_channel_capacity: usize,
131    /// broadcast endorsements channel capacity
132    pub broadcast_endorsements_channel_capacity: usize,
133    /// broadcast operations channel capacity
134    pub broadcast_operations_channel_capacity: usize,
135    /// operations minimum fees for block creator
136    pub minimal_fees: Amount,
137}
138
139/// API and server configuration, read from a file configuration.
140#[derive(Debug, Deserialize, Clone)]
141pub struct APISettings {
142    pub draw_lookahead_period_count: u64,
143    pub bind_private: SocketAddr,
144    pub bind_public: SocketAddr,
145    pub bind_api: SocketAddr,
146    pub max_arguments: u64,
147    pub openrpc_spec_path: PathBuf,
148    pub max_request_body_size: u32,
149    pub max_response_body_size: u32,
150    pub max_connections: u32,
151    pub max_subscriptions_per_connection: u32,
152    pub max_log_length: u32,
153    pub allow_hosts: Vec<String>,
154    pub batch_request_limit: u32,
155    pub ping_interval: MassaTime,
156    pub enable_http: bool,
157    pub enable_ws: bool,
158    // whether to broadcast for blocks, endorsement and operations
159    pub enable_broadcast: bool,
160    pub deferred_credits_delta: MassaTime,
161    pub max_datastore_keys_query: Option<u32>,
162    pub max_addresses_datastore_keys_query: Option<u32>,
163    pub pool_api_timeout: MassaTime,
164}
165
166#[derive(Debug, Deserialize, Clone)]
167pub struct Settings {
168    pub logging: LoggingSettings,
169    pub protocol: ProtocolSettings,
170    pub consensus: ConsensusSettings,
171    pub api: APISettings,
172    pub network: NetworkSettings,
173    pub bootstrap: BootstrapSettings,
174    pub pool: PoolSettings,
175    pub execution: ExecutionSettings,
176    pub ledger: LedgerSettings,
177    pub selector: SelectionSettings,
178    pub factory: FactorySettings,
179    pub grpc: GrpcApiSettings,
180    pub metrics: MetricsSettings,
181    pub versioning: VersioningSettings,
182    pub block_dump: BlockDumpSettings,
183    pub cli: CliSettings,
184}
185
186/// Consensus configuration
187/// Assumes `thread_count >= 1, t0_millis >= 1, t0_millis % thread_count == 0`
188#[derive(Debug, Deserialize, Clone)]
189pub struct ConsensusSettings {
190    /// Maximum number of blocks allowed in discarded blocks.
191    pub max_discarded_blocks: usize,
192    /// Maximum number of blocks allowed in `FutureIncomingBlocks`.
193    pub max_future_processing_blocks: usize,
194    /// Maximum number of blocks allowed in `DependencyWaitingBlocks`.
195    pub max_dependency_blocks: usize,
196    /// stats time span
197    pub stats_timespan: MassaTime,
198    /// force keep at least this number of final periods in RAM for each thread
199    pub force_keep_final_periods: u64,
200    /// force keep at least this number of final periods without operations in RAM for each thread
201    pub force_keep_final_periods_without_ops: u64,
202    /// old blocks are pruned every `block_db_prune_interval`
203    pub block_db_prune_interval: MassaTime,
204    /// blocks headers channel capacity
205    pub broadcast_blocks_headers_channel_capacity: usize,
206    /// blocks channel capacity
207    pub broadcast_blocks_channel_capacity: usize,
208    /// filled blocks channel capacity
209    pub broadcast_filled_blocks_channel_capacity: usize,
210}
211
212// TODO: Remove one date. Kept for retro compatibility.
213#[derive(Debug, Deserialize, Clone)]
214pub struct NetworkSettings {
215    /// Ip seen by others. If none the bind ip is used
216    pub routable_ip: Option<IpAddr>,
217}
218
219#[derive(Debug, Deserialize, Clone)]
220pub struct MetricsSettings {
221    /// enable prometheus metrics
222    pub enabled: bool,
223    /// port on which to listen for prometheus metrics
224    pub bind: SocketAddr,
225    /// interval at which to update metrics
226    pub tick_delay: MassaTime,
227}
228
229/// Protocol Configuration, read from toml user configuration file
230#[allow(dead_code)]
231#[derive(Debug, Deserialize, Clone)]
232pub struct ProtocolSettings {
233    /// after `ask_block_timeout` milliseconds we try to ask a block to another node
234    pub ask_block_timeout: MassaTime,
235    /// Max known blocks we keep during their propagation
236    pub max_blocks_kept_for_propagation: usize,
237    /// Time during which a block is expected to propagate
238    pub max_block_propagation_time: MassaTime,
239    /// Block propagation tick interval, useful for propagating blocks quickly to newly connected peers.
240    pub block_propagation_tick: MassaTime,
241    /// max known blocks our node keeps in its knowledge cache
242    pub max_known_blocks_size: usize,
243    /// max cache size for which blocks a foreign node knows about
244    pub max_node_known_blocks_size: usize,
245    /// max wanted blocks per node kept in memory
246    pub max_node_wanted_blocks_size: usize,
247    /// max known operations current node kept in memory
248    pub max_known_ops_size: usize,
249    /// size of the buffer of asked operations
250    pub asked_operations_buffer_capacity: usize,
251    /// max known operations of foreign nodes we keep in memory (by node)
252    pub max_node_known_ops_size: usize,
253    /// max known endorsements by our node that we kept in memory
254    pub max_known_endorsements_size: usize,
255    /// max known endorsements of foreign nodes we keep in memory (by node)
256    pub max_node_known_endorsements_size: usize,
257    /// we ask for the same block `max_simultaneous_ask_blocks_per_node` times at the same time
258    pub max_simultaneous_ask_blocks_per_node: usize,
259    /// Max wait time for sending a Network or Node event.
260    pub max_send_wait: MassaTime,
261    /// Maximum number of batches in the memory buffer.
262    /// Dismiss the new batches if overflow
263    pub operation_batch_buffer_capacity: usize,
264    /// Maximum number of operations in the announcement buffer.
265    /// Immediately announce if overflow.
266    pub operation_announcement_buffer_capacity: usize,
267    /// Start processing batches in the buffer each `operation_batch_proc_period` in millisecond
268    pub operation_batch_proc_period: MassaTime,
269    /// Interval at which operations are announced in batches.
270    pub operation_announcement_interval: MassaTime,
271    /// Maximum of operations sent in one message.
272    pub max_operations_per_message: u64,
273    /// MAx number of operations kept for propagation
274    pub max_ops_kept_for_propagation: usize,
275    /// Max number of endorsements merged into a single propagation round
276    pub max_endorsements_per_propagation_round: usize,
277    /// Time threshold after which operation are not propagated
278    pub max_operations_propagation_time: MassaTime,
279    /// Time threshold after which operation are not propagated
280    pub max_endorsements_propagation_time: MassaTime,
281    /// Path for initial peers
282    pub initial_peers_file: PathBuf,
283    /// Keypair
284    pub keypair_file: PathBuf,
285    /// Ip we are bind to listen to
286    pub bind: SocketAddr,
287    /// Ip seen by others. If none the bind ip is used
288    pub routable_ip: Option<IpAddr>,
289    /// Time threshold to have a connection to a node
290    pub connect_timeout: MassaTime,
291    /// Number of tester threads
292    pub thread_tester_count: u8,
293    /// Number of bytes we can read/write by seconds in a connection (must be a 10 multiple)
294    pub read_write_limit_bytes_per_second: u64,
295    /// try connection timer
296    pub try_connection_timer: MassaTime,
297    /// try connection timer for the same peer
298    pub try_connection_timer_same_peer: MassaTime,
299    /// periodically unban every peer
300    pub unban_everyone_timer: MassaTime,
301    /// Timeout connection
302    pub timeout_connection: MassaTime,
303    /// Message timeout
304    pub message_timeout: MassaTime,
305    /// Timeout for the tester operations
306    pub tester_timeout: MassaTime,
307    /// Nb in connections
308    pub max_in_connections: usize,
309    /// Peers limits per category
310    pub peers_categories: HashMap<String, PeerCategoryInfo>,
311    /// Limits for default category
312    pub default_category_info: PeerCategoryInfo,
313    /// Cooldown before testing again an old peer
314    pub test_oldest_peer_cooldown: MassaTime,
315    /// Rate limitation to apply to the data stream (per second)
316    pub rate_limit: u64,
317}
318
319/// gRPC settings
320/// the gRPC settings
321#[derive(Debug, Deserialize, Clone)]
322pub struct GrpcSettings {
323    /// whether to enable gRPC
324    pub enabled: bool,
325    /// whether to accept HTTP/1.1 requests
326    pub accept_http1: bool,
327    /// whether to enable CORS. Works only if `accept_http1` is true
328    pub enable_cors: bool,
329    /// whether to enable gRPC health service
330    pub enable_health: bool,
331    /// whether to enable gRPC reflection
332    pub enable_reflection: bool,
333    /// whether to enable TLS
334    pub enable_tls: bool,
335    /// whether to enable mTLS (requires `enable_tls` to be true)
336    pub enable_mtls: bool,
337    /// whether to generate a self-signed certificate if none is provided
338    pub generate_self_signed_certificates: bool,
339    /// 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.
340    pub subject_alt_names: Vec<String>,
341    /// bind for the Massa gRPC API
342    pub bind: SocketAddr,
343    /// which compression encodings does the server accept for requests
344    pub accept_compressed: Option<String>,
345    /// which compression encodings might the server use for responses
346    pub send_compressed: Option<String>,
347    /// limits the maximum size of a decoded message. Defaults to 4MB
348    pub max_decoding_message_size: usize,
349    /// limits the maximum size of an encoded message. Defaults to 4MB
350    pub max_encoding_message_size: usize,
351    /// limits the maximum size of streaming channel
352    pub max_channel_size: usize,
353    /// set the concurrency limit applied to on requests inbound per connection. Defaults to 32
354    pub concurrency_limit_per_connection: usize,
355    /// set a timeout on for all request handlers
356    pub timeout: MassaTime,
357    /// sets the SETTINGS_INITIAL_WINDOW_SIZE spec option for HTTP2 stream-level flow control. Default is 65,535
358    pub initial_stream_window_size: Option<u32>,
359    /// sets the max connection-level flow control for HTTP2. Default is 65,535
360    pub initial_connection_window_size: Option<u32>,
361    /// sets the SETTINGS_MAX_CONCURRENT_STREAMS spec option for HTTP2 connections. Default is no limit (`None`)
362    pub max_concurrent_streams: Option<u32>,
363    /// max number of arguments per gRPC request
364    pub max_arguments: u64,
365    /// set whether TCP keepalive messages are enabled on accepted connections
366    pub tcp_keepalive: Option<MassaTime>,
367    /// set the value of `TCP_NODELAY` option for accepted connections. Enabled by default
368    pub tcp_nodelay: bool,
369    /// set whether HTTP2 Ping frames are enabled on accepted connections. Default is no HTTP2 keepalive (`None`)
370    pub http2_keepalive_interval: Option<MassaTime>,
371    /// sets a timeout for receiving an acknowledgement of the keepalive ping. Default is 20 seconds
372    pub http2_keepalive_timeout: Option<MassaTime>,
373    /// sets whether to use an adaptive flow control. Defaults to false
374    pub http2_adaptive_window: Option<bool>,
375    /// 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
376    pub max_frame_size: Option<u32>,
377    /// when looking for next draw we want to look at max `draw_lookahead_period_count`
378    pub draw_lookahead_period_count: u64,
379    /// max number of block ids that can be included in a single request
380    pub max_block_ids_per_request: u32,
381    /// max number of addresses that can be included in a single request
382    pub max_addresses_per_request: u32,
383    /// max number of slot ranges that can be included in a single request
384    pub max_slot_ranges_per_request: u32,
385    /// max number of endorsement ids that can be included in a single request
386    pub max_endorsement_ids_per_request: u32,
387    /// max number of operation ids that can be included in a single request
388    pub max_operation_ids_per_request: u32,
389    /// max op datastore entries per request
390    pub max_datastore_entries_per_request: u64,
391    /// max number of filters that can be included in a single request
392    pub max_filters_per_request: u32,
393    /// max number of query items that can be included in a single request
394    pub max_query_items_per_request: u32,
395    /// certificate authority root path
396    pub certificate_authority_root_path: PathBuf,
397    /// server certificate path
398    pub server_certificate_path: PathBuf,
399    /// server private key path
400    pub server_private_key_path: PathBuf,
401    /// client certificate authority root path
402    pub client_certificate_authority_root_path: PathBuf,
403    /// client certificate path
404    pub client_certificate_path: PathBuf,
405    /// client private key path
406    pub client_private_key_path: PathBuf,
407    /// Max keys returned by a datastore key query
408    pub max_datastore_keys_query: Option<u32>,
409    /// interval for check the connection stream
410    pub unidirectional_stream_interval_check: u64,
411}
412
413/// gRPC API settings.
414#[derive(Debug, Deserialize, Clone)]
415pub struct GrpcApiSettings {
416    /// Public server gRPC configuration.
417    pub public: GrpcSettings,
418    /// Private server gRPC configuration.
419    pub private: GrpcSettings,
420}
421
422#[derive(Debug, Deserialize, Clone)]
423pub struct VersioningSettings {
424    // Warn user to update its node if we reach this percentage for announced network versions
425    pub(crate) mip_stats_warn_announced_version: u32,
426}
427
428#[derive(Debug, Deserialize, Clone)]
429pub struct BlockDumpSettings {
430    /// Where to dump blocks
431    pub(crate) block_dump_folder_path: PathBuf,
432    #[cfg(feature = "dump-block")]
433    /// Number of blocks to keep
434    pub(crate) max_blocks: u64,
435}
436
437#[cfg(test)]
438#[test]
439fn test_load_node_config() {
440    let _ = *SETTINGS;
441}