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