LCOV - code coverage report
Current view: top level - discoh/resolv - fd_resolv_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 12 252 4.8 %
Date: 2025-03-20 12:08:36 Functions: 2 11 18.2 %

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

Generated by: LCOV version 1.14