Line data Source code
1 : #include "generated/context.pb.h" 2 : #include "../fd_acc_mgr.h" 3 : #include "../../features/fd_features.h" 4 : #include <assert.h> 5 : 6 : int 7 : fd_runtime_fuzz_load_account( fd_txn_account_t * acc, 8 : fd_accdb_user_t * accdb, 9 : fd_funk_txn_xid_t const * xid, 10 : fd_exec_test_acct_state_t const * state, 11 0 : uchar reject_zero_lamports ) { 12 0 : if( reject_zero_lamports && state->lamports==0UL ) { 13 0 : return 0; 14 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 : if( FD_UNLIKELY( fd_funk_get_acc_meta_readonly( accdb->funk, xid, pubkey, NULL, NULL, NULL) ) ) { 23 0 : return 0; 24 0 : } 25 : 26 0 : fd_funk_rec_prepare_t prepare = {0}; 27 : 28 0 : int ok = !!fd_txn_account_init_from_funk_mutable( /* acc */ acc, 29 0 : /* pubkey */ pubkey, 30 0 : /* funk */ accdb, 31 0 : /* xid */ xid, 32 0 : /* do_create */ 1, 33 0 : /* min_data_sz */ size, 34 0 : /* prepare */ &prepare ); 35 0 : assert( ok ); 36 : 37 0 : if( state->data ) { 38 0 : fd_txn_account_set_data( acc, state->data->bytes, size ); 39 0 : } 40 : 41 0 : acc->starting_lamports = state->lamports; 42 0 : acc->starting_dlen = size; 43 0 : fd_txn_account_set_lamports( acc, state->lamports ); 44 0 : fd_txn_account_set_executable( acc, state->executable ); 45 0 : fd_txn_account_set_owner( acc, (fd_pubkey_t const *)state->owner ); 46 : 47 : /* make the account read-only by default */ 48 0 : fd_txn_account_set_readonly( acc ); 49 : 50 0 : fd_txn_account_mutable_fini( acc, accdb, &prepare ); 51 : 52 0 : return 1; 53 0 : } 54 : 55 : int 56 : fd_runtime_fuzz_restore_features( fd_features_t * features, 57 0 : fd_exec_test_feature_set_t const * feature_set ) { 58 0 : fd_features_disable_all( features ); 59 0 : for( ulong j=0UL; j < feature_set->features_count; j++ ) { 60 0 : ulong prefix = feature_set->features[j]; 61 0 : fd_feature_id_t const * id = fd_feature_id_query( prefix ); 62 0 : if( FD_UNLIKELY( !id ) ) { 63 0 : FD_LOG_WARNING(( "unsupported feature ID 0x%016lx", prefix )); 64 0 : return 0; 65 0 : } 66 : /* Enabled since genesis */ 67 0 : fd_features_set( features, id, 0UL ); 68 0 : } 69 0 : return 1; 70 0 : }