LCOV - code coverage report
Current view: top level - flamenco/runtime/tests - fd_harness_common.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 91 0.0 %
Date: 2026-04-15 06:25:28 Functions: 0 7 0.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 "../../features/fd_features.h"
       7             : #include "../../accdb/fd_accdb_sync.h"
       8             : #include <assert.h>
       9             : 
      10             : void
      11             : fd_solfuzz_pb_restore_fee_rate_governor( fd_bank_t *                              bank,
      12           0 :                                          fd_exec_test_fee_rate_governor_t const * fee_rate_governor ) {
      13           0 :   fd_fee_rate_governor_t * frg = &bank->f.fee_rate_governor;
      14           0 :   *frg = (fd_fee_rate_governor_t){
      15           0 :     .target_lamports_per_signature = fee_rate_governor->target_lamports_per_signature,
      16           0 :     .target_signatures_per_slot    = fee_rate_governor->target_signatures_per_slot,
      17           0 :     .min_lamports_per_signature    = fee_rate_governor->min_lamports_per_signature,
      18           0 :     .max_lamports_per_signature    = fee_rate_governor->max_lamports_per_signature,
      19           0 :     .burn_percent                  = (uchar)fee_rate_governor->burn_percent,
      20           0 :   };
      21           0 : }
      22             : 
      23             : void
      24             : fd_solfuzz_pb_restore_epoch_schedule( fd_bank_t *                           bank,
      25           0 :                                       fd_exec_test_epoch_schedule_t const * epoch_schedule ) {
      26           0 :   fd_epoch_schedule_t * es = &bank->f.epoch_schedule;
      27           0 :   *es = (fd_epoch_schedule_t){
      28           0 :     .slots_per_epoch             = epoch_schedule->slots_per_epoch,
      29           0 :     .leader_schedule_slot_offset = epoch_schedule->leader_schedule_slot_offset,
      30           0 :     .warmup                      = epoch_schedule->warmup,
      31           0 :     .first_normal_epoch          = epoch_schedule->first_normal_epoch,
      32           0 :     .first_normal_slot           = epoch_schedule->first_normal_slot,
      33           0 :   };
      34           0 : }
      35             : 
      36             : void
      37             : fd_solfuzz_pb_restore_blockhash_queue( fd_bank_t *                                    bank,
      38             :                                        fd_exec_test_blockhash_queue_entry_t const *   entries,
      39           0 :                                        ulong                                          entries_cnt ) {
      40           0 :   ulong blockhash_seed; FD_TEST( fd_rng_secure( &blockhash_seed, sizeof(ulong) ) );
      41           0 :   fd_blockhashes_t * blockhashes = fd_blockhashes_init( &bank->f.block_hash_queue, blockhash_seed );
      42           0 :   for( ulong i=0UL; i<entries_cnt; i++ ) {
      43           0 :     fd_hash_t hash                   = FD_LOAD( fd_hash_t, entries[i].blockhash );
      44           0 :     ulong     lamports_per_signature = entries[i].lamports_per_signature;
      45             : 
      46           0 :     fd_blockhash_info_t * blockhash = fd_blockhashes_push_new( blockhashes, &hash );
      47           0 :     blockhash->fee_calculator = (fd_fee_calculator_t){
      48           0 :       .lamports_per_signature = lamports_per_signature
      49           0 :     };
      50           0 :   }
      51           0 : }
      52             : 
      53             : ulong
      54             : fd_solfuzz_pb_get_slot( fd_exec_test_acct_state_t const * acct_states,
      55           0 :                         ulong                             acct_states_cnt ) {
      56           0 :   for( ulong i=0UL; i<acct_states_cnt; i++ ) {
      57           0 :     if( !memcmp( &acct_states[i].address, &fd_sysvar_clock_id, sizeof(fd_pubkey_t) ) ) {
      58           0 :       FD_TEST( acct_states[i].data->size==sizeof(fd_sol_sysvar_clock_t) );
      59           0 :       return FD_LOAD( ulong, acct_states[i].data->bytes );
      60           0 :     }
      61           0 :   }
      62           0 :   FD_LOG_ERR(( "invariant violation: clock sysvar account not found in acct states" ));
      63           0 : }
      64             : 
      65             : int
      66             : fd_solfuzz_pb_load_account( fd_runtime_t *                    runtime,
      67             :                             fd_accdb_user_t *                 accdb,
      68             :                             fd_funk_txn_xid_t const *         xid,
      69             :                             fd_exec_test_acct_state_t const * state,
      70           0 :                             ulong                             acc_idx ) {
      71           0 :   if( state->lamports==0UL ) return 0;
      72             : 
      73           0 :   ulong size = 0UL;
      74           0 :   if( state->data ) size = state->data->size;
      75             : 
      76           0 :   fd_pubkey_t pubkey[1];  memcpy( pubkey, state->address, sizeof(fd_pubkey_t) );
      77             : 
      78             :   /* Account must not yet exist */
      79           0 :   fd_accdb_ro_t ro[1];
      80           0 :   if( FD_UNLIKELY( fd_accdb_open_ro( accdb, ro, xid, pubkey ) ) ) {
      81           0 :     fd_accdb_close_ro( accdb, ro );
      82           0 :     return 0;
      83           0 :   }
      84             : 
      85           0 :   fd_accdb_rw_t rw[1];
      86           0 :   fd_accdb_open_rw( accdb, rw, xid, pubkey, size, FD_ACCDB_FLAG_CREATE );
      87           0 :   if( state->data ) {
      88           0 :     fd_accdb_ref_data_set( accdb, rw, state->data->bytes, size );
      89           0 :   }
      90           0 :   runtime->accounts.starting_lamports[ acc_idx ] = state->lamports;
      91           0 :   runtime->accounts.starting_dlen    [ acc_idx ] = size;
      92           0 :   fd_accdb_ref_lamports_set( rw, state->lamports   );
      93           0 :   fd_accdb_ref_exec_bit_set( rw, state->executable );
      94           0 :   fd_accdb_ref_owner_set   ( rw, state->owner      );
      95           0 :   fd_accdb_close_rw( accdb, rw );
      96             : 
      97           0 :   return 1;
      98           0 : }
      99             : 
     100             : int
     101             : fd_solfuzz_pb_restore_features( fd_features_t *                    features,
     102           0 :                                 fd_exec_test_feature_set_t const * feature_set ) {
     103           0 :   fd_features_disable_all( features );
     104           0 :   for( ulong j=0UL; j < feature_set->features_count; j++ ) {
     105           0 :     ulong                   prefix = feature_set->features[j];
     106           0 :     fd_feature_id_t const * id     = fd_feature_id_query( prefix );
     107           0 :     if( FD_UNLIKELY( !id ) ) {
     108           0 :       FD_LOG_WARNING(( "unsupported feature ID 0x%016lx", prefix ));
     109           0 :       return 0;
     110           0 :     }
     111             :     /* Enabled since genesis */
     112           0 :     fd_features_set( features, id, 0UL );
     113           0 :   }
     114           0 :   return 1;
     115           0 : }
     116             : 
     117             : #if FD_HAS_FLATCC
     118             : 
     119             : void
     120             : fd_solfuzz_fb_restore_features( fd_features_t *                    features,
     121           0 :                                 SOL_COMPAT_NS(FeatureSet_table_t)  feature_set ) {
     122           0 :   if( FD_UNLIKELY( !feature_set ) ) return;
     123             : 
     124           0 :   fd_features_disable_all( features );
     125           0 :   flatbuffers_uint64_vec_t input_features     = SOL_COMPAT_NS(FeatureSet_features( feature_set ));
     126           0 :   ulong                    input_features_cnt = flatbuffers_uint64_vec_len( input_features );
     127           0 :   for( ulong i=0UL; i<input_features_cnt; i++ ) {
     128           0 :     ulong                   prefix = flatbuffers_uint64_vec_at( input_features, i );
     129           0 :     fd_feature_id_t const * id     = fd_feature_id_query( prefix );
     130           0 :     if( FD_UNLIKELY( !id ) ) {
     131           0 :       FD_LOG_ERR(( "unsupported feature ID 0x%016lx", prefix ));
     132           0 :     }
     133             :     /* Enabled since genesis */
     134           0 :     fd_features_set( features, id, 0UL );
     135           0 :   }
     136           0 : }
     137             : 
     138             : #endif /* FD_HAS_FLATCC */

Generated by: LCOV version 1.14