LCOV - code coverage report
Current view: top level - discoh/resolv - fd_resolv_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 252 0.0 %
Date: 2025-07-14 05:02:59 Functions: 0 11 0.0 %

          Line data    Source code
       1             : #include "../bank/fd_bank_abi.h"
       2             : 
       3             : #include "../../disco/tiles.h"
       4             : #include "../../disco/metrics/fd_metrics.h"
       5             : #include "../../flamenco/runtime/fd_system_ids.h"
       6             : #include "../../flamenco/runtime/fd_system_ids_pp.h"
       7             : 
       8             : #if FD_HAS_AVX
       9             : #include "../../util/simd/fd_avx.h"
      10             : #endif
      11             : 
      12           0 : #define FD_RESOLV_IN_KIND_FRAGMENT (0)
      13           0 : #define FD_RESOLV_IN_KIND_BANK     (1)
      14             : 
      15             : struct blockhash {
      16             :   uchar b[ 32 ];
      17             : };
      18             : 
      19             : typedef struct blockhash blockhash_t;
      20             : 
      21             : struct blockhash_map {
      22             :   blockhash_t key;
      23             :   ulong       slot;
      24             : };
      25             : 
      26             : typedef struct blockhash_map blockhash_map_t;
      27             : 
      28             : static const blockhash_t null_blockhash = { 0 };
      29             : 
      30             : /* The blockhash ring holds recent blockhashes, so we can identify when
      31             :    a transaction arrives, what slot it will expire (and can no longer be
      32             :    packed) in.  This is useful so we don't send transactions to pack
      33             :    that are no longer packable.
      34             : 
      35             :    Unfortunately, poorly written transaction senders frequently send
      36             :    transactions from millions of slots ago, so we need a large ring to
      37             :    be able to determine and evict these.  The highest practically useful
      38             :    value here is around 22, which works out to 19 days of blockhash
      39             :    history.  Beyond this, the validator is likely to be restarted, and
      40             :    lose the history anyway. */
      41             : 
      42           0 : #define BLOCKHASH_LG_RING_CNT 22UL
      43           0 : #define BLOCKHASH_RING_LEN   (1UL<<BLOCKHASH_LG_RING_CNT)
      44             : 
      45             : #define MAP_NAME              map
      46           0 : #define MAP_T                 blockhash_map_t
      47           0 : #define MAP_KEY_T             blockhash_t
      48           0 : #define MAP_LG_SLOT_CNT       (BLOCKHASH_LG_RING_CNT+1UL)
      49           0 : #define MAP_KEY_NULL          null_blockhash
      50             : #if FD_HAS_AVX
      51           0 : # define MAP_KEY_INVAL(k)     _mm256_testz_si256( wb_ldu( (k).b ), wb_ldu( (k).b ) )
      52             : #else
      53             : # define MAP_KEY_INVAL(k)     MAP_KEY_EQUAL(k, null_blockhash)
      54             : #endif
      55           0 : #define MAP_KEY_EQUAL(k0,k1)  (!memcmp((k0).b,(k1).b, 32UL))
      56             : #define MAP_MEMOIZE           0
      57             : #define MAP_KEY_EQUAL_IS_SLOW 1
      58           0 : #define MAP_KEY_HASH(key)     fd_uint_load_4( (key).b )
      59             : #define MAP_QUERY_OPT         1
      60             : 
      61             : #include "../../util/tmpl/fd_map.c"
      62             : 
      63             : typedef struct {
      64             :   union {
      65             :     ulong pool_next; /* Used when it's released */
      66             :     ulong lru_next;  /* Used when it's acquired */
      67             :   };                 /* .. so it's okay to store them in the same memory */
      68             :   ulong lru_prev;
      69             : 
      70             :   ulong map_next;
      71             :   ulong map_prev;
      72             : 
      73             :   blockhash_t * blockhash;
      74             :   uchar _[ FD_TPU_PARSED_MTU ] __attribute__((aligned(alignof(fd_txn_m_t))));
      75             : } fd_stashed_txn_m_t;
      76             : 
      77             : #define POOL_NAME      pool
      78           0 : #define POOL_T         fd_stashed_txn_m_t
      79           0 : #define POOL_NEXT      pool_next
      80             : #define POOL_IDX_T     ulong
      81             : 
      82             : #include "../../util/tmpl/fd_pool.c"
      83             : 
      84             : /* We'll push at the head, which means the tail is the oldest. */
      85             : #define DLIST_NAME  lru_list
      86             : #define DLIST_ELE_T fd_stashed_txn_m_t
      87           0 : #define DLIST_PREV  lru_prev
      88           0 : #define DLIST_NEXT  lru_next
      89             : 
      90             : #include "../../util/tmpl/fd_dlist.c"
      91             : 
      92             : #define MAP_NAME          map_chain
      93           0 : #define MAP_ELE_T         fd_stashed_txn_m_t
      94             : #define MAP_KEY_T         blockhash_t *
      95           0 : #define MAP_KEY           blockhash
      96           0 : #define MAP_IDX_T         ulong
      97           0 : #define MAP_NEXT          map_next
      98           0 : #define MAP_PREV          map_prev
      99           0 : #define MAP_KEY_HASH(k,s) ((s) ^ fd_ulong_load_8( (*(k))->b ))
     100           0 : #define MAP_KEY_EQ(k0,k1) (!memcmp((*(k0))->b, (*(k1))->b, 32UL))
     101             : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
     102             : #define MAP_MULTI         1
     103             : 
     104             : #include "../../util/tmpl/fd_map_chain.c"
     105             : 
     106             : typedef struct {
     107             :   int         kind;
     108             : 
     109             :   fd_wksp_t * mem;
     110             :   ulong       chunk0;
     111             :   ulong       wmark;
     112             :   ulong       mtu;
     113             : } fd_resolv_in_ctx_t;
     114             : 
     115             : typedef struct {
     116             :   ulong round_robin_idx;
     117             :   ulong round_robin_cnt;
     118             : 
     119             :   int   bundle_failed;
     120             :   ulong bundle_id;
     121             : 
     122             :   void * root_bank;
     123             :   ulong  root_slot;
     124             : 
     125             :   blockhash_map_t * blockhash_map;
     126             : 
     127             :   ulong flushing_slot;
     128             :   ulong flush_pool_idx;
     129             : 
     130             :   fd_stashed_txn_m_t * pool;
     131             :   map_chain_t *        map_chain;
     132             :   lru_list_t           lru_list[1];
     133             : 
     134             :   ulong completed_slot;
     135             :   ulong blockhash_ring_idx;
     136             :   blockhash_t blockhash_ring[ BLOCKHASH_RING_LEN ];
     137             : 
     138             :   uchar _bank_msg[ sizeof(fd_completed_bank_t) ];
     139             : 
     140             :   struct {
     141             :     ulong lut[ FD_METRICS_COUNTER_RESOLV_LUT_RESOLVED_CNT ];
     142             :     ulong blockhash_expired;
     143             :     ulong blockhash_unknown;
     144             :     ulong bundle_peer_failure_cnt;
     145             :     ulong stash[ FD_METRICS_COUNTER_RESOLV_STASH_OPERATION_CNT ];
     146             :   } metrics;
     147             : 
     148             :   fd_resolv_in_ctx_t in[ 64UL ];
     149             : 
     150             :   fd_wksp_t * out_mem;
     151             :   ulong       out_chunk0;
     152             :   ulong       out_wmark;
     153             :   ulong       out_chunk;
     154             : } fd_resolv_ctx_t;
     155             : 
     156             : FD_FN_CONST static inline ulong
     157           0 : scratch_align( void ) {
     158           0 :   return alignof( fd_resolv_ctx_t );
     159           0 : }
     160             : 
     161             : FD_FN_PURE static inline ulong
     162           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
     163           0 :   (void)tile;
     164           0 :   ulong l = FD_LAYOUT_INIT;
     165           0 :   l = FD_LAYOUT_APPEND( l, alignof( fd_resolv_ctx_t ), sizeof( fd_resolv_ctx_t )        );
     166           0 :   l = FD_LAYOUT_APPEND( l, pool_align(),               pool_footprint     ( 1UL<<16UL ) );
     167           0 :   l = FD_LAYOUT_APPEND( l, map_chain_align(),          map_chain_footprint( 8192UL    ) );
     168           0 :   l = FD_LAYOUT_APPEND( l, map_align(),                map_footprint()                  );
     169           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
     170           0 : }
     171             : 
     172             : extern void fd_ext_bank_release( void const * bank );
     173             : 
     174             : static ulong _fd_ext_resolv_tile_cnt;
     175             : 
     176             : ulong
     177           0 : fd_ext_resolv_tile_cnt( void ) {
     178           0 :   while(  !FD_VOLATILE( _fd_ext_resolv_tile_cnt ) ) {}
     179           0 :   return _fd_ext_resolv_tile_cnt;
     180           0 : }
     181             : 
     182             : static inline void
     183           0 : metrics_write( fd_resolv_ctx_t * ctx ) {
     184           0 :   FD_MCNT_SET( RESOLV, BLOCKHASH_EXPIRED, ctx->metrics.blockhash_expired );
     185           0 :   FD_MCNT_ENUM_COPY( RESOLV, LUT_RESOLVED, ctx->metrics.lut );
     186           0 :   FD_MCNT_ENUM_COPY( RESOLV, STASH_OPERATION, ctx->metrics.stash );
     187           0 :   FD_MCNT_SET( RESOLV, TRANSACTION_BUNDLE_PEER_FAILURE, ctx->metrics.bundle_peer_failure_cnt );
     188           0 : }
     189             : 
     190             : static int
     191             : before_frag( fd_resolv_ctx_t * ctx,
     192             :              ulong             in_idx,
     193             :              ulong             seq,
     194           0 :              ulong             sig ) {
     195           0 :   (void)sig;
     196             : 
     197           0 :   if( FD_UNLIKELY( ctx->in[in_idx].kind==FD_RESOLV_IN_KIND_BANK ) ) return 0;
     198             : 
     199           0 :   return (seq % ctx->round_robin_cnt) != ctx->round_robin_idx;
     200           0 : }
     201             : 
     202             : static inline void
     203             : during_frag( fd_resolv_ctx_t * ctx,
     204             :              ulong             in_idx,
     205             :              ulong             seq FD_PARAM_UNUSED,
     206             :              ulong             sig FD_PARAM_UNUSED,
     207             :              ulong             chunk,
     208             :              ulong             sz,
     209           0 :              ulong             ctl FD_PARAM_UNUSED ) {
     210             : 
     211           0 :   if( FD_UNLIKELY( chunk<ctx->in[ in_idx ].chunk0 || chunk>ctx->in[ in_idx ].wmark || sz>ctx->in[ in_idx ].mtu ) )
     212           0 :     FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->in[ in_idx ].chunk0, ctx->in[ in_idx ].wmark ));
     213             : 
     214           0 :   switch( ctx->in[in_idx].kind ) {
     215           0 :     case FD_RESOLV_IN_KIND_BANK:
     216           0 :       fd_memcpy( ctx->_bank_msg, fd_chunk_to_laddr_const( ctx->in[in_idx].mem, chunk ), sz );
     217           0 :       break;
     218           0 :     case FD_RESOLV_IN_KIND_FRAGMENT: {
     219           0 :       uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[in_idx].mem, chunk );
     220           0 :       uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->out_mem, ctx->out_chunk );
     221           0 :       fd_memcpy( dst, src, sz );
     222           0 :       break;
     223           0 :     }
     224           0 :     default:
     225           0 :       FD_LOG_ERR(( "unknown in kind %d", ctx->in[in_idx].kind ));
     226           0 :   }
     227           0 : }
     228             : 
     229             : static inline int
     230             : publish_txn( fd_resolv_ctx_t *          ctx,
     231             :              fd_stem_context_t *        stem,
     232           0 :              fd_stashed_txn_m_t const * stashed ) {
     233           0 :   fd_txn_m_t *     txnm = (fd_txn_m_t *)fd_chunk_to_laddr( ctx->out_mem, ctx->out_chunk );
     234           0 :   fd_memcpy( txnm, stashed->_, fd_txn_m_realized_footprint( (fd_txn_m_t *)stashed->_, 1, 0 ) );
     235             : 
     236           0 :   fd_txn_t const * txnt = fd_txn_m_txn_t( txnm );
     237             : 
     238           0 :   txnm->reference_slot = ctx->flushing_slot;
     239             : 
     240           0 :   if( FD_UNLIKELY( txnt->addr_table_adtl_cnt ) ) {
     241           0 :     if( FD_UNLIKELY( !ctx->root_bank ) ) {
     242           0 :       FD_MCNT_INC( RESOLV, NO_BANK_DROP, 1 );
     243           0 :       return 0;
     244           0 :     } else {
     245           0 :       int result = fd_bank_abi_resolve_address_lookup_tables( ctx->root_bank, 0, ctx->root_slot, txnt, fd_txn_m_payload( txnm ), fd_txn_m_alut( txnm ) );
     246             :       /* result is in [-5, 0]. We want to map -5 to 0, -4 to 1, etc. */
     247           0 :       ctx->metrics.lut[ (ulong)((long)FD_METRICS_COUNTER_RESOLV_LUT_RESOLVED_CNT+result-1L) ]++;
     248             : 
     249           0 :       if( FD_UNLIKELY( result!=FD_BANK_ABI_TXN_INIT_SUCCESS ) ) return 0;
     250           0 :     }
     251           0 :   }
     252             : 
     253           0 :   ulong realized_sz = fd_txn_m_realized_footprint( txnm, 1, 1 );
     254           0 :   ulong tspub = fd_frag_meta_ts_comp( fd_tickcount() );
     255           0 :   fd_stem_publish( stem, 0UL, txnm->reference_slot, ctx->out_chunk, realized_sz, 0UL, 0UL, tspub );
     256           0 :   ctx->out_chunk = fd_dcache_compact_next( ctx->out_chunk, realized_sz, ctx->out_chunk0, ctx->out_wmark );
     257             : 
     258           0 :   return 1;
     259           0 : }
     260             : 
     261             : static inline void
     262             : after_credit( fd_resolv_ctx_t *   ctx,
     263             :               fd_stem_context_t * stem,
     264             :               int *               opt_poll_in,
     265           0 :               int *               charge_busy ) {
     266           0 :   if( FD_LIKELY( ctx->flush_pool_idx==ULONG_MAX ) ) return;
     267             : 
     268           0 :   *charge_busy = 1;
     269           0 :   *opt_poll_in = 0;
     270             : 
     271           0 :   ulong next = map_chain_idx_next_const( ctx->flush_pool_idx, ULONG_MAX, ctx->pool );
     272           0 :   map_chain_idx_remove_fast( ctx->map_chain, ctx->flush_pool_idx, ctx->pool );
     273           0 :   if( FD_LIKELY( publish_txn( ctx, stem, pool_ele( ctx->pool, ctx->flush_pool_idx ) ) ) ) {
     274           0 :     ctx->metrics.stash[ FD_METRICS_ENUM_RESOLVE_STASH_OPERATION_V_PUBLISHED_IDX ]++;
     275           0 :   } else {
     276           0 :     ctx->metrics.stash[ FD_METRICS_ENUM_RESOLVE_STASH_OPERATION_V_REMOVED_IDX ]++;
     277           0 :   }
     278           0 :   lru_list_idx_remove( ctx->lru_list, ctx->flush_pool_idx, ctx->pool );
     279           0 :   pool_idx_release( ctx->pool, ctx->flush_pool_idx );
     280           0 :   ctx->flush_pool_idx = next;
     281           0 : }
     282             : 
     283             : /* Returns 0 if not a durable nonce transaction and 1 if it may be a
     284             :    durable nonce transaction */
     285             : 
     286             : FD_FN_PURE static inline int
     287             : fd_resolv_is_durable_nonce( fd_txn_t const * txn,
     288           0 :                             uchar    const * payload ) {
     289           0 :   if( FD_UNLIKELY( txn->instr_cnt==0 ) ) return 0;
     290             : 
     291           0 :   fd_txn_instr_t const * ix0 = &txn->instr[ 0 ];
     292           0 :   fd_acct_addr_t const * prog0 = fd_txn_get_acct_addrs( txn, payload ) + ix0->program_id;
     293             :   /* First instruction must be SystemProgram nonceAdvance instruction */
     294           0 :   fd_acct_addr_t const system_program[1] = { { { SYS_PROG_ID } } };
     295           0 :   if( FD_LIKELY( memcmp( prog0, system_program, sizeof(fd_acct_addr_t) ) ) )        return 0;
     296             : 
     297             :   /* instruction with three accounts and a four byte instruction data, a
     298             :      little-endian uint value 4 */
     299           0 :   if( FD_UNLIKELY( (ix0->data_sz!=4) | (ix0->acct_cnt!=3) ) ) return 0;
     300             : 
     301           0 :   return fd_uint_load_4( payload + ix0->data_off )==4U;
     302           0 : }
     303             : 
     304             : static inline void
     305             : after_frag( fd_resolv_ctx_t *   ctx,
     306             :             ulong               in_idx,
     307             :             ulong               seq,
     308             :             ulong               sig,
     309             :             ulong               sz,
     310             :             ulong               tsorig,
     311             :             ulong               _tspub,
     312           0 :             fd_stem_context_t * stem ) {
     313           0 :   (void)seq;
     314           0 :   (void)sz;
     315           0 :   (void)_tspub;
     316             : 
     317           0 :   if( FD_UNLIKELY( ctx->in[in_idx].kind==FD_RESOLV_IN_KIND_BANK ) ) {
     318           0 :     switch( sig ) {
     319           0 :       case 0: {
     320           0 :         fd_rooted_bank_t * frag = (fd_rooted_bank_t *)ctx->_bank_msg;
     321           0 :         if( FD_LIKELY( ctx->root_bank ) ) fd_ext_bank_release( ctx->root_bank );
     322             : 
     323           0 :         ctx->root_bank = frag->bank;
     324           0 :         ctx->root_slot = frag->slot;
     325           0 :         break;
     326           0 :       }
     327           0 :       case 1: {
     328           0 :         fd_completed_bank_t * frag = (fd_completed_bank_t *)ctx->_bank_msg;
     329             : 
     330           0 :         blockhash_map_t * entry = map_query( ctx->blockhash_map, ctx->blockhash_ring[ ctx->blockhash_ring_idx%BLOCKHASH_RING_LEN ], NULL );
     331           0 :         if( FD_LIKELY( entry ) ) map_remove( ctx->blockhash_map, entry );
     332             : 
     333           0 :         memcpy( ctx->blockhash_ring[ ctx->blockhash_ring_idx%BLOCKHASH_RING_LEN ].b, frag->hash, 32UL );
     334           0 :         ctx->blockhash_ring_idx++;
     335             : 
     336           0 :         blockhash_map_t * blockhash = map_insert( ctx->blockhash_map, *(blockhash_t *)frag->hash );
     337           0 :         blockhash->slot = frag->slot;
     338             : 
     339           0 :         blockhash_t * hash = (blockhash_t *)frag->hash;
     340           0 :         ctx->flush_pool_idx  = map_chain_idx_query_const( ctx->map_chain, &hash, ULONG_MAX, ctx->pool );
     341           0 :         ctx->flushing_slot   = frag->slot;
     342             : 
     343           0 :         ctx->completed_slot = frag->slot;
     344           0 :         break;
     345           0 :       }
     346           0 :       default:
     347           0 :         FD_LOG_ERR(( "unknown sig %lu", sig ));
     348           0 :     }
     349           0 :     return;
     350           0 :   }
     351             : 
     352           0 :   fd_txn_m_t *     txnm = (fd_txn_m_t *)fd_chunk_to_laddr( ctx->out_mem, ctx->out_chunk );
     353           0 :   FD_TEST( txnm->payload_sz<=FD_TPU_MTU );
     354           0 :   FD_TEST( txnm->txn_t_sz<=FD_TXN_MAX_SZ );
     355           0 :   fd_txn_t const * txnt = fd_txn_m_txn_t( txnm );
     356             : 
     357             :   /* If we find the recent blockhash, life is simple.  We drop
     358             :      transactions that couldn't possibly execute any more, and forward
     359             :      to pack ones that could.
     360             : 
     361             :      If we can't find the recent blockhash ... it means one of four
     362             :      things,
     363             : 
     364             :      (1) The blockhash is really old (more than 19 days) or just
     365             :          non-existent.
     366             :      (2) The blockhash is not that old, but was created before this
     367             :          validator was started.
     368             :      (3) It's really new (we haven't seen the bank yet).
     369             :      (4) It's a durable nonce transaction, or part of a bundle (just let
     370             :          it pass).
     371             : 
     372             :     For durable nonce transactions, there isn't much we can do except
     373             :     pass them along and see if they execute.
     374             : 
     375             :     For the other three cases ... we don't want to flood pack with what
     376             :     might be junk transactions, so we accumulate them into a local
     377             :     buffer.  If we later see the blockhash come to exist, we forward any
     378             :     buffered transactions to back. */
     379             : 
     380           0 :   if( FD_UNLIKELY( txnm->block_engine.bundle_id && (txnm->block_engine.bundle_id!=ctx->bundle_id) ) ) {
     381           0 :     ctx->bundle_failed = 0;
     382           0 :     ctx->bundle_id     = txnm->block_engine.bundle_id;
     383           0 :   }
     384             : 
     385           0 :   if( FD_UNLIKELY( txnm->block_engine.bundle_id && ctx->bundle_failed ) ) {
     386           0 :     ctx->metrics.bundle_peer_failure_cnt++;
     387           0 :     return;
     388           0 :   }
     389             : 
     390           0 :   txnm->reference_slot = ctx->completed_slot;
     391           0 :   blockhash_map_t const * blockhash = map_query_const( ctx->blockhash_map, *(blockhash_t*)( fd_txn_m_payload( txnm )+txnt->recent_blockhash_off ), NULL );
     392           0 :   if( FD_LIKELY( blockhash ) ) {
     393           0 :     txnm->reference_slot = blockhash->slot;
     394           0 :     if( FD_UNLIKELY( txnm->reference_slot+151UL<ctx->completed_slot ) ) {
     395           0 :       if( FD_UNLIKELY( txnm->block_engine.bundle_id ) ) ctx->bundle_failed = 1;
     396           0 :       ctx->metrics.blockhash_expired++;
     397           0 :       return;
     398           0 :     }
     399           0 :   }
     400             : 
     401           0 :   int is_bundle_member = !!txnm->block_engine.bundle_id;
     402           0 :   int is_durable_nonce = fd_resolv_is_durable_nonce( txnt, fd_txn_m_payload( txnm ) );
     403             : 
     404           0 :   if( FD_UNLIKELY( !is_bundle_member && !is_durable_nonce && !blockhash ) ) {
     405           0 :     ulong pool_idx;
     406           0 :     if( FD_UNLIKELY( !pool_free( ctx->pool ) ) ) {
     407           0 :       pool_idx = lru_list_idx_pop_tail( ctx->lru_list, ctx->pool );
     408           0 :       map_chain_idx_remove_fast( ctx->map_chain, pool_idx, ctx->pool );
     409           0 :       ctx->metrics.stash[ FD_METRICS_ENUM_RESOLVE_STASH_OPERATION_V_OVERRUN_IDX ]++;
     410           0 :     } else {
     411           0 :       pool_idx = pool_idx_acquire( ctx->pool );
     412           0 :     }
     413             : 
     414           0 :     fd_stashed_txn_m_t * stash_txn = pool_ele( ctx->pool, pool_idx );
     415             :     /* There's a compiler bug in GCC version 12 (at least 12.1, 12.3 and
     416             :        12.4) that cause it to think stash_txn is a null pointer.  It
     417             :        then complains that the memcpy is bad and refuses to compile the
     418             :        memcpy below.  It is possible for pool_ele to return NULL, but
     419             :        that can't happen because if pool_free is 0, then all the pool
     420             :        elements must be in the LRU list, so idx_pop_tail won't return
     421             :        IDX_NULL; and if pool_free returns non-zero, then
     422             :        pool_idx_acquire won't return POOL_IDX_NULL. */
     423           0 :     FD_COMPILER_FORGET( stash_txn );
     424           0 :     fd_memcpy( stash_txn->_, txnm, fd_txn_m_realized_footprint( txnm, 1, 0 ) );
     425           0 :     stash_txn->blockhash = (blockhash_t *)(fd_txn_m_payload( (fd_txn_m_t *)(stash_txn->_) ) + txnt->recent_blockhash_off);
     426           0 :     ctx->metrics.stash[ FD_METRICS_ENUM_RESOLVE_STASH_OPERATION_V_INSERTED_IDX ]++;
     427             : 
     428           0 :     map_chain_ele_insert( ctx->map_chain, stash_txn, ctx->pool );
     429           0 :     lru_list_idx_push_head( ctx->lru_list, pool_idx, ctx->pool );
     430             : 
     431           0 :     return;
     432           0 :   }
     433             : 
     434           0 :   if( FD_UNLIKELY( txnt->addr_table_adtl_cnt ) ) {
     435           0 :     if( FD_UNLIKELY( !ctx->root_bank ) ) {
     436           0 :       FD_MCNT_INC( RESOLV, NO_BANK_DROP, 1 );
     437           0 :       if( FD_UNLIKELY( txnm->block_engine.bundle_id ) ) ctx->bundle_failed = 1;
     438           0 :       return;
     439           0 :     }
     440             : 
     441           0 :     int result = fd_bank_abi_resolve_address_lookup_tables( ctx->root_bank, 0, ctx->root_slot, txnt, fd_txn_m_payload( txnm ), fd_txn_m_alut( txnm ) );
     442             :     /* result is in [-5, 0]. We want to map -5 to 0, -4 to 1, etc. */
     443           0 :     ctx->metrics.lut[ (ulong)((long)FD_METRICS_COUNTER_RESOLV_LUT_RESOLVED_CNT+result-1L) ]++;
     444             : 
     445           0 :     if( FD_UNLIKELY( result!=FD_BANK_ABI_TXN_INIT_SUCCESS ) ) {
     446           0 :       if( FD_UNLIKELY( txnm->block_engine.bundle_id ) ) ctx->bundle_failed = 1;
     447           0 :       return;
     448           0 :     }
     449           0 :   }
     450             : 
     451           0 :   ulong realized_sz = fd_txn_m_realized_footprint( txnm, 1, 1 );
     452           0 :   ulong tspub = fd_frag_meta_ts_comp( fd_tickcount() );
     453           0 :   fd_stem_publish( stem, 0UL, txnm->reference_slot, ctx->out_chunk, realized_sz, 0UL, tsorig, tspub );
     454           0 :   ctx->out_chunk = fd_dcache_compact_next( ctx->out_chunk, realized_sz, ctx->out_chunk0, ctx->out_wmark );
     455           0 : }
     456             : 
     457             : static void
     458             : unprivileged_init( fd_topo_t *      topo,
     459           0 :                    fd_topo_tile_t * tile ) {
     460           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     461             : 
     462           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     463           0 :   fd_resolv_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_resolv_ctx_t ), sizeof( fd_resolv_ctx_t ) );
     464             : 
     465           0 :   ctx->round_robin_cnt = fd_topo_tile_name_cnt( topo, tile->name );
     466           0 :   ctx->round_robin_idx = tile->kind_id;
     467             : 
     468           0 :   ctx->bundle_failed = 0;
     469           0 :   ctx->bundle_id     = 0UL;
     470             : 
     471           0 :   ctx->completed_slot = 0UL;
     472           0 :   ctx->blockhash_ring_idx = 0UL;
     473             : 
     474           0 :   ctx->flush_pool_idx = ULONG_MAX;
     475             : 
     476           0 :   ctx->pool = pool_join( pool_new( FD_SCRATCH_ALLOC_APPEND( l, pool_align(), pool_footprint( 1UL<<16UL ) ), 1UL<<16UL ) );
     477           0 :   FD_TEST( ctx->pool );
     478             : 
     479           0 :   ctx->map_chain = map_chain_join( map_chain_new( FD_SCRATCH_ALLOC_APPEND( l, map_chain_align(), map_chain_footprint( 8192ULL ) ), 8192UL , 0UL ) );
     480           0 :   FD_TEST( ctx->map_chain );
     481             : 
     482           0 :   FD_TEST( ctx->lru_list==lru_list_join( lru_list_new( ctx->lru_list ) ) );
     483             : 
     484           0 :   if( FD_LIKELY( !tile->kind_id ) ) _fd_ext_resolv_tile_cnt = ctx->round_robin_cnt;
     485             : 
     486           0 :   ctx->root_bank = NULL;
     487             : 
     488           0 :   memset( ctx->blockhash_ring, 0, sizeof( ctx->blockhash_ring ) );
     489           0 :   memset( &ctx->metrics, 0, sizeof( ctx->metrics ) );
     490             : 
     491           0 :   ctx->blockhash_map = map_join( map_new( FD_SCRATCH_ALLOC_APPEND( l, map_align(), map_footprint() ) ) );
     492           0 :   FD_TEST( ctx->blockhash_map );
     493             : 
     494           0 :   FD_TEST( tile->in_cnt<=sizeof( ctx->in )/sizeof( ctx->in[ 0 ] ) );
     495           0 :   for( ulong i=0UL; i<tile->in_cnt; i++ ) {
     496           0 :     fd_topo_link_t * link = &topo->links[ tile->in_link_id[ i ] ];
     497           0 :     fd_topo_wksp_t * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
     498             : 
     499           0 :     if( FD_LIKELY( !strcmp( link->name, "replay_resol" ) ) ) ctx->in[i].kind = FD_RESOLV_IN_KIND_BANK;
     500           0 :     else                                                     ctx->in[i].kind = FD_RESOLV_IN_KIND_FRAGMENT;
     501             : 
     502           0 :     ctx->in[i].mem    = link_wksp->wksp;
     503           0 :     ctx->in[i].chunk0 = fd_dcache_compact_chunk0( ctx->in[i].mem, link->dcache );
     504           0 :     ctx->in[i].wmark  = fd_dcache_compact_wmark ( ctx->in[i].mem, link->dcache, link->mtu );
     505           0 :     ctx->in[i].mtu    = link->mtu;
     506           0 :   }
     507             : 
     508           0 :   ctx->out_mem    = topo->workspaces[ topo->objs[ topo->links[ tile->out_link_id[ 0 ] ].dcache_obj_id ].wksp_id ].wksp;
     509           0 :   ctx->out_chunk0 = fd_dcache_compact_chunk0( ctx->out_mem, topo->links[ tile->out_link_id[ 0 ] ].dcache );
     510           0 :   ctx->out_wmark  = fd_dcache_compact_wmark ( ctx->out_mem, topo->links[ tile->out_link_id[ 0 ] ].dcache, topo->links[ tile->out_link_id[ 0 ] ].mtu );
     511           0 :   ctx->out_chunk  = ctx->out_chunk0;
     512             : 
     513           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, 1UL );
     514           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     515           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     516           0 : }
     517             : 
     518           0 : #define STEM_BURST (1UL)
     519             : 
     520           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_resolv_ctx_t
     521           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_resolv_ctx_t)
     522             : 
     523           0 : #define STEM_CALLBACK_METRICS_WRITE metrics_write
     524           0 : #define STEM_CALLBACK_AFTER_CREDIT  after_credit
     525           0 : #define STEM_CALLBACK_BEFORE_FRAG   before_frag
     526           0 : #define STEM_CALLBACK_DURING_FRAG   during_frag
     527           0 : #define STEM_CALLBACK_AFTER_FRAG    after_frag
     528             : 
     529             : #include "../../disco/stem/fd_stem.c"
     530             : 
     531             : fd_topo_run_tile_t fd_tile_resolv = {
     532             :   .name                     = "resolv",
     533             :   .populate_allowed_seccomp = NULL,
     534             :   .populate_allowed_fds     = NULL,
     535             :   .scratch_align            = scratch_align,
     536             :   .scratch_footprint        = scratch_footprint,
     537             :   .unprivileged_init        = unprivileged_init,
     538             :   .run                      = stem_run,
     539             : };

Generated by: LCOV version 1.14