Line data Source code
1 : #include "../execle/fd_execle_err.h"
2 : #include "../../util/pod/fd_pod_format.h"
3 : #include "../../disco/metrics/fd_metrics.h"
4 :
5 : #include "../../discof/fd_startup.h"
6 : #include "../../discof/replay/fd_execrp.h"
7 : #include "../../flamenco/runtime/fd_bank.h"
8 : #include "../../flamenco/runtime/fd_txncache.h"
9 : #include "../../flamenco/runtime/fd_runtime.h"
10 : #include "../../flamenco/runtime/fd_executor.h"
11 : #include "../../flamenco/runtime/fd_cost_tracker.h"
12 : #include "../../flamenco/runtime/fd_hashes.h"
13 : #include "../../ballet/blake3/fd_blake3.h" /* for FD_BLAKE3_XN_MAX */
14 : #include "../../flamenco/runtime/tests/fd_dump_pb.h"
15 : #include "../../flamenco/progcache/fd_progcache_user.h"
16 : #include "../../flamenco/log_collector/fd_log_collector_base.h"
17 : #include "../../disco/events/generated/fd_event_gen.h"
18 : #include "../../flamenco/events/fd_event_runtime.h"
19 :
20 : #include <time.h>
21 : #include <linux/futex.h>
22 : #include "generated/fd_execrp_tile_seccomp.h"
23 :
24 : /* The exec tile is responsible for executing single transactions. The
25 : tile receives a parsed transaction (fd_txn_p_t) and an identifier to
26 : which bank to execute against (index into the bank pool). With this,
27 : the exec tile is able to identify the correct bank and accounts
28 : database fork to execute the transaction against. The exec tile then
29 : commits the results of the transaction to the accounts db and makes
30 : any necessary updates to the bank. */
31 :
32 : typedef struct link_ctx {
33 : ulong idx;
34 : fd_wksp_t * mem;
35 : ulong chunk;
36 : ulong chunk0;
37 : ulong wmark;
38 : } link_ctx_t;
39 :
40 : struct fd_execrp_tile {
41 : ulong tile_idx;
42 :
43 : fd_startup_gate_t startup_gate[1];
44 :
45 : /* link-related data structures. */
46 : link_ctx_t replay_in[ 1 ];
47 : link_ctx_t execrp_replay_out[ 1 ];
48 :
49 : fd_ed25519_verifier_t * verifier;
50 : fd_footer_cache_t * footer_cache;
51 :
52 : /* Capture context for debugging runtime execution. */
53 : fd_capture_ctx_t * capture_ctx;
54 : fd_capture_link_buf_t cap_execrp_out[1];
55 :
56 : /* Protobuf dumping context for debugging runtime execution and
57 : collecting seed corpora. */
58 : fd_dump_proto_ctx_t * dump_proto_ctx;
59 : fd_txn_dump_ctx_t * txn_dump_ctx;
60 :
61 : fd_banks_t * banks;
62 : fd_bank_t * bank;
63 : fd_accdb_t * accdb;
64 : fd_txncache_t * txncache;
65 : fd_progcache_t progcache[1];
66 : fd_bpf_frames_t * bpf_frames;
67 :
68 : ulong txn_idx;
69 : ulong slot;
70 : ulong dispatch_time_comp;
71 : int want_alts;
72 :
73 : fd_execrp_result_t * result;
74 :
75 : fd_log_collector_t log_collector;
76 :
77 : fd_txn_in_t txn_in;
78 : fd_txn_out_t txn_out;
79 :
80 : fd_runtime_t runtime[1];
81 :
82 : struct {
83 : ulong sigverify_cnt;
84 : ulong poh_hash_cnt;
85 :
86 : /* Ticks spent loading txn accounts */
87 : ulong txn_load_cum_ticks;
88 :
89 : /* Ticks spent validating txn invariants (e.g. status cache, fee payer) */
90 : ulong txn_check_cum_ticks;
91 :
92 : /* Ticks spent executing a txn (includes any VM time) */
93 : ulong txn_exec_cum_ticks;
94 :
95 : /* Ticks spent committing a txn (database writes) */
96 : ulong txn_commit_cum_ticks;
97 :
98 : ulong txn_result[ FD_METRICS_ENUM_TXN_RESULT_CNT ];
99 : ulong txn_version[ FD_METRICS_ENUM_TXN_VERSION_CNT ];
100 : } metrics;
101 :
102 : ulong ed25519_cache_seed;
103 : };
104 :
105 : typedef struct fd_execrp_tile fd_execrp_tile_t;
106 :
107 : FD_FN_CONST static inline ulong
108 0 : scratch_align( void ) {
109 0 : return 128UL;
110 0 : }
111 :
112 : FD_FN_PURE static inline ulong
113 0 : scratch_footprint( fd_topo_tile_t const * tile ) {
114 0 : ulong l = FD_LAYOUT_INIT;
115 0 : l = FD_LAYOUT_APPEND( l, alignof(fd_execrp_tile_t), sizeof(fd_execrp_tile_t) );
116 0 : l = FD_LAYOUT_APPEND( l, fd_txncache_align(), fd_txncache_footprint( tile->execrp.max_live_slots ) );
117 0 : l = FD_LAYOUT_APPEND( l, fd_accdb_align(), fd_accdb_footprint( tile->execrp.max_live_slots, 0 ) );
118 0 : l = FD_LAYOUT_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN, FD_PROGCACHE_SCRATCH_FOOTPRINT );
119 0 : l = FD_LAYOUT_APPEND( l, fd_ed25519_verifier_align(), fd_ed25519_verifier_footprint( FD_ED25519_VERIFIER_TXN_CACHE ) );
120 0 : l = FD_LAYOUT_APPEND( l, fd_bpf_frames_align(), fd_bpf_frames_footprint() );
121 :
122 0 : if( FD_UNLIKELY( strlen( tile->execrp.solcap_capture ) ) ) {
123 0 : l = FD_LAYOUT_APPEND( l, fd_capture_ctx_align(), fd_capture_ctx_footprint() );
124 0 : }
125 :
126 0 : if( FD_UNLIKELY( strlen( tile->execrp.dump_proto_dir ) ) ) {
127 0 : l = FD_LAYOUT_APPEND( l, alignof(fd_dump_proto_ctx_t), sizeof(fd_dump_proto_ctx_t) );
128 0 : l = FD_LAYOUT_APPEND( l, fd_txn_dump_context_align(), fd_txn_dump_context_footprint() );
129 0 : if( FD_UNLIKELY( tile->execrp.dump_instr_to_pb || tile->execrp.dump_syscall_to_pb || tile->execrp.dump_txn_to_pb ) ) {
130 0 : l = FD_LAYOUT_APPEND( l, FD_SPAD_ALIGN, FD_SPAD_FOOTPRINT( 1UL<<28UL ) );
131 0 : }
132 0 : }
133 :
134 0 : return FD_LAYOUT_FINI( l, scratch_align() );
135 0 : }
136 :
137 : static void
138 0 : metrics_write( fd_execrp_tile_t * ctx ) {
139 0 : fd_accdb_flush_metrics( ctx->accdb );
140 :
141 0 : FD_MCNT_SET ( EXECRP, SIGNATURE_CHECKED, ctx->metrics.sigverify_cnt );
142 0 : FD_MCNT_SET ( EXECRP, POH_HASH_COMPUTED, ctx->metrics.poh_hash_cnt );
143 0 : FD_MCNT_ENUM_COPY( EXECRP, TXN_PROCESSED, ctx->metrics.txn_result );
144 0 : FD_MCNT_ENUM_COPY( EXECRP, TXN_PROCESSED_BY_VERSION, ctx->metrics.txn_version );
145 :
146 0 : FD_PROGCACHE_METRICS_WRITE( EXECRP, ctx->progcache->metrics );
147 :
148 0 : FD_MCNT_SET( EXECRP, TXN_REGIME_DURATION_NANOS_LOAD, ctx->metrics.txn_load_cum_ticks+ctx->metrics.txn_check_cum_ticks );
149 0 : FD_MCNT_SET( EXECRP, TXN_REGIME_DURATION_NANOS_EXECUTE, ctx->metrics.txn_exec_cum_ticks );
150 0 : FD_MCNT_SET( EXECRP, TXN_REGIME_DURATION_NANOS_COMMIT, ctx->metrics.txn_commit_cum_ticks );
151 :
152 0 : fd_runtime_t const * runtime = ctx->runtime;
153 0 : ulong cpi_ticks = runtime->metrics.cpi_setup_cum_ticks +
154 0 : runtime->metrics.cpi_commit_cum_ticks;
155 0 : ulong exec_ticks = fd_ulong_sat_sub( runtime->metrics.vm_exec_cum_ticks, cpi_ticks );
156 0 : FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_SETUP, runtime->metrics.vm_setup_cum_ticks );
157 0 : FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_COMMIT, runtime->metrics.vm_commit_cum_ticks );
158 0 : FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_SETUP_CPI, runtime->metrics.cpi_setup_cum_ticks );
159 0 : FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_COMMIT_CPI, runtime->metrics.cpi_commit_cum_ticks );
160 0 : FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_INTERPRETER, exec_ticks );
161 :
162 0 : FD_MCNT_SET( EXECRP, CU_CONSUMED, runtime->metrics.cu_cum );
163 0 : FD_MCNT_SET( EXECRP, INSTRUCTION_EXECUTED, runtime->metrics.instr_cum );
164 0 : FD_MCNT_SET( EXECRP, CPI_EXECUTED, runtime->metrics.cpi_cum );
165 0 : FD_MCNT_SET( EXECRP, ACCOUNT_LTHASH_SKIPPED, runtime->metrics.lthash_unchanged_cnt );
166 0 : FD_MCNT_SET( EXECRP, BANK_SWITCHED, runtime->metrics.bank_switch_cnt );
167 :
168 0 : fd_txncache_join_metrics_t const * txncache = fd_txncache_join_metrics( ctx->txncache );
169 0 : FD_MCNT_SET ( EXECRP, TXNCACHE_QUERY_MISS, txncache->query_miss_cnt );
170 0 : FD_MCNT_SET ( EXECRP, TXNCACHE_INSERT_MISS, txncache->insert_miss_cnt );
171 0 : FD_MCNT_SET ( EXECRP, TXNCACHE_OPERATION_STALLED, txncache->stalled_cnt );
172 0 : FD_MHIST_COPY( EXECRP, TXNCACHE_QUERY_DURATION_NANOS, txncache->query_ticks );
173 0 : FD_MHIST_COPY( EXECRP, TXNCACHE_INSERT_DURATION_NANOS, txncache->insert_ticks );
174 :
175 0 : FD_ACCDB_METRICS_WRITE( EXECRP, fd_accdb_metrics( ctx->accdb ) );
176 0 : }
177 :
178 : static void
179 : publish_txn_finalized_msg( fd_execrp_tile_t * ctx,
180 : fd_stem_context_t * stem,
181 0 : long now ) {
182 0 : uint compute_units_consumed = 0U;
183 0 : if( FD_LIKELY( ctx->txn_out.err.is_committable ) ) {
184 0 : fd_usage_cost_details_t const * cost = &ctx->txn_out.details.txn_cost.transaction;
185 0 : compute_units_consumed = cost->signature_cost + cost->write_lock_cost + cost->data_bytes_cost + cost->programs_execution_cost + cost->loaded_accounts_data_size_cost;
186 0 : }
187 :
188 0 : fd_execrp_task_done_msg_t * msg = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
189 0 : msg->bank_idx = ctx->bank->idx;
190 0 : msg->txn_exec->txn_idx = ctx->txn_idx;
191 0 : msg->txn_exec->is_committable = ctx->txn_out.err.is_committable;
192 0 : msg->txn_exec->is_fees_only = ctx->txn_out.err.is_fees_only;
193 0 : msg->txn_exec->is_noop = ctx->txn_out.err.is_noop;
194 0 : msg->txn_exec->txn_err = ctx->txn_out.err.txn_err;
195 :
196 0 : msg->txn_exec->tick_load_start = ctx->txn_out.details.load_start_ticks;
197 0 : msg->txn_exec->tick_check_start = ctx->txn_out.details.check_start_ticks;
198 0 : msg->txn_exec->tick_exec_start = ctx->txn_out.details.exec_start_ticks;
199 0 : msg->txn_exec->tick_commit_start = ctx->txn_out.details.commit_start_ticks;
200 0 : msg->txn_exec->tick_commit_end = fd_long_if( ctx->txn_out.details.commit_start_ticks==LONG_MAX, LONG_MAX, now );
201 :
202 0 : msg->txn_exec->compute_units_consumed = compute_units_consumed;
203 0 : msg->txn_exec->transaction_fee = ctx->txn_out.details.execution_fee;
204 0 : msg->txn_exec->priority_fee = ctx->txn_out.details.priority_fee;
205 0 : msg->txn_exec->tips = ctx->txn_out.details.tips;
206 0 : msg->txn_exec->slot = ctx->slot;
207 0 : msg->txn_exec->bank_seq = ctx->bank->bank_seq;
208 0 : msg->txn_exec->start_shred_idx = ctx->txn_in.txn->start_shred_idx;
209 0 : msg->txn_exec->end_shred_idx = ctx->txn_in.txn->end_shred_idx;
210 :
211 : /* Leave the writable ALT accounts in this tile's result buffer if
212 : replay asked for them. txn_out.accounts.cnt only exceeds
213 : acct_addr_cnt once the ALTs expanded successfully, and the expanded
214 : keys list the writable accounts before the read-only ones. */
215 0 : ulong alt_writable_cnt = 0UL;
216 0 : fd_txn_t const * txn = TXN( ctx->txn_in.txn );
217 0 : if( FD_UNLIKELY( ctx->want_alts && txn->transaction_version==FD_TXN_V0 ) ) {
218 0 : ulong acct_addr_cnt = txn->acct_addr_cnt;
219 0 : ulong adtl_writable_cnt = txn->addr_table_adtl_writable_cnt;
220 0 : if( FD_LIKELY( ctx->txn_out.accounts.cnt>=acct_addr_cnt+adtl_writable_cnt ) ) {
221 0 : FD_TEST( adtl_writable_cnt<=FD_TXN_ACCT_ADDR_MAX-1UL );
222 0 : fd_memcpy( ctx->result->alt_writable, &ctx->txn_out.accounts.keys[ acct_addr_cnt ], adtl_writable_cnt*sizeof(fd_pubkey_t) );
223 0 : alt_writable_cnt = adtl_writable_cnt;
224 0 : }
225 0 : }
226 0 : msg->txn_exec->alt_writable_cnt = (uchar)alt_writable_cnt;
227 0 : ctx->want_alts = 0;
228 :
229 0 : if( FD_UNLIKELY( !msg->txn_exec->is_committable ) ) {
230 0 : uchar * signature = (uchar *)ctx->txn_in.txn->payload + TXN( ctx->txn_in.txn )->signature_off;
231 0 : FD_BASE58_ENCODE_64_BYTES( signature, signature_b58 );
232 0 : FD_LOG_WARNING(( "block marked dead (slot=%lu) because of invalid transaction (signature=%s) (txn_err=%d)", ctx->slot, signature_b58, ctx->txn_out.err.txn_err ));
233 0 : }
234 :
235 0 : fd_stem_publish( stem, ctx->execrp_replay_out->idx, (FD_EXECRP_TT_TXN_EXEC<<32)|ctx->tile_idx, ctx->execrp_replay_out->chunk, sizeof(*msg), 0UL, ctx->dispatch_time_comp, fd_frag_meta_ts_comp( fd_tickcount() ) );
236 :
237 0 : ctx->execrp_replay_out->chunk = fd_dcache_compact_next( ctx->execrp_replay_out->chunk, sizeof(*msg), ctx->execrp_replay_out->chunk0, ctx->execrp_replay_out->wmark );
238 0 : }
239 :
240 : static inline void
241 : after_credit( fd_execrp_tile_t * ctx,
242 : fd_stem_context_t * stem,
243 : int * opt_poll_in,
244 0 : int * charge_busy ) {
245 0 : (void)stem; (void)opt_poll_in; (void)charge_busy;
246 0 : fd_startup_gate_idle( ctx->startup_gate );
247 0 : }
248 :
249 : static inline int
250 : returnable_frag( fd_execrp_tile_t * ctx,
251 : ulong in_idx,
252 : ulong seq,
253 : ulong sig,
254 : ulong chunk,
255 : ulong sz,
256 : ulong ctl FD_PARAM_UNUSED,
257 : ulong tsorig FD_PARAM_UNUSED,
258 : ulong tspub,
259 0 : fd_stem_context_t * stem ) {
260 0 : fd_startup_gate_busy( ctx->startup_gate );
261 :
262 0 : FD_TEST( (sig&0xFFFFFFFFUL)==ctx->tile_idx );
263 :
264 0 : FD_MGAUGE_SET( EXECRP, IS_PROCESSING, 1UL );
265 :
266 0 : if( FD_LIKELY( in_idx==ctx->replay_in->idx ) ) {
267 0 : if( FD_UNLIKELY( chunk < ctx->replay_in->chunk0 || chunk > ctx->replay_in->wmark ) ) {
268 0 : FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->replay_in->chunk0, ctx->replay_in->wmark ));
269 0 : }
270 0 : switch( sig>>32 ) {
271 0 : case FD_EXECRP_TT_TXN_EXEC: {
272 : /* Execute. */
273 0 : fd_execrp_txn_exec_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
274 0 : ctx->bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
275 0 : FD_TEST( ctx->bank );
276 0 : ctx->txn_in.txn = msg->txn;
277 0 : ctx->want_alts = msg->want_alts;
278 0 : memcpy( ctx->txn_in.fec_merkle_root, msg->fec_merkle_root, 32UL );
279 0 : ctx->txn_in.index_in_slot = msg->index_in_slot;
280 :
281 : /* Set the capture txn index from the message so account updates
282 : during commit are recorded with the correct transaction index. */
283 0 : if( FD_UNLIKELY( ctx->capture_ctx ) ) {
284 0 : ctx->capture_ctx->current_txn_idx = msg->capture_txn_idx;
285 0 : }
286 :
287 0 : fd_runtime_prepare_and_execute_txn( ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
288 :
289 0 : ctx->metrics.txn_result[ fd_execle_err_from_runtime_err( ctx->txn_out.err.txn_err ) ]++;
290 0 : ctx->metrics.txn_version[ fd_execle_version_from_txn( TXN( ctx->txn_in.txn ) ) ]++;
291 :
292 0 : if( FD_LIKELY( ctx->txn_out.err.is_committable ) ) {
293 0 : fd_runtime_commit_txn( ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
294 0 : } else {
295 0 : fd_runtime_cancel_txn( ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
296 0 : }
297 :
298 0 : long const txn_end_ticks = fd_tickcount();
299 :
300 : /* Notify replay. */
301 0 : ctx->txn_idx = msg->txn_idx;
302 0 : ctx->dispatch_time_comp = tspub;
303 0 : ctx->slot = ctx->bank->f.slot;
304 0 : publish_txn_finalized_msg( ctx, stem, txn_end_ticks );
305 :
306 : /* Update metrics */
307 0 : ulong load_start_ticks_dt = fd_ulong_if( ctx->txn_out.details.check_start_ticks==LONG_MAX || ctx->txn_out.details.load_start_ticks==LONG_MAX, 0UL, (ulong)( ctx->txn_out.details.check_start_ticks - ctx->txn_out.details.load_start_ticks ) );
308 0 : ulong check_start_ticks_dt = fd_ulong_if( ctx->txn_out.details.exec_start_ticks==LONG_MAX || ctx->txn_out.details.check_start_ticks==LONG_MAX, 0UL, (ulong)( ctx->txn_out.details.exec_start_ticks - ctx->txn_out.details.check_start_ticks ) );
309 0 : ulong exec_start_ticks_dt = fd_ulong_if( ctx->txn_out.details.commit_start_ticks==LONG_MAX || ctx->txn_out.details.exec_start_ticks==LONG_MAX, 0UL, (ulong)( ctx->txn_out.details.commit_start_ticks - ctx->txn_out.details.exec_start_ticks ) );
310 0 : ulong commit_ticks_dt = fd_ulong_if( txn_end_ticks==LONG_MAX || ctx->txn_out.details.commit_start_ticks==LONG_MAX, 0UL, (ulong)( txn_end_ticks - ctx->txn_out.details.commit_start_ticks ) );
311 :
312 0 : ctx->metrics.txn_load_cum_ticks += load_start_ticks_dt;
313 0 : ctx->metrics.txn_check_cum_ticks += check_start_ticks_dt;
314 0 : ctx->metrics.txn_exec_cum_ticks += exec_start_ticks_dt;
315 0 : ctx->metrics.txn_commit_cum_ticks += commit_ticks_dt;
316 :
317 0 : break;
318 0 : }
319 0 : case FD_EXECRP_TT_TXN_SIGVERIFY: {
320 0 : fd_execrp_txn_sigverify_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
321 0 : FD_CHECK_CRIT( msg->cnt && msg->cnt<=FD_EXECRP_SIGVERIFY_SIG_PARA, "invalid sigverify batch" );
322 :
323 0 : fd_txn_p_t const * txns[ FD_EXECRP_SIGVERIFY_SIG_PARA ];
324 0 : fd_execrp_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
325 0 : ulong sig_cnt = 0UL;
326 0 : for( ulong i=0UL; i<msg->cnt; i++ ) {
327 0 : txns[ i ] = msg->txn+i;
328 0 : sig_cnt += TXN( txns[ i ] )->signature_cnt;
329 0 : out_msg->txn_sigverify->txn_idx[ i ] = msg->txn_idx[ i ];
330 0 : }
331 0 : FD_CHECK_CRIT( sig_cnt && sig_cnt<=FD_ED25519_VERIFIER_SIG_MAX, "invalid sigverify batch" );
332 0 : ctx->metrics.sigverify_cnt += sig_cnt;
333 0 : out_msg->bank_idx = msg->bank_idx;
334 0 : out_msg->txn_sigverify->cnt = msg->cnt;
335 0 : out_msg->txn_sigverify->err = fd_executor_txn_verify( ctx->verifier, txns, msg->cnt )!=FD_RUNTIME_EXECUTE_SUCCESS;
336 0 : fd_stem_publish( stem, ctx->execrp_replay_out->idx, (FD_EXECRP_TT_TXN_SIGVERIFY<<32)|ctx->tile_idx, ctx->execrp_replay_out->chunk, sizeof(*out_msg), 0UL, 0UL, 0UL );
337 0 : ctx->execrp_replay_out->chunk = fd_dcache_compact_next( ctx->execrp_replay_out->chunk, sizeof(*out_msg), ctx->execrp_replay_out->chunk0, ctx->execrp_replay_out->wmark );
338 0 : break;
339 0 : }
340 0 : case FD_EXECRP_TT_POH_HASH: {
341 0 : fd_execrp_poh_hash_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
342 0 : fd_execrp_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
343 0 : FD_CHECK_CRIT( msg->cnt && msg->cnt<=FD_EXECRP_POH_PARA && msg->hashcnt<=1UL, "invalid poh batch" );
344 0 : out_msg->bank_idx = msg->bank_idx;
345 0 : out_msg->poh_hash->cnt = msg->cnt;
346 0 : ctx->metrics.poh_hash_cnt += msg->hashcnt*msg->cnt;
347 0 : for( ulong i=0UL; i<msg->cnt; i++ ) {
348 0 : if( msg->hashcnt ) fd_sha256_hash( msg->hash+i, sizeof(fd_hash_t), out_msg->poh_hash->hash+i );
349 0 : else out_msg->poh_hash->hash[ i ] = msg->hash[ i ];
350 0 : }
351 0 : fd_stem_publish( stem, ctx->execrp_replay_out->idx, (FD_EXECRP_TT_POH_HASH<<32)|ctx->tile_idx, ctx->execrp_replay_out->chunk, sizeof(*out_msg), 0UL, 0UL, 0UL );
352 0 : ctx->execrp_replay_out->chunk = fd_dcache_compact_next( ctx->execrp_replay_out->chunk, sizeof(*out_msg), ctx->execrp_replay_out->chunk0, ctx->execrp_replay_out->wmark );
353 0 : break;
354 0 : }
355 0 : case FD_EXECRP_TT_CERT_VERIFY: {
356 0 : fd_execrp_cert_verify_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
357 0 : fd_bank_t const * bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
358 0 : FD_TEST( bank );
359 0 : fd_execrp_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
360 0 : out_msg->bank_idx = msg->bank_idx;
361 0 : out_msg->cert_verify->err = !!fd_alpenglow_cert_verify( bank, msg->cert, msg->tag, msg->quorum, msg->shred_version, NULL, msg->has_hm ? &msg->hm : NULL, &out_msg->cert_verify->hm );
362 0 : out_msg->cert_verify->has_hm = !msg->has_hm && !out_msg->cert_verify->err; /* hashed here */
363 0 : fd_stem_publish( stem, ctx->execrp_replay_out->idx, (FD_EXECRP_TT_CERT_VERIFY<<32)|ctx->tile_idx, ctx->execrp_replay_out->chunk, sizeof(*out_msg), 0UL, 0UL, 0UL );
364 0 : ctx->execrp_replay_out->chunk = fd_dcache_compact_next( ctx->execrp_replay_out->chunk, sizeof(*out_msg), ctx->execrp_replay_out->chunk0, ctx->execrp_replay_out->wmark );
365 0 : break;
366 0 : }
367 0 : case FD_EXECRP_TT_REWARDS: {
368 0 : fd_execrp_rewards_msg_t const * msg = fd_chunk_to_laddr_const( ctx->replay_in->mem, chunk );
369 0 : fd_bank_t * bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
370 0 : FD_TEST( bank );
371 0 : FD_CHECK_CRIT( msg->slice_cnt && msg->slice_idx<msg->slice_cnt, "invalid rewards slice" );
372 0 : fd_execrp_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
373 0 : out_msg->bank_idx = msg->bank_idx;
374 0 : out_msg->rewards->leader_credits = 0UL;
375 0 : fd_lthash_zero( &ctx->result->lthash );
376 0 : out_msg->rewards->err = !!fd_alpenglow_rewards_apply_slice( bank, ctx->accdb, NULL, ctx->footer_cache, &msg->plan, msg->slice_idx, msg->slice_cnt, &ctx->result->lthash, &out_msg->rewards->leader_credits );
377 0 : fd_stem_publish( stem, ctx->execrp_replay_out->idx, (FD_EXECRP_TT_REWARDS<<32)|ctx->tile_idx, ctx->execrp_replay_out->chunk, sizeof(*out_msg), 0UL, 0UL, 0UL );
378 0 : ctx->execrp_replay_out->chunk = fd_dcache_compact_next( ctx->execrp_replay_out->chunk, sizeof(*out_msg), ctx->execrp_replay_out->chunk0, ctx->execrp_replay_out->wmark );
379 0 : break;
380 0 : }
381 0 : case FD_EXECRP_TT_LTHASH_SUB:
382 0 : case FD_EXECRP_TT_LTHASH_ADD: {
383 : /* Hash and sum. Replay will fold the sum into the bank. */
384 0 : ulong kind = sig>>32;
385 0 : fd_execrp_lthash_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
386 0 : FD_CHECK_CRIT( msg->cnt && msg->cnt<=FD_EXECRP_LTHASH_BATCH_MAX, "invalid lthash batch" );
387 0 : fd_bank_t * bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
388 0 : FD_TEST( bank );
389 0 : fd_accdb_fork_id_t fork_id = kind==FD_EXECRP_TT_LTHASH_SUB ? bank->parent_accdb_fork_id : bank->accdb_fork_id;
390 0 : FD_TEST( fork_id.val!=USHORT_MAX );
391 0 : fd_execrp_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
392 0 : out_msg->bank_idx = msg->bank_idx;
393 0 : out_msg->lthash->cnt = msg->cnt;
394 0 : fd_lthash_value_t * sum = &ctx->result->lthash;
395 0 : fd_lthash_zero( sum );
396 0 : for( ulong i=0UL; i<msg->cnt; i+=FD_BLAKE3_XN_MAX ) {
397 0 : ulong acc_cnt = fd_ulong_min( msg->cnt-i, FD_BLAKE3_XN_MAX );
398 0 : fd_acc_t acc [ FD_BLAKE3_XN_MAX ];
399 0 : uchar const * pubkey [ FD_BLAKE3_XN_MAX ];
400 0 : int writable [ FD_BLAKE3_XN_MAX ] = { 0 };
401 0 : uchar const * owner [ FD_BLAKE3_XN_MAX ];
402 0 : ulong lamports [ FD_BLAKE3_XN_MAX ];
403 0 : int executable[ FD_BLAKE3_XN_MAX ];
404 0 : uchar const * data [ FD_BLAKE3_XN_MAX ];
405 0 : ulong data_len [ FD_BLAKE3_XN_MAX ];
406 0 : fd_lthash_value_t hash [ FD_BLAKE3_XN_MAX ];
407 0 : fd_lthash_value_t * hash_out [ FD_BLAKE3_XN_MAX ];
408 0 : for( ulong j=0UL; j<acc_cnt; j++ ) pubkey[ j ] = msg->acct[ i+j ].b;
409 0 : fd_accdb_acquire( ctx->accdb, fork_id, acc_cnt, pubkey, writable, acc );
410 0 : for( ulong j=0UL; j<acc_cnt; j++ ) {
411 0 : owner [ j ] = acc[ j ].owner;
412 0 : lamports [ j ] = acc[ j ].lamports;
413 0 : executable[ j ] = acc[ j ].executable;
414 0 : data [ j ] = acc[ j ].data;
415 0 : data_len [ j ] = acc[ j ].data_len;
416 0 : hash_out [ j ] = hash+j;
417 0 : }
418 0 : fd_hashes_account_lthash_xn( acc_cnt, pubkey, owner, lamports, executable, data, data_len, hash_out );
419 0 : fd_accdb_release( ctx->accdb, acc_cnt, acc );
420 0 : for( ulong j=0UL; j<acc_cnt; j++ ) fd_lthash_add( sum, hash+j );
421 0 : }
422 0 : fd_stem_publish( stem, ctx->execrp_replay_out->idx, (kind<<32)|ctx->tile_idx, ctx->execrp_replay_out->chunk, sizeof(*out_msg), 0UL, 0UL, 0UL );
423 0 : ctx->execrp_replay_out->chunk = fd_dcache_compact_next( ctx->execrp_replay_out->chunk, sizeof(*out_msg), ctx->execrp_replay_out->chunk0, ctx->execrp_replay_out->wmark );
424 0 : break;
425 0 : }
426 0 : default: FD_LOG_CRIT(( "unexpected signature %lu", sig ));
427 0 : }
428 0 : } else FD_LOG_CRIT(( "invalid in_idx %lu", in_idx ));
429 :
430 0 : FD_MGAUGE_SET( EXECRP, IS_PROCESSING, 0UL );
431 :
432 0 : fd_stem_credit_return( stem, in_idx, seq+1UL );
433 0 : return 0;
434 0 : }
435 :
436 : extern FD_TL int fd_wksp_oom_silent;
437 :
438 : static void
439 : privileged_init( fd_topo_t const * topo,
440 0 : fd_topo_tile_t const * tile ) {
441 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
442 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
443 0 : fd_execrp_tile_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_execrp_tile_t), sizeof(fd_execrp_tile_t) );
444 0 : FD_TEST( fd_rng_secure( &ctx->ed25519_cache_seed, sizeof(ulong) ) );
445 0 : }
446 :
447 : static void
448 : unprivileged_init( fd_topo_t const * topo,
449 0 : fd_topo_tile_t const * tile ) {
450 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
451 :
452 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
453 0 : fd_execrp_tile_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_execrp_tile_t), sizeof(fd_execrp_tile_t) );
454 0 : void * _txncache = FD_SCRATCH_ALLOC_APPEND( l, fd_txncache_align(), fd_txncache_footprint( tile->execrp.max_live_slots ) );
455 0 : void * _accdb = FD_SCRATCH_ALLOC_APPEND( l, fd_accdb_align(), fd_accdb_footprint( tile->execrp.max_live_slots, 0 ) );
456 0 : uchar * pc_scratch = FD_SCRATCH_ALLOC_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN, FD_PROGCACHE_SCRATCH_FOOTPRINT );
457 0 : void * _verifier = FD_SCRATCH_ALLOC_APPEND( l, fd_ed25519_verifier_align(), fd_ed25519_verifier_footprint( FD_ED25519_VERIFIER_TXN_CACHE ) );
458 0 : void * _bpf_frames = FD_SCRATCH_ALLOC_APPEND( l, fd_bpf_frames_align(), fd_bpf_frames_footprint() );
459 :
460 0 : void * _capture_ctx = NULL;
461 0 : if( FD_UNLIKELY( strlen( tile->execrp.solcap_capture ) ) ) {
462 0 : _capture_ctx = FD_SCRATCH_ALLOC_APPEND( l, fd_capture_ctx_align(), fd_capture_ctx_footprint() );
463 0 : }
464 :
465 0 : void * _dump_proto_ctx = NULL;
466 0 : void * _txn_dump_ctx = NULL;
467 0 : void * _dumping = NULL;
468 0 : if( FD_UNLIKELY( strlen( tile->execrp.dump_proto_dir ) ) ) {
469 0 : _dump_proto_ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_dump_proto_ctx_t), sizeof(fd_dump_proto_ctx_t) );
470 0 : _txn_dump_ctx = FD_SCRATCH_ALLOC_APPEND( l, fd_txn_dump_context_align(), fd_txn_dump_context_footprint() );
471 0 : if( FD_UNLIKELY( tile->execrp.dump_instr_to_pb || tile->execrp.dump_syscall_to_pb || tile->execrp.dump_txn_to_pb ) ) {
472 0 : _dumping = FD_SCRATCH_ALLOC_APPEND( l, FD_SPAD_ALIGN, FD_SPAD_FOOTPRINT( 1UL<<28UL ) );
473 0 : }
474 0 : }
475 :
476 0 : ctx->verifier = fd_ed25519_verifier_join( fd_ed25519_verifier_new( _verifier, FD_ED25519_VERIFIER_TXN_CACHE, ctx->ed25519_cache_seed ) );
477 0 : FD_TEST( ctx->verifier );
478 :
479 0 : ulong footer_cache_obj_id = fd_pod_query_ulong( topo->props, "footer_cache", ULONG_MAX );
480 0 : ctx->footer_cache = footer_cache_obj_id!=ULONG_MAX ? fd_footer_cache_join( fd_topo_obj_laddr( topo, footer_cache_obj_id ) ) : NULL;
481 0 : FD_TEST( footer_cache_obj_id==ULONG_MAX || ctx->footer_cache );
482 :
483 0 : ctx->txn_in.bundle.is_bundle = 0;
484 0 : ctx->tile_idx = tile->kind_id;
485 :
486 0 : ulong banks_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "banks" );
487 0 : FD_TEST( banks_obj_id!=ULONG_MAX );
488 :
489 0 : ctx->banks = fd_banks_join( fd_topo_obj_laddr( topo, banks_obj_id ) );
490 0 : FD_TEST( ctx->banks );
491 :
492 0 : ulong result_obj_id = fd_pod_query_ulong( topo->props, "execrp_result", ULONG_MAX );
493 0 : FD_TEST( result_obj_id!=ULONG_MAX );
494 0 : ctx->result = (fd_execrp_result_t *)fd_topo_obj_laddr( topo, result_obj_id )+tile->kind_id;
495 :
496 0 : FD_TEST( fd_progcache_join( ctx->progcache, fd_topo_obj_laddr( topo, tile->execrp.progcache_obj_id ), pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT ) );
497 0 : FD_TEST( (ctx->bpf_frames = fd_bpf_frames_join( _bpf_frames, fd_topo_obj_laddr( topo, tile->execrp.bpf_frames_obj_id ) )) );
498 :
499 0 : void * _txncache_shmem = fd_topo_obj_laddr( topo, tile->execrp.txncache_obj_id );
500 0 : fd_txncache_shmem_t * txncache_shmem = fd_txncache_shmem_join( _txncache_shmem );
501 0 : FD_TEST( txncache_shmem );
502 0 : ctx->txncache = fd_txncache_join( fd_txncache_new( _txncache, txncache_shmem, FD_TXNCACHE_FD ) );
503 0 : FD_TEST( ctx->txncache );
504 0 : fd_txncache_join_metrics_t * txncache_metrics = fd_txncache_join_metrics( ctx->txncache );
505 0 : fd_histf_join( fd_metrics_histf_new_ns( txncache_metrics->query_ticks, FD_MHIST_EDGES_NS( EXECRP, TXNCACHE_QUERY_DURATION_NANOS ) ) );
506 0 : fd_histf_join( fd_metrics_histf_new_ns( txncache_metrics->insert_ticks, FD_MHIST_EDGES_NS( EXECRP, TXNCACHE_INSERT_DURATION_NANOS ) ) );
507 :
508 0 : void * _accdb_shmem = fd_topo_obj_laddr( topo, tile->execrp.accdb_obj_id );
509 0 : fd_accdb_shmem_t * accdb_shmem = fd_accdb_shmem_join( _accdb_shmem );
510 0 : FD_TEST( accdb_shmem );
511 0 : fd_sleep_t * accdb_sleep = topo->sleep_obj_id!=ULONG_MAX ? fd_sleep_join( fd_topo_obj_laddr( topo, topo->sleep_obj_id ) ) : NULL;
512 0 : ctx->accdb = fd_accdb_join( fd_accdb_new( _accdb, accdb_shmem, FD_ACCDB_FD_RW, 0UL, NULL, accdb_sleep, fd_topo_find_tile( topo, "accdb", 0UL ), 0 ) );
513 0 : FD_TEST( ctx->accdb );
514 :
515 : /* First find and setup the in-link from replay to exec. */
516 0 : ctx->replay_in->idx = fd_topo_find_tile_in_link( topo, tile, "replay_execrp", ctx->tile_idx );
517 0 : FD_TEST( ctx->replay_in->idx!=ULONG_MAX );
518 0 : fd_topo_link_t const * replay_in_link = &topo->links[ tile->in_link_id[ ctx->replay_in->idx ] ];
519 0 : ctx->replay_in->mem = topo->workspaces[ topo->objs[ replay_in_link->dcache_obj_id ].wksp_id ].wksp;
520 0 : ctx->replay_in->chunk0 = fd_dcache_compact_chunk0( ctx->replay_in->mem, replay_in_link->dcache );
521 0 : ctx->replay_in->wmark = fd_dcache_compact_wmark( ctx->replay_in->mem, replay_in_link->dcache, replay_in_link->mtu );
522 0 : ctx->replay_in->chunk = ctx->replay_in->chunk0;
523 :
524 0 : ctx->execrp_replay_out->idx = fd_topo_find_tile_out_link( topo, tile, "execrp_replay", ctx->tile_idx );
525 0 : if( FD_LIKELY( ctx->execrp_replay_out->idx!=ULONG_MAX ) ) {
526 0 : fd_topo_link_t const * execrp_replay_link = &topo->links[ tile->out_link_id[ ctx->execrp_replay_out->idx ] ];
527 0 : ctx->execrp_replay_out->mem = topo->workspaces[ topo->objs[ execrp_replay_link->dcache_obj_id ].wksp_id ].wksp;
528 0 : ctx->execrp_replay_out->chunk0 = fd_dcache_compact_chunk0( ctx->execrp_replay_out->mem, execrp_replay_link->dcache );
529 0 : ctx->execrp_replay_out->wmark = fd_dcache_compact_wmark( ctx->execrp_replay_out->mem, execrp_replay_link->dcache, execrp_replay_link->mtu );
530 0 : ctx->execrp_replay_out->chunk = ctx->execrp_replay_out->chunk0;
531 0 : }
532 :
533 0 : ctx->capture_ctx = NULL;
534 0 : if( FD_UNLIKELY( strlen( tile->execrp.solcap_capture ) ) ) {
535 0 : ctx->capture_ctx = fd_capture_ctx_join( fd_capture_ctx_new( _capture_ctx ) );
536 0 : ctx->capture_ctx->solcap_start_slot = tile->execrp.capture_start_slot;
537 :
538 0 : ulong tile_idx = tile->kind_id;
539 0 : ulong idx = fd_topo_find_tile_out_link( topo, tile, "cap_execrp", tile_idx );
540 0 : FD_TEST( idx!=ULONG_MAX );
541 :
542 0 : fd_topo_link_t const * link = &topo->links[ tile->out_link_id[ idx ] ];
543 0 : fd_capture_link_buf_t * cap_execrp_out = ctx->cap_execrp_out;
544 0 : cap_execrp_out->base.vt = &fd_capture_link_buf_vt;
545 0 : cap_execrp_out->idx = idx;
546 0 : cap_execrp_out->mem = topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ].wksp;
547 0 : cap_execrp_out->chunk0 = fd_dcache_compact_chunk0( cap_execrp_out->mem, link->dcache );
548 0 : cap_execrp_out->wmark = fd_dcache_compact_wmark( cap_execrp_out->mem, link->dcache, link->mtu );
549 0 : cap_execrp_out->chunk = cap_execrp_out->chunk0;
550 0 : cap_execrp_out->mcache = link->mcache;
551 0 : cap_execrp_out->depth = fd_mcache_depth( link->mcache );
552 0 : cap_execrp_out->seq = 0UL;
553 :
554 0 : ulong consumer_tile_idx = fd_topo_find_tile(topo, "solcap", 0UL);
555 0 : fd_topo_tile_t const * consumer_tile = &topo->tiles[ consumer_tile_idx ];
556 0 : cap_execrp_out->fseq = NULL;
557 0 : for( ulong j = 0UL; j < consumer_tile->in_cnt; j++ ) {
558 0 : if( FD_UNLIKELY( consumer_tile->in_link_id[ j ] == link->id ) ) {
559 0 : cap_execrp_out->fseq = fd_fseq_join( fd_topo_obj_laddr( topo, consumer_tile->in_link_fseq_obj_id[ j ] ) );
560 0 : FD_TEST( cap_execrp_out->fseq );
561 0 : break;
562 0 : }
563 0 : }
564 :
565 0 : ctx->capture_ctx->capture_solcap = 1;
566 0 : ctx->capture_ctx->capctx_type.buf = cap_execrp_out;
567 0 : ctx->capture_ctx->capture_link = &cap_execrp_out->base;
568 0 : }
569 :
570 0 : ctx->dump_proto_ctx = NULL;
571 0 : if( FD_UNLIKELY( strlen( tile->execrp.dump_proto_dir ) ) ) {
572 0 : ctx->dump_proto_ctx = _dump_proto_ctx;
573 :
574 : /* General dumping config */
575 0 : ctx->dump_proto_ctx->dump_proto_output_dir = tile->execrp.dump_proto_dir;
576 0 : ctx->dump_proto_ctx->dump_proto_start_slot = tile->execrp.capture_start_slot;
577 :
578 : /* Syscall dumping config */
579 0 : ctx->dump_proto_ctx->dump_syscall_to_pb = !!tile->execrp.dump_syscall_to_pb;
580 0 : ctx->dump_proto_ctx->dump_syscall_name_filter = tile->execrp.dump_syscall_name_filter;
581 :
582 : /* Instruction dumping config */
583 0 : ctx->dump_proto_ctx->dump_instr_to_pb = !!tile->execrp.dump_instr_to_pb;
584 0 : ctx->dump_proto_ctx->has_dump_instr_program_id_filter = !!strlen(tile->execrp.dump_instr_program_id_filter);
585 0 : if( FD_UNLIKELY( ctx->dump_proto_ctx->has_dump_instr_program_id_filter &&
586 0 : !fd_base58_decode_32( tile->execrp.dump_instr_program_id_filter, ctx->dump_proto_ctx->dump_instr_program_id_filter ) ) ) {
587 0 : FD_LOG_ERR(( "failed to parse [capture.dump_instr_program_id_filter] %s", tile->execrp.dump_instr_program_id_filter ));
588 0 : }
589 :
590 : /* Transaction dumping config */
591 0 : ctx->dump_proto_ctx->dump_txn_to_pb = !!tile->execrp.dump_txn_to_pb;
592 0 : ctx->dump_proto_ctx->dump_txn_as_fixture = !!tile->execrp.dump_txn_as_fixture;
593 :
594 0 : if( FD_UNLIKELY( ctx->dump_proto_ctx->dump_txn_as_fixture && !ctx->dump_proto_ctx->dump_txn_to_pb ) ) {
595 0 : FD_LOG_ERR(( "[capture.dump_txn_as_fixture] requires [capture.dump_txn_to_pb] to be enabled" ));
596 0 : }
597 0 : }
598 :
599 : /* Transaction dump context (for fixture dumping) */
600 0 : ctx->txn_dump_ctx = NULL;
601 0 : if( FD_UNLIKELY( ctx->dump_proto_ctx && ctx->dump_proto_ctx->dump_txn_to_pb ) ) {
602 0 : ctx->txn_dump_ctx = fd_txn_dump_context_join( fd_txn_dump_context_new( _txn_dump_ctx ) );
603 0 : }
604 :
605 0 : ctx->runtime->accdb = ctx->accdb;
606 0 : ctx->runtime->sysvar_bank_seq = 0UL;
607 0 : ctx->runtime->progcache = ctx->progcache;
608 0 : ctx->runtime->bpf_frames = ctx->bpf_frames;
609 0 : ctx->runtime->status_cache = ctx->txncache;
610 0 : memset( &ctx->runtime->log, 0, sizeof(ctx->runtime->log) );
611 0 : ctx->runtime->log.log_collector = &ctx->log_collector;
612 0 : ctx->runtime->log.dumping_mem = _dumping;
613 0 : ctx->runtime->log.tracing_mem = NULL;
614 0 : ctx->runtime->log.capture_ctx = ctx->capture_ctx;
615 0 : ctx->runtime->log.dump_proto_ctx = ctx->dump_proto_ctx;
616 0 : ctx->runtime->log.txn_dump_ctx = ctx->txn_dump_ctx;
617 0 : ctx->runtime->fuzz.enabled = 0;
618 0 : ctx->runtime->fuzz.reclaim_accounts = 0;
619 0 : ctx->runtime->accounts.executable_cnt = 0UL;
620 0 : ctx->runtime->accounts.account_cnt = 0UL;
621 :
622 0 : memset( &ctx->metrics, 0, sizeof(ctx->metrics) );
623 0 : memset( &ctx->runtime->metrics, 0, sizeof(ctx->runtime->metrics) );
624 :
625 0 : fd_wksp_oom_silent = 1;
626 :
627 0 : ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
628 0 : if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
629 0 : FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
630 :
631 0 : fd_startup_gate_init( ctx->startup_gate, topo, tile->in_cnt );
632 0 : }
633 :
634 : static ulong
635 : populate_allowed_seccomp( fd_topo_t const * topo FD_PARAM_UNUSED,
636 : fd_topo_tile_t const * tile FD_PARAM_UNUSED,
637 : ulong out_cnt,
638 0 : struct sock_filter * out ) {
639 0 : populate_sock_filter_policy_fd_execrp_tile( out_cnt, out, (uint)fd_log_private_logfile_fd(), (uint)FD_ACCDB_FD_RW, FD_STAKE_DELEGATIONS_FD, FD_VOTE_STAKES_FD, (uint)FD_TXNCACHE_FD );
640 0 : return sock_filter_policy_fd_execrp_tile_instr_cnt;
641 0 : }
642 :
643 : static ulong
644 : populate_allowed_fds( fd_topo_t const * topo FD_PARAM_UNUSED,
645 : fd_topo_tile_t const * tile FD_PARAM_UNUSED,
646 : ulong out_fds_cnt,
647 0 : int * out_fds ) {
648 :
649 0 : if( FD_UNLIKELY( out_fds_cnt<6UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
650 :
651 0 : ulong out_cnt = 0UL;
652 0 : out_fds[ out_cnt++ ] = 2; /* stderr */
653 0 : if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) ) {
654 0 : out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
655 0 : }
656 0 : out_fds[ out_cnt++ ] = FD_ACCDB_FD_RW; /* accounts db */
657 0 : out_fds[ out_cnt++ ] = FD_STAKE_DELEGATIONS_FD; /* stake delegation disk spill */
658 0 : out_fds[ out_cnt++ ] = FD_VOTE_STAKES_FD; /* vote stakes disk spill */
659 0 : out_fds[ out_cnt++ ] = FD_TXNCACHE_FD; /* transaction cache spill */
660 :
661 0 : return out_cnt;
662 0 : }
663 :
664 0 : #define STEM_BURST (1UL)
665 :
666 : /* replay_execrp credits are returned per frag, so housekeeping only
667 : needs to keep up with the execrp_replay out link. */
668 0 : #define STEM_LAZY (1000000UL)
669 :
670 0 : #define STEM_CALLBACK_CONTEXT_TYPE fd_execrp_tile_t
671 0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_execrp_tile_t)
672 :
673 0 : #define STEM_CALLBACK_METRICS_WRITE metrics_write
674 0 : #define STEM_CALLBACK_AFTER_CREDIT after_credit
675 0 : #define STEM_CALLBACK_RETURNABLE_FRAG returnable_frag
676 :
677 : #include "../../disco/stem/fd_stem.c"
678 :
679 : static ulong
680 0 : max_event_sz( fd_topo_tile_t const * tile ) {
681 : /* execrp emits accdb_partition_added, plus runtime_txn when diffs are on. */
682 0 : ulong sz = sizeof(fd_event_accdb_partition_added_t);
683 0 : if( tile->execrp.report_runtime_diffs && sizeof(fd_event_runtime_txn_t)>sz ) sz = sizeof(fd_event_runtime_txn_t);
684 0 : return sz;
685 0 : }
686 :
687 : fd_topo_run_tile_t fd_tile_execrp = {
688 : .name = "execrp",
689 : .max_event_sz = max_event_sz,
690 : .populate_allowed_seccomp = populate_allowed_seccomp,
691 : .populate_allowed_fds = populate_allowed_fds,
692 : .scratch_align = scratch_align,
693 : .scratch_footprint = scratch_footprint,
694 : .privileged_init = privileged_init,
695 : .unprivileged_init = unprivileged_init,
696 : .run = stem_run,
697 : };
|