Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_snapshot_fd_snapshot_h 2 : #define HEADER_fd_src_flamenco_snapshot_fd_snapshot_h 3 : 4 : #if FD_HAS_ZSTD 5 : 6 : /* fd_snapshot.h provides high-level blocking APIs for Solana snapshots. */ 7 : 8 : #include "fd_snapshot_base.h" 9 : #include "../runtime/fd_runtime_public.h" 10 : #include "../../funk/fd_funk_txn.h" 11 : #include "../../ballet/lthash/fd_lthash.h" 12 : 13 : FD_PROTOTYPES_BEGIN 14 : 15 : /* Whether to initialize these objects inside fd_snapshot_load_manifest_and_status_cache, 16 : or just advance the tar cursor. */ 17 0 : #define FD_SNAPSHOT_RESTORE_NONE (0) 18 0 : #define FD_SNAPSHOT_RESTORE_MANIFEST (1) 19 0 : #define FD_SNAPSHOT_RESTORE_STATUS_CACHE (2) 20 : 21 : struct fd_snapshot_load_ctx; 22 : typedef struct fd_snapshot_load_ctx fd_snapshot_load_ctx_t; 23 : 24 : /* fd_snapshot_load_all does a blocking load of a snapshot. It is a wrapper 25 : around fd_snapshot_load_new, fd_snapshot_load_init, 26 : fd_snapshot_load_manifest_and_status_cache, and fd_snapshot_load_fini. 27 : 28 : fd_snapshot_load_new sets up the context that is passed around for the 29 : other fd_snapshot_load_* functions. 30 : 31 : fd_snapshot_load_init starts the process of loading in the snapshot and 32 : sets up the funk transactions, etc.. 33 : 34 : fd_snapshot_load_manifest_and_status_cache loads in the manifest and the 35 : status cache exiting as soon as the manifest is loaded in. 36 : 37 : fd_snapshot_load_accounts will load in the rest of the snapshot file but 38 : the runtime is still not setup to run. 39 : 40 : fd_snapshot_load_fini will use the slot context and funk which are now 41 : populated to setup the runtime and finalize the snapshot load. 42 : 43 : The reason these are broken out is to support loading in the manifest as 44 : quickly as possible, allowing for other operations to start (like 45 : stake-weighted repair) while the rest of the snapshot is being loaded. This 46 : is needed as loading in the manifest only takes a few seconds and the overall 47 : time to load in a snapshot is dominated by loading in the append vecs. 48 : 49 : source_cstr is either a local file system path. 50 : TODO: Add support for an HTTP url. 51 : 52 : slot_ctx is a valid initialized slot context. 53 : 54 : spad should have enough space to buffer the snapshot's manifest. 55 : 56 : If verify_hash!=0 calculates the snapshot hash. 57 : 58 : If check_hash!=0 checks that the snapshot hash matches the file name. 59 : 60 : snapshot_type is one of FD_SNAPSHOT_TYPE_{...}. */ 61 : 62 : ulong 63 : fd_snapshot_load_ctx_align( void ); 64 : 65 : ulong 66 : fd_snapshot_load_ctx_footprint( void ); 67 : 68 : fd_snapshot_load_ctx_t * 69 : fd_snapshot_load_new( uchar * mem, 70 : const char * snapshot_src, 71 : int snapshot_src_type, 72 : const char * snapshot_dir, 73 : fd_exec_slot_ctx_t * slot_ctx, 74 : uint verify_hash, 75 : uint check_hash, 76 : int snapshot_type, 77 : fd_spad_t * * exec_spads, 78 : ulong spad_cnt, 79 : fd_spad_t * runtime_spad, 80 : fd_exec_para_cb_ctx_t * exec_para_ctx ); 81 : 82 : void 83 : fd_snapshot_load_init( fd_snapshot_load_ctx_t * ctx ); 84 : 85 : /* restore_manifest_flags controls if the manifest and status cache objects are initialized or not. */ 86 : void 87 : fd_snapshot_load_manifest_and_status_cache( fd_snapshot_load_ctx_t * ctx, 88 : ulong * base_slot_override, 89 : int restore_manifest_flags ); 90 : 91 : void 92 : fd_snapshot_load_accounts( fd_snapshot_load_ctx_t * ctx ); 93 : 94 : void 95 : fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ); 96 : 97 : void 98 : fd_snapshot_load_all( const char * source_cstr, 99 : int source_type, 100 : const char * snapshot_dir, 101 : fd_exec_slot_ctx_t * slot_ctx, 102 : ulong * base_slot_override, 103 : fd_tpool_t * tpool, 104 : uint verify_hash, 105 : uint check_hash, 106 : int snapshot_type, 107 : fd_spad_t * * exec_spads, 108 : ulong exec_spad_cnt, 109 : fd_spad_t * runtime_spad ); 110 : 111 : void 112 : fd_snapshot_load_prefetch_manifest( fd_snapshot_load_ctx_t * ctx ); 113 : 114 : ulong 115 : fd_snapshot_get_slot( fd_snapshot_load_ctx_t * ctx ); 116 : 117 : /* Generate a non-incremental hash of the entire account database, conditionally including in the epoch account hash. */ 118 : int 119 : fd_snapshot_hash( fd_exec_slot_ctx_t * slot_ctx, 120 : fd_hash_t * accounts_hash, 121 : uint check_hash, 122 : fd_spad_t * runtime_spad, 123 : fd_exec_para_cb_ctx_t * exec_para_ctx, 124 : fd_lthash_value_t * lt_hash ); 125 : 126 : /* Generate an incremental hash of the entire account database, conditionally including in the epoch account hash. */ 127 : int 128 : fd_snapshot_inc_hash( fd_exec_slot_ctx_t * slot_ctx, 129 : fd_hash_t * accounts_hash, 130 : fd_funk_txn_t * child_txn, 131 : uint check_hash, 132 : fd_spad_t * spad, 133 : fd_lthash_value_t * lt_hash ); 134 : 135 : FD_PROTOTYPES_END 136 : 137 : #endif /* FD_HAS_ZSTD */ 138 : 139 : #endif /* HEADER_fd_src_flamenco_snapshot_fd_snapshot_h */