LCOV - code coverage report
Current view: top level - disco/gui - fd_gui.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 493 2596 19.0 %
Date: 2026-10-23 04:27:11 Functions: 26 87 29.9 %

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

Generated by: LCOV version 1.14