LCOV - code coverage report
Current view: top level - discof/gossip - fd_gossip_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 448 0.0 %
Date: 2026-06-27 05:37:02 Functions: 0 23 0.0 %

          Line data    Source code
       1             : #include "fd_gossip_tile.h"
       2             : #include "../../disco/metrics/fd_metrics.h"
       3             : #include "generated/fd_gossip_tile_seccomp.h"
       4             : 
       5             : #include "../../choreo/eqvoc/fd_eqvoc.h"
       6             : #include "../../flamenco/gossip/fd_gossip_out.h"
       7             : #include "../../flamenco/gossip/fd_active_set.h"
       8             : #include "../../flamenco/features/fd_features.h"
       9             : #include "../../disco/keyguard/fd_keyload.h"
      10             : #include "../../disco/shred/fd_stake_ci.h"
      11             : #include "../../disco/fd_txn_m.h"
      12             : #include "../tower/fd_tower_tile.h"
      13             : #include "../restore/utils/fd_ssmsg.h"
      14             : 
      15           0 : #define IN_KIND_GOSSVF        (0)
      16           0 : #define IN_KIND_SHRED_VERSION (1)
      17           0 : #define IN_KIND_SIGN          (2)
      18           0 : #define IN_KIND_TXSEND        (3)
      19           0 : #define IN_KIND_EPOCH         (4)
      20           0 : #define IN_KIND_TOWER         (5)
      21           0 : #define IN_KIND_SNAPIN_MANIF  (6)
      22             : 
      23             : FD_FN_CONST static inline ulong
      24           0 : scratch_align( void ) {
      25           0 :   return 128UL;
      26           0 : }
      27             : 
      28             : FD_FN_PURE static inline ulong
      29           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
      30           0 :   ulong l = FD_LAYOUT_INIT;
      31           0 :   l = FD_LAYOUT_APPEND( l, alignof(fd_gossip_tile_ctx_t), sizeof(fd_gossip_tile_ctx_t)                                                  );
      32           0 :   l = FD_LAYOUT_APPEND( l, fd_gossip_align(),             fd_gossip_footprint( tile->gossip.max_entries, tile->gossip.entrypoints_cnt ) );
      33           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
      34           0 : }
      35             : 
      36             : static void
      37             : gossip_send_fn( void *                ctx,
      38             :                 fd_stem_context_t *   stem,
      39             :                 uchar const *         payload,
      40             :                 ulong                 payload_sz,
      41             :                 fd_ip4_port_t const * peer_address,
      42           0 :                 ulong                 tsorig ) {
      43           0 :   fd_gossip_tile_ctx_t * gossip_ctx = (fd_gossip_tile_ctx_t *)ctx;
      44             : 
      45           0 :   uchar * packet          = (uchar *)fd_chunk_to_laddr( gossip_ctx->net_out->mem, gossip_ctx->net_out->chunk );
      46           0 :   fd_ip4_udp_hdrs_t * hdr = (fd_ip4_udp_hdrs_t *)packet;
      47           0 :   *hdr = *gossip_ctx->net_out_hdr;
      48             : 
      49           0 :   fd_ip4_hdr_t * ip4 = hdr->ip4;
      50           0 :   fd_udp_hdr_t * udp = hdr->udp;
      51             : 
      52           0 :   ip4->net_tot_len = fd_ushort_bswap( (ushort)(payload_sz + sizeof(fd_udp_hdr_t) + sizeof(fd_ip4_hdr_t)) );
      53           0 :   udp->net_len     = fd_ushort_bswap( (ushort)(payload_sz + sizeof(fd_udp_hdr_t)) );
      54           0 :   ip4->daddr       = peer_address->addr;
      55           0 :   udp->net_dport   = peer_address->port;
      56           0 :   ip4->net_id      = fd_ushort_bswap( gossip_ctx->net_id++ );
      57           0 :   ip4->check       = fd_ip4_hdr_check_fast( ip4 );
      58           0 :   udp->check       = 0;
      59             : 
      60           0 :   fd_memcpy( packet+sizeof(fd_ip4_udp_hdrs_t), payload, payload_sz );
      61             : 
      62           0 :   ulong tspub     = fd_frag_meta_ts_comp( fd_tickcount() );
      63           0 :   ulong sig       = fd_disco_netmux_sig( peer_address->addr, peer_address->port, peer_address->addr, DST_PROTO_OUTGOING, sizeof(fd_ip4_udp_hdrs_t) );
      64           0 :   ulong packet_sz = payload_sz + sizeof(fd_ip4_udp_hdrs_t);
      65             : 
      66           0 :   fd_stem_publish( stem, gossip_ctx->net_out->idx, sig, gossip_ctx->net_out->chunk, packet_sz, 0UL, tsorig, tspub );
      67           0 :   gossip_ctx->net_out->chunk = fd_dcache_compact_next( gossip_ctx->net_out->chunk, packet_sz, gossip_ctx->net_out->chunk0, gossip_ctx->net_out->wmark );
      68           0 : }
      69             : 
      70             : static void
      71             : gossip_sign_fn( void *        ctx,
      72             :                 uchar const * data,
      73             :                 ulong         data_sz,
      74             :                 int           sign_type,
      75           0 :                 uchar *       out_signature ) {
      76           0 :   fd_gossip_tile_ctx_t * gossip_ctx = (fd_gossip_tile_ctx_t *)ctx;
      77           0 :   fd_keyguard_client_sign( gossip_ctx->keyguard_client, out_signature, data, data_sz, sign_type );
      78           0 : }
      79             : 
      80             : static void
      81             : gossip_ping_tracker_change_fn( void *        _ctx,
      82             :                                uchar const * peer_pubkey,
      83             :                                fd_ip4_port_t peer_address,
      84             :                                long          now,
      85           0 :                                int           change_type ) {
      86           0 :   (void)now;
      87             : 
      88           0 :   fd_gossip_tile_ctx_t * ctx = (fd_gossip_tile_ctx_t *)_ctx;
      89             : 
      90           0 :   fd_gossip_ping_update_t * ping_update = (fd_gossip_ping_update_t *)fd_chunk_to_laddr( ctx->gossvf_out->mem, ctx->gossvf_out->chunk );
      91           0 :   fd_memcpy( ping_update->pubkey.uc, peer_pubkey, 32UL );
      92           0 :   ping_update->gossip_addr.l = peer_address.l;
      93           0 :   ping_update->remove = change_type!=FD_PING_TRACKER_CHANGE_TYPE_ACTIVE;
      94             : 
      95           0 :   fd_stem_publish( ctx->stem, ctx->gossvf_out->idx, 0UL, ctx->gossvf_out->chunk, sizeof(fd_gossip_ping_update_t), 0UL, 0UL, 0UL );
      96           0 :   ctx->gossvf_out->chunk = fd_dcache_compact_next( ctx->gossvf_out->chunk, sizeof(fd_gossip_ping_update_t), ctx->gossvf_out->chunk0, ctx->gossvf_out->wmark );
      97           0 : }
      98             : 
      99             : static void
     100             : gossip_activity_update_fn( void *                           _ctx,
     101             :                            fd_pubkey_t const *              identity,
     102             :                            fd_gossip_contact_info_t const * ci,
     103           0 :                            int                              change_type ) {
     104           0 :   fd_gossip_tile_ctx_t * ctx = (fd_gossip_tile_ctx_t *)_ctx;
     105             : 
     106             :   /* We won't start tracking updates until after the manifest is loaded.
     107             :      This is okay since this callback is triggered by all contact info
     108             :      updates, including refreshes, so any updates we missed at boot will
     109             :      show up shortly after. */
     110           0 :   if( FD_LIKELY( !ctx->my_contact_info->shred_version || ctx->wfs_state!=FD_GOSSIP_WFS_STATE_WAIT ) ) return;
     111             : 
     112             :   /* gossvf should filter out messages with mismatching shred version */
     113           0 :   FD_TEST( ci->shred_version==ctx->my_contact_info->shred_version );
     114             : 
     115             :   /* To match Agave's tvu_peers() filter, require a valid TVU UDP
     116             :      socket for the ACTIVE path. */
     117           0 :   if( FD_LIKELY( change_type==FD_GOSSIP_ACTIVITY_CHANGE_TYPE_ACTIVE ) ) {
     118           0 :     fd_ip4_port_t tvu_addr;
     119           0 :     tvu_addr.addr = ci->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TVU ].is_ipv6 ? 0U : ci->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TVU ].ip4;
     120           0 :     tvu_addr.port = ci->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TVU ].port;
     121           0 :     if( FD_UNLIKELY( !tvu_addr.l ) ) return;
     122           0 :   }
     123             : 
     124             :   /* If identity is not found in ctx->wfs_stakes the peer is likely
     125             :      unstaked and can be ignored. */
     126           0 :   ulong stake_idx = fd_stake_weight_key_sort_split( ctx->wfs_stakes, ctx->wfs_stakes_cnt, (fd_stake_weight_t){ .key = *identity } );
     127           0 :   if( FD_UNLIKELY( stake_idx>=ctx->wfs_stakes_cnt || memcmp( identity->uc, ctx->wfs_stakes[ stake_idx ].key.uc, sizeof(fd_pubkey_t) ) ) ) return;
     128             : 
     129           0 :   if( FD_LIKELY( change_type==FD_GOSSIP_ACTIVITY_CHANGE_TYPE_ACTIVE ) ) {
     130           0 :     if( FD_UNLIKELY( !ctx->wfs_active[ stake_idx ] ) ) {
     131           0 :       ctx->wfs_stake.online += ctx->wfs_stakes[ stake_idx ].stake;
     132           0 :       ctx->wfs_peers.online++;
     133           0 :     }
     134           0 :     ctx->wfs_active[ stake_idx ] = 1;
     135           0 :   }
     136           0 :   if( FD_LIKELY( change_type==FD_GOSSIP_ACTIVITY_CHANGE_TYPE_INACTIVE ) ) {
     137           0 :     if( FD_UNLIKELY( ctx->wfs_active[ stake_idx ] ) ) {
     138           0 :       ctx->wfs_stake.online -= ctx->wfs_stakes[ stake_idx ].stake;
     139           0 :       ctx->wfs_peers.online--;
     140           0 :     }
     141           0 :     ctx->wfs_active[ stake_idx ] = 0;
     142           0 :   }
     143             : 
     144           0 :   if( FD_UNLIKELY( ctx->wfs_stake.total>0UL && (ulong)( ((double)ctx->wfs_stake.online / (double)ctx->wfs_stake.total) * 100.0 ) >= 80UL ) ) {
     145           0 :     ctx->wfs_state = FD_GOSSIP_WFS_STATE_PUBLISH;
     146           0 :   }
     147           0 : }
     148             : 
     149             : static inline void
     150           0 : during_housekeeping( fd_gossip_tile_ctx_t * ctx ) {
     151           0 :   ctx->last_wallclock = fd_log_wallclock();
     152           0 :   ctx->last_tickcount = fd_tickcount();
     153           0 :   if( FD_UNLIKELY( fd_keyswitch_state_query( ctx->keyswitch )==FD_KEYSWITCH_STATE_UNHALT_PENDING ) ) {
     154           0 :     FD_LOG_DEBUG(( "keyswitch: unhalting" ));
     155           0 :     FD_CHECK_CRIT( ctx->is_halting_signing, "state machine corruption" );
     156             :     /* Defer the actual set_identity call to after_credit, because it
     157             :        may incur a stem frag publish. */
     158           0 :     ctx->is_pending_set_identity = 1;
     159           0 :   }
     160             : 
     161           0 :   if( FD_UNLIKELY( fd_keyswitch_state_query( ctx->keyswitch )==FD_KEYSWITCH_STATE_SWITCH_PENDING ) ) {
     162           0 :     ctx->is_halting_signing = 1;
     163           0 :     fd_keyswitch_state( ctx->keyswitch, FD_KEYSWITCH_STATE_COMPLETED );
     164           0 :   }
     165           0 : }
     166             : 
     167             : static inline void
     168           0 : metrics_write( fd_gossip_tile_ctx_t * ctx ) {
     169           0 :   fd_ping_tracker_metrics_t const * ping_tracker_metrics = fd_gossip_ping_tracker_metrics( ctx->gossip );
     170             : 
     171           0 :   FD_MGAUGE_SET( GOSSIP, PING_TRACKED_UNPINGED,         ping_tracker_metrics->unpinged_cnt );
     172           0 :   FD_MGAUGE_SET( GOSSIP, PING_TRACKED_INVALID,          ping_tracker_metrics->invalid_cnt );
     173           0 :   FD_MGAUGE_SET( GOSSIP, PING_TRACKED_VALID,            ping_tracker_metrics->valid_cnt );
     174           0 :   FD_MGAUGE_SET( GOSSIP, PING_TRACKED_VALID_REFRESHING, ping_tracker_metrics->refreshing_cnt );
     175             : 
     176           0 :   FD_MCNT_SET( GOSSIP, PING_TRACKER_PONG_RESULT_STAKED,     ping_tracker_metrics->pong_result[ 0UL ] );
     177           0 :   FD_MCNT_SET( GOSSIP, PING_TRACKER_PONG_RESULT_ENTRYPOINT, ping_tracker_metrics->pong_result[ 1UL ] );
     178           0 :   FD_MCNT_SET( GOSSIP, PING_TRACKER_PONG_RESULT_UNTRACKED,  ping_tracker_metrics->pong_result[ 2UL ] );
     179           0 :   FD_MCNT_SET( GOSSIP, PING_TRACKER_PONG_RESULT_ADDRESS,    ping_tracker_metrics->pong_result[ 3UL ] );
     180           0 :   FD_MCNT_SET( GOSSIP, PING_TRACKER_PONG_RESULT_TOKEN,      ping_tracker_metrics->pong_result[ 4UL ] );
     181           0 :   FD_MCNT_SET( GOSSIP, PING_TRACKER_PONG_RESULT_SUCCESS,    ping_tracker_metrics->pong_result[ 5UL ] );
     182             : 
     183           0 :   FD_MCNT_SET( GOSSIP, PING_TRACKER_EVICTED,         ping_tracker_metrics->peers_evicted );
     184           0 :   FD_MCNT_SET( GOSSIP, PING_TRACKER_ADDED,           ping_tracker_metrics->tracked_cnt );
     185           0 :   FD_MCNT_SET( GOSSIP, PING_TRACKER_STAKE_CHANGED,   ping_tracker_metrics->stake_changed_cnt );
     186           0 :   FD_MCNT_SET( GOSSIP, PING_TRACKER_ADDRESS_CHANGED, ping_tracker_metrics->address_changed_cnt );
     187             : 
     188           0 :   fd_gossip_purged_metrics_t const * purged_metrics = fd_gossip_purged_metrics2( ctx->gossip );
     189             : 
     190           0 :   FD_MGAUGE_SET( GOSSIP, CRDS_PURGED_OCCUPIED, purged_metrics->purged_cnt );
     191           0 :   FD_MCNT_SET(   GOSSIP, CRDS_PURGED_EVICTED,  purged_metrics->purged_evicted_cnt );
     192           0 :   FD_MCNT_SET(   GOSSIP, CRDS_PURGED_EXPIRED,  purged_metrics->purged_expired_cnt );
     193             : 
     194           0 :   fd_crds_metrics_t const * crds_metrics = fd_gossip_crds_metrics( ctx->gossip );
     195             : 
     196           0 :   FD_MGAUGE_ENUM_COPY( GOSSIP, CRDS_OCCUPIED,    crds_metrics->count );
     197           0 :   FD_MCNT_SET(         GOSSIP, CRDS_EXPIRED,  crds_metrics->expired_cnt );
     198           0 :   FD_MCNT_SET(         GOSSIP, CRDS_EVICTED,  crds_metrics->evicted_cnt );
     199             : 
     200           0 :   FD_MGAUGE_SET( GOSSIP, CRDS_PEER_STAKED,      crds_metrics->peer_staked_cnt );
     201           0 :   FD_MGAUGE_SET( GOSSIP, CRDS_PEER_UNSTAKED,    crds_metrics->peer_unstaked_cnt );
     202           0 :   FD_MGAUGE_SET( GOSSIP, CRDS_PEER_STAKE, crds_metrics->peer_visible_stake );
     203           0 :   FD_MCNT_SET(   GOSSIP, CRDS_PEER_EVICTED,     crds_metrics->peer_evicted_cnt );
     204             : 
     205           0 :   fd_gossip_metrics_t const * metrics = fd_gossip_metrics( ctx->gossip );
     206           0 :   fd_active_set_metrics_t const * active_set_metrics = fd_gossip_active_set_metrics2( ctx->gossip );
     207             : 
     208           0 :   ulong total_message_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ] = {0};
     209           0 :   ulong total_message_tx_bytes[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ] = {0};
     210           0 :   for( ulong i=0UL; i<FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT; i++ ) {
     211           0 :     total_message_tx[ i ] = metrics->message_tx[ i ] + active_set_metrics->message_tx[ i ];
     212           0 :     total_message_tx_bytes[ i ] = metrics->message_tx_bytes[ i ] + active_set_metrics->message_tx_bytes[ i ];
     213           0 :   }
     214           0 :   FD_MCNT_ENUM_COPY( GOSSIP, MESSAGE_TX,              total_message_tx );
     215           0 :   FD_MCNT_ENUM_COPY( GOSSIP, MESSAGE_TX_BYTES,        total_message_tx_bytes );
     216           0 :   FD_MCNT_ENUM_COPY( GOSSIP, CRDS_PUSH_TX,            active_set_metrics->crds_tx_push );
     217           0 :   FD_MCNT_ENUM_COPY( GOSSIP, CRDS_PUSH_TX_BYTES,      active_set_metrics->crds_tx_push_bytes );
     218           0 :   FD_MCNT_ENUM_COPY( GOSSIP, CRDS_PULL_RESPONSE_TX,       metrics->crds_tx_pull_response );
     219           0 :   FD_MCNT_ENUM_COPY( GOSSIP, CRDS_PULL_RESPONSE_TX_BYTES, metrics->crds_tx_pull_response_bytes );
     220             : 
     221           0 :   FD_MCNT_ENUM_COPY( GOSSIP, CRDS_RX,                 metrics->crds_rx_count );
     222             : 
     223           0 :   FD_MGAUGE_SET( GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKED_PEER_ONLINE, ctx->wfs_peers.online );
     224           0 :   FD_MGAUGE_SET( GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKE_ONLINE,       ctx->wfs_stake.online );
     225           0 :   FD_MGAUGE_SET( GOSSIP, WAIT_FOR_SUPERMAJORITY_STATE, (ulong)ctx->wfs_state );
     226           0 : }
     227             : 
     228             : /* Minimum quiet period (no new peers discovered) before we declare
     229             :    the gossip peer table saturated.  Pull requests fire every ~1.6ms,
     230             :    so 500ms of silence means ~300 pulls returned no new contact
     231             :    infos — a strong convergence signal. */
     232             : #define FD_GOSSIP_PEER_SAT_QUIET_NS (500L*1000L*1000L)
     233             : 
     234             : void
     235             : after_credit( fd_gossip_tile_ctx_t * ctx,
     236             :               fd_stem_context_t *    stem,
     237             :               int *                  opt_poll_in,
     238           0 :               int *                  charge_busy ) {
     239           0 :   ctx->stem = stem;
     240             : 
     241           0 :   if( FD_UNLIKELY( ctx->is_pending_set_identity ) ) {
     242             :     /* the identity key is swapped after the sign tile has been swapped
     243             :        because the below function directly sends a sign request. */
     244           0 :     FD_BASE58_ENCODE_32_BYTES( ctx->keyswitch->bytes, _new_id_b58 );
     245           0 :     fd_gossip_set_identity( ctx->gossip, ctx->keyswitch->bytes, ctx->last_wallclock );
     246           0 :     ctx->is_halting_signing        = 0;
     247           0 :     ctx->is_pending_set_identity   = 0;
     248           0 :     fd_keyswitch_state( ctx->keyswitch, FD_KEYSWITCH_STATE_COMPLETED );
     249           0 :     *charge_busy = 1;
     250           0 :     return;
     251           0 :   }
     252             : 
     253           0 :   if( FD_UNLIKELY( !ctx->my_contact_info->shred_version ) ) return;
     254             : 
     255           0 :   if( FD_UNLIKELY( ctx->wfs_state==FD_GOSSIP_WFS_STATE_PUBLISH ) ) {
     256           0 :     fd_stem_publish( ctx->stem, ctx->gossip_out->idx, FD_GOSSIP_UPDATE_TAG_WFS_DONE, ctx->gossip_out->chunk, 0UL, 0UL, 0UL, 0UL );
     257           0 :     ctx->wfs_state = FD_GOSSIP_WFS_STATE_DONE;
     258           0 :     *opt_poll_in = 0;
     259           0 :     *charge_busy = 1;
     260           0 :     return;
     261           0 :   }
     262             : 
     263             :   /* Prevent attempts to sign with our old identity while switching to
     264             :      the new one. */
     265           0 :   if( FD_UNLIKELY( ctx->is_halting_signing ) ) return;
     266             : 
     267           0 :   long now = ctx->last_wallclock + (long)((double)(fd_tickcount()-ctx->last_tickcount)/ctx->ticks_per_ns);
     268           0 :   fd_gossip_advance( ctx->gossip, now, stem, charge_busy );
     269             : 
     270             :   /* Peer table saturation detection.  After fd_gossip_advance updates
     271             :      the CRDS, check if the peer count has grown.  If it hasn't grown
     272             :      for FD_GOSSIP_PEER_SAT_QUIET_NS and there is at least one other
     273             :      peer, publish a one-shot PEER_SATURATED notification. */
     274           0 :   if( FD_LIKELY( !ctx->peer_sat_published ) ) {
     275           0 :     fd_crds_metrics_t const * crds_metrics = fd_gossip_crds_metrics( ctx->gossip );
     276           0 :     ulong peer_cnt = crds_metrics->peer_staked_cnt + crds_metrics->peer_unstaked_cnt;
     277           0 :     if( FD_UNLIKELY( peer_cnt>ctx->peer_sat_hwm ) ) {
     278           0 :       ctx->peer_sat_hwm       = peer_cnt;
     279           0 :       ctx->peer_sat_hwm_nanos = now;
     280           0 :     } else if( FD_UNLIKELY( peer_cnt>1UL && ctx->peer_sat_hwm_nanos!=0L &&
     281           0 :                             (now-ctx->peer_sat_hwm_nanos)>FD_GOSSIP_PEER_SAT_QUIET_NS ) ) {
     282           0 :       FD_LOG_NOTICE(( "gossip peer table saturated (%lu peers, quiet for %ld ms)",
     283           0 :                       peer_cnt, (now-ctx->peer_sat_hwm_nanos)/(1000L*1000L) ));
     284           0 :       fd_stem_publish( ctx->stem, ctx->gossip_out->idx, FD_GOSSIP_UPDATE_TAG_PEER_SATURATED, ctx->gossip_out->chunk, 0UL, 0UL, 0UL, 0UL );
     285           0 :       ctx->peer_sat_published = 1;
     286           0 :       *opt_poll_in = 0;
     287           0 :       *charge_busy = 1;
     288           0 :     }
     289           0 :   }
     290           0 : }
     291             : 
     292             : static void
     293             : handle_shred_version( fd_gossip_tile_ctx_t * ctx,
     294           0 :                        ulong                 sig ) {
     295           0 :   long now = ctx->last_wallclock + (long)((double)(fd_tickcount()-ctx->last_tickcount)/ctx->ticks_per_ns);
     296           0 :   ctx->my_contact_info->shred_version = (ushort)sig;
     297           0 :   fd_gossip_set_shred_version( ctx->gossip, (ushort)sig, now );
     298           0 : }
     299             : 
     300             : static void
     301             : handle_local_vote( fd_gossip_tile_ctx_t * ctx,
     302             :                    fd_txn_m_t const *     txn_m,
     303           0 :                    fd_stem_context_t *    stem ) {
     304           0 :   long now = ctx->last_wallclock + (long)((double)(fd_tickcount()-ctx->last_tickcount)/ctx->ticks_per_ns);
     305           0 :   fd_gossip_push_vote( ctx->gossip, fd_txn_m_payload_const( txn_m ), txn_m->payload_sz, stem, now );
     306           0 : }
     307             : 
     308             : static void
     309             : handle_epoch( fd_gossip_tile_ctx_t *      ctx,
     310           0 :               fd_epoch_info_msg_t const * msg ) {
     311           0 :   if( FD_UNLIKELY( msg->staked_vote_cnt>MAX_COMPRESSED_STAKE_WEIGHTS ) )
     312           0 :     FD_LOG_ERR(( "epoch stakes exceed MAX_COMPRESSED_STAKE_WEIGHTS=%lu", MAX_COMPRESSED_STAKE_WEIGHTS ));
     313           0 :   if( FD_UNLIKELY( msg->staked_id_cnt>MAX_SHRED_DESTS ) )
     314           0 :     FD_LOG_ERR(( "epoch id weights exceed MAX_SHRED_DESTS=%lu", MAX_SHRED_DESTS ));
     315             : 
     316           0 :   fd_stake_weight_t const * weights = fd_epoch_info_msg_id_weights( msg );
     317           0 :   fd_gossip_stakes_update( ctx->gossip, weights, msg->staked_id_cnt );
     318           0 : }
     319             : 
     320             : static void
     321             : handle_packet( fd_gossip_tile_ctx_t * ctx,
     322             :                ulong                  sig,
     323             :                uchar const *          payload,
     324             :                ulong                  payload_sz,
     325           0 :                fd_stem_context_t *    stem ) {
     326           0 :   long now = ctx->last_wallclock + (long)((double)(fd_tickcount()-ctx->last_tickcount)/ctx->ticks_per_ns);
     327             : 
     328           0 :   fd_ip4_port_t peer = (fd_ip4_port_t){
     329           0 :     .addr = fd_gossvf_sig_addr( sig ),
     330           0 :     .port = fd_gossvf_sig_port( sig )
     331           0 :   };
     332             : 
     333           0 :   switch( fd_gossvf_sig_kind( sig ) ) {
     334           0 :     case 0: {
     335           0 :       fd_gossip_rx( ctx->gossip, peer, payload, payload_sz, now, stem );
     336           0 :       fd_gossip_advance( ctx->gossip, now, stem, NULL );
     337           0 :       break;
     338           0 :     }
     339           0 :     case 1: {
     340           0 :       fd_gossip_pingreq_t * pingreq = (fd_gossip_pingreq_t *)payload;
     341           0 :       fd_gossip_ping_tracker_track( ctx->gossip, pingreq->pubkey.uc, peer, now );
     342           0 :     }
     343           0 :   }
     344           0 : }
     345             : 
     346             : static void
     347             : handle_local_duplicate_shred( fd_gossip_tile_ctx_t *            ctx,
     348             :                               ulong                             sig,
     349             :                               fd_gossip_duplicate_shred_t const chunk[FD_EQVOC_CHUNK_CNT],
     350           0 :                               fd_stem_context_t *               stem ) {
     351           0 :   if( FD_UNLIKELY( sig==FD_TOWER_SIG_SLOT_DUPLICATE ) ) {
     352           0 :     long now = ctx->last_wallclock + (long)((double)(fd_tickcount()-ctx->last_tickcount)/ctx->ticks_per_ns);
     353           0 :     for( ulong i=0UL; i<FD_EQVOC_CHUNK_CNT; i++ ) fd_gossip_push_duplicate_shred( ctx->gossip, &chunk[i], stem, now );
     354           0 :   }
     355           0 : }
     356             : 
     357             : static inline int
     358             : before_frag( fd_gossip_tile_ctx_t * ctx,
     359             :              ulong                  in_idx,
     360             :              ulong                  seq FD_PARAM_UNUSED,
     361           0 :              ulong                  sig FD_PARAM_UNUSED ) {
     362             :   /* Defer frag processing while switching identity or learning shred
     363             :      version */
     364           0 :   if( FD_UNLIKELY( ctx->is_halting_signing || ( !ctx->my_contact_info->shred_version && ctx->in[ in_idx ].kind!=IN_KIND_SHRED_VERSION ) ) ) return -1;
     365             : 
     366           0 :   return 0;
     367           0 : }
     368             : 
     369             : static inline void
     370             : during_frag( fd_gossip_tile_ctx_t * ctx,
     371             :              ulong                  in_idx,
     372             :              ulong                  seq FD_PARAM_UNUSED,
     373             :              ulong                  sig FD_PARAM_UNUSED,
     374             :              ulong                  chunk,
     375             :              ulong                  sz,
     376           0 :              ulong                  ctl FD_PARAM_UNUSED ) {
     377           0 :   switch( ctx->in[ in_idx ].kind ) {
     378           0 :     case IN_KIND_GOSSVF: {
     379           0 :       if( FD_UNLIKELY( sz!=0UL && (chunk<ctx->in[ in_idx ].chunk0 || chunk>ctx->in[ in_idx ].wmark || sz>ctx->in[ in_idx ].mtu ) ) )
     380           0 :         FD_LOG_ERR(( "chunk %lu %lu from in %d corrupt, not in range [%lu,%lu]", chunk, sz, ctx->in[ in_idx ].kind, ctx->in[ in_idx ].chunk0, ctx->in[ in_idx ].wmark ));
     381             : 
     382           0 :       fd_memcpy( ctx->gossvf_staged, fd_chunk_to_laddr_const( ctx->in[ in_idx ].mem, chunk ), sz );
     383           0 :       break;
     384           0 :     }
     385           0 :   }
     386           0 : }
     387             : 
     388             : static inline void
     389             : after_frag( fd_gossip_tile_ctx_t * ctx,
     390             :             ulong                  in_idx,
     391             :             ulong                  seq    FD_PARAM_UNUSED,
     392             :             ulong                  sig,
     393             :             ulong                  sz,
     394             :             ulong                  tsorig FD_PARAM_UNUSED,
     395             :             ulong                  tspub  FD_PARAM_UNUSED,
     396           0 :             fd_stem_context_t *    stem ) {
     397           0 :   switch( ctx->in[ in_idx ].kind ) {
     398           0 :     case IN_KIND_GOSSVF: {
     399             : 
     400           0 :       FD_TEST( sz<=sizeof(ctx->gossvf_staged) );
     401             : 
     402           0 :       handle_packet( ctx, sig, ctx->gossvf_staged, sz, stem );
     403           0 :       break;
     404           0 :     }
     405           0 :   }
     406           0 : }
     407             : 
     408             : static inline int
     409             : returnable_frag( fd_gossip_tile_ctx_t * ctx,
     410             :                  ulong                  in_idx,
     411             :                  ulong                  seq FD_PARAM_UNUSED,
     412             :                  ulong                  sig,
     413             :                  ulong                  chunk,
     414             :                  ulong                  sz,
     415             :                  ulong                  ctl FD_PARAM_UNUSED,
     416             :                  ulong                  tsorig FD_PARAM_UNUSED,
     417             :                  ulong                  tspub FD_PARAM_UNUSED,
     418           0 :                  fd_stem_context_t *    stem ) {
     419             : 
     420             :   /* Return early for unreliable links. */
     421           0 :   if( FD_UNLIKELY( ctx->in[ in_idx ].kind==IN_KIND_GOSSVF ) ) return 0;
     422             : 
     423           0 :   if( FD_UNLIKELY( sz!=0UL && (chunk<ctx->in[ in_idx ].chunk0 || chunk>ctx->in[ in_idx ].wmark || sz>ctx->in[ in_idx ].mtu ) ) )
     424           0 :     FD_LOG_ERR(( "chunk %lu %lu from in %d corrupt, not in range [%lu,%lu]", chunk, sz, ctx->in[ in_idx ].kind, ctx->in[ in_idx ].chunk0, ctx->in[ in_idx ].wmark ));
     425             : 
     426           0 :   switch( ctx->in[ in_idx ].kind ) {
     427           0 :     case IN_KIND_SHRED_VERSION: handle_shred_version( ctx, sig ); break;
     428           0 :     case IN_KIND_TXSEND:        handle_local_vote( ctx, fd_chunk_to_laddr_const( ctx->in[ in_idx ].mem, chunk ), stem ); break;
     429           0 :     case IN_KIND_EPOCH:         handle_epoch( ctx, fd_chunk_to_laddr_const( ctx->in[ in_idx ].mem, chunk ) ); break;
     430           0 :     case IN_KIND_TOWER:         handle_local_duplicate_shred( ctx, sig, fd_chunk_to_laddr_const( ctx->in[ in_idx ].mem, chunk ), stem ); break;
     431           0 :     case IN_KIND_SNAPIN_MANIF: {
     432           0 :       if( FD_LIKELY( ctx->wfs_state==FD_GOSSIP_WFS_STATE_DONE ) ) break;
     433             : 
     434           0 :       if( FD_UNLIKELY( fd_ssmsg_sig_message( sig )==FD_SSMSG_DONE ) ) {
     435           0 :         ctx->wfs_state = FD_GOSSIP_WFS_STATE_WAIT;
     436           0 :         break;
     437           0 :       }
     438             : 
     439             :       /* FIXME: Replace handling for this when manifest supports larger
     440             :          vote and stake account bounds. */
     441           0 :       fd_snapshot_manifest_t const * manifest = fd_chunk_to_laddr( ctx->in[ in_idx ].mem, chunk );
     442             : 
     443           0 :       ulong wfs_stakes_unconverted_cnt = 0UL;
     444           0 :       ctx->wfs_stake.online = 0UL;
     445           0 :       ctx->wfs_stake.total  = 0UL;
     446           0 :       ctx->wfs_peers.online = 0UL;
     447           0 :       ctx->wfs_peers.total  = 0UL;
     448           0 :       memset( ctx->wfs_active, 0, sizeof(ctx->wfs_active) );
     449             : 
     450           0 :       FD_TEST( manifest->vote_accounts_len<=FD_VOTE_ACCOUNTS_MAX );
     451           0 :       for( ulong i=0UL; i<manifest->vote_accounts_len; i++ ) {
     452           0 :           if( FD_UNLIKELY( manifest->vote_accounts[ i ].stake==0UL ) ) continue;
     453           0 :           ctx->wfs_stake.total += manifest->vote_accounts[ i ].stake;
     454             : 
     455           0 :           fd_memcpy( ctx->wfs_stakes_scratch[ wfs_stakes_unconverted_cnt ].id_key.uc, manifest->vote_accounts[ i ].node_account_pubkey, sizeof(fd_pubkey_t) );
     456           0 :           fd_memcpy( ctx->wfs_stakes_scratch[ wfs_stakes_unconverted_cnt ].vote_key.uc, manifest->vote_accounts[ i ].vote_account_pubkey, sizeof(fd_pubkey_t) );
     457           0 :           ctx->wfs_stakes_scratch[ wfs_stakes_unconverted_cnt ].stake = manifest->vote_accounts[ i ].stake;
     458           0 :           wfs_stakes_unconverted_cnt++;
     459           0 :       }
     460           0 :       ctx->wfs_stakes_cnt = compute_id_weights_from_vote_weights( ctx->wfs_stakes, ctx->wfs_stakes_scratch, wfs_stakes_unconverted_cnt );
     461             : 
     462             :       /* sort for quick lookup */
     463           0 :       fd_stake_weight_key_sort_inplace( ctx->wfs_stakes, ctx->wfs_stakes_cnt );
     464             : 
     465           0 :       ctx->wfs_peers.total = ctx->wfs_stakes_cnt;
     466           0 :       FD_MGAUGE_SET( GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKED_PEER_TOTAL, ctx->wfs_peers.total );
     467           0 :       FD_MGAUGE_SET( GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKE_TOTAL,       ctx->wfs_stake.total );
     468             : 
     469           0 :       break;
     470           0 :     }
     471           0 :     default: FD_LOG_ERR(( "unreachable" ));
     472           0 :   }
     473             : 
     474           0 :   return 0;
     475           0 : }
     476             : 
     477             : static void
     478             : privileged_init( fd_topo_t const *      topo,
     479           0 :                  fd_topo_tile_t const * tile ) {
     480           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     481             : 
     482           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     483           0 :   fd_gossip_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gossip_tile_ctx_t), sizeof(fd_gossip_tile_ctx_t) );
     484           0 :   fd_memset( ctx, 0, sizeof(fd_gossip_tile_ctx_t) );
     485             : 
     486           0 :   if( FD_UNLIKELY( !strcmp( tile->gossip.identity_key_path, "" ) ) )
     487           0 :     FD_LOG_ERR(( "identity_key_path not set" ));
     488             : 
     489           0 :   ctx->identity_key[ 0 ] = *(fd_pubkey_t const *)fd_type_pun_const( fd_keyload_load( tile->gossip.identity_key_path, /* pubkey only: */ 1 ) );
     490           0 :   FD_TEST( fd_rng_secure( &ctx->rng_seed, 4UL ) );
     491           0 :   FD_TEST( fd_rng_secure( &ctx->rng_idx,  8UL ) );
     492           0 : }
     493             : 
     494             : static inline fd_gossip_out_ctx_t
     495             : out1( fd_topo_t const *      topo,
     496             :       fd_topo_tile_t const * tile,
     497           0 :       char const *           name ) {
     498           0 :   ulong idx = ULONG_MAX;
     499             : 
     500           0 :   for( ulong i=0UL; i<tile->out_cnt; i++ ) {
     501           0 :     fd_topo_link_t const * link = &topo->links[ tile->out_link_id[ i ] ];
     502           0 :     if( !strcmp( link->name, name ) ) {
     503           0 :       if( FD_UNLIKELY( idx!=ULONG_MAX ) ) FD_LOG_ERR(( "tile %s:%lu had multiple output links named %s but expected one", tile->name, tile->kind_id, name ));
     504           0 :       idx = i;
     505           0 :     }
     506           0 :   }
     507             : 
     508           0 :   if( FD_UNLIKELY( idx==ULONG_MAX ) ) FD_LOG_ERR(( "tile %s:%lu had no output link named %s", tile->name, tile->kind_id, name ));
     509             : 
     510           0 :   ulong mtu = topo->links[ tile->out_link_id[ idx ] ].mtu;
     511           0 :   if( FD_UNLIKELY( mtu==0UL ) ) return (fd_gossip_out_ctx_t){ .idx = idx, .mem = NULL, .chunk0 = ULONG_MAX, .wmark = ULONG_MAX, .chunk = ULONG_MAX };
     512             : 
     513           0 :   void * mem   = topo->workspaces[ topo->objs[ topo->links[ tile->out_link_id[ idx ] ].dcache_obj_id ].wksp_id ].wksp;
     514           0 :   ulong chunk0 = fd_dcache_compact_chunk0( mem, topo->links[ tile->out_link_id[ idx ] ].dcache );
     515           0 :   ulong wmark  = fd_dcache_compact_wmark ( mem, topo->links[ tile->out_link_id[ idx ] ].dcache, topo->links[ tile->out_link_id[ idx ] ].mtu );
     516             : 
     517           0 :   return (fd_gossip_out_ctx_t){ .idx = idx, .mem = mem, .chunk0 = chunk0, .wmark = wmark, .chunk = chunk0 };
     518           0 : }
     519             : 
     520             : static void
     521             : unprivileged_init( fd_topo_t const *      topo,
     522           0 :                    fd_topo_tile_t const * tile ) {
     523           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     524             : 
     525           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     526           0 :   fd_gossip_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gossip_tile_ctx_t), sizeof(fd_gossip_tile_ctx_t) );
     527           0 :   void * _gossip             = FD_SCRATCH_ALLOC_APPEND( l, fd_gossip_align(),             fd_gossip_footprint( tile->gossip.max_entries, tile->gossip.entrypoints_cnt ) );
     528             : 
     529           0 :   FD_TEST( fd_rng_join( fd_rng_new( ctx->rng, ctx->rng_seed, ctx->rng_idx ) ) );
     530             : 
     531           0 :   ctx->wfs_state = fd_int_if( memcmp( tile->gossip.wait_for_supermajority_with_bank_hash.uc, ((fd_pubkey_t){ 0 }).uc, sizeof(fd_pubkey_t) ), FD_GOSSIP_WFS_STATE_INIT, FD_GOSSIP_WFS_STATE_DONE );
     532             : 
     533           0 :   FD_TEST( tile->in_cnt<=sizeof(ctx->in)/sizeof(ctx->in[0]) );
     534           0 :   ulong sign_in_tile_idx = ULONG_MAX;
     535           0 :   for( ulong i=0UL; i<tile->in_cnt; i++ ) {
     536           0 :     fd_topo_link_t const * link = &topo->links[ tile->in_link_id[ i ] ];
     537           0 :     fd_topo_wksp_t const * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
     538             : 
     539           0 :     ctx->in[ i ].mem = link_wksp->wksp;
     540           0 :     if( FD_LIKELY( link->mtu ) ) {
     541           0 :       ctx->in[ i ].chunk0 = fd_dcache_compact_chunk0( ctx->in[ i ].mem, link->dcache );
     542           0 :       ctx->in[ i ].wmark  = fd_dcache_compact_wmark ( ctx->in[ i ].mem, link->dcache, link->mtu );
     543           0 :     }
     544           0 :     ctx->in[ i ].mtu = link->mtu;
     545             : 
     546           0 :     if( FD_UNLIKELY( !strcmp( link->name, "ipecho_out" ) ) ) {
     547           0 :       ctx->in[ i ].kind = IN_KIND_SHRED_VERSION;
     548           0 :     } else if( FD_UNLIKELY( !strcmp( link->name, "gossvf_gossip" ) ) ) {
     549           0 :       ctx->in[ i ].kind = IN_KIND_GOSSVF;
     550           0 :       FD_TEST( link->mtu<=sizeof(ctx->gossvf_staged) );
     551           0 :     } else if( FD_UNLIKELY( !strcmp( link->name, "sign_gossip" ) ) ) {
     552           0 :       ctx->in[ i ].kind = IN_KIND_SIGN;
     553           0 :       sign_in_tile_idx = i;
     554           0 :     } else if( FD_UNLIKELY( !strcmp( link->name, "txsend_out" ) ) ) {
     555           0 :       ctx->in[ i ].kind = IN_KIND_TXSEND;
     556           0 :     } else if( FD_UNLIKELY( !strcmp( link->name, "replay_epoch" ) ) ) {
     557           0 :       ctx->in[ i ].kind = IN_KIND_EPOCH;
     558           0 :     } else if( FD_UNLIKELY( !strcmp( link->name, "tower_out" ) ) ) {
     559           0 :       ctx->in[ i ].kind = IN_KIND_TOWER;
     560           0 :     } else if( FD_UNLIKELY( !strcmp( link->name, "snapin_manif" ) ) ) {
     561           0 :       ctx->in[ i ].kind = IN_KIND_SNAPIN_MANIF;
     562           0 :     } else {
     563           0 :       FD_LOG_ERR(( "unexpected input link name %s", link->name ));
     564           0 :     }
     565           0 :   }
     566             : 
     567           0 :   if( FD_UNLIKELY( sign_in_tile_idx==ULONG_MAX ) )
     568           0 :     FD_LOG_ERR(( "tile %s:%lu had no input link named sign_gossip", tile->name, tile->kind_id ));
     569             : 
     570           0 :   *ctx->net_out    = out1( topo, tile, "gossip_net"    );
     571           0 :   *ctx->sign_out   = out1( topo, tile, "gossip_sign"   );
     572           0 :   *ctx->gossip_out = out1( topo, tile, "gossip_out"    );
     573           0 :   *ctx->gossvf_out = out1( topo, tile, "gossip_gossvf" );
     574             : 
     575           0 :   fd_topo_link_t const * sign_in  = &topo->links[ tile->in_link_id [ sign_in_tile_idx  ] ];
     576           0 :   fd_topo_link_t const * sign_out = &topo->links[ tile->out_link_id[ ctx->sign_out->idx ] ];
     577             : 
     578           0 :   ctx->keyswitch = fd_keyswitch_join( fd_topo_obj_laddr( topo, tile->id_keyswitch_obj_id ) );
     579           0 :   FD_TEST( ctx->keyswitch );
     580             : 
     581           0 :   if( fd_keyguard_client_join( fd_keyguard_client_new( ctx->keyguard_client,
     582           0 :                                                        sign_out->mcache,
     583           0 :                                                        sign_out->dcache,
     584           0 :                                                        sign_in->mcache,
     585           0 :                                                        sign_in->dcache,
     586           0 :                                                        sign_out->mtu ) )==NULL ) {
     587           0 :     FD_LOG_ERR(( "failed to join keyguard client" ));
     588           0 :   }
     589             : 
     590           0 :   ctx->ticks_per_ns   = fd_tempo_tick_per_ns( NULL );
     591           0 :   ctx->last_wallclock = fd_log_wallclock();
     592           0 :   ctx->last_tickcount = fd_tickcount();
     593             : 
     594           0 :   ctx->my_contact_info->shred_version = tile->gossip.shred_version;
     595             : 
     596           0 :   ctx->my_contact_info->outset = (ulong)FD_NANOSEC_TO_MICRO( tile->gossip.boot_timestamp_nanos );
     597             : 
     598           0 :   ctx->my_contact_info->version.client      = FD_GOSSIP_CONTACT_INFO_CLIENT_FIREDANCER;
     599           0 :   ctx->my_contact_info->version.major       = (ushort)fd_major_version;
     600           0 :   ctx->my_contact_info->version.minor       = (ushort)fd_minor_version;
     601           0 :   ctx->my_contact_info->version.patch       = (ushort)fd_patch_version;
     602           0 :   ctx->my_contact_info->version.commit      = fd_commit_ref_u32;
     603           0 :   ctx->my_contact_info->version.feature_set = FD_FEATURE_SET_ID;
     604             : 
     605           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP ]            = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = tile->gossip.ports.gossip   ? tile->gossip.ip_addr : 0, .port = fd_ushort_bswap( tile->gossip.ports.gossip )   };
     606           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TVU ]               = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = tile->gossip.ports.tvu      ? tile->gossip.ip_addr : 0, .port = fd_ushort_bswap( tile->gossip.ports.tvu )      };
     607           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TPU ]               = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = tile->gossip.ports.tpu      ? tile->gossip.ip_addr : 0, .port = fd_ushort_bswap( tile->gossip.ports.tpu )      };
     608           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_FORWARDS ]      = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = tile->gossip.ports.tpu      ? tile->gossip.ip_addr : 0, .port = fd_ushort_bswap( tile->gossip.ports.tpu )      };
     609           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_QUIC ]          = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = tile->gossip.ports.tpu_quic ? tile->gossip.ip_addr : 0, .port = fd_ushort_bswap( tile->gossip.ports.tpu_quic ) };
     610           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_VOTE_QUIC ]     = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = tile->gossip.ports.tpu_quic ? tile->gossip.ip_addr : 0, .port = fd_ushort_bswap( tile->gossip.ports.tpu_quic ) };
     611           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_FORWARDS_QUIC ] = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = tile->gossip.ports.tpu_quic ? tile->gossip.ip_addr : 0, .port = fd_ushort_bswap( tile->gossip.ports.tpu_quic ) };
     612           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_VOTE ]          = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = tile->gossip.ports.tpu      ? tile->gossip.ip_addr : 0, .port = fd_ushort_bswap( tile->gossip.ports.tpu )      };
     613           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_SERVE_REPAIR ]      = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = tile->gossip.ports.rserve   ? tile->gossip.ip_addr : 0, .port = fd_ushort_bswap( tile->gossip.ports.rserve )   };
     614           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_SERVE_REPAIR_QUIC ] = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = tile->gossip.ports.rserve   ? tile->gossip.ip_addr : 0, .port = fd_ushort_bswap( tile->gossip.ports.rserve )   };
     615             : 
     616           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_TVU_QUIC ]          = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = 0, .port = 0 };
     617           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_RPC ]               = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = 0, .port = 0 };
     618           0 :   ctx->my_contact_info->sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_RPC_PUBSUB ]        = (fd_gossip_socket_t){ .is_ipv6 = 0, .ip4 = 0, .port = 0 };
     619             : 
     620           0 :   ctx->gossip = fd_gossip_join( fd_gossip_new( _gossip,
     621           0 :                                                ctx->rng,
     622           0 :                                                tile->gossip.max_entries,
     623           0 :                                                tile->gossip.entrypoints_cnt,
     624           0 :                                                tile->gossip.entrypoints,
     625           0 :                                                ctx->identity_key->uc,
     626           0 :                                                ctx->my_contact_info,
     627           0 :                                                ctx->last_wallclock,
     628           0 :                                                gossip_send_fn,
     629           0 :                                                ctx,
     630           0 :                                                gossip_sign_fn,
     631           0 :                                                ctx,
     632           0 :                                                gossip_ping_tracker_change_fn,
     633           0 :                                                ctx,
     634           0 :                                                gossip_activity_update_fn,
     635           0 :                                                ctx,
     636           0 :                                                ctx->gossip_out,
     637           0 :                                                ctx->net_out ) );
     638           0 :   FD_TEST( ctx->gossip );
     639             : 
     640           0 :   FD_MGAUGE_SET( GOSSIP, CRDS_CAPACITY,        tile->gossip.max_entries     );
     641           0 :   FD_MGAUGE_SET( GOSSIP, CRDS_PEER_CAPACITY,   FD_CONTACT_INFO_TABLE_SIZE   );
     642           0 :   FD_MGAUGE_SET( GOSSIP, CRDS_PURGED_CAPACITY, 4UL*tile->gossip.max_entries );
     643             : 
     644           0 :   fd_ip4_udp_hdr_init( ctx->net_out_hdr, FD_GOSSIP_MTU, tile->gossip.bind_ip_addr, tile->gossip.ports.gossip );
     645             : 
     646           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     647           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     648           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     649           0 : }
     650             : 
     651             : static ulong
     652             : populate_allowed_seccomp( fd_topo_t const *      topo,
     653             :                           fd_topo_tile_t const * tile,
     654             :                           ulong                  out_cnt,
     655           0 :                           struct sock_filter *   out ) {
     656           0 :   (void)topo;
     657           0 :   (void)tile;
     658             : 
     659           0 :   populate_sock_filter_policy_fd_gossip_tile( out_cnt, out, (uint)fd_log_private_logfile_fd() );
     660           0 :   return sock_filter_policy_fd_gossip_tile_instr_cnt;
     661           0 : }
     662             : 
     663             : static ulong
     664             : populate_allowed_fds( fd_topo_t const *      topo,
     665             :                       fd_topo_tile_t const * tile,
     666             :                       ulong                  out_fds_cnt,
     667           0 :                       int *                  out_fds ) {
     668           0 :   (void)topo;
     669           0 :   (void)tile;
     670             : 
     671           0 :   if( FD_UNLIKELY( out_fds_cnt<2UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
     672             : 
     673           0 :   ulong out_cnt = 0UL;
     674           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
     675           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
     676           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     677           0 :   return out_cnt;
     678           0 : }
     679             : 
     680             : /* STEM_BURST must bound the maximum number of fd_stem_publish
     681             :    calls on any single output link between two consecutive
     682             :    credit checks in the stem run loop.  One iteration consists
     683             :    of after_credit (which calls fd_gossip_advance) followed by
     684             :    processing one input fragment (returnable_frag).
     685             : 
     686             :    The two reliable output links and their per-iteration worst cases:
     687             : 
     688             :    gossvf_out (via gossip_ping_tracker_change_fn):
     689             :      tx_ping evictions + expiries            FD_PING_TRACKER_MAX
     690             :      fd_ping_tracker_track from rx_values    2*FD_GOSSIP_MESSAGE_MAX_CRDS
     691             :      Total: FD_PING_TRACKER_MAX + 2*FD_GOSSIP_MESSAGE_MAX_CRDS
     692             : 
     693             :    gossip_out (via fd_gossip_tx_publish_chunk):
     694             :      fd_crds_advance expire (ContactInfos)   FD_CONTACT_INFO_TABLE_SIZE
     695             :      fd_crds_insert publish + evictions      2*FD_GOSSIP_MESSAGE_MAX_CRDS
     696             :      Total: FD_CONTACT_INFO_TABLE_SIZE + 2*FD_GOSSIP_MESSAGE_MAX_CRDS
     697             : 
     698             :    Among the reliable output links, gossvf_out dominates. */
     699             : FD_STATIC_ASSERT( FD_PING_TRACKER_MAX+2UL*FD_GOSSIP_MESSAGE_MAX_CRDS>=FD_CONTACT_INFO_TABLE_SIZE+2UL*FD_GOSSIP_MESSAGE_MAX_CRDS, "STEM_BURST does not account for worst case output link" );
     700           0 : #define STEM_BURST (FD_PING_TRACKER_MAX+2UL*FD_GOSSIP_MESSAGE_MAX_CRDS)
     701             : 
     702           0 : #define STEM_LAZY  (128L*3000L)
     703             : 
     704           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_gossip_tile_ctx_t
     705           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_gossip_tile_ctx_t)
     706             : 
     707           0 : #define STEM_CALLBACK_DURING_HOUSEKEEPING during_housekeeping
     708           0 : #define STEM_CALLBACK_METRICS_WRITE       metrics_write
     709           0 : #define STEM_CALLBACK_AFTER_CREDIT        after_credit
     710           0 : #define STEM_CALLBACK_BEFORE_FRAG         before_frag
     711           0 : #define STEM_CALLBACK_DURING_FRAG         during_frag
     712           0 : #define STEM_CALLBACK_AFTER_FRAG          after_frag
     713           0 : #define STEM_CALLBACK_RETURNABLE_FRAG     returnable_frag
     714             : 
     715             : #include "../../disco/stem/fd_stem.c"
     716             : 
     717             : fd_topo_run_tile_t fd_tile_gossip = {
     718             :   .name                     = "gossip",
     719             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     720             :   .populate_allowed_fds     = populate_allowed_fds,
     721             :   .scratch_align            = scratch_align,
     722             :   .scratch_footprint        = scratch_footprint,
     723             :   .privileged_init          = privileged_init,
     724             :   .unprivileged_init        = unprivileged_init,
     725             :   .run                      = stem_run,
     726             : };

Generated by: LCOV version 1.14