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_ADVANCE_ERROR (-1) 7 0 : #define FD_SSPARSE_ADVANCE_AGAIN ( 0) 8 0 : #define FD_SSPARSE_ADVANCE_MANIFEST ( 1) 9 0 : #define FD_SSPARSE_ADVANCE_MANIFEST_DONE ( 2) 10 0 : #define FD_SSPARSE_ADVANCE_STATUS_CACHE ( 3) 11 0 : #define FD_SSPARSE_ADVANCE_ACCOUNT_HEADER ( 4) 12 0 : #define FD_SSPARSE_ADVANCE_ACCOUNT_DATA ( 5) 13 0 : #define FD_SSPARSE_ADVANCE_ACCOUNT_BATCH ( 6) 14 0 : #define FD_SSPARSE_ADVANCE_APPENDVEC ( 7) 15 0 : #define FD_SSPARSE_ADVANCE_DONE ( 8) 16 : 17 : /* fd_ssparse_t is a solana snapshot parser. It is designed to parse a 18 : snapshot in streaming fashion, chunk by chunk. */ 19 : struct fd_ssparse { 20 : int state; 21 : uint batch_enabled : 1; 22 : 23 : struct { 24 : int seen_zero_tar_frame; 25 : int seen_manifest; 26 : int seen_status_cache; 27 : int seen_version; 28 : } flags; 29 : 30 : uchar version[ 5UL ]; 31 : 32 : struct { 33 : uchar header[ 512UL ]; 34 : ulong file_bytes; 35 : ulong file_bytes_consumed; 36 : ulong header_bytes_consumed; 37 : } tar; 38 : 39 : struct { 40 : uchar header[ 136UL ]; 41 : ulong header_bytes_consumed; 42 : ulong data_bytes_consumed; 43 : ulong data_len; 44 : } account; 45 : 46 : ulong acc_vec_bytes; 47 : ulong slot; 48 : ulong bytes_consumed; 49 : }; 50 : 51 : typedef struct fd_ssparse fd_ssparse_t; 52 : 53 : /* FD_SSPARSE_ACC_BATCH_MAX controls the max number of accounts in a 54 : batch. */ 55 0 : #define FD_SSPARSE_ACC_BATCH_MAX (8UL) 56 : 57 : struct fd_ssparse_advance_result { 58 : ulong bytes_consumed; 59 : 60 : union { 61 : struct { 62 : uchar const * data; 63 : ulong data_sz; 64 : } manifest; 65 : 66 : struct { 67 : uchar const * data; 68 : ulong data_sz; 69 : int done; 70 : } status_cache; 71 : 72 : struct { 73 : ulong slot; 74 : ulong data_len; 75 : uchar const * pubkey; 76 : ulong lamports; 77 : ulong rent_epoch; 78 : uchar const * owner; 79 : int executable; 80 : uchar const * hash; 81 : } account_header; 82 : 83 : struct { 84 : uchar const * data; 85 : ulong data_sz; 86 : } account_data; 87 : 88 : struct { 89 : /* Points to first byte of each account entry 90 : Each account entry is guaranteed unfragmented 91 : Useful for fast path processing */ 92 : uchar const * batch[ FD_SSPARSE_ACC_BATCH_MAX ]; 93 : ulong batch_cnt; 94 : ulong slot; 95 : } account_batch; 96 : 97 : /* Returned after an appendvec header. */ 98 : struct { 99 : ulong slot; 100 : ulong data_sz; /* tar entry size in bytes */ 101 : } appendvec; 102 : }; 103 : }; 104 : 105 : typedef struct fd_ssparse_advance_result fd_ssparse_advance_result_t; 106 : 107 : FD_PROTOTYPES_BEGIN 108 : 109 : fd_ssparse_t * 110 : fd_ssparse_init( fd_ssparse_t * ssparse ); 111 : 112 : /* fd_ssparse_advance parses a snapshot stream chunk. 113 : 114 : ssparse points to the parser. data points to the snapshot stream. 115 : data_sz is the size of the snapshot stream chunk. result points to 116 : fd_ssparse_advance_result_t object. On success, the contents of the 117 : result are populated according to the return result. result is not 118 : populated if the return result is ADVANCE_AGAIN or ADVANCE_ERROR. */ 119 : int 120 : fd_ssparse_advance( fd_ssparse_t * ssparse, 121 : uchar const * data, 122 : ulong data_sz, 123 : fd_ssparse_advance_result_t * result ); 124 : 125 : /* fd_ssparse_batch_enable toggles whether batch processing is enabled. 126 : If enabled, ssparse will deliver FD_SSPARSE_ADVANCE_ACCOUNT_BATCH 127 : messages. (These may help the caller processing accounts in batches 128 : to amortize per-account overhead, such as slow DRAM/disk fetches.) */ 129 : void 130 : fd_ssparse_batch_enable( fd_ssparse_t * ssparse, 131 : int enabled ); 132 : 133 : /* Parse the current appendvec after fd_ssparse_advance returns 134 : FD_SSPARSE_ADVANCE_APPENDVEC. */ 135 : void 136 : fd_ssparse_appendvec_parse( fd_ssparse_t * ssparse ); 137 : 138 : FD_PROTOTYPES_END 139 : 140 : #endif /* HEADER_fd_src_discof_restore_utils_fd_ssparse_h */