LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_blockhashes.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 36 42 85.7 %
Date: 2026-11-30 13:42:38 Functions: 5 5 100.0 %

          Line data    Source code
       1             : #include "fd_blockhashes.h"
       2             : 
       3             : fd_blockhashes_t *
       4             : fd_blockhashes_init( fd_blockhashes_t * mem,
       5        3066 :                      ulong              seed ) {
       6        3066 :   if( FD_UNLIKELY( !mem ) ) {
       7           0 :     FD_LOG_WARNING(( "NULL mem" ));
       8           0 :     return NULL;
       9           0 :   }
      10        3066 :   FD_TEST( fd_blockhash_deq_join( fd_blockhash_deq_new( &mem->d ) ) );
      11        3066 :   memset( mem->d.deque, 0x5a, sizeof(fd_blockhash_info_t) * FD_BLOCKHASHES_DEQ_MAX );
      12        3066 :   FD_TEST( fd_blockhash_map_join( fd_blockhash_map_new( mem, FD_BLOCKHASH_MAP_CHAIN_MAX, seed ) ) );
      13        3066 :   return mem;
      14        3066 : }
      15             : 
      16             : static void
      17           9 : fd_blockhashes_pop_old( fd_blockhashes_t * blockhashes ) {
      18           9 :   if( FD_UNLIKELY( fd_blockhash_deq_empty( blockhashes->d.deque ) ) ) return;
      19           9 :   fd_blockhash_info_t * info = fd_blockhash_deq_pop_head_nocopy( blockhashes->d.deque );
      20           9 :   fd_blockhash_map_ele_remove( blockhashes->map, &info->hash, NULL, blockhashes->d.deque );
      21           9 : }
      22             : 
      23             : void
      24           6 : fd_blockhashes_pop_new( fd_blockhashes_t * blockhashes ) {
      25           6 :   if( FD_UNLIKELY( fd_blockhash_deq_empty( blockhashes->d.deque ) ) ) return;
      26           6 :   fd_blockhash_info_t * info = fd_blockhash_deq_pop_tail_nocopy( blockhashes->d.deque );
      27           6 :   fd_blockhash_map_ele_remove( blockhashes->map, &info->hash, NULL, blockhashes->d.deque );
      28           6 : }
      29             : 
      30             : fd_blockhash_info_t *
      31             : fd_blockhashes_push_new( fd_blockhashes_t * blockhashes,
      32        5487 :                          fd_hash_t const *  hash ) {
      33        5487 :   if( FD_UNLIKELY( fd_blockhash_deq_full( blockhashes->d.deque ) ) ) {
      34           9 :     fd_blockhashes_pop_old( blockhashes );
      35           9 :   }
      36        5487 :   if( FD_UNLIKELY( fd_blockhash_map_idx_query( blockhashes->map, hash, ULONG_MAX, blockhashes->d.deque )!=ULONG_MAX ) ) {
      37           0 :     char bh_cstr[ FD_BASE58_ENCODED_32_SZ ]; fd_base58_encode_32( hash->uc, NULL, bh_cstr );
      38           0 :     FD_LOG_CRIT(( "Attempted to register duplicate blockhash %s", bh_cstr ));
      39           0 :   }
      40             : 
      41        5487 :   ulong hash_index = 0UL;
      42        5487 :   if( FD_LIKELY( !fd_blockhash_deq_empty( blockhashes->d.deque ) ) ) {
      43        2457 :     hash_index = fd_blockhash_deq_peek_tail_const( blockhashes->d.deque )->hash_index + 1UL;
      44        2457 :   }
      45             : 
      46        5487 :   fd_blockhash_info_t * info = fd_blockhash_deq_push_tail_nocopy( blockhashes->d.deque );
      47        5487 :   *info = (fd_blockhash_info_t) { .hash = *hash, .hash_index = hash_index };
      48             : 
      49        5487 :   fd_blockhash_map_ele_insert( blockhashes->map, info, blockhashes->d.deque );
      50             : 
      51        5487 :   return info;
      52        5487 : }
      53             : 
      54             : FD_FN_PURE int
      55             : fd_blockhashes_check_age( fd_blockhashes_t const * blockhashes,
      56             :                           fd_hash_t const *        blockhash,
      57        1332 :                           ulong                    max_age ) {
      58        1332 :   ulong const idx = fd_blockhash_map_idx_query_const( blockhashes->map, blockhash, ULONG_MAX, blockhashes->d.deque );
      59        1332 :   if( FD_UNLIKELY( idx==ULONG_MAX ) ) return 0;
      60        1293 :   return fd_blockhashes_age( blockhashes, &blockhashes->d.deque[ idx ] )<=max_age;
      61        1332 : }

Generated by: LCOV version 1.14