LCOV - code coverage report
Current view: top level - disco/pack - fd_pack_cost.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 64 81 79.0 %
Date: 2026-02-28 05:18:01 Functions: 2 121 1.7 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_disco_pack_fd_pack_cost_h
       2             : #define HEADER_fd_src_disco_pack_fd_pack_cost_h
       3             : 
       4             : #include "../../ballet/fd_ballet_base.h"
       5             : #include "fd_compute_budget_program.h"
       6             : #include "../../flamenco/runtime/fd_system_ids_pp.h"
       7             : #include "../../ballet/txn/fd_txn.h"
       8             : 
       9             : /* The functions in this header implement the transaction cost model
      10             :    that is soon to be part of consensus.
      11             :    The cost model consists of several components:
      12             :      * per-signature cost: The costs associated with transaction
      13             :        signatures + signatures from precompiles (ED25519 + SECP256*)
      14             :      * per-write-lock cost: cost assiciated with aquiring write locks
      15             :        for writable accounts listed in the transaction.
      16             :      * instruction data length cost: The fixed cost for each instruction
      17             :        data byte in the transaction payload.
      18             :      * built-in execution cost: The fixed cost associated with "builtin"
      19             :        instructions. "What are builtins" is defined here:
      20             :        https://github.com/anza-xyz/agave/blob/1baa4033e0d2d4175373f07b73ddda2f3cc0a8d6/builtins-default-costs/src/lib.rs#L120-L200
      21             :        After SIMD 170, all builtins have a fixed cost of 3000 cus.
      22             :      * BPF execution cost: The costs assosiated with any instruction
      23             :        that is not a builtin.  This value comes from the VM after
      24             :        transaction execution.
      25             :      * loaded accounts data cost: Costs associated with all the account
      26             :        data loaded from the chain.  This value is known in the
      27             :        transaction loading stage, after accounts data is loaded.
      28             :    These are all summed to determine the total transaction cost. */
      29             : 
      30             : /* Simple votes: before the remove_simple_vote_from_cost_model
      31             :    feature, simple votes had a fixed cost instead of going through the
      32             :    full cost model.
      33             : 
      34             :    To avoid feature-gating pack code, pack uses a tight upper bound,
      35             :    FD_PACK_SIMPLE_VOTE_COST, to estimate the cost of simple votes.
      36             : 
      37             :    Since this is higher than the static cost used before
      38             :    remove_simple_vote_from_cost_model is activated, this can be
      39             :    used both before and after the feature is activated.
      40             : 
      41             :    Once remove_simple_vote_from_cost_model is activated, the vote cu
      42             :    limit is no longer part of consensus, so we are free to use a
      43             :    different simple vote classifier than Agave. */
      44             : 
      45             : /* To compute the built-in cost, we need to check a table. The table
      46             :    is known ahead of time though, so we can build a perfect hash
      47             :    table for performance.
      48             :    The values of the table are based on https://github.com/
      49             :    solana-labs/solana/blob/9fb105c801e2999a24f0773443d6164e30c9ff0c/
      50             :    runtime/src/block_cost_limits.rs#L34-L47 . */
      51             : 
      52             : 
      53             : 
      54             : struct __attribute__((aligned(32))) fd_pack_builtin_prog_cost {
      55             :   uchar program_id[32];
      56             :   ulong cost_per_instr;
      57             : };
      58             : typedef struct fd_pack_builtin_prog_cost fd_pack_builtin_prog_cost_t;
      59             : 
      60             : #define MAP_PERFECT_NAME      fd_pack_builtin
      61             : #define MAP_PERFECT_LG_TBL_SZ 4
      62             : #define MAP_PERFECT_T         fd_pack_builtin_prog_cost_t
      63             : #define MAP_PERFECT_HASH_C    478U
      64             : #define MAP_PERFECT_KEY       program_id
      65             : #define MAP_PERFECT_KEY_T     fd_acct_addr_t const *
      66             : #define MAP_PERFECT_ZERO_KEY  (0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0)
      67             : #define MAP_PERFECT_COMPLEX_KEY 1
      68     9681066 : #define MAP_PERFECT_KEYS_EQUAL(k1,k2) (!memcmp( (k1), (k2), 32UL ))
      69             : 
      70    64004478 : #define PERFECT_HASH( u ) (((478U*(u))>>28)&0xFU)
      71             : 
      72             : #define MAP_PERFECT_HASH_PP( a00,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11,a12,a13,a14,a15, \
      73             :                              a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31) \
      74             :                                           PERFECT_HASH( (a08 | (a09<<8) | (a10<<16) | (a11<<24)) )
      75     9681066 : #define MAP_PERFECT_HASH_R( ptr ) PERFECT_HASH( fd_uint_load_4( (uchar const *)ptr->b + 8UL ) )
      76             : 
      77             : 
      78             : /* The cost model estimates 200,000 CUs for builtin programs that were migrated to BPF */
      79             : #define MAP_PERFECT_0  ( SYS_PROG_ID             ), .cost_per_instr= FD_COMPUTE_BUDGET_MAX_BUILTIN_CU_LIMIT
      80             : #define MAP_PERFECT_1  ( COMPUTE_BUDGET_PROG_ID  ), .cost_per_instr= FD_COMPUTE_BUDGET_MAX_BUILTIN_CU_LIMIT
      81             : #define MAP_PERFECT_2  ( BPF_UPGRADEABLE_PROG_ID ), .cost_per_instr= FD_COMPUTE_BUDGET_MAX_BUILTIN_CU_LIMIT
      82             : #define MAP_PERFECT_3  ( BPF_LOADER_1_PROG_ID    ), .cost_per_instr= FD_COMPUTE_BUDGET_MAX_BUILTIN_CU_LIMIT
      83             : #define MAP_PERFECT_4  ( BPF_LOADER_2_PROG_ID    ), .cost_per_instr= FD_COMPUTE_BUDGET_MAX_BUILTIN_CU_LIMIT
      84             : #define MAP_PERFECT_5  ( LOADER_V4_PROG_ID       ), .cost_per_instr= FD_COMPUTE_BUDGET_MAX_BUILTIN_CU_LIMIT
      85             : #define MAP_PERFECT_6  ( KECCAK_SECP_PROG_ID     ), .cost_per_instr= FD_COMPUTE_BUDGET_MAX_BUILTIN_CU_LIMIT
      86             : #define MAP_PERFECT_7  ( ED25519_SV_PROG_ID      ), .cost_per_instr= FD_COMPUTE_BUDGET_MAX_BUILTIN_CU_LIMIT
      87             : #define MAP_PERFECT_8  ( SECP256R1_PROG_ID       ), .cost_per_instr= FD_COMPUTE_BUDGET_MAX_BUILTIN_CU_LIMIT
      88             : 
      89             : #include "../../util/tmpl/fd_map_perfect.c"
      90             : 
      91             : /* Redefine it so we can use it below */
      92             : #define MAP_PERFECT_HASH_PP( a00,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11,a12,a13,a14,a15, \
      93             :                              a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31) \
      94    54323412 :                                           PERFECT_HASH( ((uint)a08 | ((uint)a09<<8) | ((uint)a10<<16) | ((uint)a11<<24)) )
      95             : 
      96    13573926 : #define FD_PACK_COST_PER_SIGNATURE                    (  720UL)
      97          78 : #define FD_PACK_COST_PER_ED25519_SIGNATURE            ( 2400UL)
      98          78 : #define FD_PACK_COST_PER_SECP256K1_SIGNATURE          ( 6690UL)
      99          18 : #define FD_PACK_COST_PER_SECP256R1_SIGNATURE          ( 4800UL)
     100    13574784 : #define FD_PACK_COST_PER_WRITABLE_ACCT                (  300UL)
     101    13573491 : #define FD_PACK_INV_COST_PER_INSTR_DATA_BYTE          (    4UL)
     102             : 
     103             : /* The computation here is similar to the computation for the max
     104             :    fd_txn_t size.  There are various things a transaction can include
     105             :    that consume CUs, and they also consume some bytes of payload.  It
     106             :    then becomes an integer linear programming problem.  First, the best
     107             :    use of bytes is to include a compute budget program instruction that
     108             :    requests 1.4M CUs.  That also requires the invocation of another
     109             :    non-builtin program, consuming 3 bytes of payload.  In total to do
     110             :    this, we need 2 pubkey and 11 bytes of instruction payload.  This is
     111             :    >18,000 CUs per byte, which is obviously the best move.
     112             : 
     113             :    From there, we can also invoke built-in programs with no accounts and
     114             :    no instruction data, which also consumes 3 bytes of payload.  The
     115             :    most expensive built-in is the BPF upgradeable loader.  We're limited
     116             :    to 64 instructions, so we can only consume it at most 62 times.  This
     117             :    is about 675 CUs per byte.
     118             : 
     119             :    We've maxed out the instruction limit, so we can only continue to
     120             :    increase the cost by adding writable accounts or writable signer
     121             :    accounts.  Writable signers consume 96 bytes use 1020 CUs.  Writable
     122             :    non-signers consume 32 bytes and use 300 CUs.  That's 10.6 CUs/byte
     123             :    and 9.4 CUs/byte, respectively, so in general, writable signers are
     124             :    more efficient and we want to add as many as we can.  We also need at
     125             :    least one writable signer to be the fee payer, and, although it's
     126             :    unusual, there's actually no reason the non-builtin program can't be
     127             :    a writable signer too.
     128             : 
     129             :    Finally, with any bytes that remain, we can add them to one of the
     130             :    instruction datas for 0.25 CUs/byte.
     131             : 
     132             :    Note that by default, 64MiB of data are assumed for the loaded
     133             :    accounts data size cost. This corresponds (currently) to 16384 CUs.
     134             : 
     135             :    This gives a transaction that looks like
     136             :      Field                   bytes consumed               CUs used
     137             :      sig cnt                      1                             0
     138             :      fee payer sig               64                           720
     139             :      8 other signatures         512                         5,670
     140             :      fixed header (no ALTs)       3                             0
     141             :      acct addr cnt                1                             0
     142             :      fee payer pubkey            32                           300
     143             :      8 writable pubkeys         256                         2,400
     144             :      2 writable non-signers      64                           600
     145             :      CBP, BPF upg loader         64                             0
     146             :      Recent blockhash            32                             0
     147             :      Instruction count            1                             0
     148             :      Compute budget program ix    8                           151.25
     149             :      62 dummy BPF upg ixs       186                       146,940
     150             :      1 dummy non-builtin ix       8                     1,400,001.25
     151             :      loaded accts data cost       0                         16384
     152             :    + ---------------------------------------------------------------
     153             :                               1,232                     1,573,166
     154             : 
     155             :    One of the main take-aways from this is that the cost of a
     156             :    transaction easily fits in a uint. */
     157             : #define FD_PACK_MAX_TXN_COST (1573166UL)
     158             : FD_STATIC_ASSERT( FD_PACK_MAX_TXN_COST < (ulong)UINT_MAX, fd_pack_max_cost );
     159             : 
     160             : /* Every transaction has at least a fee payer, a writable signer. */
     161             : #define FD_PACK_MIN_TXN_COST (FD_PACK_COST_PER_SIGNATURE+FD_PACK_COST_PER_WRITABLE_ACCT)
     162             : 
     163             : /* NOTE: THE FOLLOWING CONSTANTS ARE CONSENSUS CRITICAL AND CANNOT BE
     164             :    CHANGED WITHOUT COORDINATING WITH ANZA. */
     165             : 
     166             : /* These are bounds on known limits. Upper bound values are used to
     167             :    calculate memory footprints while lower bounds are used for
     168             :    initializing consensus-dependent logic and invariant checking.  As a
     169             :    leader, it is OK to produce blocks using limits smaller than the
     170             :    active on-chain limits. Replay should always use the correct
     171             :    chain-derived limits.
     172             : 
     173             :    The actual limits used by pack may be updated dynamically to some
     174             :    in-bounds value. If there is an anticipated feature activation that
     175             :    changes these limits, the upper bound should be the largest
     176             :    anticipated value while the lower bound should be the current active
     177             :    limit. For Frankendancer, the actual value used for consensus will be
     178             :    retrieved from Agave at runtime. */
     179           0 : #define FD_PACK_MAX_COST_PER_BLOCK_LOWER_BOUND      (48000000UL)
     180           0 : #define FD_PACK_MAX_VOTE_COST_PER_BLOCK_LOWER_BOUND (36000000UL)
     181           0 : #define FD_PACK_MAX_WRITE_COST_PER_ACCT_LOWER_BOUND (12000000UL)
     182             : 
     183           0 : #define FD_PACK_MAX_COST_PER_BLOCK_UPPER_BOUND      (100000000UL) /* simd 0286 */
     184           0 : #define FD_PACK_MAX_VOTE_COST_PER_BLOCK_UPPER_BOUND ( 36000000UL)
     185           0 : #define FD_PACK_MAX_WRITE_COST_PER_ACCT_UPPER_BOUND ( FD_PACK_MAX_COST_PER_BLOCK_UPPER_BOUND * 4UL / 10UL ) /* simd 0306 */
     186             : 
     187             : FD_STATIC_ASSERT( FD_MAX_TXN_PER_SLOT_CU==(FD_PACK_MAX_COST_PER_BLOCK_UPPER_BOUND/FD_PACK_MIN_TXN_COST), max_txn_per_slot_cu );
     188             : 
     189             : /* The txncache should at most store one entry for each transaction, so
     190             :    you would expect this value to be just FD_MAX_TXN_PER_SLOT.  But
     191             :    there's a minor complication ... Agave inserts each transaction into
     192             :    the status cache twice, once with the signature as the key, and
     193             :    once with the message hash as the key.  This is to support querying
     194             :    transactions by either signature or message hash.  We load snapshots
     195             :    from Agave nodes which serve both entries, and there is no way to
     196             :    filter out the by signature entries which are useless to us, so
     197             :    initially the status cache needs twice as much space. */
     198           0 : #define FD_PACK_MAX_TXNCACHE_TXN_PER_SLOT (2UL*FD_MAX_TXN_PER_SLOT)
     199             : 
     200             : 
     201             : /* https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_processor.rs#L55 */
     202             : 
     203        7437 : #define FD_PACK_VOTE_DEFAULT_COMPUTE_UNITS (2100UL)
     204             : 
     205             : /* SIMD-0387: BLS proof-of-possession verification cost charged by the
     206             :    vote program for authorize instructions.
     207             : 
     208             :    https://github.com/anza-xyz/agave/blob/v4.0.0-alpha.0/programs/vote/src/vote_processor.rs#L83 */
     209        7437 : #define FD_PACK_BLS_PROOF_OF_POSSESSION_VERIFICATION_COMPUTE_UNITS (34500UL)
     210             : 
     211             : /* Upper bound on execution CUs used by vote instructions.
     212             : 
     213             :    The only vote instructions which use more than the default cost are
     214             :    the authorize instruction, which also charge the BLS
     215             :    proof-of-possession verification cost.
     216             : 
     217             :    IMPORTANT: if the vote program starts charging more CUs for any
     218             :    instructions, this constant will need to be updated.
     219             :  */
     220        7437 : #define FD_PACK_VOTE_MAX_COMPUTE_UNITS (FD_PACK_VOTE_DEFAULT_COMPUTE_UNITS + FD_PACK_BLS_PROOF_OF_POSSESSION_VERIFICATION_COMPUTE_UNITS)
     221             : 
     222             : /* Max loaded account data size: FD_COMPUTE_BUDGET_MAX_LOADED_DATA_SZ
     223             : 
     224             :    Cost: ceil( FD_COMPUTE_BUDGET_MAX_LOADED_DATA_SZ / 32,768 ) * 8
     225             :        = ceil( 67,108,864 / 32,768 ) * 8
     226             :        = 2,048 * 8
     227             :        = 16,384 CUs */
     228        7437 : #define FD_PACK_VOTE_DEFAULT_LOADED_ACCOUNTS_DATA_COST (16384UL)
     229             : 
     230             : /* Maximum instruction data cost for a simple vote transaction:
     231             :    - 1 signature
     232             :    - 2 transaction accounts
     233             :    - 0 instruction accounts
     234             : 
     235             :    Which results in a fixed overhead of:
     236             :    - Signature count:           1
     237             :    - 1 signature:               64
     238             :    - Message header:            3
     239             :    - Account count:             1
     240             :    - 2 account entries:         64
     241             :    - Recent blockhash:          32
     242             :    - Instruction count:         1
     243             :    - program_id:                1
     244             :    - Instruction account count: 1
     245             :    - Instruction data length:   1
     246             :    Total:                       169 bytes
     247             : 
     248             :    Leaving (FD_TXN_MTU - 169) = 1063 bytes for the instruction data.
     249             :    This results in a cost of 1063 / 4 = 265 CUs.
     250             :     */
     251             : #define FD_PACK_SIMPLE_VOTE_MAX_INSTR_DATA_COST (265UL)
     252             : 
     253             : /* A simple vote transaction is any transaction that satisfies the
     254             :    following conditions:
     255             :    - Has 1 or 2 signatures
     256             :    - Is a legacy transaction
     257             :    - Has exactly one instruction
     258             :    - Must invoke the vote program
     259             : 
     260             :    Therefore the worst-case most expensive simple vote transaction has:
     261             :    - 2 signatures
     262             :    - 35 writable accounts (see FD_TXN_ACCT_ADDR_MAX)
     263             :    - The maximum amount of compute units for a vote program instruction
     264             :    - 1 instruction of the maximum instruction data size
     265             :    - The maximum amount of loaded accounts data
     266             :    = 65,189 CUs
     267             : */
     268             : static const ulong FD_PACK_SIMPLE_VOTE_COST = ( 2UL*FD_PACK_COST_PER_SIGNATURE                 + /* 1,440  */
     269             :                                                 35UL*FD_PACK_COST_PER_WRITABLE_ACCT            + /* 10,500 */
     270             :                                                 FD_PACK_VOTE_MAX_COMPUTE_UNITS                 + /* 36,600 */
     271             :                                                 FD_PACK_VOTE_DEFAULT_LOADED_ACCOUNTS_DATA_COST + /* 16,384 */
     272             :                                                 FD_PACK_SIMPLE_VOTE_MAX_INSTR_DATA_COST );       /* 265    */
     273             : 
     274             : #undef FD_PACK_SIMPLE_VOTE_MAX_INSTR_DATA_COST
     275             : 
     276             : /* Computes the total cost and a few related properties for the
     277             :    specified transaction.  On success, returns the cost, which is in
     278             :    [1020, FD_PACK_MAX_TXN_COST] and sets or clears the
     279             :    FD_TXN_P_FLAG_IS_SIMPLE_VOTE bit of the value pointed to by flags to
     280             :    indicate whether the transaction is a simple vote or not.
     281             : 
     282             :    Additionally:
     283             :    If opt_execution_cost is non-null, on success it will contain the
     284             :    execution cost (BPF execution cost + built-in execution cost).  This
     285             :    value is in [0, the returned value).
     286             :    If opt_fee is non-null, on success it will contain the priority fee,
     287             :    measured in lamports (i.e. the part of the fee that excludes the
     288             :    per-signature fee). This value is in [0, ULONG_MAX].
     289             :    If opt_precompile_sig_cnt is non-null, on success it will contain the
     290             :    total number of signatures in precompile instructions, namely Keccak
     291             :    and Ed25519 signature verification programs.  This value is in [0,
     292             :    256*64].  Note that this does not do full parsing of the precompile
     293             :    instruction, and it may be malformed.  If
     294             :    opt_loaded_accounts_data_cost is non-null, on success it will contain
     295             :    the total requested cost due to loaded accounts data.  This value is
     296             :    in [0, the returned value).
     297             : 
     298             :    On failure, returns 0 and does not modify the value pointed to by
     299             :    flags, opt_execution_cost, opt_fee, or opt_precompile_sig_cnt. */
     300             : static inline ulong
     301             : fd_pack_compute_cost( fd_txn_t const * txn,
     302             :                       uchar    const * payload,
     303             :                       uint           * flags,
     304             :                       ulong          * opt_execution_cost,
     305             :                       ulong          * opt_fee,
     306             :                       ulong          * opt_precompile_sig_cnt,
     307    13580853 :                       ulong          * opt_loaded_accounts_data_cost ) {
     308             : 
     309    54323412 : #define ROW(x) fd_pack_builtin_tbl + MAP_PERFECT_HASH_PP( x )
     310    13580853 :   fd_pack_builtin_prog_cost_t const * compute_budget_row     = ROW( COMPUTE_BUDGET_PROG_ID );
     311    13580853 :   fd_pack_builtin_prog_cost_t const * ed25519_precompile_row = ROW( ED25519_SV_PROG_ID     );
     312    13580853 :   fd_pack_builtin_prog_cost_t const * secp256k1_precomp_row  = ROW( KECCAK_SECP_PROG_ID    );
     313    13580853 :   fd_pack_builtin_prog_cost_t const * secp256r1_precomp_row  = ROW( SECP256R1_PROG_ID      );
     314    13580853 : #undef ROW
     315             : 
     316             :   /* special handling for simple votes */
     317    13580853 :   if( FD_UNLIKELY( fd_txn_is_simple_vote_transaction( txn, payload ) ) ) {
     318             : #if DETAILED_LOGGING
     319             :     FD_BASE58_ENCODE_64_BYTES( (const uchar *)fd_txn_get_signatures(txn, payload), signature_cstr );
     320             :     FD_LOG_NOTICE(( "TXN SIMPLE_VOTE signature[%s] total_cost[%lu]", signature_cstr, FD_PACK_SIMPLE_VOTE_COST));
     321             : #endif
     322        7437 :     *flags |= FD_TXN_P_FLAGS_IS_SIMPLE_VOTE;
     323        7437 :     fd_ulong_store_if( !!opt_execution_cost,            opt_execution_cost,            FD_PACK_VOTE_MAX_COMPUTE_UNITS                 );
     324        7437 :     fd_ulong_store_if( !!opt_fee,                       opt_fee,                       0                                              );
     325        7437 :     fd_ulong_store_if( !!opt_precompile_sig_cnt,        opt_precompile_sig_cnt,        0                                              );
     326        7437 :     fd_ulong_store_if( !!opt_loaded_accounts_data_cost, opt_loaded_accounts_data_cost, FD_PACK_VOTE_DEFAULT_LOADED_ACCOUNTS_DATA_COST );
     327        7437 :     return FD_PACK_SIMPLE_VOTE_COST;
     328        7437 :   }
     329             : 
     330    13573416 :   *flags &= ~FD_TXN_P_FLAGS_IS_SIMPLE_VOTE;
     331             : 
     332             :   /* We need to be mindful of overflow here, but it's not terrible.
     333             :      signature_cost < FD_TXN_ACCT_ADDR_MAX*720 + FD_TXN_INSTR_MAX * UCHAR_MAX * 6690,
     334             :      writable_cost  <= FD_TXN_ACCT_ADDR_MAX*300 */
     335    13573416 :   ulong signature_cnt = fd_txn_account_cnt( txn, FD_TXN_ACCT_CAT_SIGNER );
     336    13573416 :   ulong signature_cost = FD_PACK_COST_PER_SIGNATURE      * signature_cnt;
     337    13573416 :   ulong writable_cost  = FD_PACK_COST_PER_WRITABLE_ACCT  * fd_txn_account_cnt( txn, FD_TXN_ACCT_CAT_WRITABLE );
     338             : 
     339    13573416 :   ulong instr_data_sz      = 0UL; /* < FD_TPU_MTU */
     340    13573416 :   ulong non_builtin_cnt    = 0UL; /* <= FD_TXN_INSTR_MAX */
     341    13573416 :   ulong precompile_sig_cnt = 0UL; /* <= FD_TXN_INSTR_MAX * UCHAR_MAX */
     342    13573416 :   fd_acct_addr_t const * addr_base = fd_txn_get_acct_addrs( txn, payload );
     343             : 
     344    13573416 :   fd_compute_budget_program_state_t cbp[1];
     345    13573416 :   fd_compute_budget_program_init( cbp );
     346             : 
     347    23254479 :   for( ulong i=0UL; i<txn->instr_cnt; i++ ) {
     348     9681066 :     instr_data_sz += txn->instr[i].data_sz;
     349             : 
     350     9681066 :     ulong prog_id_idx = (ulong)txn->instr[i].program_id;
     351     9681066 :     fd_acct_addr_t const * prog_id = addr_base + prog_id_idx;
     352             : 
     353             :     /* Lookup prog_id in hash table */
     354             : 
     355     9681066 :     fd_pack_builtin_prog_cost_t null_row[1] = {{{ 0 }, 0UL }};
     356     9681066 :     fd_pack_builtin_prog_cost_t const * in_tbl = fd_pack_builtin_query( prog_id, null_row );
     357     9681066 :     non_builtin_cnt += !in_tbl->cost_per_instr; /* The only one with no cost is the null one */
     358             : 
     359     9681066 :     if( FD_UNLIKELY( in_tbl==compute_budget_row ) ) {
     360     4224603 :       if( FD_UNLIKELY( 0==fd_compute_budget_program_parse( payload+txn->instr[i].data_off, txn->instr[i].data_sz, cbp ) ) )
     361           3 :         return 0UL;
     362     5456463 :     } else if( FD_UNLIKELY( (in_tbl==ed25519_precompile_row) ) ) {
     363             :       /* First byte is # of signatures.  Branchless tail reading here is
     364             :          probably okay, but this seems safer. */
     365           0 :       ulong ed25519_signature_count = (txn->instr[i].data_sz>0) ? (ulong)payload[ txn->instr[i].data_off ] : 0UL;
     366           0 :       precompile_sig_cnt += ed25519_signature_count;
     367           0 :       signature_cost += ed25519_signature_count * FD_PACK_COST_PER_ED25519_SIGNATURE;
     368     5456463 :     } else if( FD_UNLIKELY( (in_tbl==secp256k1_precomp_row) ) ) {
     369           0 :       ulong secp256k1_signature_count = (txn->instr[i].data_sz>0) ? (ulong)payload[ txn->instr[i].data_off ] : 0UL;
     370           0 :       precompile_sig_cnt += secp256k1_signature_count;
     371           0 :       signature_cost += secp256k1_signature_count * FD_PACK_COST_PER_SECP256K1_SIGNATURE;
     372     5456463 :     } else if( FD_UNLIKELY( (in_tbl==secp256r1_precomp_row) ) ) {
     373           0 :       ulong secp256r1_signature_count = (txn->instr[i].data_sz>0) ? (ulong)payload[ txn->instr[i].data_off ] : 0UL;
     374           0 :       precompile_sig_cnt += secp256r1_signature_count;
     375           0 :       signature_cost += secp256r1_signature_count * FD_PACK_COST_PER_SECP256R1_SIGNATURE;
     376           0 :     }
     377     9681066 :   }
     378             : 
     379    13573413 :   ulong instr_data_cost = instr_data_sz / FD_PACK_INV_COST_PER_INSTR_DATA_BYTE; /* <= 320 */
     380             : 
     381    13573413 :   ulong fee[1];
     382    13573413 :   uint execution_cost[1];
     383    13573413 :   ulong loaded_account_data_cost[1];
     384    13573413 :   fd_compute_budget_program_finalize( cbp, txn->instr_cnt, txn->instr_cnt-non_builtin_cnt, fee, execution_cost, loaded_account_data_cost );
     385             : 
     386    13573413 :   fd_ulong_store_if( !!opt_execution_cost,            opt_execution_cost,            (ulong)(*execution_cost)      );
     387    13573413 :   fd_ulong_store_if( !!opt_fee,                       opt_fee,                       *fee                          );
     388    13573413 :   fd_ulong_store_if( !!opt_precompile_sig_cnt,        opt_precompile_sig_cnt,        precompile_sig_cnt            );
     389    13573413 :   fd_ulong_store_if( !!opt_loaded_accounts_data_cost, opt_loaded_accounts_data_cost, *loaded_account_data_cost     );
     390             : 
     391             : #if DETAILED_LOGGING
     392             :   FD_BASE58_ENCODE_64_BYTES( (const uchar *)fd_txn_get_signatures(txn, payload), signature_cstr );
     393             :   FD_LOG_NOTICE(( "TXN signature[%s] signature_cost[%lu]  writable_cost[%lu]  instr_data_cost[%lu]  non_builtin_cost[%lu]  loaded_account_data_cost[%lu]  precompile_sig_cnt[%lu]  fee[%lu]",
     394             :   signature_cstr, signature_cost, writable_cost, instr_data_cost, non_builtin_cost, *loaded_account_data_cost, precompile_sig_cnt, *fee));
     395             : #endif
     396             : 
     397             :   /* <= FD_PACK_MAX_COST, so no overflow concerns */
     398    13573413 :   return signature_cost + writable_cost + *execution_cost + instr_data_cost + *loaded_account_data_cost;
     399    13573416 : }
     400             : #undef MAP_PERFECT_HASH_PP
     401             : #undef PERFECT_HASH
     402             : 
     403             : #endif /* HEADER_fd_src_disco_pack_fd_pack_cost_h */

Generated by: LCOV version 1.14