massa_protocol_exports/
settings.rs

1// Copyright (c) 2022 MASSA LABS <info@massa.net>
2
3use std::{
4    collections::HashMap,
5    net::{IpAddr, SocketAddr},
6    path::PathBuf,
7};
8
9use massa_models::version::Version;
10use massa_time::MassaTime;
11use peernet::transports::TransportType;
12use serde::Deserialize;
13
14#[derive(Debug, Deserialize, Clone, Copy)]
15pub struct PeerCategoryInfo {
16    pub allow_local_peers: bool,
17    pub target_out_connections: usize,
18    pub max_in_connections: usize,
19    pub max_in_connections_per_ip: usize,
20}
21
22/// Dynamic protocol configuration mix in static settings and constants configurations.
23#[derive(Debug, Deserialize, Clone)]
24pub struct ProtocolConfig {
25    /// self keypair
26    pub keypair_file: PathBuf,
27    /// listeners from where we can receive messages
28    pub listeners: HashMap<SocketAddr, TransportType>,
29    /// initial peers path
30    pub initial_peers: PathBuf,
31    /// after `ask_block_timeout` milliseconds we try to ask a block to another node
32    pub ask_block_timeout: MassaTime,
33    /// Max known blocks we keep during their propagation
34    pub max_blocks_kept_for_propagation: usize,
35    /// Time during which a block is expected to propagate
36    pub max_block_propagation_time: MassaTime,
37    /// Block propagation tick interval, useful for propagating blocks quickly to newly connected peers.
38    pub block_propagation_tick: MassaTime,
39    /// max known blocks of current nodes we keep in memory
40    pub max_known_blocks_size: usize,
41    /// max known blocks of foreign nodes we keep in memory (by node)
42    pub max_node_known_blocks_size: usize,
43    /// max wanted blocks per node kept in memory
44    pub max_node_wanted_blocks_size: usize,
45    /// max known operations current node kept in memory
46    pub max_known_ops_size: usize,
47    /// max known operations of foreign nodes we keep in memory (by node)
48    pub max_node_known_ops_size: usize,
49    /// max known endorsements by our node that we kept in memory
50    pub max_known_endorsements_size: usize,
51    /// max known endorsements of foreign nodes we keep in memory (by node)
52    pub max_node_known_endorsements_size: usize,
53    /// we ask for the same block `max_simultaneous_ask_blocks_per_node` times at the same time
54    pub max_simultaneous_ask_blocks_per_node: usize,
55    /// Max wait time for sending a Network or Node event.
56    pub max_send_wait: MassaTime,
57    /// Maximum number of batches in the memory buffer.
58    /// Dismiss the new batches if overflow
59    pub operation_batch_buffer_capacity: usize,
60    /// Maximum number of operations in the announcement buffer.
61    /// Immediately announce if overflow.
62    pub operation_announcement_buffer_capacity: usize,
63    /// Start processing batches in the buffer each `operation_batch_proc_period` in millisecond
64    pub operation_batch_proc_period: MassaTime,
65    /// Maximum number of asked operations in the memory buffer.
66    pub asked_operations_buffer_capacity: usize,
67    /// Interval at which operations are announced in batches.
68    pub operation_announcement_interval: MassaTime,
69    /// Maximum time we keep an operation in the storage
70    pub max_operation_storage_time: MassaTime,
71    /// Maximum of operations sent in one message.
72    pub max_operations_per_message: u64,
73    /// Maximum of operations sent in one block.
74    pub max_operations_per_block: u32,
75    /// Maximum size in bytes of all serialized operations size in a block
76    pub max_serialized_operations_size_per_block: usize,
77    /// Maximum gas allowed in a block
78    pub max_block_gas: u64,
79    /// Gas used by a base operation (transaction, roll buy, roll sell)
80    pub base_operation_gas_cost: u64,
81    /// Gas cost of smart contract compilation
82    pub sp_compilation_cost: u64,
83    /// Controller channel size
84    pub controller_channel_size: usize,
85    /// Event channel size
86    pub event_channel_size: usize,
87    /// t0
88    pub t0: MassaTime,
89    /// Genesis timestamp
90    pub genesis_timestamp: MassaTime,
91    /// max number of operations kept in memory for propagation
92    pub max_ops_kept_for_propagation: usize,
93    /// max number of endorsements merged into a single propagation round
94    pub max_endorsements_per_propagation_round: usize,
95    /// max time we propagate operations
96    pub max_operations_propagation_time: MassaTime,
97    /// max time we propagate endorsements
98    pub max_endorsements_propagation_time: MassaTime,
99    /// Max message size
100    pub max_message_size: usize,
101    /// number of thread tester
102    pub thread_tester_count: u8,
103    /// Max size of the channel for command to the connectivity thread
104    pub max_size_channel_commands_connectivity: usize,
105    /// Max size of channel to send commands to retrieval thread of operations
106    pub max_size_channel_commands_retrieval_operations: usize,
107    /// Max size of channel to send commands to propagation thread of operations
108    pub max_size_channel_commands_propagation_operations: usize,
109    /// Max size of channel to send commands to retrieval thread of endorsements
110    pub max_size_channel_commands_retrieval_endorsements: usize,
111    /// Max size of channel to send commands to propagation thread of blocks
112    pub max_size_channel_commands_propagation_endorsements: usize,
113    /// Max size of channel to send commands to retrieval thread of blocks
114    pub max_size_channel_commands_retrieval_blocks: usize,
115    /// Max size of channel to send commands to propagation thread of blocks
116    pub max_size_channel_commands_propagation_blocks: usize,
117    /// Max size of channel to send commands to thread of peers
118    pub max_size_channel_commands_peers: usize,
119    /// Max size of channel to send commands to the peer testers
120    pub max_size_channel_commands_peer_testers: usize,
121    /// Max size of channel that transfer message from network to operation handler
122    pub max_size_channel_network_to_operation_handler: usize,
123    /// Max size of channel that transfer message from network to block handler
124    pub max_size_channel_network_to_block_handler: usize,
125    /// Max size of channel that transfer message from network to endorsement handler
126    pub max_size_channel_network_to_endorsement_handler: usize,
127    /// Max size of channel that transfer message from network to peer handler
128    pub max_size_channel_network_to_peer_handler: usize,
129    /// endorsements per block
130    pub endorsement_count: u32,
131    /// running threads count
132    pub thread_count: u8,
133    /// Maximum size of a smart contract bytecode in an `ExecuteSC` operation
134    pub max_bytecode_size: u64,
135    /// Maximum size of a function name
136    pub max_size_function_name: u16,
137    /// Maximum size of a parameter of a call in ops
138    pub max_size_call_sc_parameter: u32,
139    // Maximum size of an op datastore in ops
140    pub max_op_datastore_entry_count: u64,
141    // Maximum size of a key the in op datastore in ops
142    pub max_op_datastore_key_length: u8,
143    // Maximum size of a value in the op datastore in ops
144    pub max_op_datastore_value_length: u64,
145    /// Maximum number of denunciations in a block header
146    pub max_denunciations_in_block_header: u32,
147    /// Maximum number of endorsements that can be propagated in one message
148    pub max_endorsements_per_message: u64,
149    /// Maximum number of peers per announcement
150    pub max_size_peers_announcement: u64,
151    /// Maximum number of listeners per peer
152    pub max_size_listeners_per_peer: u64,
153    /// Last start period
154    pub last_start_period: u64,
155    /// try connection timer
156    pub try_connection_timer: MassaTime,
157    /// try connection timer same peer
158    pub try_connection_timer_same_peer: MassaTime,
159    /// periodically unban every peer
160    pub unban_everyone_timer: MassaTime,
161    /// Max in connections
162    pub max_in_connections: usize,
163    /// Timeout connection
164    pub timeout_connection: MassaTime,
165    /// Timeout message
166    pub message_timeout: MassaTime,
167    /// Timeout for the tester operations
168    pub tester_timeout: MassaTime,
169    /// Number of bytes per second that can be read/write in a connection (should be a 10 multiplier)
170    pub read_write_limit_bytes_per_second: u128,
171    /// Optional routable ip
172    pub routable_ip: Option<IpAddr>,
173    /// debug prints
174    pub debug: bool,
175    /// Peers categories infos
176    pub peers_categories: HashMap<String, PeerCategoryInfo>,
177    /// Default category infos
178    pub default_category_info: PeerCategoryInfo,
179    /// Version
180    pub version: Version,
181    /// Cooldown before testing again an old peer
182    pub test_oldest_peer_cooldown: MassaTime,
183    /// Rate limit to apply on the data stream
184    pub rate_limit: u64,
185    /// Chain id
186    pub chain_id: u64,
187}
188
189impl ProtocolConfig {
190    /// Whether the node is configured to deal with peers that do not have a
191    /// globally routable address, i.e. local networks. Mirrors the
192    /// `allow_local_peers` category setting: as soon as one category accepts
193    /// local peers, non-global endpoints are kept in the peer management
194    /// pipeline and may be dialed. Per-category checks still apply when
195    /// selecting peers to connect out; `NetworkController::try_connect`
196    /// refuses non-global destinations when this returns false.
197    pub fn allow_local_peers(&self) -> bool {
198        self.default_category_info.allow_local_peers
199            || self
200                .peers_categories
201                .values()
202                .any(|category| category.allow_local_peers)
203    }
204}