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_init_from_txn_instr( fd_instr_info_t * instr, 7 : fd_txn_in_t const * txn_in, 8 : fd_txn_out_t * txn_out, 9 96 : fd_txn_instr_t const * txn_instr ) { 10 : 11 96 : fd_txn_t const * txn_descriptor = TXN( txn_in->txn ); 12 96 : uchar * instr_acc_idxs = (uchar *)txn_in->txn->payload + txn_instr->acct_off; 13 : 14 : /* Set the stack height to 1 (since this is a top-level instruction) */ 15 96 : instr->stack_height = 1; 16 : 17 : /* Set the program id */ 18 96 : instr->program_id = txn_instr->program_id; 19 96 : instr->acct_cnt = txn_instr->acct_cnt; 20 96 : if( FD_UNLIKELY( instr->acct_cnt > FD_INSTR_ACCT_MAX ) ) { 21 0 : FD_LOG_CRIT(( "invariant violation: Instruction has too many accounts: %d > %lu", instr->acct_cnt, FD_INSTR_ACCT_MAX )); 22 0 : } 23 96 : instr->data_sz = txn_instr->data_sz; 24 96 : memcpy( instr->data, txn_in->txn->payload+txn_instr->data_off, instr->data_sz ); 25 : 26 96 : uchar acc_idx_seen[ FD_TXN_ACCT_ADDR_MAX ] = {0}; 27 : 28 5802 : for( ushort i=0; i<instr->acct_cnt; i++ ) { 29 5706 : ushort acc_idx = instr_acc_idxs[i]; 30 : 31 5706 : fd_instr_info_setup_instr_account( instr, 32 5706 : acc_idx_seen, 33 5706 : acc_idx, 34 5706 : acc_idx, 35 5706 : i, 36 5706 : (uchar)fd_runtime_account_is_writable_idx( txn_in, txn_out, instr_acc_idxs[i] ), 37 5706 : (uchar)fd_txn_is_signer( txn_descriptor, instr_acc_idxs[i] ) ); 38 : 39 5706 : } 40 96 : } 41 : 42 : int 43 : fd_instr_info_sum_account_lamports( fd_instr_info_t const * instr, 44 : fd_txn_out_t * txn_out, 45 : ulong * total_lamports_h, 46 258 : ulong * total_lamports_l ) { 47 258 : *total_lamports_h = 0UL; 48 258 : *total_lamports_l = 0UL; 49 11808 : for( ulong i=0UL; i<instr->acct_cnt; ++i ) { 50 11550 : ushort idx_in_txn = instr->accounts[i].index_in_transaction; 51 11550 : fd_accdb_rw_t const * ref = &txn_out->accounts.account[ idx_in_txn ]; 52 : 53 11550 : if( instr->is_duplicate[i] ) { 54 11076 : continue; 55 11076 : } 56 : 57 : /* Perform a checked add on a fd_uwide */ 58 474 : ulong tmp_total_lamports_h = 0UL; 59 474 : ulong tmp_total_lamports_l = 0UL; 60 : 61 474 : fd_uwide_inc( &tmp_total_lamports_h, &tmp_total_lamports_l, 62 474 : *total_lamports_h, *total_lamports_l, 63 474 : fd_accdb_ref_lamports( ref->ro ) ); 64 : 65 474 : if( tmp_total_lamports_h < *total_lamports_h ) { 66 0 : return FD_EXECUTOR_INSTR_ERR_ARITHMETIC_OVERFLOW; 67 0 : } 68 : 69 474 : *total_lamports_h = tmp_total_lamports_h; 70 474 : *total_lamports_l = tmp_total_lamports_l; 71 474 : } 72 : 73 258 : return FD_EXECUTOR_INSTR_SUCCESS; 74 258 : }