LCOV - code coverage report
Current view: top level - disco/gui - fd_gui_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 736 0.0 %
Date: 2026-08-29 04:30:01 Functions: 0 21 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 "generated/fd_gui_tile_seccomp.h"
      18             : 
      19             : #include "../../disco/tiles.h"
      20             : #include "../../disco/keyguard/fd_keyload.h"
      21             : #include "../../disco/keyguard/fd_keyswitch.h"
      22             : #include "../../disco/gui/fd_gui.h"
      23             : #include "../../disco/gui/fd_gui_store.h"
      24             : #include "../../disco/gui/fd_gui_hist.h"
      25             : #include "../../discof/replay/fd_execrp.h"
      26             : #include "../../disco/metrics/fd_metrics.h"
      27             : #include "../../disco/net/fd_net_tile.h"
      28             : #include "../../disco/fd_clock_tile.h"
      29             : #include "../../discof/genesis/fd_genesi_tile.h" // TODO: Layering violation
      30             : #include "../../ballet/sha256/fd_sha256.h"
      31             : #include "../../ballet/base64/fd_base64.h"
      32             : #include "../../waltz/http/fd_http_server.h"
      33             : #include "../../waltz/http/fd_http_server_private.h"
      34             : #include "../../third_party/cjson/cJSON_alloc.h"
      35             : #include "../../discof/repair/fd_repair.h"
      36             : #include "../../discof/replay/fd_replay_tile.h"
      37             : #include "../../disco/shred/fd_shred_tile.h"
      38             : #include "../../flamenco/accdb/fd_accdb_shmem.h"
      39             : 
      40           0 : #define IN_KIND_PACK_EXECLE   ( 2UL)
      41           0 : #define IN_KIND_PACK_POH      ( 3UL)
      42           0 : #define IN_KIND_EXECLE_POH    ( 4UL)
      43           0 : #define IN_KIND_SHRED_OUT     ( 5UL) /* firedancer only */
      44           0 : #define IN_KIND_NET_GOSSVF    ( 6UL) /* firedancer only */
      45           0 : #define IN_KIND_GOSSIP_NET    ( 7UL) /* firedancer only */
      46           0 : #define IN_KIND_GOSSIP_OUT    ( 8UL) /* firedancer only */
      47           0 : #define IN_KIND_SNAPCT        ( 9UL) /* firedancer only */
      48           0 : #define IN_KIND_REPAIR_NET    (10UL) /* firedancer only */
      49           0 : #define IN_KIND_TOWER_OUT     (11UL) /* firedancer only */
      50           0 : #define IN_KIND_REPLAY_OUT    (12UL) /* firedancer only */
      51           0 : #define IN_KIND_EPOCH         (13UL) /* firedancer only */
      52           0 : #define IN_KIND_GENESI_OUT    (14UL) /* firedancer only */
      53           0 : #define IN_KIND_SNAPIN        (15UL) /* firedancer only */
      54           0 : #define IN_KIND_EXECRP_REPLAY (16UL) /* firedancer only */
      55           0 : #define IN_KIND_BUNDLE        (17UL)
      56           0 : #define IN_KIND_SNAPIN_MANIF  (18UL) /* firedancer only */
      57           0 : #define IN_KIND_SNAPSV_OUT    (19UL) /* firedancer only */
      58           0 : #define IN_KIND_DIAG          (20UL) /* firedancer only */
      59             : 
      60             : FD_IMPORT_BINARY( firedancer_svg, "book/public/fire.svg" );
      61             : 
      62           0 : #define FD_HTTP_SERVER_GUI_MAX_REQUEST_LEN       65536
      63           0 : #define FD_HTTP_SERVER_GUI_MAX_WS_RECV_FRAME_LEN 65536
      64           0 : #define FD_HTTP_SERVER_GUI_MAX_WS_SEND_FRAME_CNT 8192
      65             : 
      66             : static fd_http_server_params_t
      67           0 : derive_http_params( fd_topo_tile_t const * tile ) {
      68           0 :   return (fd_http_server_params_t) {
      69           0 :     .max_connection_cnt    = tile->gui.max_http_connections,
      70           0 :     .max_ws_connection_cnt = tile->gui.max_websocket_connections,
      71           0 :     .max_request_len       = FD_HTTP_SERVER_GUI_MAX_REQUEST_LEN,
      72           0 :     .max_ws_recv_frame_len = FD_HTTP_SERVER_GUI_MAX_WS_RECV_FRAME_LEN,
      73           0 :     .max_ws_send_frame_cnt = FD_HTTP_SERVER_GUI_MAX_WS_SEND_FRAME_CNT,
      74           0 :     .outgoing_buffer_sz    = tile->gui.send_buffer_size_mb * (1UL<<20UL),
      75           0 :     .compress_websocket    = tile->gui.websocket_compression,
      76           0 :   };
      77           0 : }
      78             : 
      79             : struct fd_gui_in_ctx {
      80             :   fd_wksp_t * mem;
      81             :   ulong       mtu;
      82             :   ulong       chunk0;
      83             :   ulong       wmark;
      84             : };
      85             : 
      86             : typedef struct fd_gui_in_ctx fd_gui_in_ctx_t;
      87             : 
      88             : struct fd_gui_out_ctx {
      89             :   ulong       idx;
      90             :   fd_wksp_t * mem;
      91             :   ulong       chunk0;
      92             :   ulong       wmark;
      93             :   ulong       chunk;
      94             : };
      95             : 
      96             : typedef struct fd_gui_out_ctx fd_gui_out_ctx_t;
      97             : 
      98             : typedef struct {
      99             :   fd_topo_t const * topo;
     100             :   ulong             seed;
     101             : 
     102             :   int is_full_client;
     103             :   int snapshots_enabled;
     104             : 
     105             :   fd_gui_t * gui;
     106             :   fd_gui_store_t * db;
     107             :   fd_gui_peers_ctx_t * peers;
     108             : 
     109             :   ulong in_cnt;
     110             :   ulong idle_cnt;
     111             : 
     112             :   fd_clock_tile_t clock[1];
     113             : 
     114             :   ulong chunk;
     115             :   union {
     116             :     struct {
     117             :       ulong slot;
     118             :       ulong shred_idx;
     119             :     } repair_net;
     120             : 
     121             :     uchar net_gossvf[ FD_NET_MTU ];
     122             :     uchar gossip_net[ FD_NET_MTU ];
     123             : 
     124             :     struct {
     125             :       fd_snapsv_msg_t snapsv_out;
     126             :       int             snapsv_eom;
     127             :     };
     128             :   } parsed;
     129             : 
     130             :   fd_http_server_t * gui_server;
     131             : 
     132             :   char index_html_etag[ 3 ][ 24 ]; /* plain, zstd, gzip */
     133             :   char index_html_link[ 1024 ];
     134             : 
     135             :   long next_poll_nanos;
     136             : 
     137             :   fd_keyswitch_t * keyswitch;
     138             :   uchar const *    identity_key;
     139             : 
     140             :   int               has_vote_key;
     141             :   fd_pubkey_t const vote_key[ 1UL ];
     142             : 
     143             :   ulong           in_kind[ FD_TOPO_MAX_TILE_IN_LINKS ];
     144             :   int             in_reliable[ FD_TOPO_MAX_TILE_IN_LINKS ];
     145             :   ulong           in_bank_idx[ FD_TOPO_MAX_TILE_IN_LINKS ];
     146             :   fd_gui_in_ctx_t in[ FD_TOPO_MAX_TILE_IN_LINKS ];
     147             : 
     148             :   fd_net_rx_bounds_t net_in_bounds[ FD_TOPO_MAX_TILE_IN_LINKS ];
     149             : } fd_gui_ctx_t;
     150             : 
     151             : FD_FN_CONST static inline ulong
     152           0 : scratch_align( void ) {
     153           0 :   ulong a = alignof( fd_gui_ctx_t );
     154           0 :   a = fd_ulong_max( a, fd_http_server_align() );
     155           0 :   a = fd_ulong_max( a, fd_gui_peers_align() );
     156           0 :   a = fd_ulong_max( a, fd_gui_align() );
     157           0 :   a = fd_ulong_max( a, fd_alloc_align() );
     158           0 :   return a;
     159           0 : }
     160             : 
     161             : static inline ulong
     162           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
     163           0 :   fd_http_server_params_t http_param = derive_http_params( tile );
     164           0 :   ulong http_fp = fd_http_server_footprint( http_param );
     165           0 :   if( FD_UNLIKELY( !http_fp ) ) FD_LOG_ERR(( "Invalid [tiles.gui] config parameters" ));
     166             : 
     167           0 :   ulong l = FD_LAYOUT_INIT;
     168           0 :   l = FD_LAYOUT_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     169           0 :   l = FD_LAYOUT_APPEND( l, fd_http_server_align(),  http_fp );
     170           0 :   l = FD_LAYOUT_APPEND( l, fd_gui_peers_align(),    fd_gui_peers_footprint( http_param.max_ws_connection_cnt ) );
     171           0 :   l = FD_LAYOUT_APPEND( l, fd_gui_align(),          fd_gui_footprint( tile->gui.tile_cnt ) );
     172           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 ) ) );
     173           0 :   l = FD_LAYOUT_APPEND( l, fd_alloc_align(),        fd_alloc_footprint() );
     174           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
     175           0 : }
     176             : 
     177             : FD_FN_PURE static inline ulong
     178           0 : loose_footprint( fd_topo_tile_t const * tile FD_PARAM_UNUSED ) {
     179           0 :   return 128UL * (1UL<<20UL); /* 128MiB of heap space for the cJSON allocator */
     180           0 : }
     181             : 
     182             : static inline void
     183           0 : during_housekeeping( fd_gui_ctx_t * ctx ) {
     184           0 :   if( FD_UNLIKELY( fd_clock_tile_recal_due( ctx->clock ) ) ) {
     185           0 :     fd_clock_tile_recal( ctx->clock );
     186           0 :   }
     187             : 
     188           0 :   if( FD_UNLIKELY( fd_keyswitch_state_query( ctx->keyswitch )==FD_KEYSWITCH_STATE_SWITCH_PENDING ) ) {
     189           0 :     fd_gui_set_identity( ctx->gui, ctx->keyswitch->bytes );
     190           0 :     fd_gui_peers_handle_identity_change( ctx->peers );
     191           0 :     fd_keyswitch_state( ctx->keyswitch, FD_KEYSWITCH_STATE_COMPLETED );
     192           0 :   }
     193           0 : }
     194             : 
     195             : static inline void
     196           0 : metrics_write( fd_gui_ctx_t * ctx ) {
     197           0 :   FD_MGAUGE_SET( GUI, CONN_ACTIVE, ctx->gui_server->metrics.connection_cnt );
     198           0 :   FD_MGAUGE_SET( GUI, WEBSOCKET_CONN_ACTIVE, ctx->gui_server->metrics.ws_connection_cnt );
     199             : 
     200           0 :   FD_MCNT_SET( GUI, WEBSOCKET_FRAME_TX,     ctx->gui_server->metrics.frames_written );
     201           0 :   FD_MCNT_SET( GUI, WEBSOCKET_FRAME_RX, ctx->gui_server->metrics.frames_read );
     202             : 
     203           0 :   FD_MCNT_SET( GUI, BYTES_WRITTEN, ctx->gui_server->metrics.bytes_written );
     204           0 :   FD_MCNT_SET( GUI, BYTES_READ,    ctx->gui_server->metrics.bytes_read );
     205             : 
     206           0 :   FD_MGAUGE_SET( GUI, DISK_ALLOCATED_BYTES, fd_gui_store_file_sz( ctx->db ) );
     207             : 
     208           0 :   ulong db_cnt = fd_gui_store_cnt( ctx->db );
     209             : 
     210           0 :   ulong used_bytes  [ FD_GUI_HIST_CNT ];
     211           0 :   ulong cap_bytes   [ FD_GUI_HIST_CNT ]; ulong free_bytes  [ FD_GUI_HIST_CNT ];
     212           0 :   ulong used_slots  [ FD_GUI_HIST_CNT ];
     213           0 :   ulong cap_slots   [ FD_GUI_HIST_CNT ]; ulong free_slots  [ FD_GUI_HIST_CNT ];
     214           0 :   memset( used_bytes, 0, sizeof(used_bytes) );
     215           0 :   memset( cap_bytes,  0, sizeof(cap_bytes)  ); memset( free_bytes, 0, sizeof(free_bytes) );
     216           0 :   memset( used_slots, 0, sizeof(used_slots) );
     217           0 :   memset( cap_slots,  0, sizeof(cap_slots)  ); memset( free_slots, 0, sizeof(free_slots) );
     218             : 
     219           0 :   for( ulong i=0UL; i<db_cnt; i++ ) {
     220           0 :     fd_gui_store_ring_stats( ctx->db, i,
     221           0 :                              &used_bytes[ i ],
     222           0 :                              &cap_bytes[ i ],  &free_bytes[ i ],
     223           0 :                              &used_slots[ i ],
     224           0 :                              &cap_slots[ i ],  &free_slots[ i ] );
     225           0 :   }
     226             : 
     227           0 :   FD_MGAUGE_ENUM_COPY( GUI, DB_USED_BYTES,       used_bytes );
     228           0 :   FD_MGAUGE_ENUM_COPY( GUI, DB_CAPACITY_BYTES,   cap_bytes  );
     229           0 :   FD_MGAUGE_ENUM_COPY( GUI, DB_FREE_BYTES,       free_bytes );
     230           0 :   FD_MGAUGE_ENUM_COPY( GUI, DB_RECORD_USED,      used_slots );
     231           0 :   FD_MGAUGE_ENUM_COPY( GUI, DB_RECORD_CAPACITY,  cap_slots  );
     232           0 :   FD_MGAUGE_ENUM_COPY( GUI, DB_RECORD_FREE,      free_slots );
     233             : 
     234           0 :   fd_gui_store_metrics_t const * dm = fd_gui_store_metrics( ctx->db );
     235           0 :   FD_MCNT_ENUM_COPY( GUI, DB_KV_QUERIED,         dm->kv_lookups      );
     236           0 :   FD_MCNT_ENUM_COPY( GUI, DB_TS_RECORD_APPENDED, dm->ts_appends      );
     237           0 :   FD_MCNT_ENUM_COPY( GUI, DB_TS_SCANNED,         dm->ts_reads        );
     238           0 :   FD_MCNT_ENUM_COPY( GUI, DB_TS_RECORD_READ,     dm->ts_read_records );
     239           0 :   FD_MCNT_ENUM_COPY( GUI, DB_RECORD_EVICTED,     dm->evict_records   );
     240           0 :   FD_MCNT_ENUM_COPY( GUI, DB_EVICTION,           dm->evicts          );
     241           0 :   FD_MCNT_ENUM_COPY( GUI, DB_REGION_CLAIMED,     dm->region_grows    );
     242           0 :   fd_gui_hist_metrics_t const * hist = fd_gui_hist_metrics( ctx->gui );
     243           0 :   static ulong const zero_hist_metrics[ FD_GUI_HIST_CNT ] = { 0UL };
     244           0 :   ulong const * hist_map_full = hist ? hist->map_full : zero_hist_metrics;
     245           0 :   ulong const * hist_reserves = hist ? hist->reserves  : zero_hist_metrics;
     246           0 :   FD_MCNT_ENUM_COPY( GUI, DB_REGION_RECLAIMED,   dm->region_reclaims );
     247           0 :   FD_MCNT_ENUM_COPY( GUI, DB_MAP_FULL,           hist_map_full );
     248           0 :   FD_MCNT_ENUM_COPY( GUI, DB_FORCED_EVICTION,    hist_reserves );
     249           0 : }
     250             : 
     251             : static void
     252             : before_credit( fd_gui_ctx_t *      ctx,
     253             :                fd_stem_context_t * stem,
     254           0 :                int *               charge_busy ) {
     255           0 :   (void)stem;
     256             : 
     257           0 :   ctx->idle_cnt++;
     258           0 :   if( FD_LIKELY( ctx->idle_cnt<2UL*ctx->in_cnt ) ) return;
     259           0 :   ctx->idle_cnt = 0UL;
     260             : 
     261           0 :   int charge_busy_server = 0;
     262           0 :   long now = fd_clock_tile_now( ctx->clock );
     263           0 :   if( FD_UNLIKELY( now>=ctx->next_poll_nanos ) ) {
     264           0 :     charge_busy_server = fd_http_server_poll( ctx->gui_server, 0, 1UL );
     265           0 :     ctx->next_poll_nanos = fd_clock_tile_now( ctx->clock ) + 128L*1000L;
     266           0 :   }
     267             : 
     268           0 :   int charge_poll = 0;
     269           0 :   charge_poll |= fd_gui_poll( ctx->gui, now );
     270           0 :   charge_poll |= fd_gui_peers_poll( ctx->peers, now );
     271             : 
     272           0 :   *charge_busy = charge_busy_server | charge_poll;
     273           0 : }
     274             : 
     275             : static int
     276             : before_frag( fd_gui_ctx_t * ctx,
     277             :              ulong          in_idx,
     278             :              ulong          seq,
     279           0 :              ulong          sig ) {
     280           0 :   (void)seq;
     281             : 
     282           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_PACK_POH && sig==FD_PACK_MSG_REDUCE_MB_BOUND ) ) return 1;
     283             : 
     284           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_GOSSIP_OUT &&
     285           0 :                  (sig==FD_GOSSIP_UPDATE_TAG_WFS_DONE || sig==FD_GOSSIP_UPDATE_TAG_PEER_SATURATED) ) ) return 1;
     286           0 :   return 0;
     287           0 : }
     288             : 
     289             : static inline void
     290             : during_frag( fd_gui_ctx_t * ctx,
     291             :              ulong          in_idx,
     292             :              ulong          seq FD_PARAM_UNUSED,
     293             :              ulong          sig,
     294             :              ulong          chunk,
     295             :              ulong          sz,
     296           0 :              ulong          ctl ) {
     297           0 :   if( FD_UNLIKELY( ctx->in_kind[ in_idx ]==IN_KIND_TOWER_OUT ) ) return; /* process in returnable_frag */
     298             : 
     299           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[ in_idx ].mem, chunk );
     300             : 
     301           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_EPOCH ) ) {
     302           0 :     fd_epoch_info_msg_t * epoch_info = (fd_epoch_info_msg_t *)src;
     303           0 :     FD_TEST( epoch_info->staked_vote_cnt<=MAX_STAKE_WEIGHTS );
     304           0 :     FD_TEST( epoch_info->staked_id_cnt<=MAX_STAKE_WEIGHTS );
     305           0 :     sz = fd_epoch_info_msg_sz( epoch_info->staked_vote_cnt, epoch_info->staked_id_cnt );
     306           0 :   }
     307             : 
     308           0 :   if( FD_UNLIKELY( ctx->in_kind[ in_idx ]==IN_KIND_GENESI_OUT ) ) {
     309           0 :     sz = sig;
     310           0 :   }
     311             : 
     312           0 :   if( FD_UNLIKELY( ctx->in_kind[ in_idx ]==IN_KIND_DIAG ) ) {
     313           0 :     sz = sig;
     314           0 :   }
     315             : 
     316           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_REPLAY_OUT ) ) {
     317           0 :     if( FD_LIKELY( sig!=REPLAY_SIG_SLOT_COMPLETED &&
     318           0 :                    sig!=REPLAY_SIG_BECAME_LEADER  &&
     319           0 :                    sig!=REPLAY_SIG_ROOT_ADVANCED  &&
     320           0 :                    sig!=REPLAY_SIG_OC_ADVANCED ) ) return;
     321           0 :   }
     322             : 
     323           0 :   if( FD_UNLIKELY( (sz>0UL && (chunk<ctx->in[ in_idx ].chunk0 || chunk>ctx->in[ in_idx ].wmark)) || sz>ctx->in[ in_idx ].mtu ) )
     324           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 ));
     325             : 
     326           0 :   switch( ctx->in_kind[ in_idx ] ) {
     327           0 :     case IN_KIND_REPAIR_NET: {
     328           0 :       ctx->parsed.repair_net.slot = ULONG_MAX;
     329           0 :       uchar * payload;
     330           0 :       ulong payload_sz;
     331           0 :       if( FD_LIKELY( fd_ip4_udp_hdr_strip( src, sz, &payload, &payload_sz, NULL, NULL, NULL ) ) ) {
     332           0 :         fd_repair_msg_t const * msg = (fd_repair_msg_t const *)fd_type_pun_const( payload );
     333           0 :         if( FD_LIKELY( msg->kind==FD_REPAIR_KIND_SHRED ) ) {
     334           0 :           if( FD_UNLIKELY( msg->shred.slot==0 ) ) break;
     335           0 :           ctx->parsed.repair_net.slot = msg->shred.slot;
     336           0 :           ctx->parsed.repair_net.shred_idx = msg->shred.shred_idx;
     337           0 :         }
     338           0 :       }
     339           0 :       break;
     340           0 :     }
     341           0 :     case IN_KIND_NET_GOSSVF: {
     342           0 :       FD_TEST( sz<=sizeof(ctx->parsed.net_gossvf) );
     343           0 :       uchar const * net_src = fd_net_rx_translate_frag( &ctx->net_in_bounds[ in_idx ], chunk, ctl, sz );
     344           0 :       fd_memcpy( ctx->parsed.net_gossvf, net_src, sz );
     345           0 :       break;
     346           0 :     }
     347           0 :     case IN_KIND_GOSSIP_NET: {
     348           0 :       FD_TEST( sz<=sizeof(ctx->parsed.gossip_net) );
     349           0 :       fd_memcpy( ctx->parsed.gossip_net, src, sz );
     350           0 :       break;
     351           0 :     }
     352           0 :     case IN_KIND_SNAPSV_OUT: {
     353           0 :       FD_TEST( sz<=sizeof(ctx->parsed.snapsv_out) );
     354           0 :       fd_memcpy( &ctx->parsed.snapsv_out, src, sz );
     355           0 :       ctx->parsed.snapsv_eom = fd_frag_meta_ctl_eom( ctl );
     356           0 :       break;
     357           0 :     }
     358           0 :   }
     359             : 
     360           0 :   ctx->chunk = chunk;
     361           0 : }
     362             : 
     363             : static inline void
     364             : after_frag( fd_gui_ctx_t *      ctx,
     365             :             ulong               in_idx,
     366             :             ulong               seq,
     367             :             ulong               sig,
     368             :             ulong               sz,
     369             :             ulong               tsorig,
     370             :             ulong               tspub,
     371           0 :             fd_stem_context_t * stem ) {
     372           0 :   (void)seq; (void)stem;
     373             : 
     374           0 :   if( FD_LIKELY( ctx->in_reliable[ in_idx ] ) ) ctx->idle_cnt = 0UL;
     375             : 
     376           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[ in_idx ].mem, ctx->chunk );
     377             : 
     378           0 :   if( FD_UNLIKELY( ctx->in_kind[ in_idx ]==IN_KIND_TOWER_OUT ) ) return; /* process in returnable_frag */
     379             : 
     380           0 :   switch( ctx->in_kind[ in_idx ] ) {
     381           0 :     case IN_KIND_EXECRP_REPLAY: {
     382           0 :       if( FD_LIKELY( sig>>32==FD_EXECRP_TT_TXN_EXEC ) ) {
     383           0 :         fd_execrp_task_done_msg_t * msg = (fd_execrp_task_done_msg_t *)src;
     384             : 
     385           0 :         long tsorig_ns = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tsorig );
     386           0 :         long tspub_ns  = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tspub  );
     387           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 ) );
     388             : 
     389           0 :         int txn_succeeded = msg->txn_exec->is_committable && !msg->txn_exec->is_fees_only && !msg->txn_exec->txn_err;
     390           0 :         if( FD_UNLIKELY( msg->txn_exec->vote.slot!=ULONG_MAX && txn_succeeded ) ) {
     391           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) );
     392           0 :           int is_us = vote_acct_is_us && !memcmp( ctx->gui->summary.identity_key->uc, msg->txn_exec->vote.identity->uc, sizeof(fd_pubkey_t) );
     393           0 :           fd_gui_peers_handle_vote( ctx->peers,
     394           0 :                                     msg->txn_exec->vote.vote_acct,
     395           0 :                                     msg->txn_exec->vote.slot,
     396           0 :                                     is_us );
     397           0 :           if( FD_UNLIKELY( is_us ) ) {
     398           0 :             for( ulong i=0UL; i<msg->txn_exec->vote.vote_slot_cnt; i++ ) {
     399           0 :               fd_gui_stage_landed_vote( ctx->gui, msg->txn_exec->slot, msg->txn_exec->bank_seq, msg->txn_exec->vote.vote_slots[ i ] );
     400           0 :             }
     401           0 :           }
     402           0 :         }
     403           0 :       }
     404             : 
     405           0 :       break;
     406           0 :     }
     407           0 :     case IN_KIND_REPLAY_OUT: {
     408           0 :       if( FD_UNLIKELY( sig==REPLAY_SIG_SLOT_COMPLETED ) ) {
     409           0 :         fd_replay_slot_completed_t const * slot_completed =  (fd_replay_slot_completed_t const *)src;
     410             : 
     411           0 :         fd_gui_peers_update_delinquency( ctx->peers, fd_clock_tile_now( ctx->clock ) );
     412             : 
     413           0 :         fd_gui_handle_replay_update( ctx->gui, slot_completed, ctx->peers->slot_voted, fd_clock_tile_now( ctx->clock ) );
     414           0 :       } else if( FD_UNLIKELY( sig==REPLAY_SIG_BECAME_LEADER ) ) {
     415           0 :         fd_became_leader_t * became_leader = (fd_became_leader_t *)src;
     416           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 );
     417           0 :       } else if( FD_UNLIKELY( sig==REPLAY_SIG_ROOT_ADVANCED ) ) {
     418           0 :         fd_replay_root_advanced_t const * ra = (fd_replay_root_advanced_t const *)src;
     419           0 :         fd_gui_handle_root_advanced( ctx->gui, ra->slot, ra->bank_seq, fd_clock_tile_now( ctx->clock ) );
     420           0 :       } else if( FD_UNLIKELY( sig==REPLAY_SIG_OC_ADVANCED ) ) {
     421           0 :         fd_replay_oc_advanced_t const * oc = (fd_replay_oc_advanced_t const *)src;
     422           0 :         fd_gui_handle_oc_advanced( ctx->gui, oc->slot, oc->bank_seq, fd_clock_tile_now( ctx->clock ) );
     423           0 :       } else {
     424           0 :         return;
     425           0 :       }
     426           0 :       break;
     427           0 :     }
     428           0 :     case IN_KIND_EPOCH: {
     429           0 :       fd_epoch_info_msg_t * epoch_info = (fd_epoch_info_msg_t *)src;
     430           0 :       fd_gui_handle_epoch_info( ctx->gui, epoch_info, fd_clock_tile_now( ctx->clock ) );
     431           0 :       fd_gui_peers_handle_epoch_info( ctx->peers, epoch_info, fd_clock_tile_now( ctx->clock ) );
     432           0 :       break;
     433           0 :     }
     434           0 :     case IN_KIND_SNAPIN: {
     435           0 :       fd_gui_peers_handle_config_account( ctx->peers, src, sz );
     436           0 :       break;
     437           0 :     }
     438           0 :     case IN_KIND_SNAPIN_MANIF: {
     439           0 :       if( fd_ssmsg_sig_message( sig )==FD_SSMSG_DONE ) {
     440           0 :         fd_gui_peers_commit_snapshot_manifest( ctx->peers );
     441           0 :       } else {
     442           0 :         fd_gui_stage_snapshot_manifest( ctx->gui, (fd_snapshot_manifest_t const *)src );
     443           0 :         fd_gui_peers_stage_snapshot_manifest( ctx->peers, (fd_snapshot_manifest_t const *)src, fd_clock_tile_now( ctx->clock ) );
     444           0 :       }
     445           0 :       break;
     446           0 :     }
     447           0 :     case IN_KIND_GENESI_OUT: {
     448           0 :       fd_genesis_meta_t const * meta = (fd_genesis_meta_t const *)src;
     449           0 :       fd_gui_handle_genesis_hash( ctx->gui, &meta->genesis_hash );
     450           0 :       break;
     451           0 :     }
     452           0 :     case IN_KIND_SHRED_OUT: {
     453           0 :       long tsorig_nanos = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tsorig );
     454           0 :       uint sig_src      = fd_shred_sig_src( sig );
     455           0 :       if( FD_LIKELY( sig_src==SHRED_SIG_SRC_TURBINE || sig_src==SHRED_SIG_SRC_REPAIR || sig_src==SHRED_SIG_SRC_BAD_REPAIR ) ) {
     456           0 :         fd_shred_base_t const * msg = (fd_shred_base_t const *)fd_type_pun_const( src );
     457           0 :         ulong slot      = msg->shred.slot;
     458           0 :         ulong shred_idx = msg->shred.idx;
     459           0 :         int is_turbine  = sig_src==SHRED_SIG_SRC_TURBINE;
     460             :         /* tsorig is the timestamp when the shred was received by the shred tile */
     461           0 :         fd_gui_handle_shred( ctx->gui, slot, shred_idx, is_turbine, tsorig_nanos, fd_clock_tile_now( ctx->clock ) );
     462           0 :       }
     463           0 :       if( FD_UNLIKELY( sig==SHRED_SIG_FEC_COMPLETE_LEADER ) ) {
     464           0 :         fd_fec_complete_t const * complete_msg = (fd_fec_complete_t const *)fd_type_pun_const( src );
     465           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 ) );
     466           0 :       }
     467           0 :       break;
     468           0 :     }
     469           0 :     case IN_KIND_SNAPCT: {
     470           0 :       fd_gui_handle_snapshot_update( ctx->gui, (fd_snapct_update_t *)src );
     471           0 :       break;
     472           0 :     }
     473           0 :     case IN_KIND_SNAPSV_OUT: {
     474           0 :       long sample_time_nanos = fd_frag_meta_ts_decomp( tspub, fd_clock_tile_now( ctx->clock ) );
     475           0 :       fd_gui_handle_snapsv_update( ctx->gui, sig, &ctx->parsed.snapsv_out, sz, ctx->parsed.snapsv_eom, sample_time_nanos );
     476           0 :       break;
     477           0 :     }
     478           0 :     case IN_KIND_REPAIR_NET: {
     479           0 :       if( FD_UNLIKELY( ctx->parsed.repair_net.slot==ULONG_MAX ) ) break;
     480           0 :       long tsorig_ns = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tsorig );
     481           0 :       fd_gui_handle_repair_request( ctx->gui, ctx->parsed.repair_net.slot, ctx->parsed.repair_net.shred_idx, tsorig_ns );
     482           0 :       break;
     483           0 :     }
     484           0 :     case IN_KIND_NET_GOSSVF: {
     485           0 :       uchar * payload;
     486           0 :       ulong payload_sz;
     487           0 :       fd_ip4_hdr_t * ip4_hdr;
     488           0 :       fd_udp_hdr_t * udp_hdr;
     489           0 :       if( FD_LIKELY( fd_ip4_udp_hdr_strip( ctx->parsed.net_gossvf, sz, &payload, &payload_sz, NULL, &ip4_hdr, &udp_hdr ) ) ) {
     490           0 :         fd_gossip_socket_t socket = {
     491           0 :           .is_ipv6 = 0,
     492           0 :           .ip4 = ip4_hdr->saddr,
     493           0 :           .port = udp_hdr->net_sport,
     494           0 :         };
     495           0 :         fd_gui_peers_handle_gossip_message( ctx->peers, payload, payload_sz, &socket, 1 );
     496           0 :       }
     497           0 :       break;
     498           0 :     }
     499           0 :     case IN_KIND_GOSSIP_NET: {
     500           0 :       uchar * payload;
     501           0 :       ulong payload_sz;
     502           0 :       fd_ip4_hdr_t * ip4_hdr;
     503           0 :       fd_udp_hdr_t * udp_hdr;
     504           0 :       FD_TEST( fd_ip4_udp_hdr_strip( ctx->parsed.gossip_net, sz, &payload, &payload_sz, NULL, &ip4_hdr, &udp_hdr ) );
     505           0 :       fd_gossip_socket_t socket = {
     506           0 :         .is_ipv6 = 0,
     507           0 :         .ip4 = ip4_hdr->daddr,
     508           0 :         .port = udp_hdr->net_dport,
     509           0 :       };
     510           0 :       fd_gui_peers_handle_gossip_message( ctx->peers, payload, payload_sz, &socket, 0 );
     511           0 :       break;
     512           0 :     }
     513           0 :     case IN_KIND_GOSSIP_OUT: {
     514           0 :       fd_gui_peers_handle_gossip_update( ctx->peers, (fd_gossip_update_message_t *)src, fd_clock_tile_now( ctx->clock ) );
     515           0 :       break;
     516           0 :     }
     517           0 :     case IN_KIND_PACK_POH: {
     518           0 :       if( FD_UNLIKELY( sig==FD_PACK_MSG_DONE_DRAINING ) ) fd_gui_done_draining( ctx->gui, fd_clock_tile_now( ctx->clock ) );
     519           0 :       else                                                fd_gui_unbecame_leader( ctx->gui, fd_disco_execle_sig_slot( sig ), (fd_done_packing_t const *)src );
     520           0 :       break;
     521           0 :     }
     522           0 :     case IN_KIND_PACK_EXECLE: {
     523           0 :       FD_TEST( sz>=sizeof(fd_microblock_execle_trailer_t) );
     524           0 :       FD_TEST( (sz-sizeof(fd_microblock_execle_trailer_t))%sizeof(fd_txn_e_t)==0UL );
     525             : 
     526           0 :       if( FD_LIKELY( fd_disco_poh_sig_pkt_type( sig )==POH_PKT_TYPE_MICROBLOCK ) ) {
     527           0 :         fd_microblock_execle_trailer_t trailer[1];
     528           0 :         fd_memcpy( trailer, src+sz-sizeof(fd_microblock_execle_trailer_t), sizeof(fd_microblock_execle_trailer_t) );
     529           0 :         long tspub_ns = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tspub );
     530           0 :         fd_gui_microblock_execution_begin( ctx->gui,
     531           0 :                                           tspub_ns,
     532           0 :                                           fd_disco_poh_sig_slot( sig ),
     533           0 :                                           (fd_txn_e_t *)src,
     534           0 :                                           (sz-sizeof( fd_microblock_execle_trailer_t ))/sizeof( fd_txn_e_t ),
     535           0 :                                           (uint)trailer->microblock_idx,
     536           0 :                                           trailer->pack_txn_idx,
     537           0 :                                           trailer->bank_seq,
     538           0 :                                           fd_clock_tile_now( ctx->clock ) );
     539           0 :       } else {
     540           0 :         FD_LOG_ERR(( "unexpected poh packet type %lu", fd_disco_poh_sig_pkt_type( sig ) ));
     541           0 :       }
     542           0 :       break;
     543           0 :     }
     544           0 :     case IN_KIND_EXECLE_POH: {
     545           0 :       FD_TEST( sz>=sizeof(fd_microblock_trailer_t) );
     546           0 :       FD_TEST( (sz-sizeof(fd_microblock_trailer_t))%sizeof(fd_txn_p_t)==0UL );
     547             : 
     548           0 :       fd_microblock_trailer_t trailer[1];
     549           0 :       fd_memcpy( trailer, src+sz-sizeof(fd_microblock_trailer_t), sizeof(fd_microblock_trailer_t) );
     550           0 :       long tspub_ns = fd_clock_tile_tickcomp_to_wallclock( ctx->clock, tspub );
     551           0 :       ulong txn_cnt = (sz-sizeof( fd_microblock_trailer_t ))/sizeof(fd_txn_p_t);
     552           0 :       fd_gui_microblock_execution_end( ctx->gui,
     553           0 :                                       tspub_ns,
     554           0 :                                       ctx->in_bank_idx[ in_idx ],
     555           0 :                                       fd_disco_execle_sig_slot( sig ),
     556           0 :                                       txn_cnt,
     557           0 :                                       (fd_txn_p_t *)src,
     558           0 :                                       trailer->pack_txn_idx,
     559           0 :                                       trailer->txn_ns_dt,
     560           0 :                                       trailer->tips,
     561           0 :                                       trailer->bank_seq,
     562           0 :                                       fd_clock_tile_now( ctx->clock ) );
     563           0 :       break;
     564           0 :     }
     565           0 :     case IN_KIND_BUNDLE: {
     566           0 :       fd_gui_handle_block_engine_update( ctx->gui, (fd_bundle_block_engine_update_t *)src );
     567           0 :       break;
     568           0 :     }
     569           0 :     case IN_KIND_DIAG: {
     570           0 :       fd_gui_handle_diag_snapshot( ctx->gui, src, sig );
     571           0 :       break;
     572           0 :     }
     573           0 :     default: FD_LOG_ERR(( "unexpected in_kind %lu", ctx->in_kind[ in_idx ] ));
     574           0 :   }
     575           0 : }
     576             : 
     577             : static int
     578             : returnable_frag( fd_gui_ctx_t *      ctx,
     579             :                  ulong               in_idx,
     580             :                  ulong               seq    FD_PARAM_UNUSED,
     581             :                  ulong               sig,
     582             :                  ulong               chunk,
     583             :                  ulong               sz,
     584             :                  ulong               ctl    FD_PARAM_UNUSED,
     585             :                  ulong               tsorig FD_PARAM_UNUSED,
     586             :                  ulong               tspub  FD_PARAM_UNUSED,
     587           0 :                  fd_stem_context_t * stem   FD_PARAM_UNUSED ) {
     588           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 */
     589             : 
     590           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]!=IN_KIND_TOWER_OUT ) ) return 0; /* process in {before|during|after}_frag */
     591             : 
     592           0 :   if( FD_UNLIKELY( (sz>0UL && (chunk<ctx->in[ in_idx ].chunk0 || chunk>ctx->in[ in_idx ].wmark)) || sz>ctx->in[ in_idx ].mtu ) )
     593           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 ));
     594             : 
     595           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[ in_idx ].mem, chunk );
     596             : 
     597           0 :   if( FD_LIKELY( sig==FD_TOWER_SIG_SLOT_DONE ) ) {
     598           0 :     FD_TEST( sz>=sizeof(fd_tower_slot_done_t) );
     599           0 :     fd_tower_slot_done_t const * tower = (fd_tower_slot_done_t const *)src;
     600           0 :     if( FD_UNLIKELY( !fd_gui_slot_get( ctx->gui, tower->replay_slot, tower->replay_bank_seq ) ) ) return 1; /* block not replayed yet: defer polling */
     601           0 :     fd_gui_handle_tower_update( ctx->gui, tower, fd_clock_tile_now( ctx->clock ) );
     602           0 :   }
     603             : 
     604           0 :   return 0;
     605           0 : }
     606             : 
     607             : static fd_http_server_response_t
     608           0 : gui_http_request( fd_http_server_request_t const * request ) {
     609           0 :   if( FD_UNLIKELY( request->method!=FD_HTTP_SERVER_METHOD_GET ) ) {
     610           0 :     return (fd_http_server_response_t){
     611           0 :       .status = 405,
     612           0 :     };
     613           0 :   }
     614             : 
     615           0 :   if( FD_LIKELY( !strcmp( request->path, "/websocket" ) ) ) {
     616           0 :     return (fd_http_server_response_t){
     617           0 :       .status            = 200,
     618           0 :       .upgrade_websocket = 1,
     619           0 : #ifdef FD_HAS_ZSTD
     620           0 :       .compress_websocket = request->headers.compress_websocket,
     621             : #else
     622             :       .compress_websocket = 0,
     623             : #endif
     624           0 :     };
     625           0 :   } else if( FD_LIKELY( !strcmp( request->path, "/favicon.svg" ) ) ) {
     626           0 :     return (fd_http_server_response_t){
     627           0 :       .status            = 200,
     628           0 :       .static_body       = firedancer_svg,
     629           0 :       .static_body_len   = firedancer_svg_sz,
     630           0 :       .content_type      = "image/svg+xml",
     631           0 :       .cache_control     = "public, max-age=86400",
     632           0 :       .upgrade_websocket = 0,
     633           0 :     };
     634           0 :   }
     635             : 
     636           0 :   int is_vite_page = !strcmp( request->path, "/" ) ||
     637           0 :                      !strcmp( request->path, "/slotDetails" ) ||
     638           0 :                      !strcmp( request->path, "/leaderSchedule" ) ||
     639           0 :                      !strcmp( request->path, "/gossip") ||
     640           0 :                      !strcmp( request->path, "/accounts") ||
     641           0 :                      !strncmp( request->path, "/?", strlen("/?") ) ||
     642           0 :                      !strncmp( request->path, "/slotDetails?", strlen("/slotDetails?") ) ||
     643           0 :                      !strncmp( request->path, "/leaderSchedule?", strlen("/leaderSchedule?") ) ||
     644           0 :                      !strncmp( request->path, "/gossip?", strlen("/gossip?") ) ||
     645           0 :                      !strncmp( request->path, "/accounts?", strlen("/accounts?") );
     646             : 
     647           0 :   for( fd_http_static_file_t const * f = STATIC_FILES; f->name; f++ ) {
     648           0 :     if( !strcmp( request->path, f->name ) ||
     649           0 :         (!strcmp( f->name, "/index.html" ) && is_vite_page) ) {
     650           0 :       char const * content_type = NULL;
     651             : 
     652           0 :       char const * ext = strrchr( f->name, '.' );
     653           0 :       if( FD_LIKELY( ext ) ) {
     654           0 :         if( !strcmp( ext, ".html" ) ) content_type = "text/html; charset=utf-8";
     655           0 :         else if( !strcmp( ext, ".css" ) ) content_type = "text/css";
     656           0 :         else if( !strcmp( ext, ".js" ) ) content_type = "application/javascript";
     657           0 :         else if( !strcmp( ext, ".svg" ) ) content_type = "image/svg+xml";
     658           0 :         else if( !strcmp( ext, ".woff" ) ) content_type = "font/woff";
     659           0 :         else if( !strcmp( ext, ".woff2" ) ) content_type = "font/woff2";
     660           0 :         else if( !strcmp( ext, ".wasm" ) ) content_type = "application/wasm";
     661           0 :       }
     662             : 
     663           0 :       char const * cache_control = NULL;
     664           0 :       if( FD_LIKELY( !strncmp( request->path, "/assets", 7 ) ) ) cache_control = "public, max-age=31536000, immutable";
     665           0 :       else if( FD_LIKELY( !strcmp( f->name, "/index.html" ) ) )  cache_control = "no-cache";
     666           0 :       else if( FD_UNLIKELY( !strcmp( f->name, "/version" ) ) )   cache_control = "no-cache";
     667             : 
     668           0 :       const uchar * data = f->data;
     669           0 :       ulong data_len = *(f->data_len);
     670             : 
     671           0 :       int accepts_zstd = 0;
     672           0 :       if( FD_LIKELY( request->headers.accept_encoding ) ) {
     673           0 :         accepts_zstd = !!strstr( request->headers.accept_encoding, "zstd" );
     674           0 :       }
     675             : 
     676           0 :       int accepts_gzip = 0;
     677           0 :       if( FD_LIKELY( request->headers.accept_encoding ) ) {
     678           0 :         accepts_gzip = !!strstr( request->headers.accept_encoding, "gzip" );
     679           0 :       }
     680             : 
     681           0 :       char const * content_encoding = NULL;
     682           0 :       ulong enc_idx = 0UL;
     683           0 :       if( FD_LIKELY( accepts_zstd && f->zstd_data ) ) {
     684           0 :         content_encoding = "zstd";
     685           0 :         data = f->zstd_data;
     686           0 :         data_len = *(f->zstd_data_len);
     687           0 :         enc_idx = 1UL;
     688           0 :       } else if( FD_LIKELY( accepts_gzip && f->gzip_data ) ) {
     689           0 :         content_encoding = "gzip";
     690           0 :         data = f->gzip_data;
     691           0 :         data_len = *(f->gzip_data_len);
     692           0 :         enc_idx = 2UL;
     693           0 :       }
     694             : 
     695           0 :       char const * etag = NULL;
     696           0 :       char const * link = NULL;
     697           0 :       if( FD_LIKELY( !strcmp( f->name, "/index.html" ) ) ) {
     698           0 :         fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)request->ctx;
     699           0 :         etag = ctx->index_html_etag[ enc_idx ];
     700           0 :         link = ctx->index_html_link[ 0 ] ? ctx->index_html_link : NULL;
     701           0 :         if( FD_UNLIKELY( fd_http_server_etag_matches( request->headers.if_none_match, etag ) ) ) {
     702           0 :           return (fd_http_server_response_t){
     703           0 :             .status        = 304,
     704           0 :             .cache_control = cache_control,
     705           0 :             .etag          = etag,
     706           0 :             .link          = link,
     707           0 :           };
     708           0 :         }
     709           0 :       }
     710             : 
     711           0 :       return (fd_http_server_response_t){
     712           0 :         .status            = 200,
     713           0 :         .static_body       = data,
     714           0 :         .static_body_len   = data_len,
     715           0 :         .content_type      = content_type,
     716           0 :         .cache_control     = cache_control,
     717           0 :         .content_encoding  = content_encoding,
     718           0 :         .etag              = etag,
     719           0 :         .link              = link,
     720           0 :         .upgrade_websocket = 0,
     721           0 :       };
     722           0 :     }
     723           0 :   }
     724             : 
     725           0 :   return (fd_http_server_response_t){
     726           0 :     .status            = 404,
     727           0 :   };
     728           0 : }
     729             : 
     730             : static void
     731             : gui_ws_open( ulong  conn_id,
     732           0 :              void * _ctx ) {
     733           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     734             : 
     735           0 :   fd_gui_ws_open( ctx->gui, conn_id, fd_clock_tile_now( ctx->clock ) );
     736           0 :   fd_gui_peers_ws_open( ctx->peers, conn_id, fd_clock_tile_now( ctx->clock ) );
     737           0 : }
     738             : 
     739             : static void
     740             : gui_ws_close( ulong  conn_id,
     741             :               int    reason,
     742           0 :               void * _ctx ) {
     743           0 :   (void) reason;
     744           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     745           0 :   fd_gui_peers_ws_close( ctx->peers, conn_id );
     746           0 : }
     747             : 
     748             : static void
     749             : gui_ws_message( ulong         ws_conn_id,
     750             :                 uchar const * data,
     751             :                 ulong         data_len,
     752           0 :                 void *        _ctx ) {
     753           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     754             : 
     755           0 :   int reason = fd_gui_ws_message( ctx->gui, ws_conn_id, data, data_len );
     756           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 );
     757             : 
     758           0 :   if( FD_UNLIKELY( reason<0 ) ) fd_http_server_ws_close( ctx->gui_server, ws_conn_id, reason );
     759           0 : }
     760             : 
     761             : static void
     762             : privileged_init( fd_topo_t const *      topo,
     763           0 :                  fd_topo_tile_t const * tile ) {
     764           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     765             : 
     766           0 :   fd_http_server_params_t http_param = derive_http_params( tile );
     767             : 
     768           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     769           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     770           0 :   FD_TEST( fd_rng_secure( &ctx->seed, sizeof(ctx->seed) ) );
     771           0 :   http_param.treap_seed = ctx->seed;
     772           0 :   fd_http_server_t * _gui = FD_SCRATCH_ALLOC_APPEND( l, fd_http_server_align(), fd_http_server_footprint( http_param ) );
     773           0 :                      FD_SCRATCH_ALLOC_APPEND( l, fd_gui_peers_align(),    fd_gui_peers_footprint( http_param.max_ws_connection_cnt ) );
     774           0 :                      FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(),          fd_gui_footprint( tile->gui.tile_cnt )                     );
     775           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 ) ) );
     776             : 
     777           0 :   fd_http_server_callbacks_t gui_callbacks = {
     778           0 :     .request    = gui_http_request,
     779           0 :     .ws_open    = gui_ws_open,
     780           0 :     .ws_close   = gui_ws_close,
     781           0 :     .ws_message = gui_ws_message,
     782           0 :   };
     783           0 :   ctx->gui_server = fd_http_server_join( fd_http_server_new( _gui, http_param, gui_callbacks, ctx ) );
     784           0 :   fd_http_server_listen( ctx->gui_server, tile->gui.listen_addr, tile->gui.listen_port );
     785             : 
     786           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() ));
     787             : 
     788           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 ) ) );
     789           0 :   if( FD_UNLIKELY( !ctx->db ) ) FD_LOG_ERR(( "fd_gui_store_new(%s) failed; gui tile cannot start", tile->gui.gui_database_path ));
     790             : 
     791           0 :   if( FD_UNLIKELY( !strcmp( tile->gui.identity_key_path, "" ) ) )
     792           0 :     FD_LOG_ERR(( "identity_key_path not set" ));
     793             : 
     794           0 :   ctx->identity_key = fd_keyload_load( tile->gui.identity_key_path, /* pubkey only: */ 1 );
     795             : 
     796           0 :   if( FD_UNLIKELY( !strcmp( tile->gui.vote_key_path, "" ) ) ) {
     797           0 :     ctx->has_vote_key = 0;
     798           0 :   } else {
     799           0 :     ctx->has_vote_key = 1;
     800           0 :     if( FD_UNLIKELY( !fd_base58_decode_32( tile->gui.vote_key_path, (uchar *)ctx->vote_key->uc ) ) ) {
     801           0 :       const uchar * vote_key = fd_keyload_load( tile->gui.vote_key_path, /* pubkey only: */ 1 );
     802           0 :       fd_memcpy( (uchar *)ctx->vote_key->uc, vote_key, 32UL );
     803           0 :     }
     804           0 :   }
     805           0 : }
     806             : 
     807             : static int
     808             : index_html_refs( fd_http_static_file_t const * html,
     809           0 :                  char const *                  name ) {
     810           0 :   ulong name_len = strlen( name );
     811           0 :   if( FD_UNLIKELY( name_len>*(html->data_len) ) ) return 0;
     812           0 :   for( ulong i=0UL; i<=*(html->data_len)-name_len; i++ ) if( FD_UNLIKELY( !memcmp( html->data+i, name, name_len ) ) ) return 1;
     813           0 :   return 0;
     814           0 : }
     815             : 
     816             : static void
     817             : unprivileged_init( fd_topo_t const *      topo,
     818           0 :                    fd_topo_tile_t const * tile ) {
     819           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     820             : 
     821           0 :   fd_http_server_params_t http_param = derive_http_params( tile );
     822           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     823           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t )                                    );
     824           0 :                        FD_SCRATCH_ALLOC_APPEND( l, fd_http_server_align(),  fd_http_server_footprint( http_param )                    );
     825           0 :   void * _peers      = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_peers_align(),    fd_gui_peers_footprint( http_param.max_ws_connection_cnt) );
     826           0 :   void * _gui        = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(),          fd_gui_footprint( tile->gui.tile_cnt )                     );
     827           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 ) ) );
     828           0 :   void * _alloc      = FD_SCRATCH_ALLOC_APPEND( l, fd_alloc_align(),        fd_alloc_footprint()                                      );
     829             : 
     830           0 :   fd_http_static_file_t const * index_html = NULL;
     831           0 :   for( fd_http_static_file_t const * f = STATIC_FILES; f->name; f++ ) {
     832           0 :     if( FD_UNLIKELY( !strcmp( f->name, "/index.html" ) ) ) index_html = f;
     833           0 :   }
     834           0 :   FD_TEST( index_html );
     835             : 
     836           0 :   {
     837           0 :     fd_http_static_file_t const * f = index_html;
     838           0 :     uchar hash[ 32 ];
     839           0 :     uchar const * rep_data[ 3 ]     = { f->data,     f->zstd_data,     f->gzip_data     };
     840           0 :     ulong const * rep_data_len[ 3 ] = { f->data_len, f->zstd_data_len, f->gzip_data_len };
     841           0 :     for( ulong e=0UL; e<3UL; e++ ) {
     842           0 :       ctx->index_html_etag[ e ][ 0 ] = '\0';
     843           0 :       if( FD_UNLIKELY( !rep_data[ e ] ) ) continue;
     844           0 :       fd_sha256_hash( rep_data[ e ], *(rep_data_len[ e ]), hash );
     845           0 :       char b64[ FD_BASE64_ENC_SZ( 9UL )+1UL ];
     846           0 :       b64[ fd_base64_encode( b64, hash, 9UL ) ] = '\0';
     847           0 :       FD_TEST( fd_cstr_printf_check( ctx->index_html_etag[ e ], sizeof(ctx->index_html_etag[ e ]), NULL, "\"%s\"", b64 ) );
     848           0 :     }
     849           0 :   }
     850             : 
     851           0 :   char const * preload_js     = NULL;
     852           0 :   char const * preload_css    = NULL;
     853           0 :   char const * preload_worker = NULL;
     854           0 :   char const * preload_wasm   = NULL;
     855           0 :   char const * split_js[ 16 ];
     856           0 :   ulong        split_js_cnt   = 0UL;
     857           0 :   for( fd_http_static_file_t const * f = STATIC_FILES; f->name; f++ ) {
     858           0 :     char const * ext = strrchr( f->name, '.' );
     859           0 :     if( FD_UNLIKELY( !ext ) ) continue;
     860           0 :     if( FD_UNLIKELY( !strncmp( f->name, "/assets/index-", 14UL ) ) ) {
     861           0 :       if( !strcmp( ext, ".js" ) ) {
     862           0 :         if( FD_UNLIKELY( index_html_refs( index_html, f->name ) ) )                              preload_js = f->name;
     863           0 :         else if( FD_LIKELY( split_js_cnt<sizeof(split_js)/sizeof(split_js[ 0 ]) ) )              split_js[ split_js_cnt++ ] = f->name;
     864           0 :       }
     865           0 :       else if( !strcmp( ext, ".css" ) && index_html_refs( index_html, f->name ) )                preload_css = f->name;
     866           0 :     }
     867           0 :     else if( FD_UNLIKELY( !strncmp( f->name, "/assets/wsWorker-", 17UL ) && !strcmp( ext, ".js"   ) ) ) preload_worker = f->name;
     868           0 :     else if( FD_UNLIKELY( !strncmp( f->name, "/assets/zstd-dec-", 17UL ) && !strcmp( ext, ".wasm" ) ) ) preload_wasm   = f->name;
     869           0 :     else if( FD_UNLIKELY( !strncmp( f->name, "/assets/UplotReact-", 19UL ) && !strcmp( ext, ".js" ) &&
     870           0 :                           split_js_cnt<sizeof(split_js)/sizeof(split_js[ 0 ]) ) )                split_js[ split_js_cnt++ ] = f->name;
     871           0 :   }
     872             : 
     873           0 :   ctx->index_html_link[ 0 ] = '\0';
     874           0 :   ulong off = 0UL, sz;
     875           0 :   if( FD_LIKELY( preload_js ) ) {
     876           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 ) );
     877           0 :     off += sz;
     878           0 :   }
     879           0 :   if( FD_LIKELY( preload_css ) ) {
     880           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 ) );
     881           0 :     off += sz;
     882           0 :   }
     883           0 :   if( FD_LIKELY( preload_worker ) ) {
     884           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 ) );
     885           0 :     off += sz;
     886           0 :   }
     887           0 :   if( FD_LIKELY( preload_wasm ) ) {
     888           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 ) );
     889           0 :     off += sz;
     890           0 :   }
     891           0 :   for( ulong i=0UL; i<split_js_cnt; i++ ) {
     892           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 ] ) );
     893           0 :     off += sz;
     894           0 :   }
     895             : 
     896             :   /* The backtest topology has no repair tile (the backt tile stands in
     897             :      for repair and tower), but it is still the full Firedancer client. */
     898           0 :   ctx->is_full_client = ULONG_MAX!=fd_topo_find_tile( topo, "repair", 0UL ) ||
     899           0 :                         ULONG_MAX!=fd_topo_find_tile( topo, "backt",  0UL );
     900           0 :   ctx->snapshots_enabled = ULONG_MAX!=fd_topo_find_tile( topo, "snapct", 0UL );
     901             : 
     902           0 :   fd_clock_tile_init( ctx->clock );
     903             : 
     904           0 :   ctx->topo = topo;
     905           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 ) ) );
     906             :   /* The accounts database is a full-client (Firedancer) feature only.
     907             :      Frankendancer has no accdb, so its topology leaves accdb_obj_id
     908             :      unset (ULONG_MAX) and the gui tile joins no accdb shmem.  The gui
     909             :      only reads partition stats from the shmem; it never reads account
     910             :      data from disk, so it does not join the accdb fd. */
     911           0 :   fd_accdb_shmem_t * accdb_shmem = NULL;
     912           0 :   if( FD_LIKELY( tile->gui.accdb_obj_id!=ULONG_MAX ) ) {
     913           0 :     void * accdb_shmem_raw = fd_topo_obj_laddr( topo, tile->gui.accdb_obj_id );
     914           0 :     FD_TEST( accdb_shmem_raw );
     915           0 :     accdb_shmem = fd_accdb_shmem_join( accdb_shmem_raw );
     916           0 :     FD_TEST( accdb_shmem );
     917           0 :   }
     918           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, ctx->is_full_client, ctx->snapshots_enabled, tile->gui.is_voting, tile->gui.schedule_strategy, tile->gui.wfs_bank_hash, tile->gui.expected_shred_version, tile->gui.accounts_database_path, tile->gui.gui_database_path, ctx->db, ctx->topo, accdb_shmem, fd_clock_tile_now( ctx->clock ) ) );
     919           0 :   FD_TEST( ctx->gui );
     920           0 :   FD_TEST( ctx->db );
     921             : 
     922           0 :   ctx->keyswitch = fd_keyswitch_join( fd_topo_obj_laddr( topo, tile->id_keyswitch_obj_id ) );
     923           0 :   FD_TEST( ctx->keyswitch );
     924             : 
     925           0 :   fd_alloc_t * alloc = fd_alloc_join( fd_alloc_new( _alloc, 1UL ), 1UL );
     926           0 :   FD_TEST( alloc );
     927           0 :   cJSON_alloc_install( alloc );
     928             : 
     929           0 :   ctx->next_poll_nanos = fd_clock_tile_now( ctx->clock );
     930             : 
     931           0 :   ctx->idle_cnt = 0UL;
     932           0 :   FD_TEST( tile->in_cnt<=sizeof(ctx->in)/sizeof(ctx->in[0]) );
     933           0 :   ctx->in_cnt = tile->in_cnt;
     934             : 
     935           0 :   for( ulong i=0UL; i<tile->in_cnt; i++ ) {
     936           0 :     fd_topo_link_t const * link = &topo->links[ tile->in_link_id[ i ] ];
     937           0 :     fd_topo_wksp_t const * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
     938             : 
     939           0 :     if( FD_LIKELY( !strcmp( link->name, "pack_execle"  ) ) ) ctx->in_kind[ i ] = IN_KIND_PACK_EXECLE;
     940           0 :     else if( FD_LIKELY( !strcmp( link->name, "pack_poh"     ) ) ) ctx->in_kind[ i ] = IN_KIND_PACK_POH;
     941           0 :     else if( FD_LIKELY( !strcmp( link->name, "execle_poh"   ) ) ) ctx->in_kind[ i ] = IN_KIND_EXECLE_POH;
     942           0 :     else if( FD_LIKELY( !strcmp( link->name, "shred_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SHRED_OUT;
     943           0 :     else if( FD_LIKELY( !strcmp( link->name, "net_gossvf"   ) ) ) {
     944           0 :       ctx->in_kind[ i ] = IN_KIND_NET_GOSSVF;
     945           0 :       fd_net_rx_bounds_init( &ctx->net_in_bounds[ i ], link->dcache );
     946           0 :     }
     947           0 :     else if( FD_LIKELY( !strcmp( link->name, "gossip_net"    ) ) ) ctx->in_kind[ i ] = IN_KIND_GOSSIP_NET;
     948           0 :     else if( FD_LIKELY( !strcmp( link->name, "gossip_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_GOSSIP_OUT;
     949           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapct_gui"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPCT;
     950           0 :     else if( FD_LIKELY( !strcmp( link->name, "repair_net"    ) ) ) ctx->in_kind[ i ] = IN_KIND_REPAIR_NET;
     951           0 :     else if( FD_LIKELY( !strcmp( link->name, "tower_out"     ) ) ) ctx->in_kind[ i ] = IN_KIND_TOWER_OUT;
     952           0 :     else if( FD_LIKELY( !strcmp( link->name, "replay_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_REPLAY_OUT;
     953           0 :     else if( FD_LIKELY( !strcmp( link->name, "replay_epoch"  ) ) ) ctx->in_kind[ i ] = IN_KIND_EPOCH;
     954           0 :     else if( FD_LIKELY( !strcmp( link->name, "genesi_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_GENESI_OUT;
     955           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapin_gui"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPIN;
     956           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapin_manif"  ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPIN_MANIF;
     957           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapsv_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPSV_OUT;
     958           0 :     else if( FD_LIKELY( !strcmp( link->name, "execrp_replay" ) ) ) ctx->in_kind[ i ] = IN_KIND_EXECRP_REPLAY;
     959           0 :     else if( FD_LIKELY( !strcmp( link->name, "bundle_status"  ) ) ) ctx->in_kind[ i ] = IN_KIND_BUNDLE;
     960           0 :     else if( FD_LIKELY( !strcmp( link->name, "diag_gui"       ) ) ) ctx->in_kind[ i ] = IN_KIND_DIAG;
     961           0 :     else FD_LOG_ERR(( "gui tile has unexpected input link %lu %s", i, link->name ));
     962             : 
     963           0 :     if( FD_LIKELY( !strcmp( link->name, "execle_poh" ) ) ) {
     964           0 :       ulong producer = fd_topo_find_link_producer( topo, &topo->links[ tile->in_link_id[ i ] ] );
     965           0 :       ctx->in_bank_idx[ i ] = topo->tiles[ producer ].kind_id;
     966           0 :     }
     967             : 
     968           0 :     ctx->in_reliable[ i ] = tile->in_link_reliable[ i ];
     969           0 :     ctx->in[ i ].mem    = link_wksp->wksp;
     970           0 :     ctx->in[ i ].mtu    = link->mtu;
     971           0 :     ctx->in[ i ].chunk0 = fd_dcache_compact_chunk0( ctx->in[ i ].mem, link->dcache );
     972           0 :     ctx->in[ i ].wmark  = fd_dcache_compact_wmark ( ctx->in[ i ].mem, link->dcache, link->mtu );
     973           0 :   }
     974             : 
     975           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     976           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     977           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     978           0 : }
     979             : 
     980             : static ulong
     981             : populate_allowed_seccomp( fd_topo_t const *      topo,
     982             :                           fd_topo_tile_t const * tile,
     983             :                           ulong                  out_cnt,
     984           0 :                           struct sock_filter *   out ) {
     985           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     986           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     987           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     988             : 
     989           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 ) );
     990           0 :   return sock_filter_policy_fd_gui_tile_instr_cnt;
     991           0 : }
     992             : 
     993             : static ulong
     994             : populate_allowed_fds( fd_topo_t const *      topo,
     995             :                       fd_topo_tile_t const * tile,
     996             :                       ulong                  out_fds_cnt,
     997           0 :                       int *                  out_fds ) {
     998           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     999           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
    1000           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
    1001             : 
    1002           0 :   if( FD_UNLIKELY( out_fds_cnt<4UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
    1003             : 
    1004           0 :   ulong out_cnt = 0UL;
    1005           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
    1006           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
    1007           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
    1008           0 :   out_fds[ out_cnt++ ] = fd_http_server_fd( ctx->gui_server ); /* gui listen socket */
    1009           0 :   out_fds[ out_cnt++ ] = fd_gui_store_fd( ctx->db ); /* historical store data file */
    1010           0 :   return out_cnt;
    1011           0 : }
    1012             : 
    1013             : static ulong
    1014             : rlimit_file_cnt( fd_topo_t const *      topo FD_PARAM_UNUSED,
    1015           0 :                  fd_topo_tile_t const * tile ) {
    1016             :   /* pipefd, socket, stderr, logfile, guidb, and one spare for new accept() connections */
    1017           0 :   ulong base = 6UL;
    1018           0 :   return base + tile->gui.max_http_connections + tile->gui.max_websocket_connections;
    1019           0 : }
    1020             : 
    1021           0 : #define STEM_BURST (2UL)
    1022             : 
    1023             : /* See explanation in fd_pack */
    1024           0 : #define STEM_LAZY  (128L*3000L)
    1025             : 
    1026           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_gui_ctx_t
    1027           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_gui_ctx_t)
    1028             : 
    1029           0 : #define STEM_CALLBACK_DURING_HOUSEKEEPING during_housekeeping
    1030           0 : #define STEM_CALLBACK_METRICS_WRITE       metrics_write
    1031           0 : #define STEM_CALLBACK_BEFORE_CREDIT       before_credit
    1032           0 : #define STEM_CALLBACK_BEFORE_FRAG         before_frag
    1033           0 : #define STEM_CALLBACK_DURING_FRAG         during_frag
    1034           0 : #define STEM_CALLBACK_RETURNABLE_FRAG     returnable_frag
    1035           0 : #define STEM_CALLBACK_AFTER_FRAG          after_frag
    1036             : 
    1037             : #include "../../disco/stem/fd_stem.c"
    1038             : 
    1039             : fd_topo_run_tile_t fd_tile_gui = {
    1040             :   .name                     = "gui",
    1041             :   .rlimit_file_cnt_fn       = rlimit_file_cnt,
    1042             :   .populate_allowed_seccomp = populate_allowed_seccomp,
    1043             :   .populate_allowed_fds     = populate_allowed_fds,
    1044             :   .scratch_align            = scratch_align,
    1045             :   .scratch_footprint        = scratch_footprint,
    1046             :   .loose_footprint          = loose_footprint,
    1047             :   .privileged_init          = privileged_init,
    1048             :   .unprivileged_init        = unprivileged_init,
    1049             :   .run                      = stem_run,
    1050             : };

Generated by: LCOV version 1.14