LCOV - code coverage report
Current view: top level - funk - fd_funk.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 265 313 84.7 %
Date: 2026-06-06 07:11:05 Functions: 10 10 100.0 %

          Line data    Source code
       1             : #include "fd_funk.h"
       2             : #include "fd_funk_base.h"
       3             : #include <stdio.h>
       4             : 
       5             : ulong
       6        2388 : fd_funk_align( void ) {
       7        2388 :   return FD_FUNK_ALIGN;
       8        2388 : }
       9             : 
      10             : ulong
      11             : fd_funk_shmem_footprint( ulong txn_max,
      12         456 :                          ulong rec_max ) {
      13         456 :   if( FD_UNLIKELY( rec_max>UINT_MAX ) ) return 0UL;
      14             : 
      15         456 :   ulong l = FD_LAYOUT_INIT;
      16             : 
      17         456 :   l = FD_LAYOUT_APPEND( l, alignof(fd_funk_shmem_t), sizeof(fd_funk_shmem_t) );
      18             : 
      19         456 :   ulong txn_chain_cnt = fd_funk_txn_map_chain_cnt_est( txn_max );
      20         456 :   l = FD_LAYOUT_APPEND( l, fd_funk_txn_map_align(), fd_funk_txn_map_footprint( txn_chain_cnt ) );
      21         456 :   l = FD_LAYOUT_APPEND( l, fd_funk_txn_pool_align(), fd_funk_txn_pool_footprint() );
      22         456 :   l = FD_LAYOUT_APPEND( l, alignof(fd_funk_txn_t), sizeof(fd_funk_txn_t) * txn_max );
      23             : 
      24         456 :   ulong rec_chain_cnt = fd_funk_rec_map_chain_cnt_est( rec_max );
      25         456 :   l = FD_LAYOUT_APPEND( l, fd_funk_rec_map_align(), fd_funk_rec_map_footprint( rec_chain_cnt ) );
      26         456 :   l = FD_LAYOUT_APPEND( l, fd_funk_rec_pool_align(), fd_funk_rec_pool_footprint() );
      27         456 :   l = FD_LAYOUT_APPEND( l, alignof(fd_funk_rec_t), sizeof(fd_funk_rec_t) * rec_max );
      28             : 
      29         456 :   l = FD_LAYOUT_APPEND( l, fd_alloc_align(), fd_alloc_footprint() );
      30             : 
      31         456 :   return l;
      32         456 : }
      33             : 
      34             : ulong
      35             : fd_funk_locks_footprint( ulong txn_max,
      36         246 :                          ulong rec_max ) {
      37         246 :   ulong l = FD_LAYOUT_INIT;
      38         246 :   l = FD_LAYOUT_APPEND( l, alignof(fd_rwlock_t), sizeof(fd_rwlock_t) * txn_max );
      39         246 :   l = FD_LAYOUT_APPEND( l, alignof(ulong),       sizeof(ulong)       * rec_max );
      40         246 :   return FD_LAYOUT_FINI( l, fd_funk_align() );
      41         246 : }
      42             : 
      43             : /* TODO: Consider letter user just passing a join of alloc to use,
      44             :    inferring the backing wksp and cgroup_hint from that and then
      45             :    allocating exclusively from that? */
      46             : 
      47             : void *
      48             : fd_funk_shmem_new( void * shmem,
      49             :                    ulong  wksp_tag,
      50             :                    ulong  seed,
      51             :                    ulong  txn_max,
      52         225 :                    ulong  rec_max ) {
      53         225 :   fd_funk_shmem_t * funk = shmem;
      54         225 :   fd_wksp_t *       wksp = fd_wksp_containing( funk );
      55             : 
      56         225 :   if( FD_UNLIKELY( !funk ) ) {
      57           3 :     FD_LOG_WARNING(( "NULL funk" ));
      58           3 :     return NULL;
      59           3 :   }
      60             : 
      61         222 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)funk, fd_funk_align() ) ) ) {
      62           3 :     FD_LOG_WARNING(( "misaligned funk" ));
      63           3 :     return NULL;
      64           3 :   }
      65             : 
      66         219 :   if( FD_UNLIKELY( !wksp_tag ) ) {
      67           3 :     FD_LOG_WARNING(( "bad wksp_tag" ));
      68           3 :     return NULL;
      69           3 :   }
      70             : 
      71         216 :   if( FD_UNLIKELY( !wksp ) ) {
      72           3 :     FD_LOG_WARNING(( "shmem must be part of a workspace" ));
      73           3 :     return NULL;
      74           3 :   }
      75             : 
      76         213 :   if( FD_UNLIKELY( !txn_max || txn_max>FD_FUNK_TXN_IDX_NULL ) ) { /* See note in fd_funk.h about this limit */
      77           3 :     FD_LOG_WARNING(( "txn_max too large for index compression" ));
      78           3 :     return NULL;
      79           3 :   }
      80             : 
      81         210 :   if( FD_UNLIKELY( !rec_max || rec_max>UINT_MAX ) ) {
      82           0 :     FD_LOG_WARNING(( "invalid rec_max" ));
      83           0 :     return NULL;
      84           0 :   }
      85             : 
      86         210 :   FD_SCRATCH_ALLOC_INIT( l, funk+1 );
      87             : 
      88         210 :   ulong txn_chain_cnt = fd_funk_txn_map_chain_cnt_est( txn_max );
      89         210 :   void * txn_map = FD_SCRATCH_ALLOC_APPEND( l, fd_funk_txn_map_align(), fd_funk_txn_map_footprint( txn_chain_cnt ) );
      90         210 :   void * txn_pool = FD_SCRATCH_ALLOC_APPEND( l, fd_funk_txn_pool_align(), fd_funk_txn_pool_footprint() );
      91         210 :   fd_funk_txn_t * txn_ele = (fd_funk_txn_t *)FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_funk_txn_t), sizeof(fd_funk_txn_t) * txn_max );
      92             : 
      93           0 :   ulong rec_chain_cnt = fd_funk_rec_map_chain_cnt_est( rec_max );
      94         210 :   void * rec_map = FD_SCRATCH_ALLOC_APPEND( l, fd_funk_rec_map_align(), fd_funk_rec_map_footprint( rec_chain_cnt ) );
      95         210 :   void * rec_pool = FD_SCRATCH_ALLOC_APPEND( l, fd_funk_rec_pool_align(), fd_funk_rec_pool_footprint() );
      96         210 :   fd_funk_rec_t * rec_ele = (fd_funk_rec_t *)FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_funk_rec_t), sizeof(fd_funk_rec_t) * rec_max );
      97             : 
      98         210 :   void * alloc = FD_SCRATCH_ALLOC_APPEND( l, fd_alloc_align(), fd_alloc_footprint() );
      99             : 
     100         210 :   FD_TEST( _l == (ulong)funk + fd_funk_shmem_footprint( txn_max, rec_max ) );
     101             : 
     102         210 :   fd_memset( funk, 0, sizeof(fd_funk_shmem_t) );
     103             : 
     104         210 :   funk->funk_gaddr = fd_wksp_gaddr_fast( wksp, funk );
     105         210 :   funk->wksp_tag   = wksp_tag;
     106         210 :   funk->seed       = seed;
     107         210 :   funk->cycle_tag  = 3UL; /* various verify functions use tags 0-2 */
     108             : 
     109         210 :   funk->txn_map_gaddr = fd_wksp_gaddr_fast( wksp, fd_funk_txn_map_new( txn_map, txn_chain_cnt, seed ) );
     110         210 :   void * txn_pool2 = fd_funk_txn_pool_new( txn_pool );
     111         210 :   funk->txn_pool_gaddr = fd_wksp_gaddr_fast( wksp, txn_pool2 );
     112         210 :   fd_funk_txn_pool_t txn_join[1];
     113         210 :   fd_funk_txn_pool_join( txn_join, txn_pool2, txn_ele, txn_max );
     114         210 :   fd_funk_txn_pool_reset( txn_join );
     115         210 :   funk->txn_ele_gaddr = fd_wksp_gaddr_fast( wksp, txn_ele );
     116         210 :   funk->txn_max = txn_max;
     117         210 :   funk->child_head_cidx = fd_funk_txn_cidx( FD_FUNK_TXN_IDX_NULL );
     118         210 :   funk->child_tail_cidx = fd_funk_txn_cidx( FD_FUNK_TXN_IDX_NULL );
     119             : 
     120      788604 :   for( ulong i=0UL; i<txn_max; i++ ) {
     121      788394 :     txn_join->ele[ i ].state = FD_FUNK_TXN_STATE_FREE;
     122      788394 :   }
     123             : 
     124         210 :   fd_funk_txn_xid_set_root( funk->root         );
     125         210 :   fd_funk_txn_xid_set_root( funk->last_publish );
     126             : 
     127         210 :   funk->rec_map_gaddr = fd_wksp_gaddr_fast( wksp, fd_funk_rec_map_new( rec_map, rec_chain_cnt, seed ) );
     128         210 :   void * rec_pool2 = fd_funk_rec_pool_new( rec_pool );
     129         210 :   funk->rec_pool_gaddr = fd_wksp_gaddr_fast( wksp, rec_pool2 );
     130         210 :   fd_funk_rec_pool_t rec_join[1];
     131         210 :   fd_funk_rec_pool_join( rec_join, rec_pool2, rec_ele, rec_max );
     132         210 :   fd_funk_rec_pool_reset( rec_join );
     133         210 :   funk->rec_ele_gaddr = fd_wksp_gaddr_fast( wksp, rec_ele );
     134         210 :   funk->rec_max = (uint)rec_max;
     135             : 
     136         210 :   funk->alloc_gaddr = fd_wksp_gaddr_fast( wksp, fd_alloc_join( fd_alloc_new( alloc, wksp_tag ), 0UL ) );
     137             : 
     138         210 :   FD_COMPILER_MFENCE();
     139         210 :   FD_VOLATILE( funk->magic ) = FD_FUNK_MAGIC;
     140         210 :   FD_COMPILER_MFENCE();
     141             : 
     142         210 :   return (void *)funk;
     143         210 : }
     144             : 
     145             : fd_funk_t *
     146             : fd_funk_join( fd_funk_t * ljoin,
     147             :               void *      shfunk,
     148         429 :               void *      shlocks ) {
     149         429 :   if( FD_UNLIKELY( !shfunk ) ) {
     150           3 :     FD_LOG_WARNING(( "NULL shfunk" ));
     151           3 :     return NULL;
     152           3 :   }
     153         426 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shfunk, fd_funk_align() ) ) ) {
     154           3 :     FD_LOG_WARNING(( "misaligned shfunk" ));
     155           3 :     return NULL;
     156           3 :   }
     157         423 :   fd_wksp_t * wksp = fd_wksp_containing( shfunk );
     158         423 :   if( FD_UNLIKELY( !wksp ) ) {
     159           3 :     FD_LOG_WARNING(( "shfunk must be part of a workspace" ));
     160           3 :     return NULL;
     161           3 :   }
     162             : 
     163         420 :   if( FD_UNLIKELY( !shlocks ) ) {
     164           0 :     FD_LOG_WARNING(( "NULL shlocks" ));
     165           0 :     return NULL;
     166           0 :   }
     167         420 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shlocks, fd_funk_align() ) ) ) {
     168           0 :     FD_LOG_WARNING(( "misaligned shlocks" ));
     169           0 :     return NULL;
     170           0 :   }
     171             : 
     172         420 :   fd_funk_shmem_t * shmem = shfunk;
     173         420 :   if( FD_UNLIKELY( shmem->magic!=FD_FUNK_MAGIC ) ) {
     174           3 :     if (shmem->magic == FD_FUNK_MAGIC+1) {
     175           0 :       FD_LOG_WARNING(( "attempted to join a funk that crashed in a critical section" ));
     176           3 :     } else {
     177           3 :       FD_LOG_WARNING(( "bad magic" ));
     178           3 :     }
     179           3 :     return NULL;
     180           3 :   }
     181             : 
     182         417 :   if( FD_UNLIKELY( !ljoin ) ) {
     183           0 :     FD_LOG_WARNING(( "NULL ljoin" ));
     184           0 :     return NULL;
     185           0 :   }
     186             : 
     187         417 :   fd_funk_t * funk = ljoin;
     188         417 :   memset( funk, 0, sizeof(fd_funk_t) );
     189             : 
     190         417 :   funk->shmem = shfunk;
     191         417 :   funk->wksp  = wksp;
     192             : 
     193         417 :   if( FD_UNLIKELY( !fd_funk_txn_pool_join( funk->txn_pool, fd_wksp_laddr( wksp, shmem->txn_pool_gaddr ), fd_wksp_laddr( wksp, shmem->txn_ele_gaddr ), shmem->txn_max ) ) ) {
     194           0 :     FD_LOG_WARNING(( "failed to join txn_pool" ));
     195           0 :     return NULL;
     196           0 :   }
     197         417 :   if( FD_UNLIKELY( !fd_funk_txn_map_join( funk->txn_map, fd_wksp_laddr( wksp, shmem->txn_map_gaddr ), fd_wksp_laddr_fast( wksp, shmem->txn_ele_gaddr ), shmem->txn_max ) ) ) {
     198           0 :     FD_LOG_WARNING(( "failed to join txn_map" ));
     199           0 :     return NULL;
     200           0 :   }
     201         417 :   if( FD_UNLIKELY( !fd_funk_rec_map_join( funk->rec_map, fd_wksp_laddr( wksp, shmem->rec_map_gaddr ), fd_wksp_laddr( wksp, shmem->rec_ele_gaddr ), shmem->rec_max ) ) ) {
     202           0 :     FD_LOG_WARNING(( "failed to join rec_map" ));
     203           0 :     return NULL;
     204           0 :   }
     205         417 :   if( FD_UNLIKELY( !fd_funk_rec_pool_join( funk->rec_pool, fd_wksp_laddr( wksp, shmem->rec_pool_gaddr ), fd_wksp_laddr_fast( wksp, shmem->rec_ele_gaddr ), shmem->rec_max ) ) ) {
     206           0 :     FD_LOG_WARNING(( "failed to join rec_pool" ));
     207           0 :     return NULL;
     208           0 :   }
     209         417 :   FD_SCRATCH_ALLOC_INIT( l2, shlocks );
     210         417 :   funk->txn_lock = FD_SCRATCH_ALLOC_APPEND( l2, alignof(fd_rwlock_t), sizeof(fd_rwlock_t) * shmem->txn_max );
     211         417 :   funk->rec_lock = FD_SCRATCH_ALLOC_APPEND( l2, alignof(ulong),       sizeof(ulong)       * shmem->rec_max );
     212           0 :   funk->alloc = fd_wksp_laddr( wksp, shmem->alloc_gaddr );
     213         417 :   if( FD_UNLIKELY( !fd_alloc_join( funk->alloc, fd_tile_idx() ) ) ) {
     214           0 :     FD_LOG_WARNING(( "failed to join funk alloc" ));
     215           0 :     return NULL;
     216           0 :   }
     217             : 
     218         417 :   return funk;
     219         417 : }
     220             : 
     221             : void *
     222             : fd_funk_locks_new( void * shlocks,
     223             :                    ulong  txn_max,
     224         210 :                    ulong  rec_max ) {
     225         210 :   if( FD_UNLIKELY( !shlocks ) ) {
     226           0 :     FD_LOG_WARNING(( "NULL shlocks" ));
     227           0 :     return NULL;
     228           0 :   }
     229         210 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shlocks, fd_funk_align() ) ) ) {
     230           0 :     FD_LOG_WARNING(( "misaligned shlocks" ));
     231           0 :     return NULL;
     232           0 :   }
     233         210 :   FD_SCRATCH_ALLOC_INIT( l, shlocks );
     234         210 :   fd_rwlock_t * txn_lock = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_rwlock_t), sizeof(fd_rwlock_t) * txn_max );
     235         210 :   void *        rec_lock = FD_SCRATCH_ALLOC_APPEND( l, alignof(ulong),       sizeof(ulong)       * rec_max );
     236           0 :   memset( txn_lock, 0, sizeof(fd_rwlock_t) * txn_max );
     237         210 :   memset( rec_lock, 0, sizeof(ulong) *       rec_max );
     238         210 :   return shlocks;
     239         210 : }
     240             : 
     241             : void *
     242             : fd_funk_leave( fd_funk_t * funk,
     243             :                void **     opt_shfunk,
     244         324 :                void **     opt_shlocks ) {
     245             : 
     246         324 :   if( FD_UNLIKELY( !funk ) ) {
     247           3 :     FD_LOG_WARNING(( "NULL funk" ));
     248           3 :     if( opt_shfunk  ) *opt_shfunk  = NULL;
     249           3 :     if( opt_shlocks ) *opt_shlocks = NULL;
     250           3 :     return NULL;
     251           3 :   }
     252         321 :   void * shfunk  = funk->shmem;
     253         321 :   void * shlocks = (void *)funk->txn_lock;
     254             : 
     255         321 :   memset( funk, 0, sizeof(fd_funk_t) );
     256             : 
     257         321 :   if( opt_shfunk )  *opt_shfunk  = shfunk;
     258         321 :   if( opt_shlocks ) *opt_shlocks = shlocks;
     259         321 :   return (void *)funk;
     260         324 : }
     261             : 
     262             : void *
     263         159 : fd_funk_delete( void * shfunk ) {
     264             : 
     265         159 :   if( FD_UNLIKELY( !shfunk ) ) {
     266           3 :     FD_LOG_WARNING(( "NULL shfunk" ));
     267           3 :     return NULL;
     268           3 :   }
     269             : 
     270         156 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shfunk, fd_funk_align() ) ) ) {
     271           3 :     FD_LOG_WARNING(( "misaligned shfunk" ));
     272           3 :     return NULL;
     273           3 :   }
     274             : 
     275         153 :   fd_wksp_t * wksp = fd_wksp_containing( shfunk );
     276         153 :   if( FD_UNLIKELY( !wksp ) ) {
     277           3 :     FD_LOG_WARNING(( "shfunk must be part of a workspace" ));
     278           3 :     return NULL;
     279           3 :   }
     280             : 
     281         150 :   fd_funk_shmem_t * shmem = shfunk;
     282         150 :   if( FD_UNLIKELY( shmem->magic!=FD_FUNK_MAGIC ) ) {
     283           6 :     FD_LOG_WARNING(( "bad magic" ));
     284           6 :     return NULL;
     285           6 :   }
     286             : 
     287             :   /* Free all fd_alloc allocations made, individually
     288             :      (FIXME consider walking the element pool instead of the map?) */
     289             : 
     290         144 :   fd_alloc_t * alloc = fd_alloc_join( fd_wksp_laddr_fast( wksp, shmem->alloc_gaddr ), fd_tile_idx() );
     291             : 
     292         144 :   void * shmap = fd_wksp_laddr_fast( wksp, shmem->rec_map_gaddr );
     293         144 :   void * shele = fd_wksp_laddr_fast( wksp, shmem->rec_ele_gaddr );
     294         144 :   fd_funk_rec_map_t rec_map[1];
     295         144 :   if( FD_UNLIKELY( !fd_funk_rec_map_join( rec_map, shmap, shele, 0UL ) ) ) {
     296           0 :     FD_LOG_ERR(( "failed to join rec_map (corrupt funk?)" ));
     297           0 :     return NULL;
     298           0 :   }
     299         144 :   ulong chain_cnt = fd_funk_rec_map_chain_cnt( rec_map );
     300      445656 :   for( ulong chain_idx=0UL; chain_idx<chain_cnt; chain_idx++ ) {
     301      445512 :     for(
     302      445512 :         fd_funk_rec_map_iter_t iter = fd_funk_rec_map_iter( rec_map, chain_idx );
     303      446670 :         !fd_funk_rec_map_iter_done( iter );
     304      445512 :         iter = fd_funk_rec_map_iter_next( iter )
     305      445512 :     ) {
     306        1158 :       fd_funk_val_flush( fd_funk_rec_map_iter_ele( iter ), alloc, wksp );
     307        1158 :     }
     308      445512 :   }
     309             : 
     310         144 :   fd_funk_rec_map_leave( rec_map );
     311             : 
     312         144 :   FD_COMPILER_MFENCE();
     313         144 :   FD_VOLATILE( shmem->magic ) = 0UL;
     314         144 :   FD_COMPILER_MFENCE();
     315             : 
     316             :   /* Free the fd_alloc instance */
     317             : 
     318         144 :   fd_wksp_free_laddr( fd_alloc_delete( fd_alloc_leave( alloc ) ) );
     319             : 
     320         144 :   return shmem;
     321         144 : }
     322             : 
     323             : void
     324          57 : fd_funk_delete_fast( void * shfunk ) {
     325             : 
     326          57 :   if( FD_UNLIKELY( !shfunk ) ) {
     327           0 :     FD_LOG_WARNING(( "NULL shfunk" ));
     328           0 :   }
     329             : 
     330          57 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shfunk, fd_funk_align() ) ) ) {
     331           0 :     FD_LOG_WARNING(( "misaligned shfunk" ));
     332           0 :   }
     333             : 
     334          57 :   fd_funk_shmem_t * shmem = shfunk;
     335          57 :   if( FD_UNLIKELY( shmem->magic!=FD_FUNK_MAGIC ) ) {
     336           0 :     FD_LOG_WARNING(( "bad magic" ));
     337           0 :   }
     338             : 
     339          57 :   fd_wksp_t * wksp = fd_wksp_containing( shmem );
     340          57 :   if( FD_UNLIKELY( !wksp ) ) {
     341           0 :     FD_LOG_WARNING(( "shfunk must be part of a workspace" ));
     342           0 :   }
     343             : 
     344          57 :   ulong const tags[1] = { shmem->wksp_tag };
     345          57 :   fd_wksp_tag_free( wksp, tags, 1UL );
     346             : 
     347          57 : }
     348             : 
     349             : int
     350         201 : fd_funk_verify( fd_funk_t * join ) {
     351         201 :   fd_funk_shmem_t * funk = join->shmem;
     352             : 
     353        5226 : # define TEST(c) do {                                                                           \
     354        5226 :     if( FD_UNLIKELY( !(c) ) ) { FD_LOG_WARNING(( "FAIL: %s", #c )); return FD_FUNK_ERR_INVAL; } \
     355        5226 :   } while(0)
     356             : 
     357         201 :   TEST( funk );
     358             : 
     359             :   /* Test metadata */
     360             : 
     361         201 :   TEST( funk->magic==FD_FUNK_MAGIC );
     362             : 
     363         201 :   ulong funk_gaddr = funk->funk_gaddr;
     364         201 :   TEST( funk_gaddr );
     365         201 :   fd_wksp_t * wksp = fd_funk_wksp( join );
     366         201 :   TEST( wksp );
     367         201 :   TEST( fd_wksp_laddr_fast( wksp, funk_gaddr )==(void *)funk );
     368         201 :   TEST( fd_wksp_gaddr_fast( wksp, funk       )==funk_gaddr   );
     369             : 
     370         201 :   ulong wksp_tag = fd_funk_wksp_tag( join );
     371         201 :   TEST( !!wksp_tag );
     372             : 
     373         201 :   ulong seed = funk->seed; /* seed can be anything */
     374             : 
     375         201 :   TEST( funk->cycle_tag>2UL );
     376             : 
     377             :   /* Test transaction map */
     378             : 
     379         201 :   ulong txn_max = fd_funk_txn_pool_ele_max( join->txn_pool );
     380         201 :   TEST( txn_max<=FD_FUNK_TXN_IDX_NULL );
     381             : 
     382         201 :   ulong txn_map_gaddr = funk->txn_map_gaddr;
     383         201 :   TEST( txn_map_gaddr );
     384         201 :   fd_funk_txn_map_t * txn_map = fd_funk_txn_map( join );
     385         201 :   ulong txn_chain_cnt = fd_funk_txn_map_chain_cnt_est( txn_max );
     386         201 :   TEST( txn_chain_cnt==fd_funk_txn_map_chain_cnt( txn_map ) );
     387         201 :   TEST( seed==fd_funk_txn_map_seed( txn_map ) );
     388             : 
     389         201 :   ulong child_head_idx = fd_funk_txn_idx( funk->child_head_cidx );
     390         201 :   ulong child_tail_idx = fd_funk_txn_idx( funk->child_tail_cidx );
     391             : 
     392         201 :   int null_child_head = fd_funk_txn_idx_is_null( child_head_idx );
     393         201 :   int null_child_tail = fd_funk_txn_idx_is_null( child_tail_idx );
     394             : 
     395         201 :   if( !txn_max ) TEST( null_child_head & null_child_tail );
     396         201 :   else {
     397         201 :     if( null_child_head ) TEST( null_child_tail );
     398         165 :     else                  TEST( child_head_idx<txn_max );
     399             : 
     400         201 :     if( null_child_tail ) TEST( null_child_head );
     401         165 :     else                  TEST( child_tail_idx<txn_max );
     402         201 :   }
     403             : 
     404         201 :   if( !txn_max ) TEST( fd_funk_txn_idx_is_null( child_tail_idx ) );
     405             : 
     406         201 :   fd_funk_txn_xid_t const * root = fd_funk_root( join );
     407         201 :   TEST( root ); /* Practically guaranteed */
     408         201 :   TEST( fd_funk_txn_xid_eq_root( root ) );
     409             : 
     410         201 :   fd_funk_txn_xid_t * last_publish = funk->last_publish;
     411         201 :   TEST( last_publish ); /* Practically guaranteed */
     412             :   /* (*last_publish) only be root at creation and anything but root post
     413             :      creation.  But we don't know which situation applies here so this
     414             :      could be anything. */
     415             : 
     416         201 :   TEST( !fd_funk_txn_verify( join ) );
     417             : 
     418             :   /* Test record map */
     419             : 
     420         201 :   ulong rec_max = fd_funk_rec_pool_ele_max( join->rec_pool );
     421         201 :   TEST( rec_max<=FD_FUNK_TXN_IDX_NULL );
     422             : 
     423         201 :   ulong rec_map_gaddr = funk->rec_map_gaddr;
     424         201 :   TEST( rec_map_gaddr );
     425         201 :   fd_funk_rec_map_t * rec_map = fd_funk_rec_map( join );
     426         201 :   ulong rec_chain_cnt = fd_funk_rec_map_chain_cnt_est( rec_max );
     427         201 :   TEST( rec_chain_cnt==fd_funk_rec_map_chain_cnt( rec_map ) );
     428         201 :   TEST( seed==fd_funk_rec_map_seed( rec_map ) );
     429             : 
     430         201 :   TEST( !fd_funk_rec_verify( join ) );
     431             : 
     432             :   /* Test values */
     433             : 
     434         201 :   ulong alloc_gaddr = funk->alloc_gaddr;
     435         201 :   TEST( alloc_gaddr );
     436         201 :   fd_alloc_t * alloc = fd_funk_alloc( join );
     437         201 :   TEST( alloc );
     438             : 
     439         201 :   TEST( !fd_funk_val_verify( join ) );
     440             : 
     441         201 : # undef TEST
     442             : 
     443         201 :   return FD_FUNK_SUCCESS;
     444         201 : }

Generated by: LCOV version 1.14