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 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)sz;
76 0 : (void)tsorig;
77 0 : (void)tspub;
78 0 : (void)stem;
79 :
80 0 : fd_fec_set_t const * set = ctx->mem;
81 :
82 0 : if( FD_UNLIKELY( ctx->disable_blockstore_from_slot && (ctx->disable_blockstore_from_slot <= set->data_shreds->s->slot) ) ) return;
83 :
84 0 : int trusted = !!(sig & 0xFFFFFFFFUL);
85 0 : ulong est_txn_cnt = sig>>32UL;
86 :
87 : /* No error code because this cannot fail. */
88 0 : fd_ext_blockstore_insert_shreds( fd_ext_blockstore, 32UL, set->data_shreds->b, FD_SHRED_MIN_SZ, FD_SHRED_MAX_SZ, trusted );
89 0 : fd_ext_blockstore_insert_shreds( fd_ext_blockstore, 32UL, set->parity_shreds->b, FD_SHRED_MAX_SZ, FD_SHRED_MAX_SZ, trusted );
90 :
91 0 : FD_MCNT_INC( STORE, TRANSACTIONS_INSERTED, est_txn_cnt );
92 0 : }
93 :
94 : static void
95 : unprivileged_init( fd_topo_t * topo,
96 0 : fd_topo_tile_t * tile ) {
97 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
98 :
99 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
100 0 : fd_store_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_store_ctx_t ), sizeof( fd_store_ctx_t ) );
101 :
102 0 : FD_LOG_INFO(( "Waiting to acquire blockstore..." ));
103 0 : for(;;) {
104 0 : if( FD_LIKELY( FD_VOLATILE_CONST( fd_ext_blockstore ) ) ) break;
105 0 : FD_SPIN_PAUSE();
106 0 : }
107 0 : FD_COMPILER_MFENCE();
108 0 : FD_LOG_INFO(( "Got blockstore" ));
109 :
110 0 : ctx->disable_blockstore_from_slot = tile->store.disable_blockstore_from_slot;
111 :
112 0 : for( ulong i=0; i<tile->in_cnt; i++ ) {
113 0 : fd_topo_link_t * link = &topo->links[ tile->in_link_id[ i ] ];
114 0 : fd_topo_wksp_t * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
115 :
116 0 : ctx->in[ i ].mem = link_wksp->wksp;
117 0 : ctx->in[ i ].chunk0 = fd_dcache_compact_chunk0( ctx->in[ i ].mem, link->dcache );
118 0 : ctx->in[ i ].wmark = fd_dcache_compact_wmark ( ctx->in[ i ].mem, link->dcache, link->mtu );
119 0 : }
120 :
121 0 : ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, 1UL );
122 0 : if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
123 0 : FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
124 0 : }
125 :
126 0 : #define STEM_BURST (1UL)
127 :
128 : /* See explanation in fd_pack */
129 0 : #define STEM_LAZY (128L*3000L)
130 :
131 0 : #define STEM_CALLBACK_CONTEXT_TYPE fd_store_ctx_t
132 0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_store_ctx_t)
133 :
134 0 : #define STEM_CALLBACK_DURING_FRAG during_frag
135 0 : #define STEM_CALLBACK_AFTER_FRAG after_frag
136 :
137 : #include "../../disco/stem/fd_stem.c"
138 :
139 : fd_topo_run_tile_t fd_tile_store = {
140 : .name = "store",
141 : .scratch_align = scratch_align,
142 : .scratch_footprint = scratch_footprint,
143 : .unprivileged_init = unprivileged_init,
144 : .run = stem_run,
145 : };
|