LCOV - code coverage report
Current view: top level - discof/exec - fd_exec_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 233 0.0 %
Date: 2025-10-27 04:40:00 Functions: 0 10 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/runtime/context/fd_capture_ctx.h"
       7             : #include "../../flamenco/runtime/fd_bank.h"
       8             : #include "../../flamenco/runtime/fd_runtime.h"
       9             : #include "../../disco/metrics/fd_metrics.h"
      10             : 
      11             : #include "../../funk/fd_funk.h"
      12             : 
      13             : /* The exec tile is responsible for executing single transactions. The
      14             :    tile recieves a parsed transaction (fd_txn_p_t) and an identifier to
      15             :    which bank to execute against (index into the bank pool). With this,
      16             :    the exec tile is able to identify the correct bank and accounts db
      17             :    handle (funk_txn) to execute the transaction against.  The exec tile
      18             :    then commits the results of the transaction to the accounts db and
      19             :    makes any necessary updates to the bank. */
      20             : 
      21             : typedef struct link_ctx {
      22             :   ulong       idx;
      23             :   fd_wksp_t * mem;
      24             :   ulong       chunk;
      25             :   ulong       chunk0;
      26             :   ulong       wmark;
      27             : } link_ctx_t;
      28             : 
      29             : typedef struct fd_exec_tile_ctx {
      30             : 
      31             :   ulong                 tile_idx;
      32             : 
      33             :   /* link-related data structures. */
      34             :   link_ctx_t            replay_in[ 1 ];
      35             :   link_ctx_t            exec_replay_out[ 1 ]; /* TODO: Remove with solcap v2 */
      36             : 
      37             :   fd_sha512_t           sha_mem[ FD_TXN_ACTUAL_SIG_MAX ];
      38             :   fd_sha512_t *         sha_lj[ FD_TXN_ACTUAL_SIG_MAX ];
      39             : 
      40             :   fd_bank_hash_cmp_t *  bank_hash_cmp;
      41             : 
      42             :   fd_spad_t *           exec_spad;
      43             :   fd_wksp_t *           exec_spad_wksp;
      44             : 
      45             :   /* Data structures related to managing and executing the transaction.
      46             :      The fd_txn_p_t is refreshed with every transaction and is sent
      47             :      from the dispatch/replay tile.  The fd_exec_txn_ctx_t * is a valid
      48             :      local join that lives in the top-most frame of the spad that is
      49             :      setup when the exec tile is booted; its members are refreshed on
      50             :      the slot/epoch boundary. */
      51             :   fd_exec_txn_ctx_t *   txn_ctx;
      52             : 
      53             :   /* Capture context for debugging runtime execution. */
      54             :   fd_capture_ctx_t *    capture_ctx;
      55             :   uchar *               solcap_publish_buffer_ptr;
      56             :   ulong                 account_updates_flushed;
      57             : 
      58             :   /* A transaction can be executed as long as there is a valid handle to
      59             :      a funk_txn and a bank. These are queried from fd_banks_t and
      60             :      fd_funk_t. */
      61             :   fd_banks_t *          banks;
      62             :   fd_funk_t             funk[1];
      63             :   fd_progcache_t        progcache[1];
      64             : 
      65             :   fd_txncache_t *       txncache;
      66             : 
      67             :   /* We need to ensure that all solcap updates have been published
      68             :      before this message. */
      69             :   int                   pending_txn_finalized_msg;
      70             :   ulong                 txn_idx;
      71             : } fd_exec_tile_ctx_t;
      72             : 
      73             : FD_FN_CONST static inline ulong
      74           0 : scratch_align( void ) {
      75           0 :   return 128UL;
      76           0 : }
      77             : 
      78             : FD_FN_PURE static inline ulong
      79           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
      80           0 :   ulong l = FD_LAYOUT_INIT;
      81           0 :   l = FD_LAYOUT_APPEND( l, alignof(fd_exec_tile_ctx_t), sizeof(fd_exec_tile_ctx_t)                         );
      82           0 :   l = FD_LAYOUT_APPEND( l, fd_capture_ctx_align(),      fd_capture_ctx_footprint()                         );
      83           0 :   l = FD_LAYOUT_APPEND( l, fd_txncache_align(),         fd_txncache_footprint( tile->exec.max_live_slots ) );
      84           0 :   l = FD_LAYOUT_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN,  FD_PROGCACHE_SCRATCH_FOOTPRINT                     );
      85           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
      86           0 : }
      87             : 
      88             : static void
      89           0 : metrics_write( fd_exec_tile_ctx_t * ctx ) {
      90           0 :   fd_progcache_t * progcache = ctx->progcache;
      91           0 :   FD_MCNT_SET( EXEC, PROGCACHE_MISSES,        progcache->metrics->miss_cnt       );
      92           0 :   FD_MCNT_SET( EXEC, PROGCACHE_HITS,          progcache->metrics->hit_cnt        );
      93           0 :   FD_MCNT_SET( EXEC, PROGCACHE_FILLS,         progcache->metrics->fill_cnt       );
      94           0 :   FD_MCNT_SET( EXEC, PROGCACHE_FILL_TOT_SZ,   progcache->metrics->fill_tot_sz    );
      95           0 :   FD_MCNT_SET( EXEC, PROGCACHE_INVALIDATIONS, progcache->metrics->invalidate_cnt );
      96           0 :   FD_MCNT_SET( EXEC, PROGCACHE_DUP_INSERTS,   progcache->metrics->dup_insert_cnt );
      97           0 : }
      98             : 
      99             : static inline int
     100             : returnable_frag( fd_exec_tile_ctx_t * ctx,
     101             :                  ulong                in_idx,
     102             :                  ulong                seq FD_PARAM_UNUSED,
     103             :                  ulong                sig,
     104             :                  ulong                chunk,
     105             :                  ulong                sz,
     106             :                  ulong                ctl FD_PARAM_UNUSED,
     107             :                  ulong                tsorig FD_PARAM_UNUSED,
     108             :                  ulong                tspub FD_PARAM_UNUSED,
     109           0 :                  fd_stem_context_t *  stem ) {
     110             : 
     111           0 :   if( (sig&0xFFFFFFFFUL)!=ctx->tile_idx ) return 0;
     112             : 
     113           0 :   if( FD_LIKELY( in_idx==ctx->replay_in->idx ) ) {
     114           0 :     if( FD_UNLIKELY( chunk < ctx->replay_in->chunk0 || chunk > ctx->replay_in->wmark ) ) {
     115           0 :       FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->replay_in->chunk0, ctx->replay_in->wmark ));
     116           0 :     }
     117           0 :     switch( sig>>32 ) {
     118           0 :       case FD_EXEC_TT_TXN_EXEC: {
     119           0 :         FD_SPAD_FRAME_BEGIN( ctx->exec_spad ) {
     120             :         /* Execute. */
     121           0 :         fd_exec_txn_exec_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
     122           0 :         ctx->txn_ctx->exec_err = fd_runtime_prepare_and_execute_txn( ctx->banks, msg->bank_idx, ctx->txn_ctx, &msg->txn, ctx->capture_ctx );
     123             : 
     124             :         /* Commit. */
     125           0 :         fd_bank_t * bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
     126           0 :         if( FD_LIKELY( ctx->txn_ctx->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS ) ) {
     127           0 :           fd_funk_txn_xid_t xid = (fd_funk_txn_xid_t){ .ul = { fd_bank_slot_get( bank ), bank->idx } };
     128           0 :           fd_runtime_finalize_txn( ctx->funk, ctx->progcache, ctx->txncache, &xid, ctx->txn_ctx, bank, ctx->capture_ctx );
     129           0 :         }
     130             : 
     131             :         /* Notify replay. */
     132           0 :         ctx->txn_idx = msg->txn_idx;
     133           0 :         ctx->pending_txn_finalized_msg = 1;
     134             : 
     135           0 :         } FD_SPAD_FRAME_END;
     136           0 :         break;
     137           0 :       }
     138           0 :       case FD_EXEC_TT_TXN_SIGVERIFY: {
     139           0 :         fd_exec_txn_sigverify_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
     140           0 :         int res = fd_executor_txn_verify( &msg->txn, ctx->sha_lj );
     141           0 :         fd_exec_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
     142           0 :         out_msg->bank_idx               = msg->bank_idx;
     143           0 :         out_msg->txn_sigverify->txn_idx = msg->txn_idx;
     144           0 :         out_msg->txn_sigverify->err     = (res!=FD_RUNTIME_EXECUTE_SUCCESS);
     145           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 );
     146           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 );
     147           0 :         break;
     148           0 :       }
     149           0 :       default: FD_LOG_CRIT(( "unexpected signature %lu", sig ));
     150           0 :     }
     151           0 :   } else FD_LOG_CRIT(( "invalid in_idx %lu", in_idx ));
     152             : 
     153           0 :   return 0;
     154           0 : }
     155             : 
     156             : static void
     157             : unprivileged_init( fd_topo_t *      topo,
     158           0 :                    fd_topo_tile_t * tile ) {
     159             : 
     160             :   /********************************************************************/
     161             :   /* validate allocations                                             */
     162             :   /********************************************************************/
     163             : 
     164           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     165             : 
     166           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     167           0 :   fd_exec_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_tile_ctx_t), sizeof(fd_exec_tile_ctx_t) );
     168           0 :   void * capture_ctx_mem   = FD_SCRATCH_ALLOC_APPEND( l, fd_capture_ctx_align(),      fd_capture_ctx_footprint() );
     169           0 :   void * _txncache         = FD_SCRATCH_ALLOC_APPEND( l, fd_txncache_align(),         fd_txncache_footprint( tile->exec.max_live_slots ) );
     170           0 :   uchar * pc_scratch       = FD_SCRATCH_ALLOC_APPEND( l, FD_PROGCACHE_SCRATCH_ALIGN,  FD_PROGCACHE_SCRATCH_FOOTPRINT );
     171           0 :   ulong  scratch_alloc_mem = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     172             : 
     173           0 :   if( FD_UNLIKELY( scratch_alloc_mem - (ulong)scratch  - scratch_footprint( tile ) ) ) {
     174           0 :     FD_LOG_ERR( ( "Scratch_alloc_mem did not match scratch_footprint diff: %lu alloc: %lu footprint: %lu",
     175           0 :       scratch_alloc_mem - (ulong)scratch - scratch_footprint( tile ),
     176           0 :       scratch_alloc_mem,
     177           0 :       (ulong)scratch + scratch_footprint( tile ) ) );
     178           0 :   }
     179             : 
     180           0 :   for( ulong i=0UL; i<FD_TXN_ACTUAL_SIG_MAX; i++ ) {
     181           0 :     fd_sha512_t * sha = fd_sha512_join( fd_sha512_new( ctx->sha_mem+i ) );
     182           0 :     FD_TEST( sha );
     183           0 :     ctx->sha_lj[i] = sha;
     184           0 :   }
     185             : 
     186             :   /********************************************************************/
     187             :   /* validate links                                                   */
     188             :   /********************************************************************/
     189             : 
     190           0 :   ctx->tile_idx = tile->kind_id;
     191             : 
     192             :   /* First find and setup the in-link from replay to exec. */
     193           0 :   ctx->replay_in->idx = fd_topo_find_tile_in_link( topo, tile, "replay_exec", 0UL );
     194           0 :   FD_TEST( ctx->replay_in->idx!=ULONG_MAX );
     195           0 :   fd_topo_link_t * replay_in_link = &topo->links[ tile->in_link_id[ ctx->replay_in->idx ] ];
     196           0 :   FD_TEST( replay_in_link!=NULL );
     197           0 :   ctx->replay_in->mem    = topo->workspaces[ topo->objs[ replay_in_link->dcache_obj_id ].wksp_id ].wksp;
     198           0 :   ctx->replay_in->chunk0 = fd_dcache_compact_chunk0( ctx->replay_in->mem, replay_in_link->dcache );
     199           0 :   ctx->replay_in->wmark  = fd_dcache_compact_wmark( ctx->replay_in->mem, replay_in_link->dcache, replay_in_link->mtu );
     200           0 :   ctx->replay_in->chunk  = ctx->replay_in->chunk0;
     201             : 
     202           0 :   ctx->exec_replay_out->idx = fd_topo_find_tile_out_link( topo, tile, "exec_replay", ctx->tile_idx );
     203           0 :   if( FD_LIKELY( ctx->exec_replay_out->idx!=ULONG_MAX ) ) {
     204           0 :     fd_topo_link_t * exec_replay_link = &topo->links[ tile->out_link_id[ ctx->exec_replay_out->idx ] ];
     205           0 :     ctx->exec_replay_out->mem    = topo->workspaces[ topo->objs[ exec_replay_link->dcache_obj_id ].wksp_id ].wksp;
     206           0 :     ctx->exec_replay_out->chunk0 = fd_dcache_compact_chunk0( ctx->exec_replay_out->mem, exec_replay_link->dcache );
     207           0 :     ctx->exec_replay_out->wmark  = fd_dcache_compact_wmark( ctx->exec_replay_out->mem, exec_replay_link->dcache, exec_replay_link->mtu );
     208           0 :     ctx->exec_replay_out->chunk  = ctx->exec_replay_out->chunk0;
     209           0 :   }
     210             : 
     211             :   /********************************************************************/
     212             :   /* banks                                                            */
     213             :   /********************************************************************/
     214             : 
     215           0 :   ulong banks_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "banks" );
     216           0 :   if( FD_UNLIKELY( banks_obj_id==ULONG_MAX ) ) {
     217           0 :     FD_LOG_ERR(( "Could not find topology object for banks" ));
     218           0 :   }
     219             : 
     220           0 :   ctx->banks = fd_banks_join( fd_topo_obj_laddr( topo, banks_obj_id ) );
     221           0 :   if( FD_UNLIKELY( !ctx->banks ) ) {
     222           0 :     FD_LOG_ERR(( "Failed to join banks" ));
     223           0 :   }
     224             : 
     225             :   /********************************************************************/
     226             :   /* spad allocator                                                   */
     227             :   /********************************************************************/
     228             : 
     229           0 :   ulong exec_spad_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "exec_spad.%lu", ctx->tile_idx );
     230           0 :   if( FD_UNLIKELY( exec_spad_obj_id==ULONG_MAX ) ) {
     231           0 :     FD_LOG_ERR(( "Could not find topology object for exec spad" ));
     232           0 :   }
     233             : 
     234           0 :   ctx->exec_spad = fd_spad_join( fd_topo_obj_laddr( topo, exec_spad_obj_id ) );
     235           0 :   if( FD_UNLIKELY( !ctx->exec_spad ) ) {
     236           0 :     FD_LOG_ERR(( "Failed to join exec spad" ));
     237           0 :   }
     238           0 :   ctx->exec_spad_wksp = fd_wksp_containing( ctx->exec_spad );
     239             : 
     240             :   /********************************************************************/
     241             :   /* bank hash cmp                                                    */
     242             :   /********************************************************************/
     243             : 
     244           0 :   ulong bank_hash_cmp_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "bh_cmp" );
     245           0 :   if( FD_UNLIKELY( bank_hash_cmp_obj_id==ULONG_MAX ) ) {
     246           0 :     FD_LOG_ERR(( "Could not find topology object for bank hash cmp" ));
     247           0 :   }
     248           0 :   ctx->bank_hash_cmp = fd_bank_hash_cmp_join( fd_topo_obj_laddr( topo, bank_hash_cmp_obj_id ) );
     249           0 :   if( FD_UNLIKELY( !ctx->bank_hash_cmp ) ) {
     250           0 :     FD_LOG_ERR(( "Failed to join bank hash cmp" ));
     251           0 :   }
     252             : 
     253           0 :   void * shfunk = fd_topo_obj_laddr( topo, tile->exec.funk_obj_id );
     254           0 :   if( FD_UNLIKELY( !fd_funk_join( ctx->funk, shfunk ) ) ) {
     255           0 :     FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
     256           0 :   }
     257             : 
     258           0 :   void * shprogcache = fd_topo_obj_laddr( topo, tile->exec.progcache_obj_id );
     259           0 :   if( FD_UNLIKELY( !fd_progcache_join( ctx->progcache, shprogcache, pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT ) ) ) {
     260           0 :     FD_LOG_CRIT(( "fd_progcache_join() failed" ));
     261           0 :   }
     262             : 
     263           0 :   void * _txncache_shmem = fd_topo_obj_laddr( topo, tile->exec.txncache_obj_id );
     264           0 :   fd_txncache_shmem_t * txncache_shmem = fd_txncache_shmem_join( _txncache_shmem );
     265           0 :   FD_TEST( txncache_shmem );
     266           0 :   ctx->txncache = fd_txncache_join( fd_txncache_new( _txncache, txncache_shmem ) );
     267           0 :   FD_TEST( ctx->txncache );
     268             : 
     269             :   /********************************************************************/
     270             :   /* setup txn ctx                                                    */
     271             :   /********************************************************************/
     272             : 
     273           0 :   fd_spad_push( ctx->exec_spad );
     274           0 :   uchar * txn_ctx_mem         = fd_spad_alloc_check( ctx->exec_spad, FD_EXEC_TXN_CTX_ALIGN, FD_EXEC_TXN_CTX_FOOTPRINT );
     275           0 :   ctx->txn_ctx                = fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( txn_ctx_mem ), ctx->exec_spad, ctx->exec_spad_wksp );
     276           0 :   if( FD_UNLIKELY( !fd_funk_join( ctx->txn_ctx->funk, shfunk ) ) ) {
     277           0 :     FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
     278           0 :   }
     279           0 :   ctx->txn_ctx->progcache = fd_progcache_join( ctx->txn_ctx->_progcache, shprogcache, pc_scratch, FD_PROGCACHE_SCRATCH_FOOTPRINT );
     280           0 :   if( FD_UNLIKELY( !ctx->txn_ctx->progcache ) ) {
     281           0 :     FD_LOG_CRIT(( "fd_progcache_join() failed" ));
     282           0 :   }
     283           0 :   ctx->txn_ctx->status_cache  = ctx->txncache;
     284           0 :   ctx->txn_ctx->bank_hash_cmp = ctx->bank_hash_cmp;
     285           0 :   ctx->txn_ctx->spad          = ctx->exec_spad;
     286           0 :   ctx->txn_ctx->spad_wksp     = ctx->exec_spad_wksp;
     287             : 
     288             :   /********************************************************************/
     289             :   /* Capture context                                                 */
     290             :   /********************************************************************/
     291             : 
     292           0 :   ctx->capture_ctx               = NULL;
     293           0 :   ctx->solcap_publish_buffer_ptr = NULL;
     294           0 :   ctx->account_updates_flushed   = 0UL;
     295           0 :   if( FD_UNLIKELY( strlen( tile->exec.solcap_capture ) || strlen( tile->exec.dump_proto_dir ) ) ) {
     296           0 :     ctx->capture_ctx = fd_capture_ctx_join( fd_capture_ctx_new( capture_ctx_mem ) );
     297             : 
     298           0 :     if( strlen( tile->exec.dump_proto_dir ) ) {
     299           0 :       ctx->capture_ctx->dump_proto_output_dir = tile->exec.dump_proto_dir;
     300           0 :       ctx->capture_ctx->dump_proto_start_slot = tile->exec.capture_start_slot;
     301           0 :       ctx->capture_ctx->dump_instr_to_pb      = tile->exec.dump_instr_to_pb;
     302           0 :       ctx->capture_ctx->dump_txn_to_pb        = tile->exec.dump_txn_to_pb;
     303           0 :       ctx->capture_ctx->dump_syscall_to_pb    = tile->exec.dump_syscall_to_pb;
     304           0 :       ctx->capture_ctx->dump_elf_to_pb        = tile->exec.dump_elf_to_pb;
     305           0 :     }
     306             : 
     307           0 :     if( strlen( tile->exec.solcap_capture ) ) {
     308           0 :       ctx->capture_ctx->capture_txns      = 0;
     309           0 :       ctx->capture_ctx->solcap_start_slot = tile->exec.capture_start_slot;
     310           0 :       ctx->account_updates_flushed        = 0;
     311           0 :       ctx->solcap_publish_buffer_ptr      = ctx->capture_ctx->account_updates_buffer;
     312           0 :     }
     313           0 :   }
     314             : 
     315           0 :   ctx->pending_txn_finalized_msg = 0;
     316           0 : }
     317             : 
     318             : /* Publish the next account update event buffered in the capture tile to the replay tile
     319             : 
     320             :    TODO: remove this when solcap v2 is here. */
     321             : static void
     322             : publish_next_capture_ctx_account_update( fd_exec_tile_ctx_t * ctx,
     323           0 :                                          fd_stem_context_t *  stem ) {
     324           0 :   if( FD_UNLIKELY( !ctx->capture_ctx ) ) {
     325           0 :     return;
     326           0 :   }
     327             : 
     328             :   /* Copy the account update event to the buffer */
     329           0 :   ulong chunk     = ctx->exec_replay_out->chunk;
     330           0 :   uchar * out_ptr = fd_chunk_to_laddr( ctx->exec_replay_out->mem, chunk );
     331           0 :   fd_capture_ctx_account_update_msg_t * msg = (fd_capture_ctx_account_update_msg_t *)ctx->solcap_publish_buffer_ptr;
     332           0 :   memcpy( out_ptr, msg, sizeof(fd_capture_ctx_account_update_msg_t) );
     333           0 :   ctx->solcap_publish_buffer_ptr += sizeof(fd_capture_ctx_account_update_msg_t);
     334           0 :   out_ptr                        += sizeof(fd_capture_ctx_account_update_msg_t);
     335             : 
     336             :   /* Copy the data to the buffer */
     337           0 :   ulong data_sz = msg->data_sz;
     338           0 :   memcpy( out_ptr, ctx->solcap_publish_buffer_ptr, data_sz );
     339           0 :   ctx->solcap_publish_buffer_ptr += data_sz;
     340           0 :   out_ptr                        += data_sz;
     341             : 
     342             :   /* Stem publish the account update event */
     343           0 :   ulong msg_sz = sizeof(fd_capture_ctx_account_update_msg_t) + msg->data_sz;
     344           0 :   fd_stem_publish( stem, ctx->exec_replay_out->idx, 0UL, chunk, msg_sz, 0UL, 0UL, 0UL );
     345           0 :   ctx->exec_replay_out->chunk = fd_dcache_compact_next(
     346           0 :     chunk,
     347           0 :     msg_sz,
     348           0 :     ctx->exec_replay_out->chunk0,
     349           0 :     ctx->exec_replay_out->wmark );
     350             : 
     351             :   /* Advance the number of account updates flushed */
     352           0 :   ctx->account_updates_flushed++;
     353             : 
     354             :   /* If we have published all the account updates, reset the buffer pointer and length */
     355           0 :   if( ctx->account_updates_flushed == ctx->capture_ctx->account_updates_len ) {
     356           0 :     ctx->capture_ctx->account_updates_buffer_ptr = ctx->capture_ctx->account_updates_buffer;
     357           0 :     ctx->solcap_publish_buffer_ptr               = ctx->capture_ctx->account_updates_buffer;
     358           0 :     ctx->capture_ctx->account_updates_len        = 0UL;
     359           0 :     ctx->account_updates_flushed                 = 0UL;
     360           0 :   }
     361           0 : }
     362             : 
     363             : /* Publish the txn finalized message to the replay tile */
     364             : static void
     365             : publish_txn_finalized_msg( fd_exec_tile_ctx_t * ctx,
     366           0 :                            fd_stem_context_t *  stem ) {
     367           0 :   fd_exec_task_done_msg_t * msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
     368           0 :   msg->bank_idx          = ctx->txn_ctx->bank_idx;
     369           0 :   msg->txn_exec->txn_idx = ctx->txn_idx;
     370           0 :   msg->txn_exec->err     = !(ctx->txn_ctx->flags&FD_TXN_P_FLAGS_EXECUTE_SUCCESS);
     371             : 
     372           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, 0UL, 0UL );
     373             : 
     374           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 );
     375             : 
     376           0 :   ctx->pending_txn_finalized_msg = 0;
     377           0 : }
     378             : 
     379             : static void
     380             : after_credit( fd_exec_tile_ctx_t * ctx,
     381             :               fd_stem_context_t *  stem,
     382             :               int *                opt_poll_in,
     383           0 :               int *                charge_busy FD_PARAM_UNUSED ) {
     384             :   /* If we have outstanding account updates to send to solcap, send
     385             :      them.  Note that we set opt_poll_in to 0 here because we must not
     386             :      consume any more fragments from the exec tiles before publishing
     387             :      our messages, so that solcap updates are not interleaved between
     388             :      slots. */
     389           0 :   if( FD_UNLIKELY( ctx->capture_ctx && ctx->account_updates_flushed < ctx->capture_ctx->account_updates_len ) ) {
     390           0 :     publish_next_capture_ctx_account_update( ctx, stem );
     391           0 :     *opt_poll_in = 0;
     392           0 :   } else if( ctx->pending_txn_finalized_msg ) {
     393           0 :     publish_txn_finalized_msg( ctx, stem );
     394           0 :     *opt_poll_in = 0;
     395           0 :   }
     396           0 : }
     397             : 
     398             : static ulong
     399             : populate_allowed_seccomp( fd_topo_t const *      topo FD_PARAM_UNUSED,
     400             :                           fd_topo_tile_t const * tile FD_PARAM_UNUSED,
     401             :                           ulong                  out_cnt,
     402           0 :                           struct sock_filter *   out ) {
     403           0 :   populate_sock_filter_policy_fd_exec_tile( out_cnt, out, (uint)fd_log_private_logfile_fd() );
     404           0 :   return sock_filter_policy_fd_exec_tile_instr_cnt;
     405           0 : }
     406             : 
     407             : static ulong
     408             : populate_allowed_fds( fd_topo_t const *      topo FD_PARAM_UNUSED,
     409             :                       fd_topo_tile_t const * tile FD_PARAM_UNUSED,
     410             :                       ulong                  out_fds_cnt,
     411           0 :                       int *                  out_fds ) {
     412             : 
     413           0 :   if( FD_UNLIKELY( out_fds_cnt<2UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
     414             : 
     415           0 :   ulong out_cnt = 0UL;
     416           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
     417           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
     418           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     419           0 :   return out_cnt;
     420           0 : }
     421             : 
     422           0 : #define STEM_BURST (1UL)
     423             : /* Right now, depth of the replay_exec link and depth of the exec_replay
     424             :    links is 16K.  At 1M TPS, that's ~16ms to fill.  But we also want to
     425             :    be conservative here, so we use 1ms. */
     426           0 : #define STEM_LAZY  (1000000UL)
     427             : 
     428           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_exec_tile_ctx_t
     429           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_exec_tile_ctx_t)
     430             : 
     431           0 : #define STEM_CALLBACK_AFTER_CREDIT    after_credit
     432           0 : #define STEM_CALLBACK_RETURNABLE_FRAG returnable_frag
     433           0 : #define STEM_CALLBACK_METRICS_WRITE   metrics_write
     434             : 
     435             : #include "../../disco/stem/fd_stem.c"
     436             : 
     437             : fd_topo_run_tile_t fd_tile_execor = {
     438             :   .name                     = "exec",
     439             :   .loose_footprint          = 0UL,
     440             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     441             :   .populate_allowed_fds     = populate_allowed_fds,
     442             :   .scratch_align            = scratch_align,
     443             :   .scratch_footprint        = scratch_footprint,
     444             :   .unprivileged_init        = unprivileged_init,
     445             :   .run                      = stem_run,
     446             : };

Generated by: LCOV version 1.14