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_DONE ( 7) 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 { 19 : int state; 20 : uint batch_enabled : 1; 21 : 22 : struct { 23 : int seen_zero_tar_frame; 24 : int seen_manifest; 25 : int seen_status_cache; 26 : int seen_version; 27 : } flags; 28 : 29 : uchar version[ 5UL ]; 30 : 31 : struct { 32 : uchar header[ 512UL ]; 33 : ulong file_bytes; 34 : ulong file_bytes_consumed; 35 : ulong header_bytes_consumed; 36 : } tar; 37 : 38 : struct { 39 : uchar const * owner; 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 * owner; 85 : uchar const * data; 86 : ulong data_sz; 87 : } account_data; 88 : 89 : struct { 90 : /* Points to first byte of each account entry 91 : Each account entry is guaranteed unfragmented 92 : Useful for fast path processing */ 93 : uchar const * batch[ FD_SSPARSE_ACC_BATCH_MAX ]; 94 : ulong batch_cnt; 95 : ulong slot; 96 : } account_batch; 97 : }; 98 : }; 99 : 100 : typedef struct fd_ssparse_advance_result fd_ssparse_advance_result_t; 101 : 102 : FD_PROTOTYPES_BEGIN 103 : 104 : fd_ssparse_t * 105 : fd_ssparse_init( fd_ssparse_t * ssparse ); 106 : 107 : /* fd_ssparse_advance parses a snapshot stream chunk. 108 : 109 : ssparse points to the parser. data points to the snapshot stream. 110 : data_sz is the size of the snapshot stream chunk. result points to 111 : fd_ssparse_advance_result_t object. On success, the contents of the 112 : result are populated according to the return result. result is not 113 : populated if the return result is ADVANCE_AGAIN or ADVANCE_ERROR. */ 114 : int 115 : fd_ssparse_advance( fd_ssparse_t * ssparse, 116 : uchar const * data, 117 : ulong data_sz, 118 : fd_ssparse_advance_result_t * result ); 119 : 120 : /* fd_ssparse_batch_enable toggles whether batch processing is enabled. 121 : If enabled, ssparse will deliver FD_SSPARSE_ADVANCE_ACCOUNT_BATCH 122 : messages. (These may help the caller processing accounts in batches 123 : to amortize per-account overhead, such as slow DRAM/disk fetches.) */ 124 : void 125 : fd_ssparse_batch_enable( fd_ssparse_t * ssparse, 126 : int enabled ); 127 : 128 : FD_PROTOTYPES_END 129 : 130 : #endif /* HEADER_fd_src_discof_restore_utils_fd_ssparse_h */