Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_snapshot_fd_snapshot_restore_private_h 2 : #define HEADER_fd_src_flamenco_snapshot_fd_snapshot_restore_private_h 3 : 4 : #include "fd_snapshot_restore.h" 5 : 6 : /* fd_valloc_limit_t wraps a heap allocator and keeps track of 7 : allocation quota. Once exceeded, quota is set to 0UL and all 8 : allocation attempts return NULL. frees are always forwarded to the 9 : underlying valloc. */ 10 : 11 : struct fd_valloc_limit { 12 : fd_valloc_t valloc; 13 : ulong quota; 14 : ulong quota_orig; 15 : }; 16 : 17 : typedef struct fd_valloc_limit fd_valloc_limit_t; 18 : 19 : /* Accounts are loaded from a snapshot via "account vec" files, each 20 : containing multiple accounts. However, external information is 21 : required to determine the size of these files. This information is 22 : stored in the "manifest" file, which is loaded at the beginning of 23 : the snapshot. 24 : 25 : The below map serves to store the file size information. */ 26 : 27 : struct fd_snapshot_accv_key { 28 : ulong slot; 29 : ulong id; 30 : }; 31 : 32 : typedef struct fd_snapshot_accv_key fd_snapshot_accv_key_t; 33 : 34 : static const fd_snapshot_accv_key_t 35 : fd_snapshot_accv_key_null = { 0UL, 0UL }; 36 : 37 : static inline ulong 38 84 : fd_snapshot_accv_key_hash( fd_snapshot_accv_key_t key ) { 39 84 : return fd_hash( 0x39c49607bf16463aUL, &key, sizeof(fd_snapshot_accv_key_t) ); 40 84 : } 41 : 42 : struct fd_snapshot_accv_map { 43 : fd_snapshot_accv_key_t key; 44 : ulong sz; 45 : ulong hash; /* use uint or ulong hash? */ 46 : }; 47 : 48 : typedef struct fd_snapshot_accv_map fd_snapshot_accv_map_t; 49 : 50 : #define MAP_NAME fd_snapshot_accv_map 51 138 : #define MAP_T fd_snapshot_accv_map_t 52 452984970 : #define MAP_LG_SLOT_CNT 23 /* 8.39 million */ 53 84 : #define MAP_KEY_T fd_snapshot_accv_key_t 54 452984832 : #define MAP_KEY_NULL fd_snapshot_accv_key_null 55 84 : #define MAP_KEY_INVAL(k) ( ((k).slot==0UL) & ((k).id==0UL) ) 56 54 : #define MAP_KEY_EQUAL(k0,k1) ( ((k0).slot==(k1).slot) & ((k0).id==(k1).id) ) 57 : #define MAP_KEY_EQUAL_IS_SLOW 0 58 84 : #define MAP_HASH_T ulong 59 84 : #define MAP_KEY_HASH(k0) fd_snapshot_accv_key_hash(k0) 60 : #include "../../util/tmpl/fd_map.c" 61 : 62 : /* Main snapshot restore **********************************************/ 63 : 64 : struct fd_snapshot_restore { 65 : fd_acc_mgr_t * acc_mgr; 66 : fd_funk_txn_t * funk_txn; 67 : fd_valloc_t valloc; 68 : 69 : ulong slot; /* Slot number the snapshot was taken at */ 70 : 71 : uchar state; 72 : uchar manifest_done : 1; 73 : uchar status_cache_done : 1; 74 : uchar failed : 1; 75 : 76 : /* Buffer params. This buffer is used to gather file content into 77 : a contiguous byte array. Currently in use for the manifest and the 78 : account headers. (Account data does not use this buffer) */ 79 : 80 : uchar * buf; /* points to first byte of buffer */ 81 : ulong buf_ctr; /* number of bytes allocated in buffer */ 82 : ulong buf_sz; /* target buffer size (buf_ctr<buf_sz implies incomplete read) */ 83 : ulong buf_cap; /* byte capacity of buffer */ 84 : 85 : /* Account vec params. Sadly, Solana Labs encodes account vecs with 86 : garbage at the end of the file. The actual account vec sz can be 87 : smaller. In this case, we have to stop reading account data early 88 : and skip the garbage/padding. */ 89 : 90 : ulong accv_slot; /* account vec slot */ 91 : ulong accv_id; /* account vec index */ 92 : ulong accv_sz; /* account vec size */ 93 : fd_snapshot_accv_map_t * accv_map; 94 : 95 : /* Account size. Used when reading account data. */ 96 : 97 : ulong acc_sz; /* acc bytes pending write */ 98 : uchar * acc_data; /* pointer into funk acc data pending write */ 99 : ulong acc_pad; /* padding size at end of account */ 100 : 101 : /* Consumer callback */ 102 : 103 : fd_snapshot_restore_cb_manifest_fn_t cb_manifest; 104 : void * cb_manifest_ctx; 105 : 106 : fd_snapshot_restore_cb_status_cache_fn_t cb_status_cache; 107 : void * cb_status_cache_ctx; 108 : }; 109 : 110 : /* STATE_{...} are the state IDs that control file processing in the 111 : snapshot streaming state machine. */ 112 : 113 24 : #define STATE_IGNORE ((uchar)0) /* ignore file content */ 114 18 : #define STATE_READ_MANIFEST ((uchar)1) /* reading manifest (buffered) */ 115 864 : #define STATE_READ_ACCOUNT_HDR ((uchar)2) /* reading account hdr (buffered) */ 116 21 : #define STATE_READ_ACCOUNT_DATA ((uchar)3) /* reading account data (direct copy into funk) */ 117 12 : #define STATE_READ_STATUS_CACHE ((uchar)4) /* reading status cache (buffered)*/ 118 54 : #define STATE_DONE ((uchar)5) /* expect no more data */ 119 : 120 : #endif /* HEADER_fd_src_flamenco_snapshot_fd_snapshot_restore_private_h */