LCOV - code coverage report
Current view: top level - disco/gui - fd_gui_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 549 0.0 %
Date: 2026-06-19 09:21:35 Functions: 0 19 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 "../../discoh/plugin/fd_plugin.h"
      24             : #include "../../discof/replay/fd_execrp.h"
      25             : #include "../../disco/metrics/fd_metrics.h"
      26             : #include "../../disco/net/fd_net_tile.h"
      27             : #include "../../disco/fd_clock_tile.h"
      28             : #include "../../discof/genesis/fd_genesi_tile.h" // TODO: Layering violation
      29             : #include "../../waltz/http/fd_http_server.h"
      30             : #include "../../waltz/http/fd_http_server_private.h"
      31             : #include "../../ballet/json/cJSON_alloc.h"
      32             : #include "../../discof/repair/fd_repair.h"
      33             : #include "../../discof/replay/fd_replay_tile.h"
      34             : #include "../../disco/shred/fd_shred_tile.h"
      35             : #include "../../flamenco/accdb/fd_accdb_shmem.h"
      36             : 
      37           0 : #define IN_KIND_PACK_EXECLE   ( 2UL)
      38           0 : #define IN_KIND_PACK_POH      ( 3UL)
      39           0 : #define IN_KIND_EXECLE_POH    ( 4UL)
      40           0 : #define IN_KIND_SHRED_OUT     ( 5UL) /* firedancer only */
      41           0 : #define IN_KIND_NET_GOSSVF    ( 6UL) /* firedancer only */
      42           0 : #define IN_KIND_GOSSIP_NET    ( 7UL) /* firedancer only */
      43           0 : #define IN_KIND_GOSSIP_OUT    ( 8UL) /* firedancer only */
      44           0 : #define IN_KIND_SNAPCT        ( 9UL) /* firedancer only */
      45           0 : #define IN_KIND_REPAIR_NET    (10UL) /* firedancer only */
      46           0 : #define IN_KIND_TOWER_OUT     (11UL) /* firedancer only */
      47           0 : #define IN_KIND_REPLAY_OUT    (12UL) /* firedancer only */
      48           0 : #define IN_KIND_EPOCH         (13UL) /* firedancer only */
      49           0 : #define IN_KIND_GENESI_OUT    (14UL) /* firedancer only */
      50           0 : #define IN_KIND_SNAPIN        (15UL) /* firedancer only */
      51           0 : #define IN_KIND_EXECRP_REPLAY (16UL) /* firedancer only */
      52           0 : #define IN_KIND_BUNDLE        (17UL)
      53           0 : #define IN_KIND_SNAPIN_MANIF  (18UL) /* firedancer only */
      54             : 
      55             : FD_IMPORT_BINARY( firedancer_svg, "book/public/fire.svg" );
      56             : 
      57           0 : #define FD_HTTP_SERVER_GUI_MAX_REQUEST_LEN       65536
      58           0 : #define FD_HTTP_SERVER_GUI_MAX_WS_RECV_FRAME_LEN 65536
      59           0 : #define FD_HTTP_SERVER_GUI_MAX_WS_SEND_FRAME_CNT 8192
      60             : 
      61             : static fd_http_server_params_t
      62           0 : derive_http_params( fd_topo_tile_t const * tile ) {
      63           0 :   return (fd_http_server_params_t) {
      64           0 :     .max_connection_cnt    = tile->gui.max_http_connections,
      65           0 :     .max_ws_connection_cnt = tile->gui.max_websocket_connections,
      66           0 :     .max_request_len       = FD_HTTP_SERVER_GUI_MAX_REQUEST_LEN,
      67           0 :     .max_ws_recv_frame_len = FD_HTTP_SERVER_GUI_MAX_WS_RECV_FRAME_LEN,
      68           0 :     .max_ws_send_frame_cnt = FD_HTTP_SERVER_GUI_MAX_WS_SEND_FRAME_CNT,
      69           0 :     .outgoing_buffer_sz    = tile->gui.send_buffer_size_mb * (1UL<<20UL),
      70           0 :     .compress_websocket    = tile->gui.websocket_compression,
      71           0 :   };
      72           0 : }
      73             : 
      74             : struct fd_gui_in_ctx {
      75             :   fd_wksp_t * mem;
      76             :   ulong       mtu;
      77             :   ulong       chunk0;
      78             :   ulong       wmark;
      79             : };
      80             : 
      81             : typedef struct fd_gui_in_ctx fd_gui_in_ctx_t;
      82             : 
      83             : struct fd_gui_out_ctx {
      84             :   ulong       idx;
      85             :   fd_wksp_t * mem;
      86             :   ulong       chunk0;
      87             :   ulong       wmark;
      88             :   ulong       chunk;
      89             : };
      90             : 
      91             : typedef struct fd_gui_out_ctx fd_gui_out_ctx_t;
      92             : 
      93             : typedef struct {
      94             :   fd_topo_t const * topo;
      95             : 
      96             :   int is_full_client;
      97             :   int snapshots_enabled;
      98             : 
      99             :   fd_gui_t * gui;
     100             :   fd_gui_peers_ctx_t * peers;
     101             : 
     102             :   ulong in_cnt;
     103             :   ulong idle_cnt;
     104             : 
     105             :   /* Most of the gui tile uses fd_clock for timing, but some stem
     106             :      timestamps still used tickcounts, so we keep separate timestamps
     107             :      here to handle those cases until fd_clock is more widely adopted. */
     108             :   long ref_wallclock;
     109             :   long ref_tickcount;
     110             :   double tick_per_ns;
     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             :   } parsed;
     124             : 
     125             :   fd_http_server_t * gui_server;
     126             : 
     127             :   long next_poll_deadline;
     128             : 
     129             :   fd_keyswitch_t * keyswitch;
     130             :   uchar const *    identity_key;
     131             : 
     132             :   int               has_vote_key;
     133             :   fd_pubkey_t const vote_key[ 1UL ];
     134             : 
     135             :   ulong           in_kind[ 64UL ];
     136             :   int             in_reliable[ 64UL ];
     137             :   ulong           in_bank_idx[ 64UL ];
     138             :   fd_gui_in_ctx_t in[ 64UL ];
     139             : 
     140             :   fd_net_rx_bounds_t net_in_bounds[ 64UL ];
     141             : } fd_gui_ctx_t;
     142             : 
     143             : FD_FN_CONST static inline ulong
     144           0 : scratch_align( void ) {
     145           0 :   ulong a = alignof( fd_gui_ctx_t );
     146           0 :   a = fd_ulong_max( a, fd_http_server_align() );
     147           0 :   a = fd_ulong_max( a, fd_gui_peers_align() );
     148           0 :   a = fd_ulong_max( a, fd_gui_align() );
     149           0 :   a = fd_ulong_max( a, fd_alloc_align() );
     150           0 :   return a;
     151           0 : }
     152             : 
     153             : static inline ulong
     154           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
     155           0 :   fd_http_server_params_t http_param = derive_http_params( tile );
     156           0 :   ulong http_fp = fd_http_server_footprint( http_param );
     157           0 :   if( FD_UNLIKELY( !http_fp ) ) FD_LOG_ERR(( "Invalid [tiles.gui] config parameters" ));
     158             : 
     159           0 :   ulong l = FD_LAYOUT_INIT;
     160           0 :   l = FD_LAYOUT_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     161           0 :   l = FD_LAYOUT_APPEND( l, fd_http_server_align(),  http_fp );
     162           0 :   l = FD_LAYOUT_APPEND( l, fd_gui_peers_align(),    fd_gui_peers_footprint( http_param.max_ws_connection_cnt ) );
     163           0 :   l = FD_LAYOUT_APPEND( l, fd_gui_align(),          fd_gui_footprint( tile->gui.tile_cnt ) );
     164           0 :   l = FD_LAYOUT_APPEND( l, fd_alloc_align(),        fd_alloc_footprint() );
     165           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
     166           0 : }
     167             : 
     168             : FD_FN_PURE static inline ulong
     169           0 : loose_footprint( fd_topo_tile_t const * tile FD_PARAM_UNUSED ) {
     170           0 :   return 256UL * (1UL<<20UL); /* 256MiB of heap space for the cJSON allocator */
     171           0 : }
     172             : 
     173             : static inline void
     174           0 : during_housekeeping( fd_gui_ctx_t * ctx ) {
     175           0 :   ctx->ref_wallclock = fd_log_wallclock();
     176           0 :   ctx->ref_tickcount = fd_tickcount();
     177             : 
     178           0 :   if( FD_UNLIKELY( fd_clock_tile_recal_due( ctx->clock ) ) ) {
     179           0 :     fd_clock_tile_recal( ctx->clock );
     180           0 :   }
     181             : 
     182           0 :   if( FD_UNLIKELY( fd_keyswitch_state_query( ctx->keyswitch )==FD_KEYSWITCH_STATE_SWITCH_PENDING ) ) {
     183           0 :     fd_gui_set_identity( ctx->gui, ctx->keyswitch->bytes );
     184           0 :     fd_keyswitch_state( ctx->keyswitch, FD_KEYSWITCH_STATE_COMPLETED );
     185           0 :   }
     186           0 : }
     187             : 
     188             : static inline void
     189           0 : metrics_write( fd_gui_ctx_t * ctx ) {
     190           0 :   FD_MGAUGE_SET( GUI, CONN_ACTIVE, ctx->gui_server->metrics.connection_cnt );
     191           0 :   FD_MGAUGE_SET( GUI, WEBSOCKET_CONN_ACTIVE, ctx->gui_server->metrics.ws_connection_cnt );
     192             : 
     193           0 :   FD_MCNT_SET( GUI, WEBSOCKET_FRAME_TX,     ctx->gui_server->metrics.frames_written );
     194           0 :   FD_MCNT_SET( GUI, WEBSOCKET_FRAME_RX, ctx->gui_server->metrics.frames_read );
     195             : 
     196           0 :   FD_MCNT_SET( GUI, BYTES_WRITTEN, ctx->gui_server->metrics.bytes_written );
     197           0 :   FD_MCNT_SET( GUI, BYTES_READ,    ctx->gui_server->metrics.bytes_read );
     198           0 : }
     199             : 
     200             : static void
     201             : before_credit( fd_gui_ctx_t *      ctx,
     202             :                fd_stem_context_t * stem,
     203           0 :                int *               charge_busy ) {
     204           0 :   (void)stem;
     205             : 
     206           0 :   ctx->idle_cnt++;
     207           0 :   if( FD_LIKELY( ctx->idle_cnt<2UL*ctx->in_cnt ) ) return;
     208           0 :   ctx->idle_cnt = 0UL;
     209             : 
     210           0 :   int charge_busy_server = 0;
     211           0 :   long now = fd_tickcount();
     212           0 :   if( FD_UNLIKELY( now>=ctx->next_poll_deadline ) ) {
     213           0 :     charge_busy_server = fd_http_server_poll( ctx->gui_server, 0 );
     214           0 :     ctx->next_poll_deadline = fd_tickcount() + (long)(ctx->tick_per_ns * 128L * 1000L);
     215           0 :   }
     216             : 
     217           0 :   int charge_poll = 0;
     218           0 :   charge_poll |= fd_gui_poll( ctx->gui, fd_clock_tile_now( ctx->clock ) );
     219           0 :   charge_poll |= fd_gui_peers_poll( ctx->peers, fd_clock_tile_now( ctx->clock ) );
     220             : 
     221           0 :   *charge_busy = charge_busy_server | charge_poll;
     222           0 : }
     223             : 
     224             : static int
     225             : before_frag( fd_gui_ctx_t * ctx,
     226             :              ulong          in_idx,
     227             :              ulong          seq,
     228           0 :              ulong          sig ) {
     229           0 :   (void)seq;
     230             : 
     231             :   /* Ignore "done draining banks" and "reduce microblock bound" signals from pack->poh */
     232           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_PACK_POH && (sig==FD_PACK_MSG_DONE_DRAINING || sig==FD_PACK_MSG_REDUCE_MB_BOUND) ) ) return 1;
     233             : 
     234           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_GOSSIP_OUT &&
     235           0 :                  (sig==FD_GOSSIP_UPDATE_TAG_WFS_DONE || sig==FD_GOSSIP_UPDATE_TAG_PEER_SATURATED) ) ) return 1;
     236           0 :   return 0;
     237           0 : }
     238             : 
     239             : static inline void
     240             : during_frag( fd_gui_ctx_t * ctx,
     241             :              ulong          in_idx,
     242             :              ulong          seq FD_PARAM_UNUSED,
     243             :              ulong          sig,
     244             :              ulong          chunk,
     245             :              ulong          sz,
     246           0 :              ulong          ctl ) {
     247             : 
     248           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[ in_idx ].mem, chunk );
     249             : 
     250           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_EPOCH ) ) {
     251           0 :     fd_epoch_info_msg_t * epoch_info = (fd_epoch_info_msg_t *)src;
     252           0 :     FD_TEST( epoch_info->staked_vote_cnt<=MAX_COMPRESSED_STAKE_WEIGHTS );
     253           0 :     FD_TEST( epoch_info->staked_id_cnt<=MAX_SHRED_DESTS );
     254           0 :     sz = fd_epoch_info_msg_sz( epoch_info->staked_vote_cnt, epoch_info->staked_id_cnt );
     255           0 :   }
     256             : 
     257           0 :   if( FD_UNLIKELY( ctx->in_kind[ in_idx ]==IN_KIND_GENESI_OUT ) ) {
     258           0 :     sz = sig;
     259           0 :   }
     260             : 
     261           0 :   if( FD_LIKELY( ctx->in_kind[ in_idx ]==IN_KIND_REPLAY_OUT ) ) {
     262           0 :     if( FD_LIKELY( sig!=REPLAY_SIG_SLOT_COMPLETED && sig!=REPLAY_SIG_BECAME_LEADER  ) ) return;
     263           0 :   }
     264             : 
     265           0 :   if( FD_UNLIKELY( (sz>0UL && (chunk<ctx->in[ in_idx ].chunk0 || chunk>ctx->in[ in_idx ].wmark)) || sz>ctx->in[ in_idx ].mtu ) )
     266           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 ));
     267             : 
     268           0 :   switch( ctx->in_kind[ in_idx ] ) {
     269           0 :     case IN_KIND_REPAIR_NET: {
     270           0 :       ctx->parsed.repair_net.slot = ULONG_MAX;
     271           0 :       uchar * payload;
     272           0 :       ulong payload_sz;
     273           0 :       if( FD_LIKELY( fd_ip4_udp_hdr_strip( src, sz, &payload, &payload_sz, NULL, NULL, NULL ) ) ) {
     274           0 :         fd_repair_msg_t const * msg = (fd_repair_msg_t const *)fd_type_pun_const( payload );
     275           0 :         if( FD_LIKELY( msg->kind==FD_REPAIR_KIND_SHRED ) ) {
     276           0 :           if( FD_UNLIKELY( msg->shred.slot==0 ) ) break;
     277           0 :           ctx->parsed.repair_net.slot = msg->shred.slot;
     278           0 :           ctx->parsed.repair_net.shred_idx = msg->shred.shred_idx;
     279           0 :         }
     280           0 :       }
     281           0 :       break;
     282           0 :     }
     283           0 :     case IN_KIND_NET_GOSSVF: {
     284           0 :       FD_TEST( sz<=sizeof(ctx->parsed.net_gossvf) );
     285           0 :       uchar const * net_src = fd_net_rx_translate_frag( &ctx->net_in_bounds[ in_idx ], chunk, ctl, sz );
     286           0 :       fd_memcpy( ctx->parsed.net_gossvf, net_src, sz );
     287           0 :       break;
     288           0 :     }
     289           0 :     case IN_KIND_GOSSIP_NET: {
     290           0 :       FD_TEST( sz<=sizeof(ctx->parsed.gossip_net) );
     291           0 :       fd_memcpy( ctx->parsed.gossip_net, src, sz );
     292           0 :       break;
     293           0 :     }
     294           0 :   }
     295             : 
     296           0 :   ctx->chunk = chunk;
     297           0 : }
     298             : 
     299             : static inline void
     300             : after_frag( fd_gui_ctx_t *      ctx,
     301             :             ulong               in_idx,
     302             :             ulong               seq,
     303             :             ulong               sig,
     304             :             ulong               sz,
     305             :             ulong               tsorig,
     306             :             ulong               tspub,
     307           0 :             fd_stem_context_t * stem ) {
     308           0 :   (void)seq; (void)stem;
     309             : 
     310           0 :   if( FD_LIKELY( ctx->in_reliable[ in_idx ] ) ) ctx->idle_cnt = 0UL;
     311             : 
     312           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[ in_idx ].mem, ctx->chunk );
     313             : 
     314           0 :   switch( ctx->in_kind[ in_idx ] ) {
     315           0 :     case IN_KIND_EXECRP_REPLAY: {
     316           0 :       if( FD_LIKELY( sig>>32==FD_EXECRP_TT_TXN_EXEC ) ) {
     317           0 :         fd_execrp_task_done_msg_t * msg = (fd_execrp_task_done_msg_t *)src;
     318             : 
     319           0 :         long tickcount = fd_tickcount();
     320           0 :         long tsorig_ns = ctx->ref_wallclock + (long)((double)(fd_frag_meta_ts_decomp( tsorig, tickcount ) - ctx->ref_tickcount) / ctx->tick_per_ns);
     321           0 :         long tspub_ns = ctx->ref_wallclock + (long)((double)(fd_frag_meta_ts_decomp( tspub, tickcount ) - ctx->ref_tickcount) / ctx->tick_per_ns);
     322           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 );
     323             : 
     324           0 :         int txn_succeeded = msg->txn_exec->is_committable && !msg->txn_exec->is_fees_only && !msg->txn_exec->txn_err;
     325           0 :         if( FD_UNLIKELY( msg->txn_exec->vote.slot!=ULONG_MAX && txn_succeeded ) ) {
     326           0 :           fd_gui_peers_handle_vote( ctx->peers,
     327           0 :                                     msg->txn_exec->vote.vote_acct,
     328           0 :                                     msg->txn_exec->vote.slot,
     329           0 :                                     !memcmp(ctx->gui->summary.identity_key->uc, msg->txn_exec->vote.identity->uc, sizeof(fd_pubkey_t) ) );
     330           0 :         }
     331           0 :       }
     332             : 
     333           0 :       break;
     334           0 :     }
     335           0 :     case IN_KIND_REPLAY_OUT: {
     336           0 :       if( FD_UNLIKELY( sig==REPLAY_SIG_SLOT_COMPLETED ) ) {
     337           0 :         fd_replay_slot_completed_t const * slot_completed =  (fd_replay_slot_completed_t const *)src;
     338             : 
     339           0 :         fd_gui_peers_update_delinquency( ctx->peers, fd_clock_tile_now( ctx->clock ) );
     340             : 
     341           0 :         fd_gui_handle_replay_update( ctx->gui, slot_completed, ctx->peers->slot_voted, fd_clock_tile_now( ctx->clock ) );
     342           0 :       } else if( FD_UNLIKELY( sig==REPLAY_SIG_BECAME_LEADER ) ) {
     343           0 :         fd_became_leader_t * became_leader = (fd_became_leader_t *)src;
     344           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 );
     345           0 :       } else {
     346           0 :         return;
     347           0 :       }
     348           0 :       break;
     349           0 :     }
     350           0 :     case IN_KIND_EPOCH: {
     351           0 :       fd_epoch_info_msg_t * epoch_info = (fd_epoch_info_msg_t *)src;
     352           0 :       fd_gui_handle_epoch_info( ctx->gui, epoch_info, fd_clock_tile_now( ctx->clock ) );
     353           0 :       fd_gui_peers_handle_epoch_info( ctx->peers, epoch_info, fd_clock_tile_now( ctx->clock ) );
     354           0 :       break;
     355           0 :     }
     356           0 :     case IN_KIND_SNAPIN: {
     357           0 :       fd_gui_peers_handle_config_account( ctx->peers, src, sz );
     358           0 :       break;
     359           0 :     }
     360           0 :     case IN_KIND_SNAPIN_MANIF: {
     361           0 :       if( fd_ssmsg_sig_message( sig )==FD_SSMSG_DONE ) {
     362           0 :         fd_gui_peers_commit_snapshot_manifest( ctx->peers );
     363           0 :       } else {
     364           0 :         fd_gui_stage_snapshot_manifest( ctx->gui, (fd_snapshot_manifest_t const *)src );
     365           0 :         fd_gui_peers_stage_snapshot_manifest( ctx->peers, (fd_snapshot_manifest_t const *)src, fd_clock_tile_now( ctx->clock ) );
     366           0 :       }
     367           0 :       break;
     368           0 :     }
     369           0 :     case IN_KIND_GENESI_OUT: {
     370           0 :       fd_genesis_meta_t const * meta = (fd_genesis_meta_t const *)src;
     371           0 :       fd_gui_handle_genesis_hash( ctx->gui, &meta->genesis_hash );
     372           0 :       break;
     373           0 :     }
     374           0 :     case IN_KIND_TOWER_OUT: {
     375           0 :       if( FD_LIKELY( sig==FD_TOWER_SIG_SLOT_DONE )) {
     376           0 :         fd_tower_slot_done_t const * tower = (fd_tower_slot_done_t const *)src;
     377           0 :         fd_gui_handle_tower_update( ctx->gui, tower, fd_clock_tile_now( ctx->clock ) );
     378           0 :       }
     379           0 :       if( FD_UNLIKELY( sig==FD_TOWER_SIG_SLOT_CONFIRMED ) ) {
     380           0 :         fd_gui_handle_votes_update( ctx->gui, (fd_tower_slot_confirmed_t const *)src );
     381           0 :       }
     382           0 :       break;
     383           0 :     }
     384           0 :     case IN_KIND_SHRED_OUT: {
     385           0 :       long tsorig_nanos = ctx->ref_wallclock + (long)((double)(fd_frag_meta_ts_decomp( tsorig, fd_tickcount() ) - ctx->ref_tickcount) / ctx->tick_per_ns);
     386           0 :       uint sig_src      = fd_shred_sig_src( sig );
     387           0 :       if( FD_LIKELY( sig_src==SHRED_SIG_SRC_TURBINE || sig_src==SHRED_SIG_SRC_REPAIR || sig_src==SHRED_SIG_SRC_BAD_REPAIR ) ) {
     388           0 :         fd_shred_base_t const * msg = (fd_shred_base_t const *)fd_type_pun_const( src );
     389           0 :         ulong slot      = msg->shred.slot;
     390           0 :         ulong shred_idx = msg->shred.idx;
     391           0 :         int is_turbine  = sig_src==SHRED_SIG_SRC_TURBINE;
     392             :         /* tsorig is the timestamp when the shred was received by the shred tile */
     393           0 :         fd_gui_handle_shred( ctx->gui, slot, shred_idx, is_turbine, tsorig_nanos );
     394           0 :       }
     395           0 :       if( FD_UNLIKELY( sig==SHRED_SIG_FEC_COMPLETE_LEADER ) ) {
     396           0 :         fd_fec_complete_t const * complete_msg = (fd_fec_complete_t const *)fd_type_pun_const( src );
     397           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 );
     398           0 :       }
     399           0 :       break;
     400           0 :     }
     401           0 :     case IN_KIND_SNAPCT: {
     402           0 :       fd_gui_handle_snapshot_update( ctx->gui, (fd_snapct_update_t *)src );
     403           0 :       break;
     404           0 :     }
     405           0 :     case IN_KIND_REPAIR_NET: {
     406           0 :       if( FD_UNLIKELY( ctx->parsed.repair_net.slot==ULONG_MAX ) ) break;
     407           0 :       long tsorig_ns = ctx->ref_wallclock + (long)((double)(fd_frag_meta_ts_decomp( tsorig, fd_tickcount() ) - ctx->ref_tickcount) / ctx->tick_per_ns);
     408           0 :       fd_gui_handle_repair_request( ctx->gui, ctx->parsed.repair_net.slot, ctx->parsed.repair_net.shred_idx, tsorig_ns );
     409           0 :       break;
     410           0 :     }
     411           0 :     case IN_KIND_NET_GOSSVF: {
     412           0 :       uchar * payload;
     413           0 :       ulong payload_sz;
     414           0 :       fd_ip4_hdr_t * ip4_hdr;
     415           0 :       fd_udp_hdr_t * udp_hdr;
     416           0 :       if( FD_LIKELY( fd_ip4_udp_hdr_strip( ctx->parsed.net_gossvf, sz, &payload, &payload_sz, NULL, &ip4_hdr, &udp_hdr ) ) ) {
     417           0 :         fd_gossip_socket_t socket = {
     418           0 :           .is_ipv6 = 0,
     419           0 :           .ip4 = ip4_hdr->saddr,
     420           0 :           .port = udp_hdr->net_sport,
     421           0 :         };
     422           0 :         fd_gui_peers_handle_gossip_message( ctx->peers, payload, payload_sz, &socket, 1 );
     423           0 :       }
     424           0 :       break;
     425           0 :     }
     426           0 :     case IN_KIND_GOSSIP_NET: {
     427           0 :       uchar * payload;
     428           0 :       ulong payload_sz;
     429           0 :       fd_ip4_hdr_t * ip4_hdr;
     430           0 :       fd_udp_hdr_t * udp_hdr;
     431           0 :       FD_TEST( fd_ip4_udp_hdr_strip( ctx->parsed.gossip_net, sz, &payload, &payload_sz, NULL, &ip4_hdr, &udp_hdr ) );
     432           0 :       fd_gossip_socket_t socket = {
     433           0 :         .is_ipv6 = 0,
     434           0 :         .ip4 = ip4_hdr->daddr,
     435           0 :         .port = udp_hdr->net_dport,
     436           0 :       };
     437           0 :       fd_gui_peers_handle_gossip_message( ctx->peers, payload, payload_sz, &socket, 0 );
     438           0 :       break;
     439           0 :     }
     440           0 :     case IN_KIND_GOSSIP_OUT: {
     441           0 :       fd_gui_peers_handle_gossip_update( ctx->peers, (fd_gossip_update_message_t *)src, fd_clock_tile_now( ctx->clock ) );
     442           0 :       break;
     443           0 :     }
     444           0 :     case IN_KIND_PACK_POH: {
     445           0 :       fd_gui_unbecame_leader( ctx->gui, fd_disco_execle_sig_slot( sig ), (fd_done_packing_t const *)src, fd_clock_tile_now( ctx->clock ) );
     446           0 :       break;
     447           0 :     }
     448           0 :     case IN_KIND_PACK_EXECLE: {
     449           0 :       FD_TEST( sz>=sizeof(fd_microblock_execle_trailer_t) );
     450           0 :       FD_TEST( (sz-sizeof(fd_microblock_execle_trailer_t))%sizeof(fd_txn_e_t)==0UL );
     451             : 
     452           0 :       if( FD_LIKELY( fd_disco_poh_sig_pkt_type( sig )==POH_PKT_TYPE_MICROBLOCK ) ) {
     453           0 :         fd_microblock_execle_trailer_t trailer[1];
     454           0 :         fd_memcpy( trailer, src+sz-sizeof(fd_microblock_execle_trailer_t), sizeof(fd_microblock_execle_trailer_t) );
     455           0 :         long tspub_ns = ctx->ref_wallclock + (long)((double)(fd_frag_meta_ts_decomp( tspub, fd_tickcount() ) - ctx->ref_tickcount) / ctx->tick_per_ns);
     456           0 :         fd_gui_microblock_execution_begin( ctx->gui,
     457           0 :                                           tspub_ns,
     458           0 :                                           fd_disco_poh_sig_slot( sig ),
     459           0 :                                           (fd_txn_e_t *)src,
     460           0 :                                           (sz-sizeof( fd_microblock_execle_trailer_t ))/sizeof( fd_txn_e_t ),
     461           0 :                                           (uint)trailer->microblock_idx,
     462           0 :                                           trailer->pack_txn_idx );
     463           0 :       } else {
     464           0 :         FD_LOG_ERR(( "unexpected poh packet type %lu", fd_disco_poh_sig_pkt_type( sig ) ));
     465           0 :       }
     466           0 :       break;
     467           0 :     }
     468           0 :     case IN_KIND_EXECLE_POH: {
     469           0 :       FD_TEST( sz>=sizeof(fd_microblock_trailer_t) );
     470           0 :       FD_TEST( (sz-sizeof(fd_microblock_trailer_t))%sizeof(fd_txn_p_t)==0UL );
     471             : 
     472           0 :       fd_microblock_trailer_t trailer[1];
     473           0 :       fd_memcpy( trailer, src+sz-sizeof(fd_microblock_trailer_t), sizeof(fd_microblock_trailer_t) );
     474           0 :       long tspub_ns = ctx->ref_wallclock + (long)((double)(fd_frag_meta_ts_decomp( tspub, fd_tickcount() ) - ctx->ref_tickcount) / ctx->tick_per_ns);
     475           0 :       ulong txn_cnt = (sz-sizeof( fd_microblock_trailer_t ))/sizeof(fd_txn_p_t);
     476           0 :       fd_gui_microblock_execution_end( ctx->gui,
     477           0 :                                       tspub_ns,
     478           0 :                                       ctx->in_bank_idx[ in_idx ],
     479           0 :                                       fd_disco_execle_sig_slot( sig ),
     480           0 :                                       txn_cnt,
     481           0 :                                       (fd_txn_p_t *)src,
     482           0 :                                       trailer->pack_txn_idx,
     483           0 :                                       trailer->txn_ns_dt,
     484           0 :                                       trailer->tips );
     485           0 :       break;
     486           0 :     }
     487           0 :     case IN_KIND_BUNDLE: {
     488           0 :       fd_gui_handle_block_engine_update( ctx->gui, (fd_bundle_block_engine_update_t *)src );
     489           0 :       break;
     490           0 :     }
     491           0 :     default: FD_LOG_ERR(( "unexpected in_kind %lu", ctx->in_kind[ in_idx ] ));
     492           0 :   }
     493           0 : }
     494             : 
     495             : static fd_http_server_response_t
     496           0 : gui_http_request( fd_http_server_request_t const * request ) {
     497           0 :   if( FD_UNLIKELY( request->method!=FD_HTTP_SERVER_METHOD_GET ) ) {
     498           0 :     return (fd_http_server_response_t){
     499           0 :       .status = 405,
     500           0 :     };
     501           0 :   }
     502             : 
     503           0 :   if( FD_LIKELY( !strcmp( request->path, "/websocket" ) ) ) {
     504           0 :     return (fd_http_server_response_t){
     505           0 :       .status            = 200,
     506           0 :       .upgrade_websocket = 1,
     507           0 : #ifdef FD_HAS_ZSTD
     508           0 :       .compress_websocket = request->headers.compress_websocket,
     509             : #else
     510             :       .compress_websocket = 0,
     511             : #endif
     512           0 :     };
     513           0 :   } else if( FD_LIKELY( !strcmp( request->path, "/favicon.svg" ) ) ) {
     514           0 :     return (fd_http_server_response_t){
     515           0 :       .status            = 200,
     516           0 :       .static_body       = firedancer_svg,
     517           0 :       .static_body_len   = firedancer_svg_sz,
     518           0 :       .content_type      = "image/svg+xml",
     519           0 :       .upgrade_websocket = 0,
     520           0 :     };
     521           0 :   }
     522             : 
     523           0 :   int is_vite_page = !strcmp( request->path, "/" ) ||
     524           0 :                      !strcmp( request->path, "/slotDetails" ) ||
     525           0 :                      !strcmp( request->path, "/leaderSchedule" ) ||
     526           0 :                      !strcmp( request->path, "/gossip") ||
     527           0 :                      !strcmp( request->path, "/accounts") ||
     528           0 :                      !strncmp( request->path, "/?", strlen("/?") ) ||
     529           0 :                      !strncmp( request->path, "/slotDetails?", strlen("/slotDetails?") ) ||
     530           0 :                      !strncmp( request->path, "/leaderSchedule?", strlen("/leaderSchedule?") ) ||
     531           0 :                      !strncmp( request->path, "/gossip?", strlen("/gossip?") ) ||
     532           0 :                      !strncmp( request->path, "/accounts?", strlen("/accounts?") );
     533             : 
     534           0 :   for( fd_http_static_file_t const * f = STATIC_FILES; f->name; f++ ) {
     535           0 :     if( !strcmp( request->path, f->name ) ||
     536           0 :         (!strcmp( f->name, "/index.html" ) && is_vite_page) ) {
     537           0 :       char const * content_type = NULL;
     538             : 
     539           0 :       char const * ext = strrchr( f->name, '.' );
     540           0 :       if( FD_LIKELY( ext ) ) {
     541           0 :         if( !strcmp( ext, ".html" ) ) content_type = "text/html; charset=utf-8";
     542           0 :         else if( !strcmp( ext, ".css" ) ) content_type = "text/css";
     543           0 :         else if( !strcmp( ext, ".js" ) ) content_type = "application/javascript";
     544           0 :         else if( !strcmp( ext, ".svg" ) ) content_type = "image/svg+xml";
     545           0 :         else if( !strcmp( ext, ".woff" ) ) content_type = "font/woff";
     546           0 :         else if( !strcmp( ext, ".woff2" ) ) content_type = "font/woff2";
     547           0 :       }
     548             : 
     549           0 :       char const * cache_control = NULL;
     550           0 :       if( FD_LIKELY( !strncmp( request->path, "/assets", 7 ) ) ) cache_control = "public, max-age=31536000, immutable";
     551           0 :       else if( FD_LIKELY( !strcmp( f->name, "/index.html" ) ) )  cache_control = "no-cache";
     552             : 
     553           0 :       const uchar * data = f->data;
     554           0 :       ulong data_len = *(f->data_len);
     555             : 
     556           0 :       int accepts_zstd = 0;
     557           0 :       if( FD_LIKELY( request->headers.accept_encoding ) ) {
     558           0 :         accepts_zstd = !!strstr( request->headers.accept_encoding, "zstd" );
     559           0 :       }
     560             : 
     561           0 :       int accepts_gzip = 0;
     562           0 :       if( FD_LIKELY( request->headers.accept_encoding ) ) {
     563           0 :         accepts_gzip = !!strstr( request->headers.accept_encoding, "gzip" );
     564           0 :       }
     565             : 
     566           0 :       char const * content_encoding = NULL;
     567           0 :       if( FD_LIKELY( accepts_zstd && f->zstd_data ) ) {
     568           0 :         content_encoding = "zstd";
     569           0 :         data = f->zstd_data;
     570           0 :         data_len = *(f->zstd_data_len);
     571           0 :       } else if( FD_LIKELY( accepts_gzip && f->gzip_data ) ) {
     572           0 :         content_encoding = "gzip";
     573           0 :         data = f->gzip_data;
     574           0 :         data_len = *(f->gzip_data_len);
     575           0 :       }
     576             : 
     577           0 :       return (fd_http_server_response_t){
     578           0 :         .status            = 200,
     579           0 :         .static_body       = data,
     580           0 :         .static_body_len   = data_len,
     581           0 :         .content_type      = content_type,
     582           0 :         .cache_control     = cache_control,
     583           0 :         .content_encoding  = content_encoding,
     584           0 :         .upgrade_websocket = 0,
     585           0 :       };
     586           0 :     }
     587           0 :   }
     588             : 
     589           0 :   return (fd_http_server_response_t){
     590           0 :     .status            = 404,
     591           0 :   };
     592           0 : }
     593             : 
     594             : static void
     595             : gui_ws_open( ulong  conn_id,
     596           0 :              void * _ctx ) {
     597           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     598             : 
     599           0 :   fd_gui_ws_open( ctx->gui, conn_id, fd_clock_tile_now( ctx->clock ) );
     600           0 :   fd_gui_peers_ws_open( ctx->peers, conn_id, fd_clock_tile_now( ctx->clock ) );
     601           0 : }
     602             : 
     603             : static void
     604             : gui_ws_close( ulong  conn_id,
     605             :               int    reason,
     606           0 :               void * _ctx ) {
     607           0 :   (void) reason;
     608           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     609           0 :   fd_gui_peers_ws_close( ctx->peers, conn_id );
     610           0 : }
     611             : 
     612             : static void
     613             : gui_ws_message( ulong         ws_conn_id,
     614             :                 uchar const * data,
     615             :                 ulong         data_len,
     616           0 :                 void *        _ctx ) {
     617           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     618             : 
     619           0 :   int reason = fd_gui_ws_message( ctx->gui, ws_conn_id, data, data_len );
     620           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 );
     621             : 
     622           0 :   if( FD_UNLIKELY( reason<0 ) ) fd_http_server_ws_close( ctx->gui_server, ws_conn_id, reason );
     623           0 : }
     624             : 
     625             : static void
     626             : privileged_init( fd_topo_t const *      topo,
     627           0 :                  fd_topo_tile_t const * tile ) {
     628           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     629             : 
     630           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     631           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     632             : 
     633           0 :   fd_http_server_params_t http_param = derive_http_params( tile );
     634           0 :   fd_http_server_t * _gui = FD_SCRATCH_ALLOC_APPEND( l, fd_http_server_align(), fd_http_server_footprint( http_param ) );
     635             : 
     636           0 :   fd_http_server_callbacks_t gui_callbacks = {
     637           0 :     .request    = gui_http_request,
     638           0 :     .ws_open    = gui_ws_open,
     639           0 :     .ws_close   = gui_ws_close,
     640           0 :     .ws_message = gui_ws_message,
     641           0 :   };
     642           0 :   ctx->gui_server = fd_http_server_join( fd_http_server_new( _gui, http_param, gui_callbacks, ctx ) );
     643           0 :   fd_http_server_listen( ctx->gui_server, tile->gui.listen_addr, tile->gui.listen_port );
     644             : 
     645           0 :   FD_LOG_NOTICE(( "gui server listening at http://" FD_IP4_ADDR_FMT ":%u", FD_IP4_ADDR_FMT_ARGS( tile->gui.listen_addr ), tile->gui.listen_port ));
     646             : 
     647           0 :   if( FD_UNLIKELY( !strcmp( tile->gui.identity_key_path, "" ) ) )
     648           0 :     FD_LOG_ERR(( "identity_key_path not set" ));
     649             : 
     650           0 :   ctx->identity_key = fd_keyload_load( tile->gui.identity_key_path, /* pubkey only: */ 1 );
     651             : 
     652           0 :   if( FD_UNLIKELY( !strcmp( tile->gui.vote_key_path, "" ) ) ) {
     653           0 :     ctx->has_vote_key = 0;
     654           0 :   } else {
     655           0 :     ctx->has_vote_key = 1;
     656           0 :     if( FD_UNLIKELY( !fd_base58_decode_32( tile->gui.vote_key_path, (uchar *)ctx->vote_key->uc ) ) ) {
     657           0 :       const uchar * vote_key = fd_keyload_load( tile->gui.vote_key_path, /* pubkey only: */ 1 );
     658           0 :       fd_memcpy( (uchar *)ctx->vote_key->uc, vote_key, 32UL );
     659           0 :     }
     660           0 :   }
     661           0 : }
     662             : 
     663             : static void
     664             : unprivileged_init( fd_topo_t const *      topo,
     665           0 :                    fd_topo_tile_t const * tile ) {
     666           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     667             : 
     668           0 :   fd_http_server_params_t http_param = derive_http_params( tile );
     669           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     670           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t )                                    );
     671           0 :                        FD_SCRATCH_ALLOC_APPEND( l, fd_http_server_align(),  fd_http_server_footprint( http_param )                    );
     672           0 :   void * _peers      = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_peers_align(),    fd_gui_peers_footprint( http_param.max_ws_connection_cnt) );
     673           0 :   void * _gui        = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(),          fd_gui_footprint( tile->gui.tile_cnt )                    );
     674           0 :   void * _alloc      = FD_SCRATCH_ALLOC_APPEND( l, fd_alloc_align(),        fd_alloc_footprint()                                      );
     675             : 
     676           0 :   ctx->is_full_client = ULONG_MAX!=fd_topo_find_tile( topo, "repair", 0UL );
     677           0 :   ctx->snapshots_enabled = ULONG_MAX!=fd_topo_find_tile( topo, "snapct", 0UL );
     678             : 
     679           0 :   fd_clock_tile_init( ctx->clock );
     680             : 
     681           0 :   ctx->ref_wallclock = fd_log_wallclock();
     682           0 :   ctx->ref_tickcount = fd_tickcount();
     683           0 :   ctx->tick_per_ns = fd_tempo_tick_per_ns( NULL );
     684             : 
     685           0 :   ctx->topo = topo;
     686           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, fd_clock_tile_now( ctx->clock ) ) );
     687             :   /* The accounts database is a full-client (Firedancer) feature only.
     688             :      Frankendancer has no accdb, so its topology leaves accdb_obj_id
     689             :      unset (ULONG_MAX) and the gui tile joins no accdb shmem.  The gui
     690             :      only reads partition stats from the shmem; it never reads account
     691             :      data from disk, so it does not join the accdb fd. */
     692           0 :   fd_accdb_shmem_t * accdb_shmem = NULL;
     693           0 :   if( FD_LIKELY( tile->gui.accdb_obj_id!=ULONG_MAX ) ) {
     694           0 :     void * accdb_shmem_raw = fd_topo_obj_laddr( topo, tile->gui.accdb_obj_id );
     695           0 :     FD_TEST( accdb_shmem_raw );
     696           0 :     accdb_shmem = fd_accdb_shmem_join( accdb_shmem_raw );
     697           0 :     FD_TEST( accdb_shmem );
     698           0 :   }
     699           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, ctx->topo, accdb_shmem, fd_clock_tile_now( ctx->clock ) ) );
     700           0 :   FD_TEST( ctx->gui );
     701             : 
     702           0 :   ctx->keyswitch = fd_keyswitch_join( fd_topo_obj_laddr( topo, tile->id_keyswitch_obj_id ) );
     703           0 :   FD_TEST( ctx->keyswitch );
     704             : 
     705           0 :   fd_alloc_t * alloc = fd_alloc_join( fd_alloc_new( _alloc, 1UL ), 1UL );
     706           0 :   FD_TEST( alloc );
     707           0 :   cJSON_alloc_install( alloc );
     708             : 
     709           0 :   ctx->next_poll_deadline = fd_tickcount();
     710             : 
     711           0 :   ctx->idle_cnt = 0UL;
     712           0 :   ctx->in_cnt = tile->in_cnt;
     713             : 
     714           0 :   for( ulong i=0UL; i<tile->in_cnt; i++ ) {
     715           0 :     fd_topo_link_t const * link = &topo->links[ tile->in_link_id[ i ] ];
     716           0 :     fd_topo_wksp_t const * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
     717             : 
     718           0 :     if( FD_LIKELY( !strcmp( link->name, "pack_execle"  ) ) ) ctx->in_kind[ i ] = IN_KIND_PACK_EXECLE;
     719           0 :     else if( FD_LIKELY( !strcmp( link->name, "pack_poh"     ) ) ) ctx->in_kind[ i ] = IN_KIND_PACK_POH;
     720           0 :     else if( FD_LIKELY( !strcmp( link->name, "execle_poh"   ) ) ) ctx->in_kind[ i ] = IN_KIND_EXECLE_POH;
     721           0 :     else if( FD_LIKELY( !strcmp( link->name, "shred_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SHRED_OUT;
     722           0 :     else if( FD_LIKELY( !strcmp( link->name, "net_gossvf"   ) ) ) {
     723           0 :       ctx->in_kind[ i ] = IN_KIND_NET_GOSSVF;
     724           0 :       fd_net_rx_bounds_init( &ctx->net_in_bounds[ i ], link->dcache );
     725           0 :     }
     726           0 :     else if( FD_LIKELY( !strcmp( link->name, "gossip_net"    ) ) ) ctx->in_kind[ i ] = IN_KIND_GOSSIP_NET;
     727           0 :     else if( FD_LIKELY( !strcmp( link->name, "gossip_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_GOSSIP_OUT;
     728           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapct_gui"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPCT;
     729           0 :     else if( FD_LIKELY( !strcmp( link->name, "repair_net"    ) ) ) ctx->in_kind[ i ] = IN_KIND_REPAIR_NET;
     730           0 :     else if( FD_LIKELY( !strcmp( link->name, "tower_out"     ) ) ) ctx->in_kind[ i ] = IN_KIND_TOWER_OUT;
     731           0 :     else if( FD_LIKELY( !strcmp( link->name, "replay_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_REPLAY_OUT;
     732           0 :     else if( FD_LIKELY( !strcmp( link->name, "replay_epoch"  ) ) ) ctx->in_kind[ i ] = IN_KIND_EPOCH;
     733           0 :     else if( FD_LIKELY( !strcmp( link->name, "genesi_out"    ) ) ) ctx->in_kind[ i ] = IN_KIND_GENESI_OUT;
     734           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapin_gui"    ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPIN;
     735           0 :     else if( FD_LIKELY( !strcmp( link->name, "snapin_manif"  ) ) ) ctx->in_kind[ i ] = IN_KIND_SNAPIN_MANIF;
     736           0 :     else if( FD_LIKELY( !strcmp( link->name, "execrp_replay" ) ) ) ctx->in_kind[ i ] = IN_KIND_EXECRP_REPLAY;
     737           0 :     else if( FD_LIKELY( !strcmp( link->name, "bundle_status"  ) ) ) ctx->in_kind[ i ] = IN_KIND_BUNDLE;
     738           0 :     else FD_LOG_ERR(( "gui tile has unexpected input link %lu %s", i, link->name ));
     739             : 
     740           0 :     if( FD_LIKELY( !strcmp( link->name, "execle_poh" ) ) ) {
     741           0 :       ulong producer = fd_topo_find_link_producer( topo, &topo->links[ tile->in_link_id[ i ] ] );
     742           0 :       ctx->in_bank_idx[ i ] = topo->tiles[ producer ].kind_id;
     743           0 :     }
     744             : 
     745           0 :     ctx->in_reliable[ i ] = tile->in_link_reliable[ i ];
     746           0 :     ctx->in[ i ].mem    = link_wksp->wksp;
     747           0 :     ctx->in[ i ].mtu    = link->mtu;
     748           0 :     ctx->in[ i ].chunk0 = fd_dcache_compact_chunk0( ctx->in[ i ].mem, link->dcache );
     749           0 :     ctx->in[ i ].wmark  = fd_dcache_compact_wmark ( ctx->in[ i ].mem, link->dcache, link->mtu );
     750           0 :   }
     751             : 
     752           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     753           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     754           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     755           0 : }
     756             : 
     757             : static ulong
     758             : populate_allowed_seccomp( fd_topo_t const *      topo,
     759             :                           fd_topo_tile_t const * tile,
     760             :                           ulong                  out_cnt,
     761           0 :                           struct sock_filter *   out ) {
     762           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     763           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     764           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     765             : 
     766           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 ) );
     767           0 :   return sock_filter_policy_fd_gui_tile_instr_cnt;
     768           0 : }
     769             : 
     770             : static ulong
     771             : populate_allowed_fds( fd_topo_t const *      topo,
     772             :                       fd_topo_tile_t const * tile,
     773             :                       ulong                  out_fds_cnt,
     774           0 :                       int *                  out_fds ) {
     775           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     776           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     777           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     778             : 
     779           0 :   if( FD_UNLIKELY( out_fds_cnt<3UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
     780             : 
     781           0 :   ulong out_cnt = 0UL;
     782           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
     783           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
     784           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     785           0 :   out_fds[ out_cnt++ ] = fd_http_server_fd( ctx->gui_server ); /* gui listen socket */
     786           0 :   return out_cnt;
     787           0 : }
     788             : 
     789             : static ulong
     790             : rlimit_file_cnt( fd_topo_t const *      topo FD_PARAM_UNUSED,
     791           0 :                  fd_topo_tile_t const * tile ) {
     792             :   /* pipefd, socket, stderr, logfile, and one spare for new accept() connections */
     793           0 :   ulong base = 5UL;
     794           0 :   return base + tile->gui.max_http_connections + tile->gui.max_websocket_connections;
     795           0 : }
     796             : 
     797           0 : #define STEM_BURST (2UL)
     798             : 
     799             : /* See explanation in fd_pack */
     800           0 : #define STEM_LAZY  (128L*3000L)
     801             : 
     802           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_gui_ctx_t
     803           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_gui_ctx_t)
     804             : 
     805           0 : #define STEM_CALLBACK_DURING_HOUSEKEEPING during_housekeeping
     806           0 : #define STEM_CALLBACK_METRICS_WRITE       metrics_write
     807           0 : #define STEM_CALLBACK_BEFORE_CREDIT       before_credit
     808           0 : #define STEM_CALLBACK_BEFORE_FRAG         before_frag
     809           0 : #define STEM_CALLBACK_DURING_FRAG         during_frag
     810           0 : #define STEM_CALLBACK_AFTER_FRAG          after_frag
     811             : 
     812             : #include "../../disco/stem/fd_stem.c"
     813             : 
     814             : fd_topo_run_tile_t fd_tile_gui = {
     815             :   .name                     = "gui",
     816             :   .rlimit_file_cnt_fn       = rlimit_file_cnt,
     817             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     818             :   .populate_allowed_fds     = populate_allowed_fds,
     819             :   .scratch_align            = scratch_align,
     820             :   .scratch_footprint        = scratch_footprint,
     821             :   .loose_footprint          = loose_footprint,
     822             :   .privileged_init          = privileged_init,
     823             :   .unprivileged_init        = unprivileged_init,
     824             :   .run                      = stem_run,
     825             : };

Generated by: LCOV version 1.14