Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_context_fd_exec_slot_ctx_h 2 : #define HEADER_fd_src_flamenco_runtime_context_fd_exec_slot_ctx_h 3 : 4 : #include "../fd_blockstore.h" 5 : #include "../../../funk/fd_funk.h" 6 : #include "../../../util/rng/fd_rng.h" 7 : #include "../../../util/wksp/fd_wksp.h" 8 : 9 : #include "../sysvar/fd_sysvar_cache.h" 10 : #include "../../types/fd_types.h" 11 : #include "../fd_txncache.h" 12 : 13 : struct fd_account_compute_elem { 14 : fd_pubkey_t key; 15 : ulong next; 16 : ulong cu_consumed; 17 : }; 18 : typedef struct fd_account_compute_elem fd_account_compute_elem_t; 19 : 20 : static int 21 0 : fd_pubkey_eq( fd_pubkey_t const * key1, fd_pubkey_t const * key2 ) { 22 0 : return memcmp( key1->key, key2->key, sizeof(fd_pubkey_t) ) == 0; 23 0 : } 24 : 25 : static ulong 26 0 : fd_pubkey_hash( fd_pubkey_t const * key, ulong seed ) { 27 0 : return fd_hash( seed, key->key, sizeof(fd_pubkey_t) ); 28 0 : } 29 : 30 : static void 31 0 : fd_pubkey_copy( fd_pubkey_t * keyd, fd_pubkey_t const * keys ) { 32 0 : memcpy( keyd->key, keys->key, sizeof(fd_pubkey_t) ); 33 0 : } 34 : 35 : /* Contact info table */ 36 : #define MAP_NAME fd_account_compute_table 37 : #define MAP_KEY_T fd_pubkey_t 38 0 : #define MAP_KEY_EQ fd_pubkey_eq 39 0 : #define MAP_KEY_HASH fd_pubkey_hash 40 : #define MAP_KEY_COPY fd_pubkey_copy 41 407859 : #define MAP_T fd_account_compute_elem_t 42 : #include "../../../util/tmpl/fd_map_giant.c" 43 : 44 : /* fd_exec_slot_ctx_t is the context that stays constant during all 45 : transactions in a block. */ 46 : 47 : struct __attribute__((aligned(8UL))) fd_exec_slot_ctx { 48 : ulong magic; /* ==FD_EXEC_SLOT_CTX_MAGIC */ 49 : 50 : fd_funk_txn_t * funk_txn; 51 : 52 : /* External joins, pointers to be set by caller */ 53 : 54 : fd_acc_mgr_t * acc_mgr; 55 : fd_blockstore_t * blockstore; 56 : fd_block_t * block; 57 : fd_exec_epoch_ctx_t * epoch_ctx; 58 : fd_valloc_t valloc; 59 : 60 : fd_slot_bank_t slot_bank; 61 : 62 : ulong total_compute_units_requested; 63 : 64 : /* TODO figure out what to do with this */ 65 : fd_epoch_reward_status_t epoch_reward_status; 66 : 67 : /* TODO remove this stuff */ 68 : ulong signature_cnt; 69 : fd_hash_t account_delta_hash; 70 : ulong prev_lamports_per_signature; 71 : ulong parent_transaction_count; 72 : ulong txn_count; 73 : ulong nonvote_txn_count; 74 : ulong failed_txn_count; 75 : ulong nonvote_failed_txn_count; 76 : ulong total_compute_units_used; 77 : 78 : fd_sysvar_cache_t * sysvar_cache; 79 : fd_account_compute_elem_t * account_compute_table; 80 : 81 : fd_txncache_t * status_cache; 82 : fd_slot_history_t slot_history[1]; 83 : 84 : ulong tick_count; 85 : 86 : int enable_exec_recording; /* Enable/disable execution metadata 87 : recording, e.g. txn logs. Analogue 88 : of Agave's ExecutionRecordingConfig. */ 89 : 90 : ulong root_slot; 91 : ulong snapshot_freq; 92 : ulong incremental_freq; 93 : ulong last_snapshot_slot; 94 : }; 95 : 96 415524 : #define FD_EXEC_SLOT_CTX_ALIGN (alignof(fd_exec_slot_ctx_t)) 97 415524 : #define FD_EXEC_SLOT_CTX_FOOTPRINT (sizeof (fd_exec_slot_ctx_t)) 98 407859 : #define FD_EXEC_SLOT_CTX_MAGIC (0xC2287BA2A5E6FC3DUL) /* random */ 99 : 100 : /* FD_FEATURE_ACTIVE evalutes to 1 if the given feature is active, 0 101 : otherwise. First arg is the fd_exec_slot_ctx_t. Second arg is the 102 : name of the feature. 103 : 104 : Example usage: if( FD_FEATURE_ACTIVE( slot_ctx, set_exempt_rent_epoch_max ) ) */ 105 : 106 145608 : #define FD_FEATURE_ACTIVE(_slot_ctx, _feature_name) (_slot_ctx->slot_bank.slot >= _slot_ctx->epoch_ctx->features. _feature_name) 107 : 108 : FD_PROTOTYPES_BEGIN 109 : 110 : void * 111 : fd_exec_slot_ctx_new( void * mem, 112 : fd_valloc_t valloc ); 113 : 114 : fd_exec_slot_ctx_t * 115 : fd_exec_slot_ctx_join( void * mem ); 116 : 117 : void * 118 : fd_exec_slot_ctx_leave( fd_exec_slot_ctx_t * ctx ); 119 : 120 : void * 121 : fd_exec_slot_ctx_delete( void * mem ); 122 : 123 : /* fd_exec_slot_ctx_recover re-initializes the current epoch/slot 124 : context and recovers it from the manifest of a Solana Labs snapshot. 125 : Moves ownership of manifest to this function. Assumes objects in 126 : manifest were allocated using slot ctx valloc (U.B. otherwise). 127 : Assumes that slot context and epoch context use same valloc. 128 : On return, manifest is destroyed. Returns ctx on success. 129 : On failure, logs reason for error and returns NULL. */ 130 : 131 : fd_exec_slot_ctx_t * 132 : fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * ctx, 133 : fd_solana_manifest_t * manifest ); 134 : 135 : /* fd_exec_slot_ctx_recover re-initializes the current slot 136 : context's status cache from the provided solana slot deltas. 137 : Assumes objects in slot deltas were allocated using slot ctx valloc 138 : (U.B. otherwise). 139 : On return, slot deltas is destroyed. Returns ctx on success. 140 : On failure, logs reason for error and returns NULL. */ 141 : 142 : fd_exec_slot_ctx_t * 143 : fd_exec_slot_ctx_recover_status_cache( fd_exec_slot_ctx_t * ctx, 144 : fd_bank_slot_deltas_t * slot_deltas ); 145 : 146 : 147 : /* Free all allocated memory within a slot ctx */ 148 : void 149 : fd_exec_slot_ctx_free(fd_exec_slot_ctx_t * ctx); 150 : 151 : FD_PROTOTYPES_END 152 : 153 : #endif /* HEADER_fd_src_flamenco_runtime_context_fd_exec_slot_ctx_h */