LCOV - code coverage report
Current view: top level - discof/exec - fd_exec_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 277 0.0 %
Date: 2026-01-17 04:55:09 Functions: 0 8 0.0 %

          Line data    Source code
       1             : #include "../../disco/tiles.h"
       2             : #include "generated/fd_exec_tile_seccomp.h"
       3             : 
       4             : #include "../../util/pod/fd_pod_format.h"
       5             : #include "../../discof/replay/fd_exec.h"
       6             : #include "../../flamenco/capture/fd_capture_ctx.h"
       7             : #include "../../flamenco/runtime/fd_bank.h"
       8             : #include "../../flamenco/runtime/fd_runtime.h"
       9             : #include "../../flamenco/runtime/fd_acc_pool.h"
      10             : #include "../../flamenco/accdb/fd_accdb_impl_v1.h"
      11             : #include "../../flamenco/accdb/fd_accdb_impl_v2.h"
      12             : #include "../../flamenco/progcache/fd_progcache_user.h"
      13             : #include "../../flamenco/log_collector/fd_log_collector.h"
      14             : #include "../../disco/metrics/fd_metrics.h"
      15             : 
      16             : /* The exec tile is responsible for executing single transactions. The
      17             :    tile receives a parsed transaction (fd_txn_p_t) and an identifier to
      18             :    which bank to execute against (index into the bank pool). With this,
      19             :    the exec tile is able to identify the correct bank and accounts db
      20             :    handle (funk_txn) to execute the transaction against.  The exec tile
      21             :    then commits the results of the transaction to the accounts db and
      22             :    makes any necessary updates to the bank. */
      23             : 
      24             : typedef struct link_ctx {
      25             :   ulong       idx;
      26             :   fd_wksp_t * mem;
      27             :   ulong       chunk;
      28             :   ulong       chunk0;
      29             :   ulong       wmark;
      30             : } link_ctx_t;
      31             : 
      32             : typedef struct fd_exec_tile_ctx {
      33             :   ulong                 tile_idx;
      34             : 
      35             :   /* link-related data structures. */
      36             :   link_ctx_t            replay_in[ 1 ];
      37             :   link_ctx_t            exec_replay_out[ 1 ]; /* TODO: Remove with solcap v2 */
      38             :   link_ctx_t            exec_sig_out[ 1 ];
      39             : 
      40             :   fd_sha512_t           sha_mem[ FD_TXN_ACTUAL_SIG_MAX ];
      41             :   fd_sha512_t *         sha_lj[ FD_TXN_ACTUAL_SIG_MAX ];
      42             : 
      43             :   /* Capture context for debugging runtime execution. */
      44             :   fd_capture_ctx_t *    capture_ctx;
      45             :   fd_capture_link_buf_t cap_exec_out[1];
      46             : 
      47             :   /* A transaction can be executed as long as there is a valid handle to
      48             :      a funk_txn and a bank. These are queried from fd_banks_t and
      49             :      fd_funk_t. */
      50             :   fd_banks_t            banks[1];
      51             :   fd_bank_t             bank[1];
      52             :   fd_accdb_user_t       accdb[1];
      53             :   fd_progcache_t        progcache[1];
      54             : 
      55             :   fd_txncache_t *       txncache;
      56             : 
      57             :   ulong                 txn_idx;
      58             :   ulong                 slot;
      59             :   ulong                 dispatch_time_comp;
      60             : 
      61             :   fd_log_collector_t    log_collector;
      62             : 
      63             :   fd_acc_pool_t *       acc_pool;
      64             : 
      65             :   fd_txn_in_t           txn_in;
      66             :   fd_txn_out_t          txn_out;
      67             : 
      68             :   /* tracing_mem is staging memory to dump instructions/transactions
      69             :      into protobuf files.  tracing_mem is staging memory to output vm
      70             :      execution traces.
      71             :      TODO: This should not be compiled in prod. */
      72             :   uchar                 dumping_mem[ FD_SPAD_FOOTPRINT( 1UL<<28UL ) ] __attribute__((aligned(FD_SPAD_ALIGN)));
      73             :   uchar                 tracing_mem[ FD_MAX_INSTRUCTION_STACK_DEPTH ][ FD_RUNTIME_VM_TRACE_STATIC_FOOTPRINT ] __attribute__((aligned(FD_RUNTIME_VM_TRACE_STATIC_ALIGN)));
      74             : 
      75             :   fd_runtime_t runtime[1];
      76             : 
      77             :   struct {
      78             :     /* Ticks spent preparing a txn (database reads, account copies) */
      79             :     ulong txn_setup_cum_ticks;
      80             : 
      81             :     /* Ticks spent executing a txn (includes any VM time) */
      82             :     ulong txn_exec_cum_ticks;
      83             : 
      84             :     /* Ticks spent committing a txn (database writes) */
      85             :     ulong txn_commit_cum_ticks;
      86             :   } metrics;
      87             : 
      88             : } fd_exec_tile_ctx_t;
      89             : 
      90             : FD_FN_CONST static inline ulong
      91           0 : scratch_align( void ) {
      92           0 :   return 128UL;
      93           0 : }
      94             : 
      95             : FD_FN_PURE static inline ulong
      96           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
      97           0 :   ulong l = FD_LAYOUT_INIT;
      98           0 :   l = FD_LAYOUT_APPEND( l, alignof(fd_exec_tile_ctx_t), sizeof(fd_exec_tile_ctx_t)                         );
      99           0 :   l = FD_LAYOUT_APPEND( l, fd_capture_ctx_align(),      fd_capture_ctx_footprint()                         );
     100           0 :   l = FD_LAYOUT_APPEND( l, fd_txncache_align(),         fd_txncache_footprint( tile->exec.max_live_slots ) );
     101           0 :   l = FD_LAYOUT_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN,  FD_PROGCACHE_SCRATCH_FOOTPRINT                     );
     102           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
     103           0 : }
     104             : 
     105             : static void
     106           0 : metrics_write( fd_exec_tile_ctx_t * ctx ) {
     107           0 :   fd_progcache_t * progcache = ctx->progcache;
     108           0 :   FD_MCNT_SET( EXEC, PROGCACHE_MISSES,        progcache->metrics->miss_cnt       );
     109           0 :   FD_MCNT_SET( EXEC, PROGCACHE_HITS,          progcache->metrics->hit_cnt        );
     110           0 :   FD_MCNT_SET( EXEC, PROGCACHE_FILLS,         progcache->metrics->fill_cnt       );
     111           0 :   FD_MCNT_SET( EXEC, PROGCACHE_FILL_TOT_SZ,   progcache->metrics->fill_tot_sz    );
     112           0 :   FD_MCNT_SET( EXEC, PROGCACHE_INVALIDATIONS, progcache->metrics->invalidate_cnt );
     113           0 :   FD_MCNT_SET( EXEC, PROGCACHE_DUP_INSERTS,   progcache->metrics->dup_insert_cnt );
     114             : 
     115           0 :   FD_MCNT_SET( EXEC, TXN_REGIME_SETUP,  ctx->metrics.txn_setup_cum_ticks   );
     116           0 :   FD_MCNT_SET( EXEC, TXN_REGIME_EXEC,   ctx->metrics.txn_exec_cum_ticks    );
     117           0 :   FD_MCNT_SET( EXEC, TXN_REGIME_COMMIT, ctx->metrics.txn_commit_cum_ticks  );
     118             : 
     119           0 :   fd_runtime_t const * runtime = ctx->runtime;
     120           0 :   ulong cpi_ticks  = runtime->metrics.cpi_setup_cum_ticks +
     121           0 :                      runtime->metrics.cpi_commit_cum_ticks;
     122           0 :   ulong exec_ticks = runtime->metrics.vm_exec_cum_ticks - cpi_ticks;
     123           0 :   FD_MCNT_SET( EXEC, VM_REGIME_SETUP,       runtime->metrics.vm_setup_cum_ticks   );
     124           0 :   FD_MCNT_SET( EXEC, VM_REGIME_COMMIT,      runtime->metrics.vm_commit_cum_ticks  );
     125           0 :   FD_MCNT_SET( EXEC, VM_REGIME_SETUP_CPI,   runtime->metrics.cpi_setup_cum_ticks  );
     126           0 :   FD_MCNT_SET( EXEC, VM_REGIME_COMMIT_CPI,  runtime->metrics.cpi_commit_cum_ticks );
     127           0 :   FD_MCNT_SET( EXEC, VM_REGIME_INTERPRETER, exec_ticks                            );
     128             : 
     129           0 :   fd_accdb_user_t * accdb = ctx->accdb;
     130           0 :   FD_MCNT_SET( EXEC, ACCDB_CREATED, accdb->base.created_cnt );
     131             : 
     132           0 :   FD_STATIC_ASSERT( sizeof(runtime->metrics.txn_account_save)/sizeof(ulong)==FD_METRICS_ENUM_ACCOUNT_CHANGE_CNT, enum );
     133           0 :   FD_MCNT_ENUM_COPY( EXEC, TXN_ACCOUNT_CHANGES, runtime->metrics.txn_account_save );
     134           0 : }
     135             : 
     136             : /* Publish the txn finalized message to the replay tile */
     137             : static void
     138             : publish_txn_finalized_msg( fd_exec_tile_ctx_t * ctx,
     139           0 :                            fd_stem_context_t *  stem ) {
     140           0 :   fd_exec_task_done_msg_t * msg  = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
     141           0 :   msg->bank_idx                  = ctx->bank->data->idx;
     142           0 :   msg->txn_exec->txn_idx         = ctx->txn_idx;
     143           0 :   msg->txn_exec->err             = !ctx->txn_out.err.is_committable;
     144           0 :   msg->txn_exec->slot            = ctx->slot;
     145           0 :   msg->txn_exec->start_shred_idx = ctx->txn_in.txn->start_shred_idx;
     146           0 :   msg->txn_exec->end_shred_idx   = ctx->txn_in.txn->end_shred_idx;
     147           0 :   if( FD_UNLIKELY( msg->txn_exec->err ) ) {
     148           0 :     uchar * signature = (uchar *)ctx->txn_in.txn->payload + TXN( ctx->txn_in.txn )->signature_off;
     149           0 :     FD_BASE58_ENCODE_64_BYTES( signature, signature_b58 );
     150           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 ));
     151           0 :   }
     152             : 
     153           0 :   fd_stem_publish( stem, ctx->exec_replay_out->idx, (FD_EXEC_TT_TXN_EXEC<<32)|ctx->tile_idx, ctx->exec_replay_out->chunk, sizeof(*msg), 0UL, ctx->dispatch_time_comp, fd_frag_meta_ts_comp( fd_tickcount() ) );
     154             : 
     155           0 :   ctx->exec_replay_out->chunk = fd_dcache_compact_next( ctx->exec_replay_out->chunk, sizeof(*msg), ctx->exec_replay_out->chunk0, ctx->exec_replay_out->wmark );
     156           0 : }
     157             : 
     158             : static inline int
     159             : returnable_frag( fd_exec_tile_ctx_t * ctx,
     160             :                  ulong                in_idx,
     161             :                  ulong                seq FD_PARAM_UNUSED,
     162             :                  ulong                sig,
     163             :                  ulong                chunk,
     164             :                  ulong                sz,
     165             :                  ulong                ctl FD_PARAM_UNUSED,
     166             :                  ulong                tsorig FD_PARAM_UNUSED,
     167             :                  ulong                tspub,
     168           0 :                  fd_stem_context_t *  stem ) {
     169             : 
     170           0 :   if( (sig&0xFFFFFFFFUL)!=ctx->tile_idx ) return 0;
     171             : 
     172           0 :   if( FD_LIKELY( in_idx==ctx->replay_in->idx ) ) {
     173           0 :     if( FD_UNLIKELY( chunk < ctx->replay_in->chunk0 || chunk > ctx->replay_in->wmark ) ) {
     174           0 :       FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->replay_in->chunk0, ctx->replay_in->wmark ));
     175           0 :     }
     176           0 :     switch( sig>>32 ) {
     177           0 :       case FD_EXEC_TT_TXN_EXEC: {
     178             :         /* Execute. */
     179           0 :         fd_exec_txn_exec_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
     180           0 :         FD_TEST( fd_banks_bank_query( ctx->bank, ctx->banks, msg->bank_idx ) );
     181           0 :         ctx->txn_in.txn = &msg->txn;
     182             : 
     183             :         /* Set the capture txn index from the message so account updates
     184             :            during commit are recorded with the correct transaction index. */
     185           0 :         if( FD_UNLIKELY( ctx->capture_ctx ) ) {
     186           0 :           ctx->capture_ctx->current_txn_idx = msg->capture_txn_idx;
     187           0 :         }
     188             : 
     189           0 :         fd_runtime_prepare_and_execute_txn( ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
     190             : 
     191           0 :         if( FD_LIKELY( ctx->txn_out.err.is_committable ) ) {
     192           0 :           fd_runtime_commit_txn( ctx->runtime, ctx->bank, &ctx->txn_out );
     193           0 :         } else {
     194           0 :           fd_runtime_cancel_txn( ctx->runtime, &ctx->txn_out );
     195           0 :         }
     196             : 
     197           0 :         if( FD_UNLIKELY( ctx->accdb->base.ro_active ||
     198           0 :                          ctx->accdb->base.rw_active ) ) {
     199           0 :           FD_LOG_HEXDUMP_NOTICE(( "txn", msg->txn.payload, msg->txn.payload_sz ));
     200           0 :           FD_BASE58_ENCODE_64_BYTES( fd_txn_get_signatures( TXN( &msg->txn ), msg->txn.payload )[0], txn_b58 );
     201           0 :           FD_LOG_CRIT(( "detected account leaks after executing txn=%s (commit=%d ro_active=%lu rw_active=%lu)",
     202           0 :                         txn_b58, ctx->txn_out.err.is_committable,
     203           0 :                         ctx->accdb->base.ro_active, ctx->accdb->base.rw_active ));
     204           0 :         }
     205             : 
     206           0 :         if( FD_LIKELY( ctx->exec_sig_out->idx!=ULONG_MAX ) ) {
     207             :           /* Copy the txn signature to the signature out link so the
     208             :              dedup/pack tiles can drop already executed transactions. */
     209           0 :           memcpy( fd_chunk_to_laddr( ctx->exec_sig_out->mem, ctx->exec_sig_out->chunk ),
     210           0 :                   (uchar *)ctx->txn_in.txn->payload + TXN( ctx->txn_in.txn )->signature_off,
     211           0 :                   64UL );
     212           0 :           fd_stem_publish( stem, ctx->exec_sig_out->idx, 0UL, ctx->exec_sig_out->chunk, 64UL, 0UL, 0UL, 0UL );
     213           0 :           ctx->exec_sig_out->chunk = fd_dcache_compact_next( ctx->exec_sig_out->chunk, 64UL, ctx->exec_sig_out->chunk0, ctx->exec_sig_out->wmark );
     214           0 :         }
     215             : 
     216             :         /* Notify replay. */
     217           0 :         ctx->txn_idx = msg->txn_idx;
     218           0 :         ctx->dispatch_time_comp = tspub;
     219           0 :         ctx->slot = fd_bank_slot_get( ctx->bank );
     220           0 :         publish_txn_finalized_msg( ctx, stem );
     221             : 
     222             :         /* Update metrics */
     223           0 :         ulong setup_dt  = (ulong)ctx->txn_out.details.exec_start_timestamp   - (ulong)ctx->txn_out.details.prep_start_timestamp;
     224           0 :         ulong exec_dt   = (ulong)ctx->txn_out.details.commit_start_timestamp - (ulong)ctx->txn_out.details.exec_start_timestamp;
     225           0 :         ulong commit_dt = (ulong)fd_tickcount()                              - (ulong)ctx->txn_out.details.commit_start_timestamp;
     226           0 :         if( FD_UNLIKELY( ctx->txn_out.details.prep_start_timestamp==LONG_MAX ) ) {
     227           0 :           setup_dt = 0UL;
     228           0 :         }
     229           0 :         if( FD_UNLIKELY( ctx->txn_out.details.exec_start_timestamp==LONG_MAX ) ) {
     230           0 :           setup_dt = 0UL;
     231           0 :           exec_dt  = 0UL;
     232           0 :         }
     233           0 :         if( FD_UNLIKELY( ctx->txn_out.details.commit_start_timestamp==LONG_MAX ) ) {
     234           0 :           commit_dt = 0UL;
     235           0 :         }
     236           0 :         ctx->metrics.txn_setup_cum_ticks  += setup_dt;
     237           0 :         ctx->metrics.txn_exec_cum_ticks   += exec_dt;
     238           0 :         ctx->metrics.txn_commit_cum_ticks += commit_dt;
     239             : 
     240           0 :         break;
     241           0 :       }
     242           0 :       case FD_EXEC_TT_TXN_SIGVERIFY: {
     243           0 :         fd_exec_txn_sigverify_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
     244           0 :         int res = fd_executor_txn_verify( &msg->txn, ctx->sha_lj );
     245           0 :         fd_exec_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
     246           0 :         out_msg->bank_idx               = msg->bank_idx;
     247           0 :         out_msg->txn_sigverify->txn_idx = msg->txn_idx;
     248           0 :         out_msg->txn_sigverify->err     = (res!=FD_RUNTIME_EXECUTE_SUCCESS);
     249           0 :         fd_stem_publish( stem, ctx->exec_replay_out->idx, (FD_EXEC_TT_TXN_SIGVERIFY<<32)|ctx->tile_idx, ctx->exec_replay_out->chunk, sizeof(*out_msg), 0UL, 0UL, 0UL );
     250           0 :         ctx->exec_replay_out->chunk = fd_dcache_compact_next( ctx->exec_replay_out->chunk, sizeof(*out_msg), ctx->exec_replay_out->chunk0, ctx->exec_replay_out->wmark );
     251           0 :         break;
     252           0 :       }
     253           0 :       default: FD_LOG_CRIT(( "unexpected signature %lu", sig ));
     254           0 :     }
     255           0 :   } else FD_LOG_CRIT(( "invalid in_idx %lu", in_idx ));
     256             : 
     257           0 :   return 0;
     258           0 : }
     259             : 
     260             : static void
     261             : unprivileged_init( fd_topo_t *      topo,
     262           0 :                    fd_topo_tile_t * tile ) {
     263             : 
     264             :   /********************************************************************/
     265             :   /* validate allocations                                             */
     266             :   /********************************************************************/
     267             : 
     268           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     269             : 
     270           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     271           0 :   fd_exec_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_tile_ctx_t), sizeof(fd_exec_tile_ctx_t) );
     272             : 
     273           0 :   void * capture_ctx_mem   = FD_SCRATCH_ALLOC_APPEND( l, fd_capture_ctx_align(),      fd_capture_ctx_footprint() );
     274           0 :   void * _txncache         = FD_SCRATCH_ALLOC_APPEND( l, fd_txncache_align(),         fd_txncache_footprint( tile->exec.max_live_slots ) );
     275           0 :   uchar * pc_scratch       = FD_SCRATCH_ALLOC_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN,  FD_PROGCACHE_SCRATCH_FOOTPRINT );
     276           0 :   ulong  scratch_alloc_mem = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     277             : 
     278           0 :   if( FD_UNLIKELY( scratch_alloc_mem - (ulong)scratch  - scratch_footprint( tile ) ) ) {
     279           0 :     FD_LOG_ERR( ( "Scratch_alloc_mem did not match scratch_footprint diff: %lu alloc: %lu footprint: %lu",
     280           0 :       scratch_alloc_mem - (ulong)scratch - scratch_footprint( tile ),
     281           0 :       scratch_alloc_mem,
     282           0 :       (ulong)scratch + scratch_footprint( tile ) ) );
     283           0 :   }
     284             : 
     285           0 :   for( ulong i=0UL; i<FD_TXN_ACTUAL_SIG_MAX; i++ ) {
     286           0 :     fd_sha512_t * sha = fd_sha512_join( fd_sha512_new( ctx->sha_mem+i ) );
     287           0 :     FD_TEST( sha );
     288           0 :     ctx->sha_lj[i] = sha;
     289           0 :   }
     290             : 
     291             :   /********************************************************************/
     292             :   /* validate links                                                   */
     293             :   /********************************************************************/
     294             : 
     295           0 :   ctx->tile_idx = tile->kind_id;
     296             : 
     297             :   /* First find and setup the in-link from replay to exec. */
     298           0 :   ctx->replay_in->idx = fd_topo_find_tile_in_link( topo, tile, "replay_exec", 0UL );
     299           0 :   FD_TEST( ctx->replay_in->idx!=ULONG_MAX );
     300           0 :   fd_topo_link_t * replay_in_link = &topo->links[ tile->in_link_id[ ctx->replay_in->idx ] ];
     301           0 :   FD_TEST( replay_in_link!=NULL );
     302           0 :   ctx->replay_in->mem    = topo->workspaces[ topo->objs[ replay_in_link->dcache_obj_id ].wksp_id ].wksp;
     303           0 :   ctx->replay_in->chunk0 = fd_dcache_compact_chunk0( ctx->replay_in->mem, replay_in_link->dcache );
     304           0 :   ctx->replay_in->wmark  = fd_dcache_compact_wmark( ctx->replay_in->mem, replay_in_link->dcache, replay_in_link->mtu );
     305           0 :   ctx->replay_in->chunk  = ctx->replay_in->chunk0;
     306             : 
     307           0 :   ctx->exec_replay_out->idx = fd_topo_find_tile_out_link( topo, tile, "exec_replay", ctx->tile_idx );
     308           0 :   if( FD_LIKELY( ctx->exec_replay_out->idx!=ULONG_MAX ) ) {
     309           0 :     fd_topo_link_t * exec_replay_link = &topo->links[ tile->out_link_id[ ctx->exec_replay_out->idx ] ];
     310           0 :     ctx->exec_replay_out->mem    = topo->workspaces[ topo->objs[ exec_replay_link->dcache_obj_id ].wksp_id ].wksp;
     311           0 :     ctx->exec_replay_out->chunk0 = fd_dcache_compact_chunk0( ctx->exec_replay_out->mem, exec_replay_link->dcache );
     312           0 :     ctx->exec_replay_out->wmark  = fd_dcache_compact_wmark( ctx->exec_replay_out->mem, exec_replay_link->dcache, exec_replay_link->mtu );
     313           0 :     ctx->exec_replay_out->chunk  = ctx->exec_replay_out->chunk0;
     314           0 :   }
     315             : 
     316           0 :   ctx->exec_sig_out->idx = fd_topo_find_tile_out_link( topo, tile, "exec_sig", ctx->tile_idx );
     317           0 :   if( FD_LIKELY( ctx->exec_sig_out->idx!=ULONG_MAX ) ) {
     318           0 :     fd_topo_link_t * exec_sig_link = &topo->links[ tile->out_link_id[ ctx->exec_sig_out->idx ] ];
     319           0 :     ctx->exec_sig_out->mem    = topo->workspaces[ topo->objs[ exec_sig_link->dcache_obj_id ].wksp_id ].wksp;
     320           0 :     ctx->exec_sig_out->chunk0 = fd_dcache_compact_chunk0( ctx->exec_sig_out->mem, exec_sig_link->dcache );
     321           0 :     ctx->exec_sig_out->wmark  = fd_dcache_compact_wmark( ctx->exec_sig_out->mem, exec_sig_link->dcache, exec_sig_link->mtu );
     322           0 :     ctx->exec_sig_out->chunk  = ctx->exec_sig_out->chunk0;
     323           0 :   }
     324             : 
     325             :   /********************************************************************/
     326             :   /* banks                                                            */
     327             :   /********************************************************************/
     328             : 
     329           0 :   ulong banks_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "banks" );
     330           0 :   if( FD_UNLIKELY( banks_obj_id==ULONG_MAX ) ) {
     331           0 :     FD_LOG_ERR(( "Could not find topology object for banks" ));
     332           0 :   }
     333             : 
     334           0 :   ulong banks_locks_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "banks_locks" );
     335           0 :   if( FD_UNLIKELY( banks_locks_obj_id==ULONG_MAX ) ) {
     336           0 :     FD_LOG_ERR(( "Could not find topology object for banks_locks" ));
     337           0 :   }
     338             : 
     339           0 :   if( FD_UNLIKELY( !fd_banks_join( ctx->banks, fd_topo_obj_laddr( topo, banks_obj_id ), fd_topo_obj_laddr( topo, banks_locks_obj_id ) ) ) ) {
     340           0 :     FD_LOG_ERR(( "Failed to join banks" ));
     341           0 :   }
     342             : 
     343           0 :   fd_topo_obj_t const * vinyl_data = fd_topo_find_tile_obj( topo, tile, "vinyl_data" );
     344           0 :   if( !vinyl_data ) {
     345           0 :     FD_TEST( fd_accdb_user_v1_init( ctx->accdb, fd_topo_obj_laddr( topo, tile->exec.funk_obj_id ) ) );
     346           0 :   } else {
     347           0 :     fd_topo_obj_t const * vinyl_rq       = fd_topo_find_tile_obj( topo, tile, "vinyl_rq"    );
     348           0 :     fd_topo_obj_t const * vinyl_req_pool = fd_topo_find_tile_obj( topo, tile, "vinyl_rpool" );
     349           0 :     FD_TEST( fd_accdb_user_v2_init( ctx->accdb,
     350           0 :         fd_topo_obj_laddr( topo, tile->exec.funk_obj_id ),
     351           0 :         fd_topo_obj_laddr( topo, vinyl_rq->id ),
     352           0 :         topo->workspaces[ vinyl_data->wksp_id ].wksp,
     353           0 :         fd_topo_obj_laddr( topo, vinyl_req_pool->id ),
     354           0 :         vinyl_rq->id ) );
     355           0 :   }
     356             : 
     357           0 :   void * shprogcache = fd_topo_obj_laddr( topo, tile->exec.progcache_obj_id );
     358           0 :   if( FD_UNLIKELY( !fd_progcache_join( ctx->progcache, shprogcache, pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT ) ) ) {
     359           0 :     FD_LOG_CRIT(( "fd_progcache_join() failed" ));
     360           0 :   }
     361             : 
     362           0 :   void * _txncache_shmem = fd_topo_obj_laddr( topo, tile->exec.txncache_obj_id );
     363           0 :   fd_txncache_shmem_t * txncache_shmem = fd_txncache_shmem_join( _txncache_shmem );
     364           0 :   FD_TEST( txncache_shmem );
     365           0 :   ctx->txncache = fd_txncache_join( fd_txncache_new( _txncache, txncache_shmem ) );
     366           0 :   FD_TEST( ctx->txncache );
     367             : 
     368           0 :   ctx->txn_in.bundle.is_bundle = 0;
     369             : 
     370             :   /********************************************************************/
     371             :   /* Accounts pool                                                     */
     372             :   /********************************************************************/
     373             : 
     374           0 :   ctx->acc_pool = fd_acc_pool_join( fd_topo_obj_laddr( topo, tile->exec.acc_pool_obj_id ) );
     375           0 :   if( FD_UNLIKELY( !ctx->acc_pool ) ) {
     376           0 :     FD_LOG_CRIT(( "Failed to join acc pool" ));
     377           0 :   }
     378             : 
     379             :   /********************************************************************/
     380             :   /* Capture context                                                 */
     381             :   /********************************************************************/
     382             : 
     383           0 :   ctx->capture_ctx               = NULL;
     384           0 :   if( FD_UNLIKELY( strlen( tile->exec.solcap_capture ) || strlen( tile->exec.dump_proto_dir ) ) ) {
     385             : 
     386           0 :     ulong tile_idx = tile->kind_id;
     387           0 :     ulong idx = fd_topo_find_tile_out_link( topo, tile, "cap_exec", tile_idx );
     388           0 :     FD_TEST( idx!=ULONG_MAX );
     389           0 :     fd_topo_link_t * link = &topo->links[ tile->out_link_id[ idx ] ];
     390           0 :     fd_capture_link_buf_t * cap_exec_out = ctx->cap_exec_out;
     391           0 :     cap_exec_out->base.vt = &fd_capture_link_buf_vt;
     392           0 :     cap_exec_out->idx     = idx;
     393           0 :     cap_exec_out->mem     = topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ].wksp;
     394           0 :     cap_exec_out->chunk0  = fd_dcache_compact_chunk0( cap_exec_out->mem, link->dcache );
     395           0 :     cap_exec_out->wmark   = fd_dcache_compact_wmark( cap_exec_out->mem, link->dcache, link->mtu );
     396           0 :     cap_exec_out->chunk   = cap_exec_out->chunk0;
     397           0 :     cap_exec_out->mcache  = link->mcache;
     398           0 :     cap_exec_out->depth   = fd_mcache_depth( link->mcache );
     399           0 :     cap_exec_out->seq     = 0UL;
     400             : 
     401           0 :     ulong consumer_tile_idx = fd_topo_find_tile(topo, "solcap", 0UL);
     402           0 :     fd_topo_tile_t * consumer_tile = &topo->tiles[ consumer_tile_idx ];
     403           0 :     cap_exec_out->fseq = NULL;
     404           0 :     for( ulong j = 0UL; j < consumer_tile->in_cnt; j++ ) {
     405           0 :       if( FD_UNLIKELY( consumer_tile->in_link_id[ j ]  == link->id ) ) {
     406           0 :         cap_exec_out->fseq = fd_fseq_join( fd_topo_obj_laddr( topo, consumer_tile->in_link_fseq_obj_id[ j ] ) );
     407           0 :         FD_TEST( cap_exec_out->fseq );
     408           0 :         break;
     409           0 :       }
     410           0 :     }
     411             : 
     412           0 :     ctx->capture_ctx = fd_capture_ctx_join( fd_capture_ctx_new( capture_ctx_mem ) );
     413           0 :     ctx->capture_ctx->solcap_start_slot = tile->exec.capture_start_slot;
     414             : 
     415           0 :     if( strlen( tile->exec.dump_proto_dir ) ) {
     416           0 :       ctx->capture_ctx->dump_proto_output_dir = tile->exec.dump_proto_dir;
     417           0 :       ctx->capture_ctx->dump_proto_start_slot = tile->exec.capture_start_slot;
     418           0 :       ctx->capture_ctx->dump_instr_to_pb      = tile->exec.dump_instr_to_pb;
     419           0 :       ctx->capture_ctx->dump_txn_to_pb        = tile->exec.dump_txn_to_pb;
     420           0 :       ctx->capture_ctx->dump_syscall_to_pb    = tile->exec.dump_syscall_to_pb;
     421           0 :       ctx->capture_ctx->dump_elf_to_pb        = tile->exec.dump_elf_to_pb;
     422           0 :     }
     423             : 
     424           0 :     ctx->capture_ctx->capctx_type.buf = cap_exec_out;
     425           0 :     ctx->capture_ctx->capture_link    = &cap_exec_out->base;
     426           0 :   }
     427             : 
     428             :   /********************************************************************/
     429             :   /* Runtime                                                          */
     430             :   /********************************************************************/
     431             : 
     432           0 :   ctx->runtime->accdb                    = ctx->accdb;
     433           0 :   ctx->runtime->progcache                = ctx->progcache;
     434           0 :   ctx->runtime->status_cache             = ctx->txncache;
     435           0 :   ctx->runtime->acc_pool                 = ctx->acc_pool;
     436           0 :   ctx->runtime->log.log_collector        = &ctx->log_collector;
     437           0 :   ctx->runtime->log.enable_log_collector = 0;
     438           0 :   ctx->runtime->log.dumping_mem          = ctx->dumping_mem;
     439           0 :   ctx->runtime->log.enable_vm_tracing    = 0;
     440           0 :   ctx->runtime->log.tracing_mem          = &ctx->tracing_mem[0][0];
     441           0 :   ctx->runtime->log.capture_ctx          = ctx->capture_ctx;
     442             : 
     443           0 :   memset( &ctx->metrics,          0, sizeof(ctx->metrics)          );
     444           0 :   memset( &ctx->runtime->metrics, 0, sizeof(ctx->runtime->metrics) );
     445           0 : }
     446             : 
     447             : static ulong
     448             : populate_allowed_seccomp( fd_topo_t const *      topo FD_PARAM_UNUSED,
     449             :                           fd_topo_tile_t const * tile FD_PARAM_UNUSED,
     450             :                           ulong                  out_cnt,
     451           0 :                           struct sock_filter *   out ) {
     452           0 :   populate_sock_filter_policy_fd_exec_tile( out_cnt, out, (uint)fd_log_private_logfile_fd() );
     453           0 :   return sock_filter_policy_fd_exec_tile_instr_cnt;
     454           0 : }
     455             : 
     456             : static ulong
     457             : populate_allowed_fds( fd_topo_t const *      topo FD_PARAM_UNUSED,
     458             :                       fd_topo_tile_t const * tile FD_PARAM_UNUSED,
     459             :                       ulong                  out_fds_cnt,
     460           0 :                       int *                  out_fds ) {
     461             : 
     462           0 :   if( FD_UNLIKELY( out_fds_cnt<2UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
     463             : 
     464           0 :   ulong out_cnt = 0UL;
     465           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
     466           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
     467           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     468           0 :   return out_cnt;
     469           0 : }
     470             : 
     471           0 : #define STEM_BURST (2UL)
     472             : /* Right now, depth of the replay_exec link and depth of the exec_replay
     473             :    links is 16K.  At 1M TPS, that's ~16ms to fill.  But we also want to
     474             :    be conservative here, so we use 1ms. */
     475           0 : #define STEM_LAZY  (1000000UL)
     476             : 
     477           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_exec_tile_ctx_t
     478           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_exec_tile_ctx_t)
     479             : 
     480           0 : #define STEM_CALLBACK_RETURNABLE_FRAG returnable_frag
     481           0 : #define STEM_CALLBACK_METRICS_WRITE   metrics_write
     482             : 
     483             : #include "../../disco/stem/fd_stem.c"
     484             : 
     485             : fd_topo_run_tile_t fd_tile_execor = {
     486             :   .name                     = "exec",
     487             :   .loose_footprint          = 0UL,
     488             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     489             :   .populate_allowed_fds     = populate_allowed_fds,
     490             :   .scratch_align            = scratch_align,
     491             :   .scratch_footprint        = scratch_footprint,
     492             :   .unprivileged_init        = unprivileged_init,
     493             :   .run                      = stem_run,
     494             : };

Generated by: LCOV version 1.14