LCOV - code coverage report
Current view: top level - discoh/store - fd_store_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 68 0.0 %
Date: 2026-06-29 05:51:35 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             : 
      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  FD_PARAM_UNUSED, /* sz is ignored because sizeof(fd_fec_set_t)>USHORT_MAX */
      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 ) )
      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, sizeof(fd_fec_set_t) );
      54           0 : }
      55             : 
      56             : extern void fd_ext_bank_release( void const * bank );
      57             : extern void fd_ext_bank_set_block_id( void const * bank, uchar const * block_id );
      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               sz,
      73             :             ulong               tsorig,
      74             :             ulong               tspub,
      75           0 :             fd_stem_context_t * stem ) {
      76           0 :   (void)in_idx;
      77           0 :   (void)seq;
      78           0 :   (void)sz;
      79           0 :   (void)tsorig;
      80           0 :   (void)tspub;
      81           0 :   (void)stem;
      82             : 
      83           0 :   fd_fec_set_t const * set = ctx->mem;
      84             : 
      85           0 :   if( FD_UNLIKELY( ctx->disable_blockstore_from_slot && (ctx->disable_blockstore_from_slot <= set->data_shreds->s->slot) ) ) return;
      86             : 
      87           0 :   int trusted = !!(sig & 0xFFFFFFFFUL);
      88           0 :   ulong est_txn_cnt = sig>>32UL;
      89             : 
      90             :   /* No error code because this cannot fail. */
      91           0 :   fd_ext_blockstore_insert_shreds( fd_ext_blockstore, 32UL, set->data_shreds->b,   FD_SHRED_MIN_SZ, FD_SHRED_MAX_SZ, trusted );
      92           0 :   fd_ext_blockstore_insert_shreds( fd_ext_blockstore, 32UL, set->parity_shreds->b, FD_SHRED_MAX_SZ, FD_SHRED_MAX_SZ, trusted );
      93             : 
      94           0 :   FD_MCNT_INC( STORE, TXN_INSERTED, est_txn_cnt );
      95             : 
      96             :   /* On receiving the SLOT_COMPLETE in an FEC set, set the block_id of
      97             :      the slot to the FEC set's merkle root and release the bank reference.
      98             :      FEC sets from the net tile (!trusted) and non-SLOT_COMPLETE leader
      99             :      FEC sets pass through this branch as a no-op. */
     100           0 :   if( FD_UNLIKELY( trusted && ( set->data_shreds[ FD_FEC_SHRED_CNT-1UL ].s->data.flags & FD_SHRED_DATA_FLAG_SLOT_COMPLETE ) ) ) {
     101           0 :     FD_TEST( set->leader_bank );
     102           0 :     fd_ext_bank_set_block_id( set->leader_bank, set->merkle_root );
     103           0 :     fd_ext_bank_release( set->leader_bank );
     104           0 :   }
     105           0 : }
     106             : 
     107             : static void
     108             : unprivileged_init( fd_topo_t const *      topo,
     109           0 :                    fd_topo_tile_t const * tile ) {
     110           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     111             : 
     112           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     113           0 :   fd_store_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_store_ctx_t ), sizeof( fd_store_ctx_t ) );
     114             : 
     115           0 :   FD_LOG_INFO(( "Waiting to acquire blockstore..." ));
     116           0 :   for(;;) {
     117           0 :     if( FD_LIKELY( FD_VOLATILE_CONST( fd_ext_blockstore ) ) ) break;
     118           0 :     FD_SPIN_PAUSE();
     119           0 :   }
     120           0 :   FD_COMPILER_MFENCE();
     121           0 :   FD_LOG_INFO(( "Got blockstore" ));
     122             : 
     123           0 :   ctx->disable_blockstore_from_slot = tile->store.disable_blockstore_from_slot;
     124             : 
     125           0 :   for( ulong i=0; i<tile->in_cnt; i++ ) {
     126           0 :     fd_topo_link_t const * link = &topo->links[ tile->in_link_id[ i ] ];
     127           0 :     fd_topo_wksp_t const * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
     128             : 
     129           0 :     ctx->in[ i ].mem    = link_wksp->wksp;
     130           0 :     ctx->in[ i ].chunk0 = fd_dcache_compact_chunk0( ctx->in[ i ].mem, link->dcache );
     131           0 :     ctx->in[ i ].wmark  = fd_dcache_compact_wmark ( ctx->in[ i ].mem, link->dcache, link->mtu );
     132           0 :   }
     133             : 
     134           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     135           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     136           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     137           0 : }
     138             : 
     139           0 : #define STEM_BURST (1UL)
     140             : 
     141             : /* See explanation in fd_pack */
     142           0 : #define STEM_LAZY  (128L*3000L)
     143             : 
     144           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_store_ctx_t
     145           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_store_ctx_t)
     146             : 
     147           0 : #define STEM_CALLBACK_DURING_FRAG during_frag
     148           0 : #define STEM_CALLBACK_AFTER_FRAG  after_frag
     149             : 
     150             : #include "../../disco/stem/fd_stem.c"
     151             : 
     152             : fd_topo_run_tile_t fd_tile_store = {
     153             :   .name              = "store",
     154             :   .scratch_align     = scratch_align,
     155             :   .scratch_footprint = scratch_footprint,
     156             :   .unprivileged_init = unprivileged_init,
     157             :   .run               = stem_run,
     158             : };

Generated by: LCOV version 1.14