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

Generated by: LCOV version 1.14