LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_runtime_helpers.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 8 8 100.0 %
Date: 2026-07-11 05:27:41 Functions: 0 0 -

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

Generated by: LCOV version 1.14