1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// Copyright (c) 2022 MASSA LABS <info@massa.net>

use massa_models::block::BlockDeserializerArgs;
use massa_models::node::NodeId;
use massa_time::MassaTime;
use serde::Deserialize;
use std::{net::SocketAddr, path::PathBuf};

use substruct::SubStruct;

/// Bootstrap IP protocol version setting.
#[derive(Debug, Deserialize, Clone, Copy)]
pub enum IpType {
    /// Bootstrap with both IPv4 and IPv6 protocols (default).
    Both,
    /// Bootstrap only with IPv4.
    IPv4,
    /// Bootstrap only with IPv6.
    IPv6,
}

/// Bootstrap configuration.
#[derive(Debug, Deserialize, Clone)]
pub struct BootstrapConfig {
    /// Ip address of our bootstrap nodes and their public key.
    pub bootstrap_list: Vec<(SocketAddr, NodeId)>,
    /// IP version filter for bootstrap list, targeting IpType::IPv4, IpType::IPv6 or IpType::Both. Defaults to IpType::Both.
    pub bootstrap_protocol: IpType,
    /// Path to the bootstrap whitelist file. This whitelist define IPs that can bootstrap on your node.
    pub bootstrap_whitelist_path: PathBuf,
    /// Path to the bootstrap blacklist file. This whitelist define IPs that will not be able to bootstrap on your node. This list is optional.
    pub bootstrap_blacklist_path: PathBuf,
    /// Port to listen if we choose to allow other nodes to use us as bootstrap node.
    pub listen_addr: Option<SocketAddr>,
    /// connection timeout
    pub connect_timeout: MassaTime,
    /// Time allocated to managing the bootstrapping process,
    /// i.e. providing the ledger and consensus
    pub bootstrap_timeout: MassaTime,
    /// readout timeout
    pub read_timeout: MassaTime,
    /// write timeout
    pub write_timeout: MassaTime,
    /// readout error timeout
    pub read_error_timeout: MassaTime,
    /// write error timeout
    pub write_error_timeout: MassaTime,
    /// Time we wait before retrying a bootstrap
    pub retry_delay: MassaTime,
    /// Max ping delay.
    pub max_ping: MassaTime,
    /// Maximum allowed time between server and client clocks
    pub max_clock_delta: MassaTime,
    /// Cache duration
    pub cache_duration: MassaTime,
    /// Keep ledger or not if not bootstrap
    pub keep_ledger: bool,
    /// Max simultaneous bootstraps
    pub max_simultaneous_bootstraps: u32,
    /// Minimum interval between two bootstrap attempts from a given IP
    pub per_ip_min_interval: MassaTime,
    /// Max size of the IP list
    pub ip_list_max_size: usize,
    /// Read-Write limitation for a connection in bytes per seconds
    pub rate_limit: u64,
    /// thread count
    pub thread_count: u8,
    /// period per cycle
    pub periods_per_cycle: u64,
    /// max datastore key length
    pub max_datastore_key_length: u8,
    /// randomness size bytes
    pub randomness_size_bytes: usize,
    /// endorsement count
    pub endorsement_count: u32,
    /// max advertise length
    pub max_advertise_length: u32,
    /// max listeners per peer
    pub max_listeners_per_peer: u32,
    /// max bootstrap blocks length
    pub max_bootstrap_blocks_length: u32,
    /// max operations per block
    pub max_operations_per_block: u32,
    /// max bootstrap error length
    pub max_bootstrap_error_length: u64,
    /// max bootstrap final state new_elements
    pub max_final_state_elements_size: u32,
    /// max bootstrap versioning new_elements
    pub max_versioning_elements_size: u32,
    /// max datastore entry count
    pub max_datastore_entry_count: u64,
    /// max datastore value length
    pub max_datastore_value_length: u64,
    /// max op datastore entry count
    pub max_op_datastore_entry_count: u64,
    /// max op datastore key length
    pub max_op_datastore_key_length: u8,
    /// max op datastore value length
    pub max_op_datastore_value_length: u64,
    /// max function name length
    pub max_function_name_length: u16,
    /// max parameters size
    pub max_parameters_size: u32,
    /// max ledger changes
    pub max_ledger_changes_count: u64,
    /// max slot count in state changes
    pub max_changes_slot_count: u64,
    /// max rolls in proof-of-stake and state changes
    pub max_rolls_length: u64,
    /// max production stats in proof-of-stake and state changes
    pub max_production_stats_length: u64,
    /// max credits in proof-of-stake and state changes
    pub max_credits_length: u64,
    /// max executed ops
    pub max_executed_ops_length: u64,
    /// max executed ops changes
    pub max_ops_changes_length: u64,
    /// consensus bootstrap part size
    pub consensus_bootstrap_part_size: u64,
    /// max number of consensus block ids when sending a bootstrap cursor from the client
    pub max_consensus_block_ids: u64,
    /// block count to check / process for versioning stats
    pub mip_store_stats_block_considered: usize,
    /// max denunciations in block header
    pub max_denunciations_per_block_header: u32,
    /// max executed denunciations changes
    pub max_denunciation_changes_length: u64,
    /// chain id
    pub chain_id: u64,
}

