LCOV - code coverage report
Current view: top level - discof/execrp - fd_execrp_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 340 0.0 %
Date: 2026-08-13 04:56:22 Functions: 0 20 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 "../../choreo/tower/fd_tower_serdes.h"
       6             : #include "../../discof/fd_startup.h"
       7             : #include "../../discof/replay/fd_execrp.h"
       8             : #include "../../flamenco/runtime/fd_bank.h"
       9             : #include "../../flamenco/runtime/fd_txncache.h"
      10             : #include "../../flamenco/runtime/fd_runtime.h"
      11             : #include "../../flamenco/runtime/fd_executor.h"
      12             : #include "../../flamenco/runtime/tests/fd_dump_pb.h"
      13             : #include "../../flamenco/progcache/fd_progcache_user.h"
      14             : #include "../../flamenco/log_collector/fd_log_collector_base.h"
      15             : #include "../../disco/metrics/fd_metrics.h"
      16             : #include "../../disco/events/generated/fd_event_gen.h"
      17             : #include "../../flamenco/events/fd_event_runtime.h"
      18             : 
      19             : #include <time.h>
      20             : #include "generated/fd_execrp_tile_seccomp.h"
      21             : 
      22             : /* The exec tile is responsible for executing single transactions.  The
      23             :    tile receives a parsed transaction (fd_txn_p_t) and an identifier to
      24             :    which bank to execute against (index into the bank pool).  With this,
      25             :    the exec tile is able to identify the correct bank and accounts
      26             :    database fork to execute the transaction against.  The exec tile then
      27             :    commits the results of the transaction to the accounts db and makes
      28             :    any necessary updates to the bank. */
      29             : 
      30             : typedef struct link_ctx {
      31             :   ulong       idx;
      32             :   fd_wksp_t * mem;
      33             :   ulong       chunk;
      34             :   ulong       chunk0;
      35             :   ulong       wmark;
      36             : } link_ctx_t;
      37             : 
      38             : struct fd_execrp_tile {
      39             :   ulong tile_idx;
      40             : 
      41             :   fd_startup_gate_t startup_gate[1];
      42             : 
      43             :   /* link-related data structures. */
      44             :   link_ctx_t            replay_in[ 1 ];
      45             :   link_ctx_t            execrp_replay_out[ 1 ]; /* TODO: Remove with solcap v2 */
      46             : 
      47             :   fd_sha512_t           sha_mem[ FD_TXN_SIG_MAX ];
      48             :   fd_sha512_t *         sha_lj[  FD_TXN_SIG_MAX ];
      49             : 
      50             :   /* Capture context for debugging runtime execution. */
      51             :   fd_capture_ctx_t *    capture_ctx;
      52             :   fd_capture_link_buf_t cap_execrp_out[1];
      53             : 
      54             :   /* Protobuf dumping context for debugging runtime execution and
      55             :      collecting seed corpora. */
      56             :   fd_dump_proto_ctx_t * dump_proto_ctx;
      57             :   fd_txn_dump_ctx_t *   txn_dump_ctx;
      58             : 
      59             :   fd_banks_t *    banks;
      60             :   fd_bank_t *     bank;
      61             :   fd_accdb_t *    accdb;
      62             :   fd_txncache_t * txncache;
      63             :   fd_progcache_t  progcache[1];
      64             : 
      65             :   ulong txn_idx;
      66             :   ulong slot;
      67             :   ulong dispatch_time_comp;
      68             : 
      69             :   fd_log_collector_t log_collector;
      70             : 
      71             :   fd_txn_in_t  txn_in;
      72             :   fd_txn_out_t txn_out;
      73             : 
      74             :   fd_runtime_t runtime[1];
      75             : 
      76             :   struct {
      77             :     ulong sigverify_cnt;
      78             :     ulong poh_hash_cnt;
      79             : 
      80             :     /* Ticks spent loading txn accounts */
      81             :     ulong txn_load_cum_ticks;
      82             : 
      83             :     /* Ticks spent validating txn invariants (e.g. status cache, fee payer) */
      84             :     ulong txn_check_cum_ticks;
      85             : 
      86             :     /* Ticks spent executing a txn (includes any VM time) */
      87             :     ulong txn_exec_cum_ticks;
      88             : 
      89             :     /* Ticks spent committing a txn (database writes) */
      90             :     ulong txn_commit_cum_ticks;
      91             : 
      92             :     ulong txn_result[ FD_METRICS_ENUM_TRANSACTION_RESULT_CNT ];
      93             :   } metrics;
      94             : 
      95             :   /* If non-zero, emit one runtime_txn event per dispatched txn */
      96             :   int report_transaction_diffs;
      97             : };
      98             : 
      99             : typedef struct fd_execrp_tile fd_execrp_tile_t;
     100             : 
     101             : FD_FN_CONST static inline ulong
     102           0 : scratch_align( void ) {
     103           0 :   return 128UL;
     104           0 : }
     105             : 
     106             : FD_FN_PURE static inline ulong
     107           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
     108           0 :   ulong l = FD_LAYOUT_INIT;
     109           0 :   l = FD_LAYOUT_APPEND(   l, alignof(fd_execrp_tile_t),    sizeof(fd_execrp_tile_t)                             );
     110           0 :   l = FD_LAYOUT_APPEND(   l, fd_txncache_align(),          fd_txncache_footprint( tile->execrp.max_live_slots ) );
     111           0 :   l = FD_LAYOUT_APPEND(   l, fd_accdb_align(),             fd_accdb_footprint( tile->execrp.max_live_slots )    );
     112           0 :   l = FD_LAYOUT_APPEND(   l, FD_PROGCACHE_SCRATCH_ALIGN,   FD_PROGCACHE_SCRATCH_FOOTPRINT                       );
     113             : 
     114           0 :   if( FD_UNLIKELY( strlen( tile->execrp.solcap_capture ) ) ) {
     115           0 :     l = FD_LAYOUT_APPEND( l, fd_capture_ctx_align(),       fd_capture_ctx_footprint()                           );
     116           0 :   }
     117             : 
     118           0 :   if( FD_UNLIKELY( strlen( tile->execrp.dump_proto_dir ) ) ) {
     119           0 :     l = FD_LAYOUT_APPEND( l, alignof(fd_dump_proto_ctx_t), sizeof(fd_dump_proto_ctx_t)                          );
     120           0 :     l = FD_LAYOUT_APPEND( l, fd_txn_dump_context_align(),  fd_txn_dump_context_footprint()                      );
     121           0 :     if( FD_UNLIKELY( tile->execrp.dump_instr_to_pb || tile->execrp.dump_syscall_to_pb || tile->execrp.dump_txn_to_pb ) ) {
     122           0 :       l = FD_LAYOUT_APPEND( l, FD_SPAD_ALIGN,              FD_SPAD_FOOTPRINT( 1UL<<28UL )                       );
     123           0 :     }
     124           0 :   }
     125             : 
     126           0 :   return FD_LAYOUT_FINI(  l, scratch_align() );
     127           0 : }
     128             : 
     129             : static void
     130           0 : metrics_write( fd_execrp_tile_t * ctx ) {
     131           0 :   fd_accdb_flush_metrics( ctx->accdb );
     132             : 
     133           0 :   FD_MCNT_SET      ( EXECRP, SIGNATURE_VERIFIED,    ctx->metrics.sigverify_cnt );
     134           0 :   FD_MCNT_SET      ( EXECRP, POH_HASHED,     ctx->metrics.poh_hash_cnt  );
     135           0 :   FD_MCNT_ENUM_COPY( EXECRP, TXN_RESULT,   ctx->metrics.txn_result    );
     136             : 
     137           0 :   fd_progcache_metrics_t * pm = ctx->progcache->metrics;
     138           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_LOOKUP,                 pm->lookup_cnt     );
     139           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_HIT,                    pm->hit_cnt        );
     140           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_MISS,                   pm->miss_cnt       );
     141           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_OOM_HEAP,               pm->oom_heap_cnt   );
     142           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_OOM_DESC,               pm->oom_desc_cnt   );
     143           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_FILL,                   pm->fill_cnt       );
     144           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_FILL_BYTES,             pm->fill_tot_sz    );
     145           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_SPILL,                  pm->spill_cnt      );
     146           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_SPILL_BYTES,            pm->spill_tot_sz   );
     147           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_EVICTION,               pm->evict_cnt      );
     148           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_EVICTION_BYTES,         pm->evict_tot_sz   );
     149           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_DURATION_SECONDS,       pm->cum_pull_ticks );
     150           0 :   FD_MCNT_SET( EXECRP, PROGCACHE_LOAD_DURATION_SECONDS,  pm->cum_load_ticks );
     151             : 
     152           0 :   FD_MCNT_SET( EXECRP, TXN_REGIME_DURATION_NANOS_SETUP,  ctx->metrics.txn_load_cum_ticks+ctx->metrics.txn_check_cum_ticks );
     153           0 :   FD_MCNT_SET( EXECRP, TXN_REGIME_DURATION_NANOS_EXEC,   ctx->metrics.txn_exec_cum_ticks    );
     154           0 :   FD_MCNT_SET( EXECRP, TXN_REGIME_DURATION_NANOS_COMMIT, ctx->metrics.txn_commit_cum_ticks  );
     155             : 
     156           0 :   fd_runtime_t const * runtime = ctx->runtime;
     157           0 :   ulong cpi_ticks  = runtime->metrics.cpi_setup_cum_ticks +
     158           0 :                      runtime->metrics.cpi_commit_cum_ticks;
     159           0 :   ulong exec_ticks = fd_ulong_sat_sub( runtime->metrics.vm_exec_cum_ticks, cpi_ticks );
     160           0 :   FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_SETUP,       runtime->metrics.vm_setup_cum_ticks   );
     161           0 :   FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_COMMIT,      runtime->metrics.vm_commit_cum_ticks  );
     162           0 :   FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_SETUP_CPI,   runtime->metrics.cpi_setup_cum_ticks  );
     163           0 :   FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_COMMIT_CPI,  runtime->metrics.cpi_commit_cum_ticks );
     164           0 :   FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_INTERPRETER, exec_ticks                            );
     165             : 
     166           0 :   FD_MCNT_SET( EXECRP, CU_EXECUTED, runtime->metrics.cu_cum );
     167             : 
     168           0 :   FD_ACCDB_METRICS_WRITE( EXECRP, fd_accdb_metrics( ctx->accdb ) );
     169           0 : }
     170             : 
     171             : 
     172             : static void
     173             : publish_txn_finalized_msg( fd_execrp_tile_t *  ctx,
     174           0 :                            fd_stem_context_t * stem ) {
     175           0 :   fd_execrp_task_done_msg_t * msg  = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
     176           0 :   msg->bank_idx                  = ctx->bank->idx;
     177           0 :   msg->txn_exec->txn_idx         = ctx->txn_idx;
     178           0 :   msg->txn_exec->is_committable  = ctx->txn_out.err.is_committable;
     179           0 :   msg->txn_exec->is_fees_only    = ctx->txn_out.err.is_fees_only;
     180           0 :   msg->txn_exec->txn_err         = ctx->txn_out.err.txn_err;
     181           0 :   msg->txn_exec->slot            = ctx->slot;
     182           0 :   msg->txn_exec->bank_seq        = ctx->bank->bank_seq;
     183           0 :   msg->txn_exec->start_shred_idx = ctx->txn_in.txn->start_shred_idx;
     184           0 :   msg->txn_exec->end_shred_idx   = ctx->txn_in.txn->end_shred_idx;
     185             : 
     186           0 :   int is_vote = 0;
     187           0 :   if( FD_LIKELY( ctx->txn_out.details.is_simple_vote ) ) {
     188           0 :     fd_txn_t const * txn = TXN( ctx->txn_in.txn );
     189           0 :     uchar const *    payload = ctx->txn_in.txn->payload;
     190           0 :     fd_compact_tower_sync_serde_t tower_sync[ 1 ];
     191           0 :     if( FD_LIKELY( fd_txn_parse_simple_vote( txn, payload, tower_sync ) ) ) {
     192           0 :       fd_acct_addr_t const * accs = fd_txn_get_acct_addrs( txn, payload );
     193           0 :       *msg->txn_exec->vote.identity  = *(fd_pubkey_t const *)fd_type_pun_const( &accs[ 0 ] );
     194           0 :       *msg->txn_exec->vote.vote_acct = *(fd_pubkey_t const *)fd_type_pun_const( &accs[ txn->signature_cnt==1 ? 1 : 2 ] );
     195             : 
     196           0 :       ulong cur       = fd_ulong_if( tower_sync->root==ULONG_MAX, 0UL, tower_sync->root );
     197           0 :       ulong cnt       = 0UL;
     198           0 :       int   overflow  = 0;
     199           0 :       for( ulong i=0UL; i<tower_sync->lockouts_cnt; i++ ) {
     200           0 :         if( FD_UNLIKELY( __builtin_uaddl_overflow( cur, tower_sync->lockouts[ i ].offset, &cur ) ) ) { overflow = 1; break; }
     201           0 :         msg->txn_exec->vote.vote_slots[ cnt++ ] = cur;
     202           0 :       }
     203           0 :       if( FD_LIKELY( !overflow ) ) {
     204           0 :         msg->txn_exec->vote.vote_slot_cnt = (uchar)cnt;
     205           0 :         msg->txn_exec->vote.slot          = cnt ? msg->txn_exec->vote.vote_slots[ cnt-1UL ] : cur;
     206           0 :         is_vote                           = 1;
     207           0 :       }
     208           0 :     }
     209           0 :   }
     210             : 
     211           0 :   if( FD_UNLIKELY( !is_vote ) ) {
     212           0 :     msg->txn_exec->vote.slot          = ULONG_MAX;
     213           0 :     msg->txn_exec->vote.vote_slot_cnt = (uchar)0;
     214           0 :     *msg->txn_exec->vote.identity     = (fd_pubkey_t){ 0 };
     215           0 :     *msg->txn_exec->vote.vote_acct    = (fd_pubkey_t){ 0 };
     216           0 :   }
     217             : 
     218           0 :   if( FD_UNLIKELY( !msg->txn_exec->is_committable ) ) {
     219           0 :     uchar * signature = (uchar *)ctx->txn_in.txn->payload + TXN( ctx->txn_in.txn )->signature_off;
     220           0 :     FD_BASE58_ENCODE_64_BYTES( signature, signature_b58 );
     221           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 ));
     222           0 :   }
     223             : 
     224           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() ) );
     225             : 
     226           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 );
     227           0 : }
     228             : 
     229             : static inline void
     230             : after_credit( fd_execrp_tile_t *  ctx,
     231             :               fd_stem_context_t * stem,
     232             :               int *               opt_poll_in,
     233           0 :               int *               charge_busy ) {
     234           0 :   (void)stem; (void)opt_poll_in; (void)charge_busy;
     235           0 :   fd_startup_gate_idle( ctx->startup_gate );
     236           0 : }
     237             : 
     238             : static inline int
     239             : returnable_frag( fd_execrp_tile_t *  ctx,
     240             :                  ulong               in_idx,
     241             :                  ulong               seq FD_PARAM_UNUSED,
     242             :                  ulong               sig,
     243             :                  ulong               chunk,
     244             :                  ulong               sz,
     245             :                  ulong               ctl FD_PARAM_UNUSED,
     246             :                  ulong               tsorig FD_PARAM_UNUSED,
     247             :                  ulong               tspub,
     248           0 :                  fd_stem_context_t * stem ) {
     249           0 :   fd_startup_gate_busy( ctx->startup_gate );
     250             : 
     251           0 :   if( (sig&0xFFFFFFFFUL)!=ctx->tile_idx ) return 0;
     252             : 
     253           0 :   FD_MGAUGE_SET( EXECRP, PROCESSING, 1UL );
     254             : 
     255           0 :   if( FD_LIKELY( in_idx==ctx->replay_in->idx ) ) {
     256           0 :     if( FD_UNLIKELY( chunk < ctx->replay_in->chunk0 || chunk > ctx->replay_in->wmark ) ) {
     257           0 :       FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->replay_in->chunk0, ctx->replay_in->wmark ));
     258           0 :     }
     259           0 :     switch( sig>>32 ) {
     260           0 :       case FD_EXECRP_TT_TXN_EXEC: {
     261             :         /* Execute. */
     262           0 :         fd_execrp_txn_exec_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
     263           0 :         ctx->bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
     264           0 :         FD_TEST( ctx->bank );
     265           0 :         ctx->txn_in.txn = msg->txn;
     266           0 :         memcpy( ctx->txn_in.fec_merkle_root, msg->fec_merkle_root, 32UL );
     267           0 :         ctx->txn_in.index_in_slot = msg->index_in_slot;
     268             : 
     269             :         /* Set the capture txn index from the message so account updates
     270             :            during commit are recorded with the correct transaction index. */
     271           0 :         if( FD_UNLIKELY( ctx->capture_ctx ) ) {
     272           0 :           ctx->capture_ctx->current_txn_idx = msg->capture_txn_idx;
     273           0 :         }
     274             : 
     275           0 :         fd_runtime_prepare_and_execute_txn( ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
     276             : 
     277           0 :         ctx->metrics.txn_result[ fd_execle_err_from_runtime_err( ctx->txn_out.err.txn_err ) ]++;
     278             : 
     279           0 :         if( FD_LIKELY( ctx->txn_out.err.is_committable ) ) {
     280           0 :           fd_runtime_commit_txn( ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out, ctx->report_transaction_diffs );
     281           0 :         } else {
     282           0 :           fd_runtime_cancel_txn( ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out, ctx->report_transaction_diffs );
     283           0 :         }
     284             : 
     285           0 :         long const txn_end_ticks = fd_tickcount();
     286             : 
     287             :         /* Notify replay. */
     288           0 :         ctx->txn_idx = msg->txn_idx;
     289           0 :         ctx->dispatch_time_comp = tspub;
     290           0 :         ctx->slot = ctx->bank->f.slot;
     291           0 :         publish_txn_finalized_msg( ctx, stem );
     292             : 
     293             :         /* Update metrics */
     294           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 ) );
     295           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 ) );
     296           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 ) );
     297           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 ) );
     298             : 
     299           0 :         ctx->metrics.txn_load_cum_ticks   += load_start_ticks_dt;
     300           0 :         ctx->metrics.txn_check_cum_ticks  += check_start_ticks_dt;
     301           0 :         ctx->metrics.txn_exec_cum_ticks   += exec_start_ticks_dt;
     302           0 :         ctx->metrics.txn_commit_cum_ticks += commit_ticks_dt;
     303             : 
     304           0 :         break;
     305           0 :       }
     306           0 :       case FD_EXECRP_TT_TXN_SIGVERIFY: {
     307           0 :         fd_execrp_txn_sigverify_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
     308           0 :         int res = fd_executor_txn_verify( msg->txn, ctx->sha_lj );
     309           0 :         fd_execrp_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
     310           0 :         out_msg->bank_idx               = msg->bank_idx;
     311           0 :         out_msg->txn_sigverify->txn_idx = msg->txn_idx;
     312           0 :         out_msg->txn_sigverify->err     = (res!=FD_RUNTIME_EXECUTE_SUCCESS);
     313           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 );
     314           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 );
     315           0 :         ctx->metrics.sigverify_cnt += TXN( msg->txn )->signature_cnt;
     316           0 :         break;
     317           0 :       }
     318           0 :       case FD_EXECRP_TT_POH_HASH: {
     319           0 :         fd_execrp_poh_hash_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
     320           0 :         fd_execrp_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
     321           0 :         out_msg->bank_idx           = msg->bank_idx;
     322           0 :         out_msg->poh_hash->mblk_idx = msg->mblk_idx;
     323           0 :         out_msg->poh_hash->hashcnt  = msg->hashcnt;
     324           0 :         fd_sha256_hash_32_repeated( msg->hash, out_msg->poh_hash->hash, msg->hashcnt );
     325           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 );
     326           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 );
     327           0 :         ctx->metrics.poh_hash_cnt += msg->hashcnt;
     328           0 :         break;
     329           0 :       }
     330           0 :       default: FD_LOG_CRIT(( "unexpected signature %lu", sig ));
     331           0 :     }
     332           0 :   } else FD_LOG_CRIT(( "invalid in_idx %lu", in_idx ));
     333             : 
     334           0 :   FD_MGAUGE_SET( EXECRP, PROCESSING, 0UL );
     335             : 
     336           0 :   return 0;
     337           0 : }
     338             : 
     339             : extern FD_TL int fd_wksp_oom_silent;
     340             : 
     341             : static void
     342             : unprivileged_init( fd_topo_t const *      topo,
     343           0 :                    fd_topo_tile_t const * tile ) {
     344           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     345             : 
     346           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     347           0 :   fd_execrp_tile_t * ctx    = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_execrp_tile_t),    sizeof(fd_execrp_tile_t)                             );
     348           0 :   void * _txncache          = FD_SCRATCH_ALLOC_APPEND( l, fd_txncache_align(),          fd_txncache_footprint( tile->execrp.max_live_slots ) );
     349           0 :   void * _accdb             = FD_SCRATCH_ALLOC_APPEND( l, fd_accdb_align(),             fd_accdb_footprint( tile->execrp.max_live_slots )    );
     350           0 :   uchar * pc_scratch        = FD_SCRATCH_ALLOC_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN,   FD_PROGCACHE_SCRATCH_FOOTPRINT                       );
     351             : 
     352           0 :   void * _capture_ctx = NULL;
     353           0 :   if( FD_UNLIKELY( strlen( tile->execrp.solcap_capture ) ) ) {
     354           0 :     _capture_ctx            = FD_SCRATCH_ALLOC_APPEND( l, fd_capture_ctx_align(),       fd_capture_ctx_footprint()                           );
     355           0 :   }
     356             : 
     357           0 :   void * _dump_proto_ctx = NULL;
     358           0 :   void * _txn_dump_ctx = NULL;
     359           0 :   void * _dumping = NULL;
     360           0 :   if( FD_UNLIKELY( strlen( tile->execrp.dump_proto_dir ) ) ) {
     361           0 :     _dump_proto_ctx         = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_dump_proto_ctx_t), sizeof(fd_dump_proto_ctx_t)                          );
     362           0 :     _txn_dump_ctx           = FD_SCRATCH_ALLOC_APPEND( l, fd_txn_dump_context_align(),  fd_txn_dump_context_footprint()                      );
     363           0 :     if( FD_UNLIKELY( tile->execrp.dump_instr_to_pb || tile->execrp.dump_syscall_to_pb || tile->execrp.dump_txn_to_pb ) ) {
     364           0 :       _dumping              = FD_SCRATCH_ALLOC_APPEND( l, FD_SPAD_ALIGN,                FD_SPAD_FOOTPRINT( 1UL<<28UL )                       );
     365           0 :     }
     366           0 :   }
     367             : 
     368           0 :   for( ulong i=0UL; i<FD_TXN_SIG_MAX; i++ ) {
     369           0 :     fd_sha512_t * sha = fd_sha512_join( fd_sha512_new( ctx->sha_mem+i ) );
     370           0 :     FD_TEST( sha );
     371           0 :     ctx->sha_lj[ i ] = sha;
     372           0 :   }
     373             : 
     374           0 :   ctx->txn_in.bundle.is_bundle = 0;
     375           0 :   ctx->tile_idx = tile->kind_id;
     376             : 
     377           0 :   ulong banks_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "banks" );
     378           0 :   FD_TEST( banks_obj_id!=ULONG_MAX );
     379             : 
     380           0 :   ctx->banks = fd_banks_join( fd_topo_obj_laddr( topo, banks_obj_id ) );
     381           0 :   FD_TEST( ctx->banks );
     382             : 
     383           0 :   FD_TEST( fd_progcache_join( ctx->progcache, fd_topo_obj_laddr( topo, tile->execrp.progcache_obj_id ), pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT ) );
     384             : 
     385           0 :   void * _txncache_shmem = fd_topo_obj_laddr( topo, tile->execrp.txncache_obj_id );
     386           0 :   fd_txncache_shmem_t * txncache_shmem = fd_txncache_shmem_join( _txncache_shmem );
     387           0 :   FD_TEST( txncache_shmem );
     388           0 :   ctx->txncache = fd_txncache_join( fd_txncache_new( _txncache, txncache_shmem ) );
     389           0 :   FD_TEST( ctx->txncache );
     390             : 
     391           0 :   void * _accdb_shmem = fd_topo_obj_laddr( topo, tile->execrp.accdb_obj_id );
     392           0 :   fd_accdb_shmem_t * accdb_shmem = fd_accdb_shmem_join( _accdb_shmem );
     393           0 :   FD_TEST( accdb_shmem );
     394           0 :   ctx->accdb = fd_accdb_join( fd_accdb_new( _accdb, accdb_shmem, FD_ACCDB_FD_RW, 0UL, NULL ) );
     395           0 :   FD_TEST( ctx->accdb );
     396             : 
     397             : 
     398             :   /* First find and setup the in-link from replay to exec. */
     399           0 :   ctx->replay_in->idx = fd_topo_find_tile_in_link( topo, tile, "replay_execrp", 0UL );
     400           0 :   FD_TEST( ctx->replay_in->idx!=ULONG_MAX );
     401           0 :   fd_topo_link_t const * replay_in_link = &topo->links[ tile->in_link_id[ ctx->replay_in->idx ] ];
     402           0 :   ctx->replay_in->mem    = topo->workspaces[ topo->objs[ replay_in_link->dcache_obj_id ].wksp_id ].wksp;
     403           0 :   ctx->replay_in->chunk0 = fd_dcache_compact_chunk0( ctx->replay_in->mem, replay_in_link->dcache );
     404           0 :   ctx->replay_in->wmark  = fd_dcache_compact_wmark( ctx->replay_in->mem, replay_in_link->dcache, replay_in_link->mtu );
     405           0 :   ctx->replay_in->chunk  = ctx->replay_in->chunk0;
     406             : 
     407           0 :   ctx->execrp_replay_out->idx = fd_topo_find_tile_out_link( topo, tile, "execrp_replay", ctx->tile_idx );
     408           0 :   if( FD_LIKELY( ctx->execrp_replay_out->idx!=ULONG_MAX ) ) {
     409           0 :     fd_topo_link_t const * execrp_replay_link = &topo->links[ tile->out_link_id[ ctx->execrp_replay_out->idx ] ];
     410           0 :     ctx->execrp_replay_out->mem    = topo->workspaces[ topo->objs[ execrp_replay_link->dcache_obj_id ].wksp_id ].wksp;
     411           0 :     ctx->execrp_replay_out->chunk0 = fd_dcache_compact_chunk0( ctx->execrp_replay_out->mem, execrp_replay_link->dcache );
     412           0 :     ctx->execrp_replay_out->wmark  = fd_dcache_compact_wmark( ctx->execrp_replay_out->mem, execrp_replay_link->dcache, execrp_replay_link->mtu );
     413           0 :     ctx->execrp_replay_out->chunk  = ctx->execrp_replay_out->chunk0;
     414           0 :   }
     415             : 
     416             : 
     417           0 :   ctx->capture_ctx = NULL;
     418           0 :   if( FD_UNLIKELY( strlen( tile->execrp.solcap_capture ) ) ) {
     419           0 :     ctx->capture_ctx = fd_capture_ctx_join( fd_capture_ctx_new( _capture_ctx ) );
     420           0 :     ctx->capture_ctx->solcap_start_slot = tile->execrp.capture_start_slot;
     421             : 
     422           0 :     ulong tile_idx = tile->kind_id;
     423           0 :     ulong idx = fd_topo_find_tile_out_link( topo, tile, "cap_execrp", tile_idx );
     424           0 :     FD_TEST( idx!=ULONG_MAX );
     425             : 
     426           0 :     fd_topo_link_t const * link = &topo->links[ tile->out_link_id[ idx ] ];
     427           0 :     fd_capture_link_buf_t * cap_execrp_out = ctx->cap_execrp_out;
     428           0 :     cap_execrp_out->base.vt = &fd_capture_link_buf_vt;
     429           0 :     cap_execrp_out->idx     = idx;
     430           0 :     cap_execrp_out->mem     = topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ].wksp;
     431           0 :     cap_execrp_out->chunk0  = fd_dcache_compact_chunk0( cap_execrp_out->mem, link->dcache );
     432           0 :     cap_execrp_out->wmark   = fd_dcache_compact_wmark( cap_execrp_out->mem, link->dcache, link->mtu );
     433           0 :     cap_execrp_out->chunk   = cap_execrp_out->chunk0;
     434           0 :     cap_execrp_out->mcache  = link->mcache;
     435           0 :     cap_execrp_out->depth   = fd_mcache_depth( link->mcache );
     436           0 :     cap_execrp_out->seq     = 0UL;
     437             : 
     438           0 :     ulong consumer_tile_idx = fd_topo_find_tile(topo, "solcap", 0UL);
     439           0 :     fd_topo_tile_t const * consumer_tile = &topo->tiles[ consumer_tile_idx ];
     440           0 :     cap_execrp_out->fseq = NULL;
     441           0 :     for( ulong j = 0UL; j < consumer_tile->in_cnt; j++ ) {
     442           0 :       if( FD_UNLIKELY( consumer_tile->in_link_id[ j ]  == link->id ) ) {
     443           0 :         cap_execrp_out->fseq = fd_fseq_join( fd_topo_obj_laddr( topo, consumer_tile->in_link_fseq_obj_id[ j ] ) );
     444           0 :         FD_TEST( cap_execrp_out->fseq );
     445           0 :         break;
     446           0 :       }
     447           0 :     }
     448             : 
     449           0 :     ctx->capture_ctx->capture_solcap  = 1;
     450           0 :     ctx->capture_ctx->capctx_type.buf = cap_execrp_out;
     451           0 :     ctx->capture_ctx->capture_link    = &cap_execrp_out->base;
     452           0 :   }
     453             : 
     454           0 :   ctx->dump_proto_ctx = NULL;
     455           0 :   if( FD_UNLIKELY( strlen( tile->execrp.dump_proto_dir ) ) ) {
     456           0 :     ctx->dump_proto_ctx = _dump_proto_ctx;
     457             : 
     458             :     /* General dumping config */
     459           0 :     ctx->dump_proto_ctx->dump_proto_output_dir = tile->execrp.dump_proto_dir;
     460           0 :     ctx->dump_proto_ctx->dump_proto_start_slot = tile->execrp.capture_start_slot;
     461             : 
     462             :     /* Syscall dumping config */
     463           0 :     ctx->dump_proto_ctx->dump_syscall_to_pb       = !!tile->execrp.dump_syscall_to_pb;
     464           0 :     ctx->dump_proto_ctx->dump_syscall_name_filter = tile->execrp.dump_syscall_name_filter;
     465             : 
     466             :     /* Instruction dumping config */
     467           0 :     ctx->dump_proto_ctx->dump_instr_to_pb                 = !!tile->execrp.dump_instr_to_pb;
     468           0 :     ctx->dump_proto_ctx->has_dump_instr_program_id_filter = !!strlen(tile->execrp.dump_instr_program_id_filter);
     469           0 :     if( FD_UNLIKELY( ctx->dump_proto_ctx->has_dump_instr_program_id_filter &&
     470           0 :                      !fd_base58_decode_32( tile->execrp.dump_instr_program_id_filter, ctx->dump_proto_ctx->dump_instr_program_id_filter ) ) ) {
     471           0 :       FD_LOG_ERR(( "failed to parse [capture.dump_instr_program_id_filter] %s", tile->execrp.dump_instr_program_id_filter ));
     472           0 :     }
     473             : 
     474             :     /* Transaction dumping config */
     475           0 :     ctx->dump_proto_ctx->dump_txn_to_pb      = !!tile->execrp.dump_txn_to_pb;
     476           0 :     ctx->dump_proto_ctx->dump_txn_as_fixture = !!tile->execrp.dump_txn_as_fixture;
     477             : 
     478           0 :     if( FD_UNLIKELY( ctx->dump_proto_ctx->dump_txn_as_fixture && !ctx->dump_proto_ctx->dump_txn_to_pb ) ) {
     479           0 :       FD_LOG_ERR(( "[capture.dump_txn_as_fixture] requires [capture.dump_txn_to_pb] to be enabled" ));
     480           0 :     }
     481           0 :   }
     482             : 
     483             :   /* Transaction dump context (for fixture dumping) */
     484           0 :   ctx->txn_dump_ctx = NULL;
     485           0 :   if( FD_UNLIKELY( ctx->dump_proto_ctx && ctx->dump_proto_ctx->dump_txn_to_pb ) ) {
     486           0 :     ctx->txn_dump_ctx = fd_txn_dump_context_join( fd_txn_dump_context_new( _txn_dump_ctx ) );
     487           0 :   }
     488             : 
     489           0 :   ctx->runtime->accdb                    = ctx->accdb;
     490           0 :   ctx->runtime->progcache                = ctx->progcache;
     491           0 :   ctx->runtime->status_cache             = ctx->txncache;
     492           0 :   memset( &ctx->runtime->log, 0, sizeof(ctx->runtime->log) );
     493           0 :   ctx->runtime->log.log_collector        = &ctx->log_collector;
     494           0 :   ctx->runtime->log.dumping_mem          = _dumping;
     495           0 :   ctx->runtime->log.tracing_mem          = NULL;
     496           0 :   ctx->runtime->log.capture_ctx          = ctx->capture_ctx;
     497           0 :   ctx->runtime->log.dump_proto_ctx       = ctx->dump_proto_ctx;
     498           0 :   ctx->runtime->log.txn_dump_ctx         = ctx->txn_dump_ctx;
     499           0 :   ctx->runtime->fuzz.enabled             = 0;
     500           0 :   ctx->runtime->fuzz.reclaim_accounts    = 0;
     501           0 :   ctx->runtime->accounts.executable_cnt  = 0UL;
     502           0 :   ctx->runtime->accounts.account_cnt     = 0UL;
     503             : 
     504           0 :   memset( &ctx->metrics,          0, sizeof(ctx->metrics)          );
     505           0 :   memset( &ctx->runtime->metrics, 0, sizeof(ctx->runtime->metrics) );
     506             : 
     507           0 :   ctx->report_transaction_diffs = tile->execrp.report_transaction_diffs;
     508             : 
     509           0 :   fd_wksp_oom_silent = 1;
     510             : 
     511           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     512           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     513           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     514             : 
     515           0 :   fd_startup_gate_init( ctx->startup_gate, topo, tile->in_cnt );
     516           0 : }
     517             : 
     518             : static ulong
     519             : populate_allowed_seccomp( fd_topo_t const *      topo FD_PARAM_UNUSED,
     520             :                           fd_topo_tile_t const * tile FD_PARAM_UNUSED,
     521             :                           ulong                  out_cnt,
     522           0 :                           struct sock_filter *   out ) {
     523           0 :   populate_sock_filter_policy_fd_execrp_tile( out_cnt, out, (uint)fd_log_private_logfile_fd(), (uint)FD_ACCDB_FD_RW );
     524           0 :   return sock_filter_policy_fd_execrp_tile_instr_cnt;
     525           0 : }
     526             : 
     527             : static ulong
     528             : populate_allowed_fds( fd_topo_t const *      topo FD_PARAM_UNUSED,
     529             :                       fd_topo_tile_t const * tile FD_PARAM_UNUSED,
     530             :                       ulong                  out_fds_cnt,
     531           0 :                       int *                  out_fds ) {
     532             : 
     533           0 :   if( FD_UNLIKELY( out_fds_cnt<3UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
     534             : 
     535           0 :   ulong out_cnt = 0UL;
     536           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
     537           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) ) {
     538           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     539           0 :   }
     540           0 :   out_fds[ out_cnt++ ] = FD_ACCDB_FD_RW; /* accounts db */
     541             : 
     542           0 :   return out_cnt;
     543           0 : }
     544             : 
     545           0 : #define STEM_BURST (1UL)
     546             : 
     547             : /* Right now, depth of the replay_exec link and depth of the execrp_replay
     548             :    links is 16K.  At 1M TPS, that's ~16ms to fill.  But we also want to
     549             :    be conservative here, so we use 1ms. */
     550           0 : #define STEM_LAZY  (1000000UL)
     551             : 
     552           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_execrp_tile_t
     553           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_execrp_tile_t)
     554             : 
     555           0 : #define STEM_CALLBACK_METRICS_WRITE   metrics_write
     556           0 : #define STEM_CALLBACK_AFTER_CREDIT    after_credit
     557           0 : #define STEM_CALLBACK_RETURNABLE_FRAG returnable_frag
     558             : 
     559             : #include "../../disco/stem/fd_stem.c"
     560             : 
     561             : static ulong
     562           0 : max_event_sz( fd_topo_tile_t const * tile ) {
     563             :   /* execrp emits accdb_partition_added, plus runtime_txn when diffs are on. */
     564           0 :   ulong sz = sizeof(fd_event_accdb_partition_added_t);
     565           0 :   if( tile->execrp.report_transaction_diffs && sizeof(fd_event_runtime_txn_t)>sz ) sz = sizeof(fd_event_runtime_txn_t);
     566           0 :   return sz;
     567           0 : }
     568             : 
     569             : fd_topo_run_tile_t fd_tile_execrp = {
     570             :   .name                     = "execrp",
     571             :   .max_event_sz             = max_event_sz,
     572             :   .loose_footprint          = 0UL,
     573             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     574             :   .populate_allowed_fds     = populate_allowed_fds,
     575             :   .scratch_align            = scratch_align,
     576             :   .scratch_footprint        = scratch_footprint,
     577             :   .unprivileged_init        = unprivileged_init,
     578             :   .run                      = stem_run,
     579             : };

Generated by: LCOV version 1.14