LCOV - code coverage report
Current view: top level - discof/execrp - fd_execrp_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 374 0.0 %
Date: 2026-10-22 18:10: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 "../../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/fd_cost_tracker.h"
      13             : #include "../../flamenco/runtime/tests/fd_dump_pb.h"
      14             : #include "../../flamenco/progcache/fd_progcache_user.h"
      15             : #include "../../flamenco/log_collector/fd_log_collector_base.h"
      16             : #include "../../disco/metrics/fd_metrics.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 ]; /* TODO: Remove with solcap v2 */
      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             : 
      53             :   /* Capture context for debugging runtime execution. */
      54             :   fd_capture_ctx_t *    capture_ctx;
      55             :   fd_capture_link_buf_t cap_execrp_out[1];
      56             : 
      57             :   /* Protobuf dumping context for debugging runtime execution and
      58             :      collecting seed corpora. */
      59             :   fd_dump_proto_ctx_t * dump_proto_ctx;
      60             :   fd_txn_dump_ctx_t *   txn_dump_ctx;
      61             : 
      62             :   fd_banks_t *    banks;
      63             :   fd_bank_t *     bank;
      64             :   fd_accdb_t *    accdb;
      65             :   fd_txncache_t * txncache;
      66             :   fd_progcache_t  progcache[1];
      67             : 
      68             :   ulong txn_idx;
      69             :   ulong slot;
      70             :   ulong dispatch_time_comp;
      71             : 
      72             :   fd_log_collector_t log_collector;
      73             : 
      74             :   fd_txn_in_t  txn_in;
      75             :   fd_txn_out_t txn_out;
      76             : 
      77             :   fd_runtime_t runtime[1];
      78             : 
      79             :   struct {
      80             :     ulong sigverify_cnt;
      81             :     ulong poh_hash_cnt;
      82             : 
      83             :     /* Ticks spent loading txn accounts */
      84             :     ulong txn_load_cum_ticks;
      85             : 
      86             :     /* Ticks spent validating txn invariants (e.g. status cache, fee payer) */
      87             :     ulong txn_check_cum_ticks;
      88             : 
      89             :     /* Ticks spent executing a txn (includes any VM time) */
      90             :     ulong txn_exec_cum_ticks;
      91             : 
      92             :     /* Ticks spent committing a txn (database writes) */
      93             :     ulong txn_commit_cum_ticks;
      94             : 
      95             :     ulong txn_result[ FD_METRICS_ENUM_TXN_RESULT_CNT ];
      96             :     ulong txn_version[ FD_METRICS_ENUM_TXN_VERSION_CNT ];
      97             :   } metrics;
      98             : 
      99             :   ulong ed25519_cache_seed;
     100             : };
     101             : 
     102             : typedef struct fd_execrp_tile fd_execrp_tile_t;
     103             : 
     104             : /* Signer precomputation cache entries (vote authorities and frequent
     105             :    fee payers) */
     106           0 : #define ED25519_CACHE_ENT_CNT (2048UL)
     107             : 
     108             : FD_FN_CONST static inline ulong
     109           0 : scratch_align( void ) {
     110           0 :   return 128UL;
     111           0 : }
     112             : 
     113             : FD_FN_PURE static inline ulong
     114           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
     115           0 :   ulong l = FD_LAYOUT_INIT;
     116           0 :   l = FD_LAYOUT_APPEND(   l, alignof(fd_execrp_tile_t),    sizeof(fd_execrp_tile_t)                             );
     117           0 :   l = FD_LAYOUT_APPEND(   l, fd_txncache_align(),          fd_txncache_footprint( tile->execrp.max_live_slots ) );
     118           0 :   l = FD_LAYOUT_APPEND(   l, fd_accdb_align(),             fd_accdb_footprint( tile->execrp.max_live_slots, 0 )    );
     119           0 :   l = FD_LAYOUT_APPEND(   l, FD_PROGCACHE_SCRATCH_ALIGN,   FD_PROGCACHE_SCRATCH_FOOTPRINT                       );
     120           0 :   l = FD_LAYOUT_APPEND(   l, fd_ed25519_cache_align(),     fd_ed25519_cache_footprint( ED25519_CACHE_ENT_CNT )  );
     121             : 
     122           0 :   if( FD_UNLIKELY( strlen( tile->execrp.solcap_capture ) ) ) {
     123           0 :     l = FD_LAYOUT_APPEND( l, fd_capture_ctx_align(),       fd_capture_ctx_footprint()                           );
     124           0 :   }
     125             : 
     126           0 :   if( FD_UNLIKELY( strlen( tile->execrp.dump_proto_dir ) ) ) {
     127           0 :     l = FD_LAYOUT_APPEND( l, alignof(fd_dump_proto_ctx_t), sizeof(fd_dump_proto_ctx_t)                          );
     128           0 :     l = FD_LAYOUT_APPEND( l, fd_txn_dump_context_align(),  fd_txn_dump_context_footprint()                      );
     129           0 :     if( FD_UNLIKELY( tile->execrp.dump_instr_to_pb || tile->execrp.dump_syscall_to_pb || tile->execrp.dump_txn_to_pb ) ) {
     130           0 :       l = FD_LAYOUT_APPEND( l, FD_SPAD_ALIGN,              FD_SPAD_FOOTPRINT( 1UL<<28UL )                       );
     131           0 :     }
     132           0 :   }
     133             : 
     134           0 :   return FD_LAYOUT_FINI(  l, scratch_align() );
     135           0 : }
     136             : 
     137             : static void
     138           0 : metrics_write( fd_execrp_tile_t * ctx ) {
     139           0 :   fd_accdb_flush_metrics( ctx->accdb );
     140             : 
     141           0 :   FD_MCNT_SET      ( EXECRP, SIGNATURE_CHECKED,    ctx->metrics.sigverify_cnt );
     142           0 :   FD_MCNT_SET      ( EXECRP, POH_HASH_COMPUTED,     ctx->metrics.poh_hash_cnt  );
     143           0 :   FD_MCNT_ENUM_COPY( EXECRP, TXN_PROCESSED,             ctx->metrics.txn_result    );
     144           0 :   FD_MCNT_ENUM_COPY( EXECRP, TXN_PROCESSED_BY_VERSION,  ctx->metrics.txn_version   );
     145             : 
     146           0 :   FD_PROGCACHE_METRICS_WRITE( EXECRP, ctx->progcache->metrics );
     147             : 
     148           0 :   FD_MCNT_SET( EXECRP, TXN_REGIME_DURATION_NANOS_LOAD,    ctx->metrics.txn_load_cum_ticks+ctx->metrics.txn_check_cum_ticks );
     149           0 :   FD_MCNT_SET( EXECRP, TXN_REGIME_DURATION_NANOS_EXECUTE, ctx->metrics.txn_exec_cum_ticks   );
     150           0 :   FD_MCNT_SET( EXECRP, TXN_REGIME_DURATION_NANOS_COMMIT,  ctx->metrics.txn_commit_cum_ticks );
     151             : 
     152           0 :   fd_runtime_t const * runtime = ctx->runtime;
     153           0 :   ulong cpi_ticks  = runtime->metrics.cpi_setup_cum_ticks +
     154           0 :                      runtime->metrics.cpi_commit_cum_ticks;
     155           0 :   ulong exec_ticks = fd_ulong_sat_sub( runtime->metrics.vm_exec_cum_ticks, cpi_ticks );
     156           0 :   FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_SETUP,       runtime->metrics.vm_setup_cum_ticks   );
     157           0 :   FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_COMMIT,      runtime->metrics.vm_commit_cum_ticks  );
     158           0 :   FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_SETUP_CPI,   runtime->metrics.cpi_setup_cum_ticks  );
     159           0 :   FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_COMMIT_CPI,  runtime->metrics.cpi_commit_cum_ticks );
     160           0 :   FD_MCNT_SET( EXECRP, VM_REGIME_DURATION_NANOS_INTERPRETER, exec_ticks                            );
     161             : 
     162           0 :   FD_MCNT_SET( EXECRP, CU_CONSUMED, runtime->metrics.cu_cum );
     163           0 :   FD_MCNT_SET( EXECRP, INSTRUCTION_EXECUTED,   runtime->metrics.instr_cum );
     164           0 :   FD_MCNT_SET( EXECRP, CPI_EXECUTED,           runtime->metrics.cpi_cum   );
     165           0 :   FD_MCNT_SET( EXECRP, ACCOUNT_LTHASH_SKIPPED, runtime->metrics.lthash_unchanged_cnt );
     166             : 
     167           0 :   FD_ACCDB_METRICS_WRITE( EXECRP, fd_accdb_metrics( ctx->accdb ) );
     168           0 : }
     169             : 
     170             : static void
     171             : publish_txn_finalized_msg( fd_execrp_tile_t *  ctx,
     172             :                            fd_stem_context_t * stem,
     173           0 :                            long                now ) {
     174           0 :   uint compute_units_consumed = 0U;
     175           0 :   if( FD_LIKELY( ctx->txn_out.err.is_committable ) ) {
     176           0 :     fd_usage_cost_details_t const * cost = &ctx->txn_out.details.txn_cost.transaction;
     177           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;
     178           0 :   }
     179             : 
     180           0 :   fd_execrp_task_done_msg_t * msg  = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
     181           0 :   msg->bank_idx                  = ctx->bank->idx;
     182           0 :   msg->txn_exec->txn_idx         = ctx->txn_idx;
     183           0 :   msg->txn_exec->is_committable  = ctx->txn_out.err.is_committable;
     184           0 :   msg->txn_exec->is_fees_only    = ctx->txn_out.err.is_fees_only;
     185           0 :   msg->txn_exec->is_noop         = ctx->txn_out.err.is_noop;
     186           0 :   msg->txn_exec->txn_err         = ctx->txn_out.err.txn_err;
     187           0 :   msg->txn_exec->is_simple_vote  = ctx->txn_out.details.is_simple_vote;
     188             : 
     189           0 :   msg->txn_exec->tick_load_start        = ctx->txn_out.details.load_start_ticks;
     190           0 :   msg->txn_exec->tick_check_start       = ctx->txn_out.details.check_start_ticks;
     191           0 :   msg->txn_exec->tick_exec_start        = ctx->txn_out.details.exec_start_ticks;
     192           0 :   msg->txn_exec->tick_commit_start      = ctx->txn_out.details.commit_start_ticks;
     193           0 :   msg->txn_exec->tick_commit_end        = fd_long_if( ctx->txn_out.details.commit_start_ticks==LONG_MAX, LONG_MAX, now );
     194             : 
     195           0 :   msg->txn_exec->compute_units_consumed = compute_units_consumed;
     196           0 :   msg->txn_exec->transaction_fee        = ctx->txn_out.details.execution_fee;
     197           0 :   msg->txn_exec->priority_fee           = ctx->txn_out.details.priority_fee;
     198           0 :   msg->txn_exec->tips                   = ctx->txn_out.details.tips;
     199           0 :   msg->txn_exec->slot            = ctx->slot;
     200           0 :   msg->txn_exec->bank_seq        = ctx->bank->bank_seq;
     201           0 :   msg->txn_exec->start_shred_idx = ctx->txn_in.txn->start_shred_idx;
     202           0 :   msg->txn_exec->end_shred_idx   = ctx->txn_in.txn->end_shred_idx;
     203             : 
     204           0 :   int is_vote = 0;
     205           0 :   if( FD_LIKELY( ctx->txn_out.details.is_simple_vote ) ) {
     206           0 :     fd_txn_t const * txn = TXN( ctx->txn_in.txn );
     207           0 :     uchar const *    payload = ctx->txn_in.txn->payload;
     208           0 :     fd_compact_tower_sync_serde_t tower_sync[ 1 ];
     209           0 :     if( FD_LIKELY( fd_txn_parse_simple_vote( txn, payload, tower_sync ) ) ) {
     210           0 :       fd_acct_addr_t const * accs = fd_txn_get_acct_addrs( txn, payload );
     211           0 :       *msg->txn_exec->vote.identity  = *(fd_pubkey_t const *)fd_type_pun_const( &accs[ 0 ] );
     212           0 :       *msg->txn_exec->vote.vote_acct = *(fd_pubkey_t const *)fd_type_pun_const( &accs[ txn->signature_cnt==1 ? 1 : 2 ] );
     213             : 
     214           0 :       ulong cur       = fd_ulong_if( tower_sync->root==ULONG_MAX, 0UL, tower_sync->root );
     215           0 :       ulong cnt       = 0UL;
     216           0 :       int   overflow  = 0;
     217           0 :       for( ulong i=0UL; i<tower_sync->lockouts_cnt; i++ ) {
     218           0 :         if( FD_UNLIKELY( __builtin_uaddl_overflow( cur, tower_sync->lockouts[ i ].offset, &cur ) ) ) { overflow = 1; break; }
     219           0 :         msg->txn_exec->vote.vote_slots[ cnt++ ] = cur;
     220           0 :       }
     221           0 :       if( FD_LIKELY( !overflow ) ) {
     222           0 :         msg->txn_exec->vote.vote_slot_cnt = (uchar)cnt;
     223           0 :         msg->txn_exec->vote.slot          = cnt ? msg->txn_exec->vote.vote_slots[ cnt-1UL ] : cur;
     224           0 :         is_vote                           = 1;
     225           0 :       }
     226           0 :     }
     227           0 :   }
     228             : 
     229           0 :   if( FD_UNLIKELY( !is_vote ) ) {
     230           0 :     msg->txn_exec->vote.slot          = ULONG_MAX;
     231           0 :     msg->txn_exec->vote.vote_slot_cnt = (uchar)0;
     232           0 :     *msg->txn_exec->vote.identity     = (fd_pubkey_t){ 0 };
     233           0 :     *msg->txn_exec->vote.vote_acct    = (fd_pubkey_t){ 0 };
     234           0 :   }
     235             : 
     236           0 :   if( FD_UNLIKELY( !msg->txn_exec->is_committable ) ) {
     237           0 :     uchar * signature = (uchar *)ctx->txn_in.txn->payload + TXN( ctx->txn_in.txn )->signature_off;
     238           0 :     FD_BASE58_ENCODE_64_BYTES( signature, signature_b58 );
     239           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 ));
     240           0 :   }
     241             : 
     242           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() ) );
     243             : 
     244           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 );
     245           0 : }
     246             : 
     247             : static inline void
     248             : after_credit( fd_execrp_tile_t *  ctx,
     249             :               fd_stem_context_t * stem,
     250             :               int *               opt_poll_in,
     251           0 :               int *               charge_busy ) {
     252           0 :   (void)stem; (void)opt_poll_in; (void)charge_busy;
     253           0 :   fd_startup_gate_idle( ctx->startup_gate );
     254           0 : }
     255             : 
     256             : static inline int
     257             : returnable_frag( fd_execrp_tile_t *  ctx,
     258             :                  ulong               in_idx,
     259             :                  ulong               seq,
     260             :                  ulong               sig,
     261             :                  ulong               chunk,
     262             :                  ulong               sz,
     263             :                  ulong               ctl FD_PARAM_UNUSED,
     264             :                  ulong               tsorig FD_PARAM_UNUSED,
     265             :                  ulong               tspub,
     266           0 :                  fd_stem_context_t * stem ) {
     267           0 :   fd_startup_gate_busy( ctx->startup_gate );
     268             : 
     269           0 :   FD_TEST( (sig&0xFFFFFFFFUL)==ctx->tile_idx );
     270             : 
     271           0 :   FD_MGAUGE_SET( EXECRP, IS_PROCESSING, 1UL );
     272             : 
     273           0 :   if( FD_LIKELY( in_idx==ctx->replay_in->idx ) ) {
     274           0 :     if( FD_UNLIKELY( chunk < ctx->replay_in->chunk0 || chunk > ctx->replay_in->wmark ) ) {
     275           0 :       FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->replay_in->chunk0, ctx->replay_in->wmark ));
     276           0 :     }
     277           0 :     switch( sig>>32 ) {
     278           0 :       case FD_EXECRP_TT_TXN_EXEC: {
     279             :         /* Execute. */
     280           0 :         fd_execrp_txn_exec_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
     281           0 :         ctx->bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
     282           0 :         FD_TEST( ctx->bank );
     283           0 :         ctx->txn_in.txn = msg->txn;
     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, "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 :         fd_sha256_hash_32_repeated_batch( msg->hash, out_msg->poh_hash->hash, msg->hashcnt, msg->cnt );
     345           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 );
     346           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 );
     347           0 :         break;
     348           0 :       }
     349           0 :       case FD_EXECRP_TT_CERT_VERIFY: {
     350           0 :         fd_execrp_cert_verify_msg_t * msg  = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
     351           0 :         fd_bank_t const *             bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
     352           0 :         FD_TEST( bank );
     353           0 :         fd_execrp_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->execrp_replay_out->mem, ctx->execrp_replay_out->chunk );
     354           0 :         out_msg->bank_idx         = msg->bank_idx;
     355           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 );
     356           0 :         out_msg->cert_verify->has_hm = !msg->has_hm && !out_msg->cert_verify->err; /* hashed here */
     357           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 );
     358           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 );
     359           0 :         break;
     360           0 :       }
     361           0 :       default: FD_LOG_CRIT(( "unexpected signature %lu", sig ));
     362           0 :     }
     363           0 :   } else FD_LOG_CRIT(( "invalid in_idx %lu", in_idx ));
     364             : 
     365           0 :   FD_MGAUGE_SET( EXECRP, IS_PROCESSING, 0UL );
     366             : 
     367           0 :   fd_stem_credit_return( stem, in_idx, seq+1UL );
     368           0 :   return 0;
     369           0 : }
     370             : 
     371             : extern FD_TL int fd_wksp_oom_silent;
     372             : 
     373             : static void
     374             : privileged_init( fd_topo_t const *      topo,
     375           0 :                  fd_topo_tile_t const * tile ) {
     376           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     377           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     378           0 :   fd_execrp_tile_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_execrp_tile_t), sizeof(fd_execrp_tile_t) );
     379           0 :   FD_TEST( fd_rng_secure( &ctx->ed25519_cache_seed, sizeof(ulong) ) );
     380           0 : }
     381             : 
     382             : static void
     383             : unprivileged_init( fd_topo_t const *      topo,
     384           0 :                    fd_topo_tile_t const * tile ) {
     385           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     386             : 
     387           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     388           0 :   fd_execrp_tile_t * ctx    = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_execrp_tile_t),    sizeof(fd_execrp_tile_t)                             );
     389           0 :   void * _txncache          = FD_SCRATCH_ALLOC_APPEND( l, fd_txncache_align(),          fd_txncache_footprint( tile->execrp.max_live_slots ) );
     390           0 :   void * _accdb             = FD_SCRATCH_ALLOC_APPEND( l, fd_accdb_align(),             fd_accdb_footprint( tile->execrp.max_live_slots, 0 )    );
     391           0 :   uchar * pc_scratch        = FD_SCRATCH_ALLOC_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN,   FD_PROGCACHE_SCRATCH_FOOTPRINT                       );
     392           0 :   void * _ed25519_cache     = FD_SCRATCH_ALLOC_APPEND( l, fd_ed25519_cache_align(),     fd_ed25519_cache_footprint( ED25519_CACHE_ENT_CNT )  );
     393             : 
     394           0 :   void * _capture_ctx = NULL;
     395           0 :   if( FD_UNLIKELY( strlen( tile->execrp.solcap_capture ) ) ) {
     396           0 :     _capture_ctx            = FD_SCRATCH_ALLOC_APPEND( l, fd_capture_ctx_align(),       fd_capture_ctx_footprint()                           );
     397           0 :   }
     398             : 
     399           0 :   void * _dump_proto_ctx = NULL;
     400           0 :   void * _txn_dump_ctx = NULL;
     401           0 :   void * _dumping = NULL;
     402           0 :   if( FD_UNLIKELY( strlen( tile->execrp.dump_proto_dir ) ) ) {
     403           0 :     _dump_proto_ctx         = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_dump_proto_ctx_t), sizeof(fd_dump_proto_ctx_t)                          );
     404           0 :     _txn_dump_ctx           = FD_SCRATCH_ALLOC_APPEND( l, fd_txn_dump_context_align(),  fd_txn_dump_context_footprint()                      );
     405           0 :     if( FD_UNLIKELY( tile->execrp.dump_instr_to_pb || tile->execrp.dump_syscall_to_pb || tile->execrp.dump_txn_to_pb ) ) {
     406           0 :       _dumping              = FD_SCRATCH_ALLOC_APPEND( l, FD_SPAD_ALIGN,                FD_SPAD_FOOTPRINT( 1UL<<28UL )                       );
     407           0 :     }
     408           0 :   }
     409             : 
     410           0 :   for( ulong i=0UL; i<FD_TXN_SIG_MAX; i++ ) {
     411           0 :     fd_sha512_t * sha = fd_sha512_join( fd_sha512_new( ctx->sha_mem+i ) );
     412           0 :     FD_TEST( sha );
     413           0 :     ctx->sha_lj[ i ] = sha;
     414           0 :   }
     415             : 
     416           0 :   ctx->ed25519_cache = fd_ed25519_cache_join( fd_ed25519_cache_new( _ed25519_cache, ED25519_CACHE_ENT_CNT, ctx->ed25519_cache_seed ) );
     417           0 :   FD_TEST( ctx->ed25519_cache );
     418             : 
     419           0 :   ctx->txn_in.bundle.is_bundle = 0;
     420           0 :   ctx->tile_idx = tile->kind_id;
     421             : 
     422           0 :   ulong banks_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "banks" );
     423           0 :   FD_TEST( banks_obj_id!=ULONG_MAX );
     424             : 
     425           0 :   ctx->banks = fd_banks_join( fd_topo_obj_laddr( topo, banks_obj_id ) );
     426           0 :   FD_TEST( ctx->banks );
     427             : 
     428           0 :   FD_TEST( fd_progcache_join( ctx->progcache, fd_topo_obj_laddr( topo, tile->execrp.progcache_obj_id ), pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT ) );
     429             : 
     430           0 :   void * _txncache_shmem = fd_topo_obj_laddr( topo, tile->execrp.txncache_obj_id );
     431           0 :   fd_txncache_shmem_t * txncache_shmem = fd_txncache_shmem_join( _txncache_shmem );
     432           0 :   FD_TEST( txncache_shmem );
     433           0 :   ctx->txncache = fd_txncache_join( fd_txncache_new( _txncache, txncache_shmem ) );
     434           0 :   FD_TEST( ctx->txncache );
     435             : 
     436           0 :   void * _accdb_shmem = fd_topo_obj_laddr( topo, tile->execrp.accdb_obj_id );
     437           0 :   fd_accdb_shmem_t * accdb_shmem = fd_accdb_shmem_join( _accdb_shmem );
     438           0 :   FD_TEST( accdb_shmem );
     439           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;
     440           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 ) );
     441           0 :   FD_TEST( ctx->accdb );
     442             : 
     443             :   /* First find and setup the in-link from replay to exec. */
     444           0 :   ctx->replay_in->idx = fd_topo_find_tile_in_link( topo, tile, "replay_execrp", ctx->tile_idx );
     445           0 :   FD_TEST( ctx->replay_in->idx!=ULONG_MAX );
     446           0 :   fd_topo_link_t const * replay_in_link = &topo->links[ tile->in_link_id[ ctx->replay_in->idx ] ];
     447           0 :   ctx->replay_in->mem    = topo->workspaces[ topo->objs[ replay_in_link->dcache_obj_id ].wksp_id ].wksp;
     448           0 :   ctx->replay_in->chunk0 = fd_dcache_compact_chunk0( ctx->replay_in->mem, replay_in_link->dcache );
     449           0 :   ctx->replay_in->wmark  = fd_dcache_compact_wmark( ctx->replay_in->mem, replay_in_link->dcache, replay_in_link->mtu );
     450           0 :   ctx->replay_in->chunk  = ctx->replay_in->chunk0;
     451             : 
     452           0 :   ctx->execrp_replay_out->idx = fd_topo_find_tile_out_link( topo, tile, "execrp_replay", ctx->tile_idx );
     453           0 :   if( FD_LIKELY( ctx->execrp_replay_out->idx!=ULONG_MAX ) ) {
     454           0 :     fd_topo_link_t const * execrp_replay_link = &topo->links[ tile->out_link_id[ ctx->execrp_replay_out->idx ] ];
     455           0 :     ctx->execrp_replay_out->mem    = topo->workspaces[ topo->objs[ execrp_replay_link->dcache_obj_id ].wksp_id ].wksp;
     456           0 :     ctx->execrp_replay_out->chunk0 = fd_dcache_compact_chunk0( ctx->execrp_replay_out->mem, execrp_replay_link->dcache );
     457           0 :     ctx->execrp_replay_out->wmark  = fd_dcache_compact_wmark( ctx->execrp_replay_out->mem, execrp_replay_link->dcache, execrp_replay_link->mtu );
     458           0 :     ctx->execrp_replay_out->chunk  = ctx->execrp_replay_out->chunk0;
     459           0 :   }
     460             : 
     461           0 :   ctx->capture_ctx = NULL;
     462           0 :   if( FD_UNLIKELY( strlen( tile->execrp.solcap_capture ) ) ) {
     463           0 :     ctx->capture_ctx = fd_capture_ctx_join( fd_capture_ctx_new( _capture_ctx ) );
     464           0 :     ctx->capture_ctx->solcap_start_slot = tile->execrp.capture_start_slot;
     465             : 
     466           0 :     ulong tile_idx = tile->kind_id;
     467           0 :     ulong idx = fd_topo_find_tile_out_link( topo, tile, "cap_execrp", tile_idx );
     468           0 :     FD_TEST( idx!=ULONG_MAX );
     469             : 
     470           0 :     fd_topo_link_t const * link = &topo->links[ tile->out_link_id[ idx ] ];
     471           0 :     fd_capture_link_buf_t * cap_execrp_out = ctx->cap_execrp_out;
     472           0 :     cap_execrp_out->base.vt = &fd_capture_link_buf_vt;
     473           0 :     cap_execrp_out->idx     = idx;
     474           0 :     cap_execrp_out->mem     = topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ].wksp;
     475           0 :     cap_execrp_out->chunk0  = fd_dcache_compact_chunk0( cap_execrp_out->mem, link->dcache );
     476           0 :     cap_execrp_out->wmark   = fd_dcache_compact_wmark( cap_execrp_out->mem, link->dcache, link->mtu );
     477           0 :     cap_execrp_out->chunk   = cap_execrp_out->chunk0;
     478           0 :     cap_execrp_out->mcache  = link->mcache;
     479           0 :     cap_execrp_out->depth   = fd_mcache_depth( link->mcache );
     480           0 :     cap_execrp_out->seq     = 0UL;
     481             : 
     482           0 :     ulong consumer_tile_idx = fd_topo_find_tile(topo, "solcap", 0UL);
     483           0 :     fd_topo_tile_t const * consumer_tile = &topo->tiles[ consumer_tile_idx ];
     484           0 :     cap_execrp_out->fseq = NULL;
     485           0 :     for( ulong j = 0UL; j < consumer_tile->in_cnt; j++ ) {
     486           0 :       if( FD_UNLIKELY( consumer_tile->in_link_id[ j ]  == link->id ) ) {
     487           0 :         cap_execrp_out->fseq = fd_fseq_join( fd_topo_obj_laddr( topo, consumer_tile->in_link_fseq_obj_id[ j ] ) );
     488           0 :         FD_TEST( cap_execrp_out->fseq );
     489           0 :         break;
     490           0 :       }
     491           0 :     }
     492             : 
     493           0 :     ctx->capture_ctx->capture_solcap  = 1;
     494           0 :     ctx->capture_ctx->capctx_type.buf = cap_execrp_out;
     495           0 :     ctx->capture_ctx->capture_link    = &cap_execrp_out->base;
     496           0 :   }
     497             : 
     498           0 :   ctx->dump_proto_ctx = NULL;
     499           0 :   if( FD_UNLIKELY( strlen( tile->execrp.dump_proto_dir ) ) ) {
     500           0 :     ctx->dump_proto_ctx = _dump_proto_ctx;
     501             : 
     502             :     /* General dumping config */
     503           0 :     ctx->dump_proto_ctx->dump_proto_output_dir = tile->execrp.dump_proto_dir;
     504           0 :     ctx->dump_proto_ctx->dump_proto_start_slot = tile->execrp.capture_start_slot;
     505             : 
     506             :     /* Syscall dumping config */
     507           0 :     ctx->dump_proto_ctx->dump_syscall_to_pb       = !!tile->execrp.dump_syscall_to_pb;
     508           0 :     ctx->dump_proto_ctx->dump_syscall_name_filter = tile->execrp.dump_syscall_name_filter;
     509             : 
     510             :     /* Instruction dumping config */
     511           0 :     ctx->dump_proto_ctx->dump_instr_to_pb                 = !!tile->execrp.dump_instr_to_pb;
     512           0 :     ctx->dump_proto_ctx->has_dump_instr_program_id_filter = !!strlen(tile->execrp.dump_instr_program_id_filter);
     513           0 :     if( FD_UNLIKELY( ctx->dump_proto_ctx->has_dump_instr_program_id_filter &&
     514           0 :                      !fd_base58_decode_32( tile->execrp.dump_instr_program_id_filter, ctx->dump_proto_ctx->dump_instr_program_id_filter ) ) ) {
     515           0 :       FD_LOG_ERR(( "failed to parse [capture.dump_instr_program_id_filter] %s", tile->execrp.dump_instr_program_id_filter ));
     516           0 :     }
     517             : 
     518             :     /* Transaction dumping config */
     519           0 :     ctx->dump_proto_ctx->dump_txn_to_pb      = !!tile->execrp.dump_txn_to_pb;
     520           0 :     ctx->dump_proto_ctx->dump_txn_as_fixture = !!tile->execrp.dump_txn_as_fixture;
     521             : 
     522           0 :     if( FD_UNLIKELY( ctx->dump_proto_ctx->dump_txn_as_fixture && !ctx->dump_proto_ctx->dump_txn_to_pb ) ) {
     523           0 :       FD_LOG_ERR(( "[capture.dump_txn_as_fixture] requires [capture.dump_txn_to_pb] to be enabled" ));
     524           0 :     }
     525           0 :   }
     526             : 
     527             :   /* Transaction dump context (for fixture dumping) */
     528           0 :   ctx->txn_dump_ctx = NULL;
     529           0 :   if( FD_UNLIKELY( ctx->dump_proto_ctx && ctx->dump_proto_ctx->dump_txn_to_pb ) ) {
     530           0 :     ctx->txn_dump_ctx = fd_txn_dump_context_join( fd_txn_dump_context_new( _txn_dump_ctx ) );
     531           0 :   }
     532             : 
     533           0 :   ctx->runtime->accdb                    = ctx->accdb;
     534           0 :   ctx->runtime->progcache                = ctx->progcache;
     535           0 :   ctx->runtime->status_cache             = ctx->txncache;
     536           0 :   memset( &ctx->runtime->log, 0, sizeof(ctx->runtime->log) );
     537           0 :   ctx->runtime->log.log_collector        = &ctx->log_collector;
     538           0 :   ctx->runtime->log.dumping_mem          = _dumping;
     539           0 :   ctx->runtime->log.tracing_mem          = NULL;
     540           0 :   ctx->runtime->log.capture_ctx          = ctx->capture_ctx;
     541           0 :   ctx->runtime->log.dump_proto_ctx       = ctx->dump_proto_ctx;
     542           0 :   ctx->runtime->log.txn_dump_ctx         = ctx->txn_dump_ctx;
     543           0 :   ctx->runtime->fuzz.enabled             = 0;
     544           0 :   ctx->runtime->fuzz.reclaim_accounts    = 0;
     545           0 :   ctx->runtime->accounts.executable_cnt  = 0UL;
     546           0 :   ctx->runtime->accounts.account_cnt     = 0UL;
     547             : 
     548           0 :   memset( &ctx->metrics,          0, sizeof(ctx->metrics)          );
     549           0 :   memset( &ctx->runtime->metrics, 0, sizeof(ctx->runtime->metrics) );
     550             : 
     551           0 :   fd_wksp_oom_silent = 1;
     552             : 
     553           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     554           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     555           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     556             : 
     557           0 :   fd_startup_gate_init( ctx->startup_gate, topo, tile->in_cnt );
     558           0 : }
     559             : 
     560             : static ulong
     561             : populate_allowed_seccomp( fd_topo_t const *      topo FD_PARAM_UNUSED,
     562             :                           fd_topo_tile_t const * tile FD_PARAM_UNUSED,
     563             :                           ulong                  out_cnt,
     564           0 :                           struct sock_filter *   out ) {
     565           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 );
     566           0 :   return sock_filter_policy_fd_execrp_tile_instr_cnt;
     567           0 : }
     568             : 
     569             : static ulong
     570             : populate_allowed_fds( fd_topo_t const *      topo FD_PARAM_UNUSED,
     571             :                       fd_topo_tile_t const * tile FD_PARAM_UNUSED,
     572             :                       ulong                  out_fds_cnt,
     573           0 :                       int *                  out_fds ) {
     574             : 
     575           0 :   if( FD_UNLIKELY( out_fds_cnt<5UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
     576             : 
     577           0 :   ulong out_cnt = 0UL;
     578           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
     579           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) ) {
     580           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     581           0 :   }
     582           0 :   out_fds[ out_cnt++ ] = FD_ACCDB_FD_RW; /* accounts db */
     583           0 :   out_fds[ out_cnt++ ] = FD_STAKE_DELEGATIONS_FD; /* stake delegation disk spill */
     584           0 :   out_fds[ out_cnt++ ] = FD_VOTE_STAKES_FD; /* vote stakes disk spill */
     585             : 
     586           0 :   return out_cnt;
     587           0 : }
     588             : 
     589           0 : #define STEM_BURST (1UL)
     590             : 
     591             : /* replay_execrp credits are returned per frag, so housekeeping only
     592             :    needs to keep up with the execrp_replay out link. */
     593           0 : #define STEM_LAZY  (1000000UL)
     594             : 
     595           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_execrp_tile_t
     596           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_execrp_tile_t)
     597             : 
     598           0 : #define STEM_CALLBACK_METRICS_WRITE   metrics_write
     599           0 : #define STEM_CALLBACK_AFTER_CREDIT    after_credit
     600           0 : #define STEM_CALLBACK_RETURNABLE_FRAG returnable_frag
     601             : 
     602             : #include "../../disco/stem/fd_stem.c"
     603             : 
     604             : static ulong
     605           0 : max_event_sz( fd_topo_tile_t const * tile ) {
     606             :   /* execrp emits accdb_partition_added, plus runtime_txn when diffs are on. */
     607           0 :   ulong sz = sizeof(fd_event_accdb_partition_added_t);
     608           0 :   if( tile->execrp.report_runtime_diffs && sizeof(fd_event_runtime_txn_t)>sz ) sz = sizeof(fd_event_runtime_txn_t);
     609           0 :   return sz;
     610           0 : }
     611             : 
     612             : fd_topo_run_tile_t fd_tile_execrp = {
     613             :   .name                     = "execrp",
     614             :   .max_event_sz             = max_event_sz,
     615             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     616             :   .populate_allowed_fds     = populate_allowed_fds,
     617             :   .scratch_align            = scratch_align,
     618             :   .scratch_footprint        = scratch_footprint,
     619             :   .privileged_init          = privileged_init,
     620             :   .unprivileged_init        = unprivileged_init,
     621             :   .run                      = stem_run,
     622             : };

Generated by: LCOV version 1.14