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