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