/// Bootstrap server binding
#[allow(missing_docs)]
#[derive(Debug, Deserialize, Clone, SubStruct)]
#[parent(type = "BootstrapConfig")]
pub struct BootstrapSrvBindCfg {
    pub rate_limit: u64,
    pub thread_count: u8,
    pub max_datastore_key_length: u8,
    pub randomness_size_bytes: usize,
    pub consensus_bootstrap_part_size: u64,
    pub write_error_timeout: MassaTime,
}

/// Bootstrap client config
#[allow(missing_docs)]
#[derive(Debug, Deserialize, Clone, SubStruct)]
#[parent(type = "BootstrapConfig")]
pub struct BootstrapClientConfig {
    pub rate_limit: u64,
    pub endorsement_count: u32,
    pub max_listeners_per_peer: u32,
    pub max_advertise_length: u32,
    pub max_bootstrap_blocks_length: u32,
    pub max_operations_per_block: u32,
    pub thread_count: u8,
    pub randomness_size_bytes: usize,
    pub max_bootstrap_error_length: u64,
    pub max_final_state_elements_size: u32,
    pub max_versioning_elements_size: u32,
    pub max_datastore_entry_count: u64,
    pub max_datastore_key_length: u8,
    pub max_datastore_value_length: u64,
    pub max_ledger_changes_count: u64,
    pub max_changes_slot_count: u64,
    pub max_rolls_length: u64,
    pub max_production_stats_length: u64,
    pub max_credits_length: u64,
    pub max_executed_ops_length: u64,
    pub max_ops_changes_length: u64,
    pub mip_store_stats_block_considered: usize,
    pub max_denunciations_per_block_header: u32,
    pub max_denunciation_changes_length: u64,
    pub chain_id: u64,
}

/// Bootstrap Message der args
#[allow(missing_docs)]
#[derive(SubStruct)]
#[parent(type = "BootstrapClientConfig")]
pub struct BootstrapServerMessageDeserializerArgs {
    pub thread_count: u8,
    pub endorsement_count: u32,
    pub max_advertise_length: u32,
    pub max_listeners_per_peer: u32,
    pub max_bootstrap_blocks_length: u32,
    pub max_operations_per_block: u32,
    pub max_final_state_elements_size: u32,
    pub max_versioning_elements_size: u32,
    pub max_ledger_changes_count: u64,
    pub max_datastore_key_length: u8,
    pub max_datastore_value_length: u64,
    pub max_datastore_entry_count: u64,
    pub max_bootstrap_error_length: u64,
    pub max_changes_slot_count: u64,
    pub max_rolls_length: u64,
    pub max_production_stats_length: u64,
    pub max_credits_length: u64,
    pub max_executed_ops_length: u64,
    pub max_ops_changes_length: u64,
    pub mip_store_stats_block_considered: usize,
    pub max_denunciations_per_block_header: u32,
    pub max_denunciation_changes_length: u64,
    pub chain_id: u64,
}

// TODO: add a proc macro for this case
// We set last_start_period to None because we set the value during Bootstrap
impl From<&BootstrapServerMessageDeserializerArgs> for BlockDeserializerArgs {
    fn from(value: &BootstrapServerMessageDeserializerArgs) -> Self {
        Self {
            thread_count: value.thread_count,
            max_operations_per_block: value.max_operations_per_block,
            endorsement_count: value.endorsement_count,
            max_denunciations_per_block_header: value.max_denunciations_per_block_header,
            last_start_period: None,
            chain_id: value.chain_id,
        }
    }
}