LCOV - code coverage report
Current view: top level - discof/execrp - fd_execrp_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 441 0.0 %
Date: 2026-11-11 12:40:43 Functions: 0 22 0.0 %

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

Generated by: LCOV version 1.14