Line data Source code
1 : #include "fd_gui.h"
2 : #include "fd_gui_peers.h"
3 : #include "fd_gui_printf.h"
4 : #include "fd_gui_metrics.h"
5 :
6 : #include "../metrics/fd_metrics.h"
7 : #include "../plugin/fd_plugin.h"
8 :
9 : #include "../../ballet/base58/fd_base58.h"
10 : #include "../../ballet/json/cJSON.h"
11 : #include "../../disco/genesis/fd_genesis_cluster.h"
12 : #include "../../disco/pack/fd_pack.h"
13 : #include "../../disco/pack/fd_pack_cost.h"
14 :
15 : FD_IMPORT_BINARY( ipinfo, "src/disco/gui/ipinfo.bin" );
16 : #define IPINFO_MAX_NODES (1UL<<22UL) /* 4M nodes */
17 :
18 : #include <stdio.h>
19 :
20 : FD_FN_CONST ulong
21 0 : fd_gui_align( void ) {
22 0 : return 128UL;
23 0 : }
24 :
25 : FD_FN_CONST ulong
26 0 : fd_gui_footprint( void ) {
27 0 : ulong l = FD_LAYOUT_INIT;
28 0 : l = FD_LAYOUT_APPEND( l, fd_gui_align(), sizeof( fd_gui_t ) );
29 0 : l = FD_LAYOUT_APPEND( l, alignof(fd_gui_ipinfo_node_t), sizeof(fd_gui_ipinfo_node_t)*IPINFO_MAX_NODES );
30 0 : return FD_LAYOUT_FINI( l, fd_gui_align() );
31 0 : }
32 :
33 : static void
34 : build_ipinfo_trie( fd_gui_t * gui,
35 0 : fd_gui_ipinfo_node_t * nodes ) {
36 0 : gui->ipinfo.nodes = nodes;
37 0 : ulong country_code_cnt = FD_LOAD( ulong, ipinfo );
38 0 : FD_TEST( country_code_cnt && country_code_cnt<256UL ); /* 256 reserved for unknown */
39 0 : FD_TEST( ipinfo_sz>=8UL+country_code_cnt*2UL );
40 :
41 0 : for( ulong i=0UL; i<country_code_cnt; i++ ) {
42 0 : fd_memcpy( gui->ipinfo.country_code[ i ], ipinfo+8UL+i*2UL, 2UL );
43 0 : gui->ipinfo.country_code[ i ][ 2 ] = '\0';
44 0 : }
45 :
46 0 : ulong processed = 8UL+country_code_cnt*2UL;
47 0 : FD_TEST( !((ipinfo_sz-processed)%6UL) );
48 0 : FD_TEST( (ipinfo_sz-processed)/6UL<=IPINFO_MAX_NODES-1UL );
49 :
50 0 : fd_gui_ipinfo_node_t * root = &nodes[ 0 ];
51 0 : root->left = NULL;
52 0 : root->right = NULL;
53 0 : root->has_prefix = 0;
54 :
55 0 : ulong node_cnt = 1UL;
56 0 : while( processed<ipinfo_sz ) {
57 0 : uint ip_addr = fd_uint_bswap( FD_LOAD( uint, ipinfo+processed ) );
58 0 : uchar prefix_len = *( ipinfo+processed+4UL );
59 0 : FD_TEST( prefix_len<=32UL );
60 0 : uchar country_idx = *( ipinfo+processed+5UL );
61 0 : FD_TEST( country_idx<country_code_cnt );
62 :
63 0 : fd_gui_ipinfo_node_t * node = root;
64 0 : for( uchar bit_pos=0; bit_pos<prefix_len; bit_pos++ ) {
65 0 : uchar bit = (ip_addr >> (31 - bit_pos)) & 1;
66 :
67 0 : fd_gui_ipinfo_node_t * child;
68 0 : if( FD_LIKELY( !bit ) ) {
69 0 : child = node->left;
70 0 : if( FD_LIKELY( !child ) ) {
71 0 : FD_TEST( node_cnt<IPINFO_MAX_NODES );
72 0 : child = &nodes[ node_cnt++ ];
73 0 : child->left = NULL;
74 0 : child->right = NULL;
75 0 : child->has_prefix = 0;
76 0 : node->left = child;
77 0 : }
78 0 : } else {
79 0 : child = node->right;
80 0 : if( FD_LIKELY( !child ) ) {
81 0 : FD_TEST( node_cnt<IPINFO_MAX_NODES );
82 0 : child = &nodes[ node_cnt++ ];
83 0 : child->left = NULL;
84 0 : child->right = NULL;
85 0 : child->has_prefix = 0;
86 0 : node->right = child;
87 0 : }
88 0 : }
89 0 : node = child;
90 0 : }
91 :
92 0 : node->has_prefix = 1;
93 0 : node->country_code_idx = country_idx;
94 :
95 0 : processed += 6UL;
96 0 : }
97 0 : }
98 :
99 : void *
100 : fd_gui_new( void * shmem,
101 : fd_http_server_t * http,
102 : char const * version,
103 : char const * cluster,
104 : uchar const * identity_key,
105 : int has_vote_key,
106 : uchar const * vote_key,
107 : int is_full_client,
108 : int snapshots_enabled,
109 : int is_voting,
110 : int schedule_strategy,
111 : fd_topo_t * topo,
112 0 : long now ) {
113 :
114 0 : if( FD_UNLIKELY( !shmem ) ) {
115 0 : FD_LOG_WARNING(( "NULL shmem" ));
116 0 : return NULL;
117 0 : }
118 :
119 0 : if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmem, fd_gui_align() ) ) ) {
120 0 : FD_LOG_WARNING(( "misaligned shmem" ));
121 0 : return NULL;
122 0 : }
123 :
124 0 : if( FD_UNLIKELY( topo->tile_cnt>FD_GUI_TILE_TIMER_TILE_CNT ) ) {
125 0 : FD_LOG_WARNING(( "too many tiles" ));
126 0 : return NULL;
127 0 : }
128 :
129 0 : FD_SCRATCH_ALLOC_INIT( l, shmem );
130 0 : fd_gui_t * gui = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(), sizeof(fd_gui_t) );
131 0 : fd_gui_ipinfo_node_t * _nodes = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_ipinfo_node_t), sizeof(fd_gui_ipinfo_node_t)*IPINFO_MAX_NODES );
132 :
133 0 : gui->http = http;
134 0 : gui->topo = topo;
135 :
136 0 : gui->leader_slot = ULONG_MAX;
137 0 : gui->summary.schedule_strategy = schedule_strategy;
138 :
139 :
140 0 : gui->next_sample_400millis = now;
141 0 : gui->next_sample_100millis = now;
142 0 : gui->next_sample_10millis = now;
143 :
144 0 : memcpy( gui->summary.identity_key->uc, identity_key, 32UL );
145 0 : fd_base58_encode_32( identity_key, NULL, gui->summary.identity_key_base58 );
146 0 : gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
147 :
148 0 : if( FD_LIKELY( has_vote_key ) ) {
149 0 : gui->summary.has_vote_key = 1;
150 0 : memcpy( gui->summary.vote_key->uc, vote_key, 32UL );
151 0 : fd_base58_encode_32( vote_key, NULL, gui->summary.vote_key_base58 );
152 0 : gui->summary.vote_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
153 0 : } else {
154 0 : gui->summary.has_vote_key = 0;
155 0 : memset( gui->summary.vote_key_base58, 0, sizeof(gui->summary.vote_key_base58) );
156 0 : }
157 :
158 0 : gui->summary.is_full_client = is_full_client;
159 0 : gui->summary.version = version;
160 0 : gui->summary.cluster = cluster;
161 0 : gui->summary.startup_time_nanos = gui->next_sample_400millis;
162 :
163 0 : if( FD_UNLIKELY( is_full_client ) ) {
164 0 : if( FD_UNLIKELY( snapshots_enabled ) ) {
165 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP;
166 0 : gui->summary.boot_progress.joining_gossip_time_nanos = gui->next_sample_400millis;
167 0 : for( ulong i=0UL; i<FD_GUI_BOOT_PROGRESS_SNAPSHOT_CNT; i++ ) {
168 0 : gui->summary.boot_progress.loading_snapshot[ i ].reset_cnt = ULONG_MAX; /* ensures other fields are reset initially */
169 0 : gui->summary.boot_progress.loading_snapshot[ i ].read_path[ 0 ] = '\0';
170 0 : gui->summary.boot_progress.loading_snapshot[ i ].insert_path[ 0 ] = '\0';
171 0 : }
172 0 : gui->summary.boot_progress.catching_up_first_replay_slot = ULONG_MAX;
173 0 : } else {
174 0 : fd_memset( &gui->summary.boot_progress, 0, sizeof(gui->summary.boot_progress) );
175 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
176 0 : }
177 0 : } else {
178 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_INITIALIZING;
179 0 : gui->summary.startup_progress.startup_got_full_snapshot = 0;
180 0 : gui->summary.startup_progress.startup_full_snapshot_slot = 0;
181 0 : gui->summary.startup_progress.startup_incremental_snapshot_slot = 0;
182 0 : gui->summary.startup_progress.startup_waiting_for_supermajority_slot = ULONG_MAX;
183 0 : gui->summary.startup_progress.startup_ledger_max_slot = ULONG_MAX;
184 0 : }
185 :
186 0 : gui->summary.identity_account_balance = 0UL;
187 0 : gui->summary.vote_account_balance = 0UL;
188 0 : gui->summary.estimated_slot_duration_nanos = 0UL;
189 :
190 0 : gui->summary.vote_distance = 0UL;
191 0 : gui->summary.vote_state = is_voting ? FD_GUI_VOTE_STATE_VOTING : FD_GUI_VOTE_STATE_NON_VOTING;
192 :
193 0 : gui->summary.sock_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "sock" );
194 0 : gui->summary.net_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "net" );
195 0 : gui->summary.quic_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "quic" );
196 0 : gui->summary.verify_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "verify" );
197 0 : gui->summary.resolv_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolv" );
198 0 : gui->summary.bank_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "bank" );
199 0 : gui->summary.shred_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "shred" );
200 :
201 0 : gui->summary.slot_rooted = ULONG_MAX;
202 0 : gui->summary.slot_optimistically_confirmed = ULONG_MAX;
203 0 : gui->summary.slot_completed = ULONG_MAX;
204 0 : gui->summary.slot_estimated = ULONG_MAX;
205 0 : gui->summary.slot_caught_up = ULONG_MAX;
206 0 : gui->summary.slot_repair = ULONG_MAX;
207 0 : gui->summary.slot_turbine = ULONG_MAX;
208 :
209 0 : for( ulong i=0UL; i < (FD_GUI_REPAIR_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_repair[ i ].slot = ULONG_MAX;
210 0 : for( ulong i=0UL; i < (FD_GUI_TURBINE_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_turbine[ i ].slot = ULONG_MAX;
211 :
212 0 : gui->summary.estimated_tps_history_idx = 0UL;
213 0 : memset( gui->summary.estimated_tps_history, 0, sizeof(gui->summary.estimated_tps_history) );
214 :
215 0 : memset( gui->summary.txn_waterfall_reference, 0, sizeof(gui->summary.txn_waterfall_reference) );
216 0 : memset( gui->summary.txn_waterfall_current, 0, sizeof(gui->summary.txn_waterfall_current) );
217 :
218 0 : memset( gui->summary.tile_stats_reference, 0, sizeof(gui->summary.tile_stats_reference) );
219 0 : memset( gui->summary.tile_stats_current, 0, sizeof(gui->summary.tile_stats_current) );
220 :
221 0 : memset( gui->summary.tile_timers_snap[ 0 ], 0, sizeof(gui->summary.tile_timers_snap[ 0 ]) );
222 0 : memset( gui->summary.tile_timers_snap[ 1 ], 0, sizeof(gui->summary.tile_timers_snap[ 1 ]) );
223 0 : gui->summary.tile_timers_snap_idx = 2UL;
224 :
225 0 : memset( gui->summary.scheduler_counts_snap[ 0 ], 0, sizeof(gui->summary.scheduler_counts_snap[ 0 ]) );
226 0 : memset( gui->summary.scheduler_counts_snap[ 1 ], 0, sizeof(gui->summary.scheduler_counts_snap[ 1 ]) );
227 0 : gui->summary.scheduler_counts_snap_idx = 2UL;
228 :
229 0 : for( ulong i=0UL; i<FD_GUI_SLOTS_CNT; i++ ) gui->slots[ i ]->slot = ULONG_MAX;
230 0 : for( ulong i=0UL; i<FD_GUI_LEADER_CNT; i++ ) gui->leader_slots[ i ]->slot = ULONG_MAX;
231 0 : gui->leader_slots_cnt = 0UL;
232 :
233 0 : gui->block_engine.has_block_engine = 0;
234 :
235 0 : gui->epoch.has_epoch[ 0 ] = 0;
236 0 : gui->epoch.has_epoch[ 1 ] = 0;
237 :
238 0 : gui->gossip.peer_cnt = 0UL;
239 0 : gui->vote_account.vote_account_cnt = 0UL;
240 0 : gui->validator_info.info_cnt = 0UL;
241 :
242 0 : gui->pack_txn_idx = 0UL;
243 :
244 0 : gui->shreds.staged_next_broadcast = 0UL;
245 0 : gui->shreds.staged_head = 0UL;
246 0 : gui->shreds.staged_tail = 0UL;
247 0 : gui->shreds.history_tail = 0UL;
248 0 : gui->shreds.history_slot = ULONG_MAX;
249 0 : gui->summary.catch_up_repair_sz = 0UL;
250 0 : gui->summary.catch_up_turbine_sz = 0UL;
251 :
252 0 : build_ipinfo_trie( gui, _nodes );
253 :
254 0 : return gui;
255 0 : }
256 :
257 : fd_gui_t *
258 0 : fd_gui_join( void * shmem ) {
259 0 : return (fd_gui_t *)shmem;
260 0 : }
261 :
262 : void
263 : fd_gui_set_identity( fd_gui_t * gui,
264 0 : uchar const * identity_pubkey ) {
265 0 : memcpy( gui->summary.identity_key->uc, identity_pubkey, 32UL );
266 0 : fd_base58_encode_32( identity_pubkey, NULL, gui->summary.identity_key_base58 );
267 0 : gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
268 :
269 0 : fd_gui_printf_identity_key( gui );
270 0 : fd_http_server_ws_broadcast( gui->http );
271 :
272 0 : fd_gui_printf_identity_balance( gui );
273 0 : fd_http_server_ws_broadcast( gui->http );
274 0 : }
275 :
276 : void
277 : fd_gui_ws_open( fd_gui_t * gui,
278 0 : ulong ws_conn_id ) {
279 0 : void (* printers[] )( fd_gui_t * gui ) = {
280 0 : gui->summary.is_full_client ? fd_gui_printf_boot_progress : fd_gui_printf_startup_progress,
281 0 : fd_gui_printf_version,
282 0 : fd_gui_printf_cluster,
283 0 : fd_gui_printf_commit_hash,
284 0 : fd_gui_printf_identity_key,
285 0 : fd_gui_printf_vote_key,
286 0 : fd_gui_printf_startup_time_nanos,
287 0 : fd_gui_printf_vote_state,
288 0 : fd_gui_printf_vote_distance,
289 0 : fd_gui_printf_turbine_slot,
290 0 : fd_gui_printf_repair_slot,
291 0 : fd_gui_printf_slot_caught_up,
292 0 : fd_gui_printf_skipped_history,
293 0 : fd_gui_printf_skipped_history_cluster,
294 0 : fd_gui_printf_tps_history,
295 0 : fd_gui_printf_tiles,
296 0 : fd_gui_printf_schedule_strategy,
297 0 : fd_gui_printf_identity_balance,
298 0 : fd_gui_printf_vote_balance,
299 0 : fd_gui_printf_estimated_slot_duration_nanos,
300 0 : fd_gui_printf_root_slot,
301 0 : fd_gui_printf_optimistically_confirmed_slot,
302 0 : fd_gui_printf_completed_slot,
303 0 : fd_gui_printf_estimated_slot,
304 0 : fd_gui_printf_live_tile_timers,
305 0 : fd_gui_printf_live_tile_metrics,
306 0 : fd_gui_printf_catch_up_history,
307 0 : };
308 :
309 0 : ulong printers_len = sizeof(printers) / sizeof(printers[0]);
310 0 : for( ulong i=0UL; i<printers_len; i++ ) {
311 0 : printers[ i ]( gui );
312 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
313 0 : }
314 :
315 0 : if( FD_LIKELY( gui->block_engine.has_block_engine ) ) {
316 0 : fd_gui_printf_block_engine( gui );
317 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
318 0 : }
319 :
320 0 : for( ulong i=0UL; i<2UL; i++ ) {
321 0 : if( FD_LIKELY( gui->epoch.has_epoch[ i ] ) ) {
322 0 : fd_gui_printf_skip_rate( gui, i );
323 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
324 0 : fd_gui_printf_epoch( gui, i );
325 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
326 0 : }
327 0 : }
328 :
329 : /* Print peers last because it's the largest message and would
330 : block other information. */
331 0 : fd_gui_printf_peers_all( gui );
332 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
333 0 : }
334 :
335 : static void
336 0 : fd_gui_tile_timers_snap( fd_gui_t * gui ) {
337 0 : fd_gui_tile_timers_t * cur = gui->summary.tile_timers_snap[ gui->summary.tile_timers_snap_idx ];
338 0 : gui->summary.tile_timers_snap_idx = (gui->summary.tile_timers_snap_idx+1UL)%FD_GUI_TILE_TIMER_SNAP_CNT;
339 0 : for( ulong i=0UL; i<gui->topo->tile_cnt; i++ ) {
340 0 : fd_topo_tile_t * tile = &gui->topo->tiles[ i ];
341 0 : if ( FD_UNLIKELY( !tile->metrics ) ) {
342 : /* bench tiles might not have been booted initially.
343 : This check shouldn't be necessary if all tiles barrier after boot. */
344 : // TODO(FIXME) this probably isn't the right fix but it makes fddev bench work for now
345 0 : return;
346 0 : }
347 0 : volatile ulong const * tile_metrics = fd_metrics_tile( tile->metrics );
348 :
349 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_HOUSEKEEPING ) ];
350 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_HOUSEKEEPING ) ];
351 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_HOUSEKEEPING ) ];
352 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_PREFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_PREFRAG ) ];
353 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_PREFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_PREFRAG ) ];
354 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
355 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_POSTFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_POSTFRAG ) ];
356 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_POSTFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_POSTFRAG ) ];
357 :
358 0 : cur[ i ].in_backp = (int)tile_metrics[ MIDX(GAUGE, TILE, IN_BACKPRESSURE) ];
359 0 : cur[ i ].heartbeat = tile_metrics[ FD_METRICS_GAUGE_TILE_HEARTBEAT_OFF ];
360 0 : cur[ i ].backp_cnt = tile_metrics[ MIDX( COUNTER, TILE, BACKPRESSURE_COUNT ) ];
361 0 : cur[ i ].nvcsw = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_VOLUNTARY_COUNT ) ];
362 0 : cur[ i ].nivcsw = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_INVOLUNTARY_COUNT ) ];
363 0 : }
364 0 : }
365 :
366 : static void
367 0 : fd_gui_scheduler_counts_snap( fd_gui_t * gui, long now ) {
368 0 : fd_gui_scheduler_counts_t * cur = gui->summary.scheduler_counts_snap[ gui->summary.scheduler_counts_snap_idx ];
369 0 : gui->summary.scheduler_counts_snap_idx = (gui->summary.scheduler_counts_snap_idx+1UL)%FD_GUI_SCHEDULER_COUNT_SNAP_CNT;
370 :
371 0 : fd_topo_tile_t const * pack = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "pack", 0UL ) ];
372 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
373 :
374 0 : cur->sample_time_ns = now;
375 :
376 0 : cur->regular = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_REGULAR ) ];
377 0 : cur->votes = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_VOTES ) ];
378 0 : cur->conflicting = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_CONFLICTING ) ];
379 0 : cur->bundles = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_BUNDLES ) ];
380 0 : }
381 :
382 : static void
383 0 : fd_gui_estimated_tps_snap( fd_gui_t * gui ) {
384 0 : ulong total_txn_cnt = 0UL;
385 0 : ulong vote_txn_cnt = 0UL;
386 0 : ulong nonvote_failed_txn_cnt = 0UL;
387 :
388 0 : if( FD_LIKELY( gui->summary.slot_completed==ULONG_MAX ) ) return;
389 0 : for( ulong i=0UL; i<fd_ulong_min( gui->summary.slot_completed+1UL, FD_GUI_SLOTS_CNT ); i++ ) {
390 0 : ulong _slot = gui->summary.slot_completed-i;
391 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
392 0 : if( FD_UNLIKELY( !slot ) ) break; /* Slot no longer exists, no TPS. */
393 0 : if( FD_UNLIKELY( slot->completed_time==LONG_MAX ) ) continue; /* Slot is on this fork but was never completed, must have been in root path on boot. */
394 0 : if( FD_UNLIKELY( slot->completed_time+FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS*1000L*1000L*1000L<gui->next_sample_400millis ) ) break; /* Slot too old. */
395 0 : if( FD_UNLIKELY( slot->skipped ) ) continue; /* Skipped slots don't count to TPS. */
396 :
397 0 : total_txn_cnt += slot->total_txn_cnt;
398 0 : vote_txn_cnt += slot->vote_txn_cnt;
399 0 : nonvote_failed_txn_cnt += slot->nonvote_failed_txn_cnt;
400 0 : }
401 :
402 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ][ 0 ] = total_txn_cnt;
403 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ][ 1 ] = vote_txn_cnt;
404 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ][ 2 ] = nonvote_failed_txn_cnt;
405 0 : gui->summary.estimated_tps_history_idx = (gui->summary.estimated_tps_history_idx+1UL) % FD_GUI_TPS_HISTORY_SAMPLE_CNT;
406 0 : }
407 :
408 : static void
409 : fd_gui_network_stats_snap( fd_gui_t * gui,
410 0 : fd_gui_network_stats_t * cur ) {
411 0 : fd_topo_t * topo = gui->topo;
412 0 : ulong gossvf_tile_cnt = fd_topo_tile_name_cnt( topo, "gossvf" );
413 0 : ulong gossip_tile_cnt = fd_topo_tile_name_cnt( topo, "gossip" );
414 0 : ulong shred_tile_cnt = fd_topo_tile_name_cnt( topo, "shred" );
415 0 : ulong net_tile_cnt = fd_topo_tile_name_cnt( topo, "net" );
416 0 : ulong quic_tile_cnt = fd_topo_tile_name_cnt( topo, "quic" );
417 :
418 0 : cur->in.gossip = fd_gui_metrics_gossip_total_ingress_bytes( topo, gossvf_tile_cnt );
419 0 : cur->out.gossip = fd_gui_metrics_gosip_total_egress_bytes( topo, gossip_tile_cnt );
420 0 : cur->in.turbine = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_TURBINE_RCV_BYTES ) );
421 :
422 0 : cur->out.turbine = 0UL;
423 0 : cur->out.repair = 0UL;
424 0 : cur->out.tpu = 0UL;
425 0 : for( ulong i=0UL; i<net_tile_cnt; i++ ) {
426 0 : ulong net_tile_idx = fd_topo_find_tile( topo, "net", i );
427 0 : if( FD_UNLIKELY( net_tile_idx==ULONG_MAX ) ) continue;
428 0 : fd_topo_tile_t const * net = &topo->tiles[ net_tile_idx ];
429 0 : for( ulong j=0UL; j<net->in_cnt; j++ ) {
430 0 : if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "shred_net" ) ) ) {
431 0 : cur->out.turbine += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
432 0 : }
433 :
434 0 : if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "repair_net" ) ) ) {
435 0 : cur->out.repair += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
436 0 : }
437 :
438 0 : if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "send_net" ) ) ) {
439 0 : cur->out.tpu += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
440 0 : }
441 0 : }
442 0 : }
443 :
444 0 : cur->in.repair = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_OUT_RCV_BYTES ) );
445 0 : ulong repair_tile_idx = fd_topo_find_tile( topo, "repair", 0UL );
446 0 : if( FD_LIKELY( repair_tile_idx!=ULONG_MAX ) ) {
447 0 : fd_topo_tile_t const * repair = &topo->tiles[ repair_tile_idx ];
448 :
449 0 : for( ulong i=0UL; i<repair->in_cnt; i++ ) {
450 0 : if( FD_UNLIKELY( !strcmp( topo->links[ repair->in_link_id[ i ] ].name, "net_repair" ) ) ) {
451 0 : cur->in.repair += fd_metrics_link_in( repair->metrics, i )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
452 0 : }
453 0 : }
454 0 : }
455 :
456 0 : cur->in.tpu = 0UL;
457 0 : for( ulong i=0UL; i<quic_tile_cnt; i++ ) {
458 0 : ulong quic_tile_idx = fd_topo_find_tile( topo, "quic", i );
459 0 : if( FD_UNLIKELY( quic_tile_idx==ULONG_MAX ) ) continue;
460 0 : fd_topo_tile_t const * quic = &topo->tiles[ quic_tile_idx ];
461 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
462 0 : cur->in.tpu += quic_metrics[ MIDX( COUNTER, QUIC, RECEIVED_BYTES ) ];
463 0 : }
464 :
465 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
466 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
467 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
468 0 : volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
469 0 : cur->in.tpu += bundle_metrics[ MIDX( COUNTER, BUNDLE, PROTO_RECEIVED_BYTES ) ];
470 0 : }
471 :
472 0 : ulong metric_tile_idx = fd_topo_find_tile( topo, "metric", 0UL );
473 0 : if( FD_LIKELY( metric_tile_idx!=ULONG_MAX ) ) {
474 0 : fd_topo_tile_t const * metric = &topo->tiles[ metric_tile_idx ];
475 0 : volatile ulong * metric_metrics = fd_metrics_tile( metric->metrics );
476 0 : cur->in.metric = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_READ ) ];
477 0 : cur->out.metric = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_WRITTEN ) ];
478 0 : } else {
479 0 : cur->in.metric = 0UL;
480 0 : cur->out.metric = 0UL;
481 0 : }
482 0 : }
483 :
484 : /* Snapshot all of the data from metrics to construct a view of the
485 : transaction waterfall.
486 :
487 : Tiles are sampled in reverse pipeline order: this helps prevent data
488 : discrepancies where a later tile has "seen" more transactions than an
489 : earlier tile, which shouldn't typically happen. */
490 :
491 : static void
492 : fd_gui_txn_waterfall_snap( fd_gui_t * gui,
493 0 : fd_gui_txn_waterfall_t * cur ) {
494 0 : fd_topo_t * topo = gui->topo;
495 :
496 0 : cur->out.block_success = 0UL;
497 0 : cur->out.block_fail = 0UL;
498 :
499 0 : cur->out.bank_invalid = 0UL;
500 0 : for( ulong i=0UL; i<gui->summary.bank_tile_cnt; i++ ) {
501 0 : fd_topo_tile_t const * bank = &topo->tiles[ fd_topo_find_tile( topo, "bank", i ) ];
502 :
503 0 : volatile ulong const * bank_metrics = fd_metrics_tile( bank->metrics );
504 0 : if( FD_LIKELY( !gui->summary.is_full_client ) ) {
505 0 : cur->out.block_success += bank_metrics[ MIDX( COUNTER, BANK, SUCCESSFUL_TRANSACTIONS ) ];
506 :
507 0 : cur->out.block_fail +=
508 0 : bank_metrics[ MIDX( COUNTER, BANK, EXECUTED_FAILED_TRANSACTIONS ) ]
509 0 : + bank_metrics[ MIDX( COUNTER, BANK, FEE_ONLY_TRANSACTIONS ) ];
510 :
511 0 : cur->out.bank_invalid +=
512 0 : bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_ACCOUNT_UNINITIALIZED ) ]
513 0 : + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_ACCOUNT_NOT_FOUND ) ]
514 0 : + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_INVALID_ACCOUNT_OWNER ) ]
515 0 : + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_INVALID_ACCOUNT_DATA ) ]
516 0 : + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_INVALID_LOOKUP_INDEX ) ];
517 :
518 0 : cur->out.bank_invalid +=
519 0 : bank_metrics[ MIDX( COUNTER, BANK, PROCESSING_FAILED ) ];
520 :
521 : /* These branches are unused in Frankendancer */
522 0 : cur->out.bank_nonce_already_advanced = 0UL;
523 0 : cur->out.bank_nonce_advance_failed = 0UL;
524 0 : cur->out.bank_nonce_wrong_blockhash = 0UL;
525 0 : } else {
526 0 : cur->out.block_success += bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_LANDED_LANDED_SUCCESS ) ];
527 0 : cur->out.block_fail +=
528 0 : bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_LANDED_LANDED_FEES_ONLY ) ]
529 0 : + bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_LANDED_LANDED_FAILED ) ];
530 0 : cur->out.bank_invalid += bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_LANDED_UNLANDED ) ];
531 :
532 0 : cur->out.bank_nonce_already_advanced = bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_RESULT_NONCE_ALREADY_ADVANCED ) ];
533 0 : cur->out.bank_nonce_advance_failed = bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_RESULT_NONCE_ADVANCE_FAILED ) ];
534 0 : cur->out.bank_nonce_wrong_blockhash = bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_RESULT_NONCE_WRONG_BLOCKHASH ) ];
535 0 : }
536 0 : }
537 :
538 :
539 0 : fd_topo_tile_t const * pack = &topo->tiles[ fd_topo_find_tile( topo, "pack", 0UL ) ];
540 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
541 :
542 0 : cur->out.pack_invalid_bundle =
543 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DROPPED_PARTIAL_BUNDLE ) ]
544 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTION_FAILED ) ]
545 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_CREATION_FAILED ) ];
546 :
547 0 : cur->out.pack_invalid =
548 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_NONCE_CONFLICT ) ]
549 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_BUNDLE_BLACKLIST ) ]
550 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_INVALID_NONCE ) ]
551 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_WRITE_SYSVAR ) ]
552 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_ESTIMATION_FAIL ) ]
553 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_DUPLICATE_ACCOUNT ) ]
554 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_TOO_MANY_ACCOUNTS ) ]
555 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_TOO_LARGE ) ]
556 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_ADDR_LUT ) ]
557 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_UNAFFORDABLE ) ]
558 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_DUPLICATE ) ]
559 0 : - pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTION_FAILED ) ]; /* so we don't double count this, since its already accounted for in invalid_bundle */
560 :
561 0 : cur->out.pack_expired = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_EXPIRED ) ] +
562 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_EXPIRED ) ] +
563 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DELETED ) ] +
564 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_NONCE_PRIORITY ) ];
565 :
566 0 : cur->out.pack_already_executed = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_ALREADY_EXECUTED ) ];
567 :
568 0 : cur->out.pack_leader_slow = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_PRIORITY ) ];
569 :
570 0 : cur->out.pack_wait_full =
571 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DROPPED_FROM_EXTRA ) ];
572 :
573 0 : cur->out.pack_retained = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS ) ];
574 :
575 0 : ulong inserted_to_extra = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_TO_EXTRA ) ];
576 0 : ulong inserted_from_extra = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_FROM_EXTRA ) ]
577 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DROPPED_FROM_EXTRA ) ];
578 0 : cur->out.pack_retained += fd_ulong_if( inserted_to_extra>=inserted_from_extra, inserted_to_extra-inserted_from_extra, 0UL );
579 :
580 0 : cur->out.resolv_lut_failed = 0UL;
581 0 : cur->out.resolv_expired = 0UL;
582 0 : cur->out.resolv_ancient = 0UL;
583 0 : cur->out.resolv_no_ledger = 0UL;
584 0 : cur->out.resolv_retained = 0UL;
585 0 : for( ulong i=0UL; i<gui->summary.resolv_tile_cnt; i++ ) {
586 0 : fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolv", i ) ];
587 0 : volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
588 :
589 0 : if( FD_LIKELY( !gui->summary.is_full_client ) ) {
590 0 : cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLV, NO_BANK_DROP ) ];
591 0 : cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLV, BLOCKHASH_EXPIRED ) ]
592 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, TRANSACTION_BUNDLE_PEER_FAILURE ) ];
593 0 : cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
594 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
595 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
596 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
597 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
598 0 : cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ];
599 :
600 0 : ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_INSERTED ) ];
601 0 : ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ]
602 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_PUBLISHED ) ]
603 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_REMOVED ) ];
604 0 : cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
605 0 : } else {
606 0 : cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLF, NO_BANK_DROP ) ];
607 0 : cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLF, BLOCKHASH_EXPIRED ) ]
608 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, TRANSACTION_BUNDLE_PEER_FAILURE ) ];
609 0 : cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLF, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
610 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
611 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
612 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
613 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
614 0 : cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLF, STASH_OPERATION_OVERRUN ) ];
615 :
616 0 : ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLF, STASH_OPERATION_INSERTED ) ];
617 0 : ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLF, STASH_OPERATION_OVERRUN ) ]
618 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, STASH_OPERATION_PUBLISHED ) ]
619 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, STASH_OPERATION_REMOVED ) ];
620 0 : cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
621 0 : }
622 0 : }
623 :
624 :
625 0 : fd_topo_tile_t const * dedup = &topo->tiles[ fd_topo_find_tile( topo, "dedup", 0UL ) ];
626 0 : volatile ulong const * dedup_metrics = fd_metrics_tile( dedup->metrics );
627 :
628 0 : cur->out.dedup_duplicate = dedup_metrics[ MIDX( COUNTER, DEDUP, TRANSACTION_DEDUP_FAILURE ) ]
629 0 : + dedup_metrics[ MIDX( COUNTER, DEDUP, TRANSACTION_BUNDLE_PEER_FAILURE ) ];
630 :
631 :
632 0 : cur->out.verify_overrun = 0UL;
633 0 : cur->out.verify_duplicate = 0UL;
634 0 : cur->out.verify_parse = 0UL;
635 0 : cur->out.verify_failed = 0UL;
636 :
637 0 : for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
638 0 : fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
639 0 : volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
640 :
641 0 : for( ulong j=0UL; j<gui->summary.quic_tile_cnt; j++ ) {
642 : /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this verify tile. */
643 0 : cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_POLLING_FRAG_COUNT_OFF ] / gui->summary.verify_tile_cnt;
644 0 : cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_READING_FRAG_COUNT_OFF ];
645 0 : }
646 :
647 0 : cur->out.verify_failed += verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_VERIFY_FAILURE ) ] +
648 0 : verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_BUNDLE_PEER_FAILURE ) ];
649 0 : cur->out.verify_parse += verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_PARSE_FAILURE ) ];
650 0 : cur->out.verify_duplicate += verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_DEDUP_FAILURE ) ];
651 0 : }
652 :
653 :
654 0 : cur->out.quic_overrun = 0UL;
655 0 : cur->out.quic_frag_drop = 0UL;
656 0 : cur->out.quic_abandoned = 0UL;
657 0 : cur->out.tpu_quic_invalid = 0UL;
658 0 : cur->out.tpu_udp_invalid = 0UL;
659 0 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
660 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
661 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
662 :
663 0 : cur->out.tpu_udp_invalid += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_UNDERSZ ) ];
664 0 : cur->out.tpu_udp_invalid += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_OVERSZ ) ];
665 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_UNDERSZ ) ];
666 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_OVERSZ ) ];
667 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, TXN_OVERSZ ) ];
668 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_CRYPTO_FAILED ) ];
669 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NO_CONN ) ];
670 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NET_HEADER_INVALID ) ];
671 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_QUIC_HEADER_INVALID ) ];
672 0 : cur->out.quic_abandoned += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_ABANDONED ) ];
673 0 : cur->out.quic_frag_drop += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_OVERRUN ) ];
674 :
675 0 : for( ulong j=0UL; j<gui->summary.net_tile_cnt; j++ ) {
676 : /* TODO: Not precise... net frags that were skipped might not have been destined for QUIC tile */
677 : /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this QUIC tile */
678 0 : cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_POLLING_FRAG_COUNT_OFF ] / gui->summary.quic_tile_cnt;
679 0 : cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_READING_FRAG_COUNT_OFF ];
680 0 : }
681 0 : }
682 :
683 0 : cur->out.net_overrun = 0UL;
684 0 : for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
685 0 : fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
686 0 : volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
687 :
688 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_RING_FULL ) ];
689 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_DROPPED_OTHER ) ];
690 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_FILL_RING_EMPTY_DESCS ) ];
691 0 : }
692 :
693 0 : ulong bundle_txns_received = 0UL;
694 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
695 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
696 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
697 0 : volatile ulong const * bundle_metrics = fd_metrics_tile( bundle->metrics );
698 :
699 0 : bundle_txns_received = bundle_metrics[ MIDX( COUNTER, BUNDLE, TRANSACTION_RECEIVED ) ];
700 0 : }
701 :
702 0 : cur->in.pack_cranked =
703 0 : pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTED ) ]
704 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTION_FAILED ) ]
705 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_CREATION_FAILED ) ];
706 :
707 0 : if( FD_UNLIKELY( gui->summary.is_full_client ) ) {
708 0 : cur->in.gossip = 0UL;
709 0 : for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
710 0 : fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
711 0 : volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
712 0 : cur->in.gossip += verify_metrics[ MIDX( COUNTER, VERIFY, GOSSIPED_VOTES_RECEIVED ) ];
713 0 : }
714 0 : } else {
715 0 : cur->in.gossip = dedup_metrics[ MIDX( COUNTER, DEDUP, GOSSIPED_VOTES_RECEIVED ) ];
716 0 : }
717 :
718 0 : cur->in.quic = cur->out.tpu_quic_invalid +
719 0 : cur->out.quic_overrun +
720 0 : cur->out.quic_frag_drop +
721 0 : cur->out.quic_abandoned +
722 0 : cur->out.net_overrun;
723 0 : cur->in.udp = cur->out.tpu_udp_invalid;
724 0 : cur->in.block_engine = bundle_txns_received;
725 0 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
726 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
727 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
728 :
729 0 : cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_RECEIVED_QUIC_FAST ) ];
730 0 : cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_RECEIVED_QUIC_FRAG ) ];
731 0 : cur->in.udp += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_RECEIVED_UDP ) ];
732 0 : }
733 0 : }
734 :
735 : static void
736 : fd_gui_tile_stats_snap( fd_gui_t * gui,
737 : fd_gui_txn_waterfall_t const * waterfall,
738 : fd_gui_tile_stats_t * stats,
739 0 : long now ) {
740 0 : fd_topo_t const * topo = gui->topo;
741 :
742 0 : stats->sample_time_nanos = now;
743 :
744 0 : stats->net_in_rx_bytes = 0UL;
745 0 : stats->net_out_tx_bytes = 0UL;
746 0 : for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
747 0 : fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
748 0 : volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
749 :
750 0 : stats->net_in_rx_bytes += net_metrics[ MIDX( COUNTER, NET, RX_BYTES_TOTAL ) ];
751 0 : stats->net_out_tx_bytes += net_metrics[ MIDX( COUNTER, NET, TX_BYTES_TOTAL ) ];
752 0 : }
753 :
754 0 : for( ulong i=0UL; i<gui->summary.sock_tile_cnt; i++ ) {
755 0 : fd_topo_tile_t const * sock = &topo->tiles[ fd_topo_find_tile( topo, "sock", i ) ];
756 0 : volatile ulong * sock_metrics = fd_metrics_tile( sock->metrics );
757 :
758 0 : stats->net_in_rx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, RX_BYTES_TOTAL ) ];
759 0 : stats->net_out_tx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, TX_BYTES_TOTAL ) ];
760 0 : }
761 :
762 0 : stats->quic_conn_cnt = 0UL;
763 0 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
764 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
765 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
766 :
767 0 : stats->quic_conn_cnt += quic_metrics[ MIDX( GAUGE, QUIC, CONNECTIONS_ALLOC ) ];
768 0 : }
769 :
770 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
771 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
772 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
773 0 : volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
774 0 : stats->bundle_rtt_smoothed_nanos = bundle_metrics[ MIDX( GAUGE, BUNDLE, RTT_SMOOTHED ) ];
775 :
776 0 : fd_histf_new( &stats->bundle_rx_delay_hist, FD_MHIST_MIN( BUNDLE, MESSAGE_RX_DELAY_NANOS ), FD_MHIST_MAX( BUNDLE, MESSAGE_RX_DELAY_NANOS ) );
777 0 : stats->bundle_rx_delay_hist.sum = bundle_metrics[ MIDX( HISTOGRAM, BUNDLE, MESSAGE_RX_DELAY_NANOS ) + FD_HISTF_BUCKET_CNT ];
778 0 : for( ulong b=0; b<FD_HISTF_BUCKET_CNT; b++ ) stats->bundle_rx_delay_hist.counts[ b ] = bundle_metrics[ MIDX( HISTOGRAM, BUNDLE, MESSAGE_RX_DELAY_NANOS ) + b ];
779 0 : }
780 :
781 0 : stats->verify_drop_cnt = waterfall->out.verify_duplicate +
782 0 : waterfall->out.verify_parse +
783 0 : waterfall->out.verify_failed;
784 0 : stats->verify_total_cnt = waterfall->in.gossip +
785 0 : waterfall->in.quic +
786 0 : waterfall->in.udp -
787 0 : waterfall->out.net_overrun -
788 0 : waterfall->out.tpu_quic_invalid -
789 0 : waterfall->out.tpu_udp_invalid -
790 0 : waterfall->out.quic_abandoned -
791 0 : waterfall->out.quic_frag_drop -
792 0 : waterfall->out.quic_overrun -
793 0 : waterfall->out.verify_overrun;
794 0 : stats->dedup_drop_cnt = waterfall->out.dedup_duplicate;
795 0 : stats->dedup_total_cnt = stats->verify_total_cnt -
796 0 : waterfall->out.verify_duplicate -
797 0 : waterfall->out.verify_parse -
798 0 : waterfall->out.verify_failed;
799 :
800 0 : fd_topo_tile_t const * pack = &topo->tiles[ fd_topo_find_tile( topo, "pack", 0UL ) ];
801 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
802 0 : stats->pack_buffer_cnt = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS ) ];
803 0 : stats->pack_buffer_capacity = pack->pack.max_pending_transactions;
804 :
805 0 : stats->bank_txn_exec_cnt = waterfall->out.block_fail + waterfall->out.block_success;
806 0 : }
807 :
808 : static void
809 0 : fd_gui_run_boot_progress( fd_gui_t * gui, long now ) {
810 0 : fd_topo_tile_t const * snapct = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapct", 0UL ) ];
811 0 : volatile ulong * snapct_metrics = fd_metrics_tile( snapct->metrics );
812 :
813 0 : fd_topo_tile_t const * snapdc = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapdc", 0UL ) ];
814 0 : volatile ulong * snapdc_metrics = fd_metrics_tile( snapdc->metrics );
815 :
816 0 : fd_topo_tile_t const * snapin = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapin", 0UL ) ];
817 0 : volatile ulong * snapin_metrics = fd_metrics_tile( snapin->metrics );
818 :
819 0 : ulong snapshot_phase = snapct_metrics[ MIDX( GAUGE, SNAPCT, STATE ) ];
820 :
821 : /* state transitions */
822 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
823 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
824 0 : } else if( FD_LIKELY( snapshot_phase == FD_SNAPCT_STATE_SHUTDOWN && gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && gui->summary.slot_completed!=ULONG_MAX ) ) {
825 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP;
826 0 : } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_FULL_FILE
827 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_FILE
828 0 : || snapshot_phase==FD_SNAPCT_STATE_READING_FULL_HTTP
829 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_HTTP ) ) {
830 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT;
831 0 : } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_FILE
832 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE
833 0 : || snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_HTTP
834 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP ) ) {
835 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
836 0 : }
837 :
838 : /* It's possible for the incremental snapshot phase to be skipped, or
839 : complete before we can sample it. This ensures we always get at
840 : least one pass of the metrics. */
841 0 : if( FD_UNLIKELY( gui->summary.boot_progress.phase==FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP
842 0 : && gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].reset_cnt==ULONG_MAX ) ) {
843 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
844 0 : }
845 :
846 0 : switch ( gui->summary.boot_progress.phase ) {
847 0 : case FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP: {
848 0 : gui->summary.boot_progress.joining_gossip_time_nanos = now;
849 0 : break;
850 0 : }
851 0 : case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT:
852 0 : case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT: {
853 0 : ulong snapshot_idx = fd_ulong_if( gui->summary.boot_progress.phase==FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT, FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX );
854 0 : ulong _retry_cnt = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_DOWNLOAD_RETRIES ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_DOWNLOAD_RETRIES ) ]);
855 :
856 : /* reset boot state if necessary */
857 0 : if( FD_UNLIKELY( gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt!=_retry_cnt ) ) {
858 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_time_nanos = now;
859 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt = _retry_cnt;
860 0 : }
861 :
862 0 : ulong _total_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_BYTES_TOTAL ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_BYTES_TOTAL ) ] );
863 0 : ulong _read_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_BYTES_READ ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_BYTES_READ ) ] );
864 0 : ulong _decompress_decompressed_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapdc_metrics[ MIDX( GAUGE, SNAPDC, FULL_DECOMPRESSED_BYTES_WRITTEN ) ], snapdc_metrics[ MIDX( GAUGE, SNAPDC, INCREMENTAL_DECOMPRESSED_BYTES_WRITTEN ) ] );
865 0 : ulong _decompress_compressed_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapdc_metrics[ MIDX( GAUGE, SNAPDC, FULL_COMPRESSED_BYTES_READ ) ], snapdc_metrics[ MIDX( GAUGE, SNAPDC, INCREMENTAL_COMPRESSED_BYTES_READ ) ] );
866 0 : ulong _insert_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapin_metrics[ MIDX( GAUGE, SNAPIN, FULL_BYTES_READ ) ], snapin_metrics[ MIDX( GAUGE, SNAPIN, INCREMENTAL_BYTES_READ ) ] );
867 0 : ulong _insert_accounts = snapin_metrics[ MIDX( GAUGE, SNAPIN, ACCOUNTS_INSERTED ) ];
868 :
869 : /* metadata */
870 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].total_bytes_compressed = _total_bytes;
871 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].sample_time_nanos = now;
872 :
873 : /* read stage */
874 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_bytes_compressed = _read_bytes;
875 :
876 : /* decompress stage */
877 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_compressed = _decompress_compressed_bytes;
878 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_decompressed = _decompress_decompressed_bytes;
879 :
880 : /* insert stage */
881 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_bytes_decompressed = _insert_bytes;
882 :
883 : /* Use the latest compression ratio to estimate decompressed size */
884 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_accounts_current = _insert_accounts;
885 :
886 0 : break;
887 0 : }
888 0 : case FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP: {
889 0 : gui->summary.boot_progress.catching_up_time_nanos = now;
890 0 : break;
891 0 : }
892 0 : case FD_GUI_BOOT_PROGRESS_TYPE_RUNNING: break;
893 0 : default: FD_LOG_ERR(( "unknown boot progress phase: %d", gui->summary.boot_progress.phase ));
894 0 : }
895 0 : }
896 :
897 : int
898 0 : fd_gui_poll( fd_gui_t * gui, long now ) {
899 0 : int did_work = 0;
900 :
901 0 : if( FD_LIKELY( now>gui->next_sample_400millis ) ) {
902 0 : fd_gui_estimated_tps_snap( gui );
903 0 : fd_gui_printf_estimated_tps( gui );
904 0 : fd_http_server_ws_broadcast( gui->http );
905 :
906 0 : gui->next_sample_400millis += 400L*1000L*1000L;
907 0 : did_work = 1;
908 0 : }
909 :
910 0 : if( FD_LIKELY( now>gui->next_sample_100millis ) ) {
911 0 : fd_gui_txn_waterfall_snap( gui, gui->summary.txn_waterfall_current );
912 0 : fd_gui_printf_live_txn_waterfall( gui, gui->summary.txn_waterfall_reference, gui->summary.txn_waterfall_current, 0UL /* TODO: REAL NEXT LEADER SLOT */ );
913 0 : fd_http_server_ws_broadcast( gui->http );
914 :
915 0 : fd_gui_network_stats_snap( gui, gui->summary.network_stats_current );
916 0 : fd_gui_printf_live_network_metrics( gui, gui->summary.network_stats_current );
917 0 : fd_http_server_ws_broadcast( gui->http );
918 :
919 0 : *gui->summary.tile_stats_reference = *gui->summary.tile_stats_current;
920 0 : fd_gui_tile_stats_snap( gui, gui->summary.txn_waterfall_current, gui->summary.tile_stats_current, now );
921 0 : fd_gui_printf_live_tile_stats( gui, gui->summary.tile_stats_reference, gui->summary.tile_stats_current );
922 0 : fd_http_server_ws_broadcast( gui->http );
923 :
924 0 : if( FD_UNLIKELY( gui->summary.is_full_client && gui->summary.boot_progress.phase!=FD_GUI_BOOT_PROGRESS_TYPE_RUNNING ) ) {
925 0 : fd_gui_run_boot_progress( gui, now );
926 0 : fd_gui_printf_boot_progress( gui );
927 0 : fd_http_server_ws_broadcast( gui->http );
928 0 : }
929 :
930 0 : gui->next_sample_100millis += 100L*1000L*1000L;
931 0 : did_work = 1;
932 0 : }
933 :
934 0 : if( FD_LIKELY( now>gui->next_sample_10millis ) ) {
935 0 : fd_gui_tile_timers_snap( gui );
936 :
937 0 : fd_gui_printf_live_tile_timers( gui );
938 0 : fd_http_server_ws_broadcast( gui->http );
939 :
940 0 : fd_gui_printf_live_tile_metrics( gui );
941 0 : fd_http_server_ws_broadcast( gui->http );
942 :
943 0 : fd_gui_scheduler_counts_snap( gui, now );
944 :
945 0 : if( FD_LIKELY( gui->summary.is_full_client && gui->shreds.staged_next_broadcast<gui->shreds.staged_tail ) ) {
946 0 : fd_gui_printf_shred_updates( gui );
947 0 : fd_http_server_ws_broadcast( gui->http );
948 0 : gui->shreds.staged_next_broadcast = gui->shreds.staged_tail;
949 0 : }
950 :
951 0 : gui->next_sample_10millis += 10L*1000L*1000L;
952 0 : did_work = 1;
953 0 : }
954 :
955 0 : return did_work;
956 0 : }
957 :
958 : static void
959 : fd_gui_handle_gossip_update( fd_gui_t * gui,
960 0 : uchar const * msg ) {
961 0 : if( FD_UNLIKELY( gui->gossip.peer_cnt == FD_GUI_MAX_PEER_CNT ) ) {
962 0 : FD_LOG_DEBUG(("gossip peer cnt exceeds 40200 %lu, ignoring additional entries", gui->gossip.peer_cnt ));
963 0 : return;
964 0 : }
965 0 : ulong const * header = (ulong const *)fd_type_pun_const( msg );
966 0 : ulong peer_cnt = header[ 0 ];
967 :
968 0 : FD_TEST( peer_cnt<=FD_GUI_MAX_PEER_CNT );
969 :
970 0 : ulong added_cnt = 0UL;
971 0 : ulong added[ FD_GUI_MAX_PEER_CNT ] = {0};
972 :
973 0 : ulong update_cnt = 0UL;
974 0 : ulong updated[ FD_GUI_MAX_PEER_CNT ] = {0};
975 :
976 0 : ulong removed_cnt = 0UL;
977 0 : fd_pubkey_t removed[ FD_GUI_MAX_PEER_CNT ] = {0};
978 :
979 0 : uchar const * data = (uchar const *)(header+1UL);
980 0 : for( ulong i=0UL; i<gui->gossip.peer_cnt; i++ ) {
981 0 : int found = 0;
982 0 : for( ulong j=0UL; j<peer_cnt; j++ ) {
983 0 : if( FD_UNLIKELY( !memcmp( gui->gossip.peers[ i ].pubkey, data+j*(58UL+12UL*6UL), 32UL ) ) ) {
984 0 : found = 1;
985 0 : break;
986 0 : }
987 0 : }
988 :
989 0 : if( FD_UNLIKELY( !found ) ) {
990 0 : fd_memcpy( removed[ removed_cnt++ ].uc, gui->gossip.peers[ i ].pubkey->uc, 32UL );
991 0 : if( FD_LIKELY( i+1UL!=gui->gossip.peer_cnt ) ) {
992 0 : gui->gossip.peers[ i ] = gui->gossip.peers[ gui->gossip.peer_cnt-1UL ];
993 0 : i--;
994 0 : }
995 0 : gui->gossip.peer_cnt--;
996 0 : }
997 0 : }
998 :
999 0 : ulong before_peer_cnt = gui->gossip.peer_cnt;
1000 0 : for( ulong i=0UL; i<peer_cnt; i++ ) {
1001 0 : int found = 0;
1002 0 : ulong found_idx = 0;
1003 0 : for( ulong j=0UL; j<gui->gossip.peer_cnt; j++ ) {
1004 0 : if( FD_UNLIKELY( !memcmp( gui->gossip.peers[ j ].pubkey, data+i*(58UL+12UL*6UL), 32UL ) ) ) {
1005 0 : found_idx = j;
1006 0 : found = 1;
1007 0 : break;
1008 0 : }
1009 0 : }
1010 :
1011 0 : if( FD_UNLIKELY( !found ) ) {
1012 0 : fd_memcpy( gui->gossip.peers[ gui->gossip.peer_cnt ].pubkey->uc, data+i*(58UL+12UL*6UL), 32UL );
1013 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].wallclock = *(ulong const *)(data+i*(58UL+12UL*6UL)+32UL);
1014 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].shred_version = *(ushort const *)(data+i*(58UL+12UL*6UL)+40UL);
1015 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].has_version = *(data+i*(58UL+12UL*6UL)+42UL);
1016 0 : if( FD_LIKELY( gui->gossip.peers[ gui->gossip.peer_cnt ].has_version ) ) {
1017 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.major = *(ushort const *)(data+i*(58UL+12UL*6UL)+43UL);
1018 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.minor = *(ushort const *)(data+i*(58UL+12UL*6UL)+45UL);
1019 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.patch = *(ushort const *)(data+i*(58UL+12UL*6UL)+47UL);
1020 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.has_commit = *(data+i*(58UL+12UL*6UL)+49UL);
1021 0 : if( FD_LIKELY( gui->gossip.peers[ gui->gossip.peer_cnt ].version.has_commit ) ) {
1022 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.commit = *(uint const *)(data+i*(58UL+12UL*6UL)+50UL);
1023 0 : }
1024 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.feature_set = *(uint const *)(data+i*(58UL+12UL*6UL)+54UL);
1025 0 : }
1026 :
1027 0 : for( ulong j=0UL; j<12UL; j++ ) {
1028 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].sockets[ j ].ipv4 = *(uint const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL);
1029 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].sockets[ j ].port = *(ushort const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL+4UL);
1030 0 : }
1031 :
1032 0 : gui->gossip.peer_cnt = fd_ulong_min( gui->gossip.peer_cnt+1UL, FD_GUI_MAX_PEER_CNT-1UL );
1033 0 : } else {
1034 0 : int peer_updated = gui->gossip.peers[ found_idx ].shred_version!=*(ushort const *)(data+i*(58UL+12UL*6UL)+40UL) ||
1035 : // gui->gossip.peers[ found_idx ].wallclock!=*(ulong const *)(data+i*(58UL+12UL*6UL)+32UL) ||
1036 0 : gui->gossip.peers[ found_idx ].has_version!=*(data+i*(58UL+12UL*6UL)+42UL);
1037 :
1038 0 : if( FD_LIKELY( !peer_updated && gui->gossip.peers[ found_idx ].has_version ) ) {
1039 0 : peer_updated = gui->gossip.peers[ found_idx ].version.major!=*(ushort const *)(data+i*(58UL+12UL*6UL)+43UL) ||
1040 0 : gui->gossip.peers[ found_idx ].version.minor!=*(ushort const *)(data+i*(58UL+12UL*6UL)+45UL) ||
1041 0 : gui->gossip.peers[ found_idx ].version.patch!=*(ushort const *)(data+i*(58UL+12UL*6UL)+47UL) ||
1042 0 : gui->gossip.peers[ found_idx ].version.has_commit!=*(data+i*(58UL+12UL*6UL)+49UL) ||
1043 0 : (gui->gossip.peers[ found_idx ].version.has_commit && gui->gossip.peers[ found_idx ].version.commit!=*(uint const *)(data+i*(58UL+12UL*6UL)+50UL)) ||
1044 0 : gui->gossip.peers[ found_idx ].version.feature_set!=*(uint const *)(data+i*(58UL+12UL*6UL)+54UL);
1045 0 : }
1046 :
1047 0 : if( FD_LIKELY( !peer_updated ) ) {
1048 0 : for( ulong j=0UL; j<12UL; j++ ) {
1049 0 : peer_updated = gui->gossip.peers[ found_idx ].sockets[ j ].ipv4!=*(uint const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL) ||
1050 0 : gui->gossip.peers[ found_idx ].sockets[ j ].port!=*(ushort const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL+4UL);
1051 0 : if( FD_LIKELY( peer_updated ) ) break;
1052 0 : }
1053 0 : }
1054 :
1055 0 : if( FD_UNLIKELY( peer_updated ) ) {
1056 0 : updated[ update_cnt++ ] = found_idx;
1057 0 : gui->gossip.peers[ found_idx ].shred_version = *(ushort const *)(data+i*(58UL+12UL*6UL)+40UL);
1058 0 : gui->gossip.peers[ found_idx ].wallclock = *(ulong const *)(data+i*(58UL+12UL*6UL)+32UL);
1059 0 : gui->gossip.peers[ found_idx ].has_version = *(data+i*(58UL+12UL*6UL)+42UL);
1060 0 : if( FD_LIKELY( gui->gossip.peers[ found_idx ].has_version ) ) {
1061 0 : gui->gossip.peers[ found_idx ].version.major = *(ushort const *)(data+i*(58UL+12UL*6UL)+43UL);
1062 0 : gui->gossip.peers[ found_idx ].version.minor = *(ushort const *)(data+i*(58UL+12UL*6UL)+45UL);
1063 0 : gui->gossip.peers[ found_idx ].version.patch = *(ushort const *)(data+i*(58UL+12UL*6UL)+47UL);
1064 0 : gui->gossip.peers[ found_idx ].version.has_commit = *(data+i*(58UL+12UL*6UL)+49UL);
1065 0 : if( FD_LIKELY( gui->gossip.peers[ found_idx ].version.has_commit ) ) {
1066 0 : gui->gossip.peers[ found_idx ].version.commit = *(uint const *)(data+i*(58UL+12UL*6UL)+50UL);
1067 0 : }
1068 0 : gui->gossip.peers[ found_idx ].version.feature_set = *(uint const *)(data+i*(58UL+12UL*6UL)+54UL);
1069 0 : }
1070 :
1071 0 : for( ulong j=0UL; j<12UL; j++ ) {
1072 0 : gui->gossip.peers[ found_idx ].sockets[ j ].ipv4 = *(uint const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL);
1073 0 : gui->gossip.peers[ found_idx ].sockets[ j ].port = *(ushort const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL+4UL);
1074 0 : }
1075 0 : }
1076 0 : }
1077 0 : }
1078 :
1079 0 : added_cnt = gui->gossip.peer_cnt - before_peer_cnt;
1080 0 : for( ulong i=before_peer_cnt; i<gui->gossip.peer_cnt; i++ ) added[ i-before_peer_cnt ] = i;
1081 :
1082 0 : fd_gui_printf_peers_gossip_update( gui, updated, update_cnt, removed, removed_cnt, added, added_cnt );
1083 0 : fd_http_server_ws_broadcast( gui->http );
1084 0 : }
1085 :
1086 : static void
1087 : fd_gui_handle_vote_account_update( fd_gui_t * gui,
1088 0 : uchar const * msg ) {
1089 0 : if( FD_UNLIKELY( gui->vote_account.vote_account_cnt==FD_GUI_MAX_PEER_CNT ) ) {
1090 0 : FD_LOG_DEBUG(("vote account cnt exceeds 40200 %lu, ignoring additional entries", gui->vote_account.vote_account_cnt ));
1091 0 : return;
1092 0 : }
1093 0 : ulong const * header = (ulong const *)fd_type_pun_const( msg );
1094 0 : ulong peer_cnt = header[ 0 ];
1095 :
1096 0 : FD_TEST( peer_cnt<=FD_GUI_MAX_PEER_CNT );
1097 :
1098 0 : ulong added_cnt = 0UL;
1099 0 : ulong added[ FD_GUI_MAX_PEER_CNT ] = {0};
1100 :
1101 0 : ulong update_cnt = 0UL;
1102 0 : ulong updated[ FD_GUI_MAX_PEER_CNT ] = {0};
1103 :
1104 0 : ulong removed_cnt = 0UL;
1105 0 : fd_pubkey_t removed[ FD_GUI_MAX_PEER_CNT ] = {0};
1106 :
1107 0 : uchar const * data = (uchar const *)(header+1UL);
1108 0 : for( ulong i=0UL; i<gui->vote_account.vote_account_cnt; i++ ) {
1109 0 : int found = 0;
1110 0 : for( ulong j=0UL; j<peer_cnt; j++ ) {
1111 0 : if( FD_UNLIKELY( !memcmp( gui->vote_account.vote_accounts[ i ].vote_account, data+j*112UL, 32UL ) ) ) {
1112 0 : found = 1;
1113 0 : break;
1114 0 : }
1115 0 : }
1116 :
1117 0 : if( FD_UNLIKELY( !found ) ) {
1118 0 : fd_memcpy( removed[ removed_cnt++ ].uc, gui->vote_account.vote_accounts[ i ].vote_account->uc, 32UL );
1119 0 : if( FD_LIKELY( i+1UL!=gui->vote_account.vote_account_cnt ) ) {
1120 0 : gui->vote_account.vote_accounts[ i ] = gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt-1UL ];
1121 0 : i--;
1122 0 : }
1123 0 : gui->vote_account.vote_account_cnt--;
1124 0 : }
1125 0 : }
1126 :
1127 0 : ulong before_peer_cnt = gui->vote_account.vote_account_cnt;
1128 0 : for( ulong i=0UL; i<peer_cnt; i++ ) {
1129 0 : int found = 0;
1130 0 : ulong found_idx;
1131 0 : for( ulong j=0UL; j<gui->vote_account.vote_account_cnt; j++ ) {
1132 0 : if( FD_UNLIKELY( !memcmp( gui->vote_account.vote_accounts[ j ].vote_account, data+i*112UL, 32UL ) ) ) {
1133 0 : found_idx = j;
1134 0 : found = 1;
1135 0 : break;
1136 0 : }
1137 0 : }
1138 :
1139 0 : if( FD_UNLIKELY( !found ) ) {
1140 0 : fd_memcpy( gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].vote_account->uc, data+i*112UL, 32UL );
1141 0 : fd_memcpy( gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].pubkey->uc, data+i*112UL+32UL, 32UL );
1142 :
1143 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].activated_stake = *(ulong const *)(data+i*112UL+64UL);
1144 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].last_vote = *(ulong const *)(data+i*112UL+72UL);
1145 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].root_slot = *(ulong const *)(data+i*112UL+80UL);
1146 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].epoch_credits = *(ulong const *)(data+i*112UL+88UL);
1147 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].commission = *(data+i*112UL+96UL);
1148 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].delinquent = *(data+i*112UL+97UL);
1149 :
1150 0 : gui->vote_account.vote_account_cnt = fd_ulong_min( gui->vote_account.vote_account_cnt+1UL, FD_GUI_MAX_PEER_CNT-1UL );
1151 0 : } else {
1152 0 : int peer_updated =
1153 0 : memcmp( gui->vote_account.vote_accounts[ found_idx ].pubkey->uc, data+i*112UL+32UL, 32UL ) ||
1154 0 : gui->vote_account.vote_accounts[ found_idx ].activated_stake != *(ulong const *)(data+i*112UL+64UL) ||
1155 : // gui->vote_account.vote_accounts[ found_idx ].last_vote != *(ulong const *)(data+i*112UL+72UL) ||
1156 : // gui->vote_account.vote_accounts[ found_idx ].root_slot != *(ulong const *)(data+i*112UL+80UL) ||
1157 : // gui->vote_account.vote_accounts[ found_idx ].epoch_credits != *(ulong const *)(data+i*112UL+88UL) ||
1158 0 : gui->vote_account.vote_accounts[ found_idx ].commission != *(data+i*112UL+96UL) ||
1159 0 : gui->vote_account.vote_accounts[ found_idx ].delinquent != *(data+i*112UL+97UL);
1160 :
1161 0 : if( FD_UNLIKELY( peer_updated ) ) {
1162 0 : updated[ update_cnt++ ] = found_idx;
1163 :
1164 0 : fd_memcpy( gui->vote_account.vote_accounts[ found_idx ].pubkey->uc, data+i*112UL+32UL, 32UL );
1165 0 : gui->vote_account.vote_accounts[ found_idx ].activated_stake = *(ulong const *)(data+i*112UL+64UL);
1166 0 : gui->vote_account.vote_accounts[ found_idx ].last_vote = *(ulong const *)(data+i*112UL+72UL);
1167 0 : gui->vote_account.vote_accounts[ found_idx ].root_slot = *(ulong const *)(data+i*112UL+80UL);
1168 0 : gui->vote_account.vote_accounts[ found_idx ].epoch_credits = *(ulong const *)(data+i*112UL+88UL);
1169 0 : gui->vote_account.vote_accounts[ found_idx ].commission = *(data+i*112UL+96UL);
1170 0 : gui->vote_account.vote_accounts[ found_idx ].delinquent = *(data+i*112UL+97UL);
1171 0 : }
1172 0 : }
1173 0 : }
1174 :
1175 0 : added_cnt = gui->vote_account.vote_account_cnt - before_peer_cnt;
1176 0 : for( ulong i=before_peer_cnt; i<gui->vote_account.vote_account_cnt; i++ ) added[ i-before_peer_cnt ] = i;
1177 :
1178 0 : fd_gui_printf_peers_vote_account_update( gui, updated, update_cnt, removed, removed_cnt, added, added_cnt );
1179 0 : fd_http_server_ws_broadcast( gui->http );
1180 0 : }
1181 :
1182 : static void
1183 : fd_gui_handle_validator_info_update( fd_gui_t * gui,
1184 0 : uchar const * msg ) {
1185 0 : if( FD_UNLIKELY( gui->validator_info.info_cnt == FD_GUI_MAX_PEER_CNT ) ) {
1186 0 : FD_LOG_DEBUG(("validator info cnt exceeds 40200 %lu, ignoring additional entries", gui->validator_info.info_cnt ));
1187 0 : return;
1188 0 : }
1189 0 : uchar const * data = (uchar const *)fd_type_pun_const( msg );
1190 :
1191 0 : ulong added_cnt = 0UL;
1192 0 : ulong added[ 1 ] = {0};
1193 :
1194 0 : ulong update_cnt = 0UL;
1195 0 : ulong updated[ 1 ] = {0};
1196 :
1197 0 : ulong removed_cnt = 0UL;
1198 : /* Unlike gossip or vote account updates, validator info messages come
1199 : in as info is discovered, and may contain as little as 1 validator
1200 : per message. Therefore, it doesn't make sense to use the remove
1201 : mechanism. */
1202 :
1203 0 : ulong before_peer_cnt = gui->validator_info.info_cnt;
1204 0 : int found = 0;
1205 0 : ulong found_idx;
1206 0 : for( ulong j=0UL; j<gui->validator_info.info_cnt; j++ ) {
1207 0 : if( FD_UNLIKELY( !memcmp( gui->validator_info.info[ j ].pubkey, data, 32UL ) ) ) {
1208 0 : found_idx = j;
1209 0 : found = 1;
1210 0 : break;
1211 0 : }
1212 0 : }
1213 :
1214 0 : if( FD_UNLIKELY( !found ) ) {
1215 0 : fd_memcpy( gui->validator_info.info[ gui->validator_info.info_cnt ].pubkey->uc, data, 32UL );
1216 :
1217 0 : strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].name, (char const *)(data+32UL), 64 );
1218 0 : gui->validator_info.info[ gui->validator_info.info_cnt ].name[ 63 ] = '\0';
1219 :
1220 0 : strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].website, (char const *)(data+96UL), 128 );
1221 0 : gui->validator_info.info[ gui->validator_info.info_cnt ].website[ 127 ] = '\0';
1222 :
1223 0 : strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].details, (char const *)(data+224UL), 256 );
1224 0 : gui->validator_info.info[ gui->validator_info.info_cnt ].details[ 255 ] = '\0';
1225 :
1226 0 : strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].icon_uri, (char const *)(data+480UL), 128 );
1227 0 : gui->validator_info.info[ gui->validator_info.info_cnt ].icon_uri[ 127 ] = '\0';
1228 :
1229 0 : gui->validator_info.info_cnt++;
1230 0 : } else {
1231 0 : int peer_updated =
1232 0 : memcmp( gui->validator_info.info[ found_idx ].pubkey->uc, data, 32UL ) ||
1233 0 : strncmp( gui->validator_info.info[ found_idx ].name, (char const *)(data+32UL), 64 ) ||
1234 0 : strncmp( gui->validator_info.info[ found_idx ].website, (char const *)(data+96UL), 128 ) ||
1235 0 : strncmp( gui->validator_info.info[ found_idx ].details, (char const *)(data+224UL), 256 ) ||
1236 0 : strncmp( gui->validator_info.info[ found_idx ].icon_uri, (char const *)(data+480UL), 128 );
1237 :
1238 0 : if( FD_UNLIKELY( peer_updated ) ) {
1239 0 : updated[ update_cnt++ ] = found_idx;
1240 :
1241 0 : fd_memcpy( gui->validator_info.info[ found_idx ].pubkey->uc, data, 32UL );
1242 :
1243 0 : strncpy( gui->validator_info.info[ found_idx ].name, (char const *)(data+32UL), 64 );
1244 0 : gui->validator_info.info[ found_idx ].name[ 63 ] = '\0';
1245 :
1246 0 : strncpy( gui->validator_info.info[ found_idx ].website, (char const *)(data+96UL), 128 );
1247 0 : gui->validator_info.info[ found_idx ].website[ 127 ] = '\0';
1248 :
1249 0 : strncpy( gui->validator_info.info[ found_idx ].details, (char const *)(data+224UL), 256 );
1250 0 : gui->validator_info.info[ found_idx ].details[ 255 ] = '\0';
1251 :
1252 0 : strncpy( gui->validator_info.info[ found_idx ].icon_uri, (char const *)(data+480UL), 128 );
1253 0 : gui->validator_info.info[ found_idx ].icon_uri[ 127 ] = '\0';
1254 0 : }
1255 0 : }
1256 :
1257 0 : added_cnt = gui->validator_info.info_cnt - before_peer_cnt;
1258 0 : for( ulong i=before_peer_cnt; i<gui->validator_info.info_cnt; i++ ) added[ i-before_peer_cnt ] = i;
1259 :
1260 0 : fd_gui_printf_peers_validator_info_update( gui, updated, update_cnt, NULL, removed_cnt, added, added_cnt );
1261 0 : fd_http_server_ws_broadcast( gui->http );
1262 0 : }
1263 :
1264 : int
1265 : fd_gui_request_slot( fd_gui_t * gui,
1266 : ulong ws_conn_id,
1267 : ulong request_id,
1268 0 : cJSON const * params ) {
1269 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1270 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1271 :
1272 0 : ulong _slot = slot_param->valueulong;
1273 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
1274 0 : if( FD_UNLIKELY( !slot ) ) {
1275 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query", request_id );
1276 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1277 0 : return 0;
1278 0 : }
1279 :
1280 0 : fd_gui_printf_slot_request( gui, _slot, request_id );
1281 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1282 0 : return 0;
1283 0 : }
1284 :
1285 : int
1286 : fd_gui_request_slot_transactions( fd_gui_t * gui,
1287 : ulong ws_conn_id,
1288 : ulong request_id,
1289 0 : cJSON const * params ) {
1290 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1291 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1292 :
1293 0 : ulong _slot = slot_param->valueulong;
1294 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
1295 0 : if( FD_UNLIKELY( !slot ) ) {
1296 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query", request_id );
1297 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1298 0 : return 0;
1299 0 : }
1300 :
1301 0 : fd_gui_printf_slot_transactions_request( gui, _slot, request_id );
1302 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1303 0 : return 0;
1304 0 : }
1305 :
1306 : int
1307 : fd_gui_request_slot_detailed( fd_gui_t * gui,
1308 : ulong ws_conn_id,
1309 : ulong request_id,
1310 0 : cJSON const * params ) {
1311 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1312 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1313 :
1314 0 : ulong _slot = slot_param->valueulong;
1315 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
1316 0 : if( FD_UNLIKELY( !slot ) ) {
1317 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query", request_id );
1318 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1319 0 : return 0;
1320 0 : }
1321 :
1322 0 : fd_gui_printf_slot_request_detailed( gui, _slot, request_id );
1323 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1324 0 : return 0;
1325 0 : }
1326 :
1327 : static inline ulong
1328 0 : fd_gui_slot_duration( fd_gui_t const * gui, fd_gui_slot_t const * cur ) {
1329 0 : fd_gui_slot_t const * prev = fd_gui_get_slot_const( gui, cur->slot-1UL );
1330 0 : if( FD_UNLIKELY( !prev ||
1331 0 : prev->skipped ||
1332 0 : prev->completed_time == LONG_MAX ||
1333 0 : prev->slot != (cur->slot - 1UL) ||
1334 0 : cur->skipped ||
1335 0 : cur->completed_time == LONG_MAX ) ) return ULONG_MAX;
1336 :
1337 0 : return (ulong)(cur->completed_time - prev->completed_time);
1338 0 : }
1339 :
1340 : /* All rankings are initialized / reset to ULONG_MAX. These sentinels
1341 : sort AFTER non-sentinel ranking entries. Equal slots are sorted by
1342 : oldest slot AFTER. Otherwise sort by value according to ranking
1343 : type. */
1344 : #define SORT_NAME fd_gui_slot_ranking_sort
1345 0 : #define SORT_KEY_T fd_gui_slot_ranking_t
1346 0 : #define SORT_BEFORE(a,b) fd_int_if( (a).slot==ULONG_MAX, 0, fd_int_if( (b).slot==ULONG_MAX, 1, fd_int_if( (a).value==(b).value, (a).slot>(b).slot, fd_int_if( (a).type==FD_GUI_SLOT_RANKING_TYPE_DESC, (a).value>(b).value, (a).value<(b).value ) ) ) )
1347 : #include "../../util/tmpl/fd_sort.c"
1348 :
1349 : static inline void
1350 : fd_gui_try_insert_ranking( fd_gui_t * gui,
1351 : fd_gui_slot_rankings_t * rankings,
1352 0 : fd_gui_slot_t const * slot ) {
1353 : /* Rankings are inserted into an extra slot at the end of the ranking
1354 : array, then the array is sorted. */
1355 0 : #define TRY_INSERT_SLOT( ranking_name, ranking_slot, ranking_value ) \
1356 0 : do { \
1357 0 : rankings->FD_CONCAT2(largest_, ranking_name) [ FD_GUI_SLOT_RANKINGS_SZ ] = (fd_gui_slot_ranking_t){ .slot = (ranking_slot), .value = (ranking_value), .type = FD_GUI_SLOT_RANKING_TYPE_DESC }; \
1358 0 : fd_gui_slot_ranking_sort_insert( rankings->FD_CONCAT2(largest_, ranking_name), FD_GUI_SLOT_RANKINGS_SZ+1UL ); \
1359 0 : rankings->FD_CONCAT2(smallest_, ranking_name)[ FD_GUI_SLOT_RANKINGS_SZ ] = (fd_gui_slot_ranking_t){ .slot = (ranking_slot), .value = (ranking_value), .type = FD_GUI_SLOT_RANKING_TYPE_ASC }; \
1360 0 : fd_gui_slot_ranking_sort_insert( rankings->FD_CONCAT2(smallest_, ranking_name), FD_GUI_SLOT_RANKINGS_SZ+1UL ); \
1361 0 : } while (0)
1362 :
1363 0 : if( slot->skipped ) {
1364 0 : TRY_INSERT_SLOT( skipped, slot->slot, slot->slot );
1365 0 : return;
1366 0 : }
1367 :
1368 0 : ulong dur = fd_gui_slot_duration( gui, slot );
1369 0 : if( FD_LIKELY( dur!=ULONG_MAX ) ) TRY_INSERT_SLOT( duration, slot->slot, dur );
1370 0 : TRY_INSERT_SLOT( tips, slot->slot, slot->tips );
1371 0 : TRY_INSERT_SLOT( fees, slot->slot, slot->priority_fee + slot->transaction_fee );
1372 0 : TRY_INSERT_SLOT( rewards, slot->slot, slot->tips + slot->priority_fee + slot->transaction_fee );
1373 0 : TRY_INSERT_SLOT( rewards_per_cu, slot->slot, slot->compute_units==0UL ? 0UL : (slot->tips + slot->priority_fee + slot->transaction_fee) / slot->compute_units );
1374 0 : TRY_INSERT_SLOT( compute_units, slot->slot, slot->compute_units );
1375 0 : #undef TRY_INSERT_SLOT
1376 0 : }
1377 :
1378 : static void
1379 0 : fd_gui_update_slot_rankings( fd_gui_t * gui ) {
1380 0 : ulong first_replay_slot = ULONG_MAX;
1381 0 : if( FD_LIKELY( gui->summary.is_full_client ) ) {
1382 0 : ulong slot_caught_up = gui->summary.slot_caught_up;
1383 0 : ulong slot_incremental = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].slot;
1384 0 : ulong slot_full = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].slot;
1385 0 : first_replay_slot = fd_ulong_if( slot_caught_up!=ULONG_MAX, fd_ulong_if( slot_incremental!=ULONG_MAX, slot_incremental+1UL, fd_ulong_if( slot_full!=ULONG_MAX, slot_full+1UL, ULONG_MAX ) ), ULONG_MAX );
1386 0 : } else {
1387 0 : first_replay_slot = gui->summary.startup_progress.startup_ledger_max_slot;
1388 0 : }
1389 0 : if( FD_UNLIKELY( first_replay_slot==ULONG_MAX ) ) return;
1390 0 : if( FD_UNLIKELY( gui->summary.slot_rooted ==ULONG_MAX ) ) return;
1391 :
1392 0 : ulong epoch_start_slot = ULONG_MAX;
1393 0 : ulong epoch = ULONG_MAX;
1394 0 : for( ulong i = 0UL; i<2UL; i++ ) {
1395 0 : if( FD_LIKELY( gui->epoch.has_epoch[ i ] ) ) {
1396 : /* the "current" epoch is the smallest */
1397 0 : epoch_start_slot = fd_ulong_min( epoch_start_slot, gui->epoch.epochs[ i ].start_slot );
1398 0 : epoch = fd_ulong_min( epoch, gui->epoch.epochs[ i ].epoch );
1399 0 : }
1400 0 : }
1401 :
1402 0 : if( FD_UNLIKELY( epoch==ULONG_MAX ) ) return;
1403 0 : ulong epoch_idx = epoch % 2UL;
1404 :
1405 : /* No new slots since the last update */
1406 0 : if( FD_UNLIKELY( gui->epoch.epochs[ epoch_idx ].rankings_slot>gui->summary.slot_rooted ) ) return;
1407 :
1408 : /* Slots before first_replay_slot are unavailable. */
1409 0 : gui->epoch.epochs[ epoch_idx ].rankings_slot = fd_ulong_max( gui->epoch.epochs[ epoch_idx ].rankings_slot, first_replay_slot );
1410 :
1411 : /* Update the rankings. Only look through slots we haven't already. */
1412 0 : for( ulong s = gui->summary.slot_rooted; s>=gui->epoch.epochs[ epoch_idx ].rankings_slot; s--) {
1413 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, s );
1414 0 : if( FD_UNLIKELY( !slot ) ) break;
1415 :
1416 0 : fd_gui_try_insert_ranking( gui, gui->epoch.epochs[ epoch_idx ].rankings, slot );
1417 0 : if( FD_UNLIKELY( slot->mine ) ) fd_gui_try_insert_ranking( gui, gui->epoch.epochs[ epoch_idx ].my_rankings, slot );
1418 0 : }
1419 :
1420 0 : gui->epoch.epochs[ epoch_idx ].rankings_slot = gui->summary.slot_rooted + 1UL;
1421 0 : }
1422 :
1423 : int
1424 : fd_gui_request_slot_rankings( fd_gui_t * gui,
1425 : ulong ws_conn_id,
1426 : ulong request_id,
1427 0 : cJSON const * params ) {
1428 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "mine" );
1429 0 : if( FD_UNLIKELY( !cJSON_IsBool( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1430 :
1431 0 : int mine = !!(slot_param->type & cJSON_True);
1432 0 : fd_gui_update_slot_rankings( gui );
1433 0 : fd_gui_printf_slot_rankings_request( gui, request_id, mine );
1434 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1435 0 : return 0;
1436 0 : }
1437 :
1438 : int
1439 : fd_gui_request_slot_shreds( fd_gui_t * gui,
1440 : ulong ws_conn_id,
1441 : ulong request_id,
1442 0 : cJSON const * params ) {
1443 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1444 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1445 :
1446 0 : ulong _slot = slot_param->valueulong;
1447 :
1448 0 : fd_gui_slot_t const * slot = fd_gui_get_slot( gui, _slot );
1449 0 : if( FD_UNLIKELY( !slot || gui->shreds.history_tail > slot->shreds.end_offset + FD_GUI_SHREDS_HISTORY_SZ ) ) {
1450 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query_shreds", request_id );
1451 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1452 0 : return 0;
1453 0 : }
1454 :
1455 0 : fd_gui_printf_slot_shred_updates( gui, _slot, request_id );
1456 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1457 0 : return 0;
1458 0 : }
1459 :
1460 : int
1461 : fd_gui_ws_message( fd_gui_t * gui,
1462 : ulong ws_conn_id,
1463 : uchar const * data,
1464 0 : ulong data_len ) {
1465 : /* TODO: cJSON allocates, might fail SIGSYS due to brk(2)...
1466 : switch off this (or use wksp allocator) */
1467 0 : const char * parse_end;
1468 0 : cJSON * json = cJSON_ParseWithLengthOpts( (char *)data, data_len, &parse_end, 0 );
1469 0 : if( FD_UNLIKELY( !json ) ) {
1470 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1471 0 : }
1472 :
1473 0 : const cJSON * node = cJSON_GetObjectItemCaseSensitive( json, "id" );
1474 0 : if( FD_UNLIKELY( !cJSON_IsNumber( node ) ) ) {
1475 0 : cJSON_Delete( json );
1476 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1477 0 : }
1478 0 : ulong id = node->valueulong;
1479 :
1480 0 : const cJSON * topic = cJSON_GetObjectItemCaseSensitive( json, "topic" );
1481 0 : if( FD_UNLIKELY( !cJSON_IsString( topic ) || topic->valuestring==NULL ) ) {
1482 0 : cJSON_Delete( json );
1483 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1484 0 : }
1485 :
1486 0 : const cJSON * key = cJSON_GetObjectItemCaseSensitive( json, "key" );
1487 0 : if( FD_UNLIKELY( !cJSON_IsString( key ) || key->valuestring==NULL ) ) {
1488 0 : cJSON_Delete( json );
1489 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1490 0 : }
1491 :
1492 0 : if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query" ) ) ) {
1493 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
1494 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
1495 0 : cJSON_Delete( json );
1496 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1497 0 : }
1498 :
1499 0 : int result = fd_gui_request_slot( gui, ws_conn_id, id, params );
1500 0 : cJSON_Delete( json );
1501 0 : return result;
1502 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_detailed" ) ) ) {
1503 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
1504 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
1505 0 : cJSON_Delete( json );
1506 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1507 0 : }
1508 :
1509 0 : int result = fd_gui_request_slot_detailed( gui, ws_conn_id, id, params );
1510 0 : cJSON_Delete( json );
1511 0 : return result;
1512 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_transactions" ) ) ) {
1513 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
1514 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
1515 0 : cJSON_Delete( json );
1516 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1517 0 : }
1518 :
1519 0 : int result = fd_gui_request_slot_transactions( gui, ws_conn_id, id, params );
1520 0 : cJSON_Delete( json );
1521 0 : return result;
1522 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_rankings" ) ) ) {
1523 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
1524 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
1525 0 : cJSON_Delete( json );
1526 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1527 0 : }
1528 :
1529 0 : int result = fd_gui_request_slot_rankings( gui, ws_conn_id, id, params );
1530 0 : cJSON_Delete( json );
1531 0 : return result;
1532 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_shreds" ) ) ) {
1533 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
1534 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
1535 0 : cJSON_Delete( json );
1536 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1537 0 : }
1538 :
1539 0 : int result = fd_gui_request_slot_shreds( gui, ws_conn_id, id, params );
1540 0 : cJSON_Delete( json );
1541 0 : return result;
1542 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "summary" ) && !strcmp( key->valuestring, "ping" ) ) ) {
1543 0 : fd_gui_printf_summary_ping( gui, id );
1544 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1545 :
1546 0 : cJSON_Delete( json );
1547 0 : return 0;
1548 0 : }
1549 :
1550 0 : cJSON_Delete( json );
1551 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_UNKNOWN_METHOD;
1552 0 : }
1553 :
1554 : static fd_gui_slot_t *
1555 : fd_gui_clear_slot( fd_gui_t * gui,
1556 : ulong _slot,
1557 0 : ulong _parent_slot ) {
1558 0 : fd_gui_slot_t * slot = gui->slots[ _slot % FD_GUI_SLOTS_CNT ];
1559 :
1560 0 : int mine = 0;
1561 0 : ulong epoch_idx = 0UL;
1562 0 : for( ulong i=0UL; i<2UL; i++) {
1563 0 : if( FD_UNLIKELY( !gui->epoch.has_epoch[ i ] ) ) continue;
1564 0 : if( FD_LIKELY( _slot>=gui->epoch.epochs[ i ].start_slot && _slot<=gui->epoch.epochs[ i ].end_slot ) ) {
1565 0 : fd_pubkey_t const * slot_leader = fd_epoch_leaders_get( gui->epoch.epochs[ i ].lsched, _slot );
1566 0 : mine = !memcmp( slot_leader->uc, gui->summary.identity_key->uc, 32UL );
1567 0 : epoch_idx = i;
1568 0 : break;
1569 0 : }
1570 0 : }
1571 :
1572 0 : slot->slot = _slot;
1573 0 : slot->parent_slot = _parent_slot;
1574 0 : slot->max_compute_units = UINT_MAX;
1575 0 : slot->completed_time = LONG_MAX;
1576 0 : slot->mine = mine;
1577 0 : slot->skipped = 0;
1578 0 : slot->must_republish = 1;
1579 0 : slot->level = FD_GUI_SLOT_LEVEL_INCOMPLETE;
1580 0 : slot->total_txn_cnt = UINT_MAX;
1581 0 : slot->vote_txn_cnt = UINT_MAX;
1582 0 : slot->failed_txn_cnt = UINT_MAX;
1583 0 : slot->nonvote_failed_txn_cnt = UINT_MAX;
1584 0 : slot->compute_units = UINT_MAX;
1585 0 : slot->transaction_fee = ULONG_MAX;
1586 0 : slot->priority_fee = ULONG_MAX;
1587 0 : slot->tips = ULONG_MAX;
1588 0 : slot->shred_cnt = UINT_MAX;
1589 0 : slot->shreds.start_offset = ULONG_MAX;
1590 0 : slot->shreds.end_offset = ULONG_MAX;
1591 :
1592 0 : if( FD_LIKELY( slot->mine ) ) {
1593 : /* All slots start off not skipped, until we see it get off the reset
1594 : chain. */
1595 0 : gui->epoch.epochs[ epoch_idx ].my_total_slots++;
1596 :
1597 0 : slot->leader_history_idx = gui->leader_slots_cnt++;
1598 0 : fd_gui_leader_slot_t * lslot = gui->leader_slots[ slot->leader_history_idx % FD_GUI_LEADER_CNT ];
1599 :
1600 0 : lslot->slot = _slot;
1601 0 : memset( lslot->block_hash.uc, 0, sizeof(fd_hash_t) );
1602 0 : lslot->leader_start_time = LONG_MAX;
1603 0 : lslot->leader_end_time = LONG_MAX;
1604 0 : lslot->tile_timers_sample_cnt = 0UL;
1605 0 : lslot->scheduler_counts_sample_cnt = 0UL;
1606 0 : lslot->txs.microblocks_upper_bound = USHORT_MAX;
1607 0 : lslot->txs.begin_microblocks = 0U;
1608 0 : lslot->txs.end_microblocks = 0U;
1609 0 : lslot->txs.start_offset = ULONG_MAX;
1610 0 : lslot->txs.end_offset = ULONG_MAX;
1611 0 : }
1612 :
1613 0 : if( FD_UNLIKELY( !_slot ) ) {
1614 : /* Slot 0 is always rooted */
1615 0 : slot->level = FD_GUI_SLOT_LEVEL_ROOTED;
1616 0 : }
1617 :
1618 0 : return slot;
1619 0 : }
1620 :
1621 : void
1622 : fd_gui_handle_leader_schedule( fd_gui_t * gui,
1623 : fd_stake_weight_msg_t const * leader_schedule,
1624 0 : long now ) {
1625 0 : FD_TEST( leader_schedule->staked_cnt<=MAX_STAKED_LEADERS );
1626 0 : FD_TEST( leader_schedule->slot_cnt<=MAX_SLOTS_PER_EPOCH );
1627 :
1628 0 : ulong idx = leader_schedule->epoch % 2UL;
1629 0 : gui->epoch.has_epoch[ idx ] = 1;
1630 :
1631 0 : gui->epoch.epochs[ idx ].epoch = leader_schedule->epoch;
1632 0 : gui->epoch.epochs[ idx ].start_slot = leader_schedule->start_slot;
1633 0 : gui->epoch.epochs[ idx ].end_slot = leader_schedule->start_slot + leader_schedule->slot_cnt - 1; // end_slot is inclusive.
1634 0 : gui->epoch.epochs[ idx ].excluded_stake = leader_schedule->excluded_stake;
1635 0 : gui->epoch.epochs[ idx ].my_total_slots = 0UL;
1636 0 : gui->epoch.epochs[ idx ].my_skipped_slots = 0UL;
1637 :
1638 0 : memset( gui->epoch.epochs[ idx ].rankings, (int)(UINT_MAX), sizeof(gui->epoch.epochs[ idx ].rankings) );
1639 0 : memset( gui->epoch.epochs[ idx ].my_rankings, (int)(UINT_MAX), sizeof(gui->epoch.epochs[ idx ].my_rankings) );
1640 :
1641 0 : gui->epoch.epochs[ idx ].rankings_slot = leader_schedule->start_slot;
1642 :
1643 0 : fd_vote_stake_weight_t const * stake_weights = leader_schedule->weights;
1644 0 : fd_memcpy( gui->epoch.epochs[ idx ].stakes, stake_weights, leader_schedule->staked_cnt*sizeof(fd_vote_stake_weight_t) );
1645 :
1646 0 : fd_epoch_leaders_delete( fd_epoch_leaders_leave( gui->epoch.epochs[ idx ].lsched ) );
1647 0 : gui->epoch.epochs[idx].lsched = fd_epoch_leaders_join( fd_epoch_leaders_new( gui->epoch.epochs[ idx ]._lsched,
1648 0 : leader_schedule->epoch,
1649 0 : gui->epoch.epochs[ idx ].start_slot,
1650 0 : leader_schedule->slot_cnt,
1651 0 : leader_schedule->staked_cnt,
1652 0 : gui->epoch.epochs[ idx ].stakes,
1653 0 : leader_schedule->excluded_stake,
1654 0 : leader_schedule->vote_keyed_lsched ) );
1655 :
1656 0 : if( FD_UNLIKELY( leader_schedule->start_slot==0UL ) ) {
1657 0 : gui->epoch.epochs[ 0 ].start_time = now;
1658 0 : } else {
1659 0 : gui->epoch.epochs[ idx ].start_time = LONG_MAX;
1660 :
1661 0 : for( ulong i=0UL; i<fd_ulong_min( leader_schedule->start_slot-1UL, FD_GUI_SLOTS_CNT ); i++ ) {
1662 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, leader_schedule->start_slot-i );
1663 0 : if( FD_UNLIKELY( !slot ) ) break;
1664 0 : else if( FD_UNLIKELY( slot->skipped ) ) continue;
1665 :
1666 0 : gui->epoch.epochs[ idx ].start_time = slot->completed_time;
1667 0 : break;
1668 0 : }
1669 0 : }
1670 :
1671 0 : fd_gui_printf_epoch( gui, idx );
1672 0 : fd_http_server_ws_broadcast( gui->http );
1673 0 : }
1674 :
1675 : static void
1676 : fd_gui_handle_slot_start( fd_gui_t * gui,
1677 : ulong _slot,
1678 : ulong parent_slot,
1679 0 : long now ) {
1680 0 : FD_TEST( gui->leader_slot==ULONG_MAX );
1681 0 : gui->leader_slot = _slot;
1682 :
1683 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
1684 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, parent_slot );
1685 :
1686 0 : fd_gui_tile_timers_snap( gui );
1687 0 : gui->summary.tile_timers_snap_idx_slot_start = (gui->summary.tile_timers_snap_idx+(FD_GUI_TILE_TIMER_SNAP_CNT-1UL))%FD_GUI_TILE_TIMER_SNAP_CNT;
1688 :
1689 0 : fd_gui_scheduler_counts_snap( gui, now );
1690 0 : gui->summary.scheduler_counts_snap_idx_slot_start = (gui->summary.scheduler_counts_snap_idx+(FD_GUI_SCHEDULER_COUNT_SNAP_CNT-1UL))%FD_GUI_SCHEDULER_COUNT_SNAP_CNT;
1691 :
1692 0 : fd_gui_txn_waterfall_t waterfall[ 1 ];
1693 0 : fd_gui_txn_waterfall_snap( gui, waterfall );
1694 0 : fd_gui_tile_stats_snap( gui, waterfall, slot->tile_stats_begin, now );
1695 0 : }
1696 :
1697 : static void
1698 : fd_gui_handle_slot_end( fd_gui_t * gui,
1699 : ulong _slot,
1700 : ulong _cus_used,
1701 0 : long now ) {
1702 0 : if( FD_UNLIKELY( !gui->summary.is_full_client && gui->leader_slot!=_slot ) ) {
1703 0 : FD_LOG_ERR(( "gui->leader_slot %lu _slot %lu", gui->leader_slot, _slot ));
1704 0 : }
1705 0 : gui->leader_slot = ULONG_MAX;
1706 :
1707 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
1708 0 : if( FD_UNLIKELY( !slot ) ) return;
1709 :
1710 0 : if( FD_UNLIKELY( !gui->summary.is_full_client ) ) slot->compute_units = (uint)_cus_used;
1711 :
1712 0 : fd_gui_tile_timers_snap( gui );
1713 :
1714 0 : fd_gui_scheduler_counts_snap( gui, now );
1715 :
1716 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
1717 0 : if( FD_LIKELY( lslot ) ) {
1718 0 : fd_rng_t rng[ 1 ];
1719 0 : fd_rng_new( rng, 0UL, 0UL);
1720 :
1721 : /* Sampling at radom from the list of samples. By using a random
1722 : sample stride instead of a integral stride, we can downsample
1723 : more evenly over the duration of the entire block. */
1724 0 : ulong sample_count = 0UL;
1725 0 : ulong end = gui->summary.tile_timers_snap_idx;
1726 0 : end = fd_ulong_if( end<gui->summary.tile_timers_snap_idx_slot_start, end+FD_GUI_TILE_TIMER_SNAP_CNT, end );
1727 0 : for( ulong sample_snap_idx=gui->summary.tile_timers_snap_idx_slot_start; sample_snap_idx<end && sample_count<FD_GUI_TILE_TIMER_SNAP_CNT; sample_snap_idx++ ) {
1728 0 : if( FD_UNLIKELY( fd_rng_float_robust( rng ) > (float)(FD_GUI_TILE_TIMER_SNAP_CNT-sample_count) / (float)(end-gui->summary.tile_timers_snap_idx_slot_start-sample_count) ) ) continue;
1729 :
1730 0 : fd_memcpy( lslot->tile_timers[ sample_count ], gui->summary.tile_timers_snap[ sample_snap_idx%FD_GUI_TILE_TIMER_SNAP_CNT ], sizeof(lslot->tile_timers[ sample_count ]) );
1731 0 : sample_count++;
1732 0 : }
1733 0 : lslot->tile_timers_sample_cnt = sample_count;
1734 :
1735 0 : sample_count = 0UL;
1736 0 : end = gui->summary.scheduler_counts_snap_idx;
1737 0 : end = fd_ulong_if( end<gui->summary.scheduler_counts_snap_idx_slot_start, end+FD_GUI_SCHEDULER_COUNT_SNAP_CNT, end );
1738 0 : for( ulong sample_snap_idx=gui->summary.scheduler_counts_snap_idx_slot_start; sample_snap_idx<end && sample_count<FD_GUI_SCHEDULER_COUNT_SNAP_CNT; sample_snap_idx++ ) {
1739 0 : if( FD_UNLIKELY( fd_rng_float_robust( rng ) > (float)(FD_GUI_SCHEDULER_COUNT_SNAP_CNT-sample_count) / (float)(end-gui->summary.scheduler_counts_snap_idx_slot_start-sample_count) ) ) continue;
1740 :
1741 0 : fd_memcpy( lslot->scheduler_counts[ sample_count ], gui->summary.scheduler_counts_snap[ sample_snap_idx%FD_GUI_SCHEDULER_COUNT_SNAP_CNT ], sizeof(lslot->scheduler_counts[ sample_count ]) );
1742 0 : sample_count++;
1743 0 : }
1744 0 : lslot->scheduler_counts_sample_cnt = sample_count;
1745 0 : }
1746 :
1747 : /* When a slot ends, snap the state of the waterfall and save it into
1748 : that slot, and also reset the reference counters to the end of the
1749 : slot. */
1750 :
1751 0 : fd_gui_txn_waterfall_snap( gui, slot->waterfall_end );
1752 0 : memcpy( slot->waterfall_begin, gui->summary.txn_waterfall_reference, sizeof(slot->waterfall_begin) );
1753 0 : memcpy( gui->summary.txn_waterfall_reference, slot->waterfall_end, sizeof(gui->summary.txn_waterfall_reference) );
1754 :
1755 0 : fd_gui_tile_stats_snap( gui, slot->waterfall_end, slot->tile_stats_end, now );
1756 0 : }
1757 :
1758 : #define SORT_NAME fd_gui_ephemeral_slot_sort
1759 0 : #define SORT_KEY_T fd_gui_ephemeral_slot_t
1760 0 : #define SORT_BEFORE(a,b) fd_int_if( (a).slot==ULONG_MAX, 0, fd_int_if( (b).slot==ULONG_MAX, 1, fd_int_if( (a).slot==(b).slot, (a).timestamp_arrival_nanos>(b).timestamp_arrival_nanos, (a).slot>(b).slot ) ) )
1761 : #include "../../util/tmpl/fd_sort.c"
1762 :
1763 : static inline void
1764 0 : fd_gui_try_insert_ephemeral_slot( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot, long now ) {
1765 0 : int already_present = 0;
1766 0 : for( ulong i=0UL; i<slots_sz; i++ ) {
1767 : /* evict any slots older than 4.8 seconds */
1768 0 : if( FD_UNLIKELY( slots[ i ].slot!=ULONG_MAX && now-slots[ i ].timestamp_arrival_nanos>4800000000L ) ) {
1769 0 : slots[ i ].slot = ULONG_MAX;
1770 0 : continue;
1771 0 : }
1772 :
1773 : /* if we've already seen this slot, just update the timestamp */
1774 0 : if( FD_UNLIKELY( slots[ i ].slot==slot ) ) {
1775 0 : slots[ i ].timestamp_arrival_nanos = now;
1776 0 : already_present = 1;
1777 0 : }
1778 0 : }
1779 0 : if( FD_LIKELY( already_present ) ) return;
1780 :
1781 : /* Insert the new slot number, evicting a smaller slot if necessary */
1782 0 : slots[ slots_sz ].timestamp_arrival_nanos = now;
1783 0 : slots[ slots_sz ].slot = slot;
1784 0 : fd_gui_ephemeral_slot_sort_insert( slots, slots_sz+1UL );
1785 0 : }
1786 :
1787 : static inline void
1788 0 : fd_gui_try_insert_catch_up_slot( ulong * slots, ulong * slots_sz, ulong slot ) {
1789 : /* catch up history is run-length encoded */
1790 0 : int inserted = 0;
1791 0 : for( ulong i=0UL; i<*slots_sz; i++ ) {
1792 0 : if( FD_UNLIKELY( i%2UL==1UL && slots[ i ]==slot-1UL ) ) {
1793 0 : slots[ i ]++;
1794 0 : inserted = 1;
1795 0 : break;
1796 0 : } else if( FD_UNLIKELY( i%2UL==0UL && slots[ i ]==slot+1UL ) ) {
1797 0 : slots[ i ]--;
1798 0 : inserted = 1;
1799 0 : break;
1800 0 : }
1801 0 : }
1802 0 : if( FD_LIKELY( !inserted ) ) {
1803 0 : slots[ (*slots_sz)++ ] = slot;
1804 0 : slots[ (*slots_sz)++ ] = slot;
1805 0 : }
1806 :
1807 : /* colesce intervals that touch */
1808 0 : ulong removed = 0UL;
1809 0 : for( ulong i=1UL; i<(*slots_sz)-1UL; i+=2 ) {
1810 0 : if( FD_UNLIKELY( slots[ i ]==slots[ i+1UL ] ) ) {
1811 0 : slots[ i ] = ULONG_MAX;
1812 0 : slots[ i+1UL ] = ULONG_MAX;
1813 0 : removed += 2;
1814 0 : }
1815 0 : }
1816 :
1817 0 : fd_sort_up_ulong_insert( slots, (*slots_sz) );
1818 0 : (*slots_sz) -= removed;
1819 0 : }
1820 :
1821 : static inline int
1822 0 : fd_gui_ephemeral_slots_contains( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot ) {
1823 0 : for( ulong i=0UL; i<slots_sz; i++ ) {
1824 0 : if( FD_UNLIKELY( slots[ i ].slot==ULONG_MAX ) ) break;
1825 0 : if( FD_UNLIKELY( slots[ i ].slot==slot ) ) return 1;
1826 0 : }
1827 0 : return 0;
1828 0 : }
1829 :
1830 : void
1831 : fd_gui_handle_shred( fd_gui_t * gui,
1832 : ulong slot,
1833 : ulong shred_idx,
1834 : int is_turbine,
1835 0 : long tsorig ) {
1836 0 : int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot );
1837 0 : if( FD_LIKELY( is_turbine ) ) fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot, tsorig );
1838 :
1839 0 : if( FD_UNLIKELY( !was_sent && is_turbine && slot!=gui->summary.slot_turbine ) ) {
1840 0 : gui->summary.slot_turbine = slot;
1841 :
1842 0 : fd_gui_printf_turbine_slot( gui );
1843 0 : fd_http_server_ws_broadcast( gui->http );
1844 :
1845 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) fd_gui_try_insert_catch_up_slot( gui->summary.catch_up_turbine, &gui->summary.catch_up_turbine_sz, slot );
1846 0 : }
1847 :
1848 0 : fd_gui_slot_staged_shred_event_t * recv_event = &gui->shreds.staged[ gui->shreds.staged_tail % FD_GUI_SHREDS_STAGING_SZ ];
1849 0 : gui->shreds.staged_tail++;
1850 0 : recv_event->timestamp = tsorig;
1851 0 : recv_event->shred_idx = (ushort)shred_idx;
1852 0 : recv_event->slot = slot;
1853 0 : recv_event->event = fd_uchar_if( is_turbine, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_TURBINE, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_REPAIR );
1854 0 : }
1855 :
1856 : void
1857 : fd_gui_handle_exec_txn_done( fd_gui_t * gui,
1858 : ulong slot,
1859 : ulong start_shred_idx,
1860 : ulong end_shred_idx,
1861 : long tsorig_ns FD_PARAM_UNUSED,
1862 0 : long tspub_ns ) {
1863 0 : for( ulong i = start_shred_idx; i<end_shred_idx; i++ ) {
1864 : /*
1865 : We're leaving this state transition out due to its proximity to
1866 : FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE, but if we ever wanted
1867 : to send this data to the frontend we could.
1868 :
1869 : fd_gui_slot_staged_shred_event_t * exec_start_event = &gui->shreds.staged[ gui->shreds.staged_tail % FD_GUI_SHREDS_STAGING_SZ ];
1870 : gui->shreds.staged_tail++;
1871 : exec_start_event->timestamp = tsorig_ns;
1872 : exec_start_event->shred_idx = (ushort)i;
1873 : exec_start_event->slot = slot;
1874 : exec_start_event->event = FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_START;
1875 : */
1876 :
1877 0 : fd_gui_slot_staged_shred_event_t * exec_end_event = &gui->shreds.staged[ gui->shreds.staged_tail % FD_GUI_SHREDS_STAGING_SZ ];
1878 0 : gui->shreds.staged_tail++;
1879 0 : exec_end_event->timestamp = tspub_ns;
1880 0 : exec_end_event->shred_idx = (ushort)i;
1881 0 : exec_end_event->slot = slot;
1882 0 : exec_end_event->event = FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE;
1883 0 : }
1884 0 : }
1885 :
1886 : void
1887 0 : fd_gui_handle_repair_slot( fd_gui_t * gui, ulong slot, long now ) {
1888 0 : int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot );
1889 0 : fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot, now );
1890 :
1891 0 : if( FD_UNLIKELY( !was_sent && slot!=gui->summary.slot_repair ) ) {
1892 0 : gui->summary.slot_repair = slot;
1893 :
1894 0 : fd_gui_printf_repair_slot( gui );
1895 0 : fd_http_server_ws_broadcast( gui->http );
1896 :
1897 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) fd_gui_try_insert_catch_up_slot( gui->summary.catch_up_repair, &gui->summary.catch_up_repair_sz, slot );
1898 0 : }
1899 0 : }
1900 :
1901 : static void
1902 : fd_gui_handle_reset_slot_legacy( fd_gui_t * gui,
1903 : ulong * msg,
1904 0 : long now ) {
1905 0 : ulong last_landed_vote = msg[ 0 ];
1906 :
1907 0 : ulong parent_cnt = msg[ 1 ];
1908 0 : FD_TEST( parent_cnt<4096UL );
1909 :
1910 0 : ulong _slot = msg[ 2 ];
1911 :
1912 0 : for( ulong i=0UL; i<parent_cnt; i++ ) {
1913 0 : ulong parent_slot = msg[2UL+i];
1914 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
1915 0 : if( FD_UNLIKELY( !slot ) ) {
1916 0 : ulong parent_parent_slot = ULONG_MAX;
1917 0 : if( FD_UNLIKELY( i!=parent_cnt-1UL) ) parent_parent_slot = msg[ 3UL+i ];
1918 0 : fd_gui_clear_slot( gui, parent_slot, parent_parent_slot );
1919 0 : }
1920 0 : }
1921 :
1922 0 : if( FD_UNLIKELY( gui->summary.vote_distance!=_slot-last_landed_vote ) ) {
1923 0 : gui->summary.vote_distance = _slot-last_landed_vote;
1924 0 : fd_gui_printf_vote_distance( gui );
1925 0 : fd_http_server_ws_broadcast( gui->http );
1926 0 : }
1927 :
1928 0 : if( FD_LIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_NON_VOTING ) ) {
1929 0 : if( FD_UNLIKELY( last_landed_vote==ULONG_MAX || (last_landed_vote+150UL)<_slot ) ) {
1930 0 : if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_DELINQUENT ) ) {
1931 0 : gui->summary.vote_state = FD_GUI_VOTE_STATE_DELINQUENT;
1932 0 : fd_gui_printf_vote_state( gui );
1933 0 : fd_http_server_ws_broadcast( gui->http );
1934 0 : }
1935 0 : } else {
1936 0 : if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_VOTING ) ) {
1937 0 : gui->summary.vote_state = FD_GUI_VOTE_STATE_VOTING;
1938 0 : fd_gui_printf_vote_state( gui );
1939 0 : fd_http_server_ws_broadcast( gui->http );
1940 0 : }
1941 0 : }
1942 0 : }
1943 :
1944 0 : ulong parent_slot_idx = 0UL;
1945 :
1946 0 : int republish_skip_rate[ 2 ] = {0};
1947 :
1948 0 : for( ulong i=0UL; i<fd_ulong_min( _slot+1, FD_GUI_SLOTS_CNT ); i++ ) {
1949 0 : ulong parent_slot = _slot - i;
1950 :
1951 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
1952 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, parent_slot, ULONG_MAX );
1953 :
1954 : /* The chain of parents may stretch into already rooted slots if
1955 : they haven't been squashed yet, if we reach one of them we can
1956 : just exit, all the information prior to the root is already
1957 : correct. */
1958 :
1959 0 : if( FD_LIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
1960 :
1961 0 : int should_republish = slot->must_republish;
1962 0 : slot->must_republish = 0;
1963 :
1964 0 : if( FD_UNLIKELY( parent_slot!=msg[2UL+parent_slot_idx] ) ) {
1965 : /* We are between two parents in the rooted chain, which means
1966 : we were skipped. */
1967 0 : if( FD_UNLIKELY( !slot->skipped ) ) {
1968 0 : slot->skipped = 1;
1969 0 : should_republish = 1;
1970 0 : if( FD_LIKELY( slot->mine ) ) {
1971 0 : for( ulong i=0UL; i<2UL; i++ ) {
1972 0 : if( FD_LIKELY( parent_slot>=gui->epoch.epochs[ i ].start_slot && parent_slot<=gui->epoch.epochs[ i ].end_slot ) ) {
1973 0 : gui->epoch.epochs[ i ].my_skipped_slots++;
1974 0 : republish_skip_rate[ i ] = 1;
1975 0 : break;
1976 0 : }
1977 0 : }
1978 0 : }
1979 0 : }
1980 0 : } else {
1981 : /* Reached the next parent... */
1982 0 : if( FD_UNLIKELY( slot->skipped ) ) {
1983 0 : slot->skipped = 0;
1984 0 : should_republish = 1;
1985 0 : if( FD_LIKELY( slot->mine ) ) {
1986 0 : for( ulong i=0UL; i<2UL; i++ ) {
1987 0 : if( FD_LIKELY( parent_slot>=gui->epoch.epochs[ i ].start_slot && parent_slot<=gui->epoch.epochs[ i ].end_slot ) ) {
1988 0 : gui->epoch.epochs[ i ].my_skipped_slots--;
1989 0 : republish_skip_rate[ i ] = 1;
1990 0 : break;
1991 0 : }
1992 0 : }
1993 0 : }
1994 0 : }
1995 0 : parent_slot_idx++;
1996 0 : }
1997 :
1998 0 : if( FD_LIKELY( should_republish ) ) {
1999 0 : fd_gui_printf_slot( gui, parent_slot );
2000 0 : fd_http_server_ws_broadcast( gui->http );
2001 0 : }
2002 :
2003 : /* We reached the last parent in the chain, everything above this
2004 : must have already been rooted, so we can exit. */
2005 :
2006 0 : if( FD_UNLIKELY( parent_slot_idx>=parent_cnt ) ) break;
2007 0 : }
2008 :
2009 0 : ulong duration_sum = 0UL;
2010 0 : ulong slot_cnt = 0UL;
2011 :
2012 : /* If we've just caught up we should truncate our slot history to avoid including catch-up slots */
2013 0 : int just_caught_up = gui->summary.slot_caught_up!=ULONG_MAX && _slot>gui->summary.slot_caught_up && _slot<gui->summary.slot_caught_up+750UL;
2014 0 : ulong slot_duration_history_sz = fd_ulong_if( just_caught_up, _slot-gui->summary.slot_caught_up, 750UL );
2015 0 : for( ulong i=0UL; i<fd_ulong_min( _slot+1, slot_duration_history_sz ); i++ ) {
2016 0 : ulong parent_slot = _slot - i;
2017 :
2018 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, parent_slot );
2019 0 : if( FD_UNLIKELY( !slot) ) break;
2020 0 : if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
2021 0 : FD_LOG_ERR(( "_slot %lu i %lu we expect _slot-i %lu got slot->slot %lu", _slot, i, _slot-i, slot->slot ));
2022 0 : }
2023 :
2024 0 : ulong slot_duration = fd_gui_slot_duration( gui, slot );
2025 0 : if( FD_LIKELY( slot_duration!=ULONG_MAX ) ) {
2026 0 : duration_sum += slot_duration;
2027 0 : slot_cnt++;
2028 0 : }
2029 0 : }
2030 :
2031 0 : if( FD_LIKELY( slot_cnt>0 )) {
2032 0 : gui->summary.estimated_slot_duration_nanos = (ulong)(duration_sum / slot_cnt);
2033 0 : fd_gui_printf_estimated_slot_duration_nanos( gui );
2034 0 : fd_http_server_ws_broadcast( gui->http );
2035 0 : }
2036 :
2037 0 : if( FD_LIKELY( gui->summary.slot_completed==ULONG_MAX || _slot!=gui->summary.slot_completed ) ) {
2038 0 : gui->summary.slot_completed = _slot;
2039 0 : fd_gui_printf_completed_slot( gui );
2040 0 : fd_http_server_ws_broadcast( gui->http );
2041 :
2042 : /* Also update slot_turbine which could be larger than the max
2043 : turbine slot if we are leader */
2044 0 : if( FD_UNLIKELY( gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && gui->summary.slot_completed!=ULONG_MAX && gui->summary.slot_completed>gui->summary.slots_max_turbine[ 0 ].slot ) ) {
2045 0 : fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, gui->summary.slot_completed, now );
2046 0 : }
2047 :
2048 0 : int slot_turbine_hist_full = gui->summary.slots_max_turbine[ FD_GUI_TURBINE_SLOT_HISTORY_SZ-1UL ].slot!=ULONG_MAX;
2049 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX && slot_turbine_hist_full && gui->summary.slots_max_turbine[ 0 ].slot < (gui->summary.slot_completed + 3UL) ) ) {
2050 0 : gui->summary.slot_caught_up = gui->summary.slot_completed + 4UL;
2051 :
2052 0 : fd_gui_printf_slot_caught_up( gui );
2053 0 : fd_http_server_ws_broadcast( gui->http );
2054 0 : }
2055 0 : }
2056 :
2057 0 : for( ulong i=0UL; i<2UL; i++ ) {
2058 0 : if( FD_LIKELY( republish_skip_rate[ i ] ) ) {
2059 0 : fd_gui_printf_skip_rate( gui, i );
2060 0 : fd_http_server_ws_broadcast( gui->http );
2061 0 : }
2062 0 : }
2063 0 : }
2064 :
2065 : static void
2066 : fd_gui_handle_completed_slot( fd_gui_t * gui,
2067 : ulong * msg,
2068 0 : long now ) {
2069 0 : ulong _slot = msg[ 0 ];
2070 0 : uint total_txn_count = (uint)msg[ 1 ];
2071 0 : uint nonvote_txn_count = (uint)msg[ 2 ];
2072 0 : uint failed_txn_count = (uint)msg[ 3 ];
2073 0 : uint nonvote_failed_txn_count = (uint)msg[ 4 ];
2074 0 : uint compute_units = (uint)msg[ 5 ];
2075 0 : ulong transaction_fee = msg[ 6 ];
2076 0 : ulong priority_fee = msg[ 7 ];
2077 0 : ulong tips = msg[ 8 ];
2078 0 : ulong _parent_slot = msg[ 9 ];
2079 0 : ulong max_compute_units = msg[ 10 ];
2080 :
2081 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2082 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, _parent_slot );
2083 :
2084 0 : slot->completed_time = now;
2085 0 : slot->parent_slot = _parent_slot;
2086 0 : slot->max_compute_units = (uint)max_compute_units;
2087 0 : if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_COMPLETED ) ) {
2088 : /* Typically a slot goes from INCOMPLETE to COMPLETED but it can
2089 : happen that it starts higher. One such case is when we
2090 : optimistically confirm a higher slot that skips this one, but
2091 : then later we replay this one anyway to track the bank fork. */
2092 :
2093 0 : if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && _slot<gui->summary.slot_optimistically_confirmed ) ) {
2094 : /* Cluster might have already optimistically confirmed by the time
2095 : we finish replaying it. */
2096 0 : slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
2097 0 : } else {
2098 0 : slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
2099 0 : }
2100 0 : }
2101 0 : slot->total_txn_cnt = total_txn_count;
2102 0 : slot->vote_txn_cnt = total_txn_count - nonvote_txn_count;
2103 0 : slot->failed_txn_cnt = failed_txn_count;
2104 0 : slot->nonvote_failed_txn_cnt = nonvote_failed_txn_count;
2105 0 : slot->transaction_fee = transaction_fee;
2106 0 : slot->priority_fee = priority_fee;
2107 0 : slot->tips = tips;
2108 :
2109 : /* In Frankendancer, CUs come from our own leader pipeline (the field
2110 : sent from the Agave codepath is zero'd out) */
2111 0 : slot->compute_units = fd_uint_if( !gui->summary.is_full_client && slot->mine, slot->compute_units, compute_units );
2112 :
2113 0 : if( FD_UNLIKELY( gui->epoch.has_epoch[ 0 ] && _slot==gui->epoch.epochs[ 0 ].end_slot ) ) {
2114 0 : gui->epoch.epochs[ 0 ].end_time = slot->completed_time;
2115 0 : } else if( FD_UNLIKELY( gui->epoch.has_epoch[ 1 ] && _slot==gui->epoch.epochs[ 1 ].end_slot ) ) {
2116 0 : gui->epoch.epochs[ 1 ].end_time = slot->completed_time;
2117 0 : }
2118 :
2119 : /* Broadcast new skip rate if one of our slots got completed. */
2120 0 : if( FD_LIKELY( slot->mine ) ) {
2121 0 : for( ulong i=0UL; i<2UL; i++ ) {
2122 0 : if( FD_LIKELY( _slot>=gui->epoch.epochs[ i ].start_slot && _slot<=gui->epoch.epochs[ i ].end_slot ) ) {
2123 0 : fd_gui_printf_skip_rate( gui, i );
2124 0 : fd_http_server_ws_broadcast( gui->http );
2125 0 : break;
2126 0 : }
2127 0 : }
2128 0 : }
2129 0 : }
2130 :
2131 : static void
2132 : fd_gui_handle_rooted_slot_legacy( fd_gui_t * gui,
2133 0 : ulong * msg ) {
2134 0 : ulong _slot = msg[ 0 ];
2135 :
2136 : // FD_LOG_WARNING(( "Got rooted slot %lu", _slot ));
2137 :
2138 : /* Slot 0 is always rooted. No need to iterate all the way back to
2139 : i==_slot */
2140 0 : for( ulong i=0UL; i<fd_ulong_min( _slot, FD_GUI_SLOTS_CNT ); i++ ) {
2141 0 : ulong parent_slot = _slot - i;
2142 :
2143 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
2144 0 : if( FD_UNLIKELY( !slot ) ) break;
2145 :
2146 0 : if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
2147 0 : FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", _slot, i, parent_slot, slot->slot ));
2148 0 : }
2149 0 : if( FD_UNLIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
2150 :
2151 0 : slot->level = FD_GUI_SLOT_LEVEL_ROOTED;
2152 0 : fd_gui_printf_slot( gui, parent_slot );
2153 0 : fd_http_server_ws_broadcast( gui->http );
2154 0 : }
2155 :
2156 0 : gui->summary.slot_rooted = _slot;
2157 0 : fd_gui_printf_root_slot( gui );
2158 0 : fd_http_server_ws_broadcast( gui->http );
2159 0 : }
2160 :
2161 : static void
2162 : fd_gui_handle_optimistically_confirmed_slot( fd_gui_t * gui,
2163 0 : ulong _slot ) {
2164 : /* Slot 0 is always rooted. No need to iterate all the way back to
2165 : i==_slot */
2166 0 : for( ulong i=0UL; i<fd_ulong_min( _slot, FD_GUI_SLOTS_CNT ); i++ ) {
2167 0 : ulong parent_slot = _slot - i;
2168 :
2169 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
2170 0 : if( FD_UNLIKELY( !slot) ) break;
2171 :
2172 0 : if( FD_UNLIKELY( slot->slot>parent_slot ) ) {
2173 0 : FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", _slot, i, parent_slot, slot->slot ));
2174 0 : } else if( FD_UNLIKELY( slot->slot<parent_slot ) ) {
2175 : /* Slot not even replayed yet ... will come out as optimistically confirmed */
2176 0 : continue;
2177 0 : }
2178 0 : if( FD_UNLIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
2179 :
2180 0 : if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED ) ) {
2181 0 : slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
2182 0 : fd_gui_printf_slot( gui, parent_slot );
2183 0 : fd_http_server_ws_broadcast( gui->http );
2184 0 : }
2185 0 : }
2186 :
2187 0 : if( FD_UNLIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && _slot<gui->summary.slot_optimistically_confirmed ) ) {
2188 : /* Optimistically confirmed slot went backwards ... mark some slots as no
2189 : longer optimistically confirmed. */
2190 0 : for( ulong i=gui->summary.slot_optimistically_confirmed; i>=_slot; i-- ) {
2191 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, i );
2192 0 : if( FD_UNLIKELY( !slot ) ) break;
2193 0 : if( FD_LIKELY( slot->slot==i ) ) {
2194 : /* It's possible for the optimistically confirmed slot to skip
2195 : backwards between two slots that we haven't yet replayed. In
2196 : that case we don't need to change anything, since they will
2197 : get marked properly when they get completed. */
2198 0 : slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
2199 0 : fd_gui_printf_slot( gui, i );
2200 0 : fd_http_server_ws_broadcast( gui->http );
2201 0 : }
2202 0 : }
2203 0 : }
2204 :
2205 0 : gui->summary.slot_optimistically_confirmed = _slot;
2206 0 : fd_gui_printf_optimistically_confirmed_slot( gui );
2207 0 : fd_http_server_ws_broadcast( gui->http );
2208 0 : }
2209 :
2210 : static void
2211 : fd_gui_handle_balance_update( fd_gui_t * gui,
2212 0 : ulong const * msg ) {
2213 0 : switch( msg[ 0 ] ) {
2214 0 : case 0UL:
2215 0 : gui->summary.identity_account_balance = msg[ 1 ];
2216 0 : fd_gui_printf_identity_balance( gui );
2217 0 : fd_http_server_ws_broadcast( gui->http );
2218 0 : break;
2219 0 : case 1UL:
2220 0 : gui->summary.vote_account_balance = msg[ 1 ];
2221 0 : fd_gui_printf_vote_balance( gui );
2222 0 : fd_http_server_ws_broadcast( gui->http );
2223 0 : break;
2224 0 : default:
2225 0 : FD_LOG_ERR(( "balance: unknown account type: %lu", msg[ 0 ] ));
2226 0 : }
2227 0 : }
2228 :
2229 : static void
2230 : fd_gui_handle_start_progress( fd_gui_t * gui,
2231 0 : uchar const * msg ) {
2232 0 : uchar type = msg[ 0 ];
2233 :
2234 0 : switch (type) {
2235 0 : case 0:
2236 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_INITIALIZING;
2237 0 : FD_LOG_INFO(( "progress: initializing" ));
2238 0 : break;
2239 0 : case 1: {
2240 0 : char const * snapshot_type;
2241 0 : if( FD_UNLIKELY( gui->summary.startup_progress.startup_got_full_snapshot ) ) {
2242 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_SEARCHING_FOR_INCREMENTAL_SNAPSHOT;
2243 0 : snapshot_type = "incremental";
2244 0 : } else {
2245 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_SEARCHING_FOR_FULL_SNAPSHOT;
2246 0 : snapshot_type = "full";
2247 0 : }
2248 0 : FD_LOG_INFO(( "progress: searching for %s snapshot", snapshot_type ));
2249 0 : break;
2250 0 : }
2251 0 : case 2: {
2252 0 : uchar is_full_snapshot = msg[ 1 ];
2253 0 : if( FD_LIKELY( is_full_snapshot ) ) {
2254 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_DOWNLOADING_FULL_SNAPSHOT;
2255 0 : gui->summary.startup_progress.startup_full_snapshot_slot = *((ulong *)(msg + 2));
2256 0 : gui->summary.startup_progress.startup_full_snapshot_peer_ip_addr = *((uint *)(msg + 10));
2257 0 : gui->summary.startup_progress.startup_full_snapshot_peer_port = *((ushort *)(msg + 14));
2258 0 : gui->summary.startup_progress.startup_full_snapshot_total_bytes = *((ulong *)(msg + 16));
2259 0 : gui->summary.startup_progress.startup_full_snapshot_current_bytes = *((ulong *)(msg + 24));
2260 0 : gui->summary.startup_progress.startup_full_snapshot_elapsed_secs = *((double *)(msg + 32));
2261 0 : gui->summary.startup_progress.startup_full_snapshot_remaining_secs = *((double *)(msg + 40));
2262 0 : gui->summary.startup_progress.startup_full_snapshot_throughput = *((double *)(msg + 48));
2263 0 : FD_LOG_INFO(( "progress: downloading full snapshot: slot=%lu", gui->summary.startup_progress.startup_full_snapshot_slot ));
2264 0 : } else {
2265 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_DOWNLOADING_INCREMENTAL_SNAPSHOT;
2266 0 : gui->summary.startup_progress.startup_incremental_snapshot_slot = *((ulong *)(msg + 2));
2267 0 : gui->summary.startup_progress.startup_incremental_snapshot_peer_ip_addr = *((uint *)(msg + 10));
2268 0 : gui->summary.startup_progress.startup_incremental_snapshot_peer_port = *((ushort *)(msg + 14));
2269 0 : gui->summary.startup_progress.startup_incremental_snapshot_total_bytes = *((ulong *)(msg + 16));
2270 0 : gui->summary.startup_progress.startup_incremental_snapshot_current_bytes = *((ulong *)(msg + 24));
2271 0 : gui->summary.startup_progress.startup_incremental_snapshot_elapsed_secs = *((double *)(msg + 32));
2272 0 : gui->summary.startup_progress.startup_incremental_snapshot_remaining_secs = *((double *)(msg + 40));
2273 0 : gui->summary.startup_progress.startup_incremental_snapshot_throughput = *((double *)(msg + 48));
2274 0 : FD_LOG_INFO(( "progress: downloading incremental snapshot: slot=%lu", gui->summary.startup_progress.startup_incremental_snapshot_slot ));
2275 0 : }
2276 0 : break;
2277 0 : }
2278 0 : case 3: {
2279 0 : gui->summary.startup_progress.startup_got_full_snapshot = 1;
2280 0 : break;
2281 0 : }
2282 0 : case 4:
2283 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_CLEANING_BLOCK_STORE;
2284 0 : FD_LOG_INFO(( "progress: cleaning block store" ));
2285 0 : break;
2286 0 : case 5:
2287 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_CLEANING_ACCOUNTS;
2288 0 : FD_LOG_INFO(( "progress: cleaning accounts" ));
2289 0 : break;
2290 0 : case 6:
2291 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_LOADING_LEDGER;
2292 0 : FD_LOG_INFO(( "progress: loading ledger" ));
2293 0 : break;
2294 0 : case 7: {
2295 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_PROCESSING_LEDGER;
2296 0 : gui->summary.startup_progress.startup_ledger_slot = fd_ulong_load_8( msg + 1 );
2297 0 : gui->summary.startup_progress.startup_ledger_max_slot = fd_ulong_load_8( msg + 9 );
2298 0 : FD_LOG_INFO(( "progress: processing ledger: slot=%lu, max_slot=%lu", gui->summary.startup_progress.startup_ledger_slot, gui->summary.startup_progress.startup_ledger_max_slot ));
2299 0 : break;
2300 0 : }
2301 0 : case 8:
2302 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_STARTING_SERVICES;
2303 0 : FD_LOG_INFO(( "progress: starting services" ));
2304 0 : break;
2305 0 : case 9:
2306 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_HALTED;
2307 0 : FD_LOG_INFO(( "progress: halted" ));
2308 0 : break;
2309 0 : case 10: {
2310 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY;
2311 0 : gui->summary.startup_progress.startup_waiting_for_supermajority_slot = fd_ulong_load_8( msg + 1 );
2312 0 : gui->summary.startup_progress.startup_waiting_for_supermajority_stake_pct = fd_ulong_load_8( msg + 9 );
2313 0 : FD_LOG_INFO(( "progress: waiting for supermajority: slot=%lu, gossip_stake_percent=%lu", gui->summary.startup_progress.startup_waiting_for_supermajority_slot, gui->summary.startup_progress.startup_waiting_for_supermajority_stake_pct ));
2314 0 : break;
2315 0 : }
2316 0 : case 11:
2317 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_RUNNING;
2318 0 : FD_LOG_INFO(( "progress: running" ));
2319 0 : break;
2320 0 : default:
2321 0 : FD_LOG_ERR(( "progress: unknown type: %u", type ));
2322 0 : }
2323 :
2324 0 : fd_gui_printf_startup_progress( gui );
2325 0 : fd_http_server_ws_broadcast( gui->http );
2326 0 : }
2327 :
2328 : void
2329 : fd_gui_handle_genesis_hash( fd_gui_t * gui,
2330 0 : uchar const * msg ) {
2331 0 : FD_BASE58_ENCODE_32_BYTES(msg, hash_cstr);
2332 0 : ulong cluster = fd_genesis_cluster_identify(hash_cstr);
2333 0 : char const * cluster_name = fd_genesis_cluster_name(cluster);
2334 :
2335 0 : if( FD_LIKELY( strcmp( gui->summary.cluster, cluster_name ) ) ) {
2336 0 : gui->summary.cluster = fd_genesis_cluster_name(cluster);
2337 0 : fd_gui_printf_cluster( gui );
2338 0 : fd_http_server_ws_broadcast( gui->http );
2339 0 : }
2340 0 : }
2341 :
2342 : static void
2343 : fd_gui_handle_block_engine_update( fd_gui_t * gui,
2344 0 : uchar const * msg ) {
2345 0 : fd_plugin_msg_block_engine_update_t const * update = (fd_plugin_msg_block_engine_update_t const *)msg;
2346 :
2347 0 : gui->block_engine.has_block_engine = 1;
2348 :
2349 : /* copy strings and ensure null termination within bounds */
2350 0 : FD_TEST( fd_cstr_nlen( update->name, sizeof(gui->block_engine.name ) ) < sizeof(gui->block_engine.name ) );
2351 0 : FD_TEST( fd_cstr_nlen( update->url, sizeof(gui->block_engine.url ) ) < sizeof(gui->block_engine.url ) );
2352 0 : FD_TEST( fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) ) < sizeof(gui->block_engine.ip_cstr) );
2353 0 : ulong name_len = fd_cstr_nlen( update->name, sizeof(gui->block_engine.name ) );
2354 0 : ulong url_len = fd_cstr_nlen( update->url, sizeof(gui->block_engine.url ) );
2355 0 : ulong ip_cstr_len = fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) );
2356 0 : fd_memcpy( gui->block_engine.name, update->name, name_len+1UL );
2357 0 : fd_memcpy( gui->block_engine.url, update->url, url_len+1UL );
2358 0 : fd_memcpy( gui->block_engine.ip_cstr, update->ip_cstr, ip_cstr_len+1UL );
2359 :
2360 0 : gui->block_engine.status = update->status;
2361 :
2362 0 : fd_gui_printf_block_engine( gui );
2363 0 : fd_http_server_ws_broadcast( gui->http );
2364 0 : }
2365 :
2366 : void
2367 : fd_gui_handle_snapshot_update( fd_gui_t * gui,
2368 0 : fd_snapct_update_t const * msg ) {
2369 0 : FD_TEST( msg && fd_cstr_nlen( msg->read_path, 1 ) );
2370 :
2371 0 : ulong snapshot_idx = fd_ulong_if( msg->type==FD_SNAPCT_SNAPSHOT_TYPE_FULL, FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX );
2372 :
2373 0 : char const * filename = strrchr(msg->read_path, '/');
2374 :
2375 : /* Skip the '/' */
2376 0 : if( FD_UNLIKELY( filename ) ) filename++;
2377 :
2378 0 : if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_INCREMENTAL) {
2379 0 : ulong slot1, slot2;
2380 0 : if ( FD_LIKELY( sscanf( filename, "incremental-snapshot-%lu-%lu-", &slot1, &slot2 )==2 ) )
2381 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot2;
2382 0 : else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
2383 0 : } else if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_FULL) {
2384 0 : ulong slot1;
2385 0 : if ( FD_LIKELY( sscanf( filename, "snapshot-%lu-", &slot1 )==1 ) )
2386 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot1;
2387 0 : else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
2388 0 : }
2389 0 : fd_cstr_printf_check( gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_path, sizeof(gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_path), NULL, "%s", msg->read_path );
2390 0 : }
2391 :
2392 : static void
2393 0 : fd_gui_handle_reset_slot( fd_gui_t * gui, ulong reset_slot, long now ) {
2394 0 : FD_TEST( reset_slot!=ULONG_MAX );
2395 :
2396 : /* reset_slot has not changed */
2397 0 : if( FD_UNLIKELY( gui->summary.slot_completed!=ULONG_MAX && reset_slot==gui->summary.slot_completed ) ) return;
2398 :
2399 0 : ulong prev_slot_completed = gui->summary.slot_completed;
2400 0 : gui->summary.slot_completed = reset_slot;
2401 :
2402 0 : if( FD_LIKELY( fd_gui_get_slot( gui, gui->summary.slot_completed ) ) ) {
2403 0 : fd_gui_printf_slot( gui, gui->summary.slot_completed );
2404 0 : fd_http_server_ws_broadcast( gui->http );
2405 0 : }
2406 :
2407 0 : fd_gui_printf_completed_slot( gui );
2408 0 : fd_http_server_ws_broadcast( gui->http );
2409 :
2410 : /* Also update slot_turbine which could be larger than the max
2411 : turbine slot if we are leader */
2412 0 : if( FD_UNLIKELY( gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && gui->summary.slot_completed > gui->summary.slots_max_turbine[ 0 ].slot ) ) {
2413 0 : fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, gui->summary.slot_completed, now );
2414 0 : }
2415 :
2416 0 : int slot_turbine_hist_full = gui->summary.slots_max_turbine[ FD_GUI_TURBINE_SLOT_HISTORY_SZ-1UL ].slot!=ULONG_MAX;
2417 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX && slot_turbine_hist_full && gui->summary.slots_max_turbine[ 0 ].slot < (gui->summary.slot_completed + 3UL) ) ) {
2418 0 : gui->summary.slot_caught_up = gui->summary.slot_completed + 4UL;
2419 :
2420 0 : fd_gui_printf_slot_caught_up( gui );
2421 0 : fd_http_server_ws_broadcast( gui->http );
2422 0 : }
2423 :
2424 : /* ensure a history exists */
2425 0 : if( FD_UNLIKELY( prev_slot_completed==ULONG_MAX || gui->summary.slot_rooted==ULONG_MAX ) ) return;
2426 :
2427 : /* slot complete recieved out of order on the same fork? */
2428 0 : FD_TEST( fd_gui_slot_is_ancestor( gui, prev_slot_completed, gui->summary.slot_completed ) || !fd_gui_slot_is_ancestor( gui, gui->summary.slot_completed, prev_slot_completed ) );
2429 :
2430 : /* fork switch: we need to "undo" the previous fork */
2431 0 : int republish_skip_rate[ 2 ] = {0};
2432 0 : if( FD_UNLIKELY( !fd_gui_slot_is_ancestor( gui, prev_slot_completed, gui->summary.slot_completed ) ) ) {
2433 : /* The handling for skipped slot on a fork switch is tricky. We
2434 : want to rebate back any slots that were skipped but are no
2435 : longer. We also need to make sure we count skipped slots
2436 : towards the correct epoch. */
2437 0 : for( ulong i=fd_ulong_max( gui->summary.slot_completed, prev_slot_completed); i>gui->summary.slot_rooted; i-- ) {
2438 :
2439 0 : int is_skipped_on_old_fork = i<=prev_slot_completed && fd_gui_is_skipped_on_fork( gui, gui->summary.slot_rooted, prev_slot_completed, i );
2440 0 : int is_skipped_on_new_fork = i<=gui->summary.slot_completed && fd_gui_is_skipped_on_fork( gui, gui->summary.slot_rooted, gui->summary.slot_completed, i );
2441 :
2442 0 : if( FD_LIKELY( is_skipped_on_old_fork && !is_skipped_on_new_fork ) ) {
2443 0 : fd_gui_slot_t * skipped = fd_gui_get_slot( gui, i );
2444 0 : if( FD_LIKELY( !skipped ) ) {
2445 0 : fd_gui_slot_t * p = fd_gui_get_parent_slot_on_fork( gui, prev_slot_completed, i );
2446 0 : skipped = fd_gui_clear_slot( gui, i, p ? p->slot : ULONG_MAX );
2447 0 : }
2448 :
2449 0 : skipped->skipped = 0;
2450 0 : fd_gui_printf_slot( gui, skipped->slot );
2451 0 : fd_http_server_ws_broadcast( gui->http );
2452 0 : skipped->must_republish = 0;
2453 :
2454 0 : if( FD_LIKELY( skipped->mine ) ) {
2455 0 : for( ulong i=0UL; i<2UL; i++ ) {
2456 0 : if( FD_LIKELY( i>=gui->epoch.epochs[ i ].start_slot && i<=gui->epoch.epochs[ i ].end_slot ) ) {
2457 0 : gui->epoch.epochs[ i ].my_skipped_slots--;
2458 0 : republish_skip_rate[ i ] = 1;
2459 0 : break;
2460 0 : }
2461 0 : }
2462 0 : }
2463 0 : }
2464 :
2465 0 : if( FD_LIKELY( !is_skipped_on_old_fork && is_skipped_on_new_fork ) ) {
2466 0 : fd_gui_slot_t * skipped = fd_gui_get_slot( gui, i );
2467 0 : if( FD_LIKELY( !skipped ) ) {
2468 0 : fd_gui_slot_t * p = fd_gui_get_parent_slot_on_fork( gui, prev_slot_completed, i );
2469 0 : skipped = fd_gui_clear_slot( gui, i, p ? p->slot : ULONG_MAX );
2470 0 : }
2471 :
2472 0 : skipped->skipped = 1;
2473 0 : fd_gui_printf_slot( gui, skipped->slot );
2474 0 : fd_http_server_ws_broadcast( gui->http );
2475 0 : skipped->must_republish = 0;
2476 :
2477 0 : if( FD_LIKELY( skipped->mine ) ) {
2478 0 : for( ulong i=0UL; i<2UL; i++ ) {
2479 0 : if( FD_LIKELY( i>=gui->epoch.epochs[ i ].start_slot && i<=gui->epoch.epochs[ i ].end_slot ) ) {
2480 0 : gui->epoch.epochs[ i ].my_skipped_slots++;
2481 0 : republish_skip_rate[ i ] = 1;
2482 0 : break;
2483 0 : }
2484 0 : }
2485 0 : }
2486 0 : }
2487 0 : }
2488 0 : } else {
2489 : /* publish new skipped slots */
2490 0 : fd_gui_slot_t * s = fd_gui_get_slot( gui, gui->summary.slot_completed );
2491 0 : while( s && s->slot>=prev_slot_completed ) {
2492 0 : fd_gui_slot_t * p = fd_gui_get_slot( gui, s->parent_slot );
2493 0 : if( FD_UNLIKELY( !p ) ) break;
2494 0 : for( ulong i=p->slot+1; i<s->slot; i++ ) {
2495 0 : fd_gui_slot_t * skipped = fd_gui_get_slot( gui, i );
2496 0 : if( FD_LIKELY( !skipped ) ) {
2497 0 : fd_gui_slot_t * p = fd_gui_get_parent_slot_on_fork( gui, gui->summary.slot_completed, i );
2498 0 : skipped = fd_gui_clear_slot( gui, i, p ? p->slot : ULONG_MAX );
2499 0 : }
2500 0 : skipped->skipped = 1;
2501 0 : fd_gui_printf_slot( gui, skipped->slot );
2502 0 : fd_http_server_ws_broadcast( gui->http );
2503 0 : skipped->must_republish = 0;
2504 0 : if( FD_LIKELY( skipped->mine ) ) {
2505 0 : for( ulong i=0UL; i<2UL; i++ ) {
2506 0 : if( FD_LIKELY( i>=gui->epoch.epochs[ i ].start_slot && i<=gui->epoch.epochs[ i ].end_slot ) ) {
2507 0 : gui->epoch.epochs[ i ].my_skipped_slots++;
2508 0 : republish_skip_rate[ i ] = 1;
2509 0 : break;
2510 0 : }
2511 0 : }
2512 0 : }
2513 0 : }
2514 0 : s = p;
2515 0 : }
2516 0 : }
2517 :
2518 0 : for( ulong i=0UL; i<2UL; i++ ) {
2519 0 : if( FD_LIKELY( republish_skip_rate[ i ] ) ) {
2520 0 : fd_gui_printf_skip_rate( gui, i );
2521 0 : fd_http_server_ws_broadcast( gui->http );
2522 0 : }
2523 0 : }
2524 0 : }
2525 :
2526 : #define SORT_NAME fd_gui_slot_staged_shred_event_evict_sort
2527 : #define SORT_KEY_T fd_gui_slot_staged_shred_event_t
2528 : #define SORT_BEFORE(a,b) (__extension__({ (void)(b); (a).slot==ULONG_MAX; }))
2529 : #include "../../util/tmpl/fd_sort.c"
2530 :
2531 : #define SORT_NAME fd_gui_slot_staged_shred_event_slot_sort
2532 0 : #define SORT_KEY_T fd_gui_slot_staged_shred_event_t
2533 0 : #define SORT_BEFORE(a,b) ((a).slot<(b).slot)
2534 : #include "../../util/tmpl/fd_sort.c"
2535 :
2536 : static void
2537 0 : fd_gui_handle_rooted_slot( fd_gui_t * gui, ulong root_slot ) {
2538 : /* start at the new root and move backwards towards the old root,
2539 : rooting everything in-between */
2540 0 : for( ulong i=0UL; i<fd_ulong_min( root_slot, FD_GUI_SLOTS_CNT ); i++ ) {
2541 0 : ulong parent_slot = root_slot - i;
2542 :
2543 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
2544 0 : if( FD_UNLIKELY( !slot ) ) break;
2545 :
2546 0 : if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
2547 0 : FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", root_slot, i, parent_slot, slot->slot ));
2548 0 : }
2549 0 : if( FD_UNLIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
2550 :
2551 : /* change notarization levels and rebroadcast */
2552 0 : slot->level = FD_GUI_SLOT_LEVEL_ROOTED;
2553 0 : fd_gui_printf_slot( gui, parent_slot );
2554 0 : fd_http_server_ws_broadcast( gui->http );
2555 0 : }
2556 :
2557 : /* archive root shred events. We want to avoid n^2 iteration here
2558 : since it can significantly slow things down. Instead, we copy
2559 : over all rooted shreds to a scratch space, stable sort by slot,
2560 : copy the sorted arrays to the shred history. */
2561 0 : ulong archive_cnt = 0UL;
2562 0 : ulong kept_cnt = 0UL;
2563 0 : ulong kept_before_next_cnt = 0UL;
2564 :
2565 0 : for( ulong i=gui->shreds.staged_head; i<gui->shreds.staged_tail; i++ ) {
2566 0 : fd_gui_slot_staged_shred_event_t const * src = &gui->shreds.staged[ i % FD_GUI_SHREDS_STAGING_SZ ];
2567 :
2568 0 : if( FD_UNLIKELY( gui->shreds.history_slot!=ULONG_MAX && src->slot<=gui->shreds.history_slot ) ) continue;
2569 :
2570 0 : if( FD_UNLIKELY( src->slot<=root_slot ) ) {
2571 0 : gui->shreds._staged_scratch[ archive_cnt++ ] = *src;
2572 0 : continue;
2573 0 : }
2574 :
2575 : /* The entries from the staging area are evicted by setting their
2576 : slot field to ULONG MAX, then sorting the staging area.
2577 :
2578 : IMPORTANT: this sort needs to be stable since we always keep
2579 : valid un-broadcast events at the end of the ring buffer */
2580 0 : if( FD_UNLIKELY( i<gui->shreds.staged_next_broadcast ) ) kept_before_next_cnt++;
2581 0 : gui->shreds._staged_scratch2[ kept_cnt++ ] = *src;
2582 0 : }
2583 :
2584 : /* copy shred events to archive */
2585 0 : for( ulong j=0UL; j<kept_cnt; j++ ) gui->shreds.staged[ (gui->shreds.staged_head + j) % FD_GUI_SHREDS_STAGING_SZ ] = gui->shreds._staged_scratch2[ j ];
2586 0 : gui->shreds.staged_tail = gui->shreds.staged_head + kept_cnt;
2587 : /* Remap next_broadcast to preserve continuity after compaction */
2588 0 : gui->shreds.staged_next_broadcast = gui->shreds.staged_head + kept_before_next_cnt;
2589 :
2590 : /* sort scratch by slot increasing */
2591 0 : if( FD_LIKELY( archive_cnt ) ) {
2592 0 : fd_gui_slot_staged_shred_event_slot_sort_stable( gui->shreds._staged_scratch, archive_cnt, gui->shreds._staged_scratch2 );
2593 :
2594 0 : for( ulong i=0UL; i<archive_cnt; i++ ) {
2595 0 : if( FD_UNLIKELY( gui->shreds._staged_scratch[ i ].slot!=gui->shreds.history_slot ) ) {
2596 0 : fd_gui_slot_t * prev_slot = fd_gui_get_slot( gui, gui->shreds.history_slot );
2597 0 : if( FD_LIKELY( prev_slot ) ) prev_slot->shreds.end_offset = gui->shreds.history_tail;
2598 :
2599 0 : gui->shreds.history_slot = gui->shreds._staged_scratch[ i ].slot;
2600 :
2601 0 : fd_gui_slot_t * next_slot = fd_gui_get_slot( gui, gui->shreds.history_slot );
2602 0 : if( FD_LIKELY( next_slot ) ) next_slot->shreds.start_offset = gui->shreds.history_tail;
2603 0 : }
2604 :
2605 0 : gui->shreds.history[ gui->shreds.history_tail % FD_GUI_SHREDS_HISTORY_SZ ].timestamp = gui->shreds._staged_scratch[ i ].timestamp;
2606 0 : gui->shreds.history[ gui->shreds.history_tail % FD_GUI_SHREDS_HISTORY_SZ ].shred_idx = gui->shreds._staged_scratch[ i ].shred_idx;
2607 0 : gui->shreds.history[ gui->shreds.history_tail % FD_GUI_SHREDS_HISTORY_SZ ].event = gui->shreds._staged_scratch[ i ].event;
2608 :
2609 0 : gui->shreds.history_tail++;
2610 0 : }
2611 0 : }
2612 :
2613 0 : gui->summary.slot_rooted = root_slot;
2614 0 : fd_gui_printf_root_slot( gui );
2615 0 : fd_http_server_ws_broadcast( gui->http );
2616 0 : }
2617 :
2618 : void
2619 : fd_gui_handle_notarization_update( fd_gui_t * gui,
2620 0 : fd_tower_slot_confirmed_t const * notar ) {
2621 0 : if( FD_UNLIKELY( notar->slot!=ULONG_MAX && gui->summary.slot_optimistically_confirmed!=notar->slot && notar->kind==FD_TOWER_SLOT_CONFIRMED_CLUSTER ) ) {
2622 0 : fd_gui_handle_optimistically_confirmed_slot( gui, notar->slot );
2623 0 : }
2624 0 : }
2625 :
2626 : /* fd_gui_handle_tower_update handles updates from the tower tile, which
2627 : manages consensus related fork switching, rooting, slot confirmation. */
2628 : void
2629 : fd_gui_handle_tower_update( fd_gui_t * gui,
2630 : fd_tower_slot_done_t const * tower,
2631 0 : long now ) {
2632 0 : (void)now;
2633 :
2634 : /* handle new root */
2635 0 : if( FD_LIKELY( tower->root_slot!=ULONG_MAX && gui->summary.slot_rooted!=tower->root_slot ) ) {
2636 0 : fd_gui_handle_rooted_slot( gui, tower->root_slot );
2637 0 : }
2638 :
2639 0 : if( FD_UNLIKELY( gui->summary.vote_distance!=tower->reset_slot-tower->vote_slot ) ) {
2640 0 : gui->summary.vote_distance = tower->reset_slot-tower->vote_slot;
2641 0 : fd_gui_printf_vote_distance( gui );
2642 0 : fd_http_server_ws_broadcast( gui->http );
2643 0 : }
2644 :
2645 0 : if( FD_LIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_NON_VOTING ) ) {
2646 0 : if( FD_UNLIKELY( tower->vote_slot==ULONG_MAX || (tower->vote_slot+150UL)<tower->reset_slot ) ) {
2647 0 : if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_DELINQUENT ) ) {
2648 0 : gui->summary.vote_state = FD_GUI_VOTE_STATE_DELINQUENT;
2649 0 : fd_gui_printf_vote_state( gui );
2650 0 : fd_http_server_ws_broadcast( gui->http );
2651 0 : }
2652 0 : } else {
2653 0 : if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_VOTING ) ) {
2654 0 : gui->summary.vote_state = FD_GUI_VOTE_STATE_VOTING;
2655 0 : fd_gui_printf_vote_state( gui );
2656 0 : fd_http_server_ws_broadcast( gui->http );
2657 0 : }
2658 0 : }
2659 0 : }
2660 :
2661 : /* todo ... optimistic confirmation, waiting on fd_ghost / fd_notar */
2662 0 : }
2663 :
2664 : void
2665 : fd_gui_handle_replay_update( fd_gui_t * gui,
2666 : fd_gui_slot_completed_t * slot_completed,
2667 : fd_hash_t const * block_hash,
2668 0 : long now ) {
2669 0 : (void)now;
2670 :
2671 0 : if( FD_UNLIKELY( gui->summary.boot_progress.catching_up_first_replay_slot==ULONG_MAX ) ) {
2672 0 : gui->summary.boot_progress.catching_up_first_replay_slot = slot_completed->slot;
2673 0 : }
2674 :
2675 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, slot_completed->slot );
2676 0 : if( FD_UNLIKELY( slot ) ) {
2677 : /* Its possible that this slot was labeled as skipped by another
2678 : consensus fork at some point in the past. In this case no need to
2679 : clear it, but we should update parent_slot */
2680 0 : slot->parent_slot = slot_completed->parent_slot;
2681 0 : } else {
2682 0 : slot = fd_gui_clear_slot( gui, slot_completed->slot, slot_completed->parent_slot );
2683 0 : }
2684 :
2685 0 : if( FD_UNLIKELY( slot->mine ) ) {
2686 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, slot->slot );
2687 0 : if( FD_LIKELY( lslot ) ) fd_memcpy( lslot->block_hash.uc, block_hash->uc, sizeof(fd_hash_t) );
2688 0 : }
2689 :
2690 0 : slot->completed_time = slot_completed->completed_time;
2691 0 : slot->parent_slot = slot_completed->parent_slot;
2692 0 : slot->max_compute_units = fd_uint_if( slot_completed->max_compute_units==UINT_MAX, slot->max_compute_units, slot_completed->max_compute_units );
2693 0 : if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_COMPLETED ) ) {
2694 : /* Typically a slot goes from INCOMPLETE to COMPLETED but it can
2695 : happen that it starts higher. One such case is when we
2696 : optimistically confirm a higher slot that skips this one, but
2697 : then later we replay this one anyway to track the bank fork. */
2698 :
2699 0 : if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && slot->slot<gui->summary.slot_optimistically_confirmed ) ) {
2700 : /* Cluster might have already optimistically confirmed by the time
2701 : we finish replaying it. */
2702 0 : slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
2703 0 : } else {
2704 0 : slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
2705 0 : }
2706 0 : }
2707 0 : slot->total_txn_cnt = slot_completed->total_txn_cnt;
2708 0 : slot->vote_txn_cnt = slot_completed->vote_txn_cnt;
2709 0 : slot->failed_txn_cnt = slot_completed->failed_txn_cnt;
2710 0 : slot->nonvote_failed_txn_cnt = slot_completed->nonvote_failed_txn_cnt;
2711 0 : slot->transaction_fee = slot_completed->transaction_fee;
2712 0 : slot->priority_fee = slot_completed->priority_fee;
2713 0 : slot->tips = slot_completed->tips;
2714 0 : slot->compute_units = slot_completed->compute_units;
2715 0 : slot->shred_cnt = slot_completed->shred_cnt;
2716 :
2717 0 : if( FD_UNLIKELY( gui->epoch.has_epoch[ 0 ] && slot->slot==gui->epoch.epochs[ 0 ].end_slot ) ) {
2718 0 : gui->epoch.epochs[ 0 ].end_time = slot->completed_time;
2719 0 : } else if( FD_UNLIKELY( gui->epoch.has_epoch[ 1 ] && slot->slot==gui->epoch.epochs[ 1 ].end_slot ) ) {
2720 0 : gui->epoch.epochs[ 1 ].end_time = slot->completed_time;
2721 0 : }
2722 :
2723 : /* Broadcast new skip rate if one of our slots got completed. */
2724 0 : if( FD_LIKELY( slot->mine ) ) {
2725 0 : for( ulong i=0UL; i<2UL; i++ ) {
2726 0 : if( FD_LIKELY( slot->slot>=gui->epoch.epochs[ i ].start_slot && slot->slot<=gui->epoch.epochs[ i ].end_slot ) ) {
2727 0 : fd_gui_printf_skip_rate( gui, i );
2728 0 : fd_http_server_ws_broadcast( gui->http );
2729 0 : break;
2730 0 : }
2731 0 : }
2732 0 : }
2733 :
2734 : /* We'll treat the latest slot_complete from replay as the reset slot.
2735 : We get an explicit reset_slot from tower, but that message may come
2736 : in before we get the slot_complete from replay. */
2737 0 : if( FD_UNLIKELY( gui->summary.slot_completed!=slot->slot ) ) {
2738 0 : fd_gui_handle_reset_slot( gui, slot->slot, now );
2739 0 : }
2740 :
2741 : /* Add a "slot complete" event for all of the shreds in this slot */
2742 0 : if( FD_UNLIKELY( slot->shred_cnt > FD_GUI_MAX_SHREDS_PER_BLOCK ) ) FD_LOG_ERR(( "unexpected shred_cnt=%lu", (ulong)slot->shred_cnt ));
2743 0 : fd_gui_slot_staged_shred_event_t * slot_complete_event = &gui->shreds.staged[ gui->shreds.staged_tail % FD_GUI_SHREDS_STAGING_SZ ];
2744 0 : gui->shreds.staged_tail++;
2745 0 : slot_complete_event->event = FD_GUI_SLOT_SHRED_SHRED_SLOT_COMPLETE;
2746 0 : slot_complete_event->timestamp = slot_completed->completed_time;
2747 0 : slot_complete_event->shred_idx = USHORT_MAX;
2748 0 : slot_complete_event->slot = slot->slot;
2749 0 : }
2750 :
2751 : void
2752 : fd_gui_plugin_message( fd_gui_t * gui,
2753 : ulong plugin_msg,
2754 : uchar const * msg,
2755 0 : long now ) {
2756 :
2757 0 : switch( plugin_msg ) {
2758 0 : case FD_PLUGIN_MSG_SLOT_ROOTED:
2759 0 : fd_gui_handle_rooted_slot_legacy( gui, (ulong *)msg );
2760 0 : break;
2761 0 : case FD_PLUGIN_MSG_SLOT_OPTIMISTICALLY_CONFIRMED:
2762 0 : fd_gui_handle_optimistically_confirmed_slot( gui, ((ulong *)msg)[0] );
2763 0 : break;
2764 0 : case FD_PLUGIN_MSG_SLOT_COMPLETED: {
2765 0 : fd_gui_handle_completed_slot( gui, (ulong *)msg, now );
2766 0 : break;
2767 0 : }
2768 0 : case FD_PLUGIN_MSG_LEADER_SCHEDULE: {
2769 0 : FD_STATIC_ASSERT( sizeof(fd_stake_weight_msg_t)==6*sizeof(ulong), "new fields breaks things" );
2770 0 : fd_gui_handle_leader_schedule( gui, (fd_stake_weight_msg_t *)msg, now );
2771 0 : break;
2772 0 : }
2773 0 : case FD_PLUGIN_MSG_SLOT_START: {
2774 0 : ulong slot = ((ulong *)msg)[ 0 ];
2775 0 : ulong parent_slot = ((ulong *)msg)[ 1 ];
2776 0 : fd_gui_handle_slot_start( gui, slot, parent_slot, now );
2777 0 : break;
2778 0 : }
2779 0 : case FD_PLUGIN_MSG_SLOT_END: {
2780 0 : ulong slot = ((ulong *)msg)[ 0 ];
2781 0 : ulong cus_used = ((ulong *)msg)[ 1 ];
2782 0 : fd_gui_handle_slot_end( gui, slot, cus_used, now );
2783 0 : break;
2784 0 : }
2785 0 : case FD_PLUGIN_MSG_GOSSIP_UPDATE: {
2786 0 : fd_gui_handle_gossip_update( gui, msg );
2787 0 : break;
2788 0 : }
2789 0 : case FD_PLUGIN_MSG_VOTE_ACCOUNT_UPDATE: {
2790 0 : fd_gui_handle_vote_account_update( gui, msg );
2791 0 : break;
2792 0 : }
2793 0 : case FD_PLUGIN_MSG_VALIDATOR_INFO: {
2794 0 : fd_gui_handle_validator_info_update( gui, msg );
2795 0 : break;
2796 0 : }
2797 0 : case FD_PLUGIN_MSG_SLOT_RESET: {
2798 0 : fd_gui_handle_reset_slot_legacy( gui, (ulong *)msg, now );
2799 0 : break;
2800 0 : }
2801 0 : case FD_PLUGIN_MSG_BALANCE: {
2802 0 : fd_gui_handle_balance_update( gui, (ulong *)msg );
2803 0 : break;
2804 0 : }
2805 0 : case FD_PLUGIN_MSG_START_PROGRESS: {
2806 0 : fd_gui_handle_start_progress( gui, msg );
2807 0 : break;
2808 0 : }
2809 0 : case FD_PLUGIN_MSG_GENESIS_HASH_KNOWN: {
2810 0 : fd_gui_handle_genesis_hash( gui, msg );
2811 0 : break;
2812 0 : }
2813 0 : case FD_PLUGIN_MSG_BLOCK_ENGINE_UPDATE: {
2814 0 : fd_gui_handle_block_engine_update( gui, msg );
2815 0 : break;
2816 0 : }
2817 0 : default:
2818 0 : FD_LOG_ERR(( "Unhandled plugin msg: 0x%lx", plugin_msg ));
2819 0 : break;
2820 0 : }
2821 0 : }
2822 :
2823 : void
2824 : fd_gui_became_leader( fd_gui_t * gui,
2825 : ulong _slot,
2826 : long start_time_nanos,
2827 : long end_time_nanos,
2828 : ulong max_compute_units,
2829 0 : ulong max_microblocks ) {
2830 0 : if( FD_LIKELY( gui->summary.is_full_client && gui->leader_slot!=ULONG_MAX ) ) {
2831 : /* stop sampling for other leader slot in progress */
2832 0 : fd_gui_handle_slot_end( gui, gui->leader_slot, ULONG_MAX, start_time_nanos );
2833 0 : }
2834 :
2835 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2836 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
2837 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
2838 0 : if( FD_UNLIKELY( !lslot ) ) return;
2839 :
2840 0 : slot->max_compute_units = (uint)max_compute_units;
2841 0 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, start_time_nanos, lslot->leader_start_time );
2842 0 : lslot->leader_end_time = end_time_nanos;
2843 0 : if( FD_LIKELY( lslot->txs.microblocks_upper_bound==USHORT_MAX ) ) lslot->txs.microblocks_upper_bound = (ushort)max_microblocks;
2844 :
2845 0 : if( FD_UNLIKELY( gui->summary.is_full_client ) ) fd_gui_handle_slot_start( gui, slot->slot, slot->parent_slot, start_time_nanos );
2846 0 : }
2847 :
2848 : void
2849 : fd_gui_unbecame_leader( fd_gui_t * gui,
2850 : ulong _slot,
2851 : fd_done_packing_t const * done_packing,
2852 0 : long now ) {
2853 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2854 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
2855 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
2856 0 : if( FD_LIKELY( !lslot ) ) return;
2857 0 : lslot->txs.microblocks_upper_bound = (uint)done_packing->microblocks_in_slot;
2858 0 : fd_memcpy( lslot->scheduler_stats, done_packing, sizeof(fd_done_packing_t) );
2859 :
2860 : /* fd_gui_handle_slot_end may have already been called in response to
2861 : a "became_leader" message for a subseqeunt slot. */
2862 0 : if( FD_UNLIKELY( gui->summary.is_full_client && gui->leader_slot==_slot ) ) fd_gui_handle_slot_end( gui, slot->slot, ULONG_MAX, now );
2863 0 : }
2864 :
2865 : void
2866 : fd_gui_microblock_execution_begin( fd_gui_t * gui,
2867 : long now,
2868 : ulong _slot,
2869 : fd_txn_p_t * txns,
2870 : ulong txn_cnt,
2871 : uint microblock_idx,
2872 0 : ulong pack_txn_idx ) {
2873 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2874 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
2875 :
2876 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
2877 0 : if( FD_UNLIKELY( !lslot ) ) return;
2878 :
2879 0 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, now, lslot->leader_start_time );
2880 :
2881 0 : if( FD_UNLIKELY( lslot->txs.start_offset==ULONG_MAX ) ) lslot->txs.start_offset = pack_txn_idx;
2882 0 : else lslot->txs.start_offset = fd_ulong_min( lslot->txs.start_offset, pack_txn_idx );
2883 :
2884 0 : gui->pack_txn_idx = fd_ulong_max( gui->pack_txn_idx, pack_txn_idx+txn_cnt-1UL );
2885 :
2886 0 : for( ulong i=0UL; i<txn_cnt; i++ ) {
2887 0 : fd_txn_p_t * txn_payload = &txns[ i ];
2888 0 : fd_txn_t * txn = TXN( txn_payload );
2889 :
2890 0 : ulong sig_rewards = FD_PACK_FEE_PER_SIGNATURE * txn->signature_cnt;
2891 0 : ulong priority_rewards = ULONG_MAX;
2892 0 : ulong requested_execution_cus = ULONG_MAX;
2893 0 : ulong precompile_sigs = ULONG_MAX;
2894 0 : ulong requested_loaded_accounts_data_cost = ULONG_MAX;
2895 0 : uint _flags;
2896 0 : ulong cost_estimate = fd_pack_compute_cost( txn, txn_payload->payload, &_flags, &requested_execution_cus, &priority_rewards, &precompile_sigs, &requested_loaded_accounts_data_cost );
2897 0 : sig_rewards += FD_PACK_FEE_PER_SIGNATURE * precompile_sigs;
2898 0 : sig_rewards = sig_rewards * FD_PACK_TXN_FEE_BURN_PCT / 100UL;
2899 :
2900 0 : fd_gui_txn_t * txn_entry = gui->txs[ (pack_txn_idx + i)%FD_GUI_TXN_HISTORY_SZ ];
2901 0 : fd_memcpy(txn_entry->signature, txn_payload->payload + txn->signature_off, FD_SHA512_HASH_SZ);
2902 0 : txn_entry->timestamp_arrival_nanos = txn_payload->scheduler_arrival_time_nanos;
2903 0 : txn_entry->compute_units_requested = cost_estimate & 0x1FFFFFU;
2904 0 : txn_entry->priority_fee = priority_rewards;
2905 0 : txn_entry->transaction_fee = sig_rewards;
2906 0 : txn_entry->timestamp_delta_start_nanos = (int)(now - lslot->leader_start_time);
2907 0 : txn_entry->source_ipv4 = txn_payload->source_ipv4;
2908 0 : txn_entry->source_tpu = txn_payload->source_tpu;
2909 0 : txn_entry->microblock_idx = microblock_idx;
2910 0 : txn_entry->flags |= (uchar)FD_GUI_TXN_FLAGS_STARTED;
2911 0 : txn_entry->flags &= (uchar)(~(uchar)(FD_GUI_TXN_FLAGS_IS_SIMPLE_VOTE | FD_GUI_TXN_FLAGS_FROM_BUNDLE));
2912 0 : txn_entry->flags |= (uchar)fd_uint_if(txn_payload->flags & FD_TXN_P_FLAGS_IS_SIMPLE_VOTE, FD_GUI_TXN_FLAGS_IS_SIMPLE_VOTE, 0U);
2913 0 : txn_entry->flags |= (uchar)fd_uint_if((txn_payload->flags & FD_TXN_P_FLAGS_BUNDLE) || (txn_payload->flags & FD_TXN_P_FLAGS_INITIALIZER_BUNDLE), FD_GUI_TXN_FLAGS_FROM_BUNDLE, 0U);
2914 0 : }
2915 :
2916 : /* At the moment, bank publishes at most 1 transaction per microblock,
2917 : even if it received microblocks with multiple transactions
2918 : (i.e. a bundle). This means that we need to calculate microblock
2919 : count here based on the transaction count. */
2920 0 : lslot->txs.begin_microblocks += (uint)txn_cnt;
2921 0 : }
2922 :
2923 : void
2924 : fd_gui_microblock_execution_end( fd_gui_t * gui,
2925 : long now,
2926 : ulong bank_idx,
2927 : ulong _slot,
2928 : ulong txn_cnt,
2929 : fd_txn_p_t * txns,
2930 : ulong pack_txn_idx,
2931 : uchar txn_start_pct,
2932 : uchar txn_load_end_pct,
2933 : uchar txn_end_pct,
2934 : uchar txn_preload_end_pct,
2935 0 : ulong tips ) {
2936 0 : if( FD_UNLIKELY( 1UL!=txn_cnt ) ) FD_LOG_ERR(( "gui expects 1 txn per microblock from bank, found %lu", txn_cnt ));
2937 :
2938 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2939 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
2940 :
2941 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
2942 0 : if( FD_UNLIKELY( !lslot ) ) return;
2943 :
2944 0 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, now, lslot->leader_start_time );
2945 :
2946 0 : if( FD_UNLIKELY( lslot->txs.end_offset==ULONG_MAX ) ) lslot->txs.end_offset = pack_txn_idx + txn_cnt;
2947 0 : else lslot->txs.end_offset = fd_ulong_max( lslot->txs.end_offset, pack_txn_idx+txn_cnt );
2948 :
2949 0 : gui->pack_txn_idx = fd_ulong_max( gui->pack_txn_idx, pack_txn_idx+txn_cnt-1UL );
2950 :
2951 0 : for( ulong i=0UL; i<txn_cnt; i++ ) {
2952 0 : fd_txn_p_t * txn_p = &txns[ i ];
2953 :
2954 0 : fd_gui_txn_t * txn_entry = gui->txs[ (pack_txn_idx + i)%FD_GUI_TXN_HISTORY_SZ ];
2955 0 : txn_entry->bank_idx = bank_idx & 0x3FU;
2956 0 : txn_entry->compute_units_consumed = txn_p->bank_cu.actual_consumed_cus & 0x1FFFFFU;
2957 0 : txn_entry->error_code = (txn_p->flags >> 24) & 0x3FU;
2958 0 : txn_entry->timestamp_delta_end_nanos = (int)(now - lslot->leader_start_time);
2959 0 : txn_entry->txn_start_pct = txn_start_pct;
2960 0 : txn_entry->txn_load_end_pct = txn_load_end_pct;
2961 0 : txn_entry->txn_end_pct = txn_end_pct;
2962 0 : txn_entry->txn_preload_end_pct = txn_preload_end_pct;
2963 0 : txn_entry->tips = tips;
2964 0 : txn_entry->flags |= (uchar)FD_GUI_TXN_FLAGS_ENDED;
2965 0 : txn_entry->flags &= (uchar)(~(uchar)FD_GUI_TXN_FLAGS_LANDED_IN_BLOCK);
2966 0 : txn_entry->flags |= (uchar)fd_uint_if(txn_p->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS, FD_GUI_TXN_FLAGS_LANDED_IN_BLOCK, 0U);
2967 0 : }
2968 :
2969 0 : lslot->txs.end_microblocks = lslot->txs.end_microblocks + (uint)txn_cnt;
2970 0 : }
|