46
46
#define _GNU_SOURCE
47
47
48
48
#include "../../disco/topo/fd_topo.h"
49
+ #include "../../disco/shred/fd_shred_tile.h"
49
50
#include "generated/fd_repair_tile_seccomp.h"
50
51
51
52
#include "../../flamenco/repair/fd_repair.h"
@@ -326,14 +327,12 @@ send_packet( fd_repair_tile_ctx_t * ctx,
326
327
ctx -> net_out_chunk = fd_dcache_compact_next ( chunk , packet_sz , ctx -> net_out_chunk0 , ctx -> net_out_wmark );
327
328
}
328
329
329
- ulong
330
- fd_repair_handle_ping ( fd_repair_tile_ctx_t * repair_tile_ctx ,
331
- fd_repair_t * glob ,
332
- fd_gossip_ping_t const * ping ,
333
- fd_gossip_peer_addr_t const * peer_addr FD_PARAM_UNUSED ,
334
- uint self_ip4_addr FD_PARAM_UNUSED ,
335
- uchar * msg_buf ,
336
- ulong msg_buf_sz ) {
330
+ static ulong
331
+ fd_repair_handle_ping ( fd_repair_tile_ctx_t * repair_tile_ctx ,
332
+ fd_repair_t * glob ,
333
+ fd_gossip_ping_t const * ping ,
334
+ uchar * msg_buf ,
335
+ ulong msg_buf_sz ) {
337
336
fd_repair_protocol_t protocol ;
338
337
fd_repair_protocol_new_disc (& protocol , fd_repair_protocol_enum_pong );
339
338
fd_gossip_ping_t * pong = & protocol .inner .pong ;
@@ -359,8 +358,22 @@ fd_repair_handle_ping( fd_repair_tile_ctx_t * repair_tile_ctx,
359
358
return buflen ;
360
359
}
361
360
361
+ static void
362
+ fd_repair_handle_ping1 ( fd_repair_tile_ctx_t * repair_tile_ctx ,
363
+ fd_repair_t * glob ,
364
+ fd_stem_context_t * stem ,
365
+ fd_gossip_ping_t const * ping ,
366
+ uint const src_ip ,
367
+ uint const dst_port ,
368
+ ushort const src_port ) {
369
+ uchar buf [1024 ];
370
+ ulong buflen = fd_repair_handle_ping ( repair_tile_ctx , glob , ping , buf , sizeof (buf ) );
371
+ ulong tsorig = fd_frag_meta_ts_comp ( fd_tickcount () );
372
+ send_packet ( repair_tile_ctx , stem , 1 , src_ip , src_port , dst_port , buf , buflen , tsorig );
373
+ }
374
+
362
375
/* Pass a raw client response packet into the protocol. addr is the address of the sender */
363
- static int
376
+ static void
364
377
fd_repair_recv_clnt_packet ( fd_repair_tile_ctx_t * repair_tile_ctx ,
365
378
fd_stem_context_t * stem ,
366
379
fd_repair_t * glob ,
@@ -370,35 +383,25 @@ fd_repair_recv_clnt_packet( fd_repair_tile_ctx_t * repair_tile_ctx,
370
383
uint dst_ip4_addr ) {
371
384
glob -> metrics .recv_clnt_pkt ++ ;
372
385
373
- FD_SCRATCH_SCOPE_BEGIN {
374
- while ( 1 ) {
375
- ulong decoded_sz ;
376
- fd_repair_response_t * gmsg = fd_bincode_decode1_scratch (
377
- repair_response , msg , msglen , NULL , & decoded_sz );
378
- if ( FD_UNLIKELY ( !gmsg ) ) {
379
- /* Solana falls back to assuming we got a shred in this case
380
- https://github.com/solana-labs/solana/blob/master/core/src/repair/serve_repair.rs#L1198 */
381
- break ;
382
- }
383
- if ( FD_UNLIKELY ( decoded_sz != msglen ) ) {
384
- break ;
385
- }
386
-
387
- switch ( gmsg -> discriminant ) {
388
- case fd_repair_response_enum_ping :
389
- {
390
- uchar buf [FD_REPAIR_MAX_SIGN_BUF_SIZE ];
391
- ulong buflen = fd_repair_handle_ping ( repair_tile_ctx , glob , & gmsg -> inner .ping , src_addr , dst_ip4_addr , buf , sizeof (buf ) );
392
- ulong tsorig = fd_frag_meta_ts_comp ( fd_tickcount () );
393
- send_packet ( repair_tile_ctx , stem , 1 , src_addr -> addr , src_addr -> port , dst_ip4_addr , buf , buflen , tsorig );
394
- break ;
395
- }
396
- }
397
-
398
- return 0 ;
386
+ if ( FD_UNLIKELY ( msglen < sizeof (uint ) ) ) {
387
+ glob -> metrics .recv_pkt_corrupted_msg ++ ;
388
+ return ;
389
+ }
390
+ uint msg_type = FD_LOAD ( uint , msg );
391
+ msg += sizeof (uint );
392
+ msglen -= sizeof (uint );
393
+
394
+ switch ( msg_type ) {
395
+ case 0 : /* ping */
396
+ if ( FD_UNLIKELY ( msglen != 132 ) ) {
397
+ glob -> metrics .recv_pkt_corrupted_msg ++ ;
398
+ return ;
399
399
}
400
- } FD_SCRATCH_SCOPE_END ;
401
- return 0 ;
400
+ fd_repair_handle_ping1 ( repair_tile_ctx , glob , stem , fd_type_pun_const ( msg ), src_addr -> addr , dst_ip4_addr , src_addr -> port );
401
+ break ;
402
+ default :
403
+ break ;
404
+ }
402
405
}
403
406
404
407
/* Signs and prepares a repair protocol message for sending, either
@@ -618,7 +621,10 @@ before_frag( fd_repair_tile_ctx_t * ctx,
618
621
ulong sig ) {
619
622
uint in_kind = ctx -> in_kind [ in_idx ];
620
623
if ( FD_LIKELY ( in_kind == IN_KIND_NET ) ) return fd_disco_netmux_sig_proto ( sig )!= DST_PROTO_REPAIR ;
621
- 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 */
624
+ if ( FD_UNLIKELY ( in_kind == IN_KIND_SHRED ) ) {
625
+ if ( FD_UNLIKELY ( sig == ULONG_MAX ) ) return 0 ; /* repair ping */
626
+ return fd_int_if ( fd_forest_root_slot ( ctx -> forest )== ULONG_MAX , -1 , 0 ); /* not ready to read frag */
627
+ }
622
628
return 0 ;
623
629
}
624
630
@@ -707,33 +713,6 @@ after_frag_snap( fd_repair_tile_ctx_t * ctx,
707
713
// else fd_reasm_publish( ctx->reasm, &ctx->root_block_id );
708
714
}
709
715
710
- static ulong FD_FN_UNUSED
711
- fd_repair_send_ping ( fd_repair_tile_ctx_t * repair_tile_ctx ,
712
- fd_repair_t * glob ,
713
- fd_pinged_elem_t * val ,
714
- uchar * buf ,
715
- ulong buflen ) {
716
- fd_repair_response_t gmsg ;
717
- fd_repair_response_new_disc ( & gmsg , fd_repair_response_enum_ping );
718
- fd_gossip_ping_t * ping = & gmsg .inner .ping ;
719
- ping -> from = * glob -> public_key ;
720
-
721
- uchar pre_image [FD_PING_PRE_IMAGE_SZ ];
722
- memcpy ( pre_image , "SOLANA_PING_PONG" , 16UL );
723
- memcpy ( pre_image + 16UL , val -> token .uc , 32UL );
724
-
725
- fd_sha256_hash ( pre_image , FD_PING_PRE_IMAGE_SZ , & ping -> token );
726
-
727
- repair_signer ( repair_tile_ctx , ping -> signature .uc , pre_image , FD_PING_PRE_IMAGE_SZ , FD_KEYGUARD_SIGN_TYPE_SHA256_ED25519 );
728
-
729
- fd_bincode_encode_ctx_t ctx ;
730
- FD_TEST ( buflen >= FD_REPAIR_MAX_SIGN_BUF_SIZE );
731
- ctx .data = buf ;
732
- ctx .dataend = buf + buflen ;
733
- FD_TEST (0 == fd_repair_response_encode (& gmsg , & ctx ));
734
- return (ulong )((uchar * )ctx .data - buf );
735
- }
736
-
737
716
static void FD_FN_UNUSED
738
717
fd_repair_recv_pong (fd_repair_t * glob , fd_gossip_ping_t const * pong , fd_gossip_peer_addr_t const * from ) {
739
718
fd_pinged_elem_t * val = fd_pinged_table_query (glob -> pinged , from , NULL );
@@ -835,6 +814,13 @@ after_frag( fd_repair_tile_ctx_t * ctx,
835
814
return ;
836
815
}
837
816
817
+ if ( FD_UNLIKELY ( in_kind == IN_KIND_SHRED && sig == ULONG_MAX ) ) {
818
+ fd_repair_ping_fwd_t const * fwd = fd_type_pun_const ( ctx -> buffer );
819
+ fd_gossip_ping_t const * ping = fd_type_pun_const ( fwd -> ping );
820
+ fd_repair_handle_ping1 ( ctx , ctx -> repair , stem , ping , fwd -> src_ip4 , fwd -> dst_ip4 , fwd -> src_port );
821
+ return ;
822
+ }
823
+
838
824
if ( FD_UNLIKELY ( in_kind == IN_KIND_SHRED ) ) {
839
825
fd_shred_t * shred = (fd_shred_t * )fd_type_pun ( ctx -> buffer );
840
826
if ( FD_UNLIKELY ( shred -> slot <= fd_forest_root_slot ( ctx -> forest ) ) ) {
0 commit comments