Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_context_fd_exec_instr_ctx_h 2 : #define HEADER_fd_src_flamenco_runtime_context_fd_exec_instr_ctx_h 3 : 4 : #include "../info/fd_instr_info.h" 5 : #include "../fd_executor_err.h" 6 : #include "../../../funk/fd_funk.h" 7 : 8 : /* Avoid circular include dependency with forward declaration */ 9 : struct fd_borrowed_account; 10 : typedef struct fd_borrowed_account fd_borrowed_account_t; 11 : 12 : /* fd_exec_instr_ctx_t is the context needed to execute a single 13 : instruction (program invocation). */ 14 : 15 : struct __attribute__((aligned(8UL))) fd_exec_instr_ctx { 16 : ulong magic; /* ==FD_EXEC_INSTR_CTX_MAGIC */ 17 : 18 : fd_exec_txn_ctx_t * txn_ctx; /* The transaction context for this instruction */ 19 : 20 : fd_exec_instr_ctx_t const * parent; 21 : 22 : uint depth; /* starts at 0 */ 23 : uint index; /* number of preceding instructions with same parent */ 24 : uint child_cnt; /* number of child instructions */ 25 : uint instr_err; /* TODO: this is kind of redundant wrt instr_exec */ 26 : 27 : fd_funk_txn_t * funk_txn; 28 : fd_acc_mgr_t * acc_mgr; 29 : 30 : /* Most instructions log the base58 program id multiple times, so it's 31 : convenient to compute it once and reuse it. */ 32 : char program_id_base58[ FD_BASE58_ENCODED_32_SZ ]; 33 : 34 : fd_instr_info_t const * instr; 35 : }; 36 : 37 7665 : #define FD_EXEC_INSTR_CTX_ALIGN (alignof(fd_exec_instr_ctx_t)) 38 15330 : #define FD_EXEC_INSTR_CTX_FOOTPRINT (sizeof (fd_exec_instr_ctx_t)) 39 7665 : #define FD_EXEC_INSTR_CTX_MAGIC (0x18964FC6EDAAC5A8UL) /* random */ 40 : 41 : /* Be careful when using this macro. There may be places where the error 42 : will need to be handled differently. */ 43 0 : #define FD_TRY_BORROW_INSTR_ACCOUNT_DEFAULT_ERR_CHECK( ctx, idx, acc ) do { \ 44 0 : int err = fd_exec_instr_ctx_try_borrow_account( ctx, idx, acc ); \ 45 0 : if( FD_UNLIKELY( err ) ) return err; \ 46 0 : } while (0) 47 : 48 : FD_PROTOTYPES_BEGIN 49 : 50 : /* Constructors */ 51 : 52 : void * 53 : fd_exec_instr_ctx_new( void * mem ); 54 : 55 : fd_exec_instr_ctx_t * 56 : fd_exec_instr_ctx_join( void * mem ); 57 : 58 : void * 59 : fd_exec_instr_ctx_leave( fd_exec_instr_ctx_t * ctx ); 60 : 61 : void * 62 : fd_exec_instr_ctx_delete( void * mem ); 63 : 64 : /* Operators */ 65 : 66 : /* Mirrors Agave function solana_sdk::transaction_context::InstructionContext::check_number_of_instruction_accounts 67 : 68 : Assert that enough accounts were supplied to this instruction. Returns 69 : FD_EXECUTOR_INSTR_SUCCESS if the number of accounts is as expected and 70 : FD_EXECUTOR_INSTR_ERR_NOT_ENOUGH_ACC_KEYS otherwise. 71 : 72 : https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L490 */ 73 : static inline int 74 : fd_exec_instr_ctx_check_num_insn_accounts( fd_exec_instr_ctx_t * ctx, 75 0 : uint expected_accounts ) { 76 : 77 0 : if( FD_UNLIKELY( ctx->instr->acct_cnt<expected_accounts ) ) { 78 0 : return FD_EXECUTOR_INSTR_ERR_NOT_ENOUGH_ACC_KEYS; 79 0 : } 80 0 : return FD_EXECUTOR_INSTR_SUCCESS; 81 0 : } 82 : 83 : /* Mirrors Agave function solana_sdk::transaction_context::InstructionContext::try_borrow_account. 84 : 85 : Borrows an account from the instruction context with a given account index. 86 : 87 : https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L594 */ 88 : 89 : int 90 : fd_exec_instr_ctx_try_borrow_account( fd_exec_instr_ctx_t const * ctx, 91 : ulong idx, 92 : fd_borrowed_account_t * account ); 93 : 94 : /* A wrapper around fd_exec_instr_ctx_try_borrow_account that accepts an account pubkey. 95 : 96 : Borrows an account from the instruction context with a given pubkey. */ 97 : 98 : int 99 : fd_exec_instr_ctx_try_borrow_account_with_key( fd_exec_instr_ctx_t * ctx, 100 : fd_pubkey_t const * pubkey, 101 : fd_borrowed_account_t * account ); 102 : 103 : /* Mirrors Agave function solana_sdk::transaction_context::InstructionContext::find_index_of_instruction_account. 104 : 105 : Returns the index of the the instruction account given the account pubkey 106 : or -1 if the account is not found. 107 : 108 : https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L524-L538 */ 109 : 110 : int 111 : fd_exec_instr_ctx_find_idx_of_instr_account( fd_exec_instr_ctx_t const * ctx, 112 : fd_pubkey_t const * pubkey ); 113 : 114 : FD_PROTOTYPES_END 115 : 116 : #endif /* HEADER_fd_src_flamenco_runtime_context_fd_exec_instr_ctx_h */