LCOV - code coverage report
Current view: top level - disco/gui - fd_gui.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 2235 0.0 %
Date: 2025-12-05 04:49:52 Functions: 0 58 0.0 %

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

Generated by: LCOV version 1.14