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