Line data Source code
1 : /* REQUEST HANDLING ARCHITECTURE
2 : =========================================
3 :
4 : The repair tile implements two distinct request handling patterns
5 : based on the nature of the operation and its latency requirements:
6 :
7 : 1. SYNCHRONOUS REQUEST HANDLING
8 : -----------------------------------------
9 : Used for lightweight protocol messages that require immediate
10 : signing and response. These operations use the keyguard client for
11 : direct signing, which requires blocking.
12 :
13 : Message types handled synchronously:
14 : - PINGs & PONGs: Handles peer connectivity and liveness with simple
15 : round-trip messages.
16 :
17 : - PEER WARM UPs: On receiving peer information in
18 : handle_new_cluster_contact_info, we prepay the RTT cost by sending
19 : a placeholder Repair request immediately.
20 :
21 : 2. ASYNCHRONOUS REQUEST HANDLING
22 : --------------------------------
23 : Used strictly for repair requests. These requests are sent to the
24 : sign tile, and the repair tile continues handling other operations
25 : without blocking. Once the sign tile has signed the request, the
26 : repair tile will complete the request from its pending sign request
27 : deque and send the response.
28 :
29 : Note we do MANUAL credit tracking for these asynchronous sign links
30 : (see out_ctx_t definition). In particular, credits tracks the
31 : RETURN sign_repair link. This is because repair_sign is reliable,
32 : and sign_repair is unreliable. If both links were reliable, and the
33 : links filled completely, stem would get into a deadlock. Neither
34 : repair or sign would have credits, which would prevent frags from
35 : getting polled in repair or sign, which would prevent any credits
36 : from getting returned back to the tiles.
37 :
38 : Thus the sign_repair link must be unreliable. This is mostly ok,
39 : because repair_sign is still reliable, so in theory repair_tile
40 : would never publish enough frags such that sign_repair would get
41 : overrun.
42 :
43 : However, there is a fairly common case that breaks this. Consider
44 : the scenario
45 :
46 : repair_sign (depth 128) sign_repair (depth 128)
47 : repair ----------------------> sign ------------------------> repair
48 : [rest free, r130, r129] [r128, r127, ... , r1] (full)
49 :
50 : This would happen because repair is publishing too many requests too
51 : fast(common in catchup), and not polling enough frags from sign.
52 : Nothing is stopping repair from publishing more requests, because
53 : sign is functioning fast enough to handle the requests. However,
54 : nothing is stopping sign from polling the next request and signing
55 : it, and PUBLISHING it on the sign_repair link that is already full,
56 : because the sign_repair link is unreliable.
57 :
58 : In fact the only time we could stop repair from publishing more
59 : requests is if repair_sign was full, and repair would get
60 : backpressured, but sign would still be able to poll requests and
61 : overrun the sign_repair link.
62 :
63 : This is why we need to manually track credits for the sign_repair
64 : link. We must ensure that there are never more than 128 items in the
65 : ENTIRE repair_sign -> sign tile -> sign_repair work queue, else
66 : there is always a possibility of an overrun in the sign_repair link.
67 :
68 : To lose a frag to overrun isn't necessarily critical, but in general
69 : the repair tile relies on the fact that a signing task published to
70 : sign tile will always come back. If we lose a frag to overrun, then
71 : there will be an entry in the pending signs structure that is never
72 : removed, and theoretically the map could fill up. Conceptually, with
73 : a reliable sign->repair->sign structure, there should be no eviction
74 : needed in this pending signs structure.
75 :
76 : Message types handled asynchronously:
77 : - WINDOW_INDEX (exact shred): Requests for a specific shred at a
78 : known slot and index. Used when the repair tile knows exactly
79 : which shred is missing from a FEC set.
80 :
81 : - HIGHEST_WINDOW_INDEX: Requests for the highest shred in a slot.
82 : Used to determine the end boundary of a slot when the exact count
83 : is unknown.
84 :
85 : - ORPHAN: Requests for the highest shred in the parent slot of an
86 : orphaned slot. Used to establish the chain of slot ancestry when a
87 : slot's parent is missing.
88 :
89 : Async requests can be distributed across multiple sign tiles using
90 : round-robin based on the request nonce. This provides load balancing
91 : and prevents any single sign tile from becoming a bottleneck. */
92 :
93 : #define _GNU_SOURCE
94 :
95 : #include "../genesis/fd_genesi_tile.h"
96 : #include "../../disco/topo/fd_topo.h"
97 : #include "generated/fd_repair_tile_seccomp.h"
98 : #include "../../disco/fd_disco.h"
99 : #include "../../disco/keyguard/fd_keyload.h"
100 : #include "../../disco/keyguard/fd_keyguard.h"
101 : #include "../../disco/net/fd_net_tile.h"
102 : #include "../../disco/store/fd_store.h"
103 : #include "../../flamenco/gossip/fd_gossip_types.h"
104 : #include "../tower/fd_tower_tile.h"
105 : #include "../../discof/restore/utils/fd_ssmsg.h"
106 : #include "../../util/pod/fd_pod_format.h"
107 : #include "../../util/net/fd_net_headers.h"
108 : #include "../../tango/fd_tango_base.h"
109 :
110 : #include "../forest/fd_forest.h"
111 : #include "fd_repair_metrics.h"
112 : #include "fd_inflight.h"
113 : #include "fd_repair.h"
114 : #include "fd_policy.h"
115 :
116 : #define LOGGING 1
117 : #define DEBUG_LOGGING 0
118 :
119 : #define IN_KIND_CONTACT (0)
120 0 : #define IN_KIND_NET (1)
121 0 : #define IN_KIND_TOWER (2)
122 0 : #define IN_KIND_SHRED (3)
123 0 : #define IN_KIND_SIGN (4)
124 0 : #define IN_KIND_SNAP (5)
125 0 : #define IN_KIND_STAKE (6)
126 0 : #define IN_KIND_GOSSIP (7)
127 0 : #define IN_KIND_GENESIS (8)
128 :
129 : #define MAX_IN_LINKS (16)
130 :
131 : #define MAX_REPAIR_PEERS 40200UL
132 : #define MAX_BUFFER_SIZE ( MAX_REPAIR_PEERS * sizeof( fd_shred_dest_wire_t ) )
133 : #define MAX_SHRED_TILE_CNT ( 16UL )
134 : #define MAX_SIGN_TILE_CNT ( 16UL )
135 :
136 : /* Maximum size of a network packet */
137 0 : #define FD_REPAIR_MAX_PACKET_SIZE 1232
138 : /* Max number of validators that can be actively queried */
139 0 : #define FD_ACTIVE_KEY_MAX (FD_CONTACT_INFO_TABLE_SIZE)
140 : /* Max number of pending shred requests */
141 0 : #define FD_NEEDED_KEY_MAX (1<<20)
142 :
143 : /* static map from request type to metric array index */
144 : static uint metric_index[FD_REPAIR_KIND_ORPHAN + 1] = {
145 : [FD_REPAIR_KIND_SHRED] = FD_METRICS_ENUM_REPAIR_SENT_REQUEST_TYPES_V_NEEDED_WINDOW_IDX,
146 : [FD_REPAIR_KIND_HIGHEST_SHRED] = FD_METRICS_ENUM_REPAIR_SENT_REQUEST_TYPES_V_NEEDED_HIGHEST_WINDOW_IDX,
147 : [FD_REPAIR_KIND_ORPHAN] = FD_METRICS_ENUM_REPAIR_SENT_REQUEST_TYPES_V_NEEDED_ORPHAN_IDX,
148 : };
149 :
150 : typedef union {
151 : struct {
152 : fd_wksp_t * mem;
153 : ulong chunk0;
154 : ulong wmark;
155 : ulong mtu;
156 : };
157 : fd_net_rx_bounds_t net_rx;
158 : } in_ctx_t;
159 :
160 : struct out_ctx {
161 : ulong idx;
162 : fd_wksp_t * mem;
163 : ulong chunk0;
164 : ulong wmark;
165 : ulong chunk;
166 :
167 : ulong in_idx; /* index of the incoming link */
168 : ulong credits; /* available credits for link */
169 : ulong max_credits; /* maximum credits (depth) */
170 :
171 : /* credits / max_credits are used by the repair_sign link. In
172 : particular, credits manages the RETURN sign_repair link. See top
173 : of file for more details. */
174 : };
175 : typedef struct out_ctx out_ctx_t;
176 :
177 : struct fd_fec_sig {
178 : ulong key; /* map key. 32 msb = slot, 32 lsb = fec_set_idx */
179 : fd_ed25519_sig_t sig; /* Ed25519 sig identifier of the FEC. */
180 : };
181 : typedef struct fd_fec_sig fd_fec_sig_t;
182 :
183 : #define MAP_NAME fd_fec_sig
184 0 : #define MAP_T fd_fec_sig_t
185 : #define MAP_MEMOIZE 0
186 : #include "../../util/tmpl/fd_map_dynamic.c"
187 :
188 : /* Data needed to sign and send a pong that is not contained in the
189 : pong msg itself. */
190 : struct pong_data {
191 : fd_ip4_port_t peer_addr;
192 : fd_hash_t hash;
193 : uint daddr;
194 : };
195 : typedef struct pong_data pong_data_t;
196 :
197 : struct sign_req {
198 : ulong key; /* map key, ctx->pending_key_next */
199 : ulong buflen;
200 : union {
201 : uchar buf[sizeof(fd_repair_msg_t)];
202 : fd_repair_msg_t msg;
203 : };
204 : pong_data_t pong_data; /* populated only for pong msgs */
205 : };
206 : typedef struct sign_req sign_req_t;
207 :
208 : #define MAP_NAME fd_signs_map
209 0 : #define MAP_KEY key
210 0 : #define MAP_KEY_NULL ULONG_MAX
211 0 : #define MAP_KEY_INVAL(k) (k==ULONG_MAX)
212 0 : #define MAP_T sign_req_t
213 : #define MAP_MEMOIZE 0
214 : #include "../../util/tmpl/fd_map_dynamic.c"
215 :
216 : /* Because the sign tiles could be all busy when a contact info arrives,
217 : we need to save ping messages to be signed in a queue and dispatched
218 : in after_credit when there are sign tiles available. The size of the
219 : queue was determined by the following: we can limit the size of this
220 : queue to be the maximum number of active keys - which is equal to the
221 : number of warm up requests we might queue. The queue will also hold
222 : pongs, but in order for the ping to arrive the warm up request must
223 : have left the queue. It is possible that we start up and get
224 : FD_ACTIVE_KEY_MAX peers gossiped to us, and as we are queueing up
225 : their pings they all drop and another FD_ACTIVE_KEY_MAX new peers
226 : gossip to us, causing us to fill up the queue. Idk overall this
227 : scenario is highly unlikely and it's not the end of the world if we
228 : drop a warmup req or ping to a peer because the first req to them
229 : will retrigger it anyway.
230 :
231 : Typical flow is that a pong will get added to the sign_queue during
232 : an after_frag call. Then on the following after_credit will get
233 : popped from the sign_queue and added to sign_map, and then dispatched
234 : to the sign tile. */
235 :
236 : struct sign_pending {
237 : fd_repair_msg_t msg;
238 : pong_data_t pong_data; /* populated only for pong msgs */
239 : };
240 : typedef struct sign_pending sign_pending_t;
241 :
242 : #define QUEUE_NAME fd_signs_queue
243 0 : #define QUEUE_T sign_pending_t
244 0 : #define QUEUE_MAX 2*FD_ACTIVE_KEY_MAX
245 : #include "../../util/tmpl/fd_queue.c"
246 :
247 : struct ctx {
248 : long tsdebug; /* timestamp for debug printing */
249 :
250 : ulong repair_seed;
251 :
252 : fd_ip4_port_t repair_intake_addr;
253 : fd_ip4_port_t repair_serve_addr;
254 :
255 : fd_forest_t * forest;
256 : fd_fec_sig_t * fec_sigs;
257 : fd_store_t * store;
258 : fd_policy_t * policy;
259 : fd_inflights_t * inflight;
260 : fd_repair_t * protocol;
261 :
262 : fd_pubkey_t identity_public_key;
263 :
264 : fd_wksp_t * wksp;
265 :
266 : fd_stem_context_t * stem;
267 :
268 : uchar in_kind[ MAX_IN_LINKS ];
269 : in_ctx_t in_links[ MAX_IN_LINKS ];
270 :
271 : int skip_frag;
272 :
273 : uint net_out_idx;
274 : fd_wksp_t * net_out_mem;
275 : ulong net_out_chunk0;
276 : ulong net_out_wmark;
277 : ulong net_out_chunk;
278 :
279 : ulong snap_out_chunk;
280 :
281 : uint shred_tile_cnt;
282 : out_ctx_t shred_out_ctx[ MAX_SHRED_TILE_CNT ];
283 :
284 : /* repair_sign links (to sign tiles 1+) - for round-robin distribution */
285 : ulong repair_sign_cnt;
286 : out_ctx_t repair_sign_out_ctx[ MAX_SIGN_TILE_CNT ];
287 :
288 : ulong sign_rrobin_idx;
289 :
290 : /* Pending sign requests for async operations */
291 : uint pending_key_next;
292 : sign_req_t * signs_map; /* contains any request currently in the repair->sign or sign->repair dcache */
293 : sign_pending_t * sign_queue; /* contains any request waiting to be dispatched to repair->sign */
294 :
295 : ushort net_id;
296 : /* Includes Ethernet, IP, UDP headers */
297 : uchar buffer[ MAX_BUFFER_SIZE ];
298 : fd_ip4_udp_hdrs_t intake_hdr[1];
299 : fd_ip4_udp_hdrs_t serve_hdr [1];
300 :
301 : ulong manifest_slot;
302 : struct {
303 : ulong send_pkt_cnt;
304 : ulong send_pkt_rate;
305 : ulong sent_pkt_types[FD_METRICS_ENUM_REPAIR_SENT_REQUEST_TYPES_CNT];
306 : ulong repaired_slots;
307 : ulong current_slot;
308 : ulong sign_tile_unavail;
309 : ulong rerequest;
310 : fd_histf_t slot_compl_time[ 1 ];
311 : fd_histf_t response_latency[ 1 ];
312 : } metrics[ 1 ];
313 :
314 : /* Slot-level metrics */
315 : fd_repair_metrics_t * slot_metrics;
316 : ulong turbine_slot0; // catchup considered complete after this slot
317 :
318 : ulong send_pkt_cnt_ref;
319 : long send_pkt_ref_ts;
320 : };
321 : typedef struct ctx ctx_t;
322 :
323 : FD_FN_CONST static inline ulong
324 0 : scratch_align( void ) {
325 0 : return 128UL;
326 0 : }
327 :
328 : FD_FN_PURE static inline ulong
329 0 : loose_footprint( fd_topo_tile_t const * tile FD_PARAM_UNUSED ) {
330 0 : return 1UL * FD_SHMEM_GIGANTIC_PAGE_SZ;
331 0 : }
332 :
333 : FD_FN_PURE static inline ulong
334 0 : scratch_footprint( fd_topo_tile_t const * tile ) {
335 0 : ulong total_sign_depth = tile->repair.repair_sign_depth * tile->repair.repair_sign_cnt;
336 0 : int lg_sign_depth = fd_ulong_find_msb( fd_ulong_pow2_up(total_sign_depth) ) + 1;
337 :
338 0 : ulong l = FD_LAYOUT_INIT;
339 0 : l = FD_LAYOUT_APPEND( l, alignof(ctx_t), sizeof(ctx_t) );
340 0 : l = FD_LAYOUT_APPEND( l, fd_repair_align(), fd_repair_footprint () );
341 0 : l = FD_LAYOUT_APPEND( l, fd_forest_align(), fd_forest_footprint ( tile->repair.slot_max ) );
342 0 : l = FD_LAYOUT_APPEND( l, fd_policy_align(), fd_policy_footprint ( FD_NEEDED_KEY_MAX, FD_ACTIVE_KEY_MAX ) );
343 0 : l = FD_LAYOUT_APPEND( l, fd_inflights_align(), fd_inflights_footprint () );
344 0 : l = FD_LAYOUT_APPEND( l, fd_fec_sig_align(), fd_fec_sig_footprint ( 20 ) );
345 0 : l = FD_LAYOUT_APPEND( l, fd_signs_map_align(), fd_signs_map_footprint ( lg_sign_depth ) );
346 0 : l = FD_LAYOUT_APPEND( l, fd_signs_queue_align(), fd_signs_queue_footprint() );
347 0 : l = FD_LAYOUT_APPEND( l, fd_repair_metrics_align(), fd_repair_metrics_footprint() );
348 0 : return FD_LAYOUT_FINI( l, scratch_align() );
349 0 : }
350 :
351 : /* Below functions manage the current pending sign requests. */
352 :
353 : sign_req_t *
354 : sign_map_insert( ctx_t * ctx,
355 : fd_repair_msg_t const * msg,
356 0 : pong_data_t const * opt_pong_data ) {
357 :
358 : /* Check if there is any space for a new pending sign request. Should never fail as long as credit management is working. */
359 0 : if( FD_UNLIKELY( fd_signs_map_key_cnt( ctx->signs_map )==fd_signs_map_key_max( ctx->signs_map ) ) ) return NULL;
360 :
361 0 : sign_req_t * pending = fd_signs_map_insert( ctx->signs_map, ctx->pending_key_next++ );
362 0 : if( FD_UNLIKELY( !pending ) ) return NULL; // Not possible, unless the same nonce is used twice.
363 0 : pending->msg = *msg;
364 0 : pending->buflen = fd_repair_sz( msg );
365 0 : if( FD_UNLIKELY( opt_pong_data ) ) pending->pong_data = *opt_pong_data;
366 0 : return pending;
367 0 : }
368 :
369 : int
370 : sign_map_remove( ctx_t * ctx,
371 0 : ulong key ) {
372 0 : sign_req_t * pending = fd_signs_map_query( ctx->signs_map, key, NULL );
373 0 : if( FD_UNLIKELY( !pending ) ) return -1;
374 0 : fd_signs_map_remove( ctx->signs_map, pending );
375 0 : return 0;
376 0 : }
377 :
378 : static void
379 : send_packet( ctx_t * ctx,
380 : fd_stem_context_t * stem,
381 : int is_intake,
382 : uint dst_ip_addr,
383 : ushort dst_port,
384 : uint src_ip_addr,
385 : uchar const * payload,
386 : ulong payload_sz,
387 0 : ulong tsorig ) {
388 0 : ctx->metrics->send_pkt_cnt++;
389 0 : uchar * packet = fd_chunk_to_laddr( ctx->net_out_mem, ctx->net_out_chunk );
390 0 : fd_ip4_udp_hdrs_t * hdr = (fd_ip4_udp_hdrs_t *)packet;
391 0 : *hdr = *(is_intake ? ctx->intake_hdr : ctx->serve_hdr);
392 :
393 0 : fd_ip4_hdr_t * ip4 = hdr->ip4;
394 0 : ip4->saddr = src_ip_addr;
395 0 : ip4->daddr = dst_ip_addr;
396 0 : ip4->net_id = fd_ushort_bswap( ctx->net_id++ );
397 0 : ip4->check = 0U;
398 0 : ip4->net_tot_len = fd_ushort_bswap( (ushort)(payload_sz + sizeof(fd_ip4_hdr_t)+sizeof(fd_udp_hdr_t)) );
399 0 : ip4->check = fd_ip4_hdr_check_fast( ip4 );
400 :
401 0 : fd_udp_hdr_t * udp = hdr->udp;
402 0 : udp->net_dport = dst_port;
403 0 : udp->net_len = fd_ushort_bswap( (ushort)(payload_sz + sizeof(fd_udp_hdr_t)) );
404 0 : fd_memcpy( packet+sizeof(fd_ip4_udp_hdrs_t), payload, payload_sz );
405 0 : hdr->udp->check = 0U;
406 :
407 0 : ulong tspub = fd_frag_meta_ts_comp( fd_tickcount() );
408 0 : ulong sig = fd_disco_netmux_sig( dst_ip_addr, dst_port, dst_ip_addr, DST_PROTO_OUTGOING, sizeof(fd_ip4_udp_hdrs_t) );
409 0 : ulong packet_sz = payload_sz + sizeof(fd_ip4_udp_hdrs_t);
410 0 : ulong chunk = ctx->net_out_chunk;
411 0 : fd_stem_publish( stem, ctx->net_out_idx, sig, chunk, packet_sz, 0UL, tsorig, tspub );
412 0 : ctx->net_out_chunk = fd_dcache_compact_next( chunk, packet_sz, ctx->net_out_chunk0, ctx->net_out_wmark );
413 0 : }
414 :
415 : /* Returns a sign_out context with max available credits.
416 : If no sign_out context has available credits, returns NULL. */
417 : static out_ctx_t *
418 0 : sign_avail_credits( ctx_t * ctx ) {
419 0 : out_ctx_t * sign_out = NULL;
420 0 : ulong max_credits = 0;
421 0 : for( uint i = 0; i < ctx->repair_sign_cnt; i++ ) {
422 0 : if( ctx->repair_sign_out_ctx[i].credits > max_credits ) {
423 0 : max_credits = ctx->repair_sign_out_ctx[i].credits;
424 0 : sign_out = &ctx->repair_sign_out_ctx[i];
425 0 : }
426 0 : }
427 0 : return sign_out;
428 0 : }
429 :
430 : /* Prepares the signing preimage and publishes a signing request that
431 : will be signed asynchronously by the sign tile. The signed data will
432 : be returned via dcache as a frag. */
433 : static void
434 : fd_repair_send_sign_request( ctx_t * ctx,
435 : out_ctx_t * sign_out,
436 : fd_repair_msg_t const * msg,
437 0 : pong_data_t const * opt_pong_data ){
438 : /* New sign request */
439 0 : sign_req_t * pending = sign_map_insert( ctx, msg, opt_pong_data );
440 0 : if( FD_UNLIKELY( !pending ) ) return;
441 :
442 0 : ulong sig = 0;
443 0 : ulong preimage_sz = 0;
444 0 : uchar * dst = fd_chunk_to_laddr( sign_out->mem, sign_out->chunk );
445 :
446 0 : if( FD_UNLIKELY( msg->kind == FD_REPAIR_KIND_PONG ) ) {
447 0 : uchar pre_image[FD_REPAIR_PONG_PREIMAGE_SZ];
448 0 : preimage_pong( &opt_pong_data->hash, pre_image, sizeof(pre_image) );
449 0 : preimage_sz = FD_REPAIR_PONG_PREIMAGE_SZ;
450 0 : fd_memcpy( dst, pre_image, preimage_sz );
451 0 : sig = ((ulong)pending->key << 32) | (uint)FD_KEYGUARD_SIGN_TYPE_SHA256_ED25519;
452 0 : } else {
453 : /* Sign and prepare the message directly into the pending buffer */
454 0 : uchar * preimage = preimage_req( &pending->msg, &preimage_sz );
455 0 : fd_memcpy( dst, preimage, preimage_sz );
456 0 : sig = ((ulong)pending->key << 32) | (uint)FD_KEYGUARD_SIGN_TYPE_ED25519;
457 0 : }
458 :
459 0 : fd_stem_publish( ctx->stem, sign_out->idx, sig, sign_out->chunk, preimage_sz, 0UL, 0UL, 0UL );
460 0 : sign_out->chunk = fd_dcache_compact_next( sign_out->chunk, preimage_sz, sign_out->chunk0, sign_out->wmark );
461 :
462 0 : ctx->metrics->sent_pkt_types[metric_index[msg->kind]]++;
463 0 : sign_out->credits--;
464 0 : }
465 :
466 : static inline int
467 : before_frag( ctx_t * ctx,
468 : ulong in_idx,
469 : ulong seq FD_PARAM_UNUSED,
470 0 : ulong sig ) {
471 0 : uint in_kind = ctx->in_kind[ in_idx ];
472 0 : if( FD_LIKELY ( in_kind==IN_KIND_NET ) ) return fd_disco_netmux_sig_proto( sig )!=DST_PROTO_REPAIR;
473 0 : if( FD_UNLIKELY( in_kind==IN_KIND_SHRED ) ) return fd_int_if( fd_forest_root_slot( ctx->forest )==ULONG_MAX, -1, 0 ); /* not ready to read frag */
474 0 : if( FD_UNLIKELY( in_kind==IN_KIND_GOSSIP ) ) {
475 0 : return sig!=FD_GOSSIP_UPDATE_TAG_CONTACT_INFO &&
476 0 : sig!=FD_GOSSIP_UPDATE_TAG_CONTACT_INFO_REMOVE;
477 0 : }
478 0 : return 0;
479 0 : }
480 :
481 : static void
482 : during_frag( ctx_t * ctx,
483 : ulong in_idx,
484 : ulong seq FD_PARAM_UNUSED,
485 : ulong sig FD_PARAM_UNUSED,
486 : ulong chunk,
487 : ulong sz,
488 0 : ulong ctl ) {
489 0 : ctx->skip_frag = 0;
490 :
491 0 : uint in_kind = ctx->in_kind[ in_idx ];
492 0 : in_ctx_t const * in_ctx = &ctx->in_links[ in_idx ];
493 :
494 0 : if( FD_UNLIKELY( in_kind==IN_KIND_TOWER ) ) {
495 0 : if( FD_UNLIKELY( chunk<in_ctx->chunk0 || chunk>in_ctx->wmark || sz>in_ctx->mtu ) ) {
496 0 : FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, in_ctx->chunk0, in_ctx->wmark ));
497 0 : }
498 0 : uchar const * dcache_entry = fd_chunk_to_laddr_const( in_ctx->mem, chunk );
499 0 : fd_memcpy( ctx->buffer, dcache_entry, sz );
500 0 : return;
501 0 : }
502 :
503 0 : if( FD_UNLIKELY( in_kind==IN_KIND_GENESIS ) ) {
504 0 : return;
505 0 : }
506 0 : if( FD_UNLIKELY( in_kind==IN_KIND_NET ) ) {
507 0 : uchar const * dcache_entry = fd_net_rx_translate_frag( &in_ctx->net_rx, chunk, ctl, sz );
508 0 : fd_memcpy( ctx->buffer, dcache_entry, sz );
509 0 : return;
510 0 : }
511 :
512 0 : if( FD_UNLIKELY( in_kind==IN_KIND_GOSSIP ) ) {
513 0 : if( FD_UNLIKELY( chunk<in_ctx->chunk0 || chunk>in_ctx->wmark || sz>in_ctx->mtu ) ) {
514 0 : FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, in_ctx->chunk0, in_ctx->wmark ));
515 0 : }
516 0 : uchar const * dcache_entry = fd_chunk_to_laddr_const( in_ctx->mem, chunk );
517 0 : fd_memcpy( ctx->buffer, dcache_entry, sz );
518 0 : return;
519 0 : }
520 :
521 0 : if( FD_LIKELY ( in_kind==IN_KIND_SHRED ) ) {
522 0 : if( FD_UNLIKELY( chunk<in_ctx->chunk0 || chunk>in_ctx->wmark || sz>in_ctx->mtu ) ) {
523 0 : FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, in_ctx->chunk0, in_ctx->wmark ));
524 0 : }
525 0 : uchar const * dcache_entry = fd_chunk_to_laddr_const( in_ctx->mem, chunk );
526 0 : if( FD_LIKELY( sz > 0 ) ) fd_memcpy( ctx->buffer, dcache_entry, sz );
527 0 : return;
528 0 : }
529 :
530 0 : if( FD_UNLIKELY( in_kind==IN_KIND_STAKE ) ) {
531 0 : return;
532 0 : }
533 :
534 0 : if( FD_UNLIKELY( in_kind==IN_KIND_SNAP ) ) {
535 0 : if( FD_UNLIKELY( fd_ssmsg_sig_message( sig )!=FD_SSMSG_DONE ) ) ctx->snap_out_chunk = chunk;
536 0 : return;
537 0 : }
538 :
539 0 : if( FD_UNLIKELY( in_kind==IN_KIND_SIGN ) ) {
540 0 : if( FD_UNLIKELY( chunk<in_ctx->chunk0 || chunk>in_ctx->wmark || sz>in_ctx->mtu ) ) {
541 0 : FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, in_ctx->chunk0, in_ctx->wmark ));
542 0 : }
543 0 : uchar const * dcache_entry = fd_chunk_to_laddr_const( in_ctx->mem, chunk );
544 0 : fd_memcpy( ctx->buffer, dcache_entry, sz );
545 0 : return;
546 0 : }
547 :
548 0 : FD_LOG_ERR(( "Frag from unknown link (kind=%u in_idx=%lu)", in_kind, in_idx ));
549 0 : }
550 :
551 : static inline void
552 : after_snap( ctx_t * ctx,
553 : ulong sig,
554 0 : uchar const * chunk ) {
555 0 : if( FD_UNLIKELY( fd_ssmsg_sig_message( sig )!=FD_SSMSG_DONE ) ) return;
556 0 : fd_snapshot_manifest_t * manifest = (fd_snapshot_manifest_t *)chunk;
557 :
558 0 : fd_forest_init( ctx->forest, manifest->slot );
559 0 : FD_TEST( fd_forest_root_slot( ctx->forest )!=ULONG_MAX );
560 0 : }
561 :
562 : static inline void
563 0 : after_contact( ctx_t * ctx, fd_gossip_update_message_t const * msg ) {
564 0 : fd_contact_info_t const * contact_info = msg->contact_info.contact_info;
565 0 : fd_ip4_port_t repair_peer = contact_info->sockets[ FD_CONTACT_INFO_SOCKET_SERVE_REPAIR ];
566 0 : if( FD_UNLIKELY( !repair_peer.addr || !repair_peer.port ) ) return;
567 0 : fd_policy_peer_t const * peer = fd_policy_peer_insert( ctx->policy, &contact_info->pubkey, &repair_peer );
568 0 : if( peer ) {
569 : /* The repair process uses a Ping-Pong protocol that incurs one
570 : round-trip time (RTT) for the initial repair request. To
571 : optimize this, we proactively send a placeholder repair request
572 : as soon as we receive a peer's contact information for the first
573 : time, effectively prepaying the RTT cost. */
574 0 : fd_repair_msg_t * init = fd_repair_shred( ctx->protocol, &contact_info->pubkey, (ulong)fd_log_wallclock()/1000000L, 0, 0, 0 );
575 0 : fd_signs_queue_push( ctx->sign_queue, (sign_pending_t){ .msg = *init } );
576 0 : }
577 0 : }
578 :
579 : static inline void
580 : after_sign( ctx_t * ctx,
581 : ulong in_idx,
582 : ulong sig,
583 0 : fd_stem_context_t * stem ) {
584 0 : ulong pending_key = sig >> 32;
585 : /* Look up the pending request. Since the repair_sign links are
586 : reliable, the incoming sign_repair fragments represent a complete
587 : set of the previously sent outgoing messages. However, with
588 : multiple sign tiles, the responses may arrive interleaved. */
589 :
590 : /* Find which sign tile sent this response and increment its credits */
591 0 : for( uint i = 0; i < ctx->repair_sign_cnt; i++ ) {
592 0 : if( ctx->repair_sign_out_ctx[i].in_idx == in_idx ) {
593 0 : if( ctx->repair_sign_out_ctx[i].credits < ctx->repair_sign_out_ctx[i].max_credits ) {
594 0 : ctx->repair_sign_out_ctx[i].credits++;
595 0 : }
596 0 : break;
597 0 : }
598 0 : }
599 :
600 0 : sign_req_t * pending_ = fd_signs_map_query( ctx->signs_map, pending_key, NULL );
601 0 : sign_req_t pending[1] = { *pending_ }; /* Make a copy of the pending request so we can sign_map_remove immediately. */
602 0 : sign_map_remove( ctx, pending_key );
603 :
604 0 : if( FD_UNLIKELY( !pending_ ) ) FD_LOG_CRIT(( "No pending request found for key %lu", pending_key ));
605 :
606 : /* Thhis is a pong message */
607 0 : if( FD_UNLIKELY( pending->msg.kind == FD_REPAIR_KIND_PONG ) ) {
608 0 : fd_memcpy( pending->msg.pong.sig, ctx->buffer, 64UL );
609 0 : send_packet( ctx, stem, 1, pending->pong_data.peer_addr.addr, pending->pong_data.peer_addr.port, pending->pong_data.daddr, pending->buf, fd_repair_sz( &pending->msg ), fd_frag_meta_ts_comp( fd_tickcount() ) );
610 0 : return;
611 0 : }
612 :
613 : /* Inject the signature into the pending request */
614 0 : fd_memcpy( pending->buf + 4, ctx->buffer, 64UL );
615 0 : uint src_ip4 = 0U;
616 :
617 : /* This is a warmup message */
618 0 : if( FD_UNLIKELY( pending->msg.kind == FD_REPAIR_KIND_SHRED && pending->msg.shred.slot == 0 ) ) {
619 0 : fd_policy_peer_t * active = fd_policy_peer_query( ctx->policy, &pending->msg.shred.to );
620 0 : if( FD_UNLIKELY( active ) ) send_packet( ctx, stem, 1, active->ip4, active->port, src_ip4, pending->buf, pending->buflen, fd_frag_meta_ts_comp( fd_tickcount() ) );
621 0 : else { /* This is a warmup request for a peer that is no longer active. There's no reason to pick another peer for a warmup rq, so just drop it. */ }
622 0 : return;
623 0 : }
624 :
625 : /* This is a regular repair shred request
626 :
627 : TODO: anyways to make this less complicated? Essentially we need to
628 : ensure we always send out any shred requests we have, because policy_next
629 : has no way to revisit a shred. But the fact that peers can drop out
630 : of the active peer list makes this complicated.
631 :
632 : 1. If the peer is still there (common), it's fine.
633 : 2. If the peer is not there, we can select another peer and send the request.
634 : 3. If the peer is not there, and we have no other peers, we can add
635 : this request to the inflights table, pretend we've sent it and
636 : let the inflight timeout request it down the line.
637 : */
638 0 : fd_policy_peer_t * active = fd_policy_peer_query( ctx->policy, &pending->msg.shred.to );
639 0 : int is_regular_req = pending->msg.kind == FD_REPAIR_KIND_SHRED && pending->msg.shred.nonce > 0; // not a highest/orphan request
640 :
641 0 : if( FD_UNLIKELY( !active ) ) {
642 0 : fd_pubkey_t const * new_peer = fd_policy_peer_select( ctx->policy );
643 0 : if( FD_LIKELY( new_peer ) ) {
644 : /* We have a new peer, so we can send the request */
645 0 : pending->msg.shred.to = *new_peer;
646 0 : fd_signs_queue_push( ctx->sign_queue, (sign_pending_t){ .msg = pending->msg } );
647 0 : }
648 :
649 0 : if( FD_UNLIKELY( !new_peer && is_regular_req ) ) {
650 : /* This is real devastation - we clearly had a peer at the time of
651 : making this request, but for some reason we now have ZERO
652 : peers. The only thing we can do is to add this artificially to
653 : the inflights table, pretend we've sent it and let the inflight
654 : timeout request it down the line. */
655 0 : fd_inflights_request_insert( ctx->inflight, pending->msg.shred.nonce, &pending->msg.shred.to, pending->msg.shred.slot, pending->msg.shred.shred_idx );
656 0 : }
657 0 : return;
658 0 : }
659 : /* Happy path - all is well, our peer didn't drop out from beneath us. */
660 0 : if( FD_LIKELY( is_regular_req ) ) {
661 0 : fd_inflights_request_insert( ctx->inflight, pending->msg.shred.nonce, &pending->msg.shred.to, pending->msg.shred.slot, pending->msg.shred.shred_idx );
662 0 : fd_policy_peer_request_update( ctx->policy, &pending->msg.shred.to );
663 0 : }
664 0 : send_packet( ctx, stem, 1, active->ip4, active->port, src_ip4, pending->buf, pending->buflen, fd_frag_meta_ts_comp( fd_tickcount() ) );
665 0 : }
666 :
667 : static inline void
668 : after_shred( ctx_t * ctx,
669 : ulong sig,
670 : fd_shred_t * shred,
671 0 : ulong nonce ) {
672 : /* Insert the shred sig (shared by all shred members in the FEC set)
673 : into the map. */
674 :
675 0 : int is_code = fd_shred_is_code( fd_shred_type( shred->variant ) );
676 0 : int src = fd_disco_shred_out_shred_sig_is_turbine( sig ) ? SHRED_SRC_TURBINE : SHRED_SRC_REPAIR;
677 0 : if( FD_LIKELY( !is_code ) ) {
678 0 : long rtt = 0;
679 0 : fd_pubkey_t peer;
680 0 : if( FD_UNLIKELY( ( rtt = fd_inflights_request_remove( ctx->inflight, nonce, &peer ) ) > 0 ) ) {
681 0 : fd_policy_peer_response_update( ctx->policy, &peer, rtt );
682 0 : fd_histf_sample( ctx->metrics->response_latency, (ulong)rtt );
683 0 : }
684 :
685 0 : int slot_complete = !!(shred->data.flags & FD_SHRED_DATA_FLAG_SLOT_COMPLETE);
686 0 : int ref_tick = shred->data.flags & FD_SHRED_DATA_REF_TICK_MASK;
687 0 : fd_forest_blk_insert( ctx->forest, shred->slot, shred->slot - shred->data.parent_off );
688 0 : fd_forest_data_shred_insert( ctx->forest, shred->slot, shred->slot - shred->data.parent_off, shred->idx, shred->fec_set_idx, slot_complete, ref_tick, src );
689 0 : } else {
690 0 : fd_forest_code_shred_insert( ctx->forest, shred->slot, shred->idx );
691 0 : }
692 0 : }
693 :
694 : static inline void
695 : after_fec( ctx_t * ctx,
696 0 : fd_shred_t * shred ) {
697 :
698 : /* When this is a FEC completes msg, it is implied that all the
699 : other shreds in the FEC set can also be inserted. Shred inserts
700 : into the forest are idempotent so it is fine to insert the same
701 : shred multiple times. */
702 :
703 0 : int slot_complete = !!( shred->data.flags & FD_SHRED_DATA_FLAG_SLOT_COMPLETE );
704 0 : int ref_tick = shred->data.flags & FD_SHRED_DATA_REF_TICK_MASK;
705 :
706 0 : fd_forest_blk_t * ele = fd_forest_blk_insert( ctx->forest, shred->slot, shred->slot - shred->data.parent_off );
707 0 : fd_forest_fec_insert( ctx->forest, shred->slot, shred->slot - shred->data.parent_off, shred->idx, shred->fec_set_idx, slot_complete, ref_tick );
708 0 : fd_fec_sig_t * fec_sig = fd_fec_sig_query( ctx->fec_sigs, (shred->slot << 32) | shred->fec_set_idx, NULL );
709 0 : if( FD_LIKELY( fec_sig ) ) fd_fec_sig_remove( ctx->fec_sigs, fec_sig );
710 0 : FD_TEST( ele ); /* must be non-empty */
711 :
712 : /* metrics for completed slots */
713 0 : if( FD_UNLIKELY( ele->complete_idx != UINT_MAX && ele->buffered_idx==ele->complete_idx &&
714 0 : 0==memcmp( ele->cmpl, ele->fecs, sizeof(fd_forest_blk_idxs_t) * fd_forest_blk_idxs_word_cnt ) ) ) {
715 0 : long now = fd_tickcount();
716 0 : long start_ts = ele->first_req_ts == 0 || ele->slot > ctx->turbine_slot0 ? ele->first_shred_ts : ele->first_req_ts;
717 0 : ulong duration_ticks = (ulong)(now - start_ts);
718 0 : fd_histf_sample( ctx->metrics->slot_compl_time, duration_ticks );
719 0 : fd_repair_metrics_add_slot( ctx->slot_metrics, ele->slot, start_ts, now, ele->repair_cnt, ele->turbine_cnt );
720 0 : FD_LOG_INFO(( "slot is complete %lu. num_data_shreds: %u, num_repaired: %u, num_turbine: %u, num_recovered: %u, duration: %.2f ms", ele->slot, ele->complete_idx + 1, ele->repair_cnt, ele->turbine_cnt, ele->recovered_cnt, (double)fd_metrics_convert_ticks_to_nanoseconds(duration_ticks) / 1e6 ));
721 0 : }
722 0 : }
723 :
724 : static inline void
725 : after_net( ctx_t * ctx,
726 0 : ulong sz ) {
727 0 : fd_eth_hdr_t const * eth = (fd_eth_hdr_t const *)ctx->buffer;
728 0 : fd_ip4_hdr_t const * ip4 = (fd_ip4_hdr_t const *)( (ulong)eth + sizeof(fd_eth_hdr_t) );
729 0 : fd_udp_hdr_t const * udp = (fd_udp_hdr_t const *)( (ulong)ip4 + FD_IP4_GET_LEN( *ip4 ) );
730 0 : uchar * data = (uchar *)( (ulong)udp + sizeof(fd_udp_hdr_t) );
731 0 : if( FD_UNLIKELY( (ulong)udp+sizeof(fd_udp_hdr_t) > (ulong)eth+sz ) ) return;
732 0 : ulong udp_sz = fd_ushort_bswap( udp->net_len );
733 0 : if( FD_UNLIKELY( udp_sz<sizeof(fd_udp_hdr_t) ) ) return;
734 0 : ulong data_sz = udp_sz-sizeof(fd_udp_hdr_t);
735 0 : if( FD_UNLIKELY( (ulong)data+data_sz > (ulong)eth+sz ) ) return;
736 :
737 0 : fd_ip4_port_t peer_addr = { .addr=ip4->saddr, .port=udp->net_sport };
738 0 : ushort dport = udp->net_dport;
739 0 : if( ctx->repair_intake_addr.port == dport ) {
740 0 : if( FD_UNLIKELY( data_sz < sizeof(fd_repair_ping_t) ) ) {
741 : /* TODO: increment a malformed repair ping counter? */
742 0 : return;
743 0 : }
744 0 : fd_repair_ping_t * res = (fd_repair_ping_t *)fd_type_pun( data );
745 0 : switch( res->kind ) {
746 0 : case FD_REPAIR_KIND_PING: {
747 0 : fd_repair_msg_t * pong = fd_repair_pong( ctx->protocol, &res->ping.hash );
748 0 : fd_signs_queue_push( ctx->sign_queue, (sign_pending_t){ .msg = *pong, .pong_data = { .peer_addr = peer_addr, .hash = res->ping.hash, .daddr = ip4->daddr } } );
749 0 : break;
750 0 : }
751 0 : default: FD_LOG_ERR(( "unhandled kind %u", (uint)res->kind ));
752 0 : }
753 0 : } else {
754 0 : FD_LOG_WARNING(( "Unexpectedly received packet for port %u", (uint)fd_ushort_bswap( dport ) ));
755 0 : }
756 0 : }
757 :
758 : static inline void
759 : after_evict( ctx_t * ctx,
760 0 : ulong sig ) {
761 0 : ulong spilled_slot = fd_disco_shred_out_shred_sig_slot ( sig );
762 0 : uint spilled_fec_set_idx = fd_disco_shred_out_shred_sig_fec_set_idx( sig );
763 0 : uint spilled_max_idx = fd_disco_shred_out_shred_sig_data_cnt ( sig );
764 :
765 0 : fd_forest_fec_clear( ctx->forest, spilled_slot, spilled_fec_set_idx, spilled_max_idx );
766 0 : }
767 :
768 : static void
769 : after_frag( ctx_t * ctx,
770 : ulong in_idx,
771 : ulong seq FD_PARAM_UNUSED,
772 : ulong sig,
773 : ulong sz,
774 : ulong tsorig FD_PARAM_UNUSED,
775 : ulong tspub FD_PARAM_UNUSED,
776 0 : fd_stem_context_t * stem ) {
777 0 : if( FD_UNLIKELY( ctx->skip_frag ) ) return;
778 :
779 0 : ctx->stem = stem;
780 :
781 0 : uint in_kind = ctx->in_kind[ in_idx ];
782 0 : if( FD_UNLIKELY( in_kind==IN_KIND_GENESIS && sig==GENESI_SIG_BOOTSTRAP_COMPLETED ) ) {
783 0 : fd_forest_init( ctx->forest, 0 );
784 0 : return;
785 0 : }
786 :
787 0 : if( FD_UNLIKELY( in_kind==IN_KIND_GOSSIP ) ) {
788 0 : fd_gossip_update_message_t const * msg = (fd_gossip_update_message_t const *)fd_type_pun_const( ctx->buffer );
789 0 : if( FD_LIKELY( sig==FD_GOSSIP_UPDATE_TAG_CONTACT_INFO ) ){
790 0 : after_contact( ctx, msg );
791 0 : } else {
792 0 : fd_policy_peer_remove( ctx->policy, &msg->contact_info.contact_info->pubkey );
793 0 : }
794 0 : return;
795 0 : }
796 :
797 0 : if( FD_UNLIKELY( in_kind==IN_KIND_TOWER ) ) {
798 0 : fd_tower_slot_done_t const * msg = (fd_tower_slot_done_t const *)fd_type_pun_const( ctx->buffer );
799 0 : if( FD_LIKELY( msg->new_root ) ) fd_forest_publish( ctx->forest, msg->root_slot );
800 0 : return;
801 0 : }
802 :
803 0 : if( FD_UNLIKELY( in_kind==IN_KIND_SIGN ) ) {
804 0 : after_sign( ctx, in_idx, sig, stem );
805 0 : return;
806 0 : }
807 :
808 0 : if( FD_UNLIKELY( in_kind==IN_KIND_SHRED ) ) {
809 : /* There are 3 message types from shred:
810 : 1. resolver evict - incomplete FEC set is evicted by resolver
811 : 2. fec complete - FEC set is completed by resolver. Also contains a shred.
812 : 3. shred - new shred
813 :
814 : Msgs 2 and 3 have a shred header in ctx->buffer */
815 0 : int resolver_evicted = sz == 0;
816 0 : int fec_completes = sz == FD_SHRED_DATA_HEADER_SZ + sizeof(fd_hash_t) + sizeof(fd_hash_t) + sizeof(int);
817 0 : if( FD_UNLIKELY( resolver_evicted ) ) {
818 0 : after_evict( ctx, sig );
819 0 : return;
820 0 : }
821 :
822 0 : fd_shred_t * shred = (fd_shred_t *)fd_type_pun( ctx->buffer );
823 0 : uint nonce = FD_LOAD(uint, ctx->buffer + fd_shred_header_sz( shred->variant ) );
824 0 : if( FD_UNLIKELY( shred->slot <= fd_forest_root_slot( ctx->forest ) ) ) {
825 0 : FD_LOG_INFO(( "shred %lu %u %u too old, ignoring", shred->slot, shred->idx, shred->fec_set_idx ));
826 0 : return;
827 0 : };
828 0 : # if LOGGING
829 0 : if( FD_UNLIKELY( shred->slot > ctx->metrics->current_slot ) ) {
830 0 : FD_LOG_INFO(( "\n\n[Turbine]\n"
831 0 : "slot: %lu\n"
832 0 : "root: %lu\n",
833 0 : shred->slot,
834 0 : fd_forest_root_slot( ctx->forest ) ));
835 0 : }
836 0 : # endif
837 0 : ctx->metrics->current_slot = fd_ulong_max( shred->slot, ctx->metrics->current_slot );
838 0 : if( FD_UNLIKELY( ctx->turbine_slot0 == ULONG_MAX ) ) {
839 0 : ctx->turbine_slot0 = shred->slot;
840 0 : fd_repair_metrics_set_turbine_slot0( ctx->slot_metrics, shred->slot );
841 0 : fd_policy_set_turbine_slot0( ctx->policy, shred->slot );
842 0 : }
843 :
844 0 : if( FD_UNLIKELY( fec_completes ) ) {
845 0 : after_fec( ctx, shred );
846 0 : } else {
847 : /* Don't want to reinsert the shred sig for an already complete FEC set */
848 0 : fd_fec_sig_t * fec_sig = fd_fec_sig_query( ctx->fec_sigs, (shred->slot << 32) | shred->fec_set_idx, NULL );
849 0 : if( FD_UNLIKELY( !fec_sig ) ) {
850 0 : fec_sig = fd_fec_sig_insert( ctx->fec_sigs, (shred->slot << 32) | shred->fec_set_idx );
851 0 : memcpy( fec_sig->sig, shred->signature, sizeof(fd_ed25519_sig_t) );
852 0 : }
853 0 : after_shred( ctx, sig, shred, nonce );
854 0 : }
855 :
856 : /* Check if there are FECs to force complete. Algorithm: window
857 : through the idxs in interval [i, j). If j = next fec_set_idx
858 : then we know we can force complete the FEC set interval [i, j)
859 : (assuming it wasn't already completed based on `cmpl`). */
860 :
861 0 : fd_forest_blk_t * blk = fd_forest_query( ctx->forest, shred->slot );
862 0 : if( blk ) {
863 0 : uint i = blk->consumed_idx + 1;
864 0 : for( uint j = i; j < blk->buffered_idx + 1; j++ ) {
865 0 : if( FD_UNLIKELY( fd_forest_blk_idxs_test( blk->fecs, j ) ) ) {
866 0 : if( FD_UNLIKELY( fd_forest_blk_idxs_test( blk->cmpl, j ) ) ) {
867 : /* already been completed without force complete */
868 0 : } else {
869 : /* force completeable */
870 0 : fd_fec_sig_t * fec_sig = fd_fec_sig_query( ctx->fec_sigs, (shred->slot << 32) | i, NULL );
871 0 : if( FD_LIKELY( fec_sig ) ) {
872 0 : ulong sig = fd_ulong_load_8( fec_sig->sig );
873 0 : ulong tile_idx = sig % ctx->shred_tile_cnt;
874 0 : uint last_idx = j - i;
875 :
876 0 : uchar * chunk = fd_chunk_to_laddr( ctx->shred_out_ctx[tile_idx].mem, ctx->shred_out_ctx[tile_idx].chunk );
877 0 : memcpy( chunk, fec_sig->sig, sizeof(fd_ed25519_sig_t) );
878 0 : fd_fec_sig_remove( ctx->fec_sigs, fec_sig );
879 0 : fd_stem_publish( stem, ctx->shred_out_ctx[tile_idx].idx, last_idx, ctx->shred_out_ctx[tile_idx].chunk, sizeof(fd_ed25519_sig_t), 0UL, 0UL, 0UL );
880 0 : ctx->shred_out_ctx[tile_idx].chunk = fd_dcache_compact_next( ctx->shred_out_ctx[tile_idx].chunk, sizeof(fd_ed25519_sig_t), ctx->shred_out_ctx[tile_idx].chunk0, ctx->shred_out_ctx[tile_idx].wmark );
881 0 : }
882 0 : }
883 : /* advance consumed */
884 0 : blk->consumed_idx = j;
885 0 : i = j + 1;
886 0 : }
887 0 : }
888 0 : }
889 : /* update metrics */
890 0 : ctx->metrics->repaired_slots = fd_forest_highest_repaired_slot( ctx->forest );
891 0 : return;
892 0 : }
893 :
894 0 : if( FD_UNLIKELY( in_kind==IN_KIND_STAKE ) ) {
895 0 : return;
896 0 : }
897 :
898 0 : if( FD_UNLIKELY( in_kind==IN_KIND_SNAP ) ) {
899 0 : after_snap( ctx, sig, fd_chunk_to_laddr( ctx->in_links[ in_idx ].mem, ctx->snap_out_chunk ) );
900 0 : return;
901 0 : }
902 :
903 0 : if( FD_UNLIKELY( in_kind==IN_KIND_NET ) ) {
904 0 : after_net( ctx, sz );
905 0 : return;
906 0 : }
907 0 : }
908 :
909 : static inline void
910 : after_credit( ctx_t * ctx,
911 : fd_stem_context_t * stem FD_PARAM_UNUSED,
912 : int * opt_poll_in FD_PARAM_UNUSED,
913 0 : int * charge_busy ) {
914 0 : long now = fd_log_wallclock();
915 :
916 : /* Verify that there is at least one sign tile with available credits.
917 : If not, we can't send any requests and leave early. */
918 0 : out_ctx_t * sign_out = sign_avail_credits( ctx );
919 0 : if( FD_UNLIKELY( !sign_out ) ) {
920 0 : ctx->metrics->sign_tile_unavail++;
921 0 : return;
922 0 : }
923 0 : if( FD_UNLIKELY( !fd_signs_queue_empty( ctx->sign_queue ) ) ) {
924 0 : sign_pending_t signable = fd_signs_queue_pop( ctx->sign_queue );
925 0 : fd_repair_send_sign_request( ctx, sign_out, &signable.msg, signable.msg.kind == FD_REPAIR_KIND_PONG ? &signable.pong_data : NULL );
926 0 : *charge_busy = 1;
927 0 : return;
928 0 : }
929 :
930 0 : if( FD_UNLIKELY( fd_inflights_should_drain( ctx->inflight, now ) ) ) {
931 0 : ulong nonce; ulong slot; ulong shred_idx;
932 0 : *charge_busy = 1;
933 0 : fd_inflights_request_pop( ctx->inflight, &nonce, &slot, &shred_idx );
934 0 : fd_forest_blk_t * blk = fd_forest_query( ctx->forest, slot );
935 0 : if( FD_UNLIKELY( blk && !fd_forest_blk_idxs_test( blk->idxs, shred_idx ) ) ) {
936 0 : fd_pubkey_t const * peer = fd_policy_peer_select( ctx->policy );
937 0 : ctx->metrics->rerequest++;
938 0 : if( FD_UNLIKELY( !peer ) ) {
939 : /* No peers. But we CANNOT lose this request. */
940 : /* Add this request to the inflights table, pretend we've sent it and let the inflight timeout request it down the line. */
941 0 : fd_hash_t hash = { .ul[0] = 0 };
942 0 : fd_inflights_request_insert( ctx->inflight, ctx->policy->nonce++, &hash, slot, shred_idx );
943 0 : } else {
944 0 : fd_repair_msg_t * msg = fd_repair_shred( ctx->protocol, peer, (ulong)((ulong)now / 1e6L), ctx->policy->nonce++, slot, shred_idx );
945 0 : fd_repair_send_sign_request( ctx, sign_out, msg, NULL );
946 0 : return;
947 0 : }
948 0 : }
949 0 : }
950 :
951 0 : fd_repair_msg_t const * cout = fd_policy_next( ctx->policy, ctx->forest, ctx->protocol, now, ctx->metrics->current_slot, charge_busy );
952 0 : if( FD_UNLIKELY( !cout ) ) return;
953 :
954 0 : fd_repair_send_sign_request( ctx, sign_out, cout, NULL );
955 0 : }
956 :
957 : static inline void
958 0 : during_housekeeping( ctx_t * ctx ) {
959 0 : (void)ctx;
960 : # if DEBUG_LOGGING
961 : long now = fd_log_wallclock();
962 : if( FD_UNLIKELY( now - ctx->tsdebug > (long)10e9 ) ) {
963 : fd_forest_print( ctx->forest );
964 : ctx->tsdebug = fd_log_wallclock();
965 : }
966 : # endif
967 0 : }
968 :
969 : static void
970 : privileged_init( fd_topo_t * topo,
971 0 : fd_topo_tile_t * tile ) {
972 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
973 :
974 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
975 0 : ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(ctx_t), sizeof(ctx_t) );
976 0 : fd_memset( ctx, 0, sizeof(ctx_t) );
977 :
978 0 : uchar const * identity_key = fd_keyload_load( tile->repair.identity_key_path, /* pubkey only: */ 0 );
979 0 : fd_memcpy( ctx->identity_public_key.uc, identity_key + 32UL, sizeof(fd_pubkey_t) );
980 :
981 0 : FD_TEST( fd_rng_secure( &ctx->repair_seed, sizeof(ulong) ) );
982 0 : }
983 :
984 : static void
985 : unprivileged_init( fd_topo_t * topo,
986 0 : fd_topo_tile_t * tile ) {
987 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
988 :
989 0 : ulong total_sign_depth = tile->repair.repair_sign_depth * tile->repair.repair_sign_cnt;
990 0 : int lg_sign_depth = fd_ulong_find_msb( fd_ulong_pow2_up(total_sign_depth) ) + 1;
991 :
992 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
993 0 : ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(ctx_t), sizeof(ctx_t) );
994 0 : ctx->protocol = FD_SCRATCH_ALLOC_APPEND( l, fd_repair_align(), fd_repair_footprint () );
995 0 : ctx->forest = FD_SCRATCH_ALLOC_APPEND( l, fd_forest_align(), fd_forest_footprint ( tile->repair.slot_max ) );
996 0 : ctx->policy = FD_SCRATCH_ALLOC_APPEND( l, fd_policy_align(), fd_policy_footprint ( FD_NEEDED_KEY_MAX, FD_ACTIVE_KEY_MAX ) );
997 0 : ctx->inflight = FD_SCRATCH_ALLOC_APPEND( l, fd_inflights_align(), fd_inflights_footprint () );
998 0 : ctx->fec_sigs = FD_SCRATCH_ALLOC_APPEND( l, fd_fec_sig_align(), fd_fec_sig_footprint ( 20 ) );
999 0 : ctx->signs_map = FD_SCRATCH_ALLOC_APPEND( l, fd_signs_map_align(), fd_signs_map_footprint ( lg_sign_depth ) );
1000 0 : ctx->sign_queue = FD_SCRATCH_ALLOC_APPEND( l, fd_signs_queue_align(), fd_signs_queue_footprint() );
1001 0 : ctx->slot_metrics = FD_SCRATCH_ALLOC_APPEND( l, fd_repair_metrics_align(), fd_repair_metrics_footprint() );
1002 0 : FD_TEST( FD_SCRATCH_ALLOC_FINI( l, scratch_align() ) == (ulong)scratch + scratch_footprint( tile ) );
1003 :
1004 0 : ctx->protocol = fd_repair_join ( fd_repair_new ( ctx->protocol, &ctx->identity_public_key ) );
1005 0 : ctx->forest = fd_forest_join ( fd_forest_new ( ctx->forest, tile->repair.slot_max, ctx->repair_seed ) );
1006 0 : ctx->policy = fd_policy_join ( fd_policy_new ( ctx->policy, FD_NEEDED_KEY_MAX, FD_ACTIVE_KEY_MAX, ctx->repair_seed ) );
1007 0 : ctx->inflight = fd_inflights_join ( fd_inflights_new ( ctx->inflight ) );
1008 0 : ctx->fec_sigs = fd_fec_sig_join ( fd_fec_sig_new ( ctx->fec_sigs, 20 ) );
1009 0 : ctx->signs_map = fd_signs_map_join ( fd_signs_map_new ( ctx->signs_map, lg_sign_depth ) );
1010 0 : ctx->sign_queue = fd_signs_queue_join ( fd_signs_queue_new ( ctx->sign_queue ) );
1011 0 : ctx->slot_metrics = fd_repair_metrics_join( fd_repair_metrics_new( ctx->slot_metrics ) );
1012 :
1013 : /* Process in links */
1014 :
1015 0 : if( FD_UNLIKELY( tile->in_cnt > MAX_IN_LINKS ) ) FD_LOG_ERR(( "repair tile has too many input links" ));
1016 :
1017 0 : uint sign_repair_in_idx[ MAX_SIGN_TILE_CNT ] = {0};
1018 0 : uint sign_repair_idx = 0;
1019 0 : ulong sign_link_depth = 0;
1020 :
1021 0 : for( uint in_idx=0U; in_idx<(tile->in_cnt); in_idx++ ) {
1022 0 : fd_topo_link_t * link = &topo->links[ tile->in_link_id[ in_idx ] ];
1023 0 : if( 0==strcmp( link->name, "net_repair" ) ) {
1024 0 : ctx->in_kind[ in_idx ] = IN_KIND_NET;
1025 0 : fd_net_rx_bounds_init( &ctx->in_links[ in_idx ].net_rx, link->dcache );
1026 0 : continue;
1027 0 : } else if( 0==strcmp( link->name, "sign_repair" ) ) {
1028 0 : ctx->in_kind[ in_idx ] = IN_KIND_SIGN;
1029 0 : sign_repair_in_idx[ sign_repair_idx++ ] = in_idx;
1030 0 : sign_link_depth = link->depth;
1031 0 : }
1032 0 : else if( 0==strcmp( link->name, "gossip_out" ) ) ctx->in_kind[ in_idx ] = IN_KIND_GOSSIP;
1033 0 : else if( 0==strcmp( link->name, "tower_out" ) ) ctx->in_kind[ in_idx ] = IN_KIND_TOWER;
1034 0 : else if( 0==strcmp( link->name, "shred_out" ) ) ctx->in_kind[ in_idx ] = IN_KIND_SHRED;
1035 0 : else if( 0==strcmp( link->name, "snapin_manif" ) ) ctx->in_kind[ in_idx ] = IN_KIND_SNAP;
1036 0 : else if( 0==strcmp( link->name, "replay_stake" ) ) ctx->in_kind[ in_idx ] = IN_KIND_STAKE;
1037 0 : else if( 0==strcmp( link->name, "genesi_out" ) ) ctx->in_kind[ in_idx ] = IN_KIND_GENESIS;
1038 0 : else FD_LOG_ERR(( "repair tile has unexpected input link %s", link->name ));
1039 :
1040 0 : ctx->in_links[ in_idx ].mem = topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ].wksp;
1041 0 : ctx->in_links[ in_idx ].chunk0 = fd_dcache_compact_chunk0( ctx->in_links[ in_idx ].mem, link->dcache );
1042 0 : ctx->in_links[ in_idx ].wmark = fd_dcache_compact_wmark ( ctx->in_links[ in_idx ].mem, link->dcache, link->mtu );
1043 0 : ctx->in_links[ in_idx ].mtu = link->mtu;
1044 :
1045 0 : FD_TEST( fd_dcache_compact_is_safe( ctx->in_links[in_idx].mem, link->dcache, link->mtu, link->depth ) );
1046 0 : }
1047 :
1048 0 : ctx->net_out_idx = UINT_MAX;
1049 0 : ctx->shred_tile_cnt = 0;
1050 0 : ctx->repair_sign_cnt = 0;
1051 0 : ctx->sign_rrobin_idx = 0;
1052 :
1053 0 : for( uint out_idx=0U; out_idx<(tile->out_cnt); out_idx++ ) {
1054 0 : fd_topo_link_t * link = &topo->links[ tile->out_link_id[ out_idx ] ];
1055 :
1056 0 : if( 0==strcmp( link->name, "repair_net" ) ) {
1057 :
1058 0 : if( ctx->net_out_idx!=UINT_MAX ) continue; /* only use first net link */
1059 0 : ctx->net_out_idx = out_idx;
1060 0 : ctx->net_out_mem = topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ].wksp;
1061 0 : ctx->net_out_chunk0 = fd_dcache_compact_chunk0( ctx->net_out_mem, link->dcache );
1062 0 : ctx->net_out_wmark = fd_dcache_compact_wmark( ctx->net_out_mem, link->dcache, link->mtu );
1063 0 : ctx->net_out_chunk = ctx->net_out_chunk0;
1064 :
1065 0 : } else if( 0==strcmp( link->name, "repair_shred" ) ) {
1066 :
1067 0 : out_ctx_t * shred_out = &ctx->shred_out_ctx[ ctx->shred_tile_cnt++ ];
1068 0 : shred_out->idx = out_idx;
1069 0 : shred_out->mem = topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ].wksp;
1070 0 : shred_out->chunk0 = fd_dcache_compact_chunk0( shred_out->mem, link->dcache );
1071 0 : shred_out->wmark = fd_dcache_compact_wmark( shred_out->mem, link->dcache, link->mtu );
1072 0 : shred_out->chunk = shred_out->chunk0;
1073 :
1074 0 : } else if( 0==strcmp( link->name, "repair_sign" ) ) {
1075 :
1076 0 : out_ctx_t * repair_sign_out = &ctx->repair_sign_out_ctx[ ctx->repair_sign_cnt ];
1077 0 : repair_sign_out->idx = out_idx;
1078 0 : repair_sign_out->mem = topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ].wksp;
1079 0 : repair_sign_out->chunk0 = fd_dcache_compact_chunk0( repair_sign_out->mem, link->dcache );
1080 0 : repair_sign_out->wmark = fd_dcache_compact_wmark( repair_sign_out->mem, link->dcache, link->mtu );
1081 0 : repair_sign_out->chunk = repair_sign_out->chunk0;
1082 0 : repair_sign_out->in_idx = sign_repair_in_idx[ ctx->repair_sign_cnt++ ]; /* match to the sign_repair input link */
1083 0 : repair_sign_out->max_credits = sign_link_depth;
1084 0 : repair_sign_out->credits = sign_link_depth;
1085 :
1086 0 : } else {
1087 0 : FD_LOG_ERR(( "repair tile has unexpected output link %s", link->name ));
1088 0 : }
1089 0 : }
1090 0 : if( FD_UNLIKELY( ctx->net_out_idx==UINT_MAX ) ) FD_LOG_ERR(( "Missing repair_net link" ));
1091 0 : if( FD_UNLIKELY( ctx->repair_sign_cnt!=sign_repair_idx ) ) {
1092 0 : FD_LOG_ERR(( "Mismatch between repair_sign output links (%lu) and sign_repair input links (%u)", ctx->repair_sign_cnt, sign_repair_idx ));
1093 0 : }
1094 :
1095 0 : FD_TEST( ctx->shred_tile_cnt == fd_topo_tile_name_cnt( topo, "shred" ) );
1096 :
1097 : # if DEBUG_LOGGING
1098 : if( fd_signs_map_key_max( ctx->signs_map ) < tile->repair.repair_sign_depth * tile->repair.repair_sign_cnt ) {
1099 : FD_LOG_ERR(( "repair pending signs tracking map is too small: %lu < %lu. Increase the key_max", fd_signs_map_key_max( ctx->signs_map ), tile->repair.repair_sign_depth * tile->repair.repair_sign_cnt ));
1100 : }
1101 : # endif
1102 :
1103 0 : ctx->store = NULL;
1104 0 : ulong store_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "store" );
1105 0 : if( FD_LIKELY( store_obj_id!=ULONG_MAX ) ) { /* firedancer-only */
1106 0 : ctx->store = fd_store_join( fd_topo_obj_laddr( topo, store_obj_id ) );
1107 0 : FD_TEST( ctx->store->magic == FD_STORE_MAGIC );
1108 0 : }
1109 :
1110 0 : ctx->wksp = topo->workspaces[ topo->objs[ tile->tile_obj_id ].wksp_id ].wksp;
1111 0 : ctx->repair_intake_addr.port = fd_ushort_bswap( tile->repair.repair_intake_listen_port );
1112 0 : ctx->repair_serve_addr.port = fd_ushort_bswap( tile->repair.repair_serve_listen_port );
1113 :
1114 0 : ctx->net_id = (ushort)0;
1115 0 : fd_ip4_udp_hdr_init( ctx->intake_hdr, FD_REPAIR_MAX_PACKET_SIZE, 0, tile->repair.repair_intake_listen_port );
1116 0 : fd_ip4_udp_hdr_init( ctx->serve_hdr, FD_REPAIR_MAX_PACKET_SIZE, 0, tile->repair.repair_serve_listen_port );
1117 :
1118 : /* Repair set up */
1119 :
1120 0 : ctx->turbine_slot0 = ULONG_MAX;
1121 0 : FD_LOG_INFO(( "repair my addr - intake addr: " FD_IP4_ADDR_FMT ":%u, serve_addr: " FD_IP4_ADDR_FMT ":%u",
1122 0 : FD_IP4_ADDR_FMT_ARGS( ctx->repair_intake_addr.addr ), fd_ushort_bswap( ctx->repair_intake_addr.port ),
1123 0 : FD_IP4_ADDR_FMT_ARGS( ctx->repair_serve_addr.addr ), fd_ushort_bswap( ctx->repair_serve_addr.port ) ));
1124 :
1125 0 : memset( ctx->metrics, 0, sizeof(ctx->metrics) );
1126 :
1127 0 : fd_histf_join( fd_histf_new( ctx->metrics->slot_compl_time, FD_MHIST_SECONDS_MIN( REPAIR, SLOT_COMPLETE_TIME ),
1128 0 : FD_MHIST_SECONDS_MAX( REPAIR, SLOT_COMPLETE_TIME ) ) );
1129 0 : fd_histf_join( fd_histf_new( ctx->metrics->response_latency, FD_MHIST_MIN( REPAIR, RESPONSE_LATENCY ),
1130 0 : FD_MHIST_MAX( REPAIR, RESPONSE_LATENCY ) ) );
1131 :
1132 0 : ctx->tsdebug = fd_log_wallclock();
1133 0 : ctx->pending_key_next = 0;
1134 0 : ctx->send_pkt_cnt_ref = 0;
1135 0 : ctx->send_pkt_ref_ts = -1;
1136 0 : }
1137 :
1138 : static ulong
1139 : populate_allowed_seccomp( fd_topo_t const * topo FD_PARAM_UNUSED,
1140 : fd_topo_tile_t const * tile FD_PARAM_UNUSED,
1141 : ulong out_cnt,
1142 0 : struct sock_filter * out ) {
1143 0 : populate_sock_filter_policy_fd_repair_tile(
1144 0 : out_cnt, out, (uint)fd_log_private_logfile_fd(), (uint)-1 );
1145 0 : return sock_filter_policy_fd_repair_tile_instr_cnt;
1146 0 : }
1147 :
1148 : static ulong
1149 : populate_allowed_fds( fd_topo_t const * topo FD_PARAM_UNUSED,
1150 : fd_topo_tile_t const * tile FD_PARAM_UNUSED,
1151 : ulong out_fds_cnt,
1152 0 : int * out_fds ) {
1153 0 : if( FD_UNLIKELY( out_fds_cnt<2UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
1154 :
1155 0 : ulong out_cnt = 0UL;
1156 0 : out_fds[ out_cnt++ ] = 2; /* stderr */
1157 0 : if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
1158 0 : out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
1159 0 : return out_cnt;
1160 0 : }
1161 :
1162 : static inline void
1163 0 : metrics_write( ctx_t * ctx ) {
1164 0 : long now = fd_log_wallclock();
1165 0 : if( FD_UNLIKELY( ctx->send_pkt_ref_ts == -1 ) ) {
1166 0 : ctx->send_pkt_cnt_ref = ctx->metrics->send_pkt_cnt;
1167 0 : ctx->send_pkt_ref_ts = now;
1168 0 : } else if( FD_UNLIKELY( now - ctx->send_pkt_ref_ts > 1e6L ) ) {
1169 0 : ctx->metrics->send_pkt_rate = ((ctx->metrics->send_pkt_cnt - ctx->send_pkt_cnt_ref) * 1000000000UL) / (ulong)(now - ctx->send_pkt_ref_ts);
1170 0 : ctx->send_pkt_cnt_ref = ctx->metrics->send_pkt_cnt;
1171 0 : ctx->send_pkt_ref_ts = now;
1172 0 : }
1173 0 : FD_MGAUGE_SET( REPAIR, SEND_PKT_RATE, ctx->metrics->send_pkt_rate );
1174 0 : FD_MCNT_SET( REPAIR, CURRENT_SLOT, ctx->metrics->current_slot );
1175 0 : FD_MCNT_SET( REPAIR, REPAIRED_SLOTS, ctx->metrics->repaired_slots );
1176 0 : FD_MCNT_SET( REPAIR, REQUEST_PEERS, fd_peer_pool_used( ctx->policy->peers.pool ) );
1177 0 : FD_MCNT_SET( REPAIR, SIGN_TILE_UNAVAIL, ctx->metrics->sign_tile_unavail );
1178 0 : FD_MCNT_SET( REPAIR, REREQUEST_QUEUE, ctx->metrics->rerequest );
1179 :
1180 0 : FD_MCNT_SET ( REPAIR, TOTAL_PKT_COUNT, ctx->metrics->send_pkt_cnt );
1181 0 : FD_MCNT_ENUM_COPY( REPAIR, SENT_PKT_TYPES, ctx->metrics->sent_pkt_types );
1182 :
1183 0 : FD_MHIST_COPY( REPAIR, SLOT_COMPLETE_TIME, ctx->metrics->slot_compl_time );
1184 0 : FD_MHIST_COPY( REPAIR, RESPONSE_LATENCY, ctx->metrics->response_latency );
1185 0 : }
1186 :
1187 : #undef DEBUG_LOGGING
1188 :
1189 : /* TODO: This is not correct, but is temporary and will be fixed
1190 : when fixed FEC 32 goes in, and we can finally get rid of force
1191 : completes BS. */
1192 0 : #define STEM_BURST (64UL)
1193 :
1194 0 : #define STEM_CALLBACK_CONTEXT_TYPE ctx_t
1195 0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(ctx_t)
1196 :
1197 0 : #define STEM_CALLBACK_AFTER_CREDIT after_credit
1198 0 : #define STEM_CALLBACK_BEFORE_FRAG before_frag
1199 0 : #define STEM_CALLBACK_DURING_FRAG during_frag
1200 0 : #define STEM_CALLBACK_AFTER_FRAG after_frag
1201 0 : #define STEM_CALLBACK_DURING_HOUSEKEEPING during_housekeeping
1202 0 : #define STEM_CALLBACK_METRICS_WRITE metrics_write
1203 :
1204 : #include "../../disco/stem/fd_stem.c"
1205 :
1206 : fd_topo_run_tile_t fd_tile_repair = {
1207 : .name = "repair",
1208 : .loose_footprint = loose_footprint,
1209 : .populate_allowed_seccomp = populate_allowed_seccomp,
1210 : .populate_allowed_fds = populate_allowed_fds,
1211 : .scratch_align = scratch_align,
1212 : .scratch_footprint = scratch_footprint,
1213 : .unprivileged_init = unprivileged_init,
1214 : .privileged_init = privileged_init,
1215 : .run = stem_run,
1216 : };
|