Line data Source code
1 : #include "fd_instr_info.h" 2 : #include "../fd_runtime.h" 3 : #include "../fd_runtime_helpers.h" 4 : #include "../../../disco/fd_txn_p.h" 5 : #include "../../../util/bits/fd_uwide.h" 6 : 7 : void 8 : fd_instr_info_init_from_txn_instr( fd_instr_info_t * instr, 9 : fd_txn_in_t const * txn_in, 10 : fd_txn_out_t * txn_out, 11 126 : fd_txn_instr_t const * txn_instr ) { 12 : 13 126 : fd_txn_t const * txn_descriptor = TXN( txn_in->txn ); 14 126 : uchar * instr_acc_idxs = (uchar *)txn_in->txn->payload + txn_instr->acct_off; 15 : 16 : /* Set the stack height to 1 (since this is a top-level instruction) */ 17 126 : instr->stack_height = 1; 18 : 19 : /* Set the program id */ 20 126 : instr->program_id = txn_instr->program_id; 21 126 : instr->acct_cnt = txn_instr->acct_cnt; 22 126 : if( FD_UNLIKELY( instr->acct_cnt > FD_INSTR_ACCT_MAX ) ) { 23 0 : FD_LOG_CRIT(( "invariant violation: Instruction has too many accounts: %d > %lu", instr->acct_cnt, FD_INSTR_ACCT_MAX )); 24 0 : } 25 126 : instr->data_sz = txn_instr->data_sz; 26 126 : memcpy( instr->data, txn_in->txn->payload+txn_instr->data_off, instr->data_sz ); 27 : 28 126 : uchar acc_idx_seen[ FD_TXN_ACCT_ADDR_MAX ] = {0}; 29 : 30 5889 : for( ushort i=0; i<instr->acct_cnt; i++ ) { 31 5763 : ushort acc_idx = instr_acc_idxs[i]; 32 : 33 5763 : fd_instr_info_setup_instr_account( instr, 34 5763 : acc_idx_seen, 35 5763 : acc_idx, 36 5763 : acc_idx, 37 5763 : i, 38 5763 : (uchar)fd_runtime_account_is_writable_idx( txn_in, txn_out, instr_acc_idxs[i] ), 39 5763 : (uchar)fd_txn_is_signer( txn_descriptor, instr_acc_idxs[i] ) ); 40 : 41 5763 : } 42 126 : } 43 : 44 : int 45 : fd_instr_info_sum_account_lamports( fd_instr_info_t const * instr, 46 : fd_txn_out_t * txn_out, 47 : ulong * total_lamports_h, 48 8316 : ulong * total_lamports_l ) { 49 8316 : *total_lamports_h = 0UL; 50 8316 : *total_lamports_l = 0UL; 51 34098 : for( ulong i=0UL; i<instr->acct_cnt; ++i ) { 52 25782 : ushort idx_in_txn = instr->accounts[i].index_in_transaction; 53 25782 : fd_acc_t const * ref = txn_out->accounts.account[ idx_in_txn ]; 54 : 55 25782 : if( instr->is_duplicate[i] ) { 56 11508 : continue; 57 11508 : } 58 : 59 : /* Perform a checked add on a fd_uwide */ 60 14274 : ulong tmp_total_lamports_h = 0UL; 61 14274 : ulong tmp_total_lamports_l = 0UL; 62 : 63 14274 : fd_uwide_inc( &tmp_total_lamports_h, &tmp_total_lamports_l, 64 14274 : *total_lamports_h, *total_lamports_l, 65 14274 : ref->lamports ); 66 : 67 14274 : if( tmp_total_lamports_h < *total_lamports_h ) { 68 0 : return FD_EXECUTOR_INSTR_ERR_ARITHMETIC_OVERFLOW; 69 0 : } 70 : 71 14274 : *total_lamports_h = tmp_total_lamports_h; 72 14274 : *total_lamports_l = tmp_total_lamports_l; 73 14274 : } 74 : 75 8316 : return FD_EXECUTOR_INSTR_SUCCESS; 76 8316 : }