LCOV - code coverage report
Current view: top level - app/fdctl/run/tiles - fd_store.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 9 69 13.0 %
Date: 2024-11-13 11:58:15 Functions: 2 6 33.3 %

          Line data    Source code
       1             : #include "../../../../disco/tiles.h"
       2             : 
       3             : #include "../../../../disco/metrics/fd_metrics.h"
       4             : 
       5             : typedef struct {
       6             :   fd_wksp_t * mem;
       7             :   ulong       chunk0;
       8             :   ulong       wmark;
       9             : } fd_store_in_ctx_t;
      10             : 
      11             : typedef struct {
      12             :   uchar __attribute__((aligned(32UL))) mem[ FD_SHRED_STORE_MTU ];
      13             : 
      14             :   ulong disable_blockstore_from_slot;
      15             : 
      16             :   fd_store_in_ctx_t in[ 32 ];
      17             : } fd_store_ctx_t;
      18             : 
      19             : FD_FN_CONST static inline ulong
      20           3 : scratch_align( void ) {
      21           3 :   return 128UL;
      22           3 : }
      23             : 
      24             : FD_FN_PURE static inline ulong
      25           3 : scratch_footprint( fd_topo_tile_t const * tile ) {
      26           3 :   (void)tile;
      27           3 :   ulong l = FD_LAYOUT_INIT;
      28           3 :   l = FD_LAYOUT_APPEND( l, alignof( fd_store_ctx_t ), sizeof( fd_store_ctx_t ) );
      29           3 :   return FD_LAYOUT_FINI( l, scratch_align() );
      30           3 : }
      31             : 
      32             : static void const * fd_ext_blockstore;
      33             : 
      34             : void
      35           0 : fd_ext_store_initialize( void const * blockstore ) {
      36           0 :   fd_ext_blockstore = blockstore;
      37           0 :   FD_COMPILER_MFENCE();
      38           0 : }
      39             : 
      40             : static inline void
      41             : during_frag( fd_store_ctx_t * ctx,
      42             :              ulong            in_idx,
      43             :              ulong            seq,
      44             :              ulong            sig,
      45             :              ulong            chunk,
      46           0 :              ulong            sz ) {
      47           0 :   (void)sig;
      48           0 :   (void)seq;
      49           0 :   (void)in_idx;
      50             : 
      51           0 :   if( FD_UNLIKELY( chunk<ctx->in[ in_idx ].chunk0 || chunk>ctx->in[ in_idx ].wmark || sz>FD_SHRED_STORE_MTU || sz<32UL ) )
      52           0 :     FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->in[ in_idx ].chunk0, ctx->in[ in_idx ].wmark ));
      53             : 
      54           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[in_idx].mem, chunk );
      55             : 
      56           0 :   fd_memcpy( ctx->mem, src, sz );
      57           0 : }
      58             : 
      59             : extern int
      60             : fd_ext_blockstore_insert_shreds( void const *  blockstore,
      61             :                                  ulong         shred_cnt,
      62             :                                  uchar const * shred_bytes,
      63             :                                  ulong         shred_sz,
      64             :                                  ulong         stride,
      65             :                                  int           is_trusted );
      66             : 
      67             : static inline void
      68             : after_frag( fd_store_ctx_t *    ctx,
      69             :             ulong               in_idx,
      70             :             ulong               seq,
      71             :             ulong               sig,
      72             :             ulong               chunk,
      73             :             ulong               sz,
      74             :             ulong               tsorig,
      75           0 :             fd_stem_context_t * stem ) {
      76           0 :   (void)in_idx;
      77           0 :   (void)seq;
      78           0 :   (void)chunk;
      79           0 :   (void)tsorig;
      80           0 :   (void)stem;
      81             : 
      82           0 :   fd_shred34_t * shred34 = (fd_shred34_t *)ctx->mem;
      83             : 
      84           0 :   FD_TEST( shred34->shred_sz<=shred34->stride );
      85           0 :   if( FD_LIKELY( shred34->shred_cnt ) ) {
      86           0 :     FD_TEST( shred34->offset<sz  );
      87           0 :     FD_TEST( shred34->shred_cnt<=34UL );
      88           0 :     FD_TEST( shred34->stride==sizeof(shred34->pkts[0]) );
      89           0 :     FD_TEST( shred34->offset + shred34->stride*(shred34->shred_cnt - 1UL) + shred34->shred_sz <= sz);
      90           0 :   }
      91             : 
      92           0 :   if( FD_UNLIKELY( ctx->disable_blockstore_from_slot && ( ctx->disable_blockstore_from_slot <= shred34->pkts->shred.slot ) ) ) return;
      93             : 
      94             :   /* No error code because this cannot fail. */
      95           0 :   fd_ext_blockstore_insert_shreds( fd_ext_blockstore, shred34->shred_cnt, ctx->mem+shred34->offset, shred34->shred_sz, shred34->stride, !!sig );
      96             : 
      97           0 :   FD_MCNT_INC( STORE_TILE, TRANSACTIONS_INSERTED, shred34->est_txn_cnt );
      98           0 : }
      99             : 
     100             : static void
     101             : unprivileged_init( fd_topo_t *      topo,
     102           0 :                    fd_topo_tile_t * tile ) {
     103           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     104             : 
     105           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     106           0 :   fd_store_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_store_ctx_t ), sizeof( fd_store_ctx_t ) );
     107             : 
     108           0 :   FD_LOG_INFO(( "Waiting to acquire blockstore..." ));
     109           0 :   for(;;) {
     110           0 :     if( FD_LIKELY( FD_VOLATILE_CONST( fd_ext_blockstore ) ) ) break;
     111           0 :     FD_SPIN_PAUSE();
     112           0 :   }
     113           0 :   FD_COMPILER_MFENCE();
     114           0 :   FD_LOG_INFO(( "Got blockstore" ));
     115             : 
     116           0 :   ctx->disable_blockstore_from_slot = tile->store.disable_blockstore_from_slot;
     117             : 
     118           0 :   for( ulong i=0; i<tile->in_cnt; i++ ) {
     119           0 :     fd_topo_link_t * link = &topo->links[ tile->in_link_id[ i ] ];
     120           0 :     fd_topo_wksp_t * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
     121             : 
     122           0 :     ctx->in[ i ].mem    = link_wksp->wksp;
     123           0 :     ctx->in[ i ].chunk0 = fd_dcache_compact_chunk0( ctx->in[ i ].mem, link->dcache );
     124           0 :     ctx->in[ i ].wmark  = fd_dcache_compact_wmark ( ctx->in[ i ].mem, link->dcache, link->mtu );
     125           0 :   }
     126             : 
     127           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, 1UL );
     128           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     129           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     130           0 : }
     131             : 
     132           0 : #define STEM_BURST (1UL)
     133             : 
     134             : /* See explanation in fd_pack */
     135           0 : #define STEM_LAZY  (128L*3000L)
     136             : 
     137           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_store_ctx_t
     138           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_store_ctx_t)
     139             : 
     140           0 : #define STEM_CALLBACK_DURING_FRAG during_frag
     141           0 : #define STEM_CALLBACK_AFTER_FRAG  after_frag
     142             : 
     143             : #include "../../../../disco/stem/fd_stem.c"
     144             : 
     145             : fd_topo_run_tile_t fd_tile_store = {
     146             :   .name              = "store",
     147             :   .scratch_align     = scratch_align,
     148             :   .scratch_footprint = scratch_footprint,
     149             :   .unprivileged_init = unprivileged_init,
     150             :   .run               = stem_run,
     151             : };

Generated by: LCOV version 1.14