LCOV - code coverage report
Current view: top level - discoh/guih - fd_guih.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 1814 0.0 %
Date: 2026-09-17 04:28:31 Functions: 0 48 0.0 %

          Line data    Source code
       1             : #include "fd_guih.h"
       2             : #include "fd_guih_printf.h"
       3             : #include "fd_guih_metrics.h"
       4             : 
       5             : #include "../../disco/metrics/fd_metrics.h"
       6             : #include "../../discof/gossip/fd_gossip_tile.h"
       7             : #include "../../discoh/plugin/fd_plugin.h"
       8             : #include "../../disco/bundle/fd_bundle_tile.h"
       9             : 
      10             : #include "../../ballet/base58/fd_base58.h"
      11             : #include "../../ballet/json/fd_jtok.h"
      12             : #include "../../disco/genesis/fd_genesis_cluster.h"
      13             : #include "../../disco/pack/fd_pack.h"
      14             : #include "../../disco/pack/fd_pack_cost.h"
      15             : 
      16             : #include <stdio.h>
      17             : 
      18             : FD_FN_CONST ulong
      19           0 : fd_guih_align( void ) {
      20           0 :   return 128UL;
      21           0 : }
      22             : 
      23             : ulong
      24           0 : fd_guih_footprint( ulong tile_cnt ) {
      25           0 :   FD_TEST( tile_cnt && tile_cnt <=FD_TOPO_MAX_TILES );
      26             : 
      27           0 :   ulong l = FD_LAYOUT_INIT;
      28           0 :   l = FD_LAYOUT_APPEND( l, fd_guih_align(),                sizeof(fd_guih_t) );
      29           0 :   l = FD_LAYOUT_APPEND( l, alignof(fd_guih_tile_timers_t), FD_GUIH_TILE_TIMER_SNAP_CNT * tile_cnt * sizeof(fd_guih_tile_timers_t) );
      30           0 :   l = FD_LAYOUT_APPEND( l, alignof(fd_guih_tile_timers_t), FD_GUIH_LEADER_CNT * FD_GUIH_TILE_TIMER_LEADER_DOWNSAMPLE_CNT * tile_cnt * sizeof(fd_guih_tile_timers_t) );
      31           0 :   l = FD_LAYOUT_APPEND( l, fd_guih_rate_deque_align(),     fd_guih_rate_deque_footprint() ); /* ingress_maxq */
      32           0 :   l = FD_LAYOUT_APPEND( l, fd_guih_rate_deque_align(),     fd_guih_rate_deque_footprint() ); /* egress_maxq  */
      33           0 :   return FD_LAYOUT_FINI( l, fd_guih_align() );
      34           0 : }
      35             : 
      36             : void *
      37             : fd_guih_new( void *                shmem,
      38             :             fd_http_server_t *    http,
      39             :             char const *          version,
      40             :             char const *          cluster,
      41             :             uchar const *         identity_key,
      42             :             int                   has_vote_key,
      43             :             uchar const *         vote_key,
      44             :             int                   is_full_client,
      45             :             int                   snapshots_enabled FD_PARAM_UNUSED,
      46             :             int                   is_voting,
      47             :             int                   schedule_strategy,
      48             :             char const *          wfs_expected_bank_hash_cstr FD_PARAM_UNUSED,
      49             :             ushort                expected_shred_version,
      50             :             fd_topo_t const *     topo,
      51           0 :             long                  now ) {
      52             : 
      53           0 :   if( FD_UNLIKELY( !shmem ) ) {
      54           0 :     FD_LOG_WARNING(( "NULL shmem" ));
      55           0 :     return NULL;
      56           0 :   }
      57             : 
      58           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmem, fd_guih_align() ) ) ) {
      59           0 :     FD_LOG_WARNING(( "misaligned shmem" ));
      60           0 :     return NULL;
      61           0 :   }
      62             : 
      63           0 :   if( FD_UNLIKELY( topo->tile_cnt>FD_TOPO_MAX_TILES ) ) {
      64           0 :     FD_LOG_WARNING(( "too many tiles" ));
      65           0 :     return NULL;
      66           0 :   }
      67             : 
      68           0 :   ulong tile_cnt = topo->tile_cnt;
      69             : 
      70           0 :   FD_SCRATCH_ALLOC_INIT( l, shmem );
      71           0 :   fd_guih_t *             gui                  = FD_SCRATCH_ALLOC_APPEND( l, fd_guih_align(),                sizeof(fd_guih_t) );
      72           0 :   fd_guih_tile_timers_t * tile_timers_snap_mem = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_guih_tile_timers_t), FD_GUIH_TILE_TIMER_SNAP_CNT * tile_cnt * sizeof(fd_guih_tile_timers_t) );
      73           0 :   fd_guih_tile_timers_t * leader_tt_mem        = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_guih_tile_timers_t), FD_GUIH_LEADER_CNT * FD_GUIH_TILE_TIMER_LEADER_DOWNSAMPLE_CNT * tile_cnt * sizeof(fd_guih_tile_timers_t) );
      74           0 :   void *                 ingress_maxq_mem     = FD_SCRATCH_ALLOC_APPEND( l, fd_guih_rate_deque_align(),     fd_guih_rate_deque_footprint() );
      75           0 :   void *                 egress_maxq_mem      = FD_SCRATCH_ALLOC_APPEND( l, fd_guih_rate_deque_align(),     fd_guih_rate_deque_footprint() );
      76             : 
      77           0 :   gui->http     = http;
      78           0 :   gui->topo     = topo;
      79           0 :   gui->tile_cnt = tile_cnt;
      80             : 
      81           0 :   gui->summary.tile_timers_snap = tile_timers_snap_mem;
      82           0 :   gui->summary.ingress_maxq     = fd_guih_rate_deque_join( fd_guih_rate_deque_new( ingress_maxq_mem ) );
      83           0 :   gui->summary.egress_maxq      = fd_guih_rate_deque_join( fd_guih_rate_deque_new( egress_maxq_mem  ) );
      84             : 
      85           0 :   gui->summary.network_stats_has_prev = 0;
      86           0 :   gui->summary.net_rate_ema_ready     = 0;
      87           0 :   gui->summary.net_rate_prev_ts       = 0L;
      88           0 :   fd_memset( gui->summary.ingress_ema, 0, sizeof(gui->summary.ingress_ema) );
      89           0 :   fd_memset( gui->summary.egress_ema,  0, sizeof(gui->summary.egress_ema)  );
      90             : 
      91           0 :   for( ulong i=0UL; i<FD_GUIH_LEADER_CNT; i++ ) gui->leader_slots[ i ]->tile_timers = leader_tt_mem + i * FD_GUIH_TILE_TIMER_LEADER_DOWNSAMPLE_CNT * tile_cnt;
      92             : 
      93           0 :   gui->leader_slot = ULONG_MAX;
      94           0 :   gui->summary.schedule_strategy = schedule_strategy;
      95             : 
      96             : 
      97           0 :   gui->next_sample_400millis = now;
      98           0 :   gui->next_sample_100millis = now;
      99           0 :   gui->next_sample_50millis  = now;
     100           0 :   gui->next_sample_25millis  = now;
     101           0 :   gui->next_sample_10millis  = now;
     102             : 
     103           0 :   memcpy( gui->summary.identity_key->uc, identity_key, 32UL );
     104           0 :   fd_base58_encode_32( identity_key, NULL, gui->summary.identity_key_base58 );
     105           0 :   gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
     106             : 
     107           0 :   if( FD_LIKELY( has_vote_key ) ) {
     108           0 :     gui->summary.has_vote_key = 1;
     109           0 :     memcpy( gui->summary.vote_key->uc, vote_key, 32UL );
     110           0 :     fd_base58_encode_32( vote_key, NULL, gui->summary.vote_key_base58 );
     111           0 :     gui->summary.vote_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
     112           0 :   } else {
     113           0 :     gui->summary.has_vote_key = 0;
     114           0 :     memset( gui->summary.vote_key_base58, 0, sizeof(gui->summary.vote_key_base58) );
     115           0 :   }
     116             : 
     117           0 :   gui->summary.is_full_client                = is_full_client;
     118           0 :   gui->summary.version                       = version;
     119           0 :   gui->summary.cluster                       = cluster;
     120           0 :   gui->summary.startup_time_nanos            = gui->next_sample_400millis;
     121           0 :   gui->summary.expected_shred_version        = expected_shred_version;
     122           0 :   gui->summary.wfs_enabled          = 0;
     123           0 :   gui->summary.wfs_bank_hash[ 0UL ] = '\0';
     124             : 
     125           0 :   gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_INITIALIZING;
     126           0 :   gui->summary.startup_progress.startup_got_full_snapshot              = 0;
     127           0 :   gui->summary.startup_progress.startup_full_snapshot_slot             = 0;
     128           0 :   gui->summary.startup_progress.startup_incremental_snapshot_slot      = 0;
     129           0 :   gui->summary.startup_progress.startup_waiting_for_supermajority_slot = ULONG_MAX;
     130           0 :   gui->summary.startup_progress.startup_ledger_max_slot                = ULONG_MAX;
     131             : 
     132           0 :   gui->summary.identity_account_balance      = 0UL;
     133           0 :   gui->summary.vote_account_balance          = 0UL;
     134           0 :   gui->summary.estimated_slot_duration_nanos = 0UL;
     135             : 
     136           0 :   gui->summary.vote_distance = 0UL;
     137           0 :   gui->summary.vote_state = is_voting ? FD_GUIH_VOTE_STATE_VOTING : FD_GUIH_VOTE_STATE_NON_VOTING;
     138             : 
     139           0 :   gui->summary.sock_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "sock"   );
     140           0 :   gui->summary.mlx5_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "mlx5"   );
     141           0 :   gui->summary.net_tile_cnt    = fd_topo_tile_name_cnt( gui->topo, "net"    );
     142           0 :   gui->summary.quic_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "quic"   );
     143           0 :   gui->summary.verify_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "verify" );
     144           0 :   gui->summary.resolh_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolh" );
     145           0 :   gui->summary.resolv_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolv" );
     146           0 :   gui->summary.bank_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "bank"   );
     147           0 :   gui->summary.execle_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "execle" );
     148           0 :   gui->summary.execrp_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "execrp" );
     149           0 :   gui->summary.shred_tile_cnt  = fd_topo_tile_name_cnt( gui->topo, "shred"  );
     150             : 
     151           0 :   gui->summary.slot_rooted                   = ULONG_MAX;
     152           0 :   gui->summary.slot_optimistically_confirmed = ULONG_MAX;
     153           0 :   gui->summary.slot_completed                = ULONG_MAX;
     154           0 :   gui->summary.slot_estimated                = ULONG_MAX;
     155           0 :   gui->summary.slot_caught_up                = ULONG_MAX;
     156           0 :   gui->summary.slot_repair                   = ULONG_MAX;
     157           0 :   gui->summary.slot_turbine                  = ULONG_MAX;
     158           0 :   gui->summary.slot_reset                    = ULONG_MAX;
     159           0 :   gui->summary.slot_storage                  = ULONG_MAX;
     160           0 :   gui->summary.active_fork_cnt               = 1UL;
     161             : 
     162           0 :   for( ulong i=0UL; i < (FD_GUIH_REPAIR_SLOT_HISTORY_SZ+1UL); i++ )  gui->summary.slots_max_repair[ i ].slot  = ULONG_MAX;
     163           0 :   for( ulong i=0UL; i < (FD_GUIH_TURBINE_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_turbine[ i ].slot = ULONG_MAX;
     164             : 
     165           0 :   for( ulong i=0UL; i < FD_GUIH_TURBINE_RECV_TIMESTAMPS; i++ ) gui->turbine_slots[ i ].slot = ULONG_MAX;
     166             : 
     167           0 :   gui->summary.estimated_tps_history_idx = 0UL;
     168           0 :   memset( gui->summary.estimated_tps_history, 0, sizeof(gui->summary.estimated_tps_history) );
     169             : 
     170           0 :   memset( gui->summary.txn_waterfall_reference, 0, sizeof(gui->summary.txn_waterfall_reference) );
     171           0 :   memset( gui->summary.txn_waterfall_current,   0, sizeof(gui->summary.txn_waterfall_current) );
     172             : 
     173           0 :   memset( gui->summary.tile_stats_reference, 0, sizeof(gui->summary.tile_stats_reference) );
     174           0 :   memset( gui->summary.tile_stats_current, 0, sizeof(gui->summary.tile_stats_current) );
     175             : 
     176           0 :   gui->summary.progcache_history_idx = 0UL;
     177           0 :   memset( gui->summary.progcache_hits_history,    0, sizeof(gui->summary.progcache_hits_history) );
     178           0 :   memset( gui->summary.progcache_lookups_history, 0, sizeof(gui->summary.progcache_lookups_history) );
     179           0 :   gui->summary.progcache_hits_1min    = 0UL;
     180           0 :   gui->summary.progcache_lookups_1min = 0UL;
     181             : 
     182           0 :   memset( gui->summary.tile_timers_snap,            0, tile_cnt * sizeof(fd_guih_tile_timers_t) );
     183           0 :   memset( gui->summary.tile_timers_snap + tile_cnt, 0, tile_cnt * sizeof(fd_guih_tile_timers_t) );
     184           0 :   gui->summary.tile_timers_snap_idx    = 2UL;
     185             : 
     186           0 :   memset( gui->summary.scheduler_counts_snap[ 0 ], 0, sizeof(gui->summary.scheduler_counts_snap[ 0 ]) );
     187           0 :   memset( gui->summary.scheduler_counts_snap[ 1 ], 0, sizeof(gui->summary.scheduler_counts_snap[ 1 ]) );
     188           0 :   gui->summary.scheduler_counts_snap_idx    = 2UL;
     189             : 
     190           0 :   for( ulong i=0UL; i<FD_GUIH_SLOTS_CNT;  i++ ) gui->slots[ i ]->slot             = ULONG_MAX;
     191           0 :   for( ulong i=0UL; i<FD_GUIH_LEADER_CNT; i++ ) gui->leader_slots[ i ]->slot      = ULONG_MAX;
     192           0 :   gui->leader_slots_cnt      = 0UL;
     193             : 
     194           0 :   gui->tower_cnt = 0UL;
     195             : 
     196           0 :   gui->block_engine.has_block_engine = 0;
     197             : 
     198           0 :   gui->epoch.has_epoch[ 0 ] = 0;
     199           0 :   gui->epoch.has_epoch[ 1 ] = 0;
     200             : 
     201           0 :   gui->gossip.peer_cnt               = 0UL;
     202           0 :   gui->vote_account.vote_account_cnt = 0UL;
     203           0 :   gui->validator_info.info_cnt       = 0UL;
     204             : 
     205           0 :   gui->pack_txn_idx = 0UL;
     206             : 
     207           0 :   gui->shreds.leader_shred_cnt      = 0UL;
     208           0 :   gui->shreds.staged_next_broadcast = 0UL;
     209           0 :   gui->shreds.staged_head           = 0UL;
     210           0 :   gui->shreds.staged_tail           = 0UL;
     211           0 :   gui->shreds.history_tail          = 0UL;
     212           0 :   gui->shreds.history_slot          = ULONG_MAX;
     213           0 :   gui->summary.catch_up_repair_sz   = 0UL;
     214           0 :   gui->summary.catch_up_turbine_sz  = 0UL;
     215           0 :   gui->summary.late_votes_sz        = 0UL;
     216             : 
     217           0 :   return gui;
     218           0 : }
     219             : 
     220             : fd_guih_t *
     221           0 : fd_guih_join( void * shmem ) {
     222           0 :   return (fd_guih_t *)shmem;
     223           0 : }
     224             : 
     225             : void
     226             : fd_guih_set_identity( fd_guih_t *    gui,
     227           0 :                      uchar const * identity_pubkey ) {
     228           0 :   memcpy( gui->summary.identity_key->uc, identity_pubkey, 32UL );
     229           0 :   fd_base58_encode_32( identity_pubkey, NULL, gui->summary.identity_key_base58 );
     230           0 :   gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
     231             : 
     232           0 :   fd_guih_printf_identity_key( gui );
     233           0 :   fd_http_server_ws_broadcast( gui->http );
     234           0 : }
     235             : 
     236             : void
     237             : fd_guih_ws_open( fd_guih_t * gui,
     238             :                 ulong      ws_conn_id,
     239           0 :                 long now ) {
     240           0 :   void (* printers[] )( fd_guih_t * gui ) = {
     241           0 :     fd_guih_printf_startup_progress,
     242           0 :     fd_guih_printf_version,
     243           0 :     fd_guih_printf_cluster,
     244           0 :     fd_guih_printf_commit_hash,
     245           0 :     fd_guih_printf_identity_key,
     246           0 :     fd_guih_printf_vote_key,
     247           0 :     fd_guih_printf_startup_time_nanos,
     248           0 :     fd_guih_printf_vote_state,
     249           0 :     fd_guih_printf_vote_distance,
     250           0 :     fd_guih_printf_turbine_slot,
     251           0 :     fd_guih_printf_repair_slot,
     252           0 :     fd_guih_printf_slot_caught_up,
     253           0 :     fd_guih_printf_tps_history,
     254           0 :     fd_guih_printf_tiles,
     255           0 :     fd_guih_printf_schedule_strategy,
     256           0 :     fd_guih_printf_identity_balance,
     257           0 :     fd_guih_printf_vote_balance,
     258           0 :     fd_guih_printf_estimated_slot_duration_nanos,
     259           0 :     fd_guih_printf_root_slot,
     260           0 :     fd_guih_printf_storage_slot,
     261           0 :     fd_guih_printf_reset_slot,
     262           0 :     fd_guih_printf_active_fork_cnt,
     263           0 :     fd_guih_printf_optimistically_confirmed_slot,
     264           0 :     fd_guih_printf_completed_slot,
     265           0 :     fd_guih_printf_estimated_slot,
     266           0 :     fd_guih_printf_live_tile_timers,
     267           0 :     fd_guih_printf_live_tile_metrics,
     268           0 :     fd_guih_printf_catch_up_history,
     269           0 :     fd_guih_printf_vote_latency_history,
     270           0 :     fd_guih_printf_late_votes_history,
     271           0 :     fd_guih_printf_health
     272           0 :   };
     273             : 
     274           0 :   ulong printers_len = sizeof(printers) / sizeof(printers[0]);
     275           0 :   for( ulong i=0UL; i<printers_len; i++ ) {
     276           0 :     printers[ i ]( gui );
     277           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     278           0 :   }
     279             : 
     280           0 :   if( FD_LIKELY( gui->block_engine.has_block_engine ) ) {
     281           0 :     fd_guih_printf_block_engine( gui );
     282           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     283           0 :   }
     284             : 
     285           0 :   for( ulong i=0UL; i<2UL; i++ ) {
     286           0 :     if( FD_LIKELY( gui->epoch.has_epoch[ i ] ) ) {
     287           0 :       fd_guih_printf_skip_rate( gui, i );
     288           0 :       FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     289           0 :       fd_guih_printf_epoch( gui, i );
     290           0 :       FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     291           0 :     }
     292           0 :   }
     293             : 
     294           0 :   ulong epoch_idx = fd_guih_current_epoch_idx( gui );
     295           0 :   if( FD_LIKELY( epoch_idx!=ULONG_MAX ) ) {
     296           0 :     fd_guih_printf_skipped_history( gui, epoch_idx );
     297           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     298           0 :     fd_guih_printf_skipped_history_cluster( gui, epoch_idx );
     299           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     300           0 :   }
     301             : 
     302             :   /* Print peers last because it's the largest message and would
     303             :      block other information. */
     304           0 :   fd_guih_printf_peers_all( gui );
     305           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     306             : 
     307             :   /* rebroadcast 10s of historical shred data */
     308           0 :   if( FD_LIKELY( gui->shreds.staged_next_broadcast!=ULONG_MAX ) ) {
     309           0 :     fd_guih_printf_shred_rebroadcast( gui, now-(long)(10*1e9) );
     310           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     311           0 :   }
     312           0 : }
     313             : 
     314             : static void
     315           0 : fd_guih_tile_timers_snap( fd_guih_t * gui ) {
     316           0 :   fd_guih_tile_timers_t * cur = gui->summary.tile_timers_snap + gui->summary.tile_timers_snap_idx * gui->tile_cnt;
     317           0 :   gui->summary.tile_timers_snap_idx = (gui->summary.tile_timers_snap_idx+1UL)%FD_GUIH_TILE_TIMER_SNAP_CNT;
     318           0 :   for( ulong i=0UL; i<gui->topo->tile_cnt; i++ ) {
     319           0 :     fd_topo_tile_t const * tile = &gui->topo->tiles[ i ];
     320           0 :     if ( FD_UNLIKELY( !tile->metrics ) ) {
     321             :       /* bench tiles might not have been booted initially.
     322             :          This check shouldn't be necessary if all tiles barrier after boot. */
     323             :       // TODO(FIXME) this probably isn't the right fix but it makes fddev bench work for now
     324           0 :       return;
     325           0 :     }
     326           0 :     volatile ulong const * tile_metrics = fd_metrics_tile( tile->metrics );
     327             : 
     328           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_HOUSEKEEPING_IDX    ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_HOUSEKEEPING )    ];
     329           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_HOUSEKEEPING_IDX   ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_HOUSEKEEPING )   ];
     330           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_HOUSEKEEPING ) ];
     331           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_PREFRAG_IDX         ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_PREFRAG )         ];
     332           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_PREFRAG_IDX        ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_PREFRAG )        ];
     333           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX      ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG )      ];
     334           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_POSTFRAG_IDX        ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_POSTFRAG )        ];
     335           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_POSTFRAG_IDX       ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_POSTFRAG )       ];
     336             : 
     337           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_WAIT_IDX   ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_WAIT )   ];
     338           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_USER_IDX   ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_USER )   ];
     339           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_SYSTEM_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_SYSTEM ) ];
     340           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_IDLE_IDX   ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_IDLE )   ];
     341             : 
     342           0 :     cur[ i ].in_backp  = (int)tile_metrics[ MIDX(GAUGE, TILE, IN_BACKPRESSURE) ];
     343           0 :     cur[ i ].status    = (uchar)tile_metrics[ MIDX( GAUGE, TILE, STATUS ) ];
     344           0 :     cur[ i ].heartbeat = tile_metrics[ MIDX( GAUGE, TILE, HEARTBEAT_TIMESTAMP_NANOS ) ];
     345           0 :     cur[ i ].backp_cnt = tile_metrics[ MIDX( COUNTER, TILE, BACKPRESSURE ) ];
     346           0 :     cur[ i ].nvcsw     = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_VOLUNTARY ) ];
     347           0 :     cur[ i ].nivcsw    = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_INVOLUNTARY ) ];
     348           0 :     cur[ i ].minflt    = tile_metrics[ MIDX( COUNTER, TILE, PAGE_FAULT_MINOR ) ];
     349           0 :     cur[ i ].majflt    = tile_metrics[ MIDX( COUNTER, TILE, PAGE_FAULT_MAJOR ) ];
     350           0 :     cur[ i ].last_cpu  = (ushort)tile_metrics[ MIDX( GAUGE, TILE, LAST_CPU ) ];
     351           0 :     cur[ i ].interrupts     = tile_metrics[ MIDX( COUNTER, TILE, IRQ_PREEMPTED ) ];
     352           0 :     cur[ i ].tlb_shootdowns = tile_metrics[ MIDX( COUNTER, TILE, TLB_SHOOTDOWN ) ];
     353           0 :     cur[ i ].timer_ticks    = tile_metrics[ MIDX( COUNTER, TILE, TIMER_TICK ) ];
     354           0 :   }
     355           0 : }
     356             : 
     357             : static void
     358           0 : fd_guih_scheduler_counts_snap( fd_guih_t * gui, long now ) {
     359           0 :   ulong pack_tile_idx = fd_topo_find_tile( gui->topo, "pack", 0UL );
     360           0 :   if( FD_UNLIKELY( pack_tile_idx==ULONG_MAX ) ) return;
     361             : 
     362           0 :   fd_guih_scheduler_counts_t * cur = gui->summary.scheduler_counts_snap[ gui->summary.scheduler_counts_snap_idx ];
     363           0 :   gui->summary.scheduler_counts_snap_idx = (gui->summary.scheduler_counts_snap_idx+1UL)%FD_GUIH_SCHEDULER_COUNT_SNAP_CNT;
     364             : 
     365           0 :   fd_topo_tile_t const * pack = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "pack", 0UL ) ];
     366           0 :   volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
     367             : 
     368           0 :   cur->sample_time_ns = now;
     369             : 
     370           0 :   cur->regular     = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_REGULAR ) ];
     371           0 :   cur->votes       = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_VOTES ) ];
     372           0 :   cur->conflicting = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_CONFLICTING ) ];
     373           0 :   cur->bundles     = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_BUNDLES ) ];
     374           0 : }
     375             : 
     376             : static void
     377           0 : fd_guih_estimated_tps_snap( fd_guih_t * gui ) {
     378           0 :   ulong vote_failed     = 0UL;
     379           0 :   ulong vote_success    = 0UL;
     380           0 :   ulong nonvote_success = 0UL;
     381           0 :   ulong nonvote_failed  = 0UL;
     382             : 
     383           0 :   if( FD_LIKELY( gui->summary.slot_completed==ULONG_MAX ) ) return;
     384           0 :   for( ulong i=0UL; i<fd_ulong_min( gui->summary.slot_completed+1UL, FD_GUIH_SLOTS_CNT ); i++ ) {
     385           0 :     ulong _slot = gui->summary.slot_completed-i;
     386           0 :     fd_guih_slot_t const * slot = fd_guih_get_slot_const( gui, _slot );
     387           0 :     if( FD_UNLIKELY( !slot ) ) break; /* Slot no longer exists, no TPS. */
     388           0 :     if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) continue; /* Slot is on this fork but was never completed, must have been in root path on boot. */
     389           0 :     if( FD_UNLIKELY( slot->completed_time+FD_GUIH_TPS_HISTORY_WINDOW_DURATION_SECONDS*1000L*1000L*1000L<gui->next_sample_400millis ) ) break; /* Slot too old. */
     390           0 :     if( FD_UNLIKELY( slot->skipped ) ) continue; /* Skipped slots don't count to TPS. */
     391           0 :     if( FD_UNLIKELY( slot->vote_failed==UINT_MAX ) ) continue; /* Slot transaction counts not yet populated. */
     392           0 :     vote_failed     += slot->vote_failed;
     393           0 :     vote_success    += slot->vote_success;
     394           0 :     nonvote_success += slot->nonvote_success;
     395           0 :     nonvote_failed  += slot->nonvote_failed;
     396           0 :   }
     397             : 
     398           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].vote_failed = vote_failed;
     399           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].vote_success = vote_success;
     400           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].nonvote_success = nonvote_success;
     401           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].nonvote_failed = nonvote_failed;
     402           0 :   gui->summary.estimated_tps_history_idx = (gui->summary.estimated_tps_history_idx+1UL) % FD_GUIH_TPS_HISTORY_SAMPLE_CNT;
     403           0 : }
     404             : 
     405             : static void
     406             : fd_guih_network_stats_snap_egress( fd_topo_t const *         topo,
     407             :                                    char const *              tile_name,
     408           0 :                                    fd_guih_network_stats_t * cur ) {
     409           0 :   ulong tile_cnt = fd_topo_tile_name_cnt( topo, tile_name );
     410           0 :   for( ulong i=0UL; i<tile_cnt; i++ ) {
     411           0 :     ulong tile_idx = fd_topo_find_tile( topo, tile_name, i );
     412           0 :     if( FD_UNLIKELY( tile_idx==ULONG_MAX ) ) continue;
     413           0 :     fd_topo_tile_t const * tile = &topo->tiles[ tile_idx ];
     414           0 :     for( ulong j=0UL; j<tile->in_cnt; j++ ) {
     415           0 :       ulong bytes = fd_metrics_link_in( tile->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
     416           0 :       char const * link_name = topo->links[ tile->in_link_id[ j ] ].name;
     417           0 :       if( FD_UNLIKELY( !strcmp( link_name, "shred_net"  ) ) ) cur->out.turbine += bytes;
     418           0 :       if( FD_UNLIKELY( !strcmp( link_name, "repair_net" ) ) ) cur->out.repair  += bytes;
     419           0 :       if( FD_UNLIKELY( !strcmp( link_name, "txsend_net" ) ) ) cur->out.tpu     += bytes;
     420           0 :     }
     421           0 :   }
     422           0 : }
     423             : 
     424             : static void
     425             : fd_guih_network_stats_snap( fd_guih_t *               gui,
     426           0 :                            fd_guih_network_stats_t * cur ) {
     427           0 :   fd_topo_t const * topo = gui->topo;
     428           0 :   ulong gossvf_tile_cnt = fd_topo_tile_name_cnt( topo, "gossvf" );
     429           0 :   ulong gossip_tile_cnt = fd_topo_tile_name_cnt( topo, "gossip" );
     430           0 :   ulong shred_tile_cnt  = fd_topo_tile_name_cnt( topo, "shred" );
     431           0 :   ulong quic_tile_cnt   = fd_topo_tile_name_cnt( topo, "quic" );
     432             : 
     433           0 :   cur->in.gossip   = fd_guih_metrics_gossip_total_ingress_bytes( topo, gossvf_tile_cnt );
     434           0 :   cur->out.gossip  = fd_guih_metrics_gossip_total_egress_bytes( topo, gossip_tile_cnt );
     435           0 :   cur->in.turbine  = fd_guih_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_TURBINE_RX_BYTES ) );
     436             : 
     437           0 :   cur->out.turbine = 0UL;
     438           0 :   cur->out.repair  = 0UL;
     439           0 :   cur->out.rserve  = 0UL; /* rserve is not part of frankendancer */
     440           0 :   cur->out.tpu     = 0UL;
     441           0 :   fd_guih_network_stats_snap_egress( topo, "net",  cur );
     442           0 :   fd_guih_network_stats_snap_egress( topo, "mlx5", cur );
     443             : 
     444           0 :   cur->in.repair = fd_guih_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_REPAIR_RX_BYTES ) );
     445           0 :   ulong repair_tile_idx = fd_topo_find_tile( topo, "repair", 0UL );
     446           0 :   if( FD_LIKELY( repair_tile_idx!=ULONG_MAX ) ) {
     447           0 :     fd_topo_tile_t const * repair = &topo->tiles[ repair_tile_idx ];
     448             : 
     449           0 :     for( ulong i=0UL; i<repair->in_cnt; i++ ) {
     450           0 :       if( FD_UNLIKELY( !strcmp( topo->links[ repair->in_link_id[ i ] ].name, "net_repair" ) ) ) {
     451           0 :           cur->in.repair += fd_metrics_link_in( repair->metrics, i )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
     452           0 :       }
     453           0 :     }
     454           0 :   }
     455             : 
     456           0 :   cur->in.rserve = 0UL; /* rserve is not part of frankendancer */
     457             : 
     458           0 :   cur->in.tpu = 0UL;
     459           0 :   for( ulong i=0UL; i<quic_tile_cnt; i++ ) {
     460           0 :     ulong quic_tile_idx = fd_topo_find_tile( topo, "quic", i );
     461           0 :     if( FD_UNLIKELY( quic_tile_idx==ULONG_MAX ) ) continue;
     462           0 :     fd_topo_tile_t const * quic = &topo->tiles[ quic_tile_idx ];
     463           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
     464           0 :     cur->in.tpu += quic_metrics[ MIDX( COUNTER, QUIC, PKT_RX_BYTES ) ];
     465           0 :   }
     466             : 
     467           0 :   ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
     468           0 :   if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
     469           0 :     fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
     470           0 :     volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
     471           0 :     cur->in.tpu += bundle_metrics[ MIDX( COUNTER, BUNDLE, PROTOBUF_RX_BYTES ) ];
     472           0 :   }
     473             : 
     474           0 :   ulong metric_tile_idx = fd_topo_find_tile( topo, "metric", 0UL );
     475           0 :   if( FD_LIKELY( metric_tile_idx!=ULONG_MAX ) ) {
     476           0 :     fd_topo_tile_t const * metric = &topo->tiles[ metric_tile_idx ];
     477           0 :     volatile ulong * metric_metrics = fd_metrics_tile( metric->metrics );
     478           0 :     cur->in.metric  = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_READ ) ];
     479           0 :     cur->out.metric = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_WRITTEN ) ];
     480           0 :   } else {
     481           0 :     cur->in.metric  = 0UL;
     482           0 :     cur->out.metric = 0UL;
     483           0 :   }
     484           0 : }
     485             : 
     486             : static void
     487             : fd_guih_network_rate_max_update( fd_guih_t * gui,
     488           0 :                                 long       now ) {
     489           0 :   fd_guih_network_stats_t * cur  = gui->summary.network_stats_current;
     490           0 :   fd_guih_network_stats_t * prev = gui->summary.network_stats_prev;
     491             : 
     492             :   /* On the first sample we have no previous value. */
     493           0 :   if( FD_UNLIKELY( !gui->summary.network_stats_has_prev ) ) {
     494           0 :     *prev = *cur;
     495           0 :     gui->summary.network_stats_has_prev = 1;
     496           0 :     gui->summary.net_rate_prev_ts       = now;
     497           0 :     return;
     498           0 :   }
     499             : 
     500           0 :   ulong d_in[ FD_GUIH_NET_PROTO_CNT ];
     501           0 :   d_in[ 0 ] = fd_ulong_sat_sub( cur->in.turbine, prev->in.turbine );
     502           0 :   d_in[ 1 ] = fd_ulong_sat_sub( cur->in.gossip,  prev->in.gossip  );
     503           0 :   d_in[ 2 ] = fd_ulong_sat_sub( cur->in.tpu,     prev->in.tpu     );
     504           0 :   d_in[ 3 ] = fd_ulong_sat_sub( cur->in.repair,  prev->in.repair  );
     505           0 :   d_in[ 4 ] = fd_ulong_sat_sub( cur->in.rserve,  prev->in.rserve  );
     506           0 :   d_in[ 5 ] = fd_ulong_sat_sub( cur->in.metric,  prev->in.metric  );
     507             : 
     508           0 :   ulong d_out[ FD_GUIH_NET_PROTO_CNT ];
     509           0 :   d_out[ 0 ] = fd_ulong_sat_sub( cur->out.turbine, prev->out.turbine );
     510           0 :   d_out[ 1 ] = fd_ulong_sat_sub( cur->out.gossip,  prev->out.gossip  );
     511           0 :   d_out[ 2 ] = fd_ulong_sat_sub( cur->out.tpu,     prev->out.tpu     );
     512           0 :   d_out[ 3 ] = fd_ulong_sat_sub( cur->out.repair,  prev->out.repair  );
     513           0 :   d_out[ 4 ] = fd_ulong_sat_sub( cur->out.rserve,  prev->out.rserve  );
     514           0 :   d_out[ 5 ] = fd_ulong_sat_sub( cur->out.metric,  prev->out.metric  );
     515             : 
     516             :   /* Compute per-protocol instantaneous bytes/sec rate and feed the EMA. */
     517           0 :   long dt_ns = now - gui->summary.net_rate_prev_ts;
     518           0 :   if( FD_LIKELY( dt_ns>0L ) ) {
     519           0 :     double dt_sec = (double)dt_ns / 1.0e9;
     520             : 
     521           0 :     for( ulong i=0UL; i<FD_GUIH_NET_PROTO_CNT; i++ ) {
     522           0 :       double rate_in  = (double)d_in[ i ]  / dt_sec;
     523           0 :       double rate_out = (double)d_out[ i ] / dt_sec;
     524             : 
     525           0 :       if( FD_UNLIKELY( !gui->summary.net_rate_ema_ready ) ) {
     526           0 :         gui->summary.ingress_ema[ i ] = rate_in;
     527           0 :         gui->summary.egress_ema[ i ]  = rate_out;
     528           0 :       } else {
     529           0 :         gui->summary.ingress_ema[ i ] = fd_guih_ema( gui->summary.net_rate_prev_ts, now, rate_in,  gui->summary.ingress_ema[ i ], FD_GUIH_NETWORK_EMA_HALF_LIFE_NS );
     530           0 :         gui->summary.egress_ema[ i ]  = fd_guih_ema( gui->summary.net_rate_prev_ts, now, rate_out, gui->summary.egress_ema[ i ],  FD_GUIH_NETWORK_EMA_HALF_LIFE_NS );
     531           0 :       }
     532           0 :     }
     533           0 :     gui->summary.net_rate_ema_ready = 1;
     534           0 :   }
     535           0 :   gui->summary.net_rate_prev_ts = now;
     536             : 
     537             :   /* Track max total EMA in a rolling 5-minute window using monotonic
     538             :      deques.
     539             : 
     540             :      Invariant: deque entries are strictly decreasing in value from
     541             :      head to tail.  The head is always the current window maximum.
     542             : 
     543             :      Insert:  pop tail entries whose value <= new value (they can
     544             :               never become the maximum), then push the new entry.
     545             :      Expire:  pop head entries older than 5 minutes. */
     546           0 :   if( FD_LIKELY( gui->summary.net_rate_ema_ready ) ) {
     547           0 :     double sum_in  = 0.0;
     548           0 :     double sum_out = 0.0;
     549           0 :     for( ulong i=0UL; i<FD_GUIH_NET_PROTO_CNT; i++ ) {
     550           0 :       sum_in  += gui->summary.ingress_ema[ i ];
     551           0 :       sum_out += gui->summary.egress_ema[ i ];
     552           0 :     }
     553             : 
     554           0 :     while( !fd_guih_rate_deque_empty( gui->summary.ingress_maxq ) && fd_guih_rate_deque_peek_head_const( gui->summary.ingress_maxq )->ts_nanos<now-FD_GUIH_NET_RATE_MAX_WINDOW_NS ) {
     555           0 :       fd_guih_rate_deque_pop_head( gui->summary.ingress_maxq );
     556           0 :     }
     557           0 :     while( !fd_guih_rate_deque_empty( gui->summary.ingress_maxq ) && fd_guih_rate_deque_peek_tail_const( gui->summary.ingress_maxq )->value<=sum_in ) {
     558           0 :       fd_guih_rate_deque_pop_tail( gui->summary.ingress_maxq );
     559           0 :     }
     560           0 :     if( FD_UNLIKELY( fd_guih_rate_deque_full( gui->summary.ingress_maxq ) ) ) {
     561           0 :       fd_guih_rate_deque_pop_tail( gui->summary.ingress_maxq );
     562           0 :     }
     563           0 :     fd_guih_rate_deque_push_tail( gui->summary.ingress_maxq, (fd_guih_rate_entry_t){ .ts_nanos=now, .value=sum_in } );
     564             : 
     565           0 :     while( !fd_guih_rate_deque_empty( gui->summary.egress_maxq ) && fd_guih_rate_deque_peek_head_const( gui->summary.egress_maxq )->ts_nanos<now-FD_GUIH_NET_RATE_MAX_WINDOW_NS ) {
     566           0 :       fd_guih_rate_deque_pop_head( gui->summary.egress_maxq );
     567           0 :     }
     568           0 :     while( !fd_guih_rate_deque_empty( gui->summary.egress_maxq ) && fd_guih_rate_deque_peek_tail_const( gui->summary.egress_maxq )->value<=sum_out ) {
     569           0 :       fd_guih_rate_deque_pop_tail( gui->summary.egress_maxq );
     570           0 :     }
     571           0 :     if( FD_UNLIKELY( fd_guih_rate_deque_full( gui->summary.egress_maxq ) ) ) {
     572           0 :       fd_guih_rate_deque_pop_tail( gui->summary.egress_maxq );
     573           0 :     }
     574           0 :     fd_guih_rate_deque_push_tail( gui->summary.egress_maxq, (fd_guih_rate_entry_t){ .ts_nanos=now, .value=sum_out } );
     575           0 :   }
     576             : 
     577           0 :   *prev = *cur;
     578           0 : }
     579             : 
     580             : /* Snapshot all of the data from metrics to construct a view of the
     581             :    transaction waterfall.
     582             : 
     583             :    Tiles are sampled in reverse pipeline order: this helps prevent data
     584             :    discrepancies where a later tile has "seen" more transactions than an
     585             :    earlier tile, which shouldn't typically happen. */
     586             : 
     587             : static void
     588             : fd_guih_txn_waterfall_snap( fd_guih_t *               gui,
     589           0 :                            fd_guih_txn_waterfall_t * cur ) {
     590           0 :   memset( cur, 0, sizeof(fd_guih_txn_waterfall_t) );
     591           0 :   fd_topo_t const * topo = gui->topo;
     592             : 
     593           0 :   for( ulong i=0UL; i<gui->summary.bank_tile_cnt; i++ ) {
     594           0 :     fd_topo_tile_t const * bank = &topo->tiles[ fd_topo_find_tile( topo, "bank", i ) ];
     595             : 
     596           0 :     volatile ulong const * bank_metrics = fd_metrics_tile( bank->metrics );
     597           0 :     cur->out.block_success += bank_metrics[ MIDX( COUNTER, BANK, TXN_EXECUTED_SUCCESS ) ];
     598             : 
     599           0 :     cur->out.block_fail +=
     600           0 :         bank_metrics[ MIDX( COUNTER, BANK, TXN_EXECUTED_FAILED ) ]
     601           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TXN_FEE_ONLY        ) ];
     602             : 
     603           0 :     cur->out.bank_invalid +=
     604           0 :         bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_ACCOUNT_UNINITIALIZED ) ]
     605           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_ACCOUNT_NOT_FOUND ) ]
     606           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_INVALID_ACCOUNT_OWNER ) ]
     607           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_INVALID_ACCOUNT_DATA ) ]
     608           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_INVALID_LOOKUP_INDEX  ) ];
     609             : 
     610           0 :     cur->out.bank_invalid +=
     611           0 :         bank_metrics[ MIDX( COUNTER, BANK, TXN_PROCESSING_FAILED ) ];
     612           0 :   }
     613             : 
     614           0 :   for( ulong i=0UL; i<gui->summary.execle_tile_cnt; i++ ) {
     615           0 :     fd_topo_tile_t const * execle = &topo->tiles[ fd_topo_find_tile( topo, "execle", i ) ];
     616             : 
     617           0 :     volatile ulong const * execle_metrics = fd_metrics_tile( execle->metrics );
     618             : 
     619           0 :     cur->out.block_success += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_LANDED_SUCCESS ) ];
     620           0 :     cur->out.block_fail    +=
     621           0 :         execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_LANDED_FEES_ONLY ) ]
     622           0 :       + execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_LANDED_FAILED ) ];
     623           0 :     cur->out.bank_invalid  += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_UNLANDED ) ];
     624             : 
     625           0 :     cur->out.bank_nonce_already_advanced += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_RESULT_NONCE_ALREADY_ADVANCED ) ];
     626           0 :     cur->out.bank_nonce_advance_failed   += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_RESULT_NONCE_ADVANCE_FAILED ) ];
     627           0 :     cur->out.bank_nonce_wrong_blockhash  += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_RESULT_NONCE_WRONG_BLOCKHASH ) ];
     628           0 :   }
     629             : 
     630           0 :   ulong pack_tile_idx = fd_topo_find_tile( topo, "pack", 0UL );
     631           0 :   if( pack_tile_idx!=ULONG_MAX ) {
     632           0 :     fd_topo_tile_t const * pack = &topo->tiles[ pack_tile_idx ];
     633           0 :     volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
     634             : 
     635           0 :     cur->out.pack_invalid_bundle =
     636           0 :         pack_metrics[ MIDX( COUNTER, PACK, TXN_PARTIAL_BUNDLE ) ]
     637           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTION_FAILED ) ]
     638           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_CREATION_FAILED ) ];
     639             : 
     640           0 :     cur->out.pack_invalid =
     641           0 :         pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_INSTR_ACCT_CNT ) ]
     642           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_NONCE_CONFLICT ) ]
     643           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_BUNDLE_BLACKLIST ) ]
     644           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_INVALID_NONCE ) ]
     645           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_WRITE_SYSVAR ) ]
     646           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_ESTIMATION_FAIL ) ]
     647           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_DUPLICATE_ACCOUNT ) ]
     648           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_TOO_MANY_ACCOUNTS ) ]
     649           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_TOO_LARGE ) ]
     650           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_ADDR_LUT ) ]
     651           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_UNAFFORDABLE ) ]
     652           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_DUPLICATE ) ]
     653           0 :       - pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTION_FAILED ) ]; /* so we don't double count this, since its already accounted for in invalid_bundle */
     654             : 
     655           0 :     cur->out.pack_expired = pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_EXPIRED ) ] +
     656           0 :                             pack_metrics[ MIDX( COUNTER, PACK, TXN_EXPIRED ) ] +
     657           0 :                             pack_metrics[ MIDX( COUNTER, PACK, TXN_DELETED ) ] +
     658           0 :                             pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_NONCE_PRIORITY ) ];
     659             : 
     660           0 :     cur->out.pack_already_executed = pack_metrics[ MIDX( COUNTER, PACK, TXN_ALREADY_EXECUTED ) ];
     661             : 
     662           0 :     cur->out.pack_leader_slow = pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_PRIORITY ) ];
     663             : 
     664           0 :     cur->out.pack_wait_full =
     665           0 :         pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_DROPPED ) ];
     666             : 
     667           0 :     cur->out.pack_retained = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE ) ];
     668             : 
     669           0 :     ulong inserted_to_extra = pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_INSERTED ) ];
     670           0 :     ulong inserted_from_extra = pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_RETRIEVED ) ]
     671           0 :                                 + pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_DROPPED ) ];
     672           0 :     cur->out.pack_retained += fd_ulong_if( inserted_to_extra>=inserted_from_extra, inserted_to_extra-inserted_from_extra, 0UL );
     673             : 
     674           0 :     cur->in.pack_cranked =
     675           0 :         pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTED ) ]
     676           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTION_FAILED ) ]
     677           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_CREATION_FAILED ) ];
     678           0 :   }
     679             : 
     680           0 :   for( ulong i=0UL; i<gui->summary.resolh_tile_cnt; i++ ) {
     681           0 :     fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolh", i ) ];
     682           0 :     volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
     683             : 
     684           0 :     cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLH, TXN_NO_BANK ) ];
     685           0 :     cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLH, BLOCKHASH_EXPIRED ) ]
     686           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, TXN_BUNDLE_PEER_FAILED  ) ];
     687           0 :     cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
     688           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
     689           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
     690           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
     691           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
     692           0 :     cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_OVERRUN ) ];
     693             : 
     694           0 :     ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_INSERTED ) ];
     695           0 :     ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_OVERRUN ) ]
     696           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_PUBLISHED ) ]
     697           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_REMOVED ) ];
     698           0 :     cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
     699           0 :   }
     700             : 
     701           0 :   for( ulong i=0UL; i<gui->summary.resolv_tile_cnt; i++ ) {
     702           0 :     fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolv", i ) ];
     703           0 :     volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
     704             : 
     705           0 :     cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_NO_BANK ) ];
     706           0 :     cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLV, BLOCKHASH_EXPIRED ) ]
     707           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_BUNDLE_PEER_FAILED  ) ];
     708           0 :     cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
     709           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
     710           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
     711           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
     712           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
     713           0 :     cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ];
     714             : 
     715           0 :     ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_INSERTED ) ];
     716           0 :     ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ]
     717           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_PUBLISHED ) ]
     718           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_REMOVED ) ];
     719           0 :     cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
     720           0 :   }
     721             : 
     722           0 :   ulong dedup_tile_idx = fd_topo_find_tile( topo, "dedup", 0UL );
     723           0 :   if( FD_UNLIKELY( dedup_tile_idx!=ULONG_MAX ) ) {
     724           0 :     fd_topo_tile_t const * dedup = &topo->tiles[ dedup_tile_idx ];
     725           0 :     volatile ulong const * dedup_metrics = fd_metrics_tile( dedup->metrics );
     726             : 
     727           0 :     cur->out.dedup_duplicate = dedup_metrics[ MIDX( COUNTER, DEDUP, TXN_RESULT_DEDUP_FAILURE ) ]
     728           0 :                              + dedup_metrics[ MIDX( COUNTER, DEDUP, TXN_RESULT_BUNDLE_PEER_FAILURE ) ];
     729           0 :   }
     730             : 
     731           0 :   for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
     732           0 :     fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
     733           0 :     volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
     734             : 
     735           0 :     for( ulong j=0UL; j<gui->summary.quic_tile_cnt; j++ ) {
     736             :       /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this verify tile. */
     737           0 :       cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_POLLING_OVERRUN_OFF ] / gui->summary.verify_tile_cnt;
     738           0 :       cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_READING_OVERRUN_OFF ];
     739           0 :     }
     740             : 
     741           0 :     cur->out.verify_failed    += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_VERIFY_FAILURE ) ] +
     742           0 :                                  verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_BUNDLE_PEER_FAILURE ) ];
     743           0 :     cur->out.verify_parse     += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_PARSE_FAILURE ) ];
     744           0 :     cur->out.verify_duplicate += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_DEDUP_FAILURE ) ];
     745           0 :   }
     746             : 
     747           0 :   for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
     748           0 :     fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
     749           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
     750             : 
     751           0 :     cur->out.tpu_udp_invalid  += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_UNDERSIZE   ) ];
     752           0 :     cur->out.tpu_udp_invalid  += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_OVERSIZE    ) ];
     753           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_UNDERSIZE          ) ];
     754           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_OVERSIZE           ) ];
     755           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, TXN_OVERSIZE           ) ];
     756           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_CRYPTO_FAILED      ) ];
     757           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NO_CONN            ) ];
     758           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_SRC_INVALID        ) ];
     759           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NET_HEADER_INVALID ) ];
     760           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_HEADER_INVALID     ) ];
     761           0 :     cur->out.quic_abandoned   += quic_metrics[ MIDX( COUNTER, QUIC, TXN_ABANDONED          ) ];
     762           0 :     cur->out.quic_frag_drop   += quic_metrics[ MIDX( COUNTER, QUIC, TXN_OVERRUN            ) ];
     763             : 
     764           0 :     for( ulong j=0UL; j<gui->summary.sock_tile_cnt+gui->summary.net_tile_cnt+gui->summary.mlx5_tile_cnt; j++ ) {
     765             :       /* TODO: Not precise... net frags that were skipped might not have been destined for QUIC tile */
     766             :       /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this QUIC tile */
     767           0 :       cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_POLLING_OVERRUN_OFF ] / gui->summary.quic_tile_cnt;
     768           0 :       cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_READING_OVERRUN_OFF ];
     769           0 :     }
     770           0 :   }
     771             : 
     772           0 :   for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
     773           0 :     fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
     774           0 :     volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
     775             : 
     776           0 :     cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_RING_FULL ) ];
     777           0 :     cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_OTHER_DROPPED ) ];
     778           0 :     cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_FILL_RING_EMPTY ) ];
     779           0 :   }
     780           0 :   ulong bundle_txns_received = 0UL;
     781           0 :   ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
     782           0 :   if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
     783           0 :     fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
     784           0 :     volatile ulong const * bundle_metrics = fd_metrics_tile( bundle->metrics );
     785             : 
     786           0 :     bundle_txns_received = bundle_metrics[ MIDX( COUNTER, BUNDLE, TXN_RX ) ];
     787           0 :   }
     788             : 
     789           0 :   if( dedup_tile_idx!=ULONG_MAX ) {
     790           0 :     fd_topo_tile_t const * dedup = &topo->tiles[ dedup_tile_idx ];
     791           0 :     volatile ulong const * dedup_metrics = fd_metrics_tile( dedup->metrics );
     792           0 :     cur->in.gossip = dedup_metrics[ MIDX( COUNTER, DEDUP, VOTE_GOSSIP_RX ) ];
     793           0 :   }
     794             : 
     795           0 :   cur->in.quic     = cur->out.tpu_quic_invalid +
     796           0 :                      cur->out.quic_overrun +
     797           0 :                      cur->out.quic_frag_drop +
     798           0 :                      cur->out.quic_abandoned +
     799           0 :                      cur->out.net_overrun;
     800           0 :   cur->in.udp      = cur->out.tpu_udp_invalid;
     801           0 :   cur->in.block_engine = bundle_txns_received;
     802           0 :   for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
     803           0 :     fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
     804           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
     805             : 
     806           0 :     cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_QUIC_FAST ) ];
     807           0 :     cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_QUIC_FRAG ) ];
     808           0 :     cur->in.udp  += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_UDP       ) ];
     809           0 :   }
     810           0 : }
     811             : 
     812             : static void
     813             : fd_guih_tile_stats_snap( fd_guih_t *                     gui,
     814             :                         fd_guih_txn_waterfall_t const * waterfall,
     815             :                         fd_guih_tile_stats_t *          stats,
     816           0 :                         long                           now ) {
     817           0 :   memset( stats, 0, sizeof(fd_guih_tile_stats_t) );
     818           0 :   fd_topo_t const * topo = gui->topo;
     819             : 
     820           0 :   stats->sample_time_nanos = now;
     821             : 
     822           0 :   for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
     823           0 :     fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
     824           0 :     volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
     825             : 
     826           0 :     stats->net_in_rx_bytes  += net_metrics[ MIDX( COUNTER, NET, PKT_RX_BYTES ) ];
     827           0 :     stats->net_out_tx_bytes += net_metrics[ MIDX( COUNTER, NET, PKT_TX_BYTES ) ];
     828           0 :   }
     829             : 
     830           0 :   for( ulong i=0UL; i<gui->summary.sock_tile_cnt; i++ ) {
     831           0 :     fd_topo_tile_t const * sock = &topo->tiles[ fd_topo_find_tile( topo, "sock", i ) ];
     832           0 :     volatile ulong * sock_metrics = fd_metrics_tile( sock->metrics );
     833             : 
     834           0 :     stats->net_in_rx_bytes  += sock_metrics[ MIDX( COUNTER, SOCK, PKT_RX_BYTES ) ];
     835           0 :     stats->net_out_tx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, PKT_TX_BYTES ) ];
     836           0 :   }
     837             : 
     838           0 :   for( ulong i=0UL; i<gui->summary.mlx5_tile_cnt; i++ ) {
     839           0 :     fd_topo_tile_t const * mlx5 = &topo->tiles[ fd_topo_find_tile( topo, "mlx5", i ) ];
     840           0 :     volatile ulong * mlx5_metrics = fd_metrics_tile( mlx5->metrics );
     841             : 
     842           0 :     stats->net_in_rx_bytes  += mlx5_metrics[ MIDX( COUNTER, MLX5, PKT_RX_BYTES ) ];
     843           0 :     stats->net_out_tx_bytes += mlx5_metrics[ MIDX( COUNTER, MLX5, PKT_TX_BYTES ) ];
     844           0 :   }
     845             : 
     846           0 :   for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
     847           0 :     fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
     848           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
     849             : 
     850           0 :     stats->quic_conn_cnt += quic_metrics[ MIDX( GAUGE, QUIC, CONN_IN_USE ) ];
     851           0 :   }
     852             : 
     853           0 :   ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
     854           0 :   if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
     855           0 :     fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
     856           0 :     volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
     857           0 :     stats->bundle_rtt_smoothed_nanos = bundle_metrics[ MIDX( GAUGE, BUNDLE, RTT_SMOOTHED_NANOS ) ];
     858             : 
     859           0 :     fd_histf_new( &stats->bundle_rx_delay_hist, FD_MHIST_MIN( BUNDLE, MESSAGE_RX_DELAY_NANOS ), FD_MHIST_MAX( BUNDLE, MESSAGE_RX_DELAY_NANOS ) );
     860           0 :     stats->bundle_rx_delay_hist.sum = bundle_metrics[ MIDX( HISTOGRAM, BUNDLE, MESSAGE_RX_DELAY_NANOS ) + FD_HISTF_BUCKET_CNT ];
     861           0 :     for( ulong b=0; b<FD_HISTF_BUCKET_CNT; b++ ) stats->bundle_rx_delay_hist.counts[ b ] = bundle_metrics[ MIDX( HISTOGRAM, BUNDLE, MESSAGE_RX_DELAY_NANOS ) + b ];
     862           0 :   }
     863             : 
     864           0 :   stats->verify_drop_cnt = waterfall->out.verify_duplicate +
     865           0 :                            waterfall->out.verify_parse +
     866           0 :                            waterfall->out.verify_failed;
     867           0 :   stats->verify_total_cnt = waterfall->in.gossip +
     868           0 :                             waterfall->in.quic +
     869           0 :                             waterfall->in.udp -
     870           0 :                             waterfall->out.net_overrun -
     871           0 :                             waterfall->out.tpu_quic_invalid -
     872           0 :                             waterfall->out.tpu_udp_invalid -
     873           0 :                             waterfall->out.quic_abandoned -
     874           0 :                             waterfall->out.quic_frag_drop -
     875           0 :                             waterfall->out.quic_overrun -
     876           0 :                             waterfall->out.verify_overrun;
     877           0 :   stats->dedup_drop_cnt = waterfall->out.dedup_duplicate;
     878           0 :   stats->dedup_total_cnt = stats->verify_total_cnt -
     879           0 :                            waterfall->out.verify_duplicate -
     880           0 :                             waterfall->out.verify_parse -
     881           0 :                             waterfall->out.verify_failed;
     882             : 
     883           0 :   ulong pack_tile_idx = fd_topo_find_tile( topo, "pack", 0UL );
     884           0 :   if( pack_tile_idx!=ULONG_MAX ) {
     885           0 :     fd_topo_tile_t const * pack  = &topo->tiles[ pack_tile_idx ];
     886           0 :     volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
     887           0 :     stats->pack_buffer_cnt      = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE ) ];
     888           0 :     stats->pack_buffer_capacity = pack->pack.max_pending_transactions;
     889           0 :   }
     890             : 
     891           0 :   stats->bank_txn_exec_cnt = waterfall->out.block_fail + waterfall->out.block_success;
     892           0 : }
     893             : 
     894             : static inline int
     895           0 : fd_guih_ephemeral_slots_contains( fd_guih_ephemeral_slot_t * slots, ulong slots_sz, ulong slot ) {
     896           0 :   for( ulong i=0UL; i<slots_sz; i++ ) {
     897           0 :     if( FD_UNLIKELY( slots[ i ].slot==ULONG_MAX ) ) break;
     898           0 :     if( FD_UNLIKELY( slots[ i ].slot==slot ) ) return 1;
     899           0 :   }
     900           0 :   return 0;
     901           0 : }
     902             : 
     903             : #define SORT_NAME fd_guih_ephemeral_slot_sort
     904           0 : #define SORT_KEY_T fd_guih_ephemeral_slot_t
     905           0 : #define SORT_BEFORE(a,b) fd_int_if( (a).slot==ULONG_MAX, 0, fd_int_if( (b).slot==ULONG_MAX, 1, fd_int_if( (a).slot==(b).slot, (a).timestamp_arrival_nanos>(b).timestamp_arrival_nanos, (a).slot>(b).slot ) ) )
     906             : #include "../../util/tmpl/fd_sort.c"
     907             : 
     908             : static inline void
     909           0 : fd_guih_try_insert_ephemeral_slot( fd_guih_ephemeral_slot_t * slots, ulong slots_sz, ulong slot, long now ) {
     910           0 :   int already_present = 0;
     911           0 :   for( ulong i=0UL; i<slots_sz; i++ ) {
     912             :     /* evict any slots older than 4.8 seconds */
     913           0 :     if( FD_UNLIKELY( slots[ i ].slot!=ULONG_MAX && now-slots[ i ].timestamp_arrival_nanos>4800000000L ) ) {
     914           0 :       slots[ i ].slot = ULONG_MAX;
     915           0 :       continue;
     916           0 :     }
     917             : 
     918             :     /* if we've already seen this slot, just update the timestamp */
     919           0 :     if( FD_UNLIKELY( slots[ i ].slot==slot ) ) {
     920           0 :       slots[ i ].timestamp_arrival_nanos = now;
     921           0 :       already_present = 1;
     922           0 :     }
     923           0 :   }
     924           0 :   if( FD_LIKELY( already_present ) ) return;
     925             : 
     926             :   /* Insert the new slot number, evicting a smaller slot if necessary */
     927           0 :   slots[ slots_sz ].timestamp_arrival_nanos = now;
     928           0 :   slots[ slots_sz ].slot = slot;
     929           0 :   fd_guih_ephemeral_slot_sort_insert( slots, slots_sz+1UL );
     930           0 : }
     931             : 
     932             : static inline void
     933           0 : fd_guih_try_insert_run_length_slot( ulong * slots, ulong capacity, ulong * slots_sz, ulong slot ) {
     934             :   /* catch up history is run-length encoded */
     935           0 :   ulong range_idx = fd_sort_up_ulong_split( slots, *slots_sz, slot );
     936           0 :   if( FD_UNLIKELY( range_idx<(*slots_sz)-1UL              && range_idx%2UL==0UL && slots[ range_idx ]<=slot && slots[ range_idx+1UL ]>=slot ) ) return;
     937           0 :   if( FD_UNLIKELY( range_idx<(*slots_sz) && range_idx>0UL && range_idx%2UL==1UL && slots[ range_idx-1UL ]<=slot && slots[ range_idx ]>=slot ) ) return;
     938             : 
     939           0 :   slots[ (*slots_sz)++ ] = slot;
     940           0 :   slots[ (*slots_sz)++ ] = slot;
     941             : 
     942           0 :   fd_sort_up_ulong_insert( slots, (*slots_sz) );
     943             : 
     944             :   /* colesce ranges */
     945           0 :   ulong removed = 0UL;
     946           0 :   for( ulong i=1UL; i<(*slots_sz)-1UL; i+=2 ) {
     947           0 :     if( FD_UNLIKELY( slots[ i ]+1UL==slots[ i+1UL ] ) ) {
     948           0 :       slots[ i ]     = ULONG_MAX;
     949           0 :       slots[ i+1UL ] = ULONG_MAX;
     950           0 :       removed += 2;
     951           0 :     }
     952           0 :   }
     953             : 
     954           0 :   if( FD_UNLIKELY( (*slots_sz)>=removed+capacity-2UL && (*slots_sz)>=4UL ) ) {
     955             :     /* We are at capacity, start coalescing earlier intervals. */
     956           0 :     slots[ 1 ] = ULONG_MAX;
     957           0 :     slots[ 2 ] = ULONG_MAX;
     958           0 :     removed += 2;
     959           0 :   }
     960             : 
     961           0 :   fd_sort_up_ulong_insert( slots, (*slots_sz) );
     962           0 :   (*slots_sz) -= removed;
     963           0 : }
     964             : 
     965             : void
     966           0 : fd_guih_handle_repair_slot( fd_guih_t * gui, ulong slot, long now ) {
     967           0 :   int was_sent = fd_guih_ephemeral_slots_contains( gui->summary.slots_max_repair, FD_GUIH_REPAIR_SLOT_HISTORY_SZ, slot );
     968           0 :   fd_guih_try_insert_ephemeral_slot( gui->summary.slots_max_repair, FD_GUIH_REPAIR_SLOT_HISTORY_SZ, slot, now );
     969             : 
     970           0 :   if( FD_UNLIKELY( !was_sent && slot!=gui->summary.slot_repair ) ) {
     971           0 :     gui->summary.slot_repair = slot;
     972             : 
     973           0 :     fd_guih_printf_repair_slot( gui );
     974           0 :     fd_http_server_ws_broadcast( gui->http );
     975             : 
     976           0 :     if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) fd_guih_try_insert_run_length_slot( gui->summary.catch_up_repair, FD_GUIH_REPAIR_CATCH_UP_HISTORY_SZ, &gui->summary.catch_up_repair_sz, slot );
     977           0 :   }
     978           0 : }
     979             : 
     980             : int
     981           0 : fd_guih_poll( fd_guih_t * gui, long now ) {
     982           0 :   if( FD_LIKELY( now>gui->next_sample_400millis ) ) {
     983           0 :     fd_guih_estimated_tps_snap( gui );
     984           0 :     fd_guih_printf_estimated_tps( gui );
     985           0 :     fd_http_server_ws_broadcast( gui->http );
     986             : 
     987           0 :     gui->next_sample_400millis += 400L*1000L*1000L;
     988           0 :     return 1;
     989           0 :   }
     990             : 
     991           0 :   if( FD_LIKELY( now>gui->next_sample_100millis ) ) {
     992           0 :     fd_guih_txn_waterfall_snap( gui, gui->summary.txn_waterfall_current );
     993           0 :     fd_guih_printf_live_txn_waterfall( gui, gui->summary.txn_waterfall_reference, gui->summary.txn_waterfall_current, 0UL /* TODO: REAL NEXT LEADER SLOT */ );
     994           0 :     fd_http_server_ws_broadcast( gui->http );
     995             : 
     996           0 :     fd_guih_network_stats_snap( gui, gui->summary.network_stats_current );
     997           0 :     fd_guih_network_rate_max_update( gui, now );
     998           0 :     fd_guih_printf_live_network_metrics( gui, gui->summary.network_stats_current );
     999           0 :     fd_http_server_ws_broadcast( gui->http );
    1000             : 
    1001           0 :     *gui->summary.tile_stats_reference = *gui->summary.tile_stats_current;
    1002           0 :     fd_guih_tile_stats_snap( gui, gui->summary.txn_waterfall_current, gui->summary.tile_stats_current, now );
    1003           0 :     fd_guih_printf_live_tile_stats( gui, gui->summary.tile_stats_reference, gui->summary.tile_stats_current );
    1004           0 :     fd_http_server_ws_broadcast( gui->http );
    1005             : 
    1006           0 :     ulong bundle_tile_idx = fd_topo_find_tile( gui->topo, "bundle", 0UL );
    1007           0 :     if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
    1008           0 :       volatile ulong const * bundle_metrics = fd_metrics_tile( gui->topo->tiles[ bundle_tile_idx ].metrics );
    1009           0 :       int cur_state = (int)bundle_metrics[ MIDX( GAUGE, BUNDLE, STATE ) ];
    1010           0 :       if( FD_UNLIKELY( cur_state != gui->block_engine.status ) ) {
    1011           0 :         gui->block_engine.status = cur_state;
    1012           0 :         fd_guih_printf_block_engine( gui );
    1013           0 :         fd_http_server_ws_broadcast( gui->http );
    1014           0 :       }
    1015           0 :     }
    1016             : 
    1017           0 :     fd_guih_printf_health( gui );
    1018           0 :     fd_http_server_ws_broadcast( gui->http );
    1019             : 
    1020           0 :     gui->next_sample_100millis += 100L*1000L*1000L;
    1021           0 :     return 1;
    1022           0 :   }
    1023             : 
    1024           0 :   if( FD_LIKELY( now>gui->next_sample_50millis ) ) {
    1025             :     /* We get the repair slot from the sampled metric after catching up
    1026             :        and from incoming shred data before catchup. This makes the
    1027             :        catchup progress bar look complete while also keeping the
    1028             :        overview slots vis correct.  TODO: do this properly using frags
    1029             :        sent over a link */
    1030           0 :     if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
    1031           0 :       fd_topo_tile_t const * repair = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "repair", 0UL ) ];
    1032           0 :       volatile ulong const * repair_metrics = fd_metrics_tile( repair->metrics );
    1033           0 :       ulong slot = repair_metrics[ MIDX( GAUGE, REPAIR, SLOT_HIGHEST_REPAIRED ) ];
    1034           0 :       fd_guih_handle_repair_slot( gui, slot, now );
    1035           0 :     }
    1036             : 
    1037           0 :     gui->next_sample_50millis += 50L*1000L*1000L;
    1038           0 :     return 1;
    1039           0 :   }
    1040             : 
    1041           0 :   if( FD_LIKELY( now>gui->next_sample_25millis ) ) {
    1042           0 :     fd_guih_tile_timers_snap( gui );
    1043             : 
    1044           0 :     fd_guih_printf_live_tile_timers( gui );
    1045           0 :     fd_http_server_ws_broadcast( gui->http );
    1046             : 
    1047           0 :     fd_guih_printf_live_tile_metrics( gui );
    1048           0 :     fd_http_server_ws_broadcast( gui->http );
    1049             : 
    1050           0 :     gui->next_sample_25millis += (long)(25*1000L*1000L);
    1051           0 :     return 1;
    1052           0 :   }
    1053             : 
    1054             : 
    1055           0 :   if( FD_LIKELY( now>gui->next_sample_10millis ) ) {
    1056           0 :     fd_guih_scheduler_counts_snap( gui, now );
    1057             : 
    1058           0 :     fd_guih_printf_server_time_nanos( gui, now );
    1059           0 :     fd_http_server_ws_broadcast( gui->http );
    1060             : 
    1061           0 :     gui->next_sample_10millis += 10L*1000L*1000L;
    1062           0 :     return 1;
    1063           0 :   }
    1064             : 
    1065           0 :   return 0;
    1066           0 : }
    1067             : 
    1068             : FD_STATIC_ASSERT( sizeof(fd_guih_gossip_peer_t)==(60UL+12UL*6UL), gossip_peer_wire_layout );
    1069             : 
    1070             : static void
    1071             : fd_guih_handle_gossip_update( fd_guih_t *   gui,
    1072           0 :                               uchar const * msg ) {
    1073             :   /* `gui->gossip.peer_cnt` is guaranteed to be in [0, FD_GUIH_MAX_PEER_CNT], because
    1074             :   `peer_cnt` is FD_TEST-ed to be less than or equal FD_GUIH_MAX_PEER_CNT.
    1075             :   For every new peer that is added an existing peer will be removed or was still free.
    1076             :   And adding a new peer is done at most `peer_cnt` times. */
    1077           0 :   ulong peer_cnt = FD_LOAD( ulong, msg );
    1078             : 
    1079           0 :   FD_TEST( peer_cnt<=FD_GUIH_MAX_PEER_CNT );
    1080             : 
    1081           0 :   ulong added_cnt = 0UL;
    1082           0 :   ulong added[ FD_GUIH_MAX_PEER_CNT ] = {0};
    1083             : 
    1084           0 :   ulong update_cnt = 0UL;
    1085           0 :   ulong updated[ FD_GUIH_MAX_PEER_CNT ] = {0};
    1086             : 
    1087           0 :   ulong removed_cnt = 0UL;
    1088           0 :   fd_pubkey_t removed[ FD_GUIH_MAX_PEER_CNT ] = {0};
    1089             : 
    1090           0 :   fd_guih_gossip_peer_t const * peer = (fd_guih_gossip_peer_t const *)( msg + sizeof(ulong) );
    1091           0 :   for( ulong i=0UL; i<gui->gossip.peer_cnt; i++ ) {
    1092           0 :     int found = 0;
    1093           0 :     for( ulong j=0UL; j<peer_cnt; j++ ) {
    1094           0 :       if( FD_UNLIKELY( !memcmp( gui->gossip.peers[ i ].pubkey, peer[ j ].pubkey, 32UL ) ) ) {
    1095           0 :         found = 1;
    1096           0 :         break;
    1097           0 :       }
    1098           0 :     }
    1099             : 
    1100           0 :     if( FD_UNLIKELY( !found ) ) {
    1101           0 :       fd_memcpy( removed[ removed_cnt++ ].uc, gui->gossip.peers[ i ].pubkey->uc, 32UL );
    1102           0 :       if( FD_LIKELY( i+1UL!=gui->gossip.peer_cnt ) ) {
    1103           0 :         gui->gossip.peers[ i ] = gui->gossip.peers[ gui->gossip.peer_cnt-1UL ];
    1104           0 :         i--;
    1105           0 :       }
    1106           0 :       gui->gossip.peer_cnt--;
    1107           0 :     }
    1108           0 :   }
    1109             : 
    1110           0 :   ulong before_peer_cnt = gui->gossip.peer_cnt;
    1111           0 :   for( ulong i=0UL; i<peer_cnt; i++ ) {
    1112           0 :     fd_guih_gossip_peer_t const * p = &peer[ i ];
    1113             : 
    1114           0 :     int found = 0;
    1115           0 :     ulong found_idx = 0;
    1116           0 :     for( ulong j=0UL; j<gui->gossip.peer_cnt; j++ ) {
    1117           0 :       if( FD_UNLIKELY( !memcmp( gui->gossip.peers[ j ].pubkey, p->pubkey, 32UL ) ) ) {
    1118           0 :         found_idx = j;
    1119           0 :         found = 1;
    1120           0 :         break;
    1121           0 :       }
    1122           0 :     }
    1123             : 
    1124           0 :     if( FD_UNLIKELY( !found ) ) {
    1125           0 :       gui->gossip.peers[ gui->gossip.peer_cnt++ ] = *p;
    1126           0 :     } else {
    1127           0 :       fd_guih_gossip_peer_t * existing = &gui->gossip.peers[ found_idx ];
    1128             : 
    1129             :       /* `wallclock` is intentionally excluded from the update check. */
    1130           0 :       int peer_updated = existing->shred_version!=p->shred_version ||
    1131           0 :                          existing->has_version!=p->has_version;
    1132             : 
    1133           0 :       if( FD_LIKELY( !peer_updated && existing->has_version ) ) {
    1134           0 :         peer_updated = existing->version.major!=p->version.major ||
    1135           0 :                         existing->version.minor!=p->version.minor ||
    1136           0 :                         existing->version.patch!=p->version.patch ||
    1137           0 :                         existing->version.has_commit!=p->version.has_commit ||
    1138           0 :                         (existing->version.has_commit && existing->version.commit!=p->version.commit) ||
    1139           0 :                         existing->version.feature_set!=p->version.feature_set ||
    1140           0 :                         existing->version.client_id!=p->version.client_id;
    1141           0 :       }
    1142             : 
    1143           0 :       if( FD_LIKELY( !peer_updated ) ) {
    1144           0 :         for( ulong j=0UL; j<12UL; j++ ) {
    1145           0 :           peer_updated = existing->sockets[ j ].ipv4!=p->sockets[ j ].ipv4 ||
    1146           0 :                           existing->sockets[ j ].port!=p->sockets[ j ].port;
    1147           0 :           if( FD_LIKELY( peer_updated ) ) break;
    1148           0 :         }
    1149           0 :       }
    1150             : 
    1151           0 :       if( FD_UNLIKELY( peer_updated ) ) {
    1152           0 :         updated[ update_cnt++ ] = found_idx;
    1153           0 :         *existing = *p;
    1154           0 :       }
    1155           0 :     }
    1156           0 :   }
    1157             : 
    1158           0 :   added_cnt = gui->gossip.peer_cnt - before_peer_cnt;
    1159           0 :   for( ulong i=before_peer_cnt; i<gui->gossip.peer_cnt; i++ ) added[ i-before_peer_cnt ] = i;
    1160             : 
    1161           0 :   fd_guih_printf_peers_gossip_update( gui, updated, update_cnt, removed, removed_cnt, added, added_cnt );
    1162           0 :   fd_http_server_ws_broadcast( gui->http );
    1163           0 : }
    1164             : 
    1165             : FD_STATIC_ASSERT( sizeof(fd_guih_vote_account_t)==112UL, vote_account_wire_layout );
    1166             : 
    1167             : static void
    1168             : fd_guih_handle_vote_account_update( fd_guih_t *   gui,
    1169           0 :                                     uchar const * msg ) {
    1170             :   /* See fd_guih_handle_gossip_update for why `gui->vote_account.vote_account_cnt`
    1171             :   is guaranteed to be in [0, FD_GUIH_MAX_PEER_CNT]. */
    1172           0 :   ulong peer_cnt = FD_LOAD( ulong, msg );
    1173             : 
    1174           0 :   FD_TEST( peer_cnt<=FD_GUIH_MAX_PEER_CNT );
    1175             : 
    1176           0 :   ulong added_cnt = 0UL;
    1177           0 :   ulong added[ FD_GUIH_MAX_PEER_CNT ] = {0};
    1178             : 
    1179           0 :   ulong update_cnt = 0UL;
    1180           0 :   ulong updated[ FD_GUIH_MAX_PEER_CNT ] = {0};
    1181             : 
    1182           0 :   ulong removed_cnt = 0UL;
    1183           0 :   fd_pubkey_t removed[ FD_GUIH_MAX_PEER_CNT ] = {0};
    1184             : 
    1185           0 :   fd_guih_vote_account_t const * acct = (fd_guih_vote_account_t const *)( msg + sizeof(ulong) );
    1186           0 :   for( ulong i=0UL; i<gui->vote_account.vote_account_cnt; i++ ) {
    1187           0 :     int found = 0;
    1188           0 :     for( ulong j=0UL; j<peer_cnt; j++ ) {
    1189           0 :       if( FD_UNLIKELY( !memcmp( gui->vote_account.vote_accounts[ i ].vote_account, acct[ j ].vote_account, 32UL ) ) ) {
    1190           0 :         found = 1;
    1191           0 :         break;
    1192           0 :       }
    1193           0 :     }
    1194             : 
    1195           0 :     if( FD_UNLIKELY( !found ) ) {
    1196           0 :       fd_memcpy( removed[ removed_cnt++ ].uc, gui->vote_account.vote_accounts[ i ].vote_account->uc, 32UL );
    1197           0 :       if( FD_LIKELY( i+1UL!=gui->vote_account.vote_account_cnt ) ) {
    1198           0 :         gui->vote_account.vote_accounts[ i ] = gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt-1UL ];
    1199           0 :         i--;
    1200           0 :       }
    1201           0 :       gui->vote_account.vote_account_cnt--;
    1202           0 :     }
    1203           0 :   }
    1204             : 
    1205           0 :   ulong before_peer_cnt = gui->vote_account.vote_account_cnt;
    1206           0 :   for( ulong i=0UL; i<peer_cnt; i++ ) {
    1207           0 :     fd_guih_vote_account_t const * v = &acct[ i ];
    1208             : 
    1209           0 :     int found = 0;
    1210           0 :     ulong found_idx = 0;
    1211           0 :     for( ulong j=0UL; j<gui->vote_account.vote_account_cnt; j++ ) {
    1212           0 :       if( FD_UNLIKELY( !memcmp( gui->vote_account.vote_accounts[ j ].vote_account, v->vote_account, 32UL ) ) ) {
    1213           0 :         found_idx = j;
    1214           0 :         found = 1;
    1215           0 :         break;
    1216           0 :       }
    1217           0 :     }
    1218             : 
    1219           0 :     if( FD_UNLIKELY( !found ) ) {
    1220           0 :       gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt++ ] = *v;
    1221           0 :     } else {
    1222           0 :       fd_guih_vote_account_t * existing = &gui->vote_account.vote_accounts[ found_idx ];
    1223             : 
    1224             :       /* `last_vote`, `root_slot` and `epoch_credits` are intentionally
    1225             :          excluded from the update check. */
    1226           0 :       int peer_updated =
    1227           0 :         memcmp( existing->pubkey->uc, v->pubkey->uc, 32UL ) ||
    1228           0 :         existing->activated_stake != v->activated_stake ||
    1229           0 :         existing->commission      != v->commission ||
    1230           0 :         existing->delinquent      != v->delinquent;
    1231             : 
    1232           0 :       if( FD_UNLIKELY( peer_updated ) ) {
    1233           0 :         updated[ update_cnt++ ] = found_idx;
    1234           0 :         *existing = *v;
    1235           0 :       }
    1236           0 :     }
    1237           0 :   }
    1238             : 
    1239           0 :   added_cnt = gui->vote_account.vote_account_cnt - before_peer_cnt;
    1240           0 :   for( ulong i=before_peer_cnt; i<gui->vote_account.vote_account_cnt; i++ ) added[ i-before_peer_cnt ] = i;
    1241             : 
    1242           0 :   fd_guih_printf_peers_vote_account_update( gui, updated, update_cnt, removed, removed_cnt, added, added_cnt );
    1243           0 :   fd_http_server_ws_broadcast( gui->http );
    1244           0 : }
    1245             : 
    1246             : FD_STATIC_ASSERT( sizeof(fd_guih_validator_info_t)==608UL, validator_info_wire_layout );
    1247             : 
    1248             : static void
    1249             : fd_guih_handle_validator_info_update( fd_guih_t *   gui,
    1250           0 :                                       uchar const * msg ) {
    1251           0 :   if( FD_UNLIKELY( gui->validator_info.info_cnt == FD_GUIH_MAX_PEER_CNT ) ) {
    1252           0 :     FD_LOG_DEBUG(("validator info cnt exceeds 108000 %lu, ignoring additional entries", gui->validator_info.info_cnt ));
    1253           0 :     return;
    1254           0 :   }
    1255             : 
    1256           0 :   ulong added_cnt = 0UL;
    1257           0 :   ulong added[ 1 ] = {0};
    1258             : 
    1259           0 :   ulong update_cnt = 0UL;
    1260           0 :   ulong updated[ 1 ] = {0};
    1261             : 
    1262           0 :   ulong removed_cnt = 0UL;
    1263             :   /* Unlike gossip or vote account updates, validator info messages come
    1264             :      in as info is discovered, and may contain as little as 1 validator
    1265             :      per message.  Therefore, it doesn't make sense to use the remove
    1266             :      mechanism.  */
    1267             : 
    1268             : 
    1269           0 :   fd_guih_validator_info_t info = *(fd_guih_validator_info_t const *)msg;
    1270           0 :   info.name    [ 63  ] = '\0';
    1271           0 :   info.website [ 127 ] = '\0';
    1272           0 :   info.details [ 255 ] = '\0';
    1273           0 :   info.icon_uri[ 127 ] = '\0';
    1274             : 
    1275           0 :   ulong before_peer_cnt = gui->validator_info.info_cnt;
    1276           0 :   int found = 0;
    1277           0 :   ulong found_idx = 0;
    1278           0 :   for( ulong j=0UL; j<gui->validator_info.info_cnt; j++ ) {
    1279           0 :     if( FD_UNLIKELY( !memcmp( gui->validator_info.info[ j ].pubkey, info.pubkey->uc, 32UL ) ) ) {
    1280           0 :       found_idx = j;
    1281           0 :       found = 1;
    1282           0 :       break;
    1283           0 :     }
    1284           0 :   }
    1285             : 
    1286           0 :   if( FD_UNLIKELY( !found ) ) {
    1287           0 :     gui->validator_info.info[ gui->validator_info.info_cnt++ ] = info;
    1288           0 :   } else {
    1289           0 :     fd_guih_validator_info_t * existing = &gui->validator_info.info[ found_idx ];
    1290             : 
    1291           0 :     int peer_updated =
    1292           0 :       memcmp( existing->pubkey->uc, info.pubkey->uc, 32UL ) ||
    1293           0 :       strcmp( existing->name,     info.name     ) ||
    1294           0 :       strcmp( existing->website,  info.website  ) ||
    1295           0 :       strcmp( existing->details,  info.details  ) ||
    1296           0 :       strcmp( existing->icon_uri, info.icon_uri );
    1297             : 
    1298           0 :     if( FD_UNLIKELY( peer_updated ) ) {
    1299           0 :       updated[ update_cnt++ ] = found_idx;
    1300           0 :       *existing = info;
    1301           0 :     }
    1302           0 :   }
    1303             : 
    1304           0 :   added_cnt = gui->validator_info.info_cnt - before_peer_cnt;
    1305           0 :   for( ulong i=before_peer_cnt; i<gui->validator_info.info_cnt; i++ ) added[ i-before_peer_cnt ] = i;
    1306             : 
    1307           0 :   fd_guih_printf_peers_validator_info_update( gui, updated, update_cnt, NULL, removed_cnt, added, added_cnt );
    1308           0 :   fd_http_server_ws_broadcast( gui->http );
    1309           0 : }
    1310             : 
    1311             : int
    1312             : fd_guih_request_slot( fd_guih_t *    gui,
    1313             :                      ulong         ws_conn_id,
    1314             :                      ulong         request_id,
    1315             :                      char const *  params,
    1316           0 :                      ulong         params_sz ) {
    1317           0 :   ulong _slot = 0UL; int has_slot = 0;
    1318           0 :   fd_jtok_t j[1]; fd_jtok_init( j, params, params_sz );
    1319           0 :   fd_jtok_str_t key;
    1320           0 :   fd_jtok_obj_enter( j );
    1321           0 :   while( fd_jtok_obj_next( j, &key ) ) {
    1322           0 :     if( fd_jtok_str_eq( &key, "slot" ) ) { fd_jtok_ulong( j, &_slot ); has_slot = 1; }
    1323           0 :   }
    1324           0 :   if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_slot ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1325             : 
    1326           0 :   fd_guih_slot_t const * slot = fd_guih_get_slot_const( gui, _slot );
    1327           0 :   if( FD_UNLIKELY( !slot ) ) {
    1328           0 :     fd_guih_printf_null_query_response( gui->http, "slot", "query", request_id );
    1329           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1330           0 :     return 0;
    1331           0 :   }
    1332             : 
    1333           0 :   fd_guih_printf_slot_request( gui, _slot, request_id );
    1334           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1335           0 :   return 0;
    1336           0 : }
    1337             : 
    1338             : int
    1339             : fd_guih_request_slot_transactions( fd_guih_t *    gui,
    1340             :                                   ulong         ws_conn_id,
    1341             :                                   ulong         request_id,
    1342             :                                   char const *  params,
    1343           0 :                                   ulong         params_sz ) {
    1344           0 :   ulong _slot = 0UL; int has_slot = 0;
    1345           0 :   fd_jtok_t j[1]; fd_jtok_init( j, params, params_sz );
    1346           0 :   fd_jtok_str_t key;
    1347           0 :   fd_jtok_obj_enter( j );
    1348           0 :   while( fd_jtok_obj_next( j, &key ) ) {
    1349           0 :     if( fd_jtok_str_eq( &key, "slot" ) ) { fd_jtok_ulong( j, &_slot ); has_slot = 1; }
    1350           0 :   }
    1351           0 :   if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_slot ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1352             : 
    1353           0 :   fd_guih_slot_t const * slot = fd_guih_get_slot_const( gui, _slot );
    1354           0 :   if( FD_UNLIKELY( !slot ) ) {
    1355           0 :     fd_guih_printf_null_query_response( gui->http, "slot", "query_transactions", request_id );
    1356           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1357           0 :     return 0;
    1358           0 :   }
    1359             : 
    1360           0 :   fd_guih_printf_slot_transactions_request( gui, _slot, request_id );
    1361           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1362           0 :   return 0;
    1363           0 : }
    1364             : 
    1365             : int
    1366             : fd_guih_request_slot_detailed( fd_guih_t *    gui,
    1367             :                               ulong         ws_conn_id,
    1368             :                               ulong         request_id,
    1369             :                               char const *  params,
    1370           0 :                               ulong         params_sz ) {
    1371           0 :   ulong _slot = 0UL; int has_slot = 0;
    1372           0 :   fd_jtok_t j[1]; fd_jtok_init( j, params, params_sz );
    1373           0 :   fd_jtok_str_t key;
    1374           0 :   fd_jtok_obj_enter( j );
    1375           0 :   while( fd_jtok_obj_next( j, &key ) ) {
    1376           0 :     if( fd_jtok_str_eq( &key, "slot" ) ) { fd_jtok_ulong( j, &_slot ); has_slot = 1; }
    1377           0 :   }
    1378           0 :   if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_slot ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1379             : 
    1380           0 :   fd_guih_slot_t const * slot = fd_guih_get_slot_const( gui, _slot );
    1381           0 :   if( FD_UNLIKELY( !slot ) ) {
    1382           0 :     fd_guih_printf_null_query_response( gui->http, "slot", "query_detailed", request_id );
    1383           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1384           0 :     return 0;
    1385           0 :   }
    1386             : 
    1387           0 :   fd_guih_printf_slot_request_detailed( gui, _slot, request_id );
    1388           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1389           0 :   return 0;
    1390           0 : }
    1391             : 
    1392             : static inline ulong
    1393           0 : fd_guih_slot_duration( fd_guih_t const * gui, fd_guih_slot_t const * cur ) {
    1394           0 :   fd_guih_slot_t const * prev = fd_guih_get_slot_const( gui, cur->slot-1UL );
    1395           0 :   if( FD_UNLIKELY( !prev ||
    1396           0 :                    prev->skipped ||
    1397           0 :                    prev->completed_time == LONG_MAX ||
    1398           0 :                    prev->slot != (cur->slot - 1UL) ||
    1399           0 :                    cur->skipped ||
    1400           0 :                    cur->completed_time == LONG_MAX ) ) return ULONG_MAX;
    1401             : 
    1402           0 :   return (ulong)(cur->completed_time - prev->completed_time);
    1403           0 : }
    1404             : 
    1405             : /* All rankings are initialized / reset to ULONG_MAX.  These sentinels
    1406             :    sort AFTER non-sentinel ranking entries.  Equal slots are sorted by
    1407             :    oldest slot AFTER.  Otherwise sort by value according to ranking
    1408             :    type. */
    1409             : #define SORT_NAME fd_guih_slot_ranking_sort
    1410           0 : #define SORT_KEY_T fd_guih_slot_ranking_t
    1411           0 : #define SORT_BEFORE(a,b) fd_int_if( (a).slot==ULONG_MAX, 0, fd_int_if( (b).slot==ULONG_MAX, 1, fd_int_if( (a).value==(b).value, (a).slot>(b).slot, fd_int_if( (a).type==FD_GUIH_SLOT_RANKING_TYPE_DESC, (a).value>(b).value, (a).value<(b).value ) ) ) )
    1412             : #include "../../util/tmpl/fd_sort.c"
    1413             : 
    1414             : static inline void
    1415             : fd_guih_try_insert_ranking( fd_guih_t               * gui,
    1416             :                            fd_guih_slot_rankings_t * rankings,
    1417           0 :                            fd_guih_slot_t const    * slot ) {
    1418             :   /* Rankings are inserted into an extra slot at the end of the ranking
    1419             :      array, then the array is sorted. */
    1420           0 : #define TRY_INSERT_SLOT( ranking_name, ranking_slot, ranking_value ) \
    1421           0 :   do { \
    1422           0 :     rankings->FD_CONCAT2(largest_, ranking_name) [ FD_GUIH_SLOT_RANKINGS_SZ ] = (fd_guih_slot_ranking_t){ .slot = (ranking_slot), .value = (ranking_value), .type = FD_GUIH_SLOT_RANKING_TYPE_DESC }; \
    1423           0 :     fd_guih_slot_ranking_sort_insert( rankings->FD_CONCAT2(largest_, ranking_name), FD_GUIH_SLOT_RANKINGS_SZ+1UL ); \
    1424           0 :     rankings->FD_CONCAT2(smallest_, ranking_name)[ FD_GUIH_SLOT_RANKINGS_SZ ] = (fd_guih_slot_ranking_t){ .slot = (ranking_slot), .value = (ranking_value), .type = FD_GUIH_SLOT_RANKING_TYPE_ASC  }; \
    1425           0 :     fd_guih_slot_ranking_sort_insert( rankings->FD_CONCAT2(smallest_, ranking_name), FD_GUIH_SLOT_RANKINGS_SZ+1UL ); \
    1426           0 :   } while (0)
    1427             : 
    1428           0 :     if( slot->skipped ) {
    1429           0 :       TRY_INSERT_SLOT( skipped, slot->slot, slot->slot );
    1430           0 :       return;
    1431           0 :     }
    1432             : 
    1433           0 :     ulong dur = fd_guih_slot_duration( gui, slot );
    1434           0 :     if( FD_LIKELY( dur!=ULONG_MAX ) ) TRY_INSERT_SLOT( duration, slot->slot, dur                         );
    1435           0 :     TRY_INSERT_SLOT( tips,           slot->slot, slot->tips                                              );
    1436           0 :     TRY_INSERT_SLOT( fees,           slot->slot, slot->priority_fee + slot->transaction_fee              );
    1437           0 :     TRY_INSERT_SLOT( rewards,        slot->slot, slot->tips + slot->priority_fee + slot->transaction_fee );
    1438           0 :     TRY_INSERT_SLOT( rewards_per_cu, slot->slot, slot->compute_units==0UL ? 0UL : (slot->tips + slot->priority_fee + slot->transaction_fee) / slot->compute_units );
    1439           0 :     TRY_INSERT_SLOT( compute_units,  slot->slot, slot->compute_units                                     );
    1440           0 : #undef TRY_INSERT_SLOT
    1441           0 : }
    1442             : 
    1443             : static void
    1444           0 : fd_guih_update_slot_rankings( fd_guih_t * gui ) {
    1445           0 :   ulong first_replay_slot = ULONG_MAX;
    1446           0 :   first_replay_slot = gui->summary.startup_progress.startup_ledger_max_slot;
    1447           0 :   if( FD_UNLIKELY( first_replay_slot==ULONG_MAX ) ) return;
    1448           0 :   if( FD_UNLIKELY( gui->summary.slot_rooted ==ULONG_MAX ) ) return;
    1449             : 
    1450           0 :   ulong epoch_idx = fd_guih_current_epoch_idx( gui );
    1451           0 :   if( FD_UNLIKELY( epoch_idx==ULONG_MAX ) ) return;
    1452             : 
    1453             :   /* No new slots since the last update */
    1454           0 :   if( FD_UNLIKELY( gui->epoch.epochs[ epoch_idx ].rankings_slot>gui->summary.slot_rooted ) ) return;
    1455             : 
    1456             :   /* Slots before first_replay_slot are unavailable. */
    1457           0 :   gui->epoch.epochs[ epoch_idx ].rankings_slot = fd_ulong_max( gui->epoch.epochs[ epoch_idx ].rankings_slot, first_replay_slot );
    1458             : 
    1459             :   /* Update the rankings. Only look through slots we haven't already. */
    1460           0 :   for( ulong s = gui->summary.slot_rooted; s>=gui->epoch.epochs[ epoch_idx ].rankings_slot; s--) {
    1461           0 :     fd_guih_slot_t const * slot = fd_guih_get_slot_const( gui, s );
    1462           0 :     if( FD_UNLIKELY( !slot ) ) break;
    1463             : 
    1464           0 :     fd_guih_try_insert_ranking( gui, gui->epoch.epochs[ epoch_idx ].rankings, slot );
    1465           0 :     if( FD_UNLIKELY( slot->mine ) ) fd_guih_try_insert_ranking( gui, gui->epoch.epochs[ epoch_idx ].my_rankings, slot );
    1466           0 :   }
    1467             : 
    1468           0 :   gui->epoch.epochs[ epoch_idx ].rankings_slot = gui->summary.slot_rooted + 1UL;
    1469           0 : }
    1470             : 
    1471             : int
    1472             : fd_guih_request_slot_rankings( fd_guih_t *    gui,
    1473             :                               ulong         ws_conn_id,
    1474             :                               ulong         request_id,
    1475             :                               char const *  params,
    1476           0 :                               ulong         params_sz ) {
    1477           0 :   int mine = 0; int has_mine = 0;
    1478           0 :   fd_jtok_t j[1]; fd_jtok_init( j, params, params_sz );
    1479           0 :   fd_jtok_str_t key;
    1480           0 :   fd_jtok_obj_enter( j );
    1481           0 :   while( fd_jtok_obj_next( j, &key ) ) {
    1482           0 :     if( fd_jtok_str_eq( &key, "mine" ) ) { fd_jtok_bool( j, &mine ); has_mine = 1; }
    1483           0 :   }
    1484           0 :   if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_mine ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1485             : 
    1486           0 :   fd_guih_update_slot_rankings( gui );
    1487           0 :   fd_guih_printf_slot_rankings_request( gui, request_id, mine );
    1488           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1489           0 :   return 0;
    1490           0 : }
    1491             : 
    1492             : int
    1493             : fd_guih_request_slot_shreds( fd_guih_t *    gui,
    1494             :                             ulong         ws_conn_id,
    1495             :                             ulong         request_id,
    1496             :                             char const *  params,
    1497           0 :                             ulong         params_sz ) {
    1498           0 :   ulong _slot = 0UL; int has_slot = 0;
    1499           0 :   fd_jtok_t j[1]; fd_jtok_init( j, params, params_sz );
    1500           0 :   fd_jtok_str_t key;
    1501           0 :   fd_jtok_obj_enter( j );
    1502           0 :   while( fd_jtok_obj_next( j, &key ) ) {
    1503           0 :     if( fd_jtok_str_eq( &key, "slot" ) ) { fd_jtok_ulong( j, &_slot ); has_slot = 1; }
    1504           0 :   }
    1505           0 :   if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_slot ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1506             : 
    1507           0 :   fd_guih_slot_t const * slot = fd_guih_get_slot_const( gui, _slot );
    1508           0 :   if( FD_UNLIKELY( !slot || slot->shreds.start_offset==ULONG_MAX || slot->shreds.end_offset==ULONG_MAX || gui->shreds.history_tail >= slot->shreds.end_offset + FD_GUIH_SHREDS_HISTORY_SZ ) ) {
    1509           0 :     fd_guih_printf_null_query_response( gui->http, "slot", "query_shreds", request_id );
    1510           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1511           0 :     return 0;
    1512           0 :   }
    1513             : 
    1514           0 :   fd_guih_printf_slot_query_shreds( gui, _slot, request_id );
    1515           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1516           0 :   return 0;
    1517           0 : }
    1518             : 
    1519             : int
    1520             : fd_guih_ws_message( fd_guih_t *   gui,
    1521             :                     ulong         ws_conn_id,
    1522             :                     uchar const * data,
    1523           0 :                     ulong         data_len ) {
    1524           0 :   ulong         id        = 0UL; int has_id = 0;
    1525           0 :   fd_jtok_str_t topic     = {0};
    1526           0 :   fd_jtok_str_t key       = {0};
    1527           0 :   char const *  params    = NULL;
    1528           0 :   ulong         params_sz = 0UL;
    1529             : 
    1530           0 :   fd_jtok_t j[1]; fd_jtok_init( j, data, data_len );
    1531           0 :   fd_jtok_str_t member;
    1532           0 :   fd_jtok_obj_enter( j );
    1533           0 :   while( fd_jtok_obj_next( j, &member ) ) {
    1534           0 :     if(      fd_jtok_str_eq( &member, "id"     ) ) { fd_jtok_ulong( j, &id ); has_id = 1; }
    1535           0 :     else if( fd_jtok_str_eq( &member, "topic"  ) ) fd_jtok_str( j, &topic );
    1536           0 :     else if( fd_jtok_str_eq( &member, "key"    ) ) fd_jtok_str( j, &key );
    1537           0 :     else if( fd_jtok_str_eq( &member, "params" ) ) {
    1538           0 :       if( FD_UNLIKELY( fd_jtok_peek( j )!=FD_JTOK_OBJ ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1539           0 :       fd_jtok_raw( j, &params, &params_sz );
    1540           0 :     }
    1541           0 :   }
    1542           0 :   if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_id || !topic.ptr || !key.ptr ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1543             : 
    1544           0 :   if( FD_LIKELY( fd_jtok_str_eq( &topic, "slot" ) && fd_jtok_str_eq( &key, "query" ) ) ) {
    1545           0 :     if( FD_UNLIKELY( !params ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1546           0 :     return fd_guih_request_slot( gui, ws_conn_id, id, params, params_sz );
    1547           0 :   } else if( FD_LIKELY( fd_jtok_str_eq( &topic, "slot" ) && fd_jtok_str_eq( &key, "query_detailed" ) ) ) {
    1548           0 :     if( FD_UNLIKELY( !params ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1549           0 :     return fd_guih_request_slot_detailed( gui, ws_conn_id, id, params, params_sz );
    1550           0 :   } else if( FD_LIKELY( fd_jtok_str_eq( &topic, "slot" ) && fd_jtok_str_eq( &key, "query_transactions" ) ) ) {
    1551           0 :     if( FD_UNLIKELY( !params ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1552           0 :     return fd_guih_request_slot_transactions( gui, ws_conn_id, id, params, params_sz );
    1553           0 :   } else if( FD_LIKELY( fd_jtok_str_eq( &topic, "slot" ) && fd_jtok_str_eq( &key, "query_rankings" ) ) ) {
    1554           0 :     if( FD_UNLIKELY( !params ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1555           0 :     return fd_guih_request_slot_rankings( gui, ws_conn_id, id, params, params_sz );
    1556           0 :   } else if( FD_LIKELY( fd_jtok_str_eq( &topic, "slot" ) && fd_jtok_str_eq( &key, "query_shreds" ) ) ) {
    1557           0 :     if( FD_UNLIKELY( !params ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1558           0 :     return fd_guih_request_slot_shreds( gui, ws_conn_id, id, params, params_sz );
    1559           0 :   } else if( FD_LIKELY( fd_jtok_str_eq( &topic, "summary" ) && fd_jtok_str_eq( &key, "ping" ) ) ) {
    1560           0 :     fd_guih_printf_summary_ping( gui, id );
    1561           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1562           0 :     return 0;
    1563           0 :   }
    1564             : 
    1565           0 :   return FD_HTTP_SERVER_CONNECTION_CLOSE_UNKNOWN_METHOD;
    1566           0 : }
    1567             : 
    1568             : static fd_guih_slot_t *
    1569             : fd_guih_clear_slot( fd_guih_t *      gui,
    1570             :                    ulong           _slot,
    1571           0 :                    ulong           _parent_slot ) {
    1572           0 :   fd_guih_slot_t * slot = gui->slots[ _slot % FD_GUIH_SLOTS_CNT ];
    1573             : 
    1574           0 :   int mine = 0;
    1575           0 :   ulong epoch_idx = 0UL;
    1576           0 :   for( ulong i=0UL; i<2UL; i++) {
    1577           0 :     if( FD_UNLIKELY( !gui->epoch.has_epoch[ i ] ) ) continue;
    1578           0 :     if( FD_LIKELY( _slot>=gui->epoch.epochs[ i ].start_slot && _slot<=gui->epoch.epochs[ i ].end_slot ) ) {
    1579           0 :       fd_pubkey_t const * slot_leader = fd_epoch_leaders_get( gui->epoch.epochs[ i ].lsched, _slot );
    1580           0 :       mine = !memcmp( slot_leader->uc, gui->summary.identity_key->uc, 32UL );
    1581           0 :       epoch_idx = i;
    1582           0 :       break;
    1583           0 :     }
    1584           0 :   }
    1585             : 
    1586           0 :   slot->slot                   = _slot;
    1587           0 :   slot->parent_slot            = _parent_slot;
    1588           0 :   slot->vote_slot              = ULONG_MAX;
    1589           0 :   slot->vote_latency           = UCHAR_MAX;
    1590           0 :   slot->reset_slot             = ULONG_MAX;
    1591           0 :   slot->max_compute_units      = UINT_MAX;
    1592           0 :   slot->completed_time         = LONG_MAX;
    1593           0 :   slot->mine                   = mine;
    1594           0 :   slot->skipped                = 0;
    1595           0 :   slot->must_republish         = 1;
    1596           0 :   slot->level                  = FD_GUIH_SLOT_LEVEL_INCOMPLETE;
    1597           0 :   slot->vote_failed            = UINT_MAX;
    1598           0 :   slot->vote_success           = UINT_MAX;
    1599           0 :   slot->nonvote_success        = UINT_MAX;
    1600           0 :   slot->nonvote_failed         = UINT_MAX;
    1601           0 :   slot->compute_units          = UINT_MAX;
    1602           0 :   slot->transaction_fee        = ULONG_MAX;
    1603           0 :   slot->priority_fee           = ULONG_MAX;
    1604           0 :   slot->tips                   = ULONG_MAX;
    1605           0 :   slot->shred_cnt              = UINT_MAX;
    1606           0 :   slot->shreds.start_offset    = ULONG_MAX;
    1607           0 :   slot->shreds.end_offset      = ULONG_MAX;
    1608             : 
    1609           0 :   if( FD_LIKELY( slot->mine ) ) {
    1610             :     /* All slots start off not skipped, until we see it get off the reset
    1611             :        chain. */
    1612           0 :     gui->epoch.epochs[ epoch_idx ].my_total_slots++;
    1613             : 
    1614           0 :     slot->leader_history_idx = gui->leader_slots_cnt++;
    1615           0 :     fd_guih_leader_slot_t * lslot = gui->leader_slots[ slot->leader_history_idx % FD_GUIH_LEADER_CNT ];
    1616             : 
    1617           0 :     lslot->slot                        = _slot;
    1618           0 :     memset( lslot->block_hash.uc, 0, sizeof(fd_hash_t) );
    1619           0 :     lslot->leader_start_time           = LONG_MAX;
    1620           0 :     lslot->leader_end_time             = LONG_MAX;
    1621           0 :     lslot->tile_timers_sample_cnt      = 0UL;
    1622           0 :     lslot->scheduler_counts_sample_cnt = 0UL;
    1623           0 :     lslot->txs.microblocks_upper_bound = UINT_MAX;
    1624           0 :     lslot->txs.begin_microblocks       = 0U;
    1625           0 :     lslot->txs.end_microblocks         = 0U;
    1626           0 :     lslot->txs.start_offset            = ULONG_MAX;
    1627           0 :     lslot->txs.end_offset              = ULONG_MAX;
    1628           0 :     lslot->max_microblocks             = ULONG_MAX;
    1629           0 :     lslot->unbecame_leader             = 0;
    1630           0 :   }
    1631             : 
    1632           0 :   if( FD_UNLIKELY( !_slot ) ) {
    1633             :     /* Slot 0 is always rooted */
    1634           0 :     slot->level   = FD_GUIH_SLOT_LEVEL_ROOTED;
    1635           0 :   }
    1636             : 
    1637           0 :   return slot;
    1638           0 : }
    1639             : 
    1640             : void
    1641             : fd_guih_handle_leader_schedule( fd_guih_t *                    gui,
    1642             :                                fd_stake_weight_msg_t const * leader_schedule,
    1643           0 :                                long                          now ) {
    1644           0 :   FD_TEST( leader_schedule->staked_vote_cnt<=MAX_STAKE_WEIGHTS );
    1645           0 :   FD_TEST( leader_schedule->slot_cnt<=MAX_SLOTS_PER_EPOCH );
    1646             : 
    1647           0 :   ulong idx = leader_schedule->epoch % 2UL;
    1648           0 :   gui->epoch.has_epoch[ idx ] = 1;
    1649             : 
    1650           0 :   gui->epoch.epochs[ idx ].epoch                      = leader_schedule->epoch;
    1651           0 :   gui->epoch.epochs[ idx ].start_slot                 = leader_schedule->start_slot;
    1652           0 :   gui->epoch.epochs[ idx ].end_slot                   = leader_schedule->start_slot + leader_schedule->slot_cnt - 1; // end_slot is inclusive.
    1653           0 :   gui->epoch.epochs[ idx ].target_slot_duration_nanos = leader_schedule->ns_per_slot;
    1654           0 :   gui->epoch.epochs[ idx ].my_total_slots             = 0UL;
    1655           0 :   gui->epoch.epochs[ idx ].my_skipped_slots           = 0UL;
    1656             : 
    1657           0 :   memset( gui->epoch.epochs[ idx ].rankings,    (int)(UINT_MAX), sizeof(gui->epoch.epochs[ idx ].rankings)    );
    1658           0 :   memset( gui->epoch.epochs[ idx ].my_rankings, (int)(UINT_MAX), sizeof(gui->epoch.epochs[ idx ].my_rankings) );
    1659             : 
    1660           0 :   gui->epoch.epochs[ idx ].rankings_slot = leader_schedule->start_slot;
    1661             : 
    1662           0 :   fd_vote_stake_weight_t const * stake_weights = fd_stake_weight_msg_stake_weights( leader_schedule );
    1663           0 :   fd_memcpy( gui->epoch.epochs[ idx ].stakes, stake_weights, leader_schedule->staked_vote_cnt*sizeof(fd_vote_stake_weight_t) );
    1664             : 
    1665           0 :   fd_epoch_leaders_delete( fd_epoch_leaders_leave( gui->epoch.epochs[ idx ].lsched ) );
    1666           0 :   gui->epoch.epochs[idx].lsched = fd_epoch_leaders_join( fd_epoch_leaders_new( gui->epoch.epochs[ idx ]._lsched,
    1667           0 :                                                                                leader_schedule->epoch,
    1668           0 :                                                                                gui->epoch.epochs[ idx ].start_slot,
    1669           0 :                                                                                leader_schedule->slot_cnt,
    1670           0 :                                                                                leader_schedule->staked_vote_cnt,
    1671           0 :                                                                                gui->epoch.epochs[ idx ].stakes ) );
    1672             : 
    1673           0 :   if( FD_UNLIKELY( leader_schedule->start_slot==0UL ) ) {
    1674           0 :     gui->epoch.epochs[ 0 ].start_time = now;
    1675           0 :   } else {
    1676           0 :     gui->epoch.epochs[ idx ].start_time = LONG_MAX;
    1677             : 
    1678           0 :     for( ulong i=0UL; i<fd_ulong_min( leader_schedule->start_slot-1UL, FD_GUIH_SLOTS_CNT ); i++ ) {
    1679           0 :       fd_guih_slot_t const * slot = fd_guih_get_slot_const( gui, leader_schedule->start_slot-i );
    1680           0 :       if( FD_UNLIKELY( !slot ) ) break;
    1681           0 :       else if( FD_UNLIKELY( slot->skipped ) ) continue;
    1682             : 
    1683           0 :       gui->epoch.epochs[ idx ].start_time = slot->completed_time;
    1684           0 :       break;
    1685           0 :     }
    1686           0 :   }
    1687             : 
    1688           0 :   fd_guih_printf_epoch( gui, idx );
    1689           0 :   fd_http_server_ws_broadcast( gui->http );
    1690           0 : }
    1691             : 
    1692             : static void
    1693             : fd_guih_handle_slot_start( fd_guih_t * gui,
    1694             :                           ulong      _slot,
    1695             :                           ulong      parent_slot,
    1696           0 :                           long       now ) {
    1697           0 :   FD_TEST( gui->leader_slot==ULONG_MAX );
    1698           0 :   gui->leader_slot = _slot;
    1699             : 
    1700           0 :   fd_guih_slot_t * slot = fd_guih_get_slot( gui, _slot );
    1701           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_guih_clear_slot( gui, _slot, parent_slot );
    1702             : 
    1703           0 :   fd_guih_tile_timers_snap( gui );
    1704           0 :   gui->summary.tile_timers_snap_idx_slot_start = (gui->summary.tile_timers_snap_idx+(FD_GUIH_TILE_TIMER_SNAP_CNT-1UL))%FD_GUIH_TILE_TIMER_SNAP_CNT;
    1705             : 
    1706           0 :   fd_guih_scheduler_counts_snap( gui, now );
    1707           0 :   gui->summary.scheduler_counts_snap_idx_slot_start = (gui->summary.scheduler_counts_snap_idx+(FD_GUIH_SCHEDULER_COUNT_SNAP_CNT-1UL))%FD_GUIH_SCHEDULER_COUNT_SNAP_CNT;
    1708             : 
    1709           0 :   fd_guih_txn_waterfall_t waterfall[ 1 ];
    1710           0 :   fd_guih_txn_waterfall_snap( gui, waterfall );
    1711           0 :   fd_guih_tile_stats_snap( gui, waterfall, slot->tile_stats_begin, now );
    1712           0 : }
    1713             : 
    1714             : static void
    1715             : fd_guih_handle_slot_end( fd_guih_t * gui,
    1716             :                         ulong      _slot,
    1717             :                         ulong      _cus_used,
    1718           0 :                         long       now ) {
    1719           0 :   if( FD_UNLIKELY( gui->leader_slot!=_slot ) ) {
    1720           0 :     FD_LOG_ERR(( "gui->leader_slot %lu _slot %lu", gui->leader_slot, _slot ));
    1721           0 :   }
    1722           0 :   gui->leader_slot = ULONG_MAX;
    1723             : 
    1724           0 :   fd_guih_slot_t * slot = fd_guih_get_slot( gui, _slot );
    1725           0 :   if( FD_UNLIKELY( !slot ) ) return;
    1726             : 
    1727           0 :   slot->compute_units = (uint)_cus_used;
    1728             : 
    1729           0 :   fd_guih_tile_timers_snap( gui );
    1730             : 
    1731           0 :   fd_guih_scheduler_counts_snap( gui, now );
    1732             : 
    1733           0 :   fd_guih_leader_slot_t * lslot = fd_guih_get_leader_slot( gui, _slot );
    1734           0 :   if( FD_LIKELY( lslot ) ) {
    1735           0 :     fd_rng_t rng[ 1 ];
    1736           0 :     fd_rng_new( rng, 0UL, 0UL);
    1737             : 
    1738           0 : #define DOWNSAMPLE( a, a_start, a_end, a_capacity, b, b_sz, stride ) (__extension__({  \
    1739           0 :   ulong __cnt = 0UL; \
    1740           0 :   ulong __rsz = (stride); \
    1741           0 :   ulong __a_sz = (fd_ulong_if( a_end<a_start, a_end+a_capacity, a_end )-a_start); \
    1742           0 :   if( FD_UNLIKELY( __a_sz && b_sz ) ) { \
    1743           0 :     for( ulong a_idx=0UL; a_idx<__a_sz && __cnt<b_sz; a_idx++ ) { \
    1744           0 :       if( FD_UNLIKELY( fd_rng_float_robust( rng ) > (float)(b_sz-__cnt) / (float)(__a_sz-__cnt) ) ) continue; \
    1745           0 :       fd_memcpy( (b) + __cnt * __rsz, (a) + ((a_start+a_idx)%a_capacity) * __rsz, __rsz * sizeof(*(b)) ); \
    1746           0 :       __cnt++; \
    1747           0 :     } \
    1748           0 :   } \
    1749           0 :   __cnt; }))
    1750             : 
    1751           0 :     lslot->tile_timers_sample_cnt = DOWNSAMPLE(
    1752           0 :       gui->summary.tile_timers_snap,
    1753           0 :       gui->summary.tile_timers_snap_idx_slot_start,
    1754           0 :       gui->summary.tile_timers_snap_idx,
    1755           0 :       FD_GUIH_TILE_TIMER_SNAP_CNT,
    1756           0 :       lslot->tile_timers,
    1757           0 :       FD_GUIH_TILE_TIMER_LEADER_DOWNSAMPLE_CNT,
    1758           0 :       gui->tile_cnt );
    1759             : 
    1760           0 :     lslot->scheduler_counts_sample_cnt = DOWNSAMPLE(
    1761           0 :       gui->summary.scheduler_counts_snap,
    1762           0 :       gui->summary.scheduler_counts_snap_idx_slot_start,
    1763           0 :       gui->summary.scheduler_counts_snap_idx,
    1764           0 :       FD_GUIH_SCHEDULER_COUNT_SNAP_CNT,
    1765           0 :       lslot->scheduler_counts,
    1766           0 :       FD_GUIH_SCHEDULER_COUNT_LEADER_DOWNSAMPLE_CNT,
    1767           0 :       1UL );
    1768           0 : #undef DOWNSAMPLE
    1769           0 :   }
    1770             : 
    1771             :   /* When a slot ends, snap the state of the waterfall and save it into
    1772             :      that slot, and also reset the reference counters to the end of the
    1773             :      slot. */
    1774             : 
    1775           0 :   fd_guih_txn_waterfall_snap( gui, slot->waterfall_end );
    1776           0 :   memcpy( slot->waterfall_begin, gui->summary.txn_waterfall_reference, sizeof(slot->waterfall_begin) );
    1777           0 :   memcpy( gui->summary.txn_waterfall_reference, slot->waterfall_end, sizeof(gui->summary.txn_waterfall_reference) );
    1778             : 
    1779           0 :   fd_guih_tile_stats_snap( gui, slot->waterfall_end, slot->tile_stats_end, now );
    1780           0 : }
    1781             : 
    1782             : static void
    1783             : fd_guih_handle_reset_slot_legacy( fd_guih_t *    gui,
    1784             :                                  uchar const * msg,
    1785           0 :                                  long          now ) {
    1786           0 :   ulong last_landed_vote = FD_LOAD( ulong, msg );
    1787             : 
    1788           0 :   ulong parent_cnt = FD_LOAD( ulong, msg + 8UL );
    1789           0 :   FD_TEST( parent_cnt<4096UL );
    1790             : 
    1791           0 :   ulong _slot = FD_LOAD( ulong, msg + 16UL );
    1792             : 
    1793           0 :   for( ulong i=0UL; i<parent_cnt; i++ ) {
    1794           0 :     ulong parent_slot = FD_LOAD( ulong, msg + (2UL+i)*8UL );
    1795           0 :     fd_guih_slot_t * slot = fd_guih_get_slot( gui, parent_slot );
    1796           0 :     if( FD_UNLIKELY( !slot ) ) {
    1797           0 :       ulong parent_parent_slot = ULONG_MAX;
    1798           0 :       if( FD_UNLIKELY( i!=parent_cnt-1UL) ) parent_parent_slot = FD_LOAD( ulong, msg + (3UL+i)*8UL );
    1799           0 :       fd_guih_clear_slot( gui, parent_slot, parent_parent_slot );
    1800           0 :     }
    1801           0 :   }
    1802             : 
    1803           0 :   if( FD_UNLIKELY( gui->summary.vote_distance!=_slot-last_landed_vote ) ) {
    1804           0 :     gui->summary.vote_distance = _slot-last_landed_vote;
    1805           0 :     fd_guih_printf_vote_distance( gui );
    1806           0 :     fd_http_server_ws_broadcast( gui->http );
    1807           0 :   }
    1808             : 
    1809           0 :   if( FD_LIKELY( gui->summary.vote_state!=FD_GUIH_VOTE_STATE_NON_VOTING ) ) {
    1810           0 :     if( FD_UNLIKELY( last_landed_vote==ULONG_MAX || (last_landed_vote+150UL)<_slot ) ) {
    1811           0 :       if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUIH_VOTE_STATE_DELINQUENT ) ) {
    1812           0 :         gui->summary.vote_state = FD_GUIH_VOTE_STATE_DELINQUENT;
    1813           0 :         fd_guih_printf_vote_state( gui );
    1814           0 :         fd_http_server_ws_broadcast( gui->http );
    1815           0 :       }
    1816           0 :     } else {
    1817           0 :       if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUIH_VOTE_STATE_VOTING ) ) {
    1818           0 :         gui->summary.vote_state = FD_GUIH_VOTE_STATE_VOTING;
    1819           0 :         fd_guih_printf_vote_state( gui );
    1820           0 :         fd_http_server_ws_broadcast( gui->http );
    1821           0 :       }
    1822           0 :     }
    1823           0 :   }
    1824             : 
    1825           0 :   ulong parent_slot_idx = 0UL;
    1826             : 
    1827           0 :   int republish_skip_rate[ 2 ] = {0};
    1828             : 
    1829           0 :   for( ulong i=0UL; i<fd_ulong_min( _slot+1, FD_GUIH_SLOTS_CNT ); i++ ) {
    1830           0 :     ulong parent_slot = _slot - i;
    1831             : 
    1832           0 :     fd_guih_slot_t * slot = fd_guih_get_slot( gui, parent_slot );
    1833           0 :     if( FD_UNLIKELY( !slot ) ) slot = fd_guih_clear_slot( gui, parent_slot, ULONG_MAX );
    1834             : 
    1835             :     /* The chain of parents may stretch into already rooted slots if
    1836             :        they haven't been squashed yet, if we reach one of them we can
    1837             :        just exit, all the information prior to the root is already
    1838             :        correct. */
    1839             : 
    1840           0 :     if( FD_LIKELY( slot->level>=FD_GUIH_SLOT_LEVEL_ROOTED ) ) break;
    1841             : 
    1842           0 :     int should_republish = slot->must_republish;
    1843           0 :     slot->must_republish = 0;
    1844             : 
    1845           0 :     if( FD_UNLIKELY( parent_slot!=FD_LOAD( ulong, msg + (2UL+parent_slot_idx)*8UL ) ) ) {
    1846             :       /* We are between two parents in the rooted chain, which means
    1847             :          we were skipped. */
    1848           0 :       if( FD_UNLIKELY( !slot->skipped ) ) {
    1849           0 :         slot->skipped = 1;
    1850           0 :         should_republish = 1;
    1851           0 :         if( FD_LIKELY( slot->mine ) ) {
    1852           0 :           for( ulong i=0UL; i<2UL; i++ ) {
    1853           0 :             if( FD_LIKELY( parent_slot>=gui->epoch.epochs[ i ].start_slot && parent_slot<=gui->epoch.epochs[ i ].end_slot ) ) {
    1854           0 :               gui->epoch.epochs[ i ].my_skipped_slots++;
    1855           0 :               republish_skip_rate[ i ] = 1;
    1856           0 :               break;
    1857           0 :             }
    1858           0 :           }
    1859           0 :         }
    1860           0 :       }
    1861           0 :     } else {
    1862             :       /* Reached the next parent... */
    1863           0 :       if( FD_UNLIKELY( slot->skipped ) ) {
    1864           0 :         slot->skipped = 0;
    1865           0 :         should_republish = 1;
    1866           0 :         if( FD_LIKELY( slot->mine ) ) {
    1867           0 :           for( ulong i=0UL; i<2UL; i++ ) {
    1868           0 :             if( FD_LIKELY( parent_slot>=gui->epoch.epochs[ i ].start_slot && parent_slot<=gui->epoch.epochs[ i ].end_slot ) ) {
    1869           0 :               gui->epoch.epochs[ i ].my_skipped_slots--;
    1870           0 :               republish_skip_rate[ i ] = 1;
    1871           0 :               break;
    1872           0 :             }
    1873           0 :           }
    1874           0 :         }
    1875           0 :       }
    1876           0 :       parent_slot_idx++;
    1877           0 :     }
    1878             : 
    1879           0 :     if( FD_LIKELY( should_republish ) ) {
    1880           0 :       fd_guih_printf_slot( gui, parent_slot );
    1881           0 :       fd_http_server_ws_broadcast( gui->http );
    1882           0 :     }
    1883             : 
    1884             :     /* We reached the last parent in the chain, everything above this
    1885             :        must have already been rooted, so we can exit. */
    1886             : 
    1887           0 :     if( FD_UNLIKELY( parent_slot_idx>=parent_cnt ) ) break;
    1888           0 :   }
    1889             : 
    1890           0 :   ulong duration_sum = 0UL;
    1891           0 :   ulong slot_cnt = 0UL;
    1892             : 
    1893             :   /* If we've just caught up we should truncate our slot history to avoid including catch-up slots */
    1894           0 :   int just_caught_up = gui->summary.slot_caught_up!=ULONG_MAX && _slot>gui->summary.slot_caught_up && _slot<gui->summary.slot_caught_up+750UL;
    1895           0 :   ulong slot_duration_history_sz = fd_ulong_if( just_caught_up, _slot-gui->summary.slot_caught_up, 750UL );
    1896           0 :   for( ulong i=0UL; i<fd_ulong_min( _slot+1, slot_duration_history_sz ); i++ ) {
    1897           0 :     ulong parent_slot = _slot - i;
    1898             : 
    1899           0 :     fd_guih_slot_t const * slot = fd_guih_get_slot_const( gui, parent_slot );
    1900           0 :     if( FD_UNLIKELY( !slot) ) break;
    1901           0 :     if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
    1902           0 :       FD_LOG_ERR(( "_slot %lu i %lu we expect _slot-i %lu got slot->slot %lu", _slot, i, _slot-i, slot->slot ));
    1903           0 :     }
    1904             : 
    1905           0 :     ulong slot_duration = fd_guih_slot_duration( gui, slot );
    1906           0 :     if( FD_LIKELY( slot_duration!=ULONG_MAX ) ) {
    1907           0 :       duration_sum += slot_duration;
    1908           0 :       slot_cnt++;
    1909           0 :     }
    1910           0 :   }
    1911             : 
    1912           0 :   if( FD_LIKELY( slot_cnt>0 ) ) {
    1913           0 :     gui->summary.estimated_slot_duration_nanos = (ulong)(duration_sum / slot_cnt);
    1914           0 :     fd_guih_printf_estimated_slot_duration_nanos( gui );
    1915           0 :     fd_http_server_ws_broadcast( gui->http );
    1916           0 :   }
    1917             : 
    1918           0 :   if( FD_LIKELY( gui->summary.slot_completed==ULONG_MAX || _slot!=gui->summary.slot_completed ) ) {
    1919           0 :     gui->summary.slot_completed = _slot;
    1920           0 :     fd_guih_printf_completed_slot( gui );
    1921           0 :     fd_http_server_ws_broadcast( gui->http );
    1922             : 
    1923             :     /* Also update slot_turbine which could be larger than the max
    1924             :        turbine slot if we are leader */
    1925           0 :     if( FD_UNLIKELY( gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && gui->summary.slot_completed!=ULONG_MAX && gui->summary.slot_completed>gui->summary.slots_max_turbine[ 0 ].slot ) ) {
    1926           0 :       fd_guih_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUIH_TURBINE_SLOT_HISTORY_SZ, gui->summary.slot_completed, now );
    1927           0 :     }
    1928             : 
    1929           0 :     int slot_turbine_hist_full = gui->summary.slots_max_turbine[ FD_GUIH_TURBINE_SLOT_HISTORY_SZ-1UL ].slot!=ULONG_MAX;
    1930           0 :     if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX && slot_turbine_hist_full && gui->summary.slots_max_turbine[ 0 ].slot < (gui->summary.slot_completed + 3UL) ) ) {
    1931           0 :       gui->summary.slot_caught_up = gui->summary.slot_completed + 4UL;
    1932             : 
    1933           0 :       fd_guih_printf_slot_caught_up( gui );
    1934           0 :       fd_http_server_ws_broadcast( gui->http );
    1935           0 :     }
    1936           0 :   }
    1937             : 
    1938           0 :   for( ulong i=0UL; i<2UL; i++ ) {
    1939           0 :     if( FD_LIKELY( republish_skip_rate[ i ] ) ) {
    1940           0 :       fd_guih_printf_skip_rate( gui, i );
    1941           0 :       fd_http_server_ws_broadcast( gui->http );
    1942           0 :     }
    1943           0 :   }
    1944           0 : }
    1945             : 
    1946             : static void
    1947             : fd_guih_handle_completed_slot( fd_guih_t *    gui,
    1948             :                               uchar const * msg,
    1949           0 :                               long          now ) {
    1950             : 
    1951             :   /* This is the slot used by frontend clients as the "startup slot". In
    1952             :      certain boot conditions, we don't receive this slot from Agave, so
    1953             :      we include a bit of a hacky assignment here to make sure it is
    1954             :      always present. */
    1955           0 :   if( FD_UNLIKELY( gui->summary.startup_progress.startup_ledger_max_slot==ULONG_MAX ) ) {
    1956           0 :     gui->summary.startup_progress.startup_ledger_max_slot = FD_LOAD( ulong, msg );
    1957           0 :   }
    1958             : 
    1959           0 :   ulong _slot                    = FD_LOAD( ulong, msg );
    1960           0 :   uint  total_txn_count          = (uint)FD_LOAD( ulong, msg + 1UL*8UL );
    1961           0 :   uint  nonvote_txn_count        = (uint)FD_LOAD( ulong, msg + 2UL*8UL );
    1962           0 :   uint  failed_txn_count         = (uint)FD_LOAD( ulong, msg + 3UL*8UL );
    1963           0 :   uint  nonvote_failed_txn_count = (uint)FD_LOAD( ulong, msg + 4UL*8UL );
    1964           0 :   uint  compute_units            = (uint)FD_LOAD( ulong, msg + 5UL*8UL );
    1965           0 :   ulong transaction_fee          = FD_LOAD( ulong, msg + 6UL*8UL );
    1966           0 :   ulong priority_fee             = FD_LOAD( ulong, msg + 7UL*8UL );
    1967           0 :   ulong tips                     = FD_LOAD( ulong, msg + 8UL*8UL );
    1968           0 :   ulong _parent_slot             = FD_LOAD( ulong, msg + 9UL*8UL );
    1969           0 :   ulong max_compute_units        = FD_LOAD( ulong, msg + 10UL*8UL );
    1970             : 
    1971           0 :   fd_guih_slot_t * slot = fd_guih_get_slot( gui, _slot );
    1972           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_guih_clear_slot( gui, _slot, _parent_slot );
    1973             : 
    1974           0 :   slot->completed_time = now;
    1975           0 :   slot->parent_slot = _parent_slot;
    1976           0 :   slot->max_compute_units = (uint)max_compute_units;
    1977           0 :   if( FD_LIKELY( slot->level<FD_GUIH_SLOT_LEVEL_COMPLETED ) ) {
    1978             :     /* Typically a slot goes from INCOMPLETE to COMPLETED but it can
    1979             :        happen that it starts higher.  One such case is when we
    1980             :        optimistically confirm a higher slot that skips this one, but
    1981             :        then later we replay this one anyway to track the bank fork. */
    1982             : 
    1983           0 :     if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && _slot<gui->summary.slot_optimistically_confirmed ) ) {
    1984             :       /* Cluster might have already optimistically confirmed by the time
    1985             :          we finish replaying it. */
    1986           0 :       slot->level = FD_GUIH_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
    1987           0 :     } else {
    1988           0 :       slot->level = FD_GUIH_SLOT_LEVEL_COMPLETED;
    1989           0 :     }
    1990           0 :   }
    1991             : 
    1992           0 :   slot->nonvote_success = nonvote_txn_count - nonvote_failed_txn_count;
    1993           0 :   slot->nonvote_failed  = nonvote_failed_txn_count;
    1994           0 :   slot->vote_failed     = failed_txn_count - nonvote_failed_txn_count;
    1995           0 :   slot->vote_success    = total_txn_count - nonvote_txn_count - slot->vote_failed;
    1996             : 
    1997           0 :   slot->transaction_fee        = transaction_fee;
    1998           0 :   slot->priority_fee           = priority_fee;
    1999           0 :   slot->tips                   = tips;
    2000             : 
    2001             :   /* In Frankendancer, CUs come from our own leader pipeline (the field
    2002             :      sent from the Agave codepath is zero'd out) */
    2003           0 :   slot->compute_units          = fd_uint_if( slot->mine, slot->compute_units, compute_units );
    2004             : 
    2005           0 :   if( FD_UNLIKELY( gui->epoch.has_epoch[ 0 ] && _slot==gui->epoch.epochs[ 0 ].end_slot ) ) {
    2006           0 :     gui->epoch.epochs[ 0 ].end_time = slot->completed_time;
    2007           0 :   } else if( FD_UNLIKELY( gui->epoch.has_epoch[ 1 ] && _slot==gui->epoch.epochs[ 1 ].end_slot ) ) {
    2008           0 :     gui->epoch.epochs[ 1 ].end_time = slot->completed_time;
    2009           0 :   }
    2010             : 
    2011             :   /* Broadcast new skip rate if one of our slots got completed. */
    2012           0 :   if( FD_LIKELY( slot->mine ) ) {
    2013           0 :     for( ulong i=0UL; i<2UL; i++ ) {
    2014           0 :       if( FD_LIKELY( _slot>=gui->epoch.epochs[ i ].start_slot && _slot<=gui->epoch.epochs[ i ].end_slot ) ) {
    2015           0 :         fd_guih_printf_skip_rate( gui, i );
    2016           0 :         fd_http_server_ws_broadcast( gui->http );
    2017           0 :         break;
    2018           0 :       }
    2019           0 :     }
    2020           0 :   }
    2021           0 : }
    2022             : 
    2023             : static void
    2024             : fd_guih_handle_rooted_slot_legacy( fd_guih_t *    gui,
    2025           0 :                                   uchar const * msg ) {
    2026           0 :   ulong _slot = FD_LOAD( ulong, msg );
    2027             : 
    2028             :   // FD_LOG_WARNING(( "Got rooted slot %lu", _slot ));
    2029             : 
    2030             :   /* Slot 0 is always rooted.  No need to iterate all the way back to
    2031             :      i==_slot */
    2032           0 :   for( ulong i=0UL; i<fd_ulong_min( _slot, FD_GUIH_SLOTS_CNT ); i++ ) {
    2033           0 :     ulong parent_slot = _slot - i;
    2034             : 
    2035           0 :     fd_guih_slot_t * slot = fd_guih_get_slot( gui, parent_slot );
    2036           0 :     if( FD_UNLIKELY( !slot ) ) break;
    2037             : 
    2038           0 :     if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
    2039           0 :       FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", _slot, i, parent_slot, slot->slot ));
    2040           0 :     }
    2041           0 :     if( FD_UNLIKELY( slot->level>=FD_GUIH_SLOT_LEVEL_ROOTED ) ) break;
    2042             : 
    2043           0 :     slot->level = FD_GUIH_SLOT_LEVEL_ROOTED;
    2044           0 :     fd_guih_printf_slot( gui, parent_slot );
    2045           0 :     fd_http_server_ws_broadcast( gui->http );
    2046           0 :   }
    2047             : 
    2048           0 :   gui->summary.slot_rooted = _slot;
    2049           0 :   fd_guih_printf_root_slot( gui );
    2050           0 :   fd_http_server_ws_broadcast( gui->http );
    2051           0 : }
    2052             : 
    2053             : static void
    2054             : fd_guih_handle_optimistically_confirmed_slot( fd_guih_t * gui,
    2055           0 :                                              ulong      _slot ) {
    2056             :   /* Slot 0 is always rooted.  No need to iterate all the way back to
    2057             :      i==_slot */
    2058           0 :   for( ulong i=0UL; i<fd_ulong_min( _slot, FD_GUIH_SLOTS_CNT ); i++ ) {
    2059           0 :     ulong parent_slot = _slot - i;
    2060             : 
    2061           0 :     fd_guih_slot_t * slot = fd_guih_get_slot( gui, parent_slot );
    2062           0 :     if( FD_UNLIKELY( !slot) ) break;
    2063             : 
    2064           0 :     if( FD_UNLIKELY( slot->slot>parent_slot ) ) {
    2065           0 :       FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", _slot, i, parent_slot, slot->slot ));
    2066           0 :     } else if( FD_UNLIKELY( slot->slot<parent_slot ) ) {
    2067             :       /* Slot not even replayed yet ... will come out as optimistically confirmed */
    2068           0 :       continue;
    2069           0 :     }
    2070           0 :     if( FD_UNLIKELY( slot->level>=FD_GUIH_SLOT_LEVEL_ROOTED ) ) break;
    2071             : 
    2072           0 :     if( FD_LIKELY( slot->level<FD_GUIH_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED ) ) {
    2073           0 :       slot->level = FD_GUIH_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
    2074           0 :       fd_guih_printf_slot( gui, parent_slot );
    2075           0 :       fd_http_server_ws_broadcast( gui->http );
    2076           0 :     }
    2077           0 :   }
    2078             : 
    2079           0 :   if( FD_UNLIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && _slot<gui->summary.slot_optimistically_confirmed ) ) {
    2080             :     /* Optimistically confirmed slot went backwards ... mark some slots as no
    2081             :        longer optimistically confirmed. */
    2082           0 :     for( long i_=(long)gui->summary.slot_optimistically_confirmed; i_>=(long)_slot; i_-- ) {
    2083           0 :       ulong i = (ulong)i_;
    2084           0 :       fd_guih_slot_t * slot = fd_guih_get_slot( gui, i );
    2085           0 :       if( FD_UNLIKELY( !slot ) ) break;
    2086           0 :       if( FD_LIKELY( slot->slot==i ) ) {
    2087             :         /* It's possible for the optimistically confirmed slot to skip
    2088             :            backwards between two slots that we haven't yet replayed.  In
    2089             :            that case we don't need to change anything, since they will
    2090             :            get marked properly when they get completed. */
    2091           0 :         slot->level = FD_GUIH_SLOT_LEVEL_COMPLETED;
    2092           0 :         fd_guih_printf_slot( gui, i );
    2093           0 :         fd_http_server_ws_broadcast( gui->http );
    2094           0 :       }
    2095           0 :     }
    2096           0 :   }
    2097             : 
    2098           0 :   gui->summary.slot_optimistically_confirmed = _slot;
    2099           0 :   fd_guih_printf_optimistically_confirmed_slot( gui );
    2100           0 :   fd_http_server_ws_broadcast( gui->http );
    2101           0 : }
    2102             : 
    2103             : static void
    2104             : fd_guih_handle_balance_update( fd_guih_t *    gui,
    2105           0 :                               uchar const * msg ) {
    2106           0 :   switch( FD_LOAD( ulong, msg ) ) {
    2107           0 :     case 0UL:
    2108           0 :       gui->summary.identity_account_balance = FD_LOAD( ulong, msg + 8UL );
    2109           0 :       fd_guih_printf_identity_balance( gui );
    2110           0 :       fd_http_server_ws_broadcast( gui->http );
    2111           0 :       break;
    2112           0 :     case 1UL:
    2113           0 :       gui->summary.vote_account_balance = FD_LOAD( ulong, msg + 8UL );
    2114           0 :       fd_guih_printf_vote_balance( gui );
    2115           0 :       fd_http_server_ws_broadcast( gui->http );
    2116           0 :       break;
    2117           0 :     default:
    2118           0 :       FD_LOG_ERR(( "balance: unknown account type: %lu", FD_LOAD( ulong, msg ) ));
    2119           0 :   }
    2120           0 : }
    2121             : 
    2122             : static void
    2123             : fd_guih_handle_start_progress( fd_guih_t *    gui,
    2124           0 :                               uchar const * msg ) {
    2125           0 :   uchar type = msg[ 0 ];
    2126             : 
    2127           0 :   switch (type) {
    2128           0 :     case 0:
    2129           0 :       gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_INITIALIZING;
    2130           0 :       FD_LOG_INFO(( "progress: initializing" ));
    2131           0 :       break;
    2132           0 :     case 1: {
    2133           0 :       char const * snapshot_type;
    2134           0 :       if( FD_UNLIKELY( gui->summary.startup_progress.startup_got_full_snapshot ) ) {
    2135           0 :         gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_SEARCHING_FOR_INCREMENTAL_SNAPSHOT;
    2136           0 :         snapshot_type = "incremental";
    2137           0 :       } else {
    2138           0 :         gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_SEARCHING_FOR_FULL_SNAPSHOT;
    2139           0 :         snapshot_type = "full";
    2140           0 :       }
    2141           0 :       FD_LOG_INFO(( "progress: searching for %s snapshot", snapshot_type ));
    2142           0 :       break;
    2143           0 :     }
    2144           0 :     case 2: {
    2145           0 :       uchar is_full_snapshot = msg[ 1 ];
    2146           0 :       if( FD_LIKELY( is_full_snapshot ) ) {
    2147           0 :           gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_DOWNLOADING_FULL_SNAPSHOT;
    2148           0 :           gui->summary.startup_progress.startup_full_snapshot_slot = FD_LOAD( ulong, msg + 2 );
    2149           0 :           gui->summary.startup_progress.startup_full_snapshot_peer_ip_addr = FD_LOAD( uint, msg + 10 );
    2150           0 :           gui->summary.startup_progress.startup_full_snapshot_peer_port = FD_LOAD( ushort, msg + 14 );
    2151           0 :           gui->summary.startup_progress.startup_full_snapshot_total_bytes = FD_LOAD( ulong, msg + 16 );
    2152           0 :           gui->summary.startup_progress.startup_full_snapshot_current_bytes = FD_LOAD( ulong, msg + 24 );
    2153           0 :           gui->summary.startup_progress.startup_full_snapshot_elapsed_secs = FD_LOAD( double, msg + 32 );
    2154           0 :           gui->summary.startup_progress.startup_full_snapshot_remaining_secs = FD_LOAD( double, msg + 40 );
    2155           0 :           gui->summary.startup_progress.startup_full_snapshot_throughput = FD_LOAD( double, msg + 48 );
    2156           0 :           FD_LOG_INFO(( "progress: downloading full snapshot: slot=%lu", gui->summary.startup_progress.startup_full_snapshot_slot ));
    2157           0 :       } else {
    2158           0 :           gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_DOWNLOADING_INCREMENTAL_SNAPSHOT;
    2159           0 :           gui->summary.startup_progress.startup_incremental_snapshot_slot = FD_LOAD( ulong, msg + 2 );
    2160           0 :           gui->summary.startup_progress.startup_incremental_snapshot_peer_ip_addr = FD_LOAD( uint, msg + 10 );
    2161           0 :           gui->summary.startup_progress.startup_incremental_snapshot_peer_port = FD_LOAD( ushort, msg + 14 );
    2162           0 :           gui->summary.startup_progress.startup_incremental_snapshot_total_bytes = FD_LOAD( ulong, msg + 16 );
    2163           0 :           gui->summary.startup_progress.startup_incremental_snapshot_current_bytes = FD_LOAD( ulong, msg + 24 );
    2164           0 :           gui->summary.startup_progress.startup_incremental_snapshot_elapsed_secs = FD_LOAD( double, msg + 32 );
    2165           0 :           gui->summary.startup_progress.startup_incremental_snapshot_remaining_secs = FD_LOAD( double, msg + 40 );
    2166           0 :           gui->summary.startup_progress.startup_incremental_snapshot_throughput = FD_LOAD( double, msg + 48 );
    2167           0 :           FD_LOG_INFO(( "progress: downloading incremental snapshot: slot=%lu", gui->summary.startup_progress.startup_incremental_snapshot_slot ));
    2168           0 :       }
    2169           0 :       break;
    2170           0 :     }
    2171           0 :     case 3: {
    2172           0 :       gui->summary.startup_progress.startup_got_full_snapshot = 1;
    2173           0 :       break;
    2174           0 :     }
    2175           0 :     case 4:
    2176           0 :       gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_CLEANING_BLOCK_STORE;
    2177           0 :       FD_LOG_INFO(( "progress: cleaning block store" ));
    2178           0 :       break;
    2179           0 :     case 5:
    2180           0 :       gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_CLEANING_ACCOUNTS;
    2181           0 :       FD_LOG_INFO(( "progress: cleaning accounts" ));
    2182           0 :       break;
    2183           0 :     case 6:
    2184           0 :       gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_LOADING_LEDGER;
    2185           0 :       FD_LOG_INFO(( "progress: loading ledger" ));
    2186           0 :       break;
    2187           0 :     case 7: {
    2188           0 :       gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_PROCESSING_LEDGER;
    2189           0 :       gui->summary.startup_progress.startup_ledger_slot = fd_ulong_load_8( msg + 1 );
    2190           0 :       gui->summary.startup_progress.startup_ledger_max_slot = fd_ulong_load_8( msg + 9 );
    2191           0 :       FD_LOG_INFO(( "progress: processing ledger: slot=%lu, max_slot=%lu", gui->summary.startup_progress.startup_ledger_slot, gui->summary.startup_progress.startup_ledger_max_slot ));
    2192           0 :       break;
    2193           0 :     }
    2194           0 :     case 8:
    2195           0 :       gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_STARTING_SERVICES;
    2196           0 :       FD_LOG_INFO(( "progress: starting services" ));
    2197           0 :       break;
    2198           0 :     case 9:
    2199           0 :       gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_HALTED;
    2200           0 :       FD_LOG_INFO(( "progress: halted" ));
    2201           0 :       break;
    2202           0 :     case 10: {
    2203           0 :       gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY;
    2204           0 :       gui->summary.startup_progress.startup_waiting_for_supermajority_slot = fd_ulong_load_8( msg + 1 );
    2205           0 :       gui->summary.startup_progress.startup_waiting_for_supermajority_stake_pct = fd_ulong_load_8( msg + 9 );
    2206           0 :       FD_LOG_INFO(( "progress: waiting for supermajority: slot=%lu, gossip_stake_percent=%lu", gui->summary.startup_progress.startup_waiting_for_supermajority_slot, gui->summary.startup_progress.startup_waiting_for_supermajority_stake_pct ));
    2207           0 :       break;
    2208           0 :     }
    2209           0 :     case 11:
    2210           0 :       gui->summary.startup_progress.phase = FD_GUIH_START_PROGRESS_TYPE_RUNNING;
    2211           0 :       FD_LOG_INFO(( "progress: running" ));
    2212           0 :       break;
    2213           0 :     default:
    2214           0 :       FD_LOG_ERR(( "progress: unknown type: %u", type ));
    2215           0 :   }
    2216             : 
    2217           0 :   fd_guih_printf_startup_progress( gui );
    2218           0 :   fd_http_server_ws_broadcast( gui->http );
    2219           0 : }
    2220             : 
    2221             : void
    2222             : fd_guih_handle_genesis_hash( fd_guih_t *        gui,
    2223           0 :                             fd_hash_t const * msg ) {
    2224           0 :   FD_BASE58_ENCODE_32_BYTES( msg->uc, hash_cstr );
    2225           0 :   ulong cluster = fd_genesis_cluster_identify(hash_cstr);
    2226           0 :   char const * cluster_name = fd_genesis_cluster_name(cluster);
    2227             : 
    2228           0 :   if( FD_LIKELY( strcmp( gui->summary.cluster, cluster_name ) ) ) {
    2229           0 :     gui->summary.cluster = fd_genesis_cluster_name(cluster);
    2230           0 :     fd_guih_printf_cluster( gui );
    2231           0 :     fd_http_server_ws_broadcast( gui->http );
    2232           0 :   }
    2233           0 : }
    2234             : 
    2235             : void
    2236             : fd_guih_handle_block_engine_update( fd_guih_t *                              gui,
    2237           0 :                                    fd_bundle_block_engine_update_t const * update ) {
    2238           0 :   gui->block_engine.has_block_engine = 1;
    2239             : 
    2240             :   /* copy strings and ensure null termination within bounds */
    2241           0 :   FD_TEST( fd_cstr_nlen( update->name,    sizeof(gui->block_engine.name   ) ) < sizeof(gui->block_engine.name   ) );
    2242           0 :   FD_TEST( fd_cstr_nlen( update->url,     sizeof(gui->block_engine.url    ) ) < sizeof(gui->block_engine.url    ) );
    2243           0 :   FD_TEST( fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) ) < sizeof(gui->block_engine.ip_cstr) );
    2244           0 :   ulong name_len    = fd_cstr_nlen( update->name,    sizeof(gui->block_engine.name   ) );
    2245           0 :   ulong url_len     = fd_cstr_nlen( update->url,     sizeof(gui->block_engine.url    ) );
    2246           0 :   ulong ip_cstr_len = fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) );
    2247           0 :   fd_memcpy( gui->block_engine.name,    update->name,    name_len+1UL );
    2248           0 :   fd_memcpy( gui->block_engine.url,     update->url,     url_len+1UL );
    2249           0 :   fd_memcpy( gui->block_engine.ip_cstr, update->ip_cstr, ip_cstr_len+1UL );
    2250             : 
    2251           0 :   fd_guih_printf_block_engine( gui );
    2252           0 :   fd_http_server_ws_broadcast( gui->http );
    2253           0 : }
    2254             : 
    2255             : void
    2256             : fd_guih_plugin_message( fd_guih_t *   gui,
    2257             :                        ulong        plugin_msg,
    2258             :                        void const * msg,
    2259           0 :                        long         now ) {
    2260             : 
    2261           0 :   switch( plugin_msg ) {
    2262           0 :     case FD_PLUGIN_MSG_SLOT_ROOTED:
    2263           0 :       fd_guih_handle_rooted_slot_legacy( gui, msg );
    2264           0 :       break;
    2265           0 :     case FD_PLUGIN_MSG_SLOT_OPTIMISTICALLY_CONFIRMED:
    2266           0 :       fd_guih_handle_optimistically_confirmed_slot( gui, FD_LOAD( ulong, msg ) );
    2267           0 :       break;
    2268           0 :     case FD_PLUGIN_MSG_SLOT_COMPLETED: {
    2269           0 :       fd_guih_handle_completed_slot( gui, msg, now );
    2270           0 :       break;
    2271           0 :     }
    2272           0 :     case FD_PLUGIN_MSG_LEADER_SCHEDULE: {
    2273           0 :       FD_STATIC_ASSERT( sizeof(fd_stake_weight_msg_t)==6*sizeof(ulong), "new fields breaks things" );
    2274           0 :       fd_guih_handle_leader_schedule( gui, (fd_stake_weight_msg_t *)msg, now );
    2275           0 :       break;
    2276           0 :     }
    2277           0 :     case FD_PLUGIN_MSG_SLOT_START: {
    2278           0 :       ulong slot = FD_LOAD( ulong, msg );
    2279           0 :       ulong parent_slot = FD_LOAD( ulong, (uchar const *)msg + 8UL );
    2280           0 :       fd_guih_handle_slot_start( gui, slot, parent_slot, now );
    2281           0 :       break;
    2282           0 :     }
    2283           0 :     case FD_PLUGIN_MSG_SLOT_END: {
    2284           0 :       ulong slot = FD_LOAD( ulong, msg );
    2285           0 :       ulong cus_used = FD_LOAD( ulong, (uchar const *)msg + 8UL );
    2286           0 :       fd_guih_handle_slot_end( gui, slot, cus_used, now );
    2287           0 :       break;
    2288           0 :     }
    2289           0 :     case FD_PLUGIN_MSG_GOSSIP_UPDATE: {
    2290           0 :       fd_guih_handle_gossip_update( gui, msg );
    2291           0 :       break;
    2292           0 :     }
    2293           0 :     case FD_PLUGIN_MSG_VOTE_ACCOUNT_UPDATE: {
    2294           0 :       fd_guih_handle_vote_account_update( gui, msg );
    2295           0 :       break;
    2296           0 :     }
    2297           0 :     case FD_PLUGIN_MSG_VALIDATOR_INFO: {
    2298           0 :       fd_guih_handle_validator_info_update( gui, msg );
    2299           0 :       break;
    2300           0 :     }
    2301           0 :     case FD_PLUGIN_MSG_SLOT_RESET: {
    2302           0 :       fd_guih_handle_reset_slot_legacy( gui, msg, now );
    2303           0 :       break;
    2304           0 :     }
    2305           0 :     case FD_PLUGIN_MSG_BALANCE: {
    2306           0 :       fd_guih_handle_balance_update( gui, msg );
    2307           0 :       break;
    2308           0 :     }
    2309           0 :     case FD_PLUGIN_MSG_START_PROGRESS: {
    2310           0 :       fd_guih_handle_start_progress( gui, msg );
    2311           0 :       break;
    2312           0 :     }
    2313           0 :     case FD_PLUGIN_MSG_GENESIS_HASH_KNOWN: {
    2314           0 :       fd_guih_handle_genesis_hash( gui, msg );
    2315           0 :       break;
    2316           0 :     }
    2317           0 :     default:
    2318           0 :       FD_LOG_ERR(( "Unhandled plugin msg: 0x%lx", plugin_msg ));
    2319           0 :       break;
    2320           0 :   }
    2321           0 : }
    2322             : 
    2323             : void
    2324             : fd_guih_became_leader( fd_guih_t * gui,
    2325             :                       ulong      _slot,
    2326             :                       long       start_time_nanos,
    2327             :                       long       end_time_nanos,
    2328             :                       ulong      max_compute_units,
    2329           0 :                       ulong      max_microblocks ) {
    2330           0 :   fd_guih_slot_t * slot = fd_guih_get_slot( gui, _slot );
    2331           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_guih_clear_slot( gui, _slot, ULONG_MAX );
    2332           0 :   fd_guih_leader_slot_t * lslot = fd_guih_get_leader_slot( gui, _slot );
    2333           0 :   if( FD_UNLIKELY( !lslot ) ) return;
    2334             : 
    2335           0 :   slot->max_compute_units = (uint)max_compute_units;
    2336           0 :   lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, start_time_nanos, lslot->leader_start_time );
    2337           0 :   lslot->leader_end_time   = end_time_nanos;
    2338           0 :   lslot->max_microblocks   = max_microblocks;
    2339           0 :   if( FD_LIKELY( lslot->txs.microblocks_upper_bound==UINT_MAX ) ) lslot->txs.microblocks_upper_bound = (uint)max_microblocks;
    2340           0 : }
    2341             : 
    2342             : void
    2343             : fd_guih_unbecame_leader( fd_guih_t *                gui,
    2344             :                         ulong                     _slot,
    2345             :                         fd_done_packing_t const * done_packing,
    2346           0 :                         long                      now FD_PARAM_UNUSED ) {
    2347           0 :   fd_guih_slot_t * slot = fd_guih_get_slot( gui, _slot );
    2348           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_guih_clear_slot( gui, _slot, ULONG_MAX );
    2349           0 :   fd_guih_leader_slot_t * lslot = fd_guih_get_leader_slot( gui, _slot );
    2350           0 :   if( FD_LIKELY( !lslot ) ) return;
    2351           0 :   lslot->txs.microblocks_upper_bound = (uint)done_packing->microblocks_in_slot;
    2352           0 :   fd_memcpy( lslot->scheduler_stats, done_packing, sizeof(fd_done_packing_t) );
    2353             : 
    2354           0 :   lslot->unbecame_leader = 1;
    2355           0 : }
    2356             : 
    2357             : void
    2358             : fd_guih_microblock_execution_begin( fd_guih_t *   gui,
    2359             :                                    long         tspub_ns,
    2360             :                                    ulong        _slot,
    2361             :                                    fd_txn_e_t * txns,
    2362             :                                    ulong        txn_cnt,
    2363             :                                    uint         microblock_idx,
    2364           0 :                                    ulong        pack_txn_idx ) {
    2365           0 :   fd_guih_slot_t * slot = fd_guih_get_slot( gui, _slot );
    2366           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_guih_clear_slot( gui, _slot, ULONG_MAX );
    2367             : 
    2368           0 :   fd_guih_leader_slot_t * lslot = fd_guih_get_leader_slot( gui, _slot );
    2369           0 :   if( FD_UNLIKELY( !lslot ) ) return;
    2370             : 
    2371           0 :   lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, tspub_ns, lslot->leader_start_time );
    2372             : 
    2373           0 :   if( FD_UNLIKELY( lslot->txs.start_offset==ULONG_MAX ) ) lslot->txs.start_offset = pack_txn_idx;
    2374           0 :   else                                                    lslot->txs.start_offset = fd_ulong_min( lslot->txs.start_offset, pack_txn_idx );
    2375             : 
    2376           0 :   gui->pack_txn_idx = fd_ulong_max( gui->pack_txn_idx, pack_txn_idx+txn_cnt-1UL );
    2377             : 
    2378           0 :   for( ulong i=0UL; i<txn_cnt; i++ ) {
    2379           0 :     fd_txn_p_t * txn_payload = txns[ i ].txnp;
    2380           0 :     fd_txn_t * txn = TXN( txn_payload );
    2381             : 
    2382           0 :     ulong sig_rewards = FD_PACK_FEE_PER_SIGNATURE * txn->signature_cnt;
    2383           0 :     ulong priority_rewards                    = ULONG_MAX;
    2384           0 :     ulong requested_execution_cus             = ULONG_MAX;
    2385           0 :     ulong precompile_sigs                     = ULONG_MAX;
    2386           0 :     ulong requested_loaded_accounts_data_cost = ULONG_MAX;
    2387           0 :     ulong allocated_data                      = ULONG_MAX;
    2388           0 :     uint _flags = 0U;
    2389           0 :     ulong cost_estimate = fd_pack_compute_cost( txn, txn_payload->payload, &_flags, &requested_execution_cus, &priority_rewards, &precompile_sigs, &requested_loaded_accounts_data_cost, &allocated_data );
    2390           0 :     sig_rewards += FD_PACK_FEE_PER_SIGNATURE * precompile_sigs;
    2391           0 :     sig_rewards = sig_rewards * FD_PACK_TXN_FEE_BURN_PCT / 100UL;
    2392             : 
    2393           0 :     fd_guih_txn_t * txn_entry = gui->txs[ (pack_txn_idx + i)%FD_GUIH_TXN_HISTORY_SZ ];
    2394             : 
    2395             :     /* If execution_end already ran for this txn, the arrival timestamp
    2396             :        it stamped will match.  Preserve all existing flags. Otherwise
    2397             :        the entry is stale from a ring buffer wrap-around, so clear all
    2398             :        flags. */
    2399           0 :     if( FD_LIKELY( txn_entry->timestamp_arrival_nanos!=txn_payload->scheduler_arrival_time_nanos ) ) txn_entry->flags = (uchar)0;
    2400             : 
    2401           0 :     fd_memcpy( txn_entry->signature, txn_payload->payload + txn->signature_off, FD_SHA512_HASH_SZ );
    2402           0 :     txn_entry->timestamp_arrival_nanos     = txn_payload->scheduler_arrival_time_nanos;
    2403           0 :     txn_entry->compute_units_requested     = cost_estimate & 0x1FFFFFU;
    2404           0 :     txn_entry->priority_fee                = priority_rewards;
    2405           0 :     txn_entry->transaction_fee             = sig_rewards;
    2406           0 :     txn_entry->microblock_start_ns_dt      = (float)(tspub_ns - lslot->leader_start_time);
    2407           0 :     txn_entry->source_ipv4                 = txn_payload->source_ipv4;
    2408           0 :     txn_entry->source_tpu                  = txn_payload->source_tpu;
    2409           0 :     txn_entry->microblock_idx              = microblock_idx;
    2410           0 :     txn_entry->flags                      |= (uchar)FD_GUIH_TXN_FLAGS_STARTED;
    2411           0 :     txn_entry->flags                      |= (uchar)fd_uint_if( !!(txn_payload->flags & FD_TXN_P_FLAGS_IS_SIMPLE_VOTE), FD_GUIH_TXN_FLAGS_IS_SIMPLE_VOTE, 0U );
    2412           0 :     txn_entry->flags                      |= (uchar)fd_uint_if( (txn_payload->flags & FD_TXN_P_FLAGS_BUNDLE) || (txn_payload->flags & FD_TXN_P_FLAGS_INITIALIZER_BUNDLE), FD_GUIH_TXN_FLAGS_FROM_BUNDLE, 0U );
    2413           0 :   }
    2414             : 
    2415             :   /* At the moment, bank publishes at most 1 transaction per microblock,
    2416             :      even if it received microblocks with multiple transactions
    2417             :      (i.e. a bundle). This means that we need to calculate microblock
    2418             :      count here based on the transaction count. */
    2419           0 :   lslot->txs.begin_microblocks += (uint)txn_cnt;
    2420           0 : }
    2421             : 
    2422             : void
    2423             : fd_guih_microblock_execution_end( fd_guih_t *     gui,
    2424             :                                  long           tspub_ns,
    2425             :                                  ulong          bank_idx,
    2426             :                                  ulong          _slot,
    2427             :                                  ulong          txn_cnt,
    2428             :                                  fd_txn_p_t *   txns,
    2429             :                                  ulong          pack_txn_idx,
    2430             :                                  fd_txn_ns_dt_t txn_ns_dt,
    2431           0 :                                  ulong          tips ) {
    2432           0 :   if( FD_UNLIKELY( 1UL!=txn_cnt ) ) FD_LOG_ERR(( "gui expects 1 txn per microblock from bank, found %lu", txn_cnt ));
    2433             : 
    2434           0 :   fd_guih_slot_t * slot = fd_guih_get_slot( gui, _slot );
    2435           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_guih_clear_slot( gui, _slot, ULONG_MAX );
    2436             : 
    2437           0 :   fd_guih_leader_slot_t * lslot = fd_guih_get_leader_slot( gui, _slot );
    2438           0 :   if( FD_UNLIKELY( !lslot ) ) return;
    2439             : 
    2440           0 :   lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, tspub_ns, lslot->leader_start_time );
    2441             : 
    2442           0 :   if( FD_UNLIKELY( lslot->txs.end_offset==ULONG_MAX ) ) lslot->txs.end_offset = pack_txn_idx + txn_cnt;
    2443           0 :   else                                                  lslot->txs.end_offset = fd_ulong_max( lslot->txs.end_offset, pack_txn_idx+txn_cnt );
    2444             : 
    2445           0 :   gui->pack_txn_idx = fd_ulong_max( gui->pack_txn_idx, pack_txn_idx+txn_cnt-1UL );
    2446             : 
    2447           0 :   for( ulong i=0UL; i<txn_cnt; i++ ) {
    2448           0 :     fd_txn_p_t * txn_p = &txns[ i ];
    2449             : 
    2450           0 :     fd_guih_txn_t * txn_entry = gui->txs[ (pack_txn_idx + i)%FD_GUIH_TXN_HISTORY_SZ ];
    2451             : 
    2452             :     /* If execution_begin already ran for this txn, the arrival
    2453             :        timestamp it stamped will match.  Preserve all existing flags.
    2454             :        Otherwise the entry is stale from a ring buffer wrap-around, so
    2455             :        clear all flags. */
    2456           0 :     if( FD_UNLIKELY( txn_entry->timestamp_arrival_nanos!=txn_p->scheduler_arrival_time_nanos ) ) txn_entry->flags = (uchar)0;
    2457             : 
    2458           0 :     txn_entry->timestamp_arrival_nanos   = txn_p->scheduler_arrival_time_nanos;
    2459           0 :     txn_entry->bank_idx                  = bank_idx                             & 0x3FU;
    2460           0 :     txn_entry->compute_units_consumed    = txn_p->execle_cu.actual_consumed_cus & 0x1FFFFFU;
    2461           0 :     txn_entry->error_code                = (txn_p->flags >> 24)                 & 0x3FU;
    2462           0 :     txn_entry->microblock_end_ns_dt      = (float)(tspub_ns - lslot->leader_start_time);
    2463           0 :     txn_entry->txn_ns_dt                 = txn_ns_dt;
    2464           0 :     txn_entry->tips                      = tips;
    2465           0 :     txn_entry->flags                    |= (uchar)FD_GUIH_TXN_FLAGS_ENDED;
    2466           0 :     txn_entry->flags                    &= (uchar)(~(uchar)FD_GUIH_TXN_FLAGS_LANDED_IN_BLOCK);
    2467           0 :     txn_entry->flags                    |= (uchar)fd_uint_if( !!(txn_p->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS), FD_GUIH_TXN_FLAGS_LANDED_IN_BLOCK, 0U );
    2468           0 :   }
    2469             : 
    2470           0 :   lslot->txs.end_microblocks = lslot->txs.end_microblocks + (uint)txn_cnt;
    2471           0 : }

Generated by: LCOV version 1.14