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 0 : #define MAP_KEY_COPY fd_pubkey_copy 41 108786 : #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 : // TODO this leader pointer could become invalid if forks cross epoch boundaries 62 : fd_pubkey_t const * leader; /* Current leader */ 63 : ulong total_compute_units_requested; 64 : 65 : /* TODO figure out what to do with this */ 66 : fd_epoch_reward_status_t epoch_reward_status; 67 : 68 : /* TODO remove this stuff */ 69 : ulong signature_cnt; 70 : fd_hash_t account_delta_hash; 71 : fd_hash_t prev_banks_hash; 72 : ulong prev_lamports_per_signature; 73 : ulong parent_signature_cnt; 74 : ulong parent_transaction_count; 75 : 76 : fd_sysvar_cache_t * sysvar_cache; 77 : fd_account_compute_elem_t * account_compute_table; 78 : 79 : fd_txncache_t * status_cache; 80 : fd_slot_history_t slot_history[1]; 81 : 82 : int enable_exec_recording; /* Enable/disable execution metadata 83 : recording, e.g. txn logs. Analogue 84 : of Agave's ExecutionRecordingConfig. */ 85 : }; 86 : 87 113193 : #define FD_EXEC_SLOT_CTX_ALIGN (alignof(fd_exec_slot_ctx_t)) 88 113193 : #define FD_EXEC_SLOT_CTX_FOOTPRINT (sizeof (fd_exec_slot_ctx_t)) 89 108786 : #define FD_EXEC_SLOT_CTX_MAGIC (0xC2287BA2A5E6FC3DUL) /* random */ 90 : 91 : /* FD_FEATURE_ACTIVE evalutes to 1 if the given feature is active, 0 92 : otherwise. First arg is the fd_exec_slot_ctx_t. Second arg is the 93 : name of the feature. 94 : 95 : Example usage: if( FD_FEATURE_ACTIVE( slot_ctx, set_exempt_rent_epoch_max ) ) */ 96 : 97 89739 : #define FD_FEATURE_ACTIVE(_slot_ctx, _feature_name) (_slot_ctx->slot_bank.slot >= _slot_ctx->epoch_ctx->features. _feature_name) 98 : 99 : FD_PROTOTYPES_BEGIN 100 : 101 : void * 102 : fd_exec_slot_ctx_new( void * mem, 103 : fd_valloc_t valloc ); 104 : 105 : fd_exec_slot_ctx_t * 106 : fd_exec_slot_ctx_join( void * mem ); 107 : 108 : void * 109 : fd_exec_slot_ctx_leave( fd_exec_slot_ctx_t * ctx ); 110 : 111 : void * 112 : fd_exec_slot_ctx_delete( void * mem ); 113 : 114 : /* fd_exec_slot_ctx_recover re-initializes the current epoch/slot 115 : context and recovers it from the manifest of a Solana Labs snapshot. 116 : Moves ownership of manifest to this function. Assumes objects in 117 : manifest were allocated using slot ctx valloc (U.B. otherwise). 118 : Assumes that slot context and epoch context use same valloc. 119 : On return, manifest is destroyed. Returns ctx on success. 120 : On failure, logs reason for error and returns NULL. */ 121 : 122 : fd_exec_slot_ctx_t * 123 : fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * ctx, 124 : fd_solana_manifest_t * manifest ); 125 : 126 : /* fd_exec_slot_ctx_recover re-initializes the current slot 127 : context's status cache from the provided solana slot deltas. 128 : Assumes objects in slot deltas were allocated using slot ctx valloc 129 : (U.B. otherwise). 130 : On return, slot deltas is destroyed. Returns ctx on success. 131 : On failure, logs reason for error and returns NULL. */ 132 : 133 : fd_exec_slot_ctx_t * 134 : fd_exec_slot_ctx_recover_status_cache( fd_exec_slot_ctx_t * ctx, 135 : fd_bank_slot_deltas_t * slot_deltas ); 136 : 137 : 138 : /* Free all allocated memory within a slot ctx */ 139 : void 140 : fd_exec_slot_ctx_free(fd_exec_slot_ctx_t * ctx); 141 : 142 : FD_PROTOTYPES_END 143 : 144 : #endif /* HEADER_fd_src_flamenco_runtime_context_fd_exec_slot_ctx_h */