LCOV - code coverage report
Current view: top level - flamenco/runtime/info - fd_instr_info.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 33 35 94.3 %
Date: 2024-11-13 11:58:15 Functions: 28 522 5.4 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_info_fd_instr_info_h
       2             : #define HEADER_fd_src_flamenco_runtime_info_fd_instr_info_h
       3             : 
       4             : #include "../../fd_flamenco_base.h"
       5             : #include "../../types/fd_types.h"
       6             : #include "../fd_borrowed_account.h"
       7             : 
       8             : // TODO: rename to _MASK
       9      678543 : #define FD_INSTR_ACCT_FLAGS_IS_SIGNER   (0x01U)
      10      527046 : #define FD_INSTR_ACCT_FLAGS_IS_WRITABLE (0x02U)
      11             : 
      12             : #define FD_INSTR_ACCT_MAX (256)
      13             : 
      14             : struct fd_instr_info {
      15             :   uchar                   program_id;
      16             :   ushort                  data_sz;
      17             :   ushort                  acct_cnt;
      18             : 
      19             :   uchar *                 data;
      20             :   fd_pubkey_t             program_id_pubkey;
      21             : 
      22             :   uchar                   acct_txn_idxs[FD_INSTR_ACCT_MAX];
      23             :   uchar                   acct_flags[FD_INSTR_ACCT_MAX];
      24             :   fd_pubkey_t             acct_pubkeys[FD_INSTR_ACCT_MAX];
      25             :   uchar                   is_duplicate[FD_INSTR_ACCT_MAX];
      26             : 
      27             :   fd_borrowed_account_t * borrowed_accounts[FD_INSTR_ACCT_MAX];
      28             : 
      29             :   /* fd_uwide representation of uint_128 */
      30             :   ulong                   starting_lamports_h;
      31             :   ulong                   starting_lamports_l;
      32             : };
      33             : 
      34             : typedef struct fd_instr_info fd_instr_info_t;
      35             : 
      36             : FD_PROTOTYPES_BEGIN
      37             : 
      38             : int
      39             : fd_txn_account_is_demotion( fd_exec_txn_ctx_t const * txn_ctx, int idx );
      40             : 
      41             : void
      42             : fd_convert_txn_instr_to_instr( fd_exec_txn_ctx_t *     txn_ctx,
      43             :                                fd_txn_instr_t const *  txn_instr,
      44             :                                fd_borrowed_account_t * borrowed_accounts,
      45             :                                fd_instr_info_t *       instr );
      46             : 
      47             : FD_FN_PURE static inline int
      48             : fd_instr_acc_is_writable_idx( fd_instr_info_t const * instr,
      49       70386 :                               ulong                   idx ) {
      50       70386 :   return !!(instr->acct_flags[idx] & FD_INSTR_ACCT_FLAGS_IS_WRITABLE);
      51       70386 : }
      52             : 
      53             : static inline int
      54        3960 : fd_instr_acc_is_writable(fd_instr_info_t const * instr, fd_pubkey_t const * acc) {
      55       22845 :   for( uchar i = 0; i < instr->acct_cnt; i++ ) {
      56       22845 :     if( memcmp( &instr->acct_pubkeys[i], acc, sizeof( fd_pubkey_t ) )==0 ) {
      57        3960 :       return fd_instr_acc_is_writable_idx( instr, i );
      58        3960 :     }
      59       22845 :   }
      60             : 
      61           0 :   return 0;
      62        3960 : }
      63             : 
      64             : FD_FN_PURE static inline int
      65             : fd_instr_acc_is_signer_idx( fd_instr_info_t const * instr,
      66      220461 :                             ulong                   idx ) {
      67      220461 :   return !!(instr->acct_flags[idx] & FD_INSTR_ACCT_FLAGS_IS_SIGNER);
      68      220461 : }
      69             : 
      70             : static inline int
      71        1062 : fd_instr_acc_is_signer(fd_instr_info_t const * instr, fd_pubkey_t const * acc) {
      72        2691 :   for( uchar i = 0; i < instr->acct_cnt; i++ ) {
      73        2691 :     if( memcmp( &instr->acct_pubkeys[i], acc, sizeof( fd_pubkey_t ) )==0 ) {
      74        1062 :       return fd_instr_acc_is_signer_idx( instr, i );
      75        1062 :     }
      76        2691 :   }
      77             : 
      78           0 :   return 0;
      79        1062 : }
      80             : 
      81             : /* https://github.com/solana-labs/solana/blob/v1.17.23/programs/system/src/system_processor.rs#L35-L41
      82             : 
      83             :    fd_instr_any_signed matches
      84             :    solana_system_program::system_processor::Address::is_signer
      85             :    Scans instruction accounts for matching signer.
      86             : 
      87             :    Returns 1 if *any* instruction account with the given pubkey is a
      88             :    signer and 0 otherwise.  Note that the same account/pubkey can be
      89             :    specified as multiple different instruction accounts that might not
      90             :    all have the signer bit. */
      91             : 
      92             : FD_FN_PURE int
      93             : fd_instr_any_signed( fd_instr_info_t const * info,
      94             :                      fd_pubkey_t const *     pubkey );
      95             : 
      96             : /* fd_instr_info_sum_account_lamports returns the sum of lamport account
      97             :    balances of all instruction accounts in the context.
      98             : 
      99             :    Aborts on integer overflow. */
     100             : 
     101             : int
     102             : fd_instr_info_sum_account_lamports( fd_instr_info_t const * instr, 
     103             :                                     ulong *                 total_lamports_h, 
     104             :                                     ulong *                 total_lamports_l );
     105             : 
     106             : static inline void
     107             : fd_instr_get_signers( fd_instr_info_t const * self,
     108       31062 :                       fd_pubkey_t const *     signers[static FD_TXN_SIG_MAX] ) {
     109       31062 :   ulong j = 0UL;
     110      199863 :   for( uchar i = 0; i < self->acct_cnt && j < FD_TXN_SIG_MAX; i++ )
     111      168801 :     if( fd_instr_acc_is_signer_idx( self, i ) )
     112       78810 :       signers[j++] = &self->acct_pubkeys[i];
     113       31062 : }
     114             : 
     115             : /* Loop conditions could be optimized to allow for unroll/vectorize */
     116             : 
     117             : static inline int
     118             : fd_instr_signers_contains( fd_pubkey_t const * signers[FD_TXN_SIG_MAX],
     119       12582 :                            fd_pubkey_t const * pubkey ) {
     120       26259 :   for( ulong i = 0; i < FD_TXN_SIG_MAX && signers[i]; i++ )
     121       20640 :     if( 0==memcmp( signers[i], pubkey, sizeof( fd_pubkey_t ) ) ) return 1;
     122        5619 :   return 0;
     123       12582 : }
     124             : 
     125             : FD_PROTOTYPES_END
     126             : 
     127             : #endif /* HEADER_fd_src_flamenco_runtime_info_fd_instr_info_h */

Generated by: LCOV version 1.14