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-03-19 18:19:27 Functions: 1 65 1.5 %

          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             : 
      15             : #ifndef HEADER_fd_src_flamenco_runtime_fd_runtime_helpers_h
      16             : #define HEADER_fd_src_flamenco_runtime_fd_runtime_helpers_h
      17             : 
      18             : /* Return data for syscalls */
      19             : 
      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_t const *          txn,
      45             :                                            uchar const *             payload,
      46             :                                            fd_accdb_user_t *         accdb,
      47             :                                            fd_funk_txn_xid_t const * xid,
      48             :                                            ulong                     slot,
      49             :                                            fd_slot_hash_t const *    hashes, /* deque */
      50             :                                            fd_acct_addr_t *          out_accts_alt );
      51             : 
      52             : /* fd_runtime_new_fee_rate_governor_derived updates the bank's
      53             :    FeeRateGovernor to a new derived value based on the parent bank's
      54             :    FeeRateGovernor and the latest_signatures_per_slot.
      55             :    https://github.com/anza-xyz/solana-sdk/blob/badc2c40071e6e7f7a8e8452b792b66613c5164c/fee-calculator/src/lib.rs#L97-L157
      56             : 
      57             :    latest_signatures_per_slot is typically obtained from the parent
      58             :    slot's signature count for the bank being processed.
      59             : 
      60             :    The fee rate governor is deprecated in favor of FeeStructure in
      61             :    transaction fee calculations but we still need to maintain the old
      62             :    logic for recent blockhashes sysvar (and nonce logic that relies on
      63             :    it). Thus, a separate bank field, `rbh_lamports_per_sig`, tracks the
      64             :    updates to the fee rate governor derived lamports-per-second value.
      65             : 
      66             :    Relevant links:
      67             :    - Deprecation issue tracker:
      68             :      https://github.com/anza-xyz/agave/issues/3303
      69             :    - PR that deals with disambiguation between FeeStructure and
      70             :      FeeRateGovernor in SVM: https://github.com/anza-xyz/agave/pull/3216
      71             :   */
      72             : void
      73             : fd_runtime_new_fee_rate_governor_derived( fd_bank_t * bank,
      74             :                                           ulong       latest_signatures_per_slot );
      75             : 
      76             : void
      77             : fd_runtime_read_genesis( fd_banks_t *              banks,
      78             :                          fd_bank_t *               bank,
      79             :                          fd_accdb_user_t *         accdb,
      80             :                          fd_funk_txn_xid_t const * xid,
      81             :                          fd_capture_ctx_t *        capture_ctx,
      82             :                          fd_hash_t const *         genesis_hash,
      83             :                          fd_lthash_value_t const * genesis_lthash,
      84             :                          fd_genesis_t const *      genesis,
      85             :                          uchar const *             genesis_blob,
      86             :                          fd_runtime_stack_t *      runtime_stack );
      87             : 
      88             : /* Error logging handholding assertions */
      89             : 
      90             : #ifdef FD_RUNTIME_ERR_HANDHOLDING
      91             : 
      92             : /* Asserts that the error and error kind are not populated (zero) */
      93             : #define FD_TXN_TEST_ERR_OVERWRITE( txn_out ) \
      94             :    FD_TEST( !txn_out->err.exec_err );        \
      95             :    FD_TEST( !txn_out->err.exec_err_kind )
      96             : 
      97             : /* Used prior to a FD_TXN_ERR_FOR_LOG_INSTR call to deliberately
      98             :    bypass overwrite handholding checks.
      99             :    Only use this if you know what you're doing. */
     100             : #define FD_TXN_PREPARE_ERR_OVERWRITE( txn_out ) \
     101             :    txn_out->err.exec_err = 0;                   \
     102             :    txn_out->err.exec_err_kind = 0
     103             : 
     104             : #else
     105             : 
     106       25063 : #define FD_TXN_TEST_ERR_OVERWRITE( txn_out ) ( ( void )0 )
     107       21557 : #define FD_TXN_PREPARE_ERR_OVERWRITE( txn_out ) ( ( void )0 )
     108             : 
     109             : #endif
     110             : 
     111       25063 : #define FD_TXN_ERR_FOR_LOG_INSTR( txn_out, err_, idx ) (__extension__({ \
     112       25063 :     FD_TXN_TEST_ERR_OVERWRITE( txn_out );                               \
     113       25063 :     txn_out->err.exec_err = err_;                                       \
     114       25063 :     txn_out->err.exec_err_kind = FD_EXECUTOR_ERR_KIND_INSTR;            \
     115       25063 :     txn_out->err.exec_err_idx = idx;                                    \
     116       25063 :   }))
     117             : 
     118             : int
     119             : fd_runtime_find_index_of_account( fd_txn_out_t const * txn_out,
     120             :                                   fd_pubkey_t const *  pubkey );
     121             : 
     122             : typedef int fd_txn_account_condition_fn_t ( fd_txn_in_t const * txn_in,
     123             :                                             fd_txn_out_t *      txn_out,
     124             :                                             ushort              idx );
     125             : 
     126             : /* Mirrors Agave function solana_sdk::transaction_context::get_account_at_index
     127             : 
     128             :    Takes a function pointer to a condition function to check pre-conditions on the
     129             :    obtained account. If the condition function is NULL, the account is returned without
     130             :    any pre-condition checks.
     131             : 
     132             :    https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L223-L230 */
     133             : 
     134             : int
     135             : fd_runtime_get_account_at_index( fd_txn_in_t const *             txn_in,
     136             :                                  fd_txn_out_t *                  txn_out,
     137             :                                  ushort                          idx,
     138             :                                  fd_txn_account_condition_fn_t * condition );
     139             : 
     140             : /* A wrapper around fd_exec_txn_ctx_get_account_at_index that obtains an
     141             :    account from the transaction context by its pubkey. */
     142             : 
     143             : int
     144             : fd_runtime_get_account_with_key( fd_txn_in_t const *             txn_in,
     145             :                                  fd_txn_out_t *                  txn_out,
     146             :                                  fd_pubkey_t const *             pubkey,
     147             :                                  int *                           index_out,
     148             :                                  fd_txn_account_condition_fn_t * condition );
     149             : 
     150             : /* Gets an executable (program data) account via its pubkey. */
     151             : 
     152             : int
     153             : fd_runtime_get_executable_account( fd_runtime_t *              runtime,
     154             :                                    fd_txn_in_t const *         txn_in,
     155             :                                    fd_txn_out_t *              txn_out,
     156             :                                    fd_pubkey_t const *         pubkey,
     157             :                                    fd_account_meta_t const * * meta );
     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             :                                     fd_bank_t *          bank,
     185             :                                     ushort               idx );
     186             : 
     187             : /* Account pre-condition filtering functions
     188             : 
     189             :    Used to filter accounts based on pre-conditions such as existence, is_writable, etc.
     190             :    when obtaining accounts from the transaction context. Passed as a function pointer. */
     191             : 
     192             : int
     193             : fd_runtime_account_check_exists( fd_txn_in_t const * txn_in,
     194             :                                  fd_txn_out_t *      txn_out,
     195             :                                  ushort              idx );
     196             : 
     197             : /* The fee payer is a valid modifiable account if it is passed in as writable
     198             :    in the message via a valid signature. We ignore if the account has been
     199             :    demoted or not (see fd_exec_txn_ctx_account_is_writable_idx) for more details.
     200             :    Agave and Firedancer will reject the fee payer if the transaction message
     201             :    doesn't have a writable signature. */
     202             : 
     203             : int
     204             : fd_runtime_account_check_fee_payer_writable( fd_txn_in_t const * txn_in,
     205             :                                              fd_txn_out_t *      txn_out,
     206             :                                              ushort              idx );
     207             : 
     208             : int
     209             : fd_account_meta_checked_sub_lamports( fd_account_meta_t * meta,
     210             :                                       ulong               lamports );
     211             : 
     212             : FD_FN_UNUSED static void
     213             : fd_account_meta_resize( fd_account_meta_t * meta,
     214         551 :                         ulong               dlen ) {
     215         551 :   ulong old_sz    = meta->dlen;
     216         551 :   ulong new_sz    = dlen;
     217         551 :   ulong memset_sz = fd_ulong_sat_sub( new_sz, old_sz );
     218         551 :   fd_memset( fd_account_data( meta ) + old_sz, 0, memset_sz );
     219         551 :   meta->dlen = (uint)dlen;
     220         551 : }
     221             : 
     222             : FD_PROTOTYPES_END
     223             : 
     224             : #endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_helpers_h */

Generated by: LCOV version 1.14