massa_bootstrap/
settings.rs

1// Copyright (c) 2022 MASSA LABS <info@massa.net>
2
3use massa_models::block::BlockDeserializerArgs;
4use massa_models::node::NodeId;
5use massa_time::MassaTime;
6use serde::Deserialize;
7use std::{net::SocketAddr, path::PathBuf};
8
9use substruct::SubStruct;
10
11/// Bootstrap IP protocol version setting.
12#[derive(Debug, Deserialize, Clone, Copy)]
13pub enum IpType {
14    /// Bootstrap with both IPv4 and IPv6 protocols (default).
15    Both,
16    /// Bootstrap only with IPv4.
17    IPv4,
18    /// Bootstrap only with IPv6.
19    IPv6,
20}
21
22/// Bootstrap configuration.
23#[derive(Debug, Deserialize, Clone)]
24pub struct BootstrapConfig {
25    /// Ip address of our bootstrap nodes and their public key.
26    pub bootstrap_list: Vec<(SocketAddr, NodeId)>,
27    /// IP version filter for bootstrap list, targeting IpType::IPv4, IpType::IPv6 or IpType::Both. Defaults to IpType::Both.
28    pub bootstrap_protocol: IpType,
29    /// Path to the bootstrap whitelist file. This whitelist define IPs that can bootstrap on your node.
30    pub bootstrap_whitelist_path: PathBuf,
31    /// Path to the bootstrap blacklist file. This whitelist define IPs that will not be able to bootstrap on your node. This list is optional.
32    pub bootstrap_blacklist_path: PathBuf,
33    /// Port to listen if we choose to allow other nodes to use us as bootstrap node.
34    pub listen_addr: Option<SocketAddr>,
35    /// connection timeout
36    pub connect_timeout: MassaTime,
37    /// Time allocated to managing the bootstrapping process,
38    /// i.e. providing the ledger and consensus
39    pub bootstrap_timeout: MassaTime,
40    /// readout timeout
41    pub read_timeout: MassaTime,
42    /// write timeout
43    pub write_timeout: MassaTime,
44    /// readout error timeout
45    pub read_error_timeout: MassaTime,
46    /// write error timeout
47    pub write_error_timeout: MassaTime,
48    /// Time we wait before retrying a bootstrap
49    pub retry_delay: MassaTime,
50    /// Max ping delay.
51    pub max_ping: MassaTime,
52    /// Maximum allowed time between server and client clocks
53    pub max_clock_delta: MassaTime,
54    /// Cache duration
55    pub cache_duration: MassaTime,
56    /// Keep ledger or not if not bootstrap
57    pub keep_ledger: bool,
58    /// Max simultaneous bootstraps
59    pub max_simultaneous_bootstraps: u32,
60    /// Minimum interval between two bootstrap attempts from a given IP
61    pub per_ip_min_interval: MassaTime,
62    /// Max size of the IP list
63    pub ip_list_max_size: usize,
64    /// Read-Write limitation for a connection in bytes per seconds
65    pub rate_limit: u64,
66    /// thread count
67    pub thread_count: u8,
68    /// time between two periods in the same thread (t0)
69    pub t0: MassaTime,
70    /// timestamp of the network genesis
71    pub genesis_timestamp: MassaTime,
72    /// period per cycle
73    pub periods_per_cycle: u64,
74    /// max datastore key length
75    pub max_datastore_key_length: u8,
76    /// randomness size bytes
77    pub randomness_size_bytes: usize,
78    /// endorsement count
79    pub endorsement_count: u32,
80    /// max advertise length
81    pub max_advertise_length: u32,
82    /// max listeners per peer
83    pub max_listeners_per_peer: u32,
84    /// max bootstrap blocks length
85    pub max_bootstrap_blocks_length: u32,
86    /// max operations per block
87    pub max_operations_per_block: u32,
88    /// max bootstrap error length
89    pub max_bootstrap_error_length: u64,
90    /// max bootstrap final state new_elements
91    pub max_final_state_elements_size: u32,
92    /// max bootstrap versioning new_elements
93    pub max_versioning_elements_size: u32,
94    /// max bootstrap final state new_elements entry count
95    pub max_final_state_batch_allocation: u64,
96    /// max bootstrap versioning new_elements entry count
97    pub max_versioning_batch_allocation: u64,
98    /// max datastore entry count
99    pub max_datastore_entry_count: u64,
100    /// max datastore value length
101    pub max_datastore_value_length: u64,
102    /// max op datastore entry count
103    pub max_op_datastore_entry_count: u64,
104    /// max op datastore key length
105    pub max_op_datastore_key_length: u8,
106    /// max op datastore value length
107    pub max_op_datastore_value_length: u64,
108    /// max function name length
109    pub max_function_name_length: u16,
110    /// max parameters size
111    pub max_parameters_size: u32,
112    /// max ledger changes
113    pub max_ledger_changes_count: u64,
114    /// max slot count in state changes
115    pub max_changes_slot_count: u64,
116    /// max rolls in proof-of-stake and state changes
117    pub max_rolls_length: u64,
118    /// max production stats in proof-of-stake and state changes
119    pub max_production_stats_length: u64,
120    /// max credits in proof-of-stake and state changes
121    pub max_credits_length: u64,
122    /// max executed ops
123    pub max_executed_ops_length: u64,
124    /// max executed ops changes
125    pub max_ops_changes_length: u64,
126    /// consensus bootstrap part size
127    pub consensus_bootstrap_part_size: u64,
128    /// max number of consensus block ids when sending a bootstrap cursor from the client
129    pub max_consensus_block_ids: u64,
130    /// block count to check / process for versioning stats
131    pub mip_store_stats_block_considered: usize,
132    /// max denunciations in block header
133    pub max_denunciations_per_block_header: u32,
134    /// max executed denunciations changes
135    pub max_denunciation_changes_length: u64,
136    /// chain id
137    pub chain_id: u64,
138}
139
140/// Bootstrap server binding
141#[allow(missing_docs)]
142#[derive(Debug, Deserialize, Clone, SubStruct)]
143#[parent(type = "BootstrapConfig")]
144pub struct BootstrapSrvBindCfg {
145    pub rate_limit: u64,
146    pub thread_count: u8,
147    pub max_datastore_key_length: u8,
148    pub randomness_size_bytes: usize,
149    pub consensus_bootstrap_part_size: u64,
150    pub max_consensus_block_ids: u64,
151    pub write_error_timeout: MassaTime,
152}
153
154/// Bootstrap client config
155#[allow(missing_docs)]
156#[derive(Debug, Deserialize, Clone, SubStruct)]
157#[parent(type = "BootstrapConfig")]
158pub struct BootstrapClientConfig {
159    pub rate_limit: u64,
160    pub endorsement_count: u32,
161    pub max_listeners_per_peer: u32,
162    pub max_advertise_length: u32,
163    pub max_bootstrap_blocks_length: u32,
164    pub max_operations_per_block: u32,
165    pub thread_count: u8,
166    pub randomness_size_bytes: usize,
167    pub max_bootstrap_error_length: u64,
168    pub max_final_state_elements_size: u32,
169    pub max_versioning_elements_size: u32,
170    pub max_final_state_batch_allocation: u64,
171    pub max_versioning_batch_allocation: u64,
172    pub max_datastore_entry_count: u64,
173    pub max_datastore_key_length: u8,
174    pub max_datastore_value_length: u64,
175    pub max_ledger_changes_count: u64,
176    pub max_changes_slot_count: u64,
177    pub max_rolls_length: u64,
178    pub max_production_stats_length: u64,
179    pub max_credits_length: u64,
180    pub max_executed_ops_length: u64,
181    pub max_ops_changes_length: u64,
182    pub mip_store_stats_block_considered: usize,
183    pub max_denunciations_per_block_header: u32,
184    pub max_denunciation_changes_length: u64,
185    pub chain_id: u64,
186}
187
188/// Bootstrap Message der args
189#[allow(missing_docs)]
190#[derive(SubStruct)]
191#[parent(type = "BootstrapClientConfig")]
192pub struct BootstrapServerMessageDeserializerArgs {
193    pub thread_count: u8,
194    pub endorsement_count: u32,
195    pub max_advertise_length: u32,
196    pub max_listeners_per_peer: u32,
197    pub max_bootstrap_blocks_length: u32,
198    pub max_operations_per_block: u32,
199    pub max_final_state_elements_size: u32,
200    pub max_versioning_elements_size: u32,
201    pub max_final_state_batch_allocation: u64,
202    pub max_versioning_batch_allocation: u64,
203    pub max_ledger_changes_count: u64,
204    pub max_datastore_key_length: u8,
205    pub max_datastore_value_length: u64,
206    pub max_datastore_entry_count: u64,
207    pub max_bootstrap_error_length: u64,
208    pub max_changes_slot_count: u64,
209    pub max_rolls_length: u64,
210    pub max_production_stats_length: u64,
211    pub max_credits_length: u64,
212    pub max_executed_ops_length: u64,
213    pub max_ops_changes_length: u64,
214    pub mip_store_stats_block_considered: usize,
215    pub max_denunciations_per_block_header: u32,
216    pub max_denunciation_changes_length: u64,
217    pub chain_id: u64,
218}
219
220// TODO: add a proc macro for this case
221// Default last_start_period is None: the server streams state/versioning first with an
222// empty consensus graph and sends restart metadata once. The client caches it on the
223// binder before any part that actually contains blocks.
224impl From<&BootstrapServerMessageDeserializerArgs> for BlockDeserializerArgs {
225    fn from(value: &BootstrapServerMessageDeserializerArgs) -> Self {
226        Self {
227            thread_count: value.thread_count,
228            max_operations_per_block: value.max_operations_per_block,
229            endorsement_count: value.endorsement_count,
230            max_denunciations_per_block_header: value.max_denunciations_per_block_header,
231            last_start_period: None,
232            chain_id: value.chain_id,
233        }
234    }
235}