LCOV - code coverage report
Current view: top level - disco/gui - fd_gui_printf.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 2467 0.0 %
Date: 2026-08-13 04:56:22 Functions: 0 96 0.0 %

          Line data    Source code
       1             : #include "fd_gui_printf.h"
       2             : #include "fd_gui_config_parse.h"
       3             : #include "fd_gui_hist.h"
       4             : 
       5             : #include "../bundle/fd_bundle_tile.h"
       6             : #include "../diag/fd_diag_tile.h"
       7             : #include "../../waltz/http/fd_http_server_private.h"
       8             : #include "../../ballet/utf8/fd_utf8.h"
       9             : #include "../../disco/fd_txn_m.h"
      10             : #include "../../disco/metrics/fd_metrics.h"
      11             : #include "../../disco/topo/fd_topob.h"
      12             : 
      13             : static void
      14           0 : jsonp_strip_trailing_comma( fd_http_server_t * http ) {
      15           0 :   if( FD_LIKELY( !http->stage_err &&
      16           0 :                  http->stage_len>=1UL &&
      17           0 :                  http->oring[ (http->stage_off%http->oring_sz)+http->stage_len-1UL ]==(uchar)',' ) ) {
      18           0 :     http->stage_len--;
      19           0 :   }
      20           0 : }
      21             : 
      22             : static void
      23             : jsonp_open_object( fd_http_server_t * http,
      24           0 :                    char const *       key ) {
      25           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":{", key );
      26           0 :   else                   fd_http_server_printf( http, "{" );
      27           0 : }
      28             : 
      29             : static void
      30           0 : jsonp_close_object( fd_http_server_t * http ) {
      31           0 :   jsonp_strip_trailing_comma( http );
      32           0 :   fd_http_server_printf( http, "}," );
      33           0 : }
      34             : 
      35             : static void
      36             : jsonp_open_array( fd_http_server_t * http,
      37           0 :                   char const *       key ) {
      38           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":[", key );
      39           0 :   else                   fd_http_server_printf( http, "[" );
      40           0 : }
      41             : 
      42             : static void
      43           0 : jsonp_close_array( fd_http_server_t * http ) {
      44           0 :   jsonp_strip_trailing_comma( http );
      45           0 :   fd_http_server_printf( http, "]," );
      46           0 : }
      47             : 
      48             : static void
      49             : jsonp_ulong( fd_http_server_t * http,
      50             :              char const *       key,
      51           0 :              ulong              value ) {
      52           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":%lu,", key, value );
      53           0 :   else                   fd_http_server_printf( http, "%lu,", value );
      54           0 : }
      55             : 
      56             : static void
      57             : jsonp_long( fd_http_server_t * http,
      58             :             char const *       key,
      59           0 :             long               value ) {
      60           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":%ld,", key, value );
      61           0 :   else                   fd_http_server_printf( http, "%ld,", value );
      62           0 : }
      63             : 
      64             : static void
      65             : jsonp_double( fd_http_server_t * http,
      66             :               char const *       key,
      67           0 :               double             value ) {
      68           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":%.2f,", key, value );
      69           0 :   else                   fd_http_server_printf( http, "%.2f,", value );
      70           0 : }
      71             : 
      72             : static void
      73             : jsonp_double_4dp( fd_http_server_t * http,
      74             :                   char const *       key,
      75           0 :                   double             value ) {
      76           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":%.4f,", key, value );
      77           0 :   else                   fd_http_server_printf( http, "%.4f,", value );
      78           0 : }
      79             : 
      80             : static void
      81             : jsonp_ulong_as_str( fd_http_server_t * http,
      82             :                     char const *       key,
      83           0 :                     ulong              value ) {
      84           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":\"%lu\",", key, value );
      85           0 :   else                   fd_http_server_printf( http, "\"%lu\",", value );
      86           0 : }
      87             : 
      88             : static void
      89             : jsonp_long_as_str( fd_http_server_t * http,
      90             :                    char const *       key,
      91           0 :                    long               value ) {
      92           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":\"%ld\",", key, value );
      93           0 :   else                   fd_http_server_printf( http, "\"%ld\",", value );
      94           0 : }
      95             : 
      96             : static void
      97             : jsonp_sanitize_str( fd_http_server_t * http,
      98           0 :                     ulong              start_len ) {
      99             :   /* escape quotemark, reverse solidus, and control chars U+0000 through U+001F
     100             :      just replace with a space */
     101           0 :   uchar * data = http->oring;
     102           0 :   for( ulong i=start_len; i<http->stage_len; i++ ) {
     103           0 :     if( FD_UNLIKELY( data[ (http->stage_off%http->oring_sz)+i ] < 0x20 ||
     104           0 :                      data[ (http->stage_off%http->oring_sz)+i ] == '"' ||
     105           0 :                      data[ (http->stage_off%http->oring_sz)+i ] == '\\' ) ) {
     106           0 :       data[ (http->stage_off%http->oring_sz)+i ] = ' ';
     107           0 :     }
     108           0 :   }
     109           0 : }
     110             : 
     111             : static void
     112             : jsonp_string( fd_http_server_t * http,
     113             :               char const *       key,
     114           0 :               char const *       value ) {
     115           0 :   char * val = (void *)value;
     116           0 :   if( FD_LIKELY( value ) ) {
     117           0 :     if( FD_UNLIKELY( !fd_utf8_verify( value, strlen( value ) ) )) {
     118           0 :       val = NULL;
     119           0 :     }
     120           0 :   }
     121           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":", key );
     122           0 :   if( FD_LIKELY( val ) ) {
     123           0 :     fd_http_server_printf( http, "\"" );
     124           0 :     ulong start_len = http->stage_len;
     125           0 :     fd_http_server_printf( http, "%s", val );
     126           0 :     jsonp_sanitize_str( http, start_len );
     127           0 :     fd_http_server_printf( http, "\"," );
     128           0 :   } else {
     129           0 :     fd_http_server_printf( http, "null," );
     130           0 :   }
     131           0 : }
     132             : 
     133             : static void
     134             : jsonp_bool( fd_http_server_t * http,
     135             :             char const *       key,
     136           0 :             int                value ) {
     137           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":%s,", key, value ? "true" : "false" );
     138           0 :   else                   fd_http_server_printf( http, "%s,", value ? "true" : "false" );
     139           0 : }
     140             : 
     141             : static void
     142             : jsonp_null( fd_http_server_t * http,
     143           0 :             char const *       key ) {
     144           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\": null,", key );
     145           0 :   else                   fd_http_server_printf( http, "null," );
     146           0 : }
     147             : 
     148             : static void
     149             : jsonp_open_envelope( fd_http_server_t * http,
     150             :                      char const *       topic,
     151           0 :                      char const *       key ) {
     152           0 :   jsonp_open_object( http, NULL );
     153           0 :   jsonp_string( http, "topic", topic );
     154           0 :   jsonp_string( http, "key",   key );
     155           0 : }
     156             : 
     157             : static void
     158           0 : jsonp_close_envelope( fd_http_server_t * http ) {
     159           0 :   jsonp_close_object( http );
     160           0 :   jsonp_strip_trailing_comma( http );
     161           0 : }
     162             : 
     163             : void
     164             : fd_gui_printf_open_query_response_envelope( fd_http_server_t * http,
     165             :                                             char const *       topic,
     166             :                                             char const *       key,
     167           0 :                                             ulong              id ) {
     168           0 :   jsonp_open_object( http, NULL );
     169           0 :   jsonp_string( http, "topic", topic );
     170           0 :   jsonp_string( http, "key", key );
     171           0 :   jsonp_ulong( http, "id", id );
     172           0 : }
     173             : 
     174             : void
     175           0 : fd_gui_printf_close_query_response_envelope( fd_http_server_t * http ) {
     176           0 :   jsonp_close_object( http );
     177           0 :   jsonp_strip_trailing_comma( http );
     178           0 : }
     179             : 
     180             : void
     181             : fd_gui_printf_null_query_response( fd_http_server_t * http,
     182             :                                    char const *       topic,
     183             :                                    char const *       key,
     184           0 :                                    ulong              id ) {
     185           0 :   fd_gui_printf_open_query_response_envelope( http, topic, key, id );
     186           0 :     jsonp_null( http, "value" );
     187           0 :   fd_gui_printf_close_query_response_envelope( http );
     188           0 : }
     189             : 
     190             : void
     191           0 : fd_gui_printf_version( fd_gui_t * gui ) {
     192           0 :   jsonp_open_envelope( gui->http, "summary", "version" );
     193           0 :     jsonp_string( gui->http, "value", gui->summary.version );
     194           0 :   jsonp_close_envelope( gui->http );
     195           0 : }
     196             : 
     197             : void
     198           0 : fd_gui_printf_cluster( fd_gui_t * gui ) {
     199           0 :   jsonp_open_envelope( gui->http, "summary", "cluster" );
     200           0 :     jsonp_string( gui->http, "value", gui->summary.cluster );
     201           0 :   jsonp_close_envelope( gui->http );
     202           0 : }
     203             : 
     204             : void
     205           0 : fd_gui_printf_commit_hash( fd_gui_t * gui ) {
     206           0 :   jsonp_open_envelope( gui->http, "summary", "commit_hash" );
     207           0 :     jsonp_string( gui->http, "value", fd_commit_ref_cstr );
     208           0 :   jsonp_close_envelope( gui->http );
     209           0 : }
     210             : 
     211             : void
     212           0 : fd_gui_printf_identity_key( fd_gui_t * gui ) {
     213           0 :   jsonp_open_envelope( gui->http, "summary", "identity_key" );
     214           0 :     jsonp_string( gui->http, "value", gui->summary.identity_key_base58 );
     215           0 :   jsonp_close_envelope( gui->http );
     216           0 : }
     217             : 
     218             : void
     219           0 : fd_gui_printf_vote_key( fd_gui_t * gui ) {
     220           0 :   jsonp_open_envelope( gui->http, "summary", "vote_key" );
     221           0 :     if( FD_LIKELY( gui->summary.has_vote_key ) ) jsonp_string( gui->http, "value", gui->summary.vote_key_base58 );
     222           0 :     else                                         jsonp_null( gui->http, "value" );
     223           0 :   jsonp_close_envelope( gui->http );
     224           0 : }
     225             : 
     226             : void
     227           0 : fd_gui_printf_startup_time_nanos( fd_gui_t * gui ) {
     228           0 :   jsonp_open_envelope( gui->http, "summary", "startup_time_nanos" );
     229           0 :     jsonp_long_as_str( gui->http, "value", gui->summary.startup_time_nanos );
     230           0 :   jsonp_close_envelope( gui->http );
     231           0 : }
     232             : 
     233             : void
     234           0 : fd_gui_printf_server_time_nanos( fd_gui_t * gui, long now ) {
     235           0 :   jsonp_open_envelope( gui->http, "summary", "server_time_nanos" );
     236           0 :     jsonp_long_as_str( gui->http, "value", now );
     237           0 :   jsonp_close_envelope( gui->http );
     238           0 : }
     239             : 
     240             : void
     241           0 : fd_gui_printf_vote_distance( fd_gui_t * gui ) {
     242           0 :   jsonp_open_envelope( gui->http, "summary", "vote_distance" );
     243           0 :     jsonp_ulong( gui->http, "value", gui->summary.vote_distance );
     244           0 :   jsonp_close_envelope( gui->http );
     245           0 : }
     246             : 
     247             : void
     248           0 : fd_gui_printf_repair_slot( fd_gui_t * gui ) {
     249           0 :   jsonp_open_envelope( gui->http, "summary", "repair_slot" );
     250           0 :     if( FD_LIKELY( gui->summary.slot_repair!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_repair );
     251           0 :     else                                                    jsonp_null ( gui->http, "value" );
     252           0 :   jsonp_close_envelope( gui->http );
     253           0 : }
     254             : 
     255             : void
     256           0 : fd_gui_peers_printf_vote_slot( fd_gui_peers_ctx_t * peers ) {
     257           0 :   jsonp_open_envelope( peers->http, "summary", "vote_slot" );
     258           0 :     if( FD_LIKELY( peers->slot_voted!=ULONG_MAX  ) ) jsonp_ulong( peers->http, "value", peers->slot_voted );
     259           0 :     else                                             jsonp_null ( peers->http, "value" );
     260           0 :   jsonp_close_envelope( peers->http );
     261           0 : }
     262             : 
     263             : void
     264           0 : fd_gui_printf_turbine_slot( fd_gui_t * gui ) {
     265           0 :   jsonp_open_envelope( gui->http, "summary", "turbine_slot" );
     266           0 :     if( FD_LIKELY( gui->summary.slot_turbine!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_turbine );
     267           0 :     else                                                     jsonp_null ( gui->http, "value" );
     268           0 :   jsonp_close_envelope( gui->http );
     269           0 : }
     270             : 
     271             : void
     272           0 : fd_gui_printf_reset_slot( fd_gui_t * gui ) {
     273           0 :   jsonp_open_envelope( gui->http, "summary", "reset_slot" );
     274           0 :     if( FD_LIKELY( gui->summary.slot_reset!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_reset );
     275           0 :     else                                                   jsonp_null ( gui->http, "value" );
     276           0 :   jsonp_close_envelope( gui->http );
     277           0 : }
     278             : 
     279             : void
     280           0 : fd_gui_printf_storage_slot( fd_gui_t * gui ) {
     281           0 :   jsonp_open_envelope( gui->http, "summary", "storage_slot" );
     282           0 :     if( FD_LIKELY( gui->summary.slot_storage!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_storage );
     283           0 :     else                                                     jsonp_null ( gui->http, "value" );
     284           0 :   jsonp_close_envelope( gui->http );
     285           0 : }
     286             : 
     287             : void
     288           0 : fd_gui_printf_active_fork_cnt( fd_gui_t * gui ) {
     289           0 :   jsonp_open_envelope( gui->http, "summary", "active_fork_count" );
     290           0 :     if( FD_LIKELY( gui->summary.active_fork_cnt!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.active_fork_cnt );
     291           0 :     else                                                        jsonp_null ( gui->http, "value" );
     292           0 :   jsonp_close_envelope( gui->http );
     293           0 : }
     294             : 
     295             : void
     296           0 : fd_gui_printf_slot_caught_up( fd_gui_t * gui ) {
     297           0 :   jsonp_open_envelope( gui->http, "summary", "slot_caught_up" );
     298           0 :     if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_caught_up );
     299           0 :     else                                                       jsonp_null ( gui->http, "value" );
     300           0 :   jsonp_close_envelope( gui->http );
     301           0 : }
     302             : 
     303             : void
     304           0 : fd_gui_printf_catch_up_history( fd_gui_t * gui ) {
     305           0 :   jsonp_open_envelope( gui->http, "summary", "catch_up_history" );
     306           0 :     jsonp_open_object( gui->http, "value" );
     307           0 :       jsonp_open_array( gui->http, "turbine" );
     308           0 :         for( ulong i=0UL; i<gui->summary.catch_up_turbine_sz; i+=2 ) {
     309           0 :           for( ulong j=gui->summary.catch_up_turbine[ i ]; j<=gui->summary.catch_up_turbine[ i+1UL ]; j++ ) {
     310           0 :             jsonp_ulong( gui->http, NULL, j );
     311           0 :           }
     312           0 :         }
     313           0 :       jsonp_close_array( gui->http );
     314           0 :       jsonp_open_array( gui->http, "repair" );
     315           0 :         for( ulong i=0UL; i<gui->summary.catch_up_repair_sz; i+=2 ) {
     316           0 :           for( ulong j=gui->summary.catch_up_repair[ i ]; j<=gui->summary.catch_up_repair[ i+1UL ]; j++ ) {
     317           0 :             jsonp_ulong( gui->http, NULL, j );
     318           0 :           }
     319           0 :         }
     320           0 :       jsonp_close_array( gui->http );
     321             : 
     322           0 :       if( FD_LIKELY( gui->summary.boot_progress.phase==FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP ) ) {
     323           0 :         ulong min_slot = ULONG_MAX;
     324           0 :         long min_ts = LONG_MAX;
     325             : 
     326           0 : #define SHREDS_REV_ITER( age_ns, code_archive ) \
     327           0 :         do { \
     328           0 :           if( FD_UNLIKELY( gui->summary.boot_progress.catching_up_time_nanos==0L ) ) break; \
     329           0 :           void * _db = gui->db; \
     330           0 :           if( FD_LIKELY( _db ) ) { \
     331           0 :             long _hi_ns = gui->summary.boot_progress.catching_up_time_nanos; \
     332           0 :             long _lo_ns = _hi_ns - (long)(age_ns); \
     333           0 :             fd_gui_hist_iter_t _it; \
     334           0 :             if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &_it, FD_GUI_HIST_SHRED_EVENTS, _lo_ns, _hi_ns, NULL, NULL ) ) ) { \
     335           0 :               while( fd_gui_hist_range_next( &_it ) ) { \
     336           0 :                 fd_gui_slot_history_shred_event_t const * event = (fd_gui_slot_history_shred_event_t const *)_it.rec; (void)event; \
     337           0 :                 ulong db_event_slot = event->slot; (void)db_event_slot; \
     338           0 :                 if( FD_UNLIKELY( event->timestamp < _lo_ns ) ) continue; \
     339           0 :                 do { code_archive } while (0); \
     340           0 :               } \
     341           0 :               fd_gui_hist_range_end( &_it ); \
     342           0 :             } \
     343           0 :           } \
     344           0 :         } while(0);
     345             : 
     346           0 :         SHREDS_REV_ITER(
     347           0 :           15000000000,
     348           0 :           {
     349           0 :             min_slot = fd_ulong_min( min_slot, db_event_slot );
     350           0 :             min_ts = fd_long_min( min_ts, event->timestamp );
     351           0 :           }
     352           0 :         )
     353             : 
     354           0 :         jsonp_open_object( gui->http, "shreds" );
     355           0 :           jsonp_ulong      ( gui->http, "reference_slot", min_slot );
     356           0 :           jsonp_long_as_str( gui->http, "reference_ts",   min_ts   );
     357             : 
     358           0 :           jsonp_open_array( gui->http, "slot_delta" );
     359           0 :             SHREDS_REV_ITER(
     360           0 :               15000000000L,
     361           0 :               { jsonp_ulong( gui->http, NULL, db_event_slot-min_slot ); }
     362           0 :             )
     363           0 :           jsonp_close_array( gui->http );
     364           0 :           jsonp_open_array( gui->http, "shred_idx" );
     365           0 :             SHREDS_REV_ITER(
     366           0 :               15000000000L,
     367           0 :               {
     368           0 :                 if( FD_LIKELY( event->shred_idx!=USHORT_MAX ) ) jsonp_ulong( gui->http, NULL, event->shred_idx );
     369           0 :                 else                                            jsonp_null ( gui->http, NULL );
     370           0 :               }
     371           0 :             )
     372           0 :           jsonp_close_array( gui->http );
     373           0 :           jsonp_open_array( gui->http, "event" );
     374           0 :             SHREDS_REV_ITER(
     375           0 :               15000000000L,
     376           0 :               { jsonp_ulong( gui->http, NULL, event->event ); }
     377           0 :             )
     378           0 :           jsonp_close_array( gui->http );
     379           0 :           jsonp_open_array( gui->http, "event_ts_delta" );
     380           0 :             SHREDS_REV_ITER(
     381           0 :               15000000000L,
     382           0 :               { jsonp_long_as_str( gui->http, NULL, event->timestamp-min_ts ); }
     383           0 :             )
     384           0 :           jsonp_close_array( gui->http );
     385           0 :         jsonp_close_object( gui->http );
     386           0 : #undef SHREDS_REV_ITER
     387           0 :       } else {
     388           0 :         jsonp_null( gui->http, "shreds" );
     389           0 :       }
     390             : 
     391           0 :     jsonp_close_object( gui->http );
     392           0 :   jsonp_close_envelope( gui->http );
     393           0 : }
     394             : 
     395             : void
     396           0 : fd_gui_printf_vote_state( fd_gui_t * gui ) {
     397           0 :   jsonp_open_envelope( gui->http, "summary", "vote_state" );
     398           0 :     switch( gui->summary.vote_state ) {
     399           0 :       case FD_GUI_VOTE_STATE_NON_VOTING:
     400           0 :         jsonp_string( gui->http, "value", "non-voting" );
     401           0 :         break;
     402           0 :       case FD_GUI_VOTE_STATE_VOTING:
     403           0 :         jsonp_string( gui->http, "value", "voting" );
     404           0 :         break;
     405           0 :       case FD_GUI_VOTE_STATE_DELINQUENT:
     406           0 :         jsonp_string( gui->http, "value", "delinquent" );
     407           0 :         break;
     408           0 :       default:
     409           0 :         FD_LOG_ERR(( "unknown vote state %d", gui->summary.vote_state ));
     410           0 :     }
     411           0 :   jsonp_close_envelope( gui->http );
     412           0 : }
     413             : 
     414             : /* fd_gui_skipped_history_bounds computes the half open index range
     415             :    [first_known_slot_idx,root_slot_idx) into an epoch's skip arrays. */
     416             : 
     417             : static int
     418             : fd_gui_skipped_history_bounds( fd_gui_t const *       gui,
     419             :                                fd_gui_epoch_t const * rec,
     420             :                                ulong *                lo_out,
     421           0 :                                ulong *                hi_out ) {
     422           0 :   if( FD_UNLIKELY( !rec ) ) return 0;
     423           0 :   if( FD_UNLIKELY( gui->summary.slot_rooted==ULONG_MAX ) ) return 0;
     424           0 :   if( FD_UNLIKELY( gui->summary.slot_rooted<rec->start_slot ) ) return 0;
     425             : 
     426           0 :   ulong first_replay_slot = fd_ulong_if( gui->summary.slot_caught_up!=ULONG_MAX, fd_gui_first_replay_slot( gui ), ULONG_MAX );
     427           0 :   ulong start_slot        = fd_ulong_max( rec->start_slot, fd_ulong_if( first_replay_slot!=ULONG_MAX, first_replay_slot, 0UL ) );
     428           0 :   if( FD_UNLIKELY( start_slot>gui->summary.slot_rooted ) ) return 0;
     429             : 
     430           0 :   *lo_out = start_slot - rec->start_slot;
     431           0 :   *hi_out = fd_ulong_min( rec->slot_cnt, gui->summary.slot_rooted+1UL-rec->start_slot );
     432           0 :   return *lo_out<*hi_out;
     433           0 : }
     434             : 
     435             : void
     436           0 : fd_gui_printf_skipped_history( fd_gui_t * gui, ulong epoch ) {
     437           0 :   jsonp_open_envelope( gui->http, "slot", "skipped_history" );
     438           0 :     jsonp_open_array( gui->http, "value" );
     439           0 :       fd_gui_epoch_t const * rec = fd_gui_epoch( gui, epoch );
     440           0 :       ulong lo, hi;
     441           0 :       if( FD_LIKELY( fd_gui_skipped_history_bounds( gui, rec, &lo, &hi ) ) ) {
     442           0 :         for( ulong i=lo; i<hi; i++ ) {
     443           0 :           ulong slot = rec->start_slot+i;
     444           0 :           if( FD_UNLIKELY( rec->skipped[ i ] && fd_gui_slot_is_mine( gui, slot ) ) ) jsonp_ulong( gui->http, NULL, slot );
     445           0 :         }
     446           0 :       }
     447           0 :     jsonp_close_array( gui->http );
     448           0 :   jsonp_close_envelope( gui->http );
     449           0 : }
     450             : 
     451             : void
     452           0 : fd_gui_printf_skipped_history_cluster( fd_gui_t * gui, ulong epoch ) {
     453           0 :   jsonp_open_envelope( gui->http, "slot", "skipped_history_cluster" );
     454           0 :     jsonp_open_array( gui->http, "value" );
     455           0 :       fd_gui_epoch_t const * rec = fd_gui_epoch( gui, epoch );
     456           0 :       ulong lo, hi;
     457           0 :       if( FD_LIKELY( fd_gui_skipped_history_bounds( gui, rec, &lo, &hi ) ) ) {
     458           0 :         for( ulong i=lo; i<hi; i++ ) {
     459           0 :           if( FD_UNLIKELY( rec->skipped[ i ] ) ) jsonp_ulong( gui->http, NULL, rec->start_slot+i );
     460           0 :         }
     461           0 :       }
     462           0 :     jsonp_close_array( gui->http );
     463           0 :   jsonp_close_envelope( gui->http );
     464           0 : }
     465             : 
     466             : /* fd_gui_slot_is_late returns 1 if slot s belongs in the
     467             :    late_votes_history output (voted for late, or canonical but never
     468             :    voted for), 0 otherwise. */
     469             : 
     470             : static inline int
     471           0 : fd_gui_slot_is_late( fd_gui_epoch_t const * rec, ulong s ) {
     472           0 :   ulong  idx   = s-rec->start_slot;
     473           0 :   uchar  exact = rec->latency_exact[ idx ];
     474           0 :   return fd_int_if( !rec->is_voter[ idx ], 0, fd_int_if( rec->skipped[ idx ], 0, fd_int_if( exact==FD_GUI_VOTE_LATENCY_NOT_VOTED, 1, exact>1 ) ) );
     475           0 : }
     476             : 
     477             : void
     478           0 : fd_gui_printf_late_votes_history( fd_gui_t * gui ) {
     479           0 :   fd_gui_epoch_t * rec = fd_gui_current_epoch( gui );
     480           0 :   ulong first_replay_slot = fd_ulong_if( gui->summary.slot_caught_up!=ULONG_MAX, fd_gui_first_replay_slot( gui ), ULONG_MAX );
     481           0 :   ulong start_slot = FD_LIKELY( rec ) ? fd_ulong_max( rec->start_slot, fd_ulong_if( first_replay_slot!=ULONG_MAX, first_replay_slot, 0UL ) ) : 0UL;
     482           0 :   ulong end_slot   = FD_LIKELY( rec ) ? fd_ulong_min( rec->start_slot+rec->slot_cnt-1UL, gui->summary.slot_rooted ) : 0UL;
     483           0 :   int   have_any   = rec && gui->summary.slot_rooted!=ULONG_MAX;
     484             : 
     485           0 :   jsonp_open_envelope( gui->http, "slot", "late_votes_history" );
     486           0 :       jsonp_open_object( gui->http, "value" );
     487           0 :         jsonp_open_array( gui->http, "slot" );
     488           0 :           if( FD_LIKELY( have_any ) ) {
     489           0 :             ulong s = start_slot;
     490           0 :             while( s<=end_slot ) {
     491           0 :               if( FD_LIKELY( !fd_gui_slot_is_late( rec, s ) ) ) { s++; continue; }
     492           0 :               ulong run_start = s;
     493           0 :               uchar run_exact = rec->latency_exact[ s-rec->start_slot ];
     494           0 :               while( s<=end_slot && fd_gui_slot_is_late( rec, s ) && rec->latency_exact[ s-rec->start_slot ]==run_exact ) s++;
     495           0 :               jsonp_ulong( gui->http, NULL, run_start );
     496           0 :               jsonp_ulong( gui->http, NULL, s-1UL );
     497           0 :             }
     498           0 :           }
     499           0 :         jsonp_close_array( gui->http );
     500           0 :         jsonp_open_array( gui->http, "latency_exact" );
     501           0 :           if( FD_LIKELY( have_any ) ) {
     502           0 :             ulong s = start_slot;
     503           0 :             while( s<=end_slot ) {
     504           0 :               if( FD_LIKELY( !fd_gui_slot_is_late( rec, s ) ) ) { s++; continue; }
     505           0 :               uchar run_exact = rec->latency_exact[ s-rec->start_slot ];
     506           0 :               while( s<=end_slot && fd_gui_slot_is_late( rec, s ) && rec->latency_exact[ s-rec->start_slot ]==run_exact ) s++;
     507           0 :               if( FD_LIKELY( run_exact!=FD_GUI_VOTE_LATENCY_NOT_VOTED ) ) jsonp_ulong( gui->http, NULL, run_exact );
     508           0 :               else                                                        jsonp_null ( gui->http, NULL );
     509           0 :             }
     510           0 :           }
     511           0 :         jsonp_close_array( gui->http );
     512           0 :       jsonp_close_object( gui->http );
     513           0 :   jsonp_close_envelope( gui->http );
     514           0 : }
     515             : 
     516             : void
     517           0 : fd_gui_printf_tps_history( fd_gui_t * gui ) {
     518           0 :   jsonp_open_envelope( gui->http, "summary", "tps_history" );
     519           0 :     jsonp_open_array( gui->http, "value" );
     520             : 
     521           0 :     for( ulong i=0UL; i<FD_GUI_TPS_HISTORY_SAMPLE_CNT; i++ ) {
     522           0 :       ulong idx = (gui->summary.estimated_tps_history_idx+i) % FD_GUI_TPS_HISTORY_SAMPLE_CNT;
     523           0 :       ulong vote_cnt = gui->summary.estimated_tps_history[ idx ].vote_failed
     524           0 :                      + gui->summary.estimated_tps_history[ idx ].vote_success;
     525           0 :       ulong total_cnt = vote_cnt
     526           0 :                       + gui->summary.estimated_tps_history[ idx ].nonvote_success
     527           0 :                       + gui->summary.estimated_tps_history[ idx ].nonvote_failed;
     528           0 :       jsonp_open_array( gui->http, NULL );
     529           0 :         jsonp_double( gui->http, NULL, (double)total_cnt/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
     530           0 :         jsonp_double( gui->http, NULL, (double)vote_cnt/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
     531           0 :         jsonp_double( gui->http, NULL, (double)gui->summary.estimated_tps_history[ idx ].nonvote_success/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
     532           0 :         jsonp_double( gui->http, NULL, (double)gui->summary.estimated_tps_history[ idx ].nonvote_failed/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
     533           0 :       jsonp_close_array( gui->http );
     534           0 :     }
     535             : 
     536           0 :     jsonp_close_array( gui->http );
     537           0 :   jsonp_close_envelope( gui->http );
     538           0 : }
     539             : 
     540             : void
     541           0 : fd_gui_printf_block_engine( fd_gui_t * gui ) {
     542           0 :   jsonp_open_envelope( gui->http, "block_engine", "update" );
     543           0 :     jsonp_open_object( gui->http, "value" );
     544           0 :       jsonp_string( gui->http, "name",   gui->block_engine.name );
     545           0 :       jsonp_string( gui->http, "url",    gui->block_engine.url );
     546           0 :       jsonp_string( gui->http, "ip",     gui->block_engine.ip_cstr );
     547           0 :       if( FD_LIKELY( gui->block_engine.status==FD_BUNDLE_STATE_CONNECTING ) )     jsonp_string( gui->http, "status", "connecting" );
     548           0 :       else if( FD_LIKELY( gui->block_engine.status==FD_BUNDLE_STATE_CONNECTED ) ) jsonp_string( gui->http, "status", "connected" );
     549           0 :       else if( FD_LIKELY( gui->block_engine.status==FD_BUNDLE_STATE_SLEEPING ) )  jsonp_string( gui->http, "status", "sleeping" );
     550           0 :       else                                                                        jsonp_string( gui->http, "status", "disconnected" );
     551           0 :     jsonp_close_object( gui->http );
     552           0 :   jsonp_close_envelope( gui->http );
     553           0 : }
     554             : 
     555             : void
     556           0 : fd_gui_printf_tiles( fd_gui_t * gui ) {
     557           0 :   jsonp_open_envelope( gui->http, "summary", "tiles" );
     558           0 :     jsonp_open_array( gui->http, "value" );
     559           0 :       for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     560           0 :         fd_topo_tile_t const * tile = &gui->topo->tiles[ gui->summary.tile[ i ] ];
     561             : 
     562           0 :         if( FD_UNLIKELY( !strncmp( tile->name, "bench", 5UL ) ) ) {
     563             :           /* bench tiles not reported */
     564           0 :           continue;
     565           0 :         }
     566             : 
     567           0 :         jsonp_open_object( gui->http, NULL );
     568           0 :           jsonp_string( gui->http, "kind", tile->name );
     569           0 :           jsonp_ulong( gui->http, "kind_id", tile->kind_id );
     570           0 :           jsonp_ulong( gui->http, "pid", fd_metrics_tile( tile->metrics )[ MIDX( GAUGE, TILE, PID ) ] );
     571           0 :         jsonp_close_object( gui->http );
     572           0 :       }
     573           0 :     jsonp_close_array( gui->http );
     574           0 :   jsonp_close_envelope( gui->http );
     575           0 : }
     576             : 
     577             : void
     578           0 : fd_gui_printf_schedule_strategy( fd_gui_t * gui ) {
     579           0 :   jsonp_open_envelope( gui->http, "summary", "schedule_strategy" );
     580           0 :     char mode[10];
     581           0 :     switch (gui->summary.schedule_strategy) {
     582           0 :       case 0: fd_cstr_ncpy( mode, "perf",     sizeof(mode) ); break;
     583           0 :       case 1: fd_cstr_ncpy( mode, "balanced", sizeof(mode) ); break;
     584           0 :       case 2: fd_cstr_ncpy( mode, "revenue",  sizeof(mode) ); break;
     585           0 :       default: FD_LOG_ERR(("unexpected schedule_strategy %d", gui->summary.schedule_strategy));
     586           0 :     }
     587           0 :     jsonp_string( gui->http, "value", mode );
     588           0 :   jsonp_close_envelope( gui->http );
     589           0 : }
     590             : 
     591             : void
     592           0 : fd_gui_printf_identity_balance( fd_gui_t * gui ) {
     593           0 :   jsonp_open_envelope( gui->http, "summary", "identity_balance" );
     594           0 :     jsonp_ulong_as_str( gui->http, "value", gui->summary.identity_account_balance );
     595           0 :   jsonp_close_envelope( gui->http );
     596           0 : }
     597             : 
     598             : void
     599           0 : fd_gui_printf_vote_balance( fd_gui_t * gui ) {
     600           0 :   jsonp_open_envelope( gui->http, "summary", "vote_balance" );
     601           0 :     jsonp_ulong_as_str( gui->http, "value", gui->summary.vote_account_balance );
     602           0 :   jsonp_close_envelope( gui->http );
     603           0 : }
     604             : 
     605             : void
     606           0 : fd_gui_printf_vote_commission( fd_gui_t * gui ) {
     607           0 :   jsonp_open_envelope( gui->http, "summary", "vote_commission" );
     608           0 :     if( FD_LIKELY( gui->summary.vote_commission!=USHORT_MAX ) ) jsonp_ulong( gui->http, "value", (ulong)gui->summary.vote_commission );
     609           0 :     else                                                        jsonp_null ( gui->http, "value" );
     610           0 :   jsonp_close_envelope( gui->http );
     611           0 : }
     612             : 
     613             : void
     614           0 : fd_gui_printf_estimated_slot_duration_nanos( fd_gui_t * gui ) {
     615           0 :   jsonp_open_envelope( gui->http, "summary", "estimated_slot_duration_nanos" );
     616           0 :     jsonp_ulong( gui->http, "value", gui->summary.estimated_slot_duration_nanos );
     617           0 :   jsonp_close_envelope( gui->http );
     618           0 : }
     619             : 
     620             : 
     621             : void
     622           0 : fd_gui_printf_root_slot( fd_gui_t * gui ) {
     623           0 :   jsonp_open_envelope( gui->http, "summary", "root_slot" );
     624           0 :     jsonp_ulong( gui->http, "value", fd_ulong_if( gui->summary.slot_rooted!=ULONG_MAX, gui->summary.slot_rooted, 0UL ) );
     625           0 :   jsonp_close_envelope( gui->http );
     626           0 : }
     627             : 
     628             : void
     629           0 : fd_gui_printf_optimistically_confirmed_slot( fd_gui_t * gui ) {
     630           0 :   jsonp_open_envelope( gui->http, "summary", "optimistically_confirmed_slot" );
     631           0 :     jsonp_ulong( gui->http, "value", fd_ulong_if( gui->summary.slot_optimistically_confirmed!=ULONG_MAX, gui->summary.slot_optimistically_confirmed, 0UL ) );
     632           0 :   jsonp_close_envelope( gui->http );
     633           0 : }
     634             : 
     635             : void
     636           0 : fd_gui_printf_completed_slot( fd_gui_t * gui ) {
     637           0 :   jsonp_open_envelope( gui->http, "summary", "completed_slot" );
     638           0 :     jsonp_ulong( gui->http, "value", fd_ulong_if( gui->summary.slot_tower!=ULONG_MAX, gui->summary.slot_tower, 0UL ) );
     639           0 :   jsonp_close_envelope( gui->http );
     640           0 : }
     641             : 
     642             : void
     643           0 : fd_gui_printf_estimated_slot( fd_gui_t * gui ) {
     644           0 :   jsonp_open_envelope( gui->http, "summary", "estimated_slot" );
     645           0 :     jsonp_ulong( gui->http, "value", fd_ulong_if( gui->summary.slot_estimated!=ULONG_MAX, gui->summary.slot_estimated, 0UL ) );
     646           0 :   jsonp_close_envelope( gui->http );
     647           0 : }
     648             : 
     649             : void
     650             : fd_gui_printf_skip_rate( fd_gui_t * gui,
     651           0 :                          ulong      epoch ) {
     652           0 :   fd_gui_epoch_t const * rec = fd_gui_epoch( gui, epoch );
     653           0 :   jsonp_open_envelope( gui->http, "summary", "skip_rate" );
     654           0 :     jsonp_open_object( gui->http, "value" );
     655           0 :       jsonp_ulong( gui->http, "epoch", FD_LIKELY( rec ) ? rec->epoch : 0UL );
     656           0 :       double skip_rate = ( FD_LIKELY( rec ) && rec->my_total_slots ) ? (double)rec->my_skipped_slots/(double)rec->my_total_slots : 0.0;
     657           0 :       fd_http_server_printf( gui->http, "\"skip_rate\":%.7f,", skip_rate );
     658           0 :     jsonp_close_object( gui->http );
     659           0 :   jsonp_close_envelope( gui->http );
     660           0 : }
     661             : 
     662             : void
     663             : fd_gui_printf_epoch( fd_gui_t * gui,
     664           0 :                      ulong      epoch ) {
     665           0 :   fd_gui_epoch_t const * meta = fd_gui_epoch( gui, epoch );
     666           0 :   jsonp_open_envelope( gui->http, "epoch", "new" );
     667           0 :     jsonp_open_object( gui->http, "value" );
     668           0 :       jsonp_ulong( gui->http, "epoch",                   FD_LIKELY( meta ) ? meta->epoch : 0UL );
     669           0 :       if( FD_LIKELY( meta && meta->start_time!=LONG_MAX ) ) jsonp_ulong_as_str( gui->http, "start_time_nanos", (ulong)meta->start_time );
     670           0 :       else                                                  jsonp_null( gui->http, "start_time_nanos" );
     671           0 :       if( FD_LIKELY( meta && meta->end_time!=LONG_MAX ) ) jsonp_ulong_as_str( gui->http, "end_time_nanos", (ulong)meta->end_time );
     672           0 :       else                                                jsonp_null( gui->http, "end_time_nanos" );
     673           0 :       jsonp_ulong( gui->http, "start_slot",              FD_LIKELY( meta ) ? meta->start_slot : 0UL );
     674           0 :       jsonp_ulong( gui->http, "end_slot",                FD_LIKELY( meta ) ? meta->start_slot+meta->slot_cnt-1UL : 0UL );
     675           0 :       jsonp_ulong( gui->http, "target_slot_duration_nanos", FD_LIKELY( meta ) ? (ulong)meta->target_slot_duration_ns : LONG_MAX );
     676           0 :       jsonp_ulong_as_str( gui->http, "excluded_stake_lamports", 0UL );
     677           0 :       ulong pub_cnt    = FD_LIKELY( meta ) ? meta->pub_cnt : 0UL;
     678           0 :       ulong stakes_cnt = FD_LIKELY( meta ) ? meta->stakes_cnt : 0UL;
     679           0 :       ulong sched_cnt  = FD_LIKELY( meta ) ? (meta->slot_cnt+FD_EPOCH_SLOTS_PER_ROTATION-1UL)/FD_EPOCH_SLOTS_PER_ROTATION : 0UL;
     680           0 :       jsonp_open_array( gui->http, "staked_pubkeys" );
     681           0 :         for( ulong i=0UL; i<pub_cnt; i++ ) {
     682           0 :           char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
     683           0 :           fd_base58_encode_32( meta->pub[ i ].uc, NULL, identity_base58 );
     684           0 :           jsonp_string( gui->http, NULL, identity_base58 );
     685           0 :         }
     686           0 :       jsonp_close_array( gui->http );
     687             : 
     688           0 :       jsonp_open_array( gui->http, "staked_lamports" );
     689           0 :         for( ulong i=0UL; i<stakes_cnt; i++ ) jsonp_ulong_as_str( gui->http, NULL, meta->stakes[ i ].stake );
     690           0 :       jsonp_close_array( gui->http );
     691             : 
     692           0 :       jsonp_open_array( gui->http, "leader_slots" );
     693           0 :         for( ulong i=0UL; i<sched_cnt; i++ ) jsonp_ulong( gui->http, NULL, meta->sched[ i ] );
     694           0 :       jsonp_close_array( gui->http );
     695           0 :     jsonp_close_object( gui->http );
     696           0 :   jsonp_close_envelope( gui->http );
     697           0 : }
     698             : 
     699             : static void
     700             : fd_gui_printf_waterfall( fd_gui_t *               gui,
     701             :                          fd_gui_txn_waterfall_t const * prev,
     702           0 :                          fd_gui_txn_waterfall_t const * cur ) {
     703           0 :   jsonp_open_object( gui->http, "waterfall" );
     704           0 :     jsonp_open_object( gui->http, "in" );
     705           0 :       jsonp_ulong( gui->http, "pack_cranked",    cur->in.pack_cranked - prev->in.pack_cranked );
     706           0 :       jsonp_ulong( gui->http, "pack_retained",   prev->out.pack_retained );
     707           0 :       jsonp_ulong( gui->http, "resolv_retained", prev->out.resolv_retained );
     708           0 :       jsonp_ulong( gui->http, "quic",            cur->in.quic   - prev->in.quic );
     709           0 :       jsonp_ulong( gui->http, "udp",             cur->in.udp    - prev->in.udp );
     710           0 :       jsonp_ulong( gui->http, "gossip",          cur->in.gossip - prev->in.gossip );
     711           0 :       jsonp_ulong( gui->http, "block_engine",    cur->in.block_engine - prev->in.block_engine );
     712           0 :     jsonp_close_object( gui->http );
     713             : 
     714           0 :     jsonp_open_object( gui->http, "out" );
     715           0 :       jsonp_ulong( gui->http, "net_overrun",         cur->out.net_overrun         - prev->out.net_overrun );
     716           0 :       jsonp_ulong( gui->http, "quic_overrun",        cur->out.quic_overrun        - prev->out.quic_overrun );
     717           0 :       jsonp_ulong( gui->http, "quic_frag_drop",      cur->out.quic_frag_drop      - prev->out.quic_frag_drop );
     718           0 :       jsonp_ulong( gui->http, "quic_abandoned",      cur->out.quic_abandoned      - prev->out.quic_abandoned );
     719           0 :       jsonp_ulong( gui->http, "tpu_quic_invalid",    cur->out.tpu_quic_invalid    - prev->out.tpu_quic_invalid );
     720           0 :       jsonp_ulong( gui->http, "tpu_udp_invalid",     cur->out.tpu_udp_invalid     - prev->out.tpu_udp_invalid );
     721           0 :       jsonp_ulong( gui->http, "verify_overrun",      cur->out.verify_overrun      - prev->out.verify_overrun );
     722           0 :       jsonp_ulong( gui->http, "verify_parse",        cur->out.verify_parse        - prev->out.verify_parse );
     723           0 :       jsonp_ulong( gui->http, "verify_failed",       cur->out.verify_failed       - prev->out.verify_failed );
     724           0 :       jsonp_ulong( gui->http, "verify_duplicate",    cur->out.verify_duplicate    - prev->out.verify_duplicate );
     725           0 :       jsonp_ulong( gui->http, "dedup_duplicate",     cur->out.dedup_duplicate     - prev->out.dedup_duplicate );
     726           0 :       jsonp_ulong( gui->http, "resolv_lut_failed",   cur->out.resolv_lut_failed   - prev->out.resolv_lut_failed );
     727           0 :       jsonp_ulong( gui->http, "resolv_expired",      cur->out.resolv_expired      - prev->out.resolv_expired );
     728           0 :       jsonp_ulong( gui->http, "resolv_ancient",      cur->out.resolv_ancient      - prev->out.resolv_ancient );
     729           0 :       jsonp_ulong( gui->http, "resolv_no_ledger",    cur->out.resolv_no_ledger    - prev->out.resolv_no_ledger );
     730           0 :       jsonp_ulong( gui->http, "resolv_retained",     cur->out.resolv_retained );
     731           0 :       jsonp_ulong( gui->http, "pack_invalid",        cur->out.pack_invalid        - prev->out.pack_invalid );
     732           0 :       jsonp_ulong( gui->http, "pack_invalid_bundle", cur->out.pack_invalid_bundle - prev->out.pack_invalid_bundle );
     733           0 :       jsonp_ulong( gui->http, "pack_expired",        cur->out.pack_expired        - prev->out.pack_expired );
     734           0 :       jsonp_ulong( gui->http, "pack_already_executed", cur->out.pack_already_executed - prev->out.pack_already_executed );
     735           0 :       jsonp_ulong( gui->http, "pack_retained",       cur->out.pack_retained );
     736           0 :       jsonp_ulong( gui->http, "pack_wait_full",      cur->out.pack_wait_full      - prev->out.pack_wait_full );
     737           0 :       jsonp_ulong( gui->http, "pack_leader_slow",    cur->out.pack_leader_slow    - prev->out.pack_leader_slow );
     738           0 :       jsonp_ulong( gui->http, "bank_invalid",        cur->out.bank_invalid        - prev->out.bank_invalid );
     739           0 :       jsonp_ulong( gui->http, "bank_nonce_already_advanced", cur->out.bank_nonce_already_advanced - prev->out.bank_nonce_already_advanced );
     740           0 :       jsonp_ulong( gui->http, "bank_nonce_advance_failed",   cur->out.bank_nonce_advance_failed   - prev->out.bank_nonce_advance_failed   );
     741           0 :       jsonp_ulong( gui->http, "bank_nonce_wrong_blockhash",  cur->out.bank_nonce_wrong_blockhash  - prev->out.bank_nonce_wrong_blockhash  );
     742           0 :       jsonp_ulong( gui->http, "block_success",       cur->out.block_success       - prev->out.block_success );
     743           0 :       jsonp_ulong( gui->http, "block_fail",          cur->out.block_fail          - prev->out.block_fail );
     744           0 :     jsonp_close_object( gui->http );
     745           0 :   jsonp_close_object( gui->http );
     746           0 : }
     747             : 
     748             : void
     749             : fd_gui_printf_live_txn_waterfall( fd_gui_t *                     gui,
     750             :                                   fd_gui_txn_waterfall_t const * prev,
     751             :                                   fd_gui_txn_waterfall_t const * cur,
     752           0 :                                   ulong                          next_leader_slot ) {
     753           0 :   jsonp_open_envelope( gui->http, "summary", "live_txn_waterfall" );
     754           0 :     jsonp_open_object( gui->http, "value" );
     755           0 :       jsonp_ulong( gui->http, "next_leader_slot", next_leader_slot );
     756           0 :       fd_gui_printf_waterfall( gui, prev, cur );
     757           0 :     jsonp_close_object( gui->http );
     758           0 :   jsonp_close_envelope( gui->http );
     759           0 : }
     760             : 
     761             : static void
     762             : fd_gui_printf_network_metrics( fd_gui_t *                     gui,
     763           0 :                                fd_gui_network_stats_t const * cur ) {
     764           0 :   jsonp_open_array( gui->http, "ingress" );
     765           0 :     jsonp_ulong( gui->http, NULL, cur->in.turbine );
     766           0 :     jsonp_ulong( gui->http, NULL, cur->in.gossip  );
     767           0 :     jsonp_ulong( gui->http, NULL, cur->in.tpu     );
     768           0 :     jsonp_ulong( gui->http, NULL, cur->in.repair  );
     769           0 :     jsonp_ulong( gui->http, NULL, cur->in.rserve  );
     770           0 :     jsonp_ulong( gui->http, NULL, cur->in.metric  );
     771           0 :   jsonp_close_array( gui->http );
     772           0 :   jsonp_open_array( gui->http, "egress" );
     773           0 :     jsonp_ulong( gui->http, NULL, cur->out.turbine );
     774           0 :     jsonp_ulong( gui->http, NULL, cur->out.gossip  );
     775           0 :     jsonp_ulong( gui->http, NULL, cur->out.tpu     );
     776           0 :     jsonp_ulong( gui->http, NULL, cur->out.repair  );
     777           0 :     jsonp_ulong( gui->http, NULL, cur->out.rserve  );
     778           0 :     jsonp_ulong( gui->http, NULL, cur->out.metric  );
     779           0 :   jsonp_close_array( gui->http );
     780           0 :   jsonp_open_array( gui->http, "ingress_ema" );
     781           0 :     for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) jsonp_double( gui->http, NULL, gui->summary.ingress_ema[ i ].value );
     782           0 :   jsonp_close_array( gui->http );
     783           0 :   jsonp_open_array( gui->http, "egress_ema" );
     784           0 :     for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) jsonp_double( gui->http, NULL, gui->summary.egress_ema[ i ].value );
     785           0 :   jsonp_close_array( gui->http );
     786           0 :   fd_gui_rate_entry_t const * ingress_max_head = fd_gui_rate_deque_empty( gui->summary.ingress_maxq ) ? NULL : fd_gui_rate_deque_peek_head_const( gui->summary.ingress_maxq );
     787           0 :   fd_gui_rate_entry_t const * egress_max_head  = fd_gui_rate_deque_empty( gui->summary.egress_maxq )  ? NULL : fd_gui_rate_deque_peek_head_const( gui->summary.egress_maxq );
     788           0 :   jsonp_ulong( gui->http, "ingress_max_5m", ingress_max_head ? (ulong)ingress_max_head->value : 0UL );
     789           0 :   jsonp_ulong( gui->http, "egress_max_5m",  egress_max_head  ? (ulong)egress_max_head->value  : 0UL );
     790           0 : }
     791             : 
     792             : void
     793             : fd_gui_printf_live_network_metrics( fd_gui_t *                     gui,
     794           0 :                                     fd_gui_network_stats_t const * cur ) {
     795           0 :   jsonp_open_envelope( gui->http, "summary", "live_network_metrics" );
     796           0 :     jsonp_open_object( gui->http, "value" );
     797           0 :       fd_gui_printf_network_metrics( gui, cur );
     798           0 :     jsonp_close_object( gui->http );
     799           0 :   jsonp_close_envelope( gui->http );
     800           0 : }
     801             : 
     802             : static void
     803             : fd_gui_printf_tile_stats( fd_gui_t *                  gui,
     804             :                           fd_gui_tile_stats_t const * prev,
     805           0 :                           fd_gui_tile_stats_t const * cur ) {
     806           0 :   jsonp_open_object( gui->http, "tile_primary_metric" );
     807           0 :     jsonp_ulong(  gui->http, "quic",    cur->quic_conn_cnt );
     808           0 :     jsonp_double( gui->http, "bundle_rtt_smoothed_millis", (double)(cur->bundle_rtt_smoothed_nanos) / 1000000.0 );
     809             : 
     810           0 :     fd_histf_t bundle_rx_delay_hist_delta[ 1 ];
     811           0 :     fd_histf_subtract( &cur->bundle_rx_delay_hist, &prev->bundle_rx_delay_hist, bundle_rx_delay_hist_delta );
     812           0 :     ulong bundle_rx_delay_nanos_p90 = fd_histf_percentile( bundle_rx_delay_hist_delta, 90U, ULONG_MAX );
     813           0 :     jsonp_double( gui->http, "bundle_rx_delay_millis_p90", fd_double_if(bundle_rx_delay_nanos_p90==ULONG_MAX, 0.0, (double)(bundle_rx_delay_nanos_p90) / 1000000.0 ));
     814             : 
     815           0 :     if( FD_LIKELY( cur->sample_time_nanos>prev->sample_time_nanos ) ) {
     816           0 :       jsonp_ulong( gui->http, "net_in",  (ulong)((double)(cur->net_in_rx_bytes - prev->net_in_rx_bytes) * 1000000000.0 / (double)(cur->sample_time_nanos - prev->sample_time_nanos) ));
     817           0 :       jsonp_ulong( gui->http, "net_out", (ulong)((double)(cur->net_out_tx_bytes - prev->net_out_tx_bytes) * 1000000000.0 / (double)(cur->sample_time_nanos - prev->sample_time_nanos) ));
     818           0 :     } else {
     819           0 :       jsonp_ulong( gui->http, "net_in",  0 );
     820           0 :       jsonp_ulong( gui->http, "net_out", 0 );
     821           0 :     }
     822           0 :     if( FD_LIKELY( cur->verify_total_cnt>prev->verify_total_cnt ) ) {
     823           0 :       jsonp_double( gui->http, "verify", (double)(cur->verify_drop_cnt-prev->verify_drop_cnt) / (double)(cur->verify_total_cnt-prev->verify_total_cnt) );
     824           0 :     } else {
     825           0 :       jsonp_double( gui->http, "verify", 0.0 );
     826           0 :     }
     827           0 :     if( FD_LIKELY( cur->dedup_total_cnt>prev->dedup_total_cnt ) ) {
     828           0 :       jsonp_double( gui->http, "dedup", (double)(cur->dedup_drop_cnt-prev->dedup_drop_cnt) / (double)(cur->dedup_total_cnt-prev->dedup_total_cnt) );
     829           0 :     } else {
     830           0 :       jsonp_double( gui->http, "dedup", 0.0 );
     831           0 :     }
     832           0 :     jsonp_ulong(  gui->http, "bank", cur->bank_txn_exec_cnt - prev->bank_txn_exec_cnt );
     833           0 :     jsonp_double( gui->http, "pack", !cur->pack_buffer_capacity ? 1.0 : (double)cur->pack_buffer_cnt/(double)cur->pack_buffer_capacity );
     834           0 :     jsonp_double( gui->http, "poh", 0.0 );
     835           0 :     jsonp_double( gui->http, "shred", 0.0 );
     836           0 :     jsonp_double( gui->http, "store", 0.0 );
     837           0 :   jsonp_close_object( gui->http );
     838           0 : }
     839             : 
     840             : void
     841             : fd_gui_printf_live_tile_stats( fd_gui_t *                  gui,
     842             :                                fd_gui_tile_stats_t const * prev,
     843           0 :                                fd_gui_tile_stats_t const * cur ) {
     844           0 :   jsonp_open_envelope( gui->http, "summary", "live_tile_primary_metric" );
     845           0 :     jsonp_open_object( gui->http, "value" );
     846           0 :       jsonp_ulong( gui->http, "next_leader_slot", 0UL );
     847           0 :       fd_gui_printf_tile_stats( gui, prev, cur );
     848           0 :     jsonp_close_object( gui->http );
     849           0 :   jsonp_close_envelope( gui->http );
     850           0 : }
     851             : 
     852             : static void
     853             : fd_gui_printf_tile_timers( fd_gui_t *                        gui,
     854           0 :                            fd_gui_tile_timers_hist_t const * packed ) {
     855           0 :   for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     856           0 :     ulong t = gui->summary.tile[ i ];
     857           0 :     fd_topo_tile_t const * tile = &gui->topo->tiles[ t ];
     858             : 
     859           0 :     if( FD_UNLIKELY( !strncmp( tile->name, "bench", 5UL ) ) ) {
     860             :       /* bench tiles not reported */
     861           0 :       continue;
     862           0 :     }
     863             : 
     864           0 :     ushort ir = packed[ t ].idle_ratio;
     865             :     /* -1 signals "no sample this window" (NaN has no JSON representation). */
     866           0 :     double idle_ratio = ( ir==USHORT_MAX ) ? -1.0 : ( (double)ir / 10000.0 );
     867           0 :     jsonp_double( gui->http, NULL, idle_ratio );
     868           0 :   }
     869           0 : }
     870             : 
     871             : static void
     872             : fd_gui_printf_tile_metrics( fd_gui_t *                        gui,
     873           0 :                             fd_gui_tile_timers_hist_t const * packed ) {
     874           0 :   jsonp_open_array( gui->http, "timers" );
     875           0 :   for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     876           0 :     ulong t = gui->summary.tile[ i ];
     877           0 :     fd_topo_tile_t const * tile = &gui->topo->tiles[ t ];
     878             : 
     879           0 :     if( FD_UNLIKELY( !strncmp( tile->name, "bench", 5UL ) ) ) {
     880             :       /* bench tiles not reported */
     881           0 :       jsonp_null( gui->http, NULL );
     882           0 :       continue;
     883           0 :     }
     884             : 
     885           0 :     if( FD_UNLIKELY( packed[ t ].timers[ 0 ]==USHORT_MAX ) ) {
     886           0 :       jsonp_null( gui->http, NULL );
     887           0 :     } else {
     888           0 :       jsonp_open_array( gui->http, NULL );
     889           0 :         for( ulong j=0UL; j<FD_METRICS_ENUM_TILE_REGIME_CNT; j++ ) {
     890           0 :           jsonp_double( gui->http, NULL, (double)packed[ t ].timers[ j ] / 100.0 );
     891           0 :         }
     892           0 :       jsonp_close_array( gui->http );
     893           0 :     }
     894           0 :   }
     895           0 :   jsonp_close_array( gui->http );
     896             : 
     897           0 :   jsonp_open_array( gui->http, "sched_timers" );
     898           0 :   for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     899           0 :     ulong t = gui->summary.tile[ i ];
     900           0 :     fd_topo_tile_t const * tile = &gui->topo->tiles[ t ];
     901             : 
     902           0 :     if( FD_UNLIKELY( !strncmp( tile->name, "bench", 5UL ) ) ) {
     903             :       /* bench tiles not reported */
     904           0 :       jsonp_null( gui->http, NULL );
     905           0 :       continue;
     906           0 :     }
     907             : 
     908           0 :     if( FD_UNLIKELY( packed[ t ].sched_timers[ 0 ]==USHORT_MAX ) ) {
     909           0 :       jsonp_null( gui->http, NULL );
     910           0 :     } else {
     911           0 :       jsonp_open_array( gui->http, NULL );
     912           0 :         for( ulong j=0UL; j<FD_METRICS_ENUM_CPU_REGIME_CNT; j++ ) {
     913           0 :           jsonp_double( gui->http, NULL, (double)packed[ t ].sched_timers[ j ] / 100.0 );
     914           0 :         }
     915           0 :       jsonp_close_array( gui->http );
     916           0 :     }
     917           0 :   }
     918           0 :   jsonp_close_array( gui->http );
     919             : 
     920           0 :   jsonp_open_array( gui->http, "in_backp" );
     921           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     922           0 :       jsonp_bool( gui->http, NULL, packed[ gui->summary.tile[ i ] ].in_backp );
     923           0 :     }
     924           0 :   jsonp_close_array( gui->http );
     925           0 :   jsonp_open_array( gui->http, "backp_msgs" );
     926           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     927           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].backp_msgs );
     928           0 :     }
     929           0 :   jsonp_close_array( gui->http );
     930           0 :   jsonp_open_array( gui->http, "alive" );
     931           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     932           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].alive );
     933           0 :     }
     934           0 :   jsonp_close_array( gui->http );
     935           0 :   jsonp_open_array( gui->http, "nvcsw" );
     936           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     937           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].nvcsw );
     938           0 :     }
     939           0 :   jsonp_close_array( gui->http );
     940           0 :   jsonp_open_array( gui->http, "nivcsw" );
     941           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     942           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].nivcsw );
     943           0 :     }
     944           0 :   jsonp_close_array( gui->http );
     945           0 :   jsonp_open_array( gui->http, "minflt" );
     946           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     947           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].minflt );
     948           0 :     }
     949           0 :   jsonp_close_array( gui->http );
     950           0 :   jsonp_open_array( gui->http, "majflt" );
     951           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     952           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].majflt );
     953           0 :     }
     954           0 :   jsonp_close_array( gui->http );
     955           0 :   jsonp_open_array( gui->http, "last_cpu" );
     956           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     957           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].last_cpu );
     958           0 :     }
     959           0 :   jsonp_close_array( gui->http );
     960           0 :   jsonp_open_array( gui->http, "interrupts" );
     961           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     962           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].interrupts );
     963           0 :     }
     964           0 :   jsonp_close_array( gui->http );
     965           0 :   jsonp_open_array( gui->http, "tlb_shootdowns" );
     966           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     967           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].tlb_shootdowns );
     968           0 :     }
     969           0 :   jsonp_close_array( gui->http );
     970           0 :   jsonp_open_array( gui->http, "timer_ticks" );
     971           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     972           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].timer_ticks );
     973           0 :     }
     974           0 :   jsonp_close_array( gui->http );
     975           0 :   jsonp_open_array( gui->http, "priority" );
     976           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     977           0 :       int priority = fd_topob_tile_priority_type( gui->topo->tiles[ gui->summary.tile[ i ] ].name );
     978             : 
     979           0 :       char const * priority_type_str = "unknown";
     980           0 :       switch( priority ) {
     981           0 :         case FD_TOPOB_PRIORITY_FLOATING: priority_type_str = "floating"; break;
     982           0 :         case FD_TOPOB_PRIORITY_STARTUP:  priority_type_str = "startup";  break;
     983           0 :         case FD_TOPOB_PRIORITY_NORMAL:   priority_type_str = "normal";   break;
     984           0 :         case FD_TOPOB_PRIORITY_CRITICAL: priority_type_str = "critical"; break;
     985           0 :       }
     986             : 
     987           0 :       jsonp_string( gui->http, NULL, priority_type_str );
     988           0 :     }
     989           0 :   jsonp_close_array( gui->http );
     990           0 : }
     991             : 
     992             : void
     993           0 : fd_gui_printf_live_tile_timers( fd_gui_t * gui ) {
     994           0 :   jsonp_open_envelope( gui->http, "summary", "live_tile_timers" );
     995           0 :     jsonp_open_array( gui->http, "value" );
     996           0 :       fd_gui_printf_tile_timers( gui, gui->summary.tile_timers_packed );
     997           0 :     jsonp_close_array( gui->http );
     998           0 :   jsonp_close_envelope( gui->http );
     999           0 : }
    1000             : 
    1001             : void
    1002           0 : fd_gui_printf_live_tile_metrics( fd_gui_t * gui ) {
    1003           0 :   jsonp_open_envelope( gui->http, "summary", "live_tile_metrics" );
    1004           0 :       jsonp_open_object( gui->http, "value" );
    1005           0 :         fd_gui_printf_tile_metrics( gui, gui->summary.tile_timers_packed );
    1006           0 :       jsonp_close_object( gui->http );
    1007           0 :   jsonp_close_envelope( gui->http );
    1008           0 : }
    1009             : 
    1010             : void
    1011           0 : fd_gui_printf_estimated_tps( fd_gui_t * gui ) {
    1012           0 :   ulong idx = (gui->summary.estimated_tps_history_idx+FD_GUI_TPS_HISTORY_SAMPLE_CNT-1UL) % FD_GUI_TPS_HISTORY_SAMPLE_CNT;
    1013             : 
    1014           0 :   jsonp_open_envelope( gui->http, "summary", "estimated_tps" );
    1015           0 :     jsonp_open_object( gui->http, "value" );
    1016           0 :       ulong vote_cnt = gui->summary.estimated_tps_history[ idx ].vote_failed
    1017           0 :                     + gui->summary.estimated_tps_history[ idx ].vote_success;
    1018           0 :       ulong total_cnt = vote_cnt
    1019           0 :                       + gui->summary.estimated_tps_history[ idx ].nonvote_success
    1020           0 :                       + gui->summary.estimated_tps_history[ idx ].nonvote_failed;
    1021           0 :       jsonp_double( gui->http, "total",           (double)total_cnt/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
    1022           0 :       jsonp_double( gui->http, "vote",            (double)vote_cnt/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
    1023           0 :       jsonp_double( gui->http, "nonvote_success", (double)gui->summary.estimated_tps_history[ idx ].nonvote_success/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
    1024           0 :       jsonp_double( gui->http, "nonvote_failed",  (double)gui->summary.estimated_tps_history[ idx ].nonvote_failed/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
    1025           0 :     jsonp_close_object( gui->http );
    1026           0 :   jsonp_close_envelope( gui->http );
    1027           0 : }
    1028             : 
    1029             : void
    1030           0 : fd_gui_printf_live_program_cache( fd_gui_t * gui ) {
    1031           0 :   fd_topo_t const * topo = gui->topo;
    1032             : 
    1033           0 :   ulong insertions      = 0UL;
    1034           0 :   ulong insertion_bytes = 0UL;
    1035           0 :   ulong evictions       = 0UL;
    1036           0 :   ulong eviction_bytes  = 0UL;
    1037           0 :   ulong spills          = 0UL;
    1038           0 :   ulong spill_bytes     = 0UL;
    1039             : 
    1040           0 :   for( ulong i=0UL; i<gui->summary.execrp_tile_cnt; i++ ) {
    1041           0 :     fd_topo_tile_t const * execrp = &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ];
    1042           0 :     volatile ulong const * metrics = fd_metrics_tile( execrp->metrics );
    1043             : 
    1044           0 :     insertions      += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_FILL          ) ];
    1045           0 :     insertion_bytes += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_FILL_BYTES     ) ];
    1046           0 :     evictions       += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_EVICTION      ) ];
    1047           0 :     eviction_bytes  += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_EVICTION_BYTES ) ];
    1048           0 :     spills          += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_SPILL         ) ];
    1049           0 :     spill_bytes     += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_SPILL_BYTES    ) ];
    1050           0 :   }
    1051             : 
    1052           0 :   ulong free_bytes = 0UL;
    1053           0 :   ulong size_bytes = 0UL;
    1054             : 
    1055           0 :   fd_topo_tile_t const * replay = &topo->tiles[ fd_topo_find_tile( topo, "replay", 0UL ) ];
    1056           0 :   volatile ulong const * replay_metrics = fd_metrics_tile( replay->metrics );
    1057             : 
    1058           0 :   free_bytes = replay_metrics[ MIDX( GAUGE, REPLAY, PROGCACHE_FREE_BYTES ) ];
    1059           0 :   size_bytes = replay_metrics[ MIDX( GAUGE, REPLAY, PROGCACHE_SIZE_BYTES ) ];
    1060             : 
    1061           0 :   jsonp_open_envelope( gui->http, "summary", "live_program_cache" );
    1062           0 :     jsonp_open_object( gui->http, "value" );
    1063           0 :       jsonp_ulong( gui->http, "hits",            gui->summary.progcache_hits_1min    );
    1064           0 :       jsonp_ulong( gui->http, "lookups",         gui->summary.progcache_lookups_1min );
    1065           0 :       jsonp_ulong( gui->http, "insertions",      insertions      );
    1066           0 :       jsonp_ulong( gui->http, "insertion_bytes", insertion_bytes );
    1067           0 :       jsonp_ulong( gui->http, "evictions",       evictions       );
    1068           0 :       jsonp_ulong( gui->http, "eviction_bytes",  eviction_bytes  );
    1069           0 :       jsonp_ulong( gui->http, "spills",          spills          );
    1070           0 :       jsonp_ulong( gui->http, "spill_bytes",     spill_bytes     );
    1071           0 :       jsonp_ulong( gui->http, "free_bytes",      free_bytes      );
    1072           0 :       jsonp_ulong( gui->http, "size_bytes",      size_bytes      );
    1073           0 :     jsonp_close_object( gui->http );
    1074           0 :   jsonp_close_envelope( gui->http );
    1075           0 : }
    1076             : 
    1077             : void
    1078           0 : fd_gui_printf_health( fd_gui_t * gui ) {
    1079           0 :   fd_topo_t const * topo = gui->topo;
    1080             : 
    1081           0 :   ulong diag_tile_idx = fd_topo_find_tile( topo, "diag", 0UL );
    1082             : 
    1083             :   /* Default to disabled if no diag tile */
    1084           0 :   ulong bundle_status  = FD_DIAG_BUNDLE_STATUS_DISABLED;
    1085           0 :   ulong vote_status    = FD_DIAG_VOTE_STATUS_DISABLED;
    1086           0 :   ulong replay_status  = FD_DIAG_REPLAY_STATUS_DISABLED;
    1087           0 :   ulong turbine_status = FD_DIAG_TURBINE_STATUS_DISABLED;
    1088             : 
    1089           0 :   if( FD_LIKELY( diag_tile_idx!=ULONG_MAX ) ) {
    1090           0 :     volatile ulong const * metrics = fd_metrics_tile( topo->tiles[ diag_tile_idx ].metrics );
    1091           0 :     bundle_status  = metrics[ MIDX( GAUGE, DIAG, BUNDLE_STATUS  ) ];
    1092           0 :     vote_status    = metrics[ MIDX( GAUGE, DIAG, VOTE_STATUS    ) ];
    1093           0 :     replay_status  = metrics[ MIDX( GAUGE, DIAG, REPLAY_STATUS  ) ];
    1094           0 :     turbine_status = metrics[ MIDX( GAUGE, DIAG, TURBINE_STATUS ) ];
    1095           0 :   }
    1096             : 
    1097           0 :   if( FD_UNLIKELY( !gui->summary.is_full_client ) ) {
    1098           0 :     switch( gui->summary.vote_state ) {
    1099           0 :       case FD_GUI_VOTE_STATE_VOTING:     vote_status = FD_DIAG_VOTE_STATUS_VOTING;     break;
    1100           0 :       case FD_GUI_VOTE_STATE_DELINQUENT: vote_status = FD_DIAG_VOTE_STATUS_DELINQUENT; break;
    1101           0 :       default:                           vote_status = FD_DIAG_VOTE_STATUS_DISABLED;   break;
    1102           0 :     }
    1103           0 :     replay_status  = FD_DIAG_REPLAY_STATUS_DISABLED;
    1104           0 :     turbine_status = FD_DIAG_TURBINE_STATUS_DISABLED;
    1105           0 :   }
    1106             : 
    1107             :   /* Map bundle status to string */
    1108           0 :   char const * bundle_str;
    1109           0 :   switch( bundle_status ) {
    1110           0 :     case FD_DIAG_BUNDLE_STATUS_DISCONNECTED: bundle_str = "disconnected"; break;
    1111           0 :     case FD_DIAG_BUNDLE_STATUS_CONNECTING:   bundle_str = "connecting";   break;
    1112           0 :     case FD_DIAG_BUNDLE_STATUS_CONNECTED:    bundle_str = "connected";    break;
    1113           0 :     case FD_DIAG_BUNDLE_STATUS_SLEEPING:     bundle_str = "sleeping";     break;
    1114           0 :     default:                                 bundle_str = "disabled";     break;
    1115           0 :   }
    1116             : 
    1117             :   /* Map vote status to string */
    1118           0 :   char const * vote_str;
    1119           0 :   switch( vote_status ) {
    1120           0 :     case FD_DIAG_VOTE_STATUS_NOT_STARTED: vote_str = "not_started"; break;
    1121           0 :     case FD_DIAG_VOTE_STATUS_DELINQUENT:  vote_str = "delinquent";  break;
    1122           0 :     case FD_DIAG_VOTE_STATUS_VOTING:      vote_str = "voting";      break;
    1123           0 :     default:                              vote_str = "disabled";    break;
    1124           0 :   }
    1125             : 
    1126             :   /* Map replay status to string */
    1127           0 :   char const * replay_str;
    1128           0 :   switch( replay_status ) {
    1129           0 :     case FD_DIAG_REPLAY_STATUS_NOT_STARTED: replay_str = "not_started"; break;
    1130           0 :     case FD_DIAG_REPLAY_STATUS_BEHIND:      replay_str = "behind";      break;
    1131           0 :     case FD_DIAG_REPLAY_STATUS_RUNNING:     replay_str = "running";     break;
    1132           0 :     default:                                replay_str = "disabled";    break;
    1133           0 :   }
    1134             : 
    1135             :   /* Map turbine status to string */
    1136           0 :   char const * turbine_str;
    1137           0 :   switch( turbine_status ) {
    1138           0 :     case FD_DIAG_TURBINE_STATUS_NOT_STARTED:      turbine_str = "not_started";      break;
    1139           0 :     case FD_DIAG_TURBINE_STATUS_STALLED:          turbine_str = "stalled";          break;
    1140           0 :     case FD_DIAG_TURBINE_STATUS_REPAIR_OUTPACING: turbine_str = "repair_outpacing"; break;
    1141           0 :     case FD_DIAG_TURBINE_STATUS_RUNNING:          turbine_str = "running";          break;
    1142           0 :     default:                                      turbine_str = "disabled";         break;
    1143           0 :   }
    1144             : 
    1145           0 :   jsonp_open_envelope( gui->http, "summary", "health" );
    1146           0 :     jsonp_open_object( gui->http, "value" );
    1147           0 :       jsonp_string( gui->http, "vote",    vote_str    );
    1148           0 :       jsonp_string( gui->http, "bundle",  bundle_str  );
    1149           0 :       jsonp_string( gui->http, "replay",  replay_str  );
    1150           0 :       jsonp_string( gui->http, "turbine", turbine_str );
    1151           0 :     jsonp_close_object( gui->http );
    1152           0 :   jsonp_close_envelope( gui->http );
    1153           0 : }
    1154             : 
    1155             : /* Triangular-weighted average of a delta ring.  Newest sample has
    1156             :    weight n, oldest has weight 1.  Returns sum(w*delta) / weighted_dt
    1157             :    where weighted_dt is precomputed (sum of w * dt_sec for the same
    1158             :    samples). */
    1159             : static double
    1160             : fd_gui_accdb_weighted_rate( ulong const * ring,
    1161             :                             ulong         next_write_idx,
    1162             :                             ulong         n,
    1163           0 :                             double        weighted_dt ) {
    1164           0 :   if( !n || weighted_dt<=0.0 ) return 0.0;
    1165           0 :   double num = 0.0;
    1166           0 :   for( ulong k=0UL; k<n; k++ ) {
    1167           0 :     double w  = (double)(n - k);
    1168           0 :     ulong  ri = (next_write_idx + FD_GUI_ACCDB_WIN_SAMPLES - 1UL - k) % FD_GUI_ACCDB_WIN_SAMPLES;
    1169           0 :     num += w * (double)ring[ ri ];
    1170           0 :   }
    1171           0 :   return num / weighted_dt;
    1172           0 : }
    1173             : 
    1174             : void
    1175           0 : fd_gui_printf_accounts_stats( fd_gui_t * gui ) {
    1176           0 :   fd_gui_accounts_stats_t const * cur  = gui->summary.accounts_stats_current;
    1177           0 :   fd_gui_accounts_stats_t const * prev = gui->summary.accounts_stats_reference;
    1178           0 :   int have_ref = gui->summary.accounts_stats_have_reference;
    1179             : 
    1180           0 :   long  dt_nanos = have_ref ? (cur->sample_time_nanos - prev->sample_time_nanos) : 0L;
    1181             : 
    1182             :   /* Append this snap's deltas to the triangular-window rings.  The
    1183             :      emit code below applies triangular weights to compute the smoothed
    1184             :      rate.  Buffer is a simple ring; idx points to the next write slot. */
    1185           0 :   if( have_ref && dt_nanos>0L ) {
    1186           0 :     ulong i = gui->summary.accdb->accdb_win_idx;
    1187             : 
    1188           0 :     gui->summary.accdb->accdb_win_dt_nanos          [ i ] = dt_nanos;
    1189           0 :     gui->summary.accdb->agg_acquired_win            [ i ] = cur->acquired                 - prev->acquired                ;
    1190           0 :     gui->summary.accdb->agg_acquired_writable_win   [ i ] = cur->acquired_writable        - prev->acquired_writable       ;
    1191           0 :     gui->summary.accdb->agg_bytes_read_win          [ i ] = cur->bytes_read               - prev->bytes_read              ;
    1192           0 :     gui->summary.accdb->agg_bytes_copied_win        [ i ] = cur->bytes_copied             - prev->bytes_copied            ;
    1193           0 :     gui->summary.accdb->agg_bytes_written_win       [ i ] = cur->bytes_written            - prev->bytes_written           ;
    1194           0 :     gui->summary.accdb->agg_bytes_written_accdb_win [ i ] = cur->bytes_written_accdb      - prev->bytes_written_accdb     ;
    1195           0 :     gui->summary.accdb->agg_read_ops_win            [ i ] = cur->read_ops                 - prev->read_ops                ;
    1196           0 :     gui->summary.accdb->agg_write_ops_win           [ i ] = cur->write_ops                - prev->write_ops               ;
    1197           0 :     gui->summary.accdb->agg_relocated_bytes_win     [ i ] = cur->accounts_relocated_bytes - prev->accounts_relocated_bytes;
    1198             : 
    1199           0 :     ulong agg_misses_delta = 0UL;
    1200           0 :     for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {
    1201           0 :       ulong d = cur->not_found_per_class[ c ] - prev->not_found_per_class[ c ];
    1202           0 :       agg_misses_delta += d;
    1203           0 :       gui->summary.accdb->class_acq_win        [ c ][ i ] = cur->acquired_per_class            [ c ] - prev->acquired_per_class            [ c ];
    1204           0 :       gui->summary.accdb->class_acq_wr_win     [ c ][ i ] = cur->acquired_writable_per_class   [ c ] - prev->acquired_writable_per_class   [ c ];
    1205           0 :       gui->summary.accdb->class_not_found_win  [ c ][ i ] = d;
    1206           0 :       gui->summary.accdb->class_evicted_win    [ c ][ i ] = cur->evicted_per_class             [ c ] - prev->evicted_per_class             [ c ];
    1207           0 :       gui->summary.accdb->class_preevicted_win [ c ][ i ] = cur->preevicted_per_class          [ c ] - prev->preevicted_per_class          [ c ];
    1208           0 :       gui->summary.accdb->class_commit_new_win [ c ][ i ] = cur->committed_new_per_class       [ c ] - prev->committed_new_per_class       [ c ];
    1209           0 :       gui->summary.accdb->class_commit_over_win[ c ][ i ] = cur->committed_overwrite_per_class [ c ] - prev->committed_overwrite_per_class [ c ];
    1210           0 :     }
    1211           0 :     gui->summary.accdb->agg_misses_win[ i ] = agg_misses_delta;
    1212             : 
    1213             :     /* Per-partition deltas.  Diff against prev and push into ring. */
    1214           0 :     for( ulong p=0UL; p<gui->summary.accdb->partition_cnt; p++ ) {
    1215           0 :       fd_accdb_shmem_partition_info_t const * info = &gui->summary.accdb->partitions[ p ];
    1216             : 
    1217             :       /* Pool slots get reused: when a partition is released and
    1218             :          re-acquired, change_partition zeroes its counters.  Detect
    1219             :          the reset (any counter dropped below its previous value) and
    1220             :          treat this sample as the start of a new lifecycle — emit a
    1221             :          zero delta rather than letting the unsigned subtract wrap
    1222             :          into a giant rate. */
    1223           0 :       int reset = info->read_ops      < gui->summary.accdb->partition_prev_read_ops     [ p ] ||
    1224           0 :                   info->bytes_read    < gui->summary.accdb->partition_prev_bytes_read   [ p ] ||
    1225           0 :                   info->write_ops     < gui->summary.accdb->partition_prev_write_ops    [ p ] ||
    1226           0 :                   info->bytes_written < gui->summary.accdb->partition_prev_bytes_written[ p ];
    1227           0 :       if( FD_UNLIKELY( reset ) ) {
    1228           0 :         gui->summary.accdb->partition_prev_read_ops     [ p ] = info->read_ops;
    1229           0 :         gui->summary.accdb->partition_prev_bytes_read   [ p ] = info->bytes_read;
    1230           0 :         gui->summary.accdb->partition_prev_write_ops    [ p ] = info->write_ops;
    1231           0 :         gui->summary.accdb->partition_prev_bytes_written[ p ] = info->bytes_written;
    1232             :         /* Also wipe the historical window so an old lifecycle's
    1233             :            samples don't keep contributing to this slot's rate. */
    1234           0 :         for( ulong k=0UL; k<FD_GUI_ACCDB_WIN_SAMPLES; k++ ) {
    1235           0 :           gui->summary.accdb->partition_read_ops_win     [ p ][ k ] = 0UL;
    1236           0 :           gui->summary.accdb->partition_bytes_read_win   [ p ][ k ] = 0UL;
    1237           0 :           gui->summary.accdb->partition_write_ops_win    [ p ][ k ] = 0UL;
    1238           0 :           gui->summary.accdb->partition_bytes_written_win[ p ][ k ] = 0UL;
    1239           0 :         }
    1240           0 :       }
    1241           0 :       gui->summary.accdb->partition_read_ops_win     [ p ][ i ] = info->read_ops      - gui->summary.accdb->partition_prev_read_ops     [ p ];
    1242           0 :       gui->summary.accdb->partition_bytes_read_win   [ p ][ i ] = info->bytes_read    - gui->summary.accdb->partition_prev_bytes_read   [ p ];
    1243           0 :       gui->summary.accdb->partition_write_ops_win    [ p ][ i ] = info->write_ops     - gui->summary.accdb->partition_prev_write_ops    [ p ];
    1244           0 :       gui->summary.accdb->partition_bytes_written_win[ p ][ i ] = info->bytes_written - gui->summary.accdb->partition_prev_bytes_written[ p ];
    1245             : 
    1246           0 :       gui->summary.accdb->partition_prev_read_ops     [ p ] = info->read_ops;
    1247           0 :       gui->summary.accdb->partition_prev_bytes_read   [ p ] = info->bytes_read;
    1248           0 :       gui->summary.accdb->partition_prev_write_ops    [ p ] = info->write_ops;
    1249           0 :       gui->summary.accdb->partition_prev_bytes_written[ p ] = info->bytes_written;
    1250           0 :     }
    1251             : 
    1252             :     /* Per-tile deltas.  Cumulative values were snapped from each tile's
    1253             :        metric page in fd_gui_accounts_stats_snap; diff against prev and
    1254             :        push into the ring. */
    1255           0 :     for( ulong s=0UL; s<gui->summary.accdb->accdb_tile_cnt; s++ ) {
    1256           0 :       gui->summary.accdb->tile_acquired_win         [ s ][ i ] = gui->summary.accdb->tile_cur_acquired         [ s ] - gui->summary.accdb->tile_prev_acquired         [ s ];
    1257           0 :       gui->summary.accdb->tile_acquired_writable_win[ s ][ i ] = gui->summary.accdb->tile_cur_acquired_writable[ s ] - gui->summary.accdb->tile_prev_acquired_writable[ s ];
    1258           0 :       gui->summary.accdb->tile_bytes_read_win       [ s ][ i ] = gui->summary.accdb->tile_cur_bytes_read       [ s ] - gui->summary.accdb->tile_prev_bytes_read       [ s ];
    1259           0 :       gui->summary.accdb->tile_bytes_copied_win     [ s ][ i ] = gui->summary.accdb->tile_cur_bytes_copied     [ s ] - gui->summary.accdb->tile_prev_bytes_copied     [ s ];
    1260           0 :       gui->summary.accdb->tile_bytes_written_win    [ s ][ i ] = gui->summary.accdb->tile_cur_bytes_written    [ s ] - gui->summary.accdb->tile_prev_bytes_written    [ s ];
    1261           0 :       gui->summary.accdb->tile_read_ops_win         [ s ][ i ] = gui->summary.accdb->tile_cur_read_ops         [ s ] - gui->summary.accdb->tile_prev_read_ops         [ s ];
    1262           0 :       gui->summary.accdb->tile_write_ops_win        [ s ][ i ] = gui->summary.accdb->tile_cur_write_ops        [ s ] - gui->summary.accdb->tile_prev_write_ops        [ s ];
    1263           0 :       gui->summary.accdb->tile_misses_win           [ s ][ i ] = gui->summary.accdb->tile_cur_misses           [ s ] - gui->summary.accdb->tile_prev_misses           [ s ];
    1264           0 :       gui->summary.accdb->tile_evicted_win          [ s ][ i ] = gui->summary.accdb->tile_cur_evicted          [ s ] - gui->summary.accdb->tile_prev_evicted          [ s ];
    1265           0 :       gui->summary.accdb->tile_committed_win        [ s ][ i ] = gui->summary.accdb->tile_cur_committed        [ s ] - gui->summary.accdb->tile_prev_committed        [ s ];
    1266           0 :       gui->summary.accdb->tile_acquire_calls_win    [ s ][ i ] = gui->summary.accdb->tile_cur_acquire_calls    [ s ] - gui->summary.accdb->tile_prev_acquire_calls    [ s ];
    1267             : 
    1268           0 :       gui->summary.accdb->tile_prev_acquired         [ s ] = gui->summary.accdb->tile_cur_acquired         [ s ];
    1269           0 :       gui->summary.accdb->tile_prev_acquired_writable[ s ] = gui->summary.accdb->tile_cur_acquired_writable[ s ];
    1270           0 :       gui->summary.accdb->tile_prev_bytes_read       [ s ] = gui->summary.accdb->tile_cur_bytes_read       [ s ];
    1271           0 :       gui->summary.accdb->tile_prev_bytes_copied     [ s ] = gui->summary.accdb->tile_cur_bytes_copied     [ s ];
    1272           0 :       gui->summary.accdb->tile_prev_bytes_written    [ s ] = gui->summary.accdb->tile_cur_bytes_written    [ s ];
    1273           0 :       gui->summary.accdb->tile_prev_read_ops         [ s ] = gui->summary.accdb->tile_cur_read_ops         [ s ];
    1274           0 :       gui->summary.accdb->tile_prev_write_ops        [ s ] = gui->summary.accdb->tile_cur_write_ops        [ s ];
    1275           0 :       gui->summary.accdb->tile_prev_misses           [ s ] = gui->summary.accdb->tile_cur_misses           [ s ];
    1276           0 :       gui->summary.accdb->tile_prev_evicted          [ s ] = gui->summary.accdb->tile_cur_evicted          [ s ];
    1277           0 :       gui->summary.accdb->tile_prev_committed        [ s ] = gui->summary.accdb->tile_cur_committed        [ s ];
    1278           0 :       gui->summary.accdb->tile_prev_acquire_calls    [ s ] = gui->summary.accdb->tile_cur_acquire_calls    [ s ];
    1279             : 
    1280             :       /* 60s sparkline accumulator.  Sum this snap's delta into the
    1281             :          in-flight 1-second bucket; when the bucket closes (>=1s since
    1282             :          it opened), shift the history rings right (newest at index 0)
    1283             :          and start a new bucket with the leftover delta. */
    1284           0 :       ulong d_acq    = gui->summary.accdb->tile_acquired_win         [ s ][ i ];
    1285           0 :       ulong d_acq_wr = gui->summary.accdb->tile_acquired_writable_win[ s ][ i ];
    1286           0 :       gui->summary.accdb->tile_sparkline_acq_bucket   [ s ] += d_acq;
    1287           0 :       gui->summary.accdb->tile_sparkline_acq_wr_bucket[ s ] += d_acq_wr;
    1288             : 
    1289           0 :       long bucket_age = cur->sample_time_nanos - gui->summary.accdb->tile_sparkline_bucket_start_nanos[ s ];
    1290           0 :       if( gui->summary.accdb->tile_sparkline_bucket_start_nanos[ s ]==0L ) {
    1291             :         /* First snap for this slot — just open a bucket. */
    1292           0 :         gui->summary.accdb->tile_sparkline_bucket_start_nanos[ s ] = cur->sample_time_nanos;
    1293           0 :       } else if( bucket_age>=FD_GUI_ACCDB_SPARKLINE_BUCKET_NS ) {
    1294             :         /* Close the bucket: normalize to per-second, shift right, push. */
    1295           0 :         double secs = (double)bucket_age / 1e9;
    1296           0 :         double acq_rate    = (double)gui->summary.accdb->tile_sparkline_acq_bucket   [ s ] / secs;
    1297           0 :         double acq_wr_rate = (double)gui->summary.accdb->tile_sparkline_acq_wr_bucket[ s ] / secs;
    1298           0 :         memmove( &gui->summary.accdb->tile_sparkline_acq_history   [ s ][ 1 ],
    1299           0 :                  &gui->summary.accdb->tile_sparkline_acq_history   [ s ][ 0 ],
    1300           0 :                  (FD_GUI_ACCDB_SPARKLINE_SAMPLES-1UL)*sizeof(double) );
    1301           0 :         memmove( &gui->summary.accdb->tile_sparkline_acq_wr_history[ s ][ 1 ],
    1302           0 :                  &gui->summary.accdb->tile_sparkline_acq_wr_history[ s ][ 0 ],
    1303           0 :                  (FD_GUI_ACCDB_SPARKLINE_SAMPLES-1UL)*sizeof(double) );
    1304           0 :         gui->summary.accdb->tile_sparkline_acq_history   [ s ][ 0 ] = acq_rate;
    1305           0 :         gui->summary.accdb->tile_sparkline_acq_wr_history[ s ][ 0 ] = acq_wr_rate;
    1306           0 :         if( gui->summary.accdb->tile_sparkline_count[ s ]<FD_GUI_ACCDB_SPARKLINE_SAMPLES )
    1307           0 :           gui->summary.accdb->tile_sparkline_count[ s ]++;
    1308           0 :         gui->summary.accdb->tile_sparkline_acq_bucket        [ s ] = 0UL;
    1309           0 :         gui->summary.accdb->tile_sparkline_acq_wr_bucket     [ s ] = 0UL;
    1310           0 :         gui->summary.accdb->tile_sparkline_bucket_start_nanos[ s ] = cur->sample_time_nanos;
    1311           0 :       }
    1312           0 :     }
    1313             : 
    1314           0 :     gui->summary.accdb->accdb_win_idx = (i+1UL) % FD_GUI_ACCDB_WIN_SAMPLES;
    1315           0 :     if( gui->summary.accdb->accdb_win_count<FD_GUI_ACCDB_WIN_SAMPLES )
    1316           0 :       gui->summary.accdb->accdb_win_count++;
    1317           0 :   }
    1318             : 
    1319             :   /* Compute weighted denominator once: sum(weight * dt_sec).  Newest
    1320             :      sample has weight n, oldest has weight 1.  If unfilled, only the
    1321             :      count samples are used (so first-snap rate is meaningful). */
    1322           0 :   ulong  n           = gui->summary.accdb->accdb_win_count;
    1323           0 :   double weighted_dt = 0.0;
    1324           0 :   for( ulong k=0UL; k<n; k++ ) {
    1325             :     /* k=0 is newest, k=n-1 is oldest; weight = n - k */
    1326           0 :     double w  = (double)(n - k);
    1327             :     /* idx-1-k in ring */
    1328           0 :     ulong  ri = (gui->summary.accdb->accdb_win_idx + FD_GUI_ACCDB_WIN_SAMPLES - 1UL - k) % FD_GUI_ACCDB_WIN_SAMPLES;
    1329           0 :     weighted_dt += w * (double)gui->summary.accdb->accdb_win_dt_nanos[ ri ] / 1e9;
    1330           0 :   }
    1331             : 
    1332             :   /* Helper: weighted rate of a delta ring. */
    1333           0 : # define WRATE( ring ) ( fd_gui_accdb_weighted_rate( (ring), gui->summary.accdb->accdb_win_idx, n, weighted_dt ) )
    1334             : 
    1335           0 :   double agg_acquired_rate          = WRATE( gui->summary.accdb->agg_acquired_win            );
    1336           0 :   double agg_acquired_writable_rate = WRATE( gui->summary.accdb->agg_acquired_writable_win   );
    1337           0 :   double agg_bytes_read_rate        = WRATE( gui->summary.accdb->agg_bytes_read_win          );
    1338           0 :   double agg_bytes_copied_rate      = WRATE( gui->summary.accdb->agg_bytes_copied_win        );
    1339           0 :   double agg_bytes_written_rate     = WRATE( gui->summary.accdb->agg_bytes_written_win       );
    1340           0 :   double agg_bytes_written_accdb_rate = WRATE( gui->summary.accdb->agg_bytes_written_accdb_win );
    1341           0 :   double agg_read_ops_rate          = WRATE( gui->summary.accdb->agg_read_ops_win            );
    1342           0 :   double agg_write_ops_rate         = WRATE( gui->summary.accdb->agg_write_ops_win           );
    1343           0 :   double agg_relocated_bytes_rate   = WRATE( gui->summary.accdb->agg_relocated_bytes_win     );
    1344           0 :   double agg_misses_rate            = WRATE( gui->summary.accdb->agg_misses_win              );
    1345             : 
    1346           0 :   double agg_hit_rate = agg_acquired_rate>0.0
    1347           0 :     ? fmax( 0.0, 1.0 - agg_misses_rate / agg_acquired_rate )
    1348           0 :     : 0.0;
    1349             : 
    1350             : 
    1351           0 :   jsonp_open_envelope( gui->http, "accounts", "stats" );
    1352           0 :     jsonp_open_object( gui->http, "value" );
    1353           0 :       jsonp_long( gui->http, "sample_time_nanos", cur->sample_time_nanos );
    1354             : 
    1355           0 :       jsonp_open_object( gui->http, "disk" );
    1356           0 :         jsonp_ulong(  gui->http, "accounts_total",       cur->accounts_total       );
    1357           0 :         jsonp_ulong(  gui->http, "accounts_capacity",    cur->accounts_capacity    );
    1358           0 :         jsonp_ulong(  gui->http, "allocated_bytes",      cur->disk_allocated_bytes );
    1359           0 :         jsonp_ulong(  gui->http, "current_bytes",        cur->disk_current_bytes   );
    1360           0 :         jsonp_ulong(  gui->http, "used_bytes",           cur->disk_used_bytes      );
    1361           0 :       jsonp_close_object( gui->http );
    1362             : 
    1363           0 :       jsonp_open_object( gui->http, "compaction" );
    1364           0 :         jsonp_ulong(  gui->http, "in_compaction",            cur->in_compaction            );
    1365           0 :         if( FD_LIKELY( gui->summary.accdb->next_compaction_partition_idx!=ULONG_MAX ) ) {
    1366           0 :           jsonp_double( gui->http, "next_compaction_remaining_seconds", gui->summary.accdb->next_compaction_remaining_secs );
    1367           0 :           jsonp_ulong(  gui->http, "next_compaction_partition_idx",     gui->summary.accdb->next_compaction_partition_idx  );
    1368           0 :         } else {
    1369           0 :           jsonp_null( gui->http, "next_compaction_remaining_seconds" );
    1370           0 :           jsonp_null( gui->http, "next_compaction_partition_idx"     );
    1371           0 :         }
    1372           0 :         jsonp_ulong(  gui->http, "compactions_requested",    cur->compactions_requested    );
    1373           0 :         jsonp_ulong(  gui->http, "compactions_completed",    cur->compactions_completed    );
    1374           0 :         jsonp_ulong(  gui->http, "accounts_relocated_bytes", cur->accounts_relocated_bytes );
    1375           0 :         jsonp_double( gui->http, "relocated_bytes_per_sec",  agg_relocated_bytes_rate );
    1376           0 :       jsonp_close_object( gui->http );
    1377             : 
    1378           0 :       ulong cache_size_bytes = 0UL;
    1379           0 :       ulong gui_tile_idx = fd_topo_find_tile( gui->topo, "gui", 0UL );
    1380           0 :       if( FD_LIKELY( gui_tile_idx!=ULONG_MAX ) ) {
    1381           0 :         cache_size_bytes = gui->topo->tiles[ gui_tile_idx ].gui.cache_size_gib * (1UL<<30);
    1382           0 :       }
    1383             : 
    1384           0 :       jsonp_open_object( gui->http, "cache" );
    1385           0 :         jsonp_double_4dp( gui->http, "hit_rate_ema", agg_hit_rate );
    1386           0 :         jsonp_ulong(  gui->http, "size_bytes",   cache_size_bytes );
    1387             : 
    1388           0 :         jsonp_open_array( gui->http, "classes" );
    1389           0 :           for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {
    1390           0 :             jsonp_open_object( gui->http, NULL );
    1391           0 :               jsonp_ulong(  gui->http, "class",                 c );
    1392           0 :               jsonp_ulong(  gui->http, "used_slots",            cur->cache_class_used           [ c ] );
    1393           0 :               jsonp_ulong(  gui->http, "max_slots",             cur->cache_class_max            [ c ] );
    1394           0 :               jsonp_ulong(  gui->http, "reserved_slots",        cur->cache_class_reserved       [ c ] );
    1395           0 :               jsonp_ulong(  gui->http, "target_used_slots",     cur->cache_class_target_used    [ c ] );
    1396           0 :               jsonp_ulong(  gui->http, "low_water_used_slots",  cur->cache_class_low_water_used [ c ] );
    1397           0 :               jsonp_ulong(  gui->http, "not_found",             cur->not_found_per_class           [ c ] );
    1398           0 :               jsonp_ulong(  gui->http, "evicted",               cur->evicted_per_class             [ c ] );
    1399           0 :               jsonp_ulong(  gui->http, "preevicted",            cur->preevicted_per_class          [ c ] );
    1400           0 :               jsonp_ulong(  gui->http, "committed_new",         cur->committed_new_per_class       [ c ] );
    1401           0 :               jsonp_ulong(  gui->http, "committed_overwrite",   cur->committed_overwrite_per_class [ c ] );
    1402           0 :               double acq_rate    = WRATE( gui->summary.accdb->class_acq_win        [ c ] );
    1403           0 :               double acq_wr_rate = WRATE( gui->summary.accdb->class_acq_wr_win     [ c ] );
    1404           0 :               double nf_rate     = WRATE( gui->summary.accdb->class_not_found_win  [ c ] );
    1405           0 :               jsonp_double( gui->http, "not_found_per_sec",           nf_rate                                                 );
    1406           0 :               jsonp_double( gui->http, "evicted_per_sec",             WRATE( gui->summary.accdb->class_evicted_win    [ c ] ) );
    1407           0 :               jsonp_double( gui->http, "preevicted_per_sec",          WRATE( gui->summary.accdb->class_preevicted_win [ c ] ) );
    1408           0 :               jsonp_double( gui->http, "committed_new_per_sec",       WRATE( gui->summary.accdb->class_commit_new_win [ c ] ) );
    1409           0 :               jsonp_double( gui->http, "committed_overwrite_per_sec", WRATE( gui->summary.accdb->class_commit_over_win[ c ] ) );
    1410             :               /* reads_per_sec = acquired - acquired_writable (per class);
    1411             :                  writes_per_sec = acquired_writable (per class). */
    1412           0 :               jsonp_double( gui->http, "reads_per_sec",  fmax( 0.0, acq_rate - acq_wr_rate ) );
    1413           0 :               jsonp_double( gui->http, "writes_per_sec", acq_wr_rate );
    1414           0 :               jsonp_double_4dp( gui->http, "hit_rate_ema", acq_rate>0.0 ? fmax( 0.0, 1.0 - nf_rate / acq_rate ) : 0.0 );
    1415           0 :             jsonp_close_object( gui->http );
    1416           0 :           }
    1417           0 :         jsonp_close_array( gui->http );
    1418           0 :       jsonp_close_object( gui->http );
    1419             : 
    1420             :       /* Per-tile breakdown.  Iterate the slot table built at init.
    1421             :          snapwr's row disappears when it has reached the shutdown
    1422             :          status (matching how snapwr drops out of the overview tiles
    1423             :          table). */
    1424           0 :       jsonp_open_array( gui->http, "tiles" );
    1425           0 :         for( ulong s=0UL; s<gui->summary.accdb->accdb_tile_cnt; s++ ) {
    1426           0 :           ulong t_idx = (ulong)gui->summary.accdb->accdb_tile_topo_idx[ s ];
    1427           0 :           fd_topo_tile_t const * tile = &gui->topo->tiles[ t_idx ];
    1428           0 :           uchar kind = gui->summary.accdb->accdb_tile_kind[ s ];
    1429             : 
    1430           0 :           if( kind==FD_GUI_ACCDB_TILE_KIND_SNAPWR && gui->summary.accdb->tile_cur_status[ s ]==2U ) continue;
    1431             : 
    1432           0 :           double t_acq_rate    = WRATE( gui->summary.accdb->tile_acquired_win         [ s ] );
    1433           0 :           double t_acq_wr_rate = WRATE( gui->summary.accdb->tile_acquired_writable_win[ s ] );
    1434           0 :           double t_br_rate     = WRATE( gui->summary.accdb->tile_bytes_read_win       [ s ] );
    1435           0 :           double t_bc_rate     = WRATE( gui->summary.accdb->tile_bytes_copied_win     [ s ] );
    1436           0 :           double t_bw_rate     = WRATE( gui->summary.accdb->tile_bytes_written_win    [ s ] );
    1437           0 :           double t_ro_rate     = WRATE( gui->summary.accdb->tile_read_ops_win         [ s ] );
    1438           0 :           double t_wo_rate     = WRATE( gui->summary.accdb->tile_write_ops_win        [ s ] );
    1439           0 :           double t_nf_rate     = WRATE( gui->summary.accdb->tile_misses_win           [ s ] );
    1440           0 :           double t_ev_rate     = WRATE( gui->summary.accdb->tile_evicted_win          [ s ] );
    1441           0 :           double t_cm_rate     = WRATE( gui->summary.accdb->tile_committed_win        [ s ] );
    1442           0 :           double t_ac_rate     = WRATE( gui->summary.accdb->tile_acquire_calls_win    [ s ] );
    1443             : 
    1444           0 :           char const * joiner;
    1445           0 :           switch( kind ) {
    1446           0 :             case FD_GUI_ACCDB_TILE_KIND_RW:     joiner = "RW"; break;
    1447           0 :             case FD_GUI_ACCDB_TILE_KIND_SNAPWR: joiner = "RW"; break;
    1448           0 :             case FD_GUI_ACCDB_TILE_KIND_ACCDB:  joiner = "RW"; break;
    1449           0 :             default:                            joiner = "RO"; break;
    1450           0 :           }
    1451             : 
    1452           0 :           jsonp_open_object( gui->http, NULL );
    1453           0 :             jsonp_string( gui->http, "name",         tile->name );
    1454           0 :             jsonp_ulong(  gui->http, "kind_id",      tile->kind_id );
    1455           0 :             jsonp_string( gui->http, "joiner_type",  joiner );
    1456           0 :             jsonp_ulong(  gui->http, "status",       (ulong)gui->summary.accdb->tile_cur_status[ s ] );
    1457             : 
    1458             :             /* Lifetime totals. */
    1459           0 :             jsonp_ulong(  gui->http, "acquired",      gui->summary.accdb->tile_cur_acquired      [ s ] );
    1460           0 :             jsonp_ulong(  gui->http, "bytes_read",    gui->summary.accdb->tile_cur_bytes_read    [ s ] );
    1461           0 :             jsonp_ulong(  gui->http, "bytes_written", gui->summary.accdb->tile_cur_bytes_written [ s ] );
    1462             : 
    1463             :             /* Rates. */
    1464           0 :             jsonp_double( gui->http, "acquired_per_sec",          t_acq_rate    );
    1465           0 :             jsonp_double( gui->http, "acquired_writable_per_sec", t_acq_wr_rate );
    1466           0 :             jsonp_double( gui->http, "bytes_read_per_sec",        t_br_rate     );
    1467           0 :             jsonp_double( gui->http, "bytes_copied_per_sec",      t_bc_rate     );
    1468           0 :             jsonp_double( gui->http, "bytes_written_per_sec",     t_bw_rate     );
    1469           0 :             jsonp_double( gui->http, "read_ops_per_sec",          t_ro_rate     );
    1470           0 :             jsonp_double( gui->http, "write_ops_per_sec",         t_wo_rate     );
    1471           0 :             jsonp_double( gui->http, "not_found_per_sec",         t_nf_rate     );
    1472           0 :             jsonp_double( gui->http, "evicted_per_sec",           t_ev_rate     );
    1473           0 :             jsonp_double( gui->http, "committed_per_sec",         t_cm_rate     );
    1474           0 :             jsonp_double( gui->http, "acquire_calls_per_sec",     t_ac_rate     );
    1475             : 
    1476           0 :             jsonp_double_4dp( gui->http, "hit_rate_ema", t_acq_rate>0.0 ? fmax( 0.0, 1.0 - t_nf_rate / t_acq_rate ) : 0.0 );
    1477             : 
    1478             :             /* 60-second sparkline history.  Emit oldest-first so the
    1479             :                frontend treats index 0 as the leftmost (oldest) sample. */
    1480           0 :             ulong sp_cnt = gui->summary.accdb->tile_sparkline_count[ s ];
    1481           0 :             jsonp_open_array( gui->http, "acquired_history" );
    1482           0 :               for( ulong k=0UL; k<sp_cnt; k++ ) {
    1483           0 :                 ulong idx = sp_cnt - 1UL - k;
    1484           0 :                 jsonp_double( gui->http, NULL, gui->summary.accdb->tile_sparkline_acq_history[ s ][ idx ] );
    1485           0 :               }
    1486           0 :             jsonp_close_array( gui->http );
    1487           0 :             jsonp_open_array( gui->http, "acquired_writable_history" );
    1488           0 :               for( ulong k=0UL; k<sp_cnt; k++ ) {
    1489           0 :                 ulong idx = sp_cnt - 1UL - k;
    1490           0 :                 jsonp_double( gui->http, NULL, gui->summary.accdb->tile_sparkline_acq_wr_history[ s ][ idx ] );
    1491           0 :               }
    1492           0 :             jsonp_close_array( gui->http );
    1493           0 :           jsonp_close_object( gui->http );
    1494           0 :         }
    1495           0 :       jsonp_close_array( gui->http );
    1496             : 
    1497           0 :       jsonp_open_object( gui->http, "io" );
    1498           0 :         jsonp_ulong(  gui->http, "acquired",            cur->acquired            );
    1499           0 :         jsonp_ulong(  gui->http, "acquired_writable",   cur->acquired_writable   );
    1500           0 :         jsonp_ulong(  gui->http, "bytes_read",          cur->bytes_read          );
    1501           0 :         jsonp_ulong(  gui->http, "bytes_copied",        cur->bytes_copied        );
    1502           0 :         jsonp_ulong(  gui->http, "bytes_written",       cur->bytes_written       );
    1503           0 :         jsonp_ulong(  gui->http, "bytes_written_accdb", cur->bytes_written_accdb );
    1504           0 :         jsonp_ulong(  gui->http, "read_ops",            cur->read_ops            );
    1505           0 :         jsonp_ulong(  gui->http, "write_ops",           cur->write_ops           );
    1506           0 :         jsonp_double( gui->http, "acquired_per_sec",          agg_acquired_rate          );
    1507           0 :         jsonp_double( gui->http, "acquired_writable_per_sec", agg_acquired_writable_rate );
    1508           0 :         jsonp_double( gui->http, "bytes_read_per_sec",        agg_bytes_read_rate        );
    1509           0 :         jsonp_double( gui->http, "bytes_copied_per_sec",      agg_bytes_copied_rate      );
    1510           0 :         jsonp_double( gui->http, "bytes_written_per_sec",     agg_bytes_written_rate     );
    1511           0 :         jsonp_double( gui->http, "read_ops_per_sec",          agg_read_ops_rate          );
    1512           0 :         jsonp_double( gui->http, "write_ops_per_sec",         agg_write_ops_rate         );
    1513             :         /* Prewrite ratio: fraction of bytes written that came from the
    1514             :            accdb tile's background work (preevict + compaction).
    1515             :            cur->bytes_written already includes accdb tile's writes, so
    1516             :            the ratio is just accdb_rate / bytes_written_rate. */
    1517           0 :         jsonp_double( gui->http, "prewrite_ratio",
    1518           0 :                       agg_bytes_written_rate>0.0
    1519           0 :                         ? fmin( 1.0, agg_bytes_written_accdb_rate / agg_bytes_written_rate )
    1520           0 :                         : 0.0 );
    1521           0 :       jsonp_close_object( gui->http );
    1522             : 
    1523             :       /* Per-partition table.  Only emit partitions that have been
    1524             :          written to (skip the cold tail of the pool that has never been
    1525             :          allocated).  Ticks are converted to wallclock nanoseconds using
    1526             :          the GUI tile's locally-measured tick rate, since the accdb hot
    1527             :          path stamps fd_tickcount() rather than fd_log_wallclock() (no
    1528             :          syscall on the IO path). */
    1529           0 :       jsonp_open_array( gui->http, "partitions" );
    1530           0 :       if( FD_LIKELY( gui->accdb_shmem ) ) {
    1531           0 :         ulong  partition_sz = fd_accdb_shmem_partition_sz( gui->accdb_shmem );
    1532           0 :         long   now_ticks    = (long)fd_tickcount();
    1533           0 :         double tick_per_ns  = gui->tick_per_ns;
    1534           0 :         for( ulong p=0UL; p<gui->summary.accdb->partition_cnt; p++ ) {
    1535           0 :           fd_accdb_shmem_partition_info_t const * info = &gui->summary.accdb->partitions[ p ];
    1536             :           /* Skip partitions that have never been written and are not
    1537             :              currently in any compaction state. */
    1538           0 :           if( !info->bytes_written && !info->compaction_state ) continue;
    1539             : 
    1540           0 :           double read_ops_rate     = WRATE( gui->summary.accdb->partition_read_ops_win    [ p ] );
    1541           0 :           double bytes_read_rate   = WRATE( gui->summary.accdb->partition_bytes_read_win  [ p ] );
    1542           0 :           double write_ops_rate    = WRATE( gui->summary.accdb->partition_write_ops_win   [ p ] );
    1543           0 :           double bytes_written_rate= WRATE( gui->summary.accdb->partition_bytes_written_win[p ] );
    1544             : 
    1545           0 :           double age_seconds    = 0.0;
    1546           0 :           double filled_seconds = 0.0;
    1547           0 :           if( info->created_ticks && tick_per_ns>0.0 ) {
    1548           0 :             age_seconds    = ((double)(now_ticks - info->created_ticks)) / tick_per_ns / 1e9;
    1549           0 :             if( age_seconds<0.0 ) age_seconds = 0.0;
    1550           0 :           }
    1551           0 :           if( info->filled_ticks && tick_per_ns>0.0 ) {
    1552           0 :             filled_seconds = ((double)(now_ticks - info->filled_ticks )) / tick_per_ns / 1e9;
    1553           0 :             if( filled_seconds<0.0 ) filled_seconds = 0.0;
    1554           0 :           }
    1555             : 
    1556             :           /* Fully compacted, awaiting reclaim: present as an "Off" tier
    1557             :              with zeroed utilization so the row visually clears once its
    1558             :              data has been moved out. */
    1559           0 :           int    is_compacted   = info->compaction_state==0 &&
    1560           0 :                                   info->write_offset>0UL &&
    1561           0 :                                   info->compaction_offset>=info->write_offset;
    1562           0 :           ulong  tier           = is_compacted ? 255UL : (ulong)info->layer;
    1563           0 :           double utilization    = (!is_compacted && partition_sz)
    1564           0 :             ? (double)info->write_offset / (double)partition_sz : 0.0;
    1565           0 :           double fragmentation  = (!is_compacted && info->write_offset)
    1566           0 :             ? (double)info->bytes_freed / (double)info->write_offset : 0.0;
    1567           0 :           ulong  used_bytes     = (!is_compacted && info->write_offset > info->bytes_freed)
    1568           0 :             ? info->write_offset - info->bytes_freed : 0UL;
    1569           0 :           double used_frac      = partition_sz ? (double)used_bytes        / (double)partition_sz : 0.0;
    1570           0 :           double fragmented_frac= (!is_compacted && partition_sz) ? (double)info->bytes_freed / (double)partition_sz : 0.0;
    1571           0 :           double compaction_frac= (!is_compacted && partition_sz) ? (double)info->compaction_offset / (double)partition_sz : 0.0;
    1572             : 
    1573           0 :           jsonp_open_object( gui->http, NULL );
    1574           0 :             jsonp_ulong(  gui->http, "partition_idx",     p );
    1575           0 :             jsonp_ulong(  gui->http, "file_offset",       info->file_offset );
    1576           0 :             jsonp_ulong(  gui->http, "tier",              tier );
    1577           0 :             jsonp_ulong(  gui->http, "write_offset",      info->write_offset );
    1578           0 :             jsonp_ulong(  gui->http, "bytes_freed",       info->bytes_freed );
    1579           0 :             jsonp_ulong(  gui->http, "read_ops",          info->read_ops );
    1580           0 :             jsonp_ulong(  gui->http, "bytes_read",        info->bytes_read );
    1581           0 :             jsonp_ulong(  gui->http, "write_ops",         info->write_ops );
    1582           0 :             jsonp_ulong(  gui->http, "bytes_written",     info->bytes_written );
    1583           0 :             jsonp_double( gui->http, "read_ops_per_sec",     read_ops_rate );
    1584           0 :             jsonp_double( gui->http, "bytes_read_per_sec",   bytes_read_rate );
    1585           0 :             jsonp_double( gui->http, "write_ops_per_sec",    write_ops_rate );
    1586           0 :             jsonp_double( gui->http, "bytes_written_per_sec",bytes_written_rate );
    1587           0 :             jsonp_double( gui->http, "utilization",       utilization );
    1588           0 :             jsonp_double( gui->http, "fragmentation",     fragmentation );
    1589           0 :             jsonp_double( gui->http, "used_frac",         used_frac );
    1590           0 :             jsonp_double( gui->http, "fragmented_frac",   fragmented_frac );
    1591           0 :             jsonp_double( gui->http, "compaction_trigger_frac", (double)FD_ACCDB_COMPACTION_THRESHOLD_PCT/100.0 );
    1592           0 :             jsonp_double( gui->http, "age_seconds",       age_seconds );
    1593           0 :             jsonp_double( gui->http, "filled_seconds",    filled_seconds );
    1594           0 :             jsonp_ulong(  gui->http, "compaction_state",  (ulong)info->compaction_state );
    1595           0 :             jsonp_double( gui->http, "compaction_frac",   compaction_frac );
    1596           0 :             jsonp_bool(   gui->http, "is_write_head",    (int)info->is_write_head );
    1597           0 :           jsonp_close_object( gui->http );
    1598           0 :         }
    1599           0 :       }
    1600           0 :       jsonp_close_array( gui->http );
    1601             : 
    1602           0 :     jsonp_close_object( gui->http );
    1603           0 :   jsonp_close_envelope( gui->http );
    1604             : 
    1605           0 : # undef WRATE
    1606           0 : }
    1607             : 
    1608             : static void
    1609             : peers_printf_node( fd_gui_peers_ctx_t *  peers,
    1610           0 :                    ulong                 contact_info_table_idx ) {
    1611           0 :   fd_gui_peers_node_t * peer = &peers->contact_info_table[ contact_info_table_idx ];
    1612             : 
    1613           0 :   jsonp_open_object( peers->http, NULL );
    1614             : 
    1615           0 :     char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    1616           0 :     fd_base58_encode_32( peer->row.pubkey.uc, NULL, identity_base58 );
    1617           0 :     jsonp_string( peers->http, "identity_pubkey", identity_base58 );
    1618             : 
    1619           0 :     jsonp_open_object( peers->http, "gossip" );
    1620             : 
    1621           0 :       char version[ 64UL ];
    1622           0 :       FD_TEST( fd_gossip_version_cstr( peer->row.contact_info.version.major, peer->row.contact_info.version.minor, peer->row.contact_info.version.patch, version, sizeof( version ) ) );
    1623           0 :       jsonp_string( peers->http, "version", version );
    1624           0 :       jsonp_ulong( peers->http, "client_id", peer->row.contact_info.version.client );
    1625           0 :       jsonp_ulong( peers->http, "feature_set", peer->row.contact_info.version.feature_set );
    1626           0 :       jsonp_long( peers->http, "wallclock", peer->row.wallclock_nanos );
    1627           0 :       jsonp_ulong( peers->http, "shred_version", peer->row.contact_info.shred_version );
    1628           0 :       jsonp_open_object( peers->http, "sockets" );
    1629           0 :         for( ulong j=0UL; j<FD_GOSSIP_CONTACT_INFO_SOCKET_CNT; j++ ) {
    1630           0 :           char const * tag;
    1631           0 :           switch( j ) {
    1632           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP:            tag = "gossip";            break;
    1633           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_SERVE_REPAIR_QUIC: tag = "serve_repair_quic"; break;
    1634           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_RPC:               tag = "rpc";               break;
    1635           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_RPC_PUBSUB:        tag = "rpc_pubsub";        break;
    1636           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_SERVE_REPAIR:      tag = "serve_repair";      break;
    1637           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU:               tag = "tpu";               break;
    1638           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_FORWARDS:      tag = "tpu_forwards";      break;
    1639           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_FORWARDS_QUIC: tag = "tpu_forwards_quic"; break;
    1640           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_QUIC:          tag = "tpu_quic";          break;
    1641           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_VOTE:          tag = "tpu_vote";          break;
    1642           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TVU:               tag = "tvu";               break;
    1643           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TVU_QUIC:          tag = "tvu_quic";          break;
    1644           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_VOTE_QUIC:     tag = "tpu_vote_quic";     break;
    1645           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_ALPENGLOW:         tag = "alpenglow";         break;
    1646           0 :             default:                                       tag = "unknown";           break;
    1647           0 :           }
    1648           0 :           uint ip4 = peer->row.contact_info.sockets[ j ].is_ipv6 ? 0U : peer->row.contact_info.sockets[ j ].ip4;
    1649           0 :           char line[ 64 ];
    1650           0 :           FD_TEST( fd_cstr_printf( line, sizeof( line ), NULL, FD_IP4_ADDR_FMT ":%hu", FD_IP4_ADDR_FMT_ARGS( ip4 ), fd_ushort_bswap( peer->row.contact_info.sockets[ j ].port ) ) );
    1651           0 :           jsonp_string( peers->http, tag, line );
    1652           0 :         }
    1653           0 :       jsonp_close_object( peers->http );
    1654             : 
    1655           0 :       if( FD_LIKELY( peer->row.country_code_idx!=UCHAR_MAX ) ) {
    1656           0 :         jsonp_string( peers->http, "country_code", peers->dbip.country_code[ peer->row.country_code_idx ] );
    1657           0 :       } else {
    1658           0 :         jsonp_null( peers->http, "country_code" );
    1659           0 :       }
    1660             : 
    1661           0 :       if( FD_LIKELY( peer->row.city_name_idx!=UINT_MAX ) ) {
    1662           0 :         jsonp_string( peers->http, "city_name", peers->dbip.city_name[ peer->row.city_name_idx ] );
    1663           0 :       } else {
    1664           0 :         jsonp_null( peers->http, "city_name" );
    1665           0 :       }
    1666             : 
    1667           0 :     jsonp_close_object( peers->http );
    1668             : 
    1669           0 :     if( FD_LIKELY( !peer->row.has_vote_info ) ) {
    1670           0 :       jsonp_open_array( peers->http, "vote" );
    1671           0 :       jsonp_close_array( peers->http );
    1672           0 :     } else {
    1673           0 :       jsonp_open_array( peers->http, "vote" );
    1674           0 :         jsonp_open_object( peers->http, NULL );
    1675           0 :           char vote_account_base58[ FD_BASE58_ENCODED_32_SZ ];
    1676           0 :           fd_base58_encode_32( peer->row.vote_account.uc, NULL, vote_account_base58 );
    1677           0 :           jsonp_string( peers->http, "vote_account", vote_account_base58 );
    1678           0 :           jsonp_ulong_as_str( peers->http, "activated_stake", fd_ulong_if( peer->row.stake==ULONG_MAX, 0UL, peer->row.stake ) );
    1679           0 :           jsonp_ulong( peers->http, "last_vote", 0UL ); /* todo: deprecate */
    1680           0 :           jsonp_ulong( peers->http, "epoch_credits", 0UL ); /* todo: deprecate */
    1681           0 :           jsonp_ulong( peers->http, "commission", 0UL ); /* todo: deprecate */
    1682           0 :           jsonp_ulong( peers->http, "root_slot", 0UL ); /* todo: deprecate */
    1683           0 :           jsonp_bool( peers->http,  "delinquent", peer->row.delinquent );
    1684           0 :         jsonp_close_object( peers->http );
    1685           0 :       jsonp_close_array( peers->http );
    1686           0 :     }
    1687             : 
    1688           0 :     fd_gui_config_parse_info_t * node_info = fd_gui_peers_node_info_map_ele_query( peers->node_info_map, &peer->row.pubkey, NULL, peers->node_info_pool );
    1689           0 :     if( FD_UNLIKELY( !node_info ) ) {
    1690           0 :       jsonp_string( peers->http, "info", NULL );
    1691           0 :     } else {
    1692           0 :       jsonp_open_object( peers->http, "info" );
    1693           0 :         jsonp_string( peers->http, "name", node_info->name );
    1694           0 :         jsonp_string( peers->http, "details", node_info->details );
    1695           0 :         jsonp_string( peers->http, "website", node_info->website );
    1696           0 :         jsonp_string( peers->http, "icon_url", node_info->icon_uri );
    1697           0 :         jsonp_string( peers->http, "keybase_username", node_info->keybase_username );
    1698           0 :       jsonp_close_object( peers->http );
    1699           0 :     }
    1700             : 
    1701           0 :   jsonp_close_object( peers->http );
    1702           0 : }
    1703             : 
    1704             : void
    1705             : fd_gui_peers_printf_nodes( fd_gui_peers_ctx_t * peers,
    1706             :                            int *                actions,
    1707             :                            ulong *              idxs,
    1708           0 :                            ulong                count ) {
    1709           0 :   jsonp_open_envelope( peers->http, "peers", "update" );
    1710           0 :     jsonp_open_object( peers->http, "value" );
    1711           0 :       jsonp_open_array( peers->http, "add" );
    1712           0 :         for( ulong i=0UL; i<count; i++ ) if( FD_UNLIKELY( actions[ i ]==FD_GUI_PEERS_NODE_ADD ) ) peers_printf_node( peers, idxs[ i ] );
    1713           0 :       jsonp_close_array( peers->http );
    1714             : 
    1715           0 :       jsonp_open_array( peers->http, "update" );
    1716           0 :         for( ulong i=0UL; i<count; i++ ) if( FD_UNLIKELY( actions[ i ]==FD_GUI_PEERS_NODE_UPDATE ) ) peers_printf_node( peers, idxs[ i ] );
    1717           0 :       jsonp_close_array( peers->http );
    1718             : 
    1719           0 :       jsonp_open_array( peers->http, "remove" );
    1720           0 :         for( ulong i=0UL; i<count; i++ ) {
    1721           0 :           if( FD_UNLIKELY( actions[ i ]==FD_GUI_PEERS_NODE_DELETE ) ) {
    1722           0 :             jsonp_open_object( peers->http, NULL );
    1723           0 :               char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    1724           0 :               fd_base58_encode_32( peers->contact_info_table[ idxs[ i ] ].row.pubkey.uc, NULL, identity_base58 );
    1725           0 :               jsonp_string( peers->http, "identity_pubkey", identity_base58 );
    1726           0 :             jsonp_close_object( peers->http );
    1727           0 :           }
    1728           0 :         }
    1729           0 :       jsonp_close_array( peers->http );
    1730           0 :     jsonp_close_object( peers->http );
    1731           0 :   jsonp_close_envelope( peers->http );
    1732           0 : }
    1733             : 
    1734             : void
    1735           0 : fd_gui_peers_printf_node_all( fd_gui_peers_ctx_t *  peers ) {
    1736           0 :   jsonp_open_envelope( peers->http, "peers", "update" );
    1737           0 :     jsonp_open_object( peers->http, "value" );
    1738           0 :       jsonp_open_array( peers->http, "add" );
    1739             :         /* We can iter through the bandwidth tracking table since it will always be populated */
    1740           0 :         for( fd_gui_peers_bandwidth_tracking_fwd_iter_t iter = fd_gui_peers_bandwidth_tracking_fwd_iter_init( peers->bw_tracking, &FD_GUI_PEERS_BW_TRACKING_INGRESS_SORT_KEY, peers->contact_info_table );
    1741           0 :              !fd_gui_peers_bandwidth_tracking_fwd_iter_done( iter );
    1742           0 :              iter = fd_gui_peers_bandwidth_tracking_fwd_iter_next( iter, peers->contact_info_table ) ) {
    1743           0 :           ulong contact_info_table_idx = fd_gui_peers_bandwidth_tracking_fwd_iter_idx( iter );
    1744           0 :           peers_printf_node( peers, contact_info_table_idx );
    1745           0 :         }
    1746           0 :       jsonp_close_array( peers->http );
    1747           0 :       jsonp_open_array( peers->http, "update" );
    1748           0 :       jsonp_close_array( peers->http );
    1749           0 :       jsonp_open_array( peers->http, "remove" );
    1750           0 :       jsonp_close_array( peers->http );
    1751           0 :     jsonp_close_object( peers->http );
    1752           0 :   jsonp_close_envelope( peers->http );
    1753           0 : }
    1754             : 
    1755             : static void
    1756             : fd_gui_printf_ts_tile_timers( fd_gui_t *                        gui,
    1757             :                               long                              sample_time_nanos,
    1758           0 :                               fd_gui_tile_timers_hist_t const * packed ) {
    1759           0 :   jsonp_open_object( gui->http, NULL );
    1760           0 :     jsonp_long_as_str( gui->http, "timestamp_nanos", sample_time_nanos );
    1761           0 :     jsonp_open_array( gui->http, "tile_timers" );
    1762           0 :       fd_gui_printf_tile_timers( gui, packed );
    1763           0 :     jsonp_close_array( gui->http );
    1764           0 :   jsonp_close_object( gui->http );
    1765           0 : }
    1766             : 
    1767             : static int
    1768             : fd_gui_load_leader_meta( fd_gui_t *                      gui,
    1769             :                          ulong                          _slot,
    1770           0 :                          fd_gui_leader_slot_t * out ) {
    1771           0 :   memset( out, 0, sizeof(*out) );
    1772           0 :   if( FD_UNLIKELY( !gui->db ) ) return 0;
    1773           0 :   fd_gui_leader_slot_t const * rec = fd_gui_hist_kv_get_slot_any( gui, FD_GUI_HIST_LEADER_SLOT, _slot );
    1774           0 :   if( FD_UNLIKELY( !rec ) ) return 0;
    1775           0 :   *out = *rec;
    1776           0 :   return 1;
    1777           0 : }
    1778             : 
    1779             : static int
    1780             : fd_gui_load_block_hash( fd_gui_t *  gui,
    1781             :                         ulong       _slot,
    1782           0 :                         fd_hash_t * out ) {
    1783           0 :   if( FD_UNLIKELY( !gui->db ) ) return 0;
    1784             : 
    1785           0 :   fd_gui_slot_t const * replay = fd_gui_hist_kv_get_slot_any( gui, FD_GUI_HIST_SLOT, _slot );
    1786           0 :   if( FD_LIKELY( replay ) ) {
    1787           0 :     *out = replay->block_hash;
    1788           0 :     return 1;
    1789           0 :   }
    1790             : 
    1791           0 :   fd_gui_leader_slot_t const * leader = fd_gui_hist_kv_get_slot_any( gui, FD_GUI_HIST_LEADER_SLOT, _slot );
    1792           0 :   if( FD_LIKELY( leader ) ) {
    1793           0 :     *out = leader->block_hash;
    1794           0 :     return 1;
    1795           0 :   }
    1796             : 
    1797           0 :   return 0;
    1798           0 : }
    1799             : 
    1800             : static long
    1801             : fd_gui_load_slot_duration( fd_gui_t *            gui,
    1802             :                            ulong                 _slot,
    1803           0 :                            fd_gui_slot_t const * slot ) {
    1804           0 :   if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) return LONG_MAX;
    1805             : 
    1806           0 :   long parent_completed_time = LONG_MAX;
    1807           0 :   fd_gui_slot_t * parent_slot = fd_gui_slot_get_canon( gui, slot->parent_slot );
    1808           0 :   if( FD_LIKELY( parent_slot ) ) {
    1809           0 :     parent_completed_time = parent_slot->completed_time;
    1810           0 :   } else if( FD_LIKELY( gui->db ) ) {
    1811           0 :     fd_gui_slot_t const * replay = fd_gui_hist_kv_get_slot_any( gui, FD_GUI_HIST_SLOT, _slot );
    1812           0 :     if( FD_LIKELY( replay ) ) parent_completed_time = replay->parent_completed_time;
    1813           0 :   }
    1814             : 
    1815           0 :   if( FD_UNLIKELY( parent_completed_time==LONG_MAX ) ) return LONG_MAX;
    1816           0 :   return slot->completed_time - parent_completed_time;
    1817           0 : }
    1818             : 
    1819             : void
    1820             : fd_gui_printf_slot( fd_gui_t *            gui,
    1821             :                     ulong                _slot,
    1822           0 :                     fd_gui_slot_t const * slot ) {
    1823           0 :   char const * level;
    1824           0 :   switch( slot->level ) {
    1825           0 :     case FD_GUI_SLOT_LEVEL_INCOMPLETE:               level = "incomplete"; break;
    1826           0 :     case FD_GUI_SLOT_LEVEL_COMPLETED:                level = "completed";  break;
    1827           0 :     case FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED: level = "optimistically_confirmed"; break;
    1828           0 :     case FD_GUI_SLOT_LEVEL_ROOTED:                   level = "rooted"; break;
    1829           0 :     case FD_GUI_SLOT_LEVEL_FINALIZED:                level = "finalized"; break;
    1830           0 :     default:                                         level = "unknown"; break;
    1831           0 :   }
    1832             : 
    1833           0 :   long duration_nanos = fd_gui_load_slot_duration( gui, _slot, slot );
    1834             : 
    1835           0 :   jsonp_open_envelope( gui->http, "slot", "update" );
    1836           0 :     jsonp_open_object( gui->http, "value" );
    1837           0 :       fd_gui_leader_slot_t lmeta[ 1 ];
    1838           0 :       int have_lmeta = fd_gui_load_leader_meta( gui, _slot, lmeta );
    1839           0 :       jsonp_open_object( gui->http, "publish" );
    1840           0 :         jsonp_ulong( gui->http, "slot", _slot );
    1841           0 :         jsonp_bool( gui->http, "mine", slot->mine );
    1842           0 :         if( FD_UNLIKELY( slot->vote_slot!=ULONG_MAX ) ) jsonp_ulong( gui->http, "vote_slot", slot->vote_slot );
    1843           0 :         else                                            jsonp_null( gui->http, "vote_slot" );
    1844           0 :         if( FD_LIKELY( slot->vote_latency_exact!=FD_GUI_VOTE_LATENCY_NOT_VOTED ) ) jsonp_ulong( gui->http, "vote_latency_exact", slot->vote_latency_exact );
    1845           0 :         else                                                                       jsonp_null( gui->http, "vote_latency_exact" );
    1846           0 :         jsonp_bool( gui->http, "is_voter", slot->is_voter );
    1847             : 
    1848           0 :         if( FD_UNLIKELY( have_lmeta && lmeta->leader_start_time!=LONG_MAX ) ) jsonp_long_as_str( gui->http, "start_timestamp_nanos", lmeta->leader_start_time  );
    1849           0 :         else                                                                  jsonp_null       ( gui->http, "start_timestamp_nanos" );
    1850           0 :         if( FD_UNLIKELY( have_lmeta && lmeta->leader_end_time!=LONG_MAX ) ) jsonp_long_as_str( gui->http, "target_end_timestamp_nanos", lmeta->leader_end_time  );
    1851           0 :         else                                                                jsonp_null       ( gui->http, "target_end_timestamp_nanos" );
    1852             : 
    1853           0 :         jsonp_bool( gui->http, "skipped", slot->skip==FD_GUI_SKIP_STATUS_SKIPPED );
    1854           0 :         if( FD_UNLIKELY( duration_nanos==LONG_MAX ) ) jsonp_null( gui->http, "duration_nanos" );
    1855           0 :         else                                          jsonp_long( gui->http, "duration_nanos", duration_nanos );
    1856           0 :         if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) jsonp_null( gui->http, "completed_time_nanos" );
    1857           0 :         else                                                jsonp_long_as_str( gui->http, "completed_time_nanos", slot->completed_time );
    1858           0 :         jsonp_string( gui->http, "level", level );
    1859           0 :         if( FD_UNLIKELY( slot->nonvote_success==UINT_MAX ) ) jsonp_null( gui->http, "success_nonvote_transaction_cnt" );
    1860           0 :         else                                                           jsonp_ulong( gui->http, "success_nonvote_transaction_cnt", slot->nonvote_success );
    1861           0 :         if( FD_UNLIKELY( slot->nonvote_failed==UINT_MAX ) ) jsonp_null( gui->http, "failed_nonvote_transaction_cnt" );
    1862           0 :         else                                                jsonp_ulong( gui->http, "failed_nonvote_transaction_cnt", slot->nonvote_failed );
    1863           0 :         if( FD_UNLIKELY( slot->vote_success==UINT_MAX ) ) jsonp_null( gui->http, "success_vote_transaction_cnt" );
    1864           0 :         else                                              jsonp_ulong( gui->http, "success_vote_transaction_cnt", slot->vote_success );
    1865           0 :         if( FD_UNLIKELY( slot->vote_failed==UINT_MAX ) ) jsonp_null( gui->http, "failed_vote_transaction_cnt" );
    1866           0 :         else                                             jsonp_ulong( gui->http, "failed_vote_transaction_cnt", slot->vote_failed );
    1867           0 :         if( FD_UNLIKELY( slot->max_compute_units==UINT_MAX ) ) jsonp_null( gui->http, "max_compute_units" );
    1868           0 :         else                                                   jsonp_ulong( gui->http, "max_compute_units", slot->max_compute_units );
    1869           0 :         if( FD_UNLIKELY( slot->compute_units==UINT_MAX ) ) jsonp_null( gui->http, "compute_units" );
    1870           0 :         else                                               jsonp_ulong( gui->http, "compute_units", slot->compute_units );
    1871           0 :         if( FD_UNLIKELY( slot->shred_cnt==UINT_MAX ) ) jsonp_null( gui->http, "shreds" );
    1872           0 :         else                                           jsonp_ulong( gui->http, "shreds", slot->shred_cnt );
    1873           0 :         if( FD_UNLIKELY( slot->transaction_fee==ULONG_MAX ) ) jsonp_null( gui->http, "transaction_fee" );
    1874           0 :         else                                                  jsonp_ulong_as_str( gui->http, "transaction_fee", slot->transaction_fee );
    1875           0 :         if( FD_UNLIKELY( slot->priority_fee==ULONG_MAX ) ) jsonp_null( gui->http, "priority_fee" );
    1876           0 :         else                                               jsonp_ulong_as_str( gui->http, "priority_fee", slot->priority_fee );
    1877           0 :         if( FD_UNLIKELY( slot->tips==ULONG_MAX ) ) jsonp_null( gui->http, "tips" );
    1878           0 :         else                                       jsonp_ulong_as_str( gui->http, "tips", slot->tips );
    1879           0 :       jsonp_close_object( gui->http );
    1880           0 :     jsonp_close_object( gui->http );
    1881           0 :   jsonp_close_envelope( gui->http );
    1882           0 : }
    1883             : 
    1884             : void
    1885             : fd_gui_printf_summary_ping( fd_gui_t * gui,
    1886           0 :                             ulong      id ) {
    1887           0 :   jsonp_open_envelope( gui->http, "summary", "ping" );
    1888           0 :     jsonp_ulong( gui->http, "id", id );
    1889           0 :     jsonp_null( gui->http, "value" );
    1890           0 :   jsonp_close_envelope( gui->http );
    1891           0 : }
    1892             : 
    1893             : void
    1894             : fd_gui_printf_slot_rankings_request( fd_gui_t * gui,
    1895             :                                      ulong      id,
    1896           0 :                                      int        mine ) {
    1897           0 :   fd_gui_epoch_t * rec = fd_gui_current_epoch( gui );
    1898             : 
    1899           0 :   fd_gui_slot_rankings_t * rankings = FD_LIKELY( rec )
    1900           0 :     ? fd_ptr_if( mine, (fd_gui_slot_rankings_t *)rec->my_rankings, (fd_gui_slot_rankings_t *)rec->rankings )
    1901           0 :     : NULL;
    1902             : 
    1903           0 :   jsonp_open_envelope( gui->http, "slot", "query_rankings" );
    1904           0 :     jsonp_ulong( gui->http, "id", id );
    1905           0 :     jsonp_open_object( gui->http, "value" );
    1906             : 
    1907           0 : #define OUTPUT_RANKING_ARRAY(field) \
    1908           0 :       jsonp_open_array( gui->http, "slots_" FD_STRINGIFY(field) ); \
    1909           0 :       for( ulong i = 0UL; i<fd_ulong_if( rankings==NULL, 0UL, FD_GUI_SLOT_RANKINGS_SZ ); i++ ) { \
    1910           0 :         if( FD_UNLIKELY( rankings->field[ i ].slot==ULONG_MAX ) ) break; \
    1911           0 :         jsonp_ulong( gui->http, NULL, rankings->field[ i ].slot ); \
    1912           0 :       } \
    1913           0 :       jsonp_close_array( gui->http ); \
    1914           0 :       jsonp_open_array( gui->http, "vals_" FD_STRINGIFY(field) ); \
    1915           0 :       for( ulong i = 0UL; i<fd_ulong_if( rankings==NULL, 0UL, FD_GUI_SLOT_RANKINGS_SZ ); i++ ) { \
    1916           0 :         if( FD_UNLIKELY( rankings->field[ i ].slot==ULONG_MAX ) ) break; \
    1917           0 :         jsonp_ulong( gui->http, NULL, rankings->field[ i ].value ); \
    1918           0 :       } \
    1919           0 :       jsonp_close_array( gui->http )
    1920             : 
    1921           0 :       OUTPUT_RANKING_ARRAY( largest_tips );
    1922           0 :       OUTPUT_RANKING_ARRAY( largest_fees );
    1923           0 :       OUTPUT_RANKING_ARRAY( largest_rewards );
    1924           0 :       OUTPUT_RANKING_ARRAY( largest_rewards_per_cu );
    1925           0 :       OUTPUT_RANKING_ARRAY( largest_duration );
    1926           0 :       OUTPUT_RANKING_ARRAY( largest_compute_units );
    1927           0 :       OUTPUT_RANKING_ARRAY( largest_skipped );
    1928           0 :       OUTPUT_RANKING_ARRAY( smallest_tips );
    1929           0 :       OUTPUT_RANKING_ARRAY( smallest_fees );
    1930           0 :       OUTPUT_RANKING_ARRAY( smallest_rewards );
    1931           0 :       OUTPUT_RANKING_ARRAY( smallest_rewards_per_cu );
    1932           0 :       OUTPUT_RANKING_ARRAY( smallest_duration );
    1933           0 :       OUTPUT_RANKING_ARRAY( smallest_compute_units );
    1934           0 :       OUTPUT_RANKING_ARRAY( smallest_skipped );
    1935             : 
    1936           0 : #undef OUTPUT_RANKING_ARRAY
    1937             : 
    1938           0 :     jsonp_close_object( gui->http );
    1939           0 :   jsonp_close_envelope( gui->http );
    1940           0 : }
    1941             : 
    1942             : void
    1943             : fd_gui_printf_slot_request( fd_gui_t *            gui,
    1944             :                             ulong                _slot,
    1945             :                             ulong                id,
    1946           0 :                             fd_gui_slot_t const * slot ) {
    1947           0 :   char const * level;
    1948           0 :   switch( slot->level ) {
    1949           0 :     case FD_GUI_SLOT_LEVEL_INCOMPLETE:               level = "incomplete"; break;
    1950           0 :     case FD_GUI_SLOT_LEVEL_COMPLETED:                level = "completed";  break;
    1951           0 :     case FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED: level = "optimistically_confirmed"; break;
    1952           0 :     case FD_GUI_SLOT_LEVEL_ROOTED:                   level = "rooted"; break;
    1953           0 :     case FD_GUI_SLOT_LEVEL_FINALIZED:                level = "finalized"; break;
    1954           0 :     default:                                         level = "unknown"; break;
    1955           0 :   }
    1956             : 
    1957           0 :   long duration_nanos = fd_gui_load_slot_duration( gui, _slot, slot );
    1958             : 
    1959           0 :   jsonp_open_envelope( gui->http, "slot", "query" );
    1960           0 :     jsonp_ulong( gui->http, "id", id );
    1961           0 :     jsonp_open_object( gui->http, "value" );
    1962           0 :       fd_gui_leader_slot_t lmeta[ 1 ];
    1963           0 :       int have_lmeta = fd_gui_load_leader_meta( gui, _slot, lmeta );
    1964             : 
    1965           0 :       jsonp_open_object( gui->http, "publish" );
    1966           0 :         jsonp_ulong( gui->http, "slot", _slot );
    1967           0 :         jsonp_bool( gui->http, "mine", slot->mine );
    1968           0 :         if( FD_UNLIKELY( slot->vote_slot!=ULONG_MAX ) ) jsonp_ulong( gui->http, "vote_slot", slot->vote_slot );
    1969           0 :         else                                            jsonp_null( gui->http, "vote_slot" );
    1970           0 :         if( FD_LIKELY( slot->vote_latency_exact!=FD_GUI_VOTE_LATENCY_NOT_VOTED ) ) jsonp_ulong( gui->http, "vote_latency_exact", slot->vote_latency_exact );
    1971           0 :         else                                                                       jsonp_null( gui->http, "vote_latency_exact" );
    1972           0 :         jsonp_bool( gui->http, "is_voter", slot->is_voter );
    1973             : 
    1974           0 :         if( FD_UNLIKELY( have_lmeta && lmeta->leader_start_time!=LONG_MAX ) ) jsonp_long_as_str( gui->http, "start_timestamp_nanos", lmeta->leader_start_time  );
    1975           0 :         else                                                                  jsonp_null       ( gui->http, "start_timestamp_nanos" );
    1976           0 :         if( FD_UNLIKELY( have_lmeta && lmeta->leader_end_time!=LONG_MAX ) ) jsonp_long_as_str( gui->http, "target_end_timestamp_nanos", lmeta->leader_end_time  );
    1977           0 :         else                                                                jsonp_null       ( gui->http, "target_end_timestamp_nanos" );
    1978             : 
    1979           0 :         jsonp_bool( gui->http, "skipped", slot->skip==FD_GUI_SKIP_STATUS_SKIPPED );
    1980           0 :         jsonp_string( gui->http, "level", level );
    1981           0 :         if( FD_UNLIKELY( duration_nanos==LONG_MAX ) ) jsonp_null( gui->http, "duration_nanos" );
    1982           0 :         else                                          jsonp_long( gui->http, "duration_nanos", duration_nanos );
    1983           0 :         if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) jsonp_null( gui->http, "completed_time_nanos" );
    1984           0 :         else                                                jsonp_long_as_str( gui->http, "completed_time_nanos", slot->completed_time );
    1985           0 :         if( FD_UNLIKELY( slot->nonvote_success==UINT_MAX ) ) jsonp_null( gui->http, "success_nonvote_transaction_cnt" );
    1986           0 :         else                                                 jsonp_ulong( gui->http, "success_nonvote_transaction_cnt", slot->nonvote_success );
    1987           0 :         if( FD_UNLIKELY( slot->nonvote_failed==UINT_MAX ) ) jsonp_null( gui->http, "failed_nonvote_transaction_cnt" );
    1988           0 :         else                                                        jsonp_ulong( gui->http, "failed_nonvote_transaction_cnt", slot->nonvote_failed );
    1989           0 :         if( FD_UNLIKELY( slot->vote_success==UINT_MAX ) ) jsonp_null( gui->http, "success_vote_transaction_cnt" );
    1990           0 :         else                                              jsonp_ulong( gui->http, "success_vote_transaction_cnt", slot->vote_success );
    1991           0 :         if( FD_UNLIKELY( slot->vote_failed==UINT_MAX ) ) jsonp_null( gui->http, "failed_vote_transaction_cnt" );
    1992           0 :         else                                             jsonp_ulong( gui->http, "failed_vote_transaction_cnt", slot->vote_failed );
    1993           0 :         if( FD_UNLIKELY( slot->max_compute_units==UINT_MAX ) ) jsonp_null( gui->http, "max_compute_units" );
    1994           0 :         else                                                   jsonp_ulong( gui->http, "max_compute_units", slot->max_compute_units );
    1995           0 :         if( FD_UNLIKELY( slot->compute_units==UINT_MAX ) ) jsonp_null( gui->http, "compute_units" );
    1996           0 :         else                                               jsonp_ulong( gui->http, "compute_units", slot->compute_units );
    1997           0 :         if( FD_UNLIKELY( slot->shred_cnt==UINT_MAX ) ) jsonp_null( gui->http, "shreds" );
    1998           0 :         else                                           jsonp_ulong( gui->http, "shreds", slot->shred_cnt );
    1999           0 :         if( FD_UNLIKELY( slot->transaction_fee==ULONG_MAX ) ) jsonp_null( gui->http, "transaction_fee" );
    2000           0 :         else                                                  jsonp_ulong( gui->http, "transaction_fee", slot->transaction_fee );
    2001           0 :         if( FD_UNLIKELY( slot->priority_fee==ULONG_MAX ) ) jsonp_null( gui->http, "priority_fee" );
    2002           0 :         else                                               jsonp_ulong( gui->http, "priority_fee", slot->priority_fee );
    2003           0 :         if( FD_UNLIKELY( slot->tips==ULONG_MAX ) ) jsonp_null( gui->http, "tips" );
    2004           0 :         else                                       jsonp_ulong( gui->http, "tips", slot->tips );
    2005           0 :       jsonp_close_object( gui->http );
    2006             : 
    2007           0 :     jsonp_close_object( gui->http );
    2008           0 :   jsonp_close_envelope( gui->http );
    2009           0 : }
    2010             : 
    2011             : #define SORT_NAME fd_gui_slot_txn_start_sort
    2012           0 : #define SORT_KEY_T fd_gui_store_txn_start_t
    2013           0 : #define SORT_BEFORE(a,b) ( (a).txn_idx<(b).txn_idx )
    2014             : #include "../../util/tmpl/fd_sort.c"
    2015             : 
    2016             : #define SORT_NAME fd_gui_slot_txn_end_sort
    2017           0 : #define SORT_KEY_T fd_gui_store_txn_end_t
    2018           0 : #define SORT_BEFORE(a,b) ( (a).txn_idx<(b).txn_idx )
    2019             : #include "../../util/tmpl/fd_sort.c"
    2020             : 
    2021             : void
    2022             : fd_gui_printf_slot_transactions_request( fd_gui_t *            gui,
    2023             :                                          ulong                _slot,
    2024             :                                          ulong                id,
    2025           0 :                                          fd_gui_slot_t const * slot ) {
    2026           0 :   char const * level;
    2027           0 :   switch( slot->level ) {
    2028           0 :     case FD_GUI_SLOT_LEVEL_INCOMPLETE:               level = "incomplete"; break;
    2029           0 :     case FD_GUI_SLOT_LEVEL_COMPLETED:                level = "completed";  break;
    2030           0 :     case FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED: level = "optimistically_confirmed"; break;
    2031           0 :     case FD_GUI_SLOT_LEVEL_ROOTED:                   level = "rooted"; break;
    2032           0 :     case FD_GUI_SLOT_LEVEL_FINALIZED:                level = "finalized"; break;
    2033           0 :     default:                                         level = "unknown"; break;
    2034           0 :   }
    2035             : 
    2036           0 :   long duration_nanos = fd_gui_load_slot_duration( gui, _slot, slot );
    2037             : 
    2038           0 :   jsonp_open_envelope( gui->http, "slot", "query_transactions" );
    2039           0 :     jsonp_ulong( gui->http, "id", id );
    2040           0 :     jsonp_open_object( gui->http, "value" );
    2041           0 :       fd_gui_leader_slot_t lmeta[ 1 ];
    2042           0 :       int have_lmeta = fd_gui_load_leader_meta( gui, _slot, lmeta );
    2043             : 
    2044           0 :       jsonp_open_object( gui->http, "publish" );
    2045           0 :         jsonp_ulong( gui->http, "slot", _slot );
    2046           0 :         jsonp_bool( gui->http, "mine", slot->mine );
    2047           0 :         if( FD_UNLIKELY( slot->vote_slot!=ULONG_MAX ) ) jsonp_ulong( gui->http, "vote_slot", slot->vote_slot );
    2048           0 :         else                                            jsonp_null( gui->http, "vote_slot" );
    2049           0 :         if( FD_LIKELY( slot->vote_latency_exact!=FD_GUI_VOTE_LATENCY_NOT_VOTED ) ) jsonp_ulong( gui->http, "vote_latency_exact", slot->vote_latency_exact );
    2050           0 :         else                                                                       jsonp_null( gui->http, "vote_latency_exact" );
    2051           0 :         jsonp_bool( gui->http, "is_voter", slot->is_voter );
    2052             : 
    2053           0 :         if( FD_UNLIKELY( have_lmeta && lmeta->leader_start_time!=LONG_MAX ) ) jsonp_long_as_str( gui->http, "start_timestamp_nanos", lmeta->leader_start_time  );
    2054           0 :         else                                                                  jsonp_null       ( gui->http, "start_timestamp_nanos" );
    2055           0 :         if( FD_UNLIKELY( have_lmeta && lmeta->leader_end_time!=LONG_MAX ) ) jsonp_long_as_str( gui->http, "target_end_timestamp_nanos", lmeta->leader_end_time  );
    2056           0 :         else                                                                jsonp_null       ( gui->http, "target_end_timestamp_nanos" );
    2057             : 
    2058           0 :         jsonp_bool( gui->http, "skipped", slot->skip==FD_GUI_SKIP_STATUS_SKIPPED );
    2059           0 :         jsonp_string( gui->http, "level", level );
    2060           0 :         if( FD_UNLIKELY( duration_nanos==LONG_MAX ) ) jsonp_null( gui->http, "duration_nanos" );
    2061           0 :         else                                          jsonp_long( gui->http, "duration_nanos", duration_nanos );
    2062           0 :         if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) jsonp_null( gui->http, "completed_time_nanos" );
    2063           0 :         else                                                jsonp_long_as_str( gui->http, "completed_time_nanos", slot->completed_time );
    2064           0 :         if( FD_UNLIKELY( slot->nonvote_success==UINT_MAX ) ) jsonp_null( gui->http, "success_nonvote_transaction_cnt" );
    2065           0 :         else                                                 jsonp_ulong( gui->http, "success_nonvote_transaction_cnt", slot->nonvote_success );
    2066           0 :         if( FD_UNLIKELY( slot->nonvote_failed==UINT_MAX ) ) jsonp_null( gui->http, "failed_nonvote_transaction_cnt" );
    2067           0 :         else                                                        jsonp_ulong( gui->http, "failed_nonvote_transaction_cnt", slot->nonvote_failed );
    2068           0 :         if( FD_UNLIKELY( slot->vote_success==UINT_MAX ) ) jsonp_null( gui->http, "success_vote_transaction_cnt" );
    2069           0 :         else                                              jsonp_ulong( gui->http, "success_vote_transaction_cnt", slot->vote_success );
    2070           0 :         if( FD_UNLIKELY( slot->vote_failed==UINT_MAX ) ) jsonp_null( gui->http, "failed_vote_transaction_cnt" );
    2071           0 :         else                                             jsonp_ulong( gui->http, "failed_vote_transaction_cnt", slot->vote_failed );
    2072           0 :         if( FD_UNLIKELY( slot->max_compute_units==UINT_MAX ) ) jsonp_null( gui->http, "max_compute_units" );
    2073           0 :         else                                                   jsonp_ulong( gui->http, "max_compute_units", slot->max_compute_units );
    2074           0 :         if( FD_UNLIKELY( slot->compute_units==UINT_MAX ) ) jsonp_null( gui->http, "compute_units" );
    2075           0 :         else                                               jsonp_ulong( gui->http, "compute_units", slot->compute_units );
    2076           0 :         if( FD_UNLIKELY( slot->shred_cnt==UINT_MAX ) ) jsonp_null( gui->http, "shreds" );
    2077           0 :         else                                           jsonp_ulong( gui->http, "shreds", slot->shred_cnt );
    2078           0 :         if( FD_UNLIKELY( slot->transaction_fee==ULONG_MAX ) ) jsonp_null( gui->http, "transaction_fee" );
    2079           0 :         else                                                  jsonp_ulong( gui->http, "transaction_fee", slot->transaction_fee );
    2080           0 :         if( FD_UNLIKELY( slot->priority_fee==ULONG_MAX ) ) jsonp_null( gui->http, "priority_fee" );
    2081           0 :         else                                               jsonp_ulong( gui->http, "priority_fee", slot->priority_fee );
    2082           0 :         if( FD_UNLIKELY( slot->tips==ULONG_MAX ) ) jsonp_null( gui->http, "tips" );
    2083           0 :         else                                       jsonp_ulong( gui->http, "tips", slot->tips );
    2084           0 :       jsonp_close_object( gui->http );
    2085             : 
    2086           0 :       if( FD_UNLIKELY( have_lmeta && lmeta->unbecame_leader ) ) {
    2087           0 :         jsonp_open_object( gui->http, "limits" );
    2088           0 :           jsonp_ulong( gui->http, "used_total_block_cost",        lmeta->scheduler_stats->limits_usage->block_cost          );
    2089           0 :           jsonp_ulong( gui->http, "used_total_vote_cost",         lmeta->scheduler_stats->limits_usage->vote_cost           );
    2090           0 :           jsonp_ulong( gui->http, "used_total_bytes",             lmeta->scheduler_stats->limits_usage->block_data_bytes    );
    2091           0 :           jsonp_ulong( gui->http, "used_total_microblocks",       lmeta->scheduler_stats->limits_usage->microblocks         );
    2092           0 :           jsonp_open_array( gui->http, "used_account_write_costs" );
    2093           0 :             for( ulong i = 0; i<FD_PACK_TOP_WRITERS_CNT; i++ ) {
    2094           0 :               if( FD_UNLIKELY( !memcmp( lmeta->scheduler_stats->limits_usage->top_writers[ i ].key.b, ((fd_pubkey_t){ 0 }).uc, sizeof(fd_pubkey_t) ) ) ) break;
    2095             : 
    2096           0 :               jsonp_open_object( gui->http, NULL );
    2097           0 :                 char account_base58[ FD_BASE58_ENCODED_32_SZ ];
    2098           0 :                 fd_base58_encode_32( lmeta->scheduler_stats->limits_usage->top_writers[ i ].key.b, NULL, account_base58 );
    2099           0 :                 jsonp_string( gui->http, "account", account_base58 );
    2100           0 :                 jsonp_ulong( gui->http, "cost", lmeta->scheduler_stats->limits_usage->top_writers[ i ].total_cost );
    2101           0 :               jsonp_close_object( gui->http );
    2102           0 :             }
    2103           0 :           jsonp_close_array( gui->http );
    2104             : 
    2105           0 :           jsonp_ulong( gui->http, "max_total_block_cost",        lmeta->scheduler_stats->limits->max_cost_per_block        );
    2106           0 :           jsonp_ulong( gui->http, "max_total_vote_cost",         lmeta->scheduler_stats->limits->max_vote_cost_per_block   );
    2107           0 :           jsonp_ulong( gui->http, "max_account_write_cost",      lmeta->scheduler_stats->limits->max_write_cost_per_acct   );
    2108           0 :           jsonp_ulong( gui->http, "max_total_bytes",             lmeta->scheduler_stats->limits->max_data_bytes_per_block  );
    2109           0 :           jsonp_ulong( gui->http, "max_total_microblocks",       lmeta->max_microblocks                                    );
    2110           0 :         jsonp_close_object( gui->http );
    2111             : 
    2112           0 :         jsonp_open_object( gui->http, "scheduler_stats" );
    2113             :           /* block_hash is replay-sourced; prefer FD_GUI_HIST_SLOT
    2114             :              and fall back to the leader meta's own block_hash. */
    2115           0 :           fd_hash_t block_hash = lmeta->block_hash;
    2116           0 :           fd_gui_load_block_hash( gui, _slot, &block_hash );
    2117           0 :           char block_hash_base58[ FD_BASE58_ENCODED_32_SZ ];
    2118           0 :           fd_base58_encode_32( block_hash.uc, NULL, block_hash_base58 );
    2119           0 :           jsonp_string( gui->http, "block_hash", block_hash_base58 );
    2120             : 
    2121           0 :           switch( lmeta->scheduler_stats->end_slot_reason ) {
    2122           0 :             case FD_PACK_END_SLOT_REASON_TIME: {
    2123           0 :               jsonp_string( gui->http, "end_slot_reason", "timeout" );
    2124           0 :               break;
    2125           0 :             }
    2126           0 :             case FD_PACK_END_SLOT_REASON_MICROBLOCK: {
    2127           0 :               jsonp_string( gui->http, "end_slot_reason", "microblock_limit" );
    2128           0 :               break;
    2129           0 :             }
    2130           0 :             case FD_PACK_END_SLOT_REASON_LEADER_SWITCH: {
    2131           0 :               jsonp_string( gui->http, "end_slot_reason", "leader_switch" );
    2132           0 :               break;
    2133           0 :             }
    2134           0 :             default: FD_LOG_ERR(( "unreachable" ));
    2135           0 :           }
    2136           0 :           jsonp_open_array( gui->http, "slot_schedule_counts" );
    2137           0 :             for( ulong i = 0; i<FD_METRICS_COUNTER_PACK_TXN_SCHEDULED_CNT; i++ ) jsonp_ulong( gui->http, NULL, lmeta->scheduler_stats->block_results[ i ] );
    2138           0 :           jsonp_close_array( gui->http );
    2139           0 :           jsonp_open_array( gui->http, "end_slot_schedule_counts" );
    2140           0 :             for( ulong i = 0; i<FD_METRICS_COUNTER_PACK_TXN_SCHEDULED_CNT; i++ ) jsonp_ulong( gui->http, NULL, lmeta->scheduler_stats->end_block_results[ i ] );
    2141           0 :           jsonp_close_array( gui->http );
    2142             : 
    2143           0 :           if( FD_LIKELY( lmeta->scheduler_stats->pending_smallest->cus!=ULONG_MAX ) ) jsonp_ulong( gui->http, "pending_smallest_cost", lmeta->scheduler_stats->pending_smallest->cus );
    2144           0 :           else                                                                        jsonp_null( gui->http, "pending_smallest_cost" );
    2145           0 :           if( FD_LIKELY( lmeta->scheduler_stats->pending_smallest->bytes!=ULONG_MAX ) ) jsonp_ulong( gui->http, "pending_smallest_bytes", lmeta->scheduler_stats->pending_smallest->bytes );
    2146           0 :           else                                                                          jsonp_null( gui->http, "pending_smallest_bytes" );
    2147           0 :           if( FD_LIKELY( lmeta->scheduler_stats->pending_votes_smallest->cus!=ULONG_MAX ) ) jsonp_ulong( gui->http, "pending_vote_smallest_cost", lmeta->scheduler_stats->pending_votes_smallest->cus );
    2148           0 :           else                                                                              jsonp_null( gui->http, "pending_vote_smallest_cost" );
    2149           0 :           if( FD_LIKELY( lmeta->scheduler_stats->pending_votes_smallest->bytes!=ULONG_MAX ) ) jsonp_ulong( gui->http, "pending_vote_smallest_bytes", lmeta->scheduler_stats->pending_votes_smallest->bytes );
    2150           0 :           else                                                                                jsonp_null( gui->http, "pending_vote_smallest_bytes" );
    2151           0 :         jsonp_close_object( gui->http );
    2152             : 
    2153           0 :       } else {
    2154           0 :         jsonp_null( gui->http, "limits" );
    2155           0 :         jsonp_null( gui->http, "scheduler_stats" );
    2156           0 :       }
    2157             : 
    2158           0 :       int processed_all_microblocks = have_lmeta && lmeta->unbecame_leader &&
    2159           0 :                                       lmeta->microblocks_upper_bound!=UINT_MAX &&
    2160           0 :                                       lmeta->begin_microblocks==lmeta->end_microblocks &&
    2161           0 :                                       lmeta->begin_microblocks==lmeta->microblocks_upper_bound;
    2162             : 
    2163           0 :       int have_leader_window = have_lmeta &&
    2164           0 :                                lmeta->leader_start_time!=LONG_MAX &&
    2165           0 :                                lmeta->leader_end_time  !=LONG_MAX &&
    2166           0 :                                lmeta->leader_start_time<=lmeta->leader_end_time;
    2167             : 
    2168           0 :       fd_gui_store_txn_start_t *  starts = gui->slot_txn_scratch.starts;
    2169           0 :       fd_gui_store_txn_end_t *    ends   = gui->slot_txn_scratch.ends;
    2170           0 :       fd_gui_slot_txn_join_t * joined = gui->slot_txn_scratch.joined;
    2171           0 :       ulong                    start_cnt = 0UL;
    2172           0 :       ulong                    end_cnt   = 0UL;
    2173           0 :       ulong                    txn_cnt   = 0UL;
    2174           0 :       int                      have_txns = gui->db && processed_all_microblocks && have_leader_window;
    2175             : 
    2176           0 :       if( FD_LIKELY( have_txns ) ) {
    2177             :         /* Bound both scans to this slot's leader window, widened by a
    2178             :            slack to prevent losing txn's that come in right before or
    2179             :            right after the recorded leader window. */
    2180           0 :         long const txn_window_slack_ns = 2L*1000L*1000L*1000L; /* 2 s */
    2181           0 :         long txn_lo_ns = lmeta->leader_start_time - txn_window_slack_ns;
    2182           0 :         long txn_hi_ns = lmeta->leader_end_time   + txn_window_slack_ns;
    2183             : 
    2184             :         /* Scan the start half, keeping only this slot's records. */
    2185           0 :         fd_gui_hist_iter_t it;
    2186           0 :         if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_TXN_START, txn_lo_ns, txn_hi_ns, NULL, NULL ) ) ) {
    2187           0 :           while( fd_gui_hist_range_next( &it ) ) {
    2188           0 :             fd_gui_store_txn_start_t const * r = (fd_gui_store_txn_start_t const *)it.rec;
    2189           0 :             if( FD_UNLIKELY( r->slot!=_slot || r->bank_seq!=slot->bank_seq ) ) continue;
    2190           0 :             if( FD_UNLIKELY( start_cnt>=FD_MAX_TXN_PER_SLOT ) ) break;
    2191           0 :             starts[ start_cnt++ ] = *r;
    2192           0 :           }
    2193           0 :           fd_gui_hist_range_end( &it );
    2194           0 :         }
    2195             : 
    2196             :         /* Scan the end half, keeping only this slot's records. */
    2197           0 :         if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_TXN_END, txn_lo_ns, txn_hi_ns, NULL, NULL ) ) ) {
    2198           0 :           while( fd_gui_hist_range_next( &it ) ) {
    2199           0 :             fd_gui_store_txn_end_t const * r = (fd_gui_store_txn_end_t const *)it.rec;
    2200           0 :             if( FD_UNLIKELY( r->slot!=_slot || r->bank_seq!=slot->bank_seq ) ) continue;
    2201           0 :             if( FD_UNLIKELY( end_cnt>=FD_MAX_TXN_PER_SLOT ) ) break;
    2202           0 :             ends[ end_cnt++ ] = *r;
    2203           0 :           }
    2204           0 :           fd_gui_hist_range_end( &it );
    2205           0 :         }
    2206             : 
    2207             :         /* Sort both halves by txn_idx, then merge-walk to join. */
    2208           0 :         fd_gui_slot_txn_start_sort_inplace( starts, start_cnt );
    2209           0 :         fd_gui_slot_txn_end_sort_inplace  ( ends,   end_cnt   );
    2210             : 
    2211           0 :         ulong si = 0UL;
    2212           0 :         ulong ei = 0UL;
    2213           0 :         while( si<start_cnt && ei<end_cnt ) {
    2214           0 :           ulong s_idx = starts[ si ].txn_idx;
    2215           0 :           ulong e_idx = ends  [ ei ].txn_idx;
    2216           0 :           if(      s_idx<e_idx ) si++;
    2217           0 :           else if( e_idx<s_idx ) ei++;
    2218           0 :           else {
    2219           0 :             joined[ txn_cnt ].start = &starts[ si ];
    2220           0 :             joined[ txn_cnt ].end   = &ends  [ ei ];
    2221           0 :             txn_cnt++;
    2222           0 :             si++;
    2223           0 :             ei++;
    2224           0 :           }
    2225           0 :         }
    2226           0 :       }
    2227             : 
    2228           0 :       if( FD_LIKELY( have_txns ) ) {
    2229           0 :         jsonp_open_object( gui->http, "transactions" );
    2230           0 :           jsonp_long_as_str( gui->http, "start_timestamp_nanos", lmeta->leader_start_time );
    2231           0 :           jsonp_long_as_str( gui->http, "target_end_timestamp_nanos", lmeta->leader_end_time );
    2232           0 :           jsonp_open_array( gui->http, "txn_mb_start_timestamps_nanos" );
    2233           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns );
    2234           0 :           jsonp_close_array( gui->http );
    2235           0 :           jsonp_open_array( gui->http, "txn_mb_end_timestamps_nanos" );
    2236           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2237           0 :               long const mb_start = joined[ i ].start->microblock_start_ns;
    2238           0 :               long const mb_end   = fd_long_max( joined[ i ].end->microblock_end_ns, mb_start + 1L );
    2239           0 :               jsonp_long_as_str( gui->http, NULL, mb_end );
    2240           0 :             }
    2241           0 :           jsonp_close_array( gui->http );
    2242           0 :           jsonp_open_array( gui->http, "txn_compute_units_requested" );
    2243           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong( gui->http, NULL, joined[ i ].start->compute_units_requested );
    2244           0 :           jsonp_close_array( gui->http );
    2245           0 :           jsonp_open_array( gui->http, "txn_compute_units_consumed" );
    2246           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong( gui->http, NULL, joined[ i ].end->compute_units_consumed );
    2247           0 :           jsonp_close_array( gui->http );
    2248           0 :           jsonp_open_array( gui->http, "txn_priority_fee" );
    2249           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong_as_str( gui->http, NULL, joined[ i ].start->priority_fee );
    2250           0 :           jsonp_close_array( gui->http );
    2251           0 :           jsonp_open_array( gui->http, "txn_transaction_fee" );
    2252           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong_as_str( gui->http, NULL, joined[ i ].start->transaction_fee );
    2253           0 :           jsonp_close_array( gui->http );
    2254           0 :           jsonp_open_array( gui->http, "txn_error_code" );
    2255           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong( gui->http, NULL, joined[ i ].end->error_code );
    2256           0 :           jsonp_close_array( gui->http );
    2257           0 :           jsonp_open_array( gui->http, "txn_from_bundle" );
    2258           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_bool( gui->http, NULL, joined[ i ].start->flags & FD_GUI_TXN_FLAGS_FROM_BUNDLE );
    2259           0 :           jsonp_close_array( gui->http );
    2260           0 :           jsonp_open_array( gui->http, "txn_is_simple_vote" );
    2261           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_bool( gui->http, NULL, joined[ i ].start->flags & FD_GUI_TXN_FLAGS_IS_SIMPLE_VOTE );
    2262           0 :           jsonp_close_array( gui->http );
    2263           0 :           jsonp_open_array( gui->http, "txn_bank_idx" );
    2264           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong( gui->http, NULL, joined[ i ].end->bank_idx );
    2265           0 :           jsonp_close_array( gui->http );
    2266           0 :           jsonp_open_array( gui->http, "txn_check_start_timestamps_nanos" );
    2267           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2268           0 :               jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns + (long)joined[ i ].end->txn_ns_dt.check_start );
    2269           0 :             }
    2270           0 :           jsonp_close_array( gui->http );
    2271           0 :           jsonp_open_array( gui->http, "txn_load_start_timestamps_nanos" );
    2272           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2273           0 :               jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns + (long)joined[ i ].end->txn_ns_dt.load_start );
    2274           0 :             }
    2275           0 :           jsonp_close_array( gui->http );
    2276           0 :           jsonp_open_array( gui->http, "txn_execute_start_timestamps_nanos" );
    2277           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2278           0 :               jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns + (long)joined[ i ].end->txn_ns_dt.exec_start );
    2279           0 :             }
    2280           0 :           jsonp_close_array( gui->http );
    2281           0 :           jsonp_open_array( gui->http, "txn_commit_start_timestamps_nanos" );
    2282           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2283           0 :               jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns + (long)joined[ i ].end->txn_ns_dt.commit_start );
    2284           0 :             }
    2285           0 :           jsonp_close_array( gui->http );
    2286           0 :           jsonp_open_array( gui->http, "txn_commit_end_timestamps_nanos" );
    2287           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2288           0 :               jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns + (long)joined[ i ].end->txn_ns_dt.commit_end );
    2289           0 :             }
    2290           0 :           jsonp_close_array( gui->http );
    2291           0 :           jsonp_open_array( gui->http, "txn_arrival_timestamps_nanos" );
    2292           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_long_as_str( gui->http, NULL, joined[ i ].start->timestamp_arrival_nanos );
    2293           0 :           jsonp_close_array( gui->http );
    2294           0 :           jsonp_open_array( gui->http, "txn_tips" );
    2295           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong_as_str( gui->http, NULL, joined[ i ].end->tips );
    2296           0 :           jsonp_close_array( gui->http );
    2297           0 :           jsonp_open_array( gui->http, "txn_source_ipv4" );
    2298           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2299           0 :               char addr[ 64 ];
    2300           0 :               fd_cstr_printf_check( addr, sizeof(addr), NULL, FD_IP4_ADDR_FMT, FD_IP4_ADDR_FMT_ARGS( joined[ i ].start->source_ipv4 ) );
    2301           0 :               jsonp_string( gui->http, NULL, addr );
    2302           0 :             }
    2303           0 :           jsonp_close_array( gui->http );
    2304           0 :           jsonp_open_array( gui->http, "txn_source_tpu" );
    2305           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2306           0 :               switch ( joined[ i ].start->source_tpu ) {
    2307           0 :                 case FD_TXN_M_TPU_SOURCE_QUIC: {
    2308           0 :                   jsonp_string( gui->http, NULL, "quic");
    2309           0 :                   break;
    2310           0 :                 }
    2311           0 :                 case FD_TXN_M_TPU_SOURCE_UDP   : {
    2312           0 :                   jsonp_string( gui->http, NULL, "udp");
    2313           0 :                   break;
    2314           0 :                 }
    2315           0 :                 case FD_TXN_M_TPU_SOURCE_GOSSIP: {
    2316           0 :                   jsonp_string( gui->http, NULL, "gossip");
    2317           0 :                   break;
    2318           0 :                 }
    2319           0 :                 case FD_TXN_M_TPU_SOURCE_BUNDLE: {
    2320           0 :                   jsonp_string( gui->http, NULL, "bundle");
    2321           0 :                   break;
    2322           0 :                 }
    2323           0 :                 case FD_TXN_M_TPU_SOURCE_TXSEND: {
    2324           0 :                   jsonp_string( gui->http, NULL, "send");
    2325           0 :                   break;
    2326           0 :                 }
    2327           0 :                 default: FD_LOG_ERR(("unknown tpu"));
    2328           0 :               }
    2329           0 :             }
    2330           0 :           jsonp_close_array( gui->http );
    2331           0 :           jsonp_open_array( gui->http, "txn_microblock_id" );
    2332           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong( gui->http, NULL, joined[ i ].start->microblock_idx );
    2333           0 :           jsonp_close_array( gui->http );
    2334           0 :           jsonp_open_array( gui->http, "txn_landed" );
    2335           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_bool( gui->http, NULL, joined[ i ].end->flags & FD_GUI_TXN_FLAGS_LANDED_IN_BLOCK );
    2336           0 :           jsonp_close_array( gui->http );
    2337           0 :           jsonp_open_array( gui->http, "txn_signature" );
    2338           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2339           0 :               FD_BASE58_ENCODE_64_BYTES( joined[ i ].start->signature, encoded_signature );
    2340           0 :               jsonp_string( gui->http, NULL, encoded_signature );
    2341           0 :             }
    2342           0 :           jsonp_close_array( gui->http );
    2343           0 :         jsonp_close_object( gui->http );
    2344           0 :       } else {
    2345           0 :         jsonp_null( gui->http, "transactions" );
    2346           0 :       }
    2347             : 
    2348           0 :     jsonp_close_object( gui->http );
    2349           0 :   jsonp_close_envelope( gui->http );
    2350           0 : }
    2351             : 
    2352             : void
    2353             : fd_gui_printf_slot_request_detailed( fd_gui_t *            gui,
    2354             :                                      ulong                _slot,
    2355             :                                      ulong                id,
    2356           0 :                                      fd_gui_slot_t const * slot ) {
    2357           0 :   char const * level;
    2358           0 :   switch( slot->level ) {
    2359           0 :     case FD_GUI_SLOT_LEVEL_INCOMPLETE:               level = "incomplete"; break;
    2360           0 :     case FD_GUI_SLOT_LEVEL_COMPLETED:                level = "completed";  break;
    2361           0 :     case FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED: level = "optimistically_confirmed"; break;
    2362           0 :     case FD_GUI_SLOT_LEVEL_ROOTED:                   level = "rooted"; break;
    2363           0 :     case FD_GUI_SLOT_LEVEL_FINALIZED:                level = "finalized"; break;
    2364           0 :     default:                                         level = "unknown"; break;
    2365           0 :   }
    2366             : 
    2367           0 :   long duration_nanos = fd_gui_load_slot_duration( gui, _slot, slot );
    2368             : 
    2369           0 :   jsonp_open_envelope( gui->http, "slot", "query_detailed" );
    2370           0 :     jsonp_ulong( gui->http, "id", id );
    2371           0 :     jsonp_open_object( gui->http, "value" );
    2372           0 :       fd_gui_leader_slot_t lmeta[ 1 ];
    2373           0 :       int have_lmeta = fd_gui_load_leader_meta( gui, _slot, lmeta );
    2374             : 
    2375           0 :       jsonp_open_object( gui->http, "publish" );
    2376           0 :         jsonp_ulong( gui->http, "slot", _slot );
    2377           0 :         jsonp_bool( gui->http, "mine", slot->mine );
    2378           0 :         if( FD_UNLIKELY( slot->vote_slot!=ULONG_MAX ) ) jsonp_ulong( gui->http, "vote_slot", slot->vote_slot );
    2379           0 :         else                                            jsonp_null( gui->http, "vote_slot" );
    2380           0 :         if( FD_LIKELY( slot->vote_latency_exact!=FD_GUI_VOTE_LATENCY_NOT_VOTED ) ) jsonp_ulong( gui->http, "vote_latency_exact", slot->vote_latency_exact );
    2381           0 :         else                                                                       jsonp_null( gui->http, "vote_latency_exact" );
    2382           0 :         jsonp_bool( gui->http, "is_voter", slot->is_voter );
    2383             : 
    2384           0 :         if( FD_UNLIKELY( have_lmeta && lmeta->leader_start_time!=LONG_MAX ) ) jsonp_long_as_str( gui->http, "start_timestamp_nanos", lmeta->leader_start_time  );
    2385           0 :         else                                                                  jsonp_null       ( gui->http, "start_timestamp_nanos" );
    2386           0 :         if( FD_UNLIKELY( have_lmeta && lmeta->leader_end_time!=LONG_MAX ) ) jsonp_long_as_str( gui->http, "target_end_timestamp_nanos", lmeta->leader_end_time  );
    2387           0 :         else                                                                jsonp_null       ( gui->http, "target_end_timestamp_nanos" );
    2388             : 
    2389           0 :         jsonp_bool( gui->http, "skipped", slot->skip==FD_GUI_SKIP_STATUS_SKIPPED );
    2390           0 :         jsonp_string( gui->http, "level", level );
    2391           0 :         if( FD_UNLIKELY( duration_nanos==LONG_MAX ) ) jsonp_null( gui->http, "duration_nanos" );
    2392           0 :         else                                          jsonp_long( gui->http, "duration_nanos", duration_nanos );
    2393           0 :         if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) jsonp_null( gui->http, "completed_time_nanos" );
    2394           0 :         else                                                jsonp_long_as_str( gui->http, "completed_time_nanos", slot->completed_time );
    2395           0 :         if( FD_UNLIKELY( slot->nonvote_success==UINT_MAX ) ) jsonp_null( gui->http, "success_nonvote_transaction_cnt" );
    2396           0 :         else                                                 jsonp_ulong( gui->http, "success_nonvote_transaction_cnt", slot->nonvote_success );
    2397           0 :         if( FD_UNLIKELY( slot->nonvote_failed==UINT_MAX ) ) jsonp_null( gui->http, "failed_nonvote_transaction_cnt" );
    2398           0 :         else                                                        jsonp_ulong( gui->http, "failed_nonvote_transaction_cnt", slot->nonvote_failed );
    2399           0 :         if( FD_UNLIKELY( slot->vote_success==UINT_MAX ) ) jsonp_null( gui->http, "success_vote_transaction_cnt" );
    2400           0 :         else                                              jsonp_ulong( gui->http, "success_vote_transaction_cnt", slot->vote_success );
    2401           0 :         if( FD_UNLIKELY( slot->vote_failed==UINT_MAX ) ) jsonp_null( gui->http, "failed_vote_transaction_cnt" );
    2402           0 :         else                                             jsonp_ulong( gui->http, "failed_vote_transaction_cnt", slot->vote_failed );
    2403           0 :         if( FD_UNLIKELY( slot->max_compute_units==UINT_MAX ) ) jsonp_null( gui->http, "max_compute_units" );
    2404           0 :         else                                                   jsonp_ulong( gui->http, "max_compute_units", slot->max_compute_units );
    2405           0 :         if( FD_UNLIKELY( slot->compute_units==UINT_MAX ) ) jsonp_null( gui->http, "compute_units" );
    2406           0 :         else                                               jsonp_ulong( gui->http, "compute_units", slot->compute_units );
    2407           0 :         if( FD_UNLIKELY( slot->shred_cnt==UINT_MAX ) ) jsonp_null( gui->http, "shreds" );
    2408           0 :         else                                           jsonp_ulong( gui->http, "shreds", slot->shred_cnt );
    2409           0 :         if( FD_UNLIKELY( slot->transaction_fee==ULONG_MAX ) ) jsonp_null( gui->http, "transaction_fee" );
    2410           0 :         else                                                  jsonp_ulong( gui->http, "transaction_fee", slot->transaction_fee );
    2411           0 :         if( FD_UNLIKELY( slot->priority_fee==ULONG_MAX ) ) jsonp_null( gui->http, "priority_fee" );
    2412           0 :         else                                               jsonp_ulong( gui->http, "priority_fee", slot->priority_fee );
    2413           0 :         if( FD_UNLIKELY( slot->tips==ULONG_MAX ) ) jsonp_null( gui->http, "tips" );
    2414           0 :         else                                       jsonp_ulong( gui->http, "tips", slot->tips );
    2415           0 :       jsonp_close_object( gui->http );
    2416             : 
    2417           0 :       if( FD_LIKELY( gui->summary.slot_tower!=ULONG_MAX && gui->summary.slot_tower>_slot ) ) {
    2418           0 :         long leader_start_time = have_lmeta ? lmeta->leader_start_time : LONG_MAX;
    2419           0 :         long leader_end_time   = have_lmeta ? lmeta->leader_end_time   : LONG_MAX;
    2420           0 :         int  have_window       = have_lmeta && gui->db && leader_start_time!=LONG_MAX && leader_end_time!=LONG_MAX;
    2421             : 
    2422           0 :         int have_wf = 0;
    2423           0 :         fd_gui_txn_waterfall_t wf_begin[ 1 ];
    2424           0 :         fd_gui_txn_waterfall_t wf_end  [ 1 ];
    2425           0 :         if( FD_LIKELY( have_window ) ) {
    2426           0 :           fd_gui_hist_iter_t it;
    2427           0 :           if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_TXN_WATERFALL, leader_start_time, leader_end_time, NULL, NULL ) ) ) {
    2428           0 :             while( fd_gui_hist_range_next( &it ) ) {
    2429           0 :               fd_gui_txn_waterfall_t const * r = (fd_gui_txn_waterfall_t const *)it.rec;
    2430           0 :               if( FD_UNLIKELY( r->sample_time_nanos<leader_start_time || r->sample_time_nanos>leader_end_time ) ) continue;
    2431           0 :               if( FD_UNLIKELY( !have_wf ) ) *wf_begin = *r;
    2432           0 :               *wf_end = *r;
    2433           0 :               have_wf = 1;
    2434           0 :             }
    2435           0 :             fd_gui_hist_range_end( &it );
    2436           0 :           }
    2437           0 :         }
    2438           0 :         if( FD_LIKELY( have_wf ) ) fd_gui_printf_waterfall( gui, wf_begin, wf_end );
    2439           0 :         else                       jsonp_null( gui->http, "waterfall" );
    2440             : 
    2441           0 :         if( FD_LIKELY( have_window ) ) {
    2442           0 :           jsonp_open_array( gui->http, "tile_timers" );
    2443           0 :             fd_gui_hist_iter_t it;
    2444           0 :             if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_TILE_TIMERS, leader_start_time, leader_end_time, NULL, NULL ) ) ) {
    2445           0 :               fd_gui_tile_timers_hist_t sample[ FD_TOPO_MAX_TILES ];
    2446           0 :               int  have_sample   = 0;
    2447           0 :               long cur_sample_ts = LONG_MAX;
    2448           0 :               while( fd_gui_hist_range_next( &it ) ) {
    2449           0 :                 fd_gui_tile_timers_hist_t const * row = (fd_gui_tile_timers_hist_t const *)it.rec;
    2450           0 :                 if( FD_UNLIKELY( row->sample_time_nanos<leader_start_time || row->sample_time_nanos>leader_end_time ) ) continue;
    2451           0 :                 if( FD_UNLIKELY( row->tile_idx>=FD_TOPO_MAX_TILES ) ) continue;
    2452             : 
    2453             :                 /* Records are stored already-diffed and self-contained, so
    2454             :                    each distinct sample_time_nanos is emitted directly (no
    2455             :                    diff against the previous sample). */
    2456           0 :                 if( have_sample && row->sample_time_nanos!=cur_sample_ts ) {
    2457           0 :                   fd_gui_printf_ts_tile_timers( gui, cur_sample_ts, sample );
    2458           0 :                   have_sample = 0;
    2459           0 :                 }
    2460           0 :                 cur_sample_ts = row->sample_time_nanos;
    2461           0 :                 sample[ row->tile_idx ] = *row;
    2462           0 :                 have_sample = 1;
    2463           0 :               }
    2464             : 
    2465           0 :               if( have_sample ) fd_gui_printf_ts_tile_timers( gui, cur_sample_ts, sample );
    2466           0 :               fd_gui_hist_range_end( &it );
    2467           0 :             }
    2468           0 :           jsonp_close_array( gui->http );
    2469           0 :         } else {
    2470           0 :           jsonp_null( gui->http, "tile_timers" );
    2471           0 :         }
    2472             : 
    2473           0 :         if( FD_LIKELY( have_window ) ) {
    2474             :           /* Unlike tile timers (which are counters), scheduler counts are a
    2475             :              gauge and we don't take a diff. */
    2476           0 :           jsonp_open_array( gui->http, "scheduler_counts" );
    2477           0 :             fd_gui_hist_iter_t it;
    2478           0 :             if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_SCHEDULER_COUNTS, leader_start_time, leader_end_time, NULL, NULL ) ) ) {
    2479           0 :               while( fd_gui_hist_range_next( &it ) ) {
    2480           0 :                 fd_gui_scheduler_counts_t const * cur = (fd_gui_scheduler_counts_t const *)it.rec;
    2481           0 :                 if( FD_UNLIKELY( cur->sample_time_ns<leader_start_time ||
    2482           0 :                                  cur->sample_time_ns>leader_end_time ) ) continue;
    2483           0 :                 jsonp_open_object( gui->http, NULL );
    2484           0 :                   jsonp_long_as_str( gui->http, "timestamp_nanos", cur->sample_time_ns );
    2485           0 :                   jsonp_ulong      ( gui->http, "regular",         cur->regular        );
    2486           0 :                   jsonp_ulong      ( gui->http, "votes",           cur->votes          );
    2487           0 :                   jsonp_ulong      ( gui->http, "conflicting",     cur->conflicting    );
    2488           0 :                   jsonp_ulong      ( gui->http, "bundles",         cur->bundles        );
    2489           0 :                 jsonp_close_object( gui->http );
    2490           0 :               }
    2491           0 :               fd_gui_hist_range_end( &it );
    2492           0 :             }
    2493           0 :           jsonp_close_array( gui->http );
    2494           0 :         } else {
    2495           0 :           jsonp_null( gui->http, "scheduler_counts" );
    2496           0 :         }
    2497             : 
    2498           0 :         int have_tile_stats = 0;
    2499           0 :         fd_gui_tile_stats_t tile_stats_begin[ 1 ];
    2500           0 :         fd_gui_tile_stats_t tile_stats_end  [ 1 ];
    2501           0 :         if( FD_LIKELY( have_window ) ) {
    2502           0 :           fd_gui_hist_iter_t it;
    2503           0 :           if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_TILE_STATS, leader_start_time, leader_end_time, NULL, NULL ) ) ) {
    2504           0 :             while( fd_gui_hist_range_next( &it ) ) {
    2505           0 :               fd_gui_tile_stats_t cur[ 1 ];
    2506           0 :               fd_memcpy( cur, it.rec, sizeof(fd_gui_tile_stats_t) );
    2507           0 :               if( FD_UNLIKELY( cur->sample_time_nanos<leader_start_time || cur->sample_time_nanos>leader_end_time ) ) continue;
    2508           0 :               if( FD_UNLIKELY( !have_tile_stats ) ) *tile_stats_begin = *cur;
    2509           0 :               *tile_stats_end = *cur;
    2510           0 :               have_tile_stats = 1;
    2511           0 :             }
    2512           0 :             fd_gui_hist_range_end( &it );
    2513           0 :           }
    2514           0 :         }
    2515           0 :         if( FD_LIKELY( have_tile_stats ) ) fd_gui_printf_tile_stats( gui, tile_stats_begin, tile_stats_end );
    2516           0 :         else                               jsonp_null( gui->http, "tile_primary_metric" );
    2517           0 :       } else {
    2518           0 :         jsonp_null( gui->http, "waterfall" );
    2519           0 :         jsonp_null( gui->http, "tile_timers" );
    2520           0 :         jsonp_null( gui->http, "tile_primary_metric" );
    2521           0 :       }
    2522             : 
    2523           0 :     jsonp_close_object( gui->http );
    2524           0 :   jsonp_close_envelope( gui->http );
    2525           0 : }
    2526             : 
    2527             : void
    2528           0 : fd_gui_printf_boot_progress( fd_gui_t * gui ) {
    2529           0 :   jsonp_open_envelope( gui->http, "summary", "boot_progress" );
    2530           0 :     jsonp_open_object( gui->http, "value" );
    2531           0 :       switch( gui->summary.boot_progress.phase ) {
    2532           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP:               jsonp_string( gui->http, "phase", "joining_gossip" );               break;
    2533           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT:        jsonp_string( gui->http, "phase", "loading_full_snapshot" );        break;
    2534           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT: jsonp_string( gui->http, "phase", "loading_incremental_snapshot" ); break;
    2535           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY:    jsonp_string( gui->http, "phase", "waiting_for_supermajority" );    break;
    2536           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP:                  jsonp_string( gui->http, "phase", "catching_up" );                  break;
    2537           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_RUNNING:                      jsonp_string( gui->http, "phase", "running" );                      break;
    2538           0 :         default: FD_LOG_ERR(( "unknown phase %d", gui->summary.boot_progress.phase ));
    2539           0 :       }
    2540             : 
    2541           0 :       jsonp_string( gui->http, "accounts_database_path", gui->summary.accounts_database_path );
    2542           0 :       jsonp_string( gui->http, "gui_database_path", gui->summary.gui_database_path );
    2543             : 
    2544           0 :       jsonp_double( gui->http, "joining_gossip_elapsed_seconds", (double)(gui->summary.boot_progress.joining_gossip_time_nanos - gui->summary.startup_time_nanos) / 1e9 );
    2545             : 
    2546           0 : #define HANDLE_SNAPSHOT_STATE(snapshot_type, snapshot_type_upper) { \
    2547           0 :       ulong snapshot_idx = FD_GUI_BOOT_PROGRESS_##snapshot_type_upper##_SNAPSHOT_IDX; \
    2548           0 :       if( FD_LIKELY( gui->summary.boot_progress.phase>=FD_GUI_BOOT_PROGRESS_TYPE_LOADING_##snapshot_type_upper##_SNAPSHOT && gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot!=ULONG_MAX )) { \
    2549           0 :         jsonp_double      ( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_elapsed_seconds",                  (double)(gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].sample_time_nanos - gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_time_nanos) / 1e9 ); \
    2550           0 :         jsonp_ulong       ( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_reset_count",                      gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt                                            ); \
    2551           0 :         jsonp_ulong       ( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_slot",                             gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot                                                 ); \
    2552           0 :         jsonp_ulong_as_str( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_total_bytes_compressed",           gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].total_bytes_compressed                               ); \
    2553           0 :         jsonp_ulong_as_str( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_read_bytes_compressed",            gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_bytes_compressed                                ); \
    2554           0 :         jsonp_string      ( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_read_path",                        gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_path                                            ); \
    2555           0 :         jsonp_ulong_as_str( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_decompress_bytes_decompressed",    gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_decompressed                        ); \
    2556           0 :         jsonp_ulong_as_str( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_decompress_bytes_compressed",      gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_compressed                          ); \
    2557           0 :         jsonp_ulong_as_str( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_insert_bytes_decompressed",        gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_bytes_decompressed                            ); \
    2558           0 :         jsonp_ulong       ( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_insert_accounts",                  gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_accounts_current                              ); \
    2559           0 :         jsonp_ulong_as_str( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_snapwr_in_bytes_decompressed",     gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].snapwr_in_bytes_decompressed                         ); \
    2560           0 :         jsonp_ulong_as_str( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_snapwr_out_bytes_decompressed",    gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].snapwr_out_bytes_decompressed                        ); \
    2561           0 :         jsonp_ulong       ( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_snapwr_accounts",                  gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].snapwr_accounts_current                              ); \
    2562           0 :       } else { \
    2563           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_elapsed_seconds"                  ); \
    2564           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_reset_count"                      ); \
    2565           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_slot"                             ); \
    2566           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_total_bytes_compressed"           ); \
    2567           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_read_bytes_compressed"            ); \
    2568           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_read_path"                        ); \
    2569           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_decompress_bytes_decompressed"    ); \
    2570           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_decompress_bytes_compressed"      ); \
    2571           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_insert_bytes_decompressed"        ); \
    2572           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_insert_accounts"                  ); \
    2573           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_snapwr_in_bytes_decompressed"     ); \
    2574           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_snapwr_out_bytes_decompressed"    ); \
    2575           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_snapwr_accounts"                  ); \
    2576           0 :       } \
    2577           0 :     }
    2578             : 
    2579           0 :     HANDLE_SNAPSHOT_STATE(full, FULL)
    2580           0 :     HANDLE_SNAPSHOT_STATE(incremental, INCREMENTAL)
    2581           0 : #undef HANDLE_SNAPSHOT_STATE
    2582             : 
    2583           0 :     if( FD_LIKELY( gui->summary.wfs_enabled ) ) {
    2584           0 :       jsonp_string      ( gui->http, "wait_for_supermajority_bank_hash",        gui->summary.wfs_bank_hash );
    2585           0 :       char shred_version_str[ 8 ];
    2586           0 :       FD_TEST( fd_cstr_printf_check( shred_version_str, sizeof(shred_version_str), NULL, "%hu", gui->summary.expected_shred_version ) );
    2587           0 :       jsonp_string      ( gui->http, "wait_for_supermajority_shred_version",    shred_version_str );
    2588           0 :       if( FD_LIKELY( gui->summary.boot_progress.phase>=FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY ) ) {
    2589           0 :         jsonp_ulong       ( gui->http, "wait_for_supermajority_attempt",          gui->summary.boot_progress.wfs_attempt );
    2590           0 :         jsonp_ulong_as_str( gui->http, "wait_for_supermajority_total_stake",      gui->summary.boot_progress.wfs_total_stake );
    2591           0 :         jsonp_ulong_as_str( gui->http, "wait_for_supermajority_connected_stake",  gui->summary.boot_progress.wfs_connected_stake );
    2592           0 :         jsonp_ulong       ( gui->http, "wait_for_supermajority_total_peers",      gui->summary.boot_progress.wfs_total_peers );
    2593           0 :         jsonp_ulong       ( gui->http, "wait_for_supermajority_connected_peers",  gui->summary.boot_progress.wfs_connected_peers );
    2594           0 :       } else {
    2595           0 :         jsonp_null( gui->http, "wait_for_supermajority_attempt" );
    2596           0 :         jsonp_null( gui->http, "wait_for_supermajority_total_stake" );
    2597           0 :         jsonp_null( gui->http, "wait_for_supermajority_connected_stake" );
    2598           0 :         jsonp_null( gui->http, "wait_for_supermajority_total_peers" );
    2599           0 :         jsonp_null( gui->http, "wait_for_supermajority_connected_peers" );
    2600           0 :       }
    2601           0 :     } else {
    2602           0 :       jsonp_null( gui->http, "wait_for_supermajority_bank_hash" );
    2603           0 :       jsonp_null( gui->http, "wait_for_supermajority_shred_version" );
    2604           0 :       jsonp_null( gui->http, "wait_for_supermajority_attempt" );
    2605           0 :       jsonp_null( gui->http, "wait_for_supermajority_total_stake" );
    2606           0 :       jsonp_null( gui->http, "wait_for_supermajority_connected_stake" );
    2607           0 :       jsonp_null( gui->http, "wait_for_supermajority_total_peers" );
    2608           0 :       jsonp_null( gui->http, "wait_for_supermajority_connected_peers" );
    2609           0 :     }
    2610             : 
    2611           0 :     if( FD_LIKELY( gui->summary.boot_progress.phase>=FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP ) ) jsonp_double( gui->http, "catching_up_elapsed_seconds",     (double)(gui->summary.boot_progress.catching_up_time_nanos - gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].sample_time_nanos) / 1e9 );
    2612           0 :     else                                                                                       jsonp_null  ( gui->http, "catching_up_elapsed_seconds" );
    2613             : 
    2614           0 :     if( FD_LIKELY( gui->summary.boot_progress.phase>=FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP
    2615           0 :                 && gui->summary.boot_progress.catching_up_first_replay_slot!=ULONG_MAX ) ) {
    2616           0 :       jsonp_ulong( gui->http, "catching_up_first_replay_slot", gui->summary.boot_progress.catching_up_first_replay_slot );
    2617           0 :     } else {
    2618           0 :       jsonp_null( gui->http, "catching_up_first_replay_slot" );
    2619           0 :     }
    2620             : 
    2621           0 :     jsonp_close_object( gui->http );
    2622           0 :   jsonp_close_envelope( gui->http );
    2623           0 : }
    2624             : 
    2625             : void
    2626             : fd_gui_printf_peers_viewport_update( fd_gui_peers_ctx_t *  peers,
    2627           0 :                                      ulong                 ws_conn_id ) {
    2628           0 :   jsonp_open_envelope( peers->http, "gossip", "view_update" );
    2629           0 :     jsonp_open_object( peers->http, "value" );
    2630           0 :       jsonp_open_array( peers->http, "changes" );
    2631           0 :         FD_TEST( peers->scratch.viewport_cnt<=FD_GUI_PEERS_WS_VIEWPORT_MAX_SZ );
    2632             : 
    2633           0 :         ulong start_row = peers->client_viewports[ ws_conn_id ].start_row;
    2634           0 :         for( ulong i=0UL; i<peers->scratch.viewport_cnt; i++ ) {
    2635           0 :           ulong j = start_row + i;
    2636           0 :           fd_gui_peers_row_t const * cur = &peers->scratch.viewport[ i ];
    2637           0 :           fd_gui_peers_row_t const * ref = &peers->scratch.viewport_ref[ i ];
    2638             : 
    2639             :           /* This code should be kept in sync with updates to
    2640             :              fd_gui_peers_live_table */
    2641           0 :           if( FD_UNLIKELY( cur->stake!=ref->stake ) ) {
    2642           0 :             jsonp_open_object( peers->http, NULL );
    2643           0 :               jsonp_ulong ( peers->http, "row_index", j );
    2644           0 :               jsonp_string( peers->http, "column_name", "Stake" );
    2645             : 
    2646           0 :               if( FD_UNLIKELY( cur->stake==ULONG_MAX ) ) jsonp_long ( peers->http, "new_value", -1 );
    2647           0 :               else                                       jsonp_ulong( peers->http, "new_value", cur->stake );
    2648           0 :             jsonp_close_object( peers->http );
    2649           0 :           }
    2650             : 
    2651           0 :           if( FD_UNLIKELY( strncmp( cur->name, ref->name, sizeof(ref->name) ) ) ) {
    2652           0 :             jsonp_open_object( peers->http, NULL );
    2653           0 :               jsonp_ulong ( peers->http, "row_index", j );
    2654           0 :               jsonp_string( peers->http, "column_name", "Name" );
    2655           0 :               jsonp_string( peers->http, "new_value", cur->name );
    2656           0 :             jsonp_close_object( peers->http );
    2657           0 :           }
    2658             : 
    2659           0 :           if( FD_UNLIKELY( cur->country_code_idx!=ref->country_code_idx ) ) {
    2660           0 :             jsonp_open_object( peers->http, NULL );
    2661           0 :               jsonp_ulong ( peers->http, "row_index", j );
    2662           0 :               jsonp_string( peers->http, "column_name", "Country" );
    2663           0 :               if( FD_LIKELY( cur->country_code_idx!=UCHAR_MAX ) ) {
    2664           0 :                 jsonp_string( peers->http, "new_value", peers->dbip.country_code[ cur->country_code_idx ] );
    2665           0 :               } else {
    2666           0 :                 jsonp_null( peers->http, "new_value" );
    2667           0 :               }
    2668           0 :             jsonp_close_object( peers->http );
    2669           0 :           }
    2670             : 
    2671           0 :           if( FD_UNLIKELY( memcmp( cur->pubkey.uc, ref->pubkey.uc, 32UL ) ) ) {
    2672           0 :             jsonp_open_object( peers->http, NULL );
    2673           0 :               jsonp_ulong ( peers->http, "row_index", j );
    2674           0 :               jsonp_string( peers->http, "column_name", "Pubkey" );
    2675             : 
    2676           0 :               char pubkey_base58[ FD_BASE58_ENCODED_32_SZ ];
    2677           0 :               fd_base58_encode_32( cur->pubkey.uc, NULL, pubkey_base58 );
    2678           0 :               jsonp_string( peers->http, "new_value", pubkey_base58 );
    2679           0 :             jsonp_close_object( peers->http );
    2680           0 :           }
    2681             : 
    2682           0 :           uint ip4_after  = cur->contact_info.sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP ].is_ipv6 ? 0U : cur->contact_info.sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP ].ip4;
    2683           0 :           uint ip4_before = ref->contact_info.sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP ].is_ipv6 ? 0U : ref->contact_info.sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP ].ip4;
    2684           0 :           if( FD_UNLIKELY( ip4_after!=ip4_before ) ) {
    2685           0 :             jsonp_open_object( peers->http, NULL );
    2686           0 :               jsonp_ulong ( peers->http, "row_index", j );
    2687           0 :               jsonp_string( peers->http, "column_name", "IP Addr" );
    2688             : 
    2689           0 :               char peer_addr[ 16 ]; /* 255.255.255.255 + '\0' */
    2690           0 :               FD_TEST( fd_cstr_printf_check( peer_addr, sizeof(peer_addr), NULL, FD_IP4_ADDR_FMT, FD_IP4_ADDR_FMT_ARGS( ip4_after ) ) );
    2691           0 :               jsonp_string( peers->http, "new_value", peer_addr );
    2692           0 :             jsonp_close_object( peers->http );
    2693           0 :           }
    2694             : 
    2695           0 :           long cur_egress_push_bps           = (long)cur->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PUSH_IDX ].rate_ema.value;
    2696           0 :           long ref_egress_push_bps           = (long)ref->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PUSH_IDX ].rate_ema.value;
    2697           0 :           long cur_ingress_push_bps          = (long)cur->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PUSH_IDX ].rate_ema.value;
    2698           0 :           long ref_ingress_push_bps          = (long)ref->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PUSH_IDX ].rate_ema.value;
    2699           0 :           long cur_egress_pull_response_bps  = (long)cur->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    2700           0 :           long ref_egress_pull_response_bps  = (long)ref->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    2701           0 :           long cur_ingress_pull_response_bps = (long)cur->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    2702           0 :           long ref_ingress_pull_response_bps = (long)ref->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    2703             : 
    2704           0 :           if( FD_UNLIKELY( ref->valid && cur_ingress_pull_response_bps!=ref_ingress_pull_response_bps ) ) {
    2705           0 :             jsonp_open_object( peers->http, NULL );
    2706           0 :               jsonp_ulong ( peers->http, "row_index", j );
    2707           0 :               jsonp_string( peers->http, "column_name", "Ingress Pull" );
    2708           0 :               jsonp_long  ( peers->http, "new_value", cur_ingress_pull_response_bps );
    2709           0 :             jsonp_close_object( peers->http );
    2710           0 :           }
    2711             : 
    2712           0 :           if( FD_UNLIKELY( ref->valid && cur_ingress_push_bps!=ref_ingress_push_bps ) ) {
    2713           0 :             jsonp_open_object( peers->http, NULL );
    2714           0 :               jsonp_ulong ( peers->http, "row_index", j );
    2715           0 :               jsonp_string( peers->http, "column_name", "Ingress Push" );
    2716           0 :               jsonp_long  ( peers->http, "new_value", cur_ingress_push_bps );
    2717           0 :             jsonp_close_object( peers->http );
    2718           0 :           }
    2719             : 
    2720           0 :           if( FD_UNLIKELY( ref->valid && cur_egress_pull_response_bps!=ref_egress_pull_response_bps ) ) {
    2721           0 :             jsonp_open_object( peers->http, NULL );
    2722           0 :               jsonp_ulong ( peers->http, "row_index", j );
    2723           0 :               jsonp_string( peers->http, "column_name", "Egress Pull" );
    2724           0 :               jsonp_long  ( peers->http, "new_value", cur_egress_pull_response_bps );
    2725           0 :             jsonp_close_object( peers->http );
    2726           0 :           }
    2727             : 
    2728           0 :           if( FD_UNLIKELY( ref->valid && cur_egress_push_bps!=ref_egress_push_bps ) ) {
    2729           0 :             jsonp_open_object( peers->http, NULL );
    2730           0 :               jsonp_ulong ( peers->http, "row_index", j );
    2731           0 :               jsonp_string( peers->http, "column_name", "Egress Push" );
    2732           0 :               jsonp_long  ( peers->http, "new_value", cur_egress_push_bps );
    2733           0 :             jsonp_close_object( peers->http );
    2734           0 :           }
    2735             : 
    2736           0 :         }
    2737           0 :       jsonp_close_array( peers->http );
    2738           0 :     jsonp_close_object( peers->http );
    2739           0 :   jsonp_close_envelope( peers->http );
    2740           0 : }
    2741             : 
    2742             : void
    2743             : fd_gui_printf_peers_viewport_request( fd_gui_peers_ctx_t *  peers,
    2744             :                                       char const *          key,
    2745             :                                       ulong                 ws_conn_id,
    2746           0 :                                       ulong                 request_id ) {
    2747           0 :   jsonp_open_envelope( peers->http, "gossip", key );
    2748           0 :     jsonp_ulong( peers->http, "id", request_id );
    2749           0 :     jsonp_open_object( peers->http, "value" );
    2750           0 :       FD_TEST( peers->scratch.viewport_cnt<=FD_GUI_PEERS_WS_VIEWPORT_MAX_SZ );
    2751           0 :       ulong start_row = peers->client_viewports[ ws_conn_id ].start_row;
    2752           0 :       for( ulong i=0UL; i<peers->scratch.viewport_cnt; i++ ) {
    2753           0 :         ulong j = start_row + i;
    2754           0 :         fd_gui_peers_row_t const * cur = &peers->scratch.viewport[ i ];
    2755             : 
    2756           0 :         char row_index_cstr[ 32 ];
    2757           0 :         FD_TEST( fd_cstr_printf_check( row_index_cstr, sizeof(row_index_cstr), NULL, "%lu", + j ) );
    2758           0 :         jsonp_open_object( peers->http, row_index_cstr );
    2759             :           /* This code should be kept in sync with updates to
    2760             :             fd_gui_peers_live_table */
    2761           0 :           if( FD_UNLIKELY( cur->stake==ULONG_MAX ) ) jsonp_long ( peers->http, "Stake", -1 );
    2762           0 :           else                                       jsonp_ulong( peers->http, "Stake", cur->stake );
    2763             : 
    2764           0 :           char pubkey_base58[ FD_BASE58_ENCODED_32_SZ ];
    2765           0 :           fd_base58_encode_32( cur->pubkey.uc, NULL, pubkey_base58 );
    2766           0 :           jsonp_string( peers->http, "Pubkey", pubkey_base58 );
    2767           0 :           jsonp_string( peers->http, "Name", cur->name );
    2768           0 :           if( FD_LIKELY( cur->country_code_idx!=UCHAR_MAX ) ) {
    2769           0 :             jsonp_string( peers->http, "Country", peers->dbip.country_code[ cur->country_code_idx ] );
    2770           0 :           } else {
    2771           0 :             jsonp_null( peers->http, "Country" );
    2772           0 :           }
    2773             : 
    2774           0 :           uint ip4 = cur->contact_info.sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP ].is_ipv6 ? 0U : cur->contact_info.sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP ].ip4;
    2775           0 :           char peer_addr[ 16 ]; /* 255.255.255.255 + '\0' */
    2776           0 :           FD_TEST( fd_cstr_printf_check( peer_addr, sizeof(peer_addr), NULL, FD_IP4_ADDR_FMT, FD_IP4_ADDR_FMT_ARGS( ip4 ) ) );
    2777           0 :           jsonp_string( peers->http, "IP Addr", peer_addr );
    2778             : 
    2779           0 :           long cur_egress_push_bps           = (long)cur->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PUSH_IDX ].rate_ema.value;
    2780           0 :           long cur_ingress_push_bps          = (long)cur->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PUSH_IDX ].rate_ema.value;
    2781           0 :           long cur_egress_pull_response_bps  = (long)cur->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    2782           0 :           long cur_ingress_pull_response_bps = (long)cur->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    2783             : 
    2784           0 :           jsonp_long  ( peers->http, "Ingress Pull", cur_ingress_pull_response_bps );
    2785           0 :           jsonp_long  ( peers->http, "Ingress Push", cur_ingress_push_bps );
    2786           0 :           jsonp_long  ( peers->http, "Egress Pull", cur_egress_pull_response_bps );
    2787           0 :           jsonp_long  ( peers->http, "Egress Push", cur_egress_push_bps );
    2788             : 
    2789           0 :         jsonp_close_object( peers->http );
    2790           0 :       }
    2791             : 
    2792           0 :     jsonp_close_object( peers->http );
    2793           0 :   jsonp_close_envelope( peers->http );
    2794           0 : }
    2795             : 
    2796             : void
    2797           0 : fd_gui_printf_peers_view_resize( fd_gui_peers_ctx_t *  peers, ulong sz ) {
    2798           0 :   jsonp_open_envelope( peers->http, "gossip", "peers_size_update" );
    2799           0 :     jsonp_ulong( peers->http, "value", sz );
    2800           0 :   jsonp_close_envelope( peers->http );
    2801           0 : }
    2802             : 
    2803             : void
    2804           0 : fd_gui_peers_printf_gossip_stats( fd_gui_peers_ctx_t *  peers ) {
    2805           0 :   fd_gui_peers_gossip_stats_t * cur = peers->gossip_stats;
    2806             : 
    2807           0 :   jsonp_open_envelope( peers->http, "gossip", "network_stats" );
    2808           0 :     jsonp_open_object( peers->http, "value" );
    2809             : 
    2810           0 :       jsonp_open_object( peers->http, "health" );
    2811           0 :         jsonp_ulong       ( peers->http, "num_push_messages_rx_success",            cur->network_health_push_msg_rx_success             );
    2812           0 :         jsonp_ulong       ( peers->http, "num_push_messages_rx_failure",            cur->network_health_push_msg_rx_failure             );
    2813           0 :         jsonp_ulong       ( peers->http, "num_push_entries_rx_success",             cur->network_health_push_crds_rx_success            );
    2814           0 :         jsonp_ulong       ( peers->http, "num_push_entries_rx_failure",             cur->network_health_push_crds_rx_failure            );
    2815           0 :         jsonp_ulong       ( peers->http, "num_push_entries_rx_duplicate",           cur->network_health_push_crds_rx_duplicate          );
    2816           0 :         jsonp_ulong       ( peers->http, "num_pull_response_messages_rx_success",   cur->network_health_pull_response_msg_rx_success    );
    2817           0 :         jsonp_ulong       ( peers->http, "num_pull_response_messages_rx_failure",   cur->network_health_pull_response_msg_rx_failure    );
    2818           0 :         jsonp_ulong       ( peers->http, "num_pull_response_entries_rx_success",    cur->network_health_pull_response_crds_rx_success   );
    2819           0 :         jsonp_ulong       ( peers->http, "num_pull_response_entries_rx_failure",    cur->network_health_pull_response_crds_rx_failure   );
    2820           0 :         jsonp_ulong       ( peers->http, "num_pull_response_entries_rx_duplicate",  cur->network_health_pull_response_crds_rx_duplicate );
    2821           0 :         jsonp_ulong_as_str( peers->http, "total_stake",                             cur->network_health_total_stake                     );
    2822           0 :         jsonp_ulong       ( peers->http, "total_peers",                             cur->network_health_total_peers                     );
    2823           0 :         jsonp_ulong_as_str( peers->http, "connected_stake",                         cur->network_health_connected_stake                 );
    2824           0 :         jsonp_ulong       ( peers->http, "connected_staked_peers",                  cur->network_health_connected_staked_peers          );
    2825           0 :         jsonp_ulong       ( peers->http, "connected_unstaked_peers",                cur->network_health_connected_unstaked_peers        );
    2826           0 :       jsonp_close_object( peers->http );
    2827             : 
    2828           0 :       jsonp_open_object( peers->http, "ingress" );
    2829             : 
    2830           0 :         jsonp_open_array( peers->http, "peer_names" );
    2831           0 :           for( ulong i=0UL; i<cur->network_ingress_peer_sz; i++ ) jsonp_string( peers->http, NULL, cur->network_ingress_peer_names[ i ] );
    2832           0 :         jsonp_close_array( peers->http );
    2833             : 
    2834           0 :         jsonp_open_array( peers->http, "peer_identities" );
    2835           0 :           for( ulong i=0UL; i<cur->network_ingress_peer_sz; i++ ) {
    2836           0 :             char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    2837           0 :             fd_base58_encode_32( cur->network_ingress_peer_identities[ i ].uc, NULL, identity_base58 );
    2838           0 :             jsonp_string( peers->http, NULL, identity_base58 );
    2839           0 :           }
    2840           0 :         jsonp_close_array( peers->http );
    2841             : 
    2842           0 :         jsonp_open_array( peers->http, "peer_throughput" );
    2843           0 :           for( ulong i=0UL; i<cur->network_ingress_peer_sz; i++ ) jsonp_long( peers->http, NULL, cur->network_ingress_peer_bytes_per_sec[ i ] );
    2844           0 :         jsonp_close_array( peers->http );
    2845           0 :         jsonp_long( peers->http, "total_throughput", cur->network_ingress_total_bytes_per_sec );
    2846           0 :       jsonp_close_object( peers->http );
    2847             : 
    2848           0 :       jsonp_open_object( peers->http, "egress" );
    2849           0 :         jsonp_open_array( peers->http, "peer_names" );
    2850           0 :           for( ulong i=0UL; i<cur->network_egress_peer_sz; i++ ) jsonp_string( peers->http, NULL, cur->network_egress_peer_names[ i ] );
    2851           0 :         jsonp_close_array( peers->http );
    2852             : 
    2853           0 :                 jsonp_open_array( peers->http, "peer_identities" );
    2854           0 :           for( ulong i=0UL; i<cur->network_egress_peer_sz; i++ ) {
    2855           0 :             char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    2856           0 :             fd_base58_encode_32( cur->network_egress_peer_identities[ i ].uc, NULL, identity_base58 );
    2857           0 :             jsonp_string( peers->http, NULL, identity_base58 );
    2858           0 :           }
    2859           0 :         jsonp_close_array( peers->http );
    2860             : 
    2861           0 :         jsonp_open_array( peers->http, "peer_throughput" );
    2862           0 :           for( ulong i=0UL; i<cur->network_egress_peer_sz; i++ ) jsonp_long( peers->http, NULL, cur->network_egress_peer_bytes_per_sec[ i ] );
    2863           0 :         jsonp_close_array( peers->http );
    2864           0 :         jsonp_long( peers->http, "total_throughput", cur->network_egress_total_bytes_per_sec );
    2865           0 :       jsonp_close_object( peers->http );
    2866             : 
    2867           0 :       jsonp_open_object( peers->http, "storage" );
    2868             :         /* since these are gauges, we don't take a diff */
    2869           0 :         jsonp_ulong( peers->http, "capacity", cur->storage_capacity );
    2870           0 :         jsonp_ulong( peers->http, "expired_count", cur->storage_expired_cnt );
    2871           0 :         jsonp_ulong( peers->http, "evicted_count", cur->storage_evicted_cnt );
    2872           0 :         jsonp_open_array( peers->http, "count" );
    2873           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_CRDS_VALUE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->storage_active_cnt[ i ] );
    2874           0 :         jsonp_close_array( peers->http );
    2875           0 :         jsonp_open_array( peers->http, "count_tx" );
    2876           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_CRDS_VALUE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->storage_cnt_tx[ i ] );
    2877           0 :         jsonp_close_array( peers->http );
    2878           0 :         jsonp_open_array( peers->http, "bytes_tx" );
    2879           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_CRDS_VALUE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->storage_bytes_tx[ i ] );
    2880           0 :         jsonp_close_array( peers->http );
    2881           0 :       jsonp_close_object( peers->http );
    2882           0 :       jsonp_open_object( peers->http, "messages" );
    2883           0 :         jsonp_open_array( peers->http, "num_bytes_rx" );
    2884           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->messages_bytes_rx[ i ] );
    2885           0 :         jsonp_close_array( peers->http );
    2886           0 :         jsonp_open_array( peers->http, "num_bytes_tx" );
    2887           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->messages_bytes_tx[ i ] );
    2888           0 :         jsonp_close_array( peers->http );
    2889           0 :         jsonp_open_array( peers->http, "num_messages_rx" );
    2890           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->messages_count_rx[ i ] );
    2891           0 :         jsonp_close_array( peers->http );
    2892           0 :         jsonp_open_array( peers->http, "num_messages_tx" );
    2893           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->messages_count_tx[ i ] );
    2894           0 :         jsonp_close_array( peers->http );
    2895           0 :       jsonp_close_object( peers->http );
    2896           0 :     jsonp_close_object( peers->http );
    2897           0 :   jsonp_close_envelope( peers->http );
    2898           0 : }
    2899             : 
    2900             : static void
    2901           0 : fd_gui_printf_shreds_window( fd_gui_t * gui, long after_ns, long before_ns ) {
    2902             :   /* find the min slot / min ts across the window (for delta encoding). */
    2903           0 :   ulong min_slot = ULONG_MAX;
    2904           0 :   long  min_ts   = LONG_MAX;
    2905           0 :   if( FD_LIKELY( gui->db ) ) {
    2906           0 :     fd_gui_hist_iter_t it;
    2907           0 :     if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_SHRED_EVENTS, after_ns, before_ns, NULL, NULL ) ) ) {
    2908           0 :       while( fd_gui_hist_range_next( &it ) ) {
    2909           0 :         fd_gui_slot_history_shred_event_t const * e = (fd_gui_slot_history_shred_event_t const *)it.rec;
    2910           0 :         if( FD_UNLIKELY( e->timestamp<after_ns || e->timestamp>before_ns ) ) continue;
    2911           0 :         min_slot = fd_ulong_min( min_slot, e->slot );
    2912           0 :         min_ts   = fd_long_min ( min_ts,   e->timestamp );
    2913           0 :       }
    2914           0 :       fd_gui_hist_range_end( &it );
    2915           0 :     }
    2916           0 :   }
    2917             : 
    2918           0 :   jsonp_ulong      ( gui->http, "reference_slot", min_slot );
    2919           0 :   jsonp_long_as_str( gui->http, "reference_ts",   min_ts   );
    2920             : 
    2921           0 : #define SHREDS_WINDOW_ITER( code ) \
    2922           0 :   do { \
    2923           0 :     if( FD_LIKELY( gui->db ) ) { \
    2924           0 :       fd_gui_hist_iter_t it; \
    2925           0 :       if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_SHRED_EVENTS, after_ns, before_ns, NULL, NULL ) ) ) { \
    2926           0 :         while( fd_gui_hist_range_next( &it ) ) { \
    2927           0 :           fd_gui_slot_history_shred_event_t const * e = (fd_gui_slot_history_shred_event_t const *)it.rec; (void)e; \
    2928           0 :           ulong db_event_slot = e->slot; (void)db_event_slot; \
    2929           0 :           if( FD_UNLIKELY( e->timestamp<after_ns || e->timestamp>before_ns ) ) continue; \
    2930           0 :           do { code } while(0); \
    2931           0 :         } \
    2932           0 :         fd_gui_hist_range_end( &it ); \
    2933           0 :       } \
    2934           0 :     } \
    2935           0 :   } while(0)
    2936             : 
    2937           0 :   jsonp_open_array( gui->http, "slot_delta" );
    2938           0 :     SHREDS_WINDOW_ITER( { jsonp_ulong( gui->http, NULL, db_event_slot-min_slot ); } );
    2939           0 :   jsonp_close_array( gui->http );
    2940           0 :   jsonp_open_array( gui->http, "shred_idx" );
    2941           0 :     SHREDS_WINDOW_ITER({
    2942           0 :       if( FD_LIKELY( e->shred_idx!=USHORT_MAX ) ) jsonp_ulong( gui->http, NULL, e->shred_idx );
    2943           0 :       else                                        jsonp_null ( gui->http, NULL );
    2944           0 :     });
    2945           0 :   jsonp_close_array( gui->http );
    2946           0 :   jsonp_open_array( gui->http, "event" );
    2947           0 :     SHREDS_WINDOW_ITER( { jsonp_ulong( gui->http, NULL, e->event ); } );
    2948           0 :   jsonp_close_array( gui->http );
    2949           0 :   jsonp_open_array( gui->http, "event_ts_delta" );
    2950           0 :     SHREDS_WINDOW_ITER( { jsonp_long_as_str( gui->http, NULL, e->timestamp-min_ts ); } );
    2951           0 :   jsonp_close_array( gui->http );
    2952             : 
    2953           0 : #undef SHREDS_WINDOW_ITER
    2954           0 : }
    2955             : 
    2956             : void
    2957           0 : fd_gui_printf_shred_updates( fd_gui_t * gui, long after_ns, long before_ns ) {
    2958           0 :   jsonp_open_envelope( gui->http, "slot", "live_shreds" );
    2959           0 :     jsonp_open_object( gui->http, "value" );
    2960           0 :       fd_gui_printf_shreds_window( gui, after_ns, before_ns );
    2961           0 :     jsonp_close_object( gui->http );
    2962           0 :   jsonp_close_envelope( gui->http );
    2963           0 : }
    2964             : 
    2965             : void
    2966           0 : fd_gui_printf_shred_rebroadcast( fd_gui_t * gui, long after, long before ) {
    2967           0 :   jsonp_open_envelope( gui->http, "slot", "live_shreds" );
    2968           0 :     jsonp_open_object( gui->http, "value" );
    2969           0 :       fd_gui_printf_shreds_window( gui, after, before );
    2970           0 :     jsonp_close_object( gui->http );
    2971           0 :   jsonp_close_envelope( gui->http );
    2972           0 : }
    2973             : 
    2974             : void
    2975             : fd_gui_printf_timeline_query_shreds( fd_gui_t *   gui,
    2976             :                                      char const * topic,
    2977             :                                      long         start_ns,
    2978             :                                      long         end_ns,
    2979           0 :                                      ulong        id ) {
    2980           0 :   jsonp_open_envelope( gui->http, topic, "query_shreds" );
    2981           0 :     jsonp_ulong( gui->http, "id", id );
    2982           0 :     jsonp_open_object( gui->http, "value" );
    2983           0 :       fd_gui_printf_shreds_window( gui, start_ns, end_ns );
    2984           0 :     jsonp_close_object( gui->http );
    2985           0 :   jsonp_close_envelope( gui->http );
    2986           0 : }
    2987             : 
    2988             : void
    2989             : fd_gui_peers_printf_wfs_add( fd_gui_peers_ctx_t * peers,
    2990             :                              ulong const *        idxs,
    2991           0 :                              ulong                cnt ) {
    2992           0 :   jsonp_open_envelope( peers->http, "wait_for_supermajority", "peer_add" );
    2993           0 :     jsonp_open_array( peers->http, "value" );
    2994           0 :       for( ulong i=0UL; i<cnt; i++ ) {
    2995           0 :         fd_gui_wfs_peer_t * wp = &peers->wfs_peers[ idxs[ i ] ];
    2996           0 :         char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    2997           0 :         fd_base58_encode_32( wp->identity_key.uc, NULL, identity_base58 );
    2998           0 :         jsonp_string( peers->http, NULL, identity_base58 );
    2999           0 :       }
    3000           0 :     jsonp_close_array( peers->http );
    3001           0 :   jsonp_close_envelope( peers->http );
    3002           0 : }
    3003             : 
    3004             : void
    3005             : fd_gui_peers_printf_wfs_remove( fd_gui_peers_ctx_t * peers,
    3006             :                                 ulong const *        idxs,
    3007           0 :                                 ulong                cnt ) {
    3008           0 :   jsonp_open_envelope( peers->http, "wait_for_supermajority", "peer_remove" );
    3009           0 :     jsonp_open_array( peers->http, "value" );
    3010           0 :       for( ulong i=0UL; i<cnt; i++ ) {
    3011           0 :         fd_gui_wfs_peer_t * wp = &peers->wfs_peers[ idxs[ i ] ];
    3012           0 :         char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    3013           0 :         fd_base58_encode_32( wp->identity_key.uc, NULL, identity_base58 );
    3014           0 :         jsonp_string( peers->http, NULL, identity_base58 );
    3015           0 :       }
    3016           0 :     jsonp_close_array( peers->http );
    3017           0 :   jsonp_close_envelope( peers->http );
    3018           0 : }
    3019             : 
    3020             : void
    3021           0 : fd_gui_peers_printf_wfs_stakes( fd_gui_peers_ctx_t * peers ) {
    3022           0 :   jsonp_open_envelope( peers->http, "wait_for_supermajority", "stakes" );
    3023           0 :     jsonp_open_object( peers->http, "value" );
    3024             : 
    3025           0 :       jsonp_open_array( peers->http, "staked_pubkeys" );
    3026           0 :         for( ulong i=0UL; i<peers->wfs_peers_cnt; i++ ) {
    3027           0 :           char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    3028           0 :           fd_base58_encode_32( peers->wfs_peers[ i ].identity_key.uc, NULL, identity_base58 );
    3029           0 :           jsonp_string( peers->http, NULL, identity_base58 );
    3030           0 :         }
    3031           0 :       jsonp_close_array( peers->http );
    3032             : 
    3033           0 :       jsonp_open_array( peers->http, "staked_lamports" );
    3034           0 :         for( ulong i=0UL; i<peers->wfs_peers_cnt; i++ ) {
    3035           0 :           jsonp_ulong_as_str( peers->http, NULL, peers->wfs_peers[ i ].stake );
    3036           0 :         }
    3037           0 :       jsonp_close_array( peers->http );
    3038             : 
    3039           0 :       jsonp_open_array( peers->http, "infos" );
    3040           0 :         for( ulong i=0UL; i<peers->wfs_peers_cnt; i++ ) {
    3041           0 :           fd_gui_config_parse_info_t * info =
    3042           0 :               fd_gui_peers_node_info_map_ele_query(
    3043           0 :                   peers->node_info_map, &peers->wfs_peers[ i ].identity_key, NULL, peers->node_info_pool );
    3044           0 :           if( info ) {
    3045           0 :             jsonp_open_object( peers->http, NULL );
    3046           0 :               jsonp_string( peers->http, "name",             info->name );
    3047           0 :               jsonp_string( peers->http, "details",          info->details );
    3048           0 :               jsonp_string( peers->http, "website",          info->website );
    3049           0 :               jsonp_string( peers->http, "icon_url",         info->icon_uri );
    3050           0 :               jsonp_string( peers->http, "keybase_username", info->keybase_username );
    3051           0 :             jsonp_close_object( peers->http );
    3052           0 :           } else {
    3053           0 :             jsonp_null( peers->http, NULL );
    3054           0 :           }
    3055           0 :         }
    3056           0 :       jsonp_close_array( peers->http );
    3057             : 
    3058           0 :     jsonp_close_object( peers->http );
    3059           0 :   jsonp_close_envelope( peers->http );
    3060           0 : }

Generated by: LCOV version 1.14