LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_executor.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 12 22 54.5 %
Date: 2025-08-05 05:04:49 Functions: 1 80 1.2 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_fd_executor_h
       2             : #define HEADER_fd_src_flamenco_runtime_fd_executor_h
       3             : 
       4             : #include "fd_executor_err.h"
       5             : #include "context/fd_exec_txn_ctx.h"
       6             : #include "context/fd_exec_instr_ctx.h"
       7             : #include "../../ballet/block/fd_microblock.h"
       8             : #include "../../disco/pack/fd_microblock.h"
       9             : #include "../../ballet/txn/fd_txn.h"
      10             : #include "../../ballet/poh/fd_poh.h"
      11             : #include "../types/fd_types_yaml.h"
      12             : #include "../log_collector/fd_log_collector.h"
      13             : #include "tests/harness/generated/invoke.pb.h"
      14             : #include "tests/harness/generated/txn.pb.h"
      15             : #include "../features/fd_features.h"
      16             : #include "fd_runtime.h"
      17             : 
      18             : /* https://github.com/anza-xyz/agave/blob/v2.3.1/svm/src/account_loader.rs#L40-L47 */
      19           0 : #define FD_TRANSACTION_ACCOUNT_BASE_SIZE  (64UL)
      20           0 : #define FD_ADDRESS_LOOKUP_TABLE_BASE_SIZE (8248UL)
      21             : 
      22           0 : #define FD_FEE_PAYER_TXN_IDX (0UL)
      23             : 
      24             : /* FD_EXEC_CU_UPDATE consumes CUs from the current instr ctx
      25             :    and fails in case of error. */
      26           3 : #define FD_EXEC_CU_UPDATE( ctx, cost ) do {               \
      27           3 :   fd_exec_instr_ctx_t * _ctx = (ctx);                     \
      28           3 :   int err = fd_exec_consume_cus( _ctx->txn_ctx, (cost) ); \
      29           3 :   if( FD_UNLIKELY( err ) ) return err;                    \
      30           3 :   } while(0)
      31             : 
      32             : // https://github.com/anza-xyz/agave/blob/2e6ca8c1f62db62c1db7f19c9962d4db43d0d550/sdk/src/fee.rs#L82
      33           0 : #define FD_ACCOUNT_DATA_COST_PAGE_SIZE ( 32UL * 1024UL )
      34             : 
      35             : FD_PROTOTYPES_BEGIN
      36             : 
      37             : /* https://github.com/anza-xyz/agave/blob/v2.0.9/runtime/src/bank.rs#L3239-L3251 */
      38             : static inline ulong
      39           0 : get_transaction_account_lock_limit( fd_exec_txn_ctx_t const * txn_ctx ) {
      40           0 :   return fd_ulong_if( FD_FEATURE_ACTIVE_BANK( txn_ctx->bank, increase_tx_account_lock_limit ), MAX_TX_ACCOUNT_LOCKS, 64UL );
      41           0 : }
      42             : 
      43             : /* fd_exec_instr_fn_t processes an instruction.  Returns an error code
      44             :    in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}. */
      45             : 
      46             : typedef int (* fd_exec_instr_fn_t)( fd_exec_instr_ctx_t * ctx );
      47             : 
      48             : fd_exec_instr_fn_t
      49             : fd_executor_lookup_native_precompile_program( fd_txn_account_t const * prog_acc );
      50             : 
      51             : /* Returns 1 if the given pubkey matches one of the BPF loader v1/v2/v3/v4
      52             :    program IDs, and 0 otherwise. */
      53             : uchar
      54             : fd_executor_pubkey_is_bpf_loader( fd_pubkey_t const * pubkey );
      55             : 
      56             : int
      57             : fd_executor_verify_transaction( fd_exec_txn_ctx_t * txn_ctx );
      58             : 
      59             : int
      60             : fd_executor_check_transactions( fd_exec_txn_ctx_t * txn_ctx );
      61             : 
      62             : /* fd_execute_instr creates a new fd_exec_instr_ctx_t and performs
      63             :    instruction processing.  Does fd_spad_t allocations.  Returns an
      64             :    error code in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}.
      65             : 
      66             :    IMPORTANT: instr_info must have the same lifetime as txn_ctx. This can
      67             :    be achieved by using fd_executor_acquire_instr_info_elem( txn_ctx ) to
      68             :    acquire an fd_instr_info_t element with the same lifetime as the txn_ctx */
      69             : int
      70             : fd_executor_txn_verify( fd_exec_txn_ctx_t * txn_ctx );
      71             : 
      72             : int
      73             : fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx,
      74             :                   fd_instr_info_t *   instr_info );
      75             : 
      76             : int
      77             : fd_execute_txn_prepare_start( fd_exec_slot_ctx_t const * slot_ctx,
      78             :                               fd_exec_txn_ctx_t *        txn_ctx,
      79             :                               fd_txn_t const *           txn_descriptor,
      80             :                               fd_rawtxn_b_t const *      txn_raw );
      81             : 
      82             : /*
      83             :   Execute the given transaction.
      84             : 
      85             :   Makes changes to the Funk accounts DB. */
      86             : int
      87             : fd_execute_txn( fd_execute_txn_task_info_t * task_info );
      88             : 
      89             : int
      90             : fd_executor_validate_transaction_fee_payer( fd_exec_txn_ctx_t * txn_ctx );
      91             : 
      92             : void
      93             : fd_executor_setup_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx );
      94             : 
      95             : void
      96             : fd_executor_setup_txn_account_keys( fd_exec_txn_ctx_t * txn_ctx );
      97             : 
      98             : int
      99             : fd_executor_setup_txn_alut_account_keys( fd_exec_txn_ctx_t * txn_ctx );
     100             : 
     101             : /*
     102             :   Validate the txn after execution for violations of various lamport balance and size rules
     103             :  */
     104             : 
     105             : int
     106             : fd_executor_txn_check( fd_exec_txn_ctx_t * txn_ctx );
     107             : 
     108             : void
     109             : fd_txn_reclaim_accounts( fd_exec_txn_ctx_t * txn_ctx );
     110             : 
     111             : /* fd_io_strerror converts an FD_EXECUTOR_INSTR_ERR_{...} code into a
     112             :    human readable cstr.  The lifetime of the returned pointer is
     113             :    infinite and the call itself is thread safe.  The returned pointer is
     114             :    always to a non-NULL cstr. */
     115             : 
     116             : FD_FN_CONST char const *
     117             : fd_executor_instr_strerror( int err );
     118             : 
     119             : int
     120             : fd_executor_load_transaction_accounts( fd_exec_txn_ctx_t * txn_ctx );
     121             : 
     122             : int
     123             : fd_executor_validate_account_locks( fd_exec_txn_ctx_t const * txn_ctx );
     124             : 
     125             : static inline int
     126             : fd_exec_consume_cus( fd_exec_txn_ctx_t * txn_ctx,
     127           3 :                      ulong               cus ) {
     128           3 :   ulong new_cus   =  txn_ctx->compute_budget_details.compute_meter - cus;
     129           3 :   int   underflow = (txn_ctx->compute_budget_details.compute_meter < cus);
     130           3 :   if( FD_UNLIKELY( underflow ) ) {
     131           0 :     txn_ctx->compute_budget_details.compute_meter = 0UL;
     132           0 :     return FD_EXECUTOR_INSTR_ERR_COMPUTE_BUDGET_EXCEEDED;
     133           0 :   }
     134           3 :   txn_ctx->compute_budget_details.compute_meter = new_cus;
     135           3 :   return FD_EXECUTOR_INSTR_SUCCESS;
     136           3 : }
     137             : 
     138             : /* We expose these only for the fuzzing harness.
     139             :    Normally you shouldn't be invoking these manually. */
     140             : int
     141             : fd_instr_stack_push( fd_exec_txn_ctx_t *     txn_ctx,
     142             :                      fd_instr_info_t *       instr );
     143             : 
     144             : int
     145             : fd_instr_stack_pop( fd_exec_txn_ctx_t *       txn_ctx,
     146             :                     fd_instr_info_t const *   instr );
     147             : 
     148             : void
     149             : fd_exec_txn_ctx_from_exec_slot_ctx( fd_exec_slot_ctx_t const * slot_ctx,
     150             :                                     fd_exec_txn_ctx_t *        ctx,
     151             :                                     fd_wksp_t const *          funk_wksp,
     152             :                                     fd_wksp_t const *          runtime_pub_wksp,
     153             :                                     ulong                      funk_txn_gaddr,
     154             :                                     ulong                      funk_gaddr,
     155             :                                     fd_bank_hash_cmp_t *       bank_hash_cmp );
     156             : 
     157             : FD_PROTOTYPES_END
     158             : 
     159             : #endif /* HEADER_fd_src_flamenco_runtime_fd_executor_h */

Generated by: LCOV version 1.14