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