Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_rocksdb_h 2 : #define HEADER_fd_src_flamenco_runtime_fd_rocksdb_h 3 : 4 : #include "../../ballet/block/fd_microblock.h" 5 : 6 : /** allocations made for offline-replay in the blockstore */ 7 : struct fd_block { 8 : /* Used only in offline at the moment. Stored in the blockstore 9 : memory and used to iterate the block's contents. 10 : 11 : A block's data region is indexed to support iterating by shred, 12 : microblock/entry batch, microblock/entry, or transaction. 13 : This is done by iterating the headers for each, stored in allocated 14 : memory. 15 : To iterate shred payloads, for example, a caller should iterate the headers in tandem with the data region 16 : (offsetting by the bytes indicated in the shred header). 17 : 18 : Note random access of individual shred indices is not performant, due to the variable-length 19 : nature of shreds. */ 20 : 21 : ulong data_gaddr; /* ptr to the beginning of the block's allocated data region */ 22 : ulong data_sz; /* block size */ 23 : ulong shreds_gaddr; /* ptr to the first fd_block_shred_t */ 24 : ulong shreds_cnt; 25 : ulong batch_gaddr; /* list of fd_block_entry_batch_t */ 26 : ulong batch_cnt; 27 : ulong micros_gaddr; /* ptr to the list of fd_block_micro_t */ 28 : ulong micros_cnt; 29 : }; 30 : typedef struct fd_block fd_block_t; 31 : 32 : #if FD_HAS_ROCKSDB 33 : 34 : #include <rocksdb/c.h> 35 : 36 0 : #define FD_ROCKSDB_CF_CNT (20UL) 37 : 38 0 : #define FD_ROCKSDB_CFIDX_DEFAULT (0UL) 39 0 : #define FD_ROCKSDB_CFIDX_META (1UL) 40 0 : #define FD_ROCKSDB_CFIDX_DEAD_SLOTS (2UL) 41 0 : #define FD_ROCKSDB_CFIDX_DUPLICATE_SLOTS (3UL) /* Usually empty */ 42 0 : #define FD_ROCKSDB_CFIDX_ERASURE_META (4UL) 43 0 : #define FD_ROCKSDB_CFIDX_ORPHANS (5UL) /* Usually empty */ 44 0 : #define FD_ROCKSDB_CFIDX_BANK_HASHES (6UL) 45 0 : #define FD_ROCKSDB_CFIDX_ROOT (7UL) 46 0 : #define FD_ROCKSDB_CFIDX_INDEX (8UL) 47 0 : #define FD_ROCKSDB_CFIDX_DATA_SHRED (9UL) 48 0 : #define FD_ROCKSDB_CFIDX_CODE_SHRED (10UL) 49 0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_STATUS (11UL) 50 0 : #define FD_ROCKSDB_CFIDX_ADDRESS_SIGNATURES (12UL) 51 0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_MEMOS (13UL) 52 0 : #define FD_ROCKSDB_CFIDX_REWARDS (14UL) 53 0 : #define FD_ROCKSDB_CFIDX_BLOCKTIME (15UL) 54 0 : #define FD_ROCKSDB_CFIDX_PERF_SAMPLES (16UL) 55 0 : #define FD_ROCKSDB_CFIDX_BLOCK_HEIGHT (17UL) 56 0 : #define FD_ROCKSDB_CFIDX_OPTIMISTIC_SLOTS (18UL) 57 0 : #define FD_ROCKSDB_CFIDX_MERKLE_ROOT_META (19UL) /* Usually empty */ 58 : 59 : /* Solana rocksdb client */ 60 : struct fd_rocksdb { 61 : rocksdb_t * db; 62 : const char * db_name; 63 : const char * cfgs [ FD_ROCKSDB_CF_CNT ]; 64 : rocksdb_column_family_handle_t* cf_handles[ FD_ROCKSDB_CF_CNT ]; 65 : rocksdb_options_t * opts; 66 : rocksdb_readoptions_t * ro; 67 : rocksdb_writeoptions_t * wo; 68 : }; 69 : typedef struct fd_rocksdb fd_rocksdb_t; 70 : 71 : FD_PROTOTYPES_BEGIN 72 : 73 : /* fd_rocksdb_init: Returns a pointer to a description of the error on failure 74 : 75 : The provided db_name needs to point at the actual rocksdb directory 76 : as apposed to the directory above (like the solana ledger-tool) */ 77 : 78 : char * 79 : fd_rocksdb_init( fd_rocksdb_t * db, 80 : char const * db_name ); 81 : 82 : /* fd_rocksdb_new: Creates a new rocksdb 83 : 84 : The provided db_name has to the be the full path where the directory 85 : will be created. The fd_rocksdb_t object will be initialized */ 86 : 87 : void 88 : fd_rocksdb_new( fd_rocksdb_t * db, 89 : char const * db_name ); 90 : 91 : /* fd_rocksdb_destroy 92 : 93 : Frees up the internal data structures */ 94 : 95 : void 96 : fd_rocksdb_destroy( fd_rocksdb_t * db ); 97 : 98 : /* fd_rocksdb_last_slot: Returns the last slot in the db 99 : 100 : This uses the root column to discover the slot of the last root in 101 : the db. If there is an error, this sets *err to a constant string 102 : describing the error. There is no need to free that string. */ 103 : 104 : ulong 105 : fd_rocksdb_last_slot( fd_rocksdb_t * db, 106 : char ** err ); 107 : 108 : /* fd_rocksdb_first_slot: Returns the first slot in the db 109 : 110 : This uses the root column to discover the slot of the first root in 111 : the db. If there is an error, this sets *err to a constant string 112 : describing the error. There is no need to free that string. */ 113 : 114 : ulong 115 : fd_rocksdb_first_slot( fd_rocksdb_t * db, 116 : char ** err ); 117 : 118 : /* fd_rocksdb_copy_over_slot_indexed_range copies over all entries for a 119 : given column family index into another rocksdb assuming that the key 120 : is prefixed with the slot number. This includes column families where 121 : the key is just the slot number but also ones where the key starts with 122 : the slot number. */ 123 : 124 : int 125 : fd_rocksdb_copy_over_slot_indexed_range( fd_rocksdb_t * src, 126 : fd_rocksdb_t * dst, 127 : ulong cf_idx, 128 : ulong start_slot, 129 : ulong end_slot ); 130 : /* fd_rocksdb_insert_entry inserts a key, value pair into a given rocksdb */ 131 : 132 : int 133 : fd_rocksdb_insert_entry( fd_rocksdb_t * db, 134 : ulong cf_idx, 135 : const char * key, 136 : ulong key_len, 137 : const char * value, 138 : ulong value_len ); 139 : 140 : 141 : FD_PROTOTYPES_END 142 : 143 : #endif 144 : 145 : #endif // HEADER_fd_src_flamenco_runtime_fd_rocksdb_h