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