LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_executor.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 19 19 100.0 %
Date: 2025-01-08 12:08:44 Functions: 7 68 10.3 %

          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 "../../ballet/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/generated/invoke.pb.h"
      14             : #include "tests/generated/txn.pb.h"
      15             : #include "../features/fd_features.h"
      16             : #include "fd_runtime.h"
      17             : 
      18       53808 : #define FD_FEE_PAYER_TXN_IDX (0UL)
      19             : 
      20             : /* FD_EXEC_CU_UPDATE consumes CUs from the current instr ctx
      21             :    and fails in case of error. */
      22       65691 : #define FD_EXEC_CU_UPDATE( ctx, cost ) do {               \
      23       65691 :   fd_exec_instr_ctx_t * _ctx = (ctx);                     \
      24       65691 :   int err = fd_exec_consume_cus( _ctx->txn_ctx, (cost) ); \
      25       65691 :   if( FD_UNLIKELY( err ) ) return err;                    \
      26       65691 :   } while(0)
      27             : 
      28             : FD_PROTOTYPES_BEGIN
      29             : 
      30             : /* https://github.com/anza-xyz/agave/blob/v2.0.9/runtime/src/bank.rs#L3239-L3251 */
      31             : static inline ulong
      32        8364 : get_transaction_account_lock_limit( fd_exec_slot_ctx_t const * slot_ctx ) {
      33        8364 :   return fd_ulong_if( FD_FEATURE_ACTIVE( slot_ctx, increase_tx_account_lock_limit ), MAX_TX_ACCOUNT_LOCKS, 64UL );
      34        8364 : }
      35             : 
      36             : /* Create an InstrContext protobuf struct from a given
      37             :    transaction context and instr info.
      38             : 
      39             :    NOTE: Calling this function requires the caller to have a scratch
      40             :    frame ready and pushed (see dump_instr_to_protobuf) */
      41             : void
      42             : fd_create_instr_context_protobuf_from_instructions( fd_exec_test_instr_context_t       * instr_context,
      43             :                                                     fd_exec_txn_ctx_t            const * txn_ctx,
      44             :                                                     fd_instr_info_t              const * instr );
      45             : 
      46             : /* fd_exec_instr_fn_t processes an instruction.  Returns an error code
      47             :    in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}. */
      48             : 
      49             : typedef int (* fd_exec_instr_fn_t)( fd_exec_instr_ctx_t * ctx );
      50             : 
      51             : /* fd_executor_lookup_native_program returns the appropriate instruction
      52             :    processor for the given native program ID.  Returns NULL if given ID
      53             :    is not a recognized native program. */
      54             : 
      55             : fd_exec_instr_fn_t
      56             : fd_executor_lookup_native_program( fd_borrowed_account_t const * account );
      57             : 
      58             : /* TODO:FIXME: add documentation here */
      59             : 
      60             : int
      61             : fd_validate_fee_payer( fd_borrowed_account_t * account, fd_rent_t const * rent, ulong fee );
      62             : 
      63             : int
      64             : fd_executor_check_transactions( fd_exec_txn_ctx_t * txn_ctx );
      65             : 
      66             : int
      67             : fd_executor_verify_precompiles( fd_exec_txn_ctx_t * txn_ctx );
      68             : 
      69             : /* fd_execute_instr creates a new fd_exec_instr_ctx_t and performs
      70             :    instruction processing.  Does fd_scratch allocations.  Returns an
      71             :    error code in FD_EXECUTOR_INSTR_{ERR_{...},SUCCESS}.
      72             : 
      73             :    IMPORTANT: instr_info must have the same lifetime as txn_ctx. This can
      74             :    be achieved by using fd_executor_acquire_instr_info_elem( txn_ctx ) to
      75             :    acquire an fd_instr_info_t element with the same lifetime as the txn_ctx */
      76             : int
      77             : fd_executor_txn_verify( fd_exec_txn_ctx_t * txn_ctx );
      78             : 
      79             : int
      80             : fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx,
      81             :                   fd_instr_info_t *   instr_info );
      82             : 
      83             : int
      84             : fd_execute_txn_prepare_start( fd_exec_slot_ctx_t *  slot_ctx,
      85             :                                fd_exec_txn_ctx_t * txn_ctx,
      86             :                                fd_txn_t const * txn_descriptor,
      87             :                                fd_rawtxn_b_t const * txn_raw );
      88             : 
      89             : /*
      90             :   Execute the given transaction.
      91             : 
      92             :   Makes changes to the Funk accounts DB. */
      93             : int
      94             : fd_execute_txn( fd_exec_txn_ctx_t * txn_ctx );
      95             : 
      96             : uint
      97             : fd_executor_txn_uses_sysvar_instructions( fd_exec_txn_ctx_t const * txn_ctx );
      98             : 
      99             : int
     100             : fd_executor_validate_transaction_fee_payer( fd_exec_txn_ctx_t * txn_ctx );
     101             : 
     102             : int
     103             : fd_executor_setup_accessed_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx );
     104             : 
     105             : void
     106             : fd_executor_setup_borrowed_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx );
     107             : 
     108             : int
     109             : fd_executor_is_system_nonce_account( fd_borrowed_account_t * account );
     110             : 
     111             : /*
     112             :   Validate the txn after execution for violations of various lamport balance and size rules
     113             :  */
     114             : 
     115             : int
     116             : fd_executor_txn_check( fd_exec_slot_ctx_t const * slot_ctx,
     117             :                        fd_exec_txn_ctx_t *        txn );
     118             : 
     119             : void
     120             : fd_txn_reclaim_accounts( fd_exec_txn_ctx_t * txn_ctx );
     121             : 
     122             : int
     123             : fd_executor_is_blockhash_valid_for_age( fd_block_hash_queue_t const * block_hash_queue,
     124             :                                         fd_hash_t const *             blockhash,
     125             :                                         ulong                         max_age );
     126             : 
     127             : /* fd_io_strerror converts an FD_EXECUTOR_INSTR_ERR_{...} code into a
     128             :    human readable cstr.  The lifetime of the returned pointer is
     129             :    infinite and the call itself is thread safe.  The returned pointer is
     130             :    always to a non-NULL cstr. */
     131             : 
     132             : FD_FN_CONST char const *
     133             : fd_executor_instr_strerror( int err );
     134             : 
     135             : int
     136             : fd_executor_load_transaction_accounts( fd_exec_txn_ctx_t * txn_ctx );
     137             : 
     138             : int
     139             : fd_executor_validate_account_locks( fd_exec_txn_ctx_t const * txn_ctx );
     140             : 
     141             : static inline int
     142             : fd_exec_consume_cus( fd_exec_txn_ctx_t * txn_ctx,
     143       65691 :                      ulong               cus ) {
     144       65691 :   ulong new_cus   =  txn_ctx->compute_meter - cus;
     145       65691 :   int   underflow = (txn_ctx->compute_meter < cus);
     146       65691 :   if( FD_UNLIKELY( underflow ) ) {
     147        9840 :     txn_ctx->compute_meter = 0UL;
     148        9840 :     return FD_EXECUTOR_INSTR_ERR_COMPUTE_BUDGET_EXCEEDED;
     149        9840 :   }
     150       55851 :   txn_ctx->compute_meter = new_cus;
     151       55851 :   return FD_EXECUTOR_INSTR_SUCCESS;
     152       65691 : }
     153             : 
     154             : void
     155             : fd_dump_txn_to_protobuf( fd_exec_txn_ctx_t *txn_ctx, fd_spad_t * spad );
     156             : 
     157             : /* We expose these only for the fuzzing harness.
     158             :    Normally you shouldn't be invoking these manually. */
     159             : int
     160             : fd_instr_stack_push( fd_exec_txn_ctx_t *     txn_ctx,
     161             :                      fd_instr_info_t *       instr );
     162             : 
     163             : int
     164             : fd_instr_stack_pop( fd_exec_txn_ctx_t *       txn_ctx,
     165             :                     fd_instr_info_t const *   instr );
     166             : 
     167             : FD_PROTOTYPES_END
     168             : 
     169             : #endif /* HEADER_fd_src_flamenco_runtime_fd_executor_h */

Generated by: LCOV version 1.14