massa_models/config/constants.rs
1//! DEFAULT VALUES USED TO INITIALIZE DIVERS CONFIGURATIONS STRUCTURES
2//!
3//!
4//! # Default hard-coded
5//!
6//! Each crates may contains a `settings.rs` or a `config.rs` the `Default`
7//! implementation of each object take the default Values from the following
8//! file.
9//!
10//! These values are the hard-coded values that make sens to never be modified
11//! by a user. Generally, this values are passed with dependency injection in a `cfg`
12//! parameter for each worker, that is convenient for unit tests.
13//!
14//! A parallel file with the same constant definitions exist for the testing case.
15//! (`default_testing.rs`) But as for the current file you shouldn't modify it.
16use std::str::FromStr;
17
18use crate::{amount::Amount, serialization::u32_be_bytes_min_length, version::Version};
19use massa_signature::KeyPair;
20use massa_time::MassaTime;
21use num::rational::Ratio;
22
23/// Massa Community charter content
24pub const COMMUNITY_CHARTER_CONTENT: &str = include_str!("../../../COMMUNITY_CHARTER.md");
25
26/// IMPORTANNT TODO: should be removed after the bootstrap messages refacto
27pub const SIGNATURE_DESER_SIZE: usize = 64 + 1;
28
29/// Limit on the number of peers we advertise to others.
30pub const MAX_ADVERTISE_LENGTH: u32 = 10000;
31/// Maximum message length in bytes
32pub const MAX_MESSAGE_SIZE: u32 = 1048576000;
33/// Max number of operations per message
34pub const MAX_OPERATIONS_PER_MESSAGE: u32 = 1024;
35/// Length of the handshake random signature
36pub const HANDSHAKE_RANDOMNESS_SIZE_BYTES: usize = 32;
37
38/// Consensus static parameters (defined by protocol used)
39/// Changing one of the following values is considered as a breaking change
40/// Values differ in `test` flavor building for faster CI and simpler scenarios
41pub const CHANNEL_SIZE: usize = 1024;
42
43lazy_static::lazy_static! {
44 /// Time in milliseconds when the blockclique started.
45 /// In sandbox mode, the value depends on starting time and on the --restart-from-snapshot-at-period argument in CLI,
46 /// so that the network starts or restarts 10 seconds after launch
47 pub static ref GENESIS_TIMESTAMP: MassaTime = if cfg!(feature = "sandbox") {
48 std::env::var("GENESIS_TIMESTAMP").map(|timestamp| MassaTime::from_millis(timestamp.parse::<u64>().unwrap())).unwrap_or_else(|_|
49 MassaTime::now()
50 .saturating_sub(
51 T0.checked_mul(get_period_from_args()).unwrap()
52 )
53 .saturating_add(MassaTime::from_millis(1000 * 10)
54 )
55 )
56 } else {
57 MassaTime::from_millis(1705312800000) // Monday, January 15, 2024 10:00:00 AM UTC
58 };
59
60 /// TESTNET: time when the blockclique is ended.
61 pub static ref END_TIMESTAMP: Option<MassaTime> =
62 #[allow(clippy::if_same_then_else)]
63 if cfg!(feature = "sandbox") {
64 None
65 } else {
66 None
67 };
68 /// `KeyPair` to sign genesis blocks.
69 pub static ref GENESIS_KEY: KeyPair = KeyPair::from_str("S1UxdCJv5ckDK8z87E5Jq5fEfSVLi2cTHgtpfZy7iURs3KpPns8")
70 .unwrap();
71 /// number of cycle misses (strictly) above which stakers are deactivated
72 pub static ref POS_MISS_RATE_DEACTIVATION_THRESHOLD: Ratio<u64> = Ratio::new(7, 10);
73 /// node version
74 pub static ref VERSION: Version = {
75 if cfg!(feature = "sandbox") {
76 "SAND.5.0"
77 } else {
78 "MAIN.5.0"
79 }
80 .parse()
81 .unwrap()
82 };
83 /// node chain id (to avoid replay attacks)
84 ///
85 /// By signing an operation with an ID of the target chain
86 /// (e.g. whether the operation targets LABNET, BUILDNET or MAINNET), the user is protected from
87 /// a malicious actor that could steal operations created on BUILDNET / LABNET and try to replay
88 /// them on the Massa MAINNET (and potentially stealing real coins)
89 /// Chain id idea and implementation come from Ethereum EIPs:
90 /// * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
91 /// * https://eips.ethereum.org/EIPS/eip-1344
92 /// Chain id can be queried in Smart contracts (AssemblyScript: chain_id call) and in the
93 /// jsonrpc get_status call
94 pub static ref CHAINID: u64 = {
95 // MASM (MainNet): 77658377
96 // MASS (SecureNet): 77658383
97 // MASB (BuildNet): 77658366
98 // MASL (Labnet): 77658376
99 // SANDBOX (Sandbox): 77
100 match VERSION.to_string() {
101 // Sandbox
102 s if s.starts_with("SAND") => 77,
103 // BuildNet
104 s if s.starts_with("DEVN") => 77658366,
105 // SecureNet
106 s if s.starts_with("SECU") => 77658383,
107 // MainNet
108 s if s.starts_with("MAIN") => 77658377,
109 // LabNet
110 s if s.starts_with("LABN") => 77658376,
111 _ => {
112 panic!("Unhandled VERSION ({}), cannot compute chain id", *VERSION);
113 }
114 }
115 };
116}
117
118/// Helper function to parse args for lazy_static evaluations
119pub fn get_period_from_args() -> u64 {
120 let mut last_start_period = 0;
121 let mut parse_next = false;
122 for args in std::env::args() {
123 if parse_next {
124 last_start_period = u64::from_str(&args).unwrap_or_default();
125 break;
126 }
127 parse_next = args == *"--restart-from-snapshot-at-period";
128 }
129 last_start_period
130}
131
132/// Price of a roll in the network
133pub const ROLL_PRICE: Amount = Amount::const_init(100, 0);
134/// Block reward is given for each block creation
135pub const BLOCK_REWARD: Amount = Amount::const_init(40001, 5);
136/// Cost to store one byte in the ledger
137pub const LEDGER_COST_PER_BYTE: Amount = Amount::const_init(1, 4);
138/// Cost for a base entry default 0.01 MASSA
139pub const LEDGER_ENTRY_BASE_COST: Amount = Amount::const_init(1, 3);
140/// Base size of a empty datastore entry (not counting the key nor the value)
141pub const LEDGER_ENTRY_DATASTORE_BASE_SIZE: usize = 4;
142/// Time between the periods in the same thread.
143pub const T0: MassaTime = MassaTime::from_millis(16000);
144/// Proof of stake seed for the initial draw
145pub const INITIAL_DRAW_SEED: &str = "massa_genesis_seed";
146/// Number of threads
147pub const THREAD_COUNT: u8 = 32;
148/// Number of endorsement
149pub const ENDORSEMENT_COUNT: u32 = 16;
150/// Maximum number of endorsements kept for a given `(slot, index)` draw, whatever the endorsed
151/// block is. Enforced both by the endorsement pool and by the protocol propagation path, which
152/// share this bound so that neither becomes the tighter of the two.
153///
154/// An honest endorser signs exactly one endorsement per `(slot, index)`: the factory walks slots
155/// strictly monotonically and never re-endorses after a reorg. So several entries under the same
156/// key mean the drawn endorser equivocated. The endorsed block is not constrained at ingress and
157/// the endorsement id is derived from the whole signed content, so without a bound such an endorser
158/// could mint arbitrarily many valid endorsements differing only by their endorsed block, growing
159/// the pool without limit and having every node relay each variant.
160///
161/// The bound is kept above 1 for two reasons. The denunciation pool needs two conflicting
162/// endorsements to build a denunciation, so a bound of 1 would silently disable endorsement
163/// equivocation denunciation. And `EndorsementPool::get_block_endorsements` only returns the
164/// endorsement matching the parent the block factory settled on, so keeping a single variant makes
165/// insertion first-write-wins, letting an equivocating endorser deliberately send the variant that
166/// does not match our parent and permanently deny us that endorsement slot, which costs block
167/// fitness and rewards. A few variants cover the competing blockclique tips of a real fork while
168/// keeping the worst-case pool size within a small multiple of
169/// `max_endorsements_pool_size_per_thread`.
170pub const MAX_ENDORSEMENTS_PER_SLOT_INDEX: usize = 4;
171/// Threshold for fitness.
172pub const DELTA_F0: u64 = 64 * (ENDORSEMENT_COUNT as u64 + 1);
173/// Maximum number of operations per block
174pub const MAX_OPERATIONS_PER_BLOCK: u32 = 5000;
175/// Maximum block size in bytes
176pub const MAX_BLOCK_SIZE: u32 = 300_000;
177/// Maximum size in bytes of the varint prefix holding the number of operations of a serialized
178/// operation list. That count is a `u32` varint, and a varint carries 7 bits of payload per byte,
179/// hence `ceil(32 / 7) = 5` bytes at most.
180pub const MAX_OPERATIONS_COUNT_PREFIX_SIZE: usize = (u32::BITS as usize).div_ceil(7);
181
182/// Size of the serialized operation list holding operations of aggregate size `operations_size`:
183/// the operations themselves, plus the varint prefix holding their count.
184/// Use it to turn an operations size budget (such as `max_serialized_operations_size_per_block`)
185/// into the payload size a peer is allowed to send us.
186pub const fn operations_payload_size(operations_size: usize) -> usize {
187 operations_size.saturating_add(MAX_OPERATIONS_COUNT_PREFIX_SIZE)
188}
189
190/// Maximum capacity of the asynchronous messages pool
191pub const MAX_ASYNC_POOL_LENGTH: u64 = 500;
192/// Maximum operation validity period count
193pub const OPERATION_VALIDITY_PERIODS: u64 = 10;
194/// Number of periods of executed operation and denunciation history to keep
195pub const KEEP_EXECUTED_HISTORY_EXTRA_PERIODS: u64 = 10;
196/// cycle duration in periods
197pub const PERIODS_PER_CYCLE: u64 = 128;
198
199/// Number of cycles saved in `PoSFinalState`
200///
201/// 6 for PoS itself so we can check denuncations on selections at C-2 after a bootstrap
202/// See https://github.com/massalabs/massa/pull/3871
203/// 1 for pruned cycle safety during bootstrap
204pub const POS_SAVED_CYCLES: usize = 7;
205/// Number of cycle draws saved in the selector cache
206///
207/// 5 to have a C-2 to C+2 range (6 cycles post-bootstrap give 5 cycle draws)
208/// 1 for margin
209pub const SELECTOR_DRAW_CACHE_SIZE: usize = 6;
210/// Maximum number of consensus blocks in a bootstrap batch
211pub const CONSENSUS_BOOTSTRAP_PART_SIZE: u64 = 50;
212/// Max block ids in the client consensus reconnect ask. Larger local graphs are fine in-session;
213/// only the ask is capped (newest finals), and the graph is pruned to match on reconnect.
214pub const MAX_CONSENSUS_BLOCKS_IDS: u64 = 300;
215/// Maximum size of proof-of-stake rolls
216pub const MAX_ROLLS_COUNT_LENGTH: u64 = 10_000;
217/// Maximum size of proof-of-stake production stats
218pub const MAX_PRODUCTION_STATS_LENGTH: u64 = 10_000;
219/// Maximum size proof-of-stake deferred credits
220pub const MAX_DEFERRED_CREDITS_LENGTH: u64 = 10_000;
221/// Maximum size of executed ops
222pub const MAX_EXECUTED_OPS_LENGTH: u64 = 1_000;
223/// Maximum size of executed ops changes
224pub const MAX_EXECUTED_OPS_CHANGES_LENGTH: u64 = 20_000;
225/// Maximum length of a datastore key
226pub const MAX_DATASTORE_KEY_LENGTH: u8 = 255;
227/// Maximum length of an operation datastore key
228pub const MAX_OPERATION_DATASTORE_KEY_LENGTH: u8 = MAX_DATASTORE_KEY_LENGTH;
229/// Maximum length of a datastore value
230pub const MAX_DATASTORE_VALUE_LENGTH: u64 = 10_000_000;
231/// Maximum length of a smart contract bytecode
232pub const MAX_BYTECODE_LENGTH: u64 = 10_000_000;
233/// Maximum length of an operation datastore value
234pub const MAX_OPERATION_DATASTORE_VALUE_LENGTH: u64 = 500_000;
235/// Maximum ledger changes in a block
236pub const MAX_LEDGER_CHANGES_PER_SLOT: u32 = u32::MAX;
237/// Maximum production events in a block
238pub const MAX_PRODUCTION_EVENTS_PER_BLOCK: u32 = u32::MAX;
239/// Maximum ledger changes count
240pub const MAX_LEDGER_CHANGES_COUNT: u64 =
241 100_u32.saturating_mul(MAX_LEDGER_CHANGES_PER_SLOT) as u64;
242/// Maximum number of key/values in the datastore of a ledger entry
243pub const MAX_DATASTORE_ENTRY_COUNT: u64 = u64::MAX;
244/// Maximum number of key/values in the datastore of a `ExecuteSC` operation
245pub const MAX_OPERATION_DATASTORE_ENTRY_COUNT: u64 = 128;
246/// Maximum length function name in call SC
247pub const MAX_FUNCTION_NAME_LENGTH: u16 = 255;
248/// Maximum size of parameters in call SC
249pub const MAX_PARAMETERS_SIZE: u32 = 10_000_000;
250/// Maximum length of `rng_seed` in thread cycle
251pub const MAX_RNG_SEED_LENGTH: u32 = PERIODS_PER_CYCLE.saturating_mul(THREAD_COUNT as u64) as u32;
252
253/// CondomMiddleware limits
254/// see test_condom_middleware_calibrate in massa-sc-runtime for origin of
255/// values.
256/// Maximum number of function defined in a smart contract
257const MAX_RUNTIME_MODULE_DEFINED_FUNCTIONS: usize = 512;
258/// Maximum number of function used by a smart contract
259pub const MAX_RUNTIME_MODULE_FUNCTIONS: usize =
260 MAX_RUNTIME_MODULE_DEFINED_FUNCTIONS + MAX_RUNTIME_MODULE_FUNCTION_IMPORTS;
261/// Maximum number of arguments to a function
262const MAX_RUNTIME_MODULE_FUNCTION_ARGS: usize = 64;
263/// Maximum number of value a function can return
264const MAX_RUNTIME_MODULE_FUNCTION_RETURN_VALUES: usize = 8;
265/// Maximum signature length (total number of arguments and return values) for a
266/// function of a smart contract module
267pub const MAX_RUNTIME_MODULE_SIGNATURE_LEN: usize =
268 MAX_RUNTIME_MODULE_FUNCTION_ARGS + MAX_RUNTIME_MODULE_FUNCTION_RETURN_VALUES;
269/// Maximum length for the name of a function defined in a smart contract
270pub const MAX_RUNTIME_MODULE_FUNCTION_NAME_LEN: usize = 256;
271/// Maximum length for the name of a smart contract
272pub const MAX_RUNTIME_MODULE_NAME_LEN: usize = 256;
273/// Maximum number of custom section data
274pub const MAX_RUNTIME_MODULE_CUSTOM_SECTION_LEN: usize = 1;
275/// Maximum length for the custom section data
276pub const MAX_RUNTIME_MODULE_CUSTOM_SECTION_DATA_LEN: usize = 1_000_000;
277/// Maximum number of functions a module can import
278const MAX_RUNTIME_MODULE_FUNCTION_IMPORTS: usize = 256;
279/// Maximum number of memory a module can import
280const MAX_RUNTIME_MODULE_MEMORY_IMPORTS: usize = 1;
281/// Maximum number of elements a module can import
282pub const MAX_RUNTIME_MODULE_IMPORTS: usize =
283 MAX_RUNTIME_MODULE_FUNCTION_IMPORTS + MAX_RUNTIME_MODULE_MEMORY_IMPORTS;
284/// Maximum number of table initializer in a smart contract
285pub const MAX_RUNTIME_MODULE_TABLE_INITIALIZER: usize = MAX_RUNTIME_MODULE_DEFINED_FUNCTIONS;
286/// Maximum number of passive element in a smart contract
287pub const MAX_RUNTIME_MODULE_PASSIVE_ELEMENT: usize = MAX_RUNTIME_MODULE_DEFINED_FUNCTIONS;
288/// Maximum number of passive data in a smart contract
289pub const MAX_RUNTIME_MODULE_PASSIVE_DATA: usize = 512;
290/// Maximum number of global initializer in a smart contract
291pub const MAX_RUNTIME_MODULE_GLOBAL_INITIALIZER: usize = 512;
292/// Maximum number of table in a smart contract
293pub const MAX_RUNTIME_MODULE_TABLE: usize = 16;
294/// Maximum number of memories in a smart contract
295/// - only 1 supported so far (cf specification)
296pub const MAX_RUNTIME_MODULE_MEMORIES: usize = 1;
297/// Maximum number of exports for a smart contract module (function and globals)
298pub const MAX_RUNTIME_MODULE_EXPORTS: usize =
299 MAX_RUNTIME_MODULE_DEFINED_FUNCTIONS + MAX_RUNTIME_MODULE_GLOBAL_INITIALIZER;
300
301// ***********************
302// Bootstrap constants
303//
304
305/// Max message size for bootstrap
306/// Note: Update sizes are not limited, the 190Mb constant is to take them into account.
307pub const MAX_BOOTSTRAP_MESSAGE_FROM_SERVER_SIZE: u32 = MAX_BOOTSTRAP_FINAL_STATE_PARTS_SIZE
308 .saturating_add(MAX_BOOTSTRAP_VERSIONING_ELEMENTS_SIZE)
309 .saturating_add(190_000_000_u32);
310/// The number of bytes needed to encode [`MAX_BOOTSTRAP_MESSAGE_FROM_SERVER_SIZE`]
311pub const MAX_BOOTSTRAP_MESSAGE_FROM_SERVER_SIZE_BYTES: usize =
312 u32_be_bytes_min_length(MAX_BOOTSTRAP_MESSAGE_FROM_SERVER_SIZE);
313/// Max message size for bootstrap coming from client
314/// The worst case is a AskBootstrapPart with mostly 2 keys and MAX_CONSENSUS_BLOCKS_IDS blocks_ids.
315pub const MAX_BOOTSTRAP_MESSAGE_FROM_CLIENT_SIZE: u32 = 1024 * 1024;
316
317/// Bound the bootstrap message length prefix is *encoded* against, in both directions.
318///
319/// This is part of the wire format, not a policy knob: `to_be_bytes_min` derives the width of
320/// the prefix from the bound it is given, and the frame header is fixed-width, so lowering this
321/// narrows the header and leaves any peer built against the wider one blocked forever on bytes
322/// that never arrive. It stays pinned to the server-to-client bound, which is the encoding that
323/// has been on the wire since before `MAIN.5.0`. The tighter per-direction caps are enforced as
324/// value checks on the decoded length instead of by the encoding width.
325pub const BOOTSTRAP_MESSAGE_LEN_PREFIX_MAX: u32 = MAX_BOOTSTRAP_MESSAGE_FROM_SERVER_SIZE;
326/// The number of bytes needed to encode [`BOOTSTRAP_MESSAGE_LEN_PREFIX_MAX`]
327pub const BOOTSTRAP_MESSAGE_LEN_PREFIX_SIZE_BYTES: usize =
328 u32_be_bytes_min_length(BOOTSTRAP_MESSAGE_LEN_PREFIX_MAX);
329const _: () = assert!(
330 BOOTSTRAP_MESSAGE_LEN_PREFIX_SIZE_BYTES == 4,
331 "the bootstrap length prefix has been 4 bytes wide since before MAIN.5.0; changing its width \
332 breaks bootstrap against every deployed node"
333);
334/// Max number of blocks we provide/ take into account while bootstrapping
335pub const MAX_BOOTSTRAP_BLOCKS: u32 = 1000000;
336/// max bootstrapped cliques
337pub const MAX_BOOTSTRAP_CLIQUES: u32 = 1000;
338/// max bootstrapped dependencies
339pub const MAX_BOOTSTRAP_DEPS: u32 = 1000;
340/// Max number of child nodes
341pub const MAX_BOOTSTRAP_CHILDREN: u32 = 1000;
342/// Max number of cycles in PoS bootstrap
343pub const MAX_BOOTSTRAP_POS_CYCLES: u32 = 5;
344/// Max async pool changes
345pub const MAX_BOOTSTRAP_ASYNC_POOL_CHANGES: u64 = 100_000;
346/// Max bytes in final states parts
347pub const MAX_BOOTSTRAP_FINAL_STATE_PARTS_SIZE: u32 = 100_000_000;
348/// Max bytes in final states parts
349pub const MAX_BOOTSTRAP_VERSIONING_ELEMENTS_SIZE: u32 = 10_000_000;
350
351/// Rough in-memory cost of one `(key, value)` entry of a received bootstrap batch, on top of the
352/// bytes it carries: the `BTreeMap` node slot it occupies, the two `Vec` headers, and allocator
353/// rounding. Deliberately an over-estimate, so that the budget below is reached before the
354/// allocator actually is.
355pub const BOOTSTRAP_BATCH_ENTRY_OVERHEAD: usize = 96;
356
357/// Smallest wire size a *real* `(key, value)` entry of a bootstrap batch is expected to have.
358///
359/// Every state key carries a column-family prefix (`ledger/`, `versioning/`, ...) plus its own
360/// identifying bytes, so real entries run to several tens of bytes. Measured over a full mainnet
361/// bootstrap (33 state parts of 100 MB): the smallest entry seen was 22 bytes on the wire, and the
362/// densest part held ~3.57M entries, i.e. a ~443 MB in-memory footprint against the ~700 MB budget
363/// this value yields for a state part. Lowering it loosens the bound for no gain; raising it past
364/// the measured floor would start rejecting honest batches.
365pub const MIN_EXPECTED_BOOTSTRAP_ELEMENT_WIRE_SIZE: usize = 16;
366
367/// Budget for the in-memory footprint of one received bootstrap batch section, derived from the
368/// wire size that section is already bounded by.
369///
370/// Counting entries is not a sufficient bound on its own, and neither is the wire size: a batch is
371/// bounded in bytes on the wire, but an entry that costs two bytes there costs
372/// [`BOOTSTRAP_BATCH_ENTRY_OVERHEAD`] bytes once it is a map node, so a batch of tiny entries
373/// amplifies far beyond the size it announced. This budget charges each entry the bytes it carries
374/// *plus* that overhead, which bounds the amplification directly instead of bounding the wire and
375/// hoping. It is calibrated so that any batch a conforming peer can build fits comfortably —
376/// including one from a `MAIN.5.0` server, which bounds a batch by size only.
377pub const fn bootstrap_batch_allocation_budget(section_wire_size: usize) -> usize {
378 section_wire_size.saturating_add(
379 (section_wire_size / MIN_EXPECTED_BOOTSTRAP_ELEMENT_WIRE_SIZE)
380 .saturating_mul(BOOTSTRAP_BATCH_ENTRY_OVERHEAD),
381 )
382}
383/// Max size of the IP list
384pub const IP_LIST_MAX_SIZE: usize = 10000;
385/// Size of the random bytes array used for the bootstrap, safe to import
386pub const BOOTSTRAP_RANDOMNESS_SIZE_BYTES: usize = 32;
387/// Max size of the printed error
388pub const MAX_BOOTSTRAP_ERROR_LENGTH: u64 = 10000;
389
390/// Protocol controller channel size
391pub const PROTOCOL_CONTROLLER_CHANNEL_SIZE: usize = 1024;
392/// Protocol event channel size
393pub const PROTOCOL_EVENT_CHANNEL_SIZE: usize = 1024;
394
395// ***********************
396// Constants used for execution module (injected from ConsensusConfig)
397//
398
399/// Maximum of GAS allowed for a block
400pub const MAX_GAS_PER_BLOCK: u64 = u32::MAX as u64;
401/// Base GAS budget for asynchronous messages execution on one slot.
402/// This is not a strict per-slot cap: since MIP-0001, `execute_slot` tops this budget
403/// up with the gas left unused by the block at that slot (and subtracts the gas booked
404/// by deferred calls), so async execution can exceed this value on underfilled slots.
405/// The bound that always holds is `MAX_GAS_PER_BLOCK + MAX_ASYNC_GAS` for the whole slot.
406pub const MAX_ASYNC_GAS: u64 = 1_000_000_000;
407/// Constant cost applied to asynchronous messages (to take into account some costs related to snapshot)
408pub const ASYNC_MSG_CST_GAS_COST: u64 = 1_000_000;
409/// Gas used by a base operation (transaction, roll buy, roll sell)
410pub const BASE_OPERATION_GAS_COST: u64 = 800_000; // approx MAX_GAS_PER_BLOCK / MAX_OPERATIONS_PER_BLOCK
411/// Maximum event size in bytes
412pub const MAX_EVENT_DATA_SIZE_V0: usize = 50_000;
413/// Maximum event size in bytes
414pub const MAX_EVENT_DATA_SIZE: usize = 1024;
415/// Maximum event number that can be emitted for an operation
416pub const MAX_EVENT_PER_OPERATION: usize = 25;
417/// Maximum number of recursion for calls
418pub const MAX_RECURSIVE_CALLS_DEPTH: u16 = 25;
419
420//
421// Constants used in network
422//
423
424/// Max number of endorsements per message
425pub const MAX_ENDORSEMENTS_PER_MESSAGE: u32 = 1024;
426/// node send channel size
427pub const NODE_SEND_CHANNEL_SIZE: usize = 10_000;
428/// max duplex buffer size
429pub const MAX_DUPLEX_BUFFER_SIZE: usize = 1024;
430/// network controller communication channel size
431pub const NETWORK_CONTROLLER_CHANNEL_SIZE: usize = 10_000;
432/// network event channel size
433pub const NETWORK_EVENT_CHANNEL_SIZE: usize = 10_000;
434/// network node command channel size
435pub const NETWORK_NODE_COMMAND_CHANNEL_SIZE: usize = 10_000;
436/// network node event channel size
437pub const NETWORK_NODE_EVENT_CHANNEL_SIZE: usize = 10_000;
438
439//
440// Constants used in protocol
441//
442/// Maximum of time we keep the operations in the storage of the propagation thread
443pub const MAX_OPERATION_STORAGE_TIME: MassaTime = MassaTime::from_millis(60000);
444/// Maximum size of channel used for commands in retrieval thread of operations
445pub const MAX_SIZE_CHANNEL_COMMANDS_RETRIEVAL_OPERATIONS: usize = 10000;
446/// Maximum size of channel used for commands in propagation thread of operations
447pub const MAX_SIZE_CHANNEL_COMMANDS_PROPAGATION_OPERATIONS: usize = 10000;
448/// Maximum size of channel used for commands in retrieval thread of block
449pub const MAX_SIZE_CHANNEL_COMMANDS_RETRIEVAL_BLOCKS: usize = 10000;
450/// Maximum size of channel used for commands in propagation thread of block
451pub const MAX_SIZE_CHANNEL_COMMANDS_PROPAGATION_BLOCKS: usize = 10000;
452/// Maximum size of channel used for commands in retrieval thread of endorsements
453pub const MAX_SIZE_CHANNEL_COMMANDS_RETRIEVAL_ENDORSEMENTS: usize = 10000;
454/// Maximum size of channel used for commands in propagation thread of endorsements
455pub const MAX_SIZE_CHANNEL_COMMANDS_PROPAGATION_ENDORSEMENTS: usize = 10000;
456/// Maximum size of channel used for commands in connectivity thread
457pub const MAX_SIZE_CHANNEL_COMMANDS_CONNECTIVITY: usize = 10000;
458/// Maximum size of channel used for commands in peers management thread
459pub const MAX_SIZE_CHANNEL_COMMANDS_PEERS: usize = 10000;
460/// Maximum size of channel used for commands in peer testers thread
461pub const MAX_SIZE_CHANNEL_COMMANDS_PEER_TESTERS: usize = 10000;
462/// Maximum size of channel used to send network events to the operation handler
463pub const MAX_SIZE_CHANNEL_NETWORK_TO_OPERATION_HANDLER: usize = 10000;
464/// Maximum size of channel used to send network events to the block handler
465pub const MAX_SIZE_CHANNEL_NETWORK_TO_BLOCK_HANDLER: usize = 10000;
466/// Maximum size of channel used to send network events to the endorsement handler
467pub const MAX_SIZE_CHANNEL_NETWORK_TO_ENDORSEMENT_HANDLER: usize = 10000;
468/// Maximum size of channel used to send network events to the peer handler
469pub const MAX_SIZE_CHANNEL_NETWORK_TO_PEER_HANDLER: usize = 10000;
470/// Maximum number of peer in a announcement list of peer
471pub const MAX_PEERS_IN_ANNOUNCEMENT_LIST: u64 = 100;
472/// Maximum number of listeners for a peer
473pub const MAX_LISTENERS_PER_PEER: u64 = 100;
474//
475// Constants used in versioning
476//
477/// Threshold to accept a new versioning
478pub const VERSIONING_THRESHOLD_TRANSITION_ACCEPTED: Ratio<u64> = Ratio::new_raw(50, 100);
479/// Block count to process in MipStoreStats (for state change threshold)
480pub const MIP_STORE_STATS_BLOCK_CONSIDERED: usize = 1000;
481/// Minimum value allowed for activation delay (in MIP info)
482pub const VERSIONING_ACTIVATION_DELAY_MIN: MassaTime = T0.saturating_mul(PERIODS_PER_CYCLE);
483
484//
485// Constants for denunciation factory
486//
487
488/// denunciation expiration delta
489pub const DENUNCIATION_EXPIRE_PERIODS: u64 = PERIODS_PER_CYCLE;
490/// Max number of denunciations that can be included in a block header
491pub const MAX_DENUNCIATIONS_PER_BLOCK_HEADER: u32 = 128;
492/// Number of roll to remove per denunciation
493pub const ROLL_COUNT_TO_SLASH_ON_DENUNCIATION: u64 = 1;
494/// Maximum size of executed denunciations
495pub const MAX_DENUNCIATION_CHANGES_LENGTH: u64 = 1_000;
496/// Maximum size of deferred call pool changes
497// TODO define this value
498// TODO: set to a reasonable value max pool changes
499pub const DEFERRED_CALL_MAX_POOL_CHANGES: u64 = 100_000;
500/// Maximum size of deferred call future slots (1 week)
501pub const DEFERRED_CALL_MAX_FUTURE_SLOTS: u64 = 1209600;
502/// maximum gas for deferred call
503pub const DEFERRED_CALL_MAX_ASYNC_GAS: u64 = MAX_ASYNC_GAS;
504/// max change denominator
505pub const DEFERRED_CALL_BASE_FEE_MAX_CHANGE_DENOMINATOR: usize = 1250;
506/// deferred call min gas increment (1 nanomassa)
507pub const DEFERRED_CALL_MIN_GAS_INCREMENT: u64 = 1;
508/// deferred call min gas cost (10 nanomassa)
509pub const DEFERRED_CALL_MIN_GAS_COST: u64 = 10;
510/// deferred call global overbooking penalty
511pub const DEFERRED_CALL_GLOBAL_OVERBOOKING_PENALTY: Amount = Amount::from_raw(1_000_000_000);
512/// deferred call slot overbooking penalty
513pub const DEFERRED_CALL_SLOT_OVERBOOKING_PENALTY: Amount = Amount::from_raw(1_000_000_000 / 10_000);
514/// deferred call call gas cost
515pub const DEFERRED_CALL_CST_GAS_COST: u64 = 750_000;
516
517// Some checks at compile time that should not be ignored!
518#[allow(clippy::assertions_on_constants)]
519const _: () = {
520 assert!(THREAD_COUNT > 1);
521 assert!((T0).as_millis() >= 1);
522 assert!((T0).as_millis().is_multiple_of(THREAD_COUNT as u64));
523};