LCOV - code coverage report
Current view: top level - disco/gui - fd_gui.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 68 2375 2.9 %
Date: 2026-08-28 06:53:58 Functions: 5 65 7.7 %

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

Generated by: LCOV version 1.14