LCOV - code coverage report
Current view: top level - flamenco/runtime/info - fd_instr_info.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 59 63 93.7 %
Date: 2025-01-08 12:08:44 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "fd_instr_info.h"
       2             : 
       3             : #include "../fd_account.h"
       4             : #include "../../../util/bits/fd_uwide.h"
       5             : 
       6             : void
       7             : fd_convert_txn_instr_to_instr( fd_exec_txn_ctx_t *     txn_ctx,
       8             :                                fd_txn_instr_t const *  txn_instr,
       9             :                                fd_borrowed_account_t * borrowed_accounts,
      10       11340 :                                fd_instr_info_t *       instr ) {
      11             : 
      12       11340 :   fd_txn_t const *      txn_descriptor = txn_ctx->txn_descriptor;
      13       11340 :   fd_rawtxn_b_t const * txn_raw = txn_ctx->_txn_raw;
      14       11340 :   const fd_pubkey_t *   accounts = txn_ctx->accounts;
      15             : 
      16       11340 :   instr->program_id        = txn_instr->program_id;
      17       11340 :   instr->program_id_pubkey = accounts[txn_instr->program_id];
      18       11340 :   instr->acct_cnt          = txn_instr->acct_cnt;
      19       11340 :   instr->data_sz           = txn_instr->data_sz;
      20       11340 :   instr->data              = (uchar *)txn_raw->raw + txn_instr->data_off;
      21             : 
      22       11340 :   uchar acc_idx_seen[256];
      23       11340 :   memset(acc_idx_seen, 0, 256);
      24       11340 :   uchar * instr_acc_idxs = (uchar *)txn_raw->raw + txn_instr->acct_off;
      25       49719 :   for( ulong i = 0; i < instr->acct_cnt; i++ ) {
      26       38379 :     if( borrowed_accounts != NULL ) {
      27       38379 :       instr->borrowed_accounts[i] = &borrowed_accounts[instr_acc_idxs[i]];
      28       38379 :     } else {
      29           0 :       instr->borrowed_accounts[i] = NULL;
      30           0 :     }
      31             : 
      32       38379 :     uchar acc_idx = instr_acc_idxs[i];
      33             : 
      34       38379 :     instr->is_duplicate[i] = acc_idx_seen[acc_idx];
      35       38379 :     if( FD_LIKELY( !acc_idx_seen[acc_idx] ) ) {
      36             :       /* This is the first time seeing this account */
      37       36510 :       acc_idx_seen[acc_idx] = 1;
      38       36510 :     }
      39             : 
      40       38379 :     instr->acct_txn_idxs[i] = acc_idx;
      41       38379 :     instr->acct_pubkeys[i] = accounts[instr_acc_idxs[i]];
      42       38379 :     instr->acct_flags[i] = 0;
      43       38379 :     if( fd_txn_account_is_writable_idx( txn_ctx, (int)instr_acc_idxs[i]) ) {
      44       14742 :         instr->acct_flags[i] |= FD_INSTR_ACCT_FLAGS_IS_WRITABLE;
      45       14742 :     }
      46       38379 :     if( fd_txn_is_signer( txn_descriptor, instr_acc_idxs[i] ) ) {
      47       19752 :       instr->acct_flags[i] |= FD_INSTR_ACCT_FLAGS_IS_SIGNER;
      48       19752 :     }
      49       38379 :   }
      50       11340 : }
      51             : 
      52             : int
      53             : fd_instr_any_signed( fd_instr_info_t const * info,
      54        7230 :                      fd_pubkey_t const *     pubkey ) {
      55        7230 :   int is_signer = 0;
      56       32985 :   for( ulong j=0UL; j < info->acct_cnt; j++ )
      57       25755 :     is_signer |=
      58       25755 :       ( ( !!fd_instr_acc_is_signer_idx( info, j ) ) &
      59       25755 :         ( 0==memcmp( pubkey->key, info->acct_pubkeys[j].key, sizeof(fd_pubkey_t) ) ) );
      60        7230 :   return is_signer;
      61        7230 : }
      62             : 
      63             : /* https://github.com/anza-xyz/agave/blob/9706a6464665f7ebd6ead47f0d12f853ccacbab9/sdk/src/transaction_context.rs#L40 */
      64             : int
      65             : fd_instr_info_sum_account_lamports( fd_instr_info_t const * instr, 
      66             :                                     ulong *                 total_lamports_h, 
      67      558177 :                                     ulong *                 total_lamports_l ) {
      68      558177 :   *total_lamports_h = 0UL;
      69      558177 :   *total_lamports_l = 0UL;
      70     1884885 :   for( ulong i=0UL; i<instr->acct_cnt; ++i ) {
      71     1326708 :     if( instr->borrowed_accounts[i] == NULL || 
      72     1326708 :         instr->is_duplicate[i]              || 
      73     1326708 :         instr->borrowed_accounts[i]->const_meta == NULL ) {
      74       61530 :       continue;
      75       61530 :     }
      76             : 
      77             :     /* Perform a checked add on a fd_uwide */
      78     1265178 :     ulong tmp_total_lamports_h = 0UL;
      79     1265178 :     ulong tmp_total_lamports_l = 0UL;
      80             : 
      81     1265178 :     fd_uwide_inc( &tmp_total_lamports_h, &tmp_total_lamports_l, *total_lamports_h, *total_lamports_l,
      82     1265178 :                   instr->borrowed_accounts[i]->const_meta->info.lamports );
      83             :     
      84     1265178 :     if( tmp_total_lamports_h < *total_lamports_h ) {
      85           0 :       return FD_EXECUTOR_INSTR_ERR_ARITHMETIC_OVERFLOW;
      86           0 :     }
      87             : 
      88     1265178 :     *total_lamports_h = tmp_total_lamports_h;
      89     1265178 :     *total_lamports_l = tmp_total_lamports_l;
      90     1265178 :   }
      91             : 
      92      558177 :   return FD_EXECUTOR_INSTR_SUCCESS;
      93      558177 : }

Generated by: LCOV version 1.14