LCOV - code coverage report
Current view: top level - disco/gui - fd_gui_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 105 772 13.6 %
Date: 2026-09-17 04:28:31 Functions: 2 42 4.8 %

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

Generated by: LCOV version 1.14