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