LCOV - code coverage report
Current view: top level - disco/gui - fd_gui.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 2423 0.0 %
Date: 2026-05-22 08:05:30 Functions: 0 61 0.0 %

          Line data    Source code
       1             : #include "fd_gui.h"
       2             : #include "fd_gui_printf.h"
       3             : #include "fd_gui_metrics.h"
       4             : 
       5             : #include "../metrics/fd_metrics.h"
       6             : #include "../../discof/gossip/fd_gossip_tile.h"
       7             : #include "../../discoh/plugin/fd_plugin.h"
       8             : #include "../bundle/fd_bundle_tile.h"
       9             : 
      10             : #include "../../ballet/base58/fd_base58.h"
      11             : #include "../../ballet/json/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             : 
      16             : #include <stdio.h>
      17             : 
      18             : FD_FN_CONST ulong
      19           0 : fd_gui_align( void ) {
      20           0 :   return 128UL;
      21           0 : }
      22             : 
      23             : FD_FN_CONST ulong
      24           0 : fd_gui_footprint( ulong tile_cnt ) {
      25           0 :   FD_TEST( tile_cnt && tile_cnt <=FD_TOPO_MAX_TILES );
      26             : 
      27           0 :   ulong l = FD_LAYOUT_INIT;
      28           0 :   l = FD_LAYOUT_APPEND( l, fd_gui_align(),                sizeof(fd_gui_t) );
      29           0 :   l = FD_LAYOUT_APPEND( l, alignof(fd_gui_tile_timers_t), FD_GUI_TILE_TIMER_SNAP_CNT * tile_cnt * sizeof(fd_gui_tile_timers_t) );
      30           0 :   l = FD_LAYOUT_APPEND( l, alignof(fd_gui_tile_timers_t), FD_GUI_LEADER_CNT * FD_GUI_TILE_TIMER_LEADER_DOWNSAMPLE_CNT * tile_cnt * sizeof(fd_gui_tile_timers_t) );
      31           0 :   return FD_LAYOUT_FINI( l, fd_gui_align() );
      32           0 : }
      33             : 
      34             : void *
      35             : fd_gui_new( void *                shmem,
      36             :             fd_http_server_t *    http,
      37             :             char const *          version,
      38             :             char const *          cluster,
      39             :             uchar const *         identity_key,
      40             :             int                   has_vote_key,
      41             :             uchar const *         vote_key,
      42             :             int                   is_full_client,
      43             :             int                   snapshots_enabled,
      44             :             int                   is_voting,
      45             :             int                   schedule_strategy,
      46             :             char const *          wfs_expected_bank_hash_cstr,
      47             :             ushort                expected_shred_version,
      48             :             fd_topo_t *           topo,
      49           0 :             long                  now ) {
      50             : 
      51           0 :   if( FD_UNLIKELY( !shmem ) ) {
      52           0 :     FD_LOG_WARNING(( "NULL shmem" ));
      53           0 :     return NULL;
      54           0 :   }
      55             : 
      56           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmem, fd_gui_align() ) ) ) {
      57           0 :     FD_LOG_WARNING(( "misaligned shmem" ));
      58           0 :     return NULL;
      59           0 :   }
      60             : 
      61           0 :   if( FD_UNLIKELY( topo->tile_cnt>FD_TOPO_MAX_TILES ) ) {
      62           0 :     FD_LOG_WARNING(( "too many tiles" ));
      63           0 :     return NULL;
      64           0 :   }
      65             : 
      66           0 :   ulong tile_cnt = topo->tile_cnt;
      67             : 
      68           0 :   FD_SCRATCH_ALLOC_INIT( l, shmem );
      69           0 :   fd_gui_t *             gui                  = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(),                sizeof(fd_gui_t) );
      70           0 :   fd_gui_tile_timers_t * tile_timers_snap_mem = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_tile_timers_t), FD_GUI_TILE_TIMER_SNAP_CNT * tile_cnt * sizeof(fd_gui_tile_timers_t) );
      71           0 :   fd_gui_tile_timers_t * leader_tt_mem        = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_tile_timers_t), FD_GUI_LEADER_CNT * FD_GUI_TILE_TIMER_LEADER_DOWNSAMPLE_CNT * tile_cnt * sizeof(fd_gui_tile_timers_t) );
      72             : 
      73           0 :   gui->http     = http;
      74           0 :   gui->topo     = topo;
      75           0 :   gui->tile_cnt = tile_cnt;
      76             : 
      77           0 :   gui->summary.tile_timers_snap = tile_timers_snap_mem;
      78           0 :   for( ulong i=0UL; i<FD_GUI_LEADER_CNT; i++ ) gui->leader_slots[ i ]->tile_timers = leader_tt_mem + i * FD_GUI_TILE_TIMER_LEADER_DOWNSAMPLE_CNT * tile_cnt;
      79             : 
      80           0 :   gui->leader_slot = ULONG_MAX;
      81           0 :   gui->summary.schedule_strategy = schedule_strategy;
      82             : 
      83             : 
      84           0 :   gui->next_sample_400millis = now;
      85           0 :   gui->next_sample_100millis = now;
      86           0 :   gui->next_sample_50millis  = now;
      87           0 :   gui->next_sample_25millis  = now;
      88           0 :   gui->next_sample_10millis  = now;
      89             : 
      90           0 :   memcpy( gui->summary.identity_key->uc, identity_key, 32UL );
      91           0 :   fd_base58_encode_32( identity_key, NULL, gui->summary.identity_key_base58 );
      92           0 :   gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
      93             : 
      94           0 :   if( FD_LIKELY( has_vote_key ) ) {
      95           0 :     gui->summary.has_vote_key = 1;
      96           0 :     memcpy( gui->summary.vote_key->uc, vote_key, 32UL );
      97           0 :     fd_base58_encode_32( vote_key, NULL, gui->summary.vote_key_base58 );
      98           0 :     gui->summary.vote_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
      99           0 :   } else {
     100           0 :     gui->summary.has_vote_key = 0;
     101           0 :     memset( gui->summary.vote_key_base58, 0, sizeof(gui->summary.vote_key_base58) );
     102           0 :   }
     103             : 
     104           0 :   gui->summary.is_full_client                = is_full_client;
     105           0 :   gui->summary.version                       = version;
     106           0 :   gui->summary.cluster                       = cluster;
     107           0 :   gui->summary.startup_time_nanos            = gui->next_sample_400millis;
     108           0 :   gui->summary.expected_shred_version        = expected_shred_version;
     109           0 :   gui->summary.wfs_enabled          = 0;
     110           0 :   gui->summary.wfs_bank_hash[ 0UL ] = '\0';
     111             : 
     112           0 :   if( FD_UNLIKELY( is_full_client ) ) {
     113           0 :     fd_cstr_ncpy( gui->summary.wfs_bank_hash, wfs_expected_bank_hash_cstr, sizeof(gui->summary.wfs_bank_hash) );
     114           0 :     gui->summary.wfs_enabled = !!strcmp( wfs_expected_bank_hash_cstr, "" );
     115             : 
     116           0 :     if( FD_UNLIKELY( snapshots_enabled ) ) {
     117           0 :       gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP;
     118           0 :       gui->summary.boot_progress.joining_gossip_time_nanos = gui->next_sample_400millis;
     119           0 :       memset( gui->summary.boot_progress.loading_snapshot, 0, sizeof(gui->summary.boot_progress.loading_snapshot) );
     120           0 :       for( ulong i=0UL; i<FD_GUI_BOOT_PROGRESS_SNAPSHOT_CNT; i++ ) {
     121           0 :         gui->summary.boot_progress.loading_snapshot[ i ].reset_cnt = ULONG_MAX; /* ensures other fields are reset initially */
     122           0 :         gui->summary.boot_progress.loading_snapshot[ i ].slot = ULONG_MAX;
     123           0 :       }
     124           0 :       gui->summary.boot_progress.catching_up_time_nanos        = 0L;
     125           0 :       gui->summary.boot_progress.catching_up_first_replay_slot = ULONG_MAX;
     126           0 :       gui->summary.boot_progress.wfs_total_stake     = 0UL;
     127           0 :       gui->summary.boot_progress.wfs_connected_stake = 0UL;
     128           0 :       gui->summary.boot_progress.wfs_total_peers     = 0UL;
     129           0 :       gui->summary.boot_progress.wfs_connected_peers = 0UL;
     130           0 :       gui->summary.boot_progress.wfs_attempt         = 0UL;
     131           0 :     } else {
     132           0 :       fd_memset( &gui->summary.boot_progress, 0, sizeof(gui->summary.boot_progress) );
     133           0 :       gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
     134           0 :     }
     135           0 :   } else {
     136           0 :     gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_INITIALIZING;
     137           0 :     gui->summary.startup_progress.startup_got_full_snapshot              = 0;
     138           0 :     gui->summary.startup_progress.startup_full_snapshot_slot             = 0;
     139           0 :     gui->summary.startup_progress.startup_incremental_snapshot_slot      = 0;
     140           0 :     gui->summary.startup_progress.startup_waiting_for_supermajority_slot = ULONG_MAX;
     141           0 :     gui->summary.startup_progress.startup_ledger_max_slot                = ULONG_MAX;
     142           0 :   }
     143             : 
     144           0 :   gui->summary.identity_account_balance      = 0UL;
     145           0 :   gui->summary.vote_account_balance          = 0UL;
     146           0 :   gui->summary.estimated_slot_duration_nanos = 0UL;
     147             : 
     148           0 :   gui->summary.vote_distance = 0UL;
     149           0 :   gui->summary.vote_state = is_voting ? FD_GUI_VOTE_STATE_VOTING : FD_GUI_VOTE_STATE_NON_VOTING;
     150             : 
     151           0 :   gui->summary.sock_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "sock"   );
     152           0 :   gui->summary.net_tile_cnt    = fd_topo_tile_name_cnt( gui->topo, "net"    );
     153           0 :   gui->summary.quic_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "quic"   );
     154           0 :   gui->summary.verify_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "verify" );
     155           0 :   gui->summary.resolh_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolh" );
     156           0 :   gui->summary.resolv_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolv" );
     157           0 :   gui->summary.bank_tile_cnt   = fd_topo_tile_name_cnt( gui->topo, "bank"   );
     158           0 :   gui->summary.execle_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "execle" );
     159           0 :   gui->summary.execrp_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "execrp" );
     160           0 :   gui->summary.shred_tile_cnt  = fd_topo_tile_name_cnt( gui->topo, "shred"  );
     161             : 
     162           0 :   gui->summary.slot_rooted                   = ULONG_MAX;
     163           0 :   gui->summary.slot_optimistically_confirmed = ULONG_MAX;
     164           0 :   gui->summary.slot_completed                = ULONG_MAX;
     165           0 :   gui->summary.slot_estimated                = ULONG_MAX;
     166           0 :   gui->summary.slot_caught_up                = ULONG_MAX;
     167           0 :   gui->summary.slot_repair                   = ULONG_MAX;
     168           0 :   gui->summary.slot_turbine                  = ULONG_MAX;
     169           0 :   gui->summary.slot_reset                    = ULONG_MAX;
     170           0 :   gui->summary.slot_storage                  = ULONG_MAX;
     171           0 :   gui->summary.active_fork_cnt               = 1UL;
     172             : 
     173           0 :   for( ulong i=0UL; i < (FD_GUI_REPAIR_SLOT_HISTORY_SZ+1UL); i++ )  gui->summary.slots_max_repair[ i ].slot  = ULONG_MAX;
     174           0 :   for( ulong i=0UL; i < (FD_GUI_TURBINE_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_turbine[ i ].slot = ULONG_MAX;
     175             : 
     176           0 :   for( ulong i=0UL; i < FD_GUI_TURBINE_RECV_TIMESTAMPS; i++ ) gui->turbine_slots[ i ].slot = ULONG_MAX;
     177             : 
     178           0 :   gui->summary.estimated_tps_history_idx = 0UL;
     179           0 :   memset( gui->summary.estimated_tps_history, 0, sizeof(gui->summary.estimated_tps_history) );
     180             : 
     181           0 :   memset( gui->summary.txn_waterfall_reference, 0, sizeof(gui->summary.txn_waterfall_reference) );
     182           0 :   memset( gui->summary.txn_waterfall_current,   0, sizeof(gui->summary.txn_waterfall_current) );
     183             : 
     184           0 :   memset( gui->summary.tile_stats_reference, 0, sizeof(gui->summary.tile_stats_reference) );
     185           0 :   memset( gui->summary.tile_stats_current, 0, sizeof(gui->summary.tile_stats_current) );
     186             : 
     187           0 :   gui->summary.progcache_history_idx = 0UL;
     188           0 :   memset( gui->summary.progcache_hits_history,    0, sizeof(gui->summary.progcache_hits_history) );
     189           0 :   memset( gui->summary.progcache_lookups_history, 0, sizeof(gui->summary.progcache_lookups_history) );
     190           0 :   gui->summary.progcache_hits_1min    = 0UL;
     191           0 :   gui->summary.progcache_lookups_1min = 0UL;
     192             : 
     193           0 :   memset( gui->summary.tile_timers_snap,            0, tile_cnt * sizeof(fd_gui_tile_timers_t) );
     194           0 :   memset( gui->summary.tile_timers_snap + tile_cnt, 0, tile_cnt * sizeof(fd_gui_tile_timers_t) );
     195           0 :   gui->summary.tile_timers_snap_idx    = 2UL;
     196             : 
     197           0 :   memset( gui->summary.scheduler_counts_snap[ 0 ], 0, sizeof(gui->summary.scheduler_counts_snap[ 0 ]) );
     198           0 :   memset( gui->summary.scheduler_counts_snap[ 1 ], 0, sizeof(gui->summary.scheduler_counts_snap[ 1 ]) );
     199           0 :   gui->summary.scheduler_counts_snap_idx    = 2UL;
     200             : 
     201           0 :   for( ulong i=0UL; i<FD_GUI_SLOTS_CNT;  i++ ) gui->slots[ i ]->slot             = ULONG_MAX;
     202           0 :   for( ulong i=0UL; i<FD_GUI_LEADER_CNT; i++ ) gui->leader_slots[ i ]->slot      = ULONG_MAX;
     203           0 :   gui->leader_slots_cnt      = 0UL;
     204             : 
     205           0 :   gui->tower_cnt = 0UL;
     206             : 
     207           0 :   gui->block_engine.has_block_engine = 0;
     208             : 
     209           0 :   gui->epoch.has_epoch[ 0 ] = 0;
     210           0 :   gui->epoch.has_epoch[ 1 ] = 0;
     211             : 
     212           0 :   gui->gossip.peer_cnt               = 0UL;
     213           0 :   gui->vote_account.vote_account_cnt = 0UL;
     214           0 :   gui->validator_info.info_cnt       = 0UL;
     215             : 
     216           0 :   gui->pack_txn_idx = 0UL;
     217             : 
     218           0 :   gui->shreds.leader_shred_cnt      = 0UL;
     219           0 :   gui->shreds.staged_next_broadcast = 0UL;
     220           0 :   gui->shreds.staged_head           = 0UL;
     221           0 :   gui->shreds.staged_tail           = 0UL;
     222           0 :   gui->shreds.history_tail          = 0UL;
     223           0 :   gui->shreds.history_slot          = ULONG_MAX;
     224           0 :   gui->summary.catch_up_repair_sz   = 0UL;
     225           0 :   gui->summary.catch_up_turbine_sz  = 0UL;
     226           0 :   gui->summary.late_votes_sz        = 0UL;
     227             : 
     228           0 :   return gui;
     229           0 : }
     230             : 
     231             : fd_gui_t *
     232           0 : fd_gui_join( void * shmem ) {
     233           0 :   return (fd_gui_t *)shmem;
     234           0 : }
     235             : 
     236             : void
     237             : fd_gui_set_identity( fd_gui_t *    gui,
     238           0 :                      uchar const * identity_pubkey ) {
     239           0 :   memcpy( gui->summary.identity_key->uc, identity_pubkey, 32UL );
     240           0 :   fd_base58_encode_32( identity_pubkey, NULL, gui->summary.identity_key_base58 );
     241           0 :   gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
     242             : 
     243           0 :   fd_gui_printf_identity_key( gui );
     244           0 :   fd_http_server_ws_broadcast( gui->http );
     245           0 : }
     246             : 
     247             : void
     248             : fd_gui_ws_open( fd_gui_t * gui,
     249             :                 ulong      ws_conn_id,
     250           0 :                 long now ) {
     251           0 :   void (* printers[] )( fd_gui_t * gui ) = {
     252           0 :     gui->summary.is_full_client ? fd_gui_printf_boot_progress : fd_gui_printf_startup_progress,
     253           0 :     fd_gui_printf_version,
     254           0 :     fd_gui_printf_cluster,
     255           0 :     fd_gui_printf_commit_hash,
     256           0 :     fd_gui_printf_identity_key,
     257           0 :     fd_gui_printf_vote_key,
     258           0 :     fd_gui_printf_startup_time_nanos,
     259           0 :     fd_gui_printf_vote_state,
     260           0 :     fd_gui_printf_vote_distance,
     261           0 :     fd_gui_printf_turbine_slot,
     262           0 :     fd_gui_printf_repair_slot,
     263           0 :     fd_gui_printf_slot_caught_up,
     264           0 :     fd_gui_printf_tps_history,
     265           0 :     fd_gui_printf_tiles,
     266           0 :     fd_gui_printf_schedule_strategy,
     267           0 :     fd_gui_printf_identity_balance,
     268           0 :     fd_gui_printf_vote_balance,
     269           0 :     fd_gui_printf_estimated_slot_duration_nanos,
     270           0 :     fd_gui_printf_root_slot,
     271           0 :     fd_gui_printf_storage_slot,
     272           0 :     fd_gui_printf_reset_slot,
     273           0 :     fd_gui_printf_active_fork_cnt,
     274           0 :     fd_gui_printf_optimistically_confirmed_slot,
     275           0 :     fd_gui_printf_completed_slot,
     276           0 :     fd_gui_printf_estimated_slot,
     277           0 :     fd_gui_printf_live_tile_timers,
     278           0 :     fd_gui_printf_live_tile_metrics,
     279           0 :     fd_gui_printf_catch_up_history,
     280           0 :     fd_gui_printf_vote_latency_history,
     281           0 :     fd_gui_printf_late_votes_history
     282           0 :   };
     283             : 
     284           0 :   ulong printers_len = sizeof(printers) / sizeof(printers[0]);
     285           0 :   for( ulong i=0UL; i<printers_len; i++ ) {
     286           0 :     printers[ i ]( gui );
     287           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     288           0 :   }
     289             : 
     290           0 :   if( FD_LIKELY( gui->summary.is_full_client ) ) {
     291           0 :     fd_gui_printf_live_program_cache( gui );
     292           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     293           0 :   }
     294             : 
     295           0 :   if( FD_LIKELY( gui->block_engine.has_block_engine ) ) {
     296           0 :     fd_gui_printf_block_engine( gui );
     297           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     298           0 :   }
     299             : 
     300           0 :   for( ulong i=0UL; i<2UL; i++ ) {
     301           0 :     if( FD_LIKELY( gui->epoch.has_epoch[ i ] ) ) {
     302           0 :       fd_gui_printf_skip_rate( gui, i );
     303           0 :       FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     304           0 :       fd_gui_printf_epoch( gui, i );
     305           0 :       FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     306           0 :     }
     307           0 :   }
     308             : 
     309           0 :   ulong epoch_idx = fd_gui_current_epoch_idx( gui );
     310           0 :   if( FD_LIKELY( epoch_idx!=ULONG_MAX ) ) {
     311           0 :     fd_gui_printf_skipped_history( gui, epoch_idx );
     312           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     313           0 :     fd_gui_printf_skipped_history_cluster( gui, epoch_idx );
     314           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     315           0 :   }
     316             : 
     317             :   /* Print peers last because it's the largest message and would
     318             :      block other information. */
     319           0 :   fd_gui_printf_peers_all( gui );
     320           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     321             : 
     322             :   /* rebroadcast 10s of historical shred data */
     323           0 :   if( FD_LIKELY( gui->shreds.staged_next_broadcast!=ULONG_MAX ) ) {
     324           0 :     fd_gui_printf_shred_rebroadcast( gui, now-(long)(10*1e9) );
     325           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
     326           0 :   }
     327           0 : }
     328             : 
     329             : static void
     330           0 : fd_gui_tile_timers_snap( fd_gui_t * gui ) {
     331           0 :   fd_gui_tile_timers_t * cur = gui->summary.tile_timers_snap + gui->summary.tile_timers_snap_idx * gui->tile_cnt;
     332           0 :   gui->summary.tile_timers_snap_idx = (gui->summary.tile_timers_snap_idx+1UL)%FD_GUI_TILE_TIMER_SNAP_CNT;
     333           0 :   for( ulong i=0UL; i<gui->topo->tile_cnt; i++ ) {
     334           0 :     fd_topo_tile_t * tile = &gui->topo->tiles[ i ];
     335           0 :     if ( FD_UNLIKELY( !tile->metrics ) ) {
     336             :       /* bench tiles might not have been booted initially.
     337             :          This check shouldn't be necessary if all tiles barrier after boot. */
     338             :       // TODO(FIXME) this probably isn't the right fix but it makes fddev bench work for now
     339           0 :       return;
     340           0 :     }
     341           0 :     volatile ulong const * tile_metrics = fd_metrics_tile( tile->metrics );
     342             : 
     343           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 )    ];
     344           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_HOUSEKEEPING_IDX   ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_HOUSEKEEPING )   ];
     345           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_HOUSEKEEPING ) ];
     346           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 )         ];
     347           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_PREFRAG_IDX        ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_PREFRAG )        ];
     348           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX      ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG )      ];
     349           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 )        ];
     350           0 :     cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_POSTFRAG_IDX       ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_POSTFRAG )       ];
     351             : 
     352           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_WAIT_IDX   ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_WAIT )   ];
     353           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_USER_IDX   ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_USER )   ];
     354           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_SYSTEM_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_SYSTEM ) ];
     355           0 :     cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_IDLE_IDX   ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_IDLE )   ];
     356             : 
     357           0 :     cur[ i ].in_backp  = (int)tile_metrics[ MIDX(GAUGE, TILE, IN_BACKPRESSURE) ];
     358           0 :     cur[ i ].status    = (uchar)tile_metrics[ MIDX( GAUGE, TILE, STATUS ) ];
     359           0 :     cur[ i ].heartbeat = tile_metrics[ MIDX( GAUGE, TILE, HEARTBEAT ) ];
     360           0 :     cur[ i ].backp_cnt = tile_metrics[ MIDX( COUNTER, TILE, BACKPRESSURE_COUNT ) ];
     361           0 :     cur[ i ].nvcsw     = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_VOLUNTARY_COUNT ) ];
     362           0 :     cur[ i ].nivcsw    = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_INVOLUNTARY_COUNT ) ];
     363           0 :     cur[ i ].minflt    = tile_metrics[ MIDX( COUNTER, TILE, PAGE_FAULT_MINOR_COUNT ) ];
     364           0 :     cur[ i ].majflt    = tile_metrics[ MIDX( COUNTER, TILE, PAGE_FAULT_MAJOR_COUNT ) ];
     365           0 :     cur[ i ].last_cpu  = (ushort)tile_metrics[ MIDX( GAUGE, TILE, LAST_CPU ) ];
     366           0 :   }
     367           0 : }
     368             : 
     369             : static void
     370           0 : fd_gui_scheduler_counts_snap( fd_gui_t * gui, long now ) {
     371           0 :   ulong pack_tile_idx = fd_topo_find_tile( gui->topo, "pack", 0UL );
     372           0 :   if( FD_UNLIKELY( pack_tile_idx==ULONG_MAX ) ) return;
     373             : 
     374           0 :   fd_gui_scheduler_counts_t * cur = gui->summary.scheduler_counts_snap[ gui->summary.scheduler_counts_snap_idx ];
     375           0 :   gui->summary.scheduler_counts_snap_idx = (gui->summary.scheduler_counts_snap_idx+1UL)%FD_GUI_SCHEDULER_COUNT_SNAP_CNT;
     376             : 
     377           0 :   fd_topo_tile_t const * pack = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "pack", 0UL ) ];
     378           0 :   volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
     379             : 
     380           0 :   cur->sample_time_ns = now;
     381             : 
     382           0 :   cur->regular     = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_REGULAR ) ];
     383           0 :   cur->votes       = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_VOTES ) ];
     384           0 :   cur->conflicting = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_CONFLICTING ) ];
     385           0 :   cur->bundles     = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_BUNDLES ) ];
     386           0 : }
     387             : 
     388             : static void
     389           0 : fd_gui_estimated_tps_snap( fd_gui_t * gui ) {
     390           0 :   ulong vote_failed     = 0UL;
     391           0 :   ulong vote_success    = 0UL;
     392           0 :   ulong nonvote_success = 0UL;
     393           0 :   ulong nonvote_failed  = 0UL;
     394             : 
     395           0 :   if( FD_LIKELY( gui->summary.slot_completed==ULONG_MAX ) ) return;
     396           0 :   for( ulong i=0UL; i<fd_ulong_min( gui->summary.slot_completed+1UL, FD_GUI_SLOTS_CNT ); i++ ) {
     397           0 :     ulong _slot = gui->summary.slot_completed-i;
     398           0 :     fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
     399           0 :     if( FD_UNLIKELY( !slot ) ) break; /* Slot no longer exists, no TPS. */
     400           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. */
     401           0 :     if( FD_UNLIKELY( slot->completed_time+FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS*1000L*1000L*1000L<gui->next_sample_400millis ) ) break; /* Slot too old. */
     402           0 :     if( FD_UNLIKELY( slot->skipped ) ) continue; /* Skipped slots don't count to TPS. */
     403           0 :     if( FD_UNLIKELY( slot->vote_failed==UINT_MAX ) ) continue; /* Slot transaction counts not yet populated. */
     404           0 :     vote_failed     += slot->vote_failed;
     405           0 :     vote_success    += slot->vote_success;
     406           0 :     nonvote_success += slot->nonvote_success;
     407           0 :     nonvote_failed  += slot->nonvote_failed;
     408           0 :   }
     409             : 
     410           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].vote_failed = vote_failed;
     411           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].vote_success = vote_success;
     412           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].nonvote_success = nonvote_success;
     413           0 :   gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].nonvote_failed = nonvote_failed;
     414           0 :   gui->summary.estimated_tps_history_idx = (gui->summary.estimated_tps_history_idx+1UL) % FD_GUI_TPS_HISTORY_SAMPLE_CNT;
     415           0 : }
     416             : 
     417             : static void
     418             : fd_gui_network_stats_snap( fd_gui_t *               gui,
     419           0 :                            fd_gui_network_stats_t * cur ) {
     420           0 :   fd_topo_t * topo = gui->topo;
     421           0 :   ulong gossvf_tile_cnt = fd_topo_tile_name_cnt( topo, "gossvf" );
     422           0 :   ulong gossip_tile_cnt = fd_topo_tile_name_cnt( topo, "gossip" );
     423           0 :   ulong shred_tile_cnt  = fd_topo_tile_name_cnt( topo, "shred" );
     424           0 :   ulong net_tile_cnt    = fd_topo_tile_name_cnt( topo, "net" );
     425           0 :   ulong quic_tile_cnt   = fd_topo_tile_name_cnt( topo, "quic" );
     426             : 
     427           0 :   cur->in.gossip   = fd_gui_metrics_gossip_total_ingress_bytes( topo, gossvf_tile_cnt );
     428           0 :   cur->out.gossip  = fd_gui_metrics_gosip_total_egress_bytes( topo, gossip_tile_cnt );
     429           0 :   cur->in.turbine  = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_TURBINE_RCV_BYTES ) );
     430             : 
     431           0 :   cur->out.turbine = 0UL;
     432           0 :   cur->out.repair  = 0UL;
     433           0 :   cur->out.tpu     = 0UL;
     434           0 :   for( ulong i=0UL; i<net_tile_cnt; i++ ) {
     435           0 :     ulong net_tile_idx = fd_topo_find_tile( topo, "net", i );
     436           0 :     if( FD_UNLIKELY( net_tile_idx==ULONG_MAX ) ) continue;
     437           0 :     fd_topo_tile_t const * net = &topo->tiles[ net_tile_idx ];
     438           0 :     for( ulong j=0UL; j<net->in_cnt; j++ ) {
     439           0 :       if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "shred_net" ) ) ) {
     440           0 :           cur->out.turbine += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
     441           0 :       }
     442             : 
     443           0 :       if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "repair_net" ) ) ) {
     444           0 :           cur->out.repair += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
     445           0 :       }
     446             : 
     447           0 :       if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "send_net" ) ) ) {
     448           0 :           cur->out.tpu += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
     449           0 :       }
     450           0 :     }
     451           0 :   }
     452             : 
     453           0 :   cur->in.repair = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_REPAIR_RCV_BYTES ) );
     454           0 :   ulong repair_tile_idx = fd_topo_find_tile( topo, "repair", 0UL );
     455           0 :   if( FD_LIKELY( repair_tile_idx!=ULONG_MAX ) ) {
     456           0 :     fd_topo_tile_t const * repair = &topo->tiles[ repair_tile_idx ];
     457             : 
     458           0 :     for( ulong i=0UL; i<repair->in_cnt; i++ ) {
     459           0 :       if( FD_UNLIKELY( !strcmp( topo->links[ repair->in_link_id[ i ] ].name, "net_repair" ) ) ) {
     460           0 :           cur->in.repair += fd_metrics_link_in( repair->metrics, i )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
     461           0 :       }
     462           0 :     }
     463           0 :   }
     464             : 
     465           0 :   cur->in.tpu = 0UL;
     466           0 :   for( ulong i=0UL; i<quic_tile_cnt; i++ ) {
     467           0 :     ulong quic_tile_idx = fd_topo_find_tile( topo, "quic", i );
     468           0 :     if( FD_UNLIKELY( quic_tile_idx==ULONG_MAX ) ) continue;
     469           0 :     fd_topo_tile_t const * quic = &topo->tiles[ quic_tile_idx ];
     470           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
     471           0 :     cur->in.tpu += quic_metrics[ MIDX( COUNTER, QUIC, RECEIVED_BYTES ) ];
     472           0 :   }
     473             : 
     474           0 :   ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
     475           0 :   if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
     476           0 :     fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
     477           0 :     volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
     478           0 :     cur->in.tpu += bundle_metrics[ MIDX( COUNTER, BUNDLE, PROTO_RECEIVED_BYTES ) ];
     479           0 :   }
     480             : 
     481           0 :   ulong metric_tile_idx = fd_topo_find_tile( topo, "metric", 0UL );
     482           0 :   if( FD_LIKELY( metric_tile_idx!=ULONG_MAX ) ) {
     483           0 :     fd_topo_tile_t const * metric = &topo->tiles[ metric_tile_idx ];
     484           0 :     volatile ulong * metric_metrics = fd_metrics_tile( metric->metrics );
     485           0 :     cur->in.metric  = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_READ ) ];
     486           0 :     cur->out.metric = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_WRITTEN ) ];
     487           0 :   } else {
     488           0 :     cur->in.metric  = 0UL;
     489           0 :     cur->out.metric = 0UL;
     490           0 :   }
     491           0 : }
     492             : 
     493             : /* Snapshot all of the data from metrics to construct a view of the
     494             :    transaction waterfall.
     495             : 
     496             :    Tiles are sampled in reverse pipeline order: this helps prevent data
     497             :    discrepancies where a later tile has "seen" more transactions than an
     498             :    earlier tile, which shouldn't typically happen. */
     499             : 
     500             : static void
     501             : fd_gui_txn_waterfall_snap( fd_gui_t *               gui,
     502           0 :                            fd_gui_txn_waterfall_t * cur ) {
     503           0 :   memset( cur, 0, sizeof(fd_gui_txn_waterfall_t) );
     504           0 :   fd_topo_t * topo = gui->topo;
     505             : 
     506           0 :   for( ulong i=0UL; i<gui->summary.bank_tile_cnt; i++ ) {
     507           0 :     fd_topo_tile_t const * bank = &topo->tiles[ fd_topo_find_tile( topo, "bank", i ) ];
     508             : 
     509           0 :     volatile ulong const * bank_metrics = fd_metrics_tile( bank->metrics );
     510           0 :     cur->out.block_success += bank_metrics[ MIDX( COUNTER, BANK, SUCCESSFUL_TRANSACTIONS ) ];
     511             : 
     512           0 :     cur->out.block_fail +=
     513           0 :         bank_metrics[ MIDX( COUNTER, BANK, EXECUTED_FAILED_TRANSACTIONS ) ]
     514           0 :       + bank_metrics[ MIDX( COUNTER, BANK, FEE_ONLY_TRANSACTIONS        ) ];
     515             : 
     516           0 :     cur->out.bank_invalid +=
     517           0 :         bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_ACCOUNT_UNINITIALIZED ) ]
     518           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_ACCOUNT_NOT_FOUND ) ]
     519           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_INVALID_ACCOUNT_OWNER ) ]
     520           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_INVALID_ACCOUNT_DATA ) ]
     521           0 :       + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_INVALID_LOOKUP_INDEX  ) ];
     522             : 
     523           0 :     cur->out.bank_invalid +=
     524           0 :         bank_metrics[ MIDX( COUNTER, BANK, PROCESSING_FAILED ) ];
     525           0 :   }
     526             : 
     527           0 :   for( ulong i=0UL; i<gui->summary.execle_tile_cnt; i++ ) {
     528           0 :     fd_topo_tile_t const * execle = &topo->tiles[ fd_topo_find_tile( topo, "execle", i ) ];
     529             : 
     530           0 :     volatile ulong const * execle_metrics = fd_metrics_tile( execle->metrics );
     531             : 
     532           0 :     cur->out.block_success += execle_metrics[ MIDX( COUNTER, EXECLE, TRANSACTION_LANDED_LANDED_SUCCESS ) ];
     533           0 :     cur->out.block_fail    +=
     534           0 :         execle_metrics[ MIDX( COUNTER, EXECLE, TRANSACTION_LANDED_LANDED_FEES_ONLY ) ]
     535           0 :       + execle_metrics[ MIDX( COUNTER, EXECLE, TRANSACTION_LANDED_LANDED_FAILED ) ];
     536           0 :     cur->out.bank_invalid  += execle_metrics[ MIDX( COUNTER, EXECLE, TRANSACTION_LANDED_UNLANDED ) ];
     537             : 
     538           0 :     cur->out.bank_nonce_already_advanced += execle_metrics[ MIDX( COUNTER, EXECLE, TRANSACTION_RESULT_NONCE_ALREADY_ADVANCED ) ];
     539           0 :     cur->out.bank_nonce_advance_failed   += execle_metrics[ MIDX( COUNTER, EXECLE, TRANSACTION_RESULT_NONCE_ADVANCE_FAILED ) ];
     540           0 :     cur->out.bank_nonce_wrong_blockhash  += execle_metrics[ MIDX( COUNTER, EXECLE, TRANSACTION_RESULT_NONCE_WRONG_BLOCKHASH ) ];
     541           0 :   }
     542             : 
     543           0 :   ulong pack_tile_idx = fd_topo_find_tile( topo, "pack", 0UL );
     544           0 :   if( pack_tile_idx!=ULONG_MAX ) {
     545           0 :     fd_topo_tile_t const * pack = &topo->tiles[ pack_tile_idx ];
     546           0 :     volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
     547             : 
     548           0 :     cur->out.pack_invalid_bundle =
     549           0 :         pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DROPPED_PARTIAL_BUNDLE ) ]
     550           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTION_FAILED ) ]
     551           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_CREATION_FAILED ) ];
     552             : 
     553           0 :     cur->out.pack_invalid =
     554           0 :         pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_INSTR_ACCT_CNT ) ]
     555           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_NONCE_CONFLICT ) ]
     556           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_BUNDLE_BLACKLIST ) ]
     557           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_INVALID_NONCE ) ]
     558           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_WRITE_SYSVAR ) ]
     559           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_ESTIMATION_FAIL ) ]
     560           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_DUPLICATE_ACCOUNT ) ]
     561           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_TOO_MANY_ACCOUNTS ) ]
     562           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_TOO_LARGE ) ]
     563           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_ADDR_LUT ) ]
     564           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_UNAFFORDABLE ) ]
     565           0 :       + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_DUPLICATE ) ]
     566           0 :       - pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTION_FAILED ) ]; /* so we don't double count this, since its already accounted for in invalid_bundle */
     567             : 
     568           0 :     cur->out.pack_expired = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_EXPIRED ) ] +
     569           0 :                             pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_EXPIRED ) ] +
     570           0 :                             pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DELETED ) ] +
     571           0 :                             pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_NONCE_PRIORITY ) ];
     572             : 
     573           0 :     cur->out.pack_already_executed = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_ALREADY_EXECUTED ) ];
     574             : 
     575           0 :     cur->out.pack_leader_slow = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_PRIORITY ) ];
     576             : 
     577           0 :     cur->out.pack_wait_full =
     578           0 :         pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DROPPED_FROM_EXTRA ) ];
     579             : 
     580           0 :     cur->out.pack_retained = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS ) ];
     581             : 
     582           0 :     ulong inserted_to_extra = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_TO_EXTRA ) ];
     583           0 :     ulong inserted_from_extra = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_FROM_EXTRA ) ]
     584           0 :                                 + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DROPPED_FROM_EXTRA ) ];
     585           0 :     cur->out.pack_retained += fd_ulong_if( inserted_to_extra>=inserted_from_extra, inserted_to_extra-inserted_from_extra, 0UL );
     586             : 
     587           0 :     cur->in.pack_cranked =
     588           0 :         pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTED ) ]
     589           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTION_FAILED ) ]
     590           0 :       + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_CREATION_FAILED ) ];
     591           0 :   }
     592             : 
     593           0 :   for( ulong i=0UL; i<gui->summary.resolh_tile_cnt; i++ ) {
     594           0 :     fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolh", i ) ];
     595           0 :     volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
     596             : 
     597           0 :     cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLH, NO_BANK_DROP ) ];
     598           0 :     cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLH, BLOCKHASH_EXPIRED ) ]
     599           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, TRANSACTION_BUNDLE_PEER_FAILURE  ) ];
     600           0 :     cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
     601           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
     602           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
     603           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
     604           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
     605           0 :     cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_OVERRUN ) ];
     606             : 
     607           0 :     ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_INSERTED ) ];
     608           0 :     ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_OVERRUN ) ]
     609           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_PUBLISHED ) ]
     610           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_REMOVED ) ];
     611           0 :     cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
     612           0 :   }
     613             : 
     614           0 :   for( ulong i=0UL; i<gui->summary.resolv_tile_cnt; i++ ) {
     615           0 :     fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolv", i ) ];
     616           0 :     volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
     617             : 
     618           0 :     cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLV, NO_BANK_DROP ) ];
     619           0 :     cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLV, BLOCKHASH_EXPIRED ) ]
     620           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, TRANSACTION_BUNDLE_PEER_FAILURE  ) ];
     621           0 :     cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
     622           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
     623           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
     624           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
     625           0 :                                 + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
     626           0 :     cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ];
     627             : 
     628           0 :     ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_INSERTED ) ];
     629           0 :     ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ]
     630           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_PUBLISHED ) ]
     631           0 :                               + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_REMOVED ) ];
     632           0 :     cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
     633           0 :   }
     634             : 
     635           0 :   ulong dedup_tile_idx = fd_topo_find_tile( topo, "dedup", 0UL );
     636           0 :   if( FD_UNLIKELY( dedup_tile_idx!=ULONG_MAX ) ) {
     637           0 :     fd_topo_tile_t const * dedup = &topo->tiles[ dedup_tile_idx ];
     638           0 :     volatile ulong const * dedup_metrics = fd_metrics_tile( dedup->metrics );
     639             : 
     640           0 :     cur->out.dedup_duplicate = dedup_metrics[ MIDX( COUNTER, DEDUP, TRANSACTION_RESULT_DEDUP_FAILURE ) ]
     641           0 :                              + dedup_metrics[ MIDX( COUNTER, DEDUP, TRANSACTION_RESULT_BUNDLE_PEER_FAILURE ) ];
     642           0 :   }
     643             : 
     644           0 :   for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
     645           0 :     fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
     646           0 :     volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
     647             : 
     648           0 :     for( ulong j=0UL; j<gui->summary.quic_tile_cnt; j++ ) {
     649             :       /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this verify tile. */
     650           0 :       cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_POLLING_FRAG_COUNT_OFF ] / gui->summary.verify_tile_cnt;
     651           0 :       cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_READING_FRAG_COUNT_OFF ];
     652           0 :     }
     653             : 
     654           0 :     cur->out.verify_failed    += verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_RESULT_VERIFY_FAILURE ) ] +
     655           0 :                                  verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_RESULT_BUNDLE_PEER_FAILURE ) ];
     656           0 :     cur->out.verify_parse     += verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_RESULT_PARSE_FAILURE ) ];
     657           0 :     cur->out.verify_duplicate += verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_RESULT_DEDUP_FAILURE ) ];
     658           0 :   }
     659             : 
     660           0 :   for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
     661           0 :     fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
     662           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
     663             : 
     664           0 :     cur->out.tpu_udp_invalid  += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_UNDERSZ      ) ];
     665           0 :     cur->out.tpu_udp_invalid  += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_OVERSZ       ) ];
     666           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_UNDERSZ             ) ];
     667           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_OVERSZ              ) ];
     668           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, TXN_OVERSZ              ) ];
     669           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_CRYPTO_FAILED       ) ];
     670           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NO_CONN             ) ];
     671           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_WRONG_SRC           ) ];
     672           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NET_HEADER_INVALID  ) ];
     673           0 :     cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_QUIC_HEADER_INVALID ) ];
     674           0 :     cur->out.quic_abandoned   += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_ABANDONED          ) ];
     675           0 :     cur->out.quic_frag_drop   += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_OVERRUN            ) ];
     676             : 
     677           0 :     for( ulong j=0UL; j<gui->summary.net_tile_cnt; j++ ) {
     678             :       /* TODO: Not precise... net frags that were skipped might not have been destined for QUIC tile */
     679             :       /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this QUIC tile */
     680           0 :       cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_POLLING_FRAG_COUNT_OFF ] / gui->summary.quic_tile_cnt;
     681           0 :       cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_READING_FRAG_COUNT_OFF ];
     682           0 :     }
     683           0 :   }
     684             : 
     685           0 :   for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
     686           0 :     fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
     687           0 :     volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
     688             : 
     689           0 :     cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_RING_FULL ) ];
     690           0 :     cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_DROPPED_OTHER ) ];
     691           0 :     cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_FILL_RING_EMPTY_DESCS ) ];
     692           0 :   }
     693             : 
     694           0 :   ulong bundle_txns_received = 0UL;
     695           0 :   ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
     696           0 :   if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
     697           0 :     fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
     698           0 :     volatile ulong const * bundle_metrics = fd_metrics_tile( bundle->metrics );
     699             : 
     700           0 :     bundle_txns_received = bundle_metrics[ MIDX( COUNTER, BUNDLE, TRANSACTION_RECEIVED ) ];
     701           0 :   }
     702             : 
     703           0 :   if( FD_UNLIKELY( gui->summary.is_full_client ) ) {
     704           0 :     cur->in.gossip = 0UL;
     705           0 :     for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
     706           0 :       fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
     707           0 :       volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
     708           0 :       cur->in.gossip += verify_metrics[ MIDX( COUNTER, VERIFY, GOSSIPED_VOTES_RECEIVED ) ];
     709           0 :     }
     710           0 :   } else if( dedup_tile_idx!=ULONG_MAX ) {
     711           0 :     fd_topo_tile_t const * dedup = &topo->tiles[ dedup_tile_idx ];
     712           0 :     volatile ulong const * dedup_metrics = fd_metrics_tile( dedup->metrics );
     713           0 :     cur->in.gossip = dedup_metrics[ MIDX( COUNTER, DEDUP, GOSSIPED_VOTES_RECEIVED ) ];
     714           0 :   }
     715             : 
     716           0 :   cur->in.quic     = cur->out.tpu_quic_invalid +
     717           0 :                      cur->out.quic_overrun +
     718           0 :                      cur->out.quic_frag_drop +
     719           0 :                      cur->out.quic_abandoned +
     720           0 :                      cur->out.net_overrun;
     721           0 :   cur->in.udp      = cur->out.tpu_udp_invalid;
     722           0 :   cur->in.block_engine = bundle_txns_received;
     723           0 :   for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
     724           0 :     fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
     725           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
     726             : 
     727           0 :     cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_RECEIVED_QUIC_FAST ) ];
     728           0 :     cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_RECEIVED_QUIC_FRAG ) ];
     729           0 :     cur->in.udp  += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_RECEIVED_UDP       ) ];
     730           0 :   }
     731           0 : }
     732             : 
     733             : static void
     734             : fd_gui_tile_stats_snap( fd_gui_t *                     gui,
     735             :                         fd_gui_txn_waterfall_t const * waterfall,
     736             :                         fd_gui_tile_stats_t *          stats,
     737           0 :                         long                           now ) {
     738           0 :   memset( stats, 0, sizeof(fd_gui_tile_stats_t) );
     739           0 :   fd_topo_t const * topo = gui->topo;
     740             : 
     741           0 :   stats->sample_time_nanos = now;
     742             : 
     743           0 :   for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
     744           0 :     fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
     745           0 :     volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
     746             : 
     747           0 :     stats->net_in_rx_bytes  += net_metrics[ MIDX( COUNTER, NET, RX_BYTES_TOTAL ) ];
     748           0 :     stats->net_out_tx_bytes += net_metrics[ MIDX( COUNTER, NET, TX_BYTES_TOTAL ) ];
     749           0 :   }
     750             : 
     751           0 :   for( ulong i=0UL; i<gui->summary.sock_tile_cnt; i++ ) {
     752           0 :     fd_topo_tile_t const * sock = &topo->tiles[ fd_topo_find_tile( topo, "sock", i ) ];
     753           0 :     volatile ulong * sock_metrics = fd_metrics_tile( sock->metrics );
     754             : 
     755           0 :     stats->net_in_rx_bytes  += sock_metrics[ MIDX( COUNTER, SOCK, RX_BYTES_TOTAL ) ];
     756           0 :     stats->net_out_tx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, TX_BYTES_TOTAL ) ];
     757           0 :   }
     758             : 
     759           0 :   for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
     760           0 :     fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
     761           0 :     volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
     762             : 
     763           0 :     stats->quic_conn_cnt += quic_metrics[ MIDX( GAUGE, QUIC, CONNECTIONS_ALLOC ) ];
     764           0 :   }
     765             : 
     766           0 :   ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
     767           0 :   if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
     768           0 :     fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
     769           0 :     volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
     770           0 :     stats->bundle_rtt_smoothed_nanos = bundle_metrics[ MIDX( GAUGE, BUNDLE, RTT_SMOOTHED ) ];
     771             : 
     772           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 ) );
     773           0 :     stats->bundle_rx_delay_hist.sum = bundle_metrics[ MIDX( HISTOGRAM, BUNDLE, MESSAGE_RX_DELAY_NANOS ) + FD_HISTF_BUCKET_CNT ];
     774           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 ];
     775           0 :   }
     776             : 
     777           0 :   stats->verify_drop_cnt = waterfall->out.verify_duplicate +
     778           0 :                            waterfall->out.verify_parse +
     779           0 :                            waterfall->out.verify_failed;
     780           0 :   stats->verify_total_cnt = waterfall->in.gossip +
     781           0 :                             waterfall->in.quic +
     782           0 :                             waterfall->in.udp -
     783           0 :                             waterfall->out.net_overrun -
     784           0 :                             waterfall->out.tpu_quic_invalid -
     785           0 :                             waterfall->out.tpu_udp_invalid -
     786           0 :                             waterfall->out.quic_abandoned -
     787           0 :                             waterfall->out.quic_frag_drop -
     788           0 :                             waterfall->out.quic_overrun -
     789           0 :                             waterfall->out.verify_overrun;
     790           0 :   stats->dedup_drop_cnt = waterfall->out.dedup_duplicate;
     791           0 :   stats->dedup_total_cnt = stats->verify_total_cnt -
     792           0 :                            waterfall->out.verify_duplicate -
     793           0 :                             waterfall->out.verify_parse -
     794           0 :                             waterfall->out.verify_failed;
     795             : 
     796           0 :   ulong pack_tile_idx = fd_topo_find_tile( topo, "pack", 0UL );
     797           0 :   if( pack_tile_idx!=ULONG_MAX ) {
     798           0 :     fd_topo_tile_t const * pack  = &topo->tiles[ pack_tile_idx ];
     799           0 :     volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
     800           0 :     stats->pack_buffer_cnt      = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS ) ];
     801           0 :     stats->pack_buffer_capacity = pack->pack.max_pending_transactions;
     802           0 :   }
     803             : 
     804           0 :   stats->bank_txn_exec_cnt = waterfall->out.block_fail + waterfall->out.block_success;
     805           0 : }
     806             : 
     807             : static void
     808           0 : fd_gui_run_boot_progress( fd_gui_t * gui, long now ) {
     809           0 :   fd_topo_tile_t const * snapct = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapct", 0UL ) ];
     810           0 :   volatile ulong * snapct_metrics = fd_metrics_tile( snapct->metrics );
     811             : 
     812           0 :   fd_topo_tile_t const * snapdc = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapdc", 0UL ) ];
     813           0 :   volatile ulong * snapdc_metrics = fd_metrics_tile( snapdc->metrics );
     814             : 
     815           0 :   fd_topo_tile_t const * snapin = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapin", 0UL ) ];
     816           0 :   volatile ulong * snapin_metrics = fd_metrics_tile( snapin->metrics );
     817             : 
     818           0 :   fd_topo_tile_t const * gossip = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "gossip", 0UL ) ];
     819           0 :   volatile ulong * gossip_metrics = fd_metrics_tile( gossip->metrics );
     820             : 
     821           0 :   ulong snapshot_phase = snapct_metrics[ MIDX( GAUGE, SNAPCT, STATE ) ];
     822           0 :   ulong wfs_state      = gossip_metrics[ MIDX( GAUGE, GOSSIP, WFS_STATE ) ];
     823             : 
     824             :   /* state transitions */
     825           0 :   if( FD_UNLIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
     826           0 :     gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
     827           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_completed!=ULONG_MAX ) ) {
     828           0 :     if( FD_UNLIKELY( gui->summary.wfs_enabled ) ) {
     829           0 :       if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) {
     830           0 :         ulong snap_inc  = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].slot;
     831           0 :         ulong snap_full = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].slot;
     832           0 :         gui->summary.slot_caught_up = fd_ulong_if( snap_inc!=ULONG_MAX, snap_inc, snap_full );
     833           0 :         gui->summary.boot_progress.catching_up_time_nanos = now;
     834             : 
     835           0 :         fd_gui_printf_slot_caught_up( gui );
     836           0 :         fd_http_server_ws_broadcast( gui->http );
     837           0 :       }
     838           0 :       gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
     839           0 :     } else {
     840           0 :       gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP;
     841           0 :     }
     842           0 :   } else if( FD_UNLIKELY( snapshot_phase == FD_SNAPCT_STATE_SHUTDOWN && wfs_state==FD_GOSSIP_WFS_STATE_WAIT ) ) {
     843           0 :     gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY;
     844           0 :   } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_FULL_FILE
     845           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_FILE_FINI
     846           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_FILE_DONE
     847           0 :                      || snapshot_phase==FD_SNAPCT_STATE_READING_FULL_HTTP
     848           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_FINI
     849           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_DONE ) ) {
     850           0 :     gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT;
     851           0 :   } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_FILE
     852           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_FINI
     853           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_DONE
     854           0 :                      || snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_HTTP
     855           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_FINI
     856           0 :                      || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_DONE ) ) {
     857           0 :     gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
     858           0 :   }
     859             : 
     860             :   /* It's possible for the incremental snapshot phase to be skipped, or
     861             :      complete before we can sample it.  This ensures we always get at
     862             :      least one pass of the metrics. */
     863           0 :   if( FD_UNLIKELY( gui->summary.boot_progress.phase==FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP
     864           0 :                 && gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].reset_cnt==ULONG_MAX ) ) {
     865           0 :     gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
     866           0 :   }
     867             : 
     868           0 :   switch ( gui->summary.boot_progress.phase ) {
     869           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP: {
     870           0 :       gui->summary.boot_progress.joining_gossip_time_nanos = now;
     871           0 :       break;
     872           0 :     }
     873           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT:
     874           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT: {
     875           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 );
     876           0 :       ulong _retry_cnt = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_DOWNLOAD_RETRIES ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_DOWNLOAD_RETRIES ) ]);
     877             : 
     878             :       /* reset boot state if necessary */
     879           0 :       if( FD_UNLIKELY( gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt!=_retry_cnt ) ) {
     880           0 :         gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_time_nanos = now;
     881           0 :         gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt = _retry_cnt;
     882           0 :       }
     883             : 
     884           0 :       ulong _total_bytes                   = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_BYTES_TOTAL ) ],                snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_BYTES_TOTAL ) ]                );
     885           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 ) ]                 );
     886           0 :       ulong _decompress_decompressed_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapdc_metrics[ MIDX( GAUGE, SNAPDC, FULL_DECOMPRESSED_BYTES_WRITTEN ) ], snapdc_metrics[ MIDX( GAUGE, SNAPDC, INCREMENTAL_DECOMPRESSED_BYTES_WRITTEN ) ] );
     887           0 :       ulong _decompress_compressed_bytes   = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapdc_metrics[ MIDX( GAUGE, SNAPDC, FULL_COMPRESSED_BYTES_READ ) ],      snapdc_metrics[ MIDX( GAUGE, SNAPDC, INCREMENTAL_COMPRESSED_BYTES_READ ) ]      );
     888           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 ) ]                 );
     889           0 :       ulong _insert_accounts               = snapin_metrics[ MIDX( GAUGE, SNAPIN, ACCOUNTS_LOADED ) ];
     890             : 
     891             :       /* metadata */
     892           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].total_bytes_compressed = _total_bytes;
     893           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].sample_time_nanos = now;
     894             : 
     895             :       /* read stage */
     896           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_bytes_compressed = _read_bytes;
     897             : 
     898             :       /* decompress stage */
     899           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_compressed   = _decompress_compressed_bytes;
     900           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_decompressed = _decompress_decompressed_bytes;
     901             : 
     902             :       /* insert stage */
     903           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_bytes_decompressed = _insert_bytes;
     904             : 
     905             :       /* Use the latest compression ratio to estimate decompressed size */
     906           0 :       gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_accounts_current = _insert_accounts;
     907             : 
     908           0 :       break;
     909           0 :     }
     910           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY: {
     911           0 :       gui->summary.boot_progress.wfs_total_stake     = gossip_metrics[ MIDX( GAUGE, GOSSIP, WFS_STAKE_TOTAL ) ];
     912           0 :       gui->summary.boot_progress.wfs_connected_stake = gossip_metrics[ MIDX( GAUGE, GOSSIP, WFS_STAKE_ONLINE ) ];
     913           0 :       gui->summary.boot_progress.wfs_total_peers     = gossip_metrics[ MIDX( GAUGE, GOSSIP, WFS_STAKED_PEERS_TOTAL ) ];
     914           0 :       gui->summary.boot_progress.wfs_connected_peers = gossip_metrics[ MIDX( GAUGE, GOSSIP, WFS_STAKED_PEERS_ONLINE ) ];
     915           0 :       break;
     916           0 :     }
     917           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP: {
     918           0 :       gui->summary.boot_progress.catching_up_time_nanos = now;
     919           0 :       break;
     920           0 :     }
     921           0 :     case FD_GUI_BOOT_PROGRESS_TYPE_RUNNING: break;
     922           0 :     default: FD_LOG_ERR(( "unknown boot progress phase: %d", gui->summary.boot_progress.phase ));
     923           0 :   }
     924           0 : }
     925             : 
     926             : static inline int
     927           0 : fd_gui_ephemeral_slots_contains( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot ) {
     928           0 :   for( ulong i=0UL; i<slots_sz; i++ ) {
     929           0 :     if( FD_UNLIKELY( slots[ i ].slot==ULONG_MAX ) ) break;
     930           0 :     if( FD_UNLIKELY( slots[ i ].slot==slot ) ) return 1;
     931           0 :   }
     932           0 :   return 0;
     933           0 : }
     934             : 
     935             : #define SORT_NAME fd_gui_ephemeral_slot_sort
     936           0 : #define SORT_KEY_T fd_gui_ephemeral_slot_t
     937           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 ) ) )
     938             : #include "../../util/tmpl/fd_sort.c"
     939             : 
     940             : static inline void
     941           0 : fd_gui_try_insert_ephemeral_slot( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot, long now ) {
     942           0 :   int already_present = 0;
     943           0 :   for( ulong i=0UL; i<slots_sz; i++ ) {
     944             :     /* evict any slots older than 4.8 seconds */
     945           0 :     if( FD_UNLIKELY( slots[ i ].slot!=ULONG_MAX && now-slots[ i ].timestamp_arrival_nanos>4800000000L ) ) {
     946           0 :       slots[ i ].slot = ULONG_MAX;
     947           0 :       continue;
     948           0 :     }
     949             : 
     950             :     /* if we've already seen this slot, just update the timestamp */
     951           0 :     if( FD_UNLIKELY( slots[ i ].slot==slot ) ) {
     952           0 :       slots[ i ].timestamp_arrival_nanos = now;
     953           0 :       already_present = 1;
     954           0 :     }
     955           0 :   }
     956           0 :   if( FD_LIKELY( already_present ) ) return;
     957             : 
     958             :   /* Insert the new slot number, evicting a smaller slot if necessary */
     959           0 :   slots[ slots_sz ].timestamp_arrival_nanos = now;
     960           0 :   slots[ slots_sz ].slot = slot;
     961           0 :   fd_gui_ephemeral_slot_sort_insert( slots, slots_sz+1UL );
     962           0 : }
     963             : 
     964             : static inline void
     965           0 : fd_gui_try_insert_run_length_slot( ulong * slots, ulong capacity, ulong * slots_sz, ulong slot ) {
     966             :   /* catch up history is run-length encoded */
     967           0 :   ulong range_idx = fd_sort_up_ulong_split( slots, *slots_sz, slot );
     968           0 :   if( FD_UNLIKELY( range_idx<(*slots_sz)-1UL              && range_idx%2UL==0UL && slots[ range_idx ]<=slot && slots[ range_idx+1UL ]>=slot ) ) return;
     969           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;
     970             : 
     971           0 :   slots[ (*slots_sz)++ ] = slot;
     972           0 :   slots[ (*slots_sz)++ ] = slot;
     973             : 
     974           0 :   fd_sort_up_ulong_insert( slots, (*slots_sz) );
     975             : 
     976             :   /* colesce ranges */
     977           0 :   ulong removed = 0UL;
     978           0 :   for( ulong i=1UL; i<(*slots_sz)-1UL; i+=2 ) {
     979           0 :     if( FD_UNLIKELY( slots[ i ]+1UL==slots[ i+1UL ] ) ) {
     980           0 :       slots[ i ]     = ULONG_MAX;
     981           0 :       slots[ i+1UL ] = ULONG_MAX;
     982           0 :       removed += 2;
     983           0 :     }
     984           0 :   }
     985             : 
     986           0 :   if( FD_UNLIKELY( (*slots_sz)>=removed+capacity-2UL && (*slots_sz)>=4UL ) ) {
     987             :     /* We are at capacity, start coalescing earlier intervals. */
     988           0 :     slots[ 1 ] = ULONG_MAX;
     989           0 :     slots[ 2 ] = ULONG_MAX;
     990           0 :     removed += 2;
     991           0 :   }
     992             : 
     993           0 :   fd_sort_up_ulong_insert( slots, (*slots_sz) );
     994           0 :   (*slots_sz) -= removed;
     995           0 : }
     996             : 
     997             : void
     998           0 : fd_gui_handle_repair_slot( fd_gui_t * gui, ulong slot, long now ) {
     999           0 :   int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot );
    1000           0 :   fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot, now );
    1001             : 
    1002           0 :   if( FD_UNLIKELY( !was_sent && slot!=gui->summary.slot_repair ) ) {
    1003           0 :     gui->summary.slot_repair = slot;
    1004             : 
    1005           0 :     fd_gui_printf_repair_slot( gui );
    1006           0 :     fd_http_server_ws_broadcast( gui->http );
    1007             : 
    1008           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 );
    1009           0 :   }
    1010           0 : }
    1011             : 
    1012             : void
    1013           0 : fd_gui_handle_repair_request( fd_gui_t * gui, ulong slot, ulong shred_idx, long now ) {
    1014           0 :   fd_gui_slot_staged_shred_event_t * recv_event = fd_gui_staged_push( gui );
    1015           0 :   recv_event->timestamp = now;
    1016           0 :   recv_event->shred_idx = (ushort)shred_idx;
    1017           0 :   recv_event->slot      = slot;
    1018           0 :   recv_event->event     = FD_GUI_SLOT_SHRED_REPAIR_REQUEST;
    1019           0 : }
    1020             : 
    1021             : static void
    1022           0 : fd_gui_progcache_sample( fd_gui_t * gui ) {
    1023           0 :   fd_topo_t const * topo = gui->topo;
    1024             : 
    1025           0 :   ulong hits    = 0UL;
    1026           0 :   ulong lookups = 0UL;
    1027             : 
    1028           0 :   for( ulong i=0UL; i<gui->summary.execrp_tile_cnt; i++ ) {
    1029           0 :     fd_topo_tile_t const * execrp = &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ];
    1030           0 :     volatile ulong const * metrics = fd_metrics_tile( execrp->metrics );
    1031             : 
    1032           0 :     lookups += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_LOOKUPS ) ];
    1033           0 :     hits    += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_HITS    ) ];
    1034           0 :   }
    1035             : 
    1036             :   /* The execrp tile writes lookups before hits in metrics_write, so
    1037             :      reading lookups first then hits here means we may observe the
    1038             :      new hits before the new lookups, giving hits > lookups
    1039             :      momentarily.  Clamp to maintain the invariant hits <= lookups. */
    1040             : 
    1041           0 :   hits = fd_ulong_min( hits, lookups );
    1042             : 
    1043           0 :   ulong ring_idx       = gui->summary.progcache_history_idx % FD_GUI_PROGCACHE_HISTORY_CNT;
    1044           0 :   ulong oldest_hits    = gui->summary.progcache_hits_history   [ ring_idx ];
    1045           0 :   ulong oldest_lookups = gui->summary.progcache_lookups_history[ ring_idx ];
    1046             : 
    1047           0 :   gui->summary.progcache_hits_history   [ ring_idx ] = hits;
    1048           0 :   gui->summary.progcache_lookups_history[ ring_idx ] = lookups;
    1049           0 :   gui->summary.progcache_history_idx = gui->summary.progcache_history_idx + 1UL;
    1050             : 
    1051           0 :   ulong hits_1min    = hits    - oldest_hits;
    1052           0 :   ulong lookups_1min = lookups - oldest_lookups;
    1053           0 :   hits_1min = fd_ulong_min( hits_1min, lookups_1min );
    1054             : 
    1055           0 :   gui->summary.progcache_hits_1min    = hits_1min;
    1056           0 :   gui->summary.progcache_lookups_1min = lookups_1min;
    1057           0 : }
    1058             : 
    1059             : int
    1060           0 : fd_gui_poll( fd_gui_t * gui, long now ) {
    1061           0 :   if( FD_LIKELY( now>gui->next_sample_400millis ) ) {
    1062           0 :     fd_gui_estimated_tps_snap( gui );
    1063           0 :     fd_gui_printf_estimated_tps( gui );
    1064           0 :     fd_http_server_ws_broadcast( gui->http );
    1065             : 
    1066           0 :     gui->next_sample_400millis += 400L*1000L*1000L;
    1067           0 :     return 1;
    1068           0 :   }
    1069             : 
    1070           0 :   if( FD_LIKELY( now>gui->next_sample_100millis ) ) {
    1071           0 :     fd_gui_txn_waterfall_snap( gui, gui->summary.txn_waterfall_current );
    1072           0 :     fd_gui_printf_live_txn_waterfall( gui, gui->summary.txn_waterfall_reference, gui->summary.txn_waterfall_current, 0UL /* TODO: REAL NEXT LEADER SLOT */ );
    1073           0 :     fd_http_server_ws_broadcast( gui->http );
    1074             : 
    1075           0 :     fd_gui_network_stats_snap( gui, gui->summary.network_stats_current );
    1076           0 :     fd_gui_printf_live_network_metrics( gui, gui->summary.network_stats_current );
    1077           0 :     fd_http_server_ws_broadcast( gui->http );
    1078             : 
    1079           0 :     *gui->summary.tile_stats_reference = *gui->summary.tile_stats_current;
    1080           0 :     fd_gui_tile_stats_snap( gui, gui->summary.txn_waterfall_current, gui->summary.tile_stats_current, now );
    1081           0 :     fd_gui_printf_live_tile_stats( gui, gui->summary.tile_stats_reference, gui->summary.tile_stats_current );
    1082           0 :     fd_http_server_ws_broadcast( gui->http );
    1083             : 
    1084           0 :     if( FD_LIKELY( gui->summary.is_full_client ) ) {
    1085           0 :       fd_gui_progcache_sample( gui );
    1086           0 :       fd_gui_printf_live_program_cache( gui );
    1087           0 :       fd_http_server_ws_broadcast( gui->http );
    1088           0 :     }
    1089             : 
    1090           0 :     if( FD_UNLIKELY( gui->summary.is_full_client && gui->summary.boot_progress.phase!=FD_GUI_BOOT_PROGRESS_TYPE_RUNNING ) ) {
    1091           0 :       fd_gui_run_boot_progress( gui, now );
    1092           0 :       fd_gui_printf_boot_progress( gui );
    1093           0 :       fd_http_server_ws_broadcast( gui->http );
    1094           0 :     }
    1095             : 
    1096           0 :     ulong bundle_tile_idx = fd_topo_find_tile( gui->topo, "bundle", 0UL );
    1097           0 :     if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
    1098           0 :       volatile ulong const * bundle_metrics = fd_metrics_tile( gui->topo->tiles[ bundle_tile_idx ].metrics );
    1099           0 :       int cur_state = (int)bundle_metrics[ MIDX( GAUGE, BUNDLE, STATE ) ];
    1100           0 :       if( FD_UNLIKELY( cur_state != gui->block_engine.status ) ) {
    1101           0 :         gui->block_engine.status = cur_state;
    1102           0 :         fd_gui_printf_block_engine( gui );
    1103           0 :         fd_http_server_ws_broadcast( gui->http );
    1104           0 :       }
    1105           0 :     }
    1106             : 
    1107           0 :     gui->next_sample_100millis += 100L*1000L*1000L;
    1108           0 :     return 1;
    1109           0 :   }
    1110             : 
    1111           0 :   if( FD_LIKELY( now>gui->next_sample_50millis ) ) {
    1112           0 :     if( FD_LIKELY( gui->summary.is_full_client && gui->shreds.staged_next_broadcast<gui->shreds.staged_tail ) ) {
    1113           0 :       fd_gui_printf_shred_updates( gui );
    1114           0 :       fd_http_server_ws_broadcast( gui->http );
    1115           0 :       gui->shreds.staged_next_broadcast = gui->shreds.staged_tail;
    1116           0 :     }
    1117             : 
    1118             :     /* We get the repair slot from the sampled metric after catching up
    1119             :        and from incoming shred data before catchup. This makes the
    1120             :        catchup progress bar look complete while also keeping the
    1121             :        overview slots vis correct.  TODO: do this properly using frags
    1122             :        sent over a link */
    1123           0 :     if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
    1124           0 :       fd_topo_tile_t * repair = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "repair", 0UL ) ];
    1125           0 :       volatile ulong const * repair_metrics = fd_metrics_tile( repair->metrics );
    1126           0 :       ulong slot = repair_metrics[ MIDX( COUNTER, REPAIR, REPAIRED_SLOTS ) ];
    1127           0 :       fd_gui_handle_repair_slot( gui, slot, now );
    1128           0 :     }
    1129             : 
    1130           0 :     gui->next_sample_50millis += 50L*1000L*1000L;
    1131           0 :     return 1;
    1132           0 :   }
    1133             : 
    1134           0 :   if( FD_LIKELY( now>gui->next_sample_25millis ) ) {
    1135           0 :     fd_gui_tile_timers_snap( gui );
    1136             : 
    1137           0 :     fd_gui_printf_live_tile_timers( gui );
    1138           0 :     fd_http_server_ws_broadcast( gui->http );
    1139             : 
    1140           0 :     fd_gui_printf_live_tile_metrics( gui );
    1141           0 :     fd_http_server_ws_broadcast( gui->http );
    1142             : 
    1143           0 :     gui->next_sample_25millis += (long)(25*1000L*1000L);
    1144           0 :     return 1;
    1145           0 :   }
    1146             : 
    1147             : 
    1148           0 :   if( FD_LIKELY( now>gui->next_sample_10millis ) ) {
    1149           0 :     fd_gui_scheduler_counts_snap( gui, now );
    1150             : 
    1151           0 :     fd_gui_printf_server_time_nanos( gui, now );
    1152           0 :     fd_http_server_ws_broadcast( gui->http );
    1153             : 
    1154           0 :     gui->next_sample_10millis += 10L*1000L*1000L;
    1155           0 :     return 1;
    1156           0 :   }
    1157             : 
    1158           0 :   return 0;
    1159           0 : }
    1160             : 
    1161             : static void
    1162             : fd_gui_handle_gossip_update( fd_gui_t *    gui,
    1163           0 :                              uchar const * msg ) {
    1164             :   /* `gui->gossip.peer_cnt` is guaranteed to be in [0, FD_GUI_MAX_PEER_CNT], because
    1165             :   `peer_cnt` is FD_TEST-ed to be less than or equal FD_GUI_MAX_PEER_CNT.
    1166             :   For every new peer that is added an existing peer will be removed or was still free.
    1167             :   And adding a new peer is done at most `peer_cnt` times. */
    1168           0 :   ulong peer_cnt = FD_LOAD( ulong, msg );
    1169             : 
    1170           0 :   FD_TEST( peer_cnt<=FD_GUI_MAX_PEER_CNT );
    1171             : 
    1172           0 :   ulong added_cnt = 0UL;
    1173           0 :   ulong added[ FD_GUI_MAX_PEER_CNT ] = {0};
    1174             : 
    1175           0 :   ulong update_cnt = 0UL;
    1176           0 :   ulong updated[ FD_GUI_MAX_PEER_CNT ] = {0};
    1177             : 
    1178           0 :   ulong removed_cnt = 0UL;
    1179           0 :   fd_pubkey_t removed[ FD_GUI_MAX_PEER_CNT ] = {0};
    1180             : 
    1181           0 :   uchar const * data = msg + sizeof(ulong);
    1182           0 :   for( ulong i=0UL; i<gui->gossip.peer_cnt; i++ ) {
    1183           0 :     int found = 0;
    1184           0 :     for( ulong j=0UL; j<peer_cnt; j++ ) {
    1185           0 :       if( FD_UNLIKELY( !memcmp( gui->gossip.peers[ i ].pubkey, data+j*(58UL+12UL*6UL), 32UL ) ) ) {
    1186           0 :         found = 1;
    1187           0 :         break;
    1188           0 :       }
    1189           0 :     }
    1190             : 
    1191           0 :     if( FD_UNLIKELY( !found ) ) {
    1192           0 :       fd_memcpy( removed[ removed_cnt++ ].uc, gui->gossip.peers[ i ].pubkey->uc, 32UL );
    1193           0 :       if( FD_LIKELY( i+1UL!=gui->gossip.peer_cnt ) ) {
    1194           0 :         gui->gossip.peers[ i ] = gui->gossip.peers[ gui->gossip.peer_cnt-1UL ];
    1195           0 :         i--;
    1196           0 :       }
    1197           0 :       gui->gossip.peer_cnt--;
    1198           0 :     }
    1199           0 :   }
    1200             : 
    1201           0 :   ulong before_peer_cnt = gui->gossip.peer_cnt;
    1202           0 :   for( ulong i=0UL; i<peer_cnt; i++ ) {
    1203           0 :     int found = 0;
    1204           0 :     ulong found_idx = 0;
    1205           0 :     for( ulong j=0UL; j<gui->gossip.peer_cnt; j++ ) {
    1206           0 :       if( FD_UNLIKELY( !memcmp( gui->gossip.peers[ j ].pubkey, data+i*(58UL+12UL*6UL), 32UL ) ) ) {
    1207           0 :         found_idx = j;
    1208           0 :         found = 1;
    1209           0 :         break;
    1210           0 :       }
    1211           0 :     }
    1212             : 
    1213           0 :     if( FD_UNLIKELY( !found ) ) {
    1214           0 :       fd_memcpy( gui->gossip.peers[ gui->gossip.peer_cnt ].pubkey->uc, data+i*(58UL+12UL*6UL), 32UL );
    1215           0 :       gui->gossip.peers[ gui->gossip.peer_cnt ].wallclock = FD_LOAD( ulong, data+i*(58UL+12UL*6UL)+32UL );
    1216           0 :       gui->gossip.peers[ gui->gossip.peer_cnt ].shred_version = FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+40UL );
    1217           0 :       gui->gossip.peers[ gui->gossip.peer_cnt ].has_version = FD_LOAD( uchar, data+i*(58UL+12UL*6UL)+42UL );
    1218           0 :       if( FD_LIKELY( gui->gossip.peers[ gui->gossip.peer_cnt ].has_version ) ) {
    1219           0 :         gui->gossip.peers[ gui->gossip.peer_cnt ].version.major = FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+43UL );
    1220           0 :         gui->gossip.peers[ gui->gossip.peer_cnt ].version.minor = FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+45UL );
    1221           0 :         gui->gossip.peers[ gui->gossip.peer_cnt ].version.patch = FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+47UL );
    1222           0 :         gui->gossip.peers[ gui->gossip.peer_cnt ].version.has_commit = FD_LOAD( uchar, data+i*(58UL+12UL*6UL)+49UL );
    1223           0 :         if( FD_LIKELY( gui->gossip.peers[ gui->gossip.peer_cnt ].version.has_commit ) ) {
    1224           0 :           gui->gossip.peers[ gui->gossip.peer_cnt ].version.commit = FD_LOAD( uint, data+i*(58UL+12UL*6UL)+50UL );
    1225           0 :         }
    1226           0 :         gui->gossip.peers[ gui->gossip.peer_cnt ].version.feature_set = FD_LOAD( uint, data+i*(58UL+12UL*6UL)+54UL );
    1227           0 :       }
    1228             : 
    1229           0 :       for( ulong j=0UL; j<12UL; j++ ) {
    1230           0 :         gui->gossip.peers[ gui->gossip.peer_cnt ].sockets[ j ].ipv4 = FD_LOAD( uint, data+i*(58UL+12UL*6UL)+58UL+j*6UL );
    1231           0 :         gui->gossip.peers[ gui->gossip.peer_cnt ].sockets[ j ].port = FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+58UL+j*6UL+4UL );
    1232           0 :       }
    1233             : 
    1234           0 :       gui->gossip.peer_cnt++;
    1235           0 :     } else {
    1236           0 :       int peer_updated = gui->gossip.peers[ found_idx ].shred_version!=FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+40UL ) ||
    1237             :                          // gui->gossip.peers[ found_idx ].wallclock!=FD_LOAD( ulong, data+i*(58UL+12UL*6UL)+32UL ) ||
    1238           0 :                          gui->gossip.peers[ found_idx ].has_version!=FD_LOAD( uchar, data+i*(58UL+12UL*6UL)+42UL );
    1239             : 
    1240           0 :       if( FD_LIKELY( !peer_updated && gui->gossip.peers[ found_idx ].has_version ) ) {
    1241           0 :         peer_updated = gui->gossip.peers[ found_idx ].version.major!=FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+43UL ) ||
    1242           0 :                         gui->gossip.peers[ found_idx ].version.minor!=FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+45UL ) ||
    1243           0 :                         gui->gossip.peers[ found_idx ].version.patch!=FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+47UL ) ||
    1244           0 :                         gui->gossip.peers[ found_idx ].version.has_commit!=FD_LOAD( uchar, data+i*(58UL+12UL*6UL)+49UL ) ||
    1245           0 :                         (gui->gossip.peers[ found_idx ].version.has_commit && gui->gossip.peers[ found_idx ].version.commit!=FD_LOAD( uint, data+i*(58UL+12UL*6UL)+50UL )) ||
    1246           0 :                         gui->gossip.peers[ found_idx ].version.feature_set!=FD_LOAD( uint, data+i*(58UL+12UL*6UL)+54UL );
    1247           0 :       }
    1248             : 
    1249           0 :       if( FD_LIKELY( !peer_updated ) ) {
    1250           0 :         for( ulong j=0UL; j<12UL; j++ ) {
    1251           0 :           peer_updated = gui->gossip.peers[ found_idx ].sockets[ j ].ipv4!=FD_LOAD( uint, data+i*(58UL+12UL*6UL)+58UL+j*6UL ) ||
    1252           0 :                           gui->gossip.peers[ found_idx ].sockets[ j ].port!=FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+58UL+j*6UL+4UL );
    1253           0 :           if( FD_LIKELY( peer_updated ) ) break;
    1254           0 :         }
    1255           0 :       }
    1256             : 
    1257           0 :       if( FD_UNLIKELY( peer_updated ) ) {
    1258           0 :         updated[ update_cnt++ ] = found_idx;
    1259           0 :         gui->gossip.peers[ found_idx ].shred_version = FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+40UL );
    1260           0 :         gui->gossip.peers[ found_idx ].wallclock = FD_LOAD( ulong, data+i*(58UL+12UL*6UL)+32UL );
    1261           0 :         gui->gossip.peers[ found_idx ].has_version = FD_LOAD( uchar, data+i*(58UL+12UL*6UL)+42UL );
    1262           0 :         if( FD_LIKELY( gui->gossip.peers[ found_idx ].has_version ) ) {
    1263           0 :           gui->gossip.peers[ found_idx ].version.major = FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+43UL );
    1264           0 :           gui->gossip.peers[ found_idx ].version.minor = FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+45UL );
    1265           0 :           gui->gossip.peers[ found_idx ].version.patch = FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+47UL );
    1266           0 :           gui->gossip.peers[ found_idx ].version.has_commit = FD_LOAD( uchar, data+i*(58UL+12UL*6UL)+49UL );
    1267           0 :           if( FD_LIKELY( gui->gossip.peers[ found_idx ].version.has_commit ) ) {
    1268           0 :             gui->gossip.peers[ found_idx ].version.commit = FD_LOAD( uint, data+i*(58UL+12UL*6UL)+50UL );
    1269           0 :           }
    1270           0 :           gui->gossip.peers[ found_idx ].version.feature_set = FD_LOAD( uint, data+i*(58UL+12UL*6UL)+54UL );
    1271           0 :         }
    1272             : 
    1273           0 :         for( ulong j=0UL; j<12UL; j++ ) {
    1274           0 :           gui->gossip.peers[ found_idx ].sockets[ j ].ipv4 = FD_LOAD( uint, data+i*(58UL+12UL*6UL)+58UL+j*6UL );
    1275           0 :           gui->gossip.peers[ found_idx ].sockets[ j ].port = FD_LOAD( ushort, data+i*(58UL+12UL*6UL)+58UL+j*6UL+4UL );
    1276           0 :         }
    1277           0 :       }
    1278           0 :     }
    1279           0 :   }
    1280             : 
    1281           0 :   added_cnt = gui->gossip.peer_cnt - before_peer_cnt;
    1282           0 :   for( ulong i=before_peer_cnt; i<gui->gossip.peer_cnt; i++ ) added[ i-before_peer_cnt ] = i;
    1283             : 
    1284           0 :   fd_gui_printf_peers_gossip_update( gui, updated, update_cnt, removed, removed_cnt, added, added_cnt );
    1285           0 :   fd_http_server_ws_broadcast( gui->http );
    1286           0 : }
    1287             : 
    1288             : static void
    1289             : fd_gui_handle_vote_account_update( fd_gui_t *    gui,
    1290           0 :                                    uchar const * msg ) {
    1291             :   /* See fd_gui_handle_gossip_update for why `gui->vote_account.vote_account_cnt`
    1292             :   is guaranteed to be in [0, FD_GUI_MAX_PEER_CNT]. */
    1293           0 :   ulong peer_cnt = FD_LOAD( ulong, msg );
    1294             : 
    1295           0 :   FD_TEST( peer_cnt<=FD_GUI_MAX_PEER_CNT );
    1296             : 
    1297           0 :   ulong added_cnt = 0UL;
    1298           0 :   ulong added[ FD_GUI_MAX_PEER_CNT ] = {0};
    1299             : 
    1300           0 :   ulong update_cnt = 0UL;
    1301           0 :   ulong updated[ FD_GUI_MAX_PEER_CNT ] = {0};
    1302             : 
    1303           0 :   ulong removed_cnt = 0UL;
    1304           0 :   fd_pubkey_t removed[ FD_GUI_MAX_PEER_CNT ] = {0};
    1305             : 
    1306           0 :   uchar const * data = msg + sizeof(ulong);
    1307           0 :   for( ulong i=0UL; i<gui->vote_account.vote_account_cnt; i++ ) {
    1308           0 :     int found = 0;
    1309           0 :     for( ulong j=0UL; j<peer_cnt; j++ ) {
    1310           0 :       if( FD_UNLIKELY( !memcmp( gui->vote_account.vote_accounts[ i ].vote_account, data+j*112UL, 32UL ) ) ) {
    1311           0 :         found = 1;
    1312           0 :         break;
    1313           0 :       }
    1314           0 :     }
    1315             : 
    1316           0 :     if( FD_UNLIKELY( !found ) ) {
    1317           0 :       fd_memcpy( removed[ removed_cnt++ ].uc, gui->vote_account.vote_accounts[ i ].vote_account->uc, 32UL );
    1318           0 :       if( FD_LIKELY( i+1UL!=gui->vote_account.vote_account_cnt ) ) {
    1319           0 :         gui->vote_account.vote_accounts[ i ] = gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt-1UL ];
    1320           0 :         i--;
    1321           0 :       }
    1322           0 :       gui->vote_account.vote_account_cnt--;
    1323           0 :     }
    1324           0 :   }
    1325             : 
    1326           0 :   ulong before_peer_cnt = gui->vote_account.vote_account_cnt;
    1327           0 :   for( ulong i=0UL; i<peer_cnt; i++ ) {
    1328           0 :     int found = 0;
    1329           0 :     ulong found_idx;
    1330           0 :     for( ulong j=0UL; j<gui->vote_account.vote_account_cnt; j++ ) {
    1331           0 :       if( FD_UNLIKELY( !memcmp( gui->vote_account.vote_accounts[ j ].vote_account, data+i*112UL, 32UL ) ) ) {
    1332           0 :         found_idx = j;
    1333           0 :         found = 1;
    1334           0 :         break;
    1335           0 :       }
    1336           0 :     }
    1337             : 
    1338           0 :     if( FD_UNLIKELY( !found ) ) {
    1339           0 :       fd_memcpy( gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].vote_account->uc, data+i*112UL, 32UL );
    1340           0 :       fd_memcpy( gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].pubkey->uc, data+i*112UL+32UL, 32UL );
    1341             : 
    1342           0 :       gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].activated_stake = FD_LOAD( ulong, data+i*112UL+64UL );
    1343           0 :       gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].last_vote = FD_LOAD( ulong, data+i*112UL+72UL );
    1344           0 :       gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].root_slot = FD_LOAD( ulong, data+i*112UL+80UL );
    1345           0 :       gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].epoch_credits = FD_LOAD( ulong, data+i*112UL+88UL );
    1346           0 :       gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].commission = FD_LOAD( uchar, data+i*112UL+96UL );
    1347           0 :       gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].delinquent = FD_LOAD( uchar, data+i*112UL+97UL );
    1348             : 
    1349           0 :       gui->vote_account.vote_account_cnt++;
    1350           0 :     } else {
    1351           0 :       int peer_updated =
    1352           0 :         memcmp( gui->vote_account.vote_accounts[ found_idx ].pubkey->uc, data+i*112UL+32UL, 32UL ) ||
    1353           0 :         gui->vote_account.vote_accounts[ found_idx ].activated_stake != FD_LOAD( ulong, data+i*112UL+64UL ) ||
    1354             :         // gui->vote_account.vote_accounts[ found_idx ].last_vote       != FD_LOAD( ulong, data+i*112UL+72UL ) ||
    1355             :         // gui->vote_account.vote_accounts[ found_idx ].root_slot       != FD_LOAD( ulong, data+i*112UL+80UL ) ||
    1356             :         // gui->vote_account.vote_accounts[ found_idx ].epoch_credits   != FD_LOAD( ulong, data+i*112UL+88UL ) ||
    1357           0 :         gui->vote_account.vote_accounts[ found_idx ].commission      != FD_LOAD( uchar, data+i*112UL+96UL ) ||
    1358           0 :         gui->vote_account.vote_accounts[ found_idx ].delinquent      != FD_LOAD( uchar, data+i*112UL+97UL );
    1359             : 
    1360           0 :       if( FD_UNLIKELY( peer_updated ) ) {
    1361           0 :         updated[ update_cnt++ ] = found_idx;
    1362             : 
    1363           0 :         fd_memcpy( gui->vote_account.vote_accounts[ found_idx ].pubkey->uc, data+i*112UL+32UL, 32UL );
    1364           0 :         gui->vote_account.vote_accounts[ found_idx ].activated_stake = FD_LOAD( ulong, data+i*112UL+64UL );
    1365           0 :         gui->vote_account.vote_accounts[ found_idx ].last_vote = FD_LOAD( ulong, data+i*112UL+72UL );
    1366           0 :         gui->vote_account.vote_accounts[ found_idx ].root_slot = FD_LOAD( ulong, data+i*112UL+80UL );
    1367           0 :         gui->vote_account.vote_accounts[ found_idx ].epoch_credits = FD_LOAD( ulong, data+i*112UL+88UL );
    1368           0 :         gui->vote_account.vote_accounts[ found_idx ].commission = FD_LOAD( uchar, data+i*112UL+96UL );
    1369           0 :         gui->vote_account.vote_accounts[ found_idx ].delinquent = FD_LOAD( uchar, data+i*112UL+97UL );
    1370           0 :       }
    1371           0 :     }
    1372           0 :   }
    1373             : 
    1374           0 :   added_cnt = gui->vote_account.vote_account_cnt - before_peer_cnt;
    1375           0 :   for( ulong i=before_peer_cnt; i<gui->vote_account.vote_account_cnt; i++ ) added[ i-before_peer_cnt ] = i;
    1376             : 
    1377           0 :   fd_gui_printf_peers_vote_account_update( gui, updated, update_cnt, removed, removed_cnt, added, added_cnt );
    1378           0 :   fd_http_server_ws_broadcast( gui->http );
    1379           0 : }
    1380             : 
    1381             : static void
    1382             : fd_gui_handle_validator_info_update( fd_gui_t *    gui,
    1383           0 :                                      uchar const * msg ) {
    1384           0 :   if( FD_UNLIKELY( gui->validator_info.info_cnt == FD_GUI_MAX_PEER_CNT ) ) {
    1385           0 :     FD_LOG_DEBUG(("validator info cnt exceeds 108000 %lu, ignoring additional entries", gui->validator_info.info_cnt ));
    1386           0 :     return;
    1387           0 :   }
    1388           0 :   uchar const * data = (uchar const *)fd_type_pun_const( msg );
    1389             : 
    1390           0 :   ulong added_cnt = 0UL;
    1391           0 :   ulong added[ 1 ] = {0};
    1392             : 
    1393           0 :   ulong update_cnt = 0UL;
    1394           0 :   ulong updated[ 1 ] = {0};
    1395             : 
    1396           0 :   ulong removed_cnt = 0UL;
    1397             :   /* Unlike gossip or vote account updates, validator info messages come
    1398             :      in as info is discovered, and may contain as little as 1 validator
    1399             :      per message.  Therefore, it doesn't make sense to use the remove
    1400             :      mechanism.  */
    1401             : 
    1402           0 :   ulong before_peer_cnt = gui->validator_info.info_cnt;
    1403           0 :   int found = 0;
    1404           0 :   ulong found_idx;
    1405           0 :   for( ulong j=0UL; j<gui->validator_info.info_cnt; j++ ) {
    1406           0 :     if( FD_UNLIKELY( !memcmp( gui->validator_info.info[ j ].pubkey, data, 32UL ) ) ) {
    1407           0 :       found_idx = j;
    1408           0 :       found = 1;
    1409           0 :       break;
    1410           0 :     }
    1411           0 :   }
    1412             : 
    1413           0 :   if( FD_UNLIKELY( !found ) ) {
    1414           0 :     fd_memcpy( gui->validator_info.info[ gui->validator_info.info_cnt ].pubkey->uc, data, 32UL );
    1415             : 
    1416           0 :     strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].name, (char const *)(data+32UL), 64 );
    1417           0 :     gui->validator_info.info[ gui->validator_info.info_cnt ].name[ 63 ] = '\0';
    1418             : 
    1419           0 :     strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].website, (char const *)(data+96UL), 128 );
    1420           0 :     gui->validator_info.info[ gui->validator_info.info_cnt ].website[ 127 ] = '\0';
    1421             : 
    1422           0 :     strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].details, (char const *)(data+224UL), 256 );
    1423           0 :     gui->validator_info.info[ gui->validator_info.info_cnt ].details[ 255 ] = '\0';
    1424             : 
    1425           0 :     strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].icon_uri, (char const *)(data+480UL), 128 );
    1426           0 :     gui->validator_info.info[ gui->validator_info.info_cnt ].icon_uri[ 127 ] = '\0';
    1427             : 
    1428           0 :     gui->validator_info.info_cnt++;
    1429           0 :   } else {
    1430           0 :     int peer_updated =
    1431           0 :       memcmp( gui->validator_info.info[ found_idx ].pubkey->uc, data, 32UL ) ||
    1432           0 :       strncmp( gui->validator_info.info[ found_idx ].name, (char const *)(data+32UL), 64 ) ||
    1433           0 :       strncmp( gui->validator_info.info[ found_idx ].website, (char const *)(data+96UL), 128 ) ||
    1434           0 :       strncmp( gui->validator_info.info[ found_idx ].details, (char const *)(data+224UL), 256 ) ||
    1435           0 :       strncmp( gui->validator_info.info[ found_idx ].icon_uri, (char const *)(data+480UL), 128 );
    1436             : 
    1437           0 :     if( FD_UNLIKELY( peer_updated ) ) {
    1438           0 :       updated[ update_cnt++ ] = found_idx;
    1439             : 
    1440           0 :       fd_memcpy( gui->validator_info.info[ found_idx ].pubkey->uc, data, 32UL );
    1441             : 
    1442           0 :       strncpy( gui->validator_info.info[ found_idx ].name, (char const *)(data+32UL), 64 );
    1443           0 :       gui->validator_info.info[ found_idx ].name[ 63 ] = '\0';
    1444             : 
    1445           0 :       strncpy( gui->validator_info.info[ found_idx ].website, (char const *)(data+96UL), 128 );
    1446           0 :       gui->validator_info.info[ found_idx ].website[ 127 ] = '\0';
    1447             : 
    1448           0 :       strncpy( gui->validator_info.info[ found_idx ].details, (char const *)(data+224UL), 256 );
    1449           0 :       gui->validator_info.info[ found_idx ].details[ 255 ] = '\0';
    1450             : 
    1451           0 :       strncpy( gui->validator_info.info[ found_idx ].icon_uri, (char const *)(data+480UL), 128 );
    1452           0 :       gui->validator_info.info[ found_idx ].icon_uri[ 127 ] = '\0';
    1453           0 :     }
    1454           0 :   }
    1455             : 
    1456           0 :   added_cnt = gui->validator_info.info_cnt - before_peer_cnt;
    1457           0 :   for( ulong i=before_peer_cnt; i<gui->validator_info.info_cnt; i++ ) added[ i-before_peer_cnt ] = i;
    1458             : 
    1459           0 :   fd_gui_printf_peers_validator_info_update( gui, updated, update_cnt, NULL, removed_cnt, added, added_cnt );
    1460           0 :   fd_http_server_ws_broadcast( gui->http );
    1461           0 : }
    1462             : 
    1463             : int
    1464             : fd_gui_request_slot( fd_gui_t *    gui,
    1465             :                      ulong         ws_conn_id,
    1466             :                      ulong         request_id,
    1467           0 :                      cJSON const * params ) {
    1468           0 :   const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
    1469           0 :   if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1470             : 
    1471           0 :   ulong _slot = slot_param->valueulong;
    1472           0 :   fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
    1473           0 :   if( FD_UNLIKELY( !slot ) ) {
    1474           0 :     fd_gui_printf_null_query_response( gui->http, "slot", "query", request_id );
    1475           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1476           0 :     return 0;
    1477           0 :   }
    1478             : 
    1479           0 :   fd_gui_printf_slot_request( gui, _slot, request_id );
    1480           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1481           0 :   return 0;
    1482           0 : }
    1483             : 
    1484             : int
    1485             : fd_gui_request_slot_transactions( fd_gui_t *    gui,
    1486             :                                   ulong         ws_conn_id,
    1487             :                                   ulong         request_id,
    1488           0 :                                   cJSON const * params ) {
    1489           0 :   const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
    1490           0 :   if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1491             : 
    1492           0 :   ulong _slot = slot_param->valueulong;
    1493           0 :   fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
    1494           0 :   if( FD_UNLIKELY( !slot ) ) {
    1495           0 :     fd_gui_printf_null_query_response( gui->http, "slot", "query_transactions", request_id );
    1496           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1497           0 :     return 0;
    1498           0 :   }
    1499             : 
    1500           0 :   fd_gui_printf_slot_transactions_request( gui, _slot, request_id );
    1501           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1502           0 :   return 0;
    1503           0 : }
    1504             : 
    1505             : int
    1506             : fd_gui_request_slot_detailed( fd_gui_t *    gui,
    1507             :                               ulong         ws_conn_id,
    1508             :                               ulong         request_id,
    1509           0 :                               cJSON const * params ) {
    1510           0 :   const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
    1511           0 :   if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1512             : 
    1513           0 :   ulong _slot = slot_param->valueulong;
    1514           0 :   fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
    1515           0 :   if( FD_UNLIKELY( !slot ) ) {
    1516           0 :     fd_gui_printf_null_query_response( gui->http, "slot", "query_detailed", request_id );
    1517           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1518           0 :     return 0;
    1519           0 :   }
    1520             : 
    1521           0 :   fd_gui_printf_slot_request_detailed( gui, _slot, request_id );
    1522           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1523           0 :   return 0;
    1524           0 : }
    1525             : 
    1526             : static inline ulong
    1527           0 : fd_gui_slot_duration( fd_gui_t const * gui, fd_gui_slot_t const * cur ) {
    1528           0 :   fd_gui_slot_t const * prev = fd_gui_get_slot_const( gui, cur->slot-1UL );
    1529           0 :   if( FD_UNLIKELY( !prev ||
    1530           0 :                    prev->skipped ||
    1531           0 :                    prev->completed_time == LONG_MAX ||
    1532           0 :                    prev->slot != (cur->slot - 1UL) ||
    1533           0 :                    cur->skipped ||
    1534           0 :                    cur->completed_time == LONG_MAX ) ) return ULONG_MAX;
    1535             : 
    1536           0 :   return (ulong)(cur->completed_time - prev->completed_time);
    1537           0 : }
    1538             : 
    1539             : /* All rankings are initialized / reset to ULONG_MAX.  These sentinels
    1540             :    sort AFTER non-sentinel ranking entries.  Equal slots are sorted by
    1541             :    oldest slot AFTER.  Otherwise sort by value according to ranking
    1542             :    type. */
    1543             : #define SORT_NAME fd_gui_slot_ranking_sort
    1544           0 : #define SORT_KEY_T fd_gui_slot_ranking_t
    1545           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 ) ) ) )
    1546             : #include "../../util/tmpl/fd_sort.c"
    1547             : 
    1548             : static inline void
    1549             : fd_gui_try_insert_ranking( fd_gui_t               * gui,
    1550             :                            fd_gui_slot_rankings_t * rankings,
    1551           0 :                            fd_gui_slot_t const    * slot ) {
    1552             :   /* Rankings are inserted into an extra slot at the end of the ranking
    1553             :      array, then the array is sorted. */
    1554           0 : #define TRY_INSERT_SLOT( ranking_name, ranking_slot, ranking_value ) \
    1555           0 :   do { \
    1556           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 }; \
    1557           0 :     fd_gui_slot_ranking_sort_insert( rankings->FD_CONCAT2(largest_, ranking_name), FD_GUI_SLOT_RANKINGS_SZ+1UL ); \
    1558           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  }; \
    1559           0 :     fd_gui_slot_ranking_sort_insert( rankings->FD_CONCAT2(smallest_, ranking_name), FD_GUI_SLOT_RANKINGS_SZ+1UL ); \
    1560           0 :   } while (0)
    1561             : 
    1562           0 :     if( slot->skipped ) {
    1563           0 :       TRY_INSERT_SLOT( skipped, slot->slot, slot->slot );
    1564           0 :       return;
    1565           0 :     }
    1566             : 
    1567           0 :     ulong dur = fd_gui_slot_duration( gui, slot );
    1568           0 :     if( FD_LIKELY( dur!=ULONG_MAX ) ) TRY_INSERT_SLOT( duration, slot->slot, dur                         );
    1569           0 :     TRY_INSERT_SLOT( tips,           slot->slot, slot->tips                                              );
    1570           0 :     TRY_INSERT_SLOT( fees,           slot->slot, slot->priority_fee + slot->transaction_fee              );
    1571           0 :     TRY_INSERT_SLOT( rewards,        slot->slot, slot->tips + slot->priority_fee + slot->transaction_fee );
    1572           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 );
    1573           0 :     TRY_INSERT_SLOT( compute_units,  slot->slot, slot->compute_units                                     );
    1574           0 : #undef TRY_INSERT_SLOT
    1575           0 : }
    1576             : 
    1577             : static void
    1578           0 : fd_gui_update_slot_rankings( fd_gui_t * gui ) {
    1579           0 :   ulong first_replay_slot = ULONG_MAX;
    1580           0 :   if( FD_LIKELY( gui->summary.is_full_client ) ) {
    1581           0 :     ulong slot_caught_up   = gui->summary.slot_caught_up;
    1582           0 :     ulong slot_incremental = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].slot;
    1583           0 :     ulong slot_full        = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].slot;
    1584           0 :     first_replay_slot = fd_ulong_if( slot_caught_up!=ULONG_MAX, fd_ulong_if( slot_incremental!=ULONG_MAX, slot_incremental+1UL, fd_ulong_if( slot_full!=ULONG_MAX, slot_full+1UL, ULONG_MAX ) ), ULONG_MAX );
    1585           0 :   } else {
    1586           0 :     first_replay_slot = gui->summary.startup_progress.startup_ledger_max_slot;
    1587           0 :   }
    1588           0 :   if( FD_UNLIKELY( first_replay_slot==ULONG_MAX ) ) return;
    1589           0 :   if( FD_UNLIKELY( gui->summary.slot_rooted ==ULONG_MAX ) ) return;
    1590             : 
    1591           0 :   ulong epoch_idx = fd_gui_current_epoch_idx( gui );
    1592           0 :   if( FD_UNLIKELY( epoch_idx==ULONG_MAX ) ) return;
    1593             : 
    1594             :   /* No new slots since the last update */
    1595           0 :   if( FD_UNLIKELY( gui->epoch.epochs[ epoch_idx ].rankings_slot>gui->summary.slot_rooted ) ) return;
    1596             : 
    1597             :   /* Slots before first_replay_slot are unavailable. */
    1598           0 :   gui->epoch.epochs[ epoch_idx ].rankings_slot = fd_ulong_max( gui->epoch.epochs[ epoch_idx ].rankings_slot, first_replay_slot );
    1599             : 
    1600             :   /* Update the rankings. Only look through slots we haven't already. */
    1601           0 :   for( ulong s = gui->summary.slot_rooted; s>=gui->epoch.epochs[ epoch_idx ].rankings_slot; s--) {
    1602           0 :     fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, s );
    1603           0 :     if( FD_UNLIKELY( !slot ) ) break;
    1604             : 
    1605           0 :     fd_gui_try_insert_ranking( gui, gui->epoch.epochs[ epoch_idx ].rankings, slot );
    1606           0 :     if( FD_UNLIKELY( slot->mine ) ) fd_gui_try_insert_ranking( gui, gui->epoch.epochs[ epoch_idx ].my_rankings, slot );
    1607           0 :   }
    1608             : 
    1609           0 :   gui->epoch.epochs[ epoch_idx ].rankings_slot = gui->summary.slot_rooted + 1UL;
    1610           0 : }
    1611             : 
    1612             : int
    1613             : fd_gui_request_slot_rankings( fd_gui_t *    gui,
    1614             :                               ulong         ws_conn_id,
    1615             :                               ulong         request_id,
    1616           0 :                               cJSON const * params ) {
    1617           0 :   const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "mine" );
    1618           0 :   if( FD_UNLIKELY( !cJSON_IsBool( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1619             : 
    1620           0 :   int mine = !!(slot_param->type & cJSON_True);
    1621           0 :   fd_gui_update_slot_rankings( gui );
    1622           0 :   fd_gui_printf_slot_rankings_request( gui, request_id, mine );
    1623           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1624           0 :   return 0;
    1625           0 : }
    1626             : 
    1627             : int
    1628             : fd_gui_request_slot_shreds( fd_gui_t *    gui,
    1629             :                             ulong         ws_conn_id,
    1630             :                             ulong         request_id,
    1631           0 :                             cJSON const * params ) {
    1632           0 :   const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
    1633           0 :   if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1634             : 
    1635           0 :   ulong _slot = slot_param->valueulong;
    1636             : 
    1637           0 :   fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
    1638           0 :   if( FD_UNLIKELY( !slot || slot->shreds.start_offset==ULONG_MAX || slot->shreds.end_offset==ULONG_MAX || gui->shreds.history_tail >= slot->shreds.end_offset + FD_GUI_SHREDS_HISTORY_SZ ) ) {
    1639           0 :     fd_gui_printf_null_query_response( gui->http, "slot", "query_shreds", request_id );
    1640           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1641           0 :     return 0;
    1642           0 :   }
    1643             : 
    1644           0 :   fd_gui_printf_slot_query_shreds( gui, _slot, request_id );
    1645           0 :   FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1646           0 :   return 0;
    1647           0 : }
    1648             : 
    1649             : int
    1650             : fd_gui_ws_message( fd_gui_t *    gui,
    1651             :                    ulong         ws_conn_id,
    1652             :                    uchar const * data,
    1653           0 :                    ulong         data_len ) {
    1654             :   /* TODO: cJSON allocates, might fail SIGSYS due to brk(2)...
    1655             :      switch off this (or use wksp allocator) */
    1656           0 :   const char * parse_end;
    1657           0 :   cJSON * json = cJSON_ParseWithLengthOpts( (char *)data, data_len, &parse_end, 0 );
    1658           0 :   if( FD_UNLIKELY( !json ) ) {
    1659           0 :     return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1660           0 :   }
    1661             : 
    1662           0 :   const cJSON * node = cJSON_GetObjectItemCaseSensitive( json, "id" );
    1663           0 :   if( FD_UNLIKELY( !cJSON_IsNumber( node ) ) ) {
    1664           0 :     cJSON_Delete( json );
    1665           0 :     return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1666           0 :   }
    1667           0 :   ulong id = node->valueulong;
    1668             : 
    1669           0 :   const cJSON * topic = cJSON_GetObjectItemCaseSensitive( json, "topic" );
    1670           0 :   if( FD_UNLIKELY( !cJSON_IsString( topic ) || topic->valuestring==NULL ) ) {
    1671           0 :     cJSON_Delete( json );
    1672           0 :     return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1673           0 :   }
    1674             : 
    1675           0 :   const cJSON * key = cJSON_GetObjectItemCaseSensitive( json, "key" );
    1676           0 :   if( FD_UNLIKELY( !cJSON_IsString( key ) || key->valuestring==NULL ) ) {
    1677           0 :     cJSON_Delete( json );
    1678           0 :     return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1679           0 :   }
    1680             : 
    1681           0 :   if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query" ) ) ) {
    1682           0 :     const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
    1683           0 :     if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
    1684           0 :       cJSON_Delete( json );
    1685           0 :       return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1686           0 :     }
    1687             : 
    1688           0 :     int result = fd_gui_request_slot( gui, ws_conn_id, id, params );
    1689           0 :     cJSON_Delete( json );
    1690           0 :     return result;
    1691           0 :   } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_detailed" ) ) ) {
    1692           0 :     const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
    1693           0 :     if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
    1694           0 :       cJSON_Delete( json );
    1695           0 :       return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1696           0 :     }
    1697             : 
    1698           0 :     int result = fd_gui_request_slot_detailed( gui, ws_conn_id, id, params );
    1699           0 :     cJSON_Delete( json );
    1700           0 :     return result;
    1701           0 :   } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_transactions" ) ) ) {
    1702           0 :     const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
    1703           0 :     if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
    1704           0 :       cJSON_Delete( json );
    1705           0 :       return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1706           0 :     }
    1707             : 
    1708           0 :     int result = fd_gui_request_slot_transactions( gui, ws_conn_id, id, params );
    1709           0 :     cJSON_Delete( json );
    1710           0 :     return result;
    1711           0 :   } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_rankings" ) ) ) {
    1712           0 :     const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
    1713           0 :     if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
    1714           0 :       cJSON_Delete( json );
    1715           0 :       return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1716           0 :     }
    1717             : 
    1718           0 :     int result = fd_gui_request_slot_rankings( gui, ws_conn_id, id, params );
    1719           0 :     cJSON_Delete( json );
    1720           0 :     return result;
    1721           0 :   } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_shreds" ) ) ) {
    1722           0 :     const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
    1723           0 :     if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
    1724           0 :       cJSON_Delete( json );
    1725           0 :       return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
    1726           0 :     }
    1727             : 
    1728           0 :     int result = fd_gui_request_slot_shreds( gui, ws_conn_id, id, params );
    1729           0 :     cJSON_Delete( json );
    1730           0 :     return result;
    1731           0 :   } else if( FD_LIKELY( !strcmp( topic->valuestring, "summary" ) && !strcmp( key->valuestring, "ping" ) ) ) {
    1732           0 :     fd_gui_printf_summary_ping( gui, id );
    1733           0 :     FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
    1734             : 
    1735           0 :     cJSON_Delete( json );
    1736           0 :     return 0;
    1737           0 :   }
    1738             : 
    1739           0 :   cJSON_Delete( json );
    1740           0 :   return FD_HTTP_SERVER_CONNECTION_CLOSE_UNKNOWN_METHOD;
    1741           0 : }
    1742             : 
    1743             : static fd_gui_slot_t *
    1744             : fd_gui_clear_slot( fd_gui_t *      gui,
    1745             :                    ulong           _slot,
    1746           0 :                    ulong           _parent_slot ) {
    1747           0 :   fd_gui_slot_t * slot = gui->slots[ _slot % FD_GUI_SLOTS_CNT ];
    1748             : 
    1749           0 :   int mine = 0;
    1750           0 :   ulong epoch_idx = 0UL;
    1751           0 :   for( ulong i=0UL; i<2UL; i++) {
    1752           0 :     if( FD_UNLIKELY( !gui->epoch.has_epoch[ i ] ) ) continue;
    1753           0 :     if( FD_LIKELY( _slot>=gui->epoch.epochs[ i ].start_slot && _slot<=gui->epoch.epochs[ i ].end_slot ) ) {
    1754           0 :       fd_pubkey_t const * slot_leader = fd_epoch_leaders_get( gui->epoch.epochs[ i ].lsched, _slot );
    1755           0 :       mine = !memcmp( slot_leader->uc, gui->summary.identity_key->uc, 32UL );
    1756           0 :       epoch_idx = i;
    1757           0 :       break;
    1758           0 :     }
    1759           0 :   }
    1760             : 
    1761           0 :   slot->slot                   = _slot;
    1762           0 :   slot->parent_slot            = _parent_slot;
    1763           0 :   slot->vote_slot              = ULONG_MAX;
    1764           0 :   slot->vote_latency           = UCHAR_MAX;
    1765           0 :   slot->reset_slot             = ULONG_MAX;
    1766           0 :   slot->max_compute_units      = UINT_MAX;
    1767           0 :   slot->completed_time         = LONG_MAX;
    1768           0 :   slot->mine                   = mine;
    1769           0 :   slot->skipped                = 0;
    1770           0 :   slot->must_republish         = 1;
    1771           0 :   slot->level                  = FD_GUI_SLOT_LEVEL_INCOMPLETE;
    1772           0 :   slot->vote_failed            = UINT_MAX;
    1773           0 :   slot->vote_success           = UINT_MAX;
    1774           0 :   slot->nonvote_success        = UINT_MAX;
    1775           0 :   slot->nonvote_failed         = UINT_MAX;
    1776           0 :   slot->compute_units          = UINT_MAX;
    1777           0 :   slot->transaction_fee        = ULONG_MAX;
    1778           0 :   slot->priority_fee           = ULONG_MAX;
    1779           0 :   slot->tips                   = ULONG_MAX;
    1780           0 :   slot->shred_cnt              = UINT_MAX;
    1781           0 :   slot->shreds.start_offset    = ULONG_MAX;
    1782           0 :   slot->shreds.end_offset      = ULONG_MAX;
    1783             : 
    1784           0 :   if( FD_LIKELY( slot->mine ) ) {
    1785             :     /* All slots start off not skipped, until we see it get off the reset
    1786             :        chain. */
    1787           0 :     gui->epoch.epochs[ epoch_idx ].my_total_slots++;
    1788             : 
    1789           0 :     slot->leader_history_idx = gui->leader_slots_cnt++;
    1790           0 :     fd_gui_leader_slot_t * lslot = gui->leader_slots[ slot->leader_history_idx % FD_GUI_LEADER_CNT ];
    1791             : 
    1792           0 :     lslot->slot                        = _slot;
    1793           0 :     memset( lslot->block_hash.uc, 0, sizeof(fd_hash_t) );
    1794           0 :     lslot->leader_start_time           = LONG_MAX;
    1795           0 :     lslot->leader_end_time             = LONG_MAX;
    1796           0 :     lslot->tile_timers_sample_cnt      = 0UL;
    1797           0 :     lslot->scheduler_counts_sample_cnt = 0UL;
    1798           0 :     lslot->txs.microblocks_upper_bound = USHORT_MAX;
    1799           0 :     lslot->txs.begin_microblocks       = 0U;
    1800           0 :     lslot->txs.end_microblocks         = 0U;
    1801           0 :     lslot->txs.start_offset            = ULONG_MAX;
    1802           0 :     lslot->txs.end_offset              = ULONG_MAX;
    1803           0 :     lslot->unbecame_leader             = 0;
    1804           0 :   }
    1805             : 
    1806           0 :   if( FD_UNLIKELY( !_slot ) ) {
    1807             :     /* Slot 0 is always rooted */
    1808           0 :     slot->level   = FD_GUI_SLOT_LEVEL_ROOTED;
    1809           0 :   }
    1810             : 
    1811           0 :   return slot;
    1812           0 : }
    1813             : 
    1814             : void
    1815             : fd_gui_handle_leader_schedule( fd_gui_t *                    gui,
    1816             :                                fd_stake_weight_msg_t const * leader_schedule,
    1817           0 :                                long                          now ) {
    1818           0 :   FD_TEST( leader_schedule->staked_vote_cnt<=MAX_STAKED_LEADERS );
    1819           0 :   FD_TEST( leader_schedule->slot_cnt<=MAX_SLOTS_PER_EPOCH );
    1820             : 
    1821           0 :   ulong idx = leader_schedule->epoch % 2UL;
    1822           0 :   gui->epoch.has_epoch[ idx ] = 1;
    1823             : 
    1824           0 :   gui->epoch.epochs[ idx ].epoch            = leader_schedule->epoch;
    1825           0 :   gui->epoch.epochs[ idx ].start_slot       = leader_schedule->start_slot;
    1826           0 :   gui->epoch.epochs[ idx ].end_slot         = leader_schedule->start_slot + leader_schedule->slot_cnt - 1; // end_slot is inclusive.
    1827           0 :   gui->epoch.epochs[ idx ].my_total_slots   = 0UL;
    1828           0 :   gui->epoch.epochs[ idx ].my_skipped_slots = 0UL;
    1829             : 
    1830           0 :   memset( gui->epoch.epochs[ idx ].rankings,    (int)(UINT_MAX), sizeof(gui->epoch.epochs[ idx ].rankings)    );
    1831           0 :   memset( gui->epoch.epochs[ idx ].my_rankings, (int)(UINT_MAX), sizeof(gui->epoch.epochs[ idx ].my_rankings) );
    1832             : 
    1833           0 :   gui->epoch.epochs[ idx ].rankings_slot = leader_schedule->start_slot;
    1834             : 
    1835           0 :   fd_vote_stake_weight_t const * stake_weights = fd_stake_weight_msg_stake_weights( leader_schedule );
    1836           0 :   fd_memcpy( gui->epoch.epochs[ idx ].stakes, stake_weights, leader_schedule->staked_vote_cnt*sizeof(fd_vote_stake_weight_t) );
    1837             : 
    1838           0 :   fd_epoch_leaders_delete( fd_epoch_leaders_leave( gui->epoch.epochs[ idx ].lsched ) );
    1839           0 :   gui->epoch.epochs[idx].lsched = fd_epoch_leaders_join( fd_epoch_leaders_new( gui->epoch.epochs[ idx ]._lsched,
    1840           0 :                                                                                leader_schedule->epoch,
    1841           0 :                                                                                gui->epoch.epochs[ idx ].start_slot,
    1842           0 :                                                                                leader_schedule->slot_cnt,
    1843           0 :                                                                                leader_schedule->staked_vote_cnt,
    1844           0 :                                                                                gui->epoch.epochs[ idx ].stakes,
    1845           0 :                                                                                0UL ) );
    1846             : 
    1847           0 :   if( FD_UNLIKELY( leader_schedule->start_slot==0UL ) ) {
    1848           0 :     gui->epoch.epochs[ 0 ].start_time = now;
    1849           0 :   } else {
    1850           0 :     gui->epoch.epochs[ idx ].start_time = LONG_MAX;
    1851             : 
    1852           0 :     for( ulong i=0UL; i<fd_ulong_min( leader_schedule->start_slot-1UL, FD_GUI_SLOTS_CNT ); i++ ) {
    1853           0 :       fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, leader_schedule->start_slot-i );
    1854           0 :       if( FD_UNLIKELY( !slot ) ) break;
    1855           0 :       else if( FD_UNLIKELY( slot->skipped ) ) continue;
    1856             : 
    1857           0 :       gui->epoch.epochs[ idx ].start_time = slot->completed_time;
    1858           0 :       break;
    1859           0 :     }
    1860           0 :   }
    1861             : 
    1862           0 :   fd_gui_printf_epoch( gui, idx );
    1863           0 :   fd_http_server_ws_broadcast( gui->http );
    1864           0 : }
    1865             : 
    1866             : void
    1867             : fd_gui_handle_epoch_info( fd_gui_t *                  gui,
    1868             :                           fd_epoch_info_msg_t const * epoch_info,
    1869           0 :                           long                        now ) {
    1870           0 :   FD_TEST( epoch_info->staked_vote_cnt<=MAX_COMPRESSED_STAKE_WEIGHTS );
    1871           0 :   FD_TEST( epoch_info->slot_cnt<=MAX_SLOTS_PER_EPOCH );
    1872             : 
    1873           0 :   ulong idx = epoch_info->epoch % 2UL;
    1874           0 :   gui->epoch.has_epoch[ idx ] = 1;
    1875             : 
    1876           0 :   gui->epoch.epochs[ idx ].epoch            = epoch_info->epoch;
    1877           0 :   gui->epoch.epochs[ idx ].start_slot       = epoch_info->start_slot;
    1878           0 :   gui->epoch.epochs[ idx ].end_slot         = epoch_info->start_slot + epoch_info->slot_cnt - 1; // end_slot is inclusive.
    1879           0 :   gui->epoch.epochs[ idx ].my_total_slots   = 0UL;
    1880           0 :   gui->epoch.epochs[ idx ].my_skipped_slots = 0UL;
    1881             : 
    1882           0 :   memset( gui->epoch.epochs[ idx ].rankings,    (int)(UINT_MAX), sizeof(gui->epoch.epochs[ idx ].rankings)    );
    1883           0 :   memset( gui->epoch.epochs[ idx ].my_rankings, (int)(UINT_MAX), sizeof(gui->epoch.epochs[ idx ].my_rankings) );
    1884             : 
    1885           0 :   gui->epoch.epochs[ idx ].rankings_slot = epoch_info->start_slot;
    1886             : 
    1887           0 :   fd_vote_stake_weight_t const * stake_weights = fd_epoch_info_msg_stake_weights( epoch_info );
    1888           0 :   fd_memcpy( gui->epoch.epochs[ idx ].stakes, stake_weights, epoch_info->staked_vote_cnt*sizeof(fd_vote_stake_weight_t) );
    1889             : 
    1890           0 :   fd_epoch_leaders_delete( fd_epoch_leaders_leave( gui->epoch.epochs[ idx ].lsched ) );
    1891           0 :   gui->epoch.epochs[idx].lsched = fd_epoch_leaders_join( fd_epoch_leaders_new( gui->epoch.epochs[ idx ]._lsched,
    1892           0 :                                                                                epoch_info->epoch,
    1893           0 :                                                                                gui->epoch.epochs[ idx ].start_slot,
    1894           0 :                                                                                epoch_info->slot_cnt,
    1895           0 :                                                                                epoch_info->staked_vote_cnt,
    1896           0 :                                                                                gui->epoch.epochs[ idx ].stakes,
    1897           0 :                                                                                0UL ) );
    1898             : 
    1899           0 :   if( FD_UNLIKELY( epoch_info->start_slot==0UL ) ) {
    1900           0 :     gui->epoch.epochs[ 0 ].start_time = now;
    1901           0 :   } else {
    1902           0 :     gui->epoch.epochs[ idx ].start_time = LONG_MAX;
    1903             : 
    1904           0 :     for( ulong i=0UL; i<fd_ulong_min( epoch_info->start_slot-1UL, FD_GUI_SLOTS_CNT ); i++ ) {
    1905           0 :       fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, epoch_info->start_slot-i );
    1906           0 :       if( FD_UNLIKELY( !slot ) ) break;
    1907           0 :       else if( FD_UNLIKELY( slot->skipped ) ) continue;
    1908             : 
    1909           0 :       gui->epoch.epochs[ idx ].start_time = slot->completed_time;
    1910           0 :       break;
    1911           0 :     }
    1912           0 :   }
    1913             : 
    1914           0 :   fd_gui_printf_epoch( gui, idx );
    1915           0 :   fd_http_server_ws_broadcast( gui->http );
    1916           0 : }
    1917             : 
    1918             : static void
    1919             : fd_gui_handle_slot_start( fd_gui_t * gui,
    1920             :                           ulong      _slot,
    1921             :                           ulong      parent_slot,
    1922           0 :                           long       now ) {
    1923           0 :   FD_TEST( gui->leader_slot==ULONG_MAX );
    1924           0 :   gui->leader_slot = _slot;
    1925             : 
    1926           0 :   fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
    1927           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, parent_slot );
    1928             : 
    1929           0 :   fd_gui_tile_timers_snap( gui );
    1930           0 :   gui->summary.tile_timers_snap_idx_slot_start = (gui->summary.tile_timers_snap_idx+(FD_GUI_TILE_TIMER_SNAP_CNT-1UL))%FD_GUI_TILE_TIMER_SNAP_CNT;
    1931             : 
    1932           0 :   fd_gui_scheduler_counts_snap( gui, now );
    1933           0 :   gui->summary.scheduler_counts_snap_idx_slot_start = (gui->summary.scheduler_counts_snap_idx+(FD_GUI_SCHEDULER_COUNT_SNAP_CNT-1UL))%FD_GUI_SCHEDULER_COUNT_SNAP_CNT;
    1934             : 
    1935           0 :   fd_gui_txn_waterfall_t waterfall[ 1 ];
    1936           0 :   fd_gui_txn_waterfall_snap( gui, waterfall );
    1937           0 :   fd_gui_tile_stats_snap( gui, waterfall, slot->tile_stats_begin, now );
    1938           0 : }
    1939             : 
    1940             : static void
    1941             : fd_gui_handle_slot_end( fd_gui_t * gui,
    1942             :                         ulong      _slot,
    1943             :                         ulong      _cus_used,
    1944           0 :                         long       now ) {
    1945           0 :   if( FD_UNLIKELY( !gui->summary.is_full_client && gui->leader_slot!=_slot ) ) {
    1946           0 :     FD_LOG_ERR(( "gui->leader_slot %lu _slot %lu", gui->leader_slot, _slot ));
    1947           0 :   }
    1948           0 :   gui->leader_slot = ULONG_MAX;
    1949             : 
    1950           0 :   fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
    1951           0 :   if( FD_UNLIKELY( !slot ) ) return;
    1952             : 
    1953           0 :   if( FD_UNLIKELY( !gui->summary.is_full_client ) ) slot->compute_units = (uint)_cus_used;
    1954             : 
    1955           0 :   fd_gui_tile_timers_snap( gui );
    1956             : 
    1957           0 :   fd_gui_scheduler_counts_snap( gui, now );
    1958             : 
    1959           0 :   fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
    1960           0 :   if( FD_LIKELY( lslot ) ) {
    1961           0 :     fd_rng_t rng[ 1 ];
    1962           0 :     fd_rng_new( rng, 0UL, 0UL);
    1963             : 
    1964           0 : #define DOWNSAMPLE( a, a_start, a_end, a_capacity, b, b_sz, stride ) (__extension__({  \
    1965           0 :   ulong __cnt = 0UL; \
    1966           0 :   ulong __rsz = (stride); \
    1967           0 :   ulong __a_sz = (fd_ulong_if( a_end<a_start, a_end+a_capacity, a_end )-a_start); \
    1968           0 :   if( FD_UNLIKELY( __a_sz && b_sz ) ) { \
    1969           0 :     for( ulong a_idx=0UL; a_idx<__a_sz && __cnt<b_sz; a_idx++ ) { \
    1970           0 :       if( FD_UNLIKELY( fd_rng_float_robust( rng ) > (float)(b_sz-__cnt) / (float)(__a_sz-__cnt) ) ) continue; \
    1971           0 :       fd_memcpy( (b) + __cnt * __rsz, (a) + ((a_start+a_idx)%a_capacity) * __rsz, __rsz * sizeof(*(b)) ); \
    1972           0 :       __cnt++; \
    1973           0 :     } \
    1974           0 :   } \
    1975           0 :   __cnt; }))
    1976             : 
    1977           0 :     lslot->tile_timers_sample_cnt = DOWNSAMPLE(
    1978           0 :       gui->summary.tile_timers_snap,
    1979           0 :       gui->summary.tile_timers_snap_idx_slot_start,
    1980           0 :       gui->summary.tile_timers_snap_idx,
    1981           0 :       FD_GUI_TILE_TIMER_SNAP_CNT,
    1982           0 :       lslot->tile_timers,
    1983           0 :       FD_GUI_TILE_TIMER_LEADER_DOWNSAMPLE_CNT,
    1984           0 :       gui->tile_cnt );
    1985             : 
    1986           0 :     lslot->scheduler_counts_sample_cnt = DOWNSAMPLE(
    1987           0 :       gui->summary.scheduler_counts_snap,
    1988           0 :       gui->summary.scheduler_counts_snap_idx_slot_start,
    1989           0 :       gui->summary.scheduler_counts_snap_idx,
    1990           0 :       FD_GUI_SCHEDULER_COUNT_SNAP_CNT,
    1991           0 :       lslot->scheduler_counts,
    1992           0 :       FD_GUI_SCHEDULER_COUNT_LEADER_DOWNSAMPLE_CNT,
    1993           0 :       1UL );
    1994           0 : #undef DOWNSAMPLE
    1995           0 :   }
    1996             : 
    1997             :   /* When a slot ends, snap the state of the waterfall and save it into
    1998             :      that slot, and also reset the reference counters to the end of the
    1999             :      slot. */
    2000             : 
    2001           0 :   fd_gui_txn_waterfall_snap( gui, slot->waterfall_end );
    2002           0 :   memcpy( slot->waterfall_begin, gui->summary.txn_waterfall_reference, sizeof(slot->waterfall_begin) );
    2003           0 :   memcpy( gui->summary.txn_waterfall_reference, slot->waterfall_end, sizeof(gui->summary.txn_waterfall_reference) );
    2004             : 
    2005           0 :   fd_gui_tile_stats_snap( gui, slot->waterfall_end, slot->tile_stats_end, now );
    2006           0 : }
    2007             : 
    2008             : void
    2009             : fd_gui_handle_shred( fd_gui_t * gui,
    2010             :                      ulong      slot,
    2011             :                      ulong      shred_idx,
    2012             :                      int        is_turbine,
    2013           0 :                      long       tsorig ) {
    2014           0 :   int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot );
    2015           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 );
    2016             : 
    2017             :   /* If we haven't caught up yet, update repair slot using received
    2018             :      shreds. This is not technically correct, but close enough and will
    2019             :      make the progress bar look correct. */
    2020           0 :   if( FD_UNLIKELY( !is_turbine && gui->summary.slot_caught_up==ULONG_MAX ) ) fd_gui_handle_repair_slot( gui, slot, tsorig );
    2021             : 
    2022           0 :   if( FD_UNLIKELY( !was_sent && is_turbine && slot!=gui->summary.slot_turbine ) ) {
    2023           0 :     gui->summary.slot_turbine = slot;
    2024             : 
    2025           0 :     fd_gui_printf_turbine_slot( gui );
    2026           0 :     fd_http_server_ws_broadcast( gui->http );
    2027             : 
    2028           0 :     gui->turbine_slots[ slot % FD_GUI_TURBINE_RECV_TIMESTAMPS ].slot = slot;
    2029           0 :     gui->turbine_slots[ slot % FD_GUI_TURBINE_RECV_TIMESTAMPS ].timestamp = tsorig;
    2030             : 
    2031           0 :     ulong duration_sum = 0UL;
    2032           0 :     ulong slot_cnt = 0UL;
    2033             : 
    2034           0 :     for( ulong i=0UL; i<FD_GUI_TURBINE_RECV_TIMESTAMPS; i++ ) {
    2035           0 :       fd_gui_turbine_slot_t * cur = &gui->turbine_slots[ i ];
    2036           0 :       fd_gui_turbine_slot_t * prev = &gui->turbine_slots[ (i+FD_GUI_TURBINE_RECV_TIMESTAMPS-1UL) % FD_GUI_TURBINE_RECV_TIMESTAMPS ];
    2037           0 :       if( FD_UNLIKELY( cur->slot==ULONG_MAX || prev->slot==ULONG_MAX || cur->slot!=prev->slot+1UL ) ) continue;
    2038             : 
    2039           0 :       long slot_duration = cur->timestamp - prev->timestamp;
    2040           0 :       duration_sum += (ulong)fd_long_max( slot_duration, 0UL );
    2041           0 :       slot_cnt++;
    2042           0 :     }
    2043             : 
    2044           0 :     if( FD_LIKELY( slot_cnt>0 ) ) {
    2045           0 :       gui->summary.estimated_slot_duration_nanos = (ulong)(duration_sum / slot_cnt);
    2046           0 :       fd_gui_printf_estimated_slot_duration_nanos( gui );
    2047           0 :       fd_http_server_ws_broadcast( gui->http );
    2048           0 :     }
    2049             : 
    2050           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 );
    2051           0 :   }
    2052             : 
    2053           0 :   fd_gui_slot_staged_shred_event_t * recv_event = fd_gui_staged_push( gui );
    2054           0 :   recv_event->timestamp = tsorig;
    2055           0 :   recv_event->shred_idx = (ushort)shred_idx;
    2056           0 :   recv_event->slot      = slot;
    2057           0 :   recv_event->event     = fd_uchar_if( is_turbine, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_TURBINE, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_REPAIR );
    2058           0 : }
    2059             : 
    2060             : void
    2061             : fd_gui_handle_leader_fec( fd_gui_t * gui,
    2062             :                           ulong      slot,
    2063             :                           ulong      fec_shred_cnt,
    2064             :                           int        is_end_of_slot,
    2065           0 :                           long       tsorig ) {
    2066           0 :   for( ulong i=gui->shreds.leader_shred_cnt; i<gui->shreds.leader_shred_cnt+fec_shred_cnt; i++ ) {
    2067           0 :     fd_gui_slot_staged_shred_event_t * exec_end_event = fd_gui_staged_push( gui );
    2068           0 :     exec_end_event->timestamp = tsorig;
    2069           0 :     exec_end_event->shred_idx = (ushort)i;
    2070           0 :     exec_end_event->slot      = slot;
    2071           0 :     exec_end_event->event     = FD_GUI_SLOT_SHRED_SHRED_PUBLISHED;
    2072           0 :   }
    2073           0 :   gui->shreds.leader_shred_cnt += fec_shred_cnt;
    2074           0 :   if( FD_UNLIKELY( is_end_of_slot ) ) gui->shreds.leader_shred_cnt = 0UL;
    2075           0 : }
    2076             : 
    2077             : void
    2078             : fd_gui_handle_exec_txn_done( fd_gui_t * gui,
    2079             :                              ulong      slot,
    2080             :                              ulong      start_shred_idx,
    2081             :                              ulong      end_shred_idx,
    2082             :                              long       tsorig_ns FD_PARAM_UNUSED,
    2083           0 :                              long       tspub_ns ) {
    2084           0 :   for( ulong i = start_shred_idx; i<end_shred_idx; i++ ) {
    2085             :     /*
    2086             :       We're leaving this state transition out due to its proximity to
    2087             :       FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE, but if we ever wanted
    2088             :       to send this data to the frontend we could.
    2089             : 
    2090             :       fd_gui_slot_staged_shred_event_t * exec_start_event = &gui->shreds.staged[ gui->shreds.staged_tail % FD_GUI_SHREDS_STAGING_SZ ];
    2091             :       gui->shreds.staged_tail++;
    2092             :       exec_start_event->timestamp = tsorig_ns;
    2093             :       exec_start_event->shred_idx = (ushort)i;
    2094             :       exec_start_event->slot      = slot;
    2095             :       exec_start_event->event     = FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_START;
    2096             :     */
    2097             : 
    2098           0 :     fd_gui_slot_staged_shred_event_t * exec_end_event = fd_gui_staged_push( gui );
    2099           0 :     exec_end_event->timestamp = tspub_ns;
    2100           0 :     exec_end_event->shred_idx = (ushort)i;
    2101           0 :     exec_end_event->slot      = slot;
    2102           0 :     exec_end_event->event     = FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE;
    2103           0 :   }
    2104           0 : }
    2105             : 
    2106             : static void
    2107             : fd_gui_handle_reset_slot_legacy( fd_gui_t *    gui,
    2108             :                                  uchar const * msg,
    2109           0 :                                  long          now ) {
    2110           0 :   ulong last_landed_vote = FD_LOAD( ulong, msg );
    2111             : 
    2112           0 :   ulong parent_cnt = FD_LOAD( ulong, msg + 8UL );
    2113           0 :   FD_TEST( parent_cnt<4096UL );
    2114             : 
    2115           0 :   ulong _slot = FD_LOAD( ulong, msg + 16UL );
    2116             : 
    2117           0 :   for( ulong i=0UL; i<parent_cnt; i++ ) {
    2118           0 :     ulong parent_slot = FD_LOAD( ulong, msg + (2UL+i)*8UL );
    2119           0 :     fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
    2120           0 :     if( FD_UNLIKELY( !slot ) ) {
    2121           0 :       ulong parent_parent_slot = ULONG_MAX;
    2122           0 :       if( FD_UNLIKELY( i!=parent_cnt-1UL) ) parent_parent_slot = FD_LOAD( ulong, msg + (3UL+i)*8UL );
    2123           0 :       fd_gui_clear_slot( gui, parent_slot, parent_parent_slot );
    2124           0 :     }
    2125           0 :   }
    2126             : 
    2127           0 :   if( FD_UNLIKELY( gui->summary.vote_distance!=_slot-last_landed_vote ) ) {
    2128           0 :     gui->summary.vote_distance = _slot-last_landed_vote;
    2129           0 :     fd_gui_printf_vote_distance( gui );
    2130           0 :     fd_http_server_ws_broadcast( gui->http );
    2131           0 :   }
    2132             : 
    2133           0 :   if( FD_LIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_NON_VOTING ) ) {
    2134           0 :     if( FD_UNLIKELY( last_landed_vote==ULONG_MAX || (last_landed_vote+150UL)<_slot ) ) {
    2135           0 :       if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_DELINQUENT ) ) {
    2136           0 :         gui->summary.vote_state = FD_GUI_VOTE_STATE_DELINQUENT;
    2137           0 :         fd_gui_printf_vote_state( gui );
    2138           0 :         fd_http_server_ws_broadcast( gui->http );
    2139           0 :       }
    2140           0 :     } else {
    2141           0 :       if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_VOTING ) ) {
    2142           0 :         gui->summary.vote_state = FD_GUI_VOTE_STATE_VOTING;
    2143           0 :         fd_gui_printf_vote_state( gui );
    2144           0 :         fd_http_server_ws_broadcast( gui->http );
    2145           0 :       }
    2146           0 :     }
    2147           0 :   }
    2148             : 
    2149           0 :   ulong parent_slot_idx = 0UL;
    2150             : 
    2151           0 :   int republish_skip_rate[ 2 ] = {0};
    2152             : 
    2153           0 :   for( ulong i=0UL; i<fd_ulong_min( _slot+1, FD_GUI_SLOTS_CNT ); i++ ) {
    2154           0 :     ulong parent_slot = _slot - i;
    2155             : 
    2156           0 :     fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
    2157           0 :     if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, parent_slot, ULONG_MAX );
    2158             : 
    2159             :     /* The chain of parents may stretch into already rooted slots if
    2160             :        they haven't been squashed yet, if we reach one of them we can
    2161             :        just exit, all the information prior to the root is already
    2162             :        correct. */
    2163             : 
    2164           0 :     if( FD_LIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
    2165             : 
    2166           0 :     int should_republish = slot->must_republish;
    2167           0 :     slot->must_republish = 0;
    2168             : 
    2169           0 :     if( FD_UNLIKELY( parent_slot!=FD_LOAD( ulong, msg + (2UL+parent_slot_idx)*8UL ) ) ) {
    2170             :       /* We are between two parents in the rooted chain, which means
    2171             :          we were skipped. */
    2172           0 :       if( FD_UNLIKELY( !slot->skipped ) ) {
    2173           0 :         slot->skipped = 1;
    2174           0 :         should_republish = 1;
    2175           0 :         if( FD_LIKELY( slot->mine ) ) {
    2176           0 :           for( ulong i=0UL; i<2UL; i++ ) {
    2177           0 :             if( FD_LIKELY( parent_slot>=gui->epoch.epochs[ i ].start_slot && parent_slot<=gui->epoch.epochs[ i ].end_slot ) ) {
    2178           0 :               gui->epoch.epochs[ i ].my_skipped_slots++;
    2179           0 :               republish_skip_rate[ i ] = 1;
    2180           0 :               break;
    2181           0 :             }
    2182           0 :           }
    2183           0 :         }
    2184           0 :       }
    2185           0 :     } else {
    2186             :       /* Reached the next parent... */
    2187           0 :       if( FD_UNLIKELY( slot->skipped ) ) {
    2188           0 :         slot->skipped = 0;
    2189           0 :         should_republish = 1;
    2190           0 :         if( FD_LIKELY( slot->mine ) ) {
    2191           0 :           for( ulong i=0UL; i<2UL; i++ ) {
    2192           0 :             if( FD_LIKELY( parent_slot>=gui->epoch.epochs[ i ].start_slot && parent_slot<=gui->epoch.epochs[ i ].end_slot ) ) {
    2193           0 :               gui->epoch.epochs[ i ].my_skipped_slots--;
    2194           0 :               republish_skip_rate[ i ] = 1;
    2195           0 :               break;
    2196           0 :             }
    2197           0 :           }
    2198           0 :         }
    2199           0 :       }
    2200           0 :       parent_slot_idx++;
    2201           0 :     }
    2202             : 
    2203           0 :     if( FD_LIKELY( should_republish ) ) {
    2204           0 :       fd_gui_printf_slot( gui, parent_slot );
    2205           0 :       fd_http_server_ws_broadcast( gui->http );
    2206           0 :     }
    2207             : 
    2208             :     /* We reached the last parent in the chain, everything above this
    2209             :        must have already been rooted, so we can exit. */
    2210             : 
    2211           0 :     if( FD_UNLIKELY( parent_slot_idx>=parent_cnt ) ) break;
    2212           0 :   }
    2213             : 
    2214           0 :   ulong duration_sum = 0UL;
    2215           0 :   ulong slot_cnt = 0UL;
    2216             : 
    2217             :   /* If we've just caught up we should truncate our slot history to avoid including catch-up slots */
    2218           0 :   int just_caught_up = gui->summary.slot_caught_up!=ULONG_MAX && _slot>gui->summary.slot_caught_up && _slot<gui->summary.slot_caught_up+750UL;
    2219           0 :   ulong slot_duration_history_sz = fd_ulong_if( just_caught_up, _slot-gui->summary.slot_caught_up, 750UL );
    2220           0 :   for( ulong i=0UL; i<fd_ulong_min( _slot+1, slot_duration_history_sz ); i++ ) {
    2221           0 :     ulong parent_slot = _slot - i;
    2222             : 
    2223           0 :     fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, parent_slot );
    2224           0 :     if( FD_UNLIKELY( !slot) ) break;
    2225           0 :     if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
    2226           0 :       FD_LOG_ERR(( "_slot %lu i %lu we expect _slot-i %lu got slot->slot %lu", _slot, i, _slot-i, slot->slot ));
    2227           0 :     }
    2228             : 
    2229           0 :     ulong slot_duration = fd_gui_slot_duration( gui, slot );
    2230           0 :     if( FD_LIKELY( slot_duration!=ULONG_MAX ) ) {
    2231           0 :       duration_sum += slot_duration;
    2232           0 :       slot_cnt++;
    2233           0 :     }
    2234           0 :   }
    2235             : 
    2236           0 :   if( FD_LIKELY( slot_cnt>0 ) ) {
    2237           0 :     gui->summary.estimated_slot_duration_nanos = (ulong)(duration_sum / slot_cnt);
    2238           0 :     fd_gui_printf_estimated_slot_duration_nanos( gui );
    2239           0 :     fd_http_server_ws_broadcast( gui->http );
    2240           0 :   }
    2241             : 
    2242           0 :   if( FD_LIKELY( gui->summary.slot_completed==ULONG_MAX || _slot!=gui->summary.slot_completed ) ) {
    2243           0 :     gui->summary.slot_completed = _slot;
    2244           0 :     fd_gui_printf_completed_slot( gui );
    2245           0 :     fd_http_server_ws_broadcast( gui->http );
    2246             : 
    2247             :     /* Also update slot_turbine which could be larger than the max
    2248             :        turbine slot if we are leader */
    2249           0 :     if( FD_UNLIKELY( gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && gui->summary.slot_completed!=ULONG_MAX && gui->summary.slot_completed>gui->summary.slots_max_turbine[ 0 ].slot ) ) {
    2250           0 :       fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, gui->summary.slot_completed, now );
    2251           0 :     }
    2252             : 
    2253           0 :     int slot_turbine_hist_full = gui->summary.slots_max_turbine[ FD_GUI_TURBINE_SLOT_HISTORY_SZ-1UL ].slot!=ULONG_MAX;
    2254           0 :     if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX && slot_turbine_hist_full && gui->summary.slots_max_turbine[ 0 ].slot < (gui->summary.slot_completed + 3UL) ) ) {
    2255           0 :       gui->summary.slot_caught_up = gui->summary.slot_completed + 4UL;
    2256             : 
    2257           0 :       fd_gui_printf_slot_caught_up( gui );
    2258           0 :       fd_http_server_ws_broadcast( gui->http );
    2259           0 :     }
    2260           0 :   }
    2261             : 
    2262           0 :   for( ulong i=0UL; i<2UL; i++ ) {
    2263           0 :     if( FD_LIKELY( republish_skip_rate[ i ] ) ) {
    2264           0 :       fd_gui_printf_skip_rate( gui, i );
    2265           0 :       fd_http_server_ws_broadcast( gui->http );
    2266           0 :     }
    2267           0 :   }
    2268           0 : }
    2269             : 
    2270             : static void
    2271             : fd_gui_handle_completed_slot( fd_gui_t *    gui,
    2272             :                               uchar const * msg,
    2273           0 :                               long          now ) {
    2274             : 
    2275             :   /* This is the slot used by frontend clients as the "startup slot". In
    2276             :      certain boot conditions, we don't receive this slot from Agave, so
    2277             :      we include a bit of a hacky assignment here to make sure it is
    2278             :      always present. */
    2279           0 :   if( FD_UNLIKELY( gui->summary.startup_progress.startup_ledger_max_slot==ULONG_MAX ) ) {
    2280           0 :     gui->summary.startup_progress.startup_ledger_max_slot = FD_LOAD( ulong, msg );
    2281           0 :   }
    2282             : 
    2283           0 :   ulong _slot                    = FD_LOAD( ulong, msg );
    2284           0 :   uint  total_txn_count          = (uint)FD_LOAD( ulong, msg + 1UL*8UL );
    2285           0 :   uint  nonvote_txn_count        = (uint)FD_LOAD( ulong, msg + 2UL*8UL );
    2286           0 :   uint  failed_txn_count         = (uint)FD_LOAD( ulong, msg + 3UL*8UL );
    2287           0 :   uint  nonvote_failed_txn_count = (uint)FD_LOAD( ulong, msg + 4UL*8UL );
    2288           0 :   uint  compute_units            = (uint)FD_LOAD( ulong, msg + 5UL*8UL );
    2289           0 :   ulong transaction_fee          = FD_LOAD( ulong, msg + 6UL*8UL );
    2290           0 :   ulong priority_fee             = FD_LOAD( ulong, msg + 7UL*8UL );
    2291           0 :   ulong tips                     = FD_LOAD( ulong, msg + 8UL*8UL );
    2292           0 :   ulong _parent_slot             = FD_LOAD( ulong, msg + 9UL*8UL );
    2293           0 :   ulong max_compute_units        = FD_LOAD( ulong, msg + 10UL*8UL );
    2294             : 
    2295           0 :   fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
    2296           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, _parent_slot );
    2297             : 
    2298           0 :   slot->completed_time = now;
    2299           0 :   slot->parent_slot = _parent_slot;
    2300           0 :   slot->max_compute_units = (uint)max_compute_units;
    2301           0 :   if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_COMPLETED ) ) {
    2302             :     /* Typically a slot goes from INCOMPLETE to COMPLETED but it can
    2303             :        happen that it starts higher.  One such case is when we
    2304             :        optimistically confirm a higher slot that skips this one, but
    2305             :        then later we replay this one anyway to track the bank fork. */
    2306             : 
    2307           0 :     if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && _slot<gui->summary.slot_optimistically_confirmed ) ) {
    2308             :       /* Cluster might have already optimistically confirmed by the time
    2309             :          we finish replaying it. */
    2310           0 :       slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
    2311           0 :     } else {
    2312           0 :       slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
    2313           0 :     }
    2314           0 :   }
    2315             : 
    2316           0 :   slot->nonvote_success = nonvote_txn_count - nonvote_failed_txn_count;
    2317           0 :   slot->nonvote_failed  = nonvote_failed_txn_count;
    2318           0 :   slot->vote_failed     = failed_txn_count - nonvote_failed_txn_count;
    2319           0 :   slot->vote_success    = total_txn_count - nonvote_txn_count - slot->vote_failed;
    2320             : 
    2321           0 :   slot->transaction_fee        = transaction_fee;
    2322           0 :   slot->priority_fee           = priority_fee;
    2323           0 :   slot->tips                   = tips;
    2324             : 
    2325             :   /* In Frankendancer, CUs come from our own leader pipeline (the field
    2326             :      sent from the Agave codepath is zero'd out) */
    2327           0 :   slot->compute_units          = fd_uint_if( !gui->summary.is_full_client && slot->mine, slot->compute_units, compute_units );
    2328             : 
    2329           0 :   if( FD_UNLIKELY( gui->epoch.has_epoch[ 0 ] && _slot==gui->epoch.epochs[ 0 ].end_slot ) ) {
    2330           0 :     gui->epoch.epochs[ 0 ].end_time = slot->completed_time;
    2331           0 :   } else if( FD_UNLIKELY( gui->epoch.has_epoch[ 1 ] && _slot==gui->epoch.epochs[ 1 ].end_slot ) ) {
    2332           0 :     gui->epoch.epochs[ 1 ].end_time = slot->completed_time;
    2333           0 :   }
    2334             : 
    2335             :   /* Broadcast new skip rate if one of our slots got completed. */
    2336           0 :   if( FD_LIKELY( slot->mine ) ) {
    2337           0 :     for( ulong i=0UL; i<2UL; i++ ) {
    2338           0 :       if( FD_LIKELY( _slot>=gui->epoch.epochs[ i ].start_slot && _slot<=gui->epoch.epochs[ i ].end_slot ) ) {
    2339           0 :         fd_gui_printf_skip_rate( gui, i );
    2340           0 :         fd_http_server_ws_broadcast( gui->http );
    2341           0 :         break;
    2342           0 :       }
    2343           0 :     }
    2344           0 :   }
    2345           0 : }
    2346             : 
    2347             : static void
    2348             : fd_gui_handle_rooted_slot_legacy( fd_gui_t *    gui,
    2349           0 :                                   uchar const * msg ) {
    2350           0 :   ulong _slot = FD_LOAD( ulong, msg );
    2351             : 
    2352             :   // FD_LOG_WARNING(( "Got rooted slot %lu", _slot ));
    2353             : 
    2354             :   /* Slot 0 is always rooted.  No need to iterate all the way back to
    2355             :      i==_slot */
    2356           0 :   for( ulong i=0UL; i<fd_ulong_min( _slot, FD_GUI_SLOTS_CNT ); i++ ) {
    2357           0 :     ulong parent_slot = _slot - i;
    2358             : 
    2359           0 :     fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
    2360           0 :     if( FD_UNLIKELY( !slot ) ) break;
    2361             : 
    2362           0 :     if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
    2363           0 :       FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", _slot, i, parent_slot, slot->slot ));
    2364           0 :     }
    2365           0 :     if( FD_UNLIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
    2366             : 
    2367           0 :     slot->level = FD_GUI_SLOT_LEVEL_ROOTED;
    2368           0 :     fd_gui_printf_slot( gui, parent_slot );
    2369           0 :     fd_http_server_ws_broadcast( gui->http );
    2370           0 :   }
    2371             : 
    2372           0 :   gui->summary.slot_rooted = _slot;
    2373           0 :   fd_gui_printf_root_slot( gui );
    2374           0 :   fd_http_server_ws_broadcast( gui->http );
    2375           0 : }
    2376             : 
    2377             : static void
    2378             : fd_gui_handle_optimistically_confirmed_slot( fd_gui_t * gui,
    2379           0 :                                              ulong      _slot ) {
    2380             :   /* Slot 0 is always rooted.  No need to iterate all the way back to
    2381             :      i==_slot */
    2382           0 :   for( ulong i=0UL; i<fd_ulong_min( _slot, FD_GUI_SLOTS_CNT ); i++ ) {
    2383           0 :     ulong parent_slot = _slot - i;
    2384             : 
    2385           0 :     fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
    2386           0 :     if( FD_UNLIKELY( !slot) ) break;
    2387             : 
    2388           0 :     if( FD_UNLIKELY( slot->slot>parent_slot ) ) {
    2389           0 :       FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", _slot, i, parent_slot, slot->slot ));
    2390           0 :     } else if( FD_UNLIKELY( slot->slot<parent_slot ) ) {
    2391             :       /* Slot not even replayed yet ... will come out as optimistically confirmed */
    2392           0 :       continue;
    2393           0 :     }
    2394           0 :     if( FD_UNLIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
    2395             : 
    2396           0 :     if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED ) ) {
    2397           0 :       slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
    2398           0 :       fd_gui_printf_slot( gui, parent_slot );
    2399           0 :       fd_http_server_ws_broadcast( gui->http );
    2400           0 :     }
    2401           0 :   }
    2402             : 
    2403           0 :   if( FD_UNLIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && _slot<gui->summary.slot_optimistically_confirmed ) ) {
    2404             :     /* Optimistically confirmed slot went backwards ... mark some slots as no
    2405             :        longer optimistically confirmed. */
    2406           0 :     for( long i_=(long)gui->summary.slot_optimistically_confirmed; i_>=(long)_slot; i_-- ) {
    2407           0 :       ulong i = (ulong)i_;
    2408           0 :       fd_gui_slot_t * slot = fd_gui_get_slot( gui, i );
    2409           0 :       if( FD_UNLIKELY( !slot ) ) break;
    2410           0 :       if( FD_LIKELY( slot->slot==i ) ) {
    2411             :         /* It's possible for the optimistically confirmed slot to skip
    2412             :            backwards between two slots that we haven't yet replayed.  In
    2413             :            that case we don't need to change anything, since they will
    2414             :            get marked properly when they get completed. */
    2415           0 :         slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
    2416           0 :         fd_gui_printf_slot( gui, i );
    2417           0 :         fd_http_server_ws_broadcast( gui->http );
    2418           0 :       }
    2419           0 :     }
    2420           0 :   }
    2421             : 
    2422           0 :   gui->summary.slot_optimistically_confirmed = _slot;
    2423           0 :   fd_gui_printf_optimistically_confirmed_slot( gui );
    2424           0 :   fd_http_server_ws_broadcast( gui->http );
    2425           0 : }
    2426             : 
    2427             : static void
    2428             : fd_gui_handle_balance_update( fd_gui_t *    gui,
    2429           0 :                               uchar const * msg ) {
    2430           0 :   switch( FD_LOAD( ulong, msg ) ) {
    2431           0 :     case 0UL:
    2432           0 :       gui->summary.identity_account_balance = FD_LOAD( ulong, msg + 8UL );
    2433           0 :       fd_gui_printf_identity_balance( gui );
    2434           0 :       fd_http_server_ws_broadcast( gui->http );
    2435           0 :       break;
    2436           0 :     case 1UL:
    2437           0 :       gui->summary.vote_account_balance = FD_LOAD( ulong, msg + 8UL );
    2438           0 :       fd_gui_printf_vote_balance( gui );
    2439           0 :       fd_http_server_ws_broadcast( gui->http );
    2440           0 :       break;
    2441           0 :     default:
    2442           0 :       FD_LOG_ERR(( "balance: unknown account type: %lu", FD_LOAD( ulong, msg ) ));
    2443           0 :   }
    2444           0 : }
    2445             : 
    2446             : static void
    2447             : fd_gui_handle_start_progress( fd_gui_t *    gui,
    2448           0 :                               uchar const * msg ) {
    2449           0 :   uchar type = msg[ 0 ];
    2450             : 
    2451           0 :   switch (type) {
    2452           0 :     case 0:
    2453           0 :       gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_INITIALIZING;
    2454           0 :       FD_LOG_INFO(( "progress: initializing" ));
    2455           0 :       break;
    2456           0 :     case 1: {
    2457           0 :       char const * snapshot_type;
    2458           0 :       if( FD_UNLIKELY( gui->summary.startup_progress.startup_got_full_snapshot ) ) {
    2459           0 :         gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_SEARCHING_FOR_INCREMENTAL_SNAPSHOT;
    2460           0 :         snapshot_type = "incremental";
    2461           0 :       } else {
    2462           0 :         gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_SEARCHING_FOR_FULL_SNAPSHOT;
    2463           0 :         snapshot_type = "full";
    2464           0 :       }
    2465           0 :       FD_LOG_INFO(( "progress: searching for %s snapshot", snapshot_type ));
    2466           0 :       break;
    2467           0 :     }
    2468           0 :     case 2: {
    2469           0 :       uchar is_full_snapshot = msg[ 1 ];
    2470           0 :       if( FD_LIKELY( is_full_snapshot ) ) {
    2471           0 :           gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_DOWNLOADING_FULL_SNAPSHOT;
    2472           0 :           gui->summary.startup_progress.startup_full_snapshot_slot = FD_LOAD( ulong, msg + 2 );
    2473           0 :           gui->summary.startup_progress.startup_full_snapshot_peer_ip_addr = FD_LOAD( uint, msg + 10 );
    2474           0 :           gui->summary.startup_progress.startup_full_snapshot_peer_port = FD_LOAD( ushort, msg + 14 );
    2475           0 :           gui->summary.startup_progress.startup_full_snapshot_total_bytes = FD_LOAD( ulong, msg + 16 );
    2476           0 :           gui->summary.startup_progress.startup_full_snapshot_current_bytes = FD_LOAD( ulong, msg + 24 );
    2477           0 :           gui->summary.startup_progress.startup_full_snapshot_elapsed_secs = FD_LOAD( double, msg + 32 );
    2478           0 :           gui->summary.startup_progress.startup_full_snapshot_remaining_secs = FD_LOAD( double, msg + 40 );
    2479           0 :           gui->summary.startup_progress.startup_full_snapshot_throughput = FD_LOAD( double, msg + 48 );
    2480           0 :           FD_LOG_INFO(( "progress: downloading full snapshot: slot=%lu", gui->summary.startup_progress.startup_full_snapshot_slot ));
    2481           0 :       } else {
    2482           0 :           gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_DOWNLOADING_INCREMENTAL_SNAPSHOT;
    2483           0 :           gui->summary.startup_progress.startup_incremental_snapshot_slot = FD_LOAD( ulong, msg + 2 );
    2484           0 :           gui->summary.startup_progress.startup_incremental_snapshot_peer_ip_addr = FD_LOAD( uint, msg + 10 );
    2485           0 :           gui->summary.startup_progress.startup_incremental_snapshot_peer_port = FD_LOAD( ushort, msg + 14 );
    2486           0 :           gui->summary.startup_progress.startup_incremental_snapshot_total_bytes = FD_LOAD( ulong, msg + 16 );
    2487           0 :           gui->summary.startup_progress.startup_incremental_snapshot_current_bytes = FD_LOAD( ulong, msg + 24 );
    2488           0 :           gui->summary.startup_progress.startup_incremental_snapshot_elapsed_secs = FD_LOAD( double, msg + 32 );
    2489           0 :           gui->summary.startup_progress.startup_incremental_snapshot_remaining_secs = FD_LOAD( double, msg + 40 );
    2490           0 :           gui->summary.startup_progress.startup_incremental_snapshot_throughput = FD_LOAD( double, msg + 48 );
    2491           0 :           FD_LOG_INFO(( "progress: downloading incremental snapshot: slot=%lu", gui->summary.startup_progress.startup_incremental_snapshot_slot ));
    2492           0 :       }
    2493           0 :       break;
    2494           0 :     }
    2495           0 :     case 3: {
    2496           0 :       gui->summary.startup_progress.startup_got_full_snapshot = 1;
    2497           0 :       break;
    2498           0 :     }
    2499           0 :     case 4:
    2500           0 :       gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_CLEANING_BLOCK_STORE;
    2501           0 :       FD_LOG_INFO(( "progress: cleaning block store" ));
    2502           0 :       break;
    2503           0 :     case 5:
    2504           0 :       gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_CLEANING_ACCOUNTS;
    2505           0 :       FD_LOG_INFO(( "progress: cleaning accounts" ));
    2506           0 :       break;
    2507           0 :     case 6:
    2508           0 :       gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_LOADING_LEDGER;
    2509           0 :       FD_LOG_INFO(( "progress: loading ledger" ));
    2510           0 :       break;
    2511           0 :     case 7: {
    2512           0 :       gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_PROCESSING_LEDGER;
    2513           0 :       gui->summary.startup_progress.startup_ledger_slot = fd_ulong_load_8( msg + 1 );
    2514           0 :       gui->summary.startup_progress.startup_ledger_max_slot = fd_ulong_load_8( msg + 9 );
    2515           0 :       FD_LOG_INFO(( "progress: processing ledger: slot=%lu, max_slot=%lu", gui->summary.startup_progress.startup_ledger_slot, gui->summary.startup_progress.startup_ledger_max_slot ));
    2516           0 :       break;
    2517           0 :     }
    2518           0 :     case 8:
    2519           0 :       gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_STARTING_SERVICES;
    2520           0 :       FD_LOG_INFO(( "progress: starting services" ));
    2521           0 :       break;
    2522           0 :     case 9:
    2523           0 :       gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_HALTED;
    2524           0 :       FD_LOG_INFO(( "progress: halted" ));
    2525           0 :       break;
    2526           0 :     case 10: {
    2527           0 :       gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY;
    2528           0 :       gui->summary.startup_progress.startup_waiting_for_supermajority_slot = fd_ulong_load_8( msg + 1 );
    2529           0 :       gui->summary.startup_progress.startup_waiting_for_supermajority_stake_pct = fd_ulong_load_8( msg + 9 );
    2530           0 :       FD_LOG_INFO(( "progress: waiting for supermajority: slot=%lu, gossip_stake_percent=%lu", gui->summary.startup_progress.startup_waiting_for_supermajority_slot, gui->summary.startup_progress.startup_waiting_for_supermajority_stake_pct ));
    2531           0 :       break;
    2532           0 :     }
    2533           0 :     case 11:
    2534           0 :       gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_RUNNING;
    2535           0 :       FD_LOG_INFO(( "progress: running" ));
    2536           0 :       break;
    2537           0 :     default:
    2538           0 :       FD_LOG_ERR(( "progress: unknown type: %u", type ));
    2539           0 :   }
    2540             : 
    2541           0 :   fd_gui_printf_startup_progress( gui );
    2542           0 :   fd_http_server_ws_broadcast( gui->http );
    2543           0 : }
    2544             : 
    2545             : void
    2546             : fd_gui_handle_genesis_hash( fd_gui_t *        gui,
    2547           0 :                             fd_hash_t const * msg ) {
    2548           0 :   FD_BASE58_ENCODE_32_BYTES( msg->uc, hash_cstr );
    2549           0 :   ulong cluster = fd_genesis_cluster_identify(hash_cstr);
    2550           0 :   char const * cluster_name = fd_genesis_cluster_name(cluster);
    2551             : 
    2552           0 :   if( FD_LIKELY( strcmp( gui->summary.cluster, cluster_name ) ) ) {
    2553           0 :     gui->summary.cluster = fd_genesis_cluster_name(cluster);
    2554           0 :     fd_gui_printf_cluster( gui );
    2555           0 :     fd_http_server_ws_broadcast( gui->http );
    2556           0 :   }
    2557           0 : }
    2558             : 
    2559             : void
    2560             : fd_gui_handle_block_engine_update( fd_gui_t *                              gui,
    2561           0 :                                    fd_bundle_block_engine_update_t const * update ) {
    2562           0 :   gui->block_engine.has_block_engine = 1;
    2563             : 
    2564             :   /* copy strings and ensure null termination within bounds */
    2565           0 :   FD_TEST( fd_cstr_nlen( update->name,    sizeof(gui->block_engine.name   ) ) < sizeof(gui->block_engine.name   ) );
    2566           0 :   FD_TEST( fd_cstr_nlen( update->url,     sizeof(gui->block_engine.url    ) ) < sizeof(gui->block_engine.url    ) );
    2567           0 :   FD_TEST( fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) ) < sizeof(gui->block_engine.ip_cstr) );
    2568           0 :   ulong name_len    = fd_cstr_nlen( update->name,    sizeof(gui->block_engine.name   ) );
    2569           0 :   ulong url_len     = fd_cstr_nlen( update->url,     sizeof(gui->block_engine.url    ) );
    2570           0 :   ulong ip_cstr_len = fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) );
    2571           0 :   fd_memcpy( gui->block_engine.name,    update->name,    name_len+1UL );
    2572           0 :   fd_memcpy( gui->block_engine.url,     update->url,     url_len+1UL );
    2573           0 :   fd_memcpy( gui->block_engine.ip_cstr, update->ip_cstr, ip_cstr_len+1UL );
    2574             : 
    2575           0 :   fd_gui_printf_block_engine( gui );
    2576           0 :   fd_http_server_ws_broadcast( gui->http );
    2577           0 : }
    2578             : 
    2579             : void
    2580             : fd_gui_handle_snapshot_update( fd_gui_t *                 gui,
    2581           0 :                                fd_snapct_update_t const * msg ) {
    2582           0 :   FD_TEST( msg && fd_cstr_nlen( msg->read_path, 1 ) );
    2583             : 
    2584           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 );
    2585             : 
    2586           0 :   char const * filename = strrchr( msg->read_path, '/' );
    2587             : 
    2588             :   /* Skip the '/'  */
    2589           0 :   if( FD_LIKELY( filename ) ) filename++;
    2590           0 :   else                        filename = msg->read_path;
    2591             : 
    2592           0 :   if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_INCREMENTAL) {
    2593           0 :       ulong slot1, slot2;
    2594           0 :       if ( FD_LIKELY( sscanf( filename, "incremental-snapshot-%lu-%lu-", &slot1, &slot2 )==2 ) )
    2595           0 :         gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot2;
    2596           0 :       else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
    2597           0 :   } else if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_FULL) {
    2598           0 :       ulong slot1;
    2599           0 :       if ( FD_LIKELY( sscanf( filename, "snapshot-%lu-", &slot1 )==1 ) )
    2600           0 :         gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot1;
    2601           0 :       else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
    2602           0 :   }
    2603           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 );
    2604           0 : }
    2605             : 
    2606             : void
    2607             : fd_gui_stage_snapshot_manifest( fd_gui_t *                    gui,
    2608           0 :                                  fd_snapshot_manifest_t const * manifest ) {
    2609           0 :   ulong attempt = 0UL;
    2610           0 :   for( ulong i=0UL; i<manifest->hard_fork_cnt; i++ ) {
    2611           0 :     if( FD_UNLIKELY( manifest->hard_forks[ i ].slot==manifest->slot ) ) {
    2612           0 :       attempt = manifest->hard_forks[ i ].cnt;
    2613           0 :       break;
    2614           0 :     }
    2615           0 :   }
    2616           0 :   gui->summary.boot_progress.wfs_attempt = attempt;
    2617           0 : }
    2618             : 
    2619             : static void
    2620           0 : fd_gui_handle_reset_slot( fd_gui_t * gui, ulong reset_slot, long now ) {
    2621           0 :   FD_TEST( reset_slot!=ULONG_MAX );
    2622             : 
    2623             :   /* reset_slot has not changed */
    2624           0 :   if( FD_UNLIKELY( gui->summary.slot_completed!=ULONG_MAX && reset_slot==gui->summary.slot_completed ) ) return;
    2625             : 
    2626           0 :   ulong prev_slot_completed = gui->summary.slot_completed;
    2627           0 :   gui->summary.slot_completed = reset_slot;
    2628             : 
    2629           0 :   if( FD_LIKELY( fd_gui_get_slot( gui, gui->summary.slot_completed ) ) ) {
    2630           0 :     fd_gui_printf_slot( gui, gui->summary.slot_completed );
    2631           0 :     fd_http_server_ws_broadcast( gui->http );
    2632           0 :   }
    2633             : 
    2634           0 :   fd_gui_printf_completed_slot( gui );
    2635           0 :   fd_http_server_ws_broadcast( gui->http );
    2636             : 
    2637             :   /* Also update slot_turbine which could be larger than the max
    2638             :   turbine slot if we are leader */
    2639           0 :   if( FD_UNLIKELY( gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && gui->summary.slot_completed > gui->summary.slots_max_turbine[ 0 ].slot ) ) {
    2640           0 :     fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, gui->summary.slot_completed, now );
    2641           0 :   }
    2642             : 
    2643           0 :   int slot_turbine_hist_full = gui->summary.slots_max_turbine[ FD_GUI_TURBINE_SLOT_HISTORY_SZ-1UL ].slot!=ULONG_MAX;
    2644           0 :   if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX && slot_turbine_hist_full && gui->summary.slots_max_turbine[ 0 ].slot < (gui->summary.slot_completed + 3UL) ) ) {
    2645           0 :     gui->summary.slot_caught_up = gui->summary.slot_completed + 4UL;
    2646             : 
    2647           0 :     fd_gui_printf_slot_caught_up( gui );
    2648           0 :     fd_http_server_ws_broadcast( gui->http );
    2649           0 :   }
    2650             : 
    2651             :   /* ensure a history exists */
    2652           0 :   if( FD_UNLIKELY( prev_slot_completed==ULONG_MAX || gui->summary.slot_rooted==ULONG_MAX ) ) return;
    2653             : 
    2654             :   /* slot complete received out of order on the same fork? */
    2655           0 :   FD_TEST( fd_gui_slot_is_ancestor( gui, prev_slot_completed, gui->summary.slot_completed ) || !fd_gui_slot_is_ancestor( gui, gui->summary.slot_completed, prev_slot_completed ) );
    2656             : 
    2657             :   /* fork switch: we need to "undo" the previous fork */
    2658           0 :   int republish_skip_rate[ 2 ] = {0};
    2659           0 :   if( FD_UNLIKELY( !fd_gui_slot_is_ancestor( gui, prev_slot_completed, gui->summary.slot_completed ) ) ) {
    2660             :     /* The handling for skipped slot on a fork switch is tricky.  We
    2661             :         want to rebate back any slots that were skipped but are no
    2662             :         longer.  We also need to make sure we count skipped slots
    2663             :         towards the correct epoch. */
    2664           0 :     for( ulong slot=fd_ulong_max( gui->summary.slot_completed, prev_slot_completed); slot>gui->summary.slot_rooted; slot-- ) {
    2665             : 
    2666           0 :       int is_skipped_on_old_fork = slot<=prev_slot_completed         && fd_gui_is_skipped_on_fork( gui, gui->summary.slot_rooted, prev_slot_completed,         slot );
    2667           0 :       int is_skipped_on_new_fork = slot<=gui->summary.slot_completed && fd_gui_is_skipped_on_fork( gui, gui->summary.slot_rooted, gui->summary.slot_completed, slot );
    2668             : 
    2669           0 :       if( FD_LIKELY( is_skipped_on_old_fork && !is_skipped_on_new_fork ) ) {
    2670           0 :         fd_gui_slot_t * skipped = fd_gui_get_slot( gui, slot );
    2671           0 :         if( FD_LIKELY( !skipped ) ) {
    2672           0 :           fd_gui_slot_t * p = fd_gui_get_parent_slot_on_fork( gui, prev_slot_completed, slot );
    2673           0 :           skipped = fd_gui_clear_slot( gui, slot, p ? p->slot : ULONG_MAX );
    2674           0 :         }
    2675             : 
    2676           0 :         int was_skipped = skipped->skipped;
    2677           0 :         skipped->skipped = 0;
    2678           0 :         fd_gui_printf_slot( gui, skipped->slot );
    2679           0 :         fd_http_server_ws_broadcast( gui->http );
    2680           0 :         skipped->must_republish = 0;
    2681             : 
    2682           0 :         if( FD_LIKELY( was_skipped && skipped->mine ) ) {
    2683           0 :           for( ulong epoch=0UL; epoch<2UL; epoch++ ) {
    2684           0 :             if( FD_LIKELY( slot>=gui->epoch.epochs[ epoch ].start_slot && slot<=gui->epoch.epochs[ epoch ].end_slot ) ) {
    2685           0 :               gui->epoch.epochs[ epoch ].my_skipped_slots--;
    2686           0 :               republish_skip_rate[ epoch ] = 1;
    2687           0 :               break;
    2688           0 :             }
    2689           0 :           }
    2690           0 :         }
    2691           0 :       }
    2692             : 
    2693           0 :       if( FD_LIKELY( !is_skipped_on_old_fork && is_skipped_on_new_fork ) ) {
    2694           0 :         fd_gui_slot_t * skipped = fd_gui_get_slot( gui, slot );
    2695           0 :         if( FD_LIKELY( !skipped ) ) {
    2696           0 :           fd_gui_slot_t * p = fd_gui_get_parent_slot_on_fork( gui, prev_slot_completed, slot );
    2697           0 :           skipped = fd_gui_clear_slot( gui, slot, p ? p->slot : ULONG_MAX );
    2698           0 :         }
    2699             : 
    2700           0 :         int was_skipped = skipped->skipped;
    2701           0 :         skipped->skipped = 1;
    2702           0 :         fd_gui_printf_slot( gui, skipped->slot );
    2703           0 :         fd_http_server_ws_broadcast( gui->http );
    2704           0 :         skipped->must_republish = 0;
    2705             : 
    2706           0 :         if( FD_LIKELY( !was_skipped && skipped->mine ) ) {
    2707           0 :           for( ulong epoch=0UL; epoch<2UL; epoch++ ) {
    2708           0 :             if( FD_LIKELY( slot>=gui->epoch.epochs[ epoch ].start_slot && slot<=gui->epoch.epochs[ epoch ].end_slot ) ) {
    2709           0 :               gui->epoch.epochs[ epoch ].my_skipped_slots++;
    2710           0 :               republish_skip_rate[ epoch ] = 1;
    2711           0 :               break;
    2712           0 :             }
    2713           0 :           }
    2714           0 :         }
    2715           0 :       }
    2716           0 :     }
    2717           0 :   } else {
    2718             :     /* publish new skipped slots  */
    2719           0 :     fd_gui_slot_t * s = fd_gui_get_slot( gui, gui->summary.slot_completed );
    2720           0 :     while( s && s->slot>=prev_slot_completed ) {
    2721           0 :       fd_gui_slot_t * p = fd_gui_get_slot( gui, s->parent_slot );
    2722           0 :       if( FD_UNLIKELY( !p ) ) break;
    2723           0 :       for( ulong slot=p->slot+1; slot<s->slot; slot++ ) {
    2724           0 :         fd_gui_slot_t * skipped = fd_gui_get_slot( gui, slot );
    2725           0 :         if( FD_LIKELY( !skipped ) ) {
    2726           0 :           fd_gui_slot_t * p = fd_gui_get_parent_slot_on_fork( gui, gui->summary.slot_completed, slot );
    2727           0 :           skipped = fd_gui_clear_slot( gui, slot, p ? p->slot : ULONG_MAX );
    2728           0 :         }
    2729           0 :         if( FD_LIKELY( !skipped->skipped ) ) {
    2730           0 :           skipped->skipped = 1;
    2731           0 :           fd_gui_printf_slot( gui, skipped->slot );
    2732           0 :           fd_http_server_ws_broadcast( gui->http );
    2733           0 :           skipped->must_republish = 0;
    2734           0 :           if( FD_LIKELY( skipped->mine ) ) {
    2735           0 :             for( ulong epoch=0UL; epoch<2UL; epoch++ ) {
    2736           0 :               if( FD_LIKELY( slot>=gui->epoch.epochs[ epoch ].start_slot && slot<=gui->epoch.epochs[ epoch ].end_slot ) ) {
    2737           0 :                 gui->epoch.epochs[ epoch ].my_skipped_slots++;
    2738           0 :                 republish_skip_rate[ epoch ] = 1;
    2739           0 :                 break;
    2740           0 :               }
    2741           0 :             }
    2742           0 :           }
    2743           0 :         }
    2744           0 :       }
    2745           0 :       s = p;
    2746           0 :     }
    2747           0 :   }
    2748             : 
    2749           0 :   for( ulong i=0UL; i<2UL; i++ ) {
    2750           0 :     if( FD_LIKELY( republish_skip_rate[ i ] ) ) {
    2751           0 :       fd_gui_printf_skip_rate( gui, i );
    2752           0 :       fd_http_server_ws_broadcast( gui->http );
    2753           0 :     }
    2754           0 :   }
    2755           0 : }
    2756             : 
    2757             : #define SORT_NAME fd_gui_slot_staged_shred_event_slot_sort
    2758           0 : #define SORT_KEY_T fd_gui_slot_staged_shred_event_t
    2759           0 : #define SORT_BEFORE(a,b) (((a).slot<(b).slot) || (((a).slot==(b).slot) && ((a).timestamp<(b).timestamp)))
    2760             : #include "../../util/tmpl/fd_sort.c"
    2761             : 
    2762             : static void
    2763           0 : fd_gui_handle_rooted_slot( fd_gui_t * gui, ulong root_slot ) {
    2764           0 :   ulong epoch_idx   = fd_gui_current_epoch_idx( gui );
    2765           0 :   ulong epoch_start = ULONG_MAX;
    2766           0 :   ulong epoch_end   = ULONG_MAX;
    2767           0 :   if( FD_LIKELY( epoch_idx!=ULONG_MAX ) ) {
    2768           0 :     epoch_start = gui->epoch.epochs[ epoch_idx ].start_slot;
    2769           0 :     epoch_end   = gui->epoch.epochs[ epoch_idx ].end_slot;
    2770           0 :   }
    2771             : 
    2772             :   /* Epoch boundary */
    2773           0 :   if( FD_UNLIKELY( gui->summary.late_votes_sz && epoch_idx!=ULONG_MAX && ( epoch_start>gui->summary.late_votes[ 0 ] || epoch_end<gui->summary.late_votes[ 0 ] ) ) ) {
    2774           0 :     gui->summary.late_votes_sz = 0;
    2775           0 :   }
    2776             : 
    2777             :   /* Epoch boundary or startup -- backfill history */
    2778           0 :   if( FD_UNLIKELY( epoch_idx!=ULONG_MAX && gui->summary.late_votes_sz==0UL ) ) {
    2779           0 :     for( ulong s=epoch_start; s<fd_ulong_min( root_slot, epoch_start+FD_GUI_SLOTS_CNT ); s++ ) {
    2780           0 :       fd_gui_slot_t * slot = fd_gui_get_slot( gui, s );
    2781           0 :       if( FD_UNLIKELY( !slot || slot->level<FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
    2782             : 
    2783           0 :       int in_current_epoch = epoch_idx!=ULONG_MAX && epoch_start<=s && epoch_end>=s;
    2784           0 :       if( FD_UNLIKELY( in_current_epoch && ( ( !slot->skipped && slot->vote_latency==UCHAR_MAX ) || ( slot->vote_latency!=UCHAR_MAX && slot->vote_latency>1UL ) ) ) ) {
    2785           0 :         fd_gui_try_insert_run_length_slot( gui->summary.late_votes, MAX_SLOTS_PER_EPOCH, &gui->summary.late_votes_sz, s );
    2786           0 :       }
    2787           0 :     }
    2788           0 :   }
    2789             : 
    2790             :   /* start at the new root and move backwards towards the old root,
    2791             :      rooting everything in-between */
    2792           0 :   for( ulong i=0UL; i<fd_ulong_min( root_slot, FD_GUI_SLOTS_CNT ); i++ ) {
    2793           0 :     ulong parent_slot = root_slot - i;
    2794             : 
    2795           0 :     fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
    2796           0 :     if( FD_UNLIKELY( !slot ) ) break;
    2797             : 
    2798           0 :     if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
    2799           0 :       FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", root_slot, i, parent_slot, slot->slot ));
    2800           0 :     }
    2801             : 
    2802           0 :     int in_current_epoch = epoch_idx!=ULONG_MAX && epoch_start<=slot->slot && epoch_end>=slot->slot;
    2803           0 :     if( FD_UNLIKELY( in_current_epoch && ( ( !slot->skipped && slot->vote_latency==UCHAR_MAX ) || ( slot->vote_latency!=UCHAR_MAX && slot->vote_latency>1UL ) ) ) ) {
    2804           0 :       fd_gui_try_insert_run_length_slot( gui->summary.late_votes, MAX_SLOTS_PER_EPOCH, &gui->summary.late_votes_sz, slot->slot );
    2805           0 :     }
    2806             : 
    2807           0 :     if( FD_UNLIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
    2808             : 
    2809             :     /* change votes levels and rebroadcast */
    2810           0 :     slot->level = FD_GUI_SLOT_LEVEL_ROOTED;
    2811           0 :     fd_gui_printf_slot( gui, parent_slot );
    2812           0 :     fd_http_server_ws_broadcast( gui->http );
    2813           0 :   }
    2814             : 
    2815             :   /* archive root shred events.  We want to avoid n^2 iteration here
    2816             :      since it can significantly slow things down.  Instead, we copy
    2817             :      over all rooted shreds to a scratch space, sort by (slot,
    2818             :      timestamp) and copy the sorted arrays to the shred history. */
    2819           0 :   ulong archive_cnt          = 0UL;
    2820           0 :   ulong kept_cnt             = 0UL;
    2821           0 :   ulong kept_before_next_cnt = 0UL;
    2822             : 
    2823           0 :   for( ulong i=gui->shreds.staged_head; i<gui->shreds.staged_tail; i++ ) {
    2824           0 :     fd_gui_slot_staged_shred_event_t const * src = &gui->shreds.staged[ i % FD_GUI_SHREDS_STAGING_SZ ];
    2825             : 
    2826           0 :     if( FD_UNLIKELY( gui->shreds.history_slot!=ULONG_MAX && src->slot<=gui->shreds.history_slot ) ) continue;
    2827             : 
    2828           0 :     if( FD_UNLIKELY( src->slot<=root_slot ) ) {
    2829           0 :       if( FD_UNLIKELY( archive_cnt>=FD_GUI_SHREDS_STAGING_SZ ) ) continue;
    2830           0 :       gui->shreds._staged_scratch[ archive_cnt++ ] = *src;
    2831           0 :       continue;
    2832           0 :     }
    2833             : 
    2834           0 :     if( FD_UNLIKELY( i<gui->shreds.staged_next_broadcast ) ) kept_before_next_cnt++;
    2835           0 :     gui->shreds.staged[ (gui->shreds.staged_head + kept_cnt) % FD_GUI_SHREDS_STAGING_SZ ] = *src;
    2836           0 :     kept_cnt++;
    2837           0 :   }
    2838             : 
    2839           0 :   gui->shreds.staged_tail = gui->shreds.staged_head + kept_cnt;
    2840             :   /* Remap next_broadcast to preserve continuity after compaction */
    2841           0 :   gui->shreds.staged_next_broadcast = gui->shreds.staged_head + kept_before_next_cnt;
    2842             : 
    2843           0 :   if( FD_LIKELY( archive_cnt ) ) {
    2844           0 :     fd_gui_slot_staged_shred_event_slot_sort_inplace( gui->shreds._staged_scratch, archive_cnt );
    2845             : 
    2846           0 :     for( ulong i=0UL; i<archive_cnt; i++ ) {
    2847           0 :       if( FD_UNLIKELY( gui->shreds._staged_scratch[ i ].slot!=gui->shreds.history_slot ) ) {
    2848           0 :         fd_gui_slot_t * prev_slot = fd_gui_get_slot( gui, gui->shreds.history_slot );
    2849           0 :         if( FD_LIKELY( prev_slot ) ) prev_slot->shreds.end_offset = gui->shreds.history_tail;
    2850             : 
    2851           0 :         gui->shreds.history_slot = gui->shreds._staged_scratch[ i ].slot;
    2852             : 
    2853           0 :         fd_gui_slot_t * next_slot = fd_gui_get_slot( gui, gui->shreds.history_slot );
    2854           0 :         if( FD_LIKELY( next_slot ) ) next_slot->shreds.start_offset = gui->shreds.history_tail;
    2855           0 :       }
    2856             : 
    2857           0 :       gui->shreds.history[ gui->shreds.history_tail % FD_GUI_SHREDS_HISTORY_SZ ].timestamp = gui->shreds._staged_scratch[ i ].timestamp;
    2858           0 :       gui->shreds.history[ gui->shreds.history_tail % FD_GUI_SHREDS_HISTORY_SZ ].shred_idx = gui->shreds._staged_scratch[ i ].shred_idx;
    2859           0 :       gui->shreds.history[ gui->shreds.history_tail % FD_GUI_SHREDS_HISTORY_SZ ].event     = gui->shreds._staged_scratch[ i ].event;
    2860             : 
    2861           0 :       gui->shreds.history_tail++;
    2862           0 :     }
    2863           0 :   }
    2864             : 
    2865           0 :   gui->summary.slot_rooted = root_slot;
    2866           0 :   fd_gui_printf_root_slot( gui );
    2867           0 :   fd_http_server_ws_broadcast( gui->http );
    2868           0 : }
    2869             : 
    2870             : void
    2871             : fd_gui_handle_votes_update( fd_gui_t *                        gui,
    2872           0 :                                    fd_tower_slot_confirmed_t const * votes ) {
    2873           0 :   if( FD_UNLIKELY( votes->slot!=ULONG_MAX && gui->summary.slot_optimistically_confirmed!=votes->slot && votes->level==FD_TOWER_SLOT_CONFIRMED_OPTIMISTIC && !votes->fwd ) ) {
    2874           0 :     fd_gui_handle_optimistically_confirmed_slot( gui, votes->slot );
    2875           0 :   }
    2876           0 : }
    2877             : 
    2878             : static inline void
    2879           0 : try_publish_vote_status( fd_gui_t * gui, ulong _slot ) {
    2880           0 :   fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
    2881             : 
    2882             :   /* For unstaked nodes, slot->vote_slot will always be ULONG_MAX */
    2883           0 :   if( FD_UNLIKELY( !slot || slot->vote_slot==ULONG_MAX || slot->reset_slot==ULONG_MAX ) ) return;
    2884             : 
    2885           0 :   ulong vote_distance = slot->reset_slot-slot->vote_slot;
    2886           0 :   if( FD_LIKELY( vote_distance<FD_GUI_SLOTS_CNT ) ) {
    2887           0 :     for( ulong s=slot->vote_slot; s<slot->reset_slot; s++ ) {
    2888           0 :       fd_gui_slot_t * cur = fd_gui_get_slot( gui, s );
    2889           0 :       if( FD_UNLIKELY( cur && cur->skipped ) ) vote_distance--;
    2890           0 :     }
    2891           0 :   }
    2892             : 
    2893           0 :   if( FD_UNLIKELY( gui->summary.vote_distance!=vote_distance ) ) {
    2894           0 :     gui->summary.vote_distance = vote_distance;
    2895           0 :     fd_gui_printf_vote_distance( gui );
    2896           0 :     fd_http_server_ws_broadcast( gui->http );
    2897           0 :   }
    2898             : 
    2899           0 :   if( FD_LIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_NON_VOTING ) ) {
    2900           0 :     if( FD_UNLIKELY( slot->vote_slot==ULONG_MAX || vote_distance>150UL ) ) {
    2901           0 :       if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_DELINQUENT ) ) {
    2902           0 :         gui->summary.vote_state = FD_GUI_VOTE_STATE_DELINQUENT;
    2903           0 :         fd_gui_printf_vote_state( gui );
    2904           0 :         fd_http_server_ws_broadcast( gui->http );
    2905           0 :       }
    2906           0 :     } else {
    2907           0 :       if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_VOTING ) ) {
    2908           0 :         gui->summary.vote_state = FD_GUI_VOTE_STATE_VOTING;
    2909           0 :         fd_gui_printf_vote_state( gui );
    2910           0 :         fd_http_server_ws_broadcast( gui->http );
    2911           0 :       }
    2912           0 :     }
    2913           0 :   }
    2914           0 : }
    2915             : 
    2916             : /* fd_gui_handle_tower_update handles updates from the tower tile, which
    2917             :    manages consensus related fork switching, rooting, slot confirmation. */
    2918             : void
    2919             : fd_gui_handle_tower_update( fd_gui_t *                   gui,
    2920             :                             fd_tower_slot_done_t const * tower,
    2921           0 :                             long                         now ) {
    2922           0 :   (void)now;
    2923             : 
    2924           0 :   if( FD_UNLIKELY( tower->active_fork_cnt!=gui->summary.active_fork_cnt ) ) {
    2925           0 :     gui->summary.active_fork_cnt = tower->active_fork_cnt;
    2926           0 :     fd_gui_printf_active_fork_cnt( gui );
    2927           0 :     fd_http_server_ws_broadcast( gui->http );
    2928           0 :   }
    2929             : 
    2930           0 :   fd_gui_slot_t * slot = fd_gui_get_slot( gui, tower->replay_slot );
    2931           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, tower->replay_slot, ULONG_MAX );
    2932           0 :   slot->reset_slot = tower->reset_slot;
    2933             : 
    2934           0 :   try_publish_vote_status( gui, tower->replay_slot );
    2935             : 
    2936           0 :   if( FD_LIKELY( gui->summary.slot_reset!=tower->reset_slot ) ) {
    2937           0 :     gui->summary.slot_reset = tower->reset_slot;
    2938           0 :     fd_gui_printf_reset_slot( gui );
    2939           0 :     fd_http_server_ws_broadcast( gui->http );
    2940           0 :   }
    2941             : 
    2942           0 :   if( FD_UNLIKELY( tower->vote_acct_bal!=ULONG_MAX && gui->summary.vote_account_balance!=tower->vote_acct_bal ) ) {
    2943           0 :     gui->summary.vote_account_balance = tower->vote_acct_bal;
    2944           0 :     fd_gui_printf_vote_balance( gui );
    2945           0 :     fd_http_server_ws_broadcast( gui->http );
    2946           0 :   }
    2947             : 
    2948             :   /* update slot history vote latencies with new votes */
    2949           0 :   for( ulong i=0UL; i<tower->tower_cnt; i++ ) {
    2950           0 :     fd_gui_slot_t * slot = fd_gui_get_slot( gui, tower->tower[ i ].slot );
    2951           0 :     if( FD_UNLIKELY( slot && slot->vote_latency!=tower->tower[ i ].latency ) ) {
    2952           0 :       slot->vote_latency = tower->tower[ i ].latency;
    2953           0 :       fd_gui_printf_slot( gui, slot->slot );
    2954           0 :       fd_http_server_ws_broadcast( gui->http );
    2955           0 :     }
    2956           0 :     if( FD_UNLIKELY( i+1UL>=tower->tower_cnt ) ) break;
    2957           0 :     for( ulong s=tower->tower[ i ].slot+1UL; s<tower->tower[ i+1 ].slot; s++ ) {
    2958           0 :       fd_gui_slot_t * slot = fd_gui_get_slot( gui, s );
    2959           0 :       if( FD_LIKELY( slot && slot->vote_latency!=UCHAR_MAX ) ) {
    2960           0 :         slot->vote_latency = UCHAR_MAX;
    2961           0 :         fd_gui_printf_slot( gui, slot->slot );
    2962           0 :         fd_http_server_ws_broadcast( gui->http );
    2963           0 :       }
    2964           0 :     }
    2965           0 :   }
    2966           0 : }
    2967             : 
    2968             : void
    2969             : fd_gui_handle_replay_update( fd_gui_t *                         gui,
    2970             :                              fd_replay_slot_completed_t const * slot_completed,
    2971             :                              ulong                              vote_slot,
    2972           0 :                              long                               now ) {
    2973           0 :   (void)now;
    2974             : 
    2975           0 :   if( FD_LIKELY( slot_completed->root_slot!=ULONG_MAX && gui->summary.slot_rooted!=slot_completed->root_slot ) ) {
    2976           0 :     fd_gui_handle_rooted_slot( gui, slot_completed->root_slot );
    2977           0 :   }
    2978             : 
    2979           0 :   if( FD_LIKELY( gui->summary.slot_storage!=slot_completed->storage_slot ) ) {
    2980           0 :     gui->summary.slot_storage = slot_completed->storage_slot;
    2981           0 :     fd_gui_printf_storage_slot( gui );
    2982           0 :     fd_http_server_ws_broadcast( gui->http );
    2983           0 :   }
    2984             : 
    2985           0 :   if( FD_UNLIKELY( slot_completed->identity_balance!=ULONG_MAX && gui->summary.identity_account_balance!=slot_completed->identity_balance ) ) {
    2986           0 :     gui->summary.identity_account_balance = slot_completed->identity_balance;
    2987             : 
    2988           0 :     fd_gui_printf_identity_balance( gui );
    2989           0 :     fd_http_server_ws_broadcast( gui->http );
    2990           0 :   }
    2991             : 
    2992           0 :   if( FD_UNLIKELY( gui->summary.boot_progress.catching_up_first_replay_slot==ULONG_MAX ) ) {
    2993           0 :     gui->summary.boot_progress.catching_up_first_replay_slot = slot_completed->slot;
    2994           0 :   }
    2995             : 
    2996           0 :   fd_gui_slot_t * slot = fd_gui_get_slot( gui, slot_completed->slot );
    2997           0 :   if( FD_UNLIKELY( slot ) ) {
    2998             :     /* Its possible that this slot was labeled as skipped by another
    2999             :        consensus fork at some point in the past. In this case no need to
    3000             :        clear it, but we should update parent_slot */
    3001           0 :        slot->parent_slot = slot_completed->parent_slot;
    3002           0 :   } else {
    3003           0 :     slot = fd_gui_clear_slot( gui, slot_completed->slot, slot_completed->parent_slot );
    3004           0 :   }
    3005             : 
    3006           0 :   if( FD_UNLIKELY( slot->mine ) ) {
    3007           0 :     fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, slot->slot );
    3008           0 :     if( FD_LIKELY( lslot ) ) fd_memcpy( lslot->block_hash.uc, slot_completed->block_hash.uc, sizeof(fd_hash_t) );
    3009           0 :   }
    3010             : 
    3011           0 :   slot->completed_time    = slot_completed->completion_time_nanos;
    3012           0 :   slot->parent_slot       = slot_completed->parent_slot;
    3013           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 );
    3014           0 :   if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_COMPLETED ) ) {
    3015             :     /* Typically a slot goes from INCOMPLETE to COMPLETED but it can
    3016             :        happen that it starts higher.  One such case is when we
    3017             :        optimistically confirm a higher slot that skips this one, but
    3018             :        then later we replay this one anyway to track the bank fork. */
    3019             : 
    3020           0 :     if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && slot->slot<gui->summary.slot_optimistically_confirmed ) ) {
    3021             :       /* Cluster might have already optimistically confirmed by the time
    3022             :          we finish replaying it. */
    3023           0 :       slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
    3024           0 :     } else {
    3025           0 :       slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
    3026           0 :     }
    3027           0 :   }
    3028           0 :   slot->vote_failed     = fd_uint_if( slot_completed->vote_failed==ULONG_MAX,     slot->vote_failed,     (uint)slot_completed->vote_failed     );
    3029           0 :   slot->vote_success    = fd_uint_if( slot_completed->vote_success==ULONG_MAX,    slot->vote_success,    (uint)slot_completed->vote_success    );
    3030           0 :   slot->nonvote_success = fd_uint_if( slot_completed->nonvote_success==ULONG_MAX, slot->nonvote_success, (uint)slot_completed->nonvote_success );
    3031           0 :   slot->nonvote_failed  = fd_uint_if( slot_completed->nonvote_failed==ULONG_MAX,  slot->nonvote_failed,  (uint)slot_completed->nonvote_failed  );
    3032             : 
    3033           0 :   slot->transaction_fee        = slot_completed->transaction_fee;
    3034           0 :   slot->priority_fee           = slot_completed->priority_fee;
    3035           0 :   slot->tips                   = slot_completed->tips;
    3036           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 );
    3037           0 :   slot->shred_cnt              = fd_uint_if( slot_completed->shred_cnt==ULONG_MAX, slot->shred_cnt, (uint)slot_completed->shred_cnt );
    3038           0 :   slot->vote_slot              = vote_slot;
    3039             : 
    3040           0 :   try_publish_vote_status( gui, slot_completed->slot );
    3041             : 
    3042           0 :   if( FD_UNLIKELY( gui->epoch.has_epoch[ 0 ] && slot->slot==gui->epoch.epochs[ 0 ].end_slot ) ) {
    3043           0 :     gui->epoch.epochs[ 0 ].end_time = slot->completed_time;
    3044           0 :   } else if( FD_UNLIKELY( gui->epoch.has_epoch[ 1 ] && slot->slot==gui->epoch.epochs[ 1 ].end_slot ) ) {
    3045           0 :     gui->epoch.epochs[ 1 ].end_time = slot->completed_time;
    3046           0 :   }
    3047             : 
    3048             :   /* Broadcast new skip rate if one of our slots got completed. */
    3049           0 :   if( FD_LIKELY( slot->mine ) ) {
    3050           0 :     for( ulong i=0UL; i<2UL; i++ ) {
    3051           0 :       if( FD_LIKELY( slot->slot>=gui->epoch.epochs[ i ].start_slot && slot->slot<=gui->epoch.epochs[ i ].end_slot ) ) {
    3052           0 :         fd_gui_printf_skip_rate( gui, i );
    3053           0 :         fd_http_server_ws_broadcast( gui->http );
    3054           0 :         break;
    3055           0 :       }
    3056           0 :     }
    3057           0 :   }
    3058             : 
    3059             :   /* We'll treat the latest slot_complete from replay as the reset slot.
    3060             :      We get an explicit reset_slot from tower, but that message may come
    3061             :      in before we get the slot_complete from replay. */
    3062           0 :   if( FD_UNLIKELY( gui->summary.slot_completed!=slot->slot ) ) {
    3063           0 :     fd_gui_handle_reset_slot( gui, slot->slot, now );
    3064           0 :   }
    3065             : 
    3066             :   /* Add a "slot complete" event for all of the shreds in this slot */
    3067           0 :   if( FD_UNLIKELY( slot->shred_cnt > FD_GUI_MAX_SHREDS_PER_BLOCK ) ) FD_LOG_ERR(( "unexpected shred_cnt=%lu", (ulong)slot->shred_cnt ));
    3068           0 :   fd_gui_slot_staged_shred_event_t * slot_complete_event = fd_gui_staged_push( gui );
    3069           0 :   slot_complete_event->event     = FD_GUI_SLOT_SHRED_SHRED_SLOT_COMPLETE;
    3070           0 :   slot_complete_event->timestamp = slot_completed->completion_time_nanos;
    3071           0 :   slot_complete_event->shred_idx = USHORT_MAX;
    3072           0 :   slot_complete_event->slot      = slot->slot;
    3073             : 
    3074             :   /* addresses racey behavior if we just sample at 400ms */
    3075           0 :   if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
    3076           0 :     fd_topo_tile_t * repair = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "repair", 0UL ) ];
    3077           0 :     volatile ulong const * repair_metrics = fd_metrics_tile( repair->metrics );
    3078           0 :     ulong slot = repair_metrics[ MIDX( COUNTER, REPAIR, REPAIRED_SLOTS ) ];
    3079           0 :     fd_gui_handle_repair_slot( gui, slot, now );
    3080           0 :   }
    3081           0 : }
    3082             : 
    3083             : void
    3084             : fd_gui_plugin_message( fd_gui_t *   gui,
    3085             :                        ulong        plugin_msg,
    3086             :                        void const * msg,
    3087           0 :                        long         now ) {
    3088             : 
    3089           0 :   switch( plugin_msg ) {
    3090           0 :     case FD_PLUGIN_MSG_SLOT_ROOTED:
    3091           0 :       fd_gui_handle_rooted_slot_legacy( gui, msg );
    3092           0 :       break;
    3093           0 :     case FD_PLUGIN_MSG_SLOT_OPTIMISTICALLY_CONFIRMED:
    3094           0 :       fd_gui_handle_optimistically_confirmed_slot( gui, FD_LOAD( ulong, msg ) );
    3095           0 :       break;
    3096           0 :     case FD_PLUGIN_MSG_SLOT_COMPLETED: {
    3097           0 :       fd_gui_handle_completed_slot( gui, msg, now );
    3098           0 :       break;
    3099           0 :     }
    3100           0 :     case FD_PLUGIN_MSG_LEADER_SCHEDULE: {
    3101           0 :       FD_STATIC_ASSERT( sizeof(fd_stake_weight_msg_t)==6*sizeof(ulong), "new fields breaks things" );
    3102           0 :       fd_gui_handle_leader_schedule( gui, (fd_stake_weight_msg_t *)msg, now );
    3103           0 :       break;
    3104           0 :     }
    3105           0 :     case FD_PLUGIN_MSG_SLOT_START: {
    3106           0 :       ulong slot = FD_LOAD( ulong, msg );
    3107           0 :       ulong parent_slot = FD_LOAD( ulong, (uchar const *)msg + 8UL );
    3108           0 :       fd_gui_handle_slot_start( gui, slot, parent_slot, now );
    3109           0 :       break;
    3110           0 :     }
    3111           0 :     case FD_PLUGIN_MSG_SLOT_END: {
    3112           0 :       ulong slot = FD_LOAD( ulong, msg );
    3113           0 :       ulong cus_used = FD_LOAD( ulong, (uchar const *)msg + 8UL );
    3114           0 :       fd_gui_handle_slot_end( gui, slot, cus_used, now );
    3115           0 :       break;
    3116           0 :     }
    3117           0 :     case FD_PLUGIN_MSG_GOSSIP_UPDATE: {
    3118           0 :       fd_gui_handle_gossip_update( gui, msg );
    3119           0 :       break;
    3120           0 :     }
    3121           0 :     case FD_PLUGIN_MSG_VOTE_ACCOUNT_UPDATE: {
    3122           0 :       fd_gui_handle_vote_account_update( gui, msg );
    3123           0 :       break;
    3124           0 :     }
    3125           0 :     case FD_PLUGIN_MSG_VALIDATOR_INFO: {
    3126           0 :       fd_gui_handle_validator_info_update( gui, msg );
    3127           0 :       break;
    3128           0 :     }
    3129           0 :     case FD_PLUGIN_MSG_SLOT_RESET: {
    3130           0 :       fd_gui_handle_reset_slot_legacy( gui, msg, now );
    3131           0 :       break;
    3132           0 :     }
    3133           0 :     case FD_PLUGIN_MSG_BALANCE: {
    3134           0 :       fd_gui_handle_balance_update( gui, msg );
    3135           0 :       break;
    3136           0 :     }
    3137           0 :     case FD_PLUGIN_MSG_START_PROGRESS: {
    3138           0 :       fd_gui_handle_start_progress( gui, msg );
    3139           0 :       break;
    3140           0 :     }
    3141           0 :     case FD_PLUGIN_MSG_GENESIS_HASH_KNOWN: {
    3142           0 :       fd_gui_handle_genesis_hash( gui, msg );
    3143           0 :       break;
    3144           0 :     }
    3145           0 :     default:
    3146           0 :       FD_LOG_ERR(( "Unhandled plugin msg: 0x%lx", plugin_msg ));
    3147           0 :       break;
    3148           0 :   }
    3149           0 : }
    3150             : 
    3151             : void
    3152             : fd_gui_became_leader( fd_gui_t * gui,
    3153             :                       ulong      _slot,
    3154             :                       long       start_time_nanos,
    3155             :                       long       end_time_nanos,
    3156             :                       ulong      max_compute_units,
    3157           0 :                       ulong      max_microblocks ) {
    3158           0 :   if( FD_LIKELY( gui->summary.is_full_client && gui->leader_slot!=ULONG_MAX ) ) {
    3159             :     /* stop sampling for other leader slot in progress */
    3160           0 :     fd_gui_handle_slot_end( gui, gui->leader_slot, ULONG_MAX, start_time_nanos );
    3161           0 :   }
    3162             : 
    3163           0 :   fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
    3164           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
    3165           0 :   fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
    3166           0 :   if( FD_UNLIKELY( !lslot ) ) return;
    3167             : 
    3168           0 :   slot->max_compute_units = (uint)max_compute_units;
    3169           0 :   lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, start_time_nanos, lslot->leader_start_time );
    3170           0 :   lslot->leader_end_time   = end_time_nanos;
    3171           0 :   if( FD_LIKELY( lslot->txs.microblocks_upper_bound==USHORT_MAX ) ) lslot->txs.microblocks_upper_bound = (ushort)max_microblocks;
    3172             : 
    3173           0 :   if( FD_UNLIKELY( gui->summary.is_full_client ) ) fd_gui_handle_slot_start( gui, slot->slot, slot->parent_slot, start_time_nanos );
    3174           0 : }
    3175             : 
    3176             : void
    3177             : fd_gui_unbecame_leader( fd_gui_t *                gui,
    3178             :                         ulong                     _slot,
    3179             :                         fd_done_packing_t const * done_packing,
    3180           0 :                         long                      now ) {
    3181           0 :   fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
    3182           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
    3183           0 :   fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
    3184           0 :   if( FD_LIKELY( !lslot ) ) return;
    3185           0 :   lslot->txs.microblocks_upper_bound = (uint)done_packing->microblocks_in_slot;
    3186           0 :   fd_memcpy( lslot->scheduler_stats, done_packing, sizeof(fd_done_packing_t) );
    3187             : 
    3188             :   /* fd_gui_handle_slot_end may have already been called in response to
    3189             :      a "became_leader" message for a subseqeunt slot. */
    3190           0 :   if( FD_UNLIKELY( gui->summary.is_full_client && gui->leader_slot==_slot ) ) fd_gui_handle_slot_end( gui, slot->slot, ULONG_MAX, now );
    3191             : 
    3192           0 :   lslot->unbecame_leader = 1;
    3193           0 : }
    3194             : 
    3195             : void
    3196             : fd_gui_microblock_execution_begin( fd_gui_t *   gui,
    3197             :                                    long         now,
    3198             :                                    ulong        _slot,
    3199             :                                    fd_txn_e_t * txns,
    3200             :                                    ulong        txn_cnt,
    3201             :                                    uint         microblock_idx,
    3202           0 :                                    ulong        pack_txn_idx ) {
    3203           0 :   fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
    3204           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
    3205             : 
    3206           0 :   fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
    3207           0 :   if( FD_UNLIKELY( !lslot ) ) return;
    3208             : 
    3209           0 :   lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, now, lslot->leader_start_time );
    3210             : 
    3211           0 :   if( FD_UNLIKELY( lslot->txs.start_offset==ULONG_MAX ) ) lslot->txs.start_offset = pack_txn_idx;
    3212           0 :   else                                                    lslot->txs.start_offset = fd_ulong_min( lslot->txs.start_offset, pack_txn_idx );
    3213             : 
    3214           0 :   gui->pack_txn_idx = fd_ulong_max( gui->pack_txn_idx, pack_txn_idx+txn_cnt-1UL );
    3215             : 
    3216           0 :   for( ulong i=0UL; i<txn_cnt; i++ ) {
    3217           0 :     fd_txn_p_t * txn_payload = txns[ i ].txnp;
    3218           0 :     fd_txn_t * txn = TXN( txn_payload );
    3219             : 
    3220           0 :     ulong sig_rewards = FD_PACK_FEE_PER_SIGNATURE * txn->signature_cnt;
    3221           0 :     ulong priority_rewards                    = ULONG_MAX;
    3222           0 :     ulong requested_execution_cus             = ULONG_MAX;
    3223           0 :     ulong precompile_sigs                     = ULONG_MAX;
    3224           0 :     ulong requested_loaded_accounts_data_cost = ULONG_MAX;
    3225           0 :     ulong allocated_data                      = ULONG_MAX;
    3226           0 :     uint _flags;
    3227           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 );
    3228           0 :     sig_rewards += FD_PACK_FEE_PER_SIGNATURE * precompile_sigs;
    3229           0 :     sig_rewards = sig_rewards * FD_PACK_TXN_FEE_BURN_PCT / 100UL;
    3230             : 
    3231           0 :     fd_gui_txn_t * txn_entry = gui->txs[ (pack_txn_idx + i)%FD_GUI_TXN_HISTORY_SZ ];
    3232             : 
    3233             :     /* If execution_end already ran for this txn, the arrival timestamp
    3234             :        it stamped will match.  Preserve all existing flags. Otherwise
    3235             :        the entry is stale from a ring buffer wrap-around, so clear all
    3236             :        flags. */
    3237           0 :     if( FD_LIKELY( txn_entry->timestamp_arrival_nanos!=txn_payload->scheduler_arrival_time_nanos ) ) txn_entry->flags = (uchar)0;
    3238             : 
    3239           0 :     fd_memcpy( txn_entry->signature, txn_payload->payload + txn->signature_off, FD_SHA512_HASH_SZ );
    3240           0 :     txn_entry->timestamp_arrival_nanos     = txn_payload->scheduler_arrival_time_nanos;
    3241           0 :     txn_entry->compute_units_requested     = cost_estimate & 0x1FFFFFU;
    3242           0 :     txn_entry->priority_fee                = priority_rewards;
    3243           0 :     txn_entry->transaction_fee             = sig_rewards;
    3244           0 :     txn_entry->timestamp_delta_start_nanos = (int)(now - lslot->leader_start_time);
    3245           0 :     txn_entry->source_ipv4                 = txn_payload->source_ipv4;
    3246           0 :     txn_entry->source_tpu                  = txn_payload->source_tpu;
    3247           0 :     txn_entry->microblock_idx              = microblock_idx;
    3248           0 :     txn_entry->flags                      |= (uchar)FD_GUI_TXN_FLAGS_STARTED;
    3249           0 :     txn_entry->flags                      |= (uchar)fd_uint_if( !!(txn_payload->flags & FD_TXN_P_FLAGS_IS_SIMPLE_VOTE), FD_GUI_TXN_FLAGS_IS_SIMPLE_VOTE, 0U );
    3250           0 :     txn_entry->flags                      |= (uchar)fd_uint_if( (txn_payload->flags & FD_TXN_P_FLAGS_BUNDLE) || (txn_payload->flags & FD_TXN_P_FLAGS_INITIALIZER_BUNDLE), FD_GUI_TXN_FLAGS_FROM_BUNDLE, 0U );
    3251           0 :   }
    3252             : 
    3253             :   /* At the moment, bank publishes at most 1 transaction per microblock,
    3254             :      even if it received microblocks with multiple transactions
    3255             :      (i.e. a bundle). This means that we need to calculate microblock
    3256             :      count here based on the transaction count. */
    3257           0 :   lslot->txs.begin_microblocks += (uint)txn_cnt;
    3258           0 : }
    3259             : 
    3260             : void
    3261             : fd_gui_microblock_execution_end( fd_gui_t *   gui,
    3262             :                                  long         now,
    3263             :                                  ulong        bank_idx,
    3264             :                                  ulong        _slot,
    3265             :                                  ulong        txn_cnt,
    3266             :                                  fd_txn_p_t * txns,
    3267             :                                  ulong        pack_txn_idx,
    3268             :                                  uchar        txn_start_pct,
    3269             :                                  uchar        txn_load_end_pct,
    3270             :                                  uchar        txn_end_pct,
    3271             :                                  uchar        txn_preload_end_pct,
    3272           0 :                                  ulong        tips ) {
    3273           0 :   if( FD_UNLIKELY( 1UL!=txn_cnt ) ) FD_LOG_ERR(( "gui expects 1 txn per microblock from bank, found %lu", txn_cnt ));
    3274             : 
    3275           0 :   fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
    3276           0 :   if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
    3277             : 
    3278           0 :   fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
    3279           0 :   if( FD_UNLIKELY( !lslot ) ) return;
    3280             : 
    3281           0 :   lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, now, lslot->leader_start_time );
    3282             : 
    3283           0 :   if( FD_UNLIKELY( lslot->txs.end_offset==ULONG_MAX ) ) lslot->txs.end_offset = pack_txn_idx + txn_cnt;
    3284           0 :   else                                                  lslot->txs.end_offset = fd_ulong_max( lslot->txs.end_offset, pack_txn_idx+txn_cnt );
    3285             : 
    3286           0 :   gui->pack_txn_idx = fd_ulong_max( gui->pack_txn_idx, pack_txn_idx+txn_cnt-1UL );
    3287             : 
    3288           0 :   for( ulong i=0UL; i<txn_cnt; i++ ) {
    3289           0 :     fd_txn_p_t * txn_p = &txns[ i ];
    3290             : 
    3291           0 :     fd_gui_txn_t * txn_entry = gui->txs[ (pack_txn_idx + i)%FD_GUI_TXN_HISTORY_SZ ];
    3292             : 
    3293             :     /* If execution_begin already ran for this txn, the arrival
    3294             :        timestamp it stamped will match.  Preserve all existing flags.
    3295             :        Otherwise the entry is stale from a ring buffer wrap-around, so
    3296             :        clear all flags. */
    3297           0 :     if( FD_UNLIKELY( txn_entry->timestamp_arrival_nanos!=txn_p->scheduler_arrival_time_nanos ) ) txn_entry->flags = (uchar)0;
    3298             : 
    3299           0 :     txn_entry->timestamp_arrival_nanos   = txn_p->scheduler_arrival_time_nanos;
    3300           0 :     txn_entry->bank_idx                  = bank_idx                             & 0x3FU;
    3301           0 :     txn_entry->compute_units_consumed    = txn_p->execle_cu.actual_consumed_cus & 0x1FFFFFU;
    3302           0 :     txn_entry->error_code                = (txn_p->flags >> 24)                 & 0x3FU;
    3303           0 :     txn_entry->timestamp_delta_end_nanos = (int)(now - lslot->leader_start_time);
    3304           0 :     txn_entry->txn_start_pct             = txn_start_pct;
    3305           0 :     txn_entry->txn_load_end_pct          = txn_load_end_pct;
    3306           0 :     txn_entry->txn_end_pct               = txn_end_pct;
    3307           0 :     txn_entry->txn_preload_end_pct       = txn_preload_end_pct;
    3308           0 :     txn_entry->tips                      = tips;
    3309           0 :     txn_entry->flags                    |= (uchar)FD_GUI_TXN_FLAGS_ENDED;
    3310           0 :     txn_entry->flags                    &= (uchar)(~(uchar)FD_GUI_TXN_FLAGS_LANDED_IN_BLOCK);
    3311           0 :     txn_entry->flags                    |= (uchar)fd_uint_if( !!(txn_p->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS), FD_GUI_TXN_FLAGS_LANDED_IN_BLOCK, 0U );
    3312           0 :   }
    3313             : 
    3314           0 :   lslot->txs.end_microblocks = lslot->txs.end_microblocks + (uint)txn_cnt;
    3315           0 : }

Generated by: LCOV version 1.14