LCOV - code coverage report
Current view: top level - discoh/store - fd_store_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 71 0.0 %
Date: 2026-09-12 04:25:37 Functions: 0 6 0.0 %

          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             :   fd_fec_set_t __attribute__((aligned(32UL))) mem[1];
      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           0 : scratch_align( void ) {
      20           0 :   return 128UL;
      21           0 : }
      22             : 
      23             : FD_FN_PURE static inline ulong
      24           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
      25           0 :   (void)tile;
      26           0 :   ulong l = FD_LAYOUT_INIT;
      27           0 :   l = FD_LAYOUT_APPEND( l, alignof( fd_store_ctx_t ), sizeof( fd_store_ctx_t ) );
      28           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
      29           0 : }
      30             : 
      31             : static void const * fd_ext_blockstore;
      32             : /* The blockstore also requires two pieces of long-lasting memory so we don't have to alloc and dealloc as much in the rust code */
      33             : static void const * fd_ext_pinnable_slice;
      34             : static void const * fd_ext_write_batch;
      35             : 
      36             : void
      37             : fd_ext_store_initialize( void const * blockstore,
      38             :                          void const * pinnable_slice,
      39           0 :                          void const * write_batch ) {
      40           0 :   fd_ext_pinnable_slice = pinnable_slice;
      41           0 :   fd_ext_write_batch = write_batch;
      42           0 :   FD_COMPILER_MFENCE();
      43           0 :   fd_ext_blockstore = blockstore;
      44           0 :   FD_COMPILER_MFENCE();
      45           0 : }
      46             : 
      47             : static inline void
      48             : during_frag( fd_store_ctx_t * ctx,
      49             :              ulong            in_idx,
      50             :              ulong            seq FD_PARAM_UNUSED,
      51             :              ulong            sig FD_PARAM_UNUSED,
      52             :              ulong            chunk,
      53             :              ulong            sz  FD_PARAM_UNUSED, /* sz is ignored because sizeof(fd_fec_set_t)>USHORT_MAX */
      54           0 :              ulong            ctl FD_PARAM_UNUSED ) {
      55             : 
      56           0 :   if( FD_UNLIKELY( chunk<ctx->in[ in_idx ].chunk0 || chunk>ctx->in[ in_idx ].wmark ) )
      57           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 ));
      58             : 
      59           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[in_idx].mem, chunk );
      60             : 
      61           0 :   fd_memcpy( ctx->mem, src, sizeof(fd_fec_set_t) );
      62           0 : }
      63             : 
      64             : extern void fd_ext_bank_release( void const * bank );
      65             : extern void fd_ext_bank_set_block_id( void const * bank, uchar const * block_id );
      66             : 
      67             : extern int
      68             : fd_ext_blockstore_insert_shreds( void const *  blockstore,
      69             :                                  ulong         shred_cnt,
      70             :                                  uchar const * shred_bytes,
      71             :                                  ulong         shred_sz,
      72             :                                  ulong         stride,
      73             :                                  int           is_trusted,
      74             :                                  void const *  pinnable_slice,
      75             :                                  void const *  write_batch );
      76             : 
      77             : static inline void
      78             : after_frag( fd_store_ctx_t *    ctx,
      79             :             ulong               in_idx,
      80             :             ulong               seq,
      81             :             ulong               sig,
      82             :             ulong               sz,
      83             :             ulong               tsorig,
      84             :             ulong               tspub,
      85           0 :             fd_stem_context_t * stem ) {
      86           0 :   (void)in_idx;
      87           0 :   (void)seq;
      88           0 :   (void)sz;
      89           0 :   (void)tsorig;
      90           0 :   (void)tspub;
      91           0 :   (void)stem;
      92             : 
      93           0 :   fd_fec_set_t const * set = ctx->mem;
      94             : 
      95           0 :   if( FD_UNLIKELY( ctx->disable_blockstore_from_slot && (ctx->disable_blockstore_from_slot <= set->data_shreds->s->slot) ) ) return;
      96             : 
      97           0 :   int trusted = !!(sig & 0xFFFFFFFFUL);
      98           0 :   ulong est_txn_cnt = sig>>32UL;
      99             : 
     100             :   /* No error code because this cannot fail. */
     101           0 :   fd_ext_blockstore_insert_shreds( fd_ext_blockstore, 32UL, set->data_shreds->b,   FD_SHRED_MIN_SZ, FD_SHRED_MIN_SZ, trusted, fd_ext_pinnable_slice, fd_ext_write_batch );
     102           0 :   fd_ext_blockstore_insert_shreds( fd_ext_blockstore, 32UL, set->parity_shreds->b, FD_SHRED_MAX_SZ, FD_SHRED_MAX_SZ, trusted, fd_ext_pinnable_slice, fd_ext_write_batch );
     103             : 
     104           0 :   FD_MCNT_INC( STORE, TXN_INSERTED, est_txn_cnt );
     105             : 
     106             :   /* On receiving the SLOT_COMPLETE in an FEC set, set the block_id of
     107             :      the slot to the FEC set's merkle root and release the bank reference.
     108             :      FEC sets from the net tile (!trusted) and non-SLOT_COMPLETE leader
     109             :      FEC sets pass through this branch as a no-op. */
     110           0 :   if( FD_UNLIKELY( trusted && ( set->data_shreds[ FD_FEC_SHRED_CNT-1UL ].s->data.flags & FD_SHRED_DATA_FLAG_SLOT_COMPLETE ) ) ) {
     111           0 :     FD_TEST( set->leader_bank );
     112           0 :     fd_ext_bank_set_block_id( set->leader_bank, set->merkle_root );
     113           0 :     fd_ext_bank_release( set->leader_bank );
     114           0 :   }
     115           0 : }
     116             : 
     117             : static void
     118             : unprivileged_init( fd_topo_t const *      topo,
     119           0 :                    fd_topo_tile_t const * tile ) {
     120           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     121             : 
     122           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     123           0 :   fd_store_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_store_ctx_t ), sizeof( fd_store_ctx_t ) );
     124             : 
     125           0 :   FD_LOG_INFO(( "Waiting to acquire blockstore..." ));
     126           0 :   for(;;) {
     127           0 :     if( FD_LIKELY( FD_VOLATILE_CONST( fd_ext_blockstore ) ) ) break;
     128           0 :     FD_SPIN_PAUSE();
     129           0 :   }
     130           0 :   FD_COMPILER_MFENCE();
     131           0 :   FD_LOG_INFO(( "Got blockstore" ));
     132             : 
     133           0 :   ctx->disable_blockstore_from_slot = tile->store.disable_blockstore_from_slot;
     134             : 
     135           0 :   for( ulong i=0; i<tile->in_cnt; i++ ) {
     136           0 :     fd_topo_link_t const * link = &topo->links[ tile->in_link_id[ i ] ];
     137           0 :     fd_topo_wksp_t const * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
     138             : 
     139           0 :     ctx->in[ i ].mem    = link_wksp->wksp;
     140           0 :     ctx->in[ i ].chunk0 = fd_dcache_compact_chunk0( ctx->in[ i ].mem, link->dcache );
     141           0 :     ctx->in[ i ].wmark  = fd_dcache_compact_wmark ( ctx->in[ i ].mem, link->dcache, link->mtu );
     142           0 :   }
     143             : 
     144           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     145           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     146           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     147           0 : }
     148             : 
     149           0 : #define STEM_BURST (1UL)
     150             : 
     151             : /* See explanation in fd_pack */
     152           0 : #define STEM_LAZY  (128L*3000L)
     153             : 
     154           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_store_ctx_t
     155           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_store_ctx_t)
     156             : 
     157           0 : #define STEM_CALLBACK_DURING_FRAG during_frag
     158           0 : #define STEM_CALLBACK_AFTER_FRAG  after_frag
     159             : 
     160             : #include "../../disco/stem/fd_stem.c"
     161             : 
     162             : fd_topo_run_tile_t fd_tile_store = {
     163             :   .name              = "store",
     164             :   .scratch_align     = scratch_align,
     165             :   .scratch_footprint = scratch_footprint,
     166             :   .unprivileged_init = unprivileged_init,
     167             :   .run               = stem_run,
     168             : };

Generated by: LCOV version 1.14