LCOV - code coverage report
Current view: top level - flamenco/runtime/tests - fd_harness_common.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 92 99 92.9 %
Date: 2026-03-19 18:19:27 Functions: 8 8 100.0 %

          Line data    Source code
       1             : #include "fd_solfuzz_private.h"
       2             : #include "generated/context.pb.h"
       3             : #include "../fd_runtime.h"
       4             : #include "../fd_bank.h"
       5             : #include "../fd_system_ids.h"
       6             : #include "../sysvar/fd_sysvar_clock.h"
       7             : #include "../../features/fd_features.h"
       8             : #include "../../accdb/fd_accdb_sync.h"
       9             : #include <assert.h>
      10             : 
      11             : void
      12             : fd_solfuzz_pb_restore_fee_rate_governor( fd_bank_t *                              bank,
      13        5542 :                                          fd_exec_test_fee_rate_governor_t const * fee_rate_governor ) {
      14        5542 :   fd_fee_rate_governor_t * frg = fd_bank_fee_rate_governor_modify( bank );
      15        5542 :   *frg = (fd_fee_rate_governor_t){
      16        5542 :     .target_lamports_per_signature = fee_rate_governor->target_lamports_per_signature,
      17        5542 :     .target_signatures_per_slot    = fee_rate_governor->target_signatures_per_slot,
      18        5542 :     .min_lamports_per_signature    = fee_rate_governor->min_lamports_per_signature,
      19        5542 :     .max_lamports_per_signature    = fee_rate_governor->max_lamports_per_signature,
      20        5542 :     .burn_percent                  = (uchar)fee_rate_governor->burn_percent,
      21        5542 :   };
      22        5542 : }
      23             : 
      24             : void
      25             : fd_solfuzz_pb_restore_epoch_schedule( fd_bank_t *                           bank,
      26        5543 :                                       fd_exec_test_epoch_schedule_t const * epoch_schedule ) {
      27        5543 :   fd_epoch_schedule_t * es = fd_bank_epoch_schedule_modify( bank );
      28        5543 :   *es = (fd_epoch_schedule_t){
      29        5543 :     .slots_per_epoch             = epoch_schedule->slots_per_epoch,
      30        5543 :     .leader_schedule_slot_offset = epoch_schedule->leader_schedule_slot_offset,
      31        5543 :     .warmup                      = epoch_schedule->warmup,
      32        5543 :     .first_normal_epoch          = epoch_schedule->first_normal_epoch,
      33        5543 :     .first_normal_slot           = epoch_schedule->first_normal_slot,
      34        5543 :   };
      35        5543 : }
      36             : 
      37             : void
      38             : fd_solfuzz_pb_restore_rent( fd_bank_t *                 bank,
      39        5542 :                             fd_exec_test_rent_t const * rent ) {
      40        5542 :   fd_rent_t * r = fd_bank_rent_modify( bank );
      41        5542 :   *r = (fd_rent_t){
      42        5542 :     .lamports_per_uint8_year = rent->lamports_per_byte_year,
      43        5542 :     .exemption_threshold     = rent->exemption_threshold,
      44        5542 :     .burn_percent            = (uchar)rent->burn_percent,
      45        5542 :   };
      46        5542 : }
      47             : 
      48             : void
      49             : fd_solfuzz_pb_restore_blockhash_queue( fd_bank_t *                                    bank,
      50             :                                        fd_exec_test_blockhash_queue_entry_t const *   entries,
      51        5543 :                                        ulong                                          entries_cnt ) {
      52        5543 :   ulong blockhash_seed; FD_TEST( fd_rng_secure( &blockhash_seed, sizeof(ulong) ) );
      53        5543 :   fd_blockhashes_t * blockhashes = fd_blockhashes_init( fd_bank_block_hash_queue_modify( bank ), blockhash_seed );
      54      514816 :   for( ulong i=0UL; i<entries_cnt; i++ ) {
      55      509273 :     fd_hash_t hash                   = FD_LOAD( fd_hash_t, entries[i].blockhash );
      56      509273 :     ulong     lamports_per_signature = entries[i].lamports_per_signature;
      57             : 
      58      509273 :     fd_blockhash_info_t * blockhash = fd_blockhashes_push_new( blockhashes, &hash );
      59      509273 :     blockhash->fee_calculator = (fd_fee_calculator_t){
      60      509273 :       .lamports_per_signature = lamports_per_signature
      61      509273 :     };
      62      509273 :   }
      63        5543 : }
      64             : 
      65             : ulong
      66             : fd_solfuzz_pb_get_slot( fd_exec_test_acct_state_t const * acct_states,
      67        5227 :                         ulong                             acct_states_cnt ) {
      68       25127 :   for( ulong i=0UL; i<acct_states_cnt; i++ ) {
      69       25127 :     if( !memcmp( &acct_states[i].address, &fd_sysvar_clock_id, sizeof(fd_pubkey_t) ) ) {
      70        5227 :       FD_TEST( acct_states[i].data->size==sizeof(fd_sol_sysvar_clock_t) );
      71        5227 :       return FD_LOAD( ulong, acct_states[i].data->bytes );
      72        5227 :     }
      73       25127 :   }
      74           0 :   FD_LOG_ERR(( "invariant violation: clock sysvar account not found in acct states" ));
      75           0 : }
      76             : 
      77             : int
      78             : fd_solfuzz_pb_load_account( fd_runtime_t *                    runtime,
      79             :                             fd_accdb_user_t *                 accdb,
      80             :                             fd_funk_txn_xid_t const *         xid,
      81             :                             fd_exec_test_acct_state_t const * state,
      82      128208 :                             ulong                             acc_idx ) {
      83      128208 :   if( state->lamports==0UL ) return 0;
      84             : 
      85      128044 :   ulong size = 0UL;
      86      128044 :   if( state->data ) size = state->data->size;
      87             : 
      88      128044 :   fd_pubkey_t pubkey[1];  memcpy( pubkey, state->address, sizeof(fd_pubkey_t) );
      89             : 
      90             :   /* Account must not yet exist */
      91      128044 :   fd_accdb_ro_t ro[1];
      92      128044 :   if( FD_UNLIKELY( fd_accdb_open_ro( accdb, ro, xid, pubkey ) ) ) {
      93           1 :     fd_accdb_close_ro( accdb, ro );
      94           1 :     return 0;
      95           1 :   }
      96             : 
      97      128043 :   fd_accdb_rw_t rw[1];
      98      128043 :   fd_accdb_open_rw( accdb, rw, xid, pubkey, size, FD_ACCDB_FLAG_CREATE );
      99      128043 :   if( state->data ) {
     100      101131 :     fd_accdb_ref_data_set( accdb, rw, state->data->bytes, size );
     101      101131 :   }
     102      128043 :   runtime->accounts.starting_lamports[ acc_idx ] = state->lamports;
     103      128043 :   runtime->accounts.starting_dlen    [ acc_idx ] = size;
     104      128043 :   fd_accdb_ref_lamports_set( rw, state->lamports   );
     105      128043 :   fd_accdb_ref_exec_bit_set( rw, state->executable );
     106      128043 :   fd_accdb_ref_owner_set   ( rw, state->owner      );
     107      128043 :   fd_accdb_close_rw( accdb, rw );
     108             : 
     109      128043 :   return 1;
     110      128044 : }
     111             : 
     112             : int
     113             : fd_solfuzz_pb_restore_features( fd_features_t *                    features,
     114       30115 :                                 fd_exec_test_feature_set_t const * feature_set ) {
     115       30115 :   fd_features_disable_all( features );
     116     4969505 :   for( ulong j=0UL; j < feature_set->features_count; j++ ) {
     117     4939390 :     ulong                   prefix = feature_set->features[j];
     118     4939390 :     fd_feature_id_t const * id     = fd_feature_id_query( prefix );
     119     4939390 :     if( FD_UNLIKELY( !id ) ) {
     120           0 :       FD_LOG_WARNING(( "unsupported feature ID 0x%016lx", prefix ));
     121           0 :       return 0;
     122           0 :     }
     123             :     /* Enabled since genesis */
     124     4939390 :     fd_features_set( features, id, 0UL );
     125     4939390 :   }
     126       30115 :   return 1;
     127       30115 : }
     128             : 
     129             : #if FD_HAS_FLATCC
     130             : 
     131             : void
     132             : fd_solfuzz_fb_restore_features( fd_features_t *                    features,
     133         949 :                                 SOL_COMPAT_NS(FeatureSet_table_t)  feature_set ) {
     134         949 :   if( FD_UNLIKELY( !feature_set ) ) return;
     135             : 
     136         949 :   fd_features_disable_all( features );
     137         949 :   flatbuffers_uint64_vec_t input_features     = SOL_COMPAT_NS(FeatureSet_features( feature_set ));
     138         949 :   ulong                    input_features_cnt = flatbuffers_uint64_vec_len( input_features );
     139      144992 :   for( ulong i=0UL; i<input_features_cnt; i++ ) {
     140      144043 :     ulong                   prefix = flatbuffers_uint64_vec_at( input_features, i );
     141      144043 :     fd_feature_id_t const * id     = fd_feature_id_query( prefix );
     142      144043 :     if( FD_UNLIKELY( !id ) ) {
     143           0 :       FD_LOG_ERR(( "unsupported feature ID 0x%016lx", prefix ));
     144           0 :     }
     145             :     /* Enabled since genesis */
     146      144043 :     fd_features_set( features, id, 0UL );
     147      144043 :   }
     148         949 : }
     149             : 
     150             : #endif /* FD_HAS_FLATCC */

Generated by: LCOV version 1.14