LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_runtime_helpers.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 15 15 100.0 %
Date: 2026-04-10 06:33:15 Functions: 1 71 1.4 %

          Line data    Source code
       1             : #include "fd_runtime_err.h"
       2             : #include "fd_rocksdb.h"
       3             : #include "fd_acc_mgr.h"
       4             : #include "fd_hashes.h"
       5             : #include "fd_txncache.h"
       6             : #include "fd_compute_budget_details.h"
       7             : #include "fd_cost_tracker.h"
       8             : #include "context/fd_exec_instr_ctx.h"
       9             : #include "info/fd_instr_info.h"
      10             : #include "../features/fd_features.h"
      11             : #include "../capture/fd_capture_ctx.h"
      12             : #include "../../disco/pack/fd_pack.h"
      13             : #include "../../ballet/sbpf/fd_sbpf_loader.h"
      14             : #include "program/vote/fd_vote_codec.h"
      15             : 
      16             : #ifndef HEADER_fd_src_flamenco_runtime_fd_runtime_helpers_h
      17             : #define HEADER_fd_src_flamenco_runtime_fd_runtime_helpers_h
      18             : 
      19             : /* Return data for syscalls */
      20             : struct fd_txn_return_data {
      21             :   fd_pubkey_t program_id;
      22             :   ulong       len;
      23             :   uchar       data[1024];
      24             : };
      25             : typedef struct fd_txn_return_data fd_txn_return_data_t;
      26             : 
      27             : /* fd_exec_txn_ctx_t is the context needed to execute a transaction. */
      28             : 
      29             : FD_PROTOTYPES_BEGIN
      30             : 
      31             : /* Returns 0 on success, and non zero otherwise.  On failure, the out
      32             :    values will not be modified. */
      33             : int
      34             : fd_runtime_compute_max_tick_height( ulong   ticks_per_slot,
      35             :                                     ulong   slot,
      36             :                                     ulong * out_max_tick_height /* out */ );
      37             : 
      38             : void
      39             : fd_runtime_update_leaders( fd_bank_t *          bank,
      40             :                            fd_runtime_stack_t * runtime_stack );
      41             : 
      42             : /* Load the accounts in the address lookup tables of txn into out_accts_alt */
      43             : int
      44             : fd_runtime_load_txn_address_lookup_tables( fd_txn_in_t const *       txn_in,
      45             :                                            fd_txn_t const *          txn,
      46             :                                            uchar const *             payload,
      47             :                                            fd_accdb_user_t *         accdb,
      48             :                                            fd_funk_txn_xid_t const * xid,
      49             :                                            ulong                     slot,
      50             :                                            fd_slot_hash_t const *    hashes, /* deque */
      51             :                                            fd_acct_addr_t *          out_accts_alt );
      52             : 
      53             : /* fd_runtime_new_fee_rate_governor_derived updates the bank's
      54             :    FeeRateGovernor to a new derived value based on the parent bank's
      55             :    FeeRateGovernor and the latest_signatures_per_slot.
      56             :    https://github.com/anza-xyz/solana-sdk/blob/badc2c40071e6e7f7a8e8452b792b66613c5164c/fee-calculator/src/lib.rs#L97-L157
      57             : 
      58             :    latest_signatures_per_slot is typically obtained from the parent
      59             :    slot's signature count for the bank being processed.
      60             : 
      61             :    The fee rate governor is deprecated in favor of FeeStructure in
      62             :    transaction fee calculations but we still need to maintain the old
      63             :    logic for recent blockhashes sysvar (and nonce logic that relies on
      64             :    it). Thus, a separate bank field, `rbh_lamports_per_sig`, tracks the
      65             :    updates to the fee rate governor derived lamports-per-second value.
      66             : 
      67             :    Relevant links:
      68             :    - Deprecation issue tracker:
      69             :      https://github.com/anza-xyz/agave/issues/3303
      70             :    - PR that deals with disambiguation between FeeStructure and
      71             :      FeeRateGovernor in SVM: https://github.com/anza-xyz/agave/pull/3216
      72             :   */
      73             : void
      74             : fd_runtime_new_fee_rate_governor_derived( fd_bank_t * bank,
      75             :                                           ulong       latest_signatures_per_slot );
      76             : 
      77             : void
      78             : fd_runtime_read_genesis( fd_banks_t *              banks,
      79             :                          fd_bank_t *               bank,
      80             :                          fd_accdb_user_t *         accdb,
      81             :                          fd_funk_txn_xid_t const * xid,
      82             :                          fd_capture_ctx_t *        capture_ctx,
      83             :                          fd_hash_t const *         genesis_hash,
      84             :                          fd_lthash_value_t const * genesis_lthash,
      85             :                          fd_genesis_t const *      genesis,
      86             :                          uchar const *             genesis_blob,
      87             :                          fd_runtime_stack_t *      runtime_stack );
      88             : 
      89             : /* Error logging handholding assertions */
      90             : 
      91             : #ifdef FD_RUNTIME_ERR_HANDHOLDING
      92             : 
      93             : /* Asserts that the error and error kind are not populated (zero) */
      94             : #define FD_TXN_TEST_ERR_OVERWRITE( txn_out ) \
      95             :    FD_TEST( !txn_out->err.exec_err );        \
      96             :    FD_TEST( !txn_out->err.exec_err_kind )
      97             : 
      98             : /* Used prior to a FD_TXN_ERR_FOR_LOG_INSTR call to deliberately
      99             :    bypass overwrite handholding checks.
     100             :    Only use this if you know what you're doing. */
     101             : #define FD_TXN_PREPARE_ERR_OVERWRITE( txn_out ) \
     102             :    txn_out->err.exec_err = 0;                   \
     103             :    txn_out->err.exec_err_kind = 0
     104             : 
     105             : #else
     106             : 
     107          45 : #define FD_TXN_TEST_ERR_OVERWRITE( txn_out ) ( ( void )0 )
     108          45 : #define FD_TXN_PREPARE_ERR_OVERWRITE( txn_out ) ( ( void )0 )
     109             : 
     110             : #endif
     111             : 
     112          45 : #define FD_TXN_ERR_FOR_LOG_INSTR( txn_out, err_, idx ) (__extension__({ \
     113          45 :     FD_TXN_TEST_ERR_OVERWRITE( txn_out );                               \
     114          45 :     txn_out->err.exec_err = err_;                                       \
     115          45 :     txn_out->err.exec_err_kind = FD_EXECUTOR_ERR_KIND_INSTR;            \
     116          45 :     txn_out->err.exec_err_idx = idx;                                    \
     117          45 :   }))
     118             : 
     119             : int
     120             : fd_runtime_find_index_of_account( fd_txn_out_t const * txn_out,
     121             :                                   fd_pubkey_t const *  pubkey );
     122             : 
     123             : typedef int fd_txn_account_condition_fn_t ( fd_txn_in_t const * txn_in,
     124             :                                             fd_txn_out_t *      txn_out,
     125             :                                             ushort              idx );
     126             : 
     127             : /* Mirrors Agave function solana_sdk::transaction_context::get_account_at_index
     128             : 
     129             :    Takes a function pointer to a condition function to check pre-conditions on the
     130             :    obtained account. If the condition function is NULL, the account is returned without
     131             :    any pre-condition checks.
     132             : 
     133             :    https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L223-L230 */
     134             : 
     135             : fd_accdb_ref_t *
     136             : fd_runtime_get_account_at_index( fd_txn_in_t const *             txn_in,
     137             :                                  fd_txn_out_t *                  txn_out,
     138             :                                  ushort                          idx,
     139             :                                  fd_txn_account_condition_fn_t * condition );
     140             : 
     141             : /* A wrapper around fd_exec_txn_ctx_get_account_at_index that obtains an
     142             :    account from the transaction context by its pubkey. */
     143             : 
     144             : fd_accdb_ref_t *
     145             : fd_runtime_get_account_with_key( fd_txn_in_t const *             txn_in,
     146             :                                  fd_txn_out_t *                  txn_out,
     147             :                                  fd_pubkey_t const *             pubkey,
     148             :                                  int *                           index_out,
     149             :                                  fd_txn_account_condition_fn_t * condition );
     150             : 
     151             : /* Gets an executable (program data) account via its pubkey. */
     152             : 
     153             : fd_accdb_ro_t *
     154             : fd_runtime_get_executable_account( fd_runtime_t *      runtime,
     155             :                                    fd_txn_in_t const * txn_in,
     156             :                                    fd_txn_out_t *      txn_out,
     157             :                                    fd_pubkey_t const * pubkey );
     158             : 
     159             : /* Mirrors Agave function solana_sdk::transaction_context::get_key_of_account_at_index
     160             : 
     161             :    https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L212 */
     162             : 
     163             : int
     164             : fd_runtime_get_key_of_account_at_index( fd_txn_out_t *        txn_out,
     165             :                                         ushort                idx,
     166             :                                         fd_pubkey_t const * * key );
     167             : 
     168             : /* In agave, the writable accounts cache is populated by this below function.
     169             :    This cache is then referenced to determine if a transaction account is
     170             :    writable or not.
     171             : 
     172             :    The overall logic is as follows: an account can be passed
     173             :    in as writable based on the signature and readonly signature as they are
     174             :    passed in by the transaction message. However, the account's writable
     175             :    status will be demoted if either of the two conditions are met:
     176             :    1. If the account is in the set of reserved pubkeys
     177             :    2. If the account is the program id AND the upgradeable loader account is in
     178             :       the set of transaction accounts. */
     179             : /* https://github.com/anza-xyz/agave/blob/v2.1.1/sdk/program/src/message/versions/v0/loaded.rs#L137-L150 */
     180             : 
     181             : int
     182             : fd_runtime_account_is_writable_idx( fd_txn_in_t const *  txn_in,
     183             :                                     fd_txn_out_t const * txn_out,
     184             :                                     ushort               idx );
     185             : 
     186             : /* Account pre-condition filtering functions
     187             : 
     188             :    Used to filter accounts based on pre-conditions such as existence, is_writable, etc.
     189             :    when obtaining accounts from the transaction context. Passed as a function pointer. */
     190             : 
     191             : int
     192             : fd_runtime_account_check_exists( fd_txn_in_t const * txn_in,
     193             :                                  fd_txn_out_t *      txn_out,
     194             :                                  ushort              idx );
     195             : 
     196             : /* The fee payer is a valid modifiable account if it is passed in as writable
     197             :    in the message via a valid signature. We ignore if the account has been
     198             :    demoted or not (see fd_exec_txn_ctx_account_is_writable_idx) for more details.
     199             :    Agave and Firedancer will reject the fee payer if the transaction message
     200             :    doesn't have a writable signature. */
     201             : 
     202             : int
     203             : fd_runtime_account_check_fee_payer_writable( fd_txn_in_t const * txn_in,
     204             :                                              fd_txn_out_t *      txn_out,
     205             :                                              ushort              idx );
     206             : 
     207             : int
     208             : fd_account_meta_checked_sub_lamports( fd_account_meta_t * meta,
     209             :                                       ulong               lamports );
     210             : 
     211             : FD_FN_UNUSED static void
     212             : fd_account_meta_resize( fd_account_meta_t * meta,
     213          57 :                         ulong               dlen ) {
     214          57 :   ulong old_sz    = meta->dlen;
     215          57 :   ulong new_sz    = dlen;
     216          57 :   ulong memset_sz = fd_ulong_sat_sub( new_sz, old_sz );
     217          57 :   fd_memset( fd_account_data( meta ) + old_sz, 0, memset_sz );
     218          57 :   meta->dlen = (uint)dlen;
     219          57 : }
     220             : 
     221             : FD_PROTOTYPES_END
     222             : 
     223             : #endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_helpers_h */

Generated by: LCOV version 1.14