Line data Source code
1 : #ifndef HEADER_fd_src_discof_restore_utils_fd_ssparse_h 2 : #define HEADER_fd_src_discof_restore_utils_fd_ssparse_h 3 : 4 : #include "../../../util/fd_util_base.h" 5 : 6 0 : #define FD_SSPARSE_MAGIC (0xF17EDA2CE58AC5E0) /* FIREDANCE PARSE V0 */ 7 : 8 0 : #define FD_SSPARSE_ADVANCE_ERROR (-1) 9 0 : #define FD_SSPARSE_ADVANCE_AGAIN ( 0) 10 0 : #define FD_SSPARSE_ADVANCE_MANIFEST ( 1) 11 0 : #define FD_SSPARSE_ADVANCE_STATUS_CACHE ( 2) 12 0 : #define FD_SSPARSE_ADVANCE_ACCOUNT_HEADER ( 3) 13 0 : #define FD_SSPARSE_ADVANCE_ACCOUNT_DATA ( 4) 14 0 : #define FD_SSPARSE_ADVANCE_ACCOUNT_BATCH ( 5) 15 0 : #define FD_SSPARSE_ADVANCE_DONE ( 6) 16 : 17 : /* fd_ssparse_t is a solana snapshot parser. It is designed to parse a 18 : snapshot in streaming fasion, chunk by chunk. */ 19 : struct fd_ssparse_private; 20 : typedef struct fd_ssparse_private fd_ssparse_t; 21 : 22 : struct acc_vec_key { 23 : ulong slot; 24 : ulong id; 25 : }; 26 : 27 : typedef struct acc_vec_key acc_vec_key_t; 28 : 29 : struct acc_vec { 30 : acc_vec_key_t key; 31 : ulong file_sz; 32 : 33 : ulong map_next; 34 : ulong map_prev; 35 : 36 : ulong pool_next; 37 : }; 38 : 39 : typedef struct acc_vec acc_vec_t; 40 : 41 : #define POOL_NAME acc_vec_pool 42 0 : #define POOL_T acc_vec_t 43 0 : #define POOL_NEXT pool_next 44 : #define POOL_IDX_T ulong 45 : 46 : #include "../../../util/tmpl/fd_pool.c" 47 : 48 : #define MAP_NAME acc_vec_map 49 : #define MAP_ELE_T acc_vec_t 50 : #define MAP_KEY_T acc_vec_key_t 51 0 : #define MAP_KEY key 52 0 : #define MAP_IDX_T ulong 53 0 : #define MAP_NEXT map_next 54 : #define MAP_PREV map_prev 55 0 : #define MAP_KEY_HASH(k,s) fd_hash( s, k, sizeof(acc_vec_key_t) ) 56 0 : #define MAP_KEY_EQ(k0,k1) ( ((k0)->slot==(k1)->slot) && ((k0)->id==(k1)->id) ) 57 : 58 : #include "../../../util/tmpl/fd_map_chain.c" 59 : 60 : /* FD_SSPARSE_ACC_BATCH_MAX controls the max number of accounts in a 61 : batch. */ 62 0 : #define FD_SSPARSE_ACC_BATCH_MAX (8UL) 63 : 64 : struct fd_ssparse_advance_result { 65 : ulong bytes_consumed; 66 : 67 : union { 68 : struct { 69 : uchar const * data; 70 : ulong data_sz; 71 : acc_vec_map_t * acc_vec_map; 72 : acc_vec_t * acc_vec_pool; 73 : } manifest; 74 : 75 : struct { 76 : uchar const * data; 77 : ulong data_sz; 78 : } status_cache; 79 : 80 : struct { 81 : ulong slot; 82 : ulong data_len; 83 : uchar const * pubkey; 84 : ulong lamports; 85 : ulong rent_epoch; 86 : uchar const * owner; 87 : int executable; 88 : uchar const * hash; 89 : } account_header; 90 : 91 : struct { 92 : uchar const * owner; 93 : uchar const * data; 94 : ulong data_sz; 95 : } account_data; 96 : 97 : struct { 98 : /* Points to first byte of each account entry 99 : Each account entry is guaranteed unfragmented 100 : Useful for fast path processing */ 101 : uchar const * batch[ FD_SSPARSE_ACC_BATCH_MAX ]; 102 : ulong batch_cnt; 103 : ulong slot; 104 : } account_batch; 105 : }; 106 : }; 107 : 108 : typedef struct fd_ssparse_advance_result fd_ssparse_advance_result_t; 109 : 110 : FD_PROTOTYPES_BEGIN 111 : 112 : FD_FN_CONST ulong 113 : fd_ssparse_align( void ); 114 : 115 : FD_FN_CONST ulong 116 : fd_ssparse_footprint( ulong max_acc_vecs ); 117 : 118 : void * 119 : fd_ssparse_new( void * shmem, 120 : ulong max_acc_vecs, 121 : ulong seed ); 122 : 123 : fd_ssparse_t * 124 : fd_ssparse_join( void * ssparse ); 125 : 126 : /* fd_ssparse_reset rewinds the parser to accept a new snapshot stream */ 127 : void 128 : fd_ssparse_reset( fd_ssparse_t * ssparse ); 129 : 130 : /* fd_ssparse_advance parses a snapshot stream chunk. 131 : 132 : ssparse points to the parser. data points to the snapshot stream. 133 : data_sz is the size of the snapshot stream chunk. result points to 134 : fd_ssparse_advance_result_t object. On success, the contents of the 135 : result are populated according to the return result. result is not 136 : populated if the return result is ADVANCE_AGAIN or ADVANCE_ERROR. */ 137 : int 138 : fd_ssparse_advance( fd_ssparse_t * ssparse, 139 : uchar const * data, 140 : ulong data_sz, 141 : fd_ssparse_advance_result_t * result ); 142 : 143 : /* fd_ssparse_batch_enable toggles whether batch processing is enabled. 144 : If enabled, ssparse will deliver FD_SSPARSE_ADVANCE_ACCOUNT_BATCH 145 : messages. (These may help the caller processing accounts in batches 146 : to amortize per-account overhead, such as slow DRAM/disk fetches.) */ 147 : void 148 : fd_ssparse_batch_enable( fd_ssparse_t * ssparse, 149 : int enabled ); 150 : 151 : /* Test/Fuzz APIs */ 152 : 153 : /* fd_ssparse_populate_acc_vec_map is for testing/fuzzing purposes 154 : only. It takes an array of slots, ids, and file sizes and populates 155 : the ssparse object's internal append vec map. */ 156 : int 157 : fd_ssparse_populate_acc_vec_map( fd_ssparse_t * ssparse, 158 : ulong * slots, 159 : ulong * ids, 160 : ulong * file_szs, 161 : ulong cnt ); 162 : 163 : FD_PROTOTYPES_END 164 : 165 : #endif /* HEADER_fd_src_discof_restore_utils_fd_ssparse_h */