Line data Source code
1 : #include "fd_native_cpi.h" 2 : #include "../fd_borrowed_account.h" 3 : #include "../fd_executor.h" 4 : #include "../../vm/syscall/fd_vm_syscall.h" 5 : #include "../../../util/bits/fd_uwide.h" 6 : 7 : int 8 : fd_native_cpi_native_invoke( fd_exec_instr_ctx_t * ctx, 9 : fd_pubkey_t const * native_program_id, 10 : uchar * instr_data, 11 : ulong instr_data_len, 12 : fd_vm_rust_account_meta_t const * acct_metas, 13 : ulong acct_metas_len, 14 : fd_pubkey_t const * signers, 15 39 : ulong signers_cnt ) { 16 : /* Set up the instr info */ 17 39 : fd_instr_info_t * instr_info = &ctx->runtime->instr.trace[ ctx->runtime->instr.trace_length++ ]; 18 39 : fd_instruction_account_t instruction_accounts[ FD_TXN_INSTR_ACCT_MAX ]; 19 39 : ulong instruction_accounts_cnt; 20 : 21 : /* Set the stack size */ 22 39 : instr_info->stack_height = (uchar)( ctx->runtime->instr.stack_sz+1 ); 23 : 24 : /* fd_vm_prepare_instruction will handle missing/invalid account case */ 25 39 : instr_info->program_id = UCHAR_MAX; 26 39 : ulong program_id = fd_runtime_find_index_of_account( ctx->txn_out, native_program_id ); 27 39 : if( FD_LIKELY( program_id!=ULONG_MAX ) ) instr_info->program_id = (uchar)program_id; 28 : 29 39 : fd_pubkey_t instr_acct_keys[ FD_TXN_INSTR_ACCT_MAX ]; 30 39 : uchar acc_idx_seen[ FD_TXN_ACCT_ADDR_MAX ] = {0}; 31 39 : ushort caller_map[ MAX_TX_ACCOUNT_LOCKS ]; 32 39 : fd_exec_instr_ctx_instr_account_map( ctx, caller_map ); 33 : 34 39 : instr_info->acct_cnt = (ushort)acct_metas_len; 35 144 : for( ushort j=0U; j<acct_metas_len; j++ ) { 36 105 : fd_vm_rust_account_meta_t const * acct_meta = &acct_metas[j]; 37 105 : fd_pubkey_t const * acct_key = fd_type_pun_const( acct_meta->pubkey ); 38 105 : instr_acct_keys[j] = *acct_key; 39 : 40 105 : ulong idx_in_txn = fd_runtime_find_index_of_account( ctx->txn_out, acct_key ); 41 : 42 105 : fd_instr_info_setup_instr_account( instr_info, 43 105 : acc_idx_seen, 44 105 : idx_in_txn!=ULONG_MAX ? (ushort)idx_in_txn : USHORT_MAX, 45 105 : idx_in_txn!=ULONG_MAX ? caller_map[ idx_in_txn ] : USHORT_MAX, 46 105 : j, 47 105 : acct_meta->is_writable, 48 105 : acct_meta->is_signer ); 49 105 : } 50 : 51 39 : fd_memcpy( instr_info->data, instr_data, instr_data_len ); 52 39 : instr_info->data_sz = (ushort)instr_data_len; 53 : 54 : /* https://github.com/anza-xyz/agave/blob/v2.2.6/program-runtime/src/invoke_context.rs#L312-L313 */ 55 39 : int exec_err = fd_vm_prepare_instruction( instr_info, 56 39 : ctx, 57 39 : native_program_id, 58 39 : instr_acct_keys, 59 39 : instruction_accounts, 60 39 : &instruction_accounts_cnt, 61 39 : signers, 62 39 : signers_cnt ); 63 39 : if( FD_UNLIKELY( exec_err!=FD_EXECUTOR_INSTR_SUCCESS ) ) { 64 6 : return exec_err; 65 6 : } 66 : 67 : /* https://github.com/anza-xyz/agave/blob/v2.2.6/program-runtime/src/invoke_context.rs#L315-L321 */ 68 33 : return fd_execute_instr( ctx->runtime, ctx->bank, ctx->txn_in, ctx->txn_out, instr_info ); 69 39 : } 70 : 71 : void 72 : fd_native_cpi_create_account_meta( fd_pubkey_t const * key, uchar is_signer, 73 105 : uchar is_writable, fd_vm_rust_account_meta_t * meta ) { 74 105 : meta->is_signer = is_signer; 75 105 : meta->is_writable = is_writable; 76 105 : fd_memcpy( meta->pubkey, key->key, sizeof(fd_pubkey_t) ); 77 105 : }