Line data Source code
1 : #include "fd_solfuzz_private.h" 2 : #include "generated/context.pb.h" 3 : #include "../fd_acc_mgr.h" 4 : #include "../../features/fd_features.h" 5 : #include "../../accdb/fd_accdb_impl_v1.h" 6 : #include <assert.h> 7 : 8 : int 9 : fd_solfuzz_pb_load_account( fd_txn_account_t * acc, 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 : uchar reject_zero_lamports ) { 14 0 : if( reject_zero_lamports && state->lamports==0UL ) { 15 0 : return 0; 16 0 : } 17 : 18 0 : ulong size = 0UL; 19 0 : if( state->data ) size = state->data->size; 20 : 21 0 : fd_pubkey_t pubkey[1]; memcpy( pubkey, state->address, sizeof(fd_pubkey_t) ); 22 : 23 : /* Account must not yet exist */ 24 0 : fd_funk_t * funk = fd_accdb_user_v1_funk( accdb ); 25 0 : if( FD_UNLIKELY( fd_funk_get_acc_meta_readonly( funk, xid, pubkey, NULL, NULL, NULL) ) ) { 26 0 : return 0; 27 0 : } 28 : 29 0 : fd_funk_rec_prepare_t prepare = {0}; 30 : 31 0 : int ok = !!fd_txn_account_init_from_funk_mutable( /* acc */ acc, 32 0 : /* pubkey */ pubkey, 33 0 : /* funk */ accdb, 34 0 : /* xid */ xid, 35 0 : /* do_create */ 1, 36 0 : /* min_data_sz */ size, 37 0 : /* prepare */ &prepare ); 38 0 : assert( ok ); 39 : 40 0 : if( state->data ) { 41 0 : fd_txn_account_set_data( acc, state->data->bytes, size ); 42 0 : } 43 : 44 0 : acc->starting_lamports = state->lamports; 45 0 : acc->starting_dlen = size; 46 0 : fd_txn_account_set_lamports( acc, state->lamports ); 47 0 : fd_txn_account_set_executable( acc, state->executable ); 48 0 : fd_txn_account_set_owner( acc, (fd_pubkey_t const *)state->owner ); 49 : 50 : /* make the account read-only by default */ 51 0 : fd_txn_account_set_readonly( acc ); 52 : 53 0 : fd_txn_account_mutable_fini( acc, accdb, &prepare ); 54 : 55 0 : return 1; 56 0 : } 57 : 58 : int 59 : fd_solfuzz_pb_restore_features( fd_features_t * features, 60 0 : fd_exec_test_feature_set_t const * feature_set ) { 61 0 : fd_features_disable_all( features ); 62 0 : for( ulong j=0UL; j < feature_set->features_count; j++ ) { 63 0 : ulong prefix = feature_set->features[j]; 64 0 : fd_feature_id_t const * id = fd_feature_id_query( prefix ); 65 0 : if( FD_UNLIKELY( !id ) ) { 66 0 : FD_LOG_WARNING(( "unsupported feature ID 0x%016lx", prefix )); 67 0 : return 0; 68 0 : } 69 : /* Enabled since genesis */ 70 0 : fd_features_set( features, id, 0UL ); 71 0 : } 72 0 : return 1; 73 0 : } 74 : 75 : #if FD_HAS_FLATCC 76 : 77 : void 78 : fd_solfuzz_fb_restore_features( fd_features_t * features, 79 0 : SOL_COMPAT_NS(FeatureSet_table_t) feature_set ) { 80 0 : if( FD_UNLIKELY( !feature_set ) ) return; 81 : 82 0 : fd_features_disable_all( features ); 83 0 : flatbuffers_uint64_vec_t input_features = SOL_COMPAT_NS(FeatureSet_features( feature_set )); 84 0 : ulong input_features_cnt = flatbuffers_uint64_vec_len( input_features ); 85 0 : for( ulong i=0UL; i<input_features_cnt; i++ ) { 86 0 : ulong prefix = flatbuffers_uint64_vec_at( input_features, i ); 87 0 : fd_feature_id_t const * id = fd_feature_id_query( prefix ); 88 0 : if( FD_UNLIKELY( !id ) ) { 89 0 : FD_LOG_ERR(( "unsupported feature ID 0x%016lx", prefix )); 90 0 : } 91 : /* Enabled since genesis */ 92 0 : fd_features_set( features, id, 0UL ); 93 0 : } 94 0 : } 95 : 96 : #endif /* FD_HAS_FLATCC */