LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_rocksdb.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 22 0.0 %
Date: 2025-08-05 05:04:49 Functions: 0 0 -

          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             : #include "../types/fd_types.h"
       6             : 
       7             : /** allocations made for offline-replay in the blockstore */
       8             : struct fd_block {
       9             :   /* Used only in offline at the moment. Stored in the blockstore
      10             :      memory and used to iterate the block's contents.
      11             : 
      12             :    A block's data region is indexed to support iterating by shred,
      13             :    microblock/entry batch, microblock/entry, or transaction.
      14             :    This is done by iterating the headers for each, stored in allocated
      15             :    memory.
      16             :    To iterate shred payloads, for example, a caller should iterate the headers in tandem with the data region
      17             :    (offsetting by the bytes indicated in the shred header).
      18             : 
      19             :    Note random access of individual shred indices is not performant, due to the variable-length
      20             :    nature of shreds. */
      21             : 
      22             :   ulong data_gaddr;   /* ptr to the beginning of the block's allocated data region */
      23             :   ulong data_sz;      /* block size */
      24             :   ulong shreds_gaddr; /* ptr to the first fd_block_shred_t */
      25             :   ulong shreds_cnt;
      26             :   ulong batch_gaddr;  /* list of fd_block_entry_batch_t */
      27             :   ulong batch_cnt;
      28             :   ulong micros_gaddr; /* ptr to the list of fd_block_micro_t */
      29             :   ulong micros_cnt;
      30             : };
      31             : typedef struct fd_block fd_block_t;
      32             : 
      33             : #if FD_HAS_ROCKSDB
      34             : 
      35             : #include "../../ballet/shred/fd_shred.h"
      36             : #include <rocksdb/c.h>
      37             : 
      38           0 : #define FD_ROCKSDB_CF_CNT (21UL)
      39             : 
      40           0 : #define FD_ROCKSDB_CFIDX_DEFAULT                  (0UL)
      41           0 : #define FD_ROCKSDB_CFIDX_META                     (1UL)
      42           0 : #define FD_ROCKSDB_CFIDX_DEAD_SLOTS               (2UL)
      43           0 : #define FD_ROCKSDB_CFIDX_DUPLICATE_SLOTS          (3UL) /* Usually empty */
      44           0 : #define FD_ROCKSDB_CFIDX_ERASURE_META             (4UL)
      45           0 : #define FD_ROCKSDB_CFIDX_ORPHANS                  (5UL) /* Usually empty */
      46           0 : #define FD_ROCKSDB_CFIDX_BANK_HASHES              (6UL)
      47           0 : #define FD_ROCKSDB_CFIDX_ROOT                     (7UL)
      48           0 : #define FD_ROCKSDB_CFIDX_INDEX                    (8UL)
      49           0 : #define FD_ROCKSDB_CFIDX_DATA_SHRED               (9UL)
      50           0 : #define FD_ROCKSDB_CFIDX_CODE_SHRED               (10UL)
      51           0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_STATUS       (11UL)
      52           0 : #define FD_ROCKSDB_CFIDX_ADDRESS_SIGNATURES       (12UL)
      53           0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_MEMOS        (13UL)
      54           0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_STATUS_INDEX (14UL)
      55           0 : #define FD_ROCKSDB_CFIDX_REWARDS                  (15UL)
      56           0 : #define FD_ROCKSDB_CFIDX_BLOCKTIME                (16UL)
      57           0 : #define FD_ROCKSDB_CFIDX_PERF_SAMPLES             (17UL)
      58           0 : #define FD_ROCKSDB_CFIDX_BLOCK_HEIGHT             (18UL)
      59           0 : #define FD_ROCKSDB_CFIDX_OPTIMISTIC_SLOTS         (19UL)
      60           0 : #define FD_ROCKSDB_CFIDX_MERKLE_ROOT_META         (20UL) /* Usually empty */
      61             : 
      62             : /* Solana rocksdb client */
      63             : struct fd_rocksdb {
      64             :   rocksdb_t *                     db;
      65             :   const char *                    db_name;
      66             :   const char *                    cfgs      [ FD_ROCKSDB_CF_CNT ];
      67             :   rocksdb_column_family_handle_t* cf_handles[ FD_ROCKSDB_CF_CNT ];
      68             :   rocksdb_options_t *             opts;
      69             :   rocksdb_readoptions_t *         ro;
      70             :   rocksdb_writeoptions_t *        wo;
      71             : };
      72             : typedef struct fd_rocksdb fd_rocksdb_t;
      73             : #define FD_ROCKSDB_FOOTPRINT sizeof(fd_rocksdb_t)
      74             : #define FD_ROCKSDB_ALIGN (8UL)
      75             : 
      76             : /* root column iterator */
      77             : struct fd_rocksdb_root_iter {
      78             :   fd_rocksdb_t *                  db;
      79             :   rocksdb_iterator_t*             iter;
      80             : };
      81             : typedef struct fd_rocksdb_root_iter fd_rocksdb_root_iter_t;
      82             : #define FD_ROCKSDB_ROOT_ITER_FOOTPRINT sizeof(fd_rocksdb_root_iter_t)
      83             : #define FD_ROCKSDB_ROOT_ITER_ALIGN (8UL)
      84             : 
      85             : FD_PROTOTYPES_BEGIN
      86             : 
      87             : void *
      88             : fd_rocksdb_root_iter_new( void * shiter );
      89             : 
      90             : fd_rocksdb_root_iter_t *
      91             : fd_rocksdb_root_iter_join( void * iter );
      92             : 
      93             : void *
      94             : fd_rocksdb_root_iter_leave( fd_rocksdb_root_iter_t * iter );
      95             : 
      96             : /* fd_rocksdb_root_iter_seek
      97             : 
      98             :     0 = success
      99             :    -1 = seek for supplied slot failed
     100             :    -2 = seek succeeded but slot did not match what we seeked for
     101             :    -3 = seek succeeded but points at an empty slot */
     102             : 
     103             : int
     104             : fd_rocksdb_root_iter_seek( fd_rocksdb_root_iter_t * iter,
     105             :                            fd_rocksdb_t *           db,
     106             :                            ulong                    slot,
     107             :                            fd_slot_meta_t *         m,
     108             :                            fd_valloc_t              valloc );
     109             : 
     110             : /*  fd_rocksdb_root_iter_next
     111             : 
     112             :     0 = success
     113             :    -1 = not properly initialized with a seek
     114             :    -2 = invalid starting iterator
     115             :    -3 = next returned an invalid iterator state
     116             :    -4 = seek succeeded but points at an empty slot */
     117             : 
     118             : int
     119             : fd_rocksdb_root_iter_next( fd_rocksdb_root_iter_t * iter,
     120             :                            fd_slot_meta_t *         m,
     121             :                            fd_valloc_t              valloc );
     122             : 
     123             : int
     124             : fd_rocksdb_root_iter_slot( fd_rocksdb_root_iter_t * self,
     125             :                            ulong *                  slot );
     126             : 
     127             : void
     128             : fd_rocksdb_root_iter_destroy( fd_rocksdb_root_iter_t * iter );
     129             : 
     130             : /* fd_rocksdb_init: Returns a pointer to a description of the error on failure
     131             : 
     132             :   The provided db_name needs to point at the actual rocksdb directory
     133             :   as apposed to the directory above (like the solana ledger-tool) */
     134             : 
     135             : char *
     136             : fd_rocksdb_init( fd_rocksdb_t * db,
     137             :                  char const *   db_name );
     138             : 
     139             : /* fd_rocksdb_new: Creates a new rocksdb
     140             : 
     141             :    The provided db_name has to the be the full path where the directory
     142             :    will be created. The fd_rocksdb_t object will be initialized */
     143             : 
     144             : void
     145             : fd_rocksdb_new( fd_rocksdb_t * db,
     146             :                 char const *   db_name );
     147             : 
     148             : /* fd_rocksdb_destroy
     149             : 
     150             :    Frees up the internal data structures */
     151             : 
     152             : void
     153             : fd_rocksdb_destroy( fd_rocksdb_t * db );
     154             : 
     155             : /* fd_rocksdb_last_slot:  Returns the last slot in the db
     156             : 
     157             :    This uses the root column to discover the slot of the last root in
     158             :    the db.  If there is an error, this sets *err to a constant string
     159             :    describing the error.  There is no need to free that string. */
     160             : 
     161             : ulong
     162             : fd_rocksdb_last_slot( fd_rocksdb_t * db,
     163             :                       char **        err );
     164             : 
     165             : /* fd_rocksdb_first_slot:  Returns the first slot in the db
     166             : 
     167             :    This uses the root column to discover the slot of the first root in
     168             :    the db.  If there is an error, this sets *err to a constant string
     169             :    describing the error.  There is no need to free that string. */
     170             : 
     171             : ulong
     172             : fd_rocksdb_first_slot( fd_rocksdb_t * db,
     173             :                        char **        err );
     174             : 
     175             : ulong
     176             : fd_rocksdb_find_last_slot( fd_rocksdb_t * db,
     177             :                            char **        err );
     178             : 
     179             : /* fd_rocksdb_get_meta
     180             : 
     181             :    Retrieves the meta structure associated with the supplied slot.  If
     182             :    there is an error, *err is set to a string describing the error.
     183             :    It is expected that you should free() the error once done with it
     184             : 
     185             :    returns a 0 if there is no obvious error */
     186             : int
     187             : fd_rocksdb_get_meta( fd_rocksdb_t *   db,
     188             :                      ulong            slot,
     189             :                      fd_slot_meta_t * m,
     190             :                      fd_valloc_t      valloc );
     191             : 
     192             : /* fd_rocksdb_get_txn_status_raw queries transaction status metadata.
     193             :    slot is the slot number of the block that contains the txn.  sig
     194             :    points to the first signature of the txn.  Returns data==NULL if
     195             :    record not found.  On success, creates a malloc-backed buffer to hold
     196             :    return value, copies raw serialized status into buffer, sets *psz to
     197             :    the byte size of the status and returns pointer to buffer.  Caller
     198             :    must free() non-NULL returned region.  On failure, returns NULL and
     199             :    content of *psz is undefined.  Value is Protobuf-encoded
     200             :    TransactionStatusMeta.  Use fd_solblock nanopb API to deserialize
     201             :    value. */
     202             : 
     203             : void *
     204             : fd_rocksdb_get_txn_status_raw( fd_rocksdb_t * self,
     205             :                                ulong          slot,
     206             :                                void const *   sig,
     207             :                                ulong *        psz );
     208             : 
     209             : /* fd_rocksdb_copy_over_slot_indexed_range copies over all entries for a
     210             :    given column family index into another rocksdb assuming that the key
     211             :    is prefixed with the slot number. This includes column families where
     212             :    the key is just the slot number but also ones where the key starts with
     213             :    the slot number. */
     214             : 
     215             : int
     216             : fd_rocksdb_copy_over_slot_indexed_range( fd_rocksdb_t * src,
     217             :                                          fd_rocksdb_t * dst,
     218             :                                          ulong          cf_idx,
     219             :                                          ulong          start_slot,
     220             :                                          ulong          end_slot );
     221             : 
     222             : /* fd_rocksdb_copy_over_txn_status constructs a key to query a transaction
     223             :    status and copies over the entry into another rocksdb. The index is used
     224             :    to specify which transaction. */
     225             : 
     226             : void
     227             : fd_rocksdb_copy_over_txn_status( fd_rocksdb_t * src,
     228             :                                  fd_rocksdb_t * dst,
     229             :                                  ulong          slot,
     230             :                                  void const *   sig );
     231             : 
     232             : /* fd_rocksdb_insert_entry inserts a key, value pair into a given rocksdb */
     233             : 
     234             : int
     235             : fd_rocksdb_insert_entry( fd_rocksdb_t * db,
     236             :                          ulong          cf_idx,
     237             :                          const char *   key,
     238             :                          ulong          key_len,
     239             :                          const char *   value,
     240             :                          ulong          value_len );
     241             : 
     242             : int
     243             : fd_rocksdb_import_block_shredcap( fd_rocksdb_t *             db,
     244             :                                   fd_slot_meta_t *           metadata,
     245             :                                   fd_io_buffered_ostream_t * ostream,
     246             :                                   fd_io_buffered_ostream_t * bank_hash_ostream,
     247             :                                   fd_valloc_t                valloc );
     248             : 
     249             : 
     250             : FD_PROTOTYPES_END
     251             : 
     252             : #endif
     253             : 
     254             : #endif // HEADER_fd_src_flamenco_runtime_fd_rocksdb_h

Generated by: LCOV version 1.14