LCOV - code coverage report
Current view: top level - disco/gui - fd_gui_printf.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 3015 0.0 %
Date: 2026-10-22 18:10:43 Functions: 0 183 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 "../../flamenco/progcache/fd_progcache_cache.h"
      12             : #include "../../util/bits/fd_float.h"
      13             : #include "../../disco/topo/fd_topob.h"
      14             : 
      15             : static void
      16           0 : jsonp_strip_trailing_comma( fd_http_server_t * http ) {
      17           0 :   if( FD_LIKELY( !http->stage_err &&
      18           0 :                  http->stage_len>=1UL &&
      19           0 :                  http->oring[ (http->stage_off%http->oring_sz)+http->stage_len-1UL ]==(uchar)',' ) ) {
      20           0 :     http->stage_len--;
      21           0 :   }
      22           0 : }
      23             : 
      24             : static inline uchar *
      25             : jsonp_put( uchar *      q,
      26             :            char const * s,
      27           0 :            ulong        len ) {
      28           0 :   fd_memcpy( q, s, len );
      29           0 :   return q+len;
      30           0 : }
      31             : 
      32             : static inline uchar *
      33             : jsonp_put_key( uchar *      q,
      34             :                char const * key,
      35           0 :                ulong        key_len ) {
      36           0 :   *q++ = '"';
      37           0 :   q = jsonp_put( q, key, key_len );
      38           0 :   *q++ = '"';
      39           0 :   *q++ = ':';
      40           0 :   return q;
      41           0 : }
      42             : 
      43             : static inline uchar *
      44             : jsonp_put_ulong( uchar * q,
      45           0 :                  ulong   value ) {
      46           0 :   return (uchar *)fd_cstr_append_ulong_as_text( (char *)q, ' ', '\0', value, fd_ulong_base10_dig_cnt( value ) );
      47           0 : }
      48             : 
      49             : static inline uchar *
      50             : jsonp_put_long( uchar * q,
      51           0 :                 long    value ) {
      52           0 :   ulong mag = value<0L ? (ulong)-(value+1L)+1UL : (ulong)value;
      53           0 :   return (uchar *)fd_cstr_append_ulong_as_text( (char *)q, ' ', value<0L ? '-' : '\0', mag, fd_ulong_base10_dig_cnt( mag )+(ulong)(value<0L) );
      54           0 : }
      55             : 
      56             : static inline uchar *
      57             : jsonp_field_start( fd_http_server_t * http,
      58             :                    char const *       key,
      59           0 :                    ulong              value_max ) {
      60           0 :   if( FD_UNLIKELY( http->stage_err ) ) return NULL; /* as printf: nothing more until unstaged */
      61             : 
      62           0 :   ulong key_len = key ? strlen( key ) : 0UL;
      63           0 :   ulong need    = key_len+3UL+value_max;
      64           0 :   ulong avail   = http->oring_sz-http->stage_len;
      65           0 :   ulong spec    = fd_ulong_min( fd_ulong_max( need, 1024UL ), fd_ulong_max( need, avail ) );
      66           0 :   uchar * p = fd_http_server_append_start( http, spec );
      67           0 :   if( FD_UNLIKELY( !p ) ) return NULL;
      68           0 :   if( FD_LIKELY( key ) ) p = jsonp_put_key( p, key, key_len );
      69           0 :   return p;
      70           0 : }
      71             : 
      72             : static inline void
      73             : jsonp_field_end( fd_http_server_t * http,
      74           0 :                  uchar const *      end ) {
      75           0 :   fd_http_server_append_end( http, (ulong)(end-(http->oring+(http->stage_off%http->oring_sz)+http->stage_len)) );
      76           0 : }
      77             : 
      78             : static void
      79             : jsonp_open_object( fd_http_server_t * http,
      80           0 :                    char const *       key ) {
      81           0 :   uchar * q = jsonp_field_start( http, key, 1UL );
      82           0 :   if( FD_UNLIKELY( !q ) ) return;
      83           0 :   *q++ = '{';
      84           0 :   jsonp_field_end( http, q );
      85           0 : }
      86             : 
      87             : static void
      88           0 : jsonp_close_object( fd_http_server_t * http ) {
      89           0 :   jsonp_strip_trailing_comma( http );
      90           0 :   uchar * q = jsonp_field_start( http, NULL, 2UL );
      91           0 :   if( FD_UNLIKELY( !q ) ) return;
      92           0 :   jsonp_field_end( http, jsonp_put( q, "},", 2UL ) );
      93           0 : }
      94             : 
      95             : static void
      96             : jsonp_open_array( fd_http_server_t * http,
      97           0 :                   char const *       key ) {
      98           0 :   uchar * q = jsonp_field_start( http, key, 1UL );
      99           0 :   if( FD_UNLIKELY( !q ) ) return;
     100           0 :   *q++ = '[';
     101           0 :   jsonp_field_end( http, q );
     102           0 : }
     103             : 
     104             : static void
     105           0 : jsonp_close_array( fd_http_server_t * http ) {
     106           0 :   jsonp_strip_trailing_comma( http );
     107           0 :   uchar * q = jsonp_field_start( http, NULL, 2UL );
     108           0 :   if( FD_UNLIKELY( !q ) ) return;
     109           0 :   jsonp_field_end( http, jsonp_put( q, "],", 2UL ) );
     110           0 : }
     111             : 
     112             : static void
     113             : jsonp_ulong( fd_http_server_t * http,
     114             :              char const *       key,
     115           0 :              ulong              value ) {
     116           0 :   uchar * q = jsonp_field_start( http, key, 21UL );
     117           0 :   if( FD_UNLIKELY( !q ) ) return;
     118           0 :   q = jsonp_put_ulong( q, value );
     119           0 :   *q++ = ',';
     120           0 :   jsonp_field_end( http, q );
     121           0 : }
     122             : 
     123             : static void
     124             : jsonp_long( fd_http_server_t * http,
     125             :             char const *       key,
     126           0 :             long               value ) {
     127           0 :   uchar * q = jsonp_field_start( http, key, 22UL );
     128           0 :   if( FD_UNLIKELY( !q ) ) return;
     129           0 :   q = jsonp_put_long( q, value );
     130           0 :   *q++ = ',';
     131           0 :   jsonp_field_end( http, q );
     132           0 : }
     133             : 
     134             : /* jsonp_put_fixed writes value with dp (2 or 4) decimals, byte for
     135             :    byte what printf "%.2f"/"%.4f" gives, for finite |value|<1e15 (exact
     136             :    128 bit mant*10^dp>>exp, round to nearest even); returns the end of
     137             :    the text, or NULL for anything else (caller falls back to printf). */
     138             : 
     139           0 : #define JSONP_FIXED_MAX (22UL) /* -999999999999999.9999 */
     140             : 
     141             : static inline uchar *
     142             : jsonp_put_fixed( uchar * q,
     143             :                  double  value,
     144           0 :                  ulong   dp ) {
     145           0 :   ulong bits = fd_dblbits( value );
     146           0 :   ulong bexp = fd_dblbits_bexp( bits );
     147           0 :   ulong mant = fd_dblbits_mant( bits );
     148           0 :   if( FD_UNLIKELY( bexp==2047UL || !(fabs( value )<1e15) ) ) return NULL;
     149           0 :   long shift;
     150           0 :   if( FD_LIKELY( bexp ) ) { mant |= 1UL<<52; shift = 1075L-(long)bexp; } /* >=3 below 1e15<2^50 */
     151           0 :   else                    shift = 1074L;                                 /* subnormal */
     152           0 :   ulong   pow10 = dp==2UL ? 100UL : 10000UL;
     153           0 :   uint128 s     = (uint128)mant*pow10; /* <2^67 */
     154           0 :   ulong   r     = 0UL;
     155           0 :   if( FD_LIKELY( shift<128L ) ) {
     156           0 :     r = (ulong)(s>>shift);
     157           0 :     uint128 rem  = s-((uint128)r<<shift);
     158           0 :     uint128 half = (uint128)1<<(shift-1L);
     159           0 :     r += (ulong)( (rem>half) | ((rem==half) & (r&1UL)) );
     160           0 :   } /* else s<2^67<=half: rounds to 0 */
     161           0 :   if( bits>>63 ) *q++ = '-';
     162           0 :   q = jsonp_put_ulong( q, r/pow10 );
     163           0 :   *q++ = '.';
     164           0 :   ulong frac = r%pow10;
     165           0 :   if( dp==4UL ) { *q++ = (uchar)('0'+frac/1000UL); *q++ = (uchar)('0'+(frac/100UL)%10UL); }
     166           0 :   *q++ = (uchar)('0'+(frac/10UL)%10UL);
     167           0 :   *q++ = (uchar)('0'+frac%10UL);
     168           0 :   return q;
     169           0 : }
     170             : 
     171             : static void
     172             : jsonp_fixed( fd_http_server_t * http,
     173             :              char const *       key,
     174             :              double             value,
     175           0 :              ulong              dp ) {
     176           0 :   if( FD_UNLIKELY( http->stage_err ) ) return;
     177           0 :   uchar * q = jsonp_field_start( http, key, JSONP_FIXED_MAX+1UL );
     178           0 :   if( FD_UNLIKELY( !q ) ) return;
     179           0 :   uchar * end = jsonp_put_fixed( q, value, dp );
     180           0 :   if( FD_LIKELY( end ) ) {
     181           0 :     *end++ = ',';
     182           0 :     jsonp_field_end( http, end );
     183           0 :     return;
     184           0 :   }
     185             :   /* nan, inf or >=1e15: printf, as before (the reserve above is the
     186             :      one printf makes, so nothing about the ring moved) */
     187           0 :   if( FD_LIKELY( key ) ) fd_http_server_printf( http, "\"%s\":%.*f,", key, (int)dp, value );
     188           0 :   else                   fd_http_server_printf( http, "%.*f,", (int)dp, value );
     189           0 : }
     190             : 
     191             : static void
     192             : jsonp_double( fd_http_server_t * http,
     193             :               char const *       key,
     194           0 :               double             value ) {
     195           0 :   jsonp_fixed( http, key, value, 2UL );
     196           0 : }
     197             : 
     198             : static void
     199             : jsonp_centi( fd_http_server_t * http,
     200             :              char const *       key,
     201           0 :              ushort             value ) {
     202           0 :   uchar * q = jsonp_field_start( http, key, 7UL );
     203           0 :   if( FD_UNLIKELY( !q ) ) return;
     204           0 :   q = jsonp_put_ulong( q, (ulong)value/100UL );
     205           0 :   *q++ = '.';
     206           0 :   *q++ = (uchar)('0'+(value/10U)%10U);
     207           0 :   *q++ = (uchar)('0'+value%10U);
     208           0 :   *q++ = ',';
     209           0 :   jsonp_field_end( http, q );
     210           0 : }
     211             : 
     212             : static void
     213             : jsonp_double_4dp( fd_http_server_t * http,
     214             :                   char const *       key,
     215           0 :                   double             value ) {
     216           0 :   jsonp_fixed( http, key, value, 4UL );
     217           0 : }
     218             : 
     219             : static void
     220             : jsonp_ulong_as_str( fd_http_server_t * http,
     221             :                     char const *       key,
     222           0 :                     ulong              value ) {
     223           0 :   uchar * q = jsonp_field_start( http, key, 23UL );
     224           0 :   if( FD_UNLIKELY( !q ) ) return;
     225           0 :   *q++ = '"';
     226           0 :   q = jsonp_put_ulong( q, value );
     227           0 :   *q++ = '"';
     228           0 :   *q++ = ',';
     229           0 :   jsonp_field_end( http, q );
     230           0 : }
     231             : 
     232             : static void
     233             : jsonp_long_as_str( fd_http_server_t * http,
     234             :                    char const *       key,
     235           0 :                    long               value ) {
     236           0 :   uchar * q = jsonp_field_start( http, key, 24UL );
     237           0 :   if( FD_UNLIKELY( !q ) ) return;
     238           0 :   *q++ = '"';
     239           0 :   q = jsonp_put_long( q, value );
     240           0 :   *q++ = '"';
     241           0 :   *q++ = ',';
     242           0 :   jsonp_field_end( http, q );
     243           0 : }
     244             : 
     245             : static void
     246             : jsonp_string( fd_http_server_t * http,
     247             :               char const *       key,
     248           0 :               char const *       value ) {
     249           0 :   ulong value_len = value ? strlen( value ) : 0UL;
     250           0 :   if( FD_UNLIKELY( value && !fd_utf8_verify( value, value_len ) ) ) value = NULL;
     251           0 :   uchar * q = jsonp_field_start( http, key, value ? value_len+3UL : 5UL );
     252           0 :   if( FD_UNLIKELY( !q ) ) return;
     253           0 :   if( FD_LIKELY( value ) ) {
     254           0 :     *q++ = '"';
     255             :     /* escape quotemark, reverse solidus, and control chars U+0000
     256             :        through U+001F just replace with a space */
     257           0 :     for( ulong i=0UL; i<value_len; i++ ) {
     258           0 :       uchar c = (uchar)value[ i ];
     259           0 :       *q++ = fd_uchar_if( c<0x20 || c=='"' || c=='\\', (uchar)' ', c );
     260           0 :     }
     261           0 :     *q++ = '"';
     262           0 :     *q++ = ',';
     263           0 :   } else {
     264           0 :     q = jsonp_put( q, "null,", 5UL );
     265           0 :   }
     266           0 :   jsonp_field_end( http, q );
     267           0 : }
     268             : 
     269             : static void
     270             : jsonp_bool( fd_http_server_t * http,
     271             :             char const *       key,
     272           0 :             int                value ) {
     273           0 :   uchar * q = jsonp_field_start( http, key, 6UL );
     274           0 :   if( FD_UNLIKELY( !q ) ) return;
     275           0 :   q = value ? jsonp_put( q, "true,", 5UL ) : jsonp_put( q, "false,", 6UL );
     276           0 :   jsonp_field_end( http, q );
     277           0 : }
     278             : 
     279             : static void
     280             : jsonp_null( fd_http_server_t * http,
     281           0 :             char const *       key ) {
     282           0 :   uchar * q = jsonp_field_start( http, key, 6UL );
     283           0 :   if( FD_UNLIKELY( !q ) ) return;
     284           0 :   q = key ? jsonp_put( q, " null,", 6UL ) : jsonp_put( q, "null,", 5UL );
     285           0 :   jsonp_field_end( http, q );
     286           0 : }
     287             : 
     288             : static void
     289             : jsonp_text( fd_http_server_t * http,
     290             :             char const *       text,
     291           0 :             ulong              len ) {
     292           0 :   uchar * q = jsonp_field_start( http, NULL, len );
     293           0 :   if( FD_UNLIKELY( !q ) ) return;
     294           0 :   jsonp_field_end( http, jsonp_put( q, text, len ) );
     295           0 : }
     296             : 
     297             : static void
     298             : jsonp_open_envelope( fd_http_server_t * http,
     299             :                      char const *       topic,
     300           0 :                      char const *       key ) {
     301           0 :   jsonp_open_object( http, NULL );
     302           0 :   jsonp_string( http, "topic", topic );
     303           0 :   jsonp_string( http, "key",   key );
     304           0 : }
     305             : 
     306             : static void
     307           0 : jsonp_close_envelope( fd_http_server_t * http ) {
     308           0 :   jsonp_close_object( http );
     309           0 :   jsonp_strip_trailing_comma( http );
     310           0 : }
     311             : 
     312             : void
     313             : fd_gui_printf_open_query_response_envelope( fd_http_server_t * http,
     314             :                                             char const *       topic,
     315             :                                             char const *       key,
     316           0 :                                             ulong              id ) {
     317           0 :   jsonp_open_object( http, NULL );
     318           0 :   jsonp_string( http, "topic", topic );
     319           0 :   jsonp_string( http, "key", key );
     320           0 :   jsonp_ulong( http, "id", id );
     321           0 : }
     322             : 
     323             : void
     324           0 : fd_gui_printf_close_query_response_envelope( fd_http_server_t * http ) {
     325           0 :   jsonp_close_object( http );
     326           0 :   jsonp_strip_trailing_comma( http );
     327           0 : }
     328             : 
     329             : void
     330             : fd_gui_printf_null_query_response( fd_http_server_t * http,
     331             :                                    char const *       topic,
     332             :                                    char const *       key,
     333           0 :                                    ulong              id ) {
     334           0 :   fd_gui_printf_open_query_response_envelope( http, topic, key, id );
     335           0 :     jsonp_null( http, "value" );
     336           0 :   fd_gui_printf_close_query_response_envelope( http );
     337           0 : }
     338             : 
     339             : void
     340           0 : fd_gui_printf_version( fd_gui_t * gui ) {
     341           0 :   jsonp_open_envelope( gui->http, "summary", "version" );
     342           0 :     jsonp_string( gui->http, "value", gui->summary.version );
     343           0 :   jsonp_close_envelope( gui->http );
     344           0 : }
     345             : 
     346             : void
     347           0 : fd_gui_printf_is_alpenglow( fd_gui_t * gui ) {
     348           0 :   jsonp_open_envelope( gui->http, "summary", "is_alpenglow" );
     349           0 :     jsonp_bool( gui->http, "value", gui->summary.is_alpenglow );
     350           0 :   jsonp_close_envelope( gui->http );
     351           0 : }
     352             : 
     353             : void
     354           0 : fd_gui_printf_cluster( fd_gui_t * gui ) {
     355           0 :   jsonp_open_envelope( gui->http, "summary", "cluster" );
     356           0 :     jsonp_string( gui->http, "value", gui->summary.cluster );
     357           0 :   jsonp_close_envelope( gui->http );
     358           0 : }
     359             : 
     360             : void
     361           0 : fd_gui_printf_commit_hash( fd_gui_t * gui ) {
     362           0 :   jsonp_open_envelope( gui->http, "summary", "commit_hash" );
     363           0 :     jsonp_string( gui->http, "value", fd_commit_ref_cstr );
     364           0 :   jsonp_close_envelope( gui->http );
     365           0 : }
     366             : 
     367             : void
     368           0 : fd_gui_printf_identity_key( fd_gui_t * gui ) {
     369           0 :   jsonp_open_envelope( gui->http, "summary", "identity_key" );
     370           0 :     jsonp_string( gui->http, "value", gui->summary.identity_key_base58 );
     371           0 :   jsonp_close_envelope( gui->http );
     372           0 : }
     373             : 
     374             : void
     375           0 : fd_gui_printf_vote_key( fd_gui_t * gui ) {
     376           0 :   jsonp_open_envelope( gui->http, "summary", "vote_key" );
     377           0 :     if( FD_LIKELY( gui->summary.has_vote_key ) ) jsonp_string( gui->http, "value", gui->summary.vote_key_base58 );
     378           0 :     else                                         jsonp_null( gui->http, "value" );
     379           0 :   jsonp_close_envelope( gui->http );
     380           0 : }
     381             : 
     382             : void
     383           0 : fd_gui_printf_startup_time_nanos( fd_gui_t * gui ) {
     384           0 :   jsonp_open_envelope( gui->http, "summary", "startup_time_nanos" );
     385           0 :     jsonp_long_as_str( gui->http, "value", gui->summary.startup_time_nanos );
     386           0 :   jsonp_close_envelope( gui->http );
     387           0 : }
     388             : 
     389             : void
     390           0 : fd_gui_printf_server_time_nanos( fd_gui_t * gui, long now ) {
     391           0 :   jsonp_open_envelope( gui->http, "summary", "server_time_nanos" );
     392           0 :     jsonp_long_as_str( gui->http, "value", now );
     393           0 :   jsonp_close_envelope( gui->http );
     394           0 : }
     395             : 
     396             : void
     397           0 : fd_gui_printf_vote_distance( fd_gui_t * gui ) {
     398           0 :   jsonp_open_envelope( gui->http, "summary", "vote_distance" );
     399           0 :     jsonp_ulong( gui->http, "value", gui->summary.vote_distance );
     400           0 :   jsonp_close_envelope( gui->http );
     401           0 : }
     402             : 
     403             : void
     404           0 : fd_gui_printf_repair_slot( fd_gui_t * gui ) {
     405           0 :   jsonp_open_envelope( gui->http, "summary", "repair_slot" );
     406           0 :     if( FD_LIKELY( gui->summary.slot_repair!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_repair );
     407           0 :     else                                                    jsonp_null ( gui->http, "value" );
     408           0 :   jsonp_close_envelope( gui->http );
     409           0 : }
     410             : 
     411             : void
     412           0 : fd_gui_peers_printf_vote_slot( fd_gui_peers_ctx_t * peers ) {
     413           0 :   jsonp_open_envelope( peers->http, "summary", "vote_slot" );
     414           0 :     if( FD_LIKELY( peers->slot_voted!=ULONG_MAX  ) ) jsonp_ulong( peers->http, "value", peers->slot_voted );
     415           0 :     else                                             jsonp_null ( peers->http, "value" );
     416           0 :   jsonp_close_envelope( peers->http );
     417           0 : }
     418             : 
     419             : void
     420           0 : fd_gui_printf_vote_slot( fd_gui_t * gui ) {
     421           0 :   jsonp_open_envelope( gui->http, "summary", "vote_slot" );
     422           0 :     if( FD_LIKELY( gui->summary.slot_voted!=ULONG_MAX ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_voted );
     423           0 :     else                                                  jsonp_null ( gui->http, "value" );
     424           0 :   jsonp_close_envelope( gui->http );
     425           0 : }
     426             : 
     427             : void
     428           0 : fd_gui_printf_turbine_slot( fd_gui_t * gui ) {
     429           0 :   jsonp_open_envelope( gui->http, "summary", "turbine_slot" );
     430           0 :     if( FD_LIKELY( gui->summary.slot_turbine!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_turbine );
     431           0 :     else                                                     jsonp_null ( gui->http, "value" );
     432           0 :   jsonp_close_envelope( gui->http );
     433           0 : }
     434             : 
     435             : void
     436           0 : fd_gui_printf_reset_slot( fd_gui_t * gui ) {
     437           0 :   jsonp_open_envelope( gui->http, "summary", "reset_slot" );
     438           0 :     if( FD_LIKELY( gui->summary.slot_reset!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_reset );
     439           0 :     else                                                   jsonp_null ( gui->http, "value" );
     440           0 :   jsonp_close_envelope( gui->http );
     441           0 : }
     442             : 
     443             : void
     444           0 : fd_gui_printf_storage_slot( fd_gui_t * gui ) {
     445           0 :   jsonp_open_envelope( gui->http, "summary", "storage_slot" );
     446           0 :     if( FD_LIKELY( gui->summary.slot_storage!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_storage );
     447           0 :     else                                                     jsonp_null ( gui->http, "value" );
     448           0 :   jsonp_close_envelope( gui->http );
     449           0 : }
     450             : 
     451             : void
     452           0 : fd_gui_printf_active_fork_cnt( fd_gui_t * gui ) {
     453           0 :   jsonp_open_envelope( gui->http, "summary", "active_fork_count" );
     454           0 :     if( FD_LIKELY( gui->summary.active_fork_cnt!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.active_fork_cnt );
     455           0 :     else                                                        jsonp_null ( gui->http, "value" );
     456           0 :   jsonp_close_envelope( gui->http );
     457           0 : }
     458             : 
     459             : void
     460           0 : fd_gui_printf_slot_caught_up( fd_gui_t * gui ) {
     461           0 :   jsonp_open_envelope( gui->http, "summary", "slot_caught_up" );
     462           0 :     if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX  ) ) jsonp_ulong( gui->http, "value", gui->summary.slot_caught_up );
     463           0 :     else                                                       jsonp_null ( gui->http, "value" );
     464           0 :   jsonp_close_envelope( gui->http );
     465           0 : }
     466             : 
     467             : void
     468           0 : fd_gui_printf_catch_up_history( fd_gui_t * gui ) {
     469           0 :   jsonp_open_envelope( gui->http, "summary", "catch_up_history" );
     470           0 :     jsonp_open_object( gui->http, "value" );
     471           0 :       jsonp_open_array( gui->http, "turbine" );
     472           0 :         for( ulong i=0UL; i<gui->summary.catch_up_turbine_sz; i+=2 ) {
     473           0 :           for( ulong j=gui->summary.catch_up_turbine[ i ]; j<=gui->summary.catch_up_turbine[ i+1UL ]; j++ ) {
     474           0 :             jsonp_ulong( gui->http, NULL, j );
     475           0 :           }
     476           0 :         }
     477           0 :       jsonp_close_array( gui->http );
     478           0 :       jsonp_open_array( gui->http, "repair" );
     479           0 :         for( ulong i=0UL; i<gui->summary.catch_up_repair_sz; i+=2 ) {
     480           0 :           for( ulong j=gui->summary.catch_up_repair[ i ]; j<=gui->summary.catch_up_repair[ i+1UL ]; j++ ) {
     481           0 :             jsonp_ulong( gui->http, NULL, j );
     482           0 :           }
     483           0 :         }
     484           0 :       jsonp_close_array( gui->http );
     485             : 
     486           0 :       if( FD_LIKELY( gui->summary.boot_progress.phase==FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP ) ) {
     487           0 :         ulong min_slot = ULONG_MAX;
     488           0 :         long min_ts = LONG_MAX;
     489             : 
     490           0 : #define SHREDS_REV_ITER( age_ns, code_archive ) \
     491           0 :         do { \
     492           0 :           if( FD_UNLIKELY( gui->summary.boot_progress.catching_up_time_nanos==0L ) ) break; \
     493           0 :           long _hi_ns = gui->summary.boot_progress.catching_up_time_nanos; \
     494           0 :           long _lo_ns = _hi_ns - (long)(age_ns); \
     495           0 :           fd_gui_shred_event_iter_t _it[ 1 ]; \
     496           0 :           fd_gui_shred_event_iter_begin( gui, _it, _lo_ns, _hi_ns ); \
     497           0 :           while( fd_gui_shred_event_iter_next( _it ) ) { \
     498           0 :             fd_gui_shred_event_t const * event = &_it->event; (void)event; \
     499           0 :             ulong db_event_slot = event->slot; (void)db_event_slot; \
     500           0 :             do { code_archive } while (0); \
     501           0 :           } \
     502           0 :           fd_gui_shred_event_iter_end( _it ); \
     503           0 :         } while(0);
     504             : 
     505           0 :         SHREDS_REV_ITER(
     506           0 :           15000000000,
     507           0 :           {
     508           0 :             min_slot = fd_ulong_min( min_slot, db_event_slot );
     509           0 :             min_ts = fd_long_min( min_ts, event->event_time_ns );
     510           0 :           }
     511           0 :         )
     512             : 
     513           0 :         jsonp_open_object( gui->http, "shreds" );
     514           0 :           jsonp_ulong      ( gui->http, "reference_slot", min_slot );
     515           0 :           jsonp_long_as_str( gui->http, "reference_ts",   min_ts   );
     516             : 
     517           0 :           jsonp_open_array( gui->http, "slot_delta" );
     518           0 :             SHREDS_REV_ITER(
     519           0 :               15000000000L,
     520           0 :               { jsonp_ulong( gui->http, NULL, db_event_slot-min_slot ); }
     521           0 :             )
     522           0 :           jsonp_close_array( gui->http );
     523           0 :           jsonp_open_array( gui->http, "shred_idx" );
     524           0 :             SHREDS_REV_ITER(
     525           0 :               15000000000L,
     526           0 :               {
     527           0 :                 if( FD_LIKELY( event->idx!=USHORT_MAX ) ) jsonp_ulong( gui->http, NULL, event->idx );
     528           0 :                 else                                            jsonp_null ( gui->http, NULL );
     529           0 :               }
     530           0 :             )
     531           0 :           jsonp_close_array( gui->http );
     532           0 :           jsonp_open_array( gui->http, "event" );
     533           0 :             SHREDS_REV_ITER(
     534           0 :               15000000000L,
     535           0 :               { jsonp_ulong( gui->http, NULL, event->event ); }
     536           0 :             )
     537           0 :           jsonp_close_array( gui->http );
     538           0 :           jsonp_open_array( gui->http, "event_ts_delta" );
     539           0 :             SHREDS_REV_ITER(
     540           0 :               15000000000L,
     541           0 :               { jsonp_ulong_as_str( gui->http, NULL, (ulong)event->event_time_ns-(ulong)min_ts ); }
     542           0 :             )
     543           0 :           jsonp_close_array( gui->http );
     544           0 :         jsonp_close_object( gui->http );
     545           0 : #undef SHREDS_REV_ITER
     546           0 :       } else {
     547           0 :         jsonp_null( gui->http, "shreds" );
     548           0 :       }
     549             : 
     550           0 :     jsonp_close_object( gui->http );
     551           0 :   jsonp_close_envelope( gui->http );
     552           0 : }
     553             : 
     554             : void
     555           0 : fd_gui_printf_vote_state( fd_gui_t * gui ) {
     556           0 :   jsonp_open_envelope( gui->http, "summary", "vote_state" );
     557           0 :     switch( gui->summary.vote_state ) {
     558           0 :       case FD_GUI_VOTE_STATE_NON_VOTING:
     559           0 :         jsonp_string( gui->http, "value", "non-voting" );
     560           0 :         break;
     561           0 :       case FD_GUI_VOTE_STATE_VOTING:
     562           0 :         jsonp_string( gui->http, "value", "voting" );
     563           0 :         break;
     564           0 :       case FD_GUI_VOTE_STATE_DELINQUENT:
     565           0 :         jsonp_string( gui->http, "value", "delinquent" );
     566           0 :         break;
     567           0 :       default:
     568           0 :         FD_LOG_ERR(( "unknown vote state %d", gui->summary.vote_state ));
     569           0 :     }
     570           0 :   jsonp_close_envelope( gui->http );
     571           0 : }
     572             : 
     573             : /* fd_gui_skipped_history_bounds computes the half open index range
     574             :    [first_known_slot_idx,root_slot_idx) into an epoch's skip arrays. */
     575             : 
     576             : static int
     577             : fd_gui_skipped_history_bounds( fd_gui_t const *       gui,
     578             :                                fd_gui_epoch_t const * rec,
     579             :                                ulong *                lo_out,
     580           0 :                                ulong *                hi_out ) {
     581           0 :   if( FD_UNLIKELY( !rec ) ) return 0;
     582           0 :   if( FD_UNLIKELY( gui->summary.slot_rooted==ULONG_MAX ) ) return 0;
     583           0 :   if( FD_UNLIKELY( gui->summary.slot_rooted<rec->start_slot ) ) return 0;
     584             : 
     585           0 :   ulong first_replay_slot = fd_ulong_if( gui->summary.slot_caught_up!=ULONG_MAX, fd_gui_first_replay_slot( gui ), ULONG_MAX );
     586           0 :   ulong start_slot        = fd_ulong_max( rec->start_slot, fd_ulong_if( first_replay_slot!=ULONG_MAX, first_replay_slot, 0UL ) );
     587           0 :   if( FD_UNLIKELY( start_slot>gui->summary.slot_rooted ) ) return 0;
     588             : 
     589           0 :   *lo_out = start_slot - rec->start_slot;
     590           0 :   *hi_out = fd_ulong_min( rec->slot_cnt, gui->summary.slot_rooted+1UL-rec->start_slot );
     591           0 :   return *lo_out<*hi_out;
     592           0 : }
     593             : 
     594             : void
     595           0 : fd_gui_printf_skipped_history( fd_gui_t * gui, ulong epoch ) {
     596           0 :   jsonp_open_envelope( gui->http, "slot", "skipped_history" );
     597           0 :     jsonp_open_array( gui->http, "value" );
     598           0 :       fd_gui_epoch_t const * rec = fd_gui_epoch( gui, epoch );
     599           0 :       ulong lo, hi;
     600           0 :       if( FD_LIKELY( fd_gui_skipped_history_bounds( gui, rec, &lo, &hi ) ) ) {
     601           0 :         for( ulong i=lo; i<hi; i++ ) {
     602           0 :           ulong slot = rec->start_slot+i;
     603           0 :           if( FD_UNLIKELY( rec->skipped[ i ] && fd_gui_slot_is_mine( gui, slot ) ) ) jsonp_ulong( gui->http, NULL, slot );
     604           0 :         }
     605           0 :       }
     606           0 :     jsonp_close_array( gui->http );
     607           0 :   jsonp_close_envelope( gui->http );
     608           0 : }
     609             : 
     610             : void
     611           0 : fd_gui_printf_skipped_history_cluster( fd_gui_t * gui, ulong epoch ) {
     612           0 :   jsonp_open_envelope( gui->http, "slot", "skipped_history_cluster" );
     613           0 :     jsonp_open_array( gui->http, "value" );
     614           0 :       fd_gui_epoch_t const * rec = fd_gui_epoch( gui, epoch );
     615           0 :       ulong lo, hi;
     616           0 :       if( FD_LIKELY( fd_gui_skipped_history_bounds( gui, rec, &lo, &hi ) ) ) {
     617           0 :         for( ulong i=lo; i<hi; i++ ) {
     618           0 :           if( FD_UNLIKELY( rec->skipped[ i ] ) ) jsonp_ulong( gui->http, NULL, rec->start_slot+i );
     619           0 :         }
     620           0 :       }
     621           0 :     jsonp_close_array( gui->http );
     622           0 :   jsonp_close_envelope( gui->http );
     623           0 : }
     624             : 
     625             : /* fd_gui_slot_is_late returns 1 if slot s belongs in the
     626             :    late_votes_history output (voted for late, or canonical but never
     627             :    voted for), 0 otherwise. */
     628             : 
     629             : static inline int
     630           0 : fd_gui_slot_is_late( fd_gui_epoch_t const * rec, ulong s ) {
     631           0 :   ulong  idx   = s-rec->start_slot;
     632           0 :   uchar  exact = rec->latency_exact[ idx ];
     633           0 :   return fd_int_if( rec->is_voter[ idx ]!=FD_GUI_IS_VOTER_YES, 0, fd_int_if( rec->skipped[ idx ], 0, fd_int_if( exact==FD_GUI_VOTE_LATENCY_NOT_VOTED, 1, exact>1 ) ) );
     634           0 : }
     635             : 
     636             : void
     637           0 : fd_gui_printf_late_votes_history( fd_gui_t * gui ) {
     638           0 :   fd_gui_epoch_t * rec = fd_gui_current_epoch( gui );
     639           0 :   ulong first_replay_slot = fd_ulong_if( gui->summary.slot_caught_up!=ULONG_MAX, fd_gui_first_replay_slot( gui ), ULONG_MAX );
     640           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;
     641           0 :   ulong end_slot   = FD_LIKELY( rec ) ? fd_ulong_min( rec->start_slot+rec->slot_cnt-1UL, gui->summary.slot_rooted ) : 0UL;
     642           0 :   int   have_any   = rec && gui->summary.slot_rooted!=ULONG_MAX;
     643             : 
     644           0 :   jsonp_open_envelope( gui->http, "slot", "late_votes_history" );
     645           0 :       jsonp_open_object( gui->http, "value" );
     646           0 :         jsonp_open_array( gui->http, "slot" );
     647           0 :           if( FD_LIKELY( have_any ) ) {
     648           0 :             ulong s = start_slot;
     649           0 :             while( s<=end_slot ) {
     650           0 :               if( FD_LIKELY( !fd_gui_slot_is_late( rec, s ) ) ) { s++; continue; }
     651           0 :               ulong run_start = s;
     652           0 :               uchar run_exact = rec->latency_exact[ s-rec->start_slot ];
     653           0 :               while( s<=end_slot && fd_gui_slot_is_late( rec, s ) && rec->latency_exact[ s-rec->start_slot ]==run_exact ) s++;
     654           0 :               jsonp_ulong( gui->http, NULL, run_start );
     655           0 :               jsonp_ulong( gui->http, NULL, s-1UL );
     656           0 :             }
     657           0 :           }
     658           0 :         jsonp_close_array( gui->http );
     659           0 :         jsonp_open_array( gui->http, "latency_exact" );
     660           0 :           if( FD_LIKELY( have_any ) ) {
     661           0 :             ulong s = start_slot;
     662           0 :             while( s<=end_slot ) {
     663           0 :               if( FD_LIKELY( !fd_gui_slot_is_late( rec, s ) ) ) { s++; continue; }
     664           0 :               uchar run_exact = rec->latency_exact[ s-rec->start_slot ];
     665           0 :               while( s<=end_slot && fd_gui_slot_is_late( rec, s ) && rec->latency_exact[ s-rec->start_slot ]==run_exact ) s++;
     666           0 :               if( FD_LIKELY( run_exact!=FD_GUI_VOTE_LATENCY_NOT_VOTED ) ) jsonp_ulong( gui->http, NULL, run_exact );
     667           0 :               else                                                        jsonp_null ( gui->http, NULL );
     668           0 :             }
     669           0 :           }
     670           0 :         jsonp_close_array( gui->http );
     671           0 :       jsonp_close_object( gui->http );
     672           0 :   jsonp_close_envelope( gui->http );
     673           0 : }
     674             : 
     675             : void
     676           0 : fd_gui_printf_tps_history( fd_gui_t * gui ) {
     677           0 :   jsonp_open_envelope( gui->http, "summary", "tps_history" );
     678           0 :     jsonp_open_array( gui->http, "value" );
     679             : 
     680           0 :     for( ulong i=0UL; i<FD_GUI_TPS_HISTORY_SAMPLE_CNT; i++ ) {
     681           0 :       ulong idx = (gui->summary.estimated_tps_history_idx+i) % FD_GUI_TPS_HISTORY_SAMPLE_CNT;
     682           0 :       ulong vote_cnt = gui->summary.estimated_tps_history[ idx ].vote_failed
     683           0 :                      + gui->summary.estimated_tps_history[ idx ].vote_success;
     684           0 :       ulong total_cnt = vote_cnt
     685           0 :                       + gui->summary.estimated_tps_history[ idx ].nonvote_success
     686           0 :                       + gui->summary.estimated_tps_history[ idx ].nonvote_failed;
     687           0 :       jsonp_open_array( gui->http, NULL );
     688           0 :         if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
     689           0 :           ulong success_cnt = gui->summary.estimated_tps_history[ idx ].nonvote_success
     690           0 :                             + gui->summary.estimated_tps_history[ idx ].vote_success;
     691           0 :           ulong failed_cnt  = gui->summary.estimated_tps_history[ idx ].nonvote_failed
     692           0 :                             + gui->summary.estimated_tps_history[ idx ].vote_failed;
     693           0 :           jsonp_double( gui->http, NULL, (double)success_cnt/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
     694           0 :           jsonp_double( gui->http, NULL, (double)failed_cnt /(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
     695           0 :         } else {
     696           0 :         jsonp_double( gui->http, NULL, (double)total_cnt/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
     697           0 :         jsonp_double( gui->http, NULL, (double)vote_cnt/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
     698           0 :         jsonp_double( gui->http, NULL, (double)gui->summary.estimated_tps_history[ idx ].nonvote_success/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
     699           0 :         jsonp_double( gui->http, NULL, (double)gui->summary.estimated_tps_history[ idx ].nonvote_failed/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
     700           0 :         }
     701           0 :       jsonp_close_array( gui->http );
     702           0 :     }
     703             : 
     704           0 :     jsonp_close_array( gui->http );
     705           0 :   jsonp_close_envelope( gui->http );
     706           0 : }
     707             : 
     708             : void
     709           0 : fd_gui_printf_block_engine( fd_gui_t * gui ) {
     710           0 :   jsonp_open_envelope( gui->http, "block_engine", "update" );
     711           0 :     jsonp_open_object( gui->http, "value" );
     712           0 :       jsonp_string( gui->http, "name",   gui->block_engine.name );
     713           0 :       jsonp_string( gui->http, "url",    gui->block_engine.url );
     714           0 :       jsonp_string( gui->http, "ip",     gui->block_engine.ip_cstr );
     715           0 :       if( FD_LIKELY( gui->block_engine.status==FD_BUNDLE_STATE_CONNECTING ) )     jsonp_string( gui->http, "status", "connecting" );
     716           0 :       else if( FD_LIKELY( gui->block_engine.status==FD_BUNDLE_STATE_CONNECTED ) ) jsonp_string( gui->http, "status", "connected" );
     717           0 :       else if( FD_LIKELY( gui->block_engine.status==FD_BUNDLE_STATE_SLEEPING ) )  jsonp_string( gui->http, "status", "sleeping" );
     718           0 :       else                                                                        jsonp_string( gui->http, "status", "disconnected" );
     719           0 :     jsonp_close_object( gui->http );
     720           0 :   jsonp_close_envelope( gui->http );
     721           0 : }
     722             : 
     723             : static char const *
     724           0 : fd_gui_tile_priority_cstr( fd_topo_tile_t const * tile ) {
     725           0 :   switch( fd_topob_tile_priority_type( tile ) ) {
     726           0 :     case FD_TOPOB_PRIORITY_FLOATING: return "floating";
     727           0 :     case FD_TOPOB_PRIORITY_STARTUP:  return "startup";
     728           0 :     case FD_TOPOB_PRIORITY_NORMAL:   return "normal";
     729           0 :     case FD_TOPOB_PRIORITY_CRITICAL: return "critical";
     730           0 :     default:                         return "unknown";
     731           0 :   }
     732           0 : }
     733             : 
     734             : void
     735           0 : fd_gui_printf_tiles( fd_gui_t * gui ) {
     736           0 :   jsonp_open_envelope( gui->http, "summary", "tiles" );
     737           0 :     jsonp_open_array( gui->http, "value" );
     738           0 :       for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
     739           0 :         fd_topo_tile_t const * tile = &gui->topo->tiles[ gui->summary.tile[ i ] ];
     740             : 
     741           0 :         if( FD_UNLIKELY( !strncmp( tile->name, "bench", 5UL ) ) ) {
     742             :           /* bench tiles not reported */
     743           0 :           continue;
     744           0 :         }
     745             : 
     746           0 :         jsonp_open_object( gui->http, NULL );
     747           0 :           jsonp_string( gui->http, "kind",     tile->name );
     748           0 :           jsonp_ulong(  gui->http, "kind_id",  tile->kind_id );
     749           0 :           jsonp_ulong(  gui->http, "pid",      fd_metrics_tile( tile->metrics )[ MIDX( GAUGE, TILE, PID ) ] );
     750           0 :           jsonp_string( gui->http, "priority", fd_gui_tile_priority_cstr( tile ) );
     751           0 :         jsonp_close_object( gui->http );
     752           0 :       }
     753           0 :     jsonp_close_array( gui->http );
     754           0 :   jsonp_close_envelope( gui->http );
     755           0 : }
     756             : 
     757             : void
     758           0 : fd_gui_printf_schedule_strategy( fd_gui_t * gui ) {
     759           0 :   jsonp_open_envelope( gui->http, "summary", "schedule_strategy" );
     760           0 :     char mode[10];
     761           0 :     switch (gui->summary.schedule_strategy) {
     762           0 :       case 0: fd_cstr_ncpy( mode, "perf",     sizeof(mode) ); break;
     763           0 :       case 1: fd_cstr_ncpy( mode, "balanced", sizeof(mode) ); break;
     764           0 :       case 2: fd_cstr_ncpy( mode, "revenue",  sizeof(mode) ); break;
     765           0 :       default: FD_LOG_ERR(("unexpected schedule_strategy %d", gui->summary.schedule_strategy));
     766           0 :     }
     767           0 :     jsonp_string( gui->http, "value", mode );
     768           0 :   jsonp_close_envelope( gui->http );
     769           0 : }
     770             : 
     771             : void
     772           0 : fd_gui_printf_identity_balance( fd_gui_t * gui ) {
     773           0 :   jsonp_open_envelope( gui->http, "summary", "identity_balance" );
     774           0 :     jsonp_ulong_as_str( gui->http, "value", gui->summary.identity_account_balance );
     775           0 :   jsonp_close_envelope( gui->http );
     776           0 : }
     777             : 
     778             : void
     779           0 : fd_gui_printf_vote_balance( fd_gui_t * gui ) {
     780           0 :   jsonp_open_envelope( gui->http, "summary", "vote_balance" );
     781           0 :     jsonp_ulong_as_str( gui->http, "value", gui->summary.vote_account_balance );
     782           0 :   jsonp_close_envelope( gui->http );
     783           0 : }
     784             : 
     785             : void
     786           0 : fd_gui_printf_vote_commission( fd_gui_t * gui ) {
     787           0 :   jsonp_open_envelope( gui->http, "summary", "vote_commission" );
     788           0 :     if( FD_LIKELY( gui->summary.vote_commission!=USHORT_MAX ) ) jsonp_ulong( gui->http, "value", (ulong)gui->summary.vote_commission );
     789           0 :     else                                                        jsonp_null ( gui->http, "value" );
     790           0 :   jsonp_close_envelope( gui->http );
     791           0 : }
     792             : 
     793             : void
     794           0 : fd_gui_printf_estimated_slot_duration_nanos( fd_gui_t * gui ) {
     795           0 :   jsonp_open_envelope( gui->http, "summary", "estimated_slot_duration_nanos" );
     796           0 :     jsonp_ulong( gui->http, "value", gui->summary.estimated_slot_duration_nanos );
     797           0 :   jsonp_close_envelope( gui->http );
     798           0 : }
     799             : 
     800             : 
     801             : void
     802           0 : fd_gui_printf_root_slot( fd_gui_t * gui ) {
     803           0 :   jsonp_open_envelope( gui->http, "summary", "root_slot" );
     804           0 :     jsonp_ulong( gui->http, "value", fd_ulong_if( gui->summary.slot_rooted!=ULONG_MAX, gui->summary.slot_rooted, 0UL ) );
     805           0 :   jsonp_close_envelope( gui->http );
     806           0 : }
     807             : 
     808             : void
     809           0 : fd_gui_printf_finalized_slot( fd_gui_t * gui ) {
     810           0 :   jsonp_open_envelope( gui->http, "summary", "finalized_slot" );
     811           0 :     jsonp_ulong( gui->http, "value", fd_ulong_if( gui->summary.slot_finalized!=ULONG_MAX, gui->summary.slot_finalized, 0UL ) );
     812           0 :   jsonp_close_envelope( gui->http );
     813           0 : }
     814             : 
     815             : void
     816           0 : fd_gui_printf_notarized_slot( fd_gui_t * gui ) {
     817           0 :   jsonp_open_envelope( gui->http, "summary", "notarized_slot" );
     818           0 :     jsonp_ulong( gui->http, "value", fd_ulong_if( gui->summary.slot_notarized!=ULONG_MAX, gui->summary.slot_notarized, 0UL ) );
     819           0 :   jsonp_close_envelope( gui->http );
     820           0 : }
     821             : 
     822             : void
     823           0 : fd_gui_printf_optimistically_confirmed_slot( fd_gui_t * gui ) {
     824           0 :   jsonp_open_envelope( gui->http, "summary", "optimistically_confirmed_slot" );
     825           0 :     jsonp_ulong( gui->http, "value", fd_ulong_if( gui->summary.slot_optimistically_confirmed!=ULONG_MAX, gui->summary.slot_optimistically_confirmed, 0UL ) );
     826           0 :   jsonp_close_envelope( gui->http );
     827           0 : }
     828             : 
     829             : void
     830           0 : fd_gui_printf_completed_slot( fd_gui_t * gui ) {
     831           0 :   jsonp_open_envelope( gui->http, "summary", "completed_slot" );
     832           0 :     jsonp_ulong( gui->http, "value", fd_ulong_if( gui->summary.slot_tower!=ULONG_MAX, gui->summary.slot_tower, 0UL ) );
     833           0 :   jsonp_close_envelope( gui->http );
     834           0 : }
     835             : 
     836             : void
     837           0 : fd_gui_printf_estimated_slot( fd_gui_t * gui ) {
     838           0 :   jsonp_open_envelope( gui->http, "summary", "estimated_slot" );
     839           0 :     jsonp_ulong( gui->http, "value", fd_ulong_if( gui->summary.slot_estimated!=ULONG_MAX, gui->summary.slot_estimated, 0UL ) );
     840           0 :   jsonp_close_envelope( gui->http );
     841           0 : }
     842             : 
     843             : void
     844             : fd_gui_printf_skip_rate( fd_gui_t * gui,
     845           0 :                          ulong      epoch ) {
     846           0 :   fd_gui_epoch_t const * rec = fd_gui_epoch( gui, epoch );
     847           0 :   jsonp_open_envelope( gui->http, "summary", "skip_rate" );
     848           0 :     jsonp_open_object( gui->http, "value" );
     849           0 :       jsonp_ulong( gui->http, "epoch", FD_LIKELY( rec ) ? rec->epoch : 0UL );
     850           0 :       double skip_rate = ( FD_LIKELY( rec ) && rec->my_total_slots ) ? (double)rec->my_skipped_slots/(double)rec->my_total_slots : 0.0;
     851           0 :       fd_http_server_printf( gui->http, "\"skip_rate\":%.7f,", skip_rate );
     852           0 :     jsonp_close_object( gui->http );
     853           0 :   jsonp_close_envelope( gui->http );
     854           0 : }
     855             : 
     856             : void
     857             : fd_gui_printf_epoch( fd_gui_t * gui,
     858           0 :                      ulong      epoch ) {
     859           0 :   fd_gui_epoch_t const * meta = fd_gui_epoch( gui, epoch );
     860           0 :   jsonp_open_envelope( gui->http, "epoch", "new" );
     861           0 :     jsonp_open_object( gui->http, "value" );
     862           0 :       jsonp_ulong( gui->http, "epoch",                   FD_LIKELY( meta ) ? meta->epoch : 0UL );
     863           0 :       if( FD_LIKELY( meta && meta->start_time!=LONG_MAX ) ) jsonp_ulong_as_str( gui->http, "start_time_nanos", (ulong)meta->start_time );
     864           0 :       else                                                  jsonp_null( gui->http, "start_time_nanos" );
     865           0 :       if( FD_LIKELY( meta && meta->end_time!=LONG_MAX ) ) jsonp_ulong_as_str( gui->http, "end_time_nanos", (ulong)meta->end_time );
     866           0 :       else                                                jsonp_null( gui->http, "end_time_nanos" );
     867           0 :       jsonp_ulong( gui->http, "start_slot",              FD_LIKELY( meta ) ? meta->start_slot : 0UL );
     868           0 :       jsonp_ulong( gui->http, "end_slot",                FD_LIKELY( meta ) ? meta->start_slot+meta->slot_cnt-1UL : 0UL );
     869           0 :       jsonp_open_object( gui->http, "epoch_schedule" );
     870           0 :         jsonp_ulong( gui->http, "slots_per_epoch",    FD_LIKELY( meta ) ? meta->epoch_schedule.slots_per_epoch    : 0UL );
     871           0 :         jsonp_ulong( gui->http, "first_normal_epoch", FD_LIKELY( meta ) ? meta->epoch_schedule.first_normal_epoch : 0UL );
     872           0 :         jsonp_ulong( gui->http, "first_normal_slot",  FD_LIKELY( meta ) ? meta->epoch_schedule.first_normal_slot  : 0UL );
     873           0 :         jsonp_bool(  gui->http, "warmup",             FD_LIKELY( meta ) ? meta->epoch_schedule.warmup             : 0   );
     874           0 :       jsonp_close_object( gui->http );
     875           0 :       jsonp_ulong( gui->http, "target_slot_duration_nanos", FD_LIKELY( meta ) ? (ulong)meta->target_slot_duration_ns : LONG_MAX );
     876           0 :       jsonp_ulong_as_str( gui->http, "excluded_stake_lamports", 0UL );
     877           0 :       ulong pub_cnt    = FD_LIKELY( meta ) ? meta->pub_cnt : 0UL;
     878           0 :       ulong stakes_cnt = FD_LIKELY( meta ) ? meta->stakes_cnt : 0UL;
     879           0 :       ulong sched_cnt  = FD_LIKELY( meta ) ? (meta->slot_cnt+FD_EPOCH_SLOTS_PER_ROTATION-1UL)/FD_EPOCH_SLOTS_PER_ROTATION : 0UL;
     880           0 :       jsonp_open_array( gui->http, "staked_pubkeys" );
     881           0 :         for( ulong i=0UL; i<pub_cnt; i++ ) {
     882           0 :           char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
     883           0 :           fd_base58_encode_32( meta->pub[ i ].uc, NULL, identity_base58 );
     884           0 :           jsonp_string( gui->http, NULL, identity_base58 );
     885           0 :         }
     886           0 :       jsonp_close_array( gui->http );
     887             : 
     888           0 :       jsonp_open_array( gui->http, "staked_lamports" );
     889           0 :         for( ulong i=0UL; i<stakes_cnt; i++ ) jsonp_ulong_as_str( gui->http, NULL, meta->stakes[ i ].stake );
     890           0 :       jsonp_close_array( gui->http );
     891             : 
     892           0 :       jsonp_open_array( gui->http, "leader_slots" );
     893           0 :         for( ulong i=0UL; i<sched_cnt; i++ ) jsonp_ulong( gui->http, NULL, meta->sched[ i ] );
     894           0 :       jsonp_close_array( gui->http );
     895           0 :     jsonp_close_object( gui->http );
     896           0 :   jsonp_close_envelope( gui->http );
     897           0 : }
     898             : 
     899             : static void
     900             : fd_gui_printf_waterfall( fd_gui_t *               gui,
     901             :                          fd_gui_txn_waterfall_t const * prev,
     902           0 :                          fd_gui_txn_waterfall_t const * cur ) {
     903           0 :   jsonp_open_object( gui->http, "waterfall" );
     904           0 :     jsonp_open_object( gui->http, "in" );
     905           0 :       jsonp_ulong( gui->http, "pack_cranked",    cur->in.pack_cranked - prev->in.pack_cranked );
     906           0 :       jsonp_ulong( gui->http, "pack_retained",   prev->out.pack_retained );
     907           0 :       jsonp_ulong( gui->http, "resolv_retained", prev->out.resolv_retained );
     908           0 :       jsonp_ulong( gui->http, "quic",            cur->in.quic   - prev->in.quic );
     909           0 :       jsonp_ulong( gui->http, "udp",             cur->in.udp    - prev->in.udp );
     910           0 :       jsonp_ulong( gui->http, "gossip",          cur->in.gossip - prev->in.gossip );
     911           0 :       jsonp_ulong( gui->http, "block_engine",    cur->in.block_engine - prev->in.block_engine );
     912           0 :     jsonp_close_object( gui->http );
     913             : 
     914           0 :     jsonp_open_object( gui->http, "out" );
     915           0 :       jsonp_ulong( gui->http, "net_overrun",         cur->out.net_overrun         - prev->out.net_overrun );
     916           0 :       jsonp_ulong( gui->http, "quic_overrun",        cur->out.quic_overrun        - prev->out.quic_overrun );
     917           0 :       jsonp_ulong( gui->http, "quic_frag_drop",      cur->out.quic_frag_drop      - prev->out.quic_frag_drop );
     918           0 :       jsonp_ulong( gui->http, "quic_abandoned",      cur->out.quic_abandoned      - prev->out.quic_abandoned );
     919           0 :       jsonp_ulong( gui->http, "tpu_quic_invalid",    cur->out.tpu_quic_invalid    - prev->out.tpu_quic_invalid );
     920           0 :       jsonp_ulong( gui->http, "tpu_udp_invalid",     cur->out.tpu_udp_invalid     - prev->out.tpu_udp_invalid );
     921           0 :       jsonp_ulong( gui->http, "verify_overrun",      cur->out.verify_overrun      - prev->out.verify_overrun );
     922           0 :       jsonp_ulong( gui->http, "verify_parse",        cur->out.verify_parse        - prev->out.verify_parse );
     923           0 :       jsonp_ulong( gui->http, "verify_failed",       cur->out.verify_failed       - prev->out.verify_failed );
     924           0 :       jsonp_ulong( gui->http, "verify_duplicate",    cur->out.verify_duplicate    - prev->out.verify_duplicate );
     925           0 :       jsonp_ulong( gui->http, "dedup_duplicate",     cur->out.dedup_duplicate     - prev->out.dedup_duplicate );
     926           0 :       jsonp_ulong( gui->http, "resolv_lut_failed",   cur->out.resolv_lut_failed   - prev->out.resolv_lut_failed );
     927           0 :       jsonp_ulong( gui->http, "resolv_expired",      cur->out.resolv_expired      - prev->out.resolv_expired );
     928           0 :       jsonp_ulong( gui->http, "resolv_ancient",      cur->out.resolv_ancient      - prev->out.resolv_ancient );
     929           0 :       jsonp_ulong( gui->http, "resolv_no_ledger",    cur->out.resolv_no_ledger    - prev->out.resolv_no_ledger );
     930           0 :       jsonp_ulong( gui->http, "resolv_retained",     cur->out.resolv_retained );
     931           0 :       jsonp_ulong( gui->http, "pack_invalid",        cur->out.pack_invalid        - prev->out.pack_invalid );
     932           0 :       jsonp_ulong( gui->http, "pack_invalid_bundle", cur->out.pack_invalid_bundle - prev->out.pack_invalid_bundle );
     933           0 :       jsonp_ulong( gui->http, "pack_expired",        cur->out.pack_expired        - prev->out.pack_expired );
     934           0 :       jsonp_ulong( gui->http, "pack_already_executed", cur->out.pack_already_executed - prev->out.pack_already_executed );
     935           0 :       jsonp_ulong( gui->http, "pack_retained",       cur->out.pack_retained );
     936           0 :       jsonp_ulong( gui->http, "pack_wait_full",      0UL );
     937           0 :       jsonp_ulong( gui->http, "pack_leader_slow",    cur->out.pack_leader_slow    - prev->out.pack_leader_slow );
     938           0 :       jsonp_ulong( gui->http, "bank_invalid",        cur->out.bank_invalid        - prev->out.bank_invalid );
     939           0 :       jsonp_ulong( gui->http, "bank_nonce_already_advanced", cur->out.bank_nonce_already_advanced - prev->out.bank_nonce_already_advanced );
     940           0 :       jsonp_ulong( gui->http, "bank_nonce_advance_failed",   cur->out.bank_nonce_advance_failed   - prev->out.bank_nonce_advance_failed   );
     941           0 :       jsonp_ulong( gui->http, "bank_nonce_wrong_blockhash",  cur->out.bank_nonce_wrong_blockhash  - prev->out.bank_nonce_wrong_blockhash  );
     942           0 :       jsonp_ulong( gui->http, "block_success",       cur->out.block_success       - prev->out.block_success );
     943           0 :       jsonp_ulong( gui->http, "block_fail",          cur->out.block_fail          - prev->out.block_fail );
     944           0 :     jsonp_close_object( gui->http );
     945           0 :   jsonp_close_object( gui->http );
     946           0 : }
     947             : 
     948             : void
     949             : fd_gui_printf_live_txn_waterfall( fd_gui_t *                     gui,
     950             :                                   fd_gui_txn_waterfall_t const * prev,
     951             :                                   fd_gui_txn_waterfall_t const * cur,
     952           0 :                                   ulong                          next_leader_slot ) {
     953           0 :   jsonp_open_envelope( gui->http, "summary", "live_txn_waterfall" );
     954           0 :     jsonp_open_object( gui->http, "value" );
     955           0 :       jsonp_ulong( gui->http, "next_leader_slot", next_leader_slot );
     956           0 :       fd_gui_printf_waterfall( gui, prev, cur );
     957           0 :     jsonp_close_object( gui->http );
     958           0 :   jsonp_close_envelope( gui->http );
     959           0 : }
     960             : 
     961             : static void
     962             : fd_gui_printf_network_metrics( fd_gui_t *                     gui,
     963           0 :                                fd_gui_network_stats_t const * cur ) {
     964           0 :   jsonp_open_array( gui->http, "ingress" );
     965           0 :     jsonp_ulong( gui->http, NULL, cur->in.turbine );
     966           0 :     jsonp_ulong( gui->http, NULL, cur->in.gossip  );
     967           0 :     jsonp_ulong( gui->http, NULL, cur->in.tpu     );
     968           0 :     jsonp_ulong( gui->http, NULL, cur->in.repair  );
     969           0 :     jsonp_ulong( gui->http, NULL, cur->in.rserve  );
     970           0 :     jsonp_ulong( gui->http, NULL, cur->in.metric  );
     971           0 :     jsonp_ulong( gui->http, NULL, cur->in.votor   );
     972           0 :   jsonp_close_array( gui->http );
     973           0 :   jsonp_open_array( gui->http, "egress" );
     974           0 :     jsonp_ulong( gui->http, NULL, cur->out.turbine );
     975           0 :     jsonp_ulong( gui->http, NULL, cur->out.gossip  );
     976           0 :     jsonp_ulong( gui->http, NULL, cur->out.tpu     );
     977           0 :     jsonp_ulong( gui->http, NULL, cur->out.repair  );
     978           0 :     jsonp_ulong( gui->http, NULL, cur->out.rserve  );
     979           0 :     jsonp_ulong( gui->http, NULL, cur->out.metric  );
     980           0 :     jsonp_ulong( gui->http, NULL, cur->out.votor   );
     981           0 :   jsonp_close_array( gui->http );
     982           0 :   jsonp_open_array( gui->http, "ingress_ema" );
     983           0 :     for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) jsonp_double( gui->http, NULL, gui->summary.ingress_ema[ i ].value );
     984           0 :   jsonp_close_array( gui->http );
     985           0 :   jsonp_open_array( gui->http, "egress_ema" );
     986           0 :     for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) jsonp_double( gui->http, NULL, gui->summary.egress_ema[ i ].value );
     987           0 :   jsonp_close_array( gui->http );
     988           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 );
     989           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 );
     990           0 :   jsonp_ulong( gui->http, "ingress_max_5m", ingress_max_head ? (ulong)ingress_max_head->value : 0UL );
     991           0 :   jsonp_ulong( gui->http, "egress_max_5m",  egress_max_head  ? (ulong)egress_max_head->value  : 0UL );
     992           0 : }
     993             : 
     994             : void
     995             : fd_gui_printf_live_network_metrics( fd_gui_t *                     gui,
     996           0 :                                     fd_gui_network_stats_t const * cur ) {
     997           0 :   jsonp_open_envelope( gui->http, "summary", "live_network_metrics" );
     998           0 :     jsonp_open_object( gui->http, "value" );
     999           0 :       fd_gui_printf_network_metrics( gui, cur );
    1000           0 :     jsonp_close_object( gui->http );
    1001           0 :   jsonp_close_envelope( gui->http );
    1002           0 : }
    1003             : 
    1004             : static void
    1005             : fd_gui_printf_tile_stats( fd_gui_t *                  gui,
    1006             :                           fd_gui_tile_stats_t const * prev,
    1007           0 :                           fd_gui_tile_stats_t const * cur ) {
    1008           0 :   jsonp_open_object( gui->http, "tile_primary_metric" );
    1009           0 :     jsonp_ulong(  gui->http, "quic",    cur->quic_conn_cnt );
    1010           0 :     jsonp_double( gui->http, "bundle_rtt_smoothed_millis", (double)(cur->bundle_rtt_smoothed_nanos) / 1000000.0 );
    1011             : 
    1012           0 :     fd_histf_t bundle_rx_delay_hist_delta[ 1 ];
    1013           0 :     fd_histf_subtract( &cur->bundle_rx_delay_hist, &prev->bundle_rx_delay_hist, bundle_rx_delay_hist_delta );
    1014           0 :     ulong bundle_rx_delay_nanos_p90 = fd_histf_percentile( bundle_rx_delay_hist_delta, 90U, ULONG_MAX );
    1015           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 ));
    1016             : 
    1017           0 :     if( FD_LIKELY( cur->sample_time_nanos>prev->sample_time_nanos ) ) {
    1018           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) ));
    1019           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) ));
    1020           0 :     } else {
    1021           0 :       jsonp_ulong( gui->http, "net_in",  0 );
    1022           0 :       jsonp_ulong( gui->http, "net_out", 0 );
    1023           0 :     }
    1024           0 :     if( FD_LIKELY( cur->verify_total_cnt>prev->verify_total_cnt ) ) {
    1025           0 :       jsonp_double( gui->http, "verify", (double)(cur->verify_drop_cnt-prev->verify_drop_cnt) / (double)(cur->verify_total_cnt-prev->verify_total_cnt) );
    1026           0 :     } else {
    1027           0 :       jsonp_double( gui->http, "verify", 0.0 );
    1028           0 :     }
    1029           0 :     if( FD_LIKELY( cur->dedup_total_cnt>prev->dedup_total_cnt ) ) {
    1030           0 :       jsonp_double( gui->http, "dedup", (double)(cur->dedup_drop_cnt-prev->dedup_drop_cnt) / (double)(cur->dedup_total_cnt-prev->dedup_total_cnt) );
    1031           0 :     } else {
    1032           0 :       jsonp_double( gui->http, "dedup", 0.0 );
    1033           0 :     }
    1034           0 :     jsonp_ulong(  gui->http, "bank", cur->bank_txn_exec_cnt - prev->bank_txn_exec_cnt );
    1035           0 :     jsonp_double( gui->http, "pack", !cur->pack_buffer_capacity ? 1.0 : (double)cur->pack_buffer_cnt/(double)cur->pack_buffer_capacity );
    1036           0 :     jsonp_double( gui->http, "poh", 0.0 );
    1037           0 :     jsonp_double( gui->http, "shred", 0.0 );
    1038           0 :     jsonp_double( gui->http, "store", 0.0 );
    1039           0 :   jsonp_close_object( gui->http );
    1040           0 : }
    1041             : 
    1042             : void
    1043             : fd_gui_printf_live_tile_stats( fd_gui_t *                  gui,
    1044             :                                fd_gui_tile_stats_t const * prev,
    1045           0 :                                fd_gui_tile_stats_t const * cur ) {
    1046           0 :   jsonp_open_envelope( gui->http, "summary", "live_tile_primary_metric" );
    1047           0 :     jsonp_open_object( gui->http, "value" );
    1048           0 :       jsonp_ulong( gui->http, "next_leader_slot", 0UL );
    1049           0 :       fd_gui_printf_tile_stats( gui, prev, cur );
    1050           0 :     jsonp_close_object( gui->http );
    1051           0 :   jsonp_close_envelope( gui->http );
    1052           0 : }
    1053             : 
    1054             : static void
    1055             : fd_gui_printf_tile_timers( fd_gui_t *                        gui,
    1056           0 :                            fd_gui_tile_timers_hist_t const * packed ) {
    1057           0 :   for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1058           0 :     ulong t = gui->summary.tile[ i ];
    1059           0 :     fd_topo_tile_t const * tile = &gui->topo->tiles[ t ];
    1060             : 
    1061           0 :     if( FD_UNLIKELY( !strncmp( tile->name, "bench", 5UL ) ) ) {
    1062             :       /* bench tiles not reported */
    1063           0 :       continue;
    1064           0 :     }
    1065             : 
    1066           0 :     ushort ir = packed[ t ].idle_ratio;
    1067             :     /* -1 signals "no sample this window" (NaN has no JSON representation). */
    1068           0 :     double idle_ratio = ( ir==USHORT_MAX ) ? -1.0 : ( (double)ir / 10000.0 );
    1069           0 :     jsonp_double( gui->http, NULL, idle_ratio );
    1070           0 :   }
    1071           0 : }
    1072             : 
    1073             : static void
    1074             : fd_gui_printf_tile_metrics( fd_gui_t *                        gui,
    1075           0 :                             fd_gui_tile_timers_hist_t const * packed ) {
    1076           0 :   jsonp_open_array( gui->http, "timers" );
    1077           0 :   for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1078           0 :     ulong t = gui->summary.tile[ i ];
    1079           0 :     fd_topo_tile_t const * tile = &gui->topo->tiles[ t ];
    1080             : 
    1081           0 :     if( FD_UNLIKELY( !strncmp( tile->name, "bench", 5UL ) ) ) {
    1082             :       /* bench tiles not reported */
    1083           0 :       jsonp_null( gui->http, NULL );
    1084           0 :       continue;
    1085           0 :     }
    1086             : 
    1087           0 :     if( FD_UNLIKELY( packed[ t ].timers[ 0 ]==USHORT_MAX ) ) {
    1088           0 :       jsonp_null( gui->http, NULL );
    1089           0 :     } else {
    1090           0 :       jsonp_open_array( gui->http, NULL );
    1091           0 :         for( ulong j=0UL; j<FD_METRICS_ENUM_TILE_REGIME_CNT; j++ ) {
    1092           0 :           jsonp_centi( gui->http, NULL, packed[ t ].timers[ j ] );
    1093           0 :         }
    1094           0 :       jsonp_close_array( gui->http );
    1095           0 :     }
    1096           0 :   }
    1097           0 :   jsonp_close_array( gui->http );
    1098             : 
    1099           0 :   jsonp_open_array( gui->http, "sched_timers" );
    1100           0 :   for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1101           0 :     ulong t = gui->summary.tile[ i ];
    1102           0 :     fd_topo_tile_t const * tile = &gui->topo->tiles[ t ];
    1103             : 
    1104           0 :     if( FD_UNLIKELY( !strncmp( tile->name, "bench", 5UL ) ) ) {
    1105             :       /* bench tiles not reported */
    1106           0 :       jsonp_null( gui->http, NULL );
    1107           0 :       continue;
    1108           0 :     }
    1109             : 
    1110           0 :     if( FD_UNLIKELY( packed[ t ].sched_timers[ 0 ]==USHORT_MAX ) ) {
    1111           0 :       jsonp_null( gui->http, NULL );
    1112           0 :     } else {
    1113           0 :       jsonp_open_array( gui->http, NULL );
    1114           0 :         for( ulong j=0UL; j<FD_METRICS_ENUM_THREAD_REGIME_CNT; j++ ) {
    1115           0 :           jsonp_centi( gui->http, NULL, packed[ t ].sched_timers[ j ] );
    1116           0 :         }
    1117           0 :       jsonp_close_array( gui->http );
    1118           0 :     }
    1119           0 :   }
    1120           0 :   jsonp_close_array( gui->http );
    1121             : 
    1122           0 :   jsonp_open_array( gui->http, "in_backp" );
    1123           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1124           0 :       jsonp_bool( gui->http, NULL, packed[ gui->summary.tile[ i ] ].in_backp );
    1125           0 :     }
    1126           0 :   jsonp_close_array( gui->http );
    1127           0 :   jsonp_open_array( gui->http, "backp_msgs" );
    1128           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1129           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].backp_msgs );
    1130           0 :     }
    1131           0 :   jsonp_close_array( gui->http );
    1132           0 :   jsonp_open_array( gui->http, "alive" );
    1133           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1134           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].alive );
    1135           0 :     }
    1136           0 :   jsonp_close_array( gui->http );
    1137           0 :   jsonp_open_array( gui->http, "nvcsw" );
    1138           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1139           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].nvcsw );
    1140           0 :     }
    1141           0 :   jsonp_close_array( gui->http );
    1142           0 :   jsonp_open_array( gui->http, "nivcsw" );
    1143           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1144           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].nivcsw );
    1145           0 :     }
    1146           0 :   jsonp_close_array( gui->http );
    1147           0 :   jsonp_open_array( gui->http, "minflt" );
    1148           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1149           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].minflt );
    1150           0 :     }
    1151           0 :   jsonp_close_array( gui->http );
    1152           0 :   jsonp_open_array( gui->http, "majflt" );
    1153           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1154           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].majflt );
    1155           0 :     }
    1156           0 :   jsonp_close_array( gui->http );
    1157           0 :   jsonp_open_array( gui->http, "last_cpu" );
    1158           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1159           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].last_cpu );
    1160           0 :     }
    1161           0 :   jsonp_close_array( gui->http );
    1162           0 :   jsonp_open_array( gui->http, "interrupts" );
    1163           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1164           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].interrupts );
    1165           0 :     }
    1166           0 :   jsonp_close_array( gui->http );
    1167           0 :   jsonp_open_array( gui->http, "tlb_shootdowns" );
    1168           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1169           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].tlb_shootdowns );
    1170           0 :     }
    1171           0 :   jsonp_close_array( gui->http );
    1172           0 :   jsonp_open_array( gui->http, "timer_ticks" );
    1173           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1174           0 :       jsonp_ulong( gui->http, NULL, packed[ gui->summary.tile[ i ] ].timer_ticks );
    1175           0 :     }
    1176           0 :   jsonp_close_array( gui->http );
    1177           0 :   jsonp_open_array( gui->http, "priority" );
    1178           0 :     for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1179           0 :       fd_topo_tile_t const * tile = &gui->topo->tiles[ gui->summary.tile[ i ] ];
    1180           0 :       jsonp_string( gui->http, NULL, fd_gui_tile_priority_cstr( tile ) );
    1181           0 :     }
    1182           0 :   jsonp_close_array( gui->http );
    1183           0 : }
    1184             : 
    1185             : void
    1186           0 : fd_gui_printf_live_tile_timers( fd_gui_t * gui ) {
    1187           0 :   jsonp_open_envelope( gui->http, "summary", "live_tile_timers" );
    1188           0 :     jsonp_open_array( gui->http, "value" );
    1189           0 :       fd_gui_printf_tile_timers( gui, gui->summary.tile_timers_packed );
    1190           0 :     jsonp_close_array( gui->http );
    1191           0 :   jsonp_close_envelope( gui->http );
    1192           0 : }
    1193             : 
    1194             : void
    1195           0 : fd_gui_printf_live_tile_metrics( fd_gui_t * gui ) {
    1196           0 :   jsonp_open_envelope( gui->http, "summary", "live_tile_metrics" );
    1197           0 :       jsonp_open_object( gui->http, "value" );
    1198           0 :         fd_gui_printf_tile_metrics( gui, gui->summary.tile_timers_packed );
    1199           0 :       jsonp_close_object( gui->http );
    1200           0 :   jsonp_close_envelope( gui->http );
    1201           0 : }
    1202             : 
    1203             : void
    1204           0 : fd_gui_printf_estimated_tps( fd_gui_t * gui ) {
    1205           0 :   ulong idx = (gui->summary.estimated_tps_history_idx+FD_GUI_TPS_HISTORY_SAMPLE_CNT-1UL) % FD_GUI_TPS_HISTORY_SAMPLE_CNT;
    1206             : 
    1207           0 :   jsonp_open_envelope( gui->http, "summary", "estimated_tps" );
    1208           0 :     jsonp_open_object( gui->http, "value" );
    1209           0 :       ulong vote_cnt = gui->summary.estimated_tps_history[ idx ].vote_failed
    1210           0 :                     + gui->summary.estimated_tps_history[ idx ].vote_success;
    1211           0 :       ulong total_cnt = vote_cnt
    1212           0 :                       + gui->summary.estimated_tps_history[ idx ].nonvote_success
    1213           0 :                       + gui->summary.estimated_tps_history[ idx ].nonvote_failed;
    1214           0 :       if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
    1215           0 :         ulong success_cnt = gui->summary.estimated_tps_history[ idx ].nonvote_success
    1216           0 :                           + gui->summary.estimated_tps_history[ idx ].vote_success;
    1217           0 :         ulong failed_cnt  = gui->summary.estimated_tps_history[ idx ].nonvote_failed
    1218           0 :                           + gui->summary.estimated_tps_history[ idx ].vote_failed;
    1219           0 :         jsonp_double( gui->http, "success", (double)success_cnt/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
    1220           0 :         jsonp_double( gui->http, "failed",  (double)failed_cnt /(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
    1221           0 :       } else {
    1222           0 :       jsonp_double( gui->http, "total",           (double)total_cnt/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
    1223           0 :       jsonp_double( gui->http, "vote",            (double)vote_cnt/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
    1224           0 :       jsonp_double( gui->http, "nonvote_success", (double)gui->summary.estimated_tps_history[ idx ].nonvote_success/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
    1225           0 :       jsonp_double( gui->http, "nonvote_failed",  (double)gui->summary.estimated_tps_history[ idx ].nonvote_failed/(double)FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS );
    1226           0 :       }
    1227           0 :     jsonp_close_object( gui->http );
    1228           0 :   jsonp_close_envelope( gui->http );
    1229           0 : }
    1230             : 
    1231             : void
    1232           0 : fd_gui_printf_live_program_cache( fd_gui_t * gui ) {
    1233           0 :   fd_topo_t const * topo = gui->topo;
    1234             : 
    1235           0 :   ulong insertions      = 0UL;
    1236           0 :   ulong insertion_bytes = 0UL;
    1237           0 :   ulong evictions       = 0UL;
    1238           0 :   ulong eviction_bytes  = 0UL;
    1239           0 :   ulong spills          = 0UL;
    1240           0 :   ulong spill_bytes     = 0UL;
    1241             : 
    1242           0 :   for( ulong i=0UL; i<gui->summary.execrp_tile_cnt; i++ ) {
    1243           0 :     fd_topo_tile_t const * execrp = &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ];
    1244           0 :     volatile ulong const * metrics = fd_metrics_tile( execrp->metrics );
    1245             : 
    1246           0 :     insertions      += fd_metrics_enum_group_sum( metrics+MIDX( COUNTER, EXECRP, PROGCACHE_INSERTED ), FD_METRICS_ENUM_PROGCACHE_CLASS_G_ALL_MASK );
    1247           0 :     insertion_bytes += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_INSERTED_BYTES ) ];
    1248           0 :     evictions       += fd_metrics_enum_group_sum( metrics+MIDX( COUNTER, EXECRP, PROGCACHE_EVICTED  ), FD_METRICS_ENUM_PROGCACHE_CLASS_G_ALL_MASK );
    1249           0 :     eviction_bytes  += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_EVICTED_BYTES  ) ];
    1250           0 :     spills          += fd_metrics_enum_group_sum( metrics+MIDX( COUNTER, EXECRP, PROGCACHE_SPILLED  ), FD_METRICS_ENUM_PROGCACHE_CLASS_G_ALL_MASK );
    1251           0 :     spill_bytes     += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_SPILLED_BYTES  ) ];
    1252           0 :   }
    1253             : 
    1254           0 :   ulong free_bytes = 0UL;
    1255           0 :   ulong size_bytes = 0UL;
    1256           0 :   ulong replay_idx = fd_topo_find_tile( topo, "replay", 0UL );
    1257           0 :   if( FD_LIKELY( replay_idx!=ULONG_MAX ) ) {
    1258           0 :     volatile ulong const * m0 = fd_metrics_tile( topo->tiles[ replay_idx ].metrics );
    1259           0 :     for( ulong c=0UL; c<FD_PROGCACHE_CACHE_CLASS_CNT; c++ ) {
    1260           0 :       ulong mx = m0[ MIDX( GAUGE, REPLAY, PROGCACHE_CLASS_CAPACITY ) + c ];
    1261           0 :       ulong us = m0[ MIDX( GAUGE, REPLAY, PROGCACHE_CLASS_USED     ) + c ];
    1262           0 :       size_bytes +=  mx       * fd_progcache_cache_slot_sz[ c ];
    1263           0 :       free_bytes += (mx - us) * fd_progcache_cache_slot_sz[ c ];
    1264           0 :     }
    1265           0 :   }
    1266             : 
    1267           0 :   jsonp_open_envelope( gui->http, "summary", "live_program_cache" );
    1268           0 :     jsonp_open_object( gui->http, "value" );
    1269           0 :       jsonp_ulong( gui->http, "hits",            gui->summary.progcache_hits_1min    );
    1270           0 :       jsonp_ulong( gui->http, "lookups",         gui->summary.progcache_lookups_1min );
    1271           0 :       jsonp_ulong( gui->http, "insertions",      insertions      );
    1272           0 :       jsonp_ulong( gui->http, "insertion_bytes", insertion_bytes );
    1273           0 :       jsonp_ulong( gui->http, "evictions",       evictions       );
    1274           0 :       jsonp_ulong( gui->http, "eviction_bytes",  eviction_bytes  );
    1275           0 :       jsonp_ulong( gui->http, "spills",          spills          );
    1276           0 :       jsonp_ulong( gui->http, "spill_bytes",     spill_bytes     );
    1277           0 :       jsonp_ulong( gui->http, "free_bytes",      free_bytes      );
    1278           0 :       jsonp_ulong( gui->http, "size_bytes",      size_bytes      );
    1279           0 :     jsonp_close_object( gui->http );
    1280           0 :   jsonp_close_envelope( gui->http );
    1281           0 : }
    1282             : 
    1283             : static ulong
    1284             : fd_gui_tile_ordinal( fd_gui_t * gui,
    1285           0 :                      ulong      topo_tile_idx ) {
    1286           0 :   ulong ordinal = 0UL;
    1287           0 :   for( ulong i=0UL; i<gui->summary.tile_cnt; i++ ) {
    1288           0 :     ulong idx = gui->summary.tile[ i ];
    1289           0 :     if( FD_UNLIKELY( !strncmp( gui->topo->tiles[ idx ].name, "bench", 5UL ) ) ) continue;
    1290           0 :     if( FD_LIKELY( idx==topo_tile_idx ) ) return ordinal;
    1291           0 :     ordinal++;
    1292           0 :   }
    1293           0 :   return ULONG_MAX;
    1294           0 : }
    1295             : 
    1296             : static char const *
    1297           0 : fd_gui_system_file_category_cstr( uint category ) {
    1298           0 :   switch( category ) {
    1299           0 :     case FD_DIAG_SYSTEM_FILE_CATEGORY_ACCOUNTS:  return "accounts";
    1300           0 :     case FD_DIAG_SYSTEM_FILE_CATEGORY_SHREDS:    return "shreds";
    1301           0 :     case FD_DIAG_SYSTEM_FILE_CATEGORY_SNAPSHOTS: return "snapshots";
    1302           0 :     case FD_DIAG_SYSTEM_FILE_CATEGORY_GUI:       return "gui";
    1303           0 :     case FD_DIAG_SYSTEM_FILE_CATEGORY_LOGS:      return "logs";
    1304           0 :     default:                                     return "unknown";
    1305           0 :   }
    1306           0 : }
    1307             : 
    1308             : void
    1309           0 : fd_gui_printf_system_resources( fd_gui_t * gui ) {
    1310           0 :   fd_diag_system_resources_t const * system = &gui->system.resources;
    1311           0 :   jsonp_open_envelope( gui->http, "summary", "live_system_resources" );
    1312           0 :     jsonp_open_object( gui->http, "value" );
    1313           0 :       jsonp_open_array( gui->http, "cpus" );
    1314           0 :         for( ulong i=0UL; i<(ulong)system->cpu_cnt; i++ ) {
    1315           0 :           fd_diag_system_cpu_t const * cpu = &system->cpu[ i ];
    1316           0 :           jsonp_open_object( gui->http, NULL );
    1317           0 :             jsonp_bool(  gui->http, "online",    cpu->online   );
    1318           0 :             jsonp_ulong( gui->http, "numa_node", cpu->numa_idx );
    1319           0 :             if( FD_LIKELY( cpu->die_idx!=USHORT_MAX ) ) jsonp_ulong( gui->http, "die_idx", cpu->die_idx );
    1320           0 :             else                                        jsonp_null ( gui->http, "die_idx"               );
    1321           0 :             if( FD_LIKELY( cpu->sibling_idx!=USHORT_MAX ) ) jsonp_ulong( gui->http, "sibling_cpu", cpu->sibling_idx );
    1322           0 :             else                                            jsonp_null ( gui->http, "sibling_cpu"                  );
    1323           0 :             jsonp_open_array( gui->http, "tile_idxs" );
    1324           0 :               for( ulong j=0UL; j<gui->summary.tile_cnt; j++ ) {
    1325           0 :                 ulong topo_tile_idx = gui->summary.tile[ j ];
    1326           0 :                 fd_topo_tile_t const * tile = &gui->topo->tiles[ topo_tile_idx ];
    1327           0 :                 if( FD_LIKELY( tile->cpu_idx!=i || tile->floats ) ) continue;
    1328           0 :                 ulong ordinal = fd_gui_tile_ordinal( gui, topo_tile_idx );
    1329           0 :                 if( ordinal!=ULONG_MAX ) jsonp_ulong( gui->http, NULL, ordinal );
    1330           0 :               }
    1331           0 :             jsonp_close_array( gui->http );
    1332           0 :           jsonp_close_object( gui->http );
    1333           0 :         }
    1334           0 :       jsonp_close_array( gui->http );
    1335           0 :       jsonp_open_object( gui->http, "memory" );
    1336           0 :         jsonp_ulong( gui->http, "available_bytes", system->mem_available_bytes );
    1337           0 :         jsonp_ulong( gui->http, "free_bytes",      system->mem_free_bytes      );
    1338           0 :         jsonp_open_array( gui->http, "nodes" );
    1339           0 :           for( ulong i=0UL; i<(ulong)system->numa_mem_cnt; i++ ) {
    1340           0 :             fd_diag_system_numa_mem_t const * numa = &system->numa_mem[ i ];
    1341           0 :             jsonp_open_object( gui->http, NULL );
    1342           0 :               jsonp_ulong( gui->http, "node",         numa->numa_idx     );
    1343           0 :               jsonp_ulong( gui->http, "total_bytes",  numa->total_bytes  );
    1344           0 :               jsonp_ulong( gui->http, "free_bytes",   numa->free_bytes   );
    1345           0 :               jsonp_ulong( gui->http, "shared_bytes", numa->shared_bytes );
    1346           0 :               jsonp_open_array( gui->http, "tiles" );
    1347           0 :                 for( ulong j=0UL; j<(ulong)system->tile_mem_cnt; j++ ) {
    1348           0 :                   fd_diag_system_tile_mem_t const * tile = &system->tile_mem[ j ];
    1349           0 :                   ulong ordinal = fd_gui_tile_ordinal( gui, tile->tile_idx );
    1350           0 :                   if( tile->numa_idx!=numa->numa_idx || ordinal==ULONG_MAX ) continue;
    1351           0 :                   jsonp_open_object( gui->http, NULL );
    1352           0 :                     jsonp_ulong( gui->http, "tile_idx", ordinal               );
    1353           0 :                     jsonp_ulong( gui->http, "bytes",    tile->allocated_bytes );
    1354           0 :                   jsonp_close_object( gui->http );
    1355           0 :                 }
    1356           0 :               jsonp_close_array( gui->http );
    1357           0 :             jsonp_close_object( gui->http );
    1358           0 :           }
    1359           0 :         jsonp_close_array( gui->http );
    1360           0 :       jsonp_close_object( gui->http );
    1361           0 :       jsonp_open_array( gui->http, "disk" );
    1362           0 :         for( ulong i=0UL; i<(ulong)system->mount_cnt; i++ ) {
    1363           0 :           fd_diag_system_mount_t const * mount = &system->mount[ i ];
    1364           0 :           jsonp_open_object( gui->http, NULL );
    1365           0 :             jsonp_string( gui->http, "name",        mount->path );
    1366           0 :             jsonp_ulong(  gui->http, "total_bytes", mount->total_bytes );
    1367           0 :             jsonp_ulong(  gui->http, "used_bytes",  fd_ulong_sat_sub( mount->total_bytes, mount->free_bytes ) );
    1368           0 :             jsonp_open_array( gui->http, "files" );
    1369           0 :               for( ulong j=0UL; j<(ulong)system->file_cnt; j++ ) {
    1370           0 :                 fd_diag_system_file_t const * file = &system->file[ j ];
    1371           0 :                 if( file->mount_idx!=i ) continue;
    1372           0 :                 jsonp_open_object( gui->http, NULL );
    1373           0 :                   jsonp_string( gui->http, "path",     file->path );
    1374           0 :                   jsonp_string( gui->http, "category", fd_gui_system_file_category_cstr( file->category ) );
    1375           0 :                   jsonp_ulong(  gui->http, "bytes",    file->bytes );
    1376           0 :                 jsonp_close_object( gui->http );
    1377           0 :               }
    1378           0 :             jsonp_close_array( gui->http );
    1379           0 :           jsonp_close_object( gui->http );
    1380           0 :         }
    1381           0 :       jsonp_close_array( gui->http );
    1382           0 :     jsonp_close_object( gui->http );
    1383           0 :   jsonp_close_envelope( gui->http );
    1384           0 : }
    1385             : 
    1386             : void
    1387           0 : fd_gui_printf_health( fd_gui_t * gui ) {
    1388           0 :   fd_topo_t const * topo = gui->topo;
    1389             : 
    1390           0 :   ulong diag_tile_idx = fd_topo_find_tile( topo, "diag", 0UL );
    1391             : 
    1392             :   /* Default to disabled if no diag tile */
    1393           0 :   ulong bundle_status  = FD_DIAG_BUNDLE_STATUS_DISABLED;
    1394           0 :   ulong vote_status    = FD_DIAG_VOTE_STATUS_DISABLED;
    1395           0 :   ulong replay_status  = FD_DIAG_REPLAY_STATUS_DISABLED;
    1396           0 :   ulong turbine_status = FD_DIAG_TURBINE_STATUS_DISABLED;
    1397           0 :   ulong builder_status = FD_DIAG_BUILDER_STATUS_DISABLED;
    1398             : 
    1399           0 :   if( FD_LIKELY( diag_tile_idx!=ULONG_MAX ) ) {
    1400           0 :     volatile ulong const * metrics = fd_metrics_tile( topo->tiles[ diag_tile_idx ].metrics );
    1401           0 :     bundle_status  = metrics[ MIDX( GAUGE, DIAG, BUNDLE_STATE   ) ];
    1402           0 :     vote_status    = metrics[ MIDX( GAUGE, DIAG, VOTE_STATE     ) ];
    1403           0 :     replay_status  = metrics[ MIDX( GAUGE, DIAG, REPLAY_STATE   ) ];
    1404           0 :     turbine_status = metrics[ MIDX( GAUGE, DIAG, TURBINE_STATE  ) ];
    1405           0 :     builder_status = metrics[ MIDX( GAUGE, DIAG, BUILDER_STATE  ) ];
    1406           0 :   }
    1407             : 
    1408             :   /* Map bundle status to string */
    1409           0 :   char const * bundle_str;
    1410           0 :   switch( bundle_status ) {
    1411           0 :     case FD_DIAG_BUNDLE_STATUS_DISCONNECTED: bundle_str = "disconnected"; break;
    1412           0 :     case FD_DIAG_BUNDLE_STATUS_CONNECTING:   bundle_str = "connecting";   break;
    1413           0 :     case FD_DIAG_BUNDLE_STATUS_CONNECTED:    bundle_str = "connected";    break;
    1414           0 :     case FD_DIAG_BUNDLE_STATUS_SLEEPING:     bundle_str = "sleeping";     break;
    1415           0 :     default:                                 bundle_str = "disabled";     break;
    1416           0 :   }
    1417             : 
    1418             :   /* Map vote status to string */
    1419           0 :   char const * vote_str;
    1420           0 :   switch( vote_status ) {
    1421           0 :     case FD_DIAG_VOTE_STATUS_NOT_STARTED:  vote_str = "not_started"; break;
    1422           0 :     case FD_DIAG_VOTE_STATUS_DELINQUENT:   vote_str = "delinquent";  break;
    1423           0 :     case FD_DIAG_VOTE_STATUS_INADMISSIBLE: vote_str = "delinquent";  break; /* TODO: Update frontend, new recognized value */
    1424           0 :     case FD_DIAG_VOTE_STATUS_VOTING:       vote_str = "voting";      break;
    1425           0 :     default:                               vote_str = "disabled";    break;
    1426           0 :   }
    1427             : 
    1428             :   /* Map replay status to string */
    1429           0 :   char const * replay_str;
    1430           0 :   switch( replay_status ) {
    1431           0 :     case FD_DIAG_REPLAY_STATUS_NOT_STARTED: replay_str = "not_started"; break;
    1432           0 :     case FD_DIAG_REPLAY_STATUS_BEHIND:      replay_str = "behind";      break;
    1433           0 :     case FD_DIAG_REPLAY_STATUS_RUNNING:     replay_str = "running";     break;
    1434           0 :     default:                                replay_str = "disabled";    break;
    1435           0 :   }
    1436             : 
    1437             :   /* Map turbine status to string */
    1438           0 :   char const * turbine_str;
    1439           0 :   switch( turbine_status ) {
    1440           0 :     case FD_DIAG_TURBINE_STATUS_NOT_STARTED:      turbine_str = "not_started";      break;
    1441           0 :     case FD_DIAG_TURBINE_STATUS_STALLED:          turbine_str = "stalled";          break;
    1442           0 :     case FD_DIAG_TURBINE_STATUS_REPAIR_OUTPACING: turbine_str = "repair_outpacing"; break;
    1443           0 :     case FD_DIAG_TURBINE_STATUS_RUNNING:          turbine_str = "running";          break;
    1444           0 :     default:                                      turbine_str = "disabled";         break;
    1445           0 :   }
    1446             : 
    1447           0 :   char const * builder_str;
    1448           0 :   switch( builder_status ) {
    1449           0 :     case FD_DIAG_BUILDER_STATUS_DISCONNECTED: builder_str = "disconnected"; break;
    1450           0 :     case FD_DIAG_BUILDER_STATUS_CONNECTING:   builder_str = "connecting";   break;
    1451           0 :     case FD_DIAG_BUILDER_STATUS_UNHEALTHY:    builder_str = "unhealthy";    break;
    1452           0 :     case FD_DIAG_BUILDER_STATUS_CONNECTED:    builder_str = "connected";    break;
    1453           0 :     default:                                  builder_str = "disabled";     break;
    1454           0 :   }
    1455             : 
    1456           0 :   jsonp_open_envelope( gui->http, "summary", "health" );
    1457           0 :     jsonp_open_object( gui->http, "value" );
    1458           0 :       jsonp_string( gui->http, "vote",    vote_str    );
    1459           0 :       jsonp_string( gui->http, "bundle",  bundle_str  );
    1460           0 :       jsonp_string( gui->http, "replay",  replay_str  );
    1461           0 :       jsonp_string( gui->http, "turbine", turbine_str );
    1462           0 :       jsonp_string( gui->http, "builder", builder_str );
    1463           0 :     jsonp_close_object( gui->http );
    1464           0 :   jsonp_close_envelope( gui->http );
    1465           0 : }
    1466             : 
    1467             : /* Triangular-weighted average of a delta ring.  Newest sample has
    1468             :    weight n, oldest has weight 1.  Returns sum(w*delta) / weighted_dt
    1469             :    where weighted_dt is precomputed (sum of w * dt_sec for the same
    1470             :    samples). */
    1471             : static double
    1472             : fd_gui_accdb_weighted_rate( ulong const * ring,
    1473             :                             ulong         next_write_idx,
    1474             :                             ulong         n,
    1475           0 :                             double        weighted_dt ) {
    1476           0 :   if( !n || weighted_dt<=0.0 ) return 0.0;
    1477           0 :   double num = 0.0;
    1478           0 :   for( ulong k=0UL; k<n; k++ ) {
    1479           0 :     double w  = (double)(n - k);
    1480           0 :     ulong  ri = (next_write_idx + FD_GUI_ACCDB_WIN_SAMPLES - 1UL - k) % FD_GUI_ACCDB_WIN_SAMPLES;
    1481           0 :     num += w * (double)ring[ ri ];
    1482           0 :   }
    1483           0 :   return num / weighted_dt;
    1484           0 : }
    1485             : 
    1486             : static void
    1487             : fd_gui_sparkline_push( char *  text,
    1488             :                        ulong * len,
    1489             :                        double  rate,
    1490           0 :                        int     full ) {
    1491           0 :   ulong l = *len;
    1492           0 :   if( full ) {
    1493           0 :     char const * comma = memchr( text, ',', l );
    1494           0 :     ulong oldest = comma ? (ulong)(comma-text)+1UL : l;
    1495           0 :     memmove( text, text+oldest, l-oldest );
    1496           0 :     l -= oldest;
    1497           0 :   }
    1498           0 :   char ele[ 32 ];
    1499           0 :   ulong ele_len;
    1500           0 :   uchar * end = jsonp_put_fixed( (uchar *)ele, rate, 2UL );
    1501           0 :   if( FD_LIKELY( end ) ) { *end++ = ','; ele_len = (ulong)(end-(uchar *)ele); }
    1502           0 :   else FD_TEST( fd_cstr_printf_check( ele, sizeof(ele), &ele_len, "%.2f,", rate ) );
    1503           0 :   FD_TEST( ele_len<=FD_GUI_ACCDB_SPARKLINE_TEXT_MAX );
    1504           0 :   fd_memcpy( text+l, ele, ele_len );
    1505           0 :   *len = l+ele_len;
    1506           0 : }
    1507             : 
    1508             : void
    1509           0 : fd_gui_printf_accounts_stats( fd_gui_t * gui ) {
    1510           0 :   fd_gui_accounts_stats_t const * cur  = gui->summary.accounts_stats_current;
    1511           0 :   fd_gui_accounts_stats_t const * prev = gui->summary.accounts_stats_reference;
    1512           0 :   int have_ref = gui->summary.accounts_stats_have_reference;
    1513             : 
    1514           0 :   long  dt_nanos = have_ref ? (cur->sample_time_nanos - prev->sample_time_nanos) : 0L;
    1515             : 
    1516             :   /* Append this snap's deltas to the triangular-window rings.  The
    1517             :      emit code below applies triangular weights to compute the smoothed
    1518             :      rate.  Buffer is a simple ring; idx points to the next write slot. */
    1519           0 :   if( have_ref && dt_nanos>0L ) {
    1520           0 :     ulong i = gui->summary.accdb->accdb_win_idx;
    1521             : 
    1522           0 :     gui->summary.accdb->accdb_win_dt_nanos          [ i ] = dt_nanos;
    1523           0 :     gui->summary.accdb->agg_acquired_win            [ i ] = cur->acquired                 - prev->acquired                ;
    1524           0 :     gui->summary.accdb->agg_acquired_writable_win   [ i ] = cur->acquired_writable        - prev->acquired_writable       ;
    1525           0 :     gui->summary.accdb->agg_bytes_read_win          [ i ] = cur->bytes_read               - prev->bytes_read              ;
    1526           0 :     gui->summary.accdb->agg_bytes_copied_win        [ i ] = cur->bytes_copied             - prev->bytes_copied            ;
    1527           0 :     gui->summary.accdb->agg_bytes_written_win       [ i ] = cur->bytes_written            - prev->bytes_written           ;
    1528           0 :     gui->summary.accdb->agg_bytes_written_accdb_win [ i ] = cur->bytes_written_accdb      - prev->bytes_written_accdb     ;
    1529           0 :     gui->summary.accdb->agg_read_ops_win            [ i ] = cur->read_ops                 - prev->read_ops                ;
    1530           0 :     gui->summary.accdb->agg_write_ops_win           [ i ] = cur->write_ops                - prev->write_ops               ;
    1531           0 :     gui->summary.accdb->agg_relocated_bytes_win     [ i ] = cur->accounts_relocated_bytes - prev->accounts_relocated_bytes;
    1532             : 
    1533           0 :     ulong agg_misses_delta = 0UL;
    1534           0 :     for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {
    1535           0 :       ulong d = cur->not_found_per_class[ c ] - prev->not_found_per_class[ c ];
    1536           0 :       agg_misses_delta += d;
    1537           0 :       gui->summary.accdb->class_acq_win        [ c ][ i ] = cur->acquired_per_class            [ c ] - prev->acquired_per_class            [ c ];
    1538           0 :       gui->summary.accdb->class_acq_wr_win     [ c ][ i ] = cur->acquired_writable_per_class   [ c ] - prev->acquired_writable_per_class   [ c ];
    1539           0 :       gui->summary.accdb->class_not_found_win  [ c ][ i ] = d;
    1540           0 :       gui->summary.accdb->class_evicted_win    [ c ][ i ] = cur->evicted_per_class             [ c ] - prev->evicted_per_class             [ c ];
    1541           0 :       gui->summary.accdb->class_preevicted_win [ c ][ i ] = cur->preevicted_per_class          [ c ] - prev->preevicted_per_class          [ c ];
    1542           0 :       gui->summary.accdb->class_commit_new_win [ c ][ i ] = cur->committed_new_per_class       [ c ] - prev->committed_new_per_class       [ c ];
    1543           0 :       gui->summary.accdb->class_commit_over_win[ c ][ i ] = cur->committed_overwrite_per_class [ c ] - prev->committed_overwrite_per_class [ c ];
    1544           0 :     }
    1545           0 :     gui->summary.accdb->agg_misses_win[ i ] = agg_misses_delta;
    1546             : 
    1547             :     /* Per-partition deltas.  Diff against prev and push into ring. */
    1548           0 :     for( ulong p=0UL; p<gui->summary.accdb->partition_cnt; p++ ) {
    1549           0 :       fd_accdb_shmem_partition_info_t const * info = &gui->summary.accdb->partitions[ p ];
    1550             : 
    1551             :       /* Pool slots get reused: when a partition is released and
    1552             :          re-acquired, change_partition zeroes its counters.  Detect
    1553             :          the reset (any counter dropped below its previous value) and
    1554             :          treat this sample as the start of a new lifecycle — emit a
    1555             :          zero delta rather than letting the unsigned subtract wrap
    1556             :          into a giant rate. */
    1557           0 :       int reset = info->read_ops      < gui->summary.accdb->partition_prev_read_ops     [ p ] ||
    1558           0 :                   info->bytes_read    < gui->summary.accdb->partition_prev_bytes_read   [ p ] ||
    1559           0 :                   info->write_ops     < gui->summary.accdb->partition_prev_write_ops    [ p ] ||
    1560           0 :                   info->bytes_written < gui->summary.accdb->partition_prev_bytes_written[ p ];
    1561           0 :       if( FD_UNLIKELY( reset ) ) {
    1562           0 :         gui->summary.accdb->partition_prev_read_ops     [ p ] = info->read_ops;
    1563           0 :         gui->summary.accdb->partition_prev_bytes_read   [ p ] = info->bytes_read;
    1564           0 :         gui->summary.accdb->partition_prev_write_ops    [ p ] = info->write_ops;
    1565           0 :         gui->summary.accdb->partition_prev_bytes_written[ p ] = info->bytes_written;
    1566             :         /* Also wipe the historical window so an old lifecycle's
    1567             :            samples don't keep contributing to this slot's rate. */
    1568           0 :         for( ulong k=0UL; k<FD_GUI_ACCDB_WIN_SAMPLES; k++ ) {
    1569           0 :           gui->summary.accdb->partition_read_ops_win     [ p ][ k ] = 0UL;
    1570           0 :           gui->summary.accdb->partition_bytes_read_win   [ p ][ k ] = 0UL;
    1571           0 :           gui->summary.accdb->partition_write_ops_win    [ p ][ k ] = 0UL;
    1572           0 :           gui->summary.accdb->partition_bytes_written_win[ p ][ k ] = 0UL;
    1573           0 :         }
    1574           0 :       }
    1575           0 :       gui->summary.accdb->partition_read_ops_win     [ p ][ i ] = info->read_ops      - gui->summary.accdb->partition_prev_read_ops     [ p ];
    1576           0 :       gui->summary.accdb->partition_bytes_read_win   [ p ][ i ] = info->bytes_read    - gui->summary.accdb->partition_prev_bytes_read   [ p ];
    1577           0 :       gui->summary.accdb->partition_write_ops_win    [ p ][ i ] = info->write_ops     - gui->summary.accdb->partition_prev_write_ops    [ p ];
    1578           0 :       gui->summary.accdb->partition_bytes_written_win[ p ][ i ] = info->bytes_written - gui->summary.accdb->partition_prev_bytes_written[ p ];
    1579             : 
    1580           0 :       gui->summary.accdb->partition_prev_read_ops     [ p ] = info->read_ops;
    1581           0 :       gui->summary.accdb->partition_prev_bytes_read   [ p ] = info->bytes_read;
    1582           0 :       gui->summary.accdb->partition_prev_write_ops    [ p ] = info->write_ops;
    1583           0 :       gui->summary.accdb->partition_prev_bytes_written[ p ] = info->bytes_written;
    1584           0 :     }
    1585             : 
    1586             :     /* Per-tile deltas.  Cumulative values were snapped from each tile's
    1587             :        metric page in fd_gui_accounts_stats_snap; diff against prev and
    1588             :        push into the ring. */
    1589           0 :     for( ulong s=0UL; s<gui->summary.accdb->accdb_tile_cnt; s++ ) {
    1590           0 :       gui->summary.accdb->tile_acquired_win         [ s ][ i ] = gui->summary.accdb->tile_cur_acquired         [ s ] - gui->summary.accdb->tile_prev_acquired         [ s ];
    1591           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 ];
    1592           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 ];
    1593           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 ];
    1594           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 ];
    1595           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 ];
    1596           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 ];
    1597           0 :       gui->summary.accdb->tile_misses_win           [ s ][ i ] = gui->summary.accdb->tile_cur_misses           [ s ] - gui->summary.accdb->tile_prev_misses           [ s ];
    1598           0 :       gui->summary.accdb->tile_evicted_win          [ s ][ i ] = gui->summary.accdb->tile_cur_evicted          [ s ] - gui->summary.accdb->tile_prev_evicted          [ s ];
    1599           0 :       gui->summary.accdb->tile_committed_win        [ s ][ i ] = gui->summary.accdb->tile_cur_committed        [ s ] - gui->summary.accdb->tile_prev_committed        [ s ];
    1600           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 ];
    1601             : 
    1602           0 :       gui->summary.accdb->tile_prev_acquired         [ s ] = gui->summary.accdb->tile_cur_acquired         [ s ];
    1603           0 :       gui->summary.accdb->tile_prev_acquired_writable[ s ] = gui->summary.accdb->tile_cur_acquired_writable[ s ];
    1604           0 :       gui->summary.accdb->tile_prev_bytes_read       [ s ] = gui->summary.accdb->tile_cur_bytes_read       [ s ];
    1605           0 :       gui->summary.accdb->tile_prev_bytes_copied     [ s ] = gui->summary.accdb->tile_cur_bytes_copied     [ s ];
    1606           0 :       gui->summary.accdb->tile_prev_bytes_written    [ s ] = gui->summary.accdb->tile_cur_bytes_written    [ s ];
    1607           0 :       gui->summary.accdb->tile_prev_read_ops         [ s ] = gui->summary.accdb->tile_cur_read_ops         [ s ];
    1608           0 :       gui->summary.accdb->tile_prev_write_ops        [ s ] = gui->summary.accdb->tile_cur_write_ops        [ s ];
    1609           0 :       gui->summary.accdb->tile_prev_misses           [ s ] = gui->summary.accdb->tile_cur_misses           [ s ];
    1610           0 :       gui->summary.accdb->tile_prev_evicted          [ s ] = gui->summary.accdb->tile_cur_evicted          [ s ];
    1611           0 :       gui->summary.accdb->tile_prev_committed        [ s ] = gui->summary.accdb->tile_cur_committed        [ s ];
    1612           0 :       gui->summary.accdb->tile_prev_acquire_calls    [ s ] = gui->summary.accdb->tile_cur_acquire_calls    [ s ];
    1613             : 
    1614             :       /* 60s sparkline accumulator.  Sum this snap's delta into the
    1615             :          in-flight bucket; when the bucket closes (>=250ms since it
    1616             :          opened), append its per-second rate to the history text and
    1617             :          start a new bucket with the leftover delta. */
    1618           0 :       ulong d_acq    = gui->summary.accdb->tile_acquired_win         [ s ][ i ];
    1619           0 :       ulong d_acq_wr = gui->summary.accdb->tile_acquired_writable_win[ s ][ i ];
    1620           0 :       gui->summary.accdb->tile_sparkline_acq_bucket   [ s ] += d_acq;
    1621           0 :       gui->summary.accdb->tile_sparkline_acq_wr_bucket[ s ] += d_acq_wr;
    1622             : 
    1623           0 :       long bucket_age = cur->sample_time_nanos - gui->summary.accdb->tile_sparkline_bucket_start_nanos[ s ];
    1624           0 :       if( gui->summary.accdb->tile_sparkline_bucket_start_nanos[ s ]==0L ) {
    1625             :         /* First snap for this slot — just open a bucket. */
    1626           0 :         gui->summary.accdb->tile_sparkline_bucket_start_nanos[ s ] = cur->sample_time_nanos;
    1627           0 :       } else if( bucket_age>=FD_GUI_ACCDB_SPARKLINE_BUCKET_NS ) {
    1628             :         /* Close the bucket: normalize to per-second, drop the oldest
    1629             :            sample if full, push. */
    1630           0 :         double secs = (double)bucket_age / 1e9;
    1631           0 :         double acq_rate    = (double)gui->summary.accdb->tile_sparkline_acq_bucket   [ s ] / secs;
    1632           0 :         double acq_wr_rate = (double)gui->summary.accdb->tile_sparkline_acq_wr_bucket[ s ] / secs;
    1633           0 :         int full = gui->summary.accdb->tile_sparkline_count[ s ]==FD_GUI_ACCDB_SPARKLINE_SAMPLES;
    1634           0 :         fd_gui_sparkline_push( gui->summary.accdb->tile_sparkline_acq_text   [ s ], &gui->summary.accdb->tile_sparkline_acq_text_len   [ s ], acq_rate,    full );
    1635           0 :         fd_gui_sparkline_push( gui->summary.accdb->tile_sparkline_acq_wr_text[ s ], &gui->summary.accdb->tile_sparkline_acq_wr_text_len[ s ], acq_wr_rate, full );
    1636           0 :         if( !full ) gui->summary.accdb->tile_sparkline_count[ s ]++;
    1637           0 :         gui->summary.accdb->tile_sparkline_acq_bucket        [ s ] = 0UL;
    1638           0 :         gui->summary.accdb->tile_sparkline_acq_wr_bucket     [ s ] = 0UL;
    1639           0 :         gui->summary.accdb->tile_sparkline_bucket_start_nanos[ s ] = cur->sample_time_nanos;
    1640           0 :       }
    1641           0 :     }
    1642             : 
    1643           0 :     gui->summary.accdb->accdb_win_idx = (i+1UL) % FD_GUI_ACCDB_WIN_SAMPLES;
    1644           0 :     if( gui->summary.accdb->accdb_win_count<FD_GUI_ACCDB_WIN_SAMPLES )
    1645           0 :       gui->summary.accdb->accdb_win_count++;
    1646           0 :   }
    1647             : 
    1648             :   /* Compute weighted denominator once: sum(weight * dt_sec).  Newest
    1649             :      sample has weight n, oldest has weight 1.  If unfilled, only the
    1650             :      count samples are used (so first-snap rate is meaningful). */
    1651           0 :   ulong  n           = gui->summary.accdb->accdb_win_count;
    1652           0 :   double weighted_dt = 0.0;
    1653           0 :   for( ulong k=0UL; k<n; k++ ) {
    1654             :     /* k=0 is newest, k=n-1 is oldest; weight = n - k */
    1655           0 :     double w  = (double)(n - k);
    1656             :     /* idx-1-k in ring */
    1657           0 :     ulong  ri = (gui->summary.accdb->accdb_win_idx + FD_GUI_ACCDB_WIN_SAMPLES - 1UL - k) % FD_GUI_ACCDB_WIN_SAMPLES;
    1658           0 :     weighted_dt += w * (double)gui->summary.accdb->accdb_win_dt_nanos[ ri ] / 1e9;
    1659           0 :   }
    1660             : 
    1661             :   /* Helper: weighted rate of a delta ring. */
    1662           0 : # define WRATE( ring ) ( fd_gui_accdb_weighted_rate( (ring), gui->summary.accdb->accdb_win_idx, n, weighted_dt ) )
    1663             : 
    1664           0 :   double agg_acquired_rate          = WRATE( gui->summary.accdb->agg_acquired_win            );
    1665           0 :   double agg_acquired_writable_rate = WRATE( gui->summary.accdb->agg_acquired_writable_win   );
    1666           0 :   double agg_bytes_read_rate        = WRATE( gui->summary.accdb->agg_bytes_read_win          );
    1667           0 :   double agg_bytes_copied_rate      = WRATE( gui->summary.accdb->agg_bytes_copied_win        );
    1668           0 :   double agg_bytes_written_rate     = WRATE( gui->summary.accdb->agg_bytes_written_win       );
    1669           0 :   double agg_bytes_written_accdb_rate = WRATE( gui->summary.accdb->agg_bytes_written_accdb_win );
    1670           0 :   double agg_read_ops_rate          = WRATE( gui->summary.accdb->agg_read_ops_win            );
    1671           0 :   double agg_write_ops_rate         = WRATE( gui->summary.accdb->agg_write_ops_win           );
    1672           0 :   double agg_relocated_bytes_rate   = WRATE( gui->summary.accdb->agg_relocated_bytes_win     );
    1673           0 :   double agg_misses_rate            = WRATE( gui->summary.accdb->agg_misses_win              );
    1674             : 
    1675           0 :   double agg_hit_rate = agg_acquired_rate>0.0
    1676           0 :     ? fmax( 0.0, 1.0 - agg_misses_rate / agg_acquired_rate )
    1677           0 :     : 0.0;
    1678             : 
    1679             : 
    1680           0 :   jsonp_open_envelope( gui->http, "accounts", "stats" );
    1681           0 :     jsonp_open_object( gui->http, "value" );
    1682           0 :       jsonp_long( gui->http, "sample_time_nanos", cur->sample_time_nanos );
    1683             : 
    1684           0 :       jsonp_open_object( gui->http, "disk" );
    1685           0 :         jsonp_ulong(  gui->http, "accounts_total",       cur->accounts_total       );
    1686           0 :         jsonp_ulong(  gui->http, "accounts_capacity",    cur->accounts_capacity    );
    1687           0 :         jsonp_ulong(  gui->http, "allocated_bytes",      cur->disk_allocated_bytes );
    1688           0 :         jsonp_ulong(  gui->http, "current_bytes",        cur->disk_current_bytes   );
    1689           0 :         jsonp_ulong(  gui->http, "used_bytes",           cur->disk_used_bytes      );
    1690           0 :       jsonp_close_object( gui->http );
    1691             : 
    1692           0 :       jsonp_open_object( gui->http, "compaction" );
    1693           0 :         jsonp_ulong(  gui->http, "in_compaction",            cur->in_compaction            );
    1694           0 :         if( FD_LIKELY( gui->summary.accdb->next_compaction_partition_idx!=ULONG_MAX ) ) {
    1695           0 :           jsonp_double( gui->http, "next_compaction_remaining_seconds", gui->summary.accdb->next_compaction_remaining_secs );
    1696           0 :           jsonp_ulong(  gui->http, "next_compaction_partition_idx",     gui->summary.accdb->next_compaction_partition_idx  );
    1697           0 :         } else {
    1698           0 :           jsonp_null( gui->http, "next_compaction_remaining_seconds" );
    1699           0 :           jsonp_null( gui->http, "next_compaction_partition_idx"     );
    1700           0 :         }
    1701           0 :         jsonp_ulong(  gui->http, "compactions_requested",    cur->compactions_requested    );
    1702           0 :         jsonp_ulong(  gui->http, "compactions_completed",    cur->compactions_completed    );
    1703           0 :         jsonp_ulong(  gui->http, "accounts_relocated_bytes", cur->accounts_relocated_bytes );
    1704           0 :         jsonp_double( gui->http, "relocated_bytes_per_sec",  agg_relocated_bytes_rate );
    1705           0 :       jsonp_close_object( gui->http );
    1706             : 
    1707           0 :       ulong cache_size_bytes = 0UL;
    1708           0 :       ulong gui_tile_idx = fd_topo_find_tile( gui->topo, "gui", 0UL );
    1709           0 :       if( FD_LIKELY( gui_tile_idx!=ULONG_MAX ) ) {
    1710           0 :         cache_size_bytes = gui->topo->tiles[ gui_tile_idx ].gui.cache_size_gib * (1UL<<30);
    1711           0 :       }
    1712             : 
    1713           0 :       jsonp_open_object( gui->http, "cache" );
    1714           0 :         jsonp_double_4dp( gui->http, "hit_rate_ema", agg_hit_rate );
    1715           0 :         jsonp_ulong(  gui->http, "size_bytes",   cache_size_bytes );
    1716             : 
    1717           0 :         jsonp_open_array( gui->http, "classes" );
    1718           0 :           for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {
    1719           0 :             jsonp_open_object( gui->http, NULL );
    1720           0 :               jsonp_ulong(  gui->http, "class",                 c );
    1721           0 :               jsonp_ulong(  gui->http, "used_slots",            cur->cache_class_used           [ c ] );
    1722           0 :               jsonp_ulong(  gui->http, "max_slots",             cur->cache_class_max            [ c ] );
    1723           0 :               jsonp_ulong(  gui->http, "reserved_slots",        cur->cache_class_reserved       [ c ] );
    1724           0 :               jsonp_ulong(  gui->http, "target_used_slots",     cur->cache_class_target_used    [ c ] );
    1725           0 :               jsonp_ulong(  gui->http, "low_water_used_slots",  cur->cache_class_low_water_used [ c ] );
    1726           0 :               jsonp_ulong(  gui->http, "not_found",             cur->not_found_per_class           [ c ] );
    1727           0 :               jsonp_ulong(  gui->http, "evicted",               cur->evicted_per_class             [ c ] );
    1728           0 :               jsonp_ulong(  gui->http, "preevicted",            cur->preevicted_per_class          [ c ] );
    1729           0 :               jsonp_ulong(  gui->http, "committed_new",         cur->committed_new_per_class       [ c ] );
    1730           0 :               jsonp_ulong(  gui->http, "committed_overwrite",   cur->committed_overwrite_per_class [ c ] );
    1731           0 :               double acq_rate    = WRATE( gui->summary.accdb->class_acq_win        [ c ] );
    1732           0 :               double acq_wr_rate = WRATE( gui->summary.accdb->class_acq_wr_win     [ c ] );
    1733           0 :               double nf_rate     = WRATE( gui->summary.accdb->class_not_found_win  [ c ] );
    1734           0 :               jsonp_double( gui->http, "not_found_per_sec",           nf_rate                                                 );
    1735           0 :               jsonp_double( gui->http, "evicted_per_sec",             WRATE( gui->summary.accdb->class_evicted_win    [ c ] ) );
    1736           0 :               jsonp_double( gui->http, "preevicted_per_sec",          WRATE( gui->summary.accdb->class_preevicted_win [ c ] ) );
    1737           0 :               jsonp_double( gui->http, "committed_new_per_sec",       WRATE( gui->summary.accdb->class_commit_new_win [ c ] ) );
    1738           0 :               jsonp_double( gui->http, "committed_overwrite_per_sec", WRATE( gui->summary.accdb->class_commit_over_win[ c ] ) );
    1739             :               /* reads_per_sec = acquired - acquired_writable (per class);
    1740             :                  writes_per_sec = acquired_writable (per class). */
    1741           0 :               jsonp_double( gui->http, "reads_per_sec",  fmax( 0.0, acq_rate - acq_wr_rate ) );
    1742           0 :               jsonp_double( gui->http, "writes_per_sec", acq_wr_rate );
    1743           0 :               jsonp_double_4dp( gui->http, "hit_rate_ema", acq_rate>0.0 ? fmax( 0.0, 1.0 - nf_rate / acq_rate ) : 0.0 );
    1744           0 :             jsonp_close_object( gui->http );
    1745           0 :           }
    1746           0 :         jsonp_close_array( gui->http );
    1747           0 :       jsonp_close_object( gui->http );
    1748             : 
    1749             :       /* Per-tile breakdown.  Iterate the slot table built at init. */
    1750           0 :       jsonp_open_array( gui->http, "tiles" );
    1751           0 :         for( ulong s=0UL; s<gui->summary.accdb->accdb_tile_cnt; s++ ) {
    1752           0 :           ulong t_idx = (ulong)gui->summary.accdb->accdb_tile_topo_idx[ s ];
    1753           0 :           fd_topo_tile_t const * tile = &gui->topo->tiles[ t_idx ];
    1754           0 :           uchar kind = gui->summary.accdb->accdb_tile_kind[ s ];
    1755             : 
    1756           0 :           if( kind==FD_GUI_ACCDB_TILE_KIND_SNAPIN && gui->summary.accdb->tile_cur_status[ s ]==2U ) continue;
    1757             : 
    1758           0 :           double t_acq_rate    = WRATE( gui->summary.accdb->tile_acquired_win         [ s ] );
    1759           0 :           double t_acq_wr_rate = WRATE( gui->summary.accdb->tile_acquired_writable_win[ s ] );
    1760           0 :           double t_br_rate     = WRATE( gui->summary.accdb->tile_bytes_read_win       [ s ] );
    1761           0 :           double t_bc_rate     = WRATE( gui->summary.accdb->tile_bytes_copied_win     [ s ] );
    1762           0 :           double t_bw_rate     = WRATE( gui->summary.accdb->tile_bytes_written_win    [ s ] );
    1763           0 :           double t_ro_rate     = WRATE( gui->summary.accdb->tile_read_ops_win         [ s ] );
    1764           0 :           double t_wo_rate     = WRATE( gui->summary.accdb->tile_write_ops_win        [ s ] );
    1765           0 :           double t_nf_rate     = WRATE( gui->summary.accdb->tile_misses_win           [ s ] );
    1766           0 :           double t_ev_rate     = WRATE( gui->summary.accdb->tile_evicted_win          [ s ] );
    1767           0 :           double t_cm_rate     = WRATE( gui->summary.accdb->tile_committed_win        [ s ] );
    1768           0 :           double t_ac_rate     = WRATE( gui->summary.accdb->tile_acquire_calls_win    [ s ] );
    1769             : 
    1770           0 :           char const * joiner;
    1771           0 :           switch( kind ) {
    1772           0 :             case FD_GUI_ACCDB_TILE_KIND_RW:     joiner = "RW"; break;
    1773           0 :             case FD_GUI_ACCDB_TILE_KIND_SNAPIN: joiner = "RW"; break;
    1774           0 :             case FD_GUI_ACCDB_TILE_KIND_ACCDB:  joiner = "RW"; break;
    1775           0 :             default:                            joiner = "RO"; break;
    1776           0 :           }
    1777             : 
    1778           0 :           jsonp_open_object( gui->http, NULL );
    1779           0 :             jsonp_string( gui->http, "name",         tile->name );
    1780           0 :             jsonp_ulong(  gui->http, "kind_id",      tile->kind_id );
    1781           0 :             jsonp_string( gui->http, "joiner_type",  joiner );
    1782           0 :             jsonp_ulong(  gui->http, "status",       (ulong)gui->summary.accdb->tile_cur_status[ s ] );
    1783             : 
    1784             :             /* Lifetime totals. */
    1785           0 :             jsonp_ulong(  gui->http, "acquired",      gui->summary.accdb->tile_cur_acquired      [ s ] );
    1786           0 :             jsonp_ulong(  gui->http, "bytes_read",    gui->summary.accdb->tile_cur_bytes_read    [ s ] );
    1787           0 :             jsonp_ulong(  gui->http, "bytes_written", gui->summary.accdb->tile_cur_bytes_written [ s ] );
    1788             : 
    1789             :             /* Rates. */
    1790           0 :             jsonp_double( gui->http, "acquired_per_sec",          t_acq_rate    );
    1791           0 :             jsonp_double( gui->http, "acquired_writable_per_sec", t_acq_wr_rate );
    1792           0 :             jsonp_double( gui->http, "bytes_read_per_sec",        t_br_rate     );
    1793           0 :             jsonp_double( gui->http, "bytes_copied_per_sec",      t_bc_rate     );
    1794           0 :             jsonp_double( gui->http, "bytes_written_per_sec",     t_bw_rate     );
    1795           0 :             jsonp_double( gui->http, "read_ops_per_sec",          t_ro_rate     );
    1796           0 :             jsonp_double( gui->http, "write_ops_per_sec",         t_wo_rate     );
    1797           0 :             jsonp_double( gui->http, "not_found_per_sec",         t_nf_rate     );
    1798           0 :             jsonp_double( gui->http, "evicted_per_sec",           t_ev_rate     );
    1799           0 :             jsonp_double( gui->http, "committed_per_sec",         t_cm_rate     );
    1800           0 :             jsonp_double( gui->http, "acquire_calls_per_sec",     t_ac_rate     );
    1801             : 
    1802           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 );
    1803             : 
    1804             :             /* 60-second sparkline history, oldest first so the frontend
    1805             :                treats index 0 as the leftmost (oldest) sample.  The text
    1806             :                is kept formatted; copy it. */
    1807           0 :             jsonp_open_array( gui->http, "acquired_history" );
    1808           0 :               jsonp_text( gui->http, gui->summary.accdb->tile_sparkline_acq_text[ s ], gui->summary.accdb->tile_sparkline_acq_text_len[ s ] );
    1809           0 :             jsonp_close_array( gui->http );
    1810           0 :             jsonp_open_array( gui->http, "acquired_writable_history" );
    1811           0 :               jsonp_text( gui->http, gui->summary.accdb->tile_sparkline_acq_wr_text[ s ], gui->summary.accdb->tile_sparkline_acq_wr_text_len[ s ] );
    1812           0 :             jsonp_close_array( gui->http );
    1813           0 :           jsonp_close_object( gui->http );
    1814           0 :         }
    1815           0 :       jsonp_close_array( gui->http );
    1816             : 
    1817           0 :       jsonp_open_object( gui->http, "io" );
    1818           0 :         jsonp_ulong(  gui->http, "acquired",            cur->acquired            );
    1819           0 :         jsonp_ulong(  gui->http, "acquired_writable",   cur->acquired_writable   );
    1820           0 :         jsonp_ulong(  gui->http, "bytes_read",          cur->bytes_read          );
    1821           0 :         jsonp_ulong(  gui->http, "bytes_copied",        cur->bytes_copied        );
    1822           0 :         jsonp_ulong(  gui->http, "bytes_written",       cur->bytes_written       );
    1823           0 :         jsonp_ulong(  gui->http, "bytes_written_accdb", cur->bytes_written_accdb );
    1824           0 :         jsonp_ulong(  gui->http, "read_ops",            cur->read_ops            );
    1825           0 :         jsonp_ulong(  gui->http, "write_ops",           cur->write_ops           );
    1826           0 :         jsonp_double( gui->http, "acquired_per_sec",          agg_acquired_rate          );
    1827           0 :         jsonp_double( gui->http, "acquired_writable_per_sec", agg_acquired_writable_rate );
    1828           0 :         jsonp_double( gui->http, "bytes_read_per_sec",        agg_bytes_read_rate        );
    1829           0 :         jsonp_double( gui->http, "bytes_copied_per_sec",      agg_bytes_copied_rate      );
    1830           0 :         jsonp_double( gui->http, "bytes_written_per_sec",     agg_bytes_written_rate     );
    1831           0 :         jsonp_double( gui->http, "read_ops_per_sec",          agg_read_ops_rate          );
    1832           0 :         jsonp_double( gui->http, "write_ops_per_sec",         agg_write_ops_rate         );
    1833             :         /* Prewrite ratio: fraction of bytes written that came from the
    1834             :            accdb tile's background work (preevict + compaction).
    1835             :            cur->bytes_written already includes accdb tile's writes, so
    1836             :            the ratio is just accdb_rate / bytes_written_rate. */
    1837           0 :         jsonp_double( gui->http, "prewrite_ratio",
    1838           0 :                       agg_bytes_written_rate>0.0
    1839           0 :                         ? fmin( 1.0, agg_bytes_written_accdb_rate / agg_bytes_written_rate )
    1840           0 :                         : 0.0 );
    1841           0 :       jsonp_close_object( gui->http );
    1842             : 
    1843             :       /* Per-partition table.  Only emit partitions that have been
    1844             :          written to (skip the cold tail of the pool that has never been
    1845             :          allocated).  Ticks are converted to wallclock nanoseconds using
    1846             :          the GUI tile's locally-measured tick rate, since the accdb hot
    1847             :          path stamps fd_tickcount() rather than fd_log_wallclock() (no
    1848             :          syscall on the IO path). */
    1849           0 :       jsonp_open_array( gui->http, "partitions" );
    1850           0 :       if( FD_LIKELY( gui->accdb_shmem ) ) {
    1851           0 :         ulong  partition_sz = fd_accdb_shmem_partition_sz( gui->accdb_shmem );
    1852           0 :         long   now_ticks    = (long)fd_tickcount();
    1853           0 :         double tick_per_ns  = gui->tick_per_ns;
    1854           0 :         for( ulong p=0UL; p<gui->summary.accdb->partition_cnt; p++ ) {
    1855           0 :           fd_accdb_shmem_partition_info_t const * info = &gui->summary.accdb->partitions[ p ];
    1856             :           /* Skip partitions that have never been written and are not
    1857             :              currently in any compaction state. */
    1858           0 :           if( !info->bytes_written && !info->compaction_state ) continue;
    1859             : 
    1860           0 :           double read_ops_rate     = WRATE( gui->summary.accdb->partition_read_ops_win    [ p ] );
    1861           0 :           double bytes_read_rate   = WRATE( gui->summary.accdb->partition_bytes_read_win  [ p ] );
    1862           0 :           double write_ops_rate    = WRATE( gui->summary.accdb->partition_write_ops_win   [ p ] );
    1863           0 :           double bytes_written_rate= WRATE( gui->summary.accdb->partition_bytes_written_win[p ] );
    1864             : 
    1865           0 :           double age_seconds    = 0.0;
    1866           0 :           double filled_seconds = 0.0;
    1867           0 :           if( info->created_ticks && tick_per_ns>0.0 ) {
    1868           0 :             age_seconds    = ((double)(now_ticks - info->created_ticks)) / tick_per_ns / 1e9;
    1869           0 :             if( age_seconds<0.0 ) age_seconds = 0.0;
    1870           0 :           }
    1871           0 :           if( info->filled_ticks && tick_per_ns>0.0 ) {
    1872           0 :             filled_seconds = ((double)(now_ticks - info->filled_ticks )) / tick_per_ns / 1e9;
    1873           0 :             if( filled_seconds<0.0 ) filled_seconds = 0.0;
    1874           0 :           }
    1875             : 
    1876             :           /* Fully compacted, awaiting reclaim: present as an "Off" tier
    1877             :              with zeroed utilization so the row visually clears once its
    1878             :              data has been moved out. */
    1879           0 :           int    is_compacted   = info->compaction_state==0 &&
    1880           0 :                                   ( ( info->write_offset>0UL &&
    1881           0 :                                       info->compaction_offset>=info->write_offset ) ||
    1882           0 :                                     ( !info->write_offset && info->bytes_written>0UL ) );
    1883           0 :           ulong  tier           = is_compacted ? 255UL : (ulong)info->layer;
    1884           0 :           double utilization    = (!is_compacted && partition_sz)
    1885           0 :             ? (double)info->write_offset / (double)partition_sz : 0.0;
    1886           0 :           double fragmentation  = (!is_compacted && info->write_offset)
    1887           0 :             ? (double)info->bytes_freed / (double)info->write_offset : 0.0;
    1888           0 :           ulong  used_bytes     = (!is_compacted && info->write_offset > info->bytes_freed)
    1889           0 :             ? info->write_offset - info->bytes_freed : 0UL;
    1890           0 :           double used_frac      = partition_sz ? (double)used_bytes        / (double)partition_sz : 0.0;
    1891           0 :           double fragmented_frac= (!is_compacted && partition_sz) ? (double)info->bytes_freed / (double)partition_sz : 0.0;
    1892           0 :           double compaction_frac= (!is_compacted && partition_sz) ? (double)info->compaction_offset / (double)partition_sz : 0.0;
    1893             : 
    1894           0 :           jsonp_open_object( gui->http, NULL );
    1895           0 :             jsonp_ulong(  gui->http, "partition_idx",     p );
    1896           0 :             jsonp_ulong(  gui->http, "file_offset",       info->file_offset );
    1897           0 :             jsonp_ulong(  gui->http, "tier",              tier );
    1898           0 :             jsonp_ulong(  gui->http, "write_offset",      info->write_offset );
    1899           0 :             jsonp_ulong(  gui->http, "bytes_freed",       info->bytes_freed );
    1900           0 :             jsonp_ulong(  gui->http, "read_ops",          info->read_ops );
    1901           0 :             jsonp_ulong(  gui->http, "bytes_read",        info->bytes_read );
    1902           0 :             jsonp_ulong(  gui->http, "write_ops",         info->write_ops );
    1903           0 :             jsonp_ulong(  gui->http, "bytes_written",     info->bytes_written );
    1904           0 :             jsonp_double( gui->http, "read_ops_per_sec",     read_ops_rate );
    1905           0 :             jsonp_double( gui->http, "bytes_read_per_sec",   bytes_read_rate );
    1906           0 :             jsonp_double( gui->http, "write_ops_per_sec",    write_ops_rate );
    1907           0 :             jsonp_double( gui->http, "bytes_written_per_sec",bytes_written_rate );
    1908           0 :             jsonp_double( gui->http, "utilization",       utilization );
    1909           0 :             jsonp_double( gui->http, "fragmentation",     fragmentation );
    1910           0 :             jsonp_double( gui->http, "used_frac",         used_frac );
    1911           0 :             jsonp_double( gui->http, "fragmented_frac",   fragmented_frac );
    1912           0 :             jsonp_double( gui->http, "compaction_trigger_frac", (double)FD_ACCDB_COMPACTION_THRESHOLD_PCT/100.0 );
    1913           0 :             jsonp_double( gui->http, "age_seconds",       age_seconds );
    1914           0 :             jsonp_double( gui->http, "filled_seconds",    filled_seconds );
    1915           0 :             jsonp_ulong(  gui->http, "compaction_state",  (ulong)info->compaction_state );
    1916           0 :             jsonp_double( gui->http, "compaction_frac",   compaction_frac );
    1917           0 :             jsonp_bool(   gui->http, "is_write_head",    (int)info->is_write_head );
    1918           0 :           jsonp_close_object( gui->http );
    1919           0 :         }
    1920           0 :       }
    1921           0 :       jsonp_close_array( gui->http );
    1922             : 
    1923           0 :     jsonp_close_object( gui->http );
    1924           0 :   jsonp_close_envelope( gui->http );
    1925             : 
    1926           0 : # undef WRATE
    1927           0 : }
    1928             : 
    1929             : static void
    1930             : peers_printf_node( fd_gui_peers_ctx_t *  peers,
    1931           0 :                    ulong                 contact_info_table_idx ) {
    1932           0 :   fd_gui_peers_node_t * peer = &peers->contact_info_table[ contact_info_table_idx ];
    1933             : 
    1934           0 :   jsonp_open_object( peers->http, NULL );
    1935             : 
    1936           0 :     char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    1937           0 :     fd_base58_encode_32( peer->row.pubkey.uc, NULL, identity_base58 );
    1938           0 :     jsonp_string( peers->http, "identity_pubkey", identity_base58 );
    1939             : 
    1940           0 :     jsonp_open_object( peers->http, "gossip" );
    1941             : 
    1942           0 :       char version[ 64UL ];
    1943           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 ) ) );
    1944           0 :       jsonp_string( peers->http, "version", version );
    1945           0 :       jsonp_ulong( peers->http, "client_id", peer->row.contact_info.version.client );
    1946           0 :       jsonp_ulong( peers->http, "feature_set", peer->row.contact_info.version.feature_set );
    1947           0 :       jsonp_long( peers->http, "wallclock", peer->row.wallclock_nanos );
    1948           0 :       jsonp_ulong( peers->http, "shred_version", peer->row.contact_info.shred_version );
    1949           0 :       jsonp_open_object( peers->http, "sockets" );
    1950           0 :         for( ulong j=0UL; j<FD_GOSSIP_CONTACT_INFO_SOCKET_CNT; j++ ) {
    1951           0 :           char const * tag;
    1952           0 :           switch( j ) {
    1953           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP:            tag = "gossip";            break;
    1954           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_SERVE_REPAIR_QUIC: tag = "serve_repair_quic"; break;
    1955           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_RPC:               tag = "rpc";               break;
    1956           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_RPC_PUBSUB:        tag = "rpc_pubsub";        break;
    1957           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_SERVE_REPAIR:      tag = "serve_repair";      break;
    1958           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU:               tag = "tpu";               break;
    1959           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_FORWARDS:      tag = "tpu_forwards";      break;
    1960           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_FORWARDS_QUIC: tag = "tpu_forwards_quic"; break;
    1961           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_QUIC:          tag = "tpu_quic";          break;
    1962           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_VOTE:          tag = "tpu_vote";          break;
    1963           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TVU:               tag = "tvu";               break;
    1964           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TVU_QUIC:          tag = "tvu_quic";          break;
    1965           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_TPU_VOTE_QUIC:     tag = "tpu_vote_quic";     break;
    1966           0 :             case FD_GOSSIP_CONTACT_INFO_SOCKET_ALPENGLOW:         tag = "alpenglow";         break;
    1967           0 :             default:                                       tag = "unknown";           break;
    1968           0 :           }
    1969           0 :           uint   ip4  = peer->row.contact_info.sockets[ j ].is_ipv6 ? 0U : peer->row.contact_info.sockets[ j ].ip4;
    1970           0 :           ushort port = fd_ushort_bswap( peer->row.contact_info.sockets[ j ].port );
    1971           0 :           if( FD_LIKELY( !ip4 && !port ) ) continue;
    1972             : 
    1973           0 :           char line[ 64 ];
    1974           0 :           FD_TEST( fd_cstr_printf( line, sizeof( line ), NULL, FD_IP4_ADDR_FMT ":%hu", FD_IP4_ADDR_FMT_ARGS( ip4 ), port ) );
    1975           0 :           jsonp_string( peers->http, tag, line );
    1976           0 :         }
    1977           0 :       jsonp_close_object( peers->http );
    1978             : 
    1979           0 :       if( FD_LIKELY( peer->row.country_code_idx!=UCHAR_MAX ) ) {
    1980           0 :         jsonp_string( peers->http, "country_code", peers->dbip.country_code[ peer->row.country_code_idx ] );
    1981           0 :       } else {
    1982           0 :         jsonp_null( peers->http, "country_code" );
    1983           0 :       }
    1984             : 
    1985           0 :       if( FD_LIKELY( peer->row.city_name_idx!=UINT_MAX ) ) {
    1986           0 :         jsonp_string( peers->http, "city_name", peers->dbip.city_name[ peer->row.city_name_idx ] );
    1987           0 :       } else {
    1988           0 :         jsonp_null( peers->http, "city_name" );
    1989           0 :       }
    1990             : 
    1991           0 :     jsonp_close_object( peers->http );
    1992             : 
    1993           0 :     if( FD_LIKELY( !peer->row.has_vote_info ) ) {
    1994           0 :       jsonp_open_array( peers->http, "vote" );
    1995           0 :       jsonp_close_array( peers->http );
    1996           0 :     } else {
    1997           0 :       jsonp_open_array( peers->http, "vote" );
    1998           0 :         jsonp_open_object( peers->http, NULL );
    1999           0 :           char vote_account_base58[ FD_BASE58_ENCODED_32_SZ ];
    2000           0 :           fd_base58_encode_32( peer->row.vote_account.uc, NULL, vote_account_base58 );
    2001           0 :           jsonp_string( peers->http, "vote_account", vote_account_base58 );
    2002           0 :           jsonp_ulong_as_str( peers->http, "activated_stake", fd_ulong_if( peer->row.stake==ULONG_MAX, 0UL, peer->row.stake ) );
    2003           0 :           jsonp_ulong( peers->http, "last_vote", 0UL ); /* todo: deprecate */
    2004           0 :           jsonp_ulong( peers->http, "epoch_credits", 0UL ); /* todo: deprecate */
    2005           0 :           jsonp_ulong( peers->http, "commission", 0UL ); /* todo: deprecate */
    2006           0 :           jsonp_ulong( peers->http, "root_slot", 0UL ); /* todo: deprecate */
    2007           0 :           jsonp_bool( peers->http,  "delinquent", peer->row.delinquent );
    2008           0 :         jsonp_close_object( peers->http );
    2009           0 :       jsonp_close_array( peers->http );
    2010           0 :     }
    2011             : 
    2012           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 );
    2013           0 :     if( FD_UNLIKELY( !node_info || node_info->cleared ) ) {
    2014           0 :       jsonp_string( peers->http, "info", NULL );
    2015           0 :     } else {
    2016           0 :       jsonp_open_object( peers->http, "info" );
    2017           0 :         jsonp_string( peers->http, "name", node_info->name );
    2018           0 :         jsonp_string( peers->http, "details", node_info->details );
    2019           0 :         jsonp_string( peers->http, "website", node_info->website );
    2020           0 :         jsonp_string( peers->http, "icon_url", node_info->icon_uri );
    2021           0 :         jsonp_string( peers->http, "keybase_username", node_info->keybase_username );
    2022           0 :       jsonp_close_object( peers->http );
    2023           0 :     }
    2024             : 
    2025           0 :   jsonp_close_object( peers->http );
    2026           0 : }
    2027             : 
    2028             : void
    2029             : fd_gui_peers_printf_nodes( fd_gui_peers_ctx_t * peers,
    2030             :                            int *                actions,
    2031             :                            ulong *              idxs,
    2032           0 :                            ulong                count ) {
    2033           0 :   jsonp_open_envelope( peers->http, "peers", "update" );
    2034           0 :     jsonp_open_object( peers->http, "value" );
    2035           0 :       jsonp_open_array( peers->http, "add" );
    2036           0 :         for( ulong i=0UL; i<count; i++ ) if( FD_UNLIKELY( actions[ i ]==FD_GUI_PEERS_NODE_ADD ) ) peers_printf_node( peers, idxs[ i ] );
    2037           0 :       jsonp_close_array( peers->http );
    2038             : 
    2039           0 :       jsonp_open_array( peers->http, "update" );
    2040           0 :         for( ulong i=0UL; i<count; i++ ) if( FD_UNLIKELY( actions[ i ]==FD_GUI_PEERS_NODE_UPDATE ) ) peers_printf_node( peers, idxs[ i ] );
    2041           0 :       jsonp_close_array( peers->http );
    2042             : 
    2043           0 :       jsonp_open_array( peers->http, "remove" );
    2044           0 :         for( ulong i=0UL; i<count; i++ ) {
    2045           0 :           if( FD_UNLIKELY( actions[ i ]==FD_GUI_PEERS_NODE_DELETE ) ) {
    2046           0 :             jsonp_open_object( peers->http, NULL );
    2047           0 :               char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    2048           0 :               fd_base58_encode_32( peers->contact_info_table[ idxs[ i ] ].row.pubkey.uc, NULL, identity_base58 );
    2049           0 :               jsonp_string( peers->http, "identity_pubkey", identity_base58 );
    2050           0 :             jsonp_close_object( peers->http );
    2051           0 :           }
    2052           0 :         }
    2053           0 :       jsonp_close_array( peers->http );
    2054           0 :     jsonp_close_object( peers->http );
    2055           0 :   jsonp_close_envelope( peers->http );
    2056           0 : }
    2057             : 
    2058             : void
    2059           0 : fd_gui_peers_printf_node_all( fd_gui_peers_ctx_t *  peers ) {
    2060           0 :   jsonp_open_envelope( peers->http, "peers", "update" );
    2061           0 :     jsonp_open_object( peers->http, "value" );
    2062           0 :       jsonp_open_array( peers->http, "add" );
    2063           0 :         for( fd_gui_peers_node_pubkey_map_iter_t iter = fd_gui_peers_node_pubkey_map_iter_init( peers->node_pubkey_map, peers->contact_info_table );
    2064           0 :              !fd_gui_peers_node_pubkey_map_iter_done( iter, peers->node_pubkey_map, peers->contact_info_table );
    2065           0 :              iter = fd_gui_peers_node_pubkey_map_iter_next( iter, peers->node_pubkey_map, peers->contact_info_table ) ) {
    2066           0 :           fd_gui_peers_node_t const * node = fd_gui_peers_node_pubkey_map_iter_ele_const( iter, peers->node_pubkey_map, peers->contact_info_table );
    2067           0 :           peers_printf_node( peers, (ulong)(node-peers->contact_info_table) );
    2068           0 :         }
    2069           0 :       jsonp_close_array( peers->http );
    2070           0 :       jsonp_open_array( peers->http, "update" );
    2071           0 :       jsonp_close_array( peers->http );
    2072           0 :       jsonp_open_array( peers->http, "remove" );
    2073           0 :       jsonp_close_array( peers->http );
    2074           0 :     jsonp_close_object( peers->http );
    2075           0 :   jsonp_close_envelope( peers->http );
    2076           0 : }
    2077             : 
    2078             : static void
    2079             : fd_gui_printf_ts_tile_timers( fd_gui_t *                        gui,
    2080             :                               long                              sample_time_nanos,
    2081           0 :                               fd_gui_tile_timers_hist_t const * packed ) {
    2082           0 :   jsonp_open_object( gui->http, NULL );
    2083           0 :     jsonp_long_as_str( gui->http, "timestamp_nanos", sample_time_nanos );
    2084           0 :     jsonp_open_array( gui->http, "tile_timers" );
    2085           0 :       fd_gui_printf_tile_timers( gui, packed );
    2086           0 :     jsonp_close_array( gui->http );
    2087           0 :   jsonp_close_object( gui->http );
    2088           0 : }
    2089             : 
    2090             : static int
    2091             : fd_gui_load_leader_meta( fd_gui_t *                      gui,
    2092             :                          ulong                          _slot,
    2093           0 :                          fd_gui_leader_slot_t * out ) {
    2094           0 :   memset( out, 0, sizeof(*out) );
    2095           0 :   if( FD_UNLIKELY( !gui->db ) ) return 0;
    2096           0 :   fd_gui_leader_slot_t const * rec = fd_gui_hist_kv_get_slot_any( gui, FD_GUI_HIST_LEADER_SLOT, _slot );
    2097           0 :   if( FD_UNLIKELY( !rec ) ) return 0;
    2098           0 :   *out = *rec;
    2099           0 :   return 1;
    2100           0 : }
    2101             : 
    2102             : static int
    2103             : fd_gui_load_block_hash( fd_gui_t *  gui,
    2104             :                         ulong       _slot,
    2105           0 :                         fd_hash_t * out ) {
    2106           0 :   if( FD_UNLIKELY( !gui->db ) ) return 0;
    2107             : 
    2108           0 :   fd_gui_slot_t const * replay = fd_gui_hist_kv_get_slot_any( gui, FD_GUI_HIST_SLOT, _slot );
    2109           0 :   if( FD_LIKELY( replay ) ) {
    2110           0 :     *out = replay->block_hash;
    2111           0 :     return 1;
    2112           0 :   }
    2113             : 
    2114           0 :   fd_gui_leader_slot_t const * leader = fd_gui_hist_kv_get_slot_any( gui, FD_GUI_HIST_LEADER_SLOT, _slot );
    2115           0 :   if( FD_LIKELY( leader ) ) {
    2116           0 :     *out = leader->block_hash;
    2117           0 :     return 1;
    2118           0 :   }
    2119             : 
    2120           0 :   return 0;
    2121           0 : }
    2122             : 
    2123             : static long
    2124             : fd_gui_load_slot_duration( fd_gui_t *            gui,
    2125             :                            ulong                 _slot,
    2126           0 :                            fd_gui_slot_t const * slot ) {
    2127           0 :   if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) return LONG_MAX;
    2128             : 
    2129           0 :   long parent_completed_time = LONG_MAX;
    2130           0 :   fd_gui_slot_t * parent_slot = fd_gui_slot_get_canon( gui, slot->parent_slot );
    2131           0 :   if( FD_LIKELY( parent_slot ) ) {
    2132           0 :     parent_completed_time = parent_slot->completed_time;
    2133           0 :   } else if( FD_LIKELY( gui->db ) ) {
    2134           0 :     fd_gui_slot_t const * replay = fd_gui_hist_kv_get_slot_any( gui, FD_GUI_HIST_SLOT, _slot );
    2135           0 :     if( FD_LIKELY( replay ) ) parent_completed_time = replay->parent_completed_time;
    2136           0 :   }
    2137             : 
    2138           0 :   if( FD_UNLIKELY( parent_completed_time==LONG_MAX ) ) return LONG_MAX;
    2139           0 :   return slot->completed_time - parent_completed_time;
    2140           0 : }
    2141             : 
    2142             : static char const *
    2143             : fd_gui_slot_level_cstr( fd_gui_t const *      gui,
    2144             :                         ulong                 _slot,
    2145           0 :                         fd_gui_slot_t const * slot ) {
    2146           0 :   if( FD_LIKELY( !gui->summary.is_alpenglow ) ) {
    2147           0 :     switch( slot->level ) {
    2148           0 :       case FD_GUI_SLOT_LEVEL_INCOMPLETE:               return "incomplete";
    2149           0 :       case FD_GUI_SLOT_LEVEL_COMPLETED:                return "completed";
    2150           0 :       case FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED: return "optimistically_confirmed";
    2151           0 :       case FD_GUI_SLOT_LEVEL_ROOTED:                   return "rooted";
    2152           0 :       case FD_GUI_SLOT_LEVEL_FINALIZED:                return "finalized";
    2153           0 :       default:                                         return "unknown";
    2154           0 :     }
    2155           0 :   }
    2156             : 
    2157           0 :   if( FD_UNLIKELY( slot->skip==FD_GUI_SKIP_STATUS_FINALIZED && slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) return "skipped";
    2158           0 :   if( FD_UNLIKELY( slot->level<FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED && fd_gui_ag_slot_is_skip_notarized( gui, _slot ) ) ) return "skip_notarized";
    2159           0 :   if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) return "incomplete";
    2160             : 
    2161           0 :   switch( slot->level ) {
    2162           0 :     case FD_GUI_SLOT_LEVEL_INCOMPLETE:               return "incomplete";
    2163           0 :     case FD_GUI_SLOT_LEVEL_COMPLETED:                return "completed";
    2164           0 :     case FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED: return "notarized";
    2165           0 :     case FD_GUI_SLOT_LEVEL_ROOTED:
    2166           0 :     case FD_GUI_SLOT_LEVEL_FINALIZED:                return "rooted";
    2167           0 :     default:                                         return "unknown";
    2168           0 :   }
    2169           0 : }
    2170             : 
    2171             : static uchar
    2172             : fd_gui_resolve_slot_voter_state( fd_gui_t *            gui,
    2173             :                                  ulong                 _slot,
    2174           0 :                                  fd_gui_slot_t const * slot ) {
    2175           0 :   uchar state = slot->is_voter;
    2176           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
    2177           0 :     uchar epoch_state = fd_gui_slot_voter_state( gui, _slot );
    2178           0 :     if( FD_LIKELY( epoch_state!=FD_GUI_IS_VOTER_UNKNOWN ) ) state = epoch_state;
    2179           0 :   }
    2180           0 :   return state;
    2181           0 : }
    2182             : 
    2183             : static void
    2184             : fd_gui_printf_slot_is_voter( fd_gui_t *            gui,
    2185             :                              ulong                 _slot,
    2186           0 :                              fd_gui_slot_t const * slot ) {
    2187           0 :   uchar state = fd_gui_resolve_slot_voter_state( gui, _slot, slot );
    2188           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow && state==FD_GUI_IS_VOTER_UNKNOWN ) ) jsonp_null( gui->http, "is_voter" );
    2189           0 :   else                                                                             jsonp_bool( gui->http, "is_voter", state==FD_GUI_IS_VOTER_YES );
    2190           0 : }
    2191             : 
    2192             : static void
    2193             : fd_gui_printf_slot_proofs( fd_gui_t *            gui,
    2194           0 :                            fd_gui_slot_t const * slot ) {
    2195           0 :   if( FD_LIKELY( !gui->summary.is_alpenglow ) ) return;
    2196             : 
    2197           0 :   switch( slot->notarization_kind ) {
    2198           0 :     case FD_GUI_AG_NOTAR_REGULAR:  jsonp_string( gui->http, "notarization_kind", "regular"  ); break;
    2199           0 :     case FD_GUI_AG_NOTAR_FALLBACK: jsonp_string( gui->http, "notarization_kind", "fallback" ); break;
    2200           0 :     default:                       jsonp_null  ( gui->http, "notarization_kind" );             break;
    2201           0 :   }
    2202             : 
    2203           0 :   uchar final_kind = slot->finalization_kind;
    2204           0 :   if( FD_UNLIKELY( final_kind==FD_GUI_AG_FINAL_NONE && slot->skip==FD_GUI_SKIP_STATUS_FINALIZED && slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) final_kind = FD_GUI_AG_FINAL_IMPLICIT;
    2205             : 
    2206           0 :   switch( final_kind ) {
    2207           0 :     case FD_GUI_AG_FINAL_FAST:     jsonp_string( gui->http, "finalization_kind", "fast"     ); break;
    2208           0 :     case FD_GUI_AG_FINAL_SLOW:     jsonp_string( gui->http, "finalization_kind", "slow"     ); break;
    2209           0 :     case FD_GUI_AG_FINAL_IMPLICIT: jsonp_string( gui->http, "finalization_kind", "implicit" ); break;
    2210           0 :     default:                       jsonp_null  ( gui->http, "finalization_kind" );             break;
    2211           0 :   }
    2212             : 
    2213           0 :   uchar vote_rewarded       = slot->vote_rewarded;
    2214           0 :   uchar epoch_vote_rewarded = fd_gui_slot_vote_rewarded_state( gui, slot->slot );
    2215           0 :   if( FD_LIKELY( epoch_vote_rewarded!=FD_GUI_VOTE_REWARDED_UNKNOWN ) ) vote_rewarded = epoch_vote_rewarded;
    2216           0 :   if( FD_LIKELY( vote_rewarded==FD_GUI_VOTE_REWARDED_UNKNOWN ||
    2217           0 :                  fd_gui_resolve_slot_voter_state( gui, slot->slot, slot )!=FD_GUI_IS_VOTER_YES ) ) {
    2218           0 :     jsonp_null( gui->http, "vote_rewarded" );
    2219           0 :   } else {
    2220           0 :     jsonp_bool( gui->http, "vote_rewarded", vote_rewarded==FD_GUI_VOTE_REWARDED_YES );
    2221           0 :   }
    2222             : 
    2223           0 :   ushort vote_count = slot->vote_count;
    2224           0 :   ushort epoch_vote_count = fd_gui_slot_vote_count( gui, slot->slot );
    2225           0 :   if( FD_LIKELY( epoch_vote_count!=USHORT_MAX ) ) vote_count = epoch_vote_count;
    2226           0 :   if( FD_UNLIKELY( vote_count==USHORT_MAX ) ) jsonp_null ( gui->http, "vote_count" );
    2227           0 :   else                                        jsonp_ulong( gui->http, "vote_count", vote_count );
    2228           0 : }
    2229             : 
    2230             : static void
    2231             : fd_gui_printf_slot_txn_counts( fd_gui_t *            gui,
    2232           0 :                                fd_gui_slot_t const * slot ) {
    2233           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
    2234           0 :     if( FD_LIKELY( slot->nonvote_success!=UINT_MAX && slot->vote_success!=UINT_MAX ) ) jsonp_ulong( gui->http, "success_transaction_cnt", (ulong)slot->nonvote_success+(ulong)slot->vote_success );
    2235           0 :     else                                                                               jsonp_null ( gui->http, "success_transaction_cnt" );
    2236           0 :     if( FD_LIKELY( slot->nonvote_failed!=UINT_MAX && slot->vote_failed!=UINT_MAX ) ) jsonp_ulong( gui->http, "failed_transaction_cnt", (ulong)slot->nonvote_failed+(ulong)slot->vote_failed );
    2237           0 :     else                                                                             jsonp_null ( gui->http, "failed_transaction_cnt" );
    2238           0 :     return;
    2239           0 :   }
    2240             : 
    2241           0 :   if( FD_UNLIKELY( slot->nonvote_success==UINT_MAX ) ) jsonp_null ( gui->http, "success_nonvote_transaction_cnt" );
    2242           0 :   else                                                 jsonp_ulong( gui->http, "success_nonvote_transaction_cnt", slot->nonvote_success );
    2243           0 :   if( FD_UNLIKELY( slot->nonvote_failed==UINT_MAX ) ) jsonp_null ( gui->http, "failed_nonvote_transaction_cnt" );
    2244           0 :   else                                                jsonp_ulong( gui->http, "failed_nonvote_transaction_cnt", slot->nonvote_failed );
    2245           0 :   if( FD_UNLIKELY( slot->vote_success==UINT_MAX ) ) jsonp_null ( gui->http, "success_vote_transaction_cnt" );
    2246           0 :   else                                              jsonp_ulong( gui->http, "success_vote_transaction_cnt", slot->vote_success );
    2247           0 :   if( FD_UNLIKELY( slot->vote_failed==UINT_MAX ) ) jsonp_null ( gui->http, "failed_vote_transaction_cnt" );
    2248           0 :   else                                             jsonp_ulong( gui->http, "failed_vote_transaction_cnt", slot->vote_failed );
    2249           0 : }
    2250             : 
    2251             : static void
    2252             : fd_gui_printf_slot_skipped( fd_gui_t *            gui,
    2253           0 :                             fd_gui_slot_t const * slot ) {
    2254           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) return;
    2255           0 :   jsonp_bool( gui->http, "skipped", slot->skip==FD_GUI_SKIP_STATUS_FINALIZED );
    2256           0 : }
    2257             : 
    2258             : static void
    2259             : fd_gui_printf_slot_vote_latency( fd_gui_t *            gui,
    2260           0 :                                  fd_gui_slot_t const * slot ) {
    2261           0 :   if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) return;
    2262           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 );
    2263           0 :   else                                                                       jsonp_null ( gui->http, "vote_latency_exact" );
    2264           0 : }
    2265             : 
    2266             : 
    2267             : void
    2268             : fd_gui_printf_missed_vote_history( fd_gui_t * gui,
    2269           0 :                                    ulong      epoch ) {
    2270           0 :   jsonp_open_envelope( gui->http, "slot", "missed_vote_history" );
    2271           0 :     jsonp_open_object( gui->http, "value" );
    2272           0 :       jsonp_open_array( gui->http, "slot" );
    2273           0 :         fd_gui_epoch_t const * rec = fd_gui_epoch( gui, epoch );
    2274           0 :         ulong lo, hi;
    2275           0 :         if( FD_LIKELY( gui->summary.is_alpenglow && fd_gui_skipped_history_bounds( gui, rec, &lo, &hi ) ) ) {
    2276           0 :           ulong run_start = ULONG_MAX;
    2277           0 :           for( ulong i=lo; i<hi; i++ ) {
    2278           0 :             int missed = rec->vote_rewarded[ i ]==FD_GUI_VOTE_REWARDED_NO && rec->is_voter[ i ]==FD_GUI_IS_VOTER_YES;
    2279           0 :             if( FD_UNLIKELY( missed && run_start==ULONG_MAX ) ) run_start = rec->start_slot+i;
    2280           0 :             if( FD_UNLIKELY( !missed && run_start!=ULONG_MAX ) ) {
    2281           0 :               jsonp_ulong( gui->http, NULL, run_start );
    2282           0 :               jsonp_ulong( gui->http, NULL, rec->start_slot+i-1UL );
    2283           0 :               run_start = ULONG_MAX;
    2284           0 :             }
    2285           0 :           }
    2286           0 :           if( FD_UNLIKELY( run_start!=ULONG_MAX ) ) {
    2287           0 :             jsonp_ulong( gui->http, NULL, run_start );
    2288           0 :             jsonp_ulong( gui->http, NULL, rec->start_slot+hi-1UL );
    2289           0 :           }
    2290           0 :         }
    2291           0 :       jsonp_close_array( gui->http );
    2292           0 :     jsonp_close_object( gui->http );
    2293           0 :   jsonp_close_envelope( gui->http );
    2294           0 : }
    2295             : 
    2296             : void
    2297             : fd_gui_printf_slot( fd_gui_t *            gui,
    2298             :                     ulong                _slot,
    2299           0 :                     fd_gui_slot_t const * slot ) {
    2300           0 :   char const * level = fd_gui_slot_level_cstr( gui, _slot, slot );
    2301             : 
    2302           0 :   long duration_nanos = fd_gui_load_slot_duration( gui, _slot, slot );
    2303             : 
    2304           0 :   jsonp_open_envelope( gui->http, "slot", "update" );
    2305           0 :     jsonp_open_object( gui->http, "value" );
    2306           0 :       fd_gui_leader_slot_t lmeta[ 1 ];
    2307           0 :       int have_lmeta = fd_gui_load_leader_meta( gui, _slot, lmeta );
    2308           0 :       jsonp_open_object( gui->http, "publish" );
    2309           0 :         jsonp_ulong( gui->http, "slot", _slot );
    2310           0 :         jsonp_bool( gui->http, "mine", slot->mine );
    2311           0 :         if( FD_UNLIKELY( slot->vote_slot!=ULONG_MAX ) ) jsonp_ulong( gui->http, "vote_slot", slot->vote_slot );
    2312           0 :         else                                            jsonp_null( gui->http, "vote_slot" );
    2313           0 :         fd_gui_printf_slot_vote_latency( gui, slot );
    2314           0 :         fd_gui_printf_slot_is_voter( gui, _slot, slot );
    2315             : 
    2316           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  );
    2317           0 :         else                                                                  jsonp_null       ( gui->http, "start_timestamp_nanos" );
    2318           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  );
    2319           0 :         else                                                                jsonp_null       ( gui->http, "target_end_timestamp_nanos" );
    2320             : 
    2321           0 :         fd_gui_printf_slot_skipped( gui, slot );
    2322           0 :         if( FD_UNLIKELY( duration_nanos==LONG_MAX ) ) jsonp_null( gui->http, "duration_nanos" );
    2323           0 :         else                                          jsonp_long( gui->http, "duration_nanos", duration_nanos );
    2324           0 :         if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) jsonp_null( gui->http, "completed_time_nanos" );
    2325           0 :         else                                                jsonp_long_as_str( gui->http, "completed_time_nanos", slot->completed_time );
    2326           0 :         jsonp_string( gui->http, "level", level );
    2327           0 :         fd_gui_printf_slot_proofs( gui, slot );
    2328           0 :         fd_gui_printf_slot_txn_counts( gui, slot );
    2329           0 :         if( FD_UNLIKELY( slot->max_compute_units==UINT_MAX ) ) jsonp_null( gui->http, "max_compute_units" );
    2330           0 :         else                                                   jsonp_ulong( gui->http, "max_compute_units", slot->max_compute_units );
    2331           0 :         if( FD_UNLIKELY( slot->compute_units==UINT_MAX ) ) jsonp_null( gui->http, "compute_units" );
    2332           0 :         else                                               jsonp_ulong( gui->http, "compute_units", slot->compute_units );
    2333           0 :         if( FD_UNLIKELY( slot->shred_cnt==UINT_MAX ) ) jsonp_null( gui->http, "shreds" );
    2334           0 :         else                                           jsonp_ulong( gui->http, "shreds", slot->shred_cnt );
    2335           0 :         if( FD_UNLIKELY( slot->transaction_fee==ULONG_MAX ) ) jsonp_null( gui->http, "transaction_fee" );
    2336           0 :         else                                                  jsonp_ulong_as_str( gui->http, "transaction_fee", slot->transaction_fee );
    2337           0 :         if( FD_UNLIKELY( slot->priority_fee==ULONG_MAX ) ) jsonp_null( gui->http, "priority_fee" );
    2338           0 :         else                                               jsonp_ulong_as_str( gui->http, "priority_fee", slot->priority_fee );
    2339           0 :         if( FD_UNLIKELY( slot->tips==ULONG_MAX ) ) jsonp_null( gui->http, "tips" );
    2340           0 :         else                                       jsonp_ulong_as_str( gui->http, "tips", slot->tips );
    2341           0 :       jsonp_close_object( gui->http );
    2342           0 :     jsonp_close_object( gui->http );
    2343           0 :   jsonp_close_envelope( gui->http );
    2344           0 : }
    2345             : 
    2346             : void
    2347             : fd_gui_printf_summary_ping( fd_gui_t * gui,
    2348           0 :                             ulong      id ) {
    2349           0 :   jsonp_open_envelope( gui->http, "summary", "ping" );
    2350           0 :     jsonp_ulong( gui->http, "id", id );
    2351           0 :     jsonp_null( gui->http, "value" );
    2352           0 :   jsonp_close_envelope( gui->http );
    2353           0 : }
    2354             : 
    2355             : void
    2356             : fd_gui_printf_slot_rankings_request( fd_gui_t * gui,
    2357             :                                      ulong      id,
    2358           0 :                                      int        mine ) {
    2359           0 :   fd_gui_epoch_t * rec = fd_gui_current_epoch( gui );
    2360             : 
    2361           0 :   fd_gui_slot_rankings_t * rankings = FD_LIKELY( rec )
    2362           0 :     ? fd_ptr_if( mine, (fd_gui_slot_rankings_t *)rec->my_rankings, (fd_gui_slot_rankings_t *)rec->rankings )
    2363           0 :     : NULL;
    2364             : 
    2365           0 :   jsonp_open_envelope( gui->http, "slot", "query_rankings" );
    2366           0 :     jsonp_ulong( gui->http, "id", id );
    2367           0 :     jsonp_open_object( gui->http, "value" );
    2368             : 
    2369           0 : #define OUTPUT_RANKING_ARRAY(field) \
    2370           0 :       jsonp_open_array( gui->http, "slots_" FD_STRINGIFY(field) ); \
    2371           0 :       for( ulong i = 0UL; i<fd_ulong_if( rankings==NULL, 0UL, FD_GUI_SLOT_RANKINGS_SZ ); i++ ) { \
    2372           0 :         if( FD_UNLIKELY( rankings->field[ i ].slot==ULONG_MAX ) ) break; \
    2373           0 :         jsonp_ulong( gui->http, NULL, rankings->field[ i ].slot ); \
    2374           0 :       } \
    2375           0 :       jsonp_close_array( gui->http ); \
    2376           0 :       jsonp_open_array( gui->http, "vals_" FD_STRINGIFY(field) ); \
    2377           0 :       for( ulong i = 0UL; i<fd_ulong_if( rankings==NULL, 0UL, FD_GUI_SLOT_RANKINGS_SZ ); i++ ) { \
    2378           0 :         if( FD_UNLIKELY( rankings->field[ i ].slot==ULONG_MAX ) ) break; \
    2379           0 :         jsonp_ulong( gui->http, NULL, rankings->field[ i ].value ); \
    2380           0 :       } \
    2381           0 :       jsonp_close_array( gui->http )
    2382             : 
    2383           0 :       OUTPUT_RANKING_ARRAY( largest_tips );
    2384           0 :       OUTPUT_RANKING_ARRAY( largest_fees );
    2385           0 :       OUTPUT_RANKING_ARRAY( largest_rewards );
    2386           0 :       OUTPUT_RANKING_ARRAY( largest_rewards_per_cu );
    2387           0 :       OUTPUT_RANKING_ARRAY( largest_duration );
    2388           0 :       OUTPUT_RANKING_ARRAY( largest_compute_units );
    2389           0 :       OUTPUT_RANKING_ARRAY( largest_skipped );
    2390           0 :       OUTPUT_RANKING_ARRAY( smallest_tips );
    2391           0 :       OUTPUT_RANKING_ARRAY( smallest_fees );
    2392           0 :       OUTPUT_RANKING_ARRAY( smallest_rewards );
    2393           0 :       OUTPUT_RANKING_ARRAY( smallest_rewards_per_cu );
    2394           0 :       OUTPUT_RANKING_ARRAY( smallest_duration );
    2395           0 :       OUTPUT_RANKING_ARRAY( smallest_compute_units );
    2396           0 :       OUTPUT_RANKING_ARRAY( smallest_skipped );
    2397             : 
    2398           0 : #undef OUTPUT_RANKING_ARRAY
    2399             : 
    2400           0 :     jsonp_close_object( gui->http );
    2401           0 :   jsonp_close_envelope( gui->http );
    2402           0 : }
    2403             : 
    2404             : void
    2405             : fd_gui_printf_slot_request( fd_gui_t *            gui,
    2406             :                             ulong                _slot,
    2407             :                             ulong                id,
    2408           0 :                             fd_gui_slot_t const * slot ) {
    2409           0 :   char const * level = fd_gui_slot_level_cstr( gui, _slot, slot );
    2410             : 
    2411           0 :   long duration_nanos = fd_gui_load_slot_duration( gui, _slot, slot );
    2412             : 
    2413           0 :   jsonp_open_envelope( gui->http, "slot", "query" );
    2414           0 :     jsonp_ulong( gui->http, "id", id );
    2415           0 :     jsonp_open_object( gui->http, "value" );
    2416           0 :       fd_gui_leader_slot_t lmeta[ 1 ];
    2417           0 :       int have_lmeta = fd_gui_load_leader_meta( gui, _slot, lmeta );
    2418             : 
    2419           0 :       jsonp_open_object( gui->http, "publish" );
    2420           0 :         jsonp_ulong( gui->http, "slot", _slot );
    2421           0 :         jsonp_bool( gui->http, "mine", slot->mine );
    2422           0 :         if( FD_UNLIKELY( slot->vote_slot!=ULONG_MAX ) ) jsonp_ulong( gui->http, "vote_slot", slot->vote_slot );
    2423           0 :         else                                            jsonp_null( gui->http, "vote_slot" );
    2424           0 :         fd_gui_printf_slot_vote_latency( gui, slot );
    2425           0 :         fd_gui_printf_slot_is_voter( gui, _slot, slot );
    2426             : 
    2427           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  );
    2428           0 :         else                                                                  jsonp_null       ( gui->http, "start_timestamp_nanos" );
    2429           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  );
    2430           0 :         else                                                                jsonp_null       ( gui->http, "target_end_timestamp_nanos" );
    2431             : 
    2432           0 :         fd_gui_printf_slot_skipped( gui, slot );
    2433           0 :         jsonp_string( gui->http, "level", level );
    2434           0 :         fd_gui_printf_slot_proofs( gui, slot );
    2435           0 :         if( FD_UNLIKELY( duration_nanos==LONG_MAX ) ) jsonp_null( gui->http, "duration_nanos" );
    2436           0 :         else                                          jsonp_long( gui->http, "duration_nanos", duration_nanos );
    2437           0 :         if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) jsonp_null( gui->http, "completed_time_nanos" );
    2438           0 :         else                                                jsonp_long_as_str( gui->http, "completed_time_nanos", slot->completed_time );
    2439           0 :         fd_gui_printf_slot_txn_counts( gui, slot );
    2440           0 :         if( FD_UNLIKELY( slot->max_compute_units==UINT_MAX ) ) jsonp_null( gui->http, "max_compute_units" );
    2441           0 :         else                                                   jsonp_ulong( gui->http, "max_compute_units", slot->max_compute_units );
    2442           0 :         if( FD_UNLIKELY( slot->compute_units==UINT_MAX ) ) jsonp_null( gui->http, "compute_units" );
    2443           0 :         else                                               jsonp_ulong( gui->http, "compute_units", slot->compute_units );
    2444           0 :         if( FD_UNLIKELY( slot->shred_cnt==UINT_MAX ) ) jsonp_null( gui->http, "shreds" );
    2445           0 :         else                                           jsonp_ulong( gui->http, "shreds", slot->shred_cnt );
    2446           0 :         if( FD_UNLIKELY( slot->transaction_fee==ULONG_MAX ) ) jsonp_null( gui->http, "transaction_fee" );
    2447           0 :         else                                                  jsonp_ulong_as_str( gui->http, "transaction_fee", slot->transaction_fee );
    2448           0 :         if( FD_UNLIKELY( slot->priority_fee==ULONG_MAX ) ) jsonp_null( gui->http, "priority_fee" );
    2449           0 :         else                                               jsonp_ulong_as_str( gui->http, "priority_fee", slot->priority_fee );
    2450           0 :         if( FD_UNLIKELY( slot->tips==ULONG_MAX ) ) jsonp_null( gui->http, "tips" );
    2451           0 :         else                                       jsonp_ulong_as_str( gui->http, "tips", slot->tips );
    2452           0 :       jsonp_close_object( gui->http );
    2453             : 
    2454           0 :     jsonp_close_object( gui->http );
    2455           0 :   jsonp_close_envelope( gui->http );
    2456           0 : }
    2457             : 
    2458             : #define SORT_NAME fd_gui_slot_txn_start_sort
    2459           0 : #define SORT_KEY_T fd_gui_store_txn_start_t
    2460           0 : #define SORT_BEFORE(a,b) ( (a).txn_idx<(b).txn_idx )
    2461             : #include "../../util/tmpl/fd_sort.c"
    2462             : 
    2463             : #define SORT_NAME fd_gui_slot_txn_end_sort
    2464           0 : #define SORT_KEY_T fd_gui_store_txn_end_t
    2465           0 : #define SORT_BEFORE(a,b) ( (a).txn_idx<(b).txn_idx )
    2466             : #include "../../util/tmpl/fd_sort.c"
    2467             : 
    2468             : void
    2469             : fd_gui_printf_slot_transactions_request( fd_gui_t *            gui,
    2470             :                                          ulong                _slot,
    2471             :                                          ulong                id,
    2472           0 :                                          fd_gui_slot_t const * slot ) {
    2473           0 :   char const * level = fd_gui_slot_level_cstr( gui, _slot, slot );
    2474             : 
    2475           0 :   long duration_nanos = fd_gui_load_slot_duration( gui, _slot, slot );
    2476             : 
    2477           0 :   jsonp_open_envelope( gui->http, "slot", "query_transactions" );
    2478           0 :     jsonp_ulong( gui->http, "id", id );
    2479           0 :     jsonp_open_object( gui->http, "value" );
    2480           0 :       fd_gui_leader_slot_t const * lmeta = slot->bank_seq==ULONG_MAX ? fd_gui_slot_leader_get_any( gui, _slot ) : fd_gui_slot_leader_get( gui, _slot, slot->bank_seq );
    2481           0 :       int have_lmeta = !!lmeta;
    2482             : 
    2483           0 :       jsonp_open_object( gui->http, "publish" );
    2484           0 :         jsonp_ulong( gui->http, "slot", _slot );
    2485           0 :         jsonp_bool( gui->http, "mine", slot->mine );
    2486           0 :         if( FD_UNLIKELY( slot->vote_slot!=ULONG_MAX ) ) jsonp_ulong( gui->http, "vote_slot", slot->vote_slot );
    2487           0 :         else                                            jsonp_null( gui->http, "vote_slot" );
    2488           0 :         fd_gui_printf_slot_vote_latency( gui, slot );
    2489           0 :         fd_gui_printf_slot_is_voter( gui, _slot, slot );
    2490             : 
    2491           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  );
    2492           0 :         else                                                                  jsonp_null       ( gui->http, "start_timestamp_nanos" );
    2493           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  );
    2494           0 :         else                                                                jsonp_null       ( gui->http, "target_end_timestamp_nanos" );
    2495             : 
    2496           0 :         fd_gui_printf_slot_skipped( gui, slot );
    2497           0 :         jsonp_string( gui->http, "level", level );
    2498           0 :         fd_gui_printf_slot_proofs( gui, slot );
    2499           0 :         if( FD_UNLIKELY( duration_nanos==LONG_MAX ) ) jsonp_null( gui->http, "duration_nanos" );
    2500           0 :         else                                          jsonp_long( gui->http, "duration_nanos", duration_nanos );
    2501           0 :         if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) jsonp_null( gui->http, "completed_time_nanos" );
    2502           0 :         else                                                jsonp_long_as_str( gui->http, "completed_time_nanos", slot->completed_time );
    2503           0 :         fd_gui_printf_slot_txn_counts( gui, slot );
    2504           0 :         if( FD_UNLIKELY( slot->max_compute_units==UINT_MAX ) ) jsonp_null( gui->http, "max_compute_units" );
    2505           0 :         else                                                   jsonp_ulong( gui->http, "max_compute_units", slot->max_compute_units );
    2506           0 :         if( FD_UNLIKELY( slot->compute_units==UINT_MAX ) ) jsonp_null( gui->http, "compute_units" );
    2507           0 :         else                                               jsonp_ulong( gui->http, "compute_units", slot->compute_units );
    2508           0 :         if( FD_UNLIKELY( slot->shred_cnt==UINT_MAX ) ) jsonp_null( gui->http, "shreds" );
    2509           0 :         else                                           jsonp_ulong( gui->http, "shreds", slot->shred_cnt );
    2510           0 :         if( FD_UNLIKELY( slot->transaction_fee==ULONG_MAX ) ) jsonp_null( gui->http, "transaction_fee" );
    2511           0 :         else                                                  jsonp_ulong_as_str( gui->http, "transaction_fee", slot->transaction_fee );
    2512           0 :         if( FD_UNLIKELY( slot->priority_fee==ULONG_MAX ) ) jsonp_null( gui->http, "priority_fee" );
    2513           0 :         else                                               jsonp_ulong_as_str( gui->http, "priority_fee", slot->priority_fee );
    2514           0 :         if( FD_UNLIKELY( slot->tips==ULONG_MAX ) ) jsonp_null( gui->http, "tips" );
    2515           0 :         else                                       jsonp_ulong_as_str( gui->http, "tips", slot->tips );
    2516           0 :       jsonp_close_object( gui->http );
    2517             : 
    2518           0 :       if( FD_UNLIKELY( have_lmeta && lmeta->unbecame_leader ) ) {
    2519           0 :         fd_done_packing_t scheduler_stats[ 1 ];
    2520           0 :         fd_memcpy( scheduler_stats, lmeta->scheduler_stats, sizeof(scheduler_stats) );
    2521             : 
    2522           0 :         jsonp_open_object( gui->http, "limits" );
    2523           0 :           jsonp_ulong( gui->http, "used_total_block_cost",        scheduler_stats->limits_usage->block_cost          );
    2524           0 :           jsonp_ulong( gui->http, "used_total_vote_cost",         fd_ulong_if( gui->summary.is_alpenglow, 0UL, scheduler_stats->limits_usage->vote_cost ) );
    2525           0 :           jsonp_ulong( gui->http, "used_total_bytes",             scheduler_stats->limits_usage->block_data_bytes    );
    2526           0 :           jsonp_ulong( gui->http, "used_total_microblocks",       scheduler_stats->limits_usage->microblocks         );
    2527           0 :           jsonp_open_array( gui->http, "used_account_write_costs" );
    2528           0 :             for( ulong i = 0; i<FD_PACK_TOP_WRITERS_CNT; i++ ) {
    2529           0 :               if( FD_UNLIKELY( !memcmp( scheduler_stats->limits_usage->top_writers[ i ].key.b, ((fd_pubkey_t){ 0 }).uc, sizeof(fd_pubkey_t) ) ) ) break;
    2530             : 
    2531           0 :               jsonp_open_object( gui->http, NULL );
    2532           0 :                 char account_base58[ FD_BASE58_ENCODED_32_SZ ];
    2533           0 :                 fd_base58_encode_32( scheduler_stats->limits_usage->top_writers[ i ].key.b, NULL, account_base58 );
    2534           0 :                 jsonp_string( gui->http, "account", account_base58 );
    2535           0 :                 jsonp_ulong( gui->http, "cost", scheduler_stats->limits_usage->top_writers[ i ].total_cost );
    2536           0 :               jsonp_close_object( gui->http );
    2537           0 :             }
    2538           0 :           jsonp_close_array( gui->http );
    2539             : 
    2540           0 :           jsonp_ulong( gui->http, "max_total_block_cost",        scheduler_stats->limits->max_cost_per_block        );
    2541           0 :           jsonp_ulong( gui->http, "max_total_vote_cost",         fd_ulong_if( gui->summary.is_alpenglow, 0UL, scheduler_stats->limits->max_vote_cost_per_block ) );
    2542           0 :           jsonp_ulong( gui->http, "max_account_write_cost",      scheduler_stats->limits->max_write_cost_per_acct   );
    2543           0 :           jsonp_ulong( gui->http, "max_total_bytes",             scheduler_stats->limits->max_data_bytes_per_block  );
    2544           0 :           jsonp_ulong( gui->http, "max_total_microblocks",       lmeta->max_microblocks                                    );
    2545           0 :         jsonp_close_object( gui->http );
    2546             : 
    2547           0 :         jsonp_open_object( gui->http, "scheduler_stats" );
    2548             :           /* block_hash is replay-sourced; prefer FD_GUI_HIST_SLOT
    2549             :              and fall back to the leader meta's own block_hash. */
    2550           0 :           fd_hash_t block_hash = lmeta->block_hash;
    2551           0 :           fd_gui_load_block_hash( gui, _slot, &block_hash );
    2552           0 :           char block_hash_base58[ FD_BASE58_ENCODED_32_SZ ];
    2553           0 :           fd_base58_encode_32( block_hash.uc, NULL, block_hash_base58 );
    2554           0 :           jsonp_string( gui->http, "block_hash", block_hash_base58 );
    2555             : 
    2556           0 :           switch( scheduler_stats->end_slot_reason ) {
    2557           0 :             case FD_PACK_END_SLOT_REASON_TIME: {
    2558           0 :               jsonp_string( gui->http, "end_slot_reason", "timeout" );
    2559           0 :               break;
    2560           0 :             }
    2561           0 :             case FD_PACK_END_SLOT_REASON_MICROBLOCK: {
    2562           0 :               jsonp_string( gui->http, "end_slot_reason", "microblock_limit" );
    2563           0 :               break;
    2564           0 :             }
    2565           0 :             case FD_PACK_END_SLOT_REASON_ABANDONED: {
    2566           0 :               jsonp_string( gui->http, "end_slot_reason", "leader_switch" );
    2567           0 :               break;
    2568           0 :             }
    2569           0 :             default: FD_LOG_ERR(( "unreachable" ));
    2570           0 :           }
    2571           0 :           jsonp_open_array( gui->http, "slot_schedule_counts" );
    2572           0 :             for( ulong i = 0; i<FD_METRICS_COUNTER_PACK_TXN_SCHEDULE_ATTEMPTED_CNT; i++ ) jsonp_ulong( gui->http, NULL, scheduler_stats->block_results[ i ] );
    2573           0 :           jsonp_close_array( gui->http );
    2574           0 :           jsonp_open_array( gui->http, "end_slot_schedule_counts" );
    2575           0 :             for( ulong i = 0; i<FD_METRICS_COUNTER_PACK_TXN_SCHEDULE_ATTEMPTED_CNT; i++ ) jsonp_ulong( gui->http, NULL, scheduler_stats->end_block_results[ i ] );
    2576           0 :           jsonp_close_array( gui->http );
    2577             : 
    2578           0 :           fd_pack_smallest_t pending_smallest       = *scheduler_stats->pending_smallest;
    2579           0 :           fd_pack_smallest_t pending_votes_smallest = *scheduler_stats->pending_votes_smallest;
    2580           0 :           if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
    2581           0 :             pending_smallest.cus         = fd_ulong_min( pending_smallest.cus,   pending_votes_smallest.cus   );
    2582           0 :             pending_smallest.bytes       = fd_ulong_min( pending_smallest.bytes, pending_votes_smallest.bytes );
    2583           0 :             pending_votes_smallest.cus   = ULONG_MAX;
    2584           0 :             pending_votes_smallest.bytes = ULONG_MAX;
    2585           0 :           }
    2586             : 
    2587           0 :           if( FD_LIKELY( pending_smallest.cus!=ULONG_MAX ) ) jsonp_ulong( gui->http, "pending_smallest_cost", pending_smallest.cus );
    2588           0 :           else                                                jsonp_null( gui->http, "pending_smallest_cost" );
    2589           0 :           if( FD_LIKELY( pending_smallest.bytes!=ULONG_MAX ) ) jsonp_ulong( gui->http, "pending_smallest_bytes", pending_smallest.bytes );
    2590           0 :           else                                                  jsonp_null( gui->http, "pending_smallest_bytes" );
    2591           0 :           if( FD_LIKELY( pending_votes_smallest.cus!=ULONG_MAX ) ) jsonp_ulong( gui->http, "pending_vote_smallest_cost", pending_votes_smallest.cus );
    2592           0 :           else                                                      jsonp_null( gui->http, "pending_vote_smallest_cost" );
    2593           0 :           if( FD_LIKELY( pending_votes_smallest.bytes!=ULONG_MAX ) ) jsonp_ulong( gui->http, "pending_vote_smallest_bytes", pending_votes_smallest.bytes );
    2594           0 :           else                                                        jsonp_null( gui->http, "pending_vote_smallest_bytes" );
    2595           0 :         jsonp_close_object( gui->http );
    2596             : 
    2597           0 :       } else {
    2598           0 :         jsonp_null( gui->http, "limits" );
    2599           0 :         jsonp_null( gui->http, "scheduler_stats" );
    2600           0 :       }
    2601             : 
    2602           0 :       int processed_all_microblocks = have_lmeta && lmeta->unbecame_leader &&
    2603           0 :                                       lmeta->microblocks_upper_bound!=UINT_MAX &&
    2604           0 :                                       lmeta->begin_microblocks==lmeta->end_microblocks &&
    2605           0 :                                       lmeta->begin_microblocks==lmeta->microblocks_upper_bound;
    2606             : 
    2607           0 :       int have_leader_window = have_lmeta &&
    2608           0 :                                lmeta->leader_start_time!=LONG_MAX &&
    2609           0 :                                lmeta->leader_end_time  !=LONG_MAX &&
    2610           0 :                                lmeta->leader_start_time<=lmeta->leader_end_time;
    2611             : 
    2612           0 :       fd_gui_store_txn_start_t * starts    = gui->slot_txn_scratch.starts;
    2613           0 :       fd_gui_store_txn_end_t *   ends      = gui->slot_txn_scratch.ends;
    2614           0 :       fd_gui_slot_txn_join_t *   joined    = gui->slot_txn_scratch.joined;
    2615           0 :       ulong                      txn_max   = gui->slot_txn_scratch.max;
    2616           0 :       ulong                      start_cnt = 0UL;
    2617           0 :       ulong                      end_cnt   = 0UL;
    2618           0 :       ulong                      txn_cnt   = 0UL;
    2619           0 :       int                        have_txns = gui->db && processed_all_microblocks && have_leader_window;
    2620             : 
    2621           0 :       if( FD_LIKELY( have_txns && lmeta->txn_insert_time_min_ns<=lmeta->txn_insert_time_max_ns ) ) {
    2622           0 :         long txn_lo_ns = lmeta->txn_insert_time_min_ns;
    2623           0 :         long txn_hi_ns = lmeta->txn_insert_time_max_ns;
    2624             : 
    2625             :         /* Scan the start half, keeping only this slot's records. */
    2626           0 :         fd_gui_hist_iter_t it;
    2627           0 :         if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_TXN_START, txn_lo_ns, txn_hi_ns, NULL, NULL ) ) ) {
    2628           0 :           while( fd_gui_hist_range_next( &it ) ) {
    2629           0 :             fd_gui_store_txn_start_t const * r = (fd_gui_store_txn_start_t const *)it.rec;
    2630           0 :             if( FD_UNLIKELY( r->slot!=_slot || r->bank_seq!=slot->bank_seq ) ) continue;
    2631           0 :             if( FD_UNLIKELY( start_cnt>=txn_max ) ) break;
    2632           0 :             starts[ start_cnt++ ] = *r;
    2633           0 :           }
    2634           0 :           fd_gui_hist_range_end( &it );
    2635           0 :         }
    2636             : 
    2637             :         /* Scan the end half, keeping only this slot's records. */
    2638           0 :         if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_TXN_END, txn_lo_ns, txn_hi_ns, NULL, NULL ) ) ) {
    2639           0 :           while( fd_gui_hist_range_next( &it ) ) {
    2640           0 :             fd_gui_store_txn_end_t const * r = (fd_gui_store_txn_end_t const *)it.rec;
    2641           0 :             if( FD_UNLIKELY( r->slot!=_slot || r->bank_seq!=slot->bank_seq ) ) continue;
    2642           0 :             if( FD_UNLIKELY( end_cnt>=txn_max ) ) break;
    2643           0 :             ends[ end_cnt++ ] = *r;
    2644           0 :           }
    2645           0 :           fd_gui_hist_range_end( &it );
    2646           0 :         }
    2647             : 
    2648             :         /* Sort both halves by txn_idx, then merge-walk to join. */
    2649           0 :         fd_gui_slot_txn_start_sort_inplace( starts, start_cnt );
    2650           0 :         fd_gui_slot_txn_end_sort_inplace  ( ends,   end_cnt   );
    2651             : 
    2652           0 :         ulong si = 0UL;
    2653           0 :         ulong ei = 0UL;
    2654           0 :         while( si<start_cnt && ei<end_cnt ) {
    2655           0 :           ulong s_idx = starts[ si ].txn_idx;
    2656           0 :           ulong e_idx = ends  [ ei ].txn_idx;
    2657           0 :           if(      s_idx<e_idx ) si++;
    2658           0 :           else if( e_idx<s_idx ) ei++;
    2659           0 :           else {
    2660           0 :             joined[ txn_cnt ].start = &starts[ si ];
    2661           0 :             joined[ txn_cnt ].end   = &ends  [ ei ];
    2662           0 :             txn_cnt++;
    2663           0 :             si++;
    2664           0 :             ei++;
    2665           0 :           }
    2666           0 :         }
    2667           0 :       }
    2668             : 
    2669           0 :       if( FD_LIKELY( have_txns ) ) {
    2670           0 :         jsonp_open_object( gui->http, "transactions" );
    2671           0 :           jsonp_long_as_str( gui->http, "start_timestamp_nanos", lmeta->leader_start_time );
    2672           0 :           jsonp_long_as_str( gui->http, "target_end_timestamp_nanos", lmeta->leader_end_time );
    2673           0 :           jsonp_open_array( gui->http, "txn_mb_start_timestamps_nanos" );
    2674           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns );
    2675           0 :           jsonp_close_array( gui->http );
    2676           0 :           jsonp_open_array( gui->http, "txn_mb_end_timestamps_nanos" );
    2677           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2678           0 :               long const mb_start = joined[ i ].start->microblock_start_ns;
    2679           0 :               long const mb_end   = fd_long_max( joined[ i ].end->microblock_end_ns, mb_start + 1L );
    2680           0 :               jsonp_long_as_str( gui->http, NULL, mb_end );
    2681           0 :             }
    2682           0 :           jsonp_close_array( gui->http );
    2683           0 :           jsonp_open_array( gui->http, "txn_compute_units_requested" );
    2684           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong( gui->http, NULL, joined[ i ].start->compute_units_requested );
    2685           0 :           jsonp_close_array( gui->http );
    2686           0 :           jsonp_open_array( gui->http, "txn_compute_units_consumed" );
    2687           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong( gui->http, NULL, joined[ i ].end->compute_units_consumed );
    2688           0 :           jsonp_close_array( gui->http );
    2689           0 :           jsonp_open_array( gui->http, "txn_priority_fee" );
    2690           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong_as_str( gui->http, NULL, joined[ i ].start->priority_fee );
    2691           0 :           jsonp_close_array( gui->http );
    2692           0 :           jsonp_open_array( gui->http, "txn_transaction_fee" );
    2693           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong_as_str( gui->http, NULL, joined[ i ].start->transaction_fee );
    2694           0 :           jsonp_close_array( gui->http );
    2695           0 :           jsonp_open_array( gui->http, "txn_error_code" );
    2696           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong( gui->http, NULL, joined[ i ].end->error_code );
    2697           0 :           jsonp_close_array( gui->http );
    2698           0 :           jsonp_open_array( gui->http, "txn_from_bundle" );
    2699           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_bool( gui->http, NULL, joined[ i ].start->flags & FD_GUI_TXN_FLAGS_FROM_BUNDLE );
    2700           0 :           jsonp_close_array( gui->http );
    2701             :           /* Tower-only: Alpenglow has no vote transactions to flag. */
    2702           0 :           if( FD_LIKELY( !gui->summary.is_alpenglow ) ) {
    2703           0 :             jsonp_open_array( gui->http, "txn_is_simple_vote" );
    2704           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 );
    2705           0 :             jsonp_close_array( gui->http );
    2706           0 :           }
    2707           0 :           jsonp_open_array( gui->http, "txn_bank_idx" );
    2708           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong( gui->http, NULL, joined[ i ].end->bank_idx );
    2709           0 :           jsonp_close_array( gui->http );
    2710           0 :           jsonp_open_array( gui->http, "txn_check_start_timestamps_nanos" );
    2711           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2712           0 :               jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns + (long)joined[ i ].end->txn_ns_dt.check_start );
    2713           0 :             }
    2714           0 :           jsonp_close_array( gui->http );
    2715           0 :           jsonp_open_array( gui->http, "txn_load_start_timestamps_nanos" );
    2716           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2717           0 :               jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns + (long)joined[ i ].end->txn_ns_dt.load_start );
    2718           0 :             }
    2719           0 :           jsonp_close_array( gui->http );
    2720           0 :           jsonp_open_array( gui->http, "txn_execute_start_timestamps_nanos" );
    2721           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2722           0 :               jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns + (long)joined[ i ].end->txn_ns_dt.exec_start );
    2723           0 :             }
    2724           0 :           jsonp_close_array( gui->http );
    2725           0 :           jsonp_open_array( gui->http, "txn_commit_start_timestamps_nanos" );
    2726           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2727           0 :               jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns + (long)joined[ i ].end->txn_ns_dt.commit_start );
    2728           0 :             }
    2729           0 :           jsonp_close_array( gui->http );
    2730           0 :           jsonp_open_array( gui->http, "txn_commit_end_timestamps_nanos" );
    2731           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2732           0 :               jsonp_long_as_str( gui->http, NULL, joined[ i ].start->microblock_start_ns + (long)joined[ i ].end->txn_ns_dt.commit_end );
    2733           0 :             }
    2734           0 :           jsonp_close_array( gui->http );
    2735           0 :           jsonp_open_array( gui->http, "txn_arrival_timestamps_nanos" );
    2736           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_long_as_str( gui->http, NULL, joined[ i ].start->timestamp_arrival_nanos );
    2737           0 :           jsonp_close_array( gui->http );
    2738           0 :           jsonp_open_array( gui->http, "txn_tips" );
    2739           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong_as_str( gui->http, NULL, joined[ i ].end->tips );
    2740           0 :           jsonp_close_array( gui->http );
    2741           0 :           jsonp_open_array( gui->http, "txn_source_ipv4" );
    2742           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2743           0 :               char addr[ 64 ];
    2744           0 :               fd_cstr_printf_check( addr, sizeof(addr), NULL, FD_IP4_ADDR_FMT, FD_IP4_ADDR_FMT_ARGS( joined[ i ].start->source_ipv4 ) );
    2745           0 :               jsonp_string( gui->http, NULL, addr );
    2746           0 :             }
    2747           0 :           jsonp_close_array( gui->http );
    2748           0 :           jsonp_open_array( gui->http, "txn_source_tpu" );
    2749           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2750           0 :               switch ( joined[ i ].start->source_tpu ) {
    2751           0 :                 case FD_TXN_M_TPU_SOURCE_QUIC: {
    2752           0 :                   jsonp_string( gui->http, NULL, "quic");
    2753           0 :                   break;
    2754           0 :                 }
    2755           0 :                 case FD_TXN_M_TPU_SOURCE_UDP   : {
    2756           0 :                   jsonp_string( gui->http, NULL, "udp");
    2757           0 :                   break;
    2758           0 :                 }
    2759           0 :                 case FD_TXN_M_TPU_SOURCE_GOSSIP: {
    2760           0 :                   jsonp_string( gui->http, NULL, "gossip");
    2761           0 :                   break;
    2762           0 :                 }
    2763           0 :                 case FD_TXN_M_TPU_SOURCE_BUNDLE: {
    2764           0 :                   jsonp_string( gui->http, NULL, "bundle");
    2765           0 :                   break;
    2766           0 :                 }
    2767           0 :                 case FD_TXN_M_TPU_SOURCE_TXSEND: {
    2768           0 :                   jsonp_string( gui->http, NULL, "send");
    2769           0 :                   break;
    2770           0 :                 }
    2771           0 :                 default: FD_LOG_ERR(("unknown tpu"));
    2772           0 :               }
    2773           0 :             }
    2774           0 :           jsonp_close_array( gui->http );
    2775           0 :           jsonp_open_array( gui->http, "txn_microblock_id" );
    2776           0 :             for( ulong i=0UL; i<txn_cnt; i++) jsonp_ulong( gui->http, NULL, joined[ i ].start->microblock_idx );
    2777           0 :           jsonp_close_array( gui->http );
    2778           0 :           jsonp_open_array( gui->http, "txn_landed" );
    2779           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 );
    2780           0 :           jsonp_close_array( gui->http );
    2781           0 :           jsonp_open_array( gui->http, "txn_signature" );
    2782           0 :             for( ulong i=0UL; i<txn_cnt; i++) {
    2783           0 :               FD_BASE58_ENCODE_64_BYTES( joined[ i ].start->signature, encoded_signature );
    2784           0 :               jsonp_string( gui->http, NULL, encoded_signature );
    2785           0 :             }
    2786           0 :           jsonp_close_array( gui->http );
    2787           0 :         jsonp_close_object( gui->http );
    2788           0 :       } else {
    2789           0 :         jsonp_null( gui->http, "transactions" );
    2790           0 :       }
    2791             : 
    2792           0 :     jsonp_close_object( gui->http );
    2793           0 :   jsonp_close_envelope( gui->http );
    2794           0 : }
    2795             : 
    2796             : void
    2797             : fd_gui_printf_slot_request_detailed( fd_gui_t *            gui,
    2798             :                                      ulong                _slot,
    2799             :                                      ulong                id,
    2800           0 :                                      fd_gui_slot_t const * slot ) {
    2801           0 :   char const * level = fd_gui_slot_level_cstr( gui, _slot, slot );
    2802             : 
    2803           0 :   long duration_nanos = fd_gui_load_slot_duration( gui, _slot, slot );
    2804             : 
    2805           0 :   jsonp_open_envelope( gui->http, "slot", "query_detailed" );
    2806           0 :     jsonp_ulong( gui->http, "id", id );
    2807           0 :     jsonp_open_object( gui->http, "value" );
    2808           0 :       fd_gui_leader_slot_t lmeta[ 1 ];
    2809           0 :       int have_lmeta = fd_gui_load_leader_meta( gui, _slot, lmeta );
    2810             : 
    2811           0 :       jsonp_open_object( gui->http, "publish" );
    2812           0 :         jsonp_ulong( gui->http, "slot", _slot );
    2813           0 :         jsonp_bool( gui->http, "mine", slot->mine );
    2814           0 :         if( FD_UNLIKELY( slot->vote_slot!=ULONG_MAX ) ) jsonp_ulong( gui->http, "vote_slot", slot->vote_slot );
    2815           0 :         else                                            jsonp_null( gui->http, "vote_slot" );
    2816           0 :         fd_gui_printf_slot_vote_latency( gui, slot );
    2817           0 :         fd_gui_printf_slot_is_voter( gui, _slot, slot );
    2818             : 
    2819           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  );
    2820           0 :         else                                                                  jsonp_null       ( gui->http, "start_timestamp_nanos" );
    2821           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  );
    2822           0 :         else                                                                jsonp_null       ( gui->http, "target_end_timestamp_nanos" );
    2823             : 
    2824           0 :         fd_gui_printf_slot_skipped( gui, slot );
    2825           0 :         jsonp_string( gui->http, "level", level );
    2826           0 :         fd_gui_printf_slot_proofs( gui, slot );
    2827           0 :         if( FD_UNLIKELY( duration_nanos==LONG_MAX ) ) jsonp_null( gui->http, "duration_nanos" );
    2828           0 :         else                                          jsonp_long( gui->http, "duration_nanos", duration_nanos );
    2829           0 :         if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) jsonp_null( gui->http, "completed_time_nanos" );
    2830           0 :         else                                                jsonp_long_as_str( gui->http, "completed_time_nanos", slot->completed_time );
    2831           0 :         fd_gui_printf_slot_txn_counts( gui, slot );
    2832           0 :         if( FD_UNLIKELY( slot->max_compute_units==UINT_MAX ) ) jsonp_null( gui->http, "max_compute_units" );
    2833           0 :         else                                                   jsonp_ulong( gui->http, "max_compute_units", slot->max_compute_units );
    2834           0 :         if( FD_UNLIKELY( slot->compute_units==UINT_MAX ) ) jsonp_null( gui->http, "compute_units" );
    2835           0 :         else                                               jsonp_ulong( gui->http, "compute_units", slot->compute_units );
    2836           0 :         if( FD_UNLIKELY( slot->shred_cnt==UINT_MAX ) ) jsonp_null( gui->http, "shreds" );
    2837           0 :         else                                           jsonp_ulong( gui->http, "shreds", slot->shred_cnt );
    2838           0 :         if( FD_UNLIKELY( slot->transaction_fee==ULONG_MAX ) ) jsonp_null( gui->http, "transaction_fee" );
    2839           0 :         else                                                  jsonp_ulong_as_str( gui->http, "transaction_fee", slot->transaction_fee );
    2840           0 :         if( FD_UNLIKELY( slot->priority_fee==ULONG_MAX ) ) jsonp_null( gui->http, "priority_fee" );
    2841           0 :         else                                               jsonp_ulong_as_str( gui->http, "priority_fee", slot->priority_fee );
    2842           0 :         if( FD_UNLIKELY( slot->tips==ULONG_MAX ) ) jsonp_null( gui->http, "tips" );
    2843           0 :         else                                       jsonp_ulong_as_str( gui->http, "tips", slot->tips );
    2844           0 :       jsonp_close_object( gui->http );
    2845             : 
    2846           0 :       if( FD_LIKELY( gui->summary.slot_tower!=ULONG_MAX && gui->summary.slot_tower>_slot ) ) {
    2847           0 :         long leader_start_time = have_lmeta ? lmeta->leader_start_time : LONG_MAX;
    2848           0 :         long leader_end_time   = have_lmeta ? lmeta->leader_end_time   : LONG_MAX;
    2849           0 :         int  have_window       = have_lmeta && gui->db && leader_start_time!=LONG_MAX && leader_end_time!=LONG_MAX;
    2850             : 
    2851           0 :         fd_gui_txn_waterfall_t previous[ 1 ];
    2852           0 :         fd_gui_txn_waterfall_t current [ 1 ];
    2853           0 :         fd_gui_leader_slot_t const * current_lslot = fd_gui_slot_leader_get( gui, _slot, slot->bank_seq );
    2854           0 :         int have_waterfall = current_lslot && current_lslot->has_waterfall;
    2855           0 :         if( FD_LIKELY( have_waterfall ) ) {
    2856           0 :           fd_memcpy( previous, current_lslot->waterfall_reference, sizeof(previous) );
    2857           0 :           fd_memcpy( current,  current_lslot->waterfall,           sizeof(current)  );
    2858           0 :         }
    2859           0 :         if( FD_LIKELY( have_waterfall ) ) fd_gui_printf_waterfall( gui, previous, current );
    2860           0 :         else                              jsonp_null( gui->http, "waterfall" );
    2861             : 
    2862           0 :         if( FD_LIKELY( have_window ) ) {
    2863           0 :           jsonp_open_array( gui->http, "tile_timers" );
    2864           0 :             fd_gui_hist_iter_t it;
    2865           0 :             if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_TILE_TIMERS, leader_start_time, leader_end_time, NULL, NULL ) ) ) {
    2866           0 :               fd_gui_tile_timers_hist_t sample[ FD_TOPO_MAX_TILES ];
    2867           0 :               int  have_sample   = 0;
    2868           0 :               long cur_sample_ts = LONG_MAX;
    2869           0 :               while( fd_gui_hist_range_next( &it ) ) {
    2870           0 :                 fd_gui_tile_timers_hist_t const * row = (fd_gui_tile_timers_hist_t const *)it.rec;
    2871           0 :                 if( FD_UNLIKELY( row->sample_time_nanos<leader_start_time || row->sample_time_nanos>leader_end_time ) ) continue;
    2872           0 :                 if( FD_UNLIKELY( row->tile_idx>=FD_TOPO_MAX_TILES ) ) continue;
    2873             : 
    2874             :                 /* Records are stored already-diffed and self-contained, so
    2875             :                    each distinct sample_time_nanos is emitted directly (no
    2876             :                    diff against the previous sample). */
    2877           0 :                 if( have_sample && row->sample_time_nanos!=cur_sample_ts ) {
    2878           0 :                   fd_gui_printf_ts_tile_timers( gui, cur_sample_ts, sample );
    2879           0 :                   have_sample = 0;
    2880           0 :                 }
    2881           0 :                 cur_sample_ts = row->sample_time_nanos;
    2882           0 :                 sample[ row->tile_idx ] = *row;
    2883           0 :                 have_sample = 1;
    2884           0 :               }
    2885             : 
    2886           0 :               if( have_sample ) fd_gui_printf_ts_tile_timers( gui, cur_sample_ts, sample );
    2887           0 :               fd_gui_hist_range_end( &it );
    2888           0 :             }
    2889           0 :           jsonp_close_array( gui->http );
    2890           0 :         } else {
    2891           0 :           jsonp_null( gui->http, "tile_timers" );
    2892           0 :         }
    2893             : 
    2894           0 :         if( FD_LIKELY( have_window ) ) {
    2895             :           /* Unlike tile timers (which are counters), scheduler counts are a
    2896             :              gauge and we don't take a diff. */
    2897           0 :           jsonp_open_array( gui->http, "scheduler_counts" );
    2898           0 :             fd_gui_hist_iter_t it;
    2899           0 :             if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_SCHEDULER_COUNTS, leader_start_time, leader_end_time, NULL, NULL ) ) ) {
    2900           0 :               while( fd_gui_hist_range_next( &it ) ) {
    2901           0 :                 fd_gui_scheduler_counts_t const * cur = (fd_gui_scheduler_counts_t const *)it.rec;
    2902           0 :                 if( FD_UNLIKELY( cur->sample_time_ns<leader_start_time ||
    2903           0 :                                  cur->sample_time_ns>leader_end_time ) ) continue;
    2904           0 :                 ulong regular = cur->regular;
    2905           0 :                 ulong votes   = cur->votes;
    2906           0 :                 if( FD_UNLIKELY( gui->summary.is_alpenglow ) ) {
    2907           0 :                   regular += votes;
    2908           0 :                   votes    = 0UL;
    2909           0 :                 }
    2910           0 :                 jsonp_open_object( gui->http, NULL );
    2911           0 :                   jsonp_long_as_str( gui->http, "timestamp_nanos", cur->sample_time_ns );
    2912           0 :                   jsonp_ulong      ( gui->http, "regular",         regular             );
    2913           0 :                   jsonp_ulong      ( gui->http, "votes",           votes               );
    2914           0 :                   jsonp_ulong      ( gui->http, "conflicting",     cur->conflicting    );
    2915           0 :                   jsonp_ulong      ( gui->http, "bundles",         cur->bundles        );
    2916           0 :                 jsonp_close_object( gui->http );
    2917           0 :               }
    2918           0 :               fd_gui_hist_range_end( &it );
    2919           0 :             }
    2920           0 :           jsonp_close_array( gui->http );
    2921           0 :         } else {
    2922           0 :           jsonp_null( gui->http, "scheduler_counts" );
    2923           0 :         }
    2924             : 
    2925           0 :         int have_tile_stats = 0;
    2926           0 :         fd_gui_tile_stats_t tile_stats_begin[ 1 ];
    2927           0 :         fd_gui_tile_stats_t tile_stats_end  [ 1 ];
    2928           0 :         if( FD_LIKELY( have_window ) ) {
    2929           0 :           fd_gui_hist_iter_t it;
    2930           0 :           if( FD_LIKELY( !fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_TILE_STATS, leader_start_time, leader_end_time, NULL, NULL ) ) ) {
    2931           0 :             while( fd_gui_hist_range_next( &it ) ) {
    2932           0 :               fd_gui_tile_stats_t cur[ 1 ];
    2933           0 :               fd_memcpy( cur, it.rec, sizeof(fd_gui_tile_stats_t) );
    2934           0 :               if( FD_UNLIKELY( cur->sample_time_nanos<leader_start_time || cur->sample_time_nanos>leader_end_time ) ) continue;
    2935           0 :               if( FD_UNLIKELY( !have_tile_stats ) ) *tile_stats_begin = *cur;
    2936           0 :               *tile_stats_end = *cur;
    2937           0 :               have_tile_stats = 1;
    2938           0 :             }
    2939           0 :             fd_gui_hist_range_end( &it );
    2940           0 :           }
    2941           0 :         }
    2942           0 :         if( FD_LIKELY( have_tile_stats ) ) fd_gui_printf_tile_stats( gui, tile_stats_begin, tile_stats_end );
    2943           0 :         else                               jsonp_null( gui->http, "tile_primary_metric" );
    2944           0 :       } else {
    2945           0 :         jsonp_null( gui->http, "waterfall" );
    2946           0 :         jsonp_null( gui->http, "tile_timers" );
    2947           0 :         jsonp_null( gui->http, "tile_primary_metric" );
    2948           0 :       }
    2949             : 
    2950           0 :     jsonp_close_object( gui->http );
    2951           0 :   jsonp_close_envelope( gui->http );
    2952           0 : }
    2953             : 
    2954             : void
    2955           0 : fd_gui_printf_boot_progress( fd_gui_t * gui ) {
    2956           0 :   jsonp_open_envelope( gui->http, "summary", "boot_progress" );
    2957           0 :     jsonp_open_object( gui->http, "value" );
    2958           0 :       switch( gui->summary.boot_progress.phase ) {
    2959           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP:               jsonp_string( gui->http, "phase", "joining_gossip" );               break;
    2960           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT:        jsonp_string( gui->http, "phase", "loading_full_snapshot" );        break;
    2961           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT: jsonp_string( gui->http, "phase", "loading_incremental_snapshot" ); break;
    2962           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY:    jsonp_string( gui->http, "phase", "waiting_for_supermajority" );    break;
    2963           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP:                  jsonp_string( gui->http, "phase", "catching_up" );                  break;
    2964           0 :         case FD_GUI_BOOT_PROGRESS_TYPE_RUNNING:                      jsonp_string( gui->http, "phase", "running" );                      break;
    2965           0 :         default: FD_LOG_ERR(( "unknown phase %d", gui->summary.boot_progress.phase ));
    2966           0 :       }
    2967             : 
    2968           0 :       if( FD_LIKELY( gui->summary.boot_progress.phase>=FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY
    2969           0 :                   && gui->summary.boot_progress.boot_target_slot_duration_nanos!=ULONG_MAX ) ) {
    2970           0 :         jsonp_ulong( gui->http, "boot_target_slot_duration_nanos", gui->summary.boot_progress.boot_target_slot_duration_nanos );
    2971           0 :       } else {
    2972           0 :         jsonp_null( gui->http, "boot_target_slot_duration_nanos" );
    2973           0 :       }
    2974             : 
    2975           0 :       jsonp_string( gui->http, "accounts_database_path", gui->summary.accounts_database_path );
    2976           0 :       jsonp_string( gui->http, "gui_database_path", gui->summary.gui_database_path );
    2977             : 
    2978           0 :       jsonp_double( gui->http, "joining_gossip_elapsed_seconds", (double)(gui->summary.boot_progress.joining_gossip_time_nanos - gui->summary.startup_time_nanos) / 1e9 );
    2979             : 
    2980           0 : #define HANDLE_SNAPSHOT_STATE(snapshot_type, snapshot_type_upper) { \
    2981           0 :       ulong snapshot_idx = FD_GUI_BOOT_PROGRESS_##snapshot_type_upper##_SNAPSHOT_IDX; \
    2982           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 )) { \
    2983           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 ); \
    2984           0 :         jsonp_ulong       ( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_reset_count",                      gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt                                            ); \
    2985           0 :         jsonp_ulong       ( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_slot",                             gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot                                                 ); \
    2986           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                               ); \
    2987           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                                ); \
    2988           0 :         jsonp_string      ( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_read_path",                        gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_path                                            ); \
    2989           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                        ); \
    2990           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                          ); \
    2991           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                            ); \
    2992           0 :         jsonp_ulong       ( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_insert_accounts",                  gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_accounts_current                              ); \
    2993           0 :       } else { \
    2994           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_elapsed_seconds"                  ); \
    2995           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_reset_count"                      ); \
    2996           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_slot"                             ); \
    2997           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_total_bytes_compressed"           ); \
    2998           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_read_bytes_compressed"            ); \
    2999           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_read_path"                        ); \
    3000           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_decompress_bytes_decompressed"    ); \
    3001           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_decompress_bytes_compressed"      ); \
    3002           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_insert_bytes_decompressed"        ); \
    3003           0 :         jsonp_null( gui->http, "loading_" FD_STRINGIFY(snapshot_type) "_snapshot_insert_accounts"                  ); \
    3004           0 :       } \
    3005           0 :     }
    3006             : 
    3007           0 :     HANDLE_SNAPSHOT_STATE(full, FULL)
    3008           0 :     HANDLE_SNAPSHOT_STATE(incremental, INCREMENTAL)
    3009           0 : #undef HANDLE_SNAPSHOT_STATE
    3010             : 
    3011           0 :     if( FD_LIKELY( gui->summary.wfs_enabled ) ) {
    3012           0 :       jsonp_string      ( gui->http, "wait_for_supermajority_bank_hash",        gui->summary.wfs_bank_hash );
    3013           0 :       char shred_version_str[ 8 ];
    3014           0 :       FD_TEST( fd_cstr_printf_check( shred_version_str, sizeof(shred_version_str), NULL, "%hu", gui->summary.expected_shred_version ) );
    3015           0 :       jsonp_string      ( gui->http, "wait_for_supermajority_shred_version",    shred_version_str );
    3016             :       /* Only a MATCH boot waits, so NOOP reports null not zeroes. */
    3017           0 :       if( FD_LIKELY( fd_gui_wfs_mode( gui )==FD_WFS_MODE_MATCH &&
    3018           0 :                      gui->summary.boot_progress.phase>=FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY ) ) {
    3019           0 :         jsonp_ulong       ( gui->http, "wait_for_supermajority_attempt",          gui->summary.boot_progress.wfs_attempt );
    3020           0 :         jsonp_ulong_as_str( gui->http, "wait_for_supermajority_total_stake",      gui->summary.boot_progress.wfs_total_stake );
    3021           0 :         jsonp_ulong_as_str( gui->http, "wait_for_supermajority_connected_stake",  gui->summary.boot_progress.wfs_connected_stake );
    3022           0 :         jsonp_ulong       ( gui->http, "wait_for_supermajority_total_peers",      gui->summary.boot_progress.wfs_total_peers );
    3023           0 :         jsonp_ulong       ( gui->http, "wait_for_supermajority_connected_peers",  gui->summary.boot_progress.wfs_connected_peers );
    3024           0 :       } else {
    3025           0 :         jsonp_null( gui->http, "wait_for_supermajority_attempt" );
    3026           0 :         jsonp_null( gui->http, "wait_for_supermajority_total_stake" );
    3027           0 :         jsonp_null( gui->http, "wait_for_supermajority_connected_stake" );
    3028           0 :         jsonp_null( gui->http, "wait_for_supermajority_total_peers" );
    3029           0 :         jsonp_null( gui->http, "wait_for_supermajority_connected_peers" );
    3030           0 :       }
    3031           0 :     } else {
    3032           0 :       jsonp_null( gui->http, "wait_for_supermajority_bank_hash" );
    3033           0 :       jsonp_null( gui->http, "wait_for_supermajority_shred_version" );
    3034           0 :       jsonp_null( gui->http, "wait_for_supermajority_attempt" );
    3035           0 :       jsonp_null( gui->http, "wait_for_supermajority_total_stake" );
    3036           0 :       jsonp_null( gui->http, "wait_for_supermajority_connected_stake" );
    3037           0 :       jsonp_null( gui->http, "wait_for_supermajority_total_peers" );
    3038           0 :       jsonp_null( gui->http, "wait_for_supermajority_connected_peers" );
    3039           0 :     }
    3040             : 
    3041           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 );
    3042           0 :     else                                                                                       jsonp_null  ( gui->http, "catching_up_elapsed_seconds" );
    3043             : 
    3044           0 :     if( FD_LIKELY( gui->summary.boot_progress.phase>=FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP
    3045           0 :                 && gui->summary.boot_progress.catching_up_first_replay_slot!=ULONG_MAX ) ) {
    3046           0 :       jsonp_ulong( gui->http, "catching_up_first_replay_slot", gui->summary.boot_progress.catching_up_first_replay_slot );
    3047           0 :     } else {
    3048           0 :       jsonp_null( gui->http, "catching_up_first_replay_slot" );
    3049           0 :     }
    3050             : 
    3051           0 :     jsonp_close_object( gui->http );
    3052           0 :   jsonp_close_envelope( gui->http );
    3053           0 : }
    3054             : 
    3055             : void
    3056           0 : fd_gui_printf_snapshot_transfers( fd_gui_t * gui ) {
    3057           0 :   jsonp_open_envelope( gui->http, "snapshot_server", "transfers" );
    3058           0 :     jsonp_open_array( gui->http, "value" );
    3059           0 :       for( ulong i=0UL; i<gui->snapsv.pending_cnt; i++ ) {
    3060           0 :         fd_gui_snapsv_pending_t const * pending = &gui->snapsv.pending[ i ];
    3061           0 :         fd_snapsv_msg_snap_t const * msg = &pending->msg;
    3062           0 :         char client_ip[ FD_IP6_ADDR_CSTR_MAX ];
    3063           0 :         fd_ip6_addr_cstr( client_ip, &msg->req_ip );
    3064           0 :         jsonp_open_object( gui->http, NULL );
    3065           0 :           jsonp_ulong       ( gui->http, "tile_idx",    msg->key.kind_id );
    3066           0 :           jsonp_ulong       ( gui->http, "conn_idx",    msg->key.slot_idx );
    3067           0 :           jsonp_ulong_as_str( gui->http, "request_seq", msg->key.req_seq );
    3068           0 :           jsonp_string      ( gui->http, "client_ip",   client_ip );
    3069           0 :           jsonp_ulong       ( gui->http, "client_port", msg->req_port );
    3070           0 :           jsonp_ulong       ( gui->http, "slot",        msg->slot );
    3071           0 :           jsonp_bool        ( gui->http, "incremental", msg->base_slot!=ULONG_MAX );
    3072           0 :           if( FD_LIKELY( msg->base_slot!=ULONG_MAX ) ) jsonp_ulong( gui->http, "base_slot", msg->base_slot );
    3073           0 :           else                                         jsonp_null ( gui->http, "base_slot" );
    3074           0 :           jsonp_ulong_as_str( gui->http, "snapshot_size", msg->snap_sz );
    3075           0 :           jsonp_ulong_as_str( gui->http, "range_start", msg->req_off );
    3076           0 :           jsonp_ulong_as_str( gui->http, "range_size",  msg->req_sz );
    3077           0 :           jsonp_ulong_as_str( gui->http, "bytes_sent",  msg->req_cur );
    3078           0 :           jsonp_long_as_str ( gui->http, "start_time_nanos", msg->resp_ts );
    3079           0 :           jsonp_long_as_str ( gui->http, "sample_time_nanos", pending->sample_time_nanos );
    3080           0 :           jsonp_long_as_str ( gui->http, "expire_time_nanos", fd_long_sat_add( pending->sample_time_nanos, FD_SNAPSV_SYNC_EXPIRY ) );
    3081           0 :           jsonp_bool        ( gui->http, "closed",      pending->closed );
    3082           0 :         jsonp_close_object( gui->http );
    3083           0 :       }
    3084           0 :     jsonp_close_array( gui->http );
    3085           0 :   jsonp_close_envelope( gui->http );
    3086           0 : }
    3087             : 
    3088             : void
    3089             : fd_gui_printf_peers_viewport_update( fd_gui_peers_ctx_t *  peers,
    3090           0 :                                      ulong                 ws_conn_id ) {
    3091           0 :   jsonp_open_envelope( peers->http, "gossip", "view_update" );
    3092           0 :     jsonp_open_object( peers->http, "value" );
    3093           0 :       jsonp_open_array( peers->http, "changes" );
    3094           0 :         FD_TEST( peers->scratch.viewport_cnt<=FD_GUI_PEERS_WS_VIEWPORT_MAX_SZ );
    3095             : 
    3096           0 :         ulong start_row = peers->client_viewports[ ws_conn_id ].start_row;
    3097           0 :         for( ulong i=0UL; i<peers->scratch.viewport_cnt; i++ ) {
    3098           0 :           ulong j = start_row + i;
    3099           0 :           fd_gui_peers_row_t const * cur = &peers->scratch.viewport[ i ];
    3100           0 :           fd_gui_peers_row_t const * ref = &peers->scratch.viewport_ref[ i ];
    3101             : 
    3102             :           /* This code should be kept in sync with updates to
    3103             :              fd_gui_peers_live_table */
    3104           0 :           if( FD_UNLIKELY( cur->stake!=ref->stake ) ) {
    3105           0 :             jsonp_open_object( peers->http, NULL );
    3106           0 :               jsonp_ulong ( peers->http, "row_index", j );
    3107           0 :               jsonp_string( peers->http, "column_name", "Stake" );
    3108             : 
    3109           0 :               if( FD_UNLIKELY( cur->stake==ULONG_MAX ) ) jsonp_long ( peers->http, "new_value", -1 );
    3110           0 :               else                                       jsonp_ulong( peers->http, "new_value", cur->stake );
    3111           0 :             jsonp_close_object( peers->http );
    3112           0 :           }
    3113             : 
    3114           0 :           if( FD_UNLIKELY( strncmp( cur->name, ref->name, sizeof(ref->name) ) ) ) {
    3115           0 :             jsonp_open_object( peers->http, NULL );
    3116           0 :               jsonp_ulong ( peers->http, "row_index", j );
    3117           0 :               jsonp_string( peers->http, "column_name", "Name" );
    3118           0 :               jsonp_string( peers->http, "new_value", cur->name );
    3119           0 :             jsonp_close_object( peers->http );
    3120           0 :           }
    3121             : 
    3122           0 :           if( FD_UNLIKELY( cur->country_code_idx!=ref->country_code_idx ) ) {
    3123           0 :             jsonp_open_object( peers->http, NULL );
    3124           0 :               jsonp_ulong ( peers->http, "row_index", j );
    3125           0 :               jsonp_string( peers->http, "column_name", "Country" );
    3126           0 :               if( FD_LIKELY( cur->country_code_idx!=UCHAR_MAX ) ) {
    3127           0 :                 jsonp_string( peers->http, "new_value", peers->dbip.country_code[ cur->country_code_idx ] );
    3128           0 :               } else {
    3129           0 :                 jsonp_null( peers->http, "new_value" );
    3130           0 :               }
    3131           0 :             jsonp_close_object( peers->http );
    3132           0 :           }
    3133             : 
    3134           0 :           if( FD_UNLIKELY( memcmp( cur->pubkey.uc, ref->pubkey.uc, 32UL ) ) ) {
    3135           0 :             jsonp_open_object( peers->http, NULL );
    3136           0 :               jsonp_ulong ( peers->http, "row_index", j );
    3137           0 :               jsonp_string( peers->http, "column_name", "Pubkey" );
    3138             : 
    3139           0 :               char pubkey_base58[ FD_BASE58_ENCODED_32_SZ ];
    3140           0 :               fd_base58_encode_32( cur->pubkey.uc, NULL, pubkey_base58 );
    3141           0 :               jsonp_string( peers->http, "new_value", pubkey_base58 );
    3142           0 :             jsonp_close_object( peers->http );
    3143           0 :           }
    3144             : 
    3145           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;
    3146           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;
    3147           0 :           if( FD_UNLIKELY( ip4_after!=ip4_before ) ) {
    3148           0 :             jsonp_open_object( peers->http, NULL );
    3149           0 :               jsonp_ulong ( peers->http, "row_index", j );
    3150           0 :               jsonp_string( peers->http, "column_name", "IP Addr" );
    3151             : 
    3152           0 :               char peer_addr[ 16 ]; /* 255.255.255.255 + '\0' */
    3153           0 :               FD_TEST( fd_cstr_printf_check( peer_addr, sizeof(peer_addr), NULL, FD_IP4_ADDR_FMT, FD_IP4_ADDR_FMT_ARGS( ip4_after ) ) );
    3154           0 :               jsonp_string( peers->http, "new_value", peer_addr );
    3155           0 :             jsonp_close_object( peers->http );
    3156           0 :           }
    3157             : 
    3158           0 :           long cur_egress_push_bps           = (long)cur->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PUSH_IDX ].rate_ema.value;
    3159           0 :           long ref_egress_push_bps           = (long)ref->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PUSH_IDX ].rate_ema.value;
    3160           0 :           long cur_ingress_push_bps          = (long)cur->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PUSH_IDX ].rate_ema.value;
    3161           0 :           long ref_ingress_push_bps          = (long)ref->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PUSH_IDX ].rate_ema.value;
    3162           0 :           long cur_egress_pull_response_bps  = (long)cur->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    3163           0 :           long ref_egress_pull_response_bps  = (long)ref->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    3164           0 :           long cur_ingress_pull_response_bps = (long)cur->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    3165           0 :           long ref_ingress_pull_response_bps = (long)ref->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    3166             : 
    3167           0 :           if( FD_UNLIKELY( ref->valid && cur_ingress_pull_response_bps!=ref_ingress_pull_response_bps ) ) {
    3168           0 :             jsonp_open_object( peers->http, NULL );
    3169           0 :               jsonp_ulong ( peers->http, "row_index", j );
    3170           0 :               jsonp_string( peers->http, "column_name", "Ingress Pull" );
    3171           0 :               jsonp_long  ( peers->http, "new_value", cur_ingress_pull_response_bps );
    3172           0 :             jsonp_close_object( peers->http );
    3173           0 :           }
    3174             : 
    3175           0 :           if( FD_UNLIKELY( ref->valid && cur_ingress_push_bps!=ref_ingress_push_bps ) ) {
    3176           0 :             jsonp_open_object( peers->http, NULL );
    3177           0 :               jsonp_ulong ( peers->http, "row_index", j );
    3178           0 :               jsonp_string( peers->http, "column_name", "Ingress Push" );
    3179           0 :               jsonp_long  ( peers->http, "new_value", cur_ingress_push_bps );
    3180           0 :             jsonp_close_object( peers->http );
    3181           0 :           }
    3182             : 
    3183           0 :           if( FD_UNLIKELY( ref->valid && cur_egress_pull_response_bps!=ref_egress_pull_response_bps ) ) {
    3184           0 :             jsonp_open_object( peers->http, NULL );
    3185           0 :               jsonp_ulong ( peers->http, "row_index", j );
    3186           0 :               jsonp_string( peers->http, "column_name", "Egress Pull" );
    3187           0 :               jsonp_long  ( peers->http, "new_value", cur_egress_pull_response_bps );
    3188           0 :             jsonp_close_object( peers->http );
    3189           0 :           }
    3190             : 
    3191           0 :           if( FD_UNLIKELY( ref->valid && cur_egress_push_bps!=ref_egress_push_bps ) ) {
    3192           0 :             jsonp_open_object( peers->http, NULL );
    3193           0 :               jsonp_ulong ( peers->http, "row_index", j );
    3194           0 :               jsonp_string( peers->http, "column_name", "Egress Push" );
    3195           0 :               jsonp_long  ( peers->http, "new_value", cur_egress_push_bps );
    3196           0 :             jsonp_close_object( peers->http );
    3197           0 :           }
    3198             : 
    3199           0 :         }
    3200           0 :       jsonp_close_array( peers->http );
    3201           0 :     jsonp_close_object( peers->http );
    3202           0 :   jsonp_close_envelope( peers->http );
    3203           0 : }
    3204             : 
    3205             : void
    3206             : fd_gui_printf_peers_viewport_request( fd_gui_peers_ctx_t *  peers,
    3207             :                                       char const *          key,
    3208             :                                       ulong                 ws_conn_id,
    3209           0 :                                       ulong                 request_id ) {
    3210           0 :   jsonp_open_envelope( peers->http, "gossip", key );
    3211           0 :     jsonp_ulong( peers->http, "id", request_id );
    3212           0 :     jsonp_open_object( peers->http, "value" );
    3213           0 :       FD_TEST( peers->scratch.viewport_cnt<=FD_GUI_PEERS_WS_VIEWPORT_MAX_SZ );
    3214           0 :       ulong start_row = peers->client_viewports[ ws_conn_id ].start_row;
    3215           0 :       for( ulong i=0UL; i<peers->scratch.viewport_cnt; i++ ) {
    3216           0 :         ulong j = start_row + i;
    3217           0 :         fd_gui_peers_row_t const * cur = &peers->scratch.viewport[ i ];
    3218             : 
    3219           0 :         char row_index_cstr[ 32 ];
    3220           0 :         FD_TEST( fd_cstr_printf_check( row_index_cstr, sizeof(row_index_cstr), NULL, "%lu", + j ) );
    3221           0 :         jsonp_open_object( peers->http, row_index_cstr );
    3222             :           /* This code should be kept in sync with updates to
    3223             :             fd_gui_peers_live_table */
    3224           0 :           if( FD_UNLIKELY( cur->stake==ULONG_MAX ) ) jsonp_long ( peers->http, "Stake", -1 );
    3225           0 :           else                                       jsonp_ulong( peers->http, "Stake", cur->stake );
    3226             : 
    3227           0 :           char pubkey_base58[ FD_BASE58_ENCODED_32_SZ ];
    3228           0 :           fd_base58_encode_32( cur->pubkey.uc, NULL, pubkey_base58 );
    3229           0 :           jsonp_string( peers->http, "Pubkey", pubkey_base58 );
    3230           0 :           jsonp_string( peers->http, "Name", cur->name );
    3231           0 :           if( FD_LIKELY( cur->country_code_idx!=UCHAR_MAX ) ) {
    3232           0 :             jsonp_string( peers->http, "Country", peers->dbip.country_code[ cur->country_code_idx ] );
    3233           0 :           } else {
    3234           0 :             jsonp_null( peers->http, "Country" );
    3235           0 :           }
    3236             : 
    3237           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;
    3238           0 :           char peer_addr[ 16 ]; /* 255.255.255.255 + '\0' */
    3239           0 :           FD_TEST( fd_cstr_printf_check( peer_addr, sizeof(peer_addr), NULL, FD_IP4_ADDR_FMT, FD_IP4_ADDR_FMT_ARGS( ip4 ) ) );
    3240           0 :           jsonp_string( peers->http, "IP Addr", peer_addr );
    3241             : 
    3242           0 :           long cur_egress_push_bps           = (long)cur->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PUSH_IDX ].rate_ema.value;
    3243           0 :           long cur_ingress_push_bps          = (long)cur->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PUSH_IDX ].rate_ema.value;
    3244           0 :           long cur_egress_pull_response_bps  = (long)cur->gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    3245           0 :           long cur_ingress_pull_response_bps = (long)cur->gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_V_PULL_RESPONSE_IDX ].rate_ema.value;
    3246             : 
    3247           0 :           jsonp_long  ( peers->http, "Ingress Pull", cur_ingress_pull_response_bps );
    3248           0 :           jsonp_long  ( peers->http, "Ingress Push", cur_ingress_push_bps );
    3249           0 :           jsonp_long  ( peers->http, "Egress Pull", cur_egress_pull_response_bps );
    3250           0 :           jsonp_long  ( peers->http, "Egress Push", cur_egress_push_bps );
    3251             : 
    3252           0 :         jsonp_close_object( peers->http );
    3253           0 :       }
    3254             : 
    3255           0 :     jsonp_close_object( peers->http );
    3256           0 :   jsonp_close_envelope( peers->http );
    3257           0 : }
    3258             : 
    3259             : void
    3260           0 : fd_gui_printf_peers_view_resize( fd_gui_peers_ctx_t *  peers, ulong sz ) {
    3261           0 :   jsonp_open_envelope( peers->http, "gossip", "peers_size_update" );
    3262           0 :     jsonp_ulong( peers->http, "value", sz );
    3263           0 :   jsonp_close_envelope( peers->http );
    3264           0 : }
    3265             : 
    3266             : void
    3267           0 : fd_gui_peers_printf_gossip_stats( fd_gui_peers_ctx_t *  peers ) {
    3268           0 :   fd_gui_peers_gossip_stats_t * cur = peers->gossip_stats;
    3269             : 
    3270           0 :   jsonp_open_envelope( peers->http, "gossip", "network_stats" );
    3271           0 :     jsonp_open_object( peers->http, "value" );
    3272             : 
    3273           0 :       jsonp_open_object( peers->http, "health" );
    3274           0 :         jsonp_ulong       ( peers->http, "num_push_messages_rx_success",            cur->network_health_push_msg_rx_success             );
    3275           0 :         jsonp_ulong       ( peers->http, "num_push_messages_rx_failure",            cur->network_health_push_msg_rx_failure             );
    3276           0 :         jsonp_ulong       ( peers->http, "num_push_entries_rx_success",             cur->network_health_push_crds_rx_success            );
    3277           0 :         jsonp_ulong       ( peers->http, "num_push_entries_rx_failure",             cur->network_health_push_crds_rx_failure            );
    3278           0 :         jsonp_ulong       ( peers->http, "num_push_entries_rx_duplicate",           cur->network_health_push_crds_rx_duplicate          );
    3279           0 :         jsonp_ulong       ( peers->http, "num_pull_response_messages_rx_success",   cur->network_health_pull_response_msg_rx_success    );
    3280           0 :         jsonp_ulong       ( peers->http, "num_pull_response_messages_rx_failure",   cur->network_health_pull_response_msg_rx_failure    );
    3281           0 :         jsonp_ulong       ( peers->http, "num_pull_response_entries_rx_success",    cur->network_health_pull_response_crds_rx_success   );
    3282           0 :         jsonp_ulong       ( peers->http, "num_pull_response_entries_rx_failure",    cur->network_health_pull_response_crds_rx_failure   );
    3283           0 :         jsonp_ulong       ( peers->http, "num_pull_response_entries_rx_duplicate",  cur->network_health_pull_response_crds_rx_duplicate );
    3284           0 :         jsonp_ulong_as_str( peers->http, "total_stake",                             cur->network_health_total_stake                     );
    3285           0 :         jsonp_ulong       ( peers->http, "total_peers",                             cur->network_health_total_peers                     );
    3286           0 :         jsonp_ulong_as_str( peers->http, "connected_stake",                         cur->network_health_connected_stake                 );
    3287           0 :         jsonp_ulong       ( peers->http, "connected_staked_peers",                  cur->network_health_connected_staked_peers          );
    3288           0 :         jsonp_ulong       ( peers->http, "connected_unstaked_peers",                cur->network_health_connected_unstaked_peers        );
    3289           0 :       jsonp_close_object( peers->http );
    3290             : 
    3291           0 :       jsonp_open_object( peers->http, "ingress" );
    3292             : 
    3293           0 :         jsonp_open_array( peers->http, "peer_names" );
    3294           0 :           for( ulong i=0UL; i<cur->network_ingress_peer_sz; i++ ) jsonp_string( peers->http, NULL, cur->network_ingress_peer_names[ i ] );
    3295           0 :         jsonp_close_array( peers->http );
    3296             : 
    3297           0 :         jsonp_open_array( peers->http, "peer_identities" );
    3298           0 :           for( ulong i=0UL; i<cur->network_ingress_peer_sz; i++ ) {
    3299           0 :             char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    3300           0 :             fd_base58_encode_32( cur->network_ingress_peer_identities[ i ].uc, NULL, identity_base58 );
    3301           0 :             jsonp_string( peers->http, NULL, identity_base58 );
    3302           0 :           }
    3303           0 :         jsonp_close_array( peers->http );
    3304             : 
    3305           0 :         jsonp_open_array( peers->http, "peer_throughput" );
    3306           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 ] );
    3307           0 :         jsonp_close_array( peers->http );
    3308           0 :         jsonp_long( peers->http, "total_throughput", cur->network_ingress_total_bytes_per_sec );
    3309           0 :       jsonp_close_object( peers->http );
    3310             : 
    3311           0 :       jsonp_open_object( peers->http, "egress" );
    3312           0 :         jsonp_open_array( peers->http, "peer_names" );
    3313           0 :           for( ulong i=0UL; i<cur->network_egress_peer_sz; i++ ) jsonp_string( peers->http, NULL, cur->network_egress_peer_names[ i ] );
    3314           0 :         jsonp_close_array( peers->http );
    3315             : 
    3316           0 :                 jsonp_open_array( peers->http, "peer_identities" );
    3317           0 :           for( ulong i=0UL; i<cur->network_egress_peer_sz; i++ ) {
    3318           0 :             char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    3319           0 :             fd_base58_encode_32( cur->network_egress_peer_identities[ i ].uc, NULL, identity_base58 );
    3320           0 :             jsonp_string( peers->http, NULL, identity_base58 );
    3321           0 :           }
    3322           0 :         jsonp_close_array( peers->http );
    3323             : 
    3324           0 :         jsonp_open_array( peers->http, "peer_throughput" );
    3325           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 ] );
    3326           0 :         jsonp_close_array( peers->http );
    3327           0 :         jsonp_long( peers->http, "total_throughput", cur->network_egress_total_bytes_per_sec );
    3328           0 :       jsonp_close_object( peers->http );
    3329             : 
    3330           0 :       jsonp_open_object( peers->http, "storage" );
    3331             :         /* since these are gauges, we don't take a diff */
    3332           0 :         jsonp_ulong( peers->http, "capacity", cur->storage_capacity );
    3333           0 :         jsonp_ulong( peers->http, "expired_count", cur->storage_expired_cnt );
    3334           0 :         jsonp_ulong( peers->http, "evicted_count", cur->storage_evicted_cnt );
    3335           0 :         jsonp_open_array( peers->http, "count" );
    3336           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_CRDS_VALUE_TYPE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->storage_active_cnt[ i ] );
    3337           0 :         jsonp_close_array( peers->http );
    3338           0 :         jsonp_open_array( peers->http, "count_tx" );
    3339           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_CRDS_VALUE_TYPE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->storage_cnt_tx[ i ] );
    3340           0 :         jsonp_close_array( peers->http );
    3341           0 :         jsonp_open_array( peers->http, "bytes_tx" );
    3342           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_CRDS_VALUE_TYPE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->storage_bytes_tx[ i ] );
    3343           0 :         jsonp_close_array( peers->http );
    3344           0 :       jsonp_close_object( peers->http );
    3345           0 :       jsonp_open_object( peers->http, "messages" );
    3346           0 :         jsonp_open_array( peers->http, "num_bytes_rx" );
    3347           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->messages_bytes_rx[ i ] );
    3348           0 :         jsonp_close_array( peers->http );
    3349           0 :         jsonp_open_array( peers->http, "num_bytes_tx" );
    3350           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->messages_bytes_tx[ i ] );
    3351           0 :         jsonp_close_array( peers->http );
    3352           0 :         jsonp_open_array( peers->http, "num_messages_rx" );
    3353           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->messages_count_rx[ i ] );
    3354           0 :         jsonp_close_array( peers->http );
    3355           0 :         jsonp_open_array( peers->http, "num_messages_tx" );
    3356           0 :           for( ulong i = 0UL; i<FD_METRICS_ENUM_GOSSIP_MESSAGE_TYPE_CNT; i++ ) jsonp_ulong( peers->http, NULL, cur->messages_count_tx[ i ] );
    3357           0 :         jsonp_close_array( peers->http );
    3358           0 :       jsonp_close_object( peers->http );
    3359           0 :     jsonp_close_object( peers->http );
    3360           0 :   jsonp_close_envelope( peers->http );
    3361           0 : }
    3362             : 
    3363             : /* fd_gui_printf_shreds_window prints the shred events inserted in
    3364             :    [after_ns,before_ns] as columnar arrays: reference values then one
    3365             :    array per column.  The events are decoded from the batches once into
    3366             :    gui->shred_scratch and printed from there; a window with more events
    3367             :    than the scratch holds (only possible for a long query_shreds range,
    3368             :    never the 50 ms broadcast) is decoded once per column instead.  The
    3369             :    two produce the same bytes: both read the same batches in the same
    3370             :    order (see test_gui_printf). */
    3371             : 
    3372             : static void
    3373           0 : fd_gui_printf_shreds_window( fd_gui_t * gui, long after_ns, long before_ns ) {
    3374           0 :   fd_gui_shred_event_iter_t it[ 1 ];
    3375             : 
    3376             :   /* find the min slot / min ts across the window (for delta encoding)
    3377             :      and decode into the scratch while it fits */
    3378           0 :   fd_gui_shred_scratch_t * sc     = gui->shred_scratch.ev;
    3379           0 :   ulong                    sc_max = gui->shred_scratch.max;
    3380           0 :   ulong                    cnt    = 0UL;
    3381           0 :   int                      fits   = 1;
    3382           0 :   ulong min_slot = ULONG_MAX;
    3383           0 :   long  min_ts   = LONG_MAX;
    3384           0 :   fd_gui_shred_event_iter_begin( gui, it, after_ns, before_ns );
    3385           0 :   while( fd_gui_shred_event_iter_next( it ) ) {
    3386           0 :     fd_gui_shred_event_t const * e = &it->event;
    3387           0 :     min_slot = fd_ulong_min( min_slot, e->slot );
    3388           0 :     min_ts   = fd_long_min ( min_ts,   e->event_time_ns );
    3389           0 :     if( FD_LIKELY( cnt<sc_max ) ) sc[ cnt ] = (fd_gui_shred_scratch_t){ .event_time_ns = e->event_time_ns, .slot = e->slot, .idx = e->idx, .event = e->event };
    3390           0 :     else                          fits = 0;
    3391           0 :     cnt++;
    3392           0 :   }
    3393           0 :   fd_gui_shred_event_iter_end( it );
    3394             : 
    3395           0 :   jsonp_ulong      ( gui->http, "reference_slot", min_slot );
    3396           0 :   jsonp_long_as_str( gui->http, "reference_ts",   min_ts   );
    3397             : 
    3398           0 :   if( FD_LIKELY( fits ) ) {
    3399           0 :     jsonp_open_array( gui->http, "slot_delta" );
    3400           0 :       for( ulong i=0UL; i<cnt; i++ ) jsonp_ulong( gui->http, NULL, (ulong)sc[ i ].slot-min_slot );
    3401           0 :     jsonp_close_array( gui->http );
    3402           0 :     jsonp_open_array( gui->http, "shred_idx" );
    3403           0 :       for( ulong i=0UL; i<cnt; i++ ) {
    3404           0 :         if( FD_LIKELY( sc[ i ].idx!=USHORT_MAX ) ) jsonp_ulong( gui->http, NULL, sc[ i ].idx );
    3405           0 :         else                                       jsonp_null ( gui->http, NULL );
    3406           0 :       }
    3407           0 :     jsonp_close_array( gui->http );
    3408           0 :     jsonp_open_array( gui->http, "event" );
    3409           0 :       for( ulong i=0UL; i<cnt; i++ ) jsonp_ulong( gui->http, NULL, sc[ i ].event );
    3410           0 :     jsonp_close_array( gui->http );
    3411           0 :     jsonp_open_array( gui->http, "event_ts_delta" );
    3412           0 :       for( ulong i=0UL; i<cnt; i++ ) jsonp_long_as_str( gui->http, NULL, sc[ i ].event_time_ns-min_ts );
    3413           0 :     jsonp_close_array( gui->http );
    3414           0 :     return;
    3415           0 :   }
    3416             : 
    3417           0 : #define SHREDS_WINDOW_ITER( code ) \
    3418           0 :   do { \
    3419           0 :     fd_gui_shred_event_iter_t _it[ 1 ]; \
    3420           0 :     fd_gui_shred_event_iter_begin( gui, _it, after_ns, before_ns ); \
    3421           0 :     while( fd_gui_shred_event_iter_next( _it ) ) { \
    3422           0 :       fd_gui_shred_event_t const * e = &_it->event; (void)e; \
    3423           0 :       ulong db_event_slot = e->slot; (void)db_event_slot; \
    3424           0 :       do { code } while(0); \
    3425           0 :     } \
    3426           0 :     fd_gui_shred_event_iter_end( _it ); \
    3427           0 :   } while(0)
    3428             : 
    3429           0 :   jsonp_open_array( gui->http, "slot_delta" );
    3430           0 :     SHREDS_WINDOW_ITER( { jsonp_ulong( gui->http, NULL, db_event_slot-min_slot ); } );
    3431           0 :   jsonp_close_array( gui->http );
    3432           0 :   jsonp_open_array( gui->http, "shred_idx" );
    3433           0 :     SHREDS_WINDOW_ITER({
    3434           0 :       if( FD_LIKELY( e->idx!=USHORT_MAX ) ) jsonp_ulong( gui->http, NULL, e->idx );
    3435           0 :       else                                        jsonp_null ( gui->http, NULL );
    3436           0 :     });
    3437           0 :   jsonp_close_array( gui->http );
    3438           0 :   jsonp_open_array( gui->http, "event" );
    3439           0 :     SHREDS_WINDOW_ITER( { jsonp_ulong( gui->http, NULL, e->event ); } );
    3440           0 :   jsonp_close_array( gui->http );
    3441           0 :   jsonp_open_array( gui->http, "event_ts_delta" );
    3442           0 :     SHREDS_WINDOW_ITER( { jsonp_long_as_str( gui->http, NULL, e->event_time_ns-min_ts ); } );
    3443           0 :   jsonp_close_array( gui->http );
    3444             : 
    3445           0 : #undef SHREDS_WINDOW_ITER
    3446           0 : }
    3447             : 
    3448             : void
    3449           0 : fd_gui_printf_shred_updates( fd_gui_t * gui, long after_ns, long before_ns ) {
    3450           0 :   jsonp_open_envelope( gui->http, "slot", "live_shreds" );
    3451           0 :     jsonp_open_object( gui->http, "value" );
    3452           0 :       fd_gui_printf_shreds_window( gui, after_ns, before_ns );
    3453           0 :     jsonp_close_object( gui->http );
    3454           0 :   jsonp_close_envelope( gui->http );
    3455           0 : }
    3456             : 
    3457             : void
    3458           0 : fd_gui_printf_shred_rebroadcast( fd_gui_t * gui, long after, long before ) {
    3459           0 :   jsonp_open_envelope( gui->http, "slot", "live_shreds" );
    3460           0 :     jsonp_open_object( gui->http, "value" );
    3461           0 :       fd_gui_printf_shreds_window( gui, after, before );
    3462           0 :     jsonp_close_object( gui->http );
    3463           0 :   jsonp_close_envelope( gui->http );
    3464           0 : }
    3465             : 
    3466             : static void
    3467             : fd_gui_timeline_limit( fd_gui_t *   gui,
    3468             :                        char const * key,
    3469           0 :                        ulong        id ) {
    3470           0 :   jsonp_open_envelope( gui->http, "timeline", key );
    3471           0 :   jsonp_ulong( gui->http, "id", id );
    3472           0 :   jsonp_open_object( gui->http, "error" );
    3473           0 :   jsonp_string( gui->http, "code", "result_limit_exceeded" );
    3474           0 :   jsonp_close_object( gui->http );
    3475           0 :   jsonp_close_envelope( gui->http );
    3476           0 : }
    3477             : 
    3478             : static int
    3479             : fd_gui_timeline_bounds( fd_gui_t * gui,
    3480           0 :                         int        dbi ) {
    3481           0 :   long lo;
    3482           0 :   long hi;
    3483           0 :   int have = fd_gui_event_bounds( gui, dbi, &lo, &hi );
    3484           0 :   if( have && hi>lo ) {
    3485           0 :     jsonp_long_as_str( gui->http, "available_start_ns", lo );
    3486           0 :     jsonp_long_as_str( gui->http, "available_end_ns", hi );
    3487           0 :   } else {
    3488           0 :     jsonp_null( gui->http, "available_start_ns" );
    3489           0 :     jsonp_null( gui->http, "available_end_ns" );
    3490           0 :   }
    3491           0 :   return have && hi>lo;
    3492           0 : }
    3493             : 
    3494             : static int
    3495             : fd_gui_timeline_slot_skipped( fd_gui_t * gui,
    3496           0 :                               ulong      slot ) {
    3497           0 :   if( gui->summary.slot_rooted!=ULONG_MAX && slot<gui->summary.slot_rooted ) {
    3498             :     /* Root advancement persists skips in both consensus modes. */
    3499           0 :     fd_gui_epoch_t const * epoch = fd_gui_get_epoch_by_slot( gui, slot );
    3500           0 :     if( epoch && slot>=epoch->start_slot && slot-epoch->start_slot<epoch->slot_cnt &&
    3501           0 :         epoch->skipped[ slot-epoch->start_slot ] ) return 1;
    3502           0 :     return fd_gui_slot_get_canon_safe( gui, slot )->skip==FD_GUI_SKIP_STATUS_FINALIZED;
    3503           0 :   }
    3504             : 
    3505           0 :   if( gui->summary.is_alpenglow ) return 0;
    3506             : 
    3507           0 :   return fd_gui_slot_is_skipped( gui, gui->summary.slot_rooted, gui->summary.slot_tower, gui->summary.slot_tower_bank_seq, slot );
    3508           0 : }
    3509             : 
    3510             : #define SORT_NAME fd_gui_timeline_event_sort
    3511           0 : #define SORT_KEY_T fd_gui_shred_event_t
    3512           0 : #define SORT_BEFORE(a,b) ((a).slot<(b).slot)
    3513             : #include "../../util/tmpl/fd_sort.c"
    3514             : 
    3515             : int
    3516             : fd_gui_printf_timeline_query_shreds( fd_gui_t * gui,
    3517             :                                      long       start,
    3518             :                                      long       end,
    3519           0 :                                      ulong      id ) {
    3520           0 :   if( FD_UNLIKELY( start<0L || end<=start || end==LONG_MAX ) ) return -1;
    3521           0 :   fd_gui_shred_event_t * events = gui->timeline_scratch.events;
    3522           0 :   fd_gui_shred_event_iter_t it;
    3523           0 :   fd_gui_shred_event_hist_iter_begin( gui, &it, start, end );
    3524           0 :   ulong n              = 0UL;
    3525           0 :   ulong reference_slot = ULONG_MAX;
    3526           0 :   long  reference_ts   = LONG_MAX;
    3527           0 :   int   limit          = 0;
    3528             :   /* Rare duplicate slot-complete markers are acceptable for monitoring;
    3529             :      return each recorded event in the requested window. */
    3530           0 :   while( fd_gui_shred_event_iter_next( &it ) ) {
    3531           0 :     if( FD_UNLIKELY( n==FD_GUI_TIMELINE_QUERY_SHRED_MAX ) ) {
    3532           0 :       limit = 1;
    3533           0 :       break;
    3534           0 :     }
    3535           0 :     events[ n++ ] = it.event;
    3536           0 :   }
    3537           0 :   fd_gui_shred_event_iter_end( &it );
    3538           0 :   if( FD_UNLIKELY( limit ) ) {
    3539           0 :     fd_gui_timeline_limit( gui, "query_shreds", id );
    3540           0 :     return 0;
    3541           0 :   }
    3542           0 :   for( ulong i=0UL; i<n; i++ ) {
    3543           0 :     reference_slot = fd_ulong_min( reference_slot, events[ i ].slot );
    3544           0 :     reference_ts   = fd_long_min( reference_ts, events[ i ].event_time_ns );
    3545           0 :   }
    3546           0 :   jsonp_open_envelope( gui->http, "timeline", "query_shreds" );
    3547           0 :   jsonp_ulong( gui->http, "id", id );
    3548           0 :   jsonp_open_object( gui->http, "value" );
    3549           0 :   jsonp_string( gui->http, "granularity", "shred" );
    3550           0 :   fd_gui_timeline_bounds( gui, FD_GUI_HIST_SHRED_EVENTS );
    3551           0 :   if( n ) {
    3552           0 :     jsonp_ulong( gui->http, "reference_slot", reference_slot );
    3553           0 :     jsonp_long_as_str( gui->http, "reference_ts", reference_ts );
    3554           0 :   } else {
    3555           0 :     jsonp_null( gui->http, "reference_slot" );
    3556           0 :     jsonp_null( gui->http, "reference_ts" );
    3557           0 :   }
    3558           0 :   jsonp_open_array( gui->http, "slot_delta" );
    3559           0 :   for( ulong i=0UL; i<n; i++ ) jsonp_ulong( gui->http, NULL, events[ i ].slot-reference_slot );
    3560           0 :   jsonp_close_array( gui->http );
    3561           0 :   jsonp_open_array( gui->http, "idx" );
    3562           0 :   for( ulong i=0UL; i<n; i++ ) {
    3563           0 :     if( events[ i ].idx==USHORT_MAX ) jsonp_null( gui->http, NULL );
    3564           0 :     else jsonp_ulong( gui->http, NULL, events[ i ].idx );
    3565           0 :   }
    3566           0 :   jsonp_close_array( gui->http );
    3567           0 :   jsonp_open_array( gui->http, "event" );
    3568           0 :   for( ulong i=0UL; i<n; i++ ) jsonp_ulong( gui->http, NULL, events[ i ].event );
    3569           0 :   jsonp_close_array( gui->http );
    3570           0 :   jsonp_open_array( gui->http, "event_ts_delta" );
    3571           0 :   for( ulong i=0UL; i<n; i++ ) jsonp_long_as_str( gui->http, NULL, events[ i ].event_time_ns-reference_ts );
    3572           0 :   jsonp_close_array( gui->http );
    3573           0 :   fd_gui_timeline_event_sort_inplace( events, n );
    3574           0 :   jsonp_open_array( gui->http, "skipped" );
    3575           0 :   ulong prev = ULONG_MAX;
    3576           0 :   for( ulong i=0UL; i<n; i++ ) {
    3577           0 :     ulong slot = events[ i ].slot;
    3578           0 :     if( slot==prev ) continue;
    3579           0 :     prev = slot;
    3580           0 :     if( fd_gui_timeline_slot_skipped( gui, slot ) ) jsonp_ulong( gui->http, NULL, slot-reference_slot );
    3581           0 :   }
    3582           0 :   jsonp_close_array( gui->http );
    3583           0 :   jsonp_close_object( gui->http );
    3584           0 :   jsonp_close_envelope( gui->http );
    3585           0 :   return 0;
    3586           0 : }
    3587             : 
    3588             : /* fd_gui_timeline_day_bounds returns the span of live day records.
    3589             :    Returns 1 and sets *start / *end if any are available, else 0. */
    3590             : 
    3591             : static int
    3592             : fd_gui_timeline_day_bounds( fd_gui_t * gui,
    3593             :                             long *     start,
    3594           0 :                             long *     end ) {
    3595           0 :   long first, last;
    3596           0 :   if( FD_UNLIKELY( !gui->db || !gui->hist ||
    3597           0 :                    !fd_gui_store_ts_live_timestamp_bounds( gui->db, FD_GUI_HIST_TIMELINE_DAY, &first, &last ) ||
    3598           0 :                    first<FD_GUI_TIMELINE_DAY_NS ) ) return 0;
    3599             : 
    3600           0 :   *start = first-FD_GUI_TIMELINE_DAY_NS;
    3601           0 :   *end   = last;
    3602           0 :   return 1;
    3603           0 : }
    3604             : 
    3605             : int
    3606             : fd_gui_printf_timeline_query_agg( fd_gui_t *   gui,
    3607             :                                   char const * key,
    3608             :                                   char const * granularity,
    3609             :                                   ulong        g,
    3610             :                                   long         reference,
    3611             :                                   ulong        count,
    3612           0 :                                   ulong        id ) {
    3613           0 :   if( FD_UNLIKELY( reference<0L || !count || count>FD_GUI_TIMELINE_QUERY_MAX_BUCKETS || g>=FD_GUI_TIMELINE_GRANULARITY_CNT ) ) return -1;
    3614           0 :   fd_gui_timeline_granularity_t const * desc = &fd_gui_timeline_granularities[ g ];
    3615           0 :   ulong ns = fd_gui_timeline_granularity_ns( g );
    3616             : 
    3617           0 :   fd_gui_timeline_query_bucket_t * b = gui->timeline_scratch.buckets;
    3618           0 :   for( ulong i=0UL; i<count; i++ ) memset( b[ i ].fields, 0xFF, sizeof(b[ i ].fields) );
    3619             : 
    3620             :   /* The buckets are visited in ascending time order, so the record for
    3621             :      the previous bucket's day is reused until the query crosses into
    3622             :      the next day. */
    3623             : 
    3624           0 :   ulong stored      = desc->stored_idx;
    3625           0 :   ulong step        = fd_gui_timeline_stored_granularity_ns[ stored ];
    3626           0 :   ulong cur_day_idx = ULONG_MAX;
    3627           0 :   fd_gui_timeline_day_t const * cur_day = NULL;
    3628           0 :   for( ulong i=0UL; i<count; i++ ) {
    3629           0 :     for( ulong j=0UL; j<desc->merge_cnt; j++ ) {
    3630           0 :       ulong ts      = (ulong)reference + i*ns + j*step;
    3631           0 :       ulong day_idx = ts/(ulong)FD_GUI_TIMELINE_DAY_NS;
    3632           0 :       if( FD_UNLIKELY( day_idx!=cur_day_idx ) ) {
    3633           0 :         cur_day_idx = day_idx;
    3634           0 :         cur_day     = fd_gui_timeline_day_get( gui, day_idx );
    3635           0 :       }
    3636           0 :       if( FD_UNLIKELY( !cur_day ) ) continue;
    3637           0 :       ulong idx = (ts%(ulong)FD_GUI_TIMELINE_DAY_NS) / step;
    3638           0 :       for( int f=0; f<FD_GUI_TIMELINE_FIELD_CNT; f++ ) {
    3639           0 :         b[ i ].fields[ f ] = fd_gui_timeline_combine( b[ i ].fields[ f ], fd_gui_timeline_field_get( cur_day, (int)stored, f, idx ), f );
    3640           0 :       }
    3641           0 :     }
    3642           0 :   }
    3643             : 
    3644           0 :   jsonp_open_envelope( gui->http, "timeline", key );
    3645           0 :   jsonp_ulong( gui->http, "id", id );
    3646           0 :   jsonp_open_object( gui->http, "value" );
    3647           0 :   jsonp_string( gui->http, "granularity", granularity );
    3648           0 :   jsonp_long_as_str( gui->http, "reference_ts_ns", reference );
    3649           0 :   long avail_start, avail_end;
    3650           0 :   if( FD_LIKELY( fd_gui_timeline_day_bounds( gui, &avail_start, &avail_end ) ) ) {
    3651           0 :     jsonp_long_as_str( gui->http, "available_start_ns", avail_start );
    3652           0 :     jsonp_long_as_str( gui->http, "available_end_ns", avail_end );
    3653           0 :   } else {
    3654           0 :     jsonp_null( gui->http, "available_start_ns" );
    3655           0 :     jsonp_null( gui->http, "available_end_ns" );
    3656           0 :   }
    3657           0 : #define AGG_ARRAY(name,field,string) do { \
    3658           0 :   jsonp_open_array( gui->http, name ); \
    3659           0 :   for( ulong i=0UL; i<count; i++ ) { \
    3660           0 :     ulong v = b[ i ].fields[ FD_GUI_TIMELINE_FIELD_##field ]; \
    3661           0 :     if( v==ULONG_MAX ) jsonp_null( gui->http, NULL ); \
    3662           0 :     else if( string ) jsonp_ulong_as_str( gui->http, NULL, v ); \
    3663           0 :     else jsonp_ulong( gui->http, NULL, v ); \
    3664           0 :   } \
    3665           0 :   jsonp_close_array( gui->http ); \
    3666           0 : } while(0)
    3667           0 :   if( !strcmp( key, "query_agg_compute" ) ) {
    3668           0 :     AGG_ARRAY( "compute_units", COMPUTE_UNITS, 0 );
    3669           0 :     ulong max = ULONG_MAX;
    3670           0 :     for( ulong i=0UL; i<count; i++ ) {
    3671           0 :       max = fd_gui_timeline_combine( max, b[ i ].fields[ FD_GUI_TIMELINE_FIELD_MAX_COMPUTE ], FD_GUI_TIMELINE_FIELD_MAX_COMPUTE );
    3672           0 :     }
    3673           0 :     if( max==ULONG_MAX ) jsonp_null( gui->http, "max_compute_units" );
    3674           0 :     else jsonp_ulong( gui->http, "max_compute_units", max );
    3675           0 :   } else if( !strcmp( key, "query_agg_revenue" ) ) {
    3676           0 :     AGG_ARRAY( "txn_fees", TXN_FEES, 1 );
    3677           0 :     AGG_ARRAY( "prio_fees", PRIO_FEES, 1 );
    3678           0 :     AGG_ARRAY( "tips", TIPS, 1 );
    3679           0 :   } else if( !strcmp( key, "query_agg_txn" ) ) {
    3680           0 :     AGG_ARRAY( "success_nonvote_transactions", NONVOTE_SUCCESS, 0 );
    3681           0 :     AGG_ARRAY( "failed_nonvote_transactions", NONVOTE_FAILED, 0 );
    3682           0 :     AGG_ARRAY( "success_vote_transactions", VOTE_SUCCESS, 0 );
    3683           0 :     AGG_ARRAY( "failed_vote_transactions", VOTE_FAILED, 0 );
    3684           0 :   }
    3685           0 : #undef AGG_ARRAY
    3686           0 :   jsonp_close_object( gui->http );
    3687           0 :   jsonp_close_envelope( gui->http );
    3688           0 :   return 0;
    3689           0 : }
    3690             : 
    3691             : void
    3692             : fd_gui_peers_printf_wfs_add( fd_gui_peers_ctx_t * peers,
    3693             :                              ulong const *        idxs,
    3694           0 :                              ulong                cnt ) {
    3695           0 :   jsonp_open_envelope( peers->http, "wait_for_supermajority", "peer_add" );
    3696           0 :     jsonp_open_array( peers->http, "value" );
    3697           0 :       for( ulong i=0UL; i<cnt; i++ ) {
    3698           0 :         fd_gui_wfs_peer_t * wp = &peers->wfs_peers[ idxs[ i ] ];
    3699           0 :         char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    3700           0 :         fd_base58_encode_32( wp->identity_key.uc, NULL, identity_base58 );
    3701           0 :         jsonp_string( peers->http, NULL, identity_base58 );
    3702           0 :       }
    3703           0 :     jsonp_close_array( peers->http );
    3704           0 :   jsonp_close_envelope( peers->http );
    3705           0 : }
    3706             : 
    3707             : void
    3708             : fd_gui_peers_printf_wfs_remove( fd_gui_peers_ctx_t * peers,
    3709             :                                 ulong const *        idxs,
    3710           0 :                                 ulong                cnt ) {
    3711           0 :   jsonp_open_envelope( peers->http, "wait_for_supermajority", "peer_remove" );
    3712           0 :     jsonp_open_array( peers->http, "value" );
    3713           0 :       for( ulong i=0UL; i<cnt; i++ ) {
    3714           0 :         fd_gui_wfs_peer_t * wp = &peers->wfs_peers[ idxs[ i ] ];
    3715           0 :         char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    3716           0 :         fd_base58_encode_32( wp->identity_key.uc, NULL, identity_base58 );
    3717           0 :         jsonp_string( peers->http, NULL, identity_base58 );
    3718           0 :       }
    3719           0 :     jsonp_close_array( peers->http );
    3720           0 :   jsonp_close_envelope( peers->http );
    3721           0 : }
    3722             : 
    3723             : void
    3724           0 : fd_gui_peers_printf_wfs_stakes( fd_gui_peers_ctx_t * peers ) {
    3725           0 :   jsonp_open_envelope( peers->http, "wait_for_supermajority", "stakes" );
    3726           0 :     jsonp_open_object( peers->http, "value" );
    3727             : 
    3728           0 :       jsonp_open_array( peers->http, "staked_pubkeys" );
    3729           0 :         for( ulong i=0UL; i<peers->wfs_peers_cnt; i++ ) {
    3730           0 :           char identity_base58[ FD_BASE58_ENCODED_32_SZ ];
    3731           0 :           fd_base58_encode_32( peers->wfs_peers[ i ].identity_key.uc, NULL, identity_base58 );
    3732           0 :           jsonp_string( peers->http, NULL, identity_base58 );
    3733           0 :         }
    3734           0 :       jsonp_close_array( peers->http );
    3735             : 
    3736           0 :       jsonp_open_array( peers->http, "staked_lamports" );
    3737           0 :         for( ulong i=0UL; i<peers->wfs_peers_cnt; i++ ) {
    3738           0 :           jsonp_ulong_as_str( peers->http, NULL, peers->wfs_peers[ i ].stake );
    3739           0 :         }
    3740           0 :       jsonp_close_array( peers->http );
    3741             : 
    3742           0 :       jsonp_open_array( peers->http, "infos" );
    3743           0 :         for( ulong i=0UL; i<peers->wfs_peers_cnt; i++ ) {
    3744           0 :           fd_gui_config_parse_info_t * info =
    3745           0 :               fd_gui_peers_node_info_map_ele_query(
    3746           0 :                   peers->node_info_map, &peers->wfs_peers[ i ].identity_key, NULL, peers->node_info_pool );
    3747           0 :           if( info && !info->cleared ) {
    3748           0 :             jsonp_open_object( peers->http, NULL );
    3749           0 :               jsonp_string( peers->http, "name",             info->name );
    3750           0 :               jsonp_string( peers->http, "details",          info->details );
    3751           0 :               jsonp_string( peers->http, "website",          info->website );
    3752           0 :               jsonp_string( peers->http, "icon_url",         info->icon_uri );
    3753           0 :               jsonp_string( peers->http, "keybase_username", info->keybase_username );
    3754           0 :             jsonp_close_object( peers->http );
    3755           0 :           } else {
    3756           0 :             jsonp_null( peers->http, NULL );
    3757           0 :           }
    3758           0 :         }
    3759           0 :       jsonp_close_array( peers->http );
    3760             : 
    3761           0 :     jsonp_close_object( peers->http );
    3762           0 :   jsonp_close_envelope( peers->http );
    3763           0 : }

Generated by: LCOV version 1.14