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_DONE ( 5) 15 : 16 : /* fd_ssparse_t is a solana snapshot parser. It is designed to parse a 17 : snapshot in streaming fasion, chunk by chunk. */ 18 : struct fd_ssparse_private; 19 : typedef struct fd_ssparse_private fd_ssparse_t; 20 : 21 : struct acc_vec_key { 22 : ulong slot; 23 : ulong id; 24 : }; 25 : 26 : typedef struct acc_vec_key acc_vec_key_t; 27 : 28 : struct acc_vec { 29 : acc_vec_key_t key; 30 : ulong file_sz; 31 : 32 : ulong map_next; 33 : ulong map_prev; 34 : 35 : ulong pool_next; 36 : }; 37 : 38 : typedef struct acc_vec acc_vec_t; 39 : 40 : #define POOL_NAME acc_vec_pool 41 0 : #define POOL_T acc_vec_t 42 0 : #define POOL_NEXT pool_next 43 : #define POOL_IDX_T ulong 44 : 45 : #include "../../../util/tmpl/fd_pool.c" 46 : 47 : #define MAP_NAME acc_vec_map 48 : #define MAP_ELE_T acc_vec_t 49 : #define MAP_KEY_T acc_vec_key_t 50 0 : #define MAP_KEY key 51 0 : #define MAP_IDX_T ulong 52 0 : #define MAP_NEXT map_next 53 : #define MAP_PREV map_prev 54 0 : #define MAP_KEY_HASH(k,s) fd_hash( s, k, sizeof(acc_vec_key_t) ) 55 0 : #define MAP_KEY_EQ(k0,k1) ( ((k0)->slot==(k1)->slot) && ((k0)->id==(k1)->id) ) 56 : 57 : #include "../../../util/tmpl/fd_map_chain.c" 58 : 59 : struct fd_ssparse_advance_result { 60 : ulong bytes_consumed; 61 : 62 : union { 63 : struct { 64 : uchar const * data; 65 : ulong data_sz; 66 : acc_vec_map_t * acc_vec_map; 67 : acc_vec_t * acc_vec_pool; 68 : } manifest; 69 : 70 : struct { 71 : uchar const * data; 72 : ulong data_sz; 73 : } status_cache; 74 : 75 : struct { 76 : ulong slot; 77 : ulong data_len; 78 : uchar const * pubkey; 79 : ulong lamports; 80 : ulong rent_epoch; 81 : uchar const * owner; 82 : int executable; 83 : uchar const * hash; 84 : } account_header; 85 : 86 : struct { 87 : uchar const * data; 88 : ulong data_sz; 89 : } account_data; 90 : }; 91 : }; 92 : 93 : typedef struct fd_ssparse_advance_result fd_ssparse_advance_result_t; 94 : 95 : FD_PROTOTYPES_BEGIN 96 : 97 : FD_FN_CONST ulong 98 : fd_ssparse_align( void ); 99 : 100 : FD_FN_CONST ulong 101 : fd_ssparse_footprint( ulong max_acc_vecs ); 102 : 103 : void * 104 : fd_ssparse_new( void * shmem, 105 : ulong max_acc_vecs, 106 : ulong seed ); 107 : 108 : fd_ssparse_t * 109 : fd_ssparse_join( void * ssparse ); 110 : 111 : /* fd_ssparse_reset rewinds the parser to accept a new snapshot stream */ 112 : void 113 : fd_ssparse_reset( fd_ssparse_t * ssparse ); 114 : 115 : /* fd_ssparse_advance parses a snapshot stream chunk. 116 : 117 : ssparse points to the parser. data points to the snapshot stream. 118 : data_sz is the size of the snapshot stream chunk. result points to 119 : fd_ssparse_advance_result_t object. On success, the contents of the 120 : result are populated according to the return result. result is not 121 : populated if the return result is ADVANCE_AGAIN or ADVANCE_ERROR. */ 122 : int 123 : fd_ssparse_advance( fd_ssparse_t * ssparse, 124 : uchar const * data, 125 : ulong data_sz, 126 : fd_ssparse_advance_result_t * result ); 127 : 128 : /* Test/Fuzz APIs */ 129 : 130 : /* fd_ssparse_populate_acc_vec_map is for testing/fuzzing purposes 131 : only. It takes an array of slots, ids, and file sizes and populates 132 : the ssparse object's internal append vec map. */ 133 : int 134 : fd_ssparse_populate_acc_vec_map( fd_ssparse_t * ssparse, 135 : ulong * slots, 136 : ulong * ids, 137 : ulong * file_szs, 138 : ulong cnt ); 139 : 140 : FD_PROTOTYPES_END 141 : 142 : #endif /* HEADER_fd_src_discof_restore_utils_fd_ssparse_h */