Line data Source code
1 : #include "../program/fd_program_cache.h"
2 : #include "generated/context.pb.h"
3 : #include <assert.h>
4 :
5 : int
6 : fd_runtime_fuzz_load_account( fd_txn_account_t * acc,
7 : fd_funk_t * funk,
8 : fd_funk_txn_t * funk_txn,
9 : fd_exec_test_acct_state_t const * state,
10 0 : uchar reject_zero_lamports ) {
11 0 : if( reject_zero_lamports && state->lamports==0UL ) {
12 0 : return 0;
13 0 : }
14 :
15 0 : ulong size = 0UL;
16 0 : if( state->data ) size = state->data->size;
17 :
18 0 : fd_pubkey_t pubkey[1]; memcpy( pubkey, state->address, sizeof(fd_pubkey_t) );
19 :
20 : /* Account must not yet exist */
21 0 : if( FD_UNLIKELY( fd_funk_get_acc_meta_readonly( funk, funk_txn, pubkey, NULL, NULL, NULL) ) ) {
22 0 : return 0;
23 0 : }
24 :
25 0 : fd_funk_rec_prepare_t prepare = {0};
26 :
27 0 : assert( funk );
28 0 : int err = fd_txn_account_init_from_funk_mutable( /* acc */ acc,
29 0 : /* pubkey */ pubkey,
30 0 : /* funk */ funk,
31 0 : /* txn */ funk_txn,
32 0 : /* do_create */ 1,
33 0 : /* min_data_sz */ size,
34 0 : /* prepare */ &prepare );
35 0 : assert( err==FD_ACC_MGR_SUCCESS );
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, funk, funk_txn, &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 : }
71 :
72 : void
73 : fd_runtime_fuzz_refresh_program_cache( fd_exec_slot_ctx_t * slot_ctx,
74 : fd_exec_test_acct_state_t const * acct_states,
75 : ulong acct_states_count,
76 0 : fd_spad_t * runtime_spad ) {
77 0 : for( ushort i=0; i<acct_states_count; i++ ) {
78 0 : fd_pubkey_t pubkey[1] = {0};
79 0 : memcpy( &pubkey, acct_states[i].address, sizeof(fd_pubkey_t) );
80 0 : fd_program_cache_update_program( slot_ctx, pubkey, runtime_spad );
81 0 : }
82 0 : }
|