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

Generated by: LCOV version 1.14