LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_runtime_const.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 13 27 48.1 %
Date: 2026-11-30 13:42:38 Functions: 0 0 -

          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 "../../ballet/txn/fd_txn.h" /* for FD_TXN_ACCT_ADDR_MAX */
       5             : #include "../vm/fd_vm_base.h" /* fd_vm_trace_t */
       6             : 
       7             : FD_PROTOTYPES_BEGIN
       8             : 
       9             : /* FD_INSTR_SIGNERS_MAX: The (inclusive) maximum number of distinct
      10             :    signers a single instruction can have.
      11             : 
      12             :    This is the runtime bound, which is larger than the transaction
      13             :    parser bound because during CPI calls PDAs can be promoted to
      14             :    signers. Therefore in the runtime, the effective limit is the
      15             :    amount of distinct accounts the transaction can access. */
      16             : #define FD_INSTR_SIGNERS_MAX FD_TXN_ACCT_ADDR_MAX
      17             : 
      18             : /* FD_RUNTIME_MAX_STAKE_ACCOUNTS bounds cached per-stake reward-calculation
      19             :    results in the runtime stack.  Stake-delegation cache capacity is
      20             :    configured separately. */
      21             : 
      22           0 : #define FD_RUNTIME_MAX_STAKE_ACCOUNTS (2150000UL)
      23             : 
      24             : /* FD_RUNTIME_MAX_STAKE_DELEGATION_DISK_RECORDS is the maximum number
      25             :    of records in each stake-delegation disk tier. */
      26             : 
      27             : #define FD_RUNTIME_MAX_STAKE_DELEGATION_DISK_RECORDS (100000000UL)
      28             : 
      29             : /* The runtime only supports post-validator_admission_ticket banks.  The
      30             :    accumulator can still see one distinct voter per stake account before
      31             :    the final eligible set is reduced to the VAT limit below. */
      32             : 
      33           0 : #define FD_RUNTIME_MAX_STAKED_VOTE_ACCOUNTS (FD_RUNTIME_MAX_STAKE_ACCOUNTS)
      34             : 
      35             : /* Maximum number of vote accounts eligible to receive rewards or
      36             :    meaningfully contribute to consensus after
      37             :    validator_admission_ticket activation. */
      38             : 
      39      208497 : #define FD_RUNTIME_MAX_VAT_VOTE_ACCOUNTS (2000UL)
      40             : 
      41             : /* The maximum number of epoch stakes that are needed to be parsed out
      42             :    from the manifest.  Agave produced snapshots include 5 epoch stakes
      43             :    (MAX_LEADER_SCHEDULE_STAKES), E-3..E+1 for a snapshot in epoch E, and
      44             :    a block footer may carry a finalization cert from any of E-3..E, so
      45             :    all 5 are loaded. */
      46             : 
      47         945 : #define FD_RUNTIME_MANIFEST_EPOCH_STAKES_LEN (5UL)
      48             : 
      49          12 : #define FD_RUNTIME_SLOTS_PER_EPOCH (432000UL)
      50             : 
      51             : /* FD_RUNTIME_ACC_SZ_MAX is the protocol level hardcoded size limit of a
      52             :    Solana account. */
      53             : 
      54    31459116 : #define FD_RUNTIME_ACC_SZ_MAX (10UL<<20) /* 10MiB */
      55             : 
      56             : /* Bound the number of distinct writable accounts that can enter the
      57             :    cost tracker in a 200ms block with raise_block_limits_to_100m, a 50M
      58             :    CU block (FD_SLOT_PARAMS_200MS_MAX_BLOCK_UNITS*100/60).  Clusters
      59             :    with a larger block cost limit (slower slots or [development.bench])
      60             :    are not supported.  A transaction with w writable accounts costs at
      61             :    least 720+300*w CUs and carries at most 64 writable accounts.  Thus W
      62             :    writables need at least ceil(W/64) transactions:
      63             : 
      64             :      300*W + 720*ceil(W/64) <= 50000000
      65             : 
      66             :    The largest solution is 160640: 2510 full 64-account transactions
      67             :    cost 49999200 CUs.  A 160641st writable would cost 50000220 CUs. */
      68             : 
      69           0 : #define FD_RUNTIME_MAX_TXN_ACC_WRITES_PER_SLOT (160640UL)
      70             : 
      71             : /* With 100M stake accounts, ceil(100M/4096)=24415 partitions.
      72             :    Assuming uniform hashing, one partition has
      73             :    X~Binomial(100M,1/24415), with mean 4095.84. So,
      74             :    P(any partition has X>8192) <= 24415*P(X>=8193) ~= 5.75e-686. */
      75             : 
      76           0 : #define FD_RUNTIME_MAX_EPOCH_REWARD_ACC_WRITES_PER_SLOT (8192UL)
      77             : 
      78             : /* FD_RUNTIME_MAX_ACC_WRITES_PER_SLOT defines a reasonable upper bound
      79             :    on the number of unique accounts that can be written to in a single
      80             :    slot.  The worst case can be defined by:
      81             :    1. Worst case number of writable accounts in a slot from worst-case
      82             :       transactions.  This bound comes from the cost tracker: 160640.
      83             :    2. During partitioned epoch rewards.  A reasonable upper bound is
      84             :       8192 accounts per stake partition since the odds of this happening
      85             :       are very very low.
      86             :    3. All of the other account updates that can happen in a slot.  In
      87             :       the standard case this would be the sysvars, the incinerator,
      88             :       and the fee collector (up to 9 accounts, including Alpenglow updates).
      89             :       - Clock
      90             :       - SlotHashes
      91             :       - RecentBlockhashes
      92             :       - SlotHistory
      93             :       - Epoch Rewards
      94             :       - Fee Collector
      95             :       - Incinerator
      96             :       - Alpenclock (Alpenglow)
      97             :       - Leader Vote Account (Alpenglow)
      98             :    4. Alpenglow rewards can touch the full VAT vote set up to 2 times.
      99             :       This happens in the case near the epoch boundary where the reward
     100             :       cert and the finalization cert are in two different epochs. */
     101           0 : #define FD_RUNTIME_MAX_ACC_WRITES_PER_SLOT (FD_RUNTIME_MAX_TXN_ACC_WRITES_PER_SLOT + \
     102           0 :                                             FD_RUNTIME_MAX_EPOCH_REWARD_ACC_WRITES_PER_SLOT + \
     103           0 :                                             9UL + \
     104           0 :                                             (2UL * FD_RUNTIME_MAX_VAT_VOTE_ACCOUNTS))
     105             : 
     106             : /* FD_RUNTIME_ACC_DATA_GROWTH_MAX_PER_TXN is the protocol level hardcoded
     107             :    limit on the total account data growth (sum of resize deltas) across a
     108             :    single transaction.  Defined here (alongside FD_RUNTIME_ACC_SZ_MAX) so
     109             :    low-level size bounds can reference it; fd_borrowed_account.h's
     110             :    MAX_PERMITTED_ACCOUNT_DATA_ALLOCS_PER_TXN and fd_vm_private.h's
     111             :    FD_MAX_ACCOUNT_DATA_GROWTH_PER_TRANSACTION are kept equal to this via
     112             :    static asserts in those headers. */
     113             : 
     114             : #define FD_RUNTIME_ACC_DATA_GROWTH_MAX_PER_TXN (2UL*FD_RUNTIME_ACC_SZ_MAX) /* 20MiB */
     115             : 
     116             : /* FD_RUNTIME_WRITABLE_ACCOUNTS_MAX is the protocol level hardcoded
     117             :    limit of writable accounts per transaction. */
     118             : 
     119             : #define FD_RUNTIME_WRITABLE_ACCOUNTS_MAX (64UL)
     120             : 
     121             : /* Genesis creation times for major Solana clusters */
     122             : 
     123           0 : #define FD_RUNTIME_GENESIS_CREATION_TIME_MAINNET (1584368940UL)
     124           0 : #define FD_RUNTIME_GENESIS_CREATION_TIME_TESTNET (1580834132UL)
     125           0 : #define FD_RUNTIME_GENESIS_CREATION_TIME_DEVNET  (1597081016UL)
     126             : 
     127             : /* FeeStructure constants. Bank is always initialized with
     128             :    `FeeStructure::default()`
     129             :    https://github.com/anza-xyz/agave/blob/v3.1.0-beta.0/runtime/src/bank.rs#L1859
     130             :    https://github.com/anza-xyz/solana-sdk/blob/badc2c40071e6e7f7a8e8452b792b66613c5164c/fee-structure/src/lib.rs#L100 */
     131         828 : #define FD_RUNTIME_FEE_STRUCTURE_LAMPORTS_PER_SIGNATURE (5000UL)
     132             : 
     133             : /* Various constant values used by the runtime. */
     134             : 
     135        1650 : #define MICRO_LAMPORTS_PER_LAMPORT (1000000UL)
     136             : 
     137        2676 : #define SECONDS_PER_YEAR ((double)(365.242199 * 24.0 * 60.0 * 60.0))
     138             : 
     139             : /* https://github.com/anza-xyz/agave/blob/0d34a1a160129c4293dac248e14231e9e773b4ce/program-runtime/src/compute_budget.rs#L139 */
     140             : #define FD_MAX_INSTRUCTION_TRACE_LENGTH (64UL)
     141             : /* https://github.com/anza-xyz/agave/blob/f70ab5598ccd86b216c3928e4397bf4a5b58d723/compute-budget/src/compute_budget.rs#L13 */
     142      842551 : #define FD_MAX_INSTRUCTION_STACK_DEPTH  (5UL)
     143             : 
     144             : 
     145           0 : #define FD_RUNTIME_VM_TRACE_EVENT_MAX (128UL<<20)
     146             : 
     147           0 : #define FD_RUNTIME_VM_TRACE_STATIC_FOOTPRINT (FD_RUNTIME_VM_TRACE_EVENT_MAX + sizeof(fd_vm_trace_t))
     148           0 : #define FD_RUNTIME_VM_TRACE_STATIC_ALIGN     (8UL)
     149             : 
     150             : /* Maximum CPI instruction data size. 10 KiB was chosen to ensure that
     151             :    CPI instructions are not more limited than transaction instructions
     152             :    if the size of transactions is doubled in the future.
     153             :    https://github.com/anza-xyz/agave/blob/v3.1.1/transaction-context/src/lib.rs#L33 */
     154           6 : #define FD_RUNTIME_CPI_MAX_INSTR_DATA_LEN (10240UL)
     155             : 
     156             : /* The bpf loader's serialization footprint (the size of the per-stack-
     157             :    frame input region buffer) is bounded by FD_BPF_LOADER_INPUT_REGION_
     158             :    FOOTPRINT / BPF_LOADER_SERIALIZATION_FOOTPRINT below: account
     159             :    metadata plus the instruction/program-id/pointer-array trailers. */
     160        3084 : #define MAX_PERMITTED_DATA_INCREASE (10240UL) // 10KB
     161        7188 : #define FD_BPF_ALIGN_OF_U128        (8UL)
     162         954 : #define FD_ACCOUNT_REC_ALIGN        (8UL)
     163             : /* https://github.com/anza-xyz/sbpf/blob/v0.12.2/src/ebpf.rs#L37-L38 */
     164             : #define FD_RUNTIME_EBPF_HOST_ALIGN  (16UL)
     165             : 
     166             : /* FD_BPF_LOADER_UNIQUE_ACCOUNT_FOOTPRINT is the serialization footprint
     167             :    of a unique account's metadata. */
     168             : #define FD_BPF_LOADER_UNIQUE_ACCOUNT_FOOTPRINT                                     \
     169             :                                               (1UL                  /* dup byte          */ + \
     170             :                                                sizeof(uchar)        /* is_signer         */ + \
     171             :                                                sizeof(uchar)        /* is_writable       */ + \
     172             :                                                sizeof(uchar)        /* executable        */ + \
     173             :                                                sizeof(uint)         /* original_data_len */ + \
     174             :                                                sizeof(fd_pubkey_t)  /* key               */ + \
     175             :                                                sizeof(fd_pubkey_t)  /* owner             */ + \
     176             :                                                sizeof(ulong)        /* lamports          */ + \
     177             :                                                sizeof(ulong)        /* data len          */ + \
     178             :                                                FD_BPF_ALIGN_OF_U128 /* alignment padding */ + \
     179             :                                                sizeof(ulong))       /* rent_epoch        */
     180             : #define FD_BPF_LOADER_DUPLICATE_ACCOUNT_FOOTPRINT (8UL) /* 1 dup byte + 7 bytes for padding */
     181             : 
     182             : /* FD_SYSVAR_INSTRUCTIONS_FOOTPRINT bounds the worst-case serialized
     183             :    size of the sysvar instructions account.  See
     184             :    fd_sysvar_instructions.c for the format.
     185             : 
     186             :    Worst case size for V0/legacy transactions.  Each bullet is bounded by
     187             :    its own maximum; those maxima compete for the same 1232-byte tx and
     188             :    can't all be reached at once, so the sum is a deliberately loose
     189             :    over-estimate:
     190             :      - 2 bytes header (num_instructions)
     191             :      - instruction offsets: 2 bytes * FD_TXN_INSTR_MAX (64) = 128 bytes
     192             :      - per-instr fixed: 2 (num_accounts) + 32 (program_id) + 2 (data_len)
     193             :        = 36 bytes * FD_TXN_INSTR_MAX (64) = 2304 bytes
     194             :      - account refs: each takes 1 byte (an index) in the tx but serializes
     195             :        to 33 bytes (1 flag + 32-byte pubkey); a 1232-byte tx holds at most
     196             :        ~1094 indices across all its instructions, so 33 * 1094 = 36102 bytes
     197             :      - instr data: bounded by the legacy MTU FD_TXN_MTU_V0 (1232 bytes)
     198             :      - 2 bytes tail (current_instr_idx)
     199             :    Total: 39770 bytes
     200             : 
     201             :    Worst case size for V1 transactions:
     202             :    Instruction start offsets are u16, so an accepted sysvar has every
     203             :    offset <= 65535; a larger offset overflows and is rejected (matching
     204             :    agave).  The worst case is the last instruction starting at 65535:
     205             : 
     206             :      - 65535 bytes (offset of the last instruction)
     207             :      - per-acct ref: 33 bytes * 255 = 8415 bytes
     208             :      - per-instr fixed: 2 (num_accounts) + 32 (program_id) + 2 (data_len)
     209             :        = 36 bytes
     210             :      - instr data: bounded by FD_TXN_MTU (4096 bytes)
     211             :      - 2 bytes tail (current_instr_idx)
     212             :    Total: 78084 bytes, rounded up to 81920. */
     213             : #define FD_SYSVAR_INSTRUCTIONS_FOOTPRINT (81920UL)
     214             : 
     215             : /* FD_BPF_LOADER_INPUT_REGION_FOOTPRINT bounds the bytes a single
     216             :    instruction can serialize into one input region.  An instruction
     217             :    serializes at most account_lock_limit unique accounts; the remaining
     218             :    instruction accounts are duplicates. */
     219             : #define FD_BPF_LOADER_INPUT_REGION_FOOTPRINT(account_lock_limit)                                                                                    \
     220             :                                               (FD_ULONG_ALIGN_UP( (sizeof(ulong)                      /* acct_cnt       */                          +     \
     221             :                                                                    (account_lock_limit)*FD_BPF_LOADER_UNIQUE_ACCOUNT_FOOTPRINT                      +     \
     222             :                                                                    (FD_TXN_INSTR_ACCT_MAX-(account_lock_limit))*FD_BPF_LOADER_DUPLICATE_ACCOUNT_FOOTPRINT + \
     223             :                                                                    sizeof(ulong)                      /* instr data len */                          +     \
     224             :                                                                    FD_RUNTIME_CPI_MAX_INSTR_DATA_LEN  /* instr data  */                             +     \
     225             :                                                                    sizeof(fd_pubkey_t)                /* program id     */                          +     \
     226             :                                                                    (FD_BPF_ALIGN_OF_U128-1UL) +                                                           \
     227             :                                                                    FD_TXN_INSTR_ACCT_MAX*sizeof(ulong) /* direct_account_pointers_in_program_input */),   \
     228             :                                                                    FD_RUNTIME_EBPF_HOST_ALIGN ))
     229             : 
     230             : #define BPF_LOADER_SERIALIZATION_FOOTPRINT (FD_BPF_LOADER_INPUT_REGION_FOOTPRINT(64UL))
     231             : 
     232           6 : #define FD_HARD_FORKS_MAX (64UL)
     233             : 
     234             : FD_PROTOTYPES_END
     235             : 
     236             : #endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_const_h */

Generated by: LCOV version 1.14