LCOV - code coverage report
Current view: top level - disco/gui - fd_gui.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 74 2645 2.8 %
Date: 2026-09-11 04:29:08 Functions: 5 79 6.3 %

          Line data    Source code
       1             : #include "fd_gui.h"
       2             : #include "fd_gui_printf.h"
       3             : #include "fd_gui_metrics.h"
       4             : #include "fd_gui_hist.h"
       5             : 
       6             : #include "../metrics/fd_metrics.h"
       7             : #include "../../discof/gossip/fd_gossip_tile.h"
       8             : #include "../bundle/fd_bundle_tile.h"
       9             : 
      10             : #include "../../ballet/base58/fd_base58.h"
      11             : #include "../../third_party/cjson/cJSON.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             : #include "../../choreo/tower/fd_tower_serdes.h"
      16             : 
      17             : #include <stdio.h>
      18             : 
      19             : FD_FN_CONST ulong
      20         189 : fd_gui_align( void ) {
      21         189 :   return 128UL;
      22         189 : }
      23             : 
      24             : ulong
      25             : fd_gui_footprint( ulong tile_cnt,
      26             :                   ulong max_live_slots,
      27          42 :                   ulong max_txn_per_slot ) {
      28          42 :   FD_TEST( tile_cnt && tile_cnt <=FD_DIAG_SYSTEM_TILE_MAX );
      29          42 :   FD_TEST( max_live_slots && max_live_slots<=ULONG_MAX/sizeof(fd_gui_ag_slot_t) );
      30          42 :   FD_TEST( max_txn_per_slot && max_txn_per_slot<=ULONG_MAX/sizeof(fd_gui_store_txn_start_t) );
      31             : 
      32          42 :   ulong l = FD_LAYOUT_INIT;
      33          42 :   l = FD_LAYOUT_APPEND( l, fd_gui_align(),                     sizeof(fd_gui_t) );
      34          42 :   l = FD_LAYOUT_APPEND( l, alignof(fd_gui_ag_slot_t),         max_live_slots*sizeof(fd_gui_ag_slot_t) );
      35          42 :   l = FD_LAYOUT_APPEND( l, fd_gui_rate_deque_align(),         fd_gui_rate_deque_footprint() ); /* ingress_maxq */
      36          42 :   l = FD_LAYOUT_APPEND( l, fd_gui_rate_deque_align(),         fd_gui_rate_deque_footprint() ); /* egress_maxq  */
      37          42 :   l = FD_LAYOUT_APPEND( l, fd_gui_hist_align(),               fd_gui_hist_footprint() );
      38          42 :   l = FD_LAYOUT_APPEND( l, alignof(fd_gui_store_txn_start_t), max_txn_per_slot*sizeof(fd_gui_store_txn_start_t) );
      39          42 :   l = FD_LAYOUT_APPEND( l, alignof(fd_gui_store_txn_end_t),   max_txn_per_slot*sizeof(fd_gui_store_txn_end_t)   );
      40          42 :   l = FD_LAYOUT_APPEND( l, alignof(fd_gui_slot_txn_join_t),   max_txn_per_slot*sizeof(fd_gui_slot_txn_join_t)   );
      41          42 :   return FD_LAYOUT_FINI( l, fd_gui_align() );
      42          42 : }
      43             : 
      44             : static inline int
      45             : fd_gui_shreds_window_is_empty( fd_gui_t * gui,
      46             :                                long       after_ns,
      47           0 :                                long       before_ns ) {
      48           0 :   if( FD_UNLIKELY( !gui->db ) ) return 1;
      49             : 
      50           0 :   fd_gui_hist_iter_t it;
      51           0 :   if( FD_UNLIKELY( fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_SHRED_EVENTS, after_ns, before_ns, NULL, NULL ) ) ) return 1;
      52           0 :   while( fd_gui_hist_range_next( &it ) ) {
      53           0 :     fd_gui_slot_history_shred_event_t const * e = (fd_gui_slot_history_shred_event_t const *)it.rec;
      54           0 :     if( FD_UNLIKELY( e->timestamp<after_ns || e->timestamp>before_ns ) ) continue;
      55           0 :     fd_gui_hist_range_end( &it );
      56           0 :     return 0;
      57           0 :   }
      58           0 :   fd_gui_hist_range_end( &it );
      59           0 :   return 1;
      60           0 : }
      61             : 
      62             : static inline void
      63           0 : fd_gui_build_tile_order( fd_gui_t * gui ) {
      64           0 :   ulong tile_cnt   = gui->topo->tile_cnt;
      65           0 :   ulong order_cnt  = 0UL;
      66           0 :   uchar placed[ FD_DIAG_SYSTEM_TILE_MAX ] = {0};
      67             : 
      68           0 :   char const * const tile_display_order[] = {
      69           0 :     "gossvf", "gossip", "snapct", "snapld", "snapdc", "snapin", "snapwr",
      70           0 :     "net", "shred", "repair", "rotor", "replay", "execrp", "tower", "votor", "txsend", "sign",
      71           0 :     "quic", "verify", "dedup", "pack", "execle", "poh"
      72           0 :   };
      73             : 
      74           0 :   for( ulong n=0UL; n<sizeof(tile_display_order)/sizeof(tile_display_order[0]); n++ ) {
      75           0 :     for( ulong i=0UL; i<tile_cnt; i++ ) {
      76           0 :       if( FD_LIKELY( placed[ i ] ) ) continue;
      77           0 :       if( FD_UNLIKELY( !strcmp( gui->topo->tiles[ i ].name, tile_display_order[ n ] ) ) ) {
      78           0 :         gui->summary.tile[ order_cnt++ ] = i;
      79           0 :         placed[ i ] = 1;
      80           0 :       }
      81           0 :     }
      82           0 :   }
      83             : 
      84           0 :   for( ulong i=0UL; i<tile_cnt; i++ ) {
      85           0 :     if( FD_UNLIKELY( !placed[ i ] ) ) gui->summary.tile[ order_cnt++ ] = i;
      86           0 :   }
      87             : 
      88           0 :   gui->summary.tile_cnt = order_cnt;
      89           0 : }
      90             : 
      91             : void *
      92             : fd_gui_new( void *                   shmem,
      93             :             fd_http_server_t *       http,
      94             :             char const *             version,
      95             :             char const *             cluster,
      96             :             uchar const *            identity_key,
      97             :             int                      has_vote_key,
      98             :             uchar const *            vote_key,
      99             :             int                      is_full_client,
     100             :             int                      is_alpenglow,
     101             :             ulong                    max_live_slots,
     102             :             ulong                    max_txn_per_slot,
     103             :             int                      snapshots_enabled,
     104             :             int                      is_voting,
     105             :             int                      schedule_strategy,
     106             :             char const *             wfs_expected_bank_hash_cstr,
     107             :             ushort                   expected_shred_version,
     108             :             char const *             accounts_database_path,
     109             :             char const *             gui_database_path,
     110             :             void *                   db,
     111             :             fd_topo_t const *        topo,
     112             :             fd_accdb_shmem_t const * accdb_shmem,
     113           0 :             long                     now ) {
     114             : 
     115           0 :   if( FD_UNLIKELY( !shmem ) ) {
     116           0 :     FD_LOG_WARNING(( "NULL shmem" ));
     117           0 :     return NULL;
     118           0 :   }
     119             : 
     120           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmem, fd_gui_align() ) ) ) {
     121           0 :     FD_LOG_WARNING(( "misaligned shmem" ));
     122           0 :     return NULL;
     123           0 :   }
     124             : 
     125           0 :   if( FD_UNLIKELY( topo->tile_cnt>FD_DIAG_SYSTEM_TILE_MAX ) ) {
     126           0 :     FD_LOG_WARNING(( "too many tiles" ));
     127           0 :     return NULL;
     128           0 :   }
     129             : 
     130           0 :   ulong tile_cnt = topo->tile_cnt;
     131             : 
     132           0 :   FD_SCRATCH_ALLOC_INIT( l, shmem );
     133           0 :   fd_gui_t * gui              = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(),                    sizeof(fd_gui_t) );
     134           0 :   void *     ag_slot_mem      = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_ag_slot_t),         max_live_slots*sizeof(fd_gui_ag_slot_t) );
     135           0 :   void *     ingress_maxq_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_rate_deque_align(),         fd_gui_rate_deque_footprint() );
     136           0 :   void *     egress_maxq_mem  = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_rate_deque_align(),         fd_gui_rate_deque_footprint() );
     137           0 :   void *     hist_mem         = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_hist_align(),               fd_gui_hist_footprint() );
     138           0 :   void *     txn_starts_mem   = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_store_txn_start_t), max_txn_per_slot*sizeof(fd_gui_store_txn_start_t) );
     139           0 :   void *     txn_ends_mem     = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_store_txn_end_t),   max_txn_per_slot*sizeof(fd_gui_store_txn_end_t)   );
     140           0 :   void *     txn_joined_mem   = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_slot_txn_join_t),   max_txn_per_slot*sizeof(fd_gui_slot_txn_join_t)   );
     141             : 
     142           0 :   gui->slot_txn_scratch.max    = max_txn_per_slot;
     143           0 :   gui->slot_txn_scratch.starts = txn_starts_mem;
     144           0 :   gui->slot_txn_scratch.ends   = txn_ends_mem;
     145           0 :   gui->slot_txn_scratch.joined = txn_joined_mem;
     146             : 
     147           0 :   gui->http        = http;
     148           0 :   gui->topo        = topo;
     149           0 :   gui->accdb_shmem = accdb_shmem;
     150           0 :   gui->tick_per_ns = fd_tempo_tick_per_ns( NULL );
     151           0 :   gui->tile_cnt    = tile_cnt;
     152             : 
     153           0 :   gui->db   = db;
     154           0 :   gui->hist = fd_gui_hist_join( fd_gui_hist_new( hist_mem, (fd_gui_store_t const *)db ) );
     155           0 :   if( FD_UNLIKELY( !gui->hist ) ) {
     156           0 :     FD_LOG_WARNING(( "fd_gui_hist_new failed" ));
     157           0 :     return NULL;
     158           0 :   }
     159             : 
     160           0 :   gui->summary.ingress_maxq = fd_gui_rate_deque_join( fd_gui_rate_deque_new( ingress_maxq_mem ) );
     161           0 :   gui->summary.egress_maxq  = fd_gui_rate_deque_join( fd_gui_rate_deque_new( egress_maxq_mem  ) );
     162             : 
     163           0 :   gui->summary.network_stats_has_prev = 0;
     164           0 :   gui->summary.net_rate_prev_ts       = 0L;
     165           0 :   for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) {
     166           0 :     fd_gui_ema_init( &gui->summary.ingress_ema[ i ], now, FD_GUI_NETWORK_EMA_HALF_LIFE_NS );
     167           0 :     fd_gui_ema_init( &gui->summary.egress_ema [ i ], now, FD_GUI_NETWORK_EMA_HALF_LIFE_NS );
     168           0 :   }
     169             : 
     170           0 :   gui->leader_active = 0;
     171           0 :   gui->leader_slot_pending     = ULONG_MAX;
     172           0 :   gui->leader_bank_seq_pending = ULONG_MAX;
     173             : 
     174           0 :   gui->system.valid  = 0;
     175             : 
     176           0 :   gui->summary.slot_tower  = ULONG_MAX;
     177           0 :   gui->summary.slot_tower_bank_seq = ULONG_MAX;
     178           0 :   gui->summary.schedule_strategy = schedule_strategy;
     179             : 
     180             : 
     181           0 :   gui->next_sample_1sec      = now;
     182           0 :   gui->next_sample_200millis = now;
     183           0 :   gui->next_sample_100millis = now;
     184           0 :   gui->next_sample_50millis  = now;
     185           0 :   gui->next_sample_40millis  = now;
     186           0 :   gui->next_sample_25millis  = now;
     187           0 :   gui->next_sample_10millis  = now;
     188             : 
     189           0 :   memcpy( gui->summary.identity_key->uc, identity_key, 32UL );
     190           0 :   fd_base58_encode_32( identity_key, NULL, gui->summary.identity_key_base58 );
     191           0 :   gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
     192             : 
     193           0 :   if( FD_LIKELY( has_vote_key ) ) {
     194           0 :     gui->summary.has_vote_key = 1;
     195           0 :     memcpy( gui->summary.vote_key->uc, vote_key, 32UL );
     196           0 :     fd_base58_encode_32( vote_key, NULL, gui->summary.vote_key_base58 );
     197           0 :     gui->summary.vote_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
     198           0 :   } else {
     199           0 :     gui->summary.has_vote_key = 0;
     200           0 :     memset( gui->summary.vote_key_base58, 0, sizeof(gui->summary.vote_key_base58) );
     201           0 :   }
     202             : 
     203           0 :   gui->summary.is_full_client                = is_full_client;
     204           0 :   gui->summary.is_alpenglow                  = is_alpenglow;
     205           0 :   gui->summary.version                       = version;
     206           0 :   gui->summary.cluster                       = cluster;
     207           0 :   fd_cstr_ncpy( gui->summary.accounts_database_path, accounts_database_path, sizeof(gui->summary.accounts_database_path) );
     208           0 :   fd_cstr_ncpy( gui->summary.gui_database_path, gui_database_path, sizeof(gui->summary.gui_database_path) );
     209           0 :   gui->summary.startup_time_nanos            = gui->next_sample_200millis;
     210           0 :   gui->summary.expected_shred_version        = expected_shred_version;
     211           0 :   gui->summary.wfs_enabled          = 0;
     212           0 :   gui->summary.wfs_bank_hash[ 0UL ] = '\0';
     213             : 
     214           0 :   {
     215           0 :     fd_cstr_ncpy( gui->summary.wfs_bank_hash, wfs_expected_bank_hash_cstr, sizeof(gui->summary.wfs_bank_hash) );
     216           0 :     gui->summary.wfs_enabled = !!strcmp( wfs_expected_bank_hash_cstr, "" );
     217             : 
     218           0 :     if( FD_UNLIKELY( snapshots_enabled ) ) {
     219           0 :       gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP;
     220           0 :       gui->summary.boot_progress.joining_gossip_time_nanos = gui->next_sample_200millis;
     221           0 :       memset( gui->summary.boot_progress.loading_snapshot, 0, sizeof(gui->summary.boot_progress.loading_snapshot) );
     222           0 :       for( ulong i=0UL; i<FD_GUI_BOOT_PROGRESS_SNAPSHOT_CNT; i++ ) {
     223           0 :         gui->summary.boot_progress.loading_snapshot[ i ].reset_cnt = ULONG_MAX; /* ensures other fields are reset initially */
     224           0 :         gui->summary.boot_progress.loading_snapshot[ i ].slot = ULONG_MAX;
     225           0 :       }
     226           0 :       gui->summary.boot_progress.catching_up_time_nanos        = 0L;
     227           0 :       gui->summary.boot_progress.catching_up_first_replay_slot = ULONG_MAX;
     228           0 :       gui->summary.boot_progress.wfs_total_stake     = 0UL;
     229           0 :       gui->summary.boot_progress.wfs_connected_stake = 0UL;
     230           0 :       gui->summary.boot_progress.wfs_total_peers     = 0UL;
     231           0 :       gui->summary.boot_progress.wfs_connected_peers = 0UL;
     232           0 :       gui->summary.boot_progress.wfs_attempt         = 0UL;
     233           0 :     } else {
     234           0 :       fd_memset( &gui->summary.boot_progress, 0, sizeof(gui->summary.boot_progress) );
     235           0 :       gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
     236           0 :     }
     237           0 :   }
     238             : 
     239           0 :   gui->summary.identity_account_balance      = 0UL;
     240           0 :   gui->summary.vote_account_balance          = 0UL;
     241           0 :   gui->summary.vote_commission               = USHORT_MAX;
     242           0 :   gui->summary.estimated_slot_duration_nanos = 0UL;
     243             : 
     244           0 :   gui->summary.vote_distance = 0UL;
     245           0 :   gui->summary.vote_state = is_voting ? FD_GUI_VOTE_STATE_VOTING : FD_GUI_VOTE_STATE_NON_VOTING;
     246             : 
     247           0 :   gui->summary.sock_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "sock"   );
     248           0 :   gui->summary.mlx5_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "mlx5"   );
     249           0 :   gui->summary.net_tile_cnt    = fd_topo_tile_name_cnt( gui->topo, "net"    );
     250           0 :   gui->summary.quic_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "quic"   );
     251           0 :   gui->summary.verify_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "verify" );
     252           0 :   gui->summary.resolh_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolh" );
     253           0 :   gui->summary.resolv_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolv" );
     254           0 :   gui->summary.bank_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "bank"   );
     255           0 :   gui->summary.execle_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "execle" );
     256           0 :   gui->summary.execrp_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "execrp" );
     257           0 :   gui->summary.shred_tile_cnt  = fd_topo_tile_name_cnt( gui->topo, "shred"  );
     258             : 
     259           0 :   fd_gui_build_tile_order( gui );
     260             : 
     261           0 :   gui->summary.slot_rooted                   = ULONG_MAX;
     262           0 :   gui->summary.slot_finalized                = ULONG_MAX;
     263           0 :   gui->summary.slot_notarized                = ULONG_MAX;
     264           0 :   gui->summary.slot_optimistically_confirmed = ULONG_MAX;
     265           0 :   gui->summary.slot_estimated                = ULONG_MAX;
     266           0 :   gui->summary.slot_caught_up                = ULONG_MAX;
     267           0 :   gui->summary.slot_repair                   = ULONG_MAX;
     268           0 :   gui->summary.slot_turbine                  = ULONG_MAX;
     269           0 :   gui->summary.slot_reset                    = ULONG_MAX;
     270           0 :   gui->summary.slot_storage                  = ULONG_MAX;
     271           0 :   gui->summary.slot_voted                    = ULONG_MAX;
     272           0 :   gui->summary.active_fork_cnt               = 1UL;
     273             : 
     274           0 :   gui->ag.slot_cnt = max_live_slots;
     275           0 :   gui->ag.slot     = (fd_gui_ag_slot_t *)ag_slot_mem;
     276           0 :   memset( gui->ag.slot, 0, max_live_slots*sizeof(fd_gui_ag_slot_t) );
     277           0 :   for( ulong i=0UL; i<gui->ag.slot_cnt; i++ ) {
     278           0 :     gui->ag.slot[ i ].slot     = ULONG_MAX;
     279           0 :     gui->ag.slot[ i ].bank_seq = ULONG_MAX;
     280           0 :   }
     281             : 
     282           0 :   memset( gui->summary.skip_rate, 0, sizeof(gui->summary.skip_rate) );
     283           0 :   gui->summary.skip_rate[ 0 ].epoch = ULONG_MAX;
     284           0 :   gui->summary.skip_rate[ 1 ].epoch = ULONG_MAX;
     285             : 
     286           0 :   for( ulong i=0UL; i < (FD_GUI_REPAIR_SLOT_HISTORY_SZ+1UL); i++ )  gui->summary.slots_max_repair[ i ].slot  = ULONG_MAX;
     287           0 :   for( ulong i=0UL; i < (FD_GUI_TURBINE_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_turbine[ i ].slot = ULONG_MAX;
     288             : 
     289           0 :   for( ulong i=0UL; i < FD_GUI_TURBINE_RECV_TIMESTAMPS; i++ ) gui->turbine_slots[ i ].slot = ULONG_MAX;
     290             : 
     291           0 :   gui->summary.estimated_tps_history_idx = 0UL;
     292           0 :   memset( gui->summary.estimated_tps_history, 0, sizeof(gui->summary.estimated_tps_history) );
     293             : 
     294           0 :   memset( gui->summary.txn_waterfall_reference, 0, sizeof(gui->summary.txn_waterfall_reference) );
     295           0 :   memset( gui->summary.txn_waterfall_current,   0, sizeof(gui->summary.txn_waterfall_current)   );
     296             : 
     297           0 :   memset( gui->summary.tile_stats_reference, 0, sizeof(gui->summary.tile_stats_reference) );
     298           0 :   memset( gui->summary.tile_stats_current, 0, sizeof(gui->summary.tile_stats_current) );
     299             : 
     300           0 :   gui->summary.progcache_history_idx = 0UL;
     301           0 :   memset( gui->summary.progcache_hits_history,    0, sizeof(gui->summary.progcache_hits_history) );
     302           0 :   memset( gui->summary.progcache_lookups_history, 0, sizeof(gui->summary.progcache_lookups_history) );
     303           0 :   gui->summary.progcache_hits_1min    = 0UL;
     304           0 :   gui->summary.progcache_lookups_1min = 0UL;
     305             : 
     306           0 :   memset( gui->summary.accounts_stats_reference, 0, sizeof(gui->summary.accounts_stats_reference) );
     307           0 :   memset( gui->summary.accounts_stats_current,   0, sizeof(gui->summary.accounts_stats_current  ) );
     308           0 :   gui->summary.accounts_stats_have_reference = 0;
     309           0 :   gui->summary.accdb->accdb_win_idx   = 0UL;
     310           0 :   gui->summary.accdb->accdb_win_count = 0UL;
     311           0 :   memset( gui->summary.accdb->accdb_win_dt_nanos,           0, sizeof(gui->summary.accdb->accdb_win_dt_nanos)           );
     312           0 :   memset( gui->summary.accdb->agg_acquired_win,             0, sizeof(gui->summary.accdb->agg_acquired_win)             );
     313           0 :   memset( gui->summary.accdb->agg_acquired_writable_win,    0, sizeof(gui->summary.accdb->agg_acquired_writable_win)    );
     314           0 :   memset( gui->summary.accdb->agg_bytes_read_win,           0, sizeof(gui->summary.accdb->agg_bytes_read_win)           );
     315           0 :   memset( gui->summary.accdb->agg_bytes_copied_win,         0, sizeof(gui->summary.accdb->agg_bytes_copied_win)         );
     316           0 :   memset( gui->summary.accdb->agg_bytes_written_win,        0, sizeof(gui->summary.accdb->agg_bytes_written_win)        );
     317           0 :   memset( gui->summary.accdb->agg_bytes_written_accdb_win,  0, sizeof(gui->summary.accdb->agg_bytes_written_accdb_win)  );
     318           0 :   memset( gui->summary.accdb->agg_read_ops_win,             0, sizeof(gui->summary.accdb->agg_read_ops_win)             );
     319           0 :   memset( gui->summary.accdb->agg_write_ops_win,            0, sizeof(gui->summary.accdb->agg_write_ops_win)            );
     320           0 :   memset( gui->summary.accdb->agg_relocated_bytes_win,      0, sizeof(gui->summary.accdb->agg_relocated_bytes_win)      );
     321           0 :   memset( gui->summary.accdb->agg_misses_win,               0, sizeof(gui->summary.accdb->agg_misses_win)               );
     322           0 :   memset( gui->summary.accdb->class_acq_win,                0, sizeof(gui->summary.accdb->class_acq_win)                );
     323           0 :   memset( gui->summary.accdb->class_acq_wr_win,             0, sizeof(gui->summary.accdb->class_acq_wr_win)             );
     324           0 :   memset( gui->summary.accdb->class_not_found_win,          0, sizeof(gui->summary.accdb->class_not_found_win)          );
     325           0 :   memset( gui->summary.accdb->class_evicted_win,            0, sizeof(gui->summary.accdb->class_evicted_win)            );
     326           0 :   memset( gui->summary.accdb->class_preevicted_win,         0, sizeof(gui->summary.accdb->class_preevicted_win)         );
     327           0 :   memset( gui->summary.accdb->class_commit_new_win,         0, sizeof(gui->summary.accdb->class_commit_new_win)         );
     328           0 :   memset( gui->summary.accdb->class_commit_over_win,        0, sizeof(gui->summary.accdb->class_commit_over_win)        );
     329             : 
     330           0 :   gui->summary.accdb->partition_cnt = 0UL;
     331           0 :   memset( gui->summary.accdb->partition_read_ops_win,        0, sizeof(gui->summary.accdb->partition_read_ops_win)        );
     332           0 :   memset( gui->summary.accdb->partition_bytes_read_win,      0, sizeof(gui->summary.accdb->partition_bytes_read_win)      );
     333           0 :   memset( gui->summary.accdb->partition_write_ops_win,       0, sizeof(gui->summary.accdb->partition_write_ops_win)       );
     334           0 :   memset( gui->summary.accdb->partition_bytes_written_win,   0, sizeof(gui->summary.accdb->partition_bytes_written_win)   );
     335           0 :   memset( gui->summary.accdb->partitions,                    0, sizeof(gui->summary.accdb->partitions)                    );
     336           0 :   memset( gui->summary.accdb->partition_prev_read_ops,       0, sizeof(gui->summary.accdb->partition_prev_read_ops)       );
     337           0 :   memset( gui->summary.accdb->partition_prev_bytes_read,     0, sizeof(gui->summary.accdb->partition_prev_bytes_read)     );
     338           0 :   memset( gui->summary.accdb->partition_prev_write_ops,      0, sizeof(gui->summary.accdb->partition_prev_write_ops)      );
     339           0 :   memset( gui->summary.accdb->partition_prev_bytes_written,  0, sizeof(gui->summary.accdb->partition_prev_bytes_written)  );
     340           0 :   for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
     341           0 :     fd_gui_ema_init( &gui->summary.accdb->tier_fill_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
     342           0 :     fd_gui_ema_init( &gui->summary.accdb->tier_free_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
     343           0 :   }
     344           0 :   gui->summary.accdb->tier_sample_nanos              = LONG_MAX;
     345           0 :   gui->summary.accdb->next_compaction_remaining_secs = 0.0;
     346           0 :   gui->summary.accdb->next_compaction_partition_idx  = ULONG_MAX;
     347             : 
     348             :   /* Build the per-tile accdb slot table from the topology.  Order
     349             :      matters only for stable JSON ordering: RW joiners first, RO
     350             :      joiners, then snapwr at the end. */
     351           0 :   gui->summary.accdb->accdb_tile_cnt = 0UL;
     352           0 :   static const struct { char const * name; uchar kind; } accdb_kinds[] = {
     353           0 :     { "execle", FD_GUI_ACCDB_TILE_KIND_RW     },
     354           0 :     { "execrp", FD_GUI_ACCDB_TILE_KIND_RW     },
     355           0 :     { "replay", FD_GUI_ACCDB_TILE_KIND_RW     },
     356           0 :     { "tower",  FD_GUI_ACCDB_TILE_KIND_RW     },
     357           0 :     { "rpc",    FD_GUI_ACCDB_TILE_KIND_RO     },
     358           0 :     { "resolv", FD_GUI_ACCDB_TILE_KIND_RO     },
     359           0 :     { "snapwr", FD_GUI_ACCDB_TILE_KIND_SNAPWR },
     360           0 :     { "accdb",  FD_GUI_ACCDB_TILE_KIND_ACCDB  },
     361           0 :   };
     362           0 :   for( ulong k=0UL; k<sizeof(accdb_kinds)/sizeof(accdb_kinds[0]); k++ ) {
     363           0 :     ulong cnt = fd_topo_tile_name_cnt( gui->topo, accdb_kinds[ k ].name );
     364           0 :     for( ulong i=0UL; i<cnt; i++ ) {
     365           0 :       ulong t_idx = fd_topo_find_tile( gui->topo, accdb_kinds[ k ].name, i );
     366           0 :       if( FD_UNLIKELY( t_idx==ULONG_MAX ) ) continue;
     367           0 :       if( FD_UNLIKELY( gui->summary.accdb->accdb_tile_cnt>=FD_GUI_MAX_ACCDB_TILES ) ) {
     368           0 :         FD_LOG_ERR(( "too many accdb consumer tiles (limit %lu)", FD_GUI_MAX_ACCDB_TILES ));
     369           0 :       }
     370           0 :       ulong slot = gui->summary.accdb->accdb_tile_cnt++;
     371           0 :       gui->summary.accdb->accdb_tile_topo_idx[ slot ] = (ushort)t_idx;
     372           0 :       gui->summary.accdb->accdb_tile_kind    [ slot ] = accdb_kinds[ k ].kind;
     373           0 :     }
     374           0 :   }
     375           0 :   memset( gui->summary.accdb->tile_cur_acquired,           0, sizeof(gui->summary.accdb->tile_cur_acquired)           );
     376           0 :   memset( gui->summary.accdb->tile_cur_acquired_writable,  0, sizeof(gui->summary.accdb->tile_cur_acquired_writable)  );
     377           0 :   memset( gui->summary.accdb->tile_cur_bytes_read,         0, sizeof(gui->summary.accdb->tile_cur_bytes_read)         );
     378           0 :   memset( gui->summary.accdb->tile_cur_bytes_copied,       0, sizeof(gui->summary.accdb->tile_cur_bytes_copied)       );
     379           0 :   memset( gui->summary.accdb->tile_cur_bytes_written,      0, sizeof(gui->summary.accdb->tile_cur_bytes_written)      );
     380           0 :   memset( gui->summary.accdb->tile_cur_read_ops,           0, sizeof(gui->summary.accdb->tile_cur_read_ops)           );
     381           0 :   memset( gui->summary.accdb->tile_cur_write_ops,          0, sizeof(gui->summary.accdb->tile_cur_write_ops)          );
     382           0 :   memset( gui->summary.accdb->tile_cur_misses,             0, sizeof(gui->summary.accdb->tile_cur_misses)             );
     383           0 :   memset( gui->summary.accdb->tile_cur_evicted,            0, sizeof(gui->summary.accdb->tile_cur_evicted)            );
     384           0 :   memset( gui->summary.accdb->tile_cur_committed,          0, sizeof(gui->summary.accdb->tile_cur_committed)          );
     385           0 :   memset( gui->summary.accdb->tile_cur_acquire_calls,      0, sizeof(gui->summary.accdb->tile_cur_acquire_calls)      );
     386           0 :   memset( gui->summary.accdb->tile_cur_status,             0, sizeof(gui->summary.accdb->tile_cur_status)             );
     387           0 :   memset( gui->summary.accdb->tile_prev_acquired,          0, sizeof(gui->summary.accdb->tile_prev_acquired)          );
     388           0 :   memset( gui->summary.accdb->tile_prev_acquired_writable, 0, sizeof(gui->summary.accdb->tile_prev_acquired_writable) );
     389           0 :   memset( gui->summary.accdb->tile_prev_bytes_read,        0, sizeof(gui->summary.accdb->tile_prev_bytes_read)        );
     390           0 :   memset( gui->summary.accdb->tile_prev_bytes_copied,      0, sizeof(gui->summary.accdb->tile_prev_bytes_copied)      );
     391           0 :   memset( gui->summary.accdb->tile_prev_bytes_written,     0, sizeof(gui->summary.accdb->tile_prev_bytes_written)     );
     392           0 :   memset( gui->summary.accdb->tile_prev_read_ops,          0, sizeof(gui->summary.accdb->tile_prev_read_ops)          );
     393           0 :   memset( gui->summary.accdb->tile_prev_write_ops,         0, sizeof(gui->summary.accdb->tile_prev_write_ops)         );
     394           0 :   memset( gui->summary.accdb->tile_prev_misses,            0, sizeof(gui->summary.accdb->tile_prev_misses)            );
     395           0 :   memset( gui->summary.accdb->tile_prev_evicted,           0, sizeof(gui->summary.accdb->tile_prev_evicted)           );
     396           0 :   memset( gui->summary.accdb->tile_prev_committed,         0, sizeof(gui->summary.accdb->tile_prev_committed)         );
     397           0 :   memset( gui->summary.accdb->tile_prev_acquire_calls,     0, sizeof(gui->summary.accdb->tile_prev_acquire_calls)     );
     398           0 :   memset( gui->summary.accdb->tile_acquired_win,           0, sizeof(gui->summary.accdb->tile_acquired_win)           );
     399           0 :   memset( gui->summary.accdb->tile_acquired_writable_win,  0, sizeof(gui->summary.accdb->tile_acquired_writable_win)  );
     400           0 :   memset( gui->summary.accdb->tile_bytes_read_win,         0, sizeof(gui->summary.accdb->tile_bytes_read_win)         );
     401           0 :   memset( gui->summary.accdb->tile_bytes_copied_win,       0, sizeof(gui->summary.accdb->tile_bytes_copied_win)       );
     402           0 :   memset( gui->summary.accdb->tile_bytes_written_win,      0, sizeof(gui->summary.accdb->tile_bytes_written_win)      );
     403           0 :   memset( gui->summary.accdb->tile_read_ops_win,           0, sizeof(gui->summary.accdb->tile_read_ops_win)           );
     404           0 :   memset( gui->summary.accdb->tile_write_ops_win,          0, sizeof(gui->summary.accdb->tile_write_ops_win)          );
     405           0 :   memset( gui->summary.accdb->tile_misses_win,             0, sizeof(gui->summary.accdb->tile_misses_win)             );
     406           0 :   memset( gui->summary.accdb->tile_evicted_win,            0, sizeof(gui->summary.accdb->tile_evicted_win)            );
     407           0 :   memset( gui->summary.accdb->tile_committed_win,          0, sizeof(gui->summary.accdb->tile_committed_win)          );
     408           0 :   memset( gui->summary.accdb->tile_acquire_calls_win,      0, sizeof(gui->summary.accdb->tile_acquire_calls_win)      );
     409             : 
     410           0 :   memset( gui->summary.accdb->tile_sparkline_bucket_start_nanos, 0, sizeof(gui->summary.accdb->tile_sparkline_bucket_start_nanos) );
     411           0 :   memset( gui->summary.accdb->tile_sparkline_acq_bucket,         0, sizeof(gui->summary.accdb->tile_sparkline_acq_bucket)         );
     412           0 :   memset( gui->summary.accdb->tile_sparkline_acq_wr_bucket,      0, sizeof(gui->summary.accdb->tile_sparkline_acq_wr_bucket)      );
     413           0 :   memset( gui->summary.accdb->tile_sparkline_acq_history,        0, sizeof(gui->summary.accdb->tile_sparkline_acq_history)        );
     414           0 :   memset( gui->summary.accdb->tile_sparkline_acq_wr_history,     0, sizeof(gui->summary.accdb->tile_sparkline_acq_wr_history)     );
     415           0 :   memset( gui->summary.accdb->tile_sparkline_count,              0, sizeof(gui->summary.accdb->tile_sparkline_count)              );
     416             : 
     417           0 :   memset( gui->summary.tile_timers_reference, 0, sizeof(gui->summary.tile_timers_reference) );
     418           0 :   memset( gui->summary.tile_timers_current,   0, sizeof(gui->summary.tile_timers_current)   );
     419           0 :   memset( gui->summary.tile_timers_packed,    0, sizeof(gui->summary.tile_timers_packed)    );
     420             : 
     421           0 :   gui->landed_vote_cnt = 0UL;
     422             : 
     423           0 :   gui->block_engine.has_block_engine = 0;
     424             : 
     425           0 :   gui->epoch.current_epoch      = ULONG_MAX;
     426           0 :   gui->epoch.has_epoch_schedule = 0;
     427           0 :   gui->epoch.stored_epoch_cnt   = 0UL;
     428             : 
     429           0 :   gui->shreds.leader_shred_cnt        = 0UL;
     430           0 :   gui->shreds.leader_shred_slot       = ULONG_MAX;
     431           0 :   gui->shreds.broadcast_watermark_ns  = now;
     432           0 :   gui->summary.catch_up_repair_sz     = 0UL;
     433           0 :   gui->summary.catch_up_turbine_sz    = 0UL;
     434             : 
     435           0 :   fd_memset( &gui->snapsv, 0, sizeof(gui->snapsv) );
     436             : 
     437           0 :   return gui;
     438           0 : }
     439             : 
     440             : fd_gui_t *
     441           0 : fd_gui_join( void * shmem ) {
     442           0 :   return (fd_gui_t *)shmem;
     443           0 : }
     444             : 
     445             : void
     446             : fd_gui_set_identity( fd_gui_t *    gui,
     447           0 :                      uchar const * identity_pubkey ) {
     448           0 :   memcpy( gui->summary.identity_key->uc, identity_pubkey, 32UL );
     449           0 :   fd_base58_encode_32( identity_pubkey, NULL, gui->summary.identity_key_base58 );
     450           0 :   gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
     451             : 
     452           0 :   gui->summary.vote_distance = 0UL;
     453           0 :   if( FD_LIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_NON_VOTING ) ) gui->summary.vote_state = FD_GUI_VOTE_STATE_VOTING;
     454           0 :   gui->landed_vote_cnt = 0UL;
     455             : 
     456           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) gui->summary.slot_voted = ULONG_MAX;
     457             : 
     458           0 :   fd_gui_printf_identity_key( gui );
     459           0 :   fd_http_server_ws_broadcast( gui->http );
     460           0 :   if( FD_LIKELY( !gui->summary.is_alpenglow ) ) {
     461           0 :     fd_gui_printf_vote_distance( gui );
     462           0 :     fd_http_server_ws_broadcast( gui->http );
     463           0 :   } else {
     464           0 :     fd_gui_printf_vote_slot( gui );
     465           0 :     fd_http_server_ws_broadcast( gui->http );
     466           0 :   }
     467           0 :   fd_gui_printf_vote_state( gui );
     468           0 :   fd_http_server_ws_broadcast( gui->http );
     469           0 :   if( FD_LIKELY( !gui->summary.is_alpenglow ) ) fd_gui_printf_late_votes_history ( gui );
     470           0 :   else                                          fd_gui_printf_missed_vote_history( gui, gui->epoch.current_epoch );
     471           0 :   fd_http_server_ws_broadcast( gui->http );
     472           0 : }
     473             : 
     474             : void
     475             : fd_gui_handle_diag_snapshot( fd_gui_t *   gui,
     476             :                              void const * data,
     477           0 :                              ulong        data_sz ) {
     478           0 :   if( FD_UNLIKELY( !gui->summary.is_full_client || !data ) ) return;
     479             : 
     480           0 :   if( FD_UNLIKELY( data_sz!=sizeof(fd_diag_system_resources_t) ) ) return;
     481             : 
     482           0 :   fd_diag_system_resources_t snapshot[ 1 ];
     483           0 :   fd_memcpy( snapshot, data, sizeof(snapshot) );
     484           0 :   if( FD_UNLIKELY( snapshot->cpu_cnt     >FD_DIAG_SYSTEM_CPU_MAX  ||
     485           0 :                    snapshot->numa_mem_cnt>FD_DIAG_SYSTEM_NUMA_MAX ||
     486           0 :                    snapshot->tile_mem_cnt>FD_DIAG_SYSTEM_TILE_MEM_MAX ||
     487           0 :                    snapshot->mount_cnt   >FD_DIAG_SYSTEM_FILE_MAX ||
     488           0 :                    snapshot->file_cnt    >FD_DIAG_SYSTEM_FILE_MAX ) ) return;
     489           0 :   for( ulong i=0UL; i<(ulong)snapshot->cpu_cnt; i++ ) {
     490           0 :     fd_diag_system_cpu_t const * cpu = &snapshot->cpu[ i ];
     491           0 :     if( FD_UNLIKELY( cpu->cpu_idx>=FD_DIAG_SYSTEM_CPU_MAX ) ) return;
     492           0 :   }
     493           0 :   for( ulong i=0UL; i<(ulong)snapshot->tile_mem_cnt; i++ ) {
     494           0 :     fd_diag_system_tile_mem_t const * tile = &snapshot->tile_mem[ i ];
     495           0 :     if( FD_UNLIKELY( tile->tile_idx>=gui->topo->tile_cnt ) ) return;
     496           0 :   }
     497           0 :   for( ulong i=0UL; i<(ulong)snapshot->mount_cnt; i++ ) {
     498           0 :     if( FD_UNLIKELY( !memchr( snapshot->mount[ i ].path, '\0', sizeof(snapshot->mount[ i ].path) ) ) ) return;
     499           0 :   }
     500           0 :   for( ulong i=0UL; i<(ulong)snapshot->file_cnt; i++ ) {
     501           0 :     fd_diag_system_file_t const * file = &snapshot->file[ i ];
     502           0 :     if( FD_UNLIKELY( file->mount_idx>=snapshot->mount_cnt ||
     503           0 :                      file->path[ 0 ]!='/' ||
     504           0 :                      !memchr( file->path, '\0', sizeof(file->path) ) ) ) return;
     505           0 :   }
     506             : 
     507           0 :   gui->system.resources = *snapshot;
     508           0 :   gui->system.valid     = 1;
     509           0 :   fd_gui_printf_system_resources( gui );
     510           0 :   fd_http_server_ws_broadcast( gui->http );
     511           0 : }
     512             : 
     513             : void
     514             : fd_gui_ws_open( fd_gui_t * gui,
     515             :                 ulong      ws_conn_id,
     516           0 :                 long now ) {
     517           0 :   fd_gui_printf_is_alpenglow( gui );
     518           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     519             : 
     520           0 :   void (* printers[] )( fd_gui_t * gui ) = {
     521           0 :     fd_gui_printf_boot_progress,
     522           0 :     fd_gui_printf_version,
     523           0 :     fd_gui_printf_cluster,
     524           0 :     fd_gui_printf_commit_hash,
     525           0 :     fd_gui_printf_identity_key,
     526           0 :     fd_gui_printf_vote_key,
     527           0 :     fd_gui_printf_startup_time_nanos,
     528           0 :     fd_gui_printf_vote_state,
     529           0 :     fd_gui_printf_vote_distance,
     530           0 :     fd_gui_printf_turbine_slot,
     531           0 :     fd_gui_printf_repair_slot,
     532           0 :     fd_gui_printf_slot_caught_up,
     533           0 :     fd_gui_printf_tps_history,
     534           0 :     fd_gui_printf_estimated_tps,
     535           0 :     fd_gui_printf_tiles,
     536           0 :     fd_gui_printf_schedule_strategy,
     537           0 :     fd_gui_printf_identity_balance,
     538           0 :     fd_gui_printf_vote_balance,
     539           0 :     fd_gui_printf_vote_commission,
     540           0 :     fd_gui_printf_estimated_slot_duration_nanos,
     541           0 :     fd_gui_printf_root_slot,
     542           0 :     fd_gui_printf_storage_slot,
     543           0 :     fd_gui_printf_reset_slot,
     544           0 :     fd_gui_printf_active_fork_cnt,
     545           0 :     fd_gui_printf_optimistically_confirmed_slot,
     546           0 :     fd_gui_printf_completed_slot,
     547           0 :     fd_gui_printf_estimated_slot,
     548           0 :     fd_gui_printf_live_tile_timers,
     549           0 :     fd_gui_printf_live_tile_metrics,
     550           0 :     fd_gui_printf_catch_up_history,
     551           0 :     fd_gui_printf_late_votes_history,
     552           0 :     fd_gui_printf_health
     553           0 :   };
     554             : 
     555           0 :   ulong printers_len = sizeof(printers) / sizeof(printers[0]);
     556           0 :   for( ulong i=0UL; i<printers_len; i++ ) {
     557           0 :     if( FD_UNLIKELY( gui->summary.is_alpenglow && (printers[ i ]==fd_gui_printf_vote_distance || printers[ i ]==fd_gui_printf_optimistically_confirmed_slot || printers[ i ]==fd_gui_printf_late_votes_history ) ) ) continue;
     558           0 :     printers[ i ]( gui );
     559           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     560           0 :   }
     561             : 
     562           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
     563           0 :     fd_gui_printf_finalized_slot( gui );
     564           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     565           0 :     fd_gui_printf_notarized_slot( gui );
     566           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     567           0 :     fd_gui_printf_vote_slot( gui );
     568           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     569           0 :   }
     570             : 
     571           0 :   if( FD_LIKELY( gui->system.valid ) ) {
     572           0 :     fd_gui_printf_system_resources( gui );
     573           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     574           0 :   }
     575             : 
     576           0 :   {
     577           0 :     fd_gui_printf_live_program_cache( gui );
     578           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     579             : 
     580           0 :     if( FD_LIKELY( gui->summary.accounts_stats_have_reference ) ) {
     581           0 :       fd_gui_printf_accounts_stats( gui );
     582           0 :       FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     583           0 :     }
     584           0 :   }
     585             : 
     586           0 :   if( FD_LIKELY( gui->block_engine.has_block_engine ) ) {
     587           0 :     fd_gui_printf_block_engine( gui );
     588           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     589           0 :   }
     590             : 
     591           0 :   if( FD_LIKELY( gui->epoch.current_epoch!=ULONG_MAX ) ) {
     592           0 :     for( ulong e=gui->epoch.current_epoch; e<=gui->epoch.current_epoch+1UL; e++ ) {
     593           0 :       if( FD_LIKELY( fd_gui_epoch( gui, e ) ) ) {
     594           0 :         fd_gui_printf_skip_rate( gui, e );
     595           0 :         FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     596           0 :         fd_gui_printf_epoch( gui, e );
     597           0 :         FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     598           0 :       }
     599           0 :     }
     600             : 
     601           0 :     fd_gui_printf_skipped_history( gui, gui->epoch.current_epoch );
     602           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     603           0 :     fd_gui_printf_skipped_history_cluster( gui, gui->epoch.current_epoch );
     604           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     605             : 
     606           0 :     if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
     607           0 :       fd_gui_printf_missed_vote_history( gui, gui->epoch.current_epoch );
     608           0 :       FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     609           0 :     }
     610           0 :   }
     611             : 
     612             :   /* rebroadcast 10s of historical shred data */
     613           0 :   long const shred_history_start = now-10L*1000L*1000L*1000L;
     614           0 :   if( FD_LIKELY( !fd_gui_shreds_window_is_empty( gui, shred_history_start, now ) ) ) {
     615           0 :     fd_gui_printf_shred_rebroadcast( gui, shred_history_start, now );
     616           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     617           0 :   }
     618           0 : }
     619             : 
     620             : 
     621             : 
     622             : static inline ushort
     623           0 : fd_gui_tile_timers_pct( ulong delta, ulong total ) {
     624           0 :   if( FD_UNLIKELY( !total ) ) return USHORT_MAX;
     625           0 :   double percent = ( (double)delta / (double)total ) * 100.0;
     626           0 :   long   hundredths = (long)( percent * 100.0 );
     627           0 :   if( FD_UNLIKELY( hundredths<0L ) ) hundredths = 0L;
     628           0 :   if( FD_UNLIKELY( hundredths>(USHORT_MAX-1U) ) ) hundredths = (USHORT_MAX-1U);
     629           0 :   return (ushort)hundredths;
     630           0 : }
     631             : 
     632             : void
     633             : fd_gui_tile_timers_diff( fd_gui_tile_timers_hist_t *  out,
     634             :                          fd_gui_tile_timers_t const * prev,
     635             :                          fd_gui_tile_timers_t const * cur,
     636             :                          ulong                        tile_idx,
     637           0 :                          long                         sample_time_nanos ) {
     638           0 :   memset( out, 0, sizeof(*out) );
     639           0 :   out->sample_time_nanos = sample_time_nanos;
     640           0 :   out->tile_idx = (ushort)tile_idx;
     641             : 
     642           0 :   ulong cur_total = 0UL, prev_total = 0UL;
     643           0 :   for( ulong j=0UL; j<FD_METRICS_ENUM_TILE_REGIME_CNT; j++ ) {
     644           0 :     cur_total += cur->timers[ j ]; prev_total += prev->timers[ j ];
     645           0 :   }
     646           0 :   ulong busy = cur_total - prev_total;
     647           0 :   for( ulong j=0UL; j<FD_METRICS_ENUM_TILE_REGIME_CNT; j++ ) {
     648           0 :     out->timers[ j ] = fd_gui_tile_timers_pct( cur->timers[ j ] - prev->timers[ j ], busy );
     649           0 :   }
     650           0 :   if( FD_UNLIKELY( !busy ) ) {
     651           0 :     out->idle_ratio = USHORT_MAX;
     652           0 :   } else {
     653           0 :     ulong idle = cur->timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_POSTFRAG_IDX   ] - prev->timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_POSTFRAG_IDX   ];
     654           0 :     ulong bp   = cur->timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX ] - prev->timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX ];
     655           0 :     out->idle_ratio = fd_gui_tile_timers_pct( idle+bp, busy );
     656           0 :   }
     657             : 
     658           0 :   ulong cur_ctot = 0UL, prev_ctot = 0UL;
     659           0 :   for( ulong j=0UL; j<FD_METRICS_ENUM_CPU_REGIME_CNT; j++ ) { cur_ctot += cur->sched_timers[ j ]; prev_ctot += prev->sched_timers[ j ]; }
     660           0 :   ulong cbusy = cur_ctot - prev_ctot;
     661           0 :   for( ulong j=0UL; j<FD_METRICS_ENUM_CPU_REGIME_CNT; j++ ) {
     662           0 :     out->sched_timers[ j ] = fd_gui_tile_timers_pct( cur->sched_timers[ j ] - prev->sched_timers[ j ], cbusy );
     663           0 :   }
     664             : 
     665           0 :   out->alive    = (uchar)fd_ulong_if( cur->status==2U, 2UL, (ulong)( cur->heartbeat>prev->heartbeat ) );
     666           0 :   out->in_backp = (uchar)( !!cur->in_backp );
     667           0 :   out->last_cpu = cur->last_cpu;
     668             : 
     669           0 :   out->backp_msgs     = cur->backp_cnt;
     670           0 :   out->nvcsw          = cur->nvcsw;
     671           0 :   out->nivcsw         = cur->nivcsw;
     672           0 :   out->minflt         = cur->minflt;
     673           0 :   out->majflt         = cur->majflt;
     674           0 :   out->interrupts     = cur->interrupts;
     675           0 :   out->tlb_shootdowns = cur->tlb_shootdowns;
     676           0 :   out->timer_ticks    = cur->timer_ticks;
     677           0 : }
     678             : 
     679             : static void
     680           0 : fd_gui_tile_timers_snap( fd_gui_t * gui, long now ) {
     681           0 :   fd_gui_tile_timers_t * cur = gui->summary.tile_timers_current;
     682           0 :   fd_memcpy( gui->summary.tile_timers_reference, cur, gui->tile_cnt * sizeof(fd_gui_tile_timers_t) );
     683           0 :   for( ulong i=0UL; i<gui->topo->tile_cnt; i++ ) {
     684           0 :     fd_topo_tile_t const * tile = &gui->topo->tiles[ i ];
     685             :     /* NULL when the tile's metrics live in a workspace not mapped to
     686             :        this tile (e.g. bench tiles use the "bench" workspace, not
     687             :        "metric_in"). */
     688           0 :     if( FD_UNLIKELY( !tile->metrics ) ) continue;
     689           0 :     volatile ulong const * tile_metrics = fd_metrics_tile( tile->metrics );
     690             : 
     691           0 :     cur[ i ].sample_time_nanos = now;
     692             : 
     693           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 )    ];
     694           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_HOUSEKEEPING_IDX   ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_HOUSEKEEPING )   ];
     695           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_HOUSEKEEPING ) ];
     696           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 )         ];
     697           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_PREFRAG_IDX        ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_PREFRAG )        ];
     698           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX      ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG )      ];
     699           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 )        ];
     700           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_POSTFRAG_IDX       ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_POSTFRAG )       ];
     701             : 
     702           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_WAIT_IDX      ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_WAIT )      ];
     703           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_USER_IDX      ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_USER )      ];
     704           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_SYSTEM_IDX    ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_SYSTEM )    ];
     705           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_IDLE_IDX      ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_IDLE )      ];
     706           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_INTERRUPT_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_INTERRUPT ) ];
     707             : 
     708           0 :     cur[ i ].in_backp  = (int)tile_metrics[ MIDX(GAUGE, TILE, IN_BACKPRESSURE) ];
     709           0 :     cur[ i ].status    = (uchar)tile_metrics[ MIDX( GAUGE, TILE, STATUS ) ];
     710           0 :     cur[ i ].heartbeat = tile_metrics[ MIDX( GAUGE, TILE, HEARTBEAT_TIMESTAMP_NANOS ) ];
     711           0 :     cur[ i ].backp_cnt = tile_metrics[ MIDX( COUNTER, TILE, BACKPRESSURE ) ];
     712           0 :     cur[ i ].nvcsw     = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_VOLUNTARY ) ];
     713           0 :     cur[ i ].nivcsw    = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_INVOLUNTARY ) ];
     714           0 :     cur[ i ].minflt    = tile_metrics[ MIDX( COUNTER, TILE, PAGE_FAULT_MINOR ) ];
     715           0 :     cur[ i ].majflt    = tile_metrics[ MIDX( COUNTER, TILE, PAGE_FAULT_MAJOR ) ];
     716           0 :     cur[ i ].last_cpu  = (ushort)tile_metrics[ MIDX( GAUGE, TILE, LAST_CPU ) ];
     717           0 :     cur[ i ].interrupts     = tile_metrics[ MIDX( COUNTER, TILE, IRQ_PREEMPTED ) ];
     718           0 :     cur[ i ].tlb_shootdowns = tile_metrics[ MIDX( COUNTER, TILE, TLB_SHOOTDOWN ) ];
     719           0 :     cur[ i ].timer_ticks    = tile_metrics[ MIDX( COUNTER, TILE, TIMER_TICK ) ];
     720           0 :   }
     721             : 
     722           0 :   for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
     723           0 :     cur[ i ].tile_idx = i;
     724           0 :     fd_gui_tile_timers_diff( &gui->summary.tile_timers_packed[ i ], &gui->summary.tile_timers_reference[ i ], &cur[ i ], i, now );
     725           0 :   }
     726           0 : }
     727             : 
     728             : static void
     729           0 : fd_gui_scheduler_counts_snap( fd_gui_t * gui, long now ) {
     730           0 :   ulong pack_tile_idx = fd_topo_find_tile( gui->topo, "pack", 0UL );
     731           0 :   if( FD_UNLIKELY( pack_tile_idx==ULONG_MAX ) ) return;
     732             : 
     733           0 :   fd_gui_scheduler_counts_t cur[ 1 ];
     734             : 
     735           0 :   fd_topo_tile_t const * pack = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "pack", 0UL ) ];
     736           0 :   volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
     737             : 
     738           0 :   cur->sample_time_ns = now;
     739             : 
     740           0 :   cur->regular     = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_REGULAR ) ];
     741           0 :   cur->votes       = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_VOTES ) ];
     742           0 :   cur->conflicting = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_CONFLICTING ) ];
     743           0 :   cur->bundles     = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_BUNDLES ) ];
     744             : 
     745           0 :   fd_gui_hist_ts_append( gui, FD_GUI_HIST_SCHEDULER_COUNTS, now, now, cur );
     746           0 : }
     747             : 
     748             : static void
     749           0 : fd_gui_estimated_tps_snap( fd_gui_t * gui ) {
     750           0 :   ulong vote_failed     = 0UL;
     751           0 :   ulong vote_success    = 0UL;
     752           0 :   ulong nonvote_success = 0UL;
     753           0 :   ulong nonvote_failed  = 0UL;
     754             : 
     755           0 :   if( FD_LIKELY( gui->summary.slot_tower==ULONG_MAX ) ) return;
     756           0 :   ulong first_replay_slot = fd_gui_first_replay_slot( gui );
     757           0 :   for( ulong i=0UL; i<fd_ulong_min( gui->summary.slot_tower+1UL, MAX_SLOTS_PER_EPOCH ); i++ ) {
     758           0 :     ulong _slot = gui->summary.slot_tower-i;
     759           0 :     if( FD_UNLIKELY( first_replay_slot!=ULONG_MAX && _slot<first_replay_slot ) ) break;
     760           0 :     fd_gui_slot_t const * slot = fd_gui_slot_get_canon( gui, _slot );
     761           0 :     if( FD_UNLIKELY( !slot ) ) continue;
     762           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. */
     763           0 :     if( FD_UNLIKELY( slot->completed_time+FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS*1000L*1000L*1000L<gui->next_sample_200millis ) ) break; /* Slot too old. */
     764           0 :     if( FD_UNLIKELY( slot->skip!=FD_GUI_SKIP_STATUS_NOT_SKIPPED ) ) continue; /* Skipped slots don't count to TPS. */
     765           0 :     if( FD_UNLIKELY( slot->vote_failed==UINT_MAX ) ) continue; /* Slot transaction counts not yet populated. */
     766           0 :     vote_failed     += slot->vote_failed;
     767           0 :     vote_success    += slot->vote_success;
     768           0 :     nonvote_success += slot->nonvote_success;
     769           0 :     nonvote_failed  += slot->nonvote_failed;
     770           0 :   }
     771             : 
     772           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].vote_failed = vote_failed;
     773           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].vote_success = vote_success;
     774           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].nonvote_success = nonvote_success;
     775           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].nonvote_failed = nonvote_failed;
     776           0 :   gui->summary.estimated_tps_history_idx = (gui->summary.estimated_tps_history_idx+1UL) % FD_GUI_TPS_HISTORY_SAMPLE_CNT;
     777           0 : }
     778             : 
     779             : static void
     780             : fd_gui_network_stats_snap_egress( fd_topo_t const *        topo,
     781             :                                   char const *             tile_name,
     782             :                                   int                      is_alpenglow,
     783           0 :                                   fd_gui_network_stats_t * cur ) {
     784           0 :   ulong tile_cnt = fd_topo_tile_name_cnt( topo, tile_name );
     785           0 :   for( ulong i=0UL; i<tile_cnt; i++ ) {
     786           0 :     ulong tile_idx = fd_topo_find_tile( topo, tile_name, i );
     787           0 :     if( FD_UNLIKELY( tile_idx==ULONG_MAX ) ) continue;
     788           0 :     fd_topo_tile_t const * tile = &topo->tiles[ tile_idx ];
     789           0 :     for( ulong j=0UL; j<tile->in_cnt; j++ ) {
     790           0 :       ulong bytes = fd_metrics_link_in( tile->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
     791           0 :       char const * link_name = topo->links[ tile->in_link_id[ j ] ].name;
     792           0 :       if( FD_UNLIKELY( !strcmp( link_name, "shred_net"  ) ) ) cur->out.turbine += bytes;
     793           0 :       if( FD_UNLIKELY( !strcmp( link_name, "repair_net" ) ) ) cur->out.repair  += bytes;
     794           0 :       if( FD_UNLIKELY( !strcmp( link_name, "rserve_net" ) ) ) cur->out.rserve  += bytes;
     795           0 :       if( FD_UNLIKELY( !strcmp( link_name, "txsend_net" ) ) ) cur->out.tpu     += bytes;
     796           0 :       if( FD_UNLIKELY( is_alpenglow && !strcmp( link_name, "votor_net" ) ) ) cur->out.votor += bytes;
     797           0 :     }
     798           0 :   }
     799           0 : }
     800             : 
     801             : static void
     802             : fd_gui_network_stats_snap( fd_gui_t *               gui,
     803           0 :                            fd_gui_network_stats_t * cur ) {
     804           0 :   fd_topo_t const * topo = gui->topo;
     805           0 :   ulong gossvf_tile_cnt = fd_topo_tile_name_cnt( topo, "gossvf" );
     806           0 :   ulong gossip_tile_cnt = fd_topo_tile_name_cnt( topo, "gossip" );
     807           0 :   ulong shred_tile_cnt  = fd_topo_tile_name_cnt( topo, "shred" );
     808           0 :   ulong quic_tile_cnt   = fd_topo_tile_name_cnt( topo, "quic" );
     809             : 
     810           0 :   cur->in.gossip   = fd_gui_metrics_gossip_total_ingress_bytes( topo, gossvf_tile_cnt );
     811           0 :   cur->out.gossip  = fd_gui_metrics_gossip_total_egress_bytes( topo, gossip_tile_cnt );
     812           0 :   cur->in.turbine  = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_TURBINE_RX_BYTES ) );
     813             : 
     814           0 :   cur->out.turbine = 0UL;
     815           0 :   cur->out.repair  = 0UL;
     816           0 :   cur->out.rserve  = 0UL;
     817           0 :   cur->out.tpu     = 0UL;
     818           0 :   cur->out.votor   = 0UL;
     819           0 :   cur->in.votor    = 0UL;
     820           0 :   fd_gui_network_stats_snap_egress( topo, "net",  gui->summary.is_alpenglow, cur );
     821           0 :   fd_gui_network_stats_snap_egress( topo, "mlx5", gui->summary.is_alpenglow, cur );
     822             : 
     823           0 :   ulong votor_tile_idx = fd_topo_find_tile( topo, "votor", 0UL );
     824           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow && votor_tile_idx!=ULONG_MAX ) ) {
     825           0 :     fd_topo_tile_t const * votor = &topo->tiles[ votor_tile_idx ];
     826           0 :     for( ulong i=0UL; i<votor->in_cnt; i++ ) {
     827           0 :       if( FD_UNLIKELY( !strcmp( topo->links[ votor->in_link_id[ i ] ].name, "net_votor" ) ) ) {
     828           0 :           cur->in.votor += fd_metrics_link_in( votor->metrics, i )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
     829           0 :       }
     830           0 :     }
     831           0 :   }
     832             : 
     833           0 :   cur->in.repair = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_REPAIR_RX_BYTES ) );
     834           0 :   ulong repair_tile_idx = fd_topo_find_tile( topo, gui->summary.is_alpenglow ? "rotor" : "repair", 0UL );
     835           0 :   if( FD_LIKELY( repair_tile_idx!=ULONG_MAX ) ) {
     836           0 :     fd_topo_tile_t const * repair = &topo->tiles[ repair_tile_idx ];
     837             : 
     838           0 :     for( ulong i=0UL; i<repair->in_cnt; i++ ) {
     839           0 :       if( FD_UNLIKELY( !strcmp( topo->links[ repair->in_link_id[ i ] ].name, "net_repair" ) ) ) {
     840           0 :           cur->in.repair += fd_metrics_link_in( repair->metrics, i )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
     841           0 :       }
     842           0 :     }
     843           0 :   }
     844             : 
     845           0 :   cur->in.rserve = 0UL;
     846           0 :   ulong rserve_tile_idx = fd_topo_find_tile( topo, "rserve", 0UL );
     847           0 :   if( FD_LIKELY( rserve_tile_idx!=ULONG_MAX ) ) {
     848           0 :     fd_topo_tile_t const * rserve = &topo->tiles[ rserve_tile_idx ];
     849             : 
     850           0 :     for( ulong i=0UL; i<rserve->in_cnt; i++ ) {
     851           0 :       if( FD_UNLIKELY( !strcmp( topo->links[ rserve->in_link_id[ i ] ].name, "net_rserve" ) ) ) {
     852           0 :           cur->in.rserve += fd_metrics_link_in( rserve->metrics, i )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
     853           0 :       }
     854           0 :     }
     855           0 :   }
     856             : 
     857           0 :   cur->in.tpu = 0UL;
     858           0 :   for( ulong i=0UL; i<quic_tile_cnt; i++ ) {
     859           0 :     ulong quic_tile_idx = fd_topo_find_tile( topo, "quic", i );
     860           0 :     if( FD_UNLIKELY( quic_tile_idx==ULONG_MAX ) ) continue;
     861           0 :     fd_topo_tile_t const * quic = &topo->tiles[ quic_tile_idx ];
     862           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
     863           0 :     cur->in.tpu += quic_metrics[ MIDX( COUNTER, QUIC, PKT_RX_BYTES ) ];
     864           0 :   }
     865             : 
     866           0 :   ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
     867           0 :   if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
     868           0 :     fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
     869           0 :     volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
     870           0 :     cur->in.tpu += bundle_metrics[ MIDX( COUNTER, BUNDLE, PROTOBUF_RX_BYTES ) ];
     871           0 :   }
     872             : 
     873           0 :   ulong metric_tile_idx = fd_topo_find_tile( topo, "metric", 0UL );
     874           0 :   if( FD_LIKELY( metric_tile_idx!=ULONG_MAX ) ) {
     875           0 :     fd_topo_tile_t const * metric = &topo->tiles[ metric_tile_idx ];
     876           0 :     volatile ulong * metric_metrics = fd_metrics_tile( metric->metrics );
     877           0 :     cur->in.metric  = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_READ ) ];
     878           0 :     cur->out.metric = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_WRITTEN ) ];
     879           0 :   } else {
     880           0 :     cur->in.metric  = 0UL;
     881           0 :     cur->out.metric = 0UL;
     882           0 :   }
     883           0 : }
     884             : 
     885             : static void
     886             : fd_gui_network_rate_max_update( fd_gui_t * gui,
     887           0 :                                 long       now ) {
     888           0 :   fd_gui_network_stats_t * cur  = gui->summary.network_stats_current;
     889           0 :   fd_gui_network_stats_t * prev = gui->summary.network_stats_prev;
     890             : 
     891             :   /* On the first sample we have no previous value. */
     892           0 :   if( FD_UNLIKELY( !gui->summary.network_stats_has_prev ) ) {
     893           0 :     *prev = *cur;
     894           0 :     gui->summary.network_stats_has_prev = 1;
     895           0 :     gui->summary.net_rate_prev_ts       = now;
     896           0 :     return;
     897           0 :   }
     898             : 
     899           0 :   ulong d_in[ FD_GUI_NET_PROTO_CNT ];
     900           0 :   d_in[ 0 ] = fd_ulong_sat_sub( cur->in.turbine, prev->in.turbine );
     901           0 :   d_in[ 1 ] = fd_ulong_sat_sub( cur->in.gossip,  prev->in.gossip  );
     902           0 :   d_in[ 2 ] = fd_ulong_sat_sub( cur->in.tpu,     prev->in.tpu     );
     903           0 :   d_in[ 3 ] = fd_ulong_sat_sub( cur->in.repair,  prev->in.repair  );
     904           0 :   d_in[ 4 ] = fd_ulong_sat_sub( cur->in.rserve,  prev->in.rserve  );
     905           0 :   d_in[ 5 ] = fd_ulong_sat_sub( cur->in.metric,  prev->in.metric  );
     906           0 :   d_in[ 6 ] = fd_ulong_sat_sub( cur->in.votor,   prev->in.votor   ); /* 0 if !gui->summary.is_alpenglow */
     907             : 
     908           0 :   ulong d_out[ FD_GUI_NET_PROTO_CNT ];
     909           0 :   d_out[ 0 ] = fd_ulong_sat_sub( cur->out.turbine, prev->out.turbine );
     910           0 :   d_out[ 1 ] = fd_ulong_sat_sub( cur->out.gossip,  prev->out.gossip  );
     911           0 :   d_out[ 2 ] = fd_ulong_sat_sub( cur->out.tpu,     prev->out.tpu     );
     912           0 :   d_out[ 3 ] = fd_ulong_sat_sub( cur->out.repair,  prev->out.repair  );
     913           0 :   d_out[ 4 ] = fd_ulong_sat_sub( cur->out.rserve,  prev->out.rserve  );
     914           0 :   d_out[ 5 ] = fd_ulong_sat_sub( cur->out.metric,  prev->out.metric  );
     915           0 :   d_out[ 6 ] = fd_ulong_sat_sub( cur->out.votor,   prev->out.votor   );  /* 0 if !gui->summary.is_alpenglow */
     916             : 
     917             :   /* Compute per-protocol instantaneous bytes/sec rate and feed the EMA. */
     918           0 :   long dt_ns = now - gui->summary.net_rate_prev_ts;
     919           0 :   if( FD_LIKELY( dt_ns>0L ) ) {
     920           0 :     double dt_sec = (double)dt_ns / 1.0e9;
     921             : 
     922           0 :     for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) {
     923           0 :       double rate_in  = (double)d_in[ i ]  / dt_sec;
     924           0 :       double rate_out = (double)d_out[ i ] / dt_sec;
     925             : 
     926           0 :       fd_gui_ema_advance( &gui->summary.ingress_ema[ i ], now, rate_in  );
     927           0 :       fd_gui_ema_advance( &gui->summary.egress_ema [ i ], now, rate_out );
     928           0 :     }
     929           0 :   }
     930           0 :   gui->summary.net_rate_prev_ts = now;
     931             : 
     932             :   /* Track max total EMA in a rolling 5-minute window using monotonic
     933             :      deques.
     934             : 
     935             :      Invariant: deque entries are strictly decreasing in value from
     936             :      head to tail.  The head is always the current window maximum.
     937             : 
     938             :      Insert:  pop tail entries whose value <= new value (they can
     939             :               never become the maximum), then push the new entry.
     940             :      Expire:  pop head entries older than 5 minutes. */
     941           0 :   if( FD_LIKELY( gui->summary.ingress_ema[ 0 ].last_update_nanos ) ) {
     942           0 :     double sum_in  = 0.0;
     943           0 :     double sum_out = 0.0;
     944           0 :     for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) {
     945           0 :       sum_in  += gui->summary.ingress_ema[ i ].value;
     946           0 :       sum_out += gui->summary.egress_ema[ i ].value;
     947           0 :     }
     948             : 
     949           0 :     while( !fd_gui_rate_deque_empty( gui->summary.ingress_maxq ) && fd_gui_rate_deque_peek_head_const( gui->summary.ingress_maxq )->ts_nanos<now-FD_GUI_NET_RATE_MAX_WINDOW_NS ) {
     950           0 :       fd_gui_rate_deque_pop_head( gui->summary.ingress_maxq );
     951           0 :     }
     952           0 :     while( !fd_gui_rate_deque_empty( gui->summary.ingress_maxq ) && fd_gui_rate_deque_peek_tail_const( gui->summary.ingress_maxq )->value<=sum_in ) {
     953           0 :       fd_gui_rate_deque_pop_tail( gui->summary.ingress_maxq );
     954           0 :     }
     955           0 :     if( FD_UNLIKELY( fd_gui_rate_deque_full( gui->summary.ingress_maxq ) ) ) {
     956           0 :       fd_gui_rate_deque_pop_tail( gui->summary.ingress_maxq );
     957           0 :     }
     958           0 :     fd_gui_rate_deque_push_tail( gui->summary.ingress_maxq, (fd_gui_rate_entry_t){ .ts_nanos=now, .value=sum_in } );
     959             : 
     960           0 :     while( !fd_gui_rate_deque_empty( gui->summary.egress_maxq ) && fd_gui_rate_deque_peek_head_const( gui->summary.egress_maxq )->ts_nanos<now-FD_GUI_NET_RATE_MAX_WINDOW_NS ) {
     961           0 :       fd_gui_rate_deque_pop_head( gui->summary.egress_maxq );
     962           0 :     }
     963           0 :     while( !fd_gui_rate_deque_empty( gui->summary.egress_maxq ) && fd_gui_rate_deque_peek_tail_const( gui->summary.egress_maxq )->value<=sum_out ) {
     964           0 :       fd_gui_rate_deque_pop_tail( gui->summary.egress_maxq );
     965           0 :     }
     966           0 :     if( FD_UNLIKELY( fd_gui_rate_deque_full( gui->summary.egress_maxq ) ) ) {
     967           0 :       fd_gui_rate_deque_pop_tail( gui->summary.egress_maxq );
     968           0 :     }
     969           0 :     fd_gui_rate_deque_push_tail( gui->summary.egress_maxq, (fd_gui_rate_entry_t){ .ts_nanos=now, .value=sum_out } );
     970           0 :   }
     971             : 
     972           0 :   *prev = *cur;
     973           0 : }
     974             : 
     975             : /* Snapshot accdb statistics by reading the accdb tile's metric page
     976             :    (for gauges) and summing counters across all tiles that join accdb
     977             :    (executors, replay, tower, rpc, resolv, plus the accdb tile itself).
     978             :    The result feeds the GUI "Accounts" page. */
     979             : 
     980             : static void
     981             : fd_gui_accounts_stats_snap( fd_gui_t *                gui,
     982           0 :                             fd_gui_accounts_stats_t * cur ) {
     983           0 :   fd_topo_t const * topo = gui->topo;
     984             : 
     985           0 :   memset( cur, 0, sizeof(*cur) );
     986           0 :   cur->sample_time_nanos = fd_log_wallclock();
     987             : 
     988           0 :   ulong accdb_tile_idx = fd_topo_find_tile( topo, "accdb", 0UL );
     989           0 :   if( FD_UNLIKELY( accdb_tile_idx==ULONG_MAX ) ) return;
     990             : 
     991             :   /* Gauges + accdb-tile-only counters. */
     992           0 :   fd_topo_tile_t const * accdb = &topo->tiles[ accdb_tile_idx ];
     993           0 :   volatile ulong const * am    = fd_metrics_tile( accdb->metrics );
     994             : 
     995           0 :   cur->accounts_total           = am[ MIDX( GAUGE,   ACCDB, ACCOUNT_COUNT           ) ];
     996           0 :   cur->accounts_capacity        = am[ MIDX( GAUGE,   ACCDB, ACCOUNT_CAPACITY        ) ];
     997           0 :   cur->disk_allocated_bytes     = am[ MIDX( GAUGE,   ACCDB, DISK_ALLOCATED_BYTES    ) ];
     998           0 :   cur->disk_current_bytes       = am[ MIDX( GAUGE,   ACCDB, DISK_CURRENT_BYTES      ) ];
     999           0 :   cur->disk_used_bytes          = am[ MIDX( GAUGE,   ACCDB, DISK_USED_BYTES         ) ];
    1000           0 :   cur->in_compaction            = am[ MIDX( GAUGE,   ACCDB, IN_COMPACTION           ) ];
    1001           0 :   cur->compactions_requested    = am[ MIDX( COUNTER, ACCDB, COMPACTION_REQUESTED    ) ];
    1002           0 :   cur->compactions_completed    = am[ MIDX( COUNTER, ACCDB, COMPACTION_COMPLETED    ) ];
    1003           0 :   cur->accounts_relocated_bytes = am[ MIDX( COUNTER, ACCDB, ACCOUNT_RELOCATED_BYTES ) ];
    1004           0 :   cur->bytes_written_accdb      = am[ MIDX( COUNTER, ACCDB, BYTES_WRITTEN           ) ];
    1005             : 
    1006             :   /* The accdb tile owns the prewrite and compaction writes; include
    1007             :      those in the aggregate bytes_written / write_ops so the IO panel
    1008             :      reflects all on-disk write activity, not just consumer-driven
    1009             :      commits. */
    1010           0 :   cur->bytes_written += am[ MIDX( COUNTER, ACCDB, BYTES_WRITTEN    ) ];
    1011           0 :   cur->write_ops     += am[ MIDX( COUNTER, ACCDB, WRITE_OPERATION  ) ];
    1012             : 
    1013           0 :   for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {
    1014           0 :     cur->cache_class_used         [ c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_USED            ) + c ];
    1015           0 :     cur->cache_class_max          [ c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_MAX             ) + c ];
    1016           0 :     cur->cache_class_reserved     [ c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_RESERVED        ) + c ];
    1017           0 :     cur->cache_class_target_used  [ c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_TARGET_USED     ) + c ];
    1018           0 :     cur->cache_class_low_water_used[c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_LOW_WATER_USED  ) + c ];
    1019           0 :     cur->preevicted_per_class     [ c ] = am[ MIDX( COUNTER, ACCDB, ACCOUNT_PREEVICTED        ) + c ];
    1020           0 :   }
    1021             : 
    1022             :   /* Walk the per-tile slot table built at init.  Each slot reads its
    1023             :      tile's accdb counters according to its kind (RW, RO, or SNAPWR),
    1024             :      accumulates into the aggregate (cur->*), and stashes the per-tile
    1025             :      cumulative values into gui->summary.accdb->tile_cur_* for the
    1026             :      per-tile rate window pushes done later in
    1027             :      fd_gui_printf_accounts_stats. */
    1028           0 :   for( ulong s=0UL; s<gui->summary.accdb->accdb_tile_cnt; s++ ) {
    1029           0 :     ulong t_idx = (ulong)gui->summary.accdb->accdb_tile_topo_idx[ s ];
    1030           0 :     uchar kind  = gui->summary.accdb->accdb_tile_kind[ s ];
    1031           0 :     volatile ulong const * m = fd_metrics_tile( topo->tiles[ t_idx ].metrics );
    1032             : 
    1033           0 :     gui->summary.accdb->tile_cur_status[ s ] = (uchar)m[ MIDX( GAUGE, TILE, STATUS ) ];
    1034             : 
    1035           0 :     ulong t_acq=0UL, t_acw=0UL, t_misses=0UL, t_evicted=0UL, t_committed=0UL;
    1036           0 :     ulong t_bytes_read=0UL, t_bytes_copied=0UL, t_bytes_written=0UL;
    1037           0 :     ulong t_read_ops=0UL, t_write_ops=0UL;
    1038           0 :     ulong t_acquire_calls=0UL;
    1039             : 
    1040           0 :     switch( kind ) {
    1041           0 : #   define DO_RW( TILE_UPPER )                                                                                                    \
    1042           0 :         t_bytes_read    = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BYTES_READ      ) ];                                                \
    1043           0 :         t_bytes_copied  = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BYTES_COPIED    ) ];                                                \
    1044           0 :         t_bytes_written = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BYTES_WRITTEN   ) ];                                                \
    1045           0 :         t_read_ops      = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_READ_OPERATION  ) ];                                                \
    1046           0 :         t_write_ops     = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_WRITE_OPERATION ) ];                                                \
    1047           0 :         t_acquire_calls = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BATCH_ACQUIRED  ) ];                                                \
    1048           0 :         for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {                                                                     \
    1049           0 :           ulong _acq = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_ACQUIRED          ) + c ];                                     \
    1050           0 :           ulong _acw = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_WRITABLE_ACQUIRED ) + c ];                                     \
    1051           0 :           ulong _nf  = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_NOT_FOUND         ) + c ];                                     \
    1052           0 :           ulong _ev  = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_EVICTED           ) + c ];                                     \
    1053           0 :           ulong _cn  = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_COMMITTED_NEW        ) + c ];                                  \
    1054           0 :           ulong _co  = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_COMMITTED_OVERWRITE  ) + c ];                                  \
    1055           0 :           t_acq+=_acq; t_acw+=_acw; t_misses+=_nf; t_evicted+=_ev; t_committed+=_cn+_co;                                          \
    1056           0 :           cur->acquired_per_class            [ c ] += _acq;                                                                       \
    1057           0 :           cur->acquired_writable_per_class   [ c ] += _acw;                                                                       \
    1058           0 :           cur->not_found_per_class           [ c ] += _nf;                                                                        \
    1059           0 :           cur->evicted_per_class             [ c ] += _ev;                                                                        \
    1060           0 :           cur->committed_new_per_class       [ c ] += _cn;                                                                        \
    1061           0 :           cur->committed_overwrite_per_class [ c ] += _co;                                                                        \
    1062           0 :         }
    1063           0 :       case FD_GUI_ACCDB_TILE_KIND_RW:
    1064           0 :         if(      !strcmp( topo->tiles[ t_idx ].name, "execle" ) ) { DO_RW( EXECLE ); }
    1065           0 :         else if( !strcmp( topo->tiles[ t_idx ].name, "execrp" ) ) { DO_RW( EXECRP ); }
    1066           0 :         else if( !strcmp( topo->tiles[ t_idx ].name, "replay" ) ) { DO_RW( REPLAY ); }
    1067           0 :         else if( !strcmp( topo->tiles[ t_idx ].name, "tower"  ) ) { DO_RW( TOWER  ); }
    1068           0 :         cur->acquired          += t_acq;
    1069           0 :         cur->acquired_writable += t_acw;
    1070           0 :         cur->bytes_read        += t_bytes_read;
    1071           0 :         cur->bytes_copied      += t_bytes_copied;
    1072           0 :         cur->bytes_written     += t_bytes_written;
    1073           0 :         cur->read_ops          += t_read_ops;
    1074           0 :         cur->write_ops         += t_write_ops;
    1075           0 :         break;
    1076           0 : #   undef DO_RW
    1077             : 
    1078           0 : #   define DO_RO( TILE_UPPER )                                                                                                    \
    1079           0 :         t_bytes_read    = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BYTES_READ     ) ];                                                 \
    1080           0 :         t_bytes_copied  = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BYTES_COPIED   ) ];                                                 \
    1081           0 :         t_read_ops      = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_READ_OPERATION ) ];                                                 \
    1082           0 :         t_acquire_calls = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BATCH_ACQUIRED ) ];                                                 \
    1083           0 :         for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {                                                                     \
    1084           0 :           ulong _acq = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_ACQUIRED  ) + c ];                                            \
    1085           0 :           ulong _nf  = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_NOT_FOUND ) + c ];                                            \
    1086           0 :           t_acq+=_acq; t_misses+=_nf;                                                                                             \
    1087           0 :           cur->acquired_per_class [ c ] += _acq;                                                                                  \
    1088           0 :           cur->not_found_per_class[ c ] += _nf;                                                                                   \
    1089           0 :         }
    1090           0 :       case FD_GUI_ACCDB_TILE_KIND_RO:
    1091           0 :         if( !strcmp( topo->tiles[ t_idx ].name, "rpc"    ) ) { DO_RO( RPC    ); }
    1092           0 :         else if( !strcmp( topo->tiles[ t_idx ].name, "resolv" ) ) { DO_RO( RESOLV ); }
    1093           0 :         cur->acquired     += t_acq;
    1094           0 :         cur->bytes_read   += t_bytes_read;
    1095           0 :         cur->bytes_copied += t_bytes_copied;
    1096           0 :         cur->read_ops     += t_read_ops;
    1097           0 :         break;
    1098           0 : #   undef DO_RO
    1099             : 
    1100           0 :       case FD_GUI_ACCDB_TILE_KIND_SNAPWR:
    1101             :         /* snapwr writes account data to disk directly during snapshot
    1102             :            load.  It does not declare the accdb counter surface, only a
    1103             :            BytesWritten gauge.  Include in the aggregate so the IO panel
    1104             :            reflects load-time disk activity. */
    1105           0 :         t_bytes_written = m[ MIDX( GAUGE, SNAPWR, BYTES_WRITTEN ) ];
    1106           0 :         cur->bytes_written += t_bytes_written;
    1107           0 :         break;
    1108             : 
    1109           0 :       case FD_GUI_ACCDB_TILE_KIND_ACCDB:
    1110             :         /* The accdb tile owns prewrite and compaction writes.  Its own
    1111             :            bytes_written/write_ops were already folded into the aggregate
    1112             :            above (see ACCDB_BYTES_WRITTEN / ACCDB_WRITE_OPS reads).  Here
    1113             :            we only stash per-slot values so the per-tile row reflects
    1114             :            them; do not re-add to cur->* or we'd double-count.  The accdb
    1115             :            tile does not expose acquired/not_found/committed (no account
    1116             :            joiner) or read_ops/bytes_copied.  Preevicts are owned by the
    1117             :            accdb tile's background preevict pass, so map them to the
    1118             :            per-tile evicted column for this row. */
    1119           0 :         t_bytes_read    = m[ MIDX( COUNTER, ACCDB, BYTES_READ      ) ];
    1120           0 :         t_bytes_written = m[ MIDX( COUNTER, ACCDB, BYTES_WRITTEN   ) ];
    1121           0 :         t_write_ops     = m[ MIDX( COUNTER, ACCDB, WRITE_OPERATION ) ];
    1122           0 :         for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {
    1123           0 :           t_evicted += m[ MIDX( COUNTER, ACCDB, ACCOUNT_PREEVICTED ) + c ];
    1124           0 :         }
    1125           0 :         break;
    1126           0 :     }
    1127             : 
    1128           0 :     gui->summary.accdb->tile_cur_acquired         [ s ] = t_acq;
    1129           0 :     gui->summary.accdb->tile_cur_acquired_writable[ s ] = t_acw;
    1130           0 :     gui->summary.accdb->tile_cur_bytes_read       [ s ] = t_bytes_read;
    1131           0 :     gui->summary.accdb->tile_cur_bytes_copied     [ s ] = t_bytes_copied;
    1132           0 :     gui->summary.accdb->tile_cur_bytes_written    [ s ] = t_bytes_written;
    1133           0 :     gui->summary.accdb->tile_cur_read_ops         [ s ] = t_read_ops;
    1134           0 :     gui->summary.accdb->tile_cur_write_ops        [ s ] = t_write_ops;
    1135           0 :     gui->summary.accdb->tile_cur_misses           [ s ] = t_misses;
    1136           0 :     gui->summary.accdb->tile_cur_evicted          [ s ] = t_evicted;
    1137           0 :     gui->summary.accdb->tile_cur_committed        [ s ] = t_committed;
    1138           0 :     gui->summary.accdb->tile_cur_acquire_calls    [ s ] = t_acquire_calls;
    1139           0 :   }
    1140             : 
    1141           0 :   if( FD_UNLIKELY( !gui->accdb_shmem ) ) return;
    1142             : 
    1143             :   /* Snapshot per-partition utilization and fragmentation and also
    1144             :      their respective per-tier rate of growth. Actively-compacting
    1145             :      partitions excluded so relocation churn does not degrade estimates. */
    1146           0 :   ulong pcnt = fd_ulong_min( fd_accdb_shmem_partition_max( gui->accdb_shmem ), FD_GUI_MAX_PARTITIONS );
    1147           0 :   gui->summary.accdb->partition_cnt = pcnt;
    1148             : 
    1149           0 :   double tier_fill_delta[ FD_ACCDB_COMPACTION_LAYER_CNT ] = { 0.0 };
    1150           0 :   double tier_free_delta[ FD_ACCDB_COMPACTION_LAYER_CNT ] = { 0.0 };
    1151           0 :   ulong  compaction_idx   = ULONG_MAX;
    1152           0 :   ulong  compaction_layer = FD_ACCDB_COMPACTION_LAYER_CNT;
    1153           0 :   ulong  compaction_state = 0UL;
    1154           0 :   for( ulong p=0UL; p<pcnt; p++ ) {
    1155           0 :     fd_accdb_shmem_partition_info_t   prev_info =  gui->summary.accdb->partitions[ p ];
    1156           0 :     fd_accdb_shmem_partition_info_t * info      = &gui->summary.accdb->partitions[ p ];
    1157           0 :     fd_accdb_shmem_partition_info( gui->accdb_shmem, p, info );
    1158             : 
    1159           0 :     if( FD_UNLIKELY( info->compaction_state && ( compaction_state<info->compaction_state || ( compaction_state==info->compaction_state && info->layer<compaction_layer ) ) ) ) {
    1160           0 :       compaction_idx   = p;
    1161           0 :       compaction_layer = info->layer;
    1162           0 :       compaction_state = info->compaction_state;
    1163           0 :     }
    1164             : 
    1165           0 :     if( FD_LIKELY( info->layer<FD_ACCDB_COMPACTION_LAYER_CNT ) ) {
    1166             :       /* Only the <=3 write-head partitions advance, and freed bytes
    1167             :          land in a handful of partitions per 100ms snap. */
    1168           0 :       if( FD_UNLIKELY( info->write_offset>prev_info.write_offset ) )
    1169           0 :         tier_fill_delta[ info->layer ] += (double)(info->write_offset-prev_info.write_offset);
    1170           0 :       if( FD_UNLIKELY( info->compaction_state!=2 && info->bytes_freed>prev_info.bytes_freed ) )
    1171           0 :         tier_free_delta[ info->layer ] += (double)(info->bytes_freed-prev_info.bytes_freed);
    1172           0 :     }
    1173           0 :   }
    1174             : 
    1175             :   /* First snap has no valid deltas. */
    1176           0 :   if( FD_LIKELY( gui->summary.accdb->tier_sample_nanos!=LONG_MAX ) ) {
    1177           0 :     double dt_sec = (double)(cur->sample_time_nanos-gui->summary.accdb->tier_sample_nanos)/1e9;
    1178           0 :     if( FD_LIKELY( dt_sec>0.0 ) ) {
    1179           0 :       for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
    1180           0 :         fd_gui_ema_advance( &gui->summary.accdb->tier_fill_bps_ema[ k ], cur->sample_time_nanos, tier_fill_delta[ k ]/dt_sec );
    1181           0 :         fd_gui_ema_advance( &gui->summary.accdb->tier_free_bps_ema[ k ], cur->sample_time_nanos, tier_free_delta[ k ]/dt_sec );
    1182           0 :       }
    1183           0 :     }
    1184           0 :   }
    1185           0 :   gui->summary.accdb->tier_sample_nanos = cur->sample_time_nanos;
    1186             : 
    1187             :   /* Estimate next compaction time/partition. */
    1188           0 :   double next_secs = 0.0;
    1189           0 :   ulong  next_idx  = ULONG_MAX;
    1190           0 :   double partition_sz = (double)fd_accdb_shmem_partition_sz( gui->accdb_shmem );
    1191           0 :   double tier_live_bytes[ FD_ACCDB_COMPACTION_LAYER_CNT ] = { 0.0 };
    1192           0 :   for( ulong p=0UL; p<pcnt; p++ ) {
    1193           0 :     fd_accdb_shmem_partition_info_t const * info = &gui->summary.accdb->partitions[ p ];
    1194           0 :     if( info->layer<FD_ACCDB_COMPACTION_LAYER_CNT && info->compaction_state!=2 && info->write_offset>info->bytes_freed && info->compaction_offset<info->write_offset )
    1195           0 :       tier_live_bytes[ info->layer ] += (double)(info->write_offset-info->bytes_freed);
    1196           0 :   }
    1197           0 :   for( ulong p=0UL; p<pcnt; p++ ) {
    1198           0 :     fd_accdb_shmem_partition_info_t const * info = &gui->summary.accdb->partitions[ p ];
    1199           0 :     if( FD_LIKELY( info->compaction_state || !info->write_offset ) ) continue;
    1200           0 :     if( FD_UNLIKELY( info->layer>=FD_ACCDB_COMPACTION_LAYER_CNT ) ) continue;
    1201           0 :     if( FD_UNLIKELY( info->compaction_offset>=info->write_offset ) ) continue; /* compacted, awaiting reclaim */
    1202             : 
    1203           0 :     double free_bps  = gui->summary.accdb->tier_free_bps_ema[ info->layer ].value;
    1204           0 :     double live      = info->write_offset>info->bytes_freed ? (double)(info->write_offset-info->bytes_freed) : 0.0;
    1205           0 :     double frag_rate = tier_live_bytes[ info->layer ]>0.0 ? free_bps*live/tier_live_bytes[ info->layer ] : 0.0;
    1206           0 :     double deficit   = (double)FD_ACCDB_COMPACTION_THRESHOLD_PCT/100.0*partition_sz - (double)info->bytes_freed;
    1207           0 :     double frag_secs = deficit<=0.0 ? 0.0 : ( frag_rate>0.0 ? deficit/frag_rate : -1.0 );
    1208           0 :     double fill_secs = 0.0;
    1209           0 :     if( FD_UNLIKELY( info->is_write_head ) ) {
    1210           0 :       double fill_bps = gui->summary.accdb->tier_fill_bps_ema[ info->layer ].value;
    1211           0 :       fill_secs = fill_bps>0.0 ? (partition_sz-(double)info->write_offset)/fill_bps : -1.0;
    1212           0 :     }
    1213             : 
    1214           0 :     if( FD_UNLIKELY( frag_secs<0.0 || fill_secs<0.0 ) ) continue; /* no usable rate estimate (EMA warm-up) */
    1215           0 :     double est = fmax( frag_secs, fill_secs );
    1216           0 :     if( next_idx==ULONG_MAX || est<next_secs ) {
    1217           0 :       next_secs = est;
    1218           0 :       next_idx  = p;
    1219           0 :     }
    1220           0 :   }
    1221             : 
    1222           0 :   int has_compaction = compaction_idx!=ULONG_MAX;
    1223           0 :   gui->summary.accdb->next_compaction_remaining_secs = fd_double_if( has_compaction, 0.0,            next_secs );
    1224           0 :   gui->summary.accdb->next_compaction_partition_idx  = fd_ulong_if(  has_compaction, compaction_idx, next_idx  );
    1225           0 : }
    1226             : 
    1227             : /* Snapshot all of the data from metrics to construct a view of the
    1228             :    transaction waterfall.
    1229             : 
    1230             :    Tiles are sampled in reverse pipeline order: this helps prevent data
    1231             :    discrepancies where a later tile has "seen" more transactions than an
    1232             :    earlier tile, which shouldn't typically happen. */
    1233             : 
    1234             : static void
    1235             : fd_gui_txn_waterfall_snap( fd_gui_t *               gui,
    1236           6 :                            fd_gui_txn_waterfall_t * cur ) {
    1237           6 :   memset( cur, 0, sizeof(fd_gui_txn_waterfall_t) );
    1238           6 :   fd_topo_t const * topo = gui->topo;
    1239             : 
    1240           6 :   for( ulong i=0UL; i<gui->summary.bank_tile_cnt; i++ ) {
    1241           0 :     fd_topo_tile_t const * bank = &topo->tiles[ fd_topo_find_tile( topo, "bank", i ) ];
    1242             : 
    1243           0 :     volatile ulong const * bank_metrics = fd_metrics_tile( bank->metrics );
    1244           0 :     cur->out.block_success += bank_metrics[ MIDX( COUNTER, BANK, TXN_EXECUTED_SUCCESS ) ];
    1245             : 
    1246           0 :     cur->out.block_fail +=
    1247           0 :         bank_metrics[ MIDX( COUNTER, BANK, TXN_EXECUTED_FAILED ) ]
    1248           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TXN_FEE_ONLY        ) ];
    1249             : 
    1250           0 :     cur->out.bank_invalid +=
    1251           0 :         bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_ACCOUNT_UNINITIALIZED ) ]
    1252           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_ACCOUNT_NOT_FOUND ) ]
    1253           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_INVALID_ACCOUNT_OWNER ) ]
    1254           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_INVALID_ACCOUNT_DATA ) ]
    1255           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_INVALID_LOOKUP_INDEX  ) ];
    1256             : 
    1257           0 :     cur->out.bank_invalid +=
    1258           0 :         bank_metrics[ MIDX( COUNTER, BANK, TXN_PROCESSING_FAILED ) ];
    1259           0 :   }
    1260             : 
    1261           6 :   for( ulong i=0UL; i<gui->summary.execle_tile_cnt; i++ ) {
    1262           0 :     fd_topo_tile_t const * execle = &topo->tiles[ fd_topo_find_tile( topo, "execle", i ) ];
    1263             : 
    1264           0 :     volatile ulong const * execle_metrics = fd_metrics_tile( execle->metrics );
    1265             : 
    1266           0 :     cur->out.block_success += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_LANDED_SUCCESS ) ];
    1267           0 :     cur->out.block_fail    +=
    1268           0 :         execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_LANDED_FEES_ONLY ) ]
    1269           0 :       + execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_LANDED_FAILED ) ];
    1270           0 :     cur->out.bank_invalid  += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_UNLANDED ) ];
    1271             : 
    1272           0 :     cur->out.bank_nonce_already_advanced += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_RESULT_NONCE_ALREADY_ADVANCED ) ];
    1273           0 :     cur->out.bank_nonce_advance_failed   += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_RESULT_NONCE_ADVANCE_FAILED ) ];
    1274           0 :     cur->out.bank_nonce_wrong_blockhash  += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_RESULT_NONCE_WRONG_BLOCKHASH ) ];
    1275           0 :   }
    1276             : 
    1277           6 :   ulong pack_tile_idx = fd_topo_find_tile( topo, "pack", 0UL );
    1278           6 :   if( pack_tile_idx!=ULONG_MAX ) {
    1279           0 :     fd_topo_tile_t const * pack = &topo->tiles[ pack_tile_idx ];
    1280           0 :     volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
    1281             : 
    1282           0 :     cur->out.pack_invalid_bundle =
    1283           0 :         pack_metrics[ MIDX( COUNTER, PACK, TXN_PARTIAL_BUNDLE ) ]
    1284           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTION_FAILED ) ]
    1285           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_CREATION_FAILED ) ];
    1286             : 
    1287           0 :     cur->out.pack_invalid =
    1288           0 :         pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_INSTR_ACCT_CNT ) ]
    1289           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_NONCE_CONFLICT ) ]
    1290           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_BUNDLE_BLACKLIST ) ]
    1291           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_INVALID_NONCE ) ]
    1292           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_WRITE_SYSVAR ) ]
    1293           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_ESTIMATION_FAIL ) ]
    1294           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_DUPLICATE_ACCOUNT ) ]
    1295           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_TOO_MANY_ACCOUNTS ) ]
    1296           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_TOO_LARGE ) ]
    1297           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_ADDR_LUT ) ]
    1298           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_UNAFFORDABLE ) ]
    1299           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_DUPLICATE ) ]
    1300           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 */
    1301             : 
    1302           0 :     cur->out.pack_expired = pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_EXPIRED ) ] +
    1303           0 :                             pack_metrics[ MIDX( COUNTER, PACK, TXN_EXPIRED ) ] +
    1304           0 :                             pack_metrics[ MIDX( COUNTER, PACK, TXN_DELETED ) ] +
    1305           0 :                             pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_NONCE_PRIORITY ) ];
    1306             : 
    1307           0 :     cur->out.pack_already_executed = pack_metrics[ MIDX( COUNTER, PACK, TXN_ALREADY_EXECUTED ) ];
    1308             : 
    1309           0 :     cur->out.pack_leader_slow = pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_PRIORITY ) ];
    1310             : 
    1311           0 :     cur->out.pack_wait_full =
    1312           0 :         pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_DROPPED ) ];
    1313             : 
    1314           0 :     cur->out.pack_retained = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE ) ];
    1315             : 
    1316           0 :     ulong inserted_to_extra = pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_INSERTED ) ];
    1317           0 :     ulong inserted_from_extra = pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_RETRIEVED ) ]
    1318           0 :                                 + pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_DROPPED ) ];
    1319           0 :     cur->out.pack_retained += fd_ulong_if( inserted_to_extra>=inserted_from_extra, inserted_to_extra-inserted_from_extra, 0UL );
    1320             : 
    1321           0 :     cur->in.pack_cranked =
    1322           0 :         pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTED ) ]
    1323           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTION_FAILED ) ]
    1324           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_CREATION_FAILED ) ];
    1325           0 :   }
    1326             : 
    1327           6 :   for( ulong i=0UL; i<gui->summary.resolh_tile_cnt; i++ ) {
    1328           0 :     fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolh", i ) ];
    1329           0 :     volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
    1330             : 
    1331           0 :     cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLH, TXN_NO_BANK ) ];
    1332           0 :     cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLH, BLOCKHASH_EXPIRED ) ]
    1333           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, TXN_BUNDLE_PEER_FAILED  ) ];
    1334           0 :     cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
    1335           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
    1336           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
    1337           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
    1338           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
    1339           0 :     cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_OVERRUN ) ];
    1340             : 
    1341           0 :     ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_INSERTED ) ];
    1342           0 :     ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_OVERRUN ) ]
    1343           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_PUBLISHED ) ]
    1344           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_REMOVED ) ];
    1345           0 :     cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
    1346           0 :   }
    1347             : 
    1348           6 :   for( ulong i=0UL; i<gui->summary.resolv_tile_cnt; i++ ) {
    1349           0 :     fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolv", i ) ];
    1350           0 :     volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
    1351             : 
    1352           0 :     cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_NO_BANK ) ];
    1353           0 :     cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLV, BLOCKHASH_EXPIRED ) ]
    1354           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_BUNDLE_PEER_FAILED  ) ];
    1355           0 :     cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
    1356           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
    1357           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
    1358           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
    1359           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
    1360           0 :     cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ];
    1361             : 
    1362           0 :     ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_INSERTED ) ];
    1363           0 :     ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ]
    1364           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_PUBLISHED ) ]
    1365           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_REMOVED ) ];
    1366           0 :     cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
    1367           0 :   }
    1368             : 
    1369           6 :   ulong dedup_tile_idx = fd_topo_find_tile( topo, "dedup", 0UL );
    1370           6 :   if( FD_UNLIKELY( dedup_tile_idx!=ULONG_MAX ) ) {
    1371           0 :     fd_topo_tile_t const * dedup = &topo->tiles[ dedup_tile_idx ];
    1372           0 :     volatile ulong const * dedup_metrics = fd_metrics_tile( dedup->metrics );
    1373             : 
    1374           0 :     cur->out.dedup_duplicate = dedup_metrics[ MIDX( COUNTER, DEDUP, TXN_RESULT_DEDUP_FAILURE ) ]
    1375           0 :                              + dedup_metrics[ MIDX( COUNTER, DEDUP, TXN_RESULT_BUNDLE_PEER_FAILURE ) ];
    1376           0 :   }
    1377             : 
    1378           6 :   for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
    1379           0 :     fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
    1380           0 :     volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
    1381             : 
    1382           0 :     for( ulong j=0UL; j<gui->summary.quic_tile_cnt; j++ ) {
    1383             :       /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this verify tile. */
    1384           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;
    1385           0 :       cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_READING_OVERRUN_OFF ];
    1386           0 :     }
    1387             : 
    1388           0 :     cur->out.verify_failed    += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_VERIFY_FAILURE ) ] +
    1389           0 :                                  verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_BUNDLE_PEER_FAILURE ) ];
    1390           0 :     cur->out.verify_parse     += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_PARSE_FAILURE ) ];
    1391           0 :     cur->out.verify_duplicate += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_DEDUP_FAILURE ) ];
    1392           0 :   }
    1393             : 
    1394           6 :   for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
    1395           0 :     fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
    1396           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
    1397             : 
    1398           0 :     cur->out.tpu_udp_invalid  += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_UNDERSIZE    ) ];
    1399           0 :     cur->out.tpu_udp_invalid  += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_OVERSIZE     ) ];
    1400           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_UNDERSIZE           ) ];
    1401           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_OVERSIZE            ) ];
    1402           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, TXN_OVERSIZE            ) ];
    1403           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_CRYPTO_FAILED       ) ];
    1404           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NO_CONN             ) ];
    1405           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_SRC_INVALID         ) ];
    1406           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NET_HEADER_INVALID  ) ];
    1407           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_HEADER_INVALID      ) ];
    1408           0 :     cur->out.quic_abandoned   += quic_metrics[ MIDX( COUNTER, QUIC, TXN_ABANDONED           ) ];
    1409           0 :     cur->out.quic_frag_drop   += quic_metrics[ MIDX( COUNTER, QUIC, TXN_OVERRUN             ) ];
    1410             : 
    1411           0 :     for( ulong j=0UL; j<gui->summary.sock_tile_cnt+gui->summary.net_tile_cnt+gui->summary.mlx5_tile_cnt; j++ ) {
    1412             :       /* TODO: Not precise... net frags that were skipped might not have been destined for QUIC tile */
    1413             :       /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this QUIC tile */
    1414           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;
    1415           0 :       cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_READING_OVERRUN_OFF ];
    1416           0 :     }
    1417           0 :   }
    1418             : 
    1419           6 :   for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
    1420           0 :     fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
    1421           0 :     volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
    1422             : 
    1423           0 :     cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_RING_FULL ) ];
    1424           0 :     cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_OTHER_DROPPED ) ];
    1425           0 :     cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_FILL_RING_EMPTY ) ];
    1426           0 :   }
    1427           6 :   ulong bundle_txns_received = 0UL;
    1428           6 :   ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
    1429           6 :   if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
    1430           0 :     fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
    1431           0 :     volatile ulong const * bundle_metrics = fd_metrics_tile( bundle->metrics );
    1432             : 
    1433           0 :     bundle_txns_received = bundle_metrics[ MIDX( COUNTER, BUNDLE, TXN_RX ) ];
    1434           0 :   }
    1435             : 
    1436           6 :   {
    1437           6 :     cur->in.gossip = 0UL;
    1438           6 :     for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
    1439           0 :       fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
    1440           0 :       volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
    1441           0 :       cur->in.gossip += verify_metrics[ MIDX( COUNTER, VERIFY, VOTE_GOSSIP_RX ) ];
    1442           0 :     }
    1443           6 :   }
    1444             : 
    1445           6 :   cur->in.quic     = cur->out.tpu_quic_invalid +
    1446           6 :                      cur->out.quic_overrun +
    1447           6 :                      cur->out.quic_frag_drop +
    1448           6 :                      cur->out.quic_abandoned +
    1449           6 :                      cur->out.net_overrun;
    1450           6 :   cur->in.udp      = cur->out.tpu_udp_invalid;
    1451           6 :   cur->in.block_engine = bundle_txns_received;
    1452           6 :   for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
    1453           0 :     fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
    1454           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
    1455             : 
    1456           0 :     cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_QUIC_FAST ) ];
    1457           0 :     cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_QUIC_FRAG ) ];
    1458           0 :     cur->in.udp  += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_UDP       ) ];
    1459           0 :   }
    1460           6 : }
    1461             : 
    1462             : static void
    1463             : fd_gui_tile_stats_snap( fd_gui_t *                     gui,
    1464             :                         fd_gui_txn_waterfall_t const * waterfall,
    1465             :                         fd_gui_tile_stats_t *          stats,
    1466           0 :                         long                           now ) {
    1467           0 :   memset( stats, 0, sizeof(fd_gui_tile_stats_t) );
    1468           0 :   fd_topo_t const * topo = gui->topo;
    1469             : 
    1470           0 :   stats->sample_time_nanos = now;
    1471             : 
    1472           0 :   for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
    1473           0 :     fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
    1474           0 :     volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
    1475             : 
    1476           0 :     stats->net_in_rx_bytes  += net_metrics[ MIDX( COUNTER, NET, PKT_RX_BYTES ) ];
    1477           0 :     stats->net_out_tx_bytes += net_metrics[ MIDX( COUNTER, NET, PKT_TX_BYTES ) ];
    1478           0 :   }
    1479             : 
    1480           0 :   for( ulong i=0UL; i<gui->summary.sock_tile_cnt; i++ ) {
    1481           0 :     fd_topo_tile_t const * sock = &topo->tiles[ fd_topo_find_tile( topo, "sock", i ) ];
    1482           0 :     volatile ulong * sock_metrics = fd_metrics_tile( sock->metrics );
    1483             : 
    1484           0 :     stats->net_in_rx_bytes  += sock_metrics[ MIDX( COUNTER, SOCK, PKT_RX_BYTES ) ];
    1485           0 :     stats->net_out_tx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, PKT_TX_BYTES ) ];
    1486           0 :   }
    1487             : 
    1488           0 :   for( ulong i=0UL; i<gui->summary.mlx5_tile_cnt; i++ ) {
    1489           0 :     fd_topo_tile_t const * mlx5 = &topo->tiles[ fd_topo_find_tile( topo, "mlx5", i ) ];
    1490           0 :     volatile ulong * mlx5_metrics = fd_metrics_tile( mlx5->metrics );
    1491             : 
    1492           0 :     stats->net_in_rx_bytes  += mlx5_metrics[ MIDX( COUNTER, MLX5, PKT_RX_BYTES ) ];
    1493           0 :     stats->net_out_tx_bytes += mlx5_metrics[ MIDX( COUNTER, MLX5, PKT_TX_BYTES ) ];
    1494           0 :   }
    1495             : 
    1496           0 :   for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
    1497           0 :     fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
    1498           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
    1499             : 
    1500           0 :     stats->quic_conn_cnt += quic_metrics[ MIDX( GAUGE, QUIC, CONN_IN_USE ) ];
    1501           0 :   }
    1502             : 
    1503           0 :   ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
    1504           0 :   if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
    1505           0 :     fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
    1506           0 :     volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
    1507           0 :     stats->bundle_rtt_smoothed_nanos = bundle_metrics[ MIDX( GAUGE, BUNDLE, RTT_SMOOTHED_NANOS ) ];
    1508             : 
    1509           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 ) );
    1510           0 :     stats->bundle_rx_delay_hist.sum = bundle_metrics[ MIDX( HISTOGRAM, BUNDLE, MESSAGE_RX_DELAY_NANOS ) + FD_HISTF_BUCKET_CNT ];
    1511           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 ];
    1512           0 :   }
    1513             : 
    1514           0 :   stats->verify_drop_cnt = waterfall->out.verify_duplicate +
    1515           0 :                            waterfall->out.verify_parse +
    1516           0 :                            waterfall->out.verify_failed;
    1517           0 :   stats->verify_total_cnt = waterfall->in.gossip +
    1518           0 :                             waterfall->in.quic +
    1519           0 :                             waterfall->in.udp -
    1520           0 :                             waterfall->out.net_overrun -
    1521           0 :                             waterfall->out.tpu_quic_invalid -
    1522           0 :                             waterfall->out.tpu_udp_invalid -
    1523           0 :                             waterfall->out.quic_abandoned -
    1524           0 :                             waterfall->out.quic_frag_drop -
    1525           0 :                             waterfall->out.quic_overrun -
    1526           0 :                             waterfall->out.verify_overrun;
    1527           0 :   stats->dedup_drop_cnt = waterfall->out.dedup_duplicate;
    1528           0 :   stats->dedup_total_cnt = stats->verify_total_cnt -
    1529           0 :                            waterfall->out.verify_duplicate -
    1530           0 :                             waterfall->out.verify_parse -
    1531           0 :                             waterfall->out.verify_failed;
    1532             : 
    1533           0 :   ulong pack_tile_idx = fd_topo_find_tile( topo, "pack", 0UL );
    1534           0 :   if( pack_tile_idx!=ULONG_MAX ) {
    1535           0 :     fd_topo_tile_t const * pack  = &topo->tiles[ pack_tile_idx ];
    1536           0 :     volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
    1537           0 :     stats->pack_buffer_cnt      = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE ) ];
    1538           0 :     stats->pack_buffer_capacity = pack->pack.max_pending_transactions;
    1539           0 :   }
    1540             : 
    1541           0 :   stats->bank_txn_exec_cnt = waterfall->out.block_fail + waterfall->out.block_success;
    1542             : 
    1543           0 :   fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_STATS, now, now, stats );
    1544           0 : }
    1545             : 
    1546             : static void
    1547           0 : fd_gui_run_boot_progress( fd_gui_t * gui, long now ) {
    1548           0 :   fd_topo_tile_t const * snapct = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapct", 0UL ) ];
    1549           0 :   volatile ulong * snapct_metrics = fd_metrics_tile( snapct->metrics );
    1550             : 
    1551           0 :   ulong snapdc_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "snapdc" );
    1552             : 
    1553           0 :   fd_topo_tile_t const * snapin = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapin", 0UL ) ];
    1554           0 :   volatile ulong * snapin_metrics = fd_metrics_tile( snapin->metrics );
    1555             : 
    1556           0 :   fd_topo_tile_t const * snapwr = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapwr", 0UL ) ];
    1557           0 :   volatile ulong * snapwr_metrics = fd_metrics_tile( snapwr->metrics );
    1558             : 
    1559             :   /* Backtest topologies have no gossip tile; treat wait-for-supermajority
    1560             :      as done. */
    1561           0 :   ulong            wfs_state       = FD_GOSSIP_WFS_STATE_DONE;
    1562           0 :   volatile ulong * gossip_metrics  = NULL;
    1563           0 :   ulong            gossip_tile_idx = fd_topo_find_tile( gui->topo, "gossip", 0UL );
    1564           0 :   if( FD_LIKELY( gossip_tile_idx!=ULONG_MAX ) ) {
    1565           0 :     fd_topo_tile_t const * gossip = &gui->topo->tiles[ gossip_tile_idx ];
    1566           0 :     gossip_metrics = fd_metrics_tile( gossip->metrics );
    1567           0 :     wfs_state = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STATE ) ];
    1568           0 :   }
    1569             : 
    1570           0 :   ulong snapshot_phase = snapct_metrics[ MIDX( GAUGE, SNAPCT, STATE ) ];
    1571             : 
    1572             :   /* Backtest topologies have no turbine, so the regular catch-up
    1573             :      detection (turbine slot vs. replayed slot) can never trigger.
    1574             :      Consider replay caught up at the first tower root after the
    1575             :      snapshot finishes loading. */
    1576           0 :   if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX &&
    1577           0 :                    snapshot_phase==FD_SNAPCT_STATE_SHUTDOWN &&
    1578           0 :                    gui->summary.slot_tower!=ULONG_MAX &&
    1579           0 :                    fd_topo_find_tile( gui->topo, "backt", 0UL )!=ULONG_MAX ) ) {
    1580           0 :     gui->summary.slot_caught_up = gui->summary.slot_tower;
    1581           0 :     gui->summary.boot_progress.catching_up_time_nanos = now;
    1582             : 
    1583           0 :     fd_gui_printf_slot_caught_up( gui );
    1584           0 :     fd_http_server_ws_broadcast( gui->http );
    1585           0 :   }
    1586             : 
    1587             :   /* state transitions */
    1588           0 :   if( FD_UNLIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
    1589           0 :     gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
    1590           0 :     for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
    1591           0 :       fd_gui_ema_init( &gui->summary.accdb->tier_fill_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
    1592           0 :       fd_gui_ema_init( &gui->summary.accdb->tier_free_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
    1593           0 :     }
    1594           0 :   } else if( FD_LIKELY( snapshot_phase == FD_SNAPCT_STATE_SHUTDOWN && wfs_state==FD_GOSSIP_WFS_STATE_DONE && gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && gui->summary.slot_tower!=ULONG_MAX ) ) {
    1595           0 :     if( FD_UNLIKELY( gui->summary.wfs_enabled ) ) {
    1596           0 :       if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) {
    1597           0 :         ulong snap_inc  = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].slot;
    1598           0 :         ulong snap_full = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].slot;
    1599           0 :         gui->summary.slot_caught_up = fd_ulong_if( snap_inc!=ULONG_MAX, snap_inc, snap_full );
    1600           0 :         gui->summary.boot_progress.catching_up_time_nanos = now;
    1601             : 
    1602           0 :         fd_gui_printf_slot_caught_up( gui );
    1603           0 :         fd_http_server_ws_broadcast( gui->http );
    1604           0 :       }
    1605           0 :       gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
    1606           0 :       for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
    1607           0 :         fd_gui_ema_init( &gui->summary.accdb->tier_fill_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
    1608           0 :         fd_gui_ema_init( &gui->summary.accdb->tier_free_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
    1609           0 :       }
    1610           0 :     } else {
    1611           0 :       gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP;
    1612           0 :     }
    1613           0 :   } else if( FD_UNLIKELY( snapshot_phase == FD_SNAPCT_STATE_SHUTDOWN && wfs_state==FD_GOSSIP_WFS_STATE_WAIT ) ) {
    1614           0 :     gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY;
    1615           0 :   } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_FULL_FILE
    1616           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_FILE_FINI
    1617           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_FILE_DONE
    1618           0 :                      || snapshot_phase==FD_SNAPCT_STATE_READING_FULL_HTTP
    1619           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_FINI
    1620           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_DONE ) ) {
    1621           0 :     gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT;
    1622           0 :   } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_FILE
    1623           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_FINI
    1624           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_DONE
    1625           0 :                      || snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_HTTP
    1626           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_FINI
    1627           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_DONE ) ) {
    1628           0 :     gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
    1629           0 :   }
    1630             : 
    1631             :   /* It's possible for the incremental snapshot phase to be skipped, or
    1632             :      complete before we can sample it.  This ensures we always get at
    1633             :      least one pass of the metrics. */
    1634           0 :   if( FD_UNLIKELY( gui->summary.boot_progress.phase==FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP
    1635           0 :                 && gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].reset_cnt==ULONG_MAX ) ) {
    1636           0 :     gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
    1637           0 :   }
    1638             : 
    1639           0 :   switch ( gui->summary.boot_progress.phase ) {
    1640           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP: {
    1641           0 :       gui->summary.boot_progress.joining_gossip_time_nanos = now;
    1642           0 :       break;
    1643           0 :     }
    1644           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT:
    1645           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT: {
    1646           0 :       ulong snapshot_idx = fd_ulong_if( gui->summary.boot_progress.phase==FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT, FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX );
    1647           0 :       ulong _retry_cnt = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_RETRY ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_RETRY ) ]);
    1648             : 
    1649             :       /* reset boot state if necessary */
    1650           0 :       if( FD_UNLIKELY( gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt!=_retry_cnt ) ) {
    1651           0 :         gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_time_nanos = now;
    1652           0 :         gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt = _retry_cnt;
    1653           0 :       }
    1654             : 
    1655           0 :       ulong _total_bytes                   = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_SIZE_BYTES ) ],                 snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_SIZE_BYTES ) ]                );
    1656           0 :       ulong _read_bytes                    = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_BYTES_READ ) ],                 snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_BYTES_READ ) ]                 );
    1657           0 :       ulong _decompress_decompressed_bytes = fd_gui_metrics_sum_tiles_counter( gui->topo, "snapdc", snapdc_tile_cnt, fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, MIDX( GAUGE, SNAPDC, FULL_DECOMPRESSED_BYTES_WRITTEN ), MIDX( GAUGE, SNAPDC, INCREMENTAL_DECOMPRESSED_BYTES_WRITTEN ) ) );
    1658           0 :       ulong _decompress_compressed_bytes   = fd_gui_metrics_sum_tiles_counter( gui->topo, "snapdc", snapdc_tile_cnt, fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, MIDX( GAUGE, SNAPDC, FULL_COMPRESSED_BYTES_READ ),      MIDX( GAUGE, SNAPDC, INCREMENTAL_COMPRESSED_BYTES_READ )      ) );
    1659           0 :       ulong _insert_bytes                  = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapin_metrics[ MIDX( GAUGE, SNAPIN, FULL_BYTES_READ ) ],                 snapin_metrics[ MIDX( GAUGE, SNAPIN, INCREMENTAL_BYTES_READ ) ]                 );
    1660           0 :       ulong _snapwr_in_bytes               = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapwr_metrics[ MIDX( GAUGE, SNAPWR, FULL_BYTES_READ ) ],                 snapwr_metrics[ MIDX( GAUGE, SNAPWR, INCREMENTAL_BYTES_READ ) ]                 );
    1661             : 
    1662           0 :       ulong _insert_accounts_total         = snapin_metrics[ MIDX( GAUGE, SNAPIN, ACCOUNT_LOADED ) ];
    1663           0 :       ulong _insert_accounts_baseline      = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, 0UL, gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].insert_accounts_current );
    1664           0 :       ulong _insert_accounts               = fd_ulong_sat_sub( _insert_accounts_total, _insert_accounts_baseline );
    1665             : 
    1666           0 :       ulong _snapwr_accounts_total         = snapwr_metrics[ MIDX( GAUGE, SNAPWR, ACCOUNTS_WRITTEN ) ];
    1667           0 :       ulong _snapwr_accounts_baseline      = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, 0UL, gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].snapwr_accounts_current );
    1668           0 :       ulong _snapwr_accounts               = fd_ulong_sat_sub( _snapwr_accounts_total, _snapwr_accounts_baseline );
    1669             : 
    1670           0 :       ulong _snapwr_out_total              = snapwr_metrics[ MIDX( GAUGE, SNAPWR, BYTES_WRITTEN ) ];
    1671           0 :       ulong _snapwr_out_baseline           = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, 0UL, gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].snapwr_out_bytes_decompressed );
    1672           0 :       ulong _snapwr_out_bytes              = fd_ulong_sat_sub( _snapwr_out_total, _snapwr_out_baseline );
    1673             : 
    1674             :       /* metadata */
    1675           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].total_bytes_compressed = _total_bytes;
    1676           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].sample_time_nanos = now;
    1677             : 
    1678             :       /* read stage */
    1679           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_bytes_compressed = _read_bytes;
    1680             : 
    1681             :       /* decompress stage */
    1682           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_compressed   = _decompress_compressed_bytes;
    1683           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_decompressed = _decompress_decompressed_bytes;
    1684             : 
    1685             :       /* insert stage */
    1686           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_bytes_decompressed = _insert_bytes;
    1687           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_accounts_current   = _insert_accounts;
    1688             : 
    1689             :       /* snapwr (snapshot write) stage */
    1690           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].snapwr_in_bytes_decompressed  = _snapwr_in_bytes;
    1691           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].snapwr_out_bytes_decompressed = _snapwr_out_bytes;
    1692           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].snapwr_accounts_current       = _snapwr_accounts;
    1693             : 
    1694           0 :       break;
    1695           0 :     }
    1696           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY: {
    1697             :       /* Only reachable when the topology has a gossip tile. */
    1698           0 :       gui->summary.boot_progress.wfs_total_stake     = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKE_TOTAL ) ];
    1699           0 :       gui->summary.boot_progress.wfs_connected_stake = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKE_ONLINE ) ];
    1700           0 :       gui->summary.boot_progress.wfs_total_peers     = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKED_PEER_TOTAL ) ];
    1701           0 :       gui->summary.boot_progress.wfs_connected_peers = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKED_PEER_ONLINE ) ];
    1702           0 :       break;
    1703           0 :     }
    1704           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP: {
    1705           0 :       gui->summary.boot_progress.catching_up_time_nanos = now;
    1706           0 :       break;
    1707           0 :     }
    1708           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_RUNNING: break;
    1709           0 :     default: FD_LOG_ERR(( "unknown boot progress phase: %d", gui->summary.boot_progress.phase ));
    1710           0 :   }
    1711           0 : }
    1712             : 
    1713             : static inline int
    1714           0 : fd_gui_ephemeral_slots_contains( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot ) {
    1715           0 :   for( ulong i=0UL; i<slots_sz; i++ ) {
    1716           0 :     if( FD_UNLIKELY( slots[ i ].slot==ULONG_MAX ) ) break;
    1717           0 :     if( FD_UNLIKELY( slots[ i ].slot==slot ) ) return 1;
    1718           0 :   }
    1719           0 :   return 0;
    1720           0 : }
    1721             : 
    1722             : #define SORT_NAME fd_gui_ephemeral_slot_sort
    1723           0 : #define SORT_KEY_T fd_gui_ephemeral_slot_t
    1724           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 ) ) )
    1725             : #include "../../util/tmpl/fd_sort.c"
    1726             : 
    1727             : static inline void
    1728           0 : fd_gui_try_insert_ephemeral_slot( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot, long now ) {
    1729           0 :   int already_present = 0;
    1730           0 :   for( ulong i=0UL; i<slots_sz; i++ ) {
    1731             :     /* evict any slots older than 4.8 seconds */
    1732           0 :     if( FD_UNLIKELY( slots[ i ].slot!=ULONG_MAX && now-slots[ i ].timestamp_arrival_nanos>4800000000L ) ) {
    1733           0 :       slots[ i ].slot = ULONG_MAX;
    1734           0 :       continue;
    1735           0 :     }
    1736             : 
    1737             :     /* if we've already seen this slot, just update the timestamp */
    1738           0 :     if( FD_UNLIKELY( slots[ i ].slot==slot ) ) {
    1739           0 :       slots[ i ].timestamp_arrival_nanos = now;
    1740           0 :       already_present = 1;
    1741           0 :     }
    1742           0 :   }
    1743           0 :   if( FD_LIKELY( already_present ) ) return;
    1744             : 
    1745             :   /* Insert the new slot number, evicting a smaller slot if necessary */
    1746           0 :   slots[ slots_sz ].timestamp_arrival_nanos = now;
    1747           0 :   slots[ slots_sz ].slot = slot;
    1748           0 :   fd_gui_ephemeral_slot_sort_insert( slots, slots_sz+1UL );
    1749           0 : }
    1750             : 
    1751             : static inline void
    1752           0 : fd_gui_try_insert_run_length_slot( ulong * slots, ulong capacity, ulong * slots_sz, ulong slot ) {
    1753             :   /* catch up history is run-length encoded */
    1754           0 :   ulong range_idx = fd_sort_up_ulong_split( slots, *slots_sz, slot );
    1755           0 :   if( FD_UNLIKELY( range_idx<(*slots_sz)-1UL              && range_idx%2UL==0UL && slots[ range_idx ]<=slot && slots[ range_idx+1UL ]>=slot ) ) return;
    1756           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;
    1757             : 
    1758           0 :   slots[ (*slots_sz)++ ] = slot;
    1759           0 :   slots[ (*slots_sz)++ ] = slot;
    1760             : 
    1761           0 :   fd_sort_up_ulong_insert( slots, (*slots_sz) );
    1762             : 
    1763             :   /* colesce ranges */
    1764           0 :   ulong removed = 0UL;
    1765           0 :   for( ulong i=1UL; i<(*slots_sz)-1UL; i+=2 ) {
    1766           0 :     if( FD_UNLIKELY( slots[ i ]+1UL==slots[ i+1UL ] ) ) {
    1767           0 :       slots[ i ]     = ULONG_MAX;
    1768           0 :       slots[ i+1UL ] = ULONG_MAX;
    1769           0 :       removed += 2;
    1770           0 :     }
    1771           0 :   }
    1772             : 
    1773           0 :   if( FD_UNLIKELY( (*slots_sz)>=removed+capacity-2UL && (*slots_sz)>=4UL ) ) {
    1774             :     /* We are at capacity, start coalescing earlier intervals. */
    1775           0 :     slots[ 1 ] = ULONG_MAX;
    1776           0 :     slots[ 2 ] = ULONG_MAX;
    1777           0 :     removed += 2;
    1778           0 :   }
    1779             : 
    1780           0 :   fd_sort_up_ulong_insert( slots, (*slots_sz) );
    1781           0 :   (*slots_sz) -= removed;
    1782           0 : }
    1783             : 
    1784             : void
    1785           0 : fd_gui_handle_repair_slot( fd_gui_t * gui, ulong slot, long now ) {
    1786           0 :   int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot );
    1787           0 :   fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot, now );
    1788             : 
    1789           0 :   if( FD_UNLIKELY( !was_sent && slot!=gui->summary.slot_repair ) ) {
    1790           0 :     gui->summary.slot_repair = slot;
    1791             : 
    1792           0 :     fd_gui_printf_repair_slot( gui );
    1793           0 :     fd_http_server_ws_broadcast( gui->http );
    1794             : 
    1795           0 :     if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) fd_gui_try_insert_run_length_slot( gui->summary.catch_up_repair, FD_GUI_REPAIR_CATCH_UP_HISTORY_SZ, &gui->summary.catch_up_repair_sz, slot );
    1796           0 :   }
    1797           0 : }
    1798             : 
    1799             : static void
    1800           0 : fd_gui_sample_repair_slot( fd_gui_t * gui, long now ) {
    1801           0 :   ulong slot;
    1802             : 
    1803           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
    1804           0 :     ulong rotor_tile_idx = fd_topo_find_tile( gui->topo, "rotor", 0UL );
    1805           0 :     if( FD_UNLIKELY( rotor_tile_idx==ULONG_MAX ) ) return;
    1806           0 :     fd_topo_tile_t const * rotor = &gui->topo->tiles[ rotor_tile_idx ];
    1807           0 :     volatile ulong const * rotor_metrics = fd_metrics_tile( rotor->metrics );
    1808           0 :     slot = rotor_metrics[ MIDX( GAUGE, ROTOR, SLOT_HIGHEST_REPAIRED ) ];
    1809           0 :   } else {
    1810           0 :     ulong repair_tile_idx = fd_topo_find_tile( gui->topo, "repair", 0UL );
    1811           0 :     if( FD_UNLIKELY( repair_tile_idx==ULONG_MAX ) ) return;
    1812           0 :     fd_topo_tile_t const * repair = &gui->topo->tiles[ repair_tile_idx ];
    1813           0 :     volatile ulong const * repair_metrics = fd_metrics_tile( repair->metrics );
    1814           0 :     slot = repair_metrics[ MIDX( GAUGE, REPAIR, SLOT_HIGHEST_REPAIRED ) ];
    1815           0 :   }
    1816             : 
    1817           0 :   fd_gui_handle_repair_slot( gui, slot, now );
    1818           0 : }
    1819             : 
    1820             : void
    1821           0 : fd_gui_handle_repair_request( fd_gui_t * gui, ulong slot, ulong shred_idx, long now ) {
    1822           0 :   fd_gui_hist_ts_append( gui, FD_GUI_HIST_SHRED_EVENTS, now, now, &(fd_gui_slot_history_shred_event_t){ .slot = (uint)slot, .timestamp = now, .shred_idx = (ushort)shred_idx, .event = FD_GUI_SLOT_SHRED_REPAIR_REQUEST } );
    1823           0 : }
    1824             : 
    1825             : static void
    1826           0 : fd_gui_progcache_sample( fd_gui_t * gui ) {
    1827           0 :   fd_topo_t const * topo = gui->topo;
    1828             : 
    1829           0 :   ulong hits    = 0UL;
    1830           0 :   ulong lookups = 0UL;
    1831             : 
    1832           0 :   for( ulong i=0UL; i<gui->summary.execrp_tile_cnt; i++ ) {
    1833           0 :     fd_topo_tile_t const * execrp = &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ];
    1834           0 :     volatile ulong const * metrics = fd_metrics_tile( execrp->metrics );
    1835             : 
    1836           0 :     lookups += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_LOOKUP ) ];
    1837           0 :     hits    += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_HIT    ) ];
    1838           0 :   }
    1839             : 
    1840             :   /* The execrp tile writes lookups before hits in metrics_write, so
    1841             :      reading lookups first then hits here means we may observe the
    1842             :      new hits before the new lookups, giving hits > lookups
    1843             :      momentarily.  Clamp to maintain the invariant hits <= lookups. */
    1844             : 
    1845           0 :   hits = fd_ulong_min( hits, lookups );
    1846             : 
    1847           0 :   ulong ring_idx       = gui->summary.progcache_history_idx % FD_GUI_PROGCACHE_HISTORY_CNT;
    1848           0 :   ulong oldest_hits    = gui->summary.progcache_hits_history   [ ring_idx ];
    1849           0 :   ulong oldest_lookups = gui->summary.progcache_lookups_history[ ring_idx ];
    1850             : 
    1851           0 :   gui->summary.progcache_hits_history   [ ring_idx ] = hits;
    1852           0 :   gui->summary.progcache_lookups_history[ ring_idx ] = lookups;
    1853           0 :   gui->summary.progcache_history_idx = gui->summary.progcache_history_idx + 1UL;
    1854             : 
    1855           0 :   ulong hits_1min    = hits    - oldest_hits;
    1856           0 :   ulong lookups_1min = lookups - oldest_lookups;
    1857           0 :   hits_1min = fd_ulong_min( hits_1min, lookups_1min );
    1858             : 
    1859           0 :   gui->summary.progcache_hits_1min    = hits_1min;
    1860           0 :   gui->summary.progcache_lookups_1min = lookups_1min;
    1861           0 : }
    1862             : 
    1863             : int
    1864           0 : fd_gui_poll( fd_gui_t * gui, long now ) {
    1865           0 :   if( FD_LIKELY( now>gui->next_sample_1sec ) ) {
    1866           0 :     fd_gui_hist_evict_step( gui );
    1867             : 
    1868           0 :     for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
    1869           0 :       fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_TIMERS, now, now, &gui->summary.tile_timers_packed[ i ] );
    1870           0 :     }
    1871             : 
    1872           0 :     gui->next_sample_1sec += 1000L*1000L*1000L;
    1873           0 :     return 1;
    1874           0 :   }
    1875             : 
    1876           0 :   if( FD_LIKELY( now>gui->next_sample_200millis ) ) {
    1877           0 :     fd_gui_estimated_tps_snap( gui );
    1878           0 :     fd_gui_printf_estimated_tps( gui );
    1879           0 :     fd_http_server_ws_broadcast( gui->http );
    1880             : 
    1881           0 :     if( FD_LIKELY( !gui->leader_active ) ) {
    1882           0 :       for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
    1883           0 :         fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_TIMERS, now, now, &gui->summary.tile_timers_packed[ i ] );
    1884           0 :       }
    1885           0 :     }
    1886             : 
    1887           0 :     gui->next_sample_200millis += 200L*1000L*1000L;
    1888           0 :     return 1;
    1889           0 :   }
    1890             : 
    1891           0 :   if( FD_LIKELY( now>gui->next_sample_100millis ) ) {
    1892           0 :     fd_gui_txn_waterfall_snap( gui, gui->summary.txn_waterfall_current );
    1893           0 :     fd_gui_printf_live_txn_waterfall( gui, gui->summary.txn_waterfall_reference, gui->summary.txn_waterfall_current, 0UL /* TODO: REAL NEXT LEADER SLOT */ );
    1894           0 :     fd_http_server_ws_broadcast( gui->http );
    1895             : 
    1896           0 :     if( FD_LIKELY( gui->leader_active ) ) {
    1897           0 :       gui->summary.txn_waterfall_current->sample_time_nanos = now;
    1898           0 :       fd_gui_hist_ts_append( gui, FD_GUI_HIST_TXN_WATERFALL, now, now, gui->summary.txn_waterfall_current );
    1899           0 :     }
    1900             : 
    1901           0 :     fd_gui_network_stats_snap( gui, gui->summary.network_stats_current );
    1902           0 :     fd_gui_network_rate_max_update( gui, now );
    1903           0 :     fd_gui_printf_live_network_metrics( gui, gui->summary.network_stats_current );
    1904           0 :     fd_http_server_ws_broadcast( gui->http );
    1905             : 
    1906           0 :     *gui->summary.tile_stats_reference = *gui->summary.tile_stats_current;
    1907           0 :     fd_gui_tile_stats_snap( gui, gui->summary.txn_waterfall_current, gui->summary.tile_stats_current, now );
    1908           0 :     fd_gui_printf_live_tile_stats( gui, gui->summary.tile_stats_reference, gui->summary.tile_stats_current );
    1909           0 :     fd_http_server_ws_broadcast( gui->http );
    1910             : 
    1911           0 :     {
    1912           0 :       fd_gui_progcache_sample( gui );
    1913           0 :       fd_gui_printf_live_program_cache( gui );
    1914           0 :       fd_http_server_ws_broadcast( gui->http );
    1915             : 
    1916           0 :       *gui->summary.accounts_stats_reference = *gui->summary.accounts_stats_current;
    1917           0 :       fd_gui_accounts_stats_snap( gui, gui->summary.accounts_stats_current );
    1918           0 :       fd_gui_printf_accounts_stats( gui );
    1919           0 :       fd_http_server_ws_broadcast( gui->http );
    1920           0 :       gui->summary.accounts_stats_have_reference = 1;
    1921           0 :     }
    1922             : 
    1923           0 :     if( FD_UNLIKELY( gui->summary.boot_progress.phase!=FD_GUI_BOOT_PROGRESS_TYPE_RUNNING ) ) {
    1924           0 :       fd_gui_run_boot_progress( gui, now );
    1925           0 :       if( FD_UNLIKELY( memcmp( &gui->summary.boot_progress, &gui->summary.prev_boot_progress, sizeof(fd_gui_boot_progress_t) ) ) ) {
    1926           0 :         gui->summary.prev_boot_progress = gui->summary.boot_progress;
    1927           0 :         fd_gui_printf_boot_progress( gui );
    1928           0 :         fd_http_server_ws_broadcast( gui->http );
    1929           0 :       }
    1930           0 :     }
    1931             : 
    1932           0 :     ulong bundle_tile_idx = fd_topo_find_tile( gui->topo, "bundle", 0UL );
    1933           0 :     if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
    1934           0 :       volatile ulong const * bundle_metrics = fd_metrics_tile( gui->topo->tiles[ bundle_tile_idx ].metrics );
    1935           0 :       int cur_state = (int)bundle_metrics[ MIDX( GAUGE, BUNDLE, STATE ) ];
    1936           0 :       if( FD_UNLIKELY( cur_state != gui->block_engine.status ) ) {
    1937           0 :         gui->block_engine.status = cur_state;
    1938           0 :         fd_gui_printf_block_engine( gui );
    1939           0 :         fd_http_server_ws_broadcast( gui->http );
    1940           0 :       }
    1941           0 :     }
    1942             : 
    1943           0 :     fd_gui_printf_health( gui );
    1944           0 :     fd_http_server_ws_broadcast( gui->http );
    1945             : 
    1946           0 :     gui->next_sample_100millis += 100L*1000L*1000L;
    1947           0 :     return 1;
    1948           0 :   }
    1949             : 
    1950           0 :   if( FD_LIKELY( now>gui->next_sample_50millis ) ) {
    1951           0 :     if( FD_LIKELY( !fd_gui_shreds_window_is_empty( gui, gui->shreds.broadcast_watermark_ns, now ) ) ) {
    1952           0 :       fd_gui_printf_shred_updates( gui, gui->shreds.broadcast_watermark_ns, now );
    1953           0 :       fd_http_server_ws_broadcast( gui->http );
    1954           0 :     }
    1955           0 :     gui->shreds.broadcast_watermark_ns = now;
    1956             : 
    1957             :     /* We get the repair slot from the sampled metric after catching up
    1958             :        and from incoming shred data before catchup. This makes the
    1959             :        catchup progress bar look complete while also keeping the
    1960             :        overview slots vis correct.  TODO: do this properly using frags
    1961             :        sent over a link */
    1962           0 :     if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) fd_gui_sample_repair_slot( gui, now );
    1963             : 
    1964           0 :     if( FD_UNLIKELY( gui->snapsv.pending_cnt ) ) {
    1965           0 :       fd_gui_printf_snapshot_transfers( gui );
    1966           0 :       fd_http_server_ws_broadcast( gui->http );
    1967           0 :       gui->snapsv.pending_cnt = 0UL;
    1968           0 :     }
    1969             : 
    1970           0 :     gui->next_sample_50millis += 50L*1000L*1000L;
    1971           0 :     return 1;
    1972           0 :   }
    1973             : 
    1974           0 :   if( FD_LIKELY( now>gui->next_sample_40millis ) ) {
    1975           0 :     fd_gui_tile_timers_snap( gui, now );
    1976             : 
    1977           0 :     fd_gui_printf_live_tile_timers( gui );
    1978           0 :     fd_http_server_ws_broadcast( gui->http );
    1979             : 
    1980           0 :     fd_gui_printf_live_tile_metrics( gui );
    1981           0 :     fd_http_server_ws_broadcast( gui->http );
    1982             : 
    1983           0 :     if( FD_LIKELY( gui->leader_active ) ) {
    1984           0 :       for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
    1985           0 :         fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_TIMERS, now, now, &gui->summary.tile_timers_packed[ i ] );
    1986           0 :       }
    1987           0 :     }
    1988             : 
    1989           0 :     gui->next_sample_40millis += 40L*1000L*1000L;
    1990           0 :     return 1;
    1991           0 :   }
    1992             : 
    1993           0 :   if( FD_LIKELY( now>gui->next_sample_10millis ) ) {
    1994           0 :     if( FD_UNLIKELY( gui->leader_active ) ) fd_gui_scheduler_counts_snap( gui, now );
    1995             : 
    1996           0 :     fd_gui_printf_server_time_nanos( gui, now );
    1997           0 :     fd_http_server_ws_broadcast( gui->http );
    1998             : 
    1999           0 :     gui->next_sample_10millis += 10L*1000L*1000L;
    2000           0 :     return 1;
    2001           0 :   }
    2002             : 
    2003           0 :   return 0;
    2004           0 : }
    2005             : 
    2006             : int
    2007             : fd_gui_request_slot( fd_gui_t *    gui,
    2008             :                      ulong         ws_conn_id,
    2009             :                      ulong         request_id,
    2010           0 :                      cJSON const * params ) {
    2011           0 :   const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
    2012           0 :   if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2013             : 
    2014           0 :   ulong _slot = slot_param->valueulong;
    2015           0 :   fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, _slot );
    2016           0 :   int known = slot && ( slot->skip!=FD_GUI_SKIP_STATUS_UNKNOWN || fd_gui_ag_slot_is_skip_notarized( gui, _slot ) );
    2017           0 :   if( FD_UNLIKELY( !known ) ) {
    2018           0 :     fd_gui_printf_null_query_response( gui->http, "slot", "query", request_id );
    2019           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    2020           0 :     return 0;
    2021           0 :   }
    2022             : 
    2023           0 :   fd_gui_printf_slot_request( gui, _slot, request_id, slot );
    2024           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    2025           0 :   return 0;
    2026           0 : }
    2027             : 
    2028             : int
    2029             : fd_gui_request_slot_transactions( fd_gui_t *    gui,
    2030             :                                   ulong         ws_conn_id,
    2031             :                                   ulong         request_id,
    2032           0 :                                   cJSON const * params ) {
    2033           0 :   const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
    2034           0 :   if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2035             : 
    2036           0 :   ulong _slot = slot_param->valueulong;
    2037           0 :   fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, _slot );
    2038           0 :   if( FD_UNLIKELY( !slot || slot->skip==FD_GUI_SKIP_STATUS_UNKNOWN ) ) {
    2039           0 :     fd_gui_printf_null_query_response( gui->http, "slot", "query_transactions", request_id );
    2040           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    2041           0 :     return 0;
    2042           0 :   }
    2043             : 
    2044           0 :   fd_gui_printf_slot_transactions_request( gui, _slot, request_id, slot );
    2045           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    2046           0 :   return 0;
    2047           0 : }
    2048             : 
    2049             : int
    2050             : fd_gui_request_slot_detailed( fd_gui_t *    gui,
    2051             :                               ulong         ws_conn_id,
    2052             :                               ulong         request_id,
    2053           0 :                               cJSON const * params ) {
    2054           0 :   const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
    2055           0 :   if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2056             : 
    2057           0 :   ulong _slot = slot_param->valueulong;
    2058           0 :   fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, _slot );
    2059           0 :   int known = slot && ( slot->skip!=FD_GUI_SKIP_STATUS_UNKNOWN || fd_gui_ag_slot_is_skip_notarized( gui, _slot ) );
    2060           0 :   if( FD_UNLIKELY( !known ) ) {
    2061           0 :     fd_gui_printf_null_query_response( gui->http, "slot", "query_detailed", request_id );
    2062           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    2063           0 :     return 0;
    2064           0 :   }
    2065             : 
    2066           0 :   fd_gui_printf_slot_request_detailed( gui, _slot, request_id, slot );
    2067           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    2068           0 :   return 0;
    2069           0 : }
    2070             : 
    2071             : static inline ulong
    2072           0 : fd_gui_slot_duration( fd_gui_t * gui, fd_gui_slot_t const * cur ) {
    2073           0 :   if( FD_UNLIKELY( cur->skip==FD_GUI_SKIP_STATUS_FINALIZED || cur->completed_time==LONG_MAX ) ) return ULONG_MAX;
    2074           0 :   fd_gui_slot_t const * prev = fd_gui_slot_get_any( gui, cur->slot-1UL );
    2075           0 :   long parent_completed_time = LONG_MAX;
    2076           0 :   if( FD_LIKELY( prev && prev->skip!=FD_GUI_SKIP_STATUS_FINALIZED ) ) parent_completed_time = prev->completed_time;
    2077           0 :   if( FD_UNLIKELY( parent_completed_time==LONG_MAX ) ) return ULONG_MAX;
    2078             : 
    2079           0 :   return (ulong)(cur->completed_time - parent_completed_time);
    2080           0 : }
    2081             : 
    2082             : /* All rankings are initialized / reset to ULONG_MAX.  These sentinels
    2083             :    sort AFTER non-sentinel ranking entries.  Equal slots are sorted by
    2084             :    oldest slot AFTER.  Otherwise sort by value according to ranking
    2085             :    type. */
    2086             : #define SORT_NAME fd_gui_slot_ranking_sort
    2087           0 : #define SORT_KEY_T fd_gui_slot_ranking_t
    2088           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_GUI_SLOT_RANKING_TYPE_DESC, (a).value>(b).value, (a).value<(b).value ) ) ) )
    2089             : #include "../../util/tmpl/fd_sort.c"
    2090             : 
    2091             : static inline void
    2092             : fd_gui_try_insert_ranking( fd_gui_t               * gui,
    2093             :                            fd_gui_slot_rankings_t * rankings,
    2094           0 :                            fd_gui_slot_t const    * slot ) {
    2095             :   /* Rankings are inserted into an extra slot at the end of the ranking
    2096             :      array, then the array is sorted. */
    2097           0 : #define TRY_INSERT_SLOT( ranking_name, ranking_slot, ranking_value ) \
    2098           0 :   do { \
    2099           0 :     rankings->FD_CONCAT2(largest_, ranking_name) [ FD_GUI_SLOT_RANKINGS_SZ ] = (fd_gui_slot_ranking_t){ .slot = (ranking_slot), .value = (ranking_value), .type = FD_GUI_SLOT_RANKING_TYPE_DESC }; \
    2100           0 :     fd_gui_slot_ranking_sort_insert( rankings->FD_CONCAT2(largest_, ranking_name), FD_GUI_SLOT_RANKINGS_SZ+1UL ); \
    2101           0 :     rankings->FD_CONCAT2(smallest_, ranking_name)[ FD_GUI_SLOT_RANKINGS_SZ ] = (fd_gui_slot_ranking_t){ .slot = (ranking_slot), .value = (ranking_value), .type = FD_GUI_SLOT_RANKING_TYPE_ASC  }; \
    2102           0 :     fd_gui_slot_ranking_sort_insert( rankings->FD_CONCAT2(smallest_, ranking_name), FD_GUI_SLOT_RANKINGS_SZ+1UL ); \
    2103           0 :   } while (0)
    2104             : 
    2105           0 :     if( slot->skip==FD_GUI_SKIP_STATUS_FINALIZED ) {
    2106           0 :       TRY_INSERT_SLOT( skipped, slot->slot, slot->slot );
    2107           0 :       return;
    2108           0 :     }
    2109             : 
    2110           0 :     ulong dur = fd_gui_slot_duration( gui, slot );
    2111           0 :     if( FD_LIKELY( dur!=ULONG_MAX ) ) TRY_INSERT_SLOT( duration, slot->slot, dur                         );
    2112           0 :     TRY_INSERT_SLOT( tips,           slot->slot, slot->tips                                              );
    2113           0 :     TRY_INSERT_SLOT( fees,           slot->slot, slot->priority_fee + slot->transaction_fee              );
    2114           0 :     TRY_INSERT_SLOT( rewards,        slot->slot, slot->tips + slot->priority_fee + slot->transaction_fee );
    2115           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 );
    2116           0 :     TRY_INSERT_SLOT( compute_units,  slot->slot, slot->compute_units                                     );
    2117           0 : #undef TRY_INSERT_SLOT
    2118           0 : }
    2119             : 
    2120             : static void
    2121           0 : fd_gui_update_slot_rankings( fd_gui_t * gui ) {
    2122           0 :   if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) return;
    2123           0 :   ulong first_replay_slot = fd_gui_first_replay_slot( gui );
    2124           0 :   if( FD_UNLIKELY( first_replay_slot==ULONG_MAX ) ) return;
    2125           0 :   if( FD_UNLIKELY( gui->summary.slot_rooted==ULONG_MAX ) ) return;
    2126             : 
    2127           0 :   fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, gui->summary.slot_rooted );
    2128           0 :   if( FD_UNLIKELY( !epoch ) ) return;
    2129             : 
    2130             :   /* No new slots since the last update */
    2131           0 :   if( FD_UNLIKELY( epoch->rankings_slot>gui->summary.slot_rooted ) ) return;
    2132             : 
    2133             :   /* Slots before first_replay_slot are unavailable. */
    2134           0 :   epoch->rankings_slot = fd_ulong_max( epoch->rankings_slot, first_replay_slot );
    2135             : 
    2136             :   /* Update the rankings. Only look through slots we haven't already. */
    2137           0 :   for( ulong s = gui->summary.slot_rooted; s>=epoch->rankings_slot; s--) {
    2138           0 :     fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, s );
    2139           0 :     if( FD_UNLIKELY( slot->skip==FD_GUI_SKIP_STATUS_UNKNOWN ) ) break;
    2140             : 
    2141           0 :     fd_gui_try_insert_ranking( gui, epoch->rankings, slot );
    2142           0 :     if( FD_UNLIKELY( slot->mine ) ) fd_gui_try_insert_ranking( gui, epoch->my_rankings, slot );
    2143           0 :   }
    2144             : 
    2145           0 :   epoch->rankings_slot = gui->summary.slot_rooted + 1UL;
    2146           0 : }
    2147             : 
    2148             : int
    2149             : fd_gui_request_slot_rankings( fd_gui_t *    gui,
    2150             :                               ulong         ws_conn_id,
    2151             :                               ulong         request_id,
    2152           0 :                               cJSON const * params ) {
    2153           0 :   const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "mine" );
    2154           0 :   if( FD_UNLIKELY( !cJSON_IsBool( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2155             : 
    2156           0 :   int mine = !!(slot_param->type & cJSON_True);
    2157           0 :   fd_gui_update_slot_rankings( gui );
    2158           0 :   fd_gui_printf_slot_rankings_request( gui, request_id, mine );
    2159           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    2160           0 :   return 0;
    2161           0 : }
    2162             : 
    2163             : static inline int
    2164             : fd_gui_cjson_parse_ns( cJSON const * param,
    2165           0 :                           long *        out ) {
    2166           0 :   if( FD_UNLIKELY( !param ) ) return -1;
    2167           0 :   if( cJSON_IsNumber( param ) ) {
    2168           0 :     double v = param->valuedouble;
    2169           0 :     if( FD_UNLIKELY( !(v>=0.0 && v<(double)LONG_MAX) ) ) return -1;
    2170           0 :     *out = (long)v;
    2171           0 :     return 0;
    2172           0 :   }
    2173           0 :   if( cJSON_IsString( param ) && param->valuestring ) {
    2174           0 :     *out = fd_cstr_to_long( param->valuestring );
    2175           0 :     return 0;
    2176           0 :   }
    2177           0 :   return -1;
    2178           0 : }
    2179             : 
    2180             : static int
    2181             : fd_gui_request_timeline_shreds( fd_gui_t *    gui,
    2182             :                                 ulong         ws_conn_id,
    2183             :                                 char const *  topic,
    2184             :                                 ulong         request_id,
    2185           0 :                                 cJSON const * params ) {
    2186           0 :   const cJSON * start_param = cJSON_GetObjectItemCaseSensitive( params, "start_ns" );
    2187           0 :   const cJSON * end_param   = cJSON_GetObjectItemCaseSensitive( params, "end_ns"   );
    2188             : 
    2189           0 :   long start_ns, end_ns;
    2190           0 :   if( FD_UNLIKELY( fd_gui_cjson_parse_ns( start_param, &start_ns ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2191           0 :   if( FD_UNLIKELY( fd_gui_cjson_parse_ns( end_param,   &end_ns   ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2192           0 :   if( FD_UNLIKELY( !(start_ns>=0L && start_ns<LONG_MAX) || !(end_ns>=0L && end_ns<LONG_MAX) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2193           0 :   if( FD_UNLIKELY( end_ns<start_ns ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2194           0 :   if( FD_UNLIKELY( end_ns-start_ns>60L*1000L*1000L*1000L ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST; /* TODO: tune/remove */
    2195             : 
    2196           0 :   fd_gui_printf_timeline_query_shreds( gui, topic, start_ns, end_ns, request_id );
    2197           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    2198           0 :   return 0;
    2199           0 : }
    2200             : 
    2201             : int
    2202             : fd_gui_ws_message( fd_gui_t *    gui,
    2203             :                    ulong         ws_conn_id,
    2204             :                    uchar const * data,
    2205           0 :                    ulong         data_len ) {
    2206             :   /* TODO: cJSON allocates, might fail SIGSYS due to brk(2)...
    2207             :      switch off this (or use wksp allocator) */
    2208           0 :   const char * parse_end;
    2209           0 :   cJSON * json = cJSON_ParseWithLengthOpts( (char *)data, data_len, &parse_end, 0 );
    2210           0 :   if( FD_UNLIKELY( !json ) ) {
    2211           0 :     return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2212           0 :   }
    2213             : 
    2214           0 :   const cJSON * node = cJSON_GetObjectItemCaseSensitive( json, "id" );
    2215           0 :   if( FD_UNLIKELY( !cJSON_IsNumber( node ) ) ) {
    2216           0 :     cJSON_Delete( json );
    2217           0 :     return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2218           0 :   }
    2219           0 :   ulong id = node->valueulong;
    2220             : 
    2221           0 :   const cJSON * topic = cJSON_GetObjectItemCaseSensitive( json, "topic" );
    2222           0 :   if( FD_UNLIKELY( !cJSON_IsString( topic ) || topic->valuestring==NULL ) ) {
    2223           0 :     cJSON_Delete( json );
    2224           0 :     return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2225           0 :   }
    2226             : 
    2227           0 :   const cJSON * key = cJSON_GetObjectItemCaseSensitive( json, "key" );
    2228           0 :   if( FD_UNLIKELY( !cJSON_IsString( key ) || key->valuestring==NULL ) ) {
    2229           0 :     cJSON_Delete( json );
    2230           0 :     return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2231           0 :   }
    2232             : 
    2233           0 :   if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query" ) ) ) {
    2234           0 :     const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
    2235           0 :     if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
    2236           0 :       cJSON_Delete( json );
    2237           0 :       return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2238           0 :     }
    2239             : 
    2240           0 :     int result = fd_gui_request_slot( gui, ws_conn_id, id, params );
    2241           0 :     cJSON_Delete( json );
    2242           0 :     return result;
    2243           0 :   } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_detailed" ) ) ) {
    2244           0 :     const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
    2245           0 :     if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
    2246           0 :       cJSON_Delete( json );
    2247           0 :       return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2248           0 :     }
    2249             : 
    2250           0 :     int result = fd_gui_request_slot_detailed( gui, ws_conn_id, id, params );
    2251           0 :     cJSON_Delete( json );
    2252           0 :     return result;
    2253           0 :   } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_transactions" ) ) ) {
    2254           0 :     const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
    2255           0 :     if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
    2256           0 :       cJSON_Delete( json );
    2257           0 :       return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2258           0 :     }
    2259             : 
    2260           0 :     int result = fd_gui_request_slot_transactions( gui, ws_conn_id, id, params );
    2261           0 :     cJSON_Delete( json );
    2262           0 :     return result;
    2263           0 :   } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_rankings" ) ) ) {
    2264           0 :     const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
    2265           0 :     if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
    2266           0 :       cJSON_Delete( json );
    2267           0 :       return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2268           0 :     }
    2269             : 
    2270           0 :     int result = fd_gui_request_slot_rankings( gui, ws_conn_id, id, params );
    2271           0 :     cJSON_Delete( json );
    2272           0 :     return result;
    2273           0 :   } else if( FD_LIKELY( !strcmp( topic->valuestring, "timeline" ) && !strcmp( key->valuestring, "query_shreds" ) ) ) {
    2274           0 :     const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
    2275           0 :     if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
    2276           0 :       cJSON_Delete( json );
    2277           0 :       return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    2278           0 :     }
    2279             : 
    2280           0 :     int result = fd_gui_request_timeline_shreds( gui, ws_conn_id, topic->valuestring, id, params );
    2281           0 :     cJSON_Delete( json );
    2282           0 :     return result;
    2283           0 :   } else if( FD_LIKELY( !strcmp( topic->valuestring, "summary" ) && !strcmp( key->valuestring, "ping" ) ) ) {
    2284           0 :     fd_gui_printf_summary_ping( gui, id );
    2285           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    2286             : 
    2287           0 :     cJSON_Delete( json );
    2288           0 :     return 0;
    2289           0 :   }
    2290             : 
    2291           0 :   cJSON_Delete( json );
    2292           0 :   return FD_HTTP_SERVER_CONNECTION_CLOSE_UNKNOWN_METHOD;
    2293           0 : }
    2294             : 
    2295             : static inline uchar
    2296           0 : slot_get_skip_status( fd_gui_t * gui, ulong _slot ) {
    2297           0 :   ulong tower_slot = gui->summary.slot_tower;
    2298           0 :   if( FD_UNLIKELY( tower_slot==ULONG_MAX || _slot>=tower_slot ) ) return FD_GUI_SKIP_STATUS_UNKNOWN;
    2299             : 
    2300           0 :   const ulong max_consecutive_skips = 1024UL; /* TODO: prove derivation */
    2301             : 
    2302             :   /* Find the nearest landed canonical descendant and walk its lineage
    2303             :      down to obtain positive skip proof. */
    2304           0 :   ulong anchor_slot     = ULONG_MAX;
    2305           0 :   ulong anchor_bank_seq = ULONG_MAX;
    2306           0 :   ulong search_hi       = fd_ulong_min( _slot+max_consecutive_skips, tower_slot );
    2307           0 :   for( ulong s=_slot+1UL; s<=search_hi; s++ ) {
    2308           0 :     fd_gui_hist_kv_slot_iter_t it[ 1 ];
    2309             :     /* Equivocation-safe */
    2310           0 :     for( fd_gui_hist_kv_iter_begin( gui, it, FD_GUI_HIST_SLOT, s ); it->rec; fd_gui_hist_kv_iter_next( it ) ) {
    2311           0 :       fd_gui_slot_t const * rec = (fd_gui_slot_t const *)it->rec;
    2312           0 :       if( FD_LIKELY( rec->skip==FD_GUI_SKIP_STATUS_NOT_SKIPPED ) ) {
    2313           0 :         anchor_slot     = s;
    2314           0 :         anchor_bank_seq = it->bank_seq;
    2315           0 :         break;
    2316           0 :       }
    2317           0 :     }
    2318           0 :     if( FD_UNLIKELY( anchor_slot!=ULONG_MAX ) ) break;
    2319           0 :   }
    2320           0 :   if( FD_UNLIKELY( anchor_slot==ULONG_MAX ) ) return FD_GUI_SKIP_STATUS_UNKNOWN; /* no descendant found */
    2321             : 
    2322             :   /* Walk the canonical fork back up. */
    2323           0 :   ulong cur_slot     = anchor_slot;
    2324           0 :   ulong cur_bank_seq = anchor_bank_seq;
    2325           0 :   for( ulong steps=0UL; steps<max_consecutive_skips; steps++ ) {
    2326           0 :     fd_gui_hist_slot_key_t key;
    2327           0 :     key.slot = cur_slot; key.bank_seq = cur_bank_seq;
    2328           0 :     fd_gui_slot_t const * cmeta = (fd_gui_slot_t const *)fd_gui_hist_kv_get( gui, FD_GUI_HIST_SLOT, &key );
    2329           0 :     if( FD_UNLIKELY( !cmeta ) ) return FD_GUI_SKIP_STATUS_UNKNOWN; /* lineage broken / aged out */
    2330             : 
    2331           0 :     ulong parent_slot     = cmeta->parent_slot;
    2332           0 :     ulong parent_bank_seq = cmeta->parent_bank_seq;
    2333           0 :     if( FD_UNLIKELY( parent_slot==ULONG_MAX ) ) return FD_GUI_SKIP_STATUS_UNKNOWN; /* Couldn't find _slot */
    2334           0 :     if( FD_LIKELY( parent_slot==_slot ) ) return FD_GUI_SKIP_STATUS_NOT_SKIPPED;   /* _slot is on this lineage */
    2335           0 :     if( FD_LIKELY( parent_slot< _slot ) ) return FD_GUI_SKIP_STATUS_FINALIZED;     /* lineage steps over _slot: skipped */
    2336           0 :     cur_slot     = parent_slot;
    2337           0 :     cur_bank_seq = parent_bank_seq;
    2338           0 :   }
    2339           0 :   return FD_GUI_SKIP_STATUS_UNKNOWN;
    2340           0 : }
    2341             : 
    2342             : fd_gui_slot_t *
    2343           0 : fd_gui_slot_get_canon_safe( fd_gui_t * gui, ulong _slot ) {
    2344           0 :   fd_gui_slot_t * slot = fd_gui_slot_get_canon( gui, _slot );
    2345             : 
    2346           0 :   if( FD_LIKELY( slot ) ) {
    2347           0 :     return slot;
    2348           0 :   } else {
    2349           0 :     uchar level = FD_GUI_SLOT_LEVEL_COMPLETED;
    2350           0 :     if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && _slot<gui->summary.slot_optimistically_confirmed ) ) level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
    2351           0 :     if( FD_LIKELY( gui->summary.slot_rooted!=ULONG_MAX && _slot<gui->summary.slot_rooted ) ) level = FD_GUI_SLOT_LEVEL_ROOTED;
    2352             : 
    2353           0 :     *gui->skipped_scratch = (fd_gui_slot_t){
    2354           0 :       .slot             = _slot,
    2355           0 :       .bank_seq         = ULONG_MAX,
    2356           0 :       .parent_bank_seq  = ULONG_MAX,
    2357           0 :       .parent_slot      = fd_gui_slot_skipped_get_parent( gui, _slot ),
    2358           0 :       .vote_slot        = ULONG_MAX,
    2359           0 :       .completed_time   = LONG_MAX,
    2360           0 :       .parent_completed_time = LONG_MAX,
    2361           0 :       .max_compute_units= UINT_MAX,
    2362           0 :       .mine             = (uchar)(fd_gui_slot_is_mine( gui, _slot ) & 1),
    2363           0 :       .skip             = slot_get_skip_status( gui, _slot ),
    2364           0 :       .level            = level,
    2365           0 :       .compute_units    = UINT_MAX,
    2366           0 :       .transaction_fee  = ULONG_MAX,
    2367           0 :       .priority_fee     = ULONG_MAX,
    2368           0 :       .tips             = ULONG_MAX,
    2369           0 :       .shred_cnt        = UINT_MAX,
    2370           0 :       .vote_latency_exact = FD_GUI_VOTE_LATENCY_NOT_VOTED,
    2371           0 :       .is_voter         = FD_GUI_IS_VOTER_UNKNOWN,
    2372           0 :       .vote_rewarded    = fd_gui_slot_vote_rewarded_state( gui, _slot ),
    2373           0 :       .vote_success     = UINT_MAX,
    2374           0 :       .vote_failed      = UINT_MAX,
    2375           0 :       .nonvote_success  = UINT_MAX,
    2376           0 :       .nonvote_failed   = UINT_MAX,
    2377           0 :     };
    2378           0 :     fd_gui_slot_set_voter_state( gui->skipped_scratch, fd_gui_slot_voter_state( gui, _slot ) );
    2379           0 :     return gui->skipped_scratch;
    2380           0 :   }
    2381           0 : }
    2382             : 
    2383             : void
    2384             : fd_gui_handle_epoch_info( fd_gui_t *                  gui,
    2385             :                           fd_epoch_info_msg_t const * epoch_info,
    2386           0 :                           long                        now ) {
    2387           0 :   FD_TEST( epoch_info->staked_vote_cnt<=MAX_STAKE_WEIGHTS );
    2388           0 :   FD_TEST( epoch_info->slot_cnt<=MAX_SLOTS_PER_EPOCH );
    2389           0 :   FD_TEST( epoch_info->staked_vote_cnt );
    2390             : 
    2391           0 :   if( FD_UNLIKELY( !gui->epoch.has_epoch_schedule ) ) {
    2392           0 :     gui->epoch.epoch_schedule     = epoch_info->epoch_schedule;
    2393           0 :     gui->epoch.has_epoch_schedule = 1;
    2394           0 :   }
    2395             : 
    2396           0 :   fd_vote_stake_weight_t const * stake_weights = fd_epoch_info_msg_stake_weights( epoch_info );
    2397           0 :   fd_memcpy( gui->epoch.stakes_scratch, stake_weights, epoch_info->staked_vote_cnt*sizeof(fd_vote_stake_weight_t) );
    2398             : 
    2399           0 :   fd_epoch_leaders_t * lsched = fd_epoch_leaders_join( fd_epoch_leaders_new( gui->epoch.lsched_scratch,
    2400           0 :                                                                              epoch_info->epoch,
    2401           0 :                                                                              epoch_info->start_slot,
    2402           0 :                                                                              epoch_info->slot_cnt,
    2403           0 :                                                                              epoch_info->staked_vote_cnt,
    2404           0 :                                                                              gui->epoch.stakes_scratch ) );
    2405           0 :   FD_TEST( lsched );
    2406             : 
    2407           0 :   int created = 0;
    2408           0 :   fd_gui_epoch_t * epoch = fd_gui_epoch_get_or_create( gui, epoch_info->epoch, &created );
    2409           0 :   FD_TEST( epoch );
    2410             : 
    2411           0 :   if( FD_LIKELY( created ) ) {
    2412           0 :     epoch->epoch          = epoch_info->epoch;
    2413           0 :     epoch->start_slot     = epoch_info->start_slot;
    2414           0 :     epoch->slot_cnt       = epoch_info->slot_cnt;
    2415           0 :     epoch->start_time     = LONG_MAX;
    2416           0 :     epoch->end_time       = LONG_MAX;
    2417           0 :     epoch->target_slot_duration_ns = (long)epoch_info->ns_per_slot;
    2418           0 :     epoch->my_total_slots = 0UL;
    2419           0 :     epoch->my_skipped_slots = 0UL;
    2420           0 :     epoch->rankings_slot  = epoch_info->start_slot;
    2421           0 :     memset( epoch->rankings,    (int)(UINT_MAX), sizeof(epoch->rankings)    );
    2422           0 :     memset( epoch->my_rankings, (int)(UINT_MAX), sizeof(epoch->my_rankings) );
    2423           0 :     memset( epoch->latency_exact, (int)FD_GUI_VOTE_LATENCY_NOT_VOTED, sizeof(epoch->latency_exact) );
    2424           0 :     uchar is_voter_default = FD_GUI_IS_VOTER_NO;
    2425           0 :     if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) is_voter_default = FD_GUI_IS_VOTER_UNKNOWN;
    2426           0 :     memset( epoch->is_voter,      is_voter_default,                  sizeof(epoch->is_voter)      );
    2427           0 :     memset( epoch->skipped,       0,                                 sizeof(epoch->skipped)       );
    2428           0 :     memset( epoch->vote_rewarded, FD_GUI_VOTE_REWARDED_UNKNOWN,      sizeof(epoch->vote_rewarded) );
    2429           0 :     epoch->epoch_schedule = epoch_info->epoch_schedule;
    2430           0 :     epoch->pub_cnt        = lsched->pub_cnt;
    2431           0 :     epoch->stakes_cnt     = epoch_info->staked_vote_cnt;
    2432           0 :     fd_memcpy( epoch->pub,    lsched->pub,   epoch->pub_cnt*sizeof(fd_pubkey_t) );
    2433           0 :     fd_memcpy( epoch->sched,  lsched->sched, fd_ulong_min( lsched->sched_cnt, FD_GUI_EPOCH_SCHED_CNT )*sizeof(uint) );
    2434           0 :     fd_memcpy( epoch->stakes, gui->epoch.stakes_scratch, epoch->stakes_cnt*sizeof(fd_vote_stake_weight_t) );
    2435           0 :   }
    2436             : 
    2437           0 :   fd_epoch_leaders_delete( fd_epoch_leaders_leave( lsched ) );
    2438             : 
    2439           0 :   if( FD_UNLIKELY( gui->epoch.current_epoch==ULONG_MAX ) ) {
    2440           0 :     gui->epoch.current_epoch = epoch_info->epoch;
    2441           0 :   } else {
    2442           0 :     gui->epoch.current_epoch = fd_ulong_max( gui->epoch.current_epoch, epoch_info->epoch>0UL ? epoch_info->epoch-1UL : 0UL );
    2443           0 :   }
    2444             : 
    2445           0 :   epoch->start_time = now;
    2446           0 :   for( ulong i=0UL; i<fd_ulong_min( fd_ulong_sat_sub( epoch_info->start_slot, 1UL ), MAX_SLOTS_PER_EPOCH ); i++ ) {
    2447           0 :     fd_gui_slot_t const * slot = fd_gui_slot_get_any( gui, epoch_info->start_slot-i );
    2448           0 :     if( FD_UNLIKELY( !slot ) ) break;
    2449           0 :     else if( FD_UNLIKELY( slot->skip==FD_GUI_SKIP_STATUS_FINALIZED ) ) continue;
    2450           0 :     epoch->start_time = slot->parent_completed_time;
    2451           0 :     break;
    2452           0 :   }
    2453             : 
    2454           0 :   fd_gui_printf_epoch( gui, epoch_info->epoch );
    2455           0 :   fd_http_server_ws_broadcast( gui->http );
    2456           0 : }
    2457             : 
    2458             : void
    2459             : fd_gui_handle_shred( fd_gui_t * gui,
    2460             :                      ulong      slot,
    2461             :                      ulong      shred_idx,
    2462             :                      int        is_turbine,
    2463             :                      long       tsorig,
    2464           0 :                      long       now ) {
    2465           0 :   int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot );
    2466           0 :   if( FD_LIKELY( is_turbine ) ) fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot, tsorig );
    2467             : 
    2468             :   /* If we haven't caught up yet, update repair slot using received
    2469             :      shreds. This is not technically correct, but close enough and will
    2470             :      make the progress bar look correct. */
    2471           0 :   if( FD_UNLIKELY( !is_turbine && gui->summary.slot_caught_up==ULONG_MAX ) ) fd_gui_handle_repair_slot( gui, slot, tsorig );
    2472             : 
    2473           0 :   if( FD_UNLIKELY( !was_sent && is_turbine && slot!=gui->summary.slot_turbine ) ) {
    2474           0 :     gui->summary.slot_turbine = slot;
    2475             : 
    2476           0 :     fd_gui_printf_turbine_slot( gui );
    2477           0 :     fd_http_server_ws_broadcast( gui->http );
    2478             : 
    2479           0 :     gui->turbine_slots[ slot % FD_GUI_TURBINE_RECV_TIMESTAMPS ].slot = slot;
    2480           0 :     gui->turbine_slots[ slot % FD_GUI_TURBINE_RECV_TIMESTAMPS ].timestamp = tsorig;
    2481             : 
    2482           0 :     ulong duration_sum = 0UL;
    2483           0 :     ulong slot_cnt = 0UL;
    2484             : 
    2485           0 :     for( ulong i=0UL; i<FD_GUI_TURBINE_RECV_TIMESTAMPS; i++ ) {
    2486           0 :       fd_gui_turbine_slot_t * cur = &gui->turbine_slots[ i ];
    2487           0 :       fd_gui_turbine_slot_t * prev = &gui->turbine_slots[ (i+FD_GUI_TURBINE_RECV_TIMESTAMPS-1UL) % FD_GUI_TURBINE_RECV_TIMESTAMPS ];
    2488           0 :       if( FD_UNLIKELY( cur->slot==ULONG_MAX || prev->slot==ULONG_MAX || cur->slot!=prev->slot+1UL ) ) continue;
    2489             : 
    2490           0 :       long slot_duration = cur->timestamp - prev->timestamp;
    2491           0 :       duration_sum += (ulong)fd_long_max( slot_duration, 0UL );
    2492           0 :       slot_cnt++;
    2493           0 :     }
    2494             : 
    2495           0 :     if( FD_LIKELY( slot_cnt>0 ) ) {
    2496           0 :       gui->summary.estimated_slot_duration_nanos = (ulong)(duration_sum / slot_cnt);
    2497           0 :       fd_gui_printf_estimated_slot_duration_nanos( gui );
    2498           0 :       fd_http_server_ws_broadcast( gui->http );
    2499           0 :     }
    2500             : 
    2501           0 :     if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) fd_gui_try_insert_run_length_slot( gui->summary.catch_up_turbine, FD_GUI_TURBINE_CATCH_UP_HISTORY_SZ, &gui->summary.catch_up_turbine_sz, slot );
    2502           0 :   }
    2503             : 
    2504           0 :   fd_gui_hist_ts_append( gui, FD_GUI_HIST_SHRED_EVENTS, now, tsorig, &(fd_gui_slot_history_shred_event_t){ .slot = (uint)slot, .timestamp = tsorig, .shred_idx = (ushort)shred_idx, .event = fd_uchar_if( is_turbine, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_TURBINE, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_REPAIR ) } );
    2505           0 : }
    2506             : 
    2507             : void
    2508             : fd_gui_handle_leader_fec( fd_gui_t * gui,
    2509             :                           ulong      slot,
    2510             :                           ulong      fec_shred_cnt,
    2511             :                           int        is_end_of_slot,
    2512             :                           long       tsorig,
    2513           0 :                           long       now ) {
    2514             :   /* Abandoned block detected */
    2515           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow && gui->shreds.leader_shred_slot!=slot ) ) {
    2516           0 :     gui->shreds.leader_shred_cnt  = 0UL;
    2517           0 :     gui->shreds.leader_shred_slot = slot;
    2518           0 :   }
    2519             : 
    2520           0 :   for( ulong i=gui->shreds.leader_shred_cnt; i<gui->shreds.leader_shred_cnt+fec_shred_cnt; i++ ) {
    2521           0 :     fd_gui_hist_ts_append( gui, FD_GUI_HIST_SHRED_EVENTS, now, tsorig, &(fd_gui_slot_history_shred_event_t){ .slot = (uint)slot, .timestamp = tsorig, .shred_idx = (ushort)i, .event = FD_GUI_SLOT_SHRED_SHRED_PUBLISHED } );
    2522           0 :   }
    2523           0 :   gui->shreds.leader_shred_cnt += fec_shred_cnt;
    2524           0 :   if( FD_UNLIKELY( is_end_of_slot ) ) gui->shreds.leader_shred_cnt = 0UL;
    2525           0 : }
    2526             : 
    2527             : void
    2528             : fd_gui_handle_exec_txn_done( fd_gui_t * gui,
    2529             :                              ulong      slot,
    2530             :                              ulong      start_shred_idx,
    2531             :                              ulong      end_shred_idx,
    2532             :                              long       tsorig_ns FD_PARAM_UNUSED,
    2533             :                              long       tspub_ns,
    2534           0 :                              long       now ) {
    2535           0 :   for( ulong i = start_shred_idx; i<end_shred_idx; i++ ) {
    2536             :     /*
    2537             :       We're leaving this state transition out due to its proximity to
    2538             :       FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE, but if we ever wanted
    2539             :       to send this data to the frontend we could.
    2540             : 
    2541             :       fd_gui_shred_event_append( gui, slot, i, FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_START, tsorig_ns );
    2542             :     */
    2543             : 
    2544           0 :     fd_gui_hist_ts_append( gui, FD_GUI_HIST_SHRED_EVENTS, now, tspub_ns, &(fd_gui_slot_history_shred_event_t){ .slot = (uint)slot, .timestamp = tspub_ns, .shred_idx = (ushort)i, .event = FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE } );
    2545           0 :   }
    2546           0 : }
    2547             : 
    2548             : /* fd_gui_compute_vote_latency walks the fork whose landing block is
    2549             :    (landed_slot, landed_bank_seq) down toward voted_slot.  On success
    2550             :    (voted_slot is an ancestor on this fork) returns 1 and writes
    2551             :    voted_slot's bank_seq on this fork to *out_voted_bank_seq and the
    2552             :    skip-discounted latency to *out_exact.  Returns 0 if voted_slot is
    2553             :    not an ancestor on this fork, or the ancestry is not yet
    2554             :    replayed/linked. */
    2555             : 
    2556             : static int
    2557             : fd_gui_compute_vote_latency( fd_gui_t * gui,
    2558             :                              ulong      landed_slot,
    2559             :                              ulong      landed_bank_seq,
    2560             :                              ulong      voted_slot,
    2561             :                              ulong *    out_voted_bank_seq,
    2562           0 :                              ulong *    out_exact ) {
    2563           0 :   ulong on_fork_between = 0UL;
    2564           0 :   ulong cur_slot        = landed_slot;
    2565           0 :   ulong cur_bank_seq    = landed_bank_seq;
    2566           0 :   for( ulong steps=0UL; steps<1024UL; steps++ ) {
    2567           0 :     fd_gui_slot_t const * c = fd_gui_slot_get( gui, cur_slot, cur_bank_seq );
    2568           0 :     if( FD_UNLIKELY( !c ) ) return 0;
    2569           0 :     ulong pslot = c->parent_slot;
    2570           0 :     ulong pseq  = c->parent_bank_seq;
    2571           0 :     if( FD_UNLIKELY( pslot==ULONG_MAX ) ) return 0;
    2572           0 :     if( FD_UNLIKELY( pslot<voted_slot ) ) return 0;
    2573           0 :     if( FD_LIKELY( pslot==voted_slot ) ) {
    2574           0 :       *out_voted_bank_seq = pseq;
    2575           0 :       *out_exact          = 1UL + on_fork_between;
    2576           0 :       return 1;
    2577           0 :     }
    2578           0 :     on_fork_between++;
    2579           0 :     cur_slot     = pslot;
    2580           0 :     cur_bank_seq = pseq;
    2581           0 :   }
    2582           0 :   return 0;
    2583           0 : }
    2584             : 
    2585             : /* fd_gui_record_vote_latency records the minimum vote_latency_exact
    2586             :    observed for the (voted_slot, voted_bank_seq) fork. */
    2587             : 
    2588             : static void
    2589             : fd_gui_record_vote_latency( fd_gui_t * gui,
    2590             :                             ulong      voted_slot,
    2591             :                             ulong      voted_bank_seq,
    2592           0 :                             uchar      vote_latency_exact ) {
    2593           0 :   vote_latency_exact = (uchar)fd_ulong_min( vote_latency_exact, FD_GUI_VOTE_LATENCY_MAX );
    2594             : 
    2595           0 :   fd_gui_slot_t * slot = fd_gui_slot_get( gui, voted_slot, voted_bank_seq );
    2596           0 :   if( FD_LIKELY( slot ) && FD_LIKELY( vote_latency_exact<slot->vote_latency_exact ) ) {
    2597           0 :     slot->vote_latency_exact = vote_latency_exact;
    2598           0 :     fd_gui_printf_slot( gui, voted_slot, slot );
    2599           0 :     fd_http_server_ws_broadcast( gui->http );
    2600           0 :   }
    2601           0 : }
    2602             : 
    2603             : void
    2604             : fd_gui_handle_root_advanced( fd_gui_t * gui,
    2605             :                              ulong      _slot,
    2606             :                              ulong      bank_seq,
    2607           0 :                              long       now FD_PARAM_UNUSED ) {
    2608           0 :   fd_gui_slot_t * root = fd_gui_slot_get( gui, _slot, bank_seq );
    2609           0 :   if( FD_UNLIKELY( !root ) ) return;
    2610             : 
    2611             :   /* Rooting only ever advances. */
    2612           0 :   if( FD_UNLIKELY( gui->summary.slot_rooted!=ULONG_MAX && _slot<=gui->summary.slot_rooted ) ) return;
    2613             : 
    2614           0 :   ulong prev_rooted = gui->summary.slot_rooted;
    2615             : 
    2616           0 :   gui->summary.slot_rooted = _slot;
    2617           0 :   fd_gui_printf_root_slot( gui );
    2618           0 :   fd_http_server_ws_broadcast( gui->http );
    2619             : 
    2620           0 :   for( ulong cslot=_slot, cbank_seq=bank_seq; ; ) {
    2621           0 :     fd_gui_slot_t * c = fd_gui_slot_get( gui, cslot, cbank_seq );
    2622           0 :     if( FD_UNLIKELY( !c || c->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
    2623             : 
    2624           0 :     c->level = FD_GUI_SLOT_LEVEL_ROOTED;
    2625             : 
    2626           0 :     if( FD_UNLIKELY( gui->summary.is_alpenglow && c->finalization_kind==FD_GUI_AG_FINAL_NONE ) ) {
    2627           0 :       c->finalization_kind = FD_GUI_AG_FINAL_IMPLICIT;
    2628           0 :     }
    2629             : 
    2630           0 :     fd_gui_printf_slot( gui, cslot, c );
    2631           0 :     fd_http_server_ws_broadcast( gui->http );
    2632             : 
    2633             :     /* Finalize vote latencies from votes that landed in this block. */
    2634           0 :     for( ulong r=0UL; r<gui->landed_vote_cnt; r++ ) {
    2635           0 :       if( FD_UNLIKELY( gui->landed_votes[ r ].landed_slot!=cslot || gui->landed_votes[ r ].landed_bank_seq!=cbank_seq ) ) continue;
    2636           0 :       ulong voted_slot = gui->landed_votes[ r ].voted_slot;
    2637           0 :       ulong voted_bank_seq, exact;
    2638           0 :       if( FD_UNLIKELY( !fd_gui_compute_vote_latency( gui, cslot, cbank_seq, voted_slot, &voted_bank_seq, &exact ) ) ) continue;
    2639           0 :       exact = (uchar)fd_ulong_min( exact, FD_GUI_VOTE_LATENCY_MAX );
    2640           0 :       fd_gui_record_vote_latency( gui, voted_slot, voted_bank_seq, (uchar)exact );
    2641             : 
    2642           0 :       fd_gui_epoch_t * vepoch = fd_gui_get_epoch_by_slot( gui, voted_slot );
    2643           0 :       if( FD_UNLIKELY( !vepoch ) ) continue;
    2644           0 :       ulong vidx = voted_slot - vepoch->start_slot;
    2645           0 :       if( FD_UNLIKELY( vidx>=vepoch->slot_cnt ) ) continue;
    2646           0 :       if( FD_LIKELY( exact<vepoch->latency_exact[ vidx ] ) ) {
    2647           0 :         vepoch->latency_exact[ vidx ] = (uchar)exact;
    2648           0 :       }
    2649           0 :     }
    2650             : 
    2651           0 :     fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, cslot );
    2652           0 :     if( FD_LIKELY( epoch ) ) {
    2653           0 :       ulong cidx = cslot - epoch->start_slot;
    2654           0 :       if( FD_LIKELY( cidx<epoch->slot_cnt ) ) {
    2655           0 :         if( FD_UNLIKELY( gui->summary.is_alpenglow && epoch->is_voter[ cidx ]!=FD_GUI_IS_VOTER_UNKNOWN ) )
    2656           0 :           fd_gui_slot_set_voter_state( c, epoch->is_voter[ cidx ] );
    2657           0 :         epoch->is_voter[ cidx ] = c->is_voter;
    2658             : 
    2659             :         /* This slot is on the rooted fork, so it was not skipped. */
    2660           0 :         epoch->skipped[ cidx ] = 0;
    2661           0 :       }
    2662           0 :     }
    2663             : 
    2664           0 :     ulong pslot = c->parent_slot, pseq = c->parent_bank_seq;
    2665           0 :     if( FD_UNLIKELY( pslot==ULONG_MAX || pslot>=cslot ) ) break;
    2666             : 
    2667             :     /* Record and republish newly rooted skipped slots. */
    2668           0 :     for( ulong s=pslot+1UL; s<cslot; s++ ) {
    2669           0 :       if( FD_UNLIKELY( prev_rooted!=ULONG_MAX && s<=prev_rooted ) ) continue; /* already rooted earlier */
    2670             : 
    2671           0 :       fd_gui_epoch_t * sepoch = fd_gui_get_epoch_by_slot( gui, s );
    2672           0 :       if( FD_LIKELY( sepoch ) ) {
    2673           0 :         ulong sidx = s - sepoch->start_slot;
    2674           0 :         if( FD_LIKELY( sidx<sepoch->slot_cnt ) ) sepoch->skipped[ sidx ] = 1;
    2675           0 :       }
    2676             : 
    2677           0 :       if( FD_UNLIKELY( prev_rooted==ULONG_MAX ) ) continue;
    2678             : 
    2679           0 :       fd_gui_slot_t const * skipped = fd_gui_slot_get_canon_safe( gui, s );
    2680           0 :       if( FD_UNLIKELY( skipped->skip!=FD_GUI_SKIP_STATUS_FINALIZED ) ) continue;
    2681           0 :       fd_gui_printf_slot( gui, s, skipped );
    2682           0 :       fd_http_server_ws_broadcast( gui->http );
    2683           0 :     }
    2684             : 
    2685           0 :     cslot = pslot; cbank_seq = pseq;
    2686           0 :   }
    2687             : 
    2688           0 :   ulong rooted_slot = gui->summary.slot_rooted;
    2689           0 :   ulong w = 0UL;
    2690           0 :   for( ulong r=0UL; r<gui->landed_vote_cnt; r++ ) {
    2691           0 :     if( FD_UNLIKELY( gui->landed_votes[ r ].landed_slot<=rooted_slot ) ) continue;
    2692           0 :     gui->landed_votes[ w++ ] = gui->landed_votes[ r ];
    2693           0 :   }
    2694           0 :   gui->landed_vote_cnt = w;
    2695           0 : }
    2696             : 
    2697             : static fd_gui_ag_slot_t *
    2698             : fd_gui_ag_slot_entry( fd_gui_t * gui,
    2699           0 :                       ulong      slot ) {
    2700             :   /* TODO: correctly handle equivocating slots */
    2701           0 :   fd_gui_ag_slot_t * ent = &gui->ag.slot[ slot % gui->ag.slot_cnt ];
    2702           0 :   if( FD_UNLIKELY( ent->slot!=slot ) ) {
    2703           0 :     ent->slot              = slot;
    2704           0 :     memset( ent->block_id.uc, 0, sizeof(fd_hash_t) );
    2705           0 :     ent->bank_seq          = ULONG_MAX;
    2706           0 :     ent->notarization_kind = FD_GUI_AG_NOTAR_NONE;
    2707           0 :     ent->finalization_kind = FD_GUI_AG_FINAL_NONE;
    2708           0 :     ent->skip              = FD_GUI_SKIP_STATUS_UNKNOWN;
    2709           0 :   }
    2710           0 :   return ent;
    2711           0 : }
    2712             : 
    2713             : static int
    2714           0 : fd_gui_ag_slot_has_proof( fd_gui_ag_slot_t const * ent ) {
    2715           0 :   return ent->notarization_kind!=FD_GUI_AG_NOTAR_NONE || ent->finalization_kind!=FD_GUI_AG_FINAL_NONE;
    2716           0 : }
    2717             : 
    2718             : static fd_gui_ag_slot_t *
    2719             : fd_gui_ag_slot_for_certificate( fd_gui_t *        gui,
    2720             :                                 ulong             slot,
    2721           0 :                                 fd_hash_t const * block_id ) {
    2722           0 :   fd_gui_ag_slot_t * ent = fd_gui_ag_slot_entry( gui, slot );
    2723           0 :   if( FD_UNLIKELY( !fd_hash_eq( &ent->block_id, block_id ) ) ) {
    2724           0 :     ent->block_id          = *block_id;
    2725           0 :     ent->bank_seq          = ULONG_MAX;
    2726           0 :     ent->notarization_kind = FD_GUI_AG_NOTAR_NONE;
    2727           0 :     ent->finalization_kind = FD_GUI_AG_FINAL_NONE;
    2728           0 :   }
    2729           0 :   return ent;
    2730           0 : }
    2731             : 
    2732             : static void
    2733             : fd_gui_ag_slot_publish( fd_gui_t *               gui,
    2734           0 :                         fd_gui_ag_slot_t const * ent ) {
    2735           0 :   if( FD_UNLIKELY( ent->bank_seq==ULONG_MAX ) ) return; /* not replayed yet, applied when it is */
    2736             : 
    2737           0 :   fd_gui_slot_t * slot = fd_gui_slot_get( gui, ent->slot, ent->bank_seq );
    2738           0 :   if( FD_UNLIKELY( !slot ) ) return;
    2739             : 
    2740           0 :   uchar notar = fd_uchar_if( ent->notarization_kind>slot->notarization_kind, ent->notarization_kind, slot->notarization_kind );
    2741           0 :   uchar final = fd_uchar_if( ent->finalization_kind>slot->finalization_kind, ent->finalization_kind, slot->finalization_kind );
    2742           0 :   uchar level = slot->level;
    2743             : 
    2744             :   /* Increase confirmation, but don't root yet since that's handled by
    2745             :      fd_gui_handle_root_advanced. */
    2746           0 :   if( FD_LIKELY( notar!=FD_GUI_AG_NOTAR_NONE || final!=FD_GUI_AG_FINAL_NONE ) ) {
    2747           0 :     level = fd_uchar_if( level<FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED, FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED, level );
    2748           0 :   }
    2749             : 
    2750           0 :   if( FD_LIKELY( notar==slot->notarization_kind && final==slot->finalization_kind && level==slot->level ) ) return;
    2751             : 
    2752           0 :   slot->notarization_kind = notar;
    2753           0 :   slot->finalization_kind = final;
    2754           0 :   slot->level             = level;
    2755             : 
    2756           0 :   fd_gui_slot_t * canon = fd_gui_slot_get_canon( gui, ent->slot );
    2757           0 :   fd_gui_printf_slot( gui, ent->slot, fd_ptr_if( !!canon, canon, slot ) );
    2758           0 :   fd_http_server_ws_broadcast( gui->http );
    2759           0 : }
    2760             : 
    2761             : static void
    2762             : fd_gui_ag_update_notarized_slot( fd_gui_t * gui,
    2763           0 :                                  ulong      slot ) {
    2764           0 :   if( FD_LIKELY( gui->summary.slot_notarized!=ULONG_MAX && slot<=gui->summary.slot_notarized ) ) return;
    2765             : 
    2766           0 :   gui->summary.slot_notarized = slot;
    2767           0 :   fd_gui_printf_notarized_slot( gui );
    2768           0 :   fd_http_server_ws_broadcast( gui->http );
    2769           0 : }
    2770             : 
    2771             : void
    2772             : fd_gui_ag_register_block( fd_gui_t *        gui,
    2773             :                           ulong             slot,
    2774             :                           fd_hash_t const * block_id,
    2775           0 :                           ulong             bank_seq ) {
    2776           0 :   if( FD_UNLIKELY( !gui->summary.is_alpenglow || !block_id ) ) return;
    2777             : 
    2778           0 :   fd_gui_ag_slot_t * ent = fd_gui_ag_slot_entry( gui, slot );
    2779           0 :   if( FD_UNLIKELY( fd_gui_ag_slot_has_proof( ent ) && !fd_hash_eq( &ent->block_id, block_id ) ) ) return;
    2780             : 
    2781           0 :   ent->block_id = *block_id;
    2782           0 :   ent->bank_seq = bank_seq;
    2783           0 :   fd_gui_ag_slot_publish( gui, ent );
    2784           0 : }
    2785             : 
    2786             : void
    2787             : fd_gui_handle_ag_notarized( fd_gui_t *        gui,
    2788             :                             ulong             slot,
    2789             :                             fd_hash_t const * block_id,
    2790           0 :                             uchar             notarization_kind ) {
    2791           0 :   if( FD_UNLIKELY( !gui->summary.is_alpenglow || !block_id ) ) return;
    2792             : 
    2793           0 :   fd_gui_ag_slot_t * ent = fd_gui_ag_slot_for_certificate( gui, slot, block_id );
    2794           0 :   ent->notarization_kind = fd_uchar_if( notarization_kind>ent->notarization_kind, notarization_kind, ent->notarization_kind );
    2795           0 :   fd_gui_ag_slot_publish( gui, ent );
    2796           0 :   fd_gui_ag_update_notarized_slot( gui, slot );
    2797           0 : }
    2798             : 
    2799             : void
    2800             : fd_gui_handle_ag_finalized( fd_gui_t *        gui,
    2801             :                             ulong             slot,
    2802             :                             fd_hash_t const * block_id,
    2803           0 :                             uchar             finalization_kind ) {
    2804           0 :   if( FD_UNLIKELY( !gui->summary.is_alpenglow || !block_id ) ) return;
    2805             : 
    2806           0 :   fd_gui_ag_slot_t * ent = fd_gui_ag_slot_for_certificate( gui, slot, block_id );
    2807           0 :   ent->finalization_kind = fd_uchar_if( finalization_kind>ent->finalization_kind, finalization_kind, ent->finalization_kind );
    2808             : 
    2809             :   /* Finalization implies regular notarization. */
    2810           0 :   ent->notarization_kind = FD_GUI_AG_NOTAR_REGULAR;
    2811             : 
    2812           0 :   fd_gui_ag_slot_publish( gui, ent );
    2813           0 :   fd_gui_ag_update_notarized_slot( gui, slot );
    2814             : 
    2815           0 :   if( FD_LIKELY( gui->summary.slot_finalized==ULONG_MAX || slot>gui->summary.slot_finalized ) ) {
    2816           0 :     gui->summary.slot_finalized = slot;
    2817           0 :     fd_gui_printf_finalized_slot( gui );
    2818           0 :     fd_http_server_ws_broadcast( gui->http );
    2819           0 :   }
    2820           0 : }
    2821             : 
    2822             : void
    2823             : fd_gui_handle_ag_skip_cert( fd_gui_t * gui,
    2824           0 :                             ulong      slot ) {
    2825           0 :   if( FD_UNLIKELY( !gui->summary.is_alpenglow ) ) return;
    2826             : 
    2827           0 :   fd_gui_ag_slot_t * ent = fd_gui_ag_slot_entry( gui, slot );
    2828           0 :   if( FD_LIKELY( ent->skip>=FD_GUI_SKIP_STATUS_NOTARIZED ) ) return;
    2829           0 :   ent->skip = FD_GUI_SKIP_STATUS_NOTARIZED;
    2830             : 
    2831           0 :   fd_gui_printf_slot( gui, slot, fd_gui_slot_get_canon_safe( gui, slot ) );
    2832           0 :   fd_http_server_ws_broadcast( gui->http );
    2833           0 :   fd_gui_ag_update_notarized_slot( gui, slot );
    2834           0 : }
    2835             : 
    2836             : void
    2837             : fd_gui_handle_ag_leader( fd_gui_t * gui,
    2838           0 :                          ulong      parent_slot ) {
    2839           0 :   if( FD_UNLIKELY( !gui->summary.is_alpenglow ) ) return;
    2840           0 :   if( FD_UNLIKELY( gui->summary.slot_reset==parent_slot ) ) return;
    2841             : 
    2842           0 :   gui->summary.slot_reset = parent_slot;
    2843           0 :   fd_gui_printf_reset_slot( gui );
    2844           0 :   fd_http_server_ws_broadcast( gui->http );
    2845           0 : }
    2846             : 
    2847             : int
    2848             : fd_gui_ag_slot_is_skip_notarized( fd_gui_t const * gui,
    2849           0 :                                   ulong            slot ) {
    2850           0 :   if( FD_UNLIKELY( !gui->summary.is_alpenglow || slot==ULONG_MAX ) ) return 0;
    2851             : 
    2852           0 :   fd_gui_ag_slot_t const * ent = &gui->ag.slot[ slot % gui->ag.slot_cnt ];
    2853           0 :   return ent->slot==slot && ent->skip>=FD_GUI_SKIP_STATUS_NOTARIZED;
    2854           0 : }
    2855             : 
    2856             : static void
    2857             : fd_gui_handle_ag_reward( fd_gui_t * gui,
    2858             :                          ulong      slot,
    2859             :                          int        voted,
    2860           0 :                          ushort     voted_rank ) {
    2861           0 :   if( FD_UNLIKELY( !gui->summary.is_alpenglow ) ) return;
    2862             : 
    2863           0 :   uchar vote_rewarded = fd_uchar_if( !!voted, FD_GUI_VOTE_REWARDED_YES, FD_GUI_VOTE_REWARDED_NO );
    2864           0 :   uchar is_voter = fd_uchar_if( voted_rank!=USHORT_MAX, FD_GUI_IS_VOTER_YES, FD_GUI_IS_VOTER_NO );
    2865             : 
    2866           0 :   int epoch_changed = 0;
    2867           0 :   fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, slot );
    2868           0 :   if( FD_LIKELY( epoch ) ) {
    2869           0 :     ulong idx = slot - epoch->start_slot;
    2870           0 :     if( FD_LIKELY( idx<epoch->slot_cnt && ( epoch->vote_rewarded[ idx ]!=vote_rewarded || epoch->is_voter[ idx ]!=is_voter ) ) ) {
    2871           0 :       int was_missed = epoch->vote_rewarded[ idx ]==FD_GUI_VOTE_REWARDED_NO && epoch->is_voter[ idx ]==FD_GUI_IS_VOTER_YES;
    2872           0 :       epoch_changed = 1;
    2873           0 :       epoch->vote_rewarded[ idx ] = vote_rewarded;
    2874           0 :       epoch->is_voter[ idx ]      = is_voter;
    2875           0 :       int is_missed = vote_rewarded==FD_GUI_VOTE_REWARDED_NO && is_voter==FD_GUI_IS_VOTER_YES;
    2876             : 
    2877           0 :       if( FD_UNLIKELY( was_missed!=is_missed ) ) {
    2878           0 :         fd_gui_printf_missed_vote_history( gui, epoch->epoch );
    2879           0 :         fd_http_server_ws_broadcast( gui->http );
    2880           0 :       }
    2881           0 :     }
    2882           0 :   }
    2883             : 
    2884           0 :   fd_gui_slot_t * rec = fd_gui_slot_get_canon( gui, slot );
    2885           0 :   if( FD_UNLIKELY( !rec ) ) {
    2886           0 :     if( FD_UNLIKELY( epoch_changed ) ) {
    2887           0 :       fd_gui_slot_t const * skipped = fd_gui_slot_get_canon_safe( gui, slot );
    2888           0 :       if( FD_LIKELY( skipped->skip==FD_GUI_SKIP_STATUS_FINALIZED || fd_gui_ag_slot_is_skip_notarized( gui, slot ) ) ) {
    2889           0 :         fd_gui_printf_slot( gui, slot, skipped );
    2890           0 :         fd_http_server_ws_broadcast( gui->http );
    2891           0 :       }
    2892           0 :     }
    2893           0 :     return;
    2894           0 :   }
    2895             : 
    2896           0 :   int changed = rec->vote_rewarded!=vote_rewarded || rec->is_voter!=is_voter || epoch_changed;
    2897           0 :   rec->vote_rewarded = vote_rewarded;
    2898           0 :   fd_gui_slot_set_voter_state( rec, is_voter );
    2899           0 :   if( FD_UNLIKELY( !changed ) ) return;
    2900           0 :   fd_gui_printf_slot( gui, slot, rec );
    2901           0 :   fd_http_server_ws_broadcast( gui->http );
    2902           0 : }
    2903             : 
    2904             : void
    2905             : fd_gui_handle_oc_advanced( fd_gui_t * gui,
    2906             :                            ulong      _slot,
    2907             :                            ulong      bank_seq,
    2908           0 :                            long       now ) {
    2909           0 :   (void)now;
    2910             : 
    2911           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) return;
    2912             : 
    2913           0 :   fd_gui_slot_t * live_slot = fd_gui_slot_get( gui, _slot, bank_seq );
    2914           0 :   if( FD_UNLIKELY( !live_slot ) ) return;
    2915             : 
    2916           0 :   fd_gui_slot_t const * slot = fd_gui_slot_get_canon( gui, _slot );
    2917           0 :   int on_canonical_fork = ( slot && slot->bank_seq==bank_seq );
    2918           0 :   if( FD_UNLIKELY( !on_canonical_fork ) ) return; /* we've since switched forks so this update is invalid */
    2919             : 
    2920           0 :   ulong prev_oc = gui->summary.slot_optimistically_confirmed;
    2921             : 
    2922           0 :   int advanced = 0;
    2923           0 :   if( FD_LIKELY( _slot!=prev_oc ) ) {
    2924           0 :     gui->summary.slot_optimistically_confirmed = _slot;
    2925           0 :     fd_gui_printf_optimistically_confirmed_slot( gui );
    2926           0 :     fd_http_server_ws_broadcast( gui->http );
    2927           0 :     advanced = ( prev_oc==ULONG_MAX || _slot>prev_oc );
    2928           0 :   }
    2929             : 
    2930           0 :   for( ulong cslot=_slot, cbank_seq=bank_seq; ; ) {
    2931           0 :     fd_gui_slot_t * c = fd_gui_slot_get( gui, cslot, cbank_seq );
    2932           0 :     if( FD_UNLIKELY( !c || c->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
    2933             : 
    2934           0 :     if( FD_LIKELY( c->level<FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED ) ) {
    2935           0 :       c->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
    2936           0 :       fd_gui_printf_slot( gui, cslot, c );
    2937           0 :       fd_http_server_ws_broadcast( gui->http );
    2938           0 :     }
    2939             : 
    2940           0 :     ulong pslot = c->parent_slot, pseq = c->parent_bank_seq;
    2941           0 :     if( FD_UNLIKELY( pslot==ULONG_MAX || pslot>=cslot ) ) break;
    2942             : 
    2943             :     /* Republish skipped slots as well. */
    2944           0 :     if( FD_LIKELY( advanced ) ) {
    2945           0 :       for( ulong s=pslot+1UL; s<cslot; s++ ) {
    2946           0 :         if( FD_UNLIKELY( prev_oc!=ULONG_MAX && s<=prev_oc ) ) continue; /* already OC'd earlier */
    2947           0 :         if( FD_UNLIKELY( gui->summary.slot_rooted!=ULONG_MAX && s<gui->summary.slot_rooted ) ) continue; /* already rooted: handled by root advance */
    2948           0 :         fd_gui_slot_t const * skipped = fd_gui_slot_get_canon_safe( gui, s );
    2949           0 :         if( FD_UNLIKELY( skipped->skip!=FD_GUI_SKIP_STATUS_FINALIZED ) ) continue;
    2950           0 :         fd_gui_printf_slot( gui, s, skipped );
    2951           0 :         fd_http_server_ws_broadcast( gui->http );
    2952           0 :       }
    2953           0 :     }
    2954             : 
    2955           0 :     cslot = pslot; cbank_seq = pseq;
    2956           0 :   }
    2957           0 : }
    2958             : 
    2959             : void
    2960             : fd_gui_handle_genesis_hash( fd_gui_t *        gui,
    2961           0 :                             fd_hash_t const * msg ) {
    2962           0 :   FD_BASE58_ENCODE_32_BYTES( msg->uc, hash_cstr );
    2963           0 :   ulong cluster = fd_genesis_cluster_identify(hash_cstr);
    2964           0 :   char const * cluster_name = fd_genesis_cluster_name(cluster);
    2965             : 
    2966           0 :   if( FD_LIKELY( strcmp( gui->summary.cluster, cluster_name ) ) ) {
    2967           0 :     gui->summary.cluster = fd_genesis_cluster_name(cluster);
    2968           0 :     fd_gui_printf_cluster( gui );
    2969           0 :     fd_http_server_ws_broadcast( gui->http );
    2970           0 :   }
    2971           0 : }
    2972             : 
    2973             : void
    2974             : fd_gui_handle_block_engine_update( fd_gui_t *                              gui,
    2975           0 :                                    fd_bundle_block_engine_update_t const * update ) {
    2976           0 :   gui->block_engine.has_block_engine = 1;
    2977             : 
    2978             :   /* copy strings and ensure null termination within bounds */
    2979           0 :   FD_TEST( fd_cstr_nlen( update->name,    sizeof(gui->block_engine.name   ) ) < sizeof(gui->block_engine.name   ) );
    2980           0 :   FD_TEST( fd_cstr_nlen( update->url,     sizeof(gui->block_engine.url    ) ) < sizeof(gui->block_engine.url    ) );
    2981           0 :   FD_TEST( fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) ) < sizeof(gui->block_engine.ip_cstr) );
    2982           0 :   ulong name_len    = fd_cstr_nlen( update->name,    sizeof(gui->block_engine.name   ) );
    2983           0 :   ulong url_len     = fd_cstr_nlen( update->url,     sizeof(gui->block_engine.url    ) );
    2984           0 :   ulong ip_cstr_len = fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) );
    2985           0 :   fd_memcpy( gui->block_engine.name,    update->name,    name_len+1UL );
    2986           0 :   fd_memcpy( gui->block_engine.url,     update->url,     url_len+1UL );
    2987           0 :   fd_memcpy( gui->block_engine.ip_cstr, update->ip_cstr, ip_cstr_len+1UL );
    2988             : 
    2989           0 :   fd_gui_printf_block_engine( gui );
    2990           0 :   fd_http_server_ws_broadcast( gui->http );
    2991           0 : }
    2992             : 
    2993             : void
    2994             : fd_gui_handle_snapshot_update( fd_gui_t *                 gui,
    2995           0 :                                fd_snapct_update_t const * msg ) {
    2996           0 :   FD_TEST( msg && fd_cstr_nlen( msg->read_path, 1 ) );
    2997             : 
    2998           0 :   ulong snapshot_idx = fd_ulong_if( msg->type==FD_SNAPCT_SNAPSHOT_TYPE_FULL, FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX );
    2999             : 
    3000           0 :   char const * filename = strrchr( msg->read_path, '/' );
    3001             : 
    3002             :   /* Skip the '/'  */
    3003           0 :   if( FD_LIKELY( filename ) ) filename++;
    3004           0 :   else                        filename = msg->read_path;
    3005             : 
    3006           0 :   if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_INCREMENTAL) {
    3007           0 :       ulong slot1, slot2;
    3008           0 :       if ( FD_LIKELY( sscanf( filename, "incremental-snapshot-%lu-%lu-", &slot1, &slot2 )==2 ) )
    3009           0 :         gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot2;
    3010           0 :       else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
    3011           0 :   } else if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_FULL) {
    3012           0 :       ulong slot1;
    3013           0 :       if ( FD_LIKELY( sscanf( filename, "snapshot-%lu-", &slot1 )==1 ) )
    3014           0 :         gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot1;
    3015           0 :       else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
    3016           0 :   }
    3017           0 :   fd_cstr_printf_check( gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_path, sizeof(gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_path), NULL, "%s", msg->read_path );
    3018           0 : }
    3019             : 
    3020             : void
    3021             : fd_gui_handle_snapsv_update( fd_gui_t *              gui,
    3022             :                              ulong                   sig,
    3023             :                              fd_snapsv_msg_t const * msg,
    3024             :                              ulong                   sz,
    3025             :                              int                     eom,
    3026           0 :                              long                    now ) {
    3027           0 :   if( FD_UNLIKELY( sig!=FD_SNAPSV_MSG_SNAP || sz!=sizeof(fd_snapsv_msg_snap_t) ) ) return;
    3028           0 :   if( FD_UNLIKELY( gui->snapsv.pending_cnt>=FD_GUI_SNAPSV_PENDING_MAX ) ) return;
    3029           0 :   fd_gui_snapsv_pending_t * pending = &gui->snapsv.pending[ gui->snapsv.pending_cnt++ ];
    3030           0 :   pending->msg               = msg->snap;
    3031           0 :   pending->sample_time_nanos = now;
    3032           0 :   pending->closed            = eom;
    3033           0 : }
    3034             : 
    3035             : void
    3036             : fd_gui_stage_snapshot_manifest( fd_gui_t *                    gui,
    3037           0 :                                  fd_snapshot_manifest_t const * manifest ) {
    3038           0 :   ulong attempt = 0UL;
    3039           0 :   for( ulong i=0UL; i<manifest->hard_fork_cnt; i++ ) {
    3040           0 :     if( FD_UNLIKELY( manifest->hard_forks[ i ].slot==manifest->slot ) ) {
    3041           0 :       attempt = manifest->hard_forks[ i ].cnt;
    3042           0 :       break;
    3043           0 :     }
    3044           0 :   }
    3045           0 :   gui->summary.boot_progress.wfs_attempt = attempt;
    3046           0 : }
    3047             : 
    3048             : static void
    3049             : fd_gui_broadcast_skip_rate( fd_gui_t * gui,
    3050           0 :                             ulong      epoch ) {
    3051           0 :   fd_gui_epoch_t const * rec = fd_gui_epoch( gui, epoch );
    3052           0 :   if( FD_UNLIKELY( !rec ) ) return;
    3053             : 
    3054           0 :   ulong slot = epoch % 2UL;
    3055           0 :   if( FD_LIKELY( gui->summary.skip_rate[ slot ].epoch  ==epoch
    3056           0 :               && gui->summary.skip_rate[ slot ].skipped==rec->my_skipped_slots
    3057           0 :               && gui->summary.skip_rate[ slot ].total  ==rec->my_total_slots ) ) return;
    3058             : 
    3059           0 :   gui->summary.skip_rate[ slot ].epoch   = epoch;
    3060           0 :   gui->summary.skip_rate[ slot ].skipped = rec->my_skipped_slots;
    3061           0 :   gui->summary.skip_rate[ slot ].total   = rec->my_total_slots;
    3062             : 
    3063           0 :   fd_gui_printf_skip_rate( gui, epoch );
    3064           0 :   fd_http_server_ws_broadcast( gui->http );
    3065           0 : }
    3066             : 
    3067             : /* Returns 1 if the frontier was updated, and 0 otherwise. */
    3068             : 
    3069             : static int
    3070           0 : handle_tower_slot( fd_gui_t * gui, ulong reset_slot, ulong reset_bank_seq, long now FD_PARAM_UNUSED ) {
    3071           0 :   FD_TEST( reset_slot!=ULONG_MAX );
    3072             : 
    3073           0 :   ulong prev_reset_slot     = gui->summary.slot_tower;
    3074           0 :   ulong prev_reset_bank_seq = gui->summary.slot_tower_bank_seq;
    3075             : 
    3076             :   /* reset_slot is guaranteed present (returnable_frag deferred this
    3077             :      update until replay recorded it). */
    3078           0 :   if( FD_UNLIKELY( !fd_gui_slot_get( gui, reset_slot, reset_bank_seq ) ) ) {
    3079             :     /* Alpenglow drives this from replay completion rather than a
    3080             :        consensus-derived reset slot, so the record is not guaranteed. */
    3081           0 :     if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) return 0;
    3082           0 :     FD_LOG_ERR(( "fd_gui_slot_get( gui, slot_tower %lu, slot_tower_bank_seq %lu ) missing",
    3083           0 :                  reset_slot, reset_bank_seq ));
    3084           0 :   }
    3085             : 
    3086             :   /* reset_slot has not changed */
    3087           0 :   if( FD_UNLIKELY( prev_reset_slot!=ULONG_MAX && reset_slot==prev_reset_slot && reset_bank_seq==prev_reset_bank_seq ) ) return 0;
    3088             : 
    3089             :   /* slot complete received out of order on the same fork?  Check
    3090             :      against the old frontier before replacing it. */
    3091           0 :   if( FD_UNLIKELY( prev_reset_slot!=ULONG_MAX && fd_gui_slot_is_ancestor( gui, reset_slot, reset_bank_seq, prev_reset_slot, prev_reset_bank_seq ) ) ) {
    3092             :     /* Alpenglow can complete a descendant before one of its ancestors.
    3093             :        Keep advertising the highest completed block on that fork. */
    3094           0 :     if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) return 0;
    3095           0 :     FD_LOG_ERR(( "slot complete received out of order on the same fork (prev_reset_slot %lu, slot_tower %lu)", prev_reset_slot, reset_slot ));
    3096           0 :   }
    3097             : 
    3098           0 :   gui->summary.slot_tower          = reset_slot;
    3099           0 :   gui->summary.slot_tower_bank_seq = reset_bank_seq;
    3100             : 
    3101           0 :   fd_gui_printf_completed_slot( gui );
    3102           0 :   fd_http_server_ws_broadcast( gui->http );
    3103             : 
    3104             :   /* ensure a history exists */
    3105           0 :   if( FD_UNLIKELY( prev_reset_slot==ULONG_MAX || gui->summary.slot_rooted==ULONG_MAX ) ) return 1;
    3106             : 
    3107             :   /* Switch forks. */
    3108           0 :   for( ulong slot=fd_ulong_max( gui->summary.slot_tower, prev_reset_slot ); slot>gui->summary.slot_rooted; slot-- ) {
    3109           0 :     int skipped_old = slot<=prev_reset_slot && fd_gui_slot_is_skipped( gui, gui->summary.slot_rooted, prev_reset_slot, prev_reset_bank_seq, slot );
    3110           0 :     int skipped_new = slot<=gui->summary.slot_tower && fd_gui_slot_is_skipped( gui, gui->summary.slot_rooted, gui->summary.slot_tower, reset_bank_seq, slot );
    3111           0 :     if( FD_LIKELY( skipped_old!=skipped_new ) ) {
    3112           0 :       fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, slot );
    3113           0 :       if( FD_LIKELY( epoch && fd_gui_slot_is_mine( gui, slot ) ) ) {
    3114           0 :         if( skipped_new ) epoch->my_skipped_slots = fd_ulong_sat_add( epoch->my_skipped_slots, 1UL );
    3115           0 :         else              epoch->my_skipped_slots = fd_ulong_sat_sub( epoch->my_skipped_slots, 1UL );
    3116           0 :       }
    3117           0 :     }
    3118             : 
    3119             :     /* Publish new/changed slots */
    3120           0 :     if( FD_LIKELY( skipped_old!=skipped_new || slot>prev_reset_slot ) ) {
    3121           0 :       fd_gui_printf_slot( gui, slot, fd_gui_slot_get_canon_safe( gui, slot ) );
    3122           0 :       fd_http_server_ws_broadcast( gui->http );
    3123           0 :     }
    3124             : 
    3125             :     /* Persist skip status */
    3126           0 :     fd_gui_slot_t * canon = fd_gui_slot_get_canon( gui, slot );
    3127           0 :     ulong canon_bank_seq = canon ? canon->bank_seq : ULONG_MAX; /* canon, if any, IS slot */
    3128           0 :     fd_gui_hist_kv_slot_iter_t it[ 1 ];
    3129           0 :     for( fd_gui_hist_kv_iter_begin( gui, it, FD_GUI_HIST_SLOT, slot ); it->rec; fd_gui_hist_kv_iter_next( it ) ) {
    3130           0 :       ((fd_gui_slot_t *)it->rec)->skip = fd_uchar_if( it->bank_seq==canon_bank_seq, FD_GUI_SKIP_STATUS_NOT_SKIPPED, FD_GUI_SKIP_STATUS_FINALIZED );
    3131           0 :     }
    3132           0 :   }
    3133             : 
    3134           0 :   for( ulong e=gui->epoch.current_epoch; e<=gui->epoch.current_epoch+1UL; e++ ) fd_gui_broadcast_skip_rate( gui, e );
    3135           0 :   return 1;
    3136           0 : }
    3137             : 
    3138             : static inline void
    3139             : set_vote_state( fd_gui_t * gui,
    3140           0 :                 int        vote_state ) {
    3141           0 :   if( FD_UNLIKELY( gui->summary.vote_state!=vote_state ) ) {
    3142           0 :     gui->summary.vote_state = vote_state;
    3143           0 :     fd_gui_printf_vote_state( gui );
    3144           0 :     fd_http_server_ws_broadcast( gui->http );
    3145           0 :   }
    3146           0 : }
    3147             : 
    3148             : static inline void
    3149             : publish_vote_status( fd_gui_t * gui,
    3150           0 :                      int        is_voting ) {
    3151           0 :   if( FD_UNLIKELY( !is_voting ) ) {
    3152           0 :     set_vote_state( gui, FD_GUI_VOTE_STATE_NON_VOTING );
    3153           0 :     return;
    3154           0 :   }
    3155             : 
    3156           0 :   fd_gui_slot_t * slot = fd_gui_slot_get( gui, gui->summary.slot_tower, gui->summary.slot_tower_bank_seq );
    3157           0 :   FD_TEST( slot );
    3158             : 
    3159           0 :   if( FD_UNLIKELY( gui->summary.slot_tower==ULONG_MAX ) ) return;
    3160             : 
    3161           0 :   if( FD_UNLIKELY( slot->vote_slot==ULONG_MAX ) ) {
    3162             :     /* Voting is enabled but no vote has landed yet. */
    3163           0 :     set_vote_state( gui, FD_GUI_VOTE_STATE_DELINQUENT );
    3164           0 :     return;
    3165           0 :   }
    3166             : 
    3167             :   /* Snapshot the fields before the inner loop (which re-resolves slots). */
    3168           0 :   ulong vote_slot  = slot->vote_slot;
    3169           0 :   ulong reset_slot = gui->summary.slot_tower;
    3170             : 
    3171           0 :   ulong vote_distance = reset_slot-vote_slot;
    3172           0 :   if( FD_LIKELY( vote_distance<FD_GUI_MAX_VOTE_DISTANCE ) ) {
    3173           0 :     for( ulong s=vote_slot; s<reset_slot; s++ ) {
    3174           0 :       if( FD_UNLIKELY( !fd_gui_slot_get_canon( gui, s ) ) ) vote_distance--;
    3175           0 :     }
    3176           0 :   }
    3177             : 
    3178           0 :   if( FD_UNLIKELY( gui->summary.vote_distance!=vote_distance ) ) {
    3179           0 :     gui->summary.vote_distance = vote_distance;
    3180           0 :     fd_gui_printf_vote_distance( gui );
    3181           0 :     fd_http_server_ws_broadcast( gui->http );
    3182           0 :   }
    3183             : 
    3184           0 :   if( FD_UNLIKELY( vote_slot==ULONG_MAX || vote_distance>150UL ) ) {
    3185           0 :     set_vote_state( gui, FD_GUI_VOTE_STATE_DELINQUENT );
    3186           0 :   } else {
    3187           0 :     set_vote_state( gui, FD_GUI_VOTE_STATE_VOTING );
    3188           0 :   }
    3189           0 : }
    3190             : 
    3191             : /* fd_gui_handle_tower_update handles updates from the tower tile, which
    3192             :    manages consensus related fork switching, rooting, slot confirmation.
    3193             : 
    3194             :    The gui tile consumes tower_out via returnable_frag and defers any
    3195             :    update whose replay_slot has not yet been recorded from replay, so by
    3196             :    the time this runs both tower->replay_slot and tower->reset_slot are
    3197             :    guaranteed to have a DB record. */
    3198             : void
    3199             : fd_gui_handle_tower_update( fd_gui_t *                   gui,
    3200             :                             fd_tower_slot_done_t const * tower,
    3201           0 :                             long                         now ) {
    3202           0 :   if( FD_UNLIKELY( tower->active_fork_cnt!=gui->summary.active_fork_cnt ) ) {
    3203           0 :     gui->summary.active_fork_cnt = tower->active_fork_cnt;
    3204           0 :     fd_gui_printf_active_fork_cnt( gui );
    3205           0 :     fd_http_server_ws_broadcast( gui->http );
    3206           0 :   }
    3207             : 
    3208           0 :   fd_gui_slot_t * replay_slot = fd_gui_slot_get( gui, tower->replay_slot, tower->replay_bank_seq );
    3209           0 :   FD_TEST( replay_slot );
    3210           0 :   if( FD_LIKELY( tower->is_voting ) ) replay_slot->is_voter = FD_GUI_IS_VOTER_YES;
    3211           0 :   else                                replay_slot->is_voter = FD_GUI_IS_VOTER_NO;
    3212             : 
    3213             :   /* Handle already-rooted edge case. */
    3214           0 :   if( FD_UNLIKELY( replay_slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) {
    3215           0 :     fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, tower->replay_slot );
    3216           0 :     if( FD_LIKELY( epoch ) ) {
    3217           0 :       ulong cidx = tower->replay_slot - epoch->start_slot;
    3218           0 :       if( FD_LIKELY( cidx<epoch->slot_cnt ) ) epoch->is_voter[ cidx ] = replay_slot->is_voter;
    3219           0 :     }
    3220           0 :   }
    3221             : 
    3222           0 :   if( FD_LIKELY( tower->reset_slot!=ULONG_MAX ) ) {
    3223           0 :     handle_tower_slot( gui, tower->reset_slot, tower->reset_bank_seq, now );
    3224           0 :     publish_vote_status( gui, tower->is_voting );
    3225           0 :   } else if( FD_UNLIKELY( !tower->is_voting ) ) {
    3226             :     /* NON_VOTING does not need a reset slot, unlike publish_vote_status. */
    3227           0 :     set_vote_state( gui, FD_GUI_VOTE_STATE_NON_VOTING );
    3228           0 :   }
    3229             : 
    3230           0 :   if( FD_LIKELY( gui->summary.slot_reset!=tower->reset_slot ) ) {
    3231           0 :     gui->summary.slot_reset = tower->reset_slot;
    3232           0 :     fd_gui_printf_reset_slot( gui );
    3233           0 :     fd_http_server_ws_broadcast( gui->http );
    3234           0 :   }
    3235             : 
    3236           0 :   if( FD_UNLIKELY( tower->vote_acct_bal!=ULONG_MAX && gui->summary.vote_account_balance!=tower->vote_acct_bal ) ) {
    3237           0 :     gui->summary.vote_account_balance = tower->vote_acct_bal;
    3238           0 :     fd_gui_printf_vote_balance( gui );
    3239           0 :     fd_http_server_ws_broadcast( gui->http );
    3240           0 :   }
    3241             : 
    3242           0 :   if( FD_UNLIKELY( gui->summary.vote_commission!=tower->vote_acct_com ) ) {
    3243           0 :     gui->summary.vote_commission = tower->vote_acct_com;
    3244           0 :     fd_gui_printf_vote_commission( gui );
    3245           0 :     fd_http_server_ws_broadcast( gui->http );
    3246           0 :   }
    3247             : 
    3248             :   /* Update vote latencies.  This is the speculative, true correct
    3249             :      latencies are published as a vote's landed slot is rooted. */
    3250           0 :   for( ulong r=0UL; r<gui->landed_vote_cnt; r++ ) {
    3251           0 :     if( FD_UNLIKELY( gui->landed_votes[ r ].landed_slot>gui->summary.slot_tower ) ) continue;
    3252             : 
    3253           0 :     ulong voted_bank_seq, exact;
    3254           0 :     if( FD_UNLIKELY( !fd_gui_compute_vote_latency( gui, gui->landed_votes[ r ].landed_slot, gui->landed_votes[ r ].landed_bank_seq, gui->landed_votes[ r ].voted_slot, &voted_bank_seq, &exact ) ) ) continue;
    3255           0 :     exact = (uchar)fd_ulong_min( exact, FD_GUI_VOTE_LATENCY_MAX );
    3256           0 :     fd_gui_slot_t * slot = fd_gui_slot_get( gui, gui->landed_votes[ r ].voted_slot, voted_bank_seq );
    3257           0 :     if( FD_UNLIKELY( !slot ) ) continue;
    3258             : 
    3259           0 :     if( FD_LIKELY( exact>=slot->vote_latency_exact ) ) continue;
    3260           0 :     fd_gui_record_vote_latency( gui, gui->landed_votes[ r ].voted_slot, voted_bank_seq, (uchar)exact );
    3261           0 :   }
    3262           0 : }
    3263             : 
    3264             : void
    3265             : fd_gui_stage_landed_vote( fd_gui_t * gui,
    3266             :                           ulong      landed_slot,
    3267             :                           ulong      landed_bank_seq,
    3268           0 :                           ulong      voted_slot ) {
    3269           0 :   if( FD_UNLIKELY( voted_slot==ULONG_MAX || voted_slot>=landed_slot ) ) return;
    3270             : 
    3271             :   /* Handle already-rooted edge case. */
    3272           0 :   if( FD_UNLIKELY( gui->summary.slot_rooted!=ULONG_MAX && landed_slot<=gui->summary.slot_rooted ) ) {
    3273           0 :     fd_gui_slot_t const * canon = fd_gui_slot_get_canon( gui, landed_slot );
    3274           0 :     if( FD_UNLIKELY( !canon || canon->bank_seq!=landed_bank_seq ) ) return;
    3275           0 :     ulong voted_bank_seq, exact;
    3276           0 :     if( FD_UNLIKELY( !fd_gui_compute_vote_latency( gui, landed_slot, landed_bank_seq, voted_slot, &voted_bank_seq, &exact ) ) ) return;
    3277           0 :     exact = (uchar)fd_ulong_min( exact, FD_GUI_VOTE_LATENCY_MAX );
    3278           0 :     fd_gui_record_vote_latency( gui, voted_slot, voted_bank_seq, (uchar)exact );
    3279             : 
    3280           0 :     fd_gui_epoch_t * vepoch = fd_gui_get_epoch_by_slot( gui, voted_slot );
    3281           0 :     if( FD_UNLIKELY( !vepoch ) ) return;
    3282           0 :     ulong vidx = voted_slot - vepoch->start_slot;
    3283           0 :     if( FD_UNLIKELY( vidx>=vepoch->slot_cnt ) ) return;
    3284           0 :     if( FD_LIKELY( exact<vepoch->latency_exact[ vidx ] ) ) {
    3285           0 :       vepoch->latency_exact[ vidx ] = (uchar)exact;
    3286           0 :     }
    3287           0 :     return;
    3288           0 :   }
    3289             : 
    3290           0 :   if( FD_UNLIKELY( gui->landed_vote_cnt>=FD_GUI_LANDED_VOTE_MAX ) ) return;
    3291             : 
    3292           0 :   gui->landed_votes[ gui->landed_vote_cnt ].landed_slot     = landed_slot;
    3293           0 :   gui->landed_votes[ gui->landed_vote_cnt ].landed_bank_seq = landed_bank_seq;
    3294           0 :   gui->landed_votes[ gui->landed_vote_cnt ].voted_slot      = voted_slot;
    3295           0 :   gui->landed_vote_cnt++;
    3296           0 : }
    3297             : 
    3298             : void
    3299             : fd_gui_handle_replay_update( fd_gui_t *                         gui,
    3300             :                              fd_replay_slot_completed_t const * slot_completed,
    3301             :                              ulong                              vote_slot,
    3302           0 :                              long                               now ) {
    3303           0 :   if( FD_LIKELY( gui->summary.slot_storage!=slot_completed->storage_slot ) ) {
    3304           0 :     gui->summary.slot_storage = slot_completed->storage_slot;
    3305           0 :     fd_gui_printf_storage_slot( gui );
    3306           0 :     fd_http_server_ws_broadcast( gui->http );
    3307           0 :   }
    3308             : 
    3309           0 :   if( FD_UNLIKELY( slot_completed->identity_balance!=ULONG_MAX && gui->summary.identity_account_balance!=slot_completed->identity_balance ) ) {
    3310           0 :     gui->summary.identity_account_balance = slot_completed->identity_balance;
    3311             : 
    3312           0 :     fd_gui_printf_identity_balance( gui );
    3313           0 :     fd_http_server_ws_broadcast( gui->http );
    3314           0 :   }
    3315             : 
    3316           0 :   if( FD_UNLIKELY( gui->summary.boot_progress.catching_up_first_replay_slot==ULONG_MAX ) ) {
    3317           0 :     gui->summary.boot_progress.catching_up_first_replay_slot = slot_completed->slot;
    3318           0 :   }
    3319             : 
    3320           0 :   fd_gui_slot_t * slot = fd_gui_slot_get_or_create( gui,
    3321           0 :                                                     slot_completed->slot,
    3322           0 :                                                     slot_completed->parent_slot,
    3323           0 :                                                     slot_completed->bank_seq,
    3324           0 :                                                     slot_completed->parent_bank_seq );
    3325           0 :   if( FD_UNLIKELY( !slot ) ) return; /* record could not be created / was evicted */
    3326             : 
    3327           0 :   slot->completed_time    = slot_completed->completion_time_nanos;
    3328           0 :   slot->parent_slot       = slot_completed->parent_slot;
    3329           0 :   slot->max_compute_units = fd_uint_if( slot_completed->cost_tracker.block_cost_limit==ULONG_MAX, slot->max_compute_units, (uint)slot_completed->cost_tracker.block_cost_limit );
    3330             : 
    3331           0 :   fd_gui_slot_t const * parent = fd_gui_slot_parent_get( gui, slot );
    3332           0 :   slot->parent_completed_time = parent ? parent->completed_time : LONG_MAX;
    3333             : 
    3334           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
    3335           0 :     if( FD_UNLIKELY( slot_completed->voted && slot_completed->slot>=FD_NUM_SLOTS_FOR_REWARD ) ) {
    3336           0 :       vote_slot = slot_completed->slot-FD_NUM_SLOTS_FOR_REWARD;
    3337           0 :     } else {
    3338           0 :       vote_slot = gui->summary.slot_voted; /* TODO: inherit from parent so it's fork-correct. Requires tracking identity changes to be correct. */
    3339           0 :     }
    3340           0 :   }
    3341             : 
    3342           0 :   if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_COMPLETED ) ) {
    3343             :     /* Typically a slot goes from INCOMPLETE to COMPLETED but it can
    3344             :        happen that it starts higher.  One such case is when we
    3345             :        optimistically confirm a higher slot that skips this one, but
    3346             :        then later we replay this one anyway to track the bank fork. */
    3347             : 
    3348           0 :     if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && slot_completed->slot<gui->summary.slot_optimistically_confirmed ) ) {
    3349             :       /* Cluster might have already optimistically confirmed by the time
    3350             :          we finish replaying it. */
    3351           0 :       slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
    3352           0 :     } else {
    3353           0 :       slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
    3354           0 :     }
    3355           0 :   }
    3356           0 :   slot->vote_failed     = fd_uint_if( slot_completed->vote_failed==ULONG_MAX,     slot->vote_failed,     (uint)slot_completed->vote_failed     );
    3357           0 :   slot->vote_success    = fd_uint_if( slot_completed->vote_success==ULONG_MAX,    slot->vote_success,    (uint)slot_completed->vote_success    );
    3358           0 :   slot->nonvote_success = fd_uint_if( slot_completed->nonvote_success==ULONG_MAX, slot->nonvote_success, (uint)slot_completed->nonvote_success );
    3359           0 :   slot->nonvote_failed  = fd_uint_if( slot_completed->nonvote_failed==ULONG_MAX,  slot->nonvote_failed,  (uint)slot_completed->nonvote_failed  );
    3360             : 
    3361           0 :   slot->transaction_fee   = slot_completed->transaction_fee;
    3362           0 :   slot->priority_fee      = slot_completed->priority_fee;
    3363           0 :   slot->tips              = slot_completed->tips;
    3364           0 :   slot->compute_units     = fd_uint_if( slot_completed->cost_tracker.block_cost==ULONG_MAX, slot->compute_units, (uint)slot_completed->cost_tracker.block_cost );
    3365           0 :   slot->shred_cnt         = fd_uint_if( slot_completed->shred_cnt==ULONG_MAX, slot->shred_cnt, (uint)slot_completed->shred_cnt );
    3366           0 :   slot->vote_slot         = vote_slot;
    3367           0 :   slot->block_hash        = slot_completed->block_hash;
    3368             : 
    3369           0 :   fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, slot_completed->slot );
    3370           0 :   if( FD_UNLIKELY( epoch && slot_completed->slot==epoch->start_slot+epoch->slot_cnt-1UL ) ) epoch->end_time = slot->completed_time;
    3371             : 
    3372           0 :   if( FD_UNLIKELY( slot->mine ) ) {
    3373           0 :     fd_gui_leader_slot_t * lmeta = fd_gui_slot_leader_get_or_create( gui, slot_completed->slot, slot_completed->bank_seq );
    3374           0 :     if( FD_LIKELY( lmeta ) ) lmeta->block_hash = slot_completed->block_hash;
    3375             : 
    3376           0 :     fd_gui_epoch_t const * epoch = fd_gui_get_epoch_by_slot( gui, slot_completed->slot );
    3377           0 :     if( FD_LIKELY( epoch ) ) fd_gui_broadcast_skip_rate( gui, epoch->epoch );
    3378           0 :   }
    3379             : 
    3380             :   /* Add a "slot complete" event for all of the shreds in this slot */
    3381           0 :   fd_gui_hist_ts_append( gui, FD_GUI_HIST_SHRED_EVENTS, now, slot_completed->completion_time_nanos, &(fd_gui_slot_history_shred_event_t){ .slot = (uint)slot_completed->slot, .timestamp = slot_completed->completion_time_nanos, .shred_idx = USHORT_MAX, .event = FD_GUI_SLOT_SHRED_SHRED_SLOT_COMPLETE } );
    3382             : 
    3383             :   /* Set skip status based on the current tower-derived canonical fork. */
    3384           0 :   fd_gui_slot_t * canon = fd_gui_slot_get_canon( gui, slot_completed->slot );
    3385           0 :   slot->skip = fd_uchar_if( canon && canon->bank_seq==slot_completed->bank_seq, FD_GUI_SKIP_STATUS_NOT_SKIPPED, FD_GUI_SKIP_STATUS_UNKNOWN );
    3386             : 
    3387             :   /* fixes race if we just sample right after replay's SLOT_COMPLETE */
    3388           0 :   if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) fd_gui_sample_repair_slot( gui, now );
    3389             : 
    3390             :   /* Update slot_turbine when we are leader. */
    3391           0 :   if( FD_UNLIKELY( gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && slot_completed->slot > gui->summary.slots_max_turbine[ 0 ].slot ) ) {
    3392           0 :     fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot_completed->slot, now );
    3393           0 :   }
    3394             : 
    3395           0 :   int slot_turbine_hist_full = gui->summary.slots_max_turbine[ FD_GUI_TURBINE_SLOT_HISTORY_SZ-1UL ].slot!=ULONG_MAX;
    3396           0 :   if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX && slot_turbine_hist_full && gui->summary.slots_max_turbine[ 0 ].slot < (slot_completed->slot + 3UL) ) ) {
    3397           0 :     gui->summary.slot_caught_up = slot_completed->slot + 4UL;
    3398             : 
    3399           0 :     fd_gui_printf_slot_caught_up( gui );
    3400           0 :     fd_http_server_ws_broadcast( gui->http );
    3401           0 :   }
    3402             : 
    3403           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
    3404           0 :     if( FD_UNLIKELY( slot_completed->voted && slot_completed->slot>=FD_NUM_SLOTS_FOR_REWARD && ( gui->summary.slot_voted==ULONG_MAX || vote_slot>gui->summary.slot_voted ) ) ) {
    3405           0 :       gui->summary.slot_voted = vote_slot;
    3406           0 :       fd_gui_printf_vote_slot( gui );
    3407           0 :       fd_http_server_ws_broadcast( gui->http );
    3408           0 :     }
    3409             : 
    3410             :     /* Bind this bank only to certificates for the same block. */
    3411           0 :     fd_gui_ag_register_block( gui, slot_completed->slot, &slot_completed->block_id, slot_completed->bank_seq );
    3412             : 
    3413           0 :     if( FD_UNLIKELY( slot_completed->vote_balance!=ULONG_MAX && gui->summary.vote_account_balance!=slot_completed->vote_balance ) ) {
    3414           0 :       gui->summary.vote_account_balance = slot_completed->vote_balance;
    3415           0 :       fd_gui_printf_vote_balance( gui );
    3416           0 :       fd_http_server_ws_broadcast( gui->http );
    3417           0 :     }
    3418           0 :     if( FD_UNLIKELY( slot_completed->vote_commission!=USHORT_MAX && gui->summary.vote_commission!=slot_completed->vote_commission ) ) {
    3419           0 :       gui->summary.vote_commission = slot_completed->vote_commission;
    3420           0 :       fd_gui_printf_vote_commission( gui );
    3421           0 :       fd_http_server_ws_broadcast( gui->http );
    3422           0 :     }
    3423             : 
    3424           0 :     if( FD_LIKELY( slot_completed->slot>=FD_NUM_SLOTS_FOR_REWARD ) ) {
    3425           0 :       fd_gui_handle_ag_reward( gui, slot_completed->slot-FD_NUM_SLOTS_FOR_REWARD, slot_completed->voted, slot_completed->voted_rank );
    3426           0 :     }
    3427             : 
    3428           0 :     int frontier_updated = handle_tower_slot( gui, slot_completed->slot, slot_completed->bank_seq, now );
    3429             : 
    3430           0 :     if( FD_LIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_NON_VOTING ) ) {
    3431           0 :       ulong s         = gui->summary.slot_tower;
    3432           0 :       ulong voted     = gui->summary.slot_voted;
    3433           0 :       int   current   = voted!=ULONG_MAX && fd_int_if( s>=128UL, voted+128UL>s, voted>0UL );
    3434           0 :       set_vote_state( gui, fd_int_if( current, FD_GUI_VOTE_STATE_VOTING, FD_GUI_VOTE_STATE_DELINQUENT ) );
    3435           0 :     }
    3436             : 
    3437           0 :     if( FD_UNLIKELY( frontier_updated && gui->summary.slot_estimated!=slot_completed->slot ) ) {
    3438           0 :       gui->summary.slot_estimated = slot_completed->slot;
    3439           0 :       fd_gui_printf_estimated_slot( gui );
    3440           0 :       fd_http_server_ws_broadcast( gui->http );
    3441           0 :     }
    3442           0 :   }
    3443           0 : }
    3444             : 
    3445             : void
    3446             : fd_gui_became_leader( fd_gui_t * gui,
    3447             :                       ulong      _slot,
    3448             :                       long       start_time_nanos,
    3449             :                       long       end_time_nanos,
    3450             :                       ulong      max_compute_units FD_PARAM_UNUSED,
    3451             :                       ulong      max_microblocks,
    3452           0 :                       ulong      bank_seq ) {
    3453           0 :   if( FD_UNLIKELY( fd_gui_slot_is_mine( gui, _slot ) && !fd_gui_slot_is_mine( gui, _slot-1UL ) ) ) {
    3454           0 :     gui->leader_active = 1;
    3455           0 :   }
    3456             : 
    3457           0 :   fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_or_create( gui, _slot, bank_seq );
    3458           0 :   if( FD_UNLIKELY( !lslot ) ) return;
    3459             : 
    3460           0 :   lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, start_time_nanos, lslot->leader_start_time );
    3461           0 :   lslot->leader_end_time   = end_time_nanos;
    3462           0 :   lslot->max_microblocks   = max_microblocks;
    3463           0 :   if( FD_LIKELY( lslot->microblocks_upper_bound==UINT_MAX ) ) lslot->microblocks_upper_bound = (uint)max_microblocks;
    3464           0 : }
    3465             : 
    3466             : void
    3467             : fd_gui_unbecame_leader( fd_gui_t *                gui,
    3468             :                         ulong                     _slot,
    3469           9 :                         fd_done_packing_t const * done_packing ) {
    3470           9 :   if( FD_UNLIKELY( fd_gui_slot_is_mine( gui, _slot ) && !fd_gui_slot_is_mine( gui, _slot+1UL ) ) ) {
    3471           0 :     gui->leader_active = 0;
    3472           0 :   }
    3473             : 
    3474           9 :   fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_any( gui, _slot );
    3475           9 :   if( FD_UNLIKELY( !lslot ) ) return;
    3476           9 :   lslot->microblocks_upper_bound = (uint)done_packing->microblocks_in_slot;
    3477           9 :   fd_memcpy( lslot->scheduler_stats, done_packing, sizeof(fd_done_packing_t) );
    3478           9 :   lslot->unbecame_leader = 1;
    3479             : 
    3480           9 :   if( FD_LIKELY( !lslot->has_waterfall ) ) {
    3481           6 :     gui->leader_slot_pending     = lslot->slot;
    3482           6 :     gui->leader_bank_seq_pending = lslot->bank_seq;
    3483           6 :   }
    3484           9 : }
    3485             : 
    3486             : void
    3487             : fd_gui_done_draining( fd_gui_t * gui,
    3488           9 :                       long       now ) {
    3489           9 :   if( FD_UNLIKELY( gui->leader_slot_pending==ULONG_MAX ) ) return;
    3490             : 
    3491           6 :   fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get( gui, gui->leader_slot_pending, gui->leader_bank_seq_pending );
    3492           6 :   gui->leader_slot_pending     = ULONG_MAX;
    3493           6 :   gui->leader_bank_seq_pending = ULONG_MAX;
    3494           6 :   if( FD_UNLIKELY( !lslot || lslot->has_waterfall ) ) return;
    3495             : 
    3496           6 :   fd_gui_txn_waterfall_t waterfall[ 1 ];
    3497           6 :   fd_gui_txn_waterfall_snap( gui, waterfall );
    3498           6 :   waterfall->sample_time_nanos = now;
    3499             : 
    3500           6 :   fd_memcpy( lslot->waterfall_reference, gui->summary.txn_waterfall_reference, sizeof(fd_gui_txn_waterfall_t) );
    3501           6 :   fd_memcpy( lslot->waterfall,           waterfall,                             sizeof(fd_gui_txn_waterfall_t) );
    3502           6 :   lslot->has_waterfall = 1;
    3503             : 
    3504           6 :   fd_memcpy( gui->summary.txn_waterfall_reference, waterfall, sizeof(fd_gui_txn_waterfall_t) );
    3505           6 : }
    3506             : 
    3507             : void
    3508             : fd_gui_microblock_execution_begin( fd_gui_t *   gui,
    3509             :                                    long         tspub_ns,
    3510             :                                    ulong        _slot,
    3511             :                                    fd_txn_e_t * txns,
    3512             :                                    ulong        txn_cnt,
    3513             :                                    uint         microblock_idx,
    3514             :                                    ulong        pack_txn_idx,
    3515             :                                    ulong        bank_seq,
    3516           0 :                                    long         now ) {
    3517           0 :   fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_or_create( gui, _slot, bank_seq );
    3518           0 :   if( FD_UNLIKELY( !lslot ) ) return;
    3519             : 
    3520           0 :   lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, tspub_ns, lslot->leader_start_time );
    3521             : 
    3522           0 :   for( ulong i=0UL; i<txn_cnt; i++ ) {
    3523           0 :     fd_txn_p_t * txn_payload = txns[ i ].txnp;
    3524           0 :     fd_txn_t * txn = TXN( txn_payload );
    3525             : 
    3526           0 :     ulong sig_rewards = FD_PACK_FEE_PER_SIGNATURE * txn->signature_cnt;
    3527           0 :     ulong priority_rewards                    = ULONG_MAX;
    3528           0 :     ulong requested_execution_cus             = ULONG_MAX;
    3529           0 :     ulong precompile_sigs                     = ULONG_MAX;
    3530           0 :     ulong requested_loaded_accounts_data_cost = ULONG_MAX;
    3531           0 :     ulong allocated_data                      = ULONG_MAX;
    3532           0 :     uint _flags = 0U;
    3533           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 );
    3534           0 :     sig_rewards += FD_PACK_FEE_PER_SIGNATURE * precompile_sigs;
    3535           0 :     sig_rewards = sig_rewards * FD_PACK_TXN_FEE_BURN_PCT / 100UL;
    3536             : 
    3537           0 :     ulong txn_idx = pack_txn_idx + i;
    3538           0 :     uchar flags = (uchar)FD_GUI_TXN_FLAGS_STARTED;
    3539           0 :     flags |= (uchar)fd_uint_if( !!(txn_payload->flags & FD_TXN_P_FLAGS_IS_SIMPLE_VOTE), FD_GUI_TXN_FLAGS_IS_SIMPLE_VOTE, 0U );
    3540           0 :     flags |= (uchar)fd_uint_if( (txn_payload->flags & FD_TXN_P_FLAGS_BUNDLE) || (txn_payload->flags & FD_TXN_P_FLAGS_INITIALIZER_BUNDLE), FD_GUI_TXN_FLAGS_FROM_BUNDLE, 0U );
    3541             : 
    3542           0 :     fd_gui_store_txn_start_t rec = {
    3543           0 :       .slot                    = _slot,
    3544           0 :       .bank_seq                = bank_seq,
    3545           0 :       .txn_idx                 = txn_idx,
    3546           0 :       .transaction_fee         = sig_rewards,
    3547           0 :       .priority_fee            = priority_rewards,
    3548           0 :       .timestamp_arrival_nanos = txn_payload->scheduler_arrival_time_nanos,
    3549           0 :       .microblock_start_ns     = tspub_ns,
    3550           0 :       .compute_units_requested = (uint)(cost_estimate & 0x1FFFFFU),
    3551           0 :       .microblock_idx          = microblock_idx,
    3552           0 :       .source_ipv4             = txn_payload->source_ipv4,
    3553           0 :       .source_tpu              = txn_payload->source_tpu,
    3554           0 :       .flags                   = flags
    3555           0 :     };
    3556           0 :     fd_memcpy( rec.signature, txn_payload->payload + txn->signature_off, FD_SHA512_HASH_SZ );
    3557           0 :     fd_gui_hist_ts_append( gui, FD_GUI_HIST_TXN_START, now, tspub_ns, &rec );
    3558           0 :   }
    3559             : 
    3560             :   /* At the moment, bank publishes at most 1 transaction per microblock,
    3561             :      even if it received microblocks with multiple transactions
    3562             :      (i.e. a bundle). This means that we need to calculate microblock
    3563             :      count here based on the transaction count. */
    3564           0 :   lslot->begin_microblocks += (uint)txn_cnt;
    3565           0 : }
    3566             : 
    3567             : static void
    3568             : fd_gui_stage_leader_block_votes( fd_gui_t *   gui,
    3569             :                                  ulong        landed_slot,
    3570             :                                  ulong        landed_bank_seq,
    3571           0 :                                  fd_txn_p_t * txn_p ) {
    3572           0 :   if( FD_LIKELY( !(txn_p->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS) || (txn_p->flags & (FD_TXN_P_FLAGS_FEES_ONLY | FD_TXN_P_FLAGS_RESULT_MASK)) ) ) return;
    3573             : 
    3574           0 :   fd_txn_t const * txn     = TXN( txn_p );
    3575           0 :   uchar const *    payload = txn_p->payload;
    3576             : 
    3577           0 :   fd_compact_tower_sync_serde_t tower_sync[ 1 ];
    3578           0 :   if( FD_UNLIKELY( !fd_txn_parse_simple_vote( txn, payload, tower_sync ) ) ) return;
    3579             : 
    3580           0 :   fd_acct_addr_t const * accs = fd_txn_get_acct_addrs( txn, payload );
    3581           0 :   if( FD_UNLIKELY( memcmp( &accs[ 0 ], gui->summary.identity_key->uc, sizeof(fd_pubkey_t) ) ) ) return; /* not our identity */
    3582           0 :   if( FD_UNLIKELY( gui->summary.has_vote_key && memcmp( &accs[ txn->signature_cnt==1 ? 1 : 2 ], gui->summary.vote_key->uc, sizeof(fd_pubkey_t) ) ) ) return; /* not our vote account */
    3583             : 
    3584           0 :   ulong cur = fd_ulong_if( tower_sync->root==ULONG_MAX, 0UL, tower_sync->root );
    3585           0 :   for( ulong i=0UL; i<tower_sync->lockouts_cnt; i++ ) {
    3586           0 :     if( FD_UNLIKELY( __builtin_uaddl_overflow( cur, tower_sync->lockouts[ i ].offset, &cur ) ) ) return;
    3587           0 :     fd_gui_stage_landed_vote( gui, landed_slot, landed_bank_seq, cur );
    3588           0 :   }
    3589           0 : }
    3590             : 
    3591             : void
    3592             : fd_gui_microblock_execution_end( fd_gui_t *     gui,
    3593             :                                  long           tspub_ns,
    3594             :                                  ulong          bank_idx,
    3595             :                                  ulong          _slot,
    3596             :                                  ulong          txn_cnt,
    3597             :                                  fd_txn_p_t *   txns,
    3598             :                                  ulong          pack_txn_idx,
    3599             :                                  fd_txn_ns_dt_t txn_ns_dt,
    3600             :                                  ulong          tips,
    3601             :                                  ulong          bank_seq,
    3602           0 :                                  long           now ) {
    3603           0 :   if( FD_UNLIKELY( 1UL!=txn_cnt ) ) FD_LOG_ERR(( "gui expects 1 txn per microblock from bank, found %lu", txn_cnt ));
    3604             : 
    3605           0 :   fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_or_create( gui, _slot, bank_seq );
    3606           0 :   if( FD_UNLIKELY( !lslot ) ) return;
    3607             : 
    3608           0 :   lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, tspub_ns, lslot->leader_start_time );
    3609             : 
    3610           0 :   for( ulong i=0UL; i<txn_cnt; i++ ) {
    3611           0 :     fd_txn_p_t * txn_p = &txns[ i ];
    3612           0 :     ulong txn_idx = pack_txn_idx + i;
    3613             : 
    3614           0 :     uchar flags = (uchar)FD_GUI_TXN_FLAGS_ENDED;
    3615           0 :     flags |= (uchar)fd_uint_if( !!(txn_p->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS), FD_GUI_TXN_FLAGS_LANDED_IN_BLOCK, 0U );
    3616             : 
    3617           0 :     fd_gui_store_txn_end_t rec = {
    3618           0 :       .slot                    = _slot,
    3619           0 :       .bank_seq                = bank_seq,
    3620           0 :       .txn_idx                 = txn_idx,
    3621           0 :       .timestamp_arrival_nanos = txn_p->scheduler_arrival_time_nanos,
    3622           0 :       .microblock_end_ns       = tspub_ns,
    3623           0 :       .txn_ns_dt               = txn_ns_dt,
    3624           0 :       .tips                    = tips,
    3625           0 :       .compute_units_consumed  = (uint)(txn_p->execle_cu.actual_consumed_cus & 0x1FFFFFU),
    3626           0 :       .bank_idx                = (uint)(bank_idx & 0x3FU),
    3627           0 :       .error_code              = (uint)((txn_p->flags >> 24) & 0x3FU),
    3628           0 :       .flags                   = flags
    3629           0 :     };
    3630           0 :     fd_gui_hist_ts_append( gui, FD_GUI_HIST_TXN_END, now, tspub_ns, &rec );
    3631             : 
    3632             :     /* Record our own votes that land in our own leader block. */
    3633           0 :     fd_gui_stage_leader_block_votes( gui, _slot, bank_seq, txn_p );
    3634           0 :   }
    3635             : 
    3636           0 :   lslot->end_microblocks = lslot->end_microblocks + (uint)txn_cnt;
    3637           0 : }

Generated by: LCOV version 1.14