LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_runtime_const.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 3 22 13.6 %
Date: 2025-11-23 04:57:59 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 "../leaders/fd_leaders.h"
       5             : #include "../types/fd_types.h"
       6             : #include "../../ballet/txn/fd_txn.h" /* for fd_acct_addr_t */
       7             : 
       8             : FD_PROTOTYPES_BEGIN
       9             : 
      10             : /* All of the variable bounds in the bank should be deteremined by the
      11             :    max number of vote accounts and stake accounts that the system
      12             :    supports. These are not protocol-level bounds, but rather bounds
      13             :    that are used to determine the max amount of memory that various
      14             :    data structures require. */
      15             : 
      16           0 : #define FD_RUNTIME_MAX_VOTE_ACCOUNTS  (40200UL)   /* ~40k vote accounts */
      17             : 
      18       26448 : #define FD_RUNTIME_MAX_STAKE_ACCOUNTS (3000000UL) /* 3M stake accounts */
      19             : 
      20             : #define FD_RUNTIME_SLOTS_PER_EPOCH    (432000UL)  /* 432k slots per epoch */
      21             : 
      22             : /* Maximum amount of writable accounts per transaction
      23             :    https://github.com/anza-xyz/agave/blob/v3.0.8/runtime/src/bank.rs#L2946 */
      24          93 : #define FD_RUNTIME_MAX_WRITABLE_ACCOUNTS_PER_TRANSACTION (64UL)
      25             : 
      26             : /* The initial block id hash is a dummy value for the initial block id
      27             :    as one is not provided in snapshots.  This does not have an
      28             :    equivalent in Agave.
      29             : 
      30             :    TODO: This should be removed in favor of repairing the last shred of
      31             :    the snapshot slot to get the actual block id of the snapshot slot. */
      32             : 
      33           0 : #define FD_RUNTIME_INITIAL_BLOCK_ID (0xF17EDA2CE7B1DUL)
      34             : 
      35             : /* The stake program is now a BPF program which means that there is a
      36             :    variable cost in CUs to execute the stake program.  This is the
      37             :    absolute minimum cost of executing the stake program.
      38             : 
      39             :    FIXME: This is a reasonable estimate based off of BPF withdraw
      40             :    instructions.  The hard bound still needs to be determined. */
      41             : 
      42          15 : #define FD_RUNTIME_MIN_STAKE_INSN_CUS (6000UL)
      43             : 
      44             : /* FD_RUNTIME_ACC_SZ_MAX is the protocol level hardcoded size limit of a
      45             :    Solana account. */
      46             : 
      47           0 : #define FD_RUNTIME_ACC_SZ_MAX (10UL<<20) /* 10MiB */
      48             : 
      49             : /* FD_RUNTIME_WRITABLE_ACCOUNTS_MAX is the protocol level hardcoded
      50             :    limit of writable accounts per transaction. */
      51             : 
      52             : #define FD_RUNTIME_WRITABLE_ACCOUNTS_MAX (64UL)
      53             : 
      54             : /* Genesis creation times for major Solana clusters */
      55             : 
      56           0 : #define FD_RUNTIME_GENESIS_CREATION_TIME_MAINNET (1584368940UL)
      57           0 : #define FD_RUNTIME_GENESIS_CREATION_TIME_TESTNET (1580834132UL)
      58           0 : #define FD_RUNTIME_GENESIS_CREATION_TIME_DEVNET  (1597081016UL)
      59             : 
      60             : 
      61             : /* FeeStructure constants. Bank is always initialized with
      62             :    `FeeStructure::default()`
      63             :    https://github.com/anza-xyz/agave/blob/v3.1.0-beta.0/runtime/src/bank.rs#L1859
      64             :    https://github.com/anza-xyz/solana-sdk/blob/badc2c40071e6e7f7a8e8452b792b66613c5164c/fee-structure/src/lib.rs#L100 */
      65           0 : #define FD_RUNTIME_FEE_STRUCTURE_LAMPORTS_PER_SIGNATURE (5000UL)
      66             : 
      67             : static const fd_cluster_version_t FD_RUNTIME_CLUSTER_VERSION = {
      68             :   .major = 3UL,
      69             :   .minor = 0UL,
      70             :   .patch = 3UL
      71             : };
      72             : 
      73             : /* Various constant values used by the runtime. */
      74             : 
      75           0 : #define MICRO_LAMPORTS_PER_LAMPORT (1000000UL)
      76             : 
      77           0 : #define DEFAULT_HASHES_PER_TICK  (12500)
      78             : #define UPDATED_HASHES_PER_TICK2 (17500)
      79             : #define UPDATED_HASHES_PER_TICK3 (27500)
      80             : #define UPDATED_HASHES_PER_TICK4 (47500)
      81             : #define UPDATED_HASHES_PER_TICK5 (57500)
      82             : #define UPDATED_HASHES_PER_TICK6 (62500)
      83             : 
      84           0 : #define SECONDS_PER_YEAR ((double)(365.242199 * 24.0 * 60.0 * 60.0))
      85             : 
      86             : /* https://github.com/anza-xyz/agave/blob/0d34a1a160129c4293dac248e14231e9e773b4ce/program-runtime/src/compute_budget.rs#L139 */
      87             : #define FD_MAX_INSTRUCTION_TRACE_LENGTH (64UL)
      88             : /* https://github.com/anza-xyz/agave/blob/f70ab5598ccd86b216c3928e4397bf4a5b58d723/compute-budget/src/compute_budget.rs#L13 */
      89           0 : #define FD_MAX_INSTRUCTION_STACK_DEPTH  (5UL)
      90             : 
      91             : 
      92           0 : #define FD_RUNTIME_VM_TRACE_EVENT_MAX      (128UL<<20)
      93           0 : #define FD_RUNTIME_VM_TRACE_EVENT_DATA_MAX (2048UL)
      94             : 
      95           0 : #define FD_RUNTIME_VM_TRACE_STATIC_FOOTPRINT (FD_RUNTIME_VM_TRACE_EVENT_MAX + sizeof(fd_vm_trace_t))
      96           0 : #define FD_RUNTIME_VM_TRACE_STATIC_ALIGN     (8UL)
      97             : 
      98             : 
      99             : /* The bpf loader's serialization footprint is bounded in the worst case
     100             :    by 64 unique writable accounts which are each 10MiB in size (bounded
     101             :    by the amount of transaction accounts).  We can also have up to
     102             :    FD_INSTR_ACCT_MAX (256) referenced accounts in an instruction.
     103             : 
     104             :    - 8 bytes for the account count
     105             :    For each account:
     106             :      If duplicated:
     107             :        - 8 bytes for each duplicated account
     108             :     If not duplicated:
     109             :      - header for each unique account (96 bytes)
     110             :        - 1 account idx byte
     111             :        - 1 is_signer byte
     112             :        - 1 is_writable byte
     113             :        - 1 executable byte
     114             :        - 4 bytes for the original data length
     115             :        - 32 bytes for the key
     116             :        - 32 bytes for the owner
     117             :        - 8 bytes for the lamports
     118             :        - 8 bytes for the data length
     119             :        - 8 bytes for the rent epoch
     120             :      - 10MiB for the data (10485760 bytes)
     121             :      - 10240 bytes for resizing the data
     122             :      - 0 padding bytes because this is already 8 byte aligned
     123             :    - 8 bytes for instruction data length
     124             :    - 1232 bytes for the instruction data (TXN_MTU)
     125             :    - 32 bytes for the program id
     126             : 
     127             :   So the total footprint is:
     128             :   8 header bytes +
     129             :   192 duplicate accounts (256 instr accounts - 64 unique accounts) * 8 bytes     = 1536      duplicate account bytes +
     130             :   64 unique accounts * (96 header bytes + 10485760 bytes + 10240 resizing bytes) = 671750144 unique account bytes +
     131             :   8 + 1232 + 32                                                                  = 1272 bytes trailer bytes + program id = 671751416 bytes
     132             :   Total footprint: 671752960 bytes
     133             : 
     134             :   This is a reasonably tight-ish upper bound on the input region
     135             :   footprint for a single instruction at a single stack depth.  In
     136             :   reality the footprint would be slightly smaller because the
     137             :   instruction data can't be equal to the transaction MTU.
     138             :  */
     139           0 : #define MAX_PERMITTED_DATA_INCREASE (10240UL) // 10KB
     140           0 : #define FD_BPF_ALIGN_OF_U128        (8UL)
     141           0 : #define FD_ACCOUNT_REC_ALIGN        (8UL)
     142             : /* https://github.com/anza-xyz/sbpf/blob/v0.12.2/src/ebpf.rs#L37-L38 */
     143             : #define FD_RUNTIME_EBPF_HOST_ALIGN  (16UL)
     144           0 : #define FD_INSTR_ACCT_MAX            (256)
     145             : 
     146             : 
     147             : #define FD_BPF_LOADER_UNIQUE_ACCOUNT_FOOTPRINT(direct_mapping)                                                                                              \
     148             :                                               (1UL                         /* dup byte          */                                                        + \
     149             :                                                sizeof(uchar)               /* is_signer         */                                                        + \
     150             :                                                sizeof(uchar)               /* is_writable       */                                                        + \
     151             :                                                sizeof(uchar)               /* executable        */                                                        + \
     152             :                                                sizeof(uint)                /* original_data_len */                                                        + \
     153             :                                                sizeof(fd_pubkey_t)         /* key               */                                                        + \
     154             :                                                sizeof(fd_pubkey_t)         /* owner             */                                                        + \
     155             :                                                sizeof(ulong)               /* lamports          */                                                        + \
     156             :                                                sizeof(ulong)               /* data len          */                                                        + \
     157             :                                                (direct_mapping ? FD_BPF_ALIGN_OF_U128 : FD_ULONG_ALIGN_UP( FD_RUNTIME_ACC_SZ_MAX, FD_BPF_ALIGN_OF_U128 )) + \
     158             :                                                MAX_PERMITTED_DATA_INCREASE                                                                                + \
     159             :                                                sizeof(ulong))              /* rent_epoch        */
     160             : #define FD_BPF_LOADER_DUPLICATE_ACCOUNT_FOOTPRINT (8UL) /* 1 dup byte + 7 bytes for padding */
     161             : 
     162             : #define FD_BPF_LOADER_INPUT_REGION_FOOTPRINT(account_lock_limit, direct_mapping)                                                                      \
     163             :                                               (FD_ULONG_ALIGN_UP( (sizeof(ulong)         /* acct_cnt       */                                       + \
     164             :                                                                    account_lock_limit*FD_BPF_LOADER_UNIQUE_ACCOUNT_FOOTPRINT(direct_mapping)        + \
     165             :                                                                    (FD_INSTR_ACCT_MAX-account_lock_limit)*FD_BPF_LOADER_DUPLICATE_ACCOUNT_FOOTPRINT + \
     166             :                                                                    sizeof(ulong)         /* instr data len */                                       + \
     167             :                                                                    FD_TXN_MTU            /* No instr data  */                                       + \
     168             :                                                                    sizeof(fd_pubkey_t)), /* program id     */                                          \
     169             :                                                                    FD_RUNTIME_EBPF_HOST_ALIGN ))
     170             : 
     171             : 
     172             : 
     173             : #define BPF_LOADER_SERIALIZATION_FOOTPRINT (671752960UL)
     174             : FD_STATIC_ASSERT( BPF_LOADER_SERIALIZATION_FOOTPRINT==FD_BPF_LOADER_INPUT_REGION_FOOTPRINT(64UL, 0), bpf_loader_serialization_footprint );
     175             : 
     176             : 
     177             : /* Some vote instruction types are dynamically sized:
     178             :     - tower_sync_switch                (contains deque of fd_vote_lockout_t)
     179             :     - tower_sync                       (contains deque of fd_vote_lockout_t)
     180             :     - compact_vote_state_update_switch (vector of fd_lockout_offset_t)
     181             :     - compact_vote_state_update        (vector of fd_lockout_offset_t)
     182             :     - authorize_checked_with_seed      (char vector of current_authority_derived_key_seed)
     183             :     - authorize_with_seed              (char vector of current_authority_derived_key_seed)
     184             :     - update_vote_state_switch         (contains deque of fd_vote_lockout_t)
     185             :     - update_vote_state                (contains deque of fd_vote_lockout_t)
     186             :     - vote_switch                      (deque of slot numbers)
     187             :     - vote                             (deque of slot numbers)
     188             :    All other vote instruction types are statically sized.
     189             : 
     190             :    A loose bound on the max amount of encoded fd_vote_lockout_t
     191             :    possible is 1232 bytes/(12 bytes/per lockout) = 102 lockouts.  So
     192             :    the worst case bound for the deque of fd_vote_lockout is
     193             :    32 + (102 * sizeof(fd_vote_lockout_t)) = 1644 bytes.
     194             : 
     195             :    The worst case vector of fd_lockout_offset_t is one where each
     196             :    encoded element is 2 bytes.  This means that we can have 1232/2 =
     197             :    616 elements.  They are represented as being 16 bytes each, so the
     198             :    total footprint would be 9856 bytes.
     199             : 
     200             :    The deque of slot numbers is a vector of ulong, which is 8 bytes.
     201             :    So the worst case is 1232 bytes/8 bytes = 154 elements.  So, the
     202             :    total footprint is 32 + (154 * 8 bytes) = 1264 bytes.
     203             : 
     204             :    The worst case char vector is 1232 bytes as each element is 1 byte
     205             :    up to the txn MTU.
     206             : 
     207             :    With this, that means that the compact_vote_state_update_switch
     208             :    can have the largest worst case footprint where the struct is
     209             :    104 bytes (sizeof(fd_compact_vote_state_update_switch_t) + the
     210             :    worst case lockout vector of 616 elements. */
     211             : #define FD_LOCKOUT_OFFSET_FOOTPRINT   (9856UL)
     212             : #define FD_VOTE_INSTRUCTION_FOOTPRINT (sizeof(fd_vote_instruction_t) + FD_LOCKOUT_OFFSET_FOOTPRINT)
     213             : 
     214             : /* TODO: This is the value as generated by fd_types bincode decoding of
     215             :    fd_vote_state_versioned_t.  This should eventually be replaced. */
     216             : #define FD_VOTE_STATE_VERSIONED_FOOTPRINT (9248UL)
     217             : 
     218             : /* The footprint of a fd_vote_authorized_voters_t struct is defined as a
     219             :    fd_vote_authorized_voters_t followed by a pool and then a treap. */
     220             : #define FD_AUTHORIZED_VOTERS_ALIGN     (128UL)
     221             : #define FD_AUTHORIZED_VOTERS_FOOTPRINT (4888UL)
     222             : 
     223             : /* TODO: These footprints are currently overprovisioned due to test
     224             :    fixtures which currently violate protocol invariants. */
     225             : 
     226             : /* The footprint of the landed votes is determined by a deque with max
     227             :    cnt of 31.  The footprint is as follows:
     228             :    alignof(DEQUE_T) == alignof(fd_landed_vote_t) == 8
     229             :    sizeof(DEQUE_T)  == sizeof(fd_landed_vote_t)  == 24
     230             :    return fd_ulong_align_up( fd_ulong_align_up( 32UL, alignof(DEQUE_T) ) + sizeof(DEQUE_T)*max, alignof(DEQUE_(private_t)) );
     231             :    return fd_ulong_align_up( fd_ulong_align_up( 32UL, 8UL ) )            + 24UL*31UL, 8UL );
     232             :    return fd_ulong_align_up( 32UL + 744, 8UL ) == 776 */
     233             : #define FD_LANDED_VOTES_ALIGN     (32UL)
     234             : #define FD_LANDED_VOTES_FOOTPRINT (FD_VOTE_STATE_VERSIONED_FOOTPRINT)
     235             : 
     236             : /* The calculation for the landed votes footprint is the same as the
     237             :    calculation for the landed votes but the sizeof(fd_vote_lockout_t)
     238             :    is 16 bytes:
     239             :    return fd_ulong_align_up( 32UL + 16UL * 31UL, 8UL ) == 528UL */
     240             : #define FD_VOTE_LOCKOUTS_ALIGN     (32UL)
     241             : #define FD_VOTE_LOCKOUTS_FOOTPRINT (FD_VOTE_STATE_VERSIONED_FOOTPRINT)
     242             : 
     243             : FD_PROTOTYPES_END
     244             : 
     245             : #endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_const_h */

Generated by: LCOV version 1.14