Skip to content

WIP: changes to merge gossip2 branch #5154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: mmcgee/gossip2
Choose a base branch
from

Conversation

ravyu-jump
Copy link
Contributor

  • setup type defs and fn defintions for parsing
  • parsers for ping and pong
  • progress
  • rx ping/pong, tx ping, ping/pong serializers, helper functions, coalesce ping and pong into one type

@ravyu-jump ravyu-jump changed the title WIP: gossip2 branch WIP: changes to merge gossip2 branch May 16, 2025
@@ -169,6 +171,7 @@ out1( fd_topo_t const * topo,
}

if( FD_UNLIKELY( idx==ULONG_MAX ) ) FD_LOG_ERR(( "tile %s:%lu had no output link named %s", tile->name, tile->kind_id, name ));
if( opt_tile_out_idx ) *opt_tile_out_idx = idx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already returned as result->idx

*ctx->sign_out = out1( topo, tile, "gossip_sign", &sign_out_tile_idx );

fd_topo_link_t * sign_in = &topo->links[ tile->in_link_id [ sign_in_tile_idx ] ];
fd_topo_link_t * sign_out = &topo->links[ tile->out_link_id[ sign_out_tile_idx ] ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fd_topo_link_t * sign_out = &topo->links[ tile->out_link_id[ sign_out_tile_idx ] ];
fd_topo_link_t * sign_out = &topo->links[ tile->out_link_id[ ctx->sign_out->idx ] ];

fd_topo_link_t * sign_in = &topo->links[ tile->in_link_id [ sign_in_tile_idx ] ];
fd_topo_link_t * sign_out = &topo->links[ tile->out_link_id[ sign_out_tile_idx ] ];
if( fd_keyguard_client_join( fd_keyguard_client_new( ctx->keyguard_client,
sign_out->mcache,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: alignment

@@ -2,6 +2,7 @@
#define HEADER_fd_src_flamenco_gossip_fd_crds_h

#include "../../util/fd_util.h"
#include "../../util/net/fd_net_headers.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed by the header, only add include to the .h file if the header uses it, this should be in the .c

}
verify_signatures( fd_gossip_message_t const * message,
uchar const * payload ) {
if( FD_UNLIKELY( !( !!message->has_signable_data || !!message->crds_cnt ) ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this line, it doesn't do anything.

if( FD_UNLIKELY( !( !!message->has_signable_data || !!message->crds_cnt ) ) )
return FD_GOSSIP_RX_VERIFY_NO_SIGNABLE_DATA;

fd_sha512_t sha[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an argument, from the fd_gossip_t

data */
if( FD_UNLIKELY( message->has_signable_data ) ) {
/* TODO: Special case for prune */
err = fd_ed25519_verify( payload + message->signable_data_offset,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit

Suggested change
err = fd_ed25519_verify( payload + message->signable_data_offset,
err = fd_ed25519_verify( payload+message->signable_data_offset,

} else {
failed_inserts_append( gossip, pull_response->values[ i ] );
}
if( FD_UNLIKELY( err != FD_ED25519_SUCCESS ) ) return err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kbowers style nit, :) please apply everywhere

Suggested change
if( FD_UNLIKELY( err != FD_ED25519_SUCCESS ) ) return err;
if( FD_UNLIKELY( err!=FD_ED25519_SUCCESS ) ) return err;


static int
rx_prune( fd_gossip_t * gossip,
fd_gossip_prune_t const * prune,
long now ) {
if( FD_UNLIKELY( now-500L*1000L*1000L>prune->data->wallclock ) ) return FD_GOSSIP_RX_ERR_PRUNE_TIMEOUT;
else if( FD_UNLIKELY( !memcmp( gossip->identity_pubkey, prune->data->destination, 32UL ) ) ) return FD_GOSSIP_RX_ERR_PRUNE_DESTINATION;
if( FD_UNLIKELY( now-500L*1000L*1000L>(long)prune->wallclock ) ) return FD_GOSSIP_RX_PRUNE_ERR_TIMEOUT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prune wallclock should already be a long, and unitize to nanos, I'd rename wallclock_nanos


static int
rx_prune( fd_gossip_t * gossip,
fd_gossip_prune_t const * prune,
long now ) {
if( FD_UNLIKELY( now-500L*1000L*1000L>prune->data->wallclock ) ) return FD_GOSSIP_RX_ERR_PRUNE_TIMEOUT;
else if( FD_UNLIKELY( !memcmp( gossip->identity_pubkey, prune->data->destination, 32UL ) ) ) return FD_GOSSIP_RX_ERR_PRUNE_DESTINATION;
if( FD_UNLIKELY( now-500L*1000L*1000L>(long)prune->wallclock ) ) return FD_GOSSIP_RX_PRUNE_ERR_TIMEOUT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if( FD_UNLIKELY( now-500L*1000L*1000L>(long)prune->wallclock ) ) return FD_GOSSIP_RX_PRUNE_ERR_TIMEOUT;
FD_GOSSIP_RX_PRUNE_ERR_STALE;

Is probably a little more clear than TIMEOUT

@@ -201,6 +201,16 @@ fd_ping_tracker_join( void * shpt ) {
return ping_tracker;
}

static void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void
static inline void

@@ -201,6 +201,16 @@ fd_ping_tracker_join( void * shpt ) {
return ping_tracker;
}

static void
hash_ping_token( uchar const * ping_token,
uchar * expected_pong_token,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uchar * expected_pong_token,
uchar expected_pong_token[ static 32UL ],

uchar from[ 32UL ];
uchar hash[ 32UL ];
ulong prunes_len;
uchar prunes[ 33UL ][ 32UL ]; /* 33 pubkeys fit in MTU (rounded down) */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add detail on the calculation to get 33 here?

typedef struct fd_gossip_message fd_gossip_message_t;

void
fd_gossip_msg_init( fd_gossip_message_t * msg );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, zero initializing these is a performance bug

if( FD_UNLIKELY( error ) ) return error;
uchar * gossip_payload;
ulong gossip_payload_sz;
fd_ip4_port_t peer_address;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fd_ip4_port_t peer_address;
fd_ip4_port_t peer_address[ 1 ];

&peer_pubkey,
&peer_address,
&ping_token ) ) {
fd_gossip_message_t * message = new_outgoing( gossip );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to construct this message, this is just additional copies, you can serialize directly from the components.

fd_ip4_hdr_t const * ip4 = (fd_ip4_hdr_t const *)( (ulong)eth + sizeof(fd_eth_hdr_t) );
fd_udp_hdr_t const * udp = (fd_udp_hdr_t const *)( (ulong)ip4 + FD_IP4_GET_LEN( *ip4 ) );

if( FD_UNLIKELY( (ulong)udp+sizeof(fd_udp_hdr_t) > (ulong)eth+data_sz ) ) return FD_GOSSIP_RX_ERR_NETWORK_HDRS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd FD_LOG_ERR on these, gossip expects well formed network packets from the net tile.

#define FD_GOSSIP_RX_OK (0)

#define FD_GOSSIP_RX_PARSE_ERR (1)
#define FD_GOSSIP_RX_ERR_NETWORK_HDRS (2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, see other comment

/* Extract enum discriminant/tag (4b encoded) */
uint tag = 0;
CHECK_LEFT( 4UL ); tag = payload[ i ]; i+=4;
CHECK( tag<FD_GOSSIP_MESSAGE_END );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CHECK( tag<FD_GOSSIP_MESSAGE_END );
CHECK( tag<=FD_GOSSIP_MESSAGE_LAST );

#define FD_GOSSIP_CLIENT_FD (2)
#define FD_GOSSIP_CLIENT_AGAVE (3)

struct fd_gossip_contact_info {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would namespace these,

Suggested change
struct fd_gossip_contact_info {
struct fd_gossip_message_contact_info {

Assumes both token and hash are the starting address of a 32byte region of
memory */
void
fd_ping_tracker_hash_ping_token( uchar const * token,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fd_ping_tracker_hash_ping_token( uchar const * token,
fd_ping_tracker_respond( uchar const * token,

fd_ping_tracker_hash_ping_token( ping->token, message->piong->hash );
gossip->sign_fn( gossip->sign_ctx, message->piong->hash, 32UL, message->piong->signature );

fd_ping_tracker_track( gossip->ping_tracker,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to call track here, we are just responding to someone else. Also don't do the memcpys, just serialize directly into buffer.

#include "fd_crds_value.h"


#define FD_GOSSIP_MSG_MTU (1232UL) /* Maximum size of a gossip message */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need, use FD_NET_MTU

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants