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