9
9
#include "../rpcserver/fd_rpc_service.h"
10
10
11
11
#include "../../flamenco/leaders/fd_multi_epoch_leaders.h"
12
- #include "../../util/pod/fd_pod_format.h"
13
12
#include "../../disco/keyguard/fd_keyload.h"
14
13
#include "../../disco/keyguard/fd_keyswitch.h"
15
14
16
- #include <errno.h>
17
15
#include <fcntl.h>
18
16
#include <unistd.h>
19
17
20
- #define REPLAY_NOTIF_IDX 0
21
- #define STAKE_IN_IDX 1
18
+ #define IN_KIND_REPLAY_NOTIF 0
19
+ #define IN_KIND_STAKE_OUT 1
20
+ #define IN_KIND_SHRED_REPAIR 2
21
+
22
+ #define MAX_IN_LINKS (16)
23
+
24
+ typedef union {
25
+ struct {
26
+ fd_wksp_t * mem ;
27
+ ulong chunk0 ;
28
+ ulong wmark ;
29
+ ulong mtu ;
30
+ };
31
+ } fd_rpcserv_in_ctx_t ;
22
32
23
33
struct fd_rpcserv_tile_ctx {
24
34
fd_rpcserver_args_t args ;
25
35
26
36
fd_rpc_ctx_t * ctx ;
27
- fd_store_t * store ;
28
37
29
38
fd_pubkey_t identity_key ;
30
39
fd_keyswitch_t * keyswitch ;
31
40
32
- fd_wksp_t * replay_notif_in_mem ;
33
- ulong replay_notif_in_chunk0 ;
34
- ulong replay_notif_in_wmark ;
35
41
fd_replay_notif_msg_t replay_notif_in_state ;
36
42
37
- fd_wksp_t * stake_in_mem ;
38
- ulong stake_in_chunk0 ;
39
- ulong stake_in_wmark ;
43
+ uchar in_kind [ MAX_IN_LINKS ];
44
+ fd_rpcserv_in_ctx_t in_links [ MAX_IN_LINKS ];
40
45
41
46
uchar __attribute__((aligned (FD_MULTI_EPOCH_LEADERS_ALIGN ))) mleaders_mem [ FD_MULTI_EPOCH_LEADERS_FOOTPRINT ];
42
47
};
@@ -95,21 +100,15 @@ during_frag( fd_rpcserv_tile_ctx_t * ctx,
95
100
ulong chunk ,
96
101
ulong sz ,
97
102
ulong ctl FD_PARAM_UNUSED ) {
98
-
99
- if ( FD_UNLIKELY ( in_idx == REPLAY_NOTIF_IDX ) ) {
100
- if ( FD_UNLIKELY ( chunk < ctx -> replay_notif_in_chunk0 || chunk > ctx -> replay_notif_in_wmark ) ) {
101
- FD_LOG_ERR (( "chunk %lu %lu corrupt, not in range [%lu,%lu]" , chunk , sz ,
102
- ctx -> replay_notif_in_chunk0 , ctx -> replay_notif_in_wmark ));
103
- }
104
- fd_rpc_replay_during_frag ( ctx -> ctx , & ctx -> replay_notif_in_state , fd_chunk_to_laddr_const ( ctx -> replay_notif_in_mem , chunk ), (int )sz );
105
-
106
- } else if ( FD_UNLIKELY ( in_idx == STAKE_IN_IDX ) ) {
107
- if ( FD_UNLIKELY ( chunk < ctx -> stake_in_chunk0 || chunk > ctx -> stake_in_wmark ) ) {
108
- FD_LOG_ERR (( "chunk %lu %lu corrupt, not in range [%lu,%lu]" , chunk , sz ,
109
- ctx -> stake_in_chunk0 , ctx -> stake_in_wmark ));
110
- }
111
- fd_rpc_stake_during_frag ( ctx -> ctx , ctx -> args .leaders , fd_chunk_to_laddr_const ( ctx -> stake_in_mem , chunk ), (int )sz );
112
-
103
+ if ( FD_UNLIKELY ( chunk < ctx -> in_links [in_idx ].chunk0 || chunk > ctx -> in_links [in_idx ].wmark ) ) {
104
+ FD_LOG_ERR (( "chunk %lu %lu corrupt, not in range [%lu,%lu]" , chunk , sz ,
105
+ ctx -> in_links [in_idx ].chunk0 , ctx -> in_links [in_idx ].wmark ));
106
+ }
107
+ uchar kind = ctx -> in_kind [ in_idx ];
108
+ if ( FD_UNLIKELY ( kind == IN_KIND_REPLAY_NOTIF ) ) {
109
+ fd_rpc_replay_during_frag ( ctx -> ctx , & ctx -> replay_notif_in_state , fd_chunk_to_laddr_const ( ctx -> in_links [in_idx ].mem , chunk ), (int )sz );
110
+ } else if ( FD_UNLIKELY ( kind == IN_KIND_STAKE_OUT ) ) {
111
+ fd_rpc_stake_during_frag ( ctx -> ctx , ctx -> args .leaders , fd_chunk_to_laddr_const ( ctx -> in_links [in_idx ].mem , chunk ), (int )sz );
113
112
} else {
114
113
FD_LOG_ERR (("Unknown in_idx %lu for rpc" , in_idx ));
115
114
}
@@ -131,9 +130,10 @@ after_frag( fd_rpcserv_tile_ctx_t * ctx,
131
130
(void )tspub ;
132
131
(void )stem ;
133
132
134
- if ( FD_LIKELY ( in_idx == REPLAY_NOTIF_IDX ) ) {
133
+ uchar kind = ctx -> in_kind [ in_idx ];
134
+ if ( FD_UNLIKELY ( kind == IN_KIND_REPLAY_NOTIF ) ) {
135
135
fd_rpc_replay_after_frag ( ctx -> ctx , & ctx -> replay_notif_in_state );
136
- } else if ( FD_UNLIKELY ( in_idx == STAKE_IN_IDX ) ) {
136
+ } else if ( FD_UNLIKELY ( kind == IN_KIND_STAKE_OUT ) ) {
137
137
fd_rpc_stake_after_frag ( ctx -> ctx , ctx -> args .leaders );
138
138
} else {
139
139
FD_LOG_ERR (("Unknown in_idx %lu for rpc" , in_idx ));
@@ -171,12 +171,6 @@ privileged_init( fd_topo_t * topo,
171
171
uchar * spad_mem_cur = spad_mem ;
172
172
args -> spad = fd_spad_join ( fd_spad_new ( spad_mem_cur , FD_RPC_SCRATCH_MAX ) );
173
173
174
- /* Blockstore setup */
175
- ulong store_obj_id = fd_pod_queryf_ulong ( topo -> props , ULONG_MAX , "store" );
176
- FD_TEST ( store_obj_id != ULONG_MAX );
177
- args -> store = fd_store_join ( fd_topo_obj_laddr ( topo , store_obj_id ) );
178
- FD_TEST ( args -> store != NULL );
179
-
180
174
args -> block_index_max = tile -> rpcserv .block_index_max ;
181
175
args -> txn_index_max = tile -> rpcserv .txn_index_max ;
182
176
args -> acct_index_max = tile -> rpcserv .acct_index_max ;
@@ -195,13 +189,6 @@ unprivileged_init( fd_topo_t * topo,
195
189
fd_topo_tile_t * tile ) {
196
190
void * scratch = fd_topo_obj_laddr ( topo , tile -> tile_obj_id );
197
191
198
- if ( FD_UNLIKELY ( tile -> in_cnt != 2 ||
199
- strcmp ( topo -> links [ tile -> in_link_id [ REPLAY_NOTIF_IDX ] ].name , "replay_notif" ) ||
200
- strcmp ( topo -> links [ tile -> in_link_id [ STAKE_IN_IDX ] ].name , "stake_out" ) ) ) {
201
- FD_LOG_ERR (( "repair tile has none or unexpected input links %lu %s %s" ,
202
- tile -> in_cnt , topo -> links [ tile -> in_link_id [ 0 ] ].name , topo -> links [ tile -> in_link_id [ 1 ] ].name ));
203
- }
204
-
205
192
if ( FD_UNLIKELY ( tile -> out_cnt != 0 ) ) {
206
193
FD_LOG_ERR (( "repair tile has none or unexpected output links %lu %s %s" ,
207
194
tile -> out_cnt , topo -> links [ tile -> out_link_id [ 0 ] ].name , topo -> links [ tile -> out_link_id [ 1 ] ].name ));
@@ -216,15 +203,24 @@ unprivileged_init( fd_topo_t * topo,
216
203
if ( FD_UNLIKELY ( scratch_top > (ulong )scratch + scratch_footprint ( tile ) ) )
217
204
FD_LOG_ERR (( "scratch overflow %lu %lu %lu" , scratch_top - (ulong )scratch - scratch_footprint ( tile ), scratch_top , (ulong )scratch + scratch_footprint ( tile ) ));
218
205
219
- fd_topo_link_t * replay_notif_in_link = & topo -> links [ tile -> in_link_id [ REPLAY_NOTIF_IDX ] ];
220
- ctx -> replay_notif_in_mem = topo -> workspaces [ topo -> objs [ replay_notif_in_link -> dcache_obj_id ].wksp_id ].wksp ;
221
- ctx -> replay_notif_in_chunk0 = fd_dcache_compact_chunk0 ( ctx -> replay_notif_in_mem , replay_notif_in_link -> dcache );
222
- ctx -> replay_notif_in_wmark = fd_dcache_compact_wmark ( ctx -> replay_notif_in_mem , replay_notif_in_link -> dcache , replay_notif_in_link -> mtu );
206
+ for ( uint in_idx = 0U ; in_idx < (tile -> in_cnt ); in_idx ++ ) {
207
+ fd_topo_link_t * link = & topo -> links [ tile -> in_link_id [ in_idx ] ];
208
+ if ( 0 == strcmp ( link -> name , "replay_notif" ) ) {
209
+ ctx -> in_kind [ in_idx ] = IN_KIND_REPLAY_NOTIF ;
210
+ } else if ( 0 == strcmp ( link -> name , "stake_out" ) ) {
211
+ ctx -> in_kind [ in_idx ] = IN_KIND_STAKE_OUT ;
212
+ } else if ( 0 == strcmp ( link -> name , "shred_repair" ) ) {
213
+ ctx -> in_kind [ in_idx ] = IN_KIND_SHRED_REPAIR ;
214
+ } else {
215
+ FD_LOG_ERR (( "rpcserv tile has unexpected input link %s" , link -> name ));
216
+ }
223
217
224
- fd_topo_link_t * stake_in_link = & topo -> links [ tile -> in_link_id [ STAKE_IN_IDX ] ];
225
- ctx -> stake_in_mem = topo -> workspaces [ topo -> objs [ stake_in_link -> dcache_obj_id ].wksp_id ].wksp ;
226
- ctx -> stake_in_chunk0 = fd_dcache_compact_chunk0 ( ctx -> stake_in_mem , stake_in_link -> dcache );
227
- ctx -> stake_in_wmark = fd_dcache_compact_wmark ( ctx -> stake_in_mem , stake_in_link -> dcache , stake_in_link -> mtu );
218
+ ctx -> in_links [ in_idx ].mem = topo -> workspaces [ topo -> objs [ link -> dcache_obj_id ].wksp_id ].wksp ;
219
+ ctx -> in_links [ in_idx ].chunk0 = fd_dcache_compact_chunk0 ( ctx -> in_links [ in_idx ].mem , link -> dcache );
220
+ ctx -> in_links [ in_idx ].wmark = fd_dcache_compact_wmark ( ctx -> in_links [ in_idx ].mem , link -> dcache , link -> mtu );
221
+ ctx -> in_links [ in_idx ].mtu = link -> mtu ;
222
+ FD_TEST ( fd_dcache_compact_is_safe ( ctx -> in_links [in_idx ].mem , link -> dcache , link -> mtu , link -> depth ) );
223
+ }
228
224
229
225
ctx -> keyswitch = fd_keyswitch_join ( fd_topo_obj_laddr ( topo , tile -> keyswitch_obj_id ) );
230
226
FD_TEST ( ctx -> keyswitch );
0 commit comments