Line data Source code
1 : #include "fd_instr_info.h" 2 : #include "../fd_runtime.h" 3 : #include "../../../util/bits/fd_uwide.h" 4 : 5 : void 6 : fd_instr_info_accumulate_starting_lamports( fd_instr_info_t * instr, 7 : fd_txn_out_t * txn_out, 8 : ushort idx_in_callee, 9 0 : ushort idx_in_txn ) { 10 0 : if( FD_LIKELY( !instr->is_duplicate[ idx_in_callee ] ) ) { 11 0 : fd_txn_account_t const * account = &txn_out->accounts.accounts[ idx_in_txn ]; 12 0 : if( fd_txn_account_get_meta( account ) ) { 13 0 : fd_uwide_inc( 14 0 : &instr->starting_lamports_h, &instr->starting_lamports_l, 15 0 : instr->starting_lamports_h, instr->starting_lamports_l, 16 0 : fd_txn_account_get_lamports( account ) ); 17 0 : } 18 0 : } 19 0 : } 20 : 21 : void 22 : fd_instr_info_init_from_txn_instr( fd_instr_info_t * instr, 23 : fd_bank_t * bank, 24 : fd_txn_in_t const * txn_in, 25 : fd_txn_out_t * txn_out, 26 0 : fd_txn_instr_t const * txn_instr ) { 27 : 28 0 : fd_txn_t const * txn_descriptor = TXN( txn_in->txn ); 29 0 : uchar * instr_acc_idxs = (uchar *)txn_in->txn->payload + txn_instr->acct_off; 30 : 31 : /* Set the stack height to 1 (since this is a top-level instruction) */ 32 0 : instr->stack_height = 1; 33 : 34 : /* Set the program id */ 35 0 : instr->program_id = txn_instr->program_id; 36 : 37 : /* See note in fd_instr_info.h. TLDR: capping this value at 256 38 : should have literally 0 effect on program execution, down to the 39 : error codes. This is purely for the sake of not increasing the 40 : overall memory footprint of the transaction context. If this 41 : change causes issues, we may need to increase the array sizes in 42 : the instr info. */ 43 0 : instr->acct_cnt = fd_ushort_min( txn_instr->acct_cnt, FD_INSTR_ACCT_MAX ); 44 0 : instr->data_sz = txn_instr->data_sz; 45 0 : memcpy( instr->data, txn_in->txn->payload+txn_instr->data_off, instr->data_sz ); 46 : 47 0 : uchar acc_idx_seen[ FD_INSTR_ACCT_MAX ] = {0}; 48 : 49 0 : for( ushort i=0; i<instr->acct_cnt; i++ ) { 50 0 : ushort acc_idx = instr_acc_idxs[i]; 51 : 52 0 : fd_instr_info_setup_instr_account( instr, 53 0 : acc_idx_seen, 54 0 : acc_idx, 55 0 : acc_idx, 56 0 : i, 57 0 : (uchar)fd_runtime_account_is_writable_idx( txn_in, txn_out, bank, instr_acc_idxs[i] ), 58 0 : (uchar)fd_txn_is_signer( txn_descriptor, instr_acc_idxs[i] ) ); 59 : 60 0 : } 61 0 : } 62 : 63 : int 64 : fd_instr_info_sum_account_lamports( fd_instr_info_t const * instr, 65 : fd_txn_out_t * txn_out, 66 : ulong * total_lamports_h, 67 0 : ulong * total_lamports_l ) { 68 0 : *total_lamports_h = 0UL; 69 0 : *total_lamports_l = 0UL; 70 0 : for( ulong i=0UL; i<instr->acct_cnt; ++i ) { 71 0 : ushort idx_in_txn = instr->accounts[i].index_in_transaction; 72 0 : fd_txn_account_t const * account = &txn_out->accounts.accounts[ idx_in_txn ]; 73 : 74 0 : if( !fd_txn_account_get_meta( account ) || 75 0 : instr->is_duplicate[i] ) { 76 0 : continue; 77 0 : } 78 : 79 : /* Perform a checked add on a fd_uwide */ 80 0 : ulong tmp_total_lamports_h = 0UL; 81 0 : ulong tmp_total_lamports_l = 0UL; 82 : 83 0 : fd_uwide_inc( &tmp_total_lamports_h, &tmp_total_lamports_l, *total_lamports_h, *total_lamports_l, 84 0 : fd_txn_account_get_lamports( account ) ); 85 : 86 0 : if( tmp_total_lamports_h < *total_lamports_h ) { 87 0 : return FD_EXECUTOR_INSTR_ERR_ARITHMETIC_OVERFLOW; 88 0 : } 89 : 90 0 : *total_lamports_h = tmp_total_lamports_h; 91 0 : *total_lamports_l = tmp_total_lamports_l; 92 0 : } 93 : 94 0 : return FD_EXECUTOR_INSTR_SUCCESS; 95 0 : }