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