LCOV - code coverage report
Current view: top level - discoh/store - fd_store_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 9 66 13.6 %
Date: 2025-03-20 12:08:36 Functions: 2 6 33.3 %

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

Generated by: LCOV version 1.14