Line data Source code
1 : #include "fd_gui.h"
2 : #include "fd_gui_printf.h"
3 : #include "fd_gui_metrics.h"
4 : #include "fd_gui_hist.h"
5 :
6 : #include "../metrics/fd_metrics.h"
7 : #include "../../discof/gossip/fd_gossip_tile.h"
8 : #include "../bundle/fd_bundle_tile.h"
9 :
10 : #include "../../ballet/base58/fd_base58.h"
11 : #include "../../third_party/cjson/cJSON.h"
12 : #include "../../disco/genesis/fd_genesis_cluster.h"
13 : #include "../../disco/pack/fd_pack.h"
14 : #include "../../disco/pack/fd_pack_cost.h"
15 : #include "../../choreo/tower/fd_tower_serdes.h"
16 :
17 : #include <stdio.h>
18 :
19 : FD_FN_CONST ulong
20 162 : fd_gui_align( void ) {
21 162 : return 128UL;
22 162 : }
23 :
24 : ulong
25 36 : fd_gui_footprint( ulong tile_cnt ) {
26 36 : FD_TEST( tile_cnt && tile_cnt <=FD_TOPO_MAX_TILES );
27 :
28 36 : ulong l = FD_LAYOUT_INIT;
29 36 : l = FD_LAYOUT_APPEND( l, fd_gui_align(), sizeof(fd_gui_t) );
30 36 : l = FD_LAYOUT_APPEND( l, fd_gui_rate_deque_align(), fd_gui_rate_deque_footprint() ); /* ingress_maxq */
31 36 : l = FD_LAYOUT_APPEND( l, fd_gui_rate_deque_align(), fd_gui_rate_deque_footprint() ); /* egress_maxq */
32 36 : l = FD_LAYOUT_APPEND( l, fd_gui_hist_align(), fd_gui_hist_footprint() );
33 36 : return FD_LAYOUT_FINI( l, fd_gui_align() );
34 36 : }
35 :
36 : static inline int
37 : fd_gui_shreds_window_is_empty( fd_gui_t * gui,
38 : long after_ns,
39 0 : long before_ns ) {
40 0 : if( FD_UNLIKELY( !gui->db ) ) return 1;
41 :
42 0 : fd_gui_hist_iter_t it;
43 0 : if( FD_UNLIKELY( fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_SHRED_EVENTS, after_ns, before_ns, NULL, NULL ) ) ) return 1;
44 0 : while( fd_gui_hist_range_next( &it ) ) {
45 0 : fd_gui_slot_history_shred_event_t const * e = (fd_gui_slot_history_shred_event_t const *)it.rec;
46 0 : if( FD_UNLIKELY( e->timestamp<after_ns || e->timestamp>before_ns ) ) continue;
47 0 : fd_gui_hist_range_end( &it );
48 0 : return 0;
49 0 : }
50 0 : fd_gui_hist_range_end( &it );
51 0 : return 1;
52 0 : }
53 :
54 : static inline void
55 0 : fd_gui_build_tile_order( fd_gui_t * gui ) {
56 0 : ulong tile_cnt = gui->topo->tile_cnt;
57 0 : ulong order_cnt = 0UL;
58 0 : uchar placed[ FD_TOPO_MAX_TILES ] = {0};
59 :
60 0 : char const * const tile_display_order[] = {
61 0 : "gossvf", "gossip", "snapct", "snapld", "snapdc", "snapin", "snapwr",
62 0 : "net", "shred", "repair", "replay", "execrp", "tower", "txsend", "sign",
63 0 : "quic", "verify", "dedup", "pack", "execle", "poh"
64 0 : };
65 :
66 0 : for( ulong n=0UL; n<sizeof(tile_display_order)/sizeof(tile_display_order[0]); n++ ) {
67 0 : for( ulong i=0UL; i<tile_cnt; i++ ) {
68 0 : if( FD_LIKELY( placed[ i ] ) ) continue;
69 0 : if( FD_UNLIKELY( !strcmp( gui->topo->tiles[ i ].name, tile_display_order[ n ] ) ) ) {
70 0 : gui->summary.tile[ order_cnt++ ] = i;
71 0 : placed[ i ] = 1;
72 0 : }
73 0 : }
74 0 : }
75 :
76 0 : for( ulong i=0UL; i<tile_cnt; i++ ) {
77 0 : if( FD_UNLIKELY( !placed[ i ] ) ) gui->summary.tile[ order_cnt++ ] = i;
78 0 : }
79 :
80 0 : gui->summary.tile_cnt = order_cnt;
81 0 : }
82 :
83 : void *
84 : fd_gui_new( void * shmem,
85 : fd_http_server_t * http,
86 : char const * version,
87 : char const * cluster,
88 : uchar const * identity_key,
89 : int has_vote_key,
90 : uchar const * vote_key,
91 : int is_full_client,
92 : int snapshots_enabled,
93 : int is_voting,
94 : int schedule_strategy,
95 : char const * wfs_expected_bank_hash_cstr,
96 : ushort expected_shred_version,
97 : char const * accounts_database_path,
98 : char const * gui_database_path,
99 : void * db,
100 : fd_topo_t const * topo,
101 : fd_accdb_shmem_t const * accdb_shmem,
102 0 : long now ) {
103 :
104 0 : if( FD_UNLIKELY( !shmem ) ) {
105 0 : FD_LOG_WARNING(( "NULL shmem" ));
106 0 : return NULL;
107 0 : }
108 :
109 0 : if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmem, fd_gui_align() ) ) ) {
110 0 : FD_LOG_WARNING(( "misaligned shmem" ));
111 0 : return NULL;
112 0 : }
113 :
114 0 : if( FD_UNLIKELY( topo->tile_cnt>FD_TOPO_MAX_TILES ) ) {
115 0 : FD_LOG_WARNING(( "too many tiles" ));
116 0 : return NULL;
117 0 : }
118 :
119 0 : ulong tile_cnt = topo->tile_cnt;
120 :
121 0 : FD_SCRATCH_ALLOC_INIT( l, shmem );
122 0 : fd_gui_t * gui = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(), sizeof(fd_gui_t) );
123 0 : void * ingress_maxq_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_rate_deque_align(), fd_gui_rate_deque_footprint() );
124 0 : void * egress_maxq_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_rate_deque_align(), fd_gui_rate_deque_footprint() );
125 0 : void * hist_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_hist_align(), fd_gui_hist_footprint() );
126 :
127 0 : gui->http = http;
128 0 : gui->topo = topo;
129 0 : gui->accdb_shmem = accdb_shmem;
130 0 : gui->tick_per_ns = fd_tempo_tick_per_ns( NULL );
131 0 : gui->tile_cnt = tile_cnt;
132 :
133 0 : gui->db = db;
134 0 : gui->hist = fd_gui_hist_join( fd_gui_hist_new( hist_mem, (fd_gui_store_t const *)db ) );
135 0 : if( FD_UNLIKELY( !gui->hist ) ) {
136 0 : FD_LOG_WARNING(( "fd_gui_hist_new failed" ));
137 0 : return NULL;
138 0 : }
139 :
140 0 : gui->summary.ingress_maxq = fd_gui_rate_deque_join( fd_gui_rate_deque_new( ingress_maxq_mem ) );
141 0 : gui->summary.egress_maxq = fd_gui_rate_deque_join( fd_gui_rate_deque_new( egress_maxq_mem ) );
142 :
143 0 : gui->summary.network_stats_has_prev = 0;
144 0 : gui->summary.net_rate_prev_ts = 0L;
145 0 : for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) {
146 0 : fd_gui_ema_init( &gui->summary.ingress_ema[ i ], now, FD_GUI_NETWORK_EMA_HALF_LIFE_NS );
147 0 : fd_gui_ema_init( &gui->summary.egress_ema [ i ], now, FD_GUI_NETWORK_EMA_HALF_LIFE_NS );
148 0 : }
149 :
150 0 : gui->leader_active = 0;
151 :
152 0 : gui->summary.slot_tower = ULONG_MAX;
153 0 : gui->summary.slot_tower_bank_seq = ULONG_MAX;
154 0 : gui->summary.schedule_strategy = schedule_strategy;
155 :
156 :
157 0 : gui->next_sample_1sec = now;
158 0 : gui->next_sample_200millis = now;
159 0 : gui->next_sample_100millis = now;
160 0 : gui->next_sample_50millis = now;
161 0 : gui->next_sample_40millis = now;
162 0 : gui->next_sample_25millis = now;
163 0 : gui->next_sample_10millis = now;
164 :
165 0 : memcpy( gui->summary.identity_key->uc, identity_key, 32UL );
166 0 : fd_base58_encode_32( identity_key, NULL, gui->summary.identity_key_base58 );
167 0 : gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
168 :
169 0 : if( FD_LIKELY( has_vote_key ) ) {
170 0 : gui->summary.has_vote_key = 1;
171 0 : memcpy( gui->summary.vote_key->uc, vote_key, 32UL );
172 0 : fd_base58_encode_32( vote_key, NULL, gui->summary.vote_key_base58 );
173 0 : gui->summary.vote_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
174 0 : } else {
175 0 : gui->summary.has_vote_key = 0;
176 0 : memset( gui->summary.vote_key_base58, 0, sizeof(gui->summary.vote_key_base58) );
177 0 : }
178 :
179 0 : gui->summary.is_full_client = is_full_client;
180 0 : gui->summary.version = version;
181 0 : gui->summary.cluster = cluster;
182 0 : fd_cstr_ncpy( gui->summary.accounts_database_path, accounts_database_path, sizeof(gui->summary.accounts_database_path) );
183 0 : fd_cstr_ncpy( gui->summary.gui_database_path, gui_database_path, sizeof(gui->summary.gui_database_path) );
184 0 : gui->summary.startup_time_nanos = gui->next_sample_200millis;
185 0 : gui->summary.expected_shred_version = expected_shred_version;
186 0 : gui->summary.wfs_enabled = 0;
187 0 : gui->summary.wfs_bank_hash[ 0UL ] = '\0';
188 :
189 0 : {
190 0 : fd_cstr_ncpy( gui->summary.wfs_bank_hash, wfs_expected_bank_hash_cstr, sizeof(gui->summary.wfs_bank_hash) );
191 0 : gui->summary.wfs_enabled = !!strcmp( wfs_expected_bank_hash_cstr, "" );
192 :
193 0 : if( FD_UNLIKELY( snapshots_enabled ) ) {
194 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP;
195 0 : gui->summary.boot_progress.joining_gossip_time_nanos = gui->next_sample_200millis;
196 0 : memset( gui->summary.boot_progress.loading_snapshot, 0, sizeof(gui->summary.boot_progress.loading_snapshot) );
197 0 : for( ulong i=0UL; i<FD_GUI_BOOT_PROGRESS_SNAPSHOT_CNT; i++ ) {
198 0 : gui->summary.boot_progress.loading_snapshot[ i ].reset_cnt = ULONG_MAX; /* ensures other fields are reset initially */
199 0 : gui->summary.boot_progress.loading_snapshot[ i ].slot = ULONG_MAX;
200 0 : }
201 0 : gui->summary.boot_progress.catching_up_time_nanos = 0L;
202 0 : gui->summary.boot_progress.catching_up_first_replay_slot = ULONG_MAX;
203 0 : gui->summary.boot_progress.wfs_total_stake = 0UL;
204 0 : gui->summary.boot_progress.wfs_connected_stake = 0UL;
205 0 : gui->summary.boot_progress.wfs_total_peers = 0UL;
206 0 : gui->summary.boot_progress.wfs_connected_peers = 0UL;
207 0 : gui->summary.boot_progress.wfs_attempt = 0UL;
208 0 : } else {
209 0 : fd_memset( &gui->summary.boot_progress, 0, sizeof(gui->summary.boot_progress) );
210 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
211 0 : }
212 0 : }
213 :
214 0 : gui->summary.identity_account_balance = 0UL;
215 0 : gui->summary.vote_account_balance = 0UL;
216 0 : gui->summary.vote_commission = USHORT_MAX;
217 0 : gui->summary.estimated_slot_duration_nanos = 0UL;
218 :
219 0 : gui->summary.vote_distance = 0UL;
220 0 : gui->summary.vote_state = is_voting ? FD_GUI_VOTE_STATE_VOTING : FD_GUI_VOTE_STATE_NON_VOTING;
221 :
222 0 : gui->summary.sock_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "sock" );
223 0 : gui->summary.net_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "net" );
224 0 : gui->summary.quic_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "quic" );
225 0 : gui->summary.verify_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "verify" );
226 0 : gui->summary.resolh_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolh" );
227 0 : gui->summary.resolv_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolv" );
228 0 : gui->summary.bank_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "bank" );
229 0 : gui->summary.execle_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "execle" );
230 0 : gui->summary.execrp_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "execrp" );
231 0 : gui->summary.shred_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "shred" );
232 :
233 0 : fd_gui_build_tile_order( gui );
234 :
235 0 : gui->summary.slot_rooted = ULONG_MAX;
236 0 : gui->summary.slot_optimistically_confirmed = ULONG_MAX;
237 0 : gui->summary.slot_estimated = ULONG_MAX;
238 0 : gui->summary.slot_caught_up = ULONG_MAX;
239 0 : gui->summary.slot_repair = ULONG_MAX;
240 0 : gui->summary.slot_turbine = ULONG_MAX;
241 0 : gui->summary.slot_reset = ULONG_MAX;
242 0 : gui->summary.slot_storage = ULONG_MAX;
243 0 : gui->summary.active_fork_cnt = 1UL;
244 :
245 0 : memset( gui->summary.skip_rate, 0, sizeof(gui->summary.skip_rate) );
246 0 : gui->summary.skip_rate[ 0 ].epoch = ULONG_MAX;
247 0 : gui->summary.skip_rate[ 1 ].epoch = ULONG_MAX;
248 :
249 0 : for( ulong i=0UL; i < (FD_GUI_REPAIR_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_repair[ i ].slot = ULONG_MAX;
250 0 : for( ulong i=0UL; i < (FD_GUI_TURBINE_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_turbine[ i ].slot = ULONG_MAX;
251 :
252 0 : for( ulong i=0UL; i < FD_GUI_TURBINE_RECV_TIMESTAMPS; i++ ) gui->turbine_slots[ i ].slot = ULONG_MAX;
253 :
254 0 : gui->summary.estimated_tps_history_idx = 0UL;
255 0 : memset( gui->summary.estimated_tps_history, 0, sizeof(gui->summary.estimated_tps_history) );
256 :
257 0 : memset( gui->summary.txn_waterfall_reference, 0, sizeof(gui->summary.txn_waterfall_reference) );
258 0 : memset( gui->summary.txn_waterfall_current, 0, sizeof(gui->summary.txn_waterfall_current) );
259 :
260 0 : memset( gui->summary.tile_stats_reference, 0, sizeof(gui->summary.tile_stats_reference) );
261 0 : memset( gui->summary.tile_stats_current, 0, sizeof(gui->summary.tile_stats_current) );
262 :
263 0 : gui->summary.progcache_history_idx = 0UL;
264 0 : memset( gui->summary.progcache_hits_history, 0, sizeof(gui->summary.progcache_hits_history) );
265 0 : memset( gui->summary.progcache_lookups_history, 0, sizeof(gui->summary.progcache_lookups_history) );
266 0 : gui->summary.progcache_hits_1min = 0UL;
267 0 : gui->summary.progcache_lookups_1min = 0UL;
268 :
269 0 : memset( gui->summary.accounts_stats_reference, 0, sizeof(gui->summary.accounts_stats_reference) );
270 0 : memset( gui->summary.accounts_stats_current, 0, sizeof(gui->summary.accounts_stats_current ) );
271 0 : gui->summary.accounts_stats_have_reference = 0;
272 0 : gui->summary.accdb->accdb_win_idx = 0UL;
273 0 : gui->summary.accdb->accdb_win_count = 0UL;
274 0 : memset( gui->summary.accdb->accdb_win_dt_nanos, 0, sizeof(gui->summary.accdb->accdb_win_dt_nanos) );
275 0 : memset( gui->summary.accdb->agg_acquired_win, 0, sizeof(gui->summary.accdb->agg_acquired_win) );
276 0 : memset( gui->summary.accdb->agg_acquired_writable_win, 0, sizeof(gui->summary.accdb->agg_acquired_writable_win) );
277 0 : memset( gui->summary.accdb->agg_bytes_read_win, 0, sizeof(gui->summary.accdb->agg_bytes_read_win) );
278 0 : memset( gui->summary.accdb->agg_bytes_copied_win, 0, sizeof(gui->summary.accdb->agg_bytes_copied_win) );
279 0 : memset( gui->summary.accdb->agg_bytes_written_win, 0, sizeof(gui->summary.accdb->agg_bytes_written_win) );
280 0 : memset( gui->summary.accdb->agg_bytes_written_accdb_win, 0, sizeof(gui->summary.accdb->agg_bytes_written_accdb_win) );
281 0 : memset( gui->summary.accdb->agg_read_ops_win, 0, sizeof(gui->summary.accdb->agg_read_ops_win) );
282 0 : memset( gui->summary.accdb->agg_write_ops_win, 0, sizeof(gui->summary.accdb->agg_write_ops_win) );
283 0 : memset( gui->summary.accdb->agg_relocated_bytes_win, 0, sizeof(gui->summary.accdb->agg_relocated_bytes_win) );
284 0 : memset( gui->summary.accdb->agg_misses_win, 0, sizeof(gui->summary.accdb->agg_misses_win) );
285 0 : memset( gui->summary.accdb->class_acq_win, 0, sizeof(gui->summary.accdb->class_acq_win) );
286 0 : memset( gui->summary.accdb->class_acq_wr_win, 0, sizeof(gui->summary.accdb->class_acq_wr_win) );
287 0 : memset( gui->summary.accdb->class_not_found_win, 0, sizeof(gui->summary.accdb->class_not_found_win) );
288 0 : memset( gui->summary.accdb->class_evicted_win, 0, sizeof(gui->summary.accdb->class_evicted_win) );
289 0 : memset( gui->summary.accdb->class_preevicted_win, 0, sizeof(gui->summary.accdb->class_preevicted_win) );
290 0 : memset( gui->summary.accdb->class_commit_new_win, 0, sizeof(gui->summary.accdb->class_commit_new_win) );
291 0 : memset( gui->summary.accdb->class_commit_over_win, 0, sizeof(gui->summary.accdb->class_commit_over_win) );
292 :
293 0 : gui->summary.accdb->partition_cnt = 0UL;
294 0 : memset( gui->summary.accdb->partition_read_ops_win, 0, sizeof(gui->summary.accdb->partition_read_ops_win) );
295 0 : memset( gui->summary.accdb->partition_bytes_read_win, 0, sizeof(gui->summary.accdb->partition_bytes_read_win) );
296 0 : memset( gui->summary.accdb->partition_write_ops_win, 0, sizeof(gui->summary.accdb->partition_write_ops_win) );
297 0 : memset( gui->summary.accdb->partition_bytes_written_win, 0, sizeof(gui->summary.accdb->partition_bytes_written_win) );
298 0 : memset( gui->summary.accdb->partitions, 0, sizeof(gui->summary.accdb->partitions) );
299 0 : memset( gui->summary.accdb->partition_prev_read_ops, 0, sizeof(gui->summary.accdb->partition_prev_read_ops) );
300 0 : memset( gui->summary.accdb->partition_prev_bytes_read, 0, sizeof(gui->summary.accdb->partition_prev_bytes_read) );
301 0 : memset( gui->summary.accdb->partition_prev_write_ops, 0, sizeof(gui->summary.accdb->partition_prev_write_ops) );
302 0 : memset( gui->summary.accdb->partition_prev_bytes_written, 0, sizeof(gui->summary.accdb->partition_prev_bytes_written) );
303 0 : for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
304 0 : fd_gui_ema_init( &gui->summary.accdb->tier_fill_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
305 0 : fd_gui_ema_init( &gui->summary.accdb->tier_free_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
306 0 : }
307 0 : gui->summary.accdb->tier_sample_nanos = LONG_MAX;
308 0 : gui->summary.accdb->next_compaction_remaining_secs = 0.0;
309 0 : gui->summary.accdb->next_compaction_partition_idx = ULONG_MAX;
310 :
311 : /* Build the per-tile accdb slot table from the topology. Order
312 : matters only for stable JSON ordering: RW joiners first, RO
313 : joiners, then snapwr at the end. */
314 0 : gui->summary.accdb->accdb_tile_cnt = 0UL;
315 0 : static const struct { char const * name; uchar kind; } accdb_kinds[] = {
316 0 : { "execle", FD_GUI_ACCDB_TILE_KIND_RW },
317 0 : { "execrp", FD_GUI_ACCDB_TILE_KIND_RW },
318 0 : { "replay", FD_GUI_ACCDB_TILE_KIND_RW },
319 0 : { "tower", FD_GUI_ACCDB_TILE_KIND_RW },
320 0 : { "rpc", FD_GUI_ACCDB_TILE_KIND_RO },
321 0 : { "resolv", FD_GUI_ACCDB_TILE_KIND_RO },
322 0 : { "snapwr", FD_GUI_ACCDB_TILE_KIND_SNAPWR },
323 0 : { "accdb", FD_GUI_ACCDB_TILE_KIND_ACCDB },
324 0 : };
325 0 : for( ulong k=0UL; k<sizeof(accdb_kinds)/sizeof(accdb_kinds[0]); k++ ) {
326 0 : ulong cnt = fd_topo_tile_name_cnt( gui->topo, accdb_kinds[ k ].name );
327 0 : for( ulong i=0UL; i<cnt; i++ ) {
328 0 : ulong t_idx = fd_topo_find_tile( gui->topo, accdb_kinds[ k ].name, i );
329 0 : if( FD_UNLIKELY( t_idx==ULONG_MAX ) ) continue;
330 0 : if( FD_UNLIKELY( gui->summary.accdb->accdb_tile_cnt>=FD_GUI_MAX_ACCDB_TILES ) ) {
331 0 : FD_LOG_ERR(( "too many accdb consumer tiles (limit %lu)", FD_GUI_MAX_ACCDB_TILES ));
332 0 : }
333 0 : ulong slot = gui->summary.accdb->accdb_tile_cnt++;
334 0 : gui->summary.accdb->accdb_tile_topo_idx[ slot ] = (ushort)t_idx;
335 0 : gui->summary.accdb->accdb_tile_kind [ slot ] = accdb_kinds[ k ].kind;
336 0 : }
337 0 : }
338 0 : memset( gui->summary.accdb->tile_cur_acquired, 0, sizeof(gui->summary.accdb->tile_cur_acquired) );
339 0 : memset( gui->summary.accdb->tile_cur_acquired_writable, 0, sizeof(gui->summary.accdb->tile_cur_acquired_writable) );
340 0 : memset( gui->summary.accdb->tile_cur_bytes_read, 0, sizeof(gui->summary.accdb->tile_cur_bytes_read) );
341 0 : memset( gui->summary.accdb->tile_cur_bytes_copied, 0, sizeof(gui->summary.accdb->tile_cur_bytes_copied) );
342 0 : memset( gui->summary.accdb->tile_cur_bytes_written, 0, sizeof(gui->summary.accdb->tile_cur_bytes_written) );
343 0 : memset( gui->summary.accdb->tile_cur_read_ops, 0, sizeof(gui->summary.accdb->tile_cur_read_ops) );
344 0 : memset( gui->summary.accdb->tile_cur_write_ops, 0, sizeof(gui->summary.accdb->tile_cur_write_ops) );
345 0 : memset( gui->summary.accdb->tile_cur_misses, 0, sizeof(gui->summary.accdb->tile_cur_misses) );
346 0 : memset( gui->summary.accdb->tile_cur_evicted, 0, sizeof(gui->summary.accdb->tile_cur_evicted) );
347 0 : memset( gui->summary.accdb->tile_cur_committed, 0, sizeof(gui->summary.accdb->tile_cur_committed) );
348 0 : memset( gui->summary.accdb->tile_cur_acquire_calls, 0, sizeof(gui->summary.accdb->tile_cur_acquire_calls) );
349 0 : memset( gui->summary.accdb->tile_cur_status, 0, sizeof(gui->summary.accdb->tile_cur_status) );
350 0 : memset( gui->summary.accdb->tile_prev_acquired, 0, sizeof(gui->summary.accdb->tile_prev_acquired) );
351 0 : memset( gui->summary.accdb->tile_prev_acquired_writable, 0, sizeof(gui->summary.accdb->tile_prev_acquired_writable) );
352 0 : memset( gui->summary.accdb->tile_prev_bytes_read, 0, sizeof(gui->summary.accdb->tile_prev_bytes_read) );
353 0 : memset( gui->summary.accdb->tile_prev_bytes_copied, 0, sizeof(gui->summary.accdb->tile_prev_bytes_copied) );
354 0 : memset( gui->summary.accdb->tile_prev_bytes_written, 0, sizeof(gui->summary.accdb->tile_prev_bytes_written) );
355 0 : memset( gui->summary.accdb->tile_prev_read_ops, 0, sizeof(gui->summary.accdb->tile_prev_read_ops) );
356 0 : memset( gui->summary.accdb->tile_prev_write_ops, 0, sizeof(gui->summary.accdb->tile_prev_write_ops) );
357 0 : memset( gui->summary.accdb->tile_prev_misses, 0, sizeof(gui->summary.accdb->tile_prev_misses) );
358 0 : memset( gui->summary.accdb->tile_prev_evicted, 0, sizeof(gui->summary.accdb->tile_prev_evicted) );
359 0 : memset( gui->summary.accdb->tile_prev_committed, 0, sizeof(gui->summary.accdb->tile_prev_committed) );
360 0 : memset( gui->summary.accdb->tile_prev_acquire_calls, 0, sizeof(gui->summary.accdb->tile_prev_acquire_calls) );
361 0 : memset( gui->summary.accdb->tile_acquired_win, 0, sizeof(gui->summary.accdb->tile_acquired_win) );
362 0 : memset( gui->summary.accdb->tile_acquired_writable_win, 0, sizeof(gui->summary.accdb->tile_acquired_writable_win) );
363 0 : memset( gui->summary.accdb->tile_bytes_read_win, 0, sizeof(gui->summary.accdb->tile_bytes_read_win) );
364 0 : memset( gui->summary.accdb->tile_bytes_copied_win, 0, sizeof(gui->summary.accdb->tile_bytes_copied_win) );
365 0 : memset( gui->summary.accdb->tile_bytes_written_win, 0, sizeof(gui->summary.accdb->tile_bytes_written_win) );
366 0 : memset( gui->summary.accdb->tile_read_ops_win, 0, sizeof(gui->summary.accdb->tile_read_ops_win) );
367 0 : memset( gui->summary.accdb->tile_write_ops_win, 0, sizeof(gui->summary.accdb->tile_write_ops_win) );
368 0 : memset( gui->summary.accdb->tile_misses_win, 0, sizeof(gui->summary.accdb->tile_misses_win) );
369 0 : memset( gui->summary.accdb->tile_evicted_win, 0, sizeof(gui->summary.accdb->tile_evicted_win) );
370 0 : memset( gui->summary.accdb->tile_committed_win, 0, sizeof(gui->summary.accdb->tile_committed_win) );
371 0 : memset( gui->summary.accdb->tile_acquire_calls_win, 0, sizeof(gui->summary.accdb->tile_acquire_calls_win) );
372 :
373 0 : memset( gui->summary.accdb->tile_sparkline_bucket_start_nanos, 0, sizeof(gui->summary.accdb->tile_sparkline_bucket_start_nanos) );
374 0 : memset( gui->summary.accdb->tile_sparkline_acq_bucket, 0, sizeof(gui->summary.accdb->tile_sparkline_acq_bucket) );
375 0 : memset( gui->summary.accdb->tile_sparkline_acq_wr_bucket, 0, sizeof(gui->summary.accdb->tile_sparkline_acq_wr_bucket) );
376 0 : memset( gui->summary.accdb->tile_sparkline_acq_history, 0, sizeof(gui->summary.accdb->tile_sparkline_acq_history) );
377 0 : memset( gui->summary.accdb->tile_sparkline_acq_wr_history, 0, sizeof(gui->summary.accdb->tile_sparkline_acq_wr_history) );
378 0 : memset( gui->summary.accdb->tile_sparkline_count, 0, sizeof(gui->summary.accdb->tile_sparkline_count) );
379 :
380 0 : memset( gui->summary.tile_timers_reference, 0, sizeof(gui->summary.tile_timers_reference) );
381 0 : memset( gui->summary.tile_timers_current, 0, sizeof(gui->summary.tile_timers_current) );
382 0 : memset( gui->summary.tile_timers_packed, 0, sizeof(gui->summary.tile_timers_packed) );
383 :
384 0 : gui->landed_vote_cnt = 0UL;
385 :
386 0 : gui->block_engine.has_block_engine = 0;
387 :
388 0 : gui->epoch.current_epoch = ULONG_MAX;
389 0 : gui->epoch.has_epoch_schedule = 0;
390 0 : gui->epoch.stored_epoch_cnt = 0UL;
391 :
392 0 : gui->shreds.leader_shred_cnt = 0UL;
393 0 : gui->shreds.broadcast_watermark_ns = now;
394 0 : gui->summary.catch_up_repair_sz = 0UL;
395 0 : gui->summary.catch_up_turbine_sz = 0UL;
396 :
397 0 : return gui;
398 0 : }
399 :
400 : fd_gui_t *
401 0 : fd_gui_join( void * shmem ) {
402 0 : return (fd_gui_t *)shmem;
403 0 : }
404 :
405 : void
406 : fd_gui_set_identity( fd_gui_t * gui,
407 0 : uchar const * identity_pubkey ) {
408 0 : memcpy( gui->summary.identity_key->uc, identity_pubkey, 32UL );
409 0 : fd_base58_encode_32( identity_pubkey, NULL, gui->summary.identity_key_base58 );
410 0 : gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
411 :
412 0 : gui->summary.vote_distance = 0UL;
413 0 : if( FD_LIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_NON_VOTING ) ) gui->summary.vote_state = FD_GUI_VOTE_STATE_VOTING;
414 0 : gui->landed_vote_cnt = 0UL;
415 :
416 0 : fd_gui_printf_identity_key( gui );
417 0 : fd_http_server_ws_broadcast( gui->http );
418 0 : fd_gui_printf_vote_distance( gui );
419 0 : fd_http_server_ws_broadcast( gui->http );
420 0 : fd_gui_printf_vote_state( gui );
421 0 : fd_http_server_ws_broadcast( gui->http );
422 0 : fd_gui_printf_late_votes_history( gui );
423 0 : fd_http_server_ws_broadcast( gui->http );
424 0 : }
425 :
426 : void
427 : fd_gui_ws_open( fd_gui_t * gui,
428 : ulong ws_conn_id,
429 0 : long now ) {
430 0 : void (* printers[] )( fd_gui_t * gui ) = {
431 0 : fd_gui_printf_boot_progress,
432 0 : fd_gui_printf_version,
433 0 : fd_gui_printf_cluster,
434 0 : fd_gui_printf_commit_hash,
435 0 : fd_gui_printf_identity_key,
436 0 : fd_gui_printf_vote_key,
437 0 : fd_gui_printf_startup_time_nanos,
438 0 : fd_gui_printf_vote_state,
439 0 : fd_gui_printf_vote_distance,
440 0 : fd_gui_printf_turbine_slot,
441 0 : fd_gui_printf_repair_slot,
442 0 : fd_gui_printf_slot_caught_up,
443 0 : fd_gui_printf_tps_history,
444 0 : fd_gui_printf_tiles,
445 0 : fd_gui_printf_schedule_strategy,
446 0 : fd_gui_printf_identity_balance,
447 0 : fd_gui_printf_vote_balance,
448 0 : fd_gui_printf_vote_commission,
449 0 : fd_gui_printf_estimated_slot_duration_nanos,
450 0 : fd_gui_printf_root_slot,
451 0 : fd_gui_printf_storage_slot,
452 0 : fd_gui_printf_reset_slot,
453 0 : fd_gui_printf_active_fork_cnt,
454 0 : fd_gui_printf_optimistically_confirmed_slot,
455 0 : fd_gui_printf_completed_slot,
456 0 : fd_gui_printf_estimated_slot,
457 0 : fd_gui_printf_live_tile_timers,
458 0 : fd_gui_printf_live_tile_metrics,
459 0 : fd_gui_printf_catch_up_history,
460 0 : fd_gui_printf_late_votes_history,
461 0 : fd_gui_printf_health
462 0 : };
463 :
464 0 : ulong printers_len = sizeof(printers) / sizeof(printers[0]);
465 0 : for( ulong i=0UL; i<printers_len; i++ ) {
466 0 : printers[ i ]( gui );
467 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
468 0 : }
469 :
470 0 : {
471 0 : fd_gui_printf_live_program_cache( gui );
472 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
473 :
474 0 : if( FD_LIKELY( gui->summary.accounts_stats_have_reference ) ) {
475 0 : fd_gui_printf_accounts_stats( gui );
476 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
477 0 : }
478 0 : }
479 :
480 0 : if( FD_LIKELY( gui->block_engine.has_block_engine ) ) {
481 0 : fd_gui_printf_block_engine( gui );
482 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
483 0 : }
484 :
485 0 : if( FD_LIKELY( gui->epoch.current_epoch!=ULONG_MAX ) ) {
486 0 : for( ulong e=gui->epoch.current_epoch; e<=gui->epoch.current_epoch+1UL; e++ ) {
487 0 : if( FD_LIKELY( fd_gui_epoch( gui, e ) ) ) {
488 0 : fd_gui_printf_skip_rate( gui, e );
489 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
490 0 : fd_gui_printf_epoch( gui, e );
491 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
492 0 : }
493 0 : }
494 :
495 0 : fd_gui_printf_skipped_history( gui, gui->epoch.current_epoch );
496 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
497 0 : fd_gui_printf_skipped_history_cluster( gui, gui->epoch.current_epoch );
498 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
499 0 : }
500 :
501 : /* rebroadcast 10s of historical shred data */
502 0 : long const shred_history_start = now-10L*1000L*1000L*1000L;
503 0 : if( FD_LIKELY( !fd_gui_shreds_window_is_empty( gui, shred_history_start, now ) ) ) {
504 0 : fd_gui_printf_shred_rebroadcast( gui, shred_history_start, now );
505 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
506 0 : }
507 0 : }
508 :
509 :
510 :
511 : static inline ushort
512 0 : fd_gui_tile_timers_pct( ulong delta, ulong total ) {
513 0 : if( FD_UNLIKELY( !total ) ) return USHORT_MAX;
514 0 : double percent = ( (double)delta / (double)total ) * 100.0;
515 0 : long hundredths = (long)( percent * 100.0 );
516 0 : if( FD_UNLIKELY( hundredths<0L ) ) hundredths = 0L;
517 0 : if( FD_UNLIKELY( hundredths>(USHORT_MAX-1U) ) ) hundredths = (USHORT_MAX-1U);
518 0 : return (ushort)hundredths;
519 0 : }
520 :
521 : void
522 : fd_gui_tile_timers_diff( fd_gui_tile_timers_hist_t * out,
523 : fd_gui_tile_timers_t const * prev,
524 : fd_gui_tile_timers_t const * cur,
525 : ulong tile_idx,
526 0 : long sample_time_nanos ) {
527 0 : memset( out, 0, sizeof(*out) );
528 0 : out->sample_time_nanos = sample_time_nanos;
529 0 : out->tile_idx = (ushort)tile_idx;
530 :
531 0 : ulong cur_total = 0UL, prev_total = 0UL;
532 0 : for( ulong j=0UL; j<FD_METRICS_ENUM_TILE_REGIME_CNT; j++ ) {
533 0 : cur_total += cur->timers[ j ]; prev_total += prev->timers[ j ];
534 0 : }
535 0 : ulong busy = cur_total - prev_total;
536 0 : for( ulong j=0UL; j<FD_METRICS_ENUM_TILE_REGIME_CNT; j++ ) {
537 0 : out->timers[ j ] = fd_gui_tile_timers_pct( cur->timers[ j ] - prev->timers[ j ], busy );
538 0 : }
539 0 : if( FD_UNLIKELY( !busy ) ) {
540 0 : out->idle_ratio = USHORT_MAX;
541 0 : } else {
542 0 : ulong idle = cur->timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_POSTFRAG_IDX ] - prev->timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_POSTFRAG_IDX ];
543 0 : ulong bp = cur->timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX ] - prev->timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX ];
544 0 : out->idle_ratio = fd_gui_tile_timers_pct( idle+bp, busy );
545 0 : }
546 :
547 0 : ulong cur_ctot = 0UL, prev_ctot = 0UL;
548 0 : for( ulong j=0UL; j<FD_METRICS_ENUM_CPU_REGIME_CNT; j++ ) { cur_ctot += cur->sched_timers[ j ]; prev_ctot += prev->sched_timers[ j ]; }
549 0 : ulong cbusy = cur_ctot - prev_ctot;
550 0 : for( ulong j=0UL; j<FD_METRICS_ENUM_CPU_REGIME_CNT; j++ ) {
551 0 : out->sched_timers[ j ] = fd_gui_tile_timers_pct( cur->sched_timers[ j ] - prev->sched_timers[ j ], cbusy );
552 0 : }
553 :
554 0 : out->alive = (uchar)fd_ulong_if( cur->status==2U, 2UL, (ulong)( cur->heartbeat>prev->heartbeat ) );
555 0 : out->in_backp = (uchar)( !!cur->in_backp );
556 0 : out->last_cpu = cur->last_cpu;
557 :
558 0 : out->backp_msgs = cur->backp_cnt;
559 0 : out->nvcsw = cur->nvcsw;
560 0 : out->nivcsw = cur->nivcsw;
561 0 : out->minflt = cur->minflt;
562 0 : out->majflt = cur->majflt;
563 0 : out->interrupts = cur->interrupts;
564 0 : out->tlb_shootdowns = cur->tlb_shootdowns;
565 0 : out->timer_ticks = cur->timer_ticks;
566 0 : }
567 :
568 : static void
569 0 : fd_gui_tile_timers_snap( fd_gui_t * gui, long now ) {
570 0 : fd_gui_tile_timers_t * cur = gui->summary.tile_timers_current;
571 0 : fd_memcpy( gui->summary.tile_timers_reference, cur, gui->tile_cnt * sizeof(fd_gui_tile_timers_t) );
572 0 : for( ulong i=0UL; i<gui->topo->tile_cnt; i++ ) {
573 0 : fd_topo_tile_t const * tile = &gui->topo->tiles[ i ];
574 : /* NULL when the tile's metrics live in a workspace not mapped to
575 : this tile (e.g. bench tiles use the "bench" workspace, not
576 : "metric_in"). */
577 0 : if( FD_UNLIKELY( !tile->metrics ) ) continue;
578 0 : volatile ulong const * tile_metrics = fd_metrics_tile( tile->metrics );
579 :
580 0 : cur[ i ].sample_time_nanos = now;
581 :
582 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 ) ];
583 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_HOUSEKEEPING ) ];
584 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_HOUSEKEEPING ) ];
585 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 ) ];
586 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_PREFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_PREFRAG ) ];
587 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
588 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 ) ];
589 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_POSTFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_POSTFRAG ) ];
590 :
591 0 : cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_WAIT_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_WAIT ) ];
592 0 : cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_USER_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_USER ) ];
593 0 : cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_SYSTEM_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_SYSTEM ) ];
594 0 : cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_IDLE_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_IDLE ) ];
595 0 : cur[ i ].sched_timers[ FD_METRICS_ENUM_CPU_REGIME_V_INTERRUPT_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, CPU_DURATION_NANOS_INTERRUPT ) ];
596 :
597 0 : cur[ i ].in_backp = (int)tile_metrics[ MIDX(GAUGE, TILE, IN_BACKPRESSURE) ];
598 0 : cur[ i ].status = (uchar)tile_metrics[ MIDX( GAUGE, TILE, STATUS ) ];
599 0 : cur[ i ].heartbeat = tile_metrics[ MIDX( GAUGE, TILE, HEARTBEAT_TIMESTAMP_NANOS ) ];
600 0 : cur[ i ].backp_cnt = tile_metrics[ MIDX( COUNTER, TILE, BACKPRESSURE ) ];
601 0 : cur[ i ].nvcsw = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_VOLUNTARY ) ];
602 0 : cur[ i ].nivcsw = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_INVOLUNTARY ) ];
603 0 : cur[ i ].minflt = tile_metrics[ MIDX( COUNTER, TILE, PAGE_FAULT_MINOR ) ];
604 0 : cur[ i ].majflt = tile_metrics[ MIDX( COUNTER, TILE, PAGE_FAULT_MAJOR ) ];
605 0 : cur[ i ].last_cpu = (ushort)tile_metrics[ MIDX( GAUGE, TILE, LAST_CPU ) ];
606 0 : cur[ i ].interrupts = tile_metrics[ MIDX( COUNTER, TILE, IRQ_PREEMPTED ) ];
607 0 : cur[ i ].tlb_shootdowns = tile_metrics[ MIDX( COUNTER, TILE, TLB_SHOOTDOWN ) ];
608 0 : cur[ i ].timer_ticks = tile_metrics[ MIDX( COUNTER, TILE, TIMER_TICK ) ];
609 0 : }
610 :
611 0 : for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
612 0 : cur[ i ].tile_idx = i;
613 0 : fd_gui_tile_timers_diff( &gui->summary.tile_timers_packed[ i ], &gui->summary.tile_timers_reference[ i ], &cur[ i ], i, now );
614 0 : }
615 0 : }
616 :
617 : static void
618 0 : fd_gui_scheduler_counts_snap( fd_gui_t * gui, long now ) {
619 0 : ulong pack_tile_idx = fd_topo_find_tile( gui->topo, "pack", 0UL );
620 0 : if( FD_UNLIKELY( pack_tile_idx==ULONG_MAX ) ) return;
621 :
622 0 : fd_gui_scheduler_counts_t cur[ 1 ];
623 :
624 0 : fd_topo_tile_t const * pack = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "pack", 0UL ) ];
625 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
626 :
627 0 : cur->sample_time_ns = now;
628 :
629 0 : cur->regular = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_REGULAR ) ];
630 0 : cur->votes = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_VOTES ) ];
631 0 : cur->conflicting = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_CONFLICTING ) ];
632 0 : cur->bundles = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE_BUNDLES ) ];
633 :
634 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_SCHEDULER_COUNTS, now, now, cur );
635 0 : }
636 :
637 : static void
638 0 : fd_gui_estimated_tps_snap( fd_gui_t * gui ) {
639 0 : ulong vote_failed = 0UL;
640 0 : ulong vote_success = 0UL;
641 0 : ulong nonvote_success = 0UL;
642 0 : ulong nonvote_failed = 0UL;
643 :
644 0 : if( FD_LIKELY( gui->summary.slot_tower==ULONG_MAX ) ) return;
645 0 : ulong first_replay_slot = fd_gui_first_replay_slot( gui );
646 0 : for( ulong i=0UL; i<fd_ulong_min( gui->summary.slot_tower+1UL, MAX_SLOTS_PER_EPOCH ); i++ ) {
647 0 : ulong _slot = gui->summary.slot_tower-i;
648 0 : if( FD_UNLIKELY( first_replay_slot!=ULONG_MAX && _slot<first_replay_slot ) ) break;
649 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon( gui, _slot );
650 0 : if( FD_UNLIKELY( !slot ) ) continue;
651 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. */
652 0 : if( FD_UNLIKELY( slot->completed_time+FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS*1000L*1000L*1000L<gui->next_sample_200millis ) ) break; /* Slot too old. */
653 0 : if( FD_UNLIKELY( slot->skip!=FD_GUI_SKIP_STATUS_NOT_SKIPPED ) ) continue; /* Skipped slots don't count to TPS. */
654 0 : if( FD_UNLIKELY( slot->vote_failed==UINT_MAX ) ) continue; /* Slot transaction counts not yet populated. */
655 0 : vote_failed += slot->vote_failed;
656 0 : vote_success += slot->vote_success;
657 0 : nonvote_success += slot->nonvote_success;
658 0 : nonvote_failed += slot->nonvote_failed;
659 0 : }
660 :
661 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].vote_failed = vote_failed;
662 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].vote_success = vote_success;
663 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].nonvote_success = nonvote_success;
664 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].nonvote_failed = nonvote_failed;
665 0 : gui->summary.estimated_tps_history_idx = (gui->summary.estimated_tps_history_idx+1UL) % FD_GUI_TPS_HISTORY_SAMPLE_CNT;
666 0 : }
667 :
668 : static void
669 : fd_gui_network_stats_snap( fd_gui_t * gui,
670 0 : fd_gui_network_stats_t * cur ) {
671 0 : fd_topo_t const * topo = gui->topo;
672 0 : ulong gossvf_tile_cnt = fd_topo_tile_name_cnt( topo, "gossvf" );
673 0 : ulong gossip_tile_cnt = fd_topo_tile_name_cnt( topo, "gossip" );
674 0 : ulong shred_tile_cnt = fd_topo_tile_name_cnt( topo, "shred" );
675 0 : ulong net_tile_cnt = fd_topo_tile_name_cnt( topo, "net" );
676 0 : ulong quic_tile_cnt = fd_topo_tile_name_cnt( topo, "quic" );
677 :
678 0 : cur->in.gossip = fd_gui_metrics_gossip_total_ingress_bytes( topo, gossvf_tile_cnt );
679 0 : cur->out.gossip = fd_gui_metrics_gossip_total_egress_bytes( topo, gossip_tile_cnt );
680 0 : cur->in.turbine = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_TURBINE_RX_BYTES ) );
681 :
682 0 : cur->out.turbine = 0UL;
683 0 : cur->out.repair = 0UL;
684 0 : cur->out.rserve = 0UL;
685 0 : cur->out.tpu = 0UL;
686 0 : for( ulong i=0UL; i<net_tile_cnt; i++ ) {
687 0 : ulong net_tile_idx = fd_topo_find_tile( topo, "net", i );
688 0 : if( FD_UNLIKELY( net_tile_idx==ULONG_MAX ) ) continue;
689 0 : fd_topo_tile_t const * net = &topo->tiles[ net_tile_idx ];
690 0 : for( ulong j=0UL; j<net->in_cnt; j++ ) {
691 0 : if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "shred_net" ) ) ) {
692 0 : cur->out.turbine += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
693 0 : }
694 :
695 0 : if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "repair_net" ) ) ) {
696 0 : cur->out.repair += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
697 0 : }
698 0 : if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "rserve_net" ) ) ) {
699 0 : cur->out.rserve += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
700 0 : }
701 :
702 0 : if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "send_net" ) ) ) {
703 0 : cur->out.tpu += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
704 0 : }
705 0 : }
706 0 : }
707 :
708 0 : cur->in.repair = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_REPAIR_RX_BYTES ) );
709 0 : ulong repair_tile_idx = fd_topo_find_tile( topo, "repair", 0UL );
710 0 : if( FD_LIKELY( repair_tile_idx!=ULONG_MAX ) ) {
711 0 : fd_topo_tile_t const * repair = &topo->tiles[ repair_tile_idx ];
712 :
713 0 : for( ulong i=0UL; i<repair->in_cnt; i++ ) {
714 0 : if( FD_UNLIKELY( !strcmp( topo->links[ repair->in_link_id[ i ] ].name, "net_repair" ) ) ) {
715 0 : cur->in.repair += fd_metrics_link_in( repair->metrics, i )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
716 0 : }
717 0 : }
718 0 : }
719 :
720 0 : cur->in.rserve = 0UL;
721 0 : ulong rserve_tile_idx = fd_topo_find_tile( topo, "rserve", 0UL );
722 0 : if( FD_LIKELY( rserve_tile_idx!=ULONG_MAX ) ) {
723 0 : fd_topo_tile_t const * rserve = &topo->tiles[ rserve_tile_idx ];
724 :
725 0 : for( ulong i=0UL; i<rserve->in_cnt; i++ ) {
726 0 : if( FD_UNLIKELY( !strcmp( topo->links[ rserve->in_link_id[ i ] ].name, "net_rserve" ) ) ) {
727 0 : cur->in.rserve += fd_metrics_link_in( rserve->metrics, i )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
728 0 : }
729 0 : }
730 0 : }
731 :
732 0 : cur->in.tpu = 0UL;
733 0 : for( ulong i=0UL; i<quic_tile_cnt; i++ ) {
734 0 : ulong quic_tile_idx = fd_topo_find_tile( topo, "quic", i );
735 0 : if( FD_UNLIKELY( quic_tile_idx==ULONG_MAX ) ) continue;
736 0 : fd_topo_tile_t const * quic = &topo->tiles[ quic_tile_idx ];
737 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
738 0 : cur->in.tpu += quic_metrics[ MIDX( COUNTER, QUIC, PKT_RX_BYTES ) ];
739 0 : }
740 :
741 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
742 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
743 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
744 0 : volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
745 0 : cur->in.tpu += bundle_metrics[ MIDX( COUNTER, BUNDLE, PROTOBUF_RX_BYTES ) ];
746 0 : }
747 :
748 0 : ulong metric_tile_idx = fd_topo_find_tile( topo, "metric", 0UL );
749 0 : if( FD_LIKELY( metric_tile_idx!=ULONG_MAX ) ) {
750 0 : fd_topo_tile_t const * metric = &topo->tiles[ metric_tile_idx ];
751 0 : volatile ulong * metric_metrics = fd_metrics_tile( metric->metrics );
752 0 : cur->in.metric = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_READ ) ];
753 0 : cur->out.metric = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_WRITTEN ) ];
754 0 : } else {
755 0 : cur->in.metric = 0UL;
756 0 : cur->out.metric = 0UL;
757 0 : }
758 0 : }
759 :
760 : static void
761 : fd_gui_network_rate_max_update( fd_gui_t * gui,
762 0 : long now ) {
763 0 : fd_gui_network_stats_t * cur = gui->summary.network_stats_current;
764 0 : fd_gui_network_stats_t * prev = gui->summary.network_stats_prev;
765 :
766 : /* On the first sample we have no previous value. */
767 0 : if( FD_UNLIKELY( !gui->summary.network_stats_has_prev ) ) {
768 0 : *prev = *cur;
769 0 : gui->summary.network_stats_has_prev = 1;
770 0 : gui->summary.net_rate_prev_ts = now;
771 0 : return;
772 0 : }
773 :
774 0 : ulong d_in[ FD_GUI_NET_PROTO_CNT ];
775 0 : d_in[ 0 ] = fd_ulong_sat_sub( cur->in.turbine, prev->in.turbine );
776 0 : d_in[ 1 ] = fd_ulong_sat_sub( cur->in.gossip, prev->in.gossip );
777 0 : d_in[ 2 ] = fd_ulong_sat_sub( cur->in.tpu, prev->in.tpu );
778 0 : d_in[ 3 ] = fd_ulong_sat_sub( cur->in.repair, prev->in.repair );
779 0 : d_in[ 4 ] = fd_ulong_sat_sub( cur->in.rserve, prev->in.rserve );
780 0 : d_in[ 5 ] = fd_ulong_sat_sub( cur->in.metric, prev->in.metric );
781 :
782 0 : ulong d_out[ FD_GUI_NET_PROTO_CNT ];
783 0 : d_out[ 0 ] = fd_ulong_sat_sub( cur->out.turbine, prev->out.turbine );
784 0 : d_out[ 1 ] = fd_ulong_sat_sub( cur->out.gossip, prev->out.gossip );
785 0 : d_out[ 2 ] = fd_ulong_sat_sub( cur->out.tpu, prev->out.tpu );
786 0 : d_out[ 3 ] = fd_ulong_sat_sub( cur->out.repair, prev->out.repair );
787 0 : d_out[ 4 ] = fd_ulong_sat_sub( cur->out.rserve, prev->out.rserve );
788 0 : d_out[ 5 ] = fd_ulong_sat_sub( cur->out.metric, prev->out.metric );
789 :
790 : /* Compute per-protocol instantaneous bytes/sec rate and feed the EMA. */
791 0 : long dt_ns = now - gui->summary.net_rate_prev_ts;
792 0 : if( FD_LIKELY( dt_ns>0L ) ) {
793 0 : double dt_sec = (double)dt_ns / 1.0e9;
794 :
795 0 : for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) {
796 0 : double rate_in = (double)d_in[ i ] / dt_sec;
797 0 : double rate_out = (double)d_out[ i ] / dt_sec;
798 :
799 0 : fd_gui_ema_advance( &gui->summary.ingress_ema[ i ], now, rate_in );
800 0 : fd_gui_ema_advance( &gui->summary.egress_ema [ i ], now, rate_out );
801 0 : }
802 0 : }
803 0 : gui->summary.net_rate_prev_ts = now;
804 :
805 : /* Track max total EMA in a rolling 5-minute window using monotonic
806 : deques.
807 :
808 : Invariant: deque entries are strictly decreasing in value from
809 : head to tail. The head is always the current window maximum.
810 :
811 : Insert: pop tail entries whose value <= new value (they can
812 : never become the maximum), then push the new entry.
813 : Expire: pop head entries older than 5 minutes. */
814 0 : if( FD_LIKELY( gui->summary.ingress_ema[ 0 ].last_update_nanos ) ) {
815 0 : double sum_in = 0.0;
816 0 : double sum_out = 0.0;
817 0 : for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) {
818 0 : sum_in += gui->summary.ingress_ema[ i ].value;
819 0 : sum_out += gui->summary.egress_ema[ i ].value;
820 0 : }
821 :
822 0 : while( !fd_gui_rate_deque_empty( gui->summary.ingress_maxq ) && fd_gui_rate_deque_peek_head_const( gui->summary.ingress_maxq )->ts_nanos<now-FD_GUI_NET_RATE_MAX_WINDOW_NS ) {
823 0 : fd_gui_rate_deque_pop_head( gui->summary.ingress_maxq );
824 0 : }
825 0 : while( !fd_gui_rate_deque_empty( gui->summary.ingress_maxq ) && fd_gui_rate_deque_peek_tail_const( gui->summary.ingress_maxq )->value<=sum_in ) {
826 0 : fd_gui_rate_deque_pop_tail( gui->summary.ingress_maxq );
827 0 : }
828 0 : if( FD_UNLIKELY( fd_gui_rate_deque_full( gui->summary.ingress_maxq ) ) ) {
829 0 : fd_gui_rate_deque_pop_tail( gui->summary.ingress_maxq );
830 0 : }
831 0 : fd_gui_rate_deque_push_tail( gui->summary.ingress_maxq, (fd_gui_rate_entry_t){ .ts_nanos=now, .value=sum_in } );
832 :
833 0 : while( !fd_gui_rate_deque_empty( gui->summary.egress_maxq ) && fd_gui_rate_deque_peek_head_const( gui->summary.egress_maxq )->ts_nanos<now-FD_GUI_NET_RATE_MAX_WINDOW_NS ) {
834 0 : fd_gui_rate_deque_pop_head( gui->summary.egress_maxq );
835 0 : }
836 0 : while( !fd_gui_rate_deque_empty( gui->summary.egress_maxq ) && fd_gui_rate_deque_peek_tail_const( gui->summary.egress_maxq )->value<=sum_out ) {
837 0 : fd_gui_rate_deque_pop_tail( gui->summary.egress_maxq );
838 0 : }
839 0 : if( FD_UNLIKELY( fd_gui_rate_deque_full( gui->summary.egress_maxq ) ) ) {
840 0 : fd_gui_rate_deque_pop_tail( gui->summary.egress_maxq );
841 0 : }
842 0 : fd_gui_rate_deque_push_tail( gui->summary.egress_maxq, (fd_gui_rate_entry_t){ .ts_nanos=now, .value=sum_out } );
843 0 : }
844 :
845 0 : *prev = *cur;
846 0 : }
847 :
848 : /* Snapshot accdb statistics by reading the accdb tile's metric page
849 : (for gauges) and summing counters across all tiles that join accdb
850 : (executors, replay, tower, rpc, resolv, plus the accdb tile itself).
851 : The result feeds the GUI "Accounts" page. */
852 :
853 : static void
854 : fd_gui_accounts_stats_snap( fd_gui_t * gui,
855 0 : fd_gui_accounts_stats_t * cur ) {
856 0 : fd_topo_t const * topo = gui->topo;
857 :
858 0 : memset( cur, 0, sizeof(*cur) );
859 0 : cur->sample_time_nanos = fd_log_wallclock();
860 :
861 0 : ulong accdb_tile_idx = fd_topo_find_tile( topo, "accdb", 0UL );
862 0 : if( FD_UNLIKELY( accdb_tile_idx==ULONG_MAX ) ) return;
863 :
864 : /* Gauges + accdb-tile-only counters. */
865 0 : fd_topo_tile_t const * accdb = &topo->tiles[ accdb_tile_idx ];
866 0 : volatile ulong const * am = fd_metrics_tile( accdb->metrics );
867 :
868 0 : cur->accounts_total = am[ MIDX( GAUGE, ACCDB, ACCOUNT_COUNT ) ];
869 0 : cur->accounts_capacity = am[ MIDX( GAUGE, ACCDB, ACCOUNT_CAPACITY ) ];
870 0 : cur->disk_allocated_bytes = am[ MIDX( GAUGE, ACCDB, DISK_ALLOCATED_BYTES ) ];
871 0 : cur->disk_current_bytes = am[ MIDX( GAUGE, ACCDB, DISK_CURRENT_BYTES ) ];
872 0 : cur->disk_used_bytes = am[ MIDX( GAUGE, ACCDB, DISK_USED_BYTES ) ];
873 0 : cur->in_compaction = am[ MIDX( GAUGE, ACCDB, IN_COMPACTION ) ];
874 0 : cur->compactions_requested = am[ MIDX( COUNTER, ACCDB, COMPACTION_REQUESTED ) ];
875 0 : cur->compactions_completed = am[ MIDX( COUNTER, ACCDB, COMPACTION_COMPLETED ) ];
876 0 : cur->accounts_relocated_bytes = am[ MIDX( COUNTER, ACCDB, ACCOUNT_RELOCATED_BYTES ) ];
877 0 : cur->bytes_written_accdb = am[ MIDX( COUNTER, ACCDB, BYTES_WRITTEN ) ];
878 :
879 : /* The accdb tile owns the prewrite and compaction writes; include
880 : those in the aggregate bytes_written / write_ops so the IO panel
881 : reflects all on-disk write activity, not just consumer-driven
882 : commits. */
883 0 : cur->bytes_written += am[ MIDX( COUNTER, ACCDB, BYTES_WRITTEN ) ];
884 0 : cur->write_ops += am[ MIDX( COUNTER, ACCDB, WRITE_OPERATION ) ];
885 :
886 0 : for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {
887 0 : cur->cache_class_used [ c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_USED ) + c ];
888 0 : cur->cache_class_max [ c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_MAX ) + c ];
889 0 : cur->cache_class_reserved [ c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_RESERVED ) + c ];
890 0 : cur->cache_class_target_used [ c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_TARGET_USED ) + c ];
891 0 : cur->cache_class_low_water_used[c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_LOW_WATER_USED ) + c ];
892 0 : cur->preevicted_per_class [ c ] = am[ MIDX( COUNTER, ACCDB, ACCOUNT_PREEVICTED ) + c ];
893 0 : }
894 :
895 : /* Walk the per-tile slot table built at init. Each slot reads its
896 : tile's accdb counters according to its kind (RW, RO, or SNAPWR),
897 : accumulates into the aggregate (cur->*), and stashes the per-tile
898 : cumulative values into gui->summary.accdb->tile_cur_* for the
899 : per-tile rate window pushes done later in
900 : fd_gui_printf_accounts_stats. */
901 0 : for( ulong s=0UL; s<gui->summary.accdb->accdb_tile_cnt; s++ ) {
902 0 : ulong t_idx = (ulong)gui->summary.accdb->accdb_tile_topo_idx[ s ];
903 0 : uchar kind = gui->summary.accdb->accdb_tile_kind[ s ];
904 0 : volatile ulong const * m = fd_metrics_tile( topo->tiles[ t_idx ].metrics );
905 :
906 0 : gui->summary.accdb->tile_cur_status[ s ] = (uchar)m[ MIDX( GAUGE, TILE, STATUS ) ];
907 :
908 0 : ulong t_acq=0UL, t_acw=0UL, t_misses=0UL, t_evicted=0UL, t_committed=0UL;
909 0 : ulong t_bytes_read=0UL, t_bytes_copied=0UL, t_bytes_written=0UL;
910 0 : ulong t_read_ops=0UL, t_write_ops=0UL;
911 0 : ulong t_acquire_calls=0UL;
912 :
913 0 : switch( kind ) {
914 0 : # define DO_RW( TILE_UPPER ) \
915 0 : t_bytes_read = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BYTES_READ ) ]; \
916 0 : t_bytes_copied = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BYTES_COPIED ) ]; \
917 0 : t_bytes_written = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BYTES_WRITTEN ) ]; \
918 0 : t_read_ops = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_READ_OPERATION ) ]; \
919 0 : t_write_ops = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_WRITE_OPERATION ) ]; \
920 0 : t_acquire_calls = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BATCH_ACQUIRED ) ]; \
921 0 : for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) { \
922 0 : ulong _acq = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_ACQUIRED ) + c ]; \
923 0 : ulong _acw = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_WRITABLE_ACQUIRED ) + c ]; \
924 0 : ulong _nf = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_NOT_FOUND ) + c ]; \
925 0 : ulong _ev = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_EVICTED ) + c ]; \
926 0 : ulong _cn = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_COMMITTED_NEW ) + c ]; \
927 0 : ulong _co = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_COMMITTED_OVERWRITE ) + c ]; \
928 0 : t_acq+=_acq; t_acw+=_acw; t_misses+=_nf; t_evicted+=_ev; t_committed+=_cn+_co; \
929 0 : cur->acquired_per_class [ c ] += _acq; \
930 0 : cur->acquired_writable_per_class [ c ] += _acw; \
931 0 : cur->not_found_per_class [ c ] += _nf; \
932 0 : cur->evicted_per_class [ c ] += _ev; \
933 0 : cur->committed_new_per_class [ c ] += _cn; \
934 0 : cur->committed_overwrite_per_class [ c ] += _co; \
935 0 : }
936 0 : case FD_GUI_ACCDB_TILE_KIND_RW:
937 0 : if( !strcmp( topo->tiles[ t_idx ].name, "execle" ) ) { DO_RW( EXECLE ); }
938 0 : else if( !strcmp( topo->tiles[ t_idx ].name, "execrp" ) ) { DO_RW( EXECRP ); }
939 0 : else if( !strcmp( topo->tiles[ t_idx ].name, "replay" ) ) { DO_RW( REPLAY ); }
940 0 : else if( !strcmp( topo->tiles[ t_idx ].name, "tower" ) ) { DO_RW( TOWER ); }
941 0 : cur->acquired += t_acq;
942 0 : cur->acquired_writable += t_acw;
943 0 : cur->bytes_read += t_bytes_read;
944 0 : cur->bytes_copied += t_bytes_copied;
945 0 : cur->bytes_written += t_bytes_written;
946 0 : cur->read_ops += t_read_ops;
947 0 : cur->write_ops += t_write_ops;
948 0 : break;
949 0 : # undef DO_RW
950 :
951 0 : # define DO_RO( TILE_UPPER ) \
952 0 : t_bytes_read = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BYTES_READ ) ]; \
953 0 : t_bytes_copied = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BYTES_COPIED ) ]; \
954 0 : t_read_ops = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_READ_OPERATION ) ]; \
955 0 : t_acquire_calls = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BATCH_ACQUIRED ) ]; \
956 0 : for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) { \
957 0 : ulong _acq = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_ACQUIRED ) + c ]; \
958 0 : ulong _nf = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_NOT_FOUND ) + c ]; \
959 0 : t_acq+=_acq; t_misses+=_nf; \
960 0 : cur->acquired_per_class [ c ] += _acq; \
961 0 : cur->not_found_per_class[ c ] += _nf; \
962 0 : }
963 0 : case FD_GUI_ACCDB_TILE_KIND_RO:
964 0 : if( !strcmp( topo->tiles[ t_idx ].name, "rpc" ) ) { DO_RO( RPC ); }
965 0 : else if( !strcmp( topo->tiles[ t_idx ].name, "resolv" ) ) { DO_RO( RESOLV ); }
966 0 : cur->acquired += t_acq;
967 0 : cur->bytes_read += t_bytes_read;
968 0 : cur->bytes_copied += t_bytes_copied;
969 0 : cur->read_ops += t_read_ops;
970 0 : break;
971 0 : # undef DO_RO
972 :
973 0 : case FD_GUI_ACCDB_TILE_KIND_SNAPWR:
974 : /* snapwr writes account data to disk directly during snapshot
975 : load. It does not declare the accdb counter surface, only a
976 : BytesWritten gauge. Include in the aggregate so the IO panel
977 : reflects load-time disk activity. */
978 0 : t_bytes_written = m[ MIDX( GAUGE, SNAPWR, BYTES_WRITTEN ) ];
979 0 : cur->bytes_written += t_bytes_written;
980 0 : break;
981 :
982 0 : case FD_GUI_ACCDB_TILE_KIND_ACCDB:
983 : /* The accdb tile owns prewrite and compaction writes. Its own
984 : bytes_written/write_ops were already folded into the aggregate
985 : above (see ACCDB_BYTES_WRITTEN / ACCDB_WRITE_OPS reads). Here
986 : we only stash per-slot values so the per-tile row reflects
987 : them; do not re-add to cur->* or we'd double-count. The accdb
988 : tile does not expose acquired/not_found/committed (no account
989 : joiner) or read_ops/bytes_copied. Preevicts are owned by the
990 : accdb tile's background preevict pass, so map them to the
991 : per-tile evicted column for this row. */
992 0 : t_bytes_read = m[ MIDX( COUNTER, ACCDB, BYTES_READ ) ];
993 0 : t_bytes_written = m[ MIDX( COUNTER, ACCDB, BYTES_WRITTEN ) ];
994 0 : t_write_ops = m[ MIDX( COUNTER, ACCDB, WRITE_OPERATION ) ];
995 0 : for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {
996 0 : t_evicted += m[ MIDX( COUNTER, ACCDB, ACCOUNT_PREEVICTED ) + c ];
997 0 : }
998 0 : break;
999 0 : }
1000 :
1001 0 : gui->summary.accdb->tile_cur_acquired [ s ] = t_acq;
1002 0 : gui->summary.accdb->tile_cur_acquired_writable[ s ] = t_acw;
1003 0 : gui->summary.accdb->tile_cur_bytes_read [ s ] = t_bytes_read;
1004 0 : gui->summary.accdb->tile_cur_bytes_copied [ s ] = t_bytes_copied;
1005 0 : gui->summary.accdb->tile_cur_bytes_written [ s ] = t_bytes_written;
1006 0 : gui->summary.accdb->tile_cur_read_ops [ s ] = t_read_ops;
1007 0 : gui->summary.accdb->tile_cur_write_ops [ s ] = t_write_ops;
1008 0 : gui->summary.accdb->tile_cur_misses [ s ] = t_misses;
1009 0 : gui->summary.accdb->tile_cur_evicted [ s ] = t_evicted;
1010 0 : gui->summary.accdb->tile_cur_committed [ s ] = t_committed;
1011 0 : gui->summary.accdb->tile_cur_acquire_calls [ s ] = t_acquire_calls;
1012 0 : }
1013 :
1014 0 : if( FD_UNLIKELY( !gui->accdb_shmem ) ) return;
1015 :
1016 : /* Snapshot per-partition utilization and fragmentation and also
1017 : their respective per-tier rate of growth. Actively-compacting
1018 : partitions excluded so relocation churn does not degrade estimates. */
1019 0 : ulong pcnt = fd_ulong_min( fd_accdb_shmem_partition_max( gui->accdb_shmem ), FD_GUI_MAX_PARTITIONS );
1020 0 : gui->summary.accdb->partition_cnt = pcnt;
1021 :
1022 0 : double tier_fill_delta[ FD_ACCDB_COMPACTION_LAYER_CNT ] = { 0.0 };
1023 0 : double tier_free_delta[ FD_ACCDB_COMPACTION_LAYER_CNT ] = { 0.0 };
1024 0 : ulong compaction_idx = ULONG_MAX;
1025 0 : ulong compaction_layer = FD_ACCDB_COMPACTION_LAYER_CNT;
1026 0 : ulong compaction_state = 0UL;
1027 0 : for( ulong p=0UL; p<pcnt; p++ ) {
1028 0 : fd_accdb_shmem_partition_info_t prev_info = gui->summary.accdb->partitions[ p ];
1029 0 : fd_accdb_shmem_partition_info_t * info = &gui->summary.accdb->partitions[ p ];
1030 0 : fd_accdb_shmem_partition_info( gui->accdb_shmem, p, info );
1031 :
1032 0 : if( FD_UNLIKELY( info->compaction_state && ( compaction_state<info->compaction_state || ( compaction_state==info->compaction_state && info->layer<compaction_layer ) ) ) ) {
1033 0 : compaction_idx = p;
1034 0 : compaction_layer = info->layer;
1035 0 : compaction_state = info->compaction_state;
1036 0 : }
1037 :
1038 0 : if( FD_LIKELY( info->layer<FD_ACCDB_COMPACTION_LAYER_CNT ) ) {
1039 : /* Only the <=3 write-head partitions advance, and freed bytes
1040 : land in a handful of partitions per 100ms snap. */
1041 0 : if( FD_UNLIKELY( info->write_offset>prev_info.write_offset ) )
1042 0 : tier_fill_delta[ info->layer ] += (double)(info->write_offset-prev_info.write_offset);
1043 0 : if( FD_UNLIKELY( info->compaction_state!=2 && info->bytes_freed>prev_info.bytes_freed ) )
1044 0 : tier_free_delta[ info->layer ] += (double)(info->bytes_freed-prev_info.bytes_freed);
1045 0 : }
1046 0 : }
1047 :
1048 : /* First snap has no valid deltas. */
1049 0 : if( FD_LIKELY( gui->summary.accdb->tier_sample_nanos!=LONG_MAX ) ) {
1050 0 : double dt_sec = (double)(cur->sample_time_nanos-gui->summary.accdb->tier_sample_nanos)/1e9;
1051 0 : if( FD_LIKELY( dt_sec>0.0 ) ) {
1052 0 : for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
1053 0 : fd_gui_ema_advance( &gui->summary.accdb->tier_fill_bps_ema[ k ], cur->sample_time_nanos, tier_fill_delta[ k ]/dt_sec );
1054 0 : fd_gui_ema_advance( &gui->summary.accdb->tier_free_bps_ema[ k ], cur->sample_time_nanos, tier_free_delta[ k ]/dt_sec );
1055 0 : }
1056 0 : }
1057 0 : }
1058 0 : gui->summary.accdb->tier_sample_nanos = cur->sample_time_nanos;
1059 :
1060 : /* Estimate next compaction time/partition. */
1061 0 : double next_secs = 0.0;
1062 0 : ulong next_idx = ULONG_MAX;
1063 0 : double partition_sz = (double)fd_accdb_shmem_partition_sz( gui->accdb_shmem );
1064 0 : double tier_live_bytes[ FD_ACCDB_COMPACTION_LAYER_CNT ] = { 0.0 };
1065 0 : for( ulong p=0UL; p<pcnt; p++ ) {
1066 0 : fd_accdb_shmem_partition_info_t const * info = &gui->summary.accdb->partitions[ p ];
1067 0 : if( info->layer<FD_ACCDB_COMPACTION_LAYER_CNT && info->compaction_state!=2 && info->write_offset>info->bytes_freed && info->compaction_offset<info->write_offset )
1068 0 : tier_live_bytes[ info->layer ] += (double)(info->write_offset-info->bytes_freed);
1069 0 : }
1070 0 : for( ulong p=0UL; p<pcnt; p++ ) {
1071 0 : fd_accdb_shmem_partition_info_t const * info = &gui->summary.accdb->partitions[ p ];
1072 0 : if( FD_LIKELY( info->compaction_state || !info->write_offset ) ) continue;
1073 0 : if( FD_UNLIKELY( info->layer>=FD_ACCDB_COMPACTION_LAYER_CNT ) ) continue;
1074 0 : if( FD_UNLIKELY( info->compaction_offset>=info->write_offset ) ) continue; /* compacted, awaiting reclaim */
1075 :
1076 0 : double free_bps = gui->summary.accdb->tier_free_bps_ema[ info->layer ].value;
1077 0 : double live = info->write_offset>info->bytes_freed ? (double)(info->write_offset-info->bytes_freed) : 0.0;
1078 0 : double frag_rate = tier_live_bytes[ info->layer ]>0.0 ? free_bps*live/tier_live_bytes[ info->layer ] : 0.0;
1079 0 : double deficit = (double)FD_ACCDB_COMPACTION_THRESHOLD_PCT/100.0*partition_sz - (double)info->bytes_freed;
1080 0 : double frag_secs = deficit<=0.0 ? 0.0 : ( frag_rate>0.0 ? deficit/frag_rate : -1.0 );
1081 0 : double fill_secs = 0.0;
1082 0 : if( FD_UNLIKELY( info->is_write_head ) ) {
1083 0 : double fill_bps = gui->summary.accdb->tier_fill_bps_ema[ info->layer ].value;
1084 0 : fill_secs = fill_bps>0.0 ? (partition_sz-(double)info->write_offset)/fill_bps : -1.0;
1085 0 : }
1086 :
1087 0 : if( FD_UNLIKELY( frag_secs<0.0 || fill_secs<0.0 ) ) continue; /* no usable rate estimate (EMA warm-up) */
1088 0 : double est = fmax( frag_secs, fill_secs );
1089 0 : if( next_idx==ULONG_MAX || est<next_secs ) {
1090 0 : next_secs = est;
1091 0 : next_idx = p;
1092 0 : }
1093 0 : }
1094 :
1095 0 : int has_compaction = compaction_idx!=ULONG_MAX;
1096 0 : gui->summary.accdb->next_compaction_remaining_secs = fd_double_if( has_compaction, 0.0, next_secs );
1097 0 : gui->summary.accdb->next_compaction_partition_idx = fd_ulong_if( has_compaction, compaction_idx, next_idx );
1098 0 : }
1099 :
1100 : /* Snapshot all of the data from metrics to construct a view of the
1101 : transaction waterfall.
1102 :
1103 : Tiles are sampled in reverse pipeline order: this helps prevent data
1104 : discrepancies where a later tile has "seen" more transactions than an
1105 : earlier tile, which shouldn't typically happen. */
1106 :
1107 : static void
1108 : fd_gui_txn_waterfall_snap( fd_gui_t * gui,
1109 0 : fd_gui_txn_waterfall_t * cur ) {
1110 0 : memset( cur, 0, sizeof(fd_gui_txn_waterfall_t) );
1111 0 : fd_topo_t const * topo = gui->topo;
1112 :
1113 0 : for( ulong i=0UL; i<gui->summary.bank_tile_cnt; i++ ) {
1114 0 : fd_topo_tile_t const * bank = &topo->tiles[ fd_topo_find_tile( topo, "bank", i ) ];
1115 :
1116 0 : volatile ulong const * bank_metrics = fd_metrics_tile( bank->metrics );
1117 0 : cur->out.block_success += bank_metrics[ MIDX( COUNTER, BANK, TXN_EXECUTED_SUCCESS ) ];
1118 :
1119 0 : cur->out.block_fail +=
1120 0 : bank_metrics[ MIDX( COUNTER, BANK, TXN_EXECUTED_FAILED ) ]
1121 0 : + bank_metrics[ MIDX( COUNTER, BANK, TXN_FEE_ONLY ) ];
1122 :
1123 0 : cur->out.bank_invalid +=
1124 0 : bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_ACCOUNT_UNINITIALIZED ) ]
1125 0 : + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_ACCOUNT_NOT_FOUND ) ]
1126 0 : + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_INVALID_ACCOUNT_OWNER ) ]
1127 0 : + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_INVALID_ACCOUNT_DATA ) ]
1128 0 : + bank_metrics[ MIDX( COUNTER, BANK, TXN_LOAD_ADDRESS_TABLE_INVALID_LOOKUP_INDEX ) ];
1129 :
1130 0 : cur->out.bank_invalid +=
1131 0 : bank_metrics[ MIDX( COUNTER, BANK, TXN_PROCESSING_FAILED ) ];
1132 0 : }
1133 :
1134 0 : for( ulong i=0UL; i<gui->summary.execle_tile_cnt; i++ ) {
1135 0 : fd_topo_tile_t const * execle = &topo->tiles[ fd_topo_find_tile( topo, "execle", i ) ];
1136 :
1137 0 : volatile ulong const * execle_metrics = fd_metrics_tile( execle->metrics );
1138 :
1139 0 : cur->out.block_success += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_LANDED_SUCCESS ) ];
1140 0 : cur->out.block_fail +=
1141 0 : execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_LANDED_FEES_ONLY ) ]
1142 0 : + execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_LANDED_FAILED ) ];
1143 0 : cur->out.bank_invalid += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_LANDED_UNLANDED ) ];
1144 :
1145 0 : cur->out.bank_nonce_already_advanced += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_RESULT_NONCE_ALREADY_ADVANCED ) ];
1146 0 : cur->out.bank_nonce_advance_failed += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_RESULT_NONCE_ADVANCE_FAILED ) ];
1147 0 : cur->out.bank_nonce_wrong_blockhash += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_RESULT_NONCE_WRONG_BLOCKHASH ) ];
1148 0 : }
1149 :
1150 0 : ulong pack_tile_idx = fd_topo_find_tile( topo, "pack", 0UL );
1151 0 : if( pack_tile_idx!=ULONG_MAX ) {
1152 0 : fd_topo_tile_t const * pack = &topo->tiles[ pack_tile_idx ];
1153 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
1154 :
1155 0 : cur->out.pack_invalid_bundle =
1156 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_PARTIAL_BUNDLE ) ]
1157 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTION_FAILED ) ]
1158 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_CREATION_FAILED ) ];
1159 :
1160 0 : cur->out.pack_invalid =
1161 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_INSTR_ACCT_CNT ) ]
1162 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_NONCE_CONFLICT ) ]
1163 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_BUNDLE_BLACKLIST ) ]
1164 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_INVALID_NONCE ) ]
1165 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_WRITE_SYSVAR ) ]
1166 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_ESTIMATION_FAIL ) ]
1167 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_DUPLICATE_ACCOUNT ) ]
1168 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_TOO_MANY_ACCOUNTS ) ]
1169 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_TOO_LARGE ) ]
1170 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_ADDR_LUT ) ]
1171 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_UNAFFORDABLE ) ]
1172 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_DUPLICATE ) ]
1173 0 : - pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTION_FAILED ) ]; /* so we don't double count this, since its already accounted for in invalid_bundle */
1174 :
1175 0 : cur->out.pack_expired = pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_EXPIRED ) ] +
1176 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_EXPIRED ) ] +
1177 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_DELETED ) ] +
1178 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_NONCE_PRIORITY ) ];
1179 :
1180 0 : cur->out.pack_already_executed = pack_metrics[ MIDX( COUNTER, PACK, TXN_ALREADY_EXECUTED ) ];
1181 :
1182 0 : cur->out.pack_leader_slow = pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERTED_PRIORITY ) ];
1183 :
1184 0 : cur->out.pack_wait_full =
1185 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_DROPPED ) ];
1186 :
1187 0 : cur->out.pack_retained = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE ) ];
1188 :
1189 0 : ulong inserted_to_extra = pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_INSERTED ) ];
1190 0 : ulong inserted_from_extra = pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_RETRIEVED ) ]
1191 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_EXTRA_DROPPED ) ];
1192 0 : cur->out.pack_retained += fd_ulong_if( inserted_to_extra>=inserted_from_extra, inserted_to_extra-inserted_from_extra, 0UL );
1193 :
1194 0 : cur->in.pack_cranked =
1195 0 : pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTED ) ]
1196 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_INSERTION_FAILED ) ]
1197 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_RESULT_CREATION_FAILED ) ];
1198 0 : }
1199 :
1200 0 : for( ulong i=0UL; i<gui->summary.resolh_tile_cnt; i++ ) {
1201 0 : fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolh", i ) ];
1202 0 : volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
1203 :
1204 0 : cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLH, TXN_NO_BANK ) ];
1205 0 : cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLH, BLOCKHASH_EXPIRED ) ]
1206 0 : + resolv_metrics[ MIDX( COUNTER, RESOLH, TXN_BUNDLE_PEER_FAILED ) ];
1207 0 : cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
1208 0 : + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
1209 0 : + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
1210 0 : + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
1211 0 : + resolv_metrics[ MIDX( COUNTER, RESOLH, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
1212 0 : cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_OVERRUN ) ];
1213 :
1214 0 : ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_INSERTED ) ];
1215 0 : ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_OVERRUN ) ]
1216 0 : + resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_PUBLISHED ) ]
1217 0 : + resolv_metrics[ MIDX( COUNTER, RESOLH, STASH_OPERATION_REMOVED ) ];
1218 0 : cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
1219 0 : }
1220 :
1221 0 : for( ulong i=0UL; i<gui->summary.resolv_tile_cnt; i++ ) {
1222 0 : fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolv", i ) ];
1223 0 : volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
1224 :
1225 0 : cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_NO_BANK ) ];
1226 0 : cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLV, BLOCKHASH_EXPIRED ) ]
1227 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_BUNDLE_PEER_FAILED ) ];
1228 0 : cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
1229 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
1230 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
1231 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
1232 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
1233 0 : cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ];
1234 :
1235 0 : ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_INSERTED ) ];
1236 0 : ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ]
1237 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_PUBLISHED ) ]
1238 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_REMOVED ) ];
1239 0 : cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
1240 0 : }
1241 :
1242 0 : ulong dedup_tile_idx = fd_topo_find_tile( topo, "dedup", 0UL );
1243 0 : if( FD_UNLIKELY( dedup_tile_idx!=ULONG_MAX ) ) {
1244 0 : fd_topo_tile_t const * dedup = &topo->tiles[ dedup_tile_idx ];
1245 0 : volatile ulong const * dedup_metrics = fd_metrics_tile( dedup->metrics );
1246 :
1247 0 : cur->out.dedup_duplicate = dedup_metrics[ MIDX( COUNTER, DEDUP, TXN_RESULT_DEDUP_FAILURE ) ]
1248 0 : + dedup_metrics[ MIDX( COUNTER, DEDUP, TXN_RESULT_BUNDLE_PEER_FAILURE ) ];
1249 0 : }
1250 :
1251 0 : for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
1252 0 : fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
1253 0 : volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
1254 :
1255 0 : for( ulong j=0UL; j<gui->summary.quic_tile_cnt; j++ ) {
1256 : /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this verify tile. */
1257 0 : cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_POLLING_OVERRUN_OFF ] / gui->summary.verify_tile_cnt;
1258 0 : cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_READING_OVERRUN_OFF ];
1259 0 : }
1260 :
1261 0 : cur->out.verify_failed += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_VERIFY_FAILURE ) ] +
1262 0 : verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_BUNDLE_PEER_FAILURE ) ];
1263 0 : cur->out.verify_parse += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_PARSE_FAILURE ) ];
1264 0 : cur->out.verify_duplicate += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_RESULT_DEDUP_FAILURE ) ];
1265 0 : }
1266 :
1267 0 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
1268 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
1269 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
1270 :
1271 0 : cur->out.tpu_udp_invalid += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_UNDERSIZE ) ];
1272 0 : cur->out.tpu_udp_invalid += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_OVERSIZE ) ];
1273 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_UNDERSIZE ) ];
1274 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_OVERSIZE ) ];
1275 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, TXN_OVERSIZE ) ];
1276 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_CRYPTO_FAILED ) ];
1277 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NO_CONN ) ];
1278 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_SRC_INVALID ) ];
1279 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NET_HEADER_INVALID ) ];
1280 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_HEADER_INVALID ) ];
1281 0 : cur->out.quic_abandoned += quic_metrics[ MIDX( COUNTER, QUIC, TXN_ABANDONED ) ];
1282 0 : cur->out.quic_frag_drop += quic_metrics[ MIDX( COUNTER, QUIC, TXN_OVERRUN ) ];
1283 :
1284 0 : for( ulong j=0UL; j<gui->summary.net_tile_cnt; j++ ) {
1285 : /* TODO: Not precise... net frags that were skipped might not have been destined for QUIC tile */
1286 : /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this QUIC tile */
1287 0 : cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_POLLING_OVERRUN_OFF ] / gui->summary.quic_tile_cnt;
1288 0 : cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_READING_OVERRUN_OFF ];
1289 0 : }
1290 0 : }
1291 :
1292 0 : for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
1293 0 : fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
1294 0 : volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
1295 :
1296 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_RING_FULL ) ];
1297 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_OTHER_DROPPED ) ];
1298 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_FILL_RING_EMPTY ) ];
1299 0 : }
1300 :
1301 0 : ulong bundle_txns_received = 0UL;
1302 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
1303 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
1304 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
1305 0 : volatile ulong const * bundle_metrics = fd_metrics_tile( bundle->metrics );
1306 :
1307 0 : bundle_txns_received = bundle_metrics[ MIDX( COUNTER, BUNDLE, TXN_RX ) ];
1308 0 : }
1309 :
1310 0 : {
1311 0 : cur->in.gossip = 0UL;
1312 0 : for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
1313 0 : fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
1314 0 : volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
1315 0 : cur->in.gossip += verify_metrics[ MIDX( COUNTER, VERIFY, VOTE_GOSSIP_RX ) ];
1316 0 : }
1317 0 : }
1318 :
1319 0 : cur->in.quic = cur->out.tpu_quic_invalid +
1320 0 : cur->out.quic_overrun +
1321 0 : cur->out.quic_frag_drop +
1322 0 : cur->out.quic_abandoned +
1323 0 : cur->out.net_overrun;
1324 0 : cur->in.udp = cur->out.tpu_udp_invalid;
1325 0 : cur->in.block_engine = bundle_txns_received;
1326 0 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
1327 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
1328 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
1329 :
1330 0 : cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_QUIC_FAST ) ];
1331 0 : cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_QUIC_FRAG ) ];
1332 0 : cur->in.udp += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_UDP ) ];
1333 0 : }
1334 0 : }
1335 :
1336 : static void
1337 : fd_gui_tile_stats_snap( fd_gui_t * gui,
1338 : fd_gui_txn_waterfall_t const * waterfall,
1339 : fd_gui_tile_stats_t * stats,
1340 0 : long now ) {
1341 0 : memset( stats, 0, sizeof(fd_gui_tile_stats_t) );
1342 0 : fd_topo_t const * topo = gui->topo;
1343 :
1344 0 : stats->sample_time_nanos = now;
1345 :
1346 0 : for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
1347 0 : fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
1348 0 : volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
1349 :
1350 0 : stats->net_in_rx_bytes += net_metrics[ MIDX( COUNTER, NET, PKT_RX_BYTES ) ];
1351 0 : stats->net_out_tx_bytes += net_metrics[ MIDX( COUNTER, NET, PKT_TX_BYTES ) ];
1352 0 : }
1353 :
1354 0 : for( ulong i=0UL; i<gui->summary.sock_tile_cnt; i++ ) {
1355 0 : fd_topo_tile_t const * sock = &topo->tiles[ fd_topo_find_tile( topo, "sock", i ) ];
1356 0 : volatile ulong * sock_metrics = fd_metrics_tile( sock->metrics );
1357 :
1358 0 : stats->net_in_rx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, PKT_RX_BYTES ) ];
1359 0 : stats->net_out_tx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, PKT_TX_BYTES ) ];
1360 0 : }
1361 :
1362 0 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
1363 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
1364 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
1365 :
1366 0 : stats->quic_conn_cnt += quic_metrics[ MIDX( GAUGE, QUIC, CONN_IN_USE ) ];
1367 0 : }
1368 :
1369 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
1370 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
1371 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
1372 0 : volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
1373 0 : stats->bundle_rtt_smoothed_nanos = bundle_metrics[ MIDX( GAUGE, BUNDLE, RTT_SMOOTHED_NANOS ) ];
1374 :
1375 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 ) );
1376 0 : stats->bundle_rx_delay_hist.sum = bundle_metrics[ MIDX( HISTOGRAM, BUNDLE, MESSAGE_RX_DELAY_NANOS ) + FD_HISTF_BUCKET_CNT ];
1377 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 ];
1378 0 : }
1379 :
1380 0 : stats->verify_drop_cnt = waterfall->out.verify_duplicate +
1381 0 : waterfall->out.verify_parse +
1382 0 : waterfall->out.verify_failed;
1383 0 : stats->verify_total_cnt = waterfall->in.gossip +
1384 0 : waterfall->in.quic +
1385 0 : waterfall->in.udp -
1386 0 : waterfall->out.net_overrun -
1387 0 : waterfall->out.tpu_quic_invalid -
1388 0 : waterfall->out.tpu_udp_invalid -
1389 0 : waterfall->out.quic_abandoned -
1390 0 : waterfall->out.quic_frag_drop -
1391 0 : waterfall->out.quic_overrun -
1392 0 : waterfall->out.verify_overrun;
1393 0 : stats->dedup_drop_cnt = waterfall->out.dedup_duplicate;
1394 0 : stats->dedup_total_cnt = stats->verify_total_cnt -
1395 0 : waterfall->out.verify_duplicate -
1396 0 : waterfall->out.verify_parse -
1397 0 : waterfall->out.verify_failed;
1398 :
1399 0 : ulong pack_tile_idx = fd_topo_find_tile( topo, "pack", 0UL );
1400 0 : if( pack_tile_idx!=ULONG_MAX ) {
1401 0 : fd_topo_tile_t const * pack = &topo->tiles[ pack_tile_idx ];
1402 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
1403 0 : stats->pack_buffer_cnt = pack_metrics[ MIDX( GAUGE, PACK, TXN_AVAILABLE ) ];
1404 0 : stats->pack_buffer_capacity = pack->pack.max_pending_transactions;
1405 0 : }
1406 :
1407 0 : stats->bank_txn_exec_cnt = waterfall->out.block_fail + waterfall->out.block_success;
1408 :
1409 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_STATS, now, now, stats );
1410 0 : }
1411 :
1412 : static void
1413 0 : fd_gui_run_boot_progress( fd_gui_t * gui, long now ) {
1414 0 : fd_topo_tile_t const * snapct = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapct", 0UL ) ];
1415 0 : volatile ulong * snapct_metrics = fd_metrics_tile( snapct->metrics );
1416 :
1417 0 : fd_topo_tile_t const * snapdc = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapdc", 0UL ) ];
1418 0 : volatile ulong * snapdc_metrics = fd_metrics_tile( snapdc->metrics );
1419 :
1420 0 : fd_topo_tile_t const * snapin = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapin", 0UL ) ];
1421 0 : volatile ulong * snapin_metrics = fd_metrics_tile( snapin->metrics );
1422 :
1423 0 : fd_topo_tile_t const * snapwr = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapwr", 0UL ) ];
1424 0 : volatile ulong * snapwr_metrics = fd_metrics_tile( snapwr->metrics );
1425 :
1426 : /* Backtest topologies have no gossip tile; treat wait-for-supermajority
1427 : as done. */
1428 0 : ulong wfs_state = FD_GOSSIP_WFS_STATE_DONE;
1429 0 : volatile ulong * gossip_metrics = NULL;
1430 0 : ulong gossip_tile_idx = fd_topo_find_tile( gui->topo, "gossip", 0UL );
1431 0 : if( FD_LIKELY( gossip_tile_idx!=ULONG_MAX ) ) {
1432 0 : fd_topo_tile_t const * gossip = &gui->topo->tiles[ gossip_tile_idx ];
1433 0 : gossip_metrics = fd_metrics_tile( gossip->metrics );
1434 0 : wfs_state = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STATE ) ];
1435 0 : }
1436 :
1437 0 : ulong snapshot_phase = snapct_metrics[ MIDX( GAUGE, SNAPCT, STATE ) ];
1438 :
1439 : /* Backtest topologies have no turbine, so the regular catch-up
1440 : detection (turbine slot vs. replayed slot) can never trigger.
1441 : Consider replay caught up at the first tower root after the
1442 : snapshot finishes loading. */
1443 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX &&
1444 0 : snapshot_phase==FD_SNAPCT_STATE_SHUTDOWN &&
1445 0 : gui->summary.slot_tower!=ULONG_MAX &&
1446 0 : fd_topo_find_tile( gui->topo, "backt", 0UL )!=ULONG_MAX ) ) {
1447 0 : gui->summary.slot_caught_up = gui->summary.slot_tower;
1448 0 : gui->summary.boot_progress.catching_up_time_nanos = now;
1449 :
1450 0 : fd_gui_printf_slot_caught_up( gui );
1451 0 : fd_http_server_ws_broadcast( gui->http );
1452 0 : }
1453 :
1454 : /* state transitions */
1455 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
1456 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
1457 0 : for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
1458 0 : fd_gui_ema_init( &gui->summary.accdb->tier_fill_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
1459 0 : fd_gui_ema_init( &gui->summary.accdb->tier_free_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
1460 0 : }
1461 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_tower!=ULONG_MAX ) ) {
1462 0 : if( FD_UNLIKELY( gui->summary.wfs_enabled ) ) {
1463 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) {
1464 0 : ulong snap_inc = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].slot;
1465 0 : ulong snap_full = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].slot;
1466 0 : gui->summary.slot_caught_up = fd_ulong_if( snap_inc!=ULONG_MAX, snap_inc, snap_full );
1467 0 : gui->summary.boot_progress.catching_up_time_nanos = now;
1468 :
1469 0 : fd_gui_printf_slot_caught_up( gui );
1470 0 : fd_http_server_ws_broadcast( gui->http );
1471 0 : }
1472 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
1473 0 : for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
1474 0 : fd_gui_ema_init( &gui->summary.accdb->tier_fill_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
1475 0 : fd_gui_ema_init( &gui->summary.accdb->tier_free_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
1476 0 : }
1477 0 : } else {
1478 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP;
1479 0 : }
1480 0 : } else if( FD_UNLIKELY( snapshot_phase == FD_SNAPCT_STATE_SHUTDOWN && wfs_state==FD_GOSSIP_WFS_STATE_WAIT ) ) {
1481 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY;
1482 0 : } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_FULL_FILE
1483 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_FILE_FINI
1484 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_FILE_DONE
1485 0 : || snapshot_phase==FD_SNAPCT_STATE_READING_FULL_HTTP
1486 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_FINI
1487 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_DONE ) ) {
1488 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT;
1489 0 : } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_FILE
1490 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_FINI
1491 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_DONE
1492 0 : || snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_HTTP
1493 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_FINI
1494 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_DONE ) ) {
1495 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
1496 0 : }
1497 :
1498 : /* It's possible for the incremental snapshot phase to be skipped, or
1499 : complete before we can sample it. This ensures we always get at
1500 : least one pass of the metrics. */
1501 0 : if( FD_UNLIKELY( gui->summary.boot_progress.phase==FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP
1502 0 : && gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].reset_cnt==ULONG_MAX ) ) {
1503 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
1504 0 : }
1505 :
1506 0 : switch ( gui->summary.boot_progress.phase ) {
1507 0 : case FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP: {
1508 0 : gui->summary.boot_progress.joining_gossip_time_nanos = now;
1509 0 : break;
1510 0 : }
1511 0 : case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT:
1512 0 : case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT: {
1513 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 );
1514 0 : ulong _retry_cnt = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_RETRY ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_RETRY ) ]);
1515 :
1516 : /* reset boot state if necessary */
1517 0 : if( FD_UNLIKELY( gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt!=_retry_cnt ) ) {
1518 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_time_nanos = now;
1519 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt = _retry_cnt;
1520 0 : }
1521 :
1522 0 : ulong _total_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_SIZE_BYTES ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_SIZE_BYTES ) ] );
1523 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 ) ] );
1524 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 ) ] );
1525 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 ) ] );
1526 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 ) ] );
1527 0 : ulong _snapwr_in_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapwr_metrics[ MIDX( GAUGE, SNAPWR, FULL_BYTES_READ ) ], snapwr_metrics[ MIDX( GAUGE, SNAPWR, INCREMENTAL_BYTES_READ ) ] );
1528 :
1529 0 : ulong _insert_accounts_total = snapin_metrics[ MIDX( GAUGE, SNAPIN, ACCOUNT_LOADED ) ];
1530 0 : ulong _insert_accounts_baseline = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, 0UL, gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].insert_accounts_current );
1531 0 : ulong _insert_accounts = fd_ulong_sat_sub( _insert_accounts_total, _insert_accounts_baseline );
1532 :
1533 0 : ulong _snapwr_accounts_total = snapwr_metrics[ MIDX( GAUGE, SNAPWR, ACCOUNTS_WRITTEN ) ];
1534 0 : ulong _snapwr_accounts_baseline = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, 0UL, gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].snapwr_accounts_current );
1535 0 : ulong _snapwr_accounts = fd_ulong_sat_sub( _snapwr_accounts_total, _snapwr_accounts_baseline );
1536 :
1537 0 : ulong _snapwr_out_total = snapwr_metrics[ MIDX( GAUGE, SNAPWR, BYTES_WRITTEN ) ];
1538 0 : ulong _snapwr_out_baseline = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, 0UL, gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].snapwr_out_bytes_decompressed );
1539 0 : ulong _snapwr_out_bytes = fd_ulong_sat_sub( _snapwr_out_total, _snapwr_out_baseline );
1540 :
1541 : /* metadata */
1542 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].total_bytes_compressed = _total_bytes;
1543 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].sample_time_nanos = now;
1544 :
1545 : /* read stage */
1546 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_bytes_compressed = _read_bytes;
1547 :
1548 : /* decompress stage */
1549 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_compressed = _decompress_compressed_bytes;
1550 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_decompressed = _decompress_decompressed_bytes;
1551 :
1552 : /* insert stage */
1553 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_bytes_decompressed = _insert_bytes;
1554 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_accounts_current = _insert_accounts;
1555 :
1556 : /* snapwr (snapshot write) stage */
1557 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].snapwr_in_bytes_decompressed = _snapwr_in_bytes;
1558 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].snapwr_out_bytes_decompressed = _snapwr_out_bytes;
1559 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].snapwr_accounts_current = _snapwr_accounts;
1560 :
1561 0 : break;
1562 0 : }
1563 0 : case FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY: {
1564 : /* Only reachable when the topology has a gossip tile. */
1565 0 : gui->summary.boot_progress.wfs_total_stake = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKE_TOTAL ) ];
1566 0 : gui->summary.boot_progress.wfs_connected_stake = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKE_ONLINE ) ];
1567 0 : gui->summary.boot_progress.wfs_total_peers = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKED_PEER_TOTAL ) ];
1568 0 : gui->summary.boot_progress.wfs_connected_peers = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKED_PEER_ONLINE ) ];
1569 0 : break;
1570 0 : }
1571 0 : case FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP: {
1572 0 : gui->summary.boot_progress.catching_up_time_nanos = now;
1573 0 : break;
1574 0 : }
1575 0 : case FD_GUI_BOOT_PROGRESS_TYPE_RUNNING: break;
1576 0 : default: FD_LOG_ERR(( "unknown boot progress phase: %d", gui->summary.boot_progress.phase ));
1577 0 : }
1578 0 : }
1579 :
1580 : static inline int
1581 0 : fd_gui_ephemeral_slots_contains( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot ) {
1582 0 : for( ulong i=0UL; i<slots_sz; i++ ) {
1583 0 : if( FD_UNLIKELY( slots[ i ].slot==ULONG_MAX ) ) break;
1584 0 : if( FD_UNLIKELY( slots[ i ].slot==slot ) ) return 1;
1585 0 : }
1586 0 : return 0;
1587 0 : }
1588 :
1589 : #define SORT_NAME fd_gui_ephemeral_slot_sort
1590 0 : #define SORT_KEY_T fd_gui_ephemeral_slot_t
1591 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 ) ) )
1592 : #include "../../util/tmpl/fd_sort.c"
1593 :
1594 : static inline void
1595 0 : fd_gui_try_insert_ephemeral_slot( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot, long now ) {
1596 0 : int already_present = 0;
1597 0 : for( ulong i=0UL; i<slots_sz; i++ ) {
1598 : /* evict any slots older than 4.8 seconds */
1599 0 : if( FD_UNLIKELY( slots[ i ].slot!=ULONG_MAX && now-slots[ i ].timestamp_arrival_nanos>4800000000L ) ) {
1600 0 : slots[ i ].slot = ULONG_MAX;
1601 0 : continue;
1602 0 : }
1603 :
1604 : /* if we've already seen this slot, just update the timestamp */
1605 0 : if( FD_UNLIKELY( slots[ i ].slot==slot ) ) {
1606 0 : slots[ i ].timestamp_arrival_nanos = now;
1607 0 : already_present = 1;
1608 0 : }
1609 0 : }
1610 0 : if( FD_LIKELY( already_present ) ) return;
1611 :
1612 : /* Insert the new slot number, evicting a smaller slot if necessary */
1613 0 : slots[ slots_sz ].timestamp_arrival_nanos = now;
1614 0 : slots[ slots_sz ].slot = slot;
1615 0 : fd_gui_ephemeral_slot_sort_insert( slots, slots_sz+1UL );
1616 0 : }
1617 :
1618 : static inline void
1619 0 : fd_gui_try_insert_run_length_slot( ulong * slots, ulong capacity, ulong * slots_sz, ulong slot ) {
1620 : /* catch up history is run-length encoded */
1621 0 : ulong range_idx = fd_sort_up_ulong_split( slots, *slots_sz, slot );
1622 0 : if( FD_UNLIKELY( range_idx<(*slots_sz)-1UL && range_idx%2UL==0UL && slots[ range_idx ]<=slot && slots[ range_idx+1UL ]>=slot ) ) return;
1623 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;
1624 :
1625 0 : slots[ (*slots_sz)++ ] = slot;
1626 0 : slots[ (*slots_sz)++ ] = slot;
1627 :
1628 0 : fd_sort_up_ulong_insert( slots, (*slots_sz) );
1629 :
1630 : /* colesce ranges */
1631 0 : ulong removed = 0UL;
1632 0 : for( ulong i=1UL; i<(*slots_sz)-1UL; i+=2 ) {
1633 0 : if( FD_UNLIKELY( slots[ i ]+1UL==slots[ i+1UL ] ) ) {
1634 0 : slots[ i ] = ULONG_MAX;
1635 0 : slots[ i+1UL ] = ULONG_MAX;
1636 0 : removed += 2;
1637 0 : }
1638 0 : }
1639 :
1640 0 : if( FD_UNLIKELY( (*slots_sz)>=removed+capacity-2UL && (*slots_sz)>=4UL ) ) {
1641 : /* We are at capacity, start coalescing earlier intervals. */
1642 0 : slots[ 1 ] = ULONG_MAX;
1643 0 : slots[ 2 ] = ULONG_MAX;
1644 0 : removed += 2;
1645 0 : }
1646 :
1647 0 : fd_sort_up_ulong_insert( slots, (*slots_sz) );
1648 0 : (*slots_sz) -= removed;
1649 0 : }
1650 :
1651 : void
1652 0 : fd_gui_handle_repair_slot( fd_gui_t * gui, ulong slot, long now ) {
1653 0 : int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot );
1654 0 : fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot, now );
1655 :
1656 0 : if( FD_UNLIKELY( !was_sent && slot!=gui->summary.slot_repair ) ) {
1657 0 : gui->summary.slot_repair = slot;
1658 :
1659 0 : fd_gui_printf_repair_slot( gui );
1660 0 : fd_http_server_ws_broadcast( gui->http );
1661 :
1662 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 );
1663 0 : }
1664 0 : }
1665 :
1666 : void
1667 0 : fd_gui_handle_repair_request( fd_gui_t * gui, ulong slot, ulong shred_idx, long now ) {
1668 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_SHRED_EVENTS, now, now, &(fd_gui_slot_history_shred_event_t){ .slot = (uint)slot, .timestamp = now, .shred_idx = (ushort)shred_idx, .event = FD_GUI_SLOT_SHRED_REPAIR_REQUEST } );
1669 0 : }
1670 :
1671 : static void
1672 0 : fd_gui_progcache_sample( fd_gui_t * gui ) {
1673 0 : fd_topo_t const * topo = gui->topo;
1674 :
1675 0 : ulong hits = 0UL;
1676 0 : ulong lookups = 0UL;
1677 :
1678 0 : for( ulong i=0UL; i<gui->summary.execrp_tile_cnt; i++ ) {
1679 0 : fd_topo_tile_t const * execrp = &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ];
1680 0 : volatile ulong const * metrics = fd_metrics_tile( execrp->metrics );
1681 :
1682 0 : lookups += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_LOOKUP ) ];
1683 0 : hits += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_HIT ) ];
1684 0 : }
1685 :
1686 : /* The execrp tile writes lookups before hits in metrics_write, so
1687 : reading lookups first then hits here means we may observe the
1688 : new hits before the new lookups, giving hits > lookups
1689 : momentarily. Clamp to maintain the invariant hits <= lookups. */
1690 :
1691 0 : hits = fd_ulong_min( hits, lookups );
1692 :
1693 0 : ulong ring_idx = gui->summary.progcache_history_idx % FD_GUI_PROGCACHE_HISTORY_CNT;
1694 0 : ulong oldest_hits = gui->summary.progcache_hits_history [ ring_idx ];
1695 0 : ulong oldest_lookups = gui->summary.progcache_lookups_history[ ring_idx ];
1696 :
1697 0 : gui->summary.progcache_hits_history [ ring_idx ] = hits;
1698 0 : gui->summary.progcache_lookups_history[ ring_idx ] = lookups;
1699 0 : gui->summary.progcache_history_idx = gui->summary.progcache_history_idx + 1UL;
1700 :
1701 0 : ulong hits_1min = hits - oldest_hits;
1702 0 : ulong lookups_1min = lookups - oldest_lookups;
1703 0 : hits_1min = fd_ulong_min( hits_1min, lookups_1min );
1704 :
1705 0 : gui->summary.progcache_hits_1min = hits_1min;
1706 0 : gui->summary.progcache_lookups_1min = lookups_1min;
1707 0 : }
1708 :
1709 : int
1710 0 : fd_gui_poll( fd_gui_t * gui, long now ) {
1711 0 : if( FD_LIKELY( now>gui->next_sample_1sec ) ) {
1712 0 : fd_gui_hist_evict_step( gui );
1713 :
1714 0 : for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
1715 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_TIMERS, now, now, &gui->summary.tile_timers_packed[ i ] );
1716 0 : }
1717 :
1718 0 : gui->next_sample_1sec += 1000L*1000L*1000L;
1719 0 : return 1;
1720 0 : }
1721 :
1722 0 : if( FD_LIKELY( now>gui->next_sample_200millis ) ) {
1723 0 : fd_gui_estimated_tps_snap( gui );
1724 0 : fd_gui_printf_estimated_tps( gui );
1725 0 : fd_http_server_ws_broadcast( gui->http );
1726 :
1727 0 : if( FD_LIKELY( !gui->leader_active ) ) {
1728 0 : for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
1729 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_TIMERS, now, now, &gui->summary.tile_timers_packed[ i ] );
1730 0 : }
1731 0 : }
1732 :
1733 0 : gui->next_sample_200millis += 200L*1000L*1000L;
1734 0 : return 1;
1735 0 : }
1736 :
1737 0 : if( FD_LIKELY( now>gui->next_sample_100millis ) ) {
1738 0 : fd_gui_txn_waterfall_snap( gui, gui->summary.txn_waterfall_current );
1739 0 : fd_gui_printf_live_txn_waterfall( gui, gui->summary.txn_waterfall_reference, gui->summary.txn_waterfall_current, 0UL /* TODO: REAL NEXT LEADER SLOT */ );
1740 0 : fd_http_server_ws_broadcast( gui->http );
1741 :
1742 0 : if( FD_LIKELY( gui->leader_active ) ) {
1743 0 : gui->summary.txn_waterfall_current->sample_time_nanos = now;
1744 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TXN_WATERFALL, now, now, gui->summary.txn_waterfall_current );
1745 0 : }
1746 :
1747 0 : fd_gui_network_stats_snap( gui, gui->summary.network_stats_current );
1748 0 : fd_gui_network_rate_max_update( gui, now );
1749 0 : fd_gui_printf_live_network_metrics( gui, gui->summary.network_stats_current );
1750 0 : fd_http_server_ws_broadcast( gui->http );
1751 :
1752 0 : *gui->summary.tile_stats_reference = *gui->summary.tile_stats_current;
1753 0 : fd_gui_tile_stats_snap( gui, gui->summary.txn_waterfall_current, gui->summary.tile_stats_current, now );
1754 0 : fd_gui_printf_live_tile_stats( gui, gui->summary.tile_stats_reference, gui->summary.tile_stats_current );
1755 0 : fd_http_server_ws_broadcast( gui->http );
1756 :
1757 0 : {
1758 0 : fd_gui_progcache_sample( gui );
1759 0 : fd_gui_printf_live_program_cache( gui );
1760 0 : fd_http_server_ws_broadcast( gui->http );
1761 :
1762 0 : *gui->summary.accounts_stats_reference = *gui->summary.accounts_stats_current;
1763 0 : fd_gui_accounts_stats_snap( gui, gui->summary.accounts_stats_current );
1764 0 : fd_gui_printf_accounts_stats( gui );
1765 0 : fd_http_server_ws_broadcast( gui->http );
1766 0 : gui->summary.accounts_stats_have_reference = 1;
1767 0 : }
1768 :
1769 0 : if( FD_UNLIKELY( gui->summary.boot_progress.phase!=FD_GUI_BOOT_PROGRESS_TYPE_RUNNING ) ) {
1770 0 : fd_gui_run_boot_progress( gui, now );
1771 0 : if( FD_UNLIKELY( memcmp( &gui->summary.boot_progress, &gui->summary.prev_boot_progress, sizeof(fd_gui_boot_progress_t) ) ) ) {
1772 0 : gui->summary.prev_boot_progress = gui->summary.boot_progress;
1773 0 : fd_gui_printf_boot_progress( gui );
1774 0 : fd_http_server_ws_broadcast( gui->http );
1775 0 : }
1776 0 : }
1777 :
1778 0 : ulong bundle_tile_idx = fd_topo_find_tile( gui->topo, "bundle", 0UL );
1779 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
1780 0 : volatile ulong const * bundle_metrics = fd_metrics_tile( gui->topo->tiles[ bundle_tile_idx ].metrics );
1781 0 : int cur_state = (int)bundle_metrics[ MIDX( GAUGE, BUNDLE, STATE ) ];
1782 0 : if( FD_UNLIKELY( cur_state != gui->block_engine.status ) ) {
1783 0 : gui->block_engine.status = cur_state;
1784 0 : fd_gui_printf_block_engine( gui );
1785 0 : fd_http_server_ws_broadcast( gui->http );
1786 0 : }
1787 0 : }
1788 :
1789 0 : fd_gui_printf_health( gui );
1790 0 : fd_http_server_ws_broadcast( gui->http );
1791 :
1792 0 : gui->next_sample_100millis += 100L*1000L*1000L;
1793 0 : return 1;
1794 0 : }
1795 :
1796 0 : if( FD_LIKELY( now>gui->next_sample_50millis ) ) {
1797 0 : if( FD_LIKELY( !fd_gui_shreds_window_is_empty( gui, gui->shreds.broadcast_watermark_ns, now ) ) ) {
1798 0 : fd_gui_printf_shred_updates( gui, gui->shreds.broadcast_watermark_ns, now );
1799 0 : fd_http_server_ws_broadcast( gui->http );
1800 0 : }
1801 0 : gui->shreds.broadcast_watermark_ns = now;
1802 :
1803 : /* We get the repair slot from the sampled metric after catching up
1804 : and from incoming shred data before catchup. This makes the
1805 : catchup progress bar look complete while also keeping the
1806 : overview slots vis correct. TODO: do this properly using frags
1807 : sent over a link */
1808 0 : if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
1809 : /* Backtest topologies have no repair tile. */
1810 0 : ulong repair_tile_idx = fd_topo_find_tile( gui->topo, "repair", 0UL );
1811 0 : if( FD_LIKELY( repair_tile_idx!=ULONG_MAX ) ) {
1812 0 : fd_topo_tile_t const * repair = &gui->topo->tiles[ repair_tile_idx ];
1813 0 : volatile ulong const * repair_metrics = fd_metrics_tile( repair->metrics );
1814 0 : ulong slot = repair_metrics[ MIDX( GAUGE, REPAIR, SLOT_HIGHEST_REPAIRED ) ];
1815 0 : fd_gui_handle_repair_slot( gui, slot, now );
1816 0 : }
1817 0 : }
1818 :
1819 0 : gui->next_sample_50millis += 50L*1000L*1000L;
1820 0 : return 1;
1821 0 : }
1822 :
1823 0 : if( FD_LIKELY( now>gui->next_sample_40millis ) ) {
1824 0 : fd_gui_tile_timers_snap( gui, now );
1825 :
1826 0 : fd_gui_printf_live_tile_timers( gui );
1827 0 : fd_http_server_ws_broadcast( gui->http );
1828 :
1829 0 : fd_gui_printf_live_tile_metrics( gui );
1830 0 : fd_http_server_ws_broadcast( gui->http );
1831 :
1832 0 : if( FD_LIKELY( gui->leader_active ) ) {
1833 0 : for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
1834 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_TIMERS, now, now, &gui->summary.tile_timers_packed[ i ] );
1835 0 : }
1836 0 : }
1837 :
1838 0 : gui->next_sample_40millis += 40L*1000L*1000L;
1839 0 : return 1;
1840 0 : }
1841 :
1842 0 : if( FD_LIKELY( now>gui->next_sample_10millis ) ) {
1843 0 : if( FD_UNLIKELY( gui->leader_active ) ) fd_gui_scheduler_counts_snap( gui, now );
1844 :
1845 0 : fd_gui_printf_server_time_nanos( gui, now );
1846 0 : fd_http_server_ws_broadcast( gui->http );
1847 :
1848 0 : gui->next_sample_10millis += 10L*1000L*1000L;
1849 0 : return 1;
1850 0 : }
1851 :
1852 0 : return 0;
1853 0 : }
1854 :
1855 : int
1856 : fd_gui_request_slot( fd_gui_t * gui,
1857 : ulong ws_conn_id,
1858 : ulong request_id,
1859 0 : cJSON const * params ) {
1860 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1861 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1862 :
1863 0 : ulong _slot = slot_param->valueulong;
1864 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, _slot );
1865 0 : if( FD_UNLIKELY( !slot || slot->skip==FD_GUI_SKIP_STATUS_UNKNOWN ) ) {
1866 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query", request_id );
1867 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1868 0 : return 0;
1869 0 : }
1870 :
1871 0 : fd_gui_printf_slot_request( gui, _slot, request_id, slot );
1872 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1873 0 : return 0;
1874 0 : }
1875 :
1876 : int
1877 : fd_gui_request_slot_transactions( fd_gui_t * gui,
1878 : ulong ws_conn_id,
1879 : ulong request_id,
1880 0 : cJSON const * params ) {
1881 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1882 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1883 :
1884 0 : ulong _slot = slot_param->valueulong;
1885 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, _slot );
1886 0 : if( FD_UNLIKELY( !slot || slot->skip==FD_GUI_SKIP_STATUS_UNKNOWN ) ) {
1887 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query_transactions", request_id );
1888 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1889 0 : return 0;
1890 0 : }
1891 :
1892 0 : fd_gui_printf_slot_transactions_request( gui, _slot, request_id, slot );
1893 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1894 0 : return 0;
1895 0 : }
1896 :
1897 : int
1898 : fd_gui_request_slot_detailed( fd_gui_t * gui,
1899 : ulong ws_conn_id,
1900 : ulong request_id,
1901 0 : cJSON const * params ) {
1902 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1903 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1904 :
1905 0 : ulong _slot = slot_param->valueulong;
1906 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, _slot );
1907 0 : if( FD_UNLIKELY( !slot || slot->skip==FD_GUI_SKIP_STATUS_UNKNOWN ) ) {
1908 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query_detailed", request_id );
1909 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1910 0 : return 0;
1911 0 : }
1912 :
1913 0 : fd_gui_printf_slot_request_detailed( gui, _slot, request_id, slot );
1914 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1915 0 : return 0;
1916 0 : }
1917 :
1918 : static inline ulong
1919 0 : fd_gui_slot_duration( fd_gui_t * gui, fd_gui_slot_t const * cur ) {
1920 0 : if( FD_UNLIKELY( cur->skip==FD_GUI_SKIP_STATUS_SKIPPED || cur->completed_time==LONG_MAX ) ) return ULONG_MAX;
1921 0 : fd_gui_slot_t const * prev = fd_gui_slot_get_any( gui, cur->slot-1UL );
1922 0 : long parent_completed_time = LONG_MAX;
1923 0 : if( FD_LIKELY( prev && prev->skip!=FD_GUI_SKIP_STATUS_SKIPPED ) ) parent_completed_time = prev->completed_time;
1924 0 : if( FD_UNLIKELY( parent_completed_time==LONG_MAX ) ) return ULONG_MAX;
1925 :
1926 0 : return (ulong)(cur->completed_time - parent_completed_time);
1927 0 : }
1928 :
1929 : /* All rankings are initialized / reset to ULONG_MAX. These sentinels
1930 : sort AFTER non-sentinel ranking entries. Equal slots are sorted by
1931 : oldest slot AFTER. Otherwise sort by value according to ranking
1932 : type. */
1933 : #define SORT_NAME fd_gui_slot_ranking_sort
1934 0 : #define SORT_KEY_T fd_gui_slot_ranking_t
1935 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 ) ) ) )
1936 : #include "../../util/tmpl/fd_sort.c"
1937 :
1938 : static inline void
1939 : fd_gui_try_insert_ranking( fd_gui_t * gui,
1940 : fd_gui_slot_rankings_t * rankings,
1941 0 : fd_gui_slot_t const * slot ) {
1942 : /* Rankings are inserted into an extra slot at the end of the ranking
1943 : array, then the array is sorted. */
1944 0 : #define TRY_INSERT_SLOT( ranking_name, ranking_slot, ranking_value ) \
1945 0 : do { \
1946 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 }; \
1947 0 : fd_gui_slot_ranking_sort_insert( rankings->FD_CONCAT2(largest_, ranking_name), FD_GUI_SLOT_RANKINGS_SZ+1UL ); \
1948 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 }; \
1949 0 : fd_gui_slot_ranking_sort_insert( rankings->FD_CONCAT2(smallest_, ranking_name), FD_GUI_SLOT_RANKINGS_SZ+1UL ); \
1950 0 : } while (0)
1951 :
1952 0 : if( slot->skip==FD_GUI_SKIP_STATUS_SKIPPED ) {
1953 0 : TRY_INSERT_SLOT( skipped, slot->slot, slot->slot );
1954 0 : return;
1955 0 : }
1956 :
1957 0 : ulong dur = fd_gui_slot_duration( gui, slot );
1958 0 : if( FD_LIKELY( dur!=ULONG_MAX ) ) TRY_INSERT_SLOT( duration, slot->slot, dur );
1959 0 : TRY_INSERT_SLOT( tips, slot->slot, slot->tips );
1960 0 : TRY_INSERT_SLOT( fees, slot->slot, slot->priority_fee + slot->transaction_fee );
1961 0 : TRY_INSERT_SLOT( rewards, slot->slot, slot->tips + slot->priority_fee + slot->transaction_fee );
1962 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 );
1963 0 : TRY_INSERT_SLOT( compute_units, slot->slot, slot->compute_units );
1964 0 : #undef TRY_INSERT_SLOT
1965 0 : }
1966 :
1967 : static void
1968 0 : fd_gui_update_slot_rankings( fd_gui_t * gui ) {
1969 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) return;
1970 0 : ulong first_replay_slot = fd_gui_first_replay_slot( gui );
1971 0 : if( FD_UNLIKELY( first_replay_slot==ULONG_MAX ) ) return;
1972 0 : if( FD_UNLIKELY( gui->summary.slot_rooted==ULONG_MAX ) ) return;
1973 :
1974 0 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, gui->summary.slot_rooted );
1975 0 : if( FD_UNLIKELY( !epoch ) ) return;
1976 :
1977 : /* No new slots since the last update */
1978 0 : if( FD_UNLIKELY( epoch->rankings_slot>gui->summary.slot_rooted ) ) return;
1979 :
1980 : /* Slots before first_replay_slot are unavailable. */
1981 0 : epoch->rankings_slot = fd_ulong_max( epoch->rankings_slot, first_replay_slot );
1982 :
1983 : /* Update the rankings. Only look through slots we haven't already. */
1984 0 : for( ulong s = gui->summary.slot_rooted; s>=epoch->rankings_slot; s--) {
1985 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, s );
1986 0 : if( FD_UNLIKELY( slot->skip==FD_GUI_SKIP_STATUS_UNKNOWN ) ) break;
1987 :
1988 0 : fd_gui_try_insert_ranking( gui, epoch->rankings, slot );
1989 0 : if( FD_UNLIKELY( slot->mine ) ) fd_gui_try_insert_ranking( gui, epoch->my_rankings, slot );
1990 0 : }
1991 :
1992 0 : epoch->rankings_slot = gui->summary.slot_rooted + 1UL;
1993 0 : }
1994 :
1995 : int
1996 : fd_gui_request_slot_rankings( fd_gui_t * gui,
1997 : ulong ws_conn_id,
1998 : ulong request_id,
1999 0 : cJSON const * params ) {
2000 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "mine" );
2001 0 : if( FD_UNLIKELY( !cJSON_IsBool( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2002 :
2003 0 : int mine = !!(slot_param->type & cJSON_True);
2004 0 : fd_gui_update_slot_rankings( gui );
2005 0 : fd_gui_printf_slot_rankings_request( gui, request_id, mine );
2006 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2007 0 : return 0;
2008 0 : }
2009 :
2010 : static inline int
2011 : fd_gui_cjson_parse_ns( cJSON const * param,
2012 0 : long * out ) {
2013 0 : if( FD_UNLIKELY( !param ) ) return -1;
2014 0 : if( cJSON_IsNumber( param ) ) {
2015 0 : double v = param->valuedouble;
2016 0 : if( FD_UNLIKELY( !(v>=0.0 && v<(double)LONG_MAX) ) ) return -1;
2017 0 : *out = (long)v;
2018 0 : return 0;
2019 0 : }
2020 0 : if( cJSON_IsString( param ) && param->valuestring ) {
2021 0 : *out = fd_cstr_to_long( param->valuestring );
2022 0 : return 0;
2023 0 : }
2024 0 : return -1;
2025 0 : }
2026 :
2027 : static int
2028 : fd_gui_request_timeline_shreds( fd_gui_t * gui,
2029 : ulong ws_conn_id,
2030 : char const * topic,
2031 : ulong request_id,
2032 0 : cJSON const * params ) {
2033 0 : const cJSON * start_param = cJSON_GetObjectItemCaseSensitive( params, "start_ns" );
2034 0 : const cJSON * end_param = cJSON_GetObjectItemCaseSensitive( params, "end_ns" );
2035 :
2036 0 : long start_ns, end_ns;
2037 0 : if( FD_UNLIKELY( fd_gui_cjson_parse_ns( start_param, &start_ns ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2038 0 : if( FD_UNLIKELY( fd_gui_cjson_parse_ns( end_param, &end_ns ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2039 0 : if( FD_UNLIKELY( !(start_ns>=0L && start_ns<LONG_MAX) || !(end_ns>=0L && end_ns<LONG_MAX) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2040 0 : if( FD_UNLIKELY( end_ns<start_ns ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2041 0 : if( FD_UNLIKELY( end_ns-start_ns>60L*1000L*1000L*1000L ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST; /* TODO: tune/remove */
2042 :
2043 0 : fd_gui_printf_timeline_query_shreds( gui, topic, start_ns, end_ns, request_id );
2044 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2045 0 : return 0;
2046 0 : }
2047 :
2048 : int
2049 : fd_gui_ws_message( fd_gui_t * gui,
2050 : ulong ws_conn_id,
2051 : uchar const * data,
2052 0 : ulong data_len ) {
2053 : /* TODO: cJSON allocates, might fail SIGSYS due to brk(2)...
2054 : switch off this (or use wksp allocator) */
2055 0 : const char * parse_end;
2056 0 : cJSON * json = cJSON_ParseWithLengthOpts( (char *)data, data_len, &parse_end, 0 );
2057 0 : if( FD_UNLIKELY( !json ) ) {
2058 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2059 0 : }
2060 :
2061 0 : const cJSON * node = cJSON_GetObjectItemCaseSensitive( json, "id" );
2062 0 : if( FD_UNLIKELY( !cJSON_IsNumber( node ) ) ) {
2063 0 : cJSON_Delete( json );
2064 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2065 0 : }
2066 0 : ulong id = node->valueulong;
2067 :
2068 0 : const cJSON * topic = cJSON_GetObjectItemCaseSensitive( json, "topic" );
2069 0 : if( FD_UNLIKELY( !cJSON_IsString( topic ) || topic->valuestring==NULL ) ) {
2070 0 : cJSON_Delete( json );
2071 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2072 0 : }
2073 :
2074 0 : const cJSON * key = cJSON_GetObjectItemCaseSensitive( json, "key" );
2075 0 : if( FD_UNLIKELY( !cJSON_IsString( key ) || key->valuestring==NULL ) ) {
2076 0 : cJSON_Delete( json );
2077 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2078 0 : }
2079 :
2080 0 : if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query" ) ) ) {
2081 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
2082 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
2083 0 : cJSON_Delete( json );
2084 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2085 0 : }
2086 :
2087 0 : int result = fd_gui_request_slot( gui, ws_conn_id, id, params );
2088 0 : cJSON_Delete( json );
2089 0 : return result;
2090 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_detailed" ) ) ) {
2091 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
2092 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
2093 0 : cJSON_Delete( json );
2094 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2095 0 : }
2096 :
2097 0 : int result = fd_gui_request_slot_detailed( gui, ws_conn_id, id, params );
2098 0 : cJSON_Delete( json );
2099 0 : return result;
2100 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_transactions" ) ) ) {
2101 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
2102 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
2103 0 : cJSON_Delete( json );
2104 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2105 0 : }
2106 :
2107 0 : int result = fd_gui_request_slot_transactions( gui, ws_conn_id, id, params );
2108 0 : cJSON_Delete( json );
2109 0 : return result;
2110 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_rankings" ) ) ) {
2111 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
2112 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
2113 0 : cJSON_Delete( json );
2114 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2115 0 : }
2116 :
2117 0 : int result = fd_gui_request_slot_rankings( gui, ws_conn_id, id, params );
2118 0 : cJSON_Delete( json );
2119 0 : return result;
2120 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "timeline" ) && !strcmp( key->valuestring, "query_shreds" ) ) ) {
2121 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
2122 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
2123 0 : cJSON_Delete( json );
2124 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2125 0 : }
2126 :
2127 0 : int result = fd_gui_request_timeline_shreds( gui, ws_conn_id, topic->valuestring, id, params );
2128 0 : cJSON_Delete( json );
2129 0 : return result;
2130 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "summary" ) && !strcmp( key->valuestring, "ping" ) ) ) {
2131 0 : fd_gui_printf_summary_ping( gui, id );
2132 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2133 :
2134 0 : cJSON_Delete( json );
2135 0 : return 0;
2136 0 : }
2137 :
2138 0 : cJSON_Delete( json );
2139 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_UNKNOWN_METHOD;
2140 0 : }
2141 :
2142 : static inline uchar
2143 0 : slot_get_skip_status( fd_gui_t * gui, ulong _slot ) {
2144 0 : ulong tower_slot = gui->summary.slot_tower;
2145 0 : if( FD_UNLIKELY( tower_slot==ULONG_MAX || _slot>=tower_slot ) ) return FD_GUI_SKIP_STATUS_UNKNOWN;
2146 :
2147 0 : const ulong max_consecutive_skips = 1024UL; /* TODO: prove derivation */
2148 :
2149 : /* Find the nearest landed canonical descendant and walk its lineage
2150 : down to obtain positive skip proof. */
2151 0 : ulong anchor_slot = ULONG_MAX;
2152 0 : ulong anchor_bank_seq = ULONG_MAX;
2153 0 : ulong search_hi = fd_ulong_min( _slot+max_consecutive_skips, tower_slot );
2154 0 : for( ulong s=_slot+1UL; s<=search_hi; s++ ) {
2155 0 : fd_gui_hist_kv_slot_iter_t it[ 1 ];
2156 : /* Equivocation-safe */
2157 0 : for( fd_gui_hist_kv_iter_begin( gui, it, FD_GUI_HIST_SLOT, s ); it->rec; fd_gui_hist_kv_iter_next( it ) ) {
2158 0 : fd_gui_slot_t const * rec = (fd_gui_slot_t const *)it->rec;
2159 0 : if( FD_LIKELY( rec->skip==FD_GUI_SKIP_STATUS_NOT_SKIPPED ) ) {
2160 0 : anchor_slot = s;
2161 0 : anchor_bank_seq = it->bank_seq;
2162 0 : break;
2163 0 : }
2164 0 : }
2165 0 : if( FD_UNLIKELY( anchor_slot!=ULONG_MAX ) ) break;
2166 0 : }
2167 0 : if( FD_UNLIKELY( anchor_slot==ULONG_MAX ) ) return FD_GUI_SKIP_STATUS_UNKNOWN; /* no descendant found */
2168 :
2169 : /* Walk the canonical fork back up. */
2170 0 : ulong cur_slot = anchor_slot;
2171 0 : ulong cur_bank_seq = anchor_bank_seq;
2172 0 : for( ulong steps=0UL; steps<max_consecutive_skips; steps++ ) {
2173 0 : fd_gui_hist_slot_key_t key;
2174 0 : key.slot = cur_slot; key.bank_seq = cur_bank_seq;
2175 0 : fd_gui_slot_t const * cmeta = (fd_gui_slot_t const *)fd_gui_hist_kv_get( gui, FD_GUI_HIST_SLOT, &key );
2176 0 : if( FD_UNLIKELY( !cmeta ) ) return FD_GUI_SKIP_STATUS_UNKNOWN; /* lineage broken / aged out */
2177 :
2178 0 : ulong parent_slot = cmeta->parent_slot;
2179 0 : ulong parent_bank_seq = cmeta->parent_bank_seq;
2180 0 : if( FD_UNLIKELY( parent_slot==ULONG_MAX ) ) return FD_GUI_SKIP_STATUS_UNKNOWN; /* Couldn't find _slot */
2181 0 : if( FD_LIKELY( parent_slot==_slot ) ) return FD_GUI_SKIP_STATUS_NOT_SKIPPED; /* _slot is on this lineage */
2182 0 : if( FD_LIKELY( parent_slot< _slot ) ) return FD_GUI_SKIP_STATUS_SKIPPED; /* lineage steps over _slot: skipped */
2183 0 : cur_slot = parent_slot;
2184 0 : cur_bank_seq = parent_bank_seq;
2185 0 : }
2186 0 : return FD_GUI_SKIP_STATUS_UNKNOWN;
2187 0 : }
2188 :
2189 : fd_gui_slot_t *
2190 0 : fd_gui_slot_get_canon_safe( fd_gui_t * gui, ulong _slot ) {
2191 0 : fd_gui_slot_t * slot = fd_gui_slot_get_canon( gui, _slot );
2192 :
2193 0 : if( FD_LIKELY( slot ) ) {
2194 0 : return slot;
2195 0 : } else {
2196 0 : uchar level = FD_GUI_SLOT_LEVEL_COMPLETED;
2197 0 : if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && _slot<gui->summary.slot_optimistically_confirmed ) ) level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
2198 0 : if( FD_LIKELY( gui->summary.slot_rooted!=ULONG_MAX && _slot<gui->summary.slot_rooted ) ) level = FD_GUI_SLOT_LEVEL_ROOTED;
2199 :
2200 0 : *gui->skipped_scratch = (fd_gui_slot_t){
2201 0 : .slot = _slot,
2202 0 : .bank_seq = ULONG_MAX,
2203 0 : .parent_bank_seq = ULONG_MAX,
2204 0 : .parent_slot = fd_gui_slot_skipped_get_parent( gui, _slot ),
2205 0 : .vote_slot = ULONG_MAX,
2206 0 : .completed_time = LONG_MAX,
2207 0 : .parent_completed_time = LONG_MAX,
2208 0 : .max_compute_units= UINT_MAX,
2209 0 : .mine = (uchar)(fd_gui_slot_is_mine( gui, _slot ) & 1),
2210 0 : .skip = slot_get_skip_status( gui, _slot ),
2211 0 : .level = level,
2212 0 : .compute_units = UINT_MAX,
2213 0 : .transaction_fee = ULONG_MAX,
2214 0 : .priority_fee = ULONG_MAX,
2215 0 : .tips = ULONG_MAX,
2216 0 : .shred_cnt = UINT_MAX,
2217 0 : .vote_latency_exact = FD_GUI_VOTE_LATENCY_NOT_VOTED,
2218 0 : .is_voter = 0,
2219 0 : .vote_success = UINT_MAX,
2220 0 : .vote_failed = UINT_MAX,
2221 0 : .nonvote_success = UINT_MAX,
2222 0 : .nonvote_failed = UINT_MAX,
2223 0 : };
2224 0 : return gui->skipped_scratch;
2225 0 : }
2226 0 : }
2227 :
2228 : void
2229 : fd_gui_handle_epoch_info( fd_gui_t * gui,
2230 : fd_epoch_info_msg_t const * epoch_info,
2231 0 : long now ) {
2232 0 : FD_TEST( epoch_info->staked_vote_cnt<=MAX_STAKE_WEIGHTS );
2233 0 : FD_TEST( epoch_info->slot_cnt<=MAX_SLOTS_PER_EPOCH );
2234 0 : FD_TEST( epoch_info->staked_vote_cnt );
2235 :
2236 0 : if( FD_UNLIKELY( !gui->epoch.has_epoch_schedule ) ) {
2237 0 : gui->epoch.epoch_schedule = epoch_info->epoch_schedule;
2238 0 : gui->epoch.has_epoch_schedule = 1;
2239 0 : }
2240 :
2241 0 : fd_vote_stake_weight_t const * stake_weights = fd_epoch_info_msg_stake_weights( epoch_info );
2242 0 : fd_memcpy( gui->epoch.stakes_scratch, stake_weights, epoch_info->staked_vote_cnt*sizeof(fd_vote_stake_weight_t) );
2243 :
2244 0 : fd_epoch_leaders_t * lsched = fd_epoch_leaders_join( fd_epoch_leaders_new( gui->epoch.lsched_scratch,
2245 0 : epoch_info->epoch,
2246 0 : epoch_info->start_slot,
2247 0 : epoch_info->slot_cnt,
2248 0 : epoch_info->staked_vote_cnt,
2249 0 : gui->epoch.stakes_scratch ) );
2250 0 : FD_TEST( lsched );
2251 :
2252 0 : int created = 0;
2253 0 : fd_gui_epoch_t * epoch = fd_gui_epoch_get_or_create( gui, epoch_info->epoch, &created );
2254 0 : FD_TEST( epoch );
2255 :
2256 0 : if( FD_LIKELY( created ) ) {
2257 0 : epoch->epoch = epoch_info->epoch;
2258 0 : epoch->start_slot = epoch_info->start_slot;
2259 0 : epoch->slot_cnt = epoch_info->slot_cnt;
2260 0 : epoch->start_time = LONG_MAX;
2261 0 : epoch->end_time = LONG_MAX;
2262 0 : epoch->target_slot_duration_ns = (long)epoch_info->ns_per_slot;
2263 0 : epoch->my_total_slots = 0UL;
2264 0 : epoch->my_skipped_slots = 0UL;
2265 0 : epoch->rankings_slot = epoch_info->start_slot;
2266 0 : memset( epoch->rankings, (int)(UINT_MAX), sizeof(epoch->rankings) );
2267 0 : memset( epoch->my_rankings, (int)(UINT_MAX), sizeof(epoch->my_rankings) );
2268 0 : memset( epoch->latency_exact, (int)FD_GUI_VOTE_LATENCY_NOT_VOTED, sizeof(epoch->latency_exact) );
2269 0 : memset( epoch->is_voter, 0, sizeof(epoch->is_voter) );
2270 0 : memset( epoch->skipped, 0, sizeof(epoch->skipped) );
2271 0 : epoch->epoch_schedule = epoch_info->epoch_schedule;
2272 0 : epoch->pub_cnt = lsched->pub_cnt;
2273 0 : epoch->stakes_cnt = epoch_info->staked_vote_cnt;
2274 0 : fd_memcpy( epoch->pub, lsched->pub, epoch->pub_cnt*sizeof(fd_pubkey_t) );
2275 0 : fd_memcpy( epoch->sched, lsched->sched, fd_ulong_min( lsched->sched_cnt, FD_GUI_EPOCH_SCHED_CNT )*sizeof(uint) );
2276 0 : fd_memcpy( epoch->stakes, gui->epoch.stakes_scratch, epoch->stakes_cnt*sizeof(fd_vote_stake_weight_t) );
2277 0 : }
2278 :
2279 0 : fd_epoch_leaders_delete( fd_epoch_leaders_leave( lsched ) );
2280 :
2281 0 : if( FD_UNLIKELY( gui->epoch.current_epoch==ULONG_MAX ) ) {
2282 0 : gui->epoch.current_epoch = epoch_info->epoch;
2283 0 : } else {
2284 0 : gui->epoch.current_epoch = fd_ulong_max( gui->epoch.current_epoch, epoch_info->epoch>0UL ? epoch_info->epoch-1UL : 0UL );
2285 0 : }
2286 :
2287 0 : epoch->start_time = now;
2288 0 : for( ulong i=0UL; i<fd_ulong_min( fd_ulong_sat_sub( epoch_info->start_slot, 1UL ), MAX_SLOTS_PER_EPOCH ); i++ ) {
2289 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_any( gui, epoch_info->start_slot-i );
2290 0 : if( FD_UNLIKELY( !slot ) ) break;
2291 0 : else if( FD_UNLIKELY( slot->skip==FD_GUI_SKIP_STATUS_SKIPPED ) ) continue;
2292 0 : epoch->start_time = slot->parent_completed_time;
2293 0 : break;
2294 0 : }
2295 :
2296 0 : fd_gui_printf_epoch( gui, epoch_info->epoch );
2297 0 : fd_http_server_ws_broadcast( gui->http );
2298 0 : }
2299 :
2300 : void
2301 : fd_gui_handle_shred( fd_gui_t * gui,
2302 : ulong slot,
2303 : ulong shred_idx,
2304 : int is_turbine,
2305 : long tsorig,
2306 0 : long now ) {
2307 0 : int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot );
2308 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 );
2309 :
2310 : /* If we haven't caught up yet, update repair slot using received
2311 : shreds. This is not technically correct, but close enough and will
2312 : make the progress bar look correct. */
2313 0 : if( FD_UNLIKELY( !is_turbine && gui->summary.slot_caught_up==ULONG_MAX ) ) fd_gui_handle_repair_slot( gui, slot, tsorig );
2314 :
2315 0 : if( FD_UNLIKELY( !was_sent && is_turbine && slot!=gui->summary.slot_turbine ) ) {
2316 0 : gui->summary.slot_turbine = slot;
2317 :
2318 0 : fd_gui_printf_turbine_slot( gui );
2319 0 : fd_http_server_ws_broadcast( gui->http );
2320 :
2321 0 : gui->turbine_slots[ slot % FD_GUI_TURBINE_RECV_TIMESTAMPS ].slot = slot;
2322 0 : gui->turbine_slots[ slot % FD_GUI_TURBINE_RECV_TIMESTAMPS ].timestamp = tsorig;
2323 :
2324 0 : ulong duration_sum = 0UL;
2325 0 : ulong slot_cnt = 0UL;
2326 :
2327 0 : for( ulong i=0UL; i<FD_GUI_TURBINE_RECV_TIMESTAMPS; i++ ) {
2328 0 : fd_gui_turbine_slot_t * cur = &gui->turbine_slots[ i ];
2329 0 : fd_gui_turbine_slot_t * prev = &gui->turbine_slots[ (i+FD_GUI_TURBINE_RECV_TIMESTAMPS-1UL) % FD_GUI_TURBINE_RECV_TIMESTAMPS ];
2330 0 : if( FD_UNLIKELY( cur->slot==ULONG_MAX || prev->slot==ULONG_MAX || cur->slot!=prev->slot+1UL ) ) continue;
2331 :
2332 0 : long slot_duration = cur->timestamp - prev->timestamp;
2333 0 : duration_sum += (ulong)fd_long_max( slot_duration, 0UL );
2334 0 : slot_cnt++;
2335 0 : }
2336 :
2337 0 : if( FD_LIKELY( slot_cnt>0 ) ) {
2338 0 : gui->summary.estimated_slot_duration_nanos = (ulong)(duration_sum / slot_cnt);
2339 0 : fd_gui_printf_estimated_slot_duration_nanos( gui );
2340 0 : fd_http_server_ws_broadcast( gui->http );
2341 0 : }
2342 :
2343 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 );
2344 0 : }
2345 :
2346 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_SHRED_EVENTS, now, tsorig, &(fd_gui_slot_history_shred_event_t){ .slot = (uint)slot, .timestamp = tsorig, .shred_idx = (ushort)shred_idx, .event = fd_uchar_if( is_turbine, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_TURBINE, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_REPAIR ) } );
2347 0 : }
2348 :
2349 : void
2350 : fd_gui_handle_leader_fec( fd_gui_t * gui,
2351 : ulong slot,
2352 : ulong fec_shred_cnt,
2353 : int is_end_of_slot,
2354 : long tsorig,
2355 0 : long now ) {
2356 0 : for( ulong i=gui->shreds.leader_shred_cnt; i<gui->shreds.leader_shred_cnt+fec_shred_cnt; i++ ) {
2357 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_SHRED_EVENTS, now, tsorig, &(fd_gui_slot_history_shred_event_t){ .slot = (uint)slot, .timestamp = tsorig, .shred_idx = (ushort)i, .event = FD_GUI_SLOT_SHRED_SHRED_PUBLISHED } );
2358 0 : }
2359 0 : gui->shreds.leader_shred_cnt += fec_shred_cnt;
2360 0 : if( FD_UNLIKELY( is_end_of_slot ) ) gui->shreds.leader_shred_cnt = 0UL;
2361 0 : }
2362 :
2363 : void
2364 : fd_gui_handle_exec_txn_done( fd_gui_t * gui,
2365 : ulong slot,
2366 : ulong start_shred_idx,
2367 : ulong end_shred_idx,
2368 : long tsorig_ns FD_PARAM_UNUSED,
2369 : long tspub_ns,
2370 0 : long now ) {
2371 0 : for( ulong i = start_shred_idx; i<end_shred_idx; i++ ) {
2372 : /*
2373 : We're leaving this state transition out due to its proximity to
2374 : FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE, but if we ever wanted
2375 : to send this data to the frontend we could.
2376 :
2377 : fd_gui_shred_event_append( gui, slot, i, FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_START, tsorig_ns );
2378 : */
2379 :
2380 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_SHRED_EVENTS, now, tspub_ns, &(fd_gui_slot_history_shred_event_t){ .slot = (uint)slot, .timestamp = tspub_ns, .shred_idx = (ushort)i, .event = FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE } );
2381 0 : }
2382 0 : }
2383 :
2384 : /* fd_gui_compute_vote_latency walks the fork whose landing block is
2385 : (landed_slot, landed_bank_seq) down toward voted_slot. On success
2386 : (voted_slot is an ancestor on this fork) returns 1 and writes
2387 : voted_slot's bank_seq on this fork to *out_voted_bank_seq and the
2388 : skip-discounted latency to *out_exact. Returns 0 if voted_slot is
2389 : not an ancestor on this fork, or the ancestry is not yet
2390 : replayed/linked. */
2391 :
2392 : static int
2393 : fd_gui_compute_vote_latency( fd_gui_t * gui,
2394 : ulong landed_slot,
2395 : ulong landed_bank_seq,
2396 : ulong voted_slot,
2397 : ulong * out_voted_bank_seq,
2398 0 : ulong * out_exact ) {
2399 0 : ulong on_fork_between = 0UL;
2400 0 : ulong cur_slot = landed_slot;
2401 0 : ulong cur_bank_seq = landed_bank_seq;
2402 0 : for( ulong steps=0UL; steps<1024UL; steps++ ) {
2403 0 : fd_gui_slot_t const * c = fd_gui_slot_get( gui, cur_slot, cur_bank_seq );
2404 0 : if( FD_UNLIKELY( !c ) ) return 0;
2405 0 : ulong pslot = c->parent_slot;
2406 0 : ulong pseq = c->parent_bank_seq;
2407 0 : if( FD_UNLIKELY( pslot==ULONG_MAX ) ) return 0;
2408 0 : if( FD_UNLIKELY( pslot<voted_slot ) ) return 0;
2409 0 : if( FD_LIKELY( pslot==voted_slot ) ) {
2410 0 : *out_voted_bank_seq = pseq;
2411 0 : *out_exact = 1UL + on_fork_between;
2412 0 : return 1;
2413 0 : }
2414 0 : on_fork_between++;
2415 0 : cur_slot = pslot;
2416 0 : cur_bank_seq = pseq;
2417 0 : }
2418 0 : return 0;
2419 0 : }
2420 :
2421 : /* fd_gui_record_vote_latency records the minimum vote_latency_exact
2422 : observed for the (voted_slot, voted_bank_seq) fork. */
2423 :
2424 : static void
2425 : fd_gui_record_vote_latency( fd_gui_t * gui,
2426 : ulong voted_slot,
2427 : ulong voted_bank_seq,
2428 0 : uchar vote_latency_exact ) {
2429 0 : vote_latency_exact = (uchar)fd_ulong_min( vote_latency_exact, FD_GUI_VOTE_LATENCY_MAX );
2430 :
2431 0 : fd_gui_slot_t * slot = fd_gui_slot_get( gui, voted_slot, voted_bank_seq );
2432 0 : if( FD_LIKELY( slot ) && FD_LIKELY( vote_latency_exact<slot->vote_latency_exact ) ) {
2433 0 : slot->vote_latency_exact = vote_latency_exact;
2434 0 : fd_gui_printf_slot( gui, voted_slot, slot );
2435 0 : fd_http_server_ws_broadcast( gui->http );
2436 0 : }
2437 0 : }
2438 :
2439 : void
2440 : fd_gui_handle_root_advanced( fd_gui_t * gui,
2441 : ulong _slot,
2442 : ulong bank_seq,
2443 0 : long now FD_PARAM_UNUSED ) {
2444 0 : fd_gui_slot_t * root = fd_gui_slot_get( gui, _slot, bank_seq );
2445 0 : if( FD_UNLIKELY( !root ) ) return;
2446 :
2447 : /* Rooting only ever advances. */
2448 0 : if( FD_UNLIKELY( gui->summary.slot_rooted!=ULONG_MAX && _slot<=gui->summary.slot_rooted ) ) return;
2449 :
2450 0 : ulong prev_rooted = gui->summary.slot_rooted;
2451 :
2452 0 : gui->summary.slot_rooted = _slot;
2453 0 : fd_gui_printf_root_slot( gui );
2454 0 : fd_http_server_ws_broadcast( gui->http );
2455 :
2456 0 : for( ulong cslot=_slot, cbank_seq=bank_seq; ; ) {
2457 0 : fd_gui_slot_t * c = fd_gui_slot_get( gui, cslot, cbank_seq );
2458 0 : if( FD_UNLIKELY( !c || c->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
2459 :
2460 0 : c->level = FD_GUI_SLOT_LEVEL_ROOTED;
2461 :
2462 0 : fd_gui_printf_slot( gui, cslot, c );
2463 0 : fd_http_server_ws_broadcast( gui->http );
2464 :
2465 : /* Finalize vote latencies from votes that landed in this block. */
2466 0 : for( ulong r=0UL; r<gui->landed_vote_cnt; r++ ) {
2467 0 : if( FD_UNLIKELY( gui->landed_votes[ r ].landed_slot!=cslot || gui->landed_votes[ r ].landed_bank_seq!=cbank_seq ) ) continue;
2468 0 : ulong voted_slot = gui->landed_votes[ r ].voted_slot;
2469 0 : ulong voted_bank_seq, exact;
2470 0 : if( FD_UNLIKELY( !fd_gui_compute_vote_latency( gui, cslot, cbank_seq, voted_slot, &voted_bank_seq, &exact ) ) ) continue;
2471 0 : exact = (uchar)fd_ulong_min( exact, FD_GUI_VOTE_LATENCY_MAX );
2472 0 : fd_gui_record_vote_latency( gui, voted_slot, voted_bank_seq, (uchar)exact );
2473 :
2474 0 : fd_gui_epoch_t * vepoch = fd_gui_get_epoch_by_slot( gui, voted_slot );
2475 0 : if( FD_UNLIKELY( !vepoch ) ) continue;
2476 0 : ulong vidx = voted_slot - vepoch->start_slot;
2477 0 : if( FD_UNLIKELY( vidx>=vepoch->slot_cnt ) ) continue;
2478 0 : if( FD_LIKELY( exact<vepoch->latency_exact[ vidx ] ) ) {
2479 0 : vepoch->latency_exact[ vidx ] = (uchar)exact;
2480 0 : }
2481 0 : }
2482 :
2483 0 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, cslot );
2484 0 : if( FD_LIKELY( epoch ) ) {
2485 0 : ulong cidx = cslot - epoch->start_slot;
2486 0 : if( FD_LIKELY( cidx<epoch->slot_cnt ) ) {
2487 0 : epoch->is_voter[ cidx ] = c->is_voter;
2488 :
2489 : /* This slot is on the rooted fork, so it was not skipped. */
2490 0 : epoch->skipped[ cidx ] = 0;
2491 0 : }
2492 0 : }
2493 :
2494 0 : ulong pslot = c->parent_slot, pseq = c->parent_bank_seq;
2495 0 : if( FD_UNLIKELY( pslot==ULONG_MAX || pslot>=cslot ) ) break;
2496 :
2497 : /* Record and republish newly rooted skipped slots. */
2498 0 : for( ulong s=pslot+1UL; s<cslot; s++ ) {
2499 0 : if( FD_UNLIKELY( prev_rooted!=ULONG_MAX && s<=prev_rooted ) ) continue; /* already rooted earlier */
2500 :
2501 0 : fd_gui_epoch_t * sepoch = fd_gui_get_epoch_by_slot( gui, s );
2502 0 : if( FD_LIKELY( sepoch ) ) {
2503 0 : ulong sidx = s - sepoch->start_slot;
2504 0 : if( FD_LIKELY( sidx<sepoch->slot_cnt ) ) sepoch->skipped[ sidx ] = 1;
2505 0 : }
2506 :
2507 0 : if( FD_UNLIKELY( prev_rooted==ULONG_MAX ) ) continue;
2508 :
2509 0 : fd_gui_slot_t const * skipped = fd_gui_slot_get_canon_safe( gui, s );
2510 0 : if( FD_UNLIKELY( skipped->skip!=FD_GUI_SKIP_STATUS_SKIPPED ) ) continue;
2511 0 : fd_gui_printf_slot( gui, s, skipped );
2512 0 : fd_http_server_ws_broadcast( gui->http );
2513 0 : }
2514 :
2515 0 : cslot = pslot; cbank_seq = pseq;
2516 0 : }
2517 :
2518 0 : ulong rooted_slot = gui->summary.slot_rooted;
2519 0 : ulong w = 0UL;
2520 0 : for( ulong r=0UL; r<gui->landed_vote_cnt; r++ ) {
2521 0 : if( FD_UNLIKELY( gui->landed_votes[ r ].landed_slot<=rooted_slot ) ) continue;
2522 0 : gui->landed_votes[ w++ ] = gui->landed_votes[ r ];
2523 0 : }
2524 0 : gui->landed_vote_cnt = w;
2525 0 : }
2526 :
2527 : void
2528 : fd_gui_handle_oc_advanced( fd_gui_t * gui,
2529 : ulong _slot,
2530 : ulong bank_seq,
2531 0 : long now ) {
2532 0 : (void)now;
2533 :
2534 0 : fd_gui_slot_t * live_slot = fd_gui_slot_get( gui, _slot, bank_seq );
2535 0 : if( FD_UNLIKELY( !live_slot ) ) return;
2536 :
2537 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon( gui, _slot );
2538 0 : int on_canonical_fork = ( slot && slot->bank_seq==bank_seq );
2539 0 : if( FD_UNLIKELY( !on_canonical_fork ) ) return; /* we've since switched forks so this update is invalid */
2540 :
2541 0 : ulong prev_oc = gui->summary.slot_optimistically_confirmed;
2542 :
2543 0 : int advanced = 0;
2544 0 : if( FD_LIKELY( _slot!=prev_oc ) ) {
2545 0 : gui->summary.slot_optimistically_confirmed = _slot;
2546 0 : fd_gui_printf_optimistically_confirmed_slot( gui );
2547 0 : fd_http_server_ws_broadcast( gui->http );
2548 0 : advanced = ( prev_oc==ULONG_MAX || _slot>prev_oc );
2549 0 : }
2550 :
2551 0 : for( ulong cslot=_slot, cbank_seq=bank_seq; ; ) {
2552 0 : fd_gui_slot_t * c = fd_gui_slot_get( gui, cslot, cbank_seq );
2553 0 : if( FD_UNLIKELY( !c || c->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
2554 :
2555 0 : if( FD_LIKELY( c->level<FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED ) ) {
2556 0 : c->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
2557 0 : fd_gui_printf_slot( gui, cslot, c );
2558 0 : fd_http_server_ws_broadcast( gui->http );
2559 0 : }
2560 :
2561 0 : ulong pslot = c->parent_slot, pseq = c->parent_bank_seq;
2562 0 : if( FD_UNLIKELY( pslot==ULONG_MAX || pslot>=cslot ) ) break;
2563 :
2564 : /* Republish skipped slots as well. */
2565 0 : if( FD_LIKELY( advanced ) ) {
2566 0 : for( ulong s=pslot+1UL; s<cslot; s++ ) {
2567 0 : if( FD_UNLIKELY( prev_oc!=ULONG_MAX && s<=prev_oc ) ) continue; /* already OC'd earlier */
2568 0 : if( FD_UNLIKELY( gui->summary.slot_rooted!=ULONG_MAX && s<gui->summary.slot_rooted ) ) continue; /* already rooted: handled by root advance */
2569 0 : fd_gui_slot_t const * skipped = fd_gui_slot_get_canon_safe( gui, s );
2570 0 : if( FD_UNLIKELY( skipped->skip!=FD_GUI_SKIP_STATUS_SKIPPED ) ) continue;
2571 0 : fd_gui_printf_slot( gui, s, skipped );
2572 0 : fd_http_server_ws_broadcast( gui->http );
2573 0 : }
2574 0 : }
2575 :
2576 0 : cslot = pslot; cbank_seq = pseq;
2577 0 : }
2578 0 : }
2579 :
2580 : void
2581 : fd_gui_handle_genesis_hash( fd_gui_t * gui,
2582 0 : fd_hash_t const * msg ) {
2583 0 : FD_BASE58_ENCODE_32_BYTES( msg->uc, hash_cstr );
2584 0 : ulong cluster = fd_genesis_cluster_identify(hash_cstr);
2585 0 : char const * cluster_name = fd_genesis_cluster_name(cluster);
2586 :
2587 0 : if( FD_LIKELY( strcmp( gui->summary.cluster, cluster_name ) ) ) {
2588 0 : gui->summary.cluster = fd_genesis_cluster_name(cluster);
2589 0 : fd_gui_printf_cluster( gui );
2590 0 : fd_http_server_ws_broadcast( gui->http );
2591 0 : }
2592 0 : }
2593 :
2594 : void
2595 : fd_gui_handle_block_engine_update( fd_gui_t * gui,
2596 0 : fd_bundle_block_engine_update_t const * update ) {
2597 0 : gui->block_engine.has_block_engine = 1;
2598 :
2599 : /* copy strings and ensure null termination within bounds */
2600 0 : FD_TEST( fd_cstr_nlen( update->name, sizeof(gui->block_engine.name ) ) < sizeof(gui->block_engine.name ) );
2601 0 : FD_TEST( fd_cstr_nlen( update->url, sizeof(gui->block_engine.url ) ) < sizeof(gui->block_engine.url ) );
2602 0 : FD_TEST( fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) ) < sizeof(gui->block_engine.ip_cstr) );
2603 0 : ulong name_len = fd_cstr_nlen( update->name, sizeof(gui->block_engine.name ) );
2604 0 : ulong url_len = fd_cstr_nlen( update->url, sizeof(gui->block_engine.url ) );
2605 0 : ulong ip_cstr_len = fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) );
2606 0 : fd_memcpy( gui->block_engine.name, update->name, name_len+1UL );
2607 0 : fd_memcpy( gui->block_engine.url, update->url, url_len+1UL );
2608 0 : fd_memcpy( gui->block_engine.ip_cstr, update->ip_cstr, ip_cstr_len+1UL );
2609 :
2610 0 : fd_gui_printf_block_engine( gui );
2611 0 : fd_http_server_ws_broadcast( gui->http );
2612 0 : }
2613 :
2614 : void
2615 : fd_gui_handle_snapshot_update( fd_gui_t * gui,
2616 0 : fd_snapct_update_t const * msg ) {
2617 0 : FD_TEST( msg && fd_cstr_nlen( msg->read_path, 1 ) );
2618 :
2619 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 );
2620 :
2621 0 : char const * filename = strrchr( msg->read_path, '/' );
2622 :
2623 : /* Skip the '/' */
2624 0 : if( FD_LIKELY( filename ) ) filename++;
2625 0 : else filename = msg->read_path;
2626 :
2627 0 : if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_INCREMENTAL) {
2628 0 : ulong slot1, slot2;
2629 0 : if ( FD_LIKELY( sscanf( filename, "incremental-snapshot-%lu-%lu-", &slot1, &slot2 )==2 ) )
2630 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot2;
2631 0 : else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
2632 0 : } else if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_FULL) {
2633 0 : ulong slot1;
2634 0 : if ( FD_LIKELY( sscanf( filename, "snapshot-%lu-", &slot1 )==1 ) )
2635 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot1;
2636 0 : else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
2637 0 : }
2638 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 );
2639 0 : }
2640 :
2641 : void
2642 : fd_gui_stage_snapshot_manifest( fd_gui_t * gui,
2643 0 : fd_snapshot_manifest_t const * manifest ) {
2644 0 : ulong attempt = 0UL;
2645 0 : for( ulong i=0UL; i<manifest->hard_fork_cnt; i++ ) {
2646 0 : if( FD_UNLIKELY( manifest->hard_forks[ i ].slot==manifest->slot ) ) {
2647 0 : attempt = manifest->hard_forks[ i ].cnt;
2648 0 : break;
2649 0 : }
2650 0 : }
2651 0 : gui->summary.boot_progress.wfs_attempt = attempt;
2652 0 : }
2653 :
2654 : static void
2655 : fd_gui_broadcast_skip_rate( fd_gui_t * gui,
2656 0 : ulong epoch ) {
2657 0 : fd_gui_epoch_t const * rec = fd_gui_epoch( gui, epoch );
2658 0 : if( FD_UNLIKELY( !rec ) ) return;
2659 :
2660 0 : ulong slot = epoch % 2UL;
2661 0 : if( FD_LIKELY( gui->summary.skip_rate[ slot ].epoch ==epoch
2662 0 : && gui->summary.skip_rate[ slot ].skipped==rec->my_skipped_slots
2663 0 : && gui->summary.skip_rate[ slot ].total ==rec->my_total_slots ) ) return;
2664 :
2665 0 : gui->summary.skip_rate[ slot ].epoch = epoch;
2666 0 : gui->summary.skip_rate[ slot ].skipped = rec->my_skipped_slots;
2667 0 : gui->summary.skip_rate[ slot ].total = rec->my_total_slots;
2668 :
2669 0 : fd_gui_printf_skip_rate( gui, epoch );
2670 0 : fd_http_server_ws_broadcast( gui->http );
2671 0 : }
2672 :
2673 : static void
2674 0 : handle_tower_slot( fd_gui_t * gui, ulong reset_slot, ulong reset_bank_seq, long now FD_PARAM_UNUSED ) {
2675 0 : FD_TEST( reset_slot!=ULONG_MAX );
2676 :
2677 0 : ulong prev_reset_slot = gui->summary.slot_tower;
2678 0 : ulong prev_reset_bank_seq = gui->summary.slot_tower_bank_seq;
2679 0 : gui->summary.slot_tower = reset_slot;
2680 0 : gui->summary.slot_tower_bank_seq = reset_bank_seq;
2681 :
2682 : /* reset_slot is guaranteed present (returnable_frag deferred this
2683 : update until replay recorded it). */
2684 0 : FD_TEST( fd_gui_slot_get( gui, gui->summary.slot_tower, gui->summary.slot_tower_bank_seq ) );
2685 :
2686 : /* reset_slot has not changed */
2687 0 : if( FD_UNLIKELY( prev_reset_slot!=ULONG_MAX && reset_slot==prev_reset_slot && reset_bank_seq!=ULONG_MAX && reset_bank_seq==prev_reset_bank_seq ) ) return;
2688 :
2689 0 : fd_gui_printf_completed_slot( gui );
2690 0 : fd_http_server_ws_broadcast( gui->http );
2691 :
2692 : /* ensure a history exists */
2693 0 : if( FD_UNLIKELY( prev_reset_slot==ULONG_MAX || gui->summary.slot_rooted==ULONG_MAX ) ) return;
2694 :
2695 : /* slot complete received out of order on the same fork? */
2696 0 : FD_TEST( fd_gui_slot_is_ancestor( gui, prev_reset_slot, gui->summary.slot_tower ) || !fd_gui_slot_is_ancestor( gui, gui->summary.slot_tower, prev_reset_slot ) );
2697 :
2698 : /* Switch forks. */
2699 0 : for( ulong slot=fd_ulong_max( gui->summary.slot_tower, prev_reset_slot ); slot>gui->summary.slot_rooted; slot-- ) {
2700 0 : int skipped_old = slot<=prev_reset_slot && fd_gui_slot_is_skipped( gui, gui->summary.slot_rooted, prev_reset_slot, prev_reset_bank_seq, slot );
2701 0 : int skipped_new = slot<=gui->summary.slot_tower && fd_gui_slot_is_skipped( gui, gui->summary.slot_rooted, gui->summary.slot_tower, reset_bank_seq, slot );
2702 0 : if( FD_LIKELY( skipped_old!=skipped_new ) ) {
2703 0 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, slot );
2704 0 : if( FD_LIKELY( epoch && fd_gui_slot_is_mine( gui, slot ) ) ) {
2705 0 : if( skipped_new ) epoch->my_skipped_slots = fd_ulong_sat_add( epoch->my_skipped_slots, 1UL );
2706 0 : else epoch->my_skipped_slots = fd_ulong_sat_sub( epoch->my_skipped_slots, 1UL );
2707 0 : }
2708 0 : }
2709 :
2710 : /* Publish new/changed slots */
2711 0 : if( FD_LIKELY( skipped_old!=skipped_new || slot>prev_reset_slot ) ) {
2712 0 : fd_gui_printf_slot( gui, slot, fd_gui_slot_get_canon_safe( gui, slot ) );
2713 0 : fd_http_server_ws_broadcast( gui->http );
2714 0 : }
2715 :
2716 : /* Persist skip status */
2717 0 : fd_gui_slot_t * canon = fd_gui_slot_get_canon( gui, slot );
2718 0 : ulong canon_bank_seq = canon ? canon->bank_seq : ULONG_MAX; /* canon, if any, IS slot */
2719 0 : fd_gui_hist_kv_slot_iter_t it[ 1 ];
2720 0 : for( fd_gui_hist_kv_iter_begin( gui, it, FD_GUI_HIST_SLOT, slot ); it->rec; fd_gui_hist_kv_iter_next( it ) ) {
2721 0 : ((fd_gui_slot_t *)it->rec)->skip = fd_uchar_if( it->bank_seq==canon_bank_seq, FD_GUI_SKIP_STATUS_NOT_SKIPPED, FD_GUI_SKIP_STATUS_SKIPPED );
2722 0 : }
2723 0 : }
2724 :
2725 0 : for( ulong e=gui->epoch.current_epoch; e<=gui->epoch.current_epoch+1UL; e++ ) fd_gui_broadcast_skip_rate( gui, e );
2726 0 : }
2727 :
2728 : static inline void
2729 : set_vote_state( fd_gui_t * gui,
2730 0 : int vote_state ) {
2731 0 : if( FD_UNLIKELY( gui->summary.vote_state!=vote_state ) ) {
2732 0 : gui->summary.vote_state = vote_state;
2733 0 : fd_gui_printf_vote_state( gui );
2734 0 : fd_http_server_ws_broadcast( gui->http );
2735 0 : }
2736 0 : }
2737 :
2738 : static inline void
2739 : publish_vote_status( fd_gui_t * gui,
2740 0 : int is_voting ) {
2741 0 : if( FD_UNLIKELY( !is_voting ) ) {
2742 0 : set_vote_state( gui, FD_GUI_VOTE_STATE_NON_VOTING );
2743 0 : return;
2744 0 : }
2745 :
2746 0 : fd_gui_slot_t * slot = fd_gui_slot_get( gui, gui->summary.slot_tower, gui->summary.slot_tower_bank_seq );
2747 0 : FD_TEST( slot );
2748 :
2749 0 : if( FD_UNLIKELY( gui->summary.slot_tower==ULONG_MAX ) ) return;
2750 :
2751 0 : if( FD_UNLIKELY( slot->vote_slot==ULONG_MAX ) ) {
2752 : /* Voting is enabled but no vote has landed yet. */
2753 0 : set_vote_state( gui, FD_GUI_VOTE_STATE_DELINQUENT );
2754 0 : return;
2755 0 : }
2756 :
2757 : /* Snapshot the fields before the inner loop (which re-resolves slots). */
2758 0 : ulong vote_slot = slot->vote_slot;
2759 0 : ulong reset_slot = gui->summary.slot_tower;
2760 :
2761 0 : ulong vote_distance = reset_slot-vote_slot;
2762 0 : if( FD_LIKELY( vote_distance<FD_GUI_MAX_VOTE_DISTANCE ) ) {
2763 0 : for( ulong s=vote_slot; s<reset_slot; s++ ) {
2764 0 : if( FD_UNLIKELY( !fd_gui_slot_get_canon( gui, s ) ) ) vote_distance--;
2765 0 : }
2766 0 : }
2767 :
2768 0 : if( FD_UNLIKELY( gui->summary.vote_distance!=vote_distance ) ) {
2769 0 : gui->summary.vote_distance = vote_distance;
2770 0 : fd_gui_printf_vote_distance( gui );
2771 0 : fd_http_server_ws_broadcast( gui->http );
2772 0 : }
2773 :
2774 0 : if( FD_UNLIKELY( vote_slot==ULONG_MAX || vote_distance>150UL ) ) {
2775 0 : set_vote_state( gui, FD_GUI_VOTE_STATE_DELINQUENT );
2776 0 : } else {
2777 0 : set_vote_state( gui, FD_GUI_VOTE_STATE_VOTING );
2778 0 : }
2779 0 : }
2780 :
2781 : /* fd_gui_handle_tower_update handles updates from the tower tile, which
2782 : manages consensus related fork switching, rooting, slot confirmation.
2783 :
2784 : The gui tile consumes tower_out via returnable_frag and defers any
2785 : update whose replay_slot has not yet been recorded from replay, so by
2786 : the time this runs both tower->replay_slot and tower->reset_slot are
2787 : guaranteed to have a DB record. */
2788 : void
2789 : fd_gui_handle_tower_update( fd_gui_t * gui,
2790 : fd_tower_slot_done_t const * tower,
2791 0 : long now ) {
2792 0 : if( FD_UNLIKELY( tower->active_fork_cnt!=gui->summary.active_fork_cnt ) ) {
2793 0 : gui->summary.active_fork_cnt = tower->active_fork_cnt;
2794 0 : fd_gui_printf_active_fork_cnt( gui );
2795 0 : fd_http_server_ws_broadcast( gui->http );
2796 0 : }
2797 :
2798 0 : fd_gui_slot_t * replay_slot = fd_gui_slot_get( gui, tower->replay_slot, tower->replay_bank_seq );
2799 0 : FD_TEST( replay_slot );
2800 0 : replay_slot->is_voter = (uchar)(!!tower->is_voting);
2801 :
2802 : /* Handle already-rooted edge case. */
2803 0 : if( FD_UNLIKELY( replay_slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) {
2804 0 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, tower->replay_slot );
2805 0 : if( FD_LIKELY( epoch ) ) {
2806 0 : ulong cidx = tower->replay_slot - epoch->start_slot;
2807 0 : if( FD_LIKELY( cidx<epoch->slot_cnt ) ) epoch->is_voter[ cidx ] = replay_slot->is_voter;
2808 0 : }
2809 0 : }
2810 :
2811 0 : if( FD_LIKELY( tower->reset_slot!=ULONG_MAX ) ) {
2812 0 : handle_tower_slot( gui, tower->reset_slot, tower->reset_bank_seq, now );
2813 0 : publish_vote_status( gui, tower->is_voting );
2814 0 : } else if( FD_UNLIKELY( !tower->is_voting ) ) {
2815 : /* NON_VOTING does not need a reset slot, unlike publish_vote_status. */
2816 0 : set_vote_state( gui, FD_GUI_VOTE_STATE_NON_VOTING );
2817 0 : }
2818 :
2819 0 : if( FD_LIKELY( gui->summary.slot_reset!=tower->reset_slot ) ) {
2820 0 : gui->summary.slot_reset = tower->reset_slot;
2821 0 : fd_gui_printf_reset_slot( gui );
2822 0 : fd_http_server_ws_broadcast( gui->http );
2823 0 : }
2824 :
2825 0 : if( FD_UNLIKELY( tower->vote_acct_bal!=ULONG_MAX && gui->summary.vote_account_balance!=tower->vote_acct_bal ) ) {
2826 0 : gui->summary.vote_account_balance = tower->vote_acct_bal;
2827 0 : fd_gui_printf_vote_balance( gui );
2828 0 : fd_http_server_ws_broadcast( gui->http );
2829 0 : }
2830 :
2831 0 : if( FD_UNLIKELY( gui->summary.vote_commission!=tower->vote_acct_com ) ) {
2832 0 : gui->summary.vote_commission = tower->vote_acct_com;
2833 0 : fd_gui_printf_vote_commission( gui );
2834 0 : fd_http_server_ws_broadcast( gui->http );
2835 0 : }
2836 :
2837 : /* Update vote latencies. This is the speculative, true correct
2838 : latencies are published as a vote's landed slot is rooted. */
2839 0 : for( ulong r=0UL; r<gui->landed_vote_cnt; r++ ) {
2840 0 : if( FD_UNLIKELY( gui->landed_votes[ r ].landed_slot>gui->summary.slot_tower ) ) continue;
2841 :
2842 0 : ulong voted_bank_seq, exact;
2843 0 : if( FD_UNLIKELY( !fd_gui_compute_vote_latency( gui, gui->landed_votes[ r ].landed_slot, gui->landed_votes[ r ].landed_bank_seq, gui->landed_votes[ r ].voted_slot, &voted_bank_seq, &exact ) ) ) continue;
2844 0 : exact = (uchar)fd_ulong_min( exact, FD_GUI_VOTE_LATENCY_MAX );
2845 0 : fd_gui_slot_t * slot = fd_gui_slot_get( gui, gui->landed_votes[ r ].voted_slot, voted_bank_seq );
2846 0 : if( FD_UNLIKELY( !slot ) ) continue;
2847 :
2848 0 : if( FD_LIKELY( exact>=slot->vote_latency_exact ) ) continue;
2849 0 : fd_gui_record_vote_latency( gui, gui->landed_votes[ r ].voted_slot, voted_bank_seq, (uchar)exact );
2850 0 : }
2851 0 : }
2852 :
2853 : void
2854 : fd_gui_stage_landed_vote( fd_gui_t * gui,
2855 : ulong landed_slot,
2856 : ulong landed_bank_seq,
2857 0 : ulong voted_slot ) {
2858 0 : if( FD_UNLIKELY( voted_slot==ULONG_MAX || voted_slot>=landed_slot ) ) return;
2859 :
2860 : /* Handle already-rooted edge case. */
2861 0 : if( FD_UNLIKELY( gui->summary.slot_rooted!=ULONG_MAX && landed_slot<=gui->summary.slot_rooted ) ) {
2862 0 : fd_gui_slot_t const * canon = fd_gui_slot_get_canon( gui, landed_slot );
2863 0 : if( FD_UNLIKELY( !canon || canon->bank_seq!=landed_bank_seq ) ) return;
2864 0 : ulong voted_bank_seq, exact;
2865 0 : if( FD_UNLIKELY( !fd_gui_compute_vote_latency( gui, landed_slot, landed_bank_seq, voted_slot, &voted_bank_seq, &exact ) ) ) return;
2866 0 : exact = (uchar)fd_ulong_min( exact, FD_GUI_VOTE_LATENCY_MAX );
2867 0 : fd_gui_record_vote_latency( gui, voted_slot, voted_bank_seq, (uchar)exact );
2868 :
2869 0 : fd_gui_epoch_t * vepoch = fd_gui_get_epoch_by_slot( gui, voted_slot );
2870 0 : if( FD_UNLIKELY( !vepoch ) ) return;
2871 0 : ulong vidx = voted_slot - vepoch->start_slot;
2872 0 : if( FD_UNLIKELY( vidx>=vepoch->slot_cnt ) ) return;
2873 0 : if( FD_LIKELY( exact<vepoch->latency_exact[ vidx ] ) ) {
2874 0 : vepoch->latency_exact[ vidx ] = (uchar)exact;
2875 0 : }
2876 0 : return;
2877 0 : }
2878 :
2879 0 : if( FD_UNLIKELY( gui->landed_vote_cnt>=FD_GUI_LANDED_VOTE_MAX ) ) return;
2880 :
2881 0 : gui->landed_votes[ gui->landed_vote_cnt ].landed_slot = landed_slot;
2882 0 : gui->landed_votes[ gui->landed_vote_cnt ].landed_bank_seq = landed_bank_seq;
2883 0 : gui->landed_votes[ gui->landed_vote_cnt ].voted_slot = voted_slot;
2884 0 : gui->landed_vote_cnt++;
2885 0 : }
2886 :
2887 : void
2888 : fd_gui_handle_replay_update( fd_gui_t * gui,
2889 : fd_replay_slot_completed_t const * slot_completed,
2890 : ulong vote_slot,
2891 0 : long now ) {
2892 0 : if( FD_LIKELY( gui->summary.slot_storage!=slot_completed->storage_slot ) ) {
2893 0 : gui->summary.slot_storage = slot_completed->storage_slot;
2894 0 : fd_gui_printf_storage_slot( gui );
2895 0 : fd_http_server_ws_broadcast( gui->http );
2896 0 : }
2897 :
2898 0 : if( FD_UNLIKELY( slot_completed->identity_balance!=ULONG_MAX && gui->summary.identity_account_balance!=slot_completed->identity_balance ) ) {
2899 0 : gui->summary.identity_account_balance = slot_completed->identity_balance;
2900 :
2901 0 : fd_gui_printf_identity_balance( gui );
2902 0 : fd_http_server_ws_broadcast( gui->http );
2903 0 : }
2904 :
2905 0 : if( FD_UNLIKELY( gui->summary.boot_progress.catching_up_first_replay_slot==ULONG_MAX ) ) {
2906 0 : gui->summary.boot_progress.catching_up_first_replay_slot = slot_completed->slot;
2907 0 : }
2908 :
2909 0 : fd_gui_slot_t * slot = fd_gui_slot_get_or_create( gui,
2910 0 : slot_completed->slot,
2911 0 : slot_completed->parent_slot,
2912 0 : slot_completed->bank_seq,
2913 0 : slot_completed->parent_bank_seq );
2914 0 : if( FD_UNLIKELY( !slot ) ) return; /* record could not be created / was evicted */
2915 :
2916 0 : slot->completed_time = slot_completed->completion_time_nanos;
2917 0 : slot->parent_slot = slot_completed->parent_slot;
2918 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 );
2919 :
2920 0 : fd_gui_slot_t const * parent = fd_gui_slot_parent_get( gui, slot );
2921 0 : slot->parent_completed_time = parent ? parent->completed_time : LONG_MAX;
2922 :
2923 0 : if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_COMPLETED ) ) {
2924 : /* Typically a slot goes from INCOMPLETE to COMPLETED but it can
2925 : happen that it starts higher. One such case is when we
2926 : optimistically confirm a higher slot that skips this one, but
2927 : then later we replay this one anyway to track the bank fork. */
2928 :
2929 0 : if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && slot_completed->slot<gui->summary.slot_optimistically_confirmed ) ) {
2930 : /* Cluster might have already optimistically confirmed by the time
2931 : we finish replaying it. */
2932 0 : slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
2933 0 : } else {
2934 0 : slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
2935 0 : }
2936 0 : }
2937 0 : slot->vote_failed = fd_uint_if( slot_completed->vote_failed==ULONG_MAX, slot->vote_failed, (uint)slot_completed->vote_failed );
2938 0 : slot->vote_success = fd_uint_if( slot_completed->vote_success==ULONG_MAX, slot->vote_success, (uint)slot_completed->vote_success );
2939 0 : slot->nonvote_success = fd_uint_if( slot_completed->nonvote_success==ULONG_MAX, slot->nonvote_success, (uint)slot_completed->nonvote_success );
2940 0 : slot->nonvote_failed = fd_uint_if( slot_completed->nonvote_failed==ULONG_MAX, slot->nonvote_failed, (uint)slot_completed->nonvote_failed );
2941 :
2942 0 : slot->transaction_fee = slot_completed->transaction_fee;
2943 0 : slot->priority_fee = slot_completed->priority_fee;
2944 0 : slot->tips = slot_completed->tips;
2945 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 );
2946 0 : slot->shred_cnt = fd_uint_if( slot_completed->shred_cnt==ULONG_MAX, slot->shred_cnt, (uint)slot_completed->shred_cnt );
2947 0 : slot->vote_slot = vote_slot;
2948 0 : slot->block_hash = slot_completed->block_hash;
2949 :
2950 0 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, slot_completed->slot );
2951 0 : if( FD_UNLIKELY( epoch && slot_completed->slot==epoch->start_slot+epoch->slot_cnt-1UL ) ) epoch->end_time = slot->completed_time;
2952 :
2953 0 : if( FD_UNLIKELY( slot->mine ) ) {
2954 0 : fd_gui_leader_slot_t * lmeta = fd_gui_slot_leader_get_or_create( gui, slot_completed->slot, slot_completed->bank_seq );
2955 0 : if( FD_LIKELY( lmeta ) ) lmeta->block_hash = slot_completed->block_hash;
2956 :
2957 0 : fd_gui_epoch_t const * epoch = fd_gui_get_epoch_by_slot( gui, slot_completed->slot );
2958 0 : if( FD_LIKELY( epoch ) ) fd_gui_broadcast_skip_rate( gui, epoch->epoch );
2959 0 : }
2960 :
2961 : /* Add a "slot complete" event for all of the shreds in this slot */
2962 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_SHRED_EVENTS, now, slot_completed->completion_time_nanos, &(fd_gui_slot_history_shred_event_t){ .slot = (uint)slot_completed->slot, .timestamp = slot_completed->completion_time_nanos, .shred_idx = USHORT_MAX, .event = FD_GUI_SLOT_SHRED_SHRED_SLOT_COMPLETE } );
2963 :
2964 : /* Set skip status based on the current tower-derived canonical fork. */
2965 0 : fd_gui_slot_t * canon = fd_gui_slot_get_canon( gui, slot_completed->slot );
2966 0 : slot->skip = fd_uchar_if( canon && canon->bank_seq==slot_completed->bank_seq, FD_GUI_SKIP_STATUS_NOT_SKIPPED, FD_GUI_SKIP_STATUS_UNKNOWN );
2967 :
2968 : /* fixes race if we just sample right after replay's SLOT_COMPLETE */
2969 0 : if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
2970 : /* Backtest topologies have no repair tile. */
2971 0 : ulong repair_tile_idx = fd_topo_find_tile( gui->topo, "repair", 0UL );
2972 0 : if( FD_LIKELY( repair_tile_idx!=ULONG_MAX ) ) {
2973 0 : fd_topo_tile_t const * repair = &gui->topo->tiles[ repair_tile_idx ];
2974 0 : volatile ulong const * repair_metrics = fd_metrics_tile( repair->metrics );
2975 0 : ulong slot = repair_metrics[ MIDX( GAUGE, REPAIR, SLOT_HIGHEST_REPAIRED ) ];
2976 0 : fd_gui_handle_repair_slot( gui, slot, now );
2977 0 : }
2978 0 : }
2979 :
2980 : /* Update slot_turbine when we are leader. */
2981 0 : if( FD_UNLIKELY( gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && slot_completed->slot > gui->summary.slots_max_turbine[ 0 ].slot ) ) {
2982 0 : fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot_completed->slot, now );
2983 0 : }
2984 :
2985 0 : int slot_turbine_hist_full = gui->summary.slots_max_turbine[ FD_GUI_TURBINE_SLOT_HISTORY_SZ-1UL ].slot!=ULONG_MAX;
2986 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX && slot_turbine_hist_full && gui->summary.slots_max_turbine[ 0 ].slot < (slot_completed->slot + 3UL) ) ) {
2987 0 : gui->summary.slot_caught_up = slot_completed->slot + 4UL;
2988 :
2989 0 : fd_gui_printf_slot_caught_up( gui );
2990 0 : fd_http_server_ws_broadcast( gui->http );
2991 0 : }
2992 0 : }
2993 :
2994 : void
2995 : fd_gui_became_leader( fd_gui_t * gui,
2996 : ulong _slot,
2997 : long start_time_nanos,
2998 : long end_time_nanos,
2999 : ulong max_compute_units FD_PARAM_UNUSED,
3000 : ulong max_microblocks,
3001 0 : ulong bank_seq ) {
3002 0 : if( FD_UNLIKELY( fd_gui_slot_is_mine( gui, _slot ) && !fd_gui_slot_is_mine( gui, _slot-1UL ) ) ) {
3003 0 : gui->leader_active = 1;
3004 0 : }
3005 :
3006 0 : fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_or_create( gui, _slot, bank_seq );
3007 0 : if( FD_UNLIKELY( !lslot ) ) return;
3008 :
3009 0 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, start_time_nanos, lslot->leader_start_time );
3010 0 : lslot->leader_end_time = end_time_nanos;
3011 0 : lslot->max_microblocks = max_microblocks;
3012 0 : if( FD_LIKELY( lslot->microblocks_upper_bound==UINT_MAX ) ) lslot->microblocks_upper_bound = (uint)max_microblocks;
3013 0 : }
3014 :
3015 : void
3016 : fd_gui_unbecame_leader( fd_gui_t * gui,
3017 : ulong _slot,
3018 : fd_done_packing_t const * done_packing,
3019 0 : long now FD_PARAM_UNUSED ) {
3020 0 : if( FD_UNLIKELY( fd_gui_slot_is_mine( gui, _slot ) && !fd_gui_slot_is_mine( gui, _slot+1UL ) ) ) {
3021 0 : gui->leader_active = 0;
3022 0 : }
3023 :
3024 0 : fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_any( gui, _slot );
3025 0 : if( FD_LIKELY( !lslot ) ) return;
3026 0 : lslot->microblocks_upper_bound = (uint)done_packing->microblocks_in_slot;
3027 0 : fd_memcpy( lslot->scheduler_stats, done_packing, sizeof(fd_done_packing_t) );
3028 0 : lslot->unbecame_leader = 1;
3029 0 : }
3030 :
3031 : void
3032 : fd_gui_microblock_execution_begin( fd_gui_t * gui,
3033 : long tspub_ns,
3034 : ulong _slot,
3035 : fd_txn_e_t * txns,
3036 : ulong txn_cnt,
3037 : uint microblock_idx,
3038 : ulong pack_txn_idx,
3039 : ulong bank_seq,
3040 0 : long now ) {
3041 0 : fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_or_create( gui, _slot, bank_seq );
3042 0 : if( FD_UNLIKELY( !lslot ) ) return;
3043 :
3044 0 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, tspub_ns, lslot->leader_start_time );
3045 :
3046 0 : for( ulong i=0UL; i<txn_cnt; i++ ) {
3047 0 : fd_txn_p_t * txn_payload = txns[ i ].txnp;
3048 0 : fd_txn_t * txn = TXN( txn_payload );
3049 :
3050 0 : ulong sig_rewards = FD_PACK_FEE_PER_SIGNATURE * txn->signature_cnt;
3051 0 : ulong priority_rewards = ULONG_MAX;
3052 0 : ulong requested_execution_cus = ULONG_MAX;
3053 0 : ulong precompile_sigs = ULONG_MAX;
3054 0 : ulong requested_loaded_accounts_data_cost = ULONG_MAX;
3055 0 : ulong allocated_data = ULONG_MAX;
3056 0 : uint _flags = 0U;
3057 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 );
3058 0 : sig_rewards += FD_PACK_FEE_PER_SIGNATURE * precompile_sigs;
3059 0 : sig_rewards = sig_rewards * FD_PACK_TXN_FEE_BURN_PCT / 100UL;
3060 :
3061 0 : ulong txn_idx = pack_txn_idx + i;
3062 0 : uchar flags = (uchar)FD_GUI_TXN_FLAGS_STARTED;
3063 0 : flags |= (uchar)fd_uint_if( !!(txn_payload->flags & FD_TXN_P_FLAGS_IS_SIMPLE_VOTE), FD_GUI_TXN_FLAGS_IS_SIMPLE_VOTE, 0U );
3064 0 : 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 );
3065 :
3066 0 : fd_gui_store_txn_start_t rec = {
3067 0 : .slot = _slot,
3068 0 : .bank_seq = bank_seq,
3069 0 : .txn_idx = txn_idx,
3070 0 : .transaction_fee = sig_rewards,
3071 0 : .priority_fee = priority_rewards,
3072 0 : .timestamp_arrival_nanos = txn_payload->scheduler_arrival_time_nanos,
3073 0 : .microblock_start_ns = tspub_ns,
3074 0 : .compute_units_requested = (uint)(cost_estimate & 0x1FFFFFU),
3075 0 : .microblock_idx = microblock_idx,
3076 0 : .source_ipv4 = txn_payload->source_ipv4,
3077 0 : .source_tpu = txn_payload->source_tpu,
3078 0 : .flags = flags
3079 0 : };
3080 0 : fd_memcpy( rec.signature, txn_payload->payload + txn->signature_off, FD_SHA512_HASH_SZ );
3081 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TXN_START, now, tspub_ns, &rec );
3082 0 : }
3083 :
3084 : /* At the moment, bank publishes at most 1 transaction per microblock,
3085 : even if it received microblocks with multiple transactions
3086 : (i.e. a bundle). This means that we need to calculate microblock
3087 : count here based on the transaction count. */
3088 0 : lslot->begin_microblocks += (uint)txn_cnt;
3089 0 : }
3090 :
3091 : static void
3092 : fd_gui_stage_leader_block_votes( fd_gui_t * gui,
3093 : ulong landed_slot,
3094 : ulong landed_bank_seq,
3095 0 : fd_txn_p_t * txn_p ) {
3096 0 : if( FD_LIKELY( !(txn_p->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS) || (txn_p->flags & (FD_TXN_P_FLAGS_FEES_ONLY | FD_TXN_P_FLAGS_RESULT_MASK)) ) ) return;
3097 :
3098 0 : fd_txn_t const * txn = TXN( txn_p );
3099 0 : uchar const * payload = txn_p->payload;
3100 :
3101 0 : fd_compact_tower_sync_serde_t tower_sync[ 1 ];
3102 0 : if( FD_UNLIKELY( !fd_txn_parse_simple_vote( txn, payload, tower_sync ) ) ) return;
3103 :
3104 0 : fd_acct_addr_t const * accs = fd_txn_get_acct_addrs( txn, payload );
3105 0 : if( FD_UNLIKELY( memcmp( &accs[ 0 ], gui->summary.identity_key->uc, sizeof(fd_pubkey_t) ) ) ) return; /* not our identity */
3106 0 : if( FD_UNLIKELY( gui->summary.has_vote_key && memcmp( &accs[ txn->signature_cnt==1 ? 1 : 2 ], gui->summary.vote_key->uc, sizeof(fd_pubkey_t) ) ) ) return; /* not our vote account */
3107 :
3108 0 : ulong cur = fd_ulong_if( tower_sync->root==ULONG_MAX, 0UL, tower_sync->root );
3109 0 : for( ulong i=0UL; i<tower_sync->lockouts_cnt; i++ ) {
3110 0 : if( FD_UNLIKELY( __builtin_uaddl_overflow( cur, tower_sync->lockouts[ i ].offset, &cur ) ) ) return;
3111 0 : fd_gui_stage_landed_vote( gui, landed_slot, landed_bank_seq, cur );
3112 0 : }
3113 0 : }
3114 :
3115 : void
3116 : fd_gui_microblock_execution_end( fd_gui_t * gui,
3117 : long tspub_ns,
3118 : ulong bank_idx,
3119 : ulong _slot,
3120 : ulong txn_cnt,
3121 : fd_txn_p_t * txns,
3122 : ulong pack_txn_idx,
3123 : fd_txn_ns_dt_t txn_ns_dt,
3124 : ulong tips,
3125 : ulong bank_seq,
3126 0 : long now ) {
3127 0 : if( FD_UNLIKELY( 1UL!=txn_cnt ) ) FD_LOG_ERR(( "gui expects 1 txn per microblock from bank, found %lu", txn_cnt ));
3128 :
3129 0 : fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_or_create( gui, _slot, bank_seq );
3130 0 : if( FD_UNLIKELY( !lslot ) ) return;
3131 :
3132 0 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, tspub_ns, lslot->leader_start_time );
3133 :
3134 0 : for( ulong i=0UL; i<txn_cnt; i++ ) {
3135 0 : fd_txn_p_t * txn_p = &txns[ i ];
3136 0 : ulong txn_idx = pack_txn_idx + i;
3137 :
3138 0 : uchar flags = (uchar)FD_GUI_TXN_FLAGS_ENDED;
3139 0 : flags |= (uchar)fd_uint_if( !!(txn_p->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS), FD_GUI_TXN_FLAGS_LANDED_IN_BLOCK, 0U );
3140 :
3141 0 : fd_gui_store_txn_end_t rec = {
3142 0 : .slot = _slot,
3143 0 : .bank_seq = bank_seq,
3144 0 : .txn_idx = txn_idx,
3145 0 : .timestamp_arrival_nanos = txn_p->scheduler_arrival_time_nanos,
3146 0 : .microblock_end_ns = tspub_ns,
3147 0 : .txn_ns_dt = txn_ns_dt,
3148 0 : .tips = tips,
3149 0 : .compute_units_consumed = (uint)(txn_p->execle_cu.actual_consumed_cus & 0x1FFFFFU),
3150 0 : .bank_idx = (uint)(bank_idx & 0x3FU),
3151 0 : .error_code = (uint)((txn_p->flags >> 24) & 0x3FU),
3152 0 : .flags = flags
3153 0 : };
3154 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TXN_END, now, tspub_ns, &rec );
3155 :
3156 : /* Record our own votes that land in our own leader block. */
3157 0 : fd_gui_stage_leader_block_votes( gui, _slot, bank_seq, txn_p );
3158 0 : }
3159 :
3160 0 : lslot->end_microblocks = lslot->end_microblocks + (uint)txn_cnt;
3161 0 : }
|