LCOV - code coverage report
Current view: top level - funk - fd_funk_rec.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 184 285 64.6 %
Date: 2026-01-11 05:23:55 Functions: 7 9 77.8 %

          Line data    Source code
       1             : #include "fd_funk_private.h"
       2             : #include "../util/racesan/fd_racesan_target.h"
       3             : 
       4             : /* Provide the actual record map implementation */
       5             : 
       6             : #define POOL_NAME       fd_funk_rec_pool
       7     2556537 : #define POOL_ELE_T      fd_funk_rec_t
       8             : #define POOL_IDX_T      uint
       9     2566314 : #define POOL_NEXT       map_next
      10             : #define POOL_IMPL_STYLE 2
      11             : #define POOL_LAZY       1
      12             : #include "../util/tmpl/fd_pool_para.c"
      13             : 
      14             : #define MAP_NAME              fd_funk_rec_map
      15     1380141 : #define MAP_ELE_T             fd_funk_rec_t
      16       12237 : #define MAP_KEY_T             fd_funk_xid_key_pair_t
      17     1289526 : #define MAP_KEY               pair
      18             : #define MAP_KEY_EQ(k0,k1)     fd_funk_xid_key_pair_eq((k0),(k1))
      19             : #define MAP_KEY_HASH(k0,seed) fd_funk_xid_key_pair_hash((k0),(seed))
      20     1379541 : #define MAP_IDX_T             uint
      21     3283935 : #define MAP_NEXT              map_next
      22         123 : #define MAP_MAGIC             (0xf173da2ce77ecdb0UL) /* Firedancer rec db version 0 */
      23     5216520 : #define MAP_CNT_WIDTH         FD_FUNK_REC_MAP_CNT_WIDTH
      24             : #define MAP_IMPL_STYLE        2
      25             : #define MAP_PEDANTIC          1
      26             : #include "../util/tmpl/fd_map_chain_para.c"
      27             : 
      28             : static fd_funk_txn_t *
      29             : fd_funk_rec_txn_borrow( fd_funk_t const *         funk,
      30             :                         fd_funk_txn_xid_t const * xid,
      31     1276974 :                         fd_funk_txn_map_query_t * query ) {
      32     1276974 :   memset( query, 0, sizeof(fd_funk_txn_map_query_t) );
      33     1276974 :   if( fd_funk_txn_xid_eq( xid, funk->shmem->last_publish ) ) return NULL;
      34             : 
      35     1276974 :   fd_funk_txn_map_query_t txn_query[1];
      36     1276974 :   for(;;) {
      37     1276974 :     int txn_query_err = fd_funk_txn_map_query_try( funk->txn_map, xid, NULL, txn_query, 0 );
      38     1276974 :     if( FD_UNLIKELY( txn_query_err==FD_MAP_ERR_AGAIN ) ) continue;
      39     1276974 :     if( FD_UNLIKELY( txn_query_err!=FD_MAP_SUCCESS ) ) {
      40           0 :       FD_LOG_CRIT(( "fd_funk_rec op failed: txn_map_query_try(%lu:%lu) error %i-%s",
      41           0 :                    xid->ul[0], xid->ul[1],
      42           0 :                    txn_query_err, fd_map_strerror( txn_query_err ) ));
      43           0 :     }
      44     1276974 :     break;
      45     1276974 :   }
      46     1276974 :   fd_funk_txn_t * txn = fd_funk_txn_map_query_ele( txn_query );
      47     1276974 :   uint txn_state = FD_VOLATILE_CONST( txn->state );
      48     1276974 :   if( FD_UNLIKELY( txn_state!=FD_FUNK_TXN_STATE_ACTIVE ) ) {
      49           0 :     FD_LOG_CRIT(( "fd_funk_rec op failed: txn %p %lu:%lu state is %u-%s",
      50           0 :                   (void *)txn, xid->ul[0], xid->ul[1],
      51           0 :                   txn_state, fd_funk_txn_state_str( txn_state ) ));
      52           0 :   }
      53     1276974 :   return txn;
      54     1276974 : }
      55             : 
      56             : static void
      57     1276974 : fd_funk_rec_txn_release( fd_funk_txn_map_query_t const * query ) {
      58     1276974 :   if( !query->ele ) return;
      59           0 :   if( FD_UNLIKELY( fd_funk_txn_map_query_test( query )!=FD_MAP_SUCCESS ) ) {
      60           0 :     FD_LOG_CRIT(( "fd_funk_rec_txn_release: fd_funk_txn_map_query_test failed (data race detected?)" ));
      61           0 :   }
      62           0 : }
      63             : 
      64             : static void
      65             : fd_funk_rec_key_set_pair( fd_funk_xid_key_pair_t *  key_pair,
      66             :                           fd_funk_txn_xid_t const * xid,
      67           0 :                           fd_funk_rec_key_t const * key ) {
      68           0 :   fd_funk_txn_xid_copy( key_pair->xid, xid );
      69           0 :   fd_funk_rec_key_copy( key_pair->key, key );
      70           0 : }
      71             : 
      72             : fd_funk_rec_t *
      73             : fd_funk_rec_query_try( fd_funk_t *               funk,
      74             :                        fd_funk_txn_xid_t const * xid,
      75             :                        fd_funk_rec_key_t const * key,
      76        1005 :                        fd_funk_rec_query_t *     query ) {
      77        1005 :   if( FD_UNLIKELY( !funk  ) ) FD_LOG_CRIT(( "NULL funk"  ));
      78        1005 :   if( FD_UNLIKELY( !xid   ) ) FD_LOG_CRIT(( "NULL xid"   ));
      79        1005 :   if( FD_UNLIKELY( !key   ) ) FD_LOG_CRIT(( "NULL key"   ));
      80        1005 :   if( FD_UNLIKELY( !query ) ) FD_LOG_CRIT(( "NULL query" ));
      81             : 
      82        1005 :   fd_funk_xid_key_pair_t pair[1];
      83        1005 :   if( FD_UNLIKELY( fd_funk_txn_xid_eq( xid, funk->shmem->last_publish ) ) ) {
      84           0 :     fd_funk_txn_xid_set_root( pair->xid );
      85        1005 :   } else {
      86        1005 :     fd_funk_txn_xid_copy( pair->xid, xid );
      87        1005 :   }
      88        1005 :   fd_funk_rec_key_copy( pair->key, key );
      89             : 
      90        1005 :   for(;;) {
      91        1005 :     int err = fd_funk_rec_map_query_try( funk->rec_map, pair, NULL, query, 0 );
      92        1005 :     if( err == FD_MAP_SUCCESS )   break;
      93           0 :     if( err == FD_MAP_ERR_KEY )   return NULL;
      94           0 :     if( err == FD_MAP_ERR_AGAIN ) continue;
      95           0 :     FD_LOG_CRIT(( "query returned err %d", err ));
      96           0 :   }
      97        1005 :   return fd_funk_rec_map_query_ele( query );
      98        1005 : }
      99             : 
     100             : fd_funk_rec_t const *
     101             : fd_funk_rec_query_try_global( fd_funk_t const *         funk,
     102             :                               fd_funk_txn_xid_t const * xid,
     103             :                               fd_funk_rec_key_t const * key,
     104             :                               fd_funk_txn_xid_t *       txn_out,
     105           0 :                               fd_funk_rec_query_t *     query ) {
     106           0 :   if( FD_UNLIKELY( !funk  ) ) FD_LOG_CRIT(( "NULL funk"  ));
     107           0 :   if( FD_UNLIKELY( !key   ) ) FD_LOG_CRIT(( "NULL key"   ));
     108           0 :   if( FD_UNLIKELY( !query ) ) FD_LOG_CRIT(( "NULL query" ));
     109             : 
     110             :   /* Attach to the funk transaction */
     111             : 
     112           0 :   fd_funk_txn_map_query_t txn_query[1];
     113           0 :   fd_funk_txn_t * txn = fd_funk_rec_txn_borrow( funk, xid, txn_query );
     114             : 
     115             :   /* Look for the first element in the hash chain with the right
     116             :      record key. This takes advantage of the fact that elements with
     117             :      the same record key appear on the same hash chain in order of
     118             :      newest to oldest. */
     119             : 
     120           0 :   fd_funk_xid_key_pair_t pair[1];
     121           0 :   fd_funk_rec_key_set_pair( pair, xid, key );
     122             : 
     123           0 :   fd_funk_rec_map_t const * rec_map = funk->rec_map;
     124             : 
     125           0 :   ulong hash = fd_funk_rec_map_key_hash( pair, rec_map->map->seed );
     126           0 :   ulong chain_idx = (hash & (rec_map->map->chain_cnt-1UL) );
     127           0 :   fd_funk_rec_map_shmem_private_chain_t * chain = fd_funk_rec_map_shmem_private_chain( rec_map->map, hash );
     128             : 
     129             :   /* Start a speculative record map transaction */
     130             : 
     131           0 :   struct {
     132           0 :     fd_funk_rec_map_txn_t txn;
     133           0 :     fd_funk_rec_map_txn_private_info_t lock[1];
     134           0 :   } txn_mem;
     135           0 :   fd_funk_rec_map_txn_t * rec_txn;
     136           0 :   fd_funk_rec_t const * res;
     137             : 
     138           0 : retry:
     139           0 :   res = NULL;
     140           0 :   rec_txn = fd_funk_rec_map_txn_init( &txn_mem.txn, (void *)rec_map, 1UL );
     141           0 :   txn_mem.lock[ 0 ].chain = chain;
     142           0 :   txn_mem.txn.spec_cnt++;
     143           0 :   if( FD_UNLIKELY( fd_funk_rec_map_txn_try( rec_txn, FD_MAP_FLAG_BLOCKING )!=FD_MAP_SUCCESS ) ) {
     144           0 :     FD_LOG_CRIT(( "fd_funk_rec_map_txn_try failed" ));
     145           0 :   }
     146             : 
     147           0 :   query->ele     = NULL;
     148           0 :   query->chain   = chain;
     149           0 :   query->ver_cnt = txn_mem.lock[0].ver_cnt;
     150             : 
     151           0 :   for( fd_funk_rec_map_iter_t iter = fd_funk_rec_map_iter( funk->rec_map, chain_idx );
     152           0 :        !fd_funk_rec_map_iter_done( iter );
     153           0 :        iter = fd_funk_rec_map_iter_next( iter ) ) {
     154           0 :     fd_funk_rec_t const * ele = fd_funk_rec_map_iter_ele_const( iter );
     155           0 :     if( FD_LIKELY( fd_funk_rec_key_eq( key, ele->pair.key ) ) ) {
     156             : 
     157             :       /* For cur_txn in path from [txn] to [root] where root is NULL */
     158             : 
     159           0 :       for( fd_funk_txn_t const * cur_txn = txn; ; cur_txn = fd_funk_txn_parent( cur_txn, funk->txn_pool ) ) {
     160             :         /* If record ele is part of transaction cur_txn, we have a
     161             :            match. According to the property above, this will be the
     162             :            youngest descendent in the transaction stack. */
     163             : 
     164           0 :         int match = FD_UNLIKELY( cur_txn ) ? /* opt for root find (FIXME: eliminate branch with cmov into txn_xid_eq?) */
     165           0 :           fd_funk_txn_xid_eq( &cur_txn->xid, ele->pair.xid ) :
     166           0 :           fd_funk_txn_xid_eq_root( ele->pair.xid );
     167             : 
     168           0 :         if( FD_LIKELY( match ) ) {
     169           0 :           if( txn_out ) {
     170           0 :             *txn_out = *( cur_txn ? &cur_txn->xid : fd_funk_last_publish( funk ) );
     171           0 :           }
     172           0 :           query->ele = (fd_funk_rec_t *)ele;
     173           0 :           res = query->ele;
     174           0 :           goto found;
     175           0 :         }
     176             : 
     177           0 :         if( cur_txn == NULL ) break;
     178           0 :       }
     179           0 :     }
     180           0 :   }
     181             : 
     182           0 : found:
     183           0 :   if( FD_UNLIKELY( fd_funk_rec_map_txn_test( rec_txn )!=FD_MAP_SUCCESS ) ) goto retry;
     184           0 :   if( FD_LIKELY( txn ) ) fd_funk_txn_xid_assert( txn, pair->xid );
     185           0 :   fd_funk_rec_txn_release( txn_query );
     186           0 :   return res;
     187           0 : }
     188             : 
     189             : fd_funk_rec_t *
     190             : fd_funk_rec_prepare( fd_funk_t *               funk,
     191             :                      fd_funk_txn_xid_t const * xid,
     192             :                      fd_funk_rec_key_t const * key,
     193             :                      fd_funk_rec_prepare_t *   prepare,
     194     1276974 :                      int *                     opt_err ) {
     195     1276974 :   if( FD_UNLIKELY( !funk    ) ) FD_LOG_CRIT(( "NULL funk"    ));
     196     1276974 :   if( FD_UNLIKELY( !xid     ) ) FD_LOG_CRIT(( "NULL xid"     ));
     197     1276974 :   if( FD_UNLIKELY( !prepare ) ) FD_LOG_CRIT(( "NULL prepare" ));
     198             : 
     199     1276974 :   fd_funk_txn_map_query_t txn_query[1];
     200     1276974 :   fd_funk_txn_t * txn = fd_funk_rec_txn_borrow( funk, xid, txn_query );
     201             : 
     202     1276974 :   memset( prepare, 0, sizeof(fd_funk_rec_prepare_t) );
     203             : 
     204     1276974 :   if( !txn ) { /* Modifying last published */
     205           0 :     if( FD_UNLIKELY( fd_funk_last_publish_is_frozen( funk ) ) ) {
     206           0 :       fd_int_store_if( !!opt_err, opt_err, FD_FUNK_ERR_FROZEN );
     207           0 :       fd_funk_rec_txn_release( txn_query );
     208           0 :       return NULL;
     209           0 :     }
     210     1276974 :   } else {
     211     1276974 :     if( FD_UNLIKELY( fd_funk_txn_is_frozen( txn ) ) ) {
     212           0 :       fd_int_store_if( !!opt_err, opt_err, FD_FUNK_ERR_FROZEN );
     213           0 :       fd_funk_rec_txn_release( txn_query );
     214           0 :       return NULL;
     215           0 :     }
     216     1276974 :   }
     217             : 
     218     1276974 :   fd_funk_rec_t * rec = prepare->rec = fd_funk_rec_pool_acquire( funk->rec_pool, NULL, 1, opt_err );
     219     1276974 :   if( opt_err && *opt_err == FD_POOL_ERR_CORRUPT ) {
     220           0 :     FD_LOG_CRIT(( "corrupt element returned from funk rec pool" ));
     221           0 :   }
     222     1276974 :   if( FD_UNLIKELY( !rec ) ) {
     223           0 :     fd_int_store_if( !!opt_err, opt_err, FD_FUNK_ERR_REC );
     224           0 :     fd_funk_rec_txn_release( txn_query );
     225           0 :     return rec;
     226           0 :   }
     227             : 
     228     1276974 :   fd_funk_val_init( rec );
     229     1276974 :   if( txn == NULL ) {
     230           0 :     fd_funk_txn_xid_set_root( rec->pair.xid );
     231     1276974 :   } else {
     232     1276974 :     fd_funk_txn_xid_copy( rec->pair.xid, &txn->xid );
     233     1276974 :     prepare->rec_head_idx = &txn->rec_head_idx;
     234     1276974 :     prepare->rec_tail_idx = &txn->rec_tail_idx;
     235     1276974 :   }
     236     1276974 :   fd_funk_rec_key_copy( rec->pair.key, key );
     237     1276974 :   rec->tag      = 0;
     238     1276974 :   rec->pub      = 0;
     239     1276974 :   rec->prev_idx = FD_FUNK_REC_IDX_NULL;
     240     1276974 :   rec->next_idx = FD_FUNK_REC_IDX_NULL;
     241     1276974 :   fd_funk_rec_txn_release( txn_query );
     242     1276974 :   return rec;
     243     1276974 : }
     244             : 
     245             : #if FD_HAS_ATOMIC
     246             : 
     247             : static void
     248             : fd_funk_rec_push_tail( fd_funk_t *             funk,
     249     1277214 :                        fd_funk_rec_prepare_t * prepare ) {
     250     1277214 :   fd_funk_rec_t * rec = prepare->rec;
     251     1277214 :   uint rec_idx = (uint)( rec - funk->rec_pool->ele );
     252     1277214 :   uint * rec_head_idx = prepare->rec_head_idx;
     253     1277214 :   uint * rec_tail_idx = prepare->rec_tail_idx;
     254             : 
     255     1277214 :   for(;;) {
     256             : 
     257             :     /* Doubly linked list append.  Robust in the event of concurrent
     258             :        publishes.  Iteration during publish not supported.  Sequence:
     259             :        - Identify tail element
     260             :        - Set new element's prev and next pointers
     261             :        - Set tail element's next pointer
     262             :        - Set tail pointer */
     263             : 
     264     1277214 :     uint rec_prev_idx = FD_VOLATILE_CONST( *rec_tail_idx );
     265     1277214 :     rec->prev_idx = rec_prev_idx;
     266     1277214 :     FD_COMPILER_MFENCE();
     267             : 
     268     1277214 :     uint * next_idx_p;
     269     1277214 :     if( fd_funk_rec_idx_is_null( rec_prev_idx ) ) {
     270      395934 :       next_idx_p = rec_head_idx;
     271      881280 :     } else {
     272      881280 :       next_idx_p = &funk->rec_pool->ele[ rec_prev_idx ].next_idx;
     273      881280 :     }
     274             : 
     275     1277214 :     fd_racesan_hook( "funk_rec_push_tail:next_cas" );
     276     1277214 :     if( FD_UNLIKELY( !__sync_bool_compare_and_swap( next_idx_p, FD_FUNK_REC_IDX_NULL, rec_idx ) ) ) {
     277             :       /* Another thread beat us to the punch */
     278           0 :       FD_SPIN_PAUSE();
     279           0 :       continue;
     280           0 :     }
     281             : 
     282     1277214 :     fd_racesan_hook( "funk_rec_push_tail:tail_cas" );
     283     1277214 :     if( FD_UNLIKELY( !__sync_bool_compare_and_swap( rec_tail_idx, rec_prev_idx, rec_idx ) ) ) {
     284             :       /* This CAS is guaranteed to succeed if the previous CAS passed. */
     285           0 :       FD_LOG_CRIT(( "Irrecoverable data race encountered while appending to txn rec list (invariant violation?): cas(%p,%u,%u)",
     286           0 :                     (void *)rec_tail_idx, rec_prev_idx, rec_idx ));
     287           0 :     }
     288             : 
     289     1277214 :     break;
     290     1277214 :   }
     291     1277214 : }
     292             : 
     293             : #else
     294             : 
     295             : static void
     296             : fd_funk_rec_push_tail( fd_funk_t *             funk,
     297             :                        fd_funk_rec_prepare_t * prepare ) {
     298             :   fd_funk_rec_t * rec = prepare->rec;
     299             :   uint rec_idx      = (uint)( rec - funk->rec_pool->ele );
     300             :   uint * rec_head_idx = prepare->rec_head_idx;
     301             :   uint * rec_tail_idx = prepare->rec_tail_idx;
     302             :   uint rec_prev_idx = *rec_tail_idx;
     303             :   *rec_tail_idx = rec_idx;
     304             :   rec->prev_idx = rec_prev_idx;
     305             :   rec->next_idx = FD_FUNK_REC_IDX_NULL;
     306             :   if( fd_funk_rec_idx_is_null( rec_prev_idx ) ) {
     307             :     *rec_head_idx = rec_idx;
     308             :   } else {
     309             :     funk->rec_pool->ele[ rec_prev_idx ].next_idx = rec_idx;
     310             :   }
     311             : }
     312             : 
     313             : #endif
     314             : 
     315             : void
     316             : fd_funk_rec_publish( fd_funk_t *             funk,
     317     1277214 :                      fd_funk_rec_prepare_t * prepare ) {
     318     1277214 :   fd_funk_rec_t * rec = prepare->rec;
     319     1277214 :   rec->prev_idx = FD_FUNK_REC_IDX_NULL;
     320     1277214 :   rec->next_idx = FD_FUNK_REC_IDX_NULL;
     321     1277214 :   rec->pub      = 1;
     322             : 
     323     1277214 :   if( prepare->rec_head_idx ) {
     324     1277214 :     fd_funk_rec_push_tail( funk, prepare );
     325     1277214 :   }
     326             : 
     327     1277214 :   fd_racesan_hook( "funk_rec_publish:map_insert" );
     328     1277214 :   int insert_err = fd_funk_rec_map_insert( funk->rec_map, rec, FD_MAP_FLAG_BLOCKING );
     329     1277214 :   if( insert_err ) {
     330           0 :     FD_LOG_CRIT(( "fd_funk_rec_map_insert failed (%i-%s)", insert_err, fd_map_strerror( insert_err ) ));
     331           0 :   }
     332     1277214 : }
     333             : 
     334             : int
     335         243 : fd_funk_rec_verify( fd_funk_t * funk ) {
     336         243 :   fd_funk_rec_map_t *  rec_map  = funk->rec_map;
     337         243 :   fd_funk_rec_pool_t * rec_pool = funk->rec_pool;
     338         243 :   ulong rec_max = fd_funk_rec_pool_ele_max( rec_pool );
     339             : 
     340      495348 : # define TEST(c) do {                                                                           \
     341      495348 :     if( FD_UNLIKELY( !(c) ) ) { FD_LOG_WARNING(( "FAIL: %s", #c )); return FD_FUNK_ERR_INVAL; } \
     342      495348 :   } while(0)
     343             : 
     344         243 :   TEST( !fd_funk_rec_map_verify( rec_map ) );
     345         243 :   TEST( !fd_funk_rec_pool_verify( rec_pool ) );
     346             : 
     347             :   /* Iterate (again) over all records in use */
     348             : 
     349         243 :   fd_funk_rec_map_shmem_private_chain_t * chain_tbl =
     350         243 :     fd_funk_rec_map_shmem_private_chain( rec_map->map, 0UL );
     351         243 :   ulong chain_cnt = fd_funk_rec_map_chain_cnt( rec_map );
     352      444819 :   for( ulong chain_idx=0UL; chain_idx<chain_cnt; chain_idx++ ) {
     353      444576 :     ulong chain_ele_cnt = fd_funk_rec_map_private_vcnt_cnt( chain_tbl[ chain_idx ].ver_cnt );
     354      444576 :     ulong chain_ele_idx = 0UL;
     355      444576 :     for( fd_funk_rec_map_iter_t iter = fd_funk_rec_map_iter( rec_map, chain_idx );
     356      456813 :          !fd_funk_rec_map_iter_done( iter );
     357      444576 :          iter = fd_funk_rec_map_iter_next( iter ), chain_ele_idx++ ) {
     358       12237 :       fd_funk_rec_t const * rec = fd_funk_rec_map_iter_ele_const( iter );
     359             : 
     360             :       /* Make sure every record either links up with the last published
     361             :          transaction or an in-prep transaction and the flags are sane. */
     362             : 
     363       12237 :       fd_funk_txn_xid_t const * xid = fd_funk_rec_xid( rec );
     364             : 
     365       12237 :       if( fd_funk_txn_xid_eq_root( xid ) ) { /* This is a record from the last published transaction */
     366             : 
     367       11232 :         TEST( fd_funk_txn_xid_eq_root( xid ) );
     368             :         /* No record linked list at the root txn */
     369       11232 :         TEST( fd_funk_rec_idx_is_null( rec->prev_idx ) );
     370       11232 :         TEST( fd_funk_rec_idx_is_null( rec->next_idx ) );
     371             : 
     372       11232 :       } else { /* This is a record from an in-prep transaction */
     373             : 
     374        1005 :         fd_funk_txn_map_query_t query[1];
     375        1005 :         TEST( fd_funk_txn_map_query_try( funk->txn_map, xid, NULL, query, 0 )==FD_MAP_SUCCESS );
     376             : 
     377        1005 :       }
     378       12237 :     }
     379      444576 :     TEST( chain_ele_idx==chain_ele_cnt );
     380      444576 :   }
     381             : 
     382             :   /* Clear record tags and then verify membership */
     383             : 
     384      889395 :   for( ulong rec_idx=0UL; rec_idx<rec_max; rec_idx++ ) rec_pool->ele[ rec_idx ].tag = 0;
     385             : 
     386         243 :   do {
     387         243 :     fd_funk_all_iter_t iter[1];
     388       12480 :     for( fd_funk_all_iter_new( funk, iter ); !fd_funk_all_iter_done( iter ); fd_funk_all_iter_next( iter ) ) {
     389       12237 :       fd_funk_rec_t * rec = fd_funk_all_iter_ele( iter );
     390       12237 :       if( fd_funk_txn_xid_eq_root( rec->pair.xid ) ) {
     391       11232 :         TEST( !rec->tag );
     392       11232 :         rec->tag = 1;
     393       11232 :       }
     394       12237 :     }
     395             : 
     396         243 :     fd_funk_txn_all_iter_t txn_iter[1];
     397         834 :     for( fd_funk_txn_all_iter_new( funk, txn_iter ); !fd_funk_txn_all_iter_done( txn_iter ); fd_funk_txn_all_iter_next( txn_iter ) ) {
     398         591 :       fd_funk_txn_t const * txn = fd_funk_txn_all_iter_ele_const( txn_iter );
     399             : 
     400         591 :       uint rec_idx = txn->rec_head_idx;
     401        1596 :       while( !fd_funk_rec_idx_is_null( rec_idx ) ) {
     402        1005 :         TEST( (rec_idx<rec_max) && !rec_pool->ele[ rec_idx ].tag );
     403        1005 :         rec_pool->ele[ rec_idx ].tag = 1;
     404        1005 :         fd_funk_rec_query_t query[1];
     405        1005 :         fd_funk_rec_t const * rec2 = fd_funk_rec_query_try( funk, &txn->xid, rec_pool->ele[ rec_idx ].pair.key, query );
     406        1005 :         TEST( rec2 == rec_pool->ele + rec_idx );
     407        1005 :         uint next_idx = rec_pool->ele[ rec_idx ].next_idx;
     408        1005 :         if( !fd_funk_rec_idx_is_null( next_idx ) ) TEST( rec_pool->ele[ next_idx ].prev_idx==rec_idx );
     409        1005 :         rec_idx = next_idx;
     410        1005 :       }
     411         591 :     }
     412         243 :   } while(0);
     413             : 
     414         243 :   do {
     415         243 :     fd_funk_txn_all_iter_t txn_iter[1];
     416         834 :     for( fd_funk_txn_all_iter_new( funk, txn_iter ); !fd_funk_txn_all_iter_done( txn_iter ); fd_funk_txn_all_iter_next( txn_iter ) ) {
     417         591 :       fd_funk_txn_t const * txn = fd_funk_txn_all_iter_ele_const( txn_iter );
     418             : 
     419         591 :       uint  rec_idx = txn->rec_tail_idx;
     420        1596 :       while( !fd_funk_rec_idx_is_null( rec_idx ) ) {
     421        1005 :         TEST( (rec_idx<rec_max) && rec_pool->ele[ rec_idx ].tag );
     422        1005 :         rec_pool->ele[ rec_idx ].tag = 0;
     423        1005 :         uint prev_idx = rec_pool->ele[ rec_idx ].prev_idx;
     424        1005 :         if( !fd_funk_rec_idx_is_null( prev_idx ) ) TEST( rec_pool->ele[ prev_idx ].next_idx==rec_idx );
     425        1005 :         rec_idx = prev_idx;
     426        1005 :       }
     427         591 :     }
     428         243 :   } while(0);
     429             : 
     430         243 :   fd_funk_all_iter_t iter[1];
     431       12480 :   for( fd_funk_all_iter_new( funk, iter ); !fd_funk_all_iter_done( iter ); fd_funk_all_iter_next( iter ) ) {
     432       12237 :     fd_funk_rec_t const * rec = fd_funk_all_iter_ele( iter );
     433       12237 :     FD_TEST( rec->tag == fd_funk_txn_xid_eq_root( rec->pair.xid ) );
     434       12237 :   }
     435             : 
     436         243 : # undef TEST
     437             : 
     438         243 :   return FD_FUNK_SUCCESS;
     439         243 : }

Generated by: LCOV version 1.14