Line data Source code
1 : #include "../../disco/tiles.h"
2 : #include "generated/fd_exec_tile_seccomp.h"
3 :
4 : #include "../../util/pod/fd_pod_format.h"
5 : #include "../../discof/replay/fd_exec.h"
6 : #include "../../flamenco/runtime/context/fd_capture_ctx.h"
7 : #include "../../flamenco/runtime/fd_bank.h"
8 : #include "../../flamenco/runtime/fd_exec_stack.h"
9 : #include "../../flamenco/runtime/fd_runtime.h"
10 : #include "../../disco/metrics/fd_metrics.h"
11 :
12 : #include "../../funk/fd_funk.h"
13 :
14 : /* The exec tile is responsible for executing single transactions. The
15 : tile recieves a parsed transaction (fd_txn_p_t) and an identifier to
16 : which bank to execute against (index into the bank pool). With this,
17 : the exec tile is able to identify the correct bank and accounts db
18 : handle (funk_txn) to execute the transaction against. The exec tile
19 : then commits the results of the transaction to the accounts db and
20 : makes any necessary updates to the bank. */
21 :
22 : typedef struct link_ctx {
23 : ulong idx;
24 : fd_wksp_t * mem;
25 : ulong chunk;
26 : ulong chunk0;
27 : ulong wmark;
28 : } link_ctx_t;
29 :
30 : typedef struct fd_exec_tile_ctx {
31 :
32 : ulong tile_idx;
33 :
34 : /* link-related data structures. */
35 : link_ctx_t replay_in[ 1 ];
36 : link_ctx_t exec_replay_out[ 1 ]; /* TODO: Remove with solcap v2 */
37 : link_ctx_t exec_sig_out[ 1 ];
38 :
39 : fd_sha512_t sha_mem[ FD_TXN_ACTUAL_SIG_MAX ];
40 : fd_sha512_t * sha_lj[ FD_TXN_ACTUAL_SIG_MAX ];
41 :
42 : fd_bank_hash_cmp_t * bank_hash_cmp;
43 :
44 : /* Data structures related to managing and executing the transaction.
45 : The fd_txn_p_t is refreshed with every transaction and is sent
46 : from the dispatch/replay tile. The fd_exec_txn_ctx_t * is a valid
47 : local join that lives in the top-most frame of the spad that is
48 : setup when the exec tile is booted; its members are refreshed on
49 : the slot/epoch boundary. */
50 : fd_exec_txn_ctx_t txn_ctx[1];
51 :
52 : /* Capture context for debugging runtime execution. */
53 : fd_capture_ctx_t * capture_ctx;
54 : uchar * solcap_publish_buffer_ptr;
55 : ulong account_updates_flushed;
56 :
57 : /* A transaction can be executed as long as there is a valid handle to
58 : a funk_txn and a bank. These are queried from fd_banks_t and
59 : fd_funk_t. */
60 : fd_banks_t * banks;
61 : fd_funk_t funk[1];
62 : fd_progcache_t progcache[1];
63 :
64 : fd_txncache_t * txncache;
65 :
66 : /* We need to ensure that all solcap updates have been published
67 : before this message. */
68 : int pending_txn_finalized_msg;
69 : ulong txn_idx;
70 : ulong slot;
71 : ulong dispatch_time_comp;
72 :
73 : fd_exec_stack_t exec_stack;
74 : fd_exec_accounts_t exec_accounts;
75 :
76 : /* tracing_mem is staging memory to dump instructions/transactions
77 : into protobuf files. tracing_mem is staging memory to output vm
78 : execution traces.
79 : TODO: This should not be compiled in prod. */
80 : uchar dumping_mem[ FD_SPAD_FOOTPRINT( 1UL<<28UL ) ] __attribute__((aligned(FD_SPAD_ALIGN)));
81 : uchar tracing_mem[ FD_MAX_INSTRUCTION_STACK_DEPTH ][ FD_RUNTIME_VM_TRACE_STATIC_FOOTPRINT ] __attribute__((aligned(FD_RUNTIME_VM_TRACE_STATIC_ALIGN)));
82 :
83 : } fd_exec_tile_ctx_t;
84 :
85 : FD_FN_CONST static inline ulong
86 0 : scratch_align( void ) {
87 0 : return 128UL;
88 0 : }
89 :
90 : FD_FN_PURE static inline ulong
91 0 : scratch_footprint( fd_topo_tile_t const * tile ) {
92 0 : ulong l = FD_LAYOUT_INIT;
93 0 : l = FD_LAYOUT_APPEND( l, alignof(fd_exec_tile_ctx_t), sizeof(fd_exec_tile_ctx_t) );
94 0 : l = FD_LAYOUT_APPEND( l, fd_capture_ctx_align(), fd_capture_ctx_footprint() );
95 0 : l = FD_LAYOUT_APPEND( l, fd_txncache_align(), fd_txncache_footprint( tile->exec.max_live_slots ) );
96 0 : l = FD_LAYOUT_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN, FD_PROGCACHE_SCRATCH_FOOTPRINT );
97 0 : return FD_LAYOUT_FINI( l, scratch_align() );
98 0 : }
99 :
100 : static void
101 0 : metrics_write( fd_exec_tile_ctx_t * ctx ) {
102 0 : fd_progcache_t * progcache = ctx->progcache;
103 0 : FD_MCNT_SET( EXEC, PROGCACHE_MISSES, progcache->metrics->miss_cnt );
104 0 : FD_MCNT_SET( EXEC, PROGCACHE_HITS, progcache->metrics->hit_cnt );
105 0 : FD_MCNT_SET( EXEC, PROGCACHE_FILLS, progcache->metrics->fill_cnt );
106 0 : FD_MCNT_SET( EXEC, PROGCACHE_FILL_TOT_SZ, progcache->metrics->fill_tot_sz );
107 0 : FD_MCNT_SET( EXEC, PROGCACHE_INVALIDATIONS, progcache->metrics->invalidate_cnt );
108 0 : FD_MCNT_SET( EXEC, PROGCACHE_DUP_INSERTS, progcache->metrics->dup_insert_cnt );
109 0 : }
110 :
111 : static inline int
112 : returnable_frag( fd_exec_tile_ctx_t * ctx,
113 : ulong in_idx,
114 : ulong seq FD_PARAM_UNUSED,
115 : ulong sig,
116 : ulong chunk,
117 : ulong sz,
118 : ulong ctl FD_PARAM_UNUSED,
119 : ulong tsorig FD_PARAM_UNUSED,
120 : ulong tspub,
121 0 : fd_stem_context_t * stem ) {
122 :
123 0 : if( (sig&0xFFFFFFFFUL)!=ctx->tile_idx ) return 0;
124 :
125 0 : if( FD_LIKELY( in_idx==ctx->replay_in->idx ) ) {
126 0 : if( FD_UNLIKELY( chunk < ctx->replay_in->chunk0 || chunk > ctx->replay_in->wmark ) ) {
127 0 : FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->replay_in->chunk0, ctx->replay_in->wmark ));
128 0 : }
129 0 : switch( sig>>32 ) {
130 0 : case FD_EXEC_TT_TXN_EXEC: {
131 : /* Execute. */
132 0 : fd_exec_txn_exec_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
133 0 : ctx->txn_ctx->exec_err = fd_runtime_prepare_and_execute_txn( ctx->banks,
134 0 : msg->bank_idx,
135 0 : ctx->txn_ctx,
136 0 : &msg->txn,
137 0 : ctx->capture_ctx,
138 0 : &ctx->exec_stack,
139 0 : &ctx->exec_accounts,
140 0 : ctx->dumping_mem,
141 0 : &ctx->tracing_mem[0][0] );
142 :
143 : /* Commit. */
144 0 : fd_bank_t * bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
145 0 : if( FD_LIKELY( ctx->txn_ctx->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS ) ) {
146 0 : fd_funk_txn_xid_t xid = (fd_funk_txn_xid_t){ .ul = { fd_bank_slot_get( bank ), bank->idx } };
147 0 : fd_runtime_finalize_txn( ctx->funk, ctx->progcache, ctx->txncache, &xid, ctx->txn_ctx, bank, ctx->capture_ctx, NULL );
148 0 : }
149 :
150 0 : if( FD_LIKELY( ctx->exec_sig_out->idx!=ULONG_MAX ) ) {
151 : /* Copy the txn signature to the signature out link so the
152 : dedup/pack tiles can drop already executed transactions. */
153 0 : memcpy( fd_chunk_to_laddr( ctx->exec_sig_out->mem, ctx->exec_sig_out->chunk ),
154 0 : (uchar *)ctx->txn_ctx->txn.payload + TXN( &ctx->txn_ctx->txn )->signature_off,
155 0 : 64UL );
156 0 : fd_stem_publish( stem, ctx->exec_sig_out->idx, 0UL, ctx->exec_sig_out->chunk, 64UL, 0UL, 0UL, 0UL );
157 0 : ctx->exec_sig_out->chunk = fd_dcache_compact_next( ctx->exec_sig_out->chunk, 64UL, ctx->exec_sig_out->chunk0, ctx->exec_sig_out->wmark );
158 0 : }
159 :
160 : /* Notify replay. */
161 0 : ctx->txn_idx = msg->txn_idx;
162 0 : ctx->dispatch_time_comp = tspub;
163 0 : ctx->slot = fd_bank_slot_get( bank );
164 0 : ctx->pending_txn_finalized_msg = 1;
165 :
166 0 : break;
167 0 : }
168 0 : case FD_EXEC_TT_TXN_SIGVERIFY: {
169 0 : fd_exec_txn_sigverify_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
170 0 : int res = fd_executor_txn_verify( &msg->txn, ctx->sha_lj );
171 0 : fd_exec_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
172 0 : out_msg->bank_idx = msg->bank_idx;
173 0 : out_msg->txn_sigverify->txn_idx = msg->txn_idx;
174 0 : out_msg->txn_sigverify->err = (res!=FD_RUNTIME_EXECUTE_SUCCESS);
175 0 : fd_stem_publish( stem, ctx->exec_replay_out->idx, (FD_EXEC_TT_TXN_SIGVERIFY<<32)|ctx->tile_idx, ctx->exec_replay_out->chunk, sizeof(*out_msg), 0UL, 0UL, 0UL );
176 0 : ctx->exec_replay_out->chunk = fd_dcache_compact_next( ctx->exec_replay_out->chunk, sizeof(*out_msg), ctx->exec_replay_out->chunk0, ctx->exec_replay_out->wmark );
177 0 : break;
178 0 : }
179 0 : default: FD_LOG_CRIT(( "unexpected signature %lu", sig ));
180 0 : }
181 0 : } else FD_LOG_CRIT(( "invalid in_idx %lu", in_idx ));
182 :
183 0 : return 0;
184 0 : }
185 :
186 : static void
187 : unprivileged_init( fd_topo_t * topo,
188 0 : fd_topo_tile_t * tile ) {
189 :
190 : /********************************************************************/
191 : /* validate allocations */
192 : /********************************************************************/
193 :
194 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
195 :
196 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
197 0 : fd_exec_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_tile_ctx_t), sizeof(fd_exec_tile_ctx_t) );
198 0 : void * capture_ctx_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_capture_ctx_align(), fd_capture_ctx_footprint() );
199 0 : void * _txncache = FD_SCRATCH_ALLOC_APPEND( l, fd_txncache_align(), fd_txncache_footprint( tile->exec.max_live_slots ) );
200 0 : uchar * pc_scratch = FD_SCRATCH_ALLOC_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN, FD_PROGCACHE_SCRATCH_FOOTPRINT );
201 0 : ulong scratch_alloc_mem = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
202 :
203 0 : if( FD_UNLIKELY( scratch_alloc_mem - (ulong)scratch - scratch_footprint( tile ) ) ) {
204 0 : FD_LOG_ERR( ( "Scratch_alloc_mem did not match scratch_footprint diff: %lu alloc: %lu footprint: %lu",
205 0 : scratch_alloc_mem - (ulong)scratch - scratch_footprint( tile ),
206 0 : scratch_alloc_mem,
207 0 : (ulong)scratch + scratch_footprint( tile ) ) );
208 0 : }
209 :
210 0 : for( ulong i=0UL; i<FD_TXN_ACTUAL_SIG_MAX; i++ ) {
211 0 : fd_sha512_t * sha = fd_sha512_join( fd_sha512_new( ctx->sha_mem+i ) );
212 0 : FD_TEST( sha );
213 0 : ctx->sha_lj[i] = sha;
214 0 : }
215 :
216 : /********************************************************************/
217 : /* validate links */
218 : /********************************************************************/
219 :
220 0 : ctx->tile_idx = tile->kind_id;
221 :
222 : /* First find and setup the in-link from replay to exec. */
223 0 : ctx->replay_in->idx = fd_topo_find_tile_in_link( topo, tile, "replay_exec", 0UL );
224 0 : FD_TEST( ctx->replay_in->idx!=ULONG_MAX );
225 0 : fd_topo_link_t * replay_in_link = &topo->links[ tile->in_link_id[ ctx->replay_in->idx ] ];
226 0 : FD_TEST( replay_in_link!=NULL );
227 0 : ctx->replay_in->mem = topo->workspaces[ topo->objs[ replay_in_link->dcache_obj_id ].wksp_id ].wksp;
228 0 : ctx->replay_in->chunk0 = fd_dcache_compact_chunk0( ctx->replay_in->mem, replay_in_link->dcache );
229 0 : ctx->replay_in->wmark = fd_dcache_compact_wmark( ctx->replay_in->mem, replay_in_link->dcache, replay_in_link->mtu );
230 0 : ctx->replay_in->chunk = ctx->replay_in->chunk0;
231 :
232 0 : ctx->exec_replay_out->idx = fd_topo_find_tile_out_link( topo, tile, "exec_replay", ctx->tile_idx );
233 0 : if( FD_LIKELY( ctx->exec_replay_out->idx!=ULONG_MAX ) ) {
234 0 : fd_topo_link_t * exec_replay_link = &topo->links[ tile->out_link_id[ ctx->exec_replay_out->idx ] ];
235 0 : ctx->exec_replay_out->mem = topo->workspaces[ topo->objs[ exec_replay_link->dcache_obj_id ].wksp_id ].wksp;
236 0 : ctx->exec_replay_out->chunk0 = fd_dcache_compact_chunk0( ctx->exec_replay_out->mem, exec_replay_link->dcache );
237 0 : ctx->exec_replay_out->wmark = fd_dcache_compact_wmark( ctx->exec_replay_out->mem, exec_replay_link->dcache, exec_replay_link->mtu );
238 0 : ctx->exec_replay_out->chunk = ctx->exec_replay_out->chunk0;
239 0 : }
240 :
241 0 : ctx->exec_sig_out->idx = fd_topo_find_tile_out_link( topo, tile, "exec_sig", ctx->tile_idx );
242 0 : if( FD_LIKELY( ctx->exec_sig_out->idx!=ULONG_MAX ) ) {
243 0 : fd_topo_link_t * exec_sig_link = &topo->links[ tile->out_link_id[ ctx->exec_sig_out->idx ] ];
244 0 : ctx->exec_sig_out->mem = topo->workspaces[ topo->objs[ exec_sig_link->dcache_obj_id ].wksp_id ].wksp;
245 0 : ctx->exec_sig_out->chunk0 = fd_dcache_compact_chunk0( ctx->exec_sig_out->mem, exec_sig_link->dcache );
246 0 : ctx->exec_sig_out->wmark = fd_dcache_compact_wmark( ctx->exec_sig_out->mem, exec_sig_link->dcache, exec_sig_link->mtu );
247 0 : ctx->exec_sig_out->chunk = ctx->exec_sig_out->chunk0;
248 0 : }
249 :
250 : /********************************************************************/
251 : /* banks */
252 : /********************************************************************/
253 :
254 0 : ulong banks_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "banks" );
255 0 : if( FD_UNLIKELY( banks_obj_id==ULONG_MAX ) ) {
256 0 : FD_LOG_ERR(( "Could not find topology object for banks" ));
257 0 : }
258 :
259 0 : ctx->banks = fd_banks_join( fd_topo_obj_laddr( topo, banks_obj_id ) );
260 0 : if( FD_UNLIKELY( !ctx->banks ) ) {
261 0 : FD_LOG_ERR(( "Failed to join banks" ));
262 0 : }
263 :
264 : /********************************************************************/
265 : /* bank hash cmp */
266 : /********************************************************************/
267 :
268 0 : ulong bank_hash_cmp_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "bh_cmp" );
269 0 : if( FD_UNLIKELY( bank_hash_cmp_obj_id==ULONG_MAX ) ) {
270 0 : FD_LOG_ERR(( "Could not find topology object for bank hash cmp" ));
271 0 : }
272 0 : ctx->bank_hash_cmp = fd_bank_hash_cmp_join( fd_topo_obj_laddr( topo, bank_hash_cmp_obj_id ) );
273 0 : if( FD_UNLIKELY( !ctx->bank_hash_cmp ) ) {
274 0 : FD_LOG_ERR(( "Failed to join bank hash cmp" ));
275 0 : }
276 :
277 0 : void * shfunk = fd_topo_obj_laddr( topo, tile->exec.funk_obj_id );
278 0 : if( FD_UNLIKELY( !fd_funk_join( ctx->funk, shfunk ) ) ) {
279 0 : FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
280 0 : }
281 :
282 0 : void * shprogcache = fd_topo_obj_laddr( topo, tile->exec.progcache_obj_id );
283 0 : if( FD_UNLIKELY( !fd_progcache_join( ctx->progcache, shprogcache, pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT ) ) ) {
284 0 : FD_LOG_CRIT(( "fd_progcache_join() failed" ));
285 0 : }
286 :
287 0 : void * _txncache_shmem = fd_topo_obj_laddr( topo, tile->exec.txncache_obj_id );
288 0 : fd_txncache_shmem_t * txncache_shmem = fd_txncache_shmem_join( _txncache_shmem );
289 0 : FD_TEST( txncache_shmem );
290 0 : ctx->txncache = fd_txncache_join( fd_txncache_new( _txncache, txncache_shmem ) );
291 0 : FD_TEST( ctx->txncache );
292 :
293 : /********************************************************************/
294 : /* setup txn ctx */
295 : /********************************************************************/
296 :
297 0 : FD_TEST( fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( ctx->txn_ctx ) ) );
298 :
299 0 : if( FD_UNLIKELY( !fd_funk_join( ctx->txn_ctx->funk, shfunk ) ) ) {
300 0 : FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
301 0 : }
302 0 : ctx->txn_ctx->progcache = fd_progcache_join( ctx->txn_ctx->_progcache, shprogcache, pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT );
303 0 : if( FD_UNLIKELY( !ctx->txn_ctx->progcache ) ) {
304 0 : FD_LOG_CRIT(( "fd_progcache_join() failed" ));
305 0 : }
306 0 : ctx->txn_ctx->status_cache = ctx->txncache;
307 0 : ctx->txn_ctx->bank_hash_cmp = ctx->bank_hash_cmp;
308 0 : ctx->txn_ctx->bundle.is_bundle = 0;
309 :
310 : /********************************************************************/
311 : /* Capture context */
312 : /********************************************************************/
313 :
314 0 : ctx->capture_ctx = NULL;
315 0 : ctx->solcap_publish_buffer_ptr = NULL;
316 0 : ctx->account_updates_flushed = 0UL;
317 0 : if( FD_UNLIKELY( strlen( tile->exec.solcap_capture ) || strlen( tile->exec.dump_proto_dir ) ) ) {
318 0 : ctx->capture_ctx = fd_capture_ctx_join( fd_capture_ctx_new( capture_ctx_mem ) );
319 :
320 0 : if( strlen( tile->exec.dump_proto_dir ) ) {
321 0 : ctx->capture_ctx->dump_proto_output_dir = tile->exec.dump_proto_dir;
322 0 : ctx->capture_ctx->dump_proto_start_slot = tile->exec.capture_start_slot;
323 0 : ctx->capture_ctx->dump_instr_to_pb = tile->exec.dump_instr_to_pb;
324 0 : ctx->capture_ctx->dump_txn_to_pb = tile->exec.dump_txn_to_pb;
325 0 : ctx->capture_ctx->dump_syscall_to_pb = tile->exec.dump_syscall_to_pb;
326 0 : ctx->capture_ctx->dump_elf_to_pb = tile->exec.dump_elf_to_pb;
327 0 : }
328 :
329 0 : if( strlen( tile->exec.solcap_capture ) ) {
330 0 : ctx->capture_ctx->capture_txns = 0;
331 0 : ctx->capture_ctx->solcap_start_slot = tile->exec.capture_start_slot;
332 0 : ctx->account_updates_flushed = 0;
333 0 : ctx->solcap_publish_buffer_ptr = ctx->capture_ctx->account_updates_buffer;
334 0 : }
335 0 : }
336 :
337 0 : ctx->pending_txn_finalized_msg = 0;
338 0 : }
339 :
340 : /* Publish the next account update event buffered in the capture tile to the replay tile
341 :
342 : TODO: remove this when solcap v2 is here. */
343 : static void
344 : publish_next_capture_ctx_account_update( fd_exec_tile_ctx_t * ctx,
345 0 : fd_stem_context_t * stem ) {
346 0 : if( FD_UNLIKELY( !ctx->capture_ctx ) ) {
347 0 : return;
348 0 : }
349 :
350 : /* Copy the account update event to the buffer */
351 0 : ulong chunk = ctx->exec_replay_out->chunk;
352 0 : uchar * out_ptr = fd_chunk_to_laddr( ctx->exec_replay_out->mem, chunk );
353 0 : fd_capture_ctx_account_update_msg_t * msg = (fd_capture_ctx_account_update_msg_t *)ctx->solcap_publish_buffer_ptr;
354 0 : memcpy( out_ptr, msg, sizeof(fd_capture_ctx_account_update_msg_t) );
355 0 : ctx->solcap_publish_buffer_ptr += sizeof(fd_capture_ctx_account_update_msg_t);
356 0 : out_ptr += sizeof(fd_capture_ctx_account_update_msg_t);
357 :
358 : /* Copy the data to the buffer */
359 0 : ulong data_sz = msg->data_sz;
360 0 : memcpy( out_ptr, ctx->solcap_publish_buffer_ptr, data_sz );
361 0 : ctx->solcap_publish_buffer_ptr += data_sz;
362 0 : out_ptr += data_sz;
363 :
364 : /* Stem publish the account update event */
365 0 : ulong msg_sz = sizeof(fd_capture_ctx_account_update_msg_t) + msg->data_sz;
366 0 : fd_stem_publish( stem, ctx->exec_replay_out->idx, 0UL, chunk, msg_sz, 0UL, 0UL, 0UL );
367 0 : ctx->exec_replay_out->chunk = fd_dcache_compact_next(
368 0 : chunk,
369 0 : msg_sz,
370 0 : ctx->exec_replay_out->chunk0,
371 0 : ctx->exec_replay_out->wmark );
372 :
373 : /* Advance the number of account updates flushed */
374 0 : ctx->account_updates_flushed++;
375 :
376 : /* If we have published all the account updates, reset the buffer pointer and length */
377 0 : if( ctx->account_updates_flushed == ctx->capture_ctx->account_updates_len ) {
378 0 : ctx->capture_ctx->account_updates_buffer_ptr = ctx->capture_ctx->account_updates_buffer;
379 0 : ctx->solcap_publish_buffer_ptr = ctx->capture_ctx->account_updates_buffer;
380 0 : ctx->capture_ctx->account_updates_len = 0UL;
381 0 : ctx->account_updates_flushed = 0UL;
382 0 : }
383 0 : }
384 :
385 : /* Publish the txn finalized message to the replay tile */
386 : static void
387 : publish_txn_finalized_msg( fd_exec_tile_ctx_t * ctx,
388 0 : fd_stem_context_t * stem ) {
389 0 : fd_exec_task_done_msg_t * msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
390 0 : msg->bank_idx = ctx->txn_ctx->bank_idx;
391 0 : msg->txn_exec->txn_idx = ctx->txn_idx;
392 0 : msg->txn_exec->err = !(ctx->txn_ctx->flags&FD_TXN_P_FLAGS_EXECUTE_SUCCESS);
393 0 : msg->txn_exec->slot = ctx->slot;
394 0 : msg->txn_exec->start_shred_idx = ctx->txn_ctx->txn.start_shred_idx;
395 0 : msg->txn_exec->end_shred_idx = ctx->txn_ctx->txn.end_shred_idx;
396 0 : if( FD_UNLIKELY( msg->txn_exec->err ) ) {
397 0 : FD_LOG_WARNING(( "txn failed to execute, bad block detected err=%d", ctx->txn_ctx->exec_err ));
398 0 : }
399 :
400 0 : fd_stem_publish( stem, ctx->exec_replay_out->idx, (FD_EXEC_TT_TXN_EXEC<<32)|ctx->tile_idx, ctx->exec_replay_out->chunk, sizeof(*msg), 0UL, ctx->dispatch_time_comp, fd_frag_meta_ts_comp( fd_tickcount() ) );
401 :
402 0 : ctx->exec_replay_out->chunk = fd_dcache_compact_next( ctx->exec_replay_out->chunk, sizeof(*msg), ctx->exec_replay_out->chunk0, ctx->exec_replay_out->wmark );
403 :
404 0 : ctx->pending_txn_finalized_msg = 0;
405 0 : }
406 :
407 : static void
408 : after_credit( fd_exec_tile_ctx_t * ctx,
409 : fd_stem_context_t * stem,
410 : int * opt_poll_in,
411 0 : int * charge_busy FD_PARAM_UNUSED ) {
412 : /* If we have outstanding account updates to send to solcap, send
413 : them. Note that we set opt_poll_in to 0 here because we must not
414 : consume any more fragments from the exec tiles before publishing
415 : our messages, so that solcap updates are not interleaved between
416 : slots. */
417 0 : if( FD_UNLIKELY( ctx->capture_ctx && ctx->account_updates_flushed < ctx->capture_ctx->account_updates_len ) ) {
418 0 : publish_next_capture_ctx_account_update( ctx, stem );
419 0 : *opt_poll_in = 0;
420 0 : } else if( ctx->pending_txn_finalized_msg ) {
421 0 : publish_txn_finalized_msg( ctx, stem );
422 0 : *opt_poll_in = 0;
423 0 : }
424 0 : }
425 :
426 : static ulong
427 : populate_allowed_seccomp( fd_topo_t const * topo FD_PARAM_UNUSED,
428 : fd_topo_tile_t const * tile FD_PARAM_UNUSED,
429 : ulong out_cnt,
430 0 : struct sock_filter * out ) {
431 0 : populate_sock_filter_policy_fd_exec_tile( out_cnt, out, (uint)fd_log_private_logfile_fd() );
432 0 : return sock_filter_policy_fd_exec_tile_instr_cnt;
433 0 : }
434 :
435 : static ulong
436 : populate_allowed_fds( fd_topo_t const * topo FD_PARAM_UNUSED,
437 : fd_topo_tile_t const * tile FD_PARAM_UNUSED,
438 : ulong out_fds_cnt,
439 0 : int * out_fds ) {
440 :
441 0 : if( FD_UNLIKELY( out_fds_cnt<2UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
442 :
443 0 : ulong out_cnt = 0UL;
444 0 : out_fds[ out_cnt++ ] = 2; /* stderr */
445 0 : if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
446 0 : out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
447 0 : return out_cnt;
448 0 : }
449 :
450 0 : #define STEM_BURST (2UL)
451 : /* Right now, depth of the replay_exec link and depth of the exec_replay
452 : links is 16K. At 1M TPS, that's ~16ms to fill. But we also want to
453 : be conservative here, so we use 1ms. */
454 0 : #define STEM_LAZY (1000000UL)
455 :
456 0 : #define STEM_CALLBACK_CONTEXT_TYPE fd_exec_tile_ctx_t
457 0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_exec_tile_ctx_t)
458 :
459 0 : #define STEM_CALLBACK_AFTER_CREDIT after_credit
460 0 : #define STEM_CALLBACK_RETURNABLE_FRAG returnable_frag
461 0 : #define STEM_CALLBACK_METRICS_WRITE metrics_write
462 :
463 : #include "../../disco/stem/fd_stem.c"
464 :
465 : fd_topo_run_tile_t fd_tile_execor = {
466 : .name = "exec",
467 : .loose_footprint = 0UL,
468 : .populate_allowed_seccomp = populate_allowed_seccomp,
469 : .populate_allowed_fds = populate_allowed_fds,
470 : .scratch_align = scratch_align,
471 : .scratch_footprint = scratch_footprint,
472 : .unprivileged_init = unprivileged_init,
473 : .run = stem_run,
474 : };
|