LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_runtime_helpers.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 8 0.0 %
Date: 2025-12-13 04:39:40 Functions: 0 0 -

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

Generated by: LCOV version 1.14