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