rialo_limits/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) Subzero Labs, Inc.
3
4use rialo_s_pubkey::Pubkey;
5
6mod compute_budget;
7pub mod rex;
8
9pub use compute_budget::*;
10// Re-export rex module contents for easier access.
11pub use rex::update_size::*;
12
13/// The number of bytes in a kilobyte.
14const KIB: u64 = 1024;
15
16/// The number of bytes in a megabyte.
17const MIB: u64 = 1024 * KIB;
18
19/// The maximum size of a program instruction payload in bytes.
20pub const MAX_INSTRUCTION_DATA_SIZE: u64 = 65 * KIB;
21
22/// The maximum size of a consensus block in bytes.
23pub const MAX_CONSENSUS_BLOCK_SIZE: u64 = 512 * KIB;
24
25/// The maximum size of a single transaction in bytes.
26pub const MAX_TRANSACTION_SIZE: u64 = 128 * KIB;
27
28/// The maximum size for a payload received from a remote backend in bytes.
29pub const MAX_RESPONSE_SIZE: usize = (10 * MIB) as usize;
30
31/// The size of the data portion of a network packet in bytes.
32/// Note: Maximum over-the-wire size of a Transaction
33/// 1280 is IPv6 minimum MTU
34/// 40 bytes is the size of the IPv6 header
35/// 8 bytes is the size of the fragment header
36pub const PACKET_DATA_SIZE: usize = 4096 - 40 - 8;
37
38#[cfg(test)]
39static_assertions::const_assert_eq!(PACKET_DATA_SIZE, 4048);
40
41// The packet has a maximum length of 1232 bytes.
42// This means the maximum number of 32 byte keys is 38.
43// 38 as an min-sized encoded u16 is 1 byte.
44// We can simply read this byte, if it's >38 we can return None.
45pub const MAX_STATIC_ACCOUNTS_PER_PACKET: u8 =
46 (PACKET_DATA_SIZE / core::mem::size_of::<Pubkey>()) as u8;