LCOV - code coverage report
Current view: top level - discof/restore/utils - fd_slot_delta_parser.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 25 34 73.5 %
Date: 2026-09-17 04:28:31 Functions: 1 7 14.3 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_discof_restore_utils_fd_slot_delta_parser_h
       2             : #define HEADER_fd_src_discof_restore_utils_fd_slot_delta_parser_h
       3             : 
       4             : #include "../../../util/fd_util_base.h"
       5             : 
       6             : struct fd_slot_delta_parser_private;
       7             : typedef struct fd_slot_delta_parser_private fd_slot_delta_parser_t;
       8             : 
       9             : struct fd_sstxncache_entry {
      10             :   ulong slot;
      11             :   uchar blockhash[ 32UL ];
      12             :   uchar txnhash[ 20UL ];
      13             :   uchar result;
      14             : };
      15             : typedef struct fd_sstxncache_entry fd_sstxncache_entry_t;
      16             : 
      17             : struct fd_sstxncache_hash {
      18             :   uchar txnhash[ 20UL ];
      19             : };
      20             : typedef struct fd_sstxncache_hash fd_sstxncache_hash_t;
      21             : 
      22          42 : #define FD_SLOT_DELTA_MAX_ENTRIES (300UL)
      23             : 
      24             : /* status cache txn hashes are a 20 byte extract of the 32 byte txn
      25             :    message hash.  The txnhash_offset specifies where it is sampled at.
      26             :    Due to an Agave bug, the max offset is 11 bytes.  */
      27             : #define FD_SLOT_DELTA_MAX_TXNHASH_OFFSET (11UL)
      28             : 
      29             : struct fd_slot_entry {
      30             :   ulong slot;
      31             : 
      32             :   struct {
      33             :     ulong next;
      34             :   } pool;
      35             : 
      36             :   struct {
      37             :     ulong next;
      38             :     ulong prev;
      39             :   } map;
      40             : };
      41             : typedef struct fd_slot_entry fd_slot_entry_t;
      42             : 
      43             : #define POOL_NAME  slot_pool
      44          84 : #define POOL_T     fd_slot_entry_t
      45             : #define POOL_IDX_T ulong
      46       12600 : #define POOL_NEXT  pool.next
      47             : #include "../../../util/tmpl/fd_pool.c"
      48             : 
      49             : #define MAP_NAME                           slot_set
      50        2889 : #define MAP_KEY                            slot
      51             : #define MAP_KEY_T                          ulong
      52          69 : #define MAP_ELE_T                          fd_slot_entry_t
      53        3513 : #define MAP_PREV                           map.prev
      54        3738 : #define MAP_NEXT                           map.next
      55             : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
      56             : #include "../../../util/tmpl/fd_map_chain.c"
      57             : 
      58             : typedef void
      59             : (* fd_slot_delta_parser_process_group_fn_t)( void *        _ctx,
      60             :                                              uchar const * blockhash,
      61             :                                              ulong         txnhash_offset );
      62             : 
      63             : typedef void
      64             : (* fd_slot_delta_parser_process_entry_fn_t)( void *                        _ctx,
      65             :                                              fd_sstxncache_entry_t const * entry );
      66             : 
      67             : FD_PROTOTYPES_BEGIN
      68             : 
      69             : FD_FN_CONST ulong
      70             : fd_slot_delta_parser_align( void );
      71             : 
      72             : FD_FN_CONST ulong
      73             : fd_slot_delta_parser_footprint( void );
      74             : 
      75             : void *
      76             : fd_slot_delta_parser_new( void * shmem );
      77             : 
      78             : fd_slot_delta_parser_t *
      79             : fd_slot_delta_parser_join( void * shmem );
      80             : 
      81             : void *
      82             : fd_slot_delta_parser_leave( fd_slot_delta_parser_t * parser );
      83             : 
      84             : void *
      85             : fd_slot_delta_parser_delete( void * shmem );
      86             : 
      87             : void
      88             : fd_slot_delta_parser_init( fd_slot_delta_parser_t * parser );
      89             : 
      90             : /* VerifySlotDeltasError::SlotIsNotRoot
      91             :    https://github.com/anza-xyz/agave/blob/v3.1.8/snapshots/src/error.rs#L135 */
      92           9 : #define FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_SLOT_IS_NOT_ROOT           (-1)
      93             : /* VerifySlotDeltasError:SlotHasMultipleEntries
      94             :    https://github.com/anza-xyz/agave/blob/v3.1.8/snapshots/src/error.rs#L141 */
      95           9 : #define FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_SLOT_HASH_MULTIPLE_ENTRIES (-2)
      96             : /* VerifySlotDeltasError::TooManyEntries
      97             :    https://github.com/anza-xyz/agave/blob/v3.1.8/snapshots/src/error.rs#L132 */
      98           9 : #define FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_TOO_MANY_ENTRIES           (-3)
      99           0 : #define FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_EXCESS_DATA_IN_BUFFER      (-4)
     100           9 : #define FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_INVALID_TXNHASH_OFFSET     (-5)
     101           3 : #define FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_UNEXPECTED_EOF             (-6)
     102           3 : #define FD_SLOT_DELTA_PARSER_ADVANCE_AGAIN                            ( 0)
     103      434082 : #define FD_SLOT_DELTA_PARSER_ADVANCE_ENTRY                            ( 1)
     104      234552 : #define FD_SLOT_DELTA_PARSER_ADVANCE_GROUP                            ( 2)
     105      256950 : #define FD_SLOT_DELTA_PARSER_ADVANCE_SLOT                             ( 3)
     106      254352 : #define FD_SLOT_DELTA_PARSER_ADVANCE_DONE                             ( 4)
     107             : 
     108             : static inline const char *
     109          12 : fd_slot_delta_parser_advance_str( int err ) {
     110          12 :   switch( err ) {
     111           3 :     case FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_SLOT_IS_NOT_ROOT:           return "error_slot_is_not_root";
     112           3 :     case FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_SLOT_HASH_MULTIPLE_ENTRIES: return "error_slot_hash_multiple_entries";
     113           3 :     case FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_TOO_MANY_ENTRIES:           return "error_too_many_entries";
     114           0 :     case FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_EXCESS_DATA_IN_BUFFER:      return "error_excess_data_in_buffer";
     115           3 :     case FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_INVALID_TXNHASH_OFFSET:     return "error_invalid_txnhash_offset";
     116           0 :     case FD_SLOT_DELTA_PARSER_ADVANCE_ERROR_UNEXPECTED_EOF:             return "error_unexpected_eof";
     117           0 :     case FD_SLOT_DELTA_PARSER_ADVANCE_AGAIN:                            return "again";
     118           0 :     case FD_SLOT_DELTA_PARSER_ADVANCE_ENTRY:                            return "entry";
     119           0 :     case FD_SLOT_DELTA_PARSER_ADVANCE_GROUP:                            return "group";
     120           0 :     case FD_SLOT_DELTA_PARSER_ADVANCE_SLOT:                             return "slot";
     121           0 :     case FD_SLOT_DELTA_PARSER_ADVANCE_DONE:                             return "done";
     122           0 :     default:                                                            return "unknown";
     123          12 :   }
     124          12 : }
     125             : 
     126             : struct fd_slot_delta_parser_advance_result {
     127             :   ulong bytes_consumed;
     128             :   union {
     129             :     fd_sstxncache_entry_t const * entry;
     130             :     ulong                         slot;
     131             : 
     132             :     struct {
     133             :       uchar const * blockhash;
     134             :       ulong         txnhash_offset;
     135             :       ulong         slot;
     136             :     } group;
     137             :   };
     138             : };
     139             : 
     140             : typedef struct fd_slot_delta_parser_advance_result fd_slot_delta_parser_advance_result_t;
     141             : 
     142             : int
     143             : fd_slot_delta_parser_consume( fd_slot_delta_parser_t *                parser,
     144             :                               uchar const *                           buf,
     145             :                               ulong                                   bufsz,
     146             :                               fd_slot_delta_parser_advance_result_t * result );
     147             : 
     148             : /* fd_slot_delta_slot_set is a hash set of slots from the txncache. */
     149             : struct fd_slot_delta_slot_set {
     150             :   slot_set_t *      map;
     151             :   fd_slot_entry_t * pool;
     152             :   ulong             ele_cnt; /* number of slots */
     153             : };
     154             : typedef struct fd_slot_delta_slot_set fd_slot_delta_slot_set_t;
     155             : 
     156             : fd_slot_delta_slot_set_t
     157             : fd_slot_delta_parser_slot_set( fd_slot_delta_parser_t * parser );
     158             : 
     159             : FD_PROTOTYPES_END
     160             : 
     161             : #endif /* HEADER_fd_src_discof_restore_utils_fd_slot_delta_parser_h */

Generated by: LCOV version 1.14