Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_runtime_const_h 2 : #define HEADER_fd_src_flamenco_runtime_fd_runtime_const_h 3 : 4 : #include "../leaders/fd_leaders.h" 5 : #include "../types/fd_types.h" 6 : #include "../../ballet/txn/fd_txn.h" /* for fd_acct_addr_t */ 7 : #include "../vm/fd_vm_base.h" /* fd_vm_trace_t */ 8 : 9 : FD_PROTOTYPES_BEGIN 10 : 11 : /* All of the variable bounds in the bank should be deteremined by the 12 : max number of vote accounts and stake accounts that the system 13 : supports. These are not protocol-level bounds, but rather bounds 14 : that are used to determine the max amount of memory that various 15 : data structures require. */ 16 : 17 57 : #define FD_RUNTIME_MAX_VOTE_ACCOUNTS (40200UL) /* ~40k vote accounts */ 18 : 19 176193 : #define FD_RUNTIME_MAX_STAKE_ACCOUNTS (3000000UL) /* 3M stake accounts */ 20 : 21 : #define FD_RUNTIME_SLOTS_PER_EPOCH (432000UL) /* 432k slots per epoch */ 22 : 23 : /* Maximum amount of writable accounts per transaction 24 : https://github.com/anza-xyz/agave/blob/v3.0.8/runtime/src/bank.rs#L2946 */ 25 108 : #define FD_RUNTIME_MAX_WRITABLE_ACCOUNTS_PER_TRANSACTION (64UL) 26 : 27 : /* The initial block id hash is a dummy value for the initial block id 28 : as one is not provided in snapshots. This does not have an 29 : equivalent in Agave. 30 : 31 : TODO: This should be removed in favor of repairing the last shred of 32 : the snapshot slot to get the actual block id of the snapshot slot. */ 33 : 34 0 : #define FD_RUNTIME_INITIAL_BLOCK_ID (0xF17EDA2CE7B1DUL) 35 : 36 : /* The stake program is now a BPF program which means that there is a 37 : variable cost in CUs to execute the stake program. This is the 38 : absolute minimum cost of executing the stake program. 39 : 40 : FIXME: This is a reasonable estimate based off of BPF withdraw 41 : instructions. The hard bound still needs to be determined. */ 42 : 43 : #define FD_RUNTIME_MIN_STAKE_INSN_CUS (6000UL) 44 : 45 : /* FD_RUNTIME_ACC_SZ_MAX is the protocol level hardcoded size limit of a 46 : Solana account. */ 47 : 48 18 : #define FD_RUNTIME_ACC_SZ_MAX (10UL<<20) /* 10MiB */ 49 : 50 : /* FD_RUNTIME_WRITABLE_ACCOUNTS_MAX is the protocol level hardcoded 51 : limit of writable accounts per transaction. */ 52 : 53 : #define FD_RUNTIME_WRITABLE_ACCOUNTS_MAX (64UL) 54 : 55 : /* Genesis creation times for major Solana clusters */ 56 : 57 0 : #define FD_RUNTIME_GENESIS_CREATION_TIME_MAINNET (1584368940UL) 58 0 : #define FD_RUNTIME_GENESIS_CREATION_TIME_TESTNET (1580834132UL) 59 0 : #define FD_RUNTIME_GENESIS_CREATION_TIME_DEVNET (1597081016UL) 60 : 61 : 62 : /* FeeStructure constants. Bank is always initialized with 63 : `FeeStructure::default()` 64 : https://github.com/anza-xyz/agave/blob/v3.1.0-beta.0/runtime/src/bank.rs#L1859 65 : https://github.com/anza-xyz/solana-sdk/blob/badc2c40071e6e7f7a8e8452b792b66613c5164c/fee-structure/src/lib.rs#L100 */ 66 6 : #define FD_RUNTIME_FEE_STRUCTURE_LAMPORTS_PER_SIGNATURE (5000UL) 67 : 68 : static const fd_cluster_version_t FD_RUNTIME_CLUSTER_VERSION = { 69 : .major = 3UL, 70 : .minor = 0UL, 71 : .patch = 3UL 72 : }; 73 : 74 : /* Various constant values used by the runtime. */ 75 : 76 12 : #define MICRO_LAMPORTS_PER_LAMPORT (1000000UL) 77 : 78 0 : #define DEFAULT_HASHES_PER_TICK (12500) 79 : #define UPDATED_HASHES_PER_TICK2 (17500) 80 : #define UPDATED_HASHES_PER_TICK3 (27500) 81 : #define UPDATED_HASHES_PER_TICK4 (47500) 82 : #define UPDATED_HASHES_PER_TICK5 (57500) 83 : #define UPDATED_HASHES_PER_TICK6 (62500) 84 : 85 0 : #define SECONDS_PER_YEAR ((double)(365.242199 * 24.0 * 60.0 * 60.0)) 86 : 87 : /* https://github.com/anza-xyz/agave/blob/0d34a1a160129c4293dac248e14231e9e773b4ce/program-runtime/src/compute_budget.rs#L139 */ 88 : #define FD_MAX_INSTRUCTION_TRACE_LENGTH (64UL) 89 : /* https://github.com/anza-xyz/agave/blob/f70ab5598ccd86b216c3928e4397bf4a5b58d723/compute-budget/src/compute_budget.rs#L13 */ 90 0 : #define FD_MAX_INSTRUCTION_STACK_DEPTH (5UL) 91 : 92 : 93 0 : #define FD_RUNTIME_VM_TRACE_EVENT_MAX (128UL<<20) 94 0 : #define FD_RUNTIME_VM_TRACE_EVENT_DATA_MAX (2048UL) 95 : 96 0 : #define FD_RUNTIME_VM_TRACE_STATIC_FOOTPRINT (FD_RUNTIME_VM_TRACE_EVENT_MAX + sizeof(fd_vm_trace_t)) 97 0 : #define FD_RUNTIME_VM_TRACE_STATIC_ALIGN (8UL) 98 : 99 : /* Maximum CPI instruction data size. 10 KiB was chosen to ensure that 100 : CPI instructions are not more limited than transaction instructions 101 : if the size of transactions is doubled in the future. 102 : https://github.com/anza-xyz/agave/blob/v3.1.1/transaction-context/src/lib.rs#L33 */ 103 : #define FD_RUNTIME_CPI_MAX_INSTR_DATA_LEN (10240UL) 104 : 105 : /* The bpf loader's serialization footprint is bounded in the worst case 106 : by 64 unique writable accounts which are each 10MiB in size (bounded 107 : by the amount of transaction accounts). We can also have up to 108 : FD_BPF_INSTR_ACCT_MAX (255) referenced accounts in an instruction. 109 : 110 : - 8 bytes for the account count 111 : For each account: 112 : If duplicated: 113 : - 8 bytes for each duplicated account 114 : If not duplicated: 115 : - header for each unique account (96 bytes) 116 : - 1 account idx byte 117 : - 1 is_signer byte 118 : - 1 is_writable byte 119 : - 1 executable byte 120 : - 4 bytes for the original data length 121 : - 32 bytes for the key 122 : - 32 bytes for the owner 123 : - 8 bytes for the lamports 124 : - 8 bytes for the data length 125 : - 8 bytes for the rent epoch 126 : - 10MiB for the data (10485760 bytes) 127 : - 10240 bytes for resizing the data 128 : - 0 padding bytes because this is already 8 byte aligned 129 : - 8 bytes for instruction data length 130 : - 1232 bytes for the instruction data (TXN_MTU) 131 : - 32 bytes for the program id 132 : 133 : So the total footprint is: 134 : 8 header bytes + 135 : 192 duplicate accounts (256 instr accounts - 64 unique accounts) * 8 bytes = 1536 duplicate account bytes + 136 : 64 unique accounts * (96 header bytes + 10485760 bytes + 10240 resizing bytes) = 671750144 unique account bytes + 137 : 8 + 1232 + 32 = 1272 bytes trailer bytes + program id = 671751416 bytes 138 : Total footprint: 671752960 bytes 139 : 140 : This is a reasonably tight-ish upper bound on the input region 141 : footprint for a single instruction at a single stack depth. In 142 : reality the footprint would be slightly smaller because the 143 : instruction data can't be equal to the transaction MTU. 144 : */ 145 48 : #define MAX_PERMITTED_DATA_INCREASE (10240UL) // 10KB 146 0 : #define FD_BPF_ALIGN_OF_U128 (8UL) 147 0 : #define FD_ACCOUNT_REC_ALIGN (8UL) 148 : /* https://github.com/anza-xyz/sbpf/blob/v0.12.2/src/ebpf.rs#L37-L38 */ 149 : #define FD_RUNTIME_EBPF_HOST_ALIGN (16UL) 150 : 151 : /* FD_INSTR_ACCT_MAX is the maximum number of accounts that can 152 : be referenced by a single instruction. 153 : 154 : This is different from FD_BPF_INSTR_ACCT_MAX, which is enforced by the 155 : BPF serializer. It is possible to pass in more than FD_BPF_INSTR_ACCT_MAX 156 : instruction accounts in a transaction (for example mainnet transaction) 157 : 3eDdfZE6HswPxFKrtnQPsEmTkyL1iP57gRPEXwaqNGAqF1paGXCYYMwh7z4uQDUMgFor742sikVSQZW1gFRDhPNh). 158 : 159 : A transaction like this will be loaded and sanitized, but will fail in the 160 : bpf serialization stage. It is also possible to invoke a native program with 161 : more than FD_BPF_INSTR_ACCT_MAX instruction accounts that will execute successfully. 162 : 163 : Therefore we need to derive a bound from a worst-case transaction: one that 164 : has the maximum possible number of instruction accounts at the expense of 165 : everything else. This is a legacy transaction with a single account address, 166 : a single signature, a single instruction with empty data and as many 167 : instruction accounts as possible. 168 : 169 : Therefore, the maximum number of instruction accounts is: 170 : (MTU - fixed overhead) / (size of instruction account) 171 : = (MTU 172 : - signature count (1 byte, value=1) 173 : - signature (64 bytes) 174 : - signature count in header (1 byte) 175 : - readonly signed count (1 byte) 176 : - readonly unsigned count (1 byte) 177 : - account count (1 byte, compact-u16 value=1) 178 : - 1 account address (32 bytes) 179 : - recent blockhash (32 bytes) 180 : - instruction count (1 byte, compact-u16 value=1) 181 : - program id index (1 byte) 182 : - instruction account count (2 bytes) 183 : - data len (1 byte, value=0) 184 : = 1232 - 1 - 64 - 1 - 1 - 1 - 1 - 32 - 32 - 1 - 1 - 2 - 1 185 : = 1094 186 : 187 : TODO: SIMD-406 (https://github.com/solana-foundation/solana-improvement-documents/pull/406) 188 : limits the number of instruction accounts to 255 in transaction sanitization. 189 : 190 : Once the corresponding feature gate has been activated, we can reduce 191 : FD_INSTR_ACCT_MAX to 255. We cannot reduce this before as this would cause 192 : the result of the get_processed_sibling_instruction syscall to diverge from 193 : Agave. */ 194 6 : #define FD_INSTR_ACCT_MAX (1094UL) 195 : 196 : /* FD_BPF_INSTR_ACCT_MAX is the maximum number of accounts that 197 : an instruction that goes through the bpf loader serializer can reference. 198 : 199 : The BPF loader has a lower limit for the number of instruction accounts 200 : than is enforced in transaction sanitization. 201 : 202 : TODO: remove this limit once SIMD-406 is activated, as we can then use the 203 : same limit everywhere. 204 : 205 : https://github.com/anza-xyz/agave/blob/v3.1.4/transaction-context/src/lib.rs#L30-L32 */ 206 : #define FD_BPF_INSTR_ACCT_MAX (255UL) 207 : 208 : #define FD_BPF_LOADER_UNIQUE_ACCOUNT_FOOTPRINT(direct_mapping) \ 209 : (1UL /* dup byte */ + \ 210 : sizeof(uchar) /* is_signer */ + \ 211 : sizeof(uchar) /* is_writable */ + \ 212 : sizeof(uchar) /* executable */ + \ 213 : sizeof(uint) /* original_data_len */ + \ 214 : sizeof(fd_pubkey_t) /* key */ + \ 215 : sizeof(fd_pubkey_t) /* owner */ + \ 216 : sizeof(ulong) /* lamports */ + \ 217 : sizeof(ulong) /* data len */ + \ 218 : (direct_mapping ? FD_BPF_ALIGN_OF_U128 : FD_ULONG_ALIGN_UP( FD_RUNTIME_ACC_SZ_MAX, FD_BPF_ALIGN_OF_U128 )) + \ 219 : MAX_PERMITTED_DATA_INCREASE + \ 220 : sizeof(ulong)) /* rent_epoch */ 221 : #define FD_BPF_LOADER_DUPLICATE_ACCOUNT_FOOTPRINT (8UL) /* 1 dup byte + 7 bytes for padding */ 222 : 223 : #define FD_BPF_LOADER_INPUT_REGION_FOOTPRINT(account_lock_limit, direct_mapping) \ 224 : (FD_ULONG_ALIGN_UP( (sizeof(ulong) /* acct_cnt */ + \ 225 : account_lock_limit*FD_BPF_LOADER_UNIQUE_ACCOUNT_FOOTPRINT(direct_mapping) + \ 226 : (FD_BPF_INSTR_ACCT_MAX-account_lock_limit)*FD_BPF_LOADER_DUPLICATE_ACCOUNT_FOOTPRINT + \ 227 : sizeof(ulong) /* instr data len */ + \ 228 : FD_TXN_MTU /* No instr data */ + \ 229 : sizeof(fd_pubkey_t)), /* program id */ \ 230 : FD_RUNTIME_EBPF_HOST_ALIGN )) 231 : 232 : 233 : 234 : #define BPF_LOADER_SERIALIZATION_FOOTPRINT (671752960UL) 235 : FD_STATIC_ASSERT( BPF_LOADER_SERIALIZATION_FOOTPRINT==FD_BPF_LOADER_INPUT_REGION_FOOTPRINT(64UL, 0), bpf_loader_serialization_footprint ); 236 : 237 : 238 : /* Some vote instruction types are dynamically sized: 239 : - tower_sync_switch (contains deque of fd_vote_lockout_t) 240 : - tower_sync (contains deque of fd_vote_lockout_t) 241 : - compact_vote_state_update_switch (vector of fd_lockout_offset_t) 242 : - compact_vote_state_update (vector of fd_lockout_offset_t) 243 : - authorize_checked_with_seed (char vector of current_authority_derived_key_seed) 244 : - authorize_with_seed (char vector of current_authority_derived_key_seed) 245 : - update_vote_state_switch (contains deque of fd_vote_lockout_t) 246 : - update_vote_state (contains deque of fd_vote_lockout_t) 247 : - vote_switch (deque of slot numbers) 248 : - vote (deque of slot numbers) 249 : All other vote instruction types are statically sized. 250 : 251 : A loose bound on the max amount of encoded fd_vote_lockout_t 252 : possible is 1232 bytes/(12 bytes/per lockout) = 102 lockouts. So 253 : the worst case bound for the deque of fd_vote_lockout is 254 : 32 + (102 * sizeof(fd_vote_lockout_t)) = 1644 bytes. 255 : 256 : The worst case vector of fd_lockout_offset_t is one where each 257 : encoded element is 2 bytes. This means that we can have 1232/2 = 258 : 616 elements. They are represented as being 16 bytes each, so the 259 : total footprint would be 9856 bytes. 260 : 261 : The deque of slot numbers is a vector of ulong, which is 8 bytes. 262 : So the worst case is 1232 bytes/8 bytes = 154 elements. So, the 263 : total footprint is 32 + (154 * 8 bytes) = 1264 bytes. 264 : 265 : The worst case char vector is 1232 bytes as each element is 1 byte 266 : up to the txn MTU. 267 : 268 : With this, that means that the compact_vote_state_update_switch 269 : can have the largest worst case footprint where the struct is 270 : 104 bytes (sizeof(fd_compact_vote_state_update_switch_t) + the 271 : worst case lockout vector of 616 elements. */ 272 : #define FD_LOCKOUT_OFFSET_FOOTPRINT (9856UL) 273 : #define FD_VOTE_INSTRUCTION_FOOTPRINT (sizeof(fd_vote_instruction_t) + FD_LOCKOUT_OFFSET_FOOTPRINT) 274 : 275 : /* TODO: This is the value as generated by fd_types bincode decoding of 276 : fd_vote_state_versioned_t. This should eventually be replaced. */ 277 : #define FD_VOTE_STATE_VERSIONED_FOOTPRINT (9248UL) 278 : 279 : /* The footprint of a fd_vote_authorized_voters_t struct is defined as a 280 : fd_vote_authorized_voters_t followed by a pool and then a treap. */ 281 : #define FD_AUTHORIZED_VOTERS_ALIGN (128UL) 282 : #define FD_AUTHORIZED_VOTERS_FOOTPRINT (4888UL) 283 : 284 : /* TODO: These footprints are currently overprovisioned due to test 285 : fixtures which currently violate protocol invariants. */ 286 : 287 : /* The footprint of the landed votes is determined by a deque with max 288 : cnt of 31. The footprint is as follows: 289 : alignof(DEQUE_T) == alignof(fd_landed_vote_t) == 8 290 : sizeof(DEQUE_T) == sizeof(fd_landed_vote_t) == 24 291 : return fd_ulong_align_up( fd_ulong_align_up( 32UL, alignof(DEQUE_T) ) + sizeof(DEQUE_T)*max, alignof(DEQUE_(private_t)) ); 292 : return fd_ulong_align_up( fd_ulong_align_up( 32UL, 8UL ) ) + 24UL*31UL, 8UL ); 293 : return fd_ulong_align_up( 32UL + 744, 8UL ) == 776 */ 294 : #define FD_LANDED_VOTES_ALIGN (32UL) 295 : #define FD_LANDED_VOTES_FOOTPRINT (FD_VOTE_STATE_VERSIONED_FOOTPRINT) 296 : 297 : /* The calculation for the landed votes footprint is the same as the 298 : calculation for the landed votes but the sizeof(fd_vote_lockout_t) 299 : is 16 bytes: 300 : return fd_ulong_align_up( 32UL + 16UL * 31UL, 8UL ) == 528UL */ 301 : #define FD_VOTE_LOCKOUTS_ALIGN (32UL) 302 : #define FD_VOTE_LOCKOUTS_FOOTPRINT (FD_VOTE_STATE_VERSIONED_FOOTPRINT) 303 : 304 : static const FD_FN_UNUSED fd_account_meta_t FD_ACCOUNT_META_DEFAULT = {0}; 305 : 306 : FD_PROTOTYPES_END 307 : 308 : #endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_const_h */