Line data Source code
1 : #include "fd_solfuzz_private.h" 2 : #include "generated/context.pb.h" 3 : #include "../fd_runtime.h" 4 : #include "../../features/fd_features.h" 5 : #include "../../accdb/fd_accdb_sync.h" 6 : #include <assert.h> 7 : 8 : int 9 : fd_solfuzz_pb_load_account( fd_runtime_t * runtime, 10 : fd_accdb_user_t * accdb, 11 : fd_funk_txn_xid_t const * xid, 12 : fd_exec_test_acct_state_t const * state, 13 0 : ulong acc_idx ) { 14 0 : if( state->lamports==0UL ) return 0; 15 : 16 0 : ulong size = 0UL; 17 0 : if( state->data ) size = state->data->size; 18 : 19 0 : fd_pubkey_t pubkey[1]; memcpy( pubkey, state->address, sizeof(fd_pubkey_t) ); 20 : 21 : /* Account must not yet exist */ 22 0 : fd_accdb_ro_t ro[1]; 23 0 : if( FD_UNLIKELY( fd_accdb_open_ro( accdb, ro, xid, pubkey ) ) ) { 24 0 : fd_accdb_close_ro( accdb, ro ); 25 0 : return 0; 26 0 : } 27 : 28 0 : fd_accdb_rw_t rw[1]; 29 0 : fd_accdb_open_rw( accdb, rw, xid, pubkey, size, FD_ACCDB_FLAG_CREATE ); 30 0 : if( state->data ) { 31 0 : fd_accdb_ref_data_set( accdb, rw, state->data->bytes, size ); 32 0 : } 33 0 : runtime->accounts.starting_lamports[ acc_idx ] = state->lamports; 34 0 : runtime->accounts.starting_dlen [ acc_idx ] = size; 35 0 : fd_accdb_ref_lamports_set( rw, state->lamports ); 36 0 : fd_accdb_ref_exec_bit_set( rw, state->executable ); 37 0 : fd_accdb_ref_owner_set ( rw, state->owner ); 38 0 : fd_accdb_close_rw( accdb, rw ); 39 : 40 0 : return 1; 41 0 : } 42 : 43 : int 44 : fd_solfuzz_pb_restore_features( fd_features_t * features, 45 0 : fd_exec_test_feature_set_t const * feature_set ) { 46 0 : fd_features_disable_all( features ); 47 0 : for( ulong j=0UL; j < feature_set->features_count; j++ ) { 48 0 : ulong prefix = feature_set->features[j]; 49 0 : fd_feature_id_t const * id = fd_feature_id_query( prefix ); 50 0 : if( FD_UNLIKELY( !id ) ) { 51 0 : FD_LOG_WARNING(( "unsupported feature ID 0x%016lx", prefix )); 52 0 : return 0; 53 0 : } 54 : /* Enabled since genesis */ 55 0 : fd_features_set( features, id, 0UL ); 56 0 : } 57 0 : return 1; 58 0 : } 59 : 60 : #if FD_HAS_FLATCC 61 : 62 : void 63 : fd_solfuzz_fb_restore_features( fd_features_t * features, 64 0 : SOL_COMPAT_NS(FeatureSet_table_t) feature_set ) { 65 0 : if( FD_UNLIKELY( !feature_set ) ) return; 66 : 67 0 : fd_features_disable_all( features ); 68 0 : flatbuffers_uint64_vec_t input_features = SOL_COMPAT_NS(FeatureSet_features( feature_set )); 69 0 : ulong input_features_cnt = flatbuffers_uint64_vec_len( input_features ); 70 0 : for( ulong i=0UL; i<input_features_cnt; i++ ) { 71 0 : ulong prefix = flatbuffers_uint64_vec_at( input_features, i ); 72 0 : fd_feature_id_t const * id = fd_feature_id_query( prefix ); 73 0 : if( FD_UNLIKELY( !id ) ) { 74 0 : FD_LOG_ERR(( "unsupported feature ID 0x%016lx", prefix )); 75 0 : } 76 : /* Enabled since genesis */ 77 0 : fd_features_set( features, id, 0UL ); 78 0 : } 79 0 : } 80 : 81 : #endif /* FD_HAS_FLATCC */