Line data Source code
1 : #include "../program/fd_program_cache.h"
2 : #include "generated/context.pb.h"
3 : #include "../fd_acc_mgr.h"
4 : #include "../../features/fd_features.h"
5 : #include <assert.h>
6 :
7 : int
8 : fd_runtime_fuzz_load_account( fd_txn_account_t * acc,
9 : fd_funk_t * funk,
10 : fd_funk_txn_xid_t const * xid,
11 : fd_exec_test_acct_state_t const * state,
12 0 : uchar reject_zero_lamports ) {
13 0 : if( reject_zero_lamports && state->lamports==0UL ) {
14 0 : return 0;
15 0 : }
16 :
17 0 : ulong size = 0UL;
18 0 : if( state->data ) size = state->data->size;
19 :
20 0 : fd_pubkey_t pubkey[1]; memcpy( pubkey, state->address, sizeof(fd_pubkey_t) );
21 :
22 : /* Account must not yet exist */
23 0 : if( FD_UNLIKELY( fd_funk_get_acc_meta_readonly( funk, xid, pubkey, NULL, NULL, NULL) ) ) {
24 0 : return 0;
25 0 : }
26 :
27 0 : fd_funk_rec_prepare_t prepare = {0};
28 :
29 0 : assert( funk );
30 0 : int err = fd_txn_account_init_from_funk_mutable( /* acc */ acc,
31 0 : /* pubkey */ pubkey,
32 0 : /* funk */ funk,
33 0 : /* xid */ xid,
34 0 : /* do_create */ 1,
35 0 : /* min_data_sz */ size,
36 0 : /* prepare */ &prepare );
37 0 : assert( err==FD_ACC_MGR_SUCCESS );
38 :
39 0 : if( state->data ) {
40 0 : fd_txn_account_set_data( acc, state->data->bytes, size );
41 0 : }
42 :
43 0 : acc->starting_lamports = state->lamports;
44 0 : acc->starting_dlen = size;
45 0 : fd_txn_account_set_lamports( acc, state->lamports );
46 0 : fd_txn_account_set_executable( acc, state->executable );
47 0 : fd_txn_account_set_owner( acc, (fd_pubkey_t const *)state->owner );
48 :
49 : /* make the account read-only by default */
50 0 : fd_txn_account_set_readonly( acc );
51 :
52 0 : fd_txn_account_mutable_fini( acc, funk, &prepare );
53 :
54 0 : return 1;
55 0 : }
56 :
57 : int
58 : fd_runtime_fuzz_restore_features( fd_features_t * features,
59 0 : fd_exec_test_feature_set_t const * feature_set ) {
60 0 : fd_features_disable_all( features );
61 0 : for( ulong j=0UL; j < feature_set->features_count; j++ ) {
62 0 : ulong prefix = feature_set->features[j];
63 0 : fd_feature_id_t const * id = fd_feature_id_query( prefix );
64 0 : if( FD_UNLIKELY( !id ) ) {
65 0 : FD_LOG_WARNING(( "unsupported feature ID 0x%016lx", prefix ));
66 0 : return 0;
67 0 : }
68 : /* Enabled since genesis */
69 0 : fd_features_set( features, id, 0UL );
70 0 : }
71 0 : return 1;
72 0 : }
73 :
74 : void
75 : fd_runtime_fuzz_refresh_program_cache( fd_bank_t * bank,
76 : fd_funk_t * funk,
77 : fd_funk_txn_xid_t const * xid,
78 : fd_exec_test_acct_state_t const * acct_states,
79 : ulong acct_states_count,
80 0 : fd_spad_t * runtime_spad ) {
81 0 : for( ushort i=0; i<acct_states_count; i++ ) {
82 0 : fd_pubkey_t pubkey[1] = {0};
83 0 : memcpy( &pubkey, acct_states[i].address, sizeof(fd_pubkey_t) );
84 0 : fd_program_cache_update_program( bank, funk, xid, pubkey, runtime_spad );
85 0 : }
86 0 : }
|