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