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