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 :
71 : fd_exec_stack_t exec_stack;
72 : fd_exec_accounts_t exec_accounts;
73 :
74 : /* tracing_mem is staging memory to dump instructions/transactions
75 : into protobuf files. tracing_mem is staging memory to output vm
76 : execution traces.
77 : TODO: This should not be compiled in prod. */
78 : uchar dumping_mem[ FD_SPAD_FOOTPRINT( 1UL<<28UL ) ] __attribute__((aligned(FD_SPAD_ALIGN)));
79 : uchar tracing_mem[ FD_MAX_INSTRUCTION_STACK_DEPTH ][ FD_RUNTIME_VM_TRACE_STATIC_FOOTPRINT ] __attribute__((aligned(FD_RUNTIME_VM_TRACE_STATIC_ALIGN)));
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 FD_PARAM_UNUSED,
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->txn_ctx->exec_err = fd_runtime_prepare_and_execute_txn( ctx->banks,
132 0 : msg->bank_idx,
133 0 : ctx->txn_ctx,
134 0 : &msg->txn,
135 0 : ctx->capture_ctx,
136 0 : &ctx->exec_stack,
137 0 : &ctx->exec_accounts,
138 0 : ctx->dumping_mem,
139 0 : &ctx->tracing_mem[0][0] );
140 :
141 : /* Commit. */
142 0 : fd_bank_t * bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
143 0 : if( FD_LIKELY( ctx->txn_ctx->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS ) ) {
144 0 : fd_funk_txn_xid_t xid = (fd_funk_txn_xid_t){ .ul = { fd_bank_slot_get( bank ), bank->idx } };
145 0 : fd_runtime_finalize_txn( ctx->funk, ctx->progcache, ctx->txncache, &xid, ctx->txn_ctx, bank, ctx->capture_ctx, NULL );
146 0 : }
147 :
148 0 : if( FD_LIKELY( ctx->exec_sig_out->idx!=ULONG_MAX ) ) {
149 : /* Copy the txn signature to the signature out link so the
150 : dedup/pack tiles can drop already executed transactions. */
151 0 : memcpy( fd_chunk_to_laddr( ctx->exec_sig_out->mem, ctx->exec_sig_out->chunk ),
152 0 : (uchar *)ctx->txn_ctx->txn.payload + TXN( &ctx->txn_ctx->txn )->signature_off,
153 0 : 64UL );
154 0 : fd_stem_publish( stem, ctx->exec_sig_out->idx, 0UL, ctx->exec_sig_out->chunk, 64UL, 0UL, 0UL, 0UL );
155 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 );
156 0 : }
157 :
158 : /* Notify replay. */
159 0 : ctx->txn_idx = msg->txn_idx;
160 0 : ctx->pending_txn_finalized_msg = 1;
161 :
162 0 : break;
163 0 : }
164 0 : case FD_EXEC_TT_TXN_SIGVERIFY: {
165 0 : fd_exec_txn_sigverify_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
166 0 : int res = fd_executor_txn_verify( &msg->txn, ctx->sha_lj );
167 0 : fd_exec_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
168 0 : out_msg->bank_idx = msg->bank_idx;
169 0 : out_msg->txn_sigverify->txn_idx = msg->txn_idx;
170 0 : out_msg->txn_sigverify->err = (res!=FD_RUNTIME_EXECUTE_SUCCESS);
171 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 );
172 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 );
173 0 : break;
174 0 : }
175 0 : default: FD_LOG_CRIT(( "unexpected signature %lu", sig ));
176 0 : }
177 0 : } else FD_LOG_CRIT(( "invalid in_idx %lu", in_idx ));
178 :
179 0 : return 0;
180 0 : }
181 :
182 : static void
183 : unprivileged_init( fd_topo_t * topo,
184 0 : fd_topo_tile_t * tile ) {
185 :
186 : /********************************************************************/
187 : /* validate allocations */
188 : /********************************************************************/
189 :
190 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
191 :
192 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
193 0 : fd_exec_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_tile_ctx_t), sizeof(fd_exec_tile_ctx_t) );
194 0 : void * capture_ctx_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_capture_ctx_align(), fd_capture_ctx_footprint() );
195 0 : void * _txncache = FD_SCRATCH_ALLOC_APPEND( l, fd_txncache_align(), fd_txncache_footprint( tile->exec.max_live_slots ) );
196 0 : uchar * pc_scratch = FD_SCRATCH_ALLOC_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN, FD_PROGCACHE_SCRATCH_FOOTPRINT );
197 0 : ulong scratch_alloc_mem = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
198 :
199 0 : if( FD_UNLIKELY( scratch_alloc_mem - (ulong)scratch - scratch_footprint( tile ) ) ) {
200 0 : FD_LOG_ERR( ( "Scratch_alloc_mem did not match scratch_footprint diff: %lu alloc: %lu footprint: %lu",
201 0 : scratch_alloc_mem - (ulong)scratch - scratch_footprint( tile ),
202 0 : scratch_alloc_mem,
203 0 : (ulong)scratch + scratch_footprint( tile ) ) );
204 0 : }
205 :
206 0 : for( ulong i=0UL; i<FD_TXN_ACTUAL_SIG_MAX; i++ ) {
207 0 : fd_sha512_t * sha = fd_sha512_join( fd_sha512_new( ctx->sha_mem+i ) );
208 0 : FD_TEST( sha );
209 0 : ctx->sha_lj[i] = sha;
210 0 : }
211 :
212 : /********************************************************************/
213 : /* validate links */
214 : /********************************************************************/
215 :
216 0 : ctx->tile_idx = tile->kind_id;
217 :
218 : /* First find and setup the in-link from replay to exec. */
219 0 : ctx->replay_in->idx = fd_topo_find_tile_in_link( topo, tile, "replay_exec", 0UL );
220 0 : FD_TEST( ctx->replay_in->idx!=ULONG_MAX );
221 0 : fd_topo_link_t * replay_in_link = &topo->links[ tile->in_link_id[ ctx->replay_in->idx ] ];
222 0 : FD_TEST( replay_in_link!=NULL );
223 0 : ctx->replay_in->mem = topo->workspaces[ topo->objs[ replay_in_link->dcache_obj_id ].wksp_id ].wksp;
224 0 : ctx->replay_in->chunk0 = fd_dcache_compact_chunk0( ctx->replay_in->mem, replay_in_link->dcache );
225 0 : ctx->replay_in->wmark = fd_dcache_compact_wmark( ctx->replay_in->mem, replay_in_link->dcache, replay_in_link->mtu );
226 0 : ctx->replay_in->chunk = ctx->replay_in->chunk0;
227 :
228 0 : ctx->exec_replay_out->idx = fd_topo_find_tile_out_link( topo, tile, "exec_replay", ctx->tile_idx );
229 0 : if( FD_LIKELY( ctx->exec_replay_out->idx!=ULONG_MAX ) ) {
230 0 : fd_topo_link_t * exec_replay_link = &topo->links[ tile->out_link_id[ ctx->exec_replay_out->idx ] ];
231 0 : ctx->exec_replay_out->mem = topo->workspaces[ topo->objs[ exec_replay_link->dcache_obj_id ].wksp_id ].wksp;
232 0 : ctx->exec_replay_out->chunk0 = fd_dcache_compact_chunk0( ctx->exec_replay_out->mem, exec_replay_link->dcache );
233 0 : ctx->exec_replay_out->wmark = fd_dcache_compact_wmark( ctx->exec_replay_out->mem, exec_replay_link->dcache, exec_replay_link->mtu );
234 0 : ctx->exec_replay_out->chunk = ctx->exec_replay_out->chunk0;
235 0 : }
236 :
237 0 : ctx->exec_sig_out->idx = fd_topo_find_tile_out_link( topo, tile, "exec_sig", ctx->tile_idx );
238 0 : if( FD_LIKELY( ctx->exec_sig_out->idx!=ULONG_MAX ) ) {
239 0 : fd_topo_link_t * exec_sig_link = &topo->links[ tile->out_link_id[ ctx->exec_sig_out->idx ] ];
240 0 : ctx->exec_sig_out->mem = topo->workspaces[ topo->objs[ exec_sig_link->dcache_obj_id ].wksp_id ].wksp;
241 0 : ctx->exec_sig_out->chunk0 = fd_dcache_compact_chunk0( ctx->exec_sig_out->mem, exec_sig_link->dcache );
242 0 : ctx->exec_sig_out->wmark = fd_dcache_compact_wmark( ctx->exec_sig_out->mem, exec_sig_link->dcache, exec_sig_link->mtu );
243 0 : ctx->exec_sig_out->chunk = ctx->exec_sig_out->chunk0;
244 0 : }
245 :
246 : /********************************************************************/
247 : /* banks */
248 : /********************************************************************/
249 :
250 0 : ulong banks_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "banks" );
251 0 : if( FD_UNLIKELY( banks_obj_id==ULONG_MAX ) ) {
252 0 : FD_LOG_ERR(( "Could not find topology object for banks" ));
253 0 : }
254 :
255 0 : ctx->banks = fd_banks_join( fd_topo_obj_laddr( topo, banks_obj_id ) );
256 0 : if( FD_UNLIKELY( !ctx->banks ) ) {
257 0 : FD_LOG_ERR(( "Failed to join banks" ));
258 0 : }
259 :
260 : /********************************************************************/
261 : /* bank hash cmp */
262 : /********************************************************************/
263 :
264 0 : ulong bank_hash_cmp_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "bh_cmp" );
265 0 : if( FD_UNLIKELY( bank_hash_cmp_obj_id==ULONG_MAX ) ) {
266 0 : FD_LOG_ERR(( "Could not find topology object for bank hash cmp" ));
267 0 : }
268 0 : ctx->bank_hash_cmp = fd_bank_hash_cmp_join( fd_topo_obj_laddr( topo, bank_hash_cmp_obj_id ) );
269 0 : if( FD_UNLIKELY( !ctx->bank_hash_cmp ) ) {
270 0 : FD_LOG_ERR(( "Failed to join bank hash cmp" ));
271 0 : }
272 :
273 0 : void * shfunk = fd_topo_obj_laddr( topo, tile->exec.funk_obj_id );
274 0 : if( FD_UNLIKELY( !fd_funk_join( ctx->funk, shfunk ) ) ) {
275 0 : FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
276 0 : }
277 :
278 0 : void * shprogcache = fd_topo_obj_laddr( topo, tile->exec.progcache_obj_id );
279 0 : if( FD_UNLIKELY( !fd_progcache_join( ctx->progcache, shprogcache, pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT ) ) ) {
280 0 : FD_LOG_CRIT(( "fd_progcache_join() failed" ));
281 0 : }
282 :
283 0 : void * _txncache_shmem = fd_topo_obj_laddr( topo, tile->exec.txncache_obj_id );
284 0 : fd_txncache_shmem_t * txncache_shmem = fd_txncache_shmem_join( _txncache_shmem );
285 0 : FD_TEST( txncache_shmem );
286 0 : ctx->txncache = fd_txncache_join( fd_txncache_new( _txncache, txncache_shmem ) );
287 0 : FD_TEST( ctx->txncache );
288 :
289 : /********************************************************************/
290 : /* setup txn ctx */
291 : /********************************************************************/
292 :
293 0 : FD_TEST( fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( ctx->txn_ctx ) ) );
294 :
295 0 : if( FD_UNLIKELY( !fd_funk_join( ctx->txn_ctx->funk, shfunk ) ) ) {
296 0 : FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
297 0 : }
298 0 : ctx->txn_ctx->progcache = fd_progcache_join( ctx->txn_ctx->_progcache, shprogcache, pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT );
299 0 : if( FD_UNLIKELY( !ctx->txn_ctx->progcache ) ) {
300 0 : FD_LOG_CRIT(( "fd_progcache_join() failed" ));
301 0 : }
302 0 : ctx->txn_ctx->status_cache = ctx->txncache;
303 0 : ctx->txn_ctx->bank_hash_cmp = ctx->bank_hash_cmp;
304 0 : ctx->txn_ctx->bundle.is_bundle = 0;
305 :
306 : /********************************************************************/
307 : /* Capture context */
308 : /********************************************************************/
309 :
310 0 : ctx->capture_ctx = NULL;
311 0 : ctx->solcap_publish_buffer_ptr = NULL;
312 0 : ctx->account_updates_flushed = 0UL;
313 0 : if( FD_UNLIKELY( strlen( tile->exec.solcap_capture ) || strlen( tile->exec.dump_proto_dir ) ) ) {
314 0 : ctx->capture_ctx = fd_capture_ctx_join( fd_capture_ctx_new( capture_ctx_mem ) );
315 :
316 0 : if( strlen( tile->exec.dump_proto_dir ) ) {
317 0 : ctx->capture_ctx->dump_proto_output_dir = tile->exec.dump_proto_dir;
318 0 : ctx->capture_ctx->dump_proto_start_slot = tile->exec.capture_start_slot;
319 0 : ctx->capture_ctx->dump_instr_to_pb = tile->exec.dump_instr_to_pb;
320 0 : ctx->capture_ctx->dump_txn_to_pb = tile->exec.dump_txn_to_pb;
321 0 : ctx->capture_ctx->dump_syscall_to_pb = tile->exec.dump_syscall_to_pb;
322 0 : ctx->capture_ctx->dump_elf_to_pb = tile->exec.dump_elf_to_pb;
323 0 : }
324 :
325 0 : if( strlen( tile->exec.solcap_capture ) ) {
326 0 : ctx->capture_ctx->capture_txns = 0;
327 0 : ctx->capture_ctx->solcap_start_slot = tile->exec.capture_start_slot;
328 0 : ctx->account_updates_flushed = 0;
329 0 : ctx->solcap_publish_buffer_ptr = ctx->capture_ctx->account_updates_buffer;
330 0 : }
331 0 : }
332 :
333 0 : ctx->pending_txn_finalized_msg = 0;
334 0 : }
335 :
336 : /* Publish the next account update event buffered in the capture tile to the replay tile
337 :
338 : TODO: remove this when solcap v2 is here. */
339 : static void
340 : publish_next_capture_ctx_account_update( fd_exec_tile_ctx_t * ctx,
341 0 : fd_stem_context_t * stem ) {
342 0 : if( FD_UNLIKELY( !ctx->capture_ctx ) ) {
343 0 : return;
344 0 : }
345 :
346 : /* Copy the account update event to the buffer */
347 0 : ulong chunk = ctx->exec_replay_out->chunk;
348 0 : uchar * out_ptr = fd_chunk_to_laddr( ctx->exec_replay_out->mem, chunk );
349 0 : fd_capture_ctx_account_update_msg_t * msg = (fd_capture_ctx_account_update_msg_t *)ctx->solcap_publish_buffer_ptr;
350 0 : memcpy( out_ptr, msg, sizeof(fd_capture_ctx_account_update_msg_t) );
351 0 : ctx->solcap_publish_buffer_ptr += sizeof(fd_capture_ctx_account_update_msg_t);
352 0 : out_ptr += sizeof(fd_capture_ctx_account_update_msg_t);
353 :
354 : /* Copy the data to the buffer */
355 0 : ulong data_sz = msg->data_sz;
356 0 : memcpy( out_ptr, ctx->solcap_publish_buffer_ptr, data_sz );
357 0 : ctx->solcap_publish_buffer_ptr += data_sz;
358 0 : out_ptr += data_sz;
359 :
360 : /* Stem publish the account update event */
361 0 : ulong msg_sz = sizeof(fd_capture_ctx_account_update_msg_t) + msg->data_sz;
362 0 : fd_stem_publish( stem, ctx->exec_replay_out->idx, 0UL, chunk, msg_sz, 0UL, 0UL, 0UL );
363 0 : ctx->exec_replay_out->chunk = fd_dcache_compact_next(
364 0 : chunk,
365 0 : msg_sz,
366 0 : ctx->exec_replay_out->chunk0,
367 0 : ctx->exec_replay_out->wmark );
368 :
369 : /* Advance the number of account updates flushed */
370 0 : ctx->account_updates_flushed++;
371 :
372 : /* If we have published all the account updates, reset the buffer pointer and length */
373 0 : if( ctx->account_updates_flushed == ctx->capture_ctx->account_updates_len ) {
374 0 : ctx->capture_ctx->account_updates_buffer_ptr = ctx->capture_ctx->account_updates_buffer;
375 0 : ctx->solcap_publish_buffer_ptr = ctx->capture_ctx->account_updates_buffer;
376 0 : ctx->capture_ctx->account_updates_len = 0UL;
377 0 : ctx->account_updates_flushed = 0UL;
378 0 : }
379 0 : }
380 :
381 : /* Publish the txn finalized message to the replay tile */
382 : static void
383 : publish_txn_finalized_msg( fd_exec_tile_ctx_t * ctx,
384 0 : fd_stem_context_t * stem ) {
385 0 : fd_exec_task_done_msg_t * msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
386 0 : msg->bank_idx = ctx->txn_ctx->bank_idx;
387 0 : msg->txn_exec->txn_idx = ctx->txn_idx;
388 0 : msg->txn_exec->err = !(ctx->txn_ctx->flags&FD_TXN_P_FLAGS_EXECUTE_SUCCESS);
389 0 : if( FD_UNLIKELY( msg->txn_exec->err ) ) {
390 0 : FD_LOG_WARNING(( "txn failed to execute, bad block detected err=%d", ctx->txn_ctx->exec_err ));
391 0 : }
392 :
393 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, 0UL, 0UL );
394 :
395 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 );
396 :
397 0 : ctx->pending_txn_finalized_msg = 0;
398 0 : }
399 :
400 : static void
401 : after_credit( fd_exec_tile_ctx_t * ctx,
402 : fd_stem_context_t * stem,
403 : int * opt_poll_in,
404 0 : int * charge_busy FD_PARAM_UNUSED ) {
405 : /* If we have outstanding account updates to send to solcap, send
406 : them. Note that we set opt_poll_in to 0 here because we must not
407 : consume any more fragments from the exec tiles before publishing
408 : our messages, so that solcap updates are not interleaved between
409 : slots. */
410 0 : if( FD_UNLIKELY( ctx->capture_ctx && ctx->account_updates_flushed < ctx->capture_ctx->account_updates_len ) ) {
411 0 : publish_next_capture_ctx_account_update( ctx, stem );
412 0 : *opt_poll_in = 0;
413 0 : } else if( ctx->pending_txn_finalized_msg ) {
414 0 : publish_txn_finalized_msg( ctx, stem );
415 0 : *opt_poll_in = 0;
416 0 : }
417 0 : }
418 :
419 : static ulong
420 : populate_allowed_seccomp( fd_topo_t const * topo FD_PARAM_UNUSED,
421 : fd_topo_tile_t const * tile FD_PARAM_UNUSED,
422 : ulong out_cnt,
423 0 : struct sock_filter * out ) {
424 0 : populate_sock_filter_policy_fd_exec_tile( out_cnt, out, (uint)fd_log_private_logfile_fd() );
425 0 : return sock_filter_policy_fd_exec_tile_instr_cnt;
426 0 : }
427 :
428 : static ulong
429 : populate_allowed_fds( fd_topo_t const * topo FD_PARAM_UNUSED,
430 : fd_topo_tile_t const * tile FD_PARAM_UNUSED,
431 : ulong out_fds_cnt,
432 0 : int * out_fds ) {
433 :
434 0 : if( FD_UNLIKELY( out_fds_cnt<2UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
435 :
436 0 : ulong out_cnt = 0UL;
437 0 : out_fds[ out_cnt++ ] = 2; /* stderr */
438 0 : if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
439 0 : out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
440 0 : return out_cnt;
441 0 : }
442 :
443 0 : #define STEM_BURST (2UL)
444 : /* Right now, depth of the replay_exec link and depth of the exec_replay
445 : links is 16K. At 1M TPS, that's ~16ms to fill. But we also want to
446 : be conservative here, so we use 1ms. */
447 0 : #define STEM_LAZY (1000000UL)
448 :
449 0 : #define STEM_CALLBACK_CONTEXT_TYPE fd_exec_tile_ctx_t
450 0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_exec_tile_ctx_t)
451 :
452 0 : #define STEM_CALLBACK_AFTER_CREDIT after_credit
453 0 : #define STEM_CALLBACK_RETURNABLE_FRAG returnable_frag
454 0 : #define STEM_CALLBACK_METRICS_WRITE metrics_write
455 :
456 : #include "../../disco/stem/fd_stem.c"
457 :
458 : fd_topo_run_tile_t fd_tile_execor = {
459 : .name = "exec",
460 : .loose_footprint = 0UL,
461 : .populate_allowed_seccomp = populate_allowed_seccomp,
462 : .populate_allowed_fds = populate_allowed_fds,
463 : .scratch_align = scratch_align,
464 : .scratch_footprint = scratch_footprint,
465 : .unprivileged_init = unprivileged_init,
466 : .run = stem_run,
467 : };
|