LCOV - code coverage report
Current view: top level - flamenco/runtime/info - fd_instr_info.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 17 52 32.7 %
Date: 2025-12-28 05:17:03 Functions: 1 3 33.3 %

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

Generated by: LCOV version 1.14