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 33 75.8 %
Date: 2026-06-29 05:51:35 Functions: 1 5 20.0 %

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

Generated by: LCOV version 1.14