LCOV - code coverage report
Current view: top level - disco/gui - fd_gui_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 742 0.0 %
Date: 2026-10-22 18:10:43 Functions: 0 48 0.0 %

          Line data    Source code
       1             : /* The frontend assets are pre-built and statically compiled into the
       2             :    binary here.  To regenerate them, run
       3             : 
       4             :     $ git clone https://github.com/firedancer-io/firedancer-frontend.git frontend
       5             :     $ make frontend
       6             : 
       7             :    from the repository root. */
       8             : 
       9             : #include "../../disco/gui/generated/http_import_dist.h"
      10             : 
      11             : /* STATIC_FILES is the null-terminated list of frontend assets baked into
      12             :    the binary.  It is defined in generated/http_import_dist.c and accessed
      13             :    in the gui_http_request callback. */
      14             : 
      15             : #include <sys/socket.h> /* SOCK_CLOEXEC, SOCK_NONBLOCK needed for seccomp filter */
      16             : 
      17             : #include <linux/futex.h>
      18             : #include "generated/fd_gui_tile_seccomp.h"
      19             : 
      20             : #include "../../disco/tiles.h"
      21             : #include "../../disco/keyguard/fd_keyload.h"
      22             : #include "../../disco/keyguard/fd_keyswitch.h"
      23             : #include "../../disco/gui/fd_gui.h"
      24             : #include "../../disco/gui/fd_gui_store.h"
      25             : #include "../../disco/gui/fd_gui_hist.h"
      26             : #include "../../discof/replay/fd_execrp.h"
      27             : #include "../../disco/metrics/fd_metrics.h"
      28             : #include "../../disco/net/fd_net_tile.h"
      29             : #include "../../disco/waker/fd_waker.h"
      30             : #include "../../disco/sleep/fd_sleep.h"
      31             : #include "../../disco/fd_clock_tile.h"
      32             : #include "../../discof/genesis/fd_genesi_tile.h" // TODO: Layering violation
      33             : #include "../../ballet/sha256/fd_sha256.h"
      34             : #include "../../ballet/base64/fd_base64.h"
      35             : #include "../../waltz/http/fd_http_server.h"
      36             : #include "../../waltz/http/fd_http_server_private.h"
      37             : #include "../../discof/repair/fd_repair.h"
      38             : #include "../../discof/replay/fd_replay_tile.h"
      39             : #include "../../discof/votor/fd_votor_tile.h"
      40             : #include "../../disco/shred/fd_shred_tile.h"
      41             : #include "../../flamenco/accdb/fd_accdb_shmem.h"
      42             : 
      43             : /* We're not going to use the TOWER DB, but need to keep its metric
      44             :    for backwards compatibility, so then we need an explicit mapping. */
      45             : 
      46             : FD_STATIC_ASSERT( FD_METRICS_ENUM_GUI_DB_TYPE_CNT==FD_GUI_HIST_CNT+1UL, gui_db_enum );
      47             : 
      48             : static ulong const gui_db_type_idx[ FD_GUI_HIST_CNT ] = {
      49             :   [ FD_GUI_HIST_SCHEDULER_COUNTS ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_SCHEDULER_COUNTS_IDX,
      50             :   [ FD_GUI_HIST_TILE_TIMERS      ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_TILE_TIMERS_IDX,
      51             :   [ FD_GUI_HIST_SHRED_EVENTS     ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_SHRED_EVENTS_IDX,
      52             :   [ FD_GUI_HIST_TXN_START        ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_TXN_START_IDX,
      53             :   [ FD_GUI_HIST_TXN_END          ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_TXN_END_IDX,
      54             :   [ FD_GUI_HIST_SLOT             ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_SLOT_IDX,
      55             :   [ FD_GUI_HIST_LEADER_SLOT      ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_LEADER_SLOT_IDX,
      56             :   [ FD_GUI_HIST_EPOCH            ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_EPOCH_IDX,
      57             :   [ FD_GUI_HIST_TILE_STATS       ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_TILE_STATS_IDX,
      58             :   [ FD_GUI_HIST_TXN_WATERFALL    ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_TXN_WATERFALL_IDX,
      59             :   [ FD_GUI_HIST_TIMELINE_DAY     ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_TIMELINE_DAY_IDX,
      60             :   [ FD_GUI_HIST_REPLAY_TXN       ] = FD_METRICS_ENUM_GUI_DB_TYPE_V_REPLAY_TXN_IDX,
      61             : };
      62             : 
      63           0 : #define IN_KIND_PACK_EXECLE   ( 2UL)
      64           0 : #define IN_KIND_PACK_POH      ( 3UL)
      65           0 : #define IN_KIND_EXECLE_POH    ( 4UL)
      66           0 : #define IN_KIND_SHRED_OUT     ( 5UL) /* firedancer only */
      67           0 : #define IN_KIND_GOSSVF_GUI    ( 6UL) /* firedancer only */
      68           0 : #define IN_KIND_GOSSIP_GUI    ( 7UL) /* firedancer only */
      69           0 : #define IN_KIND_GOSSIP_OUT    ( 8UL) /* firedancer only */
      70           0 : #define IN_KIND_SNAPCT        ( 9UL) /* firedancer only */
      71           0 : #define IN_KIND_REPAIR_NET    (10UL) /* firedancer only */
      72           0 : #define IN_KIND_REPLAY_OUT    (12UL) /* firedancer only */
      73           0 : #define IN_KIND_EPOCH         (13UL) /* firedancer only */
      74           0 : #define IN_KIND_GENESI_OUT    (14UL) /* firedancer only */
      75           0 : #define IN_KIND_SNAPIN        (15UL) /* firedancer only */
      76           0 : #define IN_KIND_EXECRP_REPLAY (16UL) /* firedancer only */
      77           0 : #define IN_KIND_BUNDLE        (17UL)
      78           0 : #define IN_KIND_SNAPIN_MANIF  (18UL) /* firedancer only */
      79           0 : #define IN_KIND_SNAPSV_OUT    (19UL) /* firedancer only */
      80           0 : #define IN_KIND_DIAG          (20UL) /* firedancer only */
      81           0 : #define IN_KIND_VOTOR_OUT     (21UL) /* firedancer only */
      82             : 
      83             : FD_IMPORT_BINARY( firedancer_svg, "book/public/fire.svg" );
      84             : 
      85           0 : #define FD_HTTP_SERVER_GUI_MAX_REQUEST_LEN       65536
      86           0 : #define FD_HTTP_SERVER_GUI_MAX_WS_RECV_FRAME_LEN 65536
      87           0 : #define FD_HTTP_SERVER_GUI_MAX_WS_SEND_FRAME_CNT 8192
      88             : 
      89             : #define FD_GUI_TIMELINE_RAW_RESPONSE_MAX (32UL<<20)
      90             : FD_STATIC_ASSERT( FD_GUI_TIMELINE_QUERY_SHRED_MAX*56UL+4096UL<=FD_GUI_TIMELINE_RAW_RESPONSE_MAX, shred_response_bound );
      91             : /* Agg txn has four numeric arrays, and agg revenue has three
      92             :    ulong-string arrays: at most 4*21=84 or 3*23=69 bytes per bucket
      93             :    including commas, within the shared 512-byte budget. */
      94             : FD_STATIC_ASSERT( FD_GUI_TIMELINE_QUERY_MAX_BUCKETS*512UL+4096UL<=FD_GUI_TIMELINE_RAW_RESPONSE_MAX, agg_response_bound );
      95             : FD_STATIC_ASSERT( 2UL*FD_GUI_TIMELINE_RAW_RESPONSE_MAX+(FD_GUI_TIMELINE_RAW_RESPONSE_MAX>>8)<FD_GUI_HTTP_MIN_SEND_BUFFER_SZ,
      96             :                   compressed_response_bound );
      97             : 
      98             : static fd_http_server_params_t
      99           0 : derive_http_params( fd_topo_tile_t const * tile ) {
     100           0 :   if( FD_UNLIKELY( tile->gui.send_buffer_size_mb<(FD_GUI_HTTP_MIN_SEND_BUFFER_SZ>>20) || tile->gui.send_buffer_size_mb>(ULONG_MAX>>20) ) ) {
     101           0 :     FD_LOG_ERR(( "[tiles.gui.send_buffer_size_mb] must be at least %lu MiB and fit in ulong bytes", FD_GUI_HTTP_MIN_SEND_BUFFER_SZ>>20 ));
     102           0 :   }
     103           0 :   return (fd_http_server_params_t) {
     104           0 :     .max_connection_cnt    = tile->gui.max_http_connections,
     105           0 :     .max_ws_connection_cnt = tile->gui.max_websocket_connections,
     106           0 :     .max_request_len       = FD_HTTP_SERVER_GUI_MAX_REQUEST_LEN,
     107           0 :     .max_ws_recv_frame_len = FD_HTTP_SERVER_GUI_MAX_WS_RECV_FRAME_LEN,
     108           0 :     .max_ws_send_frame_cnt = FD_HTTP_SERVER_GUI_MAX_WS_SEND_FRAME_CNT,
     109           0 :     .outgoing_buffer_sz    = tile->gui.send_buffer_size_mb * (1UL<<20UL),
     110           0 :     .send_buffer_sz        = 4UL<<20UL,
     111           0 :     .compress_websocket    = tile->gui.websocket_compression,
     112           0 :   };
     113           0 : }
     114             : 
     115             : struct fd_gui_in_ctx {
     116             :   fd_wksp_t * mem;
     117             :   ulong       mtu;
     118             :   ulong       chunk0;
     119             :   ulong       wmark;
     120             : };
     121             : 
     122             : typedef struct fd_gui_in_ctx fd_gui_in_ctx_t;
     123             : 
     124             : struct fd_gui_out_ctx {
     125             :   ulong       idx;
     126             :   fd_wksp_t * mem;
     127             :   ulong       chunk0;
     128             :   ulong       wmark;
     129             :   ulong       chunk;
     130             : };
     131             : 
     132             : typedef struct fd_gui_out_ctx fd_gui_out_ctx_t;
     133             : 
     134             : typedef struct {
     135             :   fd_topo_t const * topo;
     136             :   ulong             seed;
     137             : 
     138             :   int snapshots_enabled;
     139             : 
     140             :   fd_gui_t * gui;
     141             :   fd_gui_store_t * db;
     142             :   fd_gui_peers_ctx_t * peers;
     143             : 
     144             :   ulong in_cnt;
     145             :   ulong idle_cnt;
     146             : 
     147             :   long deadline_ticks;
     148             : 
     149             :   fd_clock_tile_t clock[1];
     150             : 
     151             :   ulong chunk;
     152             :   union {
     153             :     struct {
     154             :       ulong slot;
     155             :       ulong shred_idx;
     156             :     } repair_net;
     157             : 
     158             :     fd_gui_gossip_bw_rec_t gossip_bw[ FD_GUI_GOSSIP_BW_REC_MAX ];
     159             : 
     160             :     struct {
     161             :       fd_snapsv_msg_t snapsv_out;
     162             :       int             snapsv_eom;
     163             :     };
     164             : 
     165             :     fd_votor_msg_t votor_out;
     166             :   } parsed;
     167             : 
     168             :   fd_http_server_t * gui_server;
     169             : 
     170             :   char index_html_etag[ 3 ][ 24 ]; /* plain, zstd, gzip */
     171             :   char index_html_link[ 1024 ];
     172             : 
     173             : 
     174             :   /* The tile is a waker client: the server runs in epoll mode on the
     175             :      inherited inner epoll fd and fd servicing is gated on the waker
     176             :      readiness fseq.  See fd_waker.h. */
     177             :   ulong   waker_client_idx;
     178             :   ulong * waker_fseq;
     179             : 
     180             :   fd_keyswitch_t * keyswitch;
     181             :   uchar const *    identity_key;
     182             : 
     183             :   int               has_vote_key;
     184             :   fd_pubkey_t const vote_key[ 1UL ];
     185             : 
     186             :   ulong           in_kind[ FD_TOPO_MAX_TILE_IN_LINKS ];
     187             :   int             in_reliable[ FD_TOPO_MAX_TILE_IN_LINKS ];
     188             :   ulong           in_bank_idx[ FD_TOPO_MAX_TILE_IN_LINKS ];
     189             :   fd_gui_in_ctx_t in[ FD_TOPO_MAX_TILE_IN_LINKS ];
     190             : } fd_gui_ctx_t;
     191             : 
     192             : FD_FN_CONST static inline ulong
     193           0 : scratch_align( void ) {
     194           0 :   ulong a = alignof( fd_gui_ctx_t );
     195           0 :   a = fd_ulong_max( a, fd_http_server_align() );
     196           0 :   a = fd_ulong_max( a, fd_gui_peers_align() );
     197           0 :   a = fd_ulong_max( a, fd_gui_align() );
     198           0 :   return a;
     199           0 : }
     200             : 
     201             : static inline ulong
     202           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
     203           0 :   fd_http_server_params_t http_param = derive_http_params( tile );
     204           0 :   ulong http_fp = fd_http_server_footprint( http_param );
     205           0 :   if( FD_UNLIKELY( !http_fp ) ) FD_LOG_ERR(( "Invalid [tiles.gui] config parameters" ));
     206             : 
     207           0 :   ulong l = FD_LAYOUT_INIT;
     208           0 :   l = FD_LAYOUT_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     209           0 :   l = FD_LAYOUT_APPEND( l, fd_http_server_align(),  http_fp );
     210           0 :   l = FD_LAYOUT_APPEND( l, fd_gui_peers_align(),    fd_gui_peers_footprint( http_param.max_ws_connection_cnt ) );
     211           0 :   l = FD_LAYOUT_APPEND( l, fd_gui_align(),          fd_gui_footprint( tile->gui.tile_cnt, tile->gui.max_live_slots, tile->gui.max_txn_per_slot ) );
     212           0 :   l = FD_LAYOUT_APPEND( l, fd_gui_store_align(),    fd_gui_store_footprint( tile->gui.db_size_gib<<30, fd_gui_hist_db_cnt(), fd_gui_hist_db_descs( tile->gui.db_size_gib<<30 ) ) );
     213           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
     214           0 : }
     215             : 
     216             : static inline void
     217           0 : during_housekeeping( fd_gui_ctx_t * ctx ) {
     218           0 :   if( FD_UNLIKELY( fd_clock_tile_recal_due( ctx->clock ) ) ) {
     219           0 :     fd_clock_tile_recal( ctx->clock );
     220           0 :   }
     221             : 
     222           0 :   if( FD_UNLIKELY( fd_keyswitch_state_query( ctx->keyswitch )==FD_KEYSWITCH_STATE_SWITCH_PENDING ) ) {
     223           0 :     fd_gui_set_identity( ctx->gui, ctx->keyswitch->bytes );
     224           0 :     if( FD_LIKELY( !ctx->gui->summary.is_alpenglow ) ) fd_gui_peers_handle_identity_change( ctx->peers );
     225           0 :     fd_keyswitch_state( ctx->keyswitch, FD_KEYSWITCH_STATE_COMPLETED );
     226           0 :   }
     227           0 : }
     228             : 
     229             : static inline void
     230             : gui_db_metric_copy( ulong         off,
     231           0 :                     ulong const * values ) {
     232           0 :   for( ulong i=0UL; i<FD_GUI_HIST_CNT; i++ ) fd_metrics_tl[ off+gui_db_type_idx[ i ] ] = values[ i ];
     233           0 : }
     234             : 
     235             : static inline void
     236           0 : metrics_write( fd_gui_ctx_t * ctx ) {
     237           0 :   FD_MGAUGE_SET( GUI, CONN_OPEN,           ctx->gui_server->metrics.connection_cnt    );
     238           0 :   FD_MGAUGE_SET( GUI, WEBSOCKET_CONN_OPEN, ctx->gui_server->metrics.ws_connection_cnt );
     239             : 
     240           0 :   FD_MCNT_SET( GUI, WEBSOCKET_FRAME_TX, ctx->gui_server->metrics.frames_written );
     241           0 :   FD_MCNT_SET( GUI, WEBSOCKET_FRAME_RX, ctx->gui_server->metrics.frames_read    );
     242             : 
     243           0 :   FD_MCNT_SET( GUI, CONN_TX_BYTES, ctx->gui_server->metrics.bytes_written );
     244           0 :   FD_MCNT_SET( GUI, CONN_RX_BYTES, ctx->gui_server->metrics.bytes_read    );
     245             : 
     246           0 :   FD_MGAUGE_SET( GUI, DISK_ALLOCATED_BYTES, fd_gui_store_file_sz( ctx->db ) );
     247             : 
     248           0 :   ulong db_cnt = fd_gui_store_cnt( ctx->db );
     249             : 
     250           0 :   ulong used_bytes  [ FD_GUI_HIST_CNT ];
     251           0 :   ulong cap_bytes   [ FD_GUI_HIST_CNT ]; ulong free_bytes  [ FD_GUI_HIST_CNT ];
     252           0 :   ulong used_slots  [ FD_GUI_HIST_CNT ];
     253           0 :   ulong cap_slots   [ FD_GUI_HIST_CNT ]; ulong free_slots  [ FD_GUI_HIST_CNT ];
     254           0 :   memset( used_bytes, 0, sizeof(used_bytes) );
     255           0 :   memset( cap_bytes,  0, sizeof(cap_bytes)  ); memset( free_bytes, 0, sizeof(free_bytes) );
     256           0 :   memset( used_slots, 0, sizeof(used_slots) );
     257           0 :   memset( cap_slots,  0, sizeof(cap_slots)  ); memset( free_slots, 0, sizeof(free_slots) );
     258             : 
     259           0 :   for( ulong i=0UL; i<db_cnt; i++ ) {
     260           0 :     fd_gui_store_ring_stats( ctx->db, i,
     261           0 :                              &used_bytes[ i ],
     262           0 :                              &cap_bytes[ i ],  &free_bytes[ i ],
     263           0 :                              &used_slots[ i ],
     264           0 :                              &cap_slots[ i ],  &free_slots[ i ] );
     265           0 :   }
     266             : 
     267           0 :   gui_db_metric_copy( MIDX( GAUGE, GUI, DB_USED_BYTES       ), used_bytes );
     268           0 :   gui_db_metric_copy( MIDX( GAUGE, GUI, DB_ALLOCATED_BYTES  ), cap_bytes  );
     269           0 :   FD_MGAUGE_SET( GUI, DB_FREE_BYTES, fd_gui_store_free_region_cnt( ctx->db )*FD_GUI_STORE_REGION_SZ ); /* shared by every ring */
     270           0 :   gui_db_metric_copy( MIDX( GAUGE, GUI, DB_RECORD_USED      ), used_slots );
     271           0 :   gui_db_metric_copy( MIDX( GAUGE, GUI, DB_RECORD_ALLOCATED ), cap_slots  );
     272             : 
     273           0 :   fd_gui_store_metrics_t const * dm = fd_gui_store_metrics( ctx->db );
     274           0 :   fd_gui_hist_metrics_t const * hist = fd_gui_hist_metrics( ctx->gui );
     275           0 :   static ulong const zero_hist_metrics[ FD_GUI_HIST_CNT ] = { 0UL };
     276           0 :   ulong const * hist_map_full = hist ? hist->map_full : zero_hist_metrics;
     277           0 :   ulong const * hist_reserves = hist ? hist->reserves  : zero_hist_metrics;
     278           0 :   gui_db_metric_copy( MIDX( COUNTER, GUI, DB_KV_QUERIED                   ), dm->kv_lookups      );
     279           0 :   gui_db_metric_copy( MIDX( COUNTER, GUI, DB_TIME_SERIES_RECORD_APPENDED  ), dm->ts_appends      );
     280           0 :   gui_db_metric_copy( MIDX( COUNTER, GUI, DB_TIME_SERIES_SCANNED          ), dm->ts_reads        );
     281           0 :   gui_db_metric_copy( MIDX( COUNTER, GUI, DB_TIME_SERIES_RECORD_READ      ), dm->ts_read_records );
     282           0 :   gui_db_metric_copy( MIDX( COUNTER, GUI, DB_RECORD_EVICTED               ), dm->evict_records   );
     283           0 :   gui_db_metric_copy( MIDX( COUNTER, GUI, DB_EVICTION_PASS_COMPLETED      ), dm->evicts          );
     284           0 :   gui_db_metric_copy( MIDX( COUNTER, GUI, DB_REGION_CLAIMED               ), dm->region_grows    );
     285           0 :   gui_db_metric_copy( MIDX( COUNTER, GUI, DB_REGION_RELEASED              ), dm->region_reclaims );
     286           0 :   gui_db_metric_copy( MIDX( COUNTER, GUI, DB_RECORD_DROPPED               ), hist_map_full       );
     287           0 :   gui_db_metric_copy( MIDX( COUNTER, GUI, DB_FORCED_EVICT_WRITE_COMPLETED ), hist_reserves       );
     288           0 : }
     289             : 
     290             : static inline void
     291             : deadline_update( fd_gui_ctx_t * ctx,
     292           0 :                  long           now ) {
     293           0 :   long due = fd_long_min( fd_gui_next_deadline( ctx->gui ), fd_gui_peers_next_deadline( ctx->peers ) );
     294           0 :   ctx->deadline_ticks = due-now>=FD_SLEEP_PARK_CAP_NS ? LONG_MAX : fd_clock_tile_wallclock_to_tickcount( ctx->clock, due );
     295           0 : }
     296             : 
     297             : static long
     298           0 : next_deadline( fd_gui_ctx_t const * ctx ) {
     299           0 :   return ctx->deadline_ticks;
     300           0 : }
     301             : 
     302             : static void
     303             : before_credit( fd_gui_ctx_t *      ctx,
     304             :                fd_stem_context_t * stem,
     305           0 :                int *               charge_busy ) {
     306           0 :   ctx->idle_cnt++;
     307           0 :   int due = stem->now>=ctx->deadline_ticks;
     308           0 :   if( FD_LIKELY( ctx->idle_cnt<2UL*ctx->in_cnt && !due ) ) return;
     309           0 :   ctx->idle_cnt = 0UL;
     310             : 
     311           0 :   int charge_busy_server = 0;
     312           0 :   long now = fd_clock_tile_now( ctx->clock );
     313             :   /* Wake protocol (fd_waker.h): only service fds when the waker
     314             :      raised our readiness word.  Clear FIRST, service a bounded
     315             :      amount, rearm LAST.  The drain is deliberately bounded (gui is
     316             :      a reliable consumer of hot links; unbounded fd work here would
     317             :      backpressure replay): EPOLL_CTL_MOD re-polls the inner set
     318             :      immediately, so leftover or raced readiness re-fires the outer
     319             :      set and servicing resumes next iteration. */
     320           0 :   if( FD_UNLIKELY( fd_fseq_query( ctx->waker_fseq )==1UL ) ) {
     321           0 :     fd_fseq_update( ctx->waker_fseq, 0UL );
     322             :     /* 8 matches a browser's per-host parallel connection budget */
     323           0 :     charge_busy_server = fd_http_server_epoll_poll( ctx->gui_server, 8UL );
     324           0 :     fd_waker_client_rearm( ctx->waker_client_idx );
     325           0 :   }
     326             : 
     327           0 :   int charge_poll = 0;
     328           0 :   charge_poll |= fd_gui_poll( ctx->gui, now );
     329           0 :   charge_poll |= fd_gui_peers_poll( ctx->peers, now );
     330             : 
     331           0 :   deadline_update( ctx, now );
     332             : 
     333           0 :   *charge_busy = charge_busy_server | charge_poll;
     334           0 : }
     335             : 
     336             : static int
     337             : before_frag( fd_gui_ctx_t * ctx,
     338             :              ulong          in_idx,
     339             :              ulong          seq,
     340           0 :              ulong          sig ) {
     341           0 :   (void)seq;
     342             : 
     343           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_PACK_POH && sig==FD_PACK_MSG_REDUCE_MB_BOUND ) ) return 1;
     344           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_EXECRP_REPLAY && sig>>32!=FD_EXECRP_TT_TXN_EXEC ) ) return 1;
     345             : 
     346           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_GOSSIP_OUT &&
     347           0 :                  (sig==FD_GOSSIP_UPDATE_TAG_WFS_DONE || sig==FD_GOSSIP_UPDATE_TAG_PEER_SATURATED) ) ) return 1;
     348           0 :   return 0;
     349           0 : }
     350             : 
     351             : static inline void
     352             : during_frag( fd_gui_ctx_t * ctx,
     353             :              ulong          in_idx,
     354             :              ulong          seq FD_PARAM_UNUSED,
     355             :              ulong          sig,
     356             :              ulong          chunk,
     357             :              ulong          sz,
     358           0 :              ulong          ctl ) {
     359           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[ in_idx ].mem, chunk );
     360             : 
     361           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_EPOCH ) ) {
     362           0 :     fd_epoch_info_msg_t * epoch_info = (fd_epoch_info_msg_t *)src;
     363           0 :     FD_TEST( epoch_info->staked_vote_cnt<=MAX_STAKE_WEIGHTS );
     364           0 :     FD_TEST( epoch_info->staked_id_cnt<=MAX_STAKE_WEIGHTS );
     365           0 :     sz = fd_epoch_info_msg_sz( epoch_info->staked_vote_cnt, epoch_info->staked_id_cnt );
     366           0 :   }
     367             : 
     368           0 :   if( FD_UNLIKELY( ctx->in_kind[ in_idx ]==IN_KIND_GENESI_OUT ) ) {
     369           0 :     sz = sig;
     370           0 :   }
     371             : 
     372           0 :   if( FD_UNLIKELY( ctx->in_kind[ in_idx ]==IN_KIND_DIAG ) ) {
     373           0 :     sz = sig;
     374           0 :   }
     375             : 
     376           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_REPLAY_OUT ) ) {
     377           0 :     if( FD_LIKELY( sig!=REPLAY_SIG_SLOT_COMPLETED &&
     378           0 :                    sig!=REPLAY_SIG_BECAME_LEADER  &&
     379           0 :                    sig!=REPLAY_SIG_ROOT_ADVANCED  &&
     380           0 :                    sig!=REPLAY_SIG_OC_ADVANCED &&
     381           0 :                    sig!=REPLAY_SIG_TXN_EXECUTED ) ) return;
     382           0 :   }
     383             : 
     384           0 :   if( FD_UNLIKELY( (sz>0UL && (chunk<ctx->in[ in_idx ].chunk0 || chunk>ctx->in[ in_idx ].wmark)) || sz>ctx->in[ in_idx ].mtu ) )
     385           0 :     FD_LOG_ERR(( "in_kind %lu chunk %lu %lu corrupt, not in range [%lu,%lu] or too large (%lu)", ctx->in_kind[ in_idx ], chunk, sz, ctx->in[ in_idx ].chunk0, ctx->in[ in_idx ].wmark, ctx->in[ in_idx ].mtu ));
     386             : 
     387           0 :   switch( ctx->in_kind[ in_idx ] ) {
     388           0 :     case IN_KIND_REPAIR_NET: {
     389           0 :       ctx->parsed.repair_net.slot = ULONG_MAX;
     390           0 :       uchar * payload;
     391           0 :       ulong payload_sz;
     392           0 :       if( FD_LIKELY( fd_ip4_udp_hdr_strip( src, sz, &payload, &payload_sz, NULL, NULL, NULL ) ) ) {
     393           0 :         fd_repair_msg_t const * msg = (fd_repair_msg_t const *)fd_type_pun_const( payload );
     394           0 :         if( FD_LIKELY( msg->kind==FD_REPAIR_KIND_SHRED ) ) {
     395           0 :           if( FD_UNLIKELY( msg->shred.slot==0 ) ) break;
     396           0 :           ctx->parsed.repair_net.slot = msg->shred.slot;
     397           0 :           ctx->parsed.repair_net.shred_idx = msg->shred.shred_idx;
     398           0 :         }
     399           0 :       }
     400           0 :       break;
     401           0 :     }
     402           0 :     case IN_KIND_GOSSVF_GUI:
     403           0 :     case IN_KIND_GOSSIP_GUI: {
     404           0 :       FD_TEST( sz<=sizeof(ctx->parsed.gossip_bw) && !(sz%sizeof(fd_gui_gossip_bw_rec_t)) );
     405           0 :       fd_memcpy( ctx->parsed.gossip_bw, src, sz );
     406           0 :       break;
     407           0 :     }
     408           0 :     case IN_KIND_SNAPSV_OUT: {
     409           0 :       FD_TEST( sz<=sizeof(ctx->parsed.snapsv_out) );
     410           0 :       fd_memcpy( &ctx->parsed.snapsv_out, src, sz );
     411           0 :       ctx->parsed.snapsv_eom = fd_frag_meta_ctl_eom( ctl );
     412           0 :       break;
     413           0 :     }
     414           0 :     case IN_KIND_VOTOR_OUT: {
     415           0 :       if( FD_UNLIKELY( sz!=sizeof(fd_votor_msg_t) ) ) break;
     416           0 :       fd_memcpy( &ctx->parsed.votor_out, src, sz );
     417           0 :       break;
     418           0 :     }
     419           0 :   }
     420             : 
     421           0 :   ctx->chunk = chunk;
     422           0 : }
     423             : 
     424             : static inline void
     425             : after_frag( fd_gui_ctx_t *      ctx,
     426             :             ulong               in_idx,
     427             :             ulong               seq,
     428             :             ulong               sig,
     429             :             ulong               sz,
     430             :             ulong               tsorig,
     431             :             ulong               tspub,
     432           0 :             fd_stem_context_t * stem ) {
     433           0 :   (void)stem;
     434             : 
     435           0 :   if( FD_LIKELY( ctx->in_reliable[ in_idx ] ) ) ctx->idle_cnt = 0UL;
     436             : 
     437           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[ in_idx ].mem, ctx->chunk );
     438             : 
     439           0 :   switch( ctx->in_kind[ in_idx ] ) {
     440           0 :     case IN_KIND_EXECRP_REPLAY: {
     441           0 :       if( FD_LIKELY( sig>>32==FD_EXECRP_TT_TXN_EXEC ) ) {
     442           0 :         fd_execrp_task_done_msg_t * msg = (fd_execrp_task_done_msg_t *)src;
     443             : 
     444           0 :         long tsorig_ns = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tsorig );
     445           0 :         long tspub_ns  = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tspub  );
     446           0 :         fd_gui_handle_exec_txn_done( ctx->gui, msg->txn_exec->slot, msg->txn_exec->start_shred_idx, msg->txn_exec->end_shred_idx, tsorig_ns, tspub_ns, fd_clock_tile_now( ctx->clock ) );
     447             : 
     448           0 :         int txn_succeeded = msg->txn_exec->is_committable && !msg->txn_exec->is_fees_only && !msg->txn_exec->txn_err;
     449           0 :         if( FD_UNLIKELY( msg->txn_exec->vote.slot!=ULONG_MAX && txn_succeeded ) ) {
     450           0 :           int vote_acct_is_us = !ctx->gui->summary.has_vote_key || !memcmp( ctx->gui->summary.vote_key->uc, msg->txn_exec->vote.vote_acct->uc, sizeof(fd_pubkey_t) );
     451           0 :           int is_us = !ctx->gui->summary.is_alpenglow && vote_acct_is_us && !memcmp( ctx->gui->summary.identity_key->uc, msg->txn_exec->vote.identity->uc, sizeof(fd_pubkey_t) );
     452           0 :           fd_gui_peers_handle_vote( ctx->peers,
     453           0 :                                     msg->txn_exec->vote.vote_acct,
     454           0 :                                     msg->txn_exec->vote.slot,
     455           0 :                                     is_us );
     456           0 :           if( FD_UNLIKELY( is_us ) ) {
     457           0 :             for( ulong i=0UL; i<msg->txn_exec->vote.vote_slot_cnt; i++ ) {
     458           0 :               fd_gui_stage_landed_vote( ctx->gui, msg->txn_exec->slot, msg->txn_exec->bank_seq, msg->txn_exec->vote.vote_slots[ i ] );
     459           0 :             }
     460           0 :           }
     461           0 :         }
     462           0 :       }
     463             : 
     464           0 :       break;
     465           0 :     }
     466           0 :     case IN_KIND_VOTOR_OUT: {
     467           0 :       if( FD_UNLIKELY( sz!=sizeof(fd_votor_msg_t) ) ) return;
     468             : 
     469           0 :       fd_votor_msg_t const * msg = &ctx->parsed.votor_out;
     470             : 
     471           0 :       switch( sig ) {
     472           0 :         case FD_VOTOR_SIG_CERTED: {
     473           0 :           fd_votor_certed_t const * certed = &msg->certed;
     474           0 :           switch( certed->kind ) {
     475           0 :             case AG_CERT_KIND_FINAL:          fd_gui_handle_ag_finalized( ctx->gui, certed->slot, &certed->block_id, FD_GUI_AG_FINAL_SLOW     ); break;
     476           0 :             case AG_CERT_KIND_FAST_FINAL:     fd_gui_handle_ag_finalized( ctx->gui, certed->slot, &certed->block_id, FD_GUI_AG_FINAL_FAST     ); break;
     477           0 :             case AG_CERT_KIND_NOTAR:          fd_gui_handle_ag_notarized( ctx->gui, certed->slot, &certed->block_id, FD_GUI_AG_NOTAR_REGULAR  ); break;
     478           0 :             case AG_CERT_KIND_NOTAR_FALLBACK: fd_gui_handle_ag_notarized( ctx->gui, certed->slot, &certed->block_id, FD_GUI_AG_NOTAR_FALLBACK ); break;
     479           0 :             case AG_CERT_KIND_SKIP:           fd_gui_handle_ag_skip_cert( ctx->gui, certed->slot );                                            break;
     480           0 :             default:                                                                                                                          break;
     481           0 :           }
     482           0 :           break;
     483           0 :         }
     484           0 :         case FD_VOTOR_SIG_LEADER: fd_gui_handle_ag_leader( ctx->gui, msg->leader.parent_slot ); break;
     485           0 :         default:                  break;
     486           0 :       }
     487           0 :       break;
     488           0 :     }
     489           0 :     case IN_KIND_REPLAY_OUT: {
     490           0 :       if( FD_UNLIKELY( sig==REPLAY_SIG_SLOT_COMPLETED ) ) {
     491           0 :         fd_replay_slot_completed_t const * slot_completed =  (fd_replay_slot_completed_t const *)src;
     492             : 
     493           0 :         if( FD_LIKELY( !ctx->gui->summary.is_alpenglow ) ) fd_gui_peers_update_delinquency( ctx->peers, fd_clock_tile_now( ctx->clock ) );
     494             : 
     495           0 :         fd_gui_handle_replay_update( ctx->gui, slot_completed, ctx->peers->slot_voted, fd_clock_tile_now( ctx->clock ) );
     496           0 :       } else if( FD_UNLIKELY( sig==REPLAY_SIG_BECAME_LEADER ) ) {
     497           0 :         fd_became_leader_t * became_leader = (fd_became_leader_t *)src;
     498           0 :         fd_gui_became_leader( ctx->gui, became_leader->slot, became_leader->slot_start_ns, became_leader->slot_end_ns, became_leader->limits.slot_max_cost, became_leader->max_microblocks_in_slot, became_leader->bank_seq );
     499           0 :       } else if( FD_UNLIKELY( sig==REPLAY_SIG_ROOT_ADVANCED ) ) {
     500           0 :         fd_replay_root_advanced_t const * ra = (fd_replay_root_advanced_t const *)src;
     501           0 :         fd_gui_handle_root_advanced( ctx->gui, ra->slot, ra->bank_seq, fd_clock_tile_now( ctx->clock ) );
     502           0 :       } else if( FD_UNLIKELY( sig==REPLAY_SIG_OC_ADVANCED ) ) {
     503           0 :         fd_replay_oc_advanced_t const * oc = (fd_replay_oc_advanced_t const *)src;
     504           0 :         fd_gui_handle_oc_advanced( ctx->gui, oc->slot, oc->bank_seq, fd_clock_tile_now( ctx->clock ) );
     505           0 :       } else if( FD_LIKELY( sig==REPLAY_SIG_TXN_EXECUTED ) ) {
     506           0 :         if( FD_UNLIKELY( sz!=sizeof(fd_replay_txn_executed_t) ) ) FD_LOG_ERR(( "invalid replay transaction message size %lu", sz ));
     507           0 :         fd_gui_handle_replay_txn( ctx->gui, (fd_replay_txn_executed_t const *)src, fd_clock_tile_now( ctx->clock ) );
     508           0 :       } else {
     509           0 :         return;
     510           0 :       }
     511           0 :       break;
     512           0 :     }
     513           0 :     case IN_KIND_EPOCH: {
     514           0 :       fd_epoch_info_msg_t * epoch_info = (fd_epoch_info_msg_t *)src;
     515           0 :       fd_gui_handle_epoch_info( ctx->gui, epoch_info, fd_clock_tile_now( ctx->clock ) );
     516           0 :       fd_gui_peers_handle_epoch_info( ctx->peers, epoch_info, fd_clock_tile_now( ctx->clock ) );
     517           0 :       break;
     518           0 :     }
     519           0 :     case IN_KIND_SNAPIN: {
     520           0 :       fd_gui_peers_handle_config_account( ctx->peers, src, sz, sig );
     521           0 :       break;
     522           0 :     }
     523           0 :     case IN_KIND_SNAPIN_MANIF: {
     524           0 :       if( fd_ssmsg_sig_message( sig )==FD_SSMSG_DONE ) {
     525           0 :         if( fd_gui_wfs_mode( ctx->gui )!=FD_WFS_MODE_NOOP ) fd_gui_peers_commit_snapshot_manifest( ctx->peers );
     526           0 :       } else {
     527           0 :         fd_gui_stage_snapshot_manifest( ctx->gui, (fd_snapshot_manifest_t const *)src );
     528           0 :         fd_gui_peers_stage_snapshot_manifest( ctx->peers, (fd_snapshot_manifest_t const *)src, fd_clock_tile_now( ctx->clock ) );
     529           0 :       }
     530           0 :       break;
     531           0 :     }
     532           0 :     case IN_KIND_GENESI_OUT: {
     533           0 :       fd_genesis_meta_t const * meta = (fd_genesis_meta_t const *)src;
     534           0 :       fd_gui_handle_genesis_hash( ctx->gui, &meta->genesis_hash );
     535           0 :       break;
     536           0 :     }
     537           0 :     case IN_KIND_SHRED_OUT: {
     538           0 :       long tsorig_nanos = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tsorig );
     539           0 :       uint sig_src      = fd_shred_sig_src( sig );
     540           0 :       if( FD_LIKELY( sig_src==SHRED_SIG_SRC_TURBINE || sig_src==SHRED_SIG_SRC_REPAIR || sig_src==SHRED_SIG_SRC_BAD_REPAIR ) ) {
     541           0 :         fd_shred_base_t const * msg = (fd_shred_base_t const *)fd_type_pun_const( src );
     542           0 :         ulong slot      = msg->shred.slot;
     543           0 :         ulong shred_idx = msg->shred.idx;
     544           0 :         int is_turbine  = sig_src==SHRED_SIG_SRC_TURBINE;
     545             :         /* tsorig is the timestamp when the shred was received by the shred tile */
     546           0 :         fd_gui_handle_shred( ctx->gui, slot, shred_idx, is_turbine, tsorig_nanos, fd_clock_tile_now( ctx->clock ) );
     547           0 :       }
     548           0 :       if( FD_UNLIKELY( sig==SHRED_SIG_FEC_COMPLETE_LEADER ) ) {
     549           0 :         fd_fec_complete_t const * complete_msg = (fd_fec_complete_t const *)fd_type_pun_const( src );
     550           0 :         fd_gui_handle_leader_fec( ctx->gui, complete_msg->last_shred_hdr.slot, FD_FEC_SHRED_CNT, complete_msg->last_shred_hdr.data.flags & FD_SHRED_DATA_FLAG_SLOT_COMPLETE, tsorig_nanos, fd_clock_tile_now( ctx->clock ) );
     551           0 :       }
     552           0 :       break;
     553           0 :     }
     554           0 :     case IN_KIND_SNAPCT: {
     555           0 :       fd_gui_handle_snapshot_update( ctx->gui, (fd_snapct_update_t *)src );
     556           0 :       break;
     557           0 :     }
     558           0 :     case IN_KIND_SNAPSV_OUT: {
     559           0 :       long sample_time_nanos = fd_frag_meta_ts_decomp( tspub, fd_clock_tile_now( ctx->clock ) );
     560           0 :       fd_gui_handle_snapsv_update( ctx->gui, sig, &ctx->parsed.snapsv_out, sz, ctx->parsed.snapsv_eom, sample_time_nanos );
     561           0 :       break;
     562           0 :     }
     563           0 :     case IN_KIND_REPAIR_NET: {
     564           0 :       if( FD_UNLIKELY( ctx->parsed.repair_net.slot==ULONG_MAX ) ) break;
     565           0 :       long tsorig_ns = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tsorig );
     566           0 :       fd_gui_handle_repair_request( ctx->gui, ctx->parsed.repair_net.slot, ctx->parsed.repair_net.shred_idx, tsorig_ns, fd_clock_tile_now( ctx->clock ) );
     567           0 :       break;
     568           0 :     }
     569           0 :     case IN_KIND_GOSSVF_GUI:
     570           0 :     case IN_KIND_GOSSIP_GUI: {
     571           0 :       fd_gui_peers_handle_gossip_bw( ctx->peers, ctx->parsed.gossip_bw, sz/sizeof(fd_gui_gossip_bw_rec_t), ctx->in_kind[ in_idx ]==IN_KIND_GOSSVF_GUI );
     572           0 :       break;
     573           0 :     }
     574           0 :     case IN_KIND_GOSSIP_OUT: {
     575           0 :       fd_gui_peers_handle_gossip_update( ctx->peers, (fd_gossip_update_message_t *)src, fd_clock_tile_now( ctx->clock ) );
     576           0 :       break;
     577           0 :     }
     578           0 :     case IN_KIND_PACK_POH: {
     579           0 :       if( FD_UNLIKELY( sig==FD_PACK_MSG_DONE_DRAINING ) ) fd_gui_done_draining( ctx->gui, fd_clock_tile_now( ctx->clock ) );
     580           0 :       else                                                fd_gui_unbecame_leader( ctx->gui, fd_disco_execle_sig_slot( sig ), (fd_done_packing_t const *)src );
     581           0 :       break;
     582           0 :     }
     583           0 :     case IN_KIND_PACK_EXECLE: {
     584           0 :       FD_TEST( sz>=sizeof(fd_microblock_execle_trailer_t) );
     585           0 :       FD_TEST( (sz-sizeof(fd_microblock_execle_trailer_t))%sizeof(fd_txn_e_t)==0UL );
     586             : 
     587           0 :       if( FD_LIKELY( fd_disco_poh_sig_pkt_type( sig )==POH_PKT_TYPE_MICROBLOCK ) ) {
     588           0 :         fd_microblock_execle_trailer_t trailer[1];
     589           0 :         fd_memcpy( trailer, src+sz-sizeof(fd_microblock_execle_trailer_t), sizeof(fd_microblock_execle_trailer_t) );
     590           0 :         long tspub_ns = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tspub );
     591           0 :         fd_gui_microblock_execution_begin( ctx->gui,
     592           0 :                                           tspub_ns,
     593           0 :                                           fd_disco_poh_sig_slot( sig ),
     594           0 :                                           (fd_txn_e_t *)src,
     595           0 :                                           (sz-sizeof( fd_microblock_execle_trailer_t ))/sizeof( fd_txn_e_t ),
     596           0 :                                           (uint)trailer->microblock_idx,
     597           0 :                                           trailer->pack_txn_idx,
     598           0 :                                           trailer->bank_seq,
     599           0 :                                           fd_clock_tile_now( ctx->clock ) );
     600           0 :       } else {
     601           0 :         FD_LOG_ERR(( "unexpected poh packet type %lu", fd_disco_poh_sig_pkt_type( sig ) ));
     602           0 :       }
     603             :       /* The link is shallow; return the credit now, like the execle. */
     604           0 :       fd_stem_credit_return( stem, in_idx, seq+1UL );
     605           0 :       break;
     606           0 :     }
     607           0 :     case IN_KIND_EXECLE_POH: {
     608           0 :       FD_TEST( sz>=sizeof(fd_microblock_trailer_t) );
     609           0 :       FD_TEST( (sz-sizeof(fd_microblock_trailer_t))%sizeof(fd_txn_p_t)==0UL );
     610             : 
     611           0 :       fd_microblock_trailer_t trailer[1];
     612           0 :       fd_memcpy( trailer, src+sz-sizeof(fd_microblock_trailer_t), sizeof(fd_microblock_trailer_t) );
     613           0 :       long tspub_ns = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tspub );
     614           0 :       ulong txn_cnt = (sz-sizeof( fd_microblock_trailer_t ))/sizeof(fd_txn_p_t);
     615           0 :       fd_gui_microblock_execution_end( ctx->gui,
     616           0 :                                       tspub_ns,
     617           0 :                                       ctx->in_bank_idx[ in_idx ],
     618           0 :                                       fd_disco_execle_sig_slot( sig ),
     619           0 :                                       txn_cnt,
     620           0 :                                       (fd_txn_p_t *)src,
     621           0 :                                       trailer->pack_txn_idx,
     622           0 :                                       trailer->txn_ns_dt,
     623           0 :                                       trailer->exec_end_ticks,
     624           0 :                                       trailer->tips,
     625           0 :                                       trailer->bank_seq,
     626           0 :                                       fd_clock_tile_now( ctx->clock ) );
     627           0 :       break;
     628           0 :     }
     629           0 :     case IN_KIND_BUNDLE: {
     630           0 :       fd_gui_handle_block_engine_update( ctx->gui, (fd_bundle_block_engine_update_t *)src );
     631           0 :       break;
     632           0 :     }
     633           0 :     case IN_KIND_DIAG: {
     634           0 :       fd_gui_handle_diag_snapshot( ctx->gui, src, sig );
     635           0 :       break;
     636           0 :     }
     637           0 :     default: FD_LOG_ERR(( "unexpected in_kind %lu", ctx->in_kind[ in_idx ] ));
     638           0 :   }
     639           0 : }
     640             : 
     641             : static int
     642             : returnable_frag( fd_gui_ctx_t *      ctx,
     643             :                  ulong               in_idx,
     644             :                  ulong               seq    FD_PARAM_UNUSED,
     645             :                  ulong               sig    FD_PARAM_UNUSED,
     646             :                  ulong               chunk  FD_PARAM_UNUSED,
     647             :                  ulong               sz     FD_PARAM_UNUSED,
     648             :                  ulong               ctl    FD_PARAM_UNUSED,
     649             :                  ulong               tsorig FD_PARAM_UNUSED,
     650             :                  ulong               tspub  FD_PARAM_UNUSED,
     651           0 :                  fd_stem_context_t * stem   FD_PARAM_UNUSED ) {
     652           0 :   if( FD_UNLIKELY( ctx->in_kind[ in_idx ]==IN_KIND_REPLAY_OUT && !ctx->gui->epoch.has_epoch_schedule ) ) return 1; /* epoch info not received yet: defer polling */
     653           0 :   return 0;
     654           0 : }
     655             : 
     656             : static fd_http_server_response_t
     657           0 : gui_http_request( fd_http_server_request_t const * request ) {
     658           0 :   if( FD_UNLIKELY( request->method!=FD_HTTP_SERVER_METHOD_GET ) ) {
     659           0 :     return (fd_http_server_response_t){
     660           0 :       .status = 405,
     661           0 :     };
     662           0 :   }
     663             : 
     664           0 :   if( FD_LIKELY( !strcmp( request->path, "/websocket" ) ) ) {
     665           0 :     return (fd_http_server_response_t){
     666           0 :       .status            = 200,
     667           0 :       .upgrade_websocket = 1,
     668           0 :       .compress_websocket = request->headers.compress_websocket,
     669           0 :     };
     670           0 :   } else if( FD_LIKELY( !strcmp( request->path, "/favicon.svg" ) ) ) {
     671           0 :     return (fd_http_server_response_t){
     672           0 :       .status            = 200,
     673           0 :       .static_body       = firedancer_svg,
     674           0 :       .static_body_len   = firedancer_svg_sz,
     675           0 :       .content_type      = "image/svg+xml",
     676           0 :       .cache_control     = "public, max-age=86400",
     677           0 :       .upgrade_websocket = 0,
     678           0 :     };
     679           0 :   }
     680             : 
     681           0 :   int is_vite_page = !strcmp( request->path, "/" ) ||
     682           0 :                      !strcmp( request->path, "/slotDetails" ) ||
     683           0 :                      !strcmp( request->path, "/leaderSchedule" ) ||
     684           0 :                      !strcmp( request->path, "/gossip") ||
     685           0 :                      !strcmp( request->path, "/accounts") ||
     686           0 :                      !strncmp( request->path, "/?", strlen("/?") ) ||
     687           0 :                      !strncmp( request->path, "/slotDetails?", strlen("/slotDetails?") ) ||
     688           0 :                      !strncmp( request->path, "/leaderSchedule?", strlen("/leaderSchedule?") ) ||
     689           0 :                      !strncmp( request->path, "/gossip?", strlen("/gossip?") ) ||
     690           0 :                      !strncmp( request->path, "/accounts?", strlen("/accounts?") );
     691             : 
     692           0 :   for( fd_http_static_file_t const * f = STATIC_FILES; f->name; f++ ) {
     693           0 :     if( !strcmp( request->path, f->name ) ||
     694           0 :         (!strcmp( f->name, "/index.html" ) && is_vite_page) ) {
     695           0 :       char const * content_type = NULL;
     696             : 
     697           0 :       char const * ext = strrchr( f->name, '.' );
     698           0 :       if( FD_LIKELY( ext ) ) {
     699           0 :         if( !strcmp( ext, ".html" ) ) content_type = "text/html; charset=utf-8";
     700           0 :         else if( !strcmp( ext, ".css" ) ) content_type = "text/css";
     701           0 :         else if( !strcmp( ext, ".js" ) ) content_type = "application/javascript";
     702           0 :         else if( !strcmp( ext, ".svg" ) ) content_type = "image/svg+xml";
     703           0 :         else if( !strcmp( ext, ".woff" ) ) content_type = "font/woff";
     704           0 :         else if( !strcmp( ext, ".woff2" ) ) content_type = "font/woff2";
     705           0 :         else if( !strcmp( ext, ".wasm" ) ) content_type = "application/wasm";
     706           0 :       }
     707             : 
     708           0 :       char const * cache_control = NULL;
     709           0 :       if( FD_LIKELY( !strncmp( request->path, "/assets", 7 ) ) ) cache_control = "public, max-age=31536000, immutable";
     710           0 :       else if( FD_LIKELY( !strcmp( f->name, "/index.html" ) ) )  cache_control = "no-cache";
     711           0 :       else if( FD_UNLIKELY( !strcmp( f->name, "/version" ) ) )   cache_control = "no-cache";
     712             : 
     713           0 :       const uchar * data = f->data;
     714           0 :       ulong data_len = *(f->data_len);
     715             : 
     716           0 :       int q_zstd = 0;
     717           0 :       int q_gzip = 0;
     718           0 :       if( FD_LIKELY( request->headers.accept_encoding ) ) {
     719           0 :         q_zstd = fd_http_server_accept_encoding_q( request->headers.accept_encoding, "zstd" );
     720           0 :         q_gzip = fd_http_server_accept_encoding_q( request->headers.accept_encoding, "gzip" );
     721           0 :       }
     722             : 
     723             :       /* the client's preferred acceptable coding, zstd on a tie; a
     724             :          variant that did not shrink is not worth the decode */
     725           0 :       int zstd_ok = q_zstd && f->zstd_data && *(f->zstd_data_len)<data_len;
     726           0 :       int gzip_ok = q_gzip && f->gzip_data && *(f->gzip_data_len)<data_len;
     727           0 :       char const * content_encoding = NULL;
     728           0 :       ulong enc_idx = 0UL;
     729           0 :       if( FD_LIKELY( zstd_ok && (q_zstd>=q_gzip || !gzip_ok) ) ) {
     730           0 :         content_encoding = "zstd";
     731           0 :         data = f->zstd_data;
     732           0 :         data_len = *(f->zstd_data_len);
     733           0 :         enc_idx = 1UL;
     734           0 :       } else if( FD_LIKELY( gzip_ok ) ) {
     735           0 :         content_encoding = "gzip";
     736           0 :         data = f->gzip_data;
     737           0 :         data_len = *(f->gzip_data_len);
     738           0 :         enc_idx = 2UL;
     739           0 :       }
     740             : 
     741           0 :       char const * etag = NULL;
     742           0 :       char const * link = NULL;
     743           0 :       if( FD_LIKELY( !strcmp( f->name, "/index.html" ) ) ) {
     744           0 :         fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)request->ctx;
     745           0 :         etag = ctx->index_html_etag[ enc_idx ];
     746           0 :         link = ctx->index_html_link[ 0 ] ? ctx->index_html_link : NULL;
     747           0 :         if( FD_UNLIKELY( fd_http_server_etag_matches( request->headers.if_none_match, etag ) ) ) {
     748           0 :           return (fd_http_server_response_t){
     749           0 :             .status        = 304,
     750           0 :             .cache_control = cache_control,
     751           0 :             .vary          = "Accept-Encoding",
     752           0 :             .etag          = etag,
     753           0 :             .link          = link,
     754           0 :           };
     755           0 :         }
     756           0 :       }
     757             : 
     758           0 :       return (fd_http_server_response_t){
     759           0 :         .status            = 200,
     760           0 :         .static_body       = data,
     761           0 :         .static_body_len   = data_len,
     762           0 :         .content_type      = content_type,
     763           0 :         .cache_control     = cache_control,
     764           0 :         .content_encoding  = content_encoding,
     765           0 :         .vary              = "Accept-Encoding",
     766           0 :         .etag              = etag,
     767           0 :         .link              = link,
     768           0 :         .upgrade_websocket = 0,
     769           0 :       };
     770           0 :     }
     771           0 :   }
     772             : 
     773           0 :   return (fd_http_server_response_t){
     774           0 :     .status            = 404,
     775           0 :   };
     776           0 : }
     777             : 
     778             : static void
     779             : gui_ws_open( ulong  conn_id,
     780           0 :              void * _ctx ) {
     781           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     782             : 
     783           0 :   fd_gui_ws_open( ctx->gui, conn_id, fd_clock_tile_now( ctx->clock ) );
     784           0 :   fd_gui_peers_ws_open( ctx->peers, conn_id, fd_clock_tile_now( ctx->clock ) );
     785           0 : }
     786             : 
     787             : static void
     788             : gui_ws_close( ulong  conn_id,
     789             :               int    reason,
     790           0 :               void * _ctx ) {
     791           0 :   (void) reason;
     792           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     793           0 :   fd_gui_peers_ws_close( ctx->peers, conn_id );
     794           0 : }
     795             : 
     796             : static void
     797             : gui_ws_message( ulong         ws_conn_id,
     798             :                 uchar const * data,
     799             :                 ulong         data_len,
     800           0 :                 void *        _ctx ) {
     801           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     802             : 
     803           0 :   int reason = fd_gui_ws_message( ctx->gui, ws_conn_id, data, data_len );
     804           0 :   if( FD_UNLIKELY( reason==FD_HTTP_SERVER_CONNECTION_CLOSE_UNKNOWN_METHOD ) ) reason = fd_gui_peers_ws_message( ctx->peers, ws_conn_id, data, data_len );
     805             : 
     806           0 :   if( FD_UNLIKELY( reason<0 ) ) fd_http_server_ws_close( ctx->gui_server, ws_conn_id, reason );
     807           0 : }
     808             : 
     809             : static void
     810             : privileged_init( fd_topo_t const *      topo,
     811           0 :                  fd_topo_tile_t const * tile ) {
     812           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     813             : 
     814           0 :   fd_http_server_params_t http_param = derive_http_params( tile );
     815             : 
     816           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     817           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     818           0 :   FD_TEST( fd_rng_secure( &ctx->seed, sizeof(ctx->seed) ) );
     819           0 :   http_param.treap_seed = ctx->seed;
     820           0 :   fd_http_server_t * _gui = FD_SCRATCH_ALLOC_APPEND( l, fd_http_server_align(), fd_http_server_footprint( http_param ) );
     821           0 :                      FD_SCRATCH_ALLOC_APPEND( l, fd_gui_peers_align(),    fd_gui_peers_footprint( http_param.max_ws_connection_cnt ) );
     822           0 :                      FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(),          fd_gui_footprint( tile->gui.tile_cnt, tile->gui.max_live_slots, tile->gui.max_txn_per_slot ) );
     823           0 :   void * _db       = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_store_align(),       fd_gui_store_footprint( tile->gui.db_size_gib<<30, fd_gui_hist_db_cnt(), fd_gui_hist_db_descs( tile->gui.db_size_gib<<30 ) ) );
     824             : 
     825           0 :   fd_http_server_callbacks_t gui_callbacks = {
     826           0 :     .request    = gui_http_request,
     827           0 :     .ws_open    = gui_ws_open,
     828           0 :     .ws_close   = gui_ws_close,
     829           0 :     .ws_message = gui_ws_message,
     830           0 :   };
     831           0 :   ctx->gui_server = fd_http_server_join( fd_http_server_new( _gui, http_param, gui_callbacks, ctx ) );
     832             : 
     833           0 :   ctx->waker_client_idx = tile->waker_client_idx;
     834           0 :   FD_TEST( ctx->waker_client_idx!=ULONG_MAX );
     835           0 :   fd_http_server_listen( ctx->gui_server, FD_WAKER_INNER_FD( ctx->waker_client_idx ), tile->gui.listen_addr, tile->gui.listen_port );
     836             : 
     837           0 :   FD_LOG_NOTICE(( "gui server listening at %shttp://" FD_IP4_ADDR_FMT ":%u%s", fd_log_style_bold(), FD_IP4_ADDR_FMT_ARGS( tile->gui.listen_addr ), tile->gui.listen_port, fd_log_style_normal() ));
     838             : 
     839           0 :   ctx->db = fd_gui_store_join( fd_gui_store_new( _db, tile->gui.gui_database_path, tile->gui.db_size_gib<<30, fd_gui_hist_db_cnt(), ctx->seed, fd_gui_hist_db_descs( tile->gui.db_size_gib<<30 ) ) );
     840           0 :   if( FD_UNLIKELY( !ctx->db ) ) FD_LOG_ERR(( "fd_gui_store_new(%s) failed; gui tile cannot start", tile->gui.gui_database_path ));
     841             : 
     842           0 :   if( FD_UNLIKELY( !strcmp( tile->gui.identity_key_path, "" ) ) )
     843           0 :     FD_LOG_ERR(( "identity_key_path not set" ));
     844             : 
     845           0 :   ctx->identity_key = fd_keyload_load( tile->gui.identity_key_path, /* pubkey only: */ 1 );
     846             : 
     847           0 :   if( FD_UNLIKELY( !strcmp( tile->gui.vote_key_path, "" ) ) ) {
     848           0 :     ctx->has_vote_key = 0;
     849           0 :   } else {
     850           0 :     ctx->has_vote_key = 1;
     851           0 :     if( FD_UNLIKELY( !fd_base58_decode_32( tile->gui.vote_key_path, (uchar *)ctx->vote_key->uc ) ) ) {
     852           0 :       const uchar * vote_key = fd_keyload_load( tile->gui.vote_key_path, /* pubkey only: */ 1 );
     853           0 :       fd_memcpy( (uchar *)ctx->vote_key->uc, vote_key, 32UL );
     854           0 :     }
     855           0 :   }
     856           0 : }
     857             : 
     858             : static int
     859             : index_html_refs( fd_http_static_file_t const * html,
     860           0 :                  char const *                  name ) {
     861           0 :   ulong name_len = strlen( name );
     862           0 :   if( FD_UNLIKELY( name_len>*(html->data_len) ) ) return 0;
     863           0 :   for( ulong i=0UL; i<=*(html->data_len)-name_len; i++ ) if( FD_UNLIKELY( !memcmp( html->data+i, name, name_len ) ) ) return 1;
     864           0 :   return 0;
     865           0 : }
     866             : 
     867             : /* One ETag per index.html representation (plain, zstd, gzip).  Returns
     868             :    the index.html static file. */
     869             : 
     870             : static fd_http_static_file_t const *
     871           0 : index_html_etag_init( fd_gui_ctx_t * ctx ) {
     872           0 :   fd_http_static_file_t const * index_html = NULL;
     873           0 :   for( fd_http_static_file_t const * f = STATIC_FILES; f->name; f++ ) {
     874           0 :     if( FD_UNLIKELY( !strcmp( f->name, "/index.html" ) ) ) index_html = f;
     875           0 :   }
     876           0 :   FD_TEST( index_html );
     877             : 
     878           0 :   fd_http_static_file_t const * f = index_html;
     879           0 :   uchar hash[ 32 ];
     880           0 :   uchar const * rep_data[ 3 ]     = { f->data,     f->zstd_data,     f->gzip_data     };
     881           0 :   ulong const * rep_data_len[ 3 ] = { f->data_len, f->zstd_data_len, f->gzip_data_len };
     882           0 :   for( ulong e=0UL; e<3UL; e++ ) {
     883           0 :     ctx->index_html_etag[ e ][ 0 ] = '\0';
     884           0 :     if( FD_UNLIKELY( !rep_data[ e ] ) ) continue;
     885           0 :     fd_sha256_hash( rep_data[ e ], *(rep_data_len[ e ]), hash );
     886           0 :     char b64[ FD_BASE64_ENC_SZ( 9UL )+1UL ];
     887           0 :     b64[ fd_base64_encode( b64, hash, 9UL ) ] = '\0';
     888           0 :     FD_TEST( fd_cstr_printf_check( ctx->index_html_etag[ e ], sizeof(ctx->index_html_etag[ e ]), NULL, "\"%s\"", b64 ) );
     889           0 :   }
     890           0 :   return index_html;
     891           0 : }
     892             : 
     893             : static void
     894             : unprivileged_init( fd_topo_t const *      topo,
     895           0 :                    fd_topo_tile_t const * tile ) {
     896           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     897             : 
     898           0 :   fd_http_server_params_t http_param = derive_http_params( tile );
     899           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     900           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t )                                    );
     901           0 :                        FD_SCRATCH_ALLOC_APPEND( l, fd_http_server_align(),  fd_http_server_footprint( http_param )                    );
     902           0 :   void * _peers      = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_peers_align(),    fd_gui_peers_footprint( http_param.max_ws_connection_cnt) );
     903           0 :   void * _gui        = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(),          fd_gui_footprint( tile->gui.tile_cnt, tile->gui.max_live_slots, tile->gui.max_txn_per_slot ) );
     904           0 :                        FD_SCRATCH_ALLOC_APPEND( l, fd_gui_store_align(),       fd_gui_store_footprint( tile->gui.db_size_gib<<30, fd_gui_hist_db_cnt(), fd_gui_hist_db_descs( tile->gui.db_size_gib<<30 ) ) );
     905             : 
     906           0 :   fd_http_static_file_t const * index_html = index_html_etag_init( ctx );
     907             : 
     908           0 :   char const * preload_js     = NULL;
     909           0 :   char const * preload_css    = NULL;
     910           0 :   char const * preload_worker = NULL;
     911           0 :   char const * preload_wasm   = NULL;
     912           0 :   char const * split_js[ 16 ];
     913           0 :   ulong        split_js_cnt   = 0UL;
     914           0 :   for( fd_http_static_file_t const * f = STATIC_FILES; f->name; f++ ) {
     915           0 :     char const * ext = strrchr( f->name, '.' );
     916           0 :     if( FD_UNLIKELY( !ext ) ) continue;
     917           0 :     if( FD_UNLIKELY( !strncmp( f->name, "/assets/index-", 14UL ) ) ) {
     918           0 :       if( !strcmp( ext, ".js" ) ) {
     919           0 :         if( FD_UNLIKELY( index_html_refs( index_html, f->name ) ) )                              preload_js = f->name;
     920           0 :         else if( FD_LIKELY( split_js_cnt<sizeof(split_js)/sizeof(split_js[ 0 ]) ) )              split_js[ split_js_cnt++ ] = f->name;
     921           0 :       }
     922           0 :       else if( !strcmp( ext, ".css" ) && index_html_refs( index_html, f->name ) )                preload_css = f->name;
     923           0 :     }
     924           0 :     else if( FD_UNLIKELY( !strncmp( f->name, "/assets/wsWorker-", 17UL ) && !strcmp( ext, ".js"   ) ) ) preload_worker = f->name;
     925           0 :     else if( FD_UNLIKELY( !strncmp( f->name, "/assets/zstd-dec-", 17UL ) && !strcmp( ext, ".wasm" ) ) ) preload_wasm   = f->name;
     926           0 :     else if( FD_UNLIKELY( !strncmp( f->name, "/assets/UplotReact-", 19UL ) && !strcmp( ext, ".js" ) &&
     927           0 :                           split_js_cnt<sizeof(split_js)/sizeof(split_js[ 0 ]) ) )                split_js[ split_js_cnt++ ] = f->name;
     928           0 :   }
     929             : 
     930           0 :   ctx->index_html_link[ 0 ] = '\0';
     931           0 :   ulong off = 0UL, sz;
     932           0 :   if( FD_LIKELY( preload_js ) ) {
     933           0 :     FD_TEST( fd_cstr_printf_check( ctx->index_html_link+off, sizeof(ctx->index_html_link)-off, &sz, "%s<%s>; rel=modulepreload", off ? ", " : "", preload_js ) );
     934           0 :     off += sz;
     935           0 :   }
     936           0 :   if( FD_LIKELY( preload_css ) ) {
     937           0 :     FD_TEST( fd_cstr_printf_check( ctx->index_html_link+off, sizeof(ctx->index_html_link)-off, &sz, "%s<%s>; rel=preload; as=style; crossorigin", off ? ", " : "", preload_css ) );
     938           0 :     off += sz;
     939           0 :   }
     940           0 :   if( FD_LIKELY( preload_worker ) ) {
     941           0 :     FD_TEST( fd_cstr_printf_check( ctx->index_html_link+off, sizeof(ctx->index_html_link)-off, &sz, "%s<%s>; rel=preload; as=worker", off ? ", " : "", preload_worker ) );
     942           0 :     off += sz;
     943           0 :   }
     944           0 :   if( FD_LIKELY( preload_wasm ) ) {
     945           0 :     FD_TEST( fd_cstr_printf_check( ctx->index_html_link+off, sizeof(ctx->index_html_link)-off, &sz, "%s<%s>; rel=preload; as=fetch; crossorigin", off ? ", " : "", preload_wasm ) );
     946           0 :     off += sz;
     947           0 :   }
     948           0 :   for( ulong i=0UL; i<split_js_cnt; i++ ) {
     949           0 :     FD_TEST( fd_cstr_printf_check( ctx->index_html_link+off, sizeof(ctx->index_html_link)-off, &sz, "%s<%s>; rel=modulepreload", off ? ", " : "", split_js[ i ] ) );
     950           0 :     off += sz;
     951           0 :   }
     952             : 
     953           0 :   ctx->snapshots_enabled = ULONG_MAX!=fd_topo_find_tile( topo, "snapct", 0UL );
     954             : 
     955           0 :   fd_clock_tile_init( ctx->clock );
     956             : 
     957           0 :   ctx->topo = topo;
     958           0 :   ctx->peers = fd_gui_peers_join( fd_gui_peers_new( _peers, ctx->gui_server, ctx->topo, http_param.max_ws_connection_cnt, tile->gui.wfs_bank_hash, ctx->seed, fd_clock_tile_now( ctx->clock ) ) );
     959             :   /* The gui only reads partition stats from the accdb shmem; it never
     960             :      reads account data from disk, so it does not join the accdb fd. */
     961           0 :   fd_accdb_shmem_t * accdb_shmem = NULL;
     962           0 :   if( FD_LIKELY( tile->gui.accdb_obj_id!=ULONG_MAX ) ) {
     963           0 :     void * accdb_shmem_raw = fd_topo_obj_laddr( topo, tile->gui.accdb_obj_id );
     964           0 :     FD_TEST( accdb_shmem_raw );
     965           0 :     accdb_shmem = fd_accdb_shmem_join( accdb_shmem_raw );
     966           0 :     FD_TEST( accdb_shmem );
     967           0 :   }
     968           0 :   ctx->gui   = fd_gui_join( fd_gui_new( _gui, ctx->gui_server, fd_version_cstr, tile->gui.cluster, ctx->identity_key, ctx->has_vote_key, ctx->vote_key->uc, tile->gui.is_alpenglow, tile->gui.max_live_slots, tile->gui.max_txn_per_slot, ctx->snapshots_enabled, tile->gui.is_voting, tile->gui.schedule_strategy, tile->gui.wfs_bank_hash, tile->gui.expected_shred_version, tile->gui.wfs_slot, tile->gui.accounts_database_path, tile->gui.gui_database_path, ctx->db, ctx->topo, accdb_shmem, fd_clock_tile_now( ctx->clock ) ) );
     969           0 :   FD_TEST( ctx->gui );
     970           0 :   FD_TEST( ctx->db );
     971             : 
     972           0 :   ctx->keyswitch = fd_keyswitch_join( fd_topo_obj_laddr( topo, tile->id_keyswitch_obj_id ) );
     973           0 :   FD_TEST( ctx->keyswitch );
     974             : 
     975           0 :   FD_TEST( ctx->waker_client_idx!=ULONG_MAX );
     976           0 :   ctx->waker_fseq = fd_fseq_join( fd_topo_obj_laddr( topo, tile->waker_fseq_obj_id ) );
     977           0 :   FD_TEST( ctx->waker_fseq );
     978             : 
     979           0 :   ctx->idle_cnt       = 0UL;
     980           0 :   deadline_update( ctx, fd_clock_tile_now( ctx->clock ) );
     981           0 :   FD_TEST( tile->in_cnt<=sizeof(ctx->in)/sizeof(ctx->in[0]) );
     982           0 :   ctx->in_cnt = tile->in_cnt;
     983             : 
     984           0 :   for( ulong i=0UL; i<tile->in_cnt; i++ ) {
     985           0 :     fd_topo_link_t const * link = &topo->links[ tile->in_link_id[ i ] ];
     986           0 :     fd_topo_wksp_t const * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
     987             : 
     988           0 :     if( FD_LIKELY( !strcmp( link->name, "pack_execle"  ) ) ) ctx->in_kind[ i ] = IN_KIND_PACK_EXECLE;
     989           0 :     else if( FD_LIKELY( !strcmp( link->name, "pack_poh"     ) ) ) ctx->in_kind[ i ] = IN_KIND_PACK_POH;
     990           0 :     else if( FD_LIKELY( !strcmp( link->name, "execle_poh"   ) ) ) ctx->in_kind[ i ] = IN_KIND_EXECLE_POH;
     991           0 :     else if( FD_LIKELY( !strcmp( link->name, "shred_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SHRED_OUT;
     992           0 :     else if( FD_LIKELY( !strcmp( link->name, "gossvf_gui"   ) ) ) ctx->in_kind[ i ] = IN_KIND_GOSSVF_GUI;
     993           0 :     else if( FD_LIKELY( !strcmp( link->name, "gossip_gui"    ) ) ) ctx->in_kind[ i ] = IN_KIND_GOSSIP_GUI;
     994           0 :     else if( FD_LIKELY( !strcmp( link->name, "gossip_ciseen" ) ) ) ctx->in_kind[ i ] = IN_KIND_GOSSIP_OUT;
     995           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapct_gui"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPCT;
     996           0 :     else if( FD_LIKELY( !strcmp( link->name, "repair_net"    ) ) ) ctx->in_kind[ i ] = IN_KIND_REPAIR_NET;
     997           0 :     else if( FD_LIKELY( !strcmp( link->name, "replay_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_REPLAY_OUT;
     998           0 :     else if( FD_LIKELY( !strcmp( link->name, "replay_epoch"  ) ) ) ctx->in_kind[ i ] = IN_KIND_EPOCH;
     999           0 :     else if( FD_LIKELY( !strcmp( link->name, "genesi_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_GENESI_OUT;
    1000           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapin_gui"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPIN;
    1001           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapin_manif"  ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPIN_MANIF;
    1002           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapsv_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPSV_OUT;
    1003           0 :     else if( FD_LIKELY( !strcmp( link->name, "execrp_replay" ) ) ) ctx->in_kind[ i ] = IN_KIND_EXECRP_REPLAY;
    1004           0 :     else if( FD_LIKELY( !strcmp( link->name, "bundle_status"  ) ) ) ctx->in_kind[ i ] = IN_KIND_BUNDLE;
    1005           0 :     else if( FD_LIKELY( !strcmp( link->name, "diag_gui"       ) ) ) ctx->in_kind[ i ] = IN_KIND_DIAG;
    1006           0 :     else if( FD_LIKELY( !strcmp( link->name, "votor_out"      ) ) ) ctx->in_kind[ i ] = IN_KIND_VOTOR_OUT;
    1007           0 :     else FD_LOG_ERR(( "gui tile has unexpected input link %lu %s", i, link->name ));
    1008             : 
    1009           0 :     if( FD_LIKELY( !strcmp( link->name, "execle_poh" ) ) ) {
    1010           0 :       ulong producer = fd_topo_find_link_producer( topo, &topo->links[ tile->in_link_id[ i ] ] );
    1011           0 :       ctx->in_bank_idx[ i ] = topo->tiles[ producer ].kind_id;
    1012           0 :     }
    1013             : 
    1014           0 :     ctx->in_reliable[ i ] = tile->in_link_reliable[ i ];
    1015           0 :     ctx->in[ i ].mem    = link_wksp->wksp;
    1016           0 :     ctx->in[ i ].mtu    = link->mtu;
    1017           0 :     ctx->in[ i ].chunk0 = fd_dcache_compact_chunk0( ctx->in[ i ].mem, link->dcache );
    1018           0 :     ctx->in[ i ].wmark  = fd_dcache_compact_wmark ( ctx->in[ i ].mem, link->dcache, link->mtu );
    1019           0 :   }
    1020             : 
    1021           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
    1022           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
    1023           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
    1024           0 : }
    1025             : 
    1026             : static ulong
    1027             : populate_allowed_seccomp( fd_topo_t const *      topo,
    1028             :                           fd_topo_tile_t const * tile,
    1029             :                           ulong                  out_cnt,
    1030           0 :                           struct sock_filter *   out ) {
    1031           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
    1032           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
    1033           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
    1034             : 
    1035           0 :   uint epoll_inner_fd = (uint)FD_WAKER_INNER_FD( tile->waker_client_idx );
    1036           0 :   uint epoll_outer_fd = (uint)FD_WAKER_OUTER_FD;
    1037             : 
    1038           0 :   populate_sock_filter_policy_fd_gui_tile( out_cnt, out, (uint)fd_log_private_logfile_fd(), (uint)fd_http_server_fd( ctx->gui_server ), (uint)fd_gui_store_fd( ctx->db ), epoll_inner_fd, epoll_outer_fd );
    1039           0 :   return sock_filter_policy_fd_gui_tile_instr_cnt;
    1040           0 : }
    1041             : 
    1042             : static ulong
    1043             : populate_allowed_fds( fd_topo_t const *      topo,
    1044             :                       fd_topo_tile_t const * tile,
    1045             :                       ulong                  out_fds_cnt,
    1046           0 :                       int *                  out_fds ) {
    1047           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
    1048           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
    1049           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
    1050             : 
    1051           0 :   if( FD_UNLIKELY( out_fds_cnt<6UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
    1052             : 
    1053           0 :   ulong out_cnt = 0UL;
    1054           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
    1055           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
    1056           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
    1057           0 :   out_fds[ out_cnt++ ] = fd_http_server_fd( ctx->gui_server ); /* gui listen socket */
    1058           0 :   out_fds[ out_cnt++ ] = fd_gui_store_fd( ctx->db ); /* historical store data file */
    1059           0 :   out_fds[ out_cnt++ ] = FD_WAKER_OUTER_FD;                             /* waker outer epoll fd (rearm) */
    1060           0 :   out_fds[ out_cnt++ ] = FD_WAKER_INNER_FD( tile->waker_client_idx );   /* waker inner epoll fd */
    1061           0 :   return out_cnt;
    1062           0 : }
    1063             : 
    1064             : static ulong
    1065             : rlimit_file_cnt( fd_topo_t const *      topo FD_PARAM_UNUSED,
    1066           0 :                  fd_topo_tile_t const * tile ) {
    1067             :   /* pipefd, socket, stderr, logfile, guidb, and one spare for new accept() connections */
    1068           0 :   ulong base = 6UL;
    1069           0 :   return base + tile->gui.max_http_connections + tile->gui.max_websocket_connections;
    1070           0 : }
    1071             : 
    1072           0 : #define STEM_BURST (2UL)
    1073             : 
    1074             : /* See explanation in fd_pack */
    1075           0 : #define STEM_LAZY  (128L*3000L)
    1076             : 
    1077           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_gui_ctx_t
    1078           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_gui_ctx_t)
    1079             : 
    1080           0 : #define STEM_CALLBACK_DURING_HOUSEKEEPING during_housekeeping
    1081           0 : #define STEM_CALLBACK_METRICS_WRITE       metrics_write
    1082           0 : #define STEM_CALLBACK_BEFORE_CREDIT       before_credit
    1083           0 : #define STEM_CALLBACK_NEXT_DEADLINE       next_deadline
    1084           0 : #define STEM_CALLBACK_BEFORE_FRAG         before_frag
    1085           0 : #define STEM_CALLBACK_DURING_FRAG         during_frag
    1086           0 : #define STEM_CALLBACK_RETURNABLE_FRAG     returnable_frag
    1087           0 : #define STEM_CALLBACK_AFTER_FRAG          after_frag
    1088             : 
    1089             : #include "../../disco/stem/fd_stem.c"
    1090             : 
    1091             : #ifndef FD_TILE_TEST
    1092             : fd_topo_run_tile_t fd_tile_gui = {
    1093             :   .name                     = "gui",
    1094             :   .rlimit_file_cnt_fn       = rlimit_file_cnt,
    1095             :   .populate_allowed_seccomp = populate_allowed_seccomp,
    1096             :   .populate_allowed_fds     = populate_allowed_fds,
    1097             :   .scratch_align            = scratch_align,
    1098             :   .scratch_footprint        = scratch_footprint,
    1099             :   .privileged_init          = privileged_init,
    1100             :   .unprivileged_init        = unprivileged_init,
    1101             :   .run                      = stem_run,
    1102             : };
    1103             : #endif

Generated by: LCOV version 1.14