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