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 "../../ballet/json/fd_jtok.h"
12 : #include "../../ballet/shred/fd_shred.h"
13 : #include "../../disco/genesis/fd_genesis_cluster.h"
14 : #include "../../disco/pack/fd_pack.h"
15 : #include "../../disco/pack/fd_pack_cost.h"
16 : #include "../shred/fd_fec_set.h"
17 :
18 : FD_STATIC_ASSERT( FD_FEC_SHRED_CNT==32UL, fec_shred_count );
19 :
20 : #include <stdio.h>
21 :
22 : FD_FN_CONST ulong
23 621 : fd_gui_align( void ) {
24 621 : return 128UL;
25 621 : }
26 :
27 : ulong
28 : fd_gui_footprint( ulong tile_cnt,
29 : ulong max_live_slots,
30 138 : ulong max_txn_per_slot ) {
31 138 : FD_TEST( tile_cnt && tile_cnt <=FD_DIAG_SYSTEM_TILE_MAX );
32 138 : FD_TEST( max_live_slots && max_live_slots<=ULONG_MAX/sizeof(fd_gui_ag_slot_t) );
33 138 : FD_TEST( max_txn_per_slot && max_txn_per_slot<=ULONG_MAX/sizeof(fd_gui_store_txn_start_t) );
34 :
35 138 : ulong l = FD_LAYOUT_INIT;
36 138 : l = FD_LAYOUT_APPEND( l, fd_gui_align(), sizeof(fd_gui_t) );
37 138 : l = FD_LAYOUT_APPEND( l, alignof(fd_gui_ag_slot_t), max_live_slots*sizeof(fd_gui_ag_slot_t) );
38 138 : l = FD_LAYOUT_APPEND( l, fd_gui_rate_deque_align(), fd_gui_rate_deque_footprint() ); /* ingress_maxq */
39 138 : l = FD_LAYOUT_APPEND( l, fd_gui_rate_deque_align(), fd_gui_rate_deque_footprint() ); /* egress_maxq */
40 138 : l = FD_LAYOUT_APPEND( l, fd_gui_hist_align(), fd_gui_hist_footprint() );
41 138 : l = FD_LAYOUT_APPEND( l, alignof(fd_gui_store_txn_start_t), max_txn_per_slot*sizeof(fd_gui_store_txn_start_t) );
42 138 : l = FD_LAYOUT_APPEND( l, alignof(fd_gui_store_txn_end_t), max_txn_per_slot*sizeof(fd_gui_store_txn_end_t) );
43 138 : l = FD_LAYOUT_APPEND( l, alignof(fd_gui_slot_txn_join_t), max_txn_per_slot*sizeof(fd_gui_slot_txn_join_t) );
44 138 : l = FD_LAYOUT_APPEND( l, alignof(fd_gui_shred_scratch_t), FD_GUI_SHRED_SCRATCH_MAX*sizeof(fd_gui_shred_scratch_t) );
45 138 : l = FD_LAYOUT_APPEND( l, alignof(long), FD_GUI_EXEC_DONE_SLOT_CNT*FD_SHRED_BLK_MAX*sizeof(long) );
46 138 : return FD_LAYOUT_FINI( l, fd_gui_align() );
47 138 : }
48 :
49 : static inline void
50 0 : fd_gui_build_tile_order( fd_gui_t * gui ) {
51 0 : ulong tile_cnt = gui->topo->tile_cnt;
52 0 : ulong order_cnt = 0UL;
53 0 : uchar placed[ FD_DIAG_SYSTEM_TILE_MAX ] = {0};
54 :
55 0 : char const * const tile_display_order[] = {
56 0 : "gossvf", "gossip", "snapct", "snapld", "snapdc", "snapin",
57 0 : "net", "shred", "repair", "replay", "execrp", "votor", "sign",
58 0 : "quic", "verify", "dedup", "pack", "execle"
59 0 : };
60 :
61 0 : for( ulong n=0UL; n<sizeof(tile_display_order)/sizeof(tile_display_order[0]); n++ ) {
62 0 : for( ulong i=0UL; i<tile_cnt; i++ ) {
63 0 : if( FD_LIKELY( placed[ i ] ) ) continue;
64 0 : if( FD_UNLIKELY( !strcmp( gui->topo->tiles[ i ].name, tile_display_order[ n ] ) ) ) {
65 0 : gui->summary.tile[ order_cnt++ ] = i;
66 0 : placed[ i ] = 1;
67 0 : }
68 0 : }
69 0 : }
70 :
71 0 : for( ulong i=0UL; i<tile_cnt; i++ ) {
72 0 : if( FD_UNLIKELY( !placed[ i ] ) ) gui->summary.tile[ order_cnt++ ] = i;
73 0 : }
74 :
75 0 : gui->summary.tile_cnt = order_cnt;
76 0 : }
77 :
78 : void *
79 : fd_gui_new( void * shmem,
80 : fd_http_server_t * http,
81 : char const * version,
82 : char const * cluster,
83 : uchar const * identity_key,
84 : int has_vote_key,
85 : uchar const * vote_key,
86 : ulong max_live_slots,
87 : ulong max_txn_per_slot,
88 : int snapshots_enabled,
89 : int is_voting,
90 : int schedule_strategy,
91 : char const * wfs_expected_bank_hash_cstr,
92 : ushort expected_shred_version,
93 : ulong wfs_slot,
94 : char const * accounts_database_path,
95 : char const * gui_database_path,
96 : void * db,
97 : fd_topo_t const * topo,
98 : fd_accdb_shmem_t const * accdb_shmem,
99 0 : long now ) {
100 :
101 0 : if( FD_UNLIKELY( !shmem ) ) {
102 0 : FD_LOG_WARNING(( "NULL shmem" ));
103 0 : return NULL;
104 0 : }
105 :
106 0 : if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmem, fd_gui_align() ) ) ) {
107 0 : FD_LOG_WARNING(( "misaligned shmem" ));
108 0 : return NULL;
109 0 : }
110 :
111 0 : if( FD_UNLIKELY( topo->tile_cnt>FD_DIAG_SYSTEM_TILE_MAX ) ) {
112 0 : FD_LOG_WARNING(( "too many tiles" ));
113 0 : return NULL;
114 0 : }
115 :
116 0 : ulong tile_cnt = topo->tile_cnt;
117 :
118 0 : FD_SCRATCH_ALLOC_INIT( l, shmem );
119 0 : fd_gui_t * gui = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(), sizeof(fd_gui_t) );
120 0 : void * ag_slot_mem = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_ag_slot_t), max_live_slots*sizeof(fd_gui_ag_slot_t) );
121 0 : void * ingress_maxq_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_rate_deque_align(), fd_gui_rate_deque_footprint() );
122 0 : void * egress_maxq_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_rate_deque_align(), fd_gui_rate_deque_footprint() );
123 0 : void * hist_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_hist_align(), fd_gui_hist_footprint() );
124 0 : void * txn_starts_mem = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_store_txn_start_t), max_txn_per_slot*sizeof(fd_gui_store_txn_start_t) );
125 0 : void * txn_ends_mem = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_store_txn_end_t), max_txn_per_slot*sizeof(fd_gui_store_txn_end_t) );
126 0 : void * txn_joined_mem = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_slot_txn_join_t), max_txn_per_slot*sizeof(fd_gui_slot_txn_join_t) );
127 0 : void * shred_sc_mem = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gui_shred_scratch_t), FD_GUI_SHRED_SCRATCH_MAX*sizeof(fd_gui_shred_scratch_t) );
128 0 : void * exec_done_mem = FD_SCRATCH_ALLOC_APPEND( l, alignof(long), FD_GUI_EXEC_DONE_SLOT_CNT*FD_SHRED_BLK_MAX*sizeof(long) );
129 :
130 0 : gui->slot_txn_scratch.max = max_txn_per_slot;
131 0 : gui->slot_txn_scratch.starts = txn_starts_mem;
132 0 : gui->slot_txn_scratch.ends = txn_ends_mem;
133 0 : gui->slot_txn_scratch.joined = txn_joined_mem;
134 0 : gui->shred_scratch.ev = shred_sc_mem;
135 0 : gui->shred_scratch.max = FD_GUI_SHRED_SCRATCH_MAX;
136 0 : gui->exec_done.ts = exec_done_mem;
137 0 : for( ulong i=0UL; i<FD_GUI_EXEC_DONE_SLOT_CNT; i++ ) gui->exec_done.slot[ i ] = ULONG_MAX;
138 :
139 0 : gui->http = http;
140 0 : gui->topo = topo;
141 0 : gui->accdb_shmem = accdb_shmem;
142 0 : gui->tick_per_ns = fd_tempo_tick_per_ns( NULL );
143 0 : gui->tile_cnt = tile_cnt;
144 :
145 0 : gui->db = db;
146 0 : gui->hist = fd_gui_hist_join( fd_gui_hist_new( hist_mem, (fd_gui_store_t const *)db ) );
147 0 : if( FD_UNLIKELY( !gui->hist ) ) {
148 0 : FD_LOG_WARNING(( "fd_gui_hist_new failed" ));
149 0 : return NULL;
150 0 : }
151 :
152 0 : gui->summary.ingress_maxq = fd_gui_rate_deque_join( fd_gui_rate_deque_new( ingress_maxq_mem ) );
153 0 : gui->summary.egress_maxq = fd_gui_rate_deque_join( fd_gui_rate_deque_new( egress_maxq_mem ) );
154 :
155 0 : gui->summary.network_stats_has_prev = 0;
156 0 : gui->summary.net_rate_prev_ts = 0L;
157 0 : for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) {
158 0 : fd_gui_ema_init( &gui->summary.ingress_ema[ i ], now, FD_GUI_NETWORK_EMA_HALF_LIFE_NS );
159 0 : fd_gui_ema_init( &gui->summary.egress_ema [ i ], now, FD_GUI_NETWORK_EMA_HALF_LIFE_NS );
160 0 : }
161 :
162 0 : gui->leader_begin_slot = 0UL;
163 0 : gui->leader_end_slot = 0UL;
164 0 : gui->leader_slot_pending = ULONG_MAX;
165 0 : gui->leader_bank_seq_pending = ULONG_MAX;
166 :
167 0 : gui->system.valid = 0;
168 :
169 0 : gui->summary.slot_tower = ULONG_MAX;
170 0 : gui->summary.slot_tower_bank_seq = ULONG_MAX;
171 0 : gui->summary.schedule_strategy = schedule_strategy;
172 :
173 :
174 0 : gui->next_sample_1sec = now;
175 0 : gui->next_sample_200millis = now;
176 0 : gui->next_sample_100millis = now;
177 0 : gui->next_sample_50millis = now;
178 0 : gui->next_sample_40millis = now;
179 0 : gui->next_sample_25millis = now;
180 0 : gui->next_sample_10millis = now;
181 :
182 0 : memcpy( gui->summary.identity_key->uc, identity_key, 32UL );
183 0 : fd_base58_encode_32( identity_key, NULL, gui->summary.identity_key_base58 );
184 0 : gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
185 :
186 0 : if( FD_LIKELY( has_vote_key ) ) {
187 0 : gui->summary.has_vote_key = 1;
188 0 : memcpy( gui->summary.vote_key->uc, vote_key, 32UL );
189 0 : fd_base58_encode_32( vote_key, NULL, gui->summary.vote_key_base58 );
190 0 : gui->summary.vote_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
191 0 : } else {
192 0 : gui->summary.has_vote_key = 0;
193 0 : memset( gui->summary.vote_key_base58, 0, sizeof(gui->summary.vote_key_base58) );
194 0 : }
195 :
196 0 : gui->summary.version = version;
197 0 : gui->summary.cluster = cluster;
198 0 : fd_cstr_ncpy( gui->summary.accounts_database_path, accounts_database_path, sizeof(gui->summary.accounts_database_path) );
199 0 : fd_cstr_ncpy( gui->summary.gui_database_path, gui_database_path, sizeof(gui->summary.gui_database_path) );
200 0 : gui->summary.startup_time_nanos = gui->next_sample_200millis;
201 0 : gui->summary.expected_shred_version = expected_shred_version;
202 0 : gui->summary.wfs_enabled = 0;
203 0 : gui->summary.wfs_bank_hash[ 0UL ] = '\0';
204 0 : gui->summary.wfs_slot = wfs_slot;
205 :
206 0 : {
207 0 : fd_cstr_ncpy( gui->summary.wfs_bank_hash, wfs_expected_bank_hash_cstr, sizeof(gui->summary.wfs_bank_hash) );
208 0 : gui->summary.wfs_enabled = !!strcmp( wfs_expected_bank_hash_cstr, "" );
209 :
210 0 : if( FD_UNLIKELY( snapshots_enabled ) ) {
211 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP;
212 0 : gui->summary.boot_progress.joining_gossip_time_nanos = gui->next_sample_200millis;
213 0 : memset( gui->summary.boot_progress.loading_snapshot, 0, sizeof(gui->summary.boot_progress.loading_snapshot) );
214 0 : for( ulong i=0UL; i<FD_GUI_BOOT_PROGRESS_SNAPSHOT_CNT; i++ ) {
215 0 : gui->summary.boot_progress.loading_snapshot[ i ].reset_cnt = ULONG_MAX; /* ensures other fields are reset initially */
216 0 : gui->summary.boot_progress.loading_snapshot[ i ].slot = ULONG_MAX;
217 0 : }
218 0 : gui->summary.boot_progress.catching_up_time_nanos = 0L;
219 0 : gui->summary.boot_progress.catching_up_first_replay_slot = ULONG_MAX;
220 0 : gui->summary.boot_progress.wfs_total_stake = 0UL;
221 0 : gui->summary.boot_progress.wfs_connected_stake = 0UL;
222 0 : gui->summary.boot_progress.wfs_total_peers = 0UL;
223 0 : gui->summary.boot_progress.wfs_connected_peers = 0UL;
224 0 : gui->summary.boot_progress.wfs_attempt = 0UL;
225 0 : } else {
226 0 : fd_memset( &gui->summary.boot_progress, 0, sizeof(gui->summary.boot_progress) );
227 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
228 0 : }
229 0 : gui->summary.boot_progress.boot_target_slot_duration_nanos = ULONG_MAX;
230 0 : }
231 :
232 0 : gui->summary.identity_account_balance = 0UL;
233 0 : gui->summary.vote_account_balance = 0UL;
234 0 : gui->summary.vote_commission = USHORT_MAX;
235 0 : gui->summary.estimated_slot_duration_nanos = 0UL;
236 :
237 0 : gui->summary.is_voting = !!is_voting;
238 0 : gui->summary.vote_state = is_voting ? FD_GUI_VOTE_STATE_VOTING : FD_GUI_VOTE_STATE_NON_VOTING;
239 :
240 0 : gui->summary.sock_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "sock" );
241 0 : gui->summary.mlx5_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "mlx5" );
242 0 : gui->summary.iavf_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "iavf" );
243 0 : gui->summary.net_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "net" );
244 0 : gui->summary.quic_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "quic" );
245 0 : gui->summary.verify_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "verify" );
246 0 : gui->summary.resolv_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolv" );
247 0 : gui->summary.execle_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "execle" );
248 0 : gui->summary.execrp_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "execrp" );
249 0 : gui->summary.shred_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "shred" );
250 :
251 0 : fd_gui_build_tile_order( gui );
252 :
253 0 : gui->summary.slot_rooted = ULONG_MAX;
254 0 : gui->summary.slot_finalized = ULONG_MAX;
255 0 : gui->summary.slot_notarized = ULONG_MAX;
256 0 : gui->summary.slot_estimated = ULONG_MAX;
257 0 : gui->summary.slot_caught_up = ULONG_MAX;
258 0 : gui->summary.slot_repair = ULONG_MAX;
259 0 : gui->summary.slot_turbine = ULONG_MAX;
260 0 : gui->summary.slot_reset = ULONG_MAX;
261 0 : gui->summary.slot_storage = ULONG_MAX;
262 0 : gui->summary.slot_voted = ULONG_MAX;
263 0 : gui->summary.active_fork_cnt = 1UL;
264 :
265 0 : gui->ag.slot_cnt = max_live_slots;
266 0 : gui->max_consecutive_skips = fd_ulong_if( max_live_slots>FD_VOTOR_REWARD_SLOT_DELTA, max_live_slots-FD_VOTOR_REWARD_SLOT_DELTA, 1UL );
267 0 : gui->ag.slot = (fd_gui_ag_slot_t *)ag_slot_mem;
268 0 : memset( gui->ag.slot, 0, max_live_slots*sizeof(fd_gui_ag_slot_t) );
269 0 : for( ulong i=0UL; i<gui->ag.slot_cnt; i++ ) {
270 0 : gui->ag.slot[ i ].slot = ULONG_MAX;
271 0 : gui->ag.slot[ i ].bank_seq = ULONG_MAX;
272 0 : }
273 :
274 0 : memset( gui->cpu_util.total, 0, sizeof(gui->cpu_util.total) );
275 0 : memset( gui->cpu_util.idle, 0, sizeof(gui->cpu_util.idle) );
276 0 : gui->cpu_util.last_slot = ULONG_MAX;
277 0 : gui->cpu_util.cur_day = ULONG_MAX;
278 :
279 0 : memset( gui->summary.skip_rate, 0, sizeof(gui->summary.skip_rate) );
280 0 : gui->summary.skip_rate[ 0 ].epoch = ULONG_MAX;
281 0 : gui->summary.skip_rate[ 1 ].epoch = ULONG_MAX;
282 :
283 0 : for( ulong i=0UL; i < (FD_GUI_REPAIR_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_repair[ i ].slot = ULONG_MAX;
284 0 : for( ulong i=0UL; i < (FD_GUI_TURBINE_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_turbine[ i ].slot = ULONG_MAX;
285 :
286 0 : for( ulong i=0UL; i < FD_GUI_TURBINE_RECV_TIMESTAMPS; i++ ) gui->turbine_slots[ i ].slot = ULONG_MAX;
287 :
288 0 : gui->summary.estimated_tps_history_idx = 0UL;
289 0 : memset( gui->summary.estimated_tps_history, 0, sizeof(gui->summary.estimated_tps_history) );
290 :
291 0 : memset( gui->summary.txn_waterfall_reference, 0, sizeof(gui->summary.txn_waterfall_reference) );
292 0 : memset( gui->summary.txn_waterfall_current, 0, sizeof(gui->summary.txn_waterfall_current) );
293 :
294 0 : memset( gui->summary.tile_stats_reference, 0, sizeof(gui->summary.tile_stats_reference) );
295 0 : memset( gui->summary.tile_stats_current, 0, sizeof(gui->summary.tile_stats_current) );
296 :
297 0 : gui->summary.progcache_history_idx = 0UL;
298 0 : memset( gui->summary.progcache_hits_history, 0, sizeof(gui->summary.progcache_hits_history) );
299 0 : memset( gui->summary.progcache_lookups_history, 0, sizeof(gui->summary.progcache_lookups_history) );
300 0 : gui->summary.progcache_hits_1min = 0UL;
301 0 : gui->summary.progcache_lookups_1min = 0UL;
302 :
303 0 : memset( gui->summary.accounts_stats_reference, 0, sizeof(gui->summary.accounts_stats_reference) );
304 0 : memset( gui->summary.accounts_stats_current, 0, sizeof(gui->summary.accounts_stats_current ) );
305 0 : gui->summary.accounts_stats_have_reference = 0;
306 0 : gui->summary.accdb->accdb_win_idx = 0UL;
307 0 : gui->summary.accdb->accdb_win_count = 0UL;
308 0 : memset( gui->summary.accdb->accdb_win_dt_nanos, 0, sizeof(gui->summary.accdb->accdb_win_dt_nanos) );
309 0 : memset( gui->summary.accdb->agg_acquired_win, 0, sizeof(gui->summary.accdb->agg_acquired_win) );
310 0 : memset( gui->summary.accdb->agg_acquired_writable_win, 0, sizeof(gui->summary.accdb->agg_acquired_writable_win) );
311 0 : memset( gui->summary.accdb->agg_bytes_read_win, 0, sizeof(gui->summary.accdb->agg_bytes_read_win) );
312 0 : memset( gui->summary.accdb->agg_bytes_copied_win, 0, sizeof(gui->summary.accdb->agg_bytes_copied_win) );
313 0 : memset( gui->summary.accdb->agg_bytes_written_win, 0, sizeof(gui->summary.accdb->agg_bytes_written_win) );
314 0 : memset( gui->summary.accdb->agg_bytes_written_accdb_win, 0, sizeof(gui->summary.accdb->agg_bytes_written_accdb_win) );
315 0 : memset( gui->summary.accdb->agg_read_ops_win, 0, sizeof(gui->summary.accdb->agg_read_ops_win) );
316 0 : memset( gui->summary.accdb->agg_write_ops_win, 0, sizeof(gui->summary.accdb->agg_write_ops_win) );
317 0 : memset( gui->summary.accdb->agg_relocated_bytes_win, 0, sizeof(gui->summary.accdb->agg_relocated_bytes_win) );
318 0 : memset( gui->summary.accdb->agg_misses_win, 0, sizeof(gui->summary.accdb->agg_misses_win) );
319 0 : memset( gui->summary.accdb->class_acq_win, 0, sizeof(gui->summary.accdb->class_acq_win) );
320 0 : memset( gui->summary.accdb->class_acq_wr_win, 0, sizeof(gui->summary.accdb->class_acq_wr_win) );
321 0 : memset( gui->summary.accdb->class_not_found_win, 0, sizeof(gui->summary.accdb->class_not_found_win) );
322 0 : memset( gui->summary.accdb->class_evicted_win, 0, sizeof(gui->summary.accdb->class_evicted_win) );
323 0 : memset( gui->summary.accdb->class_preevicted_win, 0, sizeof(gui->summary.accdb->class_preevicted_win) );
324 0 : memset( gui->summary.accdb->class_commit_new_win, 0, sizeof(gui->summary.accdb->class_commit_new_win) );
325 0 : memset( gui->summary.accdb->class_commit_over_win, 0, sizeof(gui->summary.accdb->class_commit_over_win) );
326 :
327 0 : gui->summary.accdb->partition_cnt = 0UL;
328 0 : memset( gui->summary.accdb->partition_read_ops_win, 0, sizeof(gui->summary.accdb->partition_read_ops_win) );
329 0 : memset( gui->summary.accdb->partition_bytes_read_win, 0, sizeof(gui->summary.accdb->partition_bytes_read_win) );
330 0 : memset( gui->summary.accdb->partition_write_ops_win, 0, sizeof(gui->summary.accdb->partition_write_ops_win) );
331 0 : memset( gui->summary.accdb->partition_bytes_written_win, 0, sizeof(gui->summary.accdb->partition_bytes_written_win) );
332 0 : memset( gui->summary.accdb->partitions, 0, sizeof(gui->summary.accdb->partitions) );
333 0 : memset( gui->summary.accdb->partition_prev_read_ops, 0, sizeof(gui->summary.accdb->partition_prev_read_ops) );
334 0 : memset( gui->summary.accdb->partition_prev_bytes_read, 0, sizeof(gui->summary.accdb->partition_prev_bytes_read) );
335 0 : memset( gui->summary.accdb->partition_prev_write_ops, 0, sizeof(gui->summary.accdb->partition_prev_write_ops) );
336 0 : memset( gui->summary.accdb->partition_prev_bytes_written, 0, sizeof(gui->summary.accdb->partition_prev_bytes_written) );
337 0 : for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
338 0 : fd_gui_ema_init( &gui->summary.accdb->tier_fill_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
339 0 : fd_gui_ema_init( &gui->summary.accdb->tier_free_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
340 0 : }
341 0 : gui->summary.accdb->tier_sample_nanos = LONG_MAX;
342 0 : gui->summary.accdb->next_compaction_remaining_secs = 0.0;
343 0 : gui->summary.accdb->next_compaction_partition_idx = ULONG_MAX;
344 :
345 : /* Build the per-tile accdb slot table from the topology. Order
346 : matters only for stable JSON ordering: RW joiners first, RO
347 : joiners, then snapin and accdb. */
348 0 : gui->summary.accdb->accdb_tile_cnt = 0UL;
349 0 : static const struct { char const * name; uchar kind; } accdb_kinds[] = {
350 0 : { "execle", FD_GUI_ACCDB_TILE_KIND_RW },
351 0 : { "execrp", FD_GUI_ACCDB_TILE_KIND_RW },
352 0 : { "replay", FD_GUI_ACCDB_TILE_KIND_RW },
353 0 : { "rpc", FD_GUI_ACCDB_TILE_KIND_RO },
354 0 : { "resolv", FD_GUI_ACCDB_TILE_KIND_RO },
355 0 : { "snapin", FD_GUI_ACCDB_TILE_KIND_SNAPIN },
356 0 : { "accdb", FD_GUI_ACCDB_TILE_KIND_ACCDB },
357 0 : };
358 0 : for( ulong k=0UL; k<sizeof(accdb_kinds)/sizeof(accdb_kinds[0]); k++ ) {
359 0 : ulong cnt = fd_topo_tile_name_cnt( gui->topo, accdb_kinds[ k ].name );
360 0 : for( ulong i=0UL; i<cnt; i++ ) {
361 0 : ulong t_idx = fd_topo_find_tile( gui->topo, accdb_kinds[ k ].name, i );
362 0 : if( FD_UNLIKELY( t_idx==ULONG_MAX ) ) continue;
363 0 : ulong slot = gui->summary.accdb->accdb_tile_cnt++;
364 0 : gui->summary.accdb->accdb_tile_topo_idx[ slot ] = (ushort)t_idx;
365 0 : gui->summary.accdb->accdb_tile_kind [ slot ] = accdb_kinds[ k ].kind;
366 0 : }
367 0 : }
368 0 : memset( gui->summary.accdb->tile_cur_acquired, 0, sizeof(gui->summary.accdb->tile_cur_acquired) );
369 0 : memset( gui->summary.accdb->tile_cur_acquired_writable, 0, sizeof(gui->summary.accdb->tile_cur_acquired_writable) );
370 0 : memset( gui->summary.accdb->tile_cur_bytes_read, 0, sizeof(gui->summary.accdb->tile_cur_bytes_read) );
371 0 : memset( gui->summary.accdb->tile_cur_bytes_copied, 0, sizeof(gui->summary.accdb->tile_cur_bytes_copied) );
372 0 : memset( gui->summary.accdb->tile_cur_bytes_written, 0, sizeof(gui->summary.accdb->tile_cur_bytes_written) );
373 0 : memset( gui->summary.accdb->tile_cur_read_ops, 0, sizeof(gui->summary.accdb->tile_cur_read_ops) );
374 0 : memset( gui->summary.accdb->tile_cur_write_ops, 0, sizeof(gui->summary.accdb->tile_cur_write_ops) );
375 0 : memset( gui->summary.accdb->tile_cur_misses, 0, sizeof(gui->summary.accdb->tile_cur_misses) );
376 0 : memset( gui->summary.accdb->tile_cur_evicted, 0, sizeof(gui->summary.accdb->tile_cur_evicted) );
377 0 : memset( gui->summary.accdb->tile_cur_committed, 0, sizeof(gui->summary.accdb->tile_cur_committed) );
378 0 : memset( gui->summary.accdb->tile_cur_acquire_calls, 0, sizeof(gui->summary.accdb->tile_cur_acquire_calls) );
379 0 : memset( gui->summary.accdb->tile_cur_status, 0, sizeof(gui->summary.accdb->tile_cur_status) );
380 0 : memset( gui->summary.accdb->tile_prev_acquired, 0, sizeof(gui->summary.accdb->tile_prev_acquired) );
381 0 : memset( gui->summary.accdb->tile_prev_acquired_writable, 0, sizeof(gui->summary.accdb->tile_prev_acquired_writable) );
382 0 : memset( gui->summary.accdb->tile_prev_bytes_read, 0, sizeof(gui->summary.accdb->tile_prev_bytes_read) );
383 0 : memset( gui->summary.accdb->tile_prev_bytes_copied, 0, sizeof(gui->summary.accdb->tile_prev_bytes_copied) );
384 0 : memset( gui->summary.accdb->tile_prev_bytes_written, 0, sizeof(gui->summary.accdb->tile_prev_bytes_written) );
385 0 : memset( gui->summary.accdb->tile_prev_read_ops, 0, sizeof(gui->summary.accdb->tile_prev_read_ops) );
386 0 : memset( gui->summary.accdb->tile_prev_write_ops, 0, sizeof(gui->summary.accdb->tile_prev_write_ops) );
387 0 : memset( gui->summary.accdb->tile_prev_misses, 0, sizeof(gui->summary.accdb->tile_prev_misses) );
388 0 : memset( gui->summary.accdb->tile_prev_evicted, 0, sizeof(gui->summary.accdb->tile_prev_evicted) );
389 0 : memset( gui->summary.accdb->tile_prev_committed, 0, sizeof(gui->summary.accdb->tile_prev_committed) );
390 0 : memset( gui->summary.accdb->tile_prev_acquire_calls, 0, sizeof(gui->summary.accdb->tile_prev_acquire_calls) );
391 0 : memset( gui->summary.accdb->tile_acquired_win, 0, sizeof(gui->summary.accdb->tile_acquired_win) );
392 0 : memset( gui->summary.accdb->tile_acquired_writable_win, 0, sizeof(gui->summary.accdb->tile_acquired_writable_win) );
393 0 : memset( gui->summary.accdb->tile_bytes_read_win, 0, sizeof(gui->summary.accdb->tile_bytes_read_win) );
394 0 : memset( gui->summary.accdb->tile_bytes_copied_win, 0, sizeof(gui->summary.accdb->tile_bytes_copied_win) );
395 0 : memset( gui->summary.accdb->tile_bytes_written_win, 0, sizeof(gui->summary.accdb->tile_bytes_written_win) );
396 0 : memset( gui->summary.accdb->tile_read_ops_win, 0, sizeof(gui->summary.accdb->tile_read_ops_win) );
397 0 : memset( gui->summary.accdb->tile_write_ops_win, 0, sizeof(gui->summary.accdb->tile_write_ops_win) );
398 0 : memset( gui->summary.accdb->tile_misses_win, 0, sizeof(gui->summary.accdb->tile_misses_win) );
399 0 : memset( gui->summary.accdb->tile_evicted_win, 0, sizeof(gui->summary.accdb->tile_evicted_win) );
400 0 : memset( gui->summary.accdb->tile_committed_win, 0, sizeof(gui->summary.accdb->tile_committed_win) );
401 0 : memset( gui->summary.accdb->tile_acquire_calls_win, 0, sizeof(gui->summary.accdb->tile_acquire_calls_win) );
402 :
403 0 : memset( gui->summary.accdb->tile_sparkline_bucket_start_nanos, 0, sizeof(gui->summary.accdb->tile_sparkline_bucket_start_nanos) );
404 0 : memset( gui->summary.accdb->tile_sparkline_acq_bucket, 0, sizeof(gui->summary.accdb->tile_sparkline_acq_bucket) );
405 0 : memset( gui->summary.accdb->tile_sparkline_acq_wr_bucket, 0, sizeof(gui->summary.accdb->tile_sparkline_acq_wr_bucket) );
406 0 : memset( gui->summary.accdb->tile_sparkline_acq_text_len, 0, sizeof(gui->summary.accdb->tile_sparkline_acq_text_len) );
407 0 : memset( gui->summary.accdb->tile_sparkline_acq_wr_text_len, 0, sizeof(gui->summary.accdb->tile_sparkline_acq_wr_text_len) );
408 0 : memset( gui->summary.accdb->tile_sparkline_count, 0, sizeof(gui->summary.accdb->tile_sparkline_count) );
409 :
410 0 : memset( gui->summary.tile_timers_reference, 0, sizeof(gui->summary.tile_timers_reference) );
411 0 : memset( gui->summary.tile_timers_current, 0, sizeof(gui->summary.tile_timers_current) );
412 0 : memset( gui->summary.tile_timers_packed, 0, sizeof(gui->summary.tile_timers_packed) );
413 :
414 0 : gui->block_engine.has_block_engine = 0;
415 :
416 0 : gui->epoch.current_epoch = ULONG_MAX;
417 0 : gui->epoch.has_epoch_schedule = 0;
418 0 : gui->epoch.missed_vote_history_dirty = ULONG_MAX;
419 :
420 0 : gui->shreds.leader_shred_cnt = 0UL;
421 0 : gui->shreds.leader_shred_slot = ULONG_MAX;
422 0 : gui->shreds.dropped_event_cnt = 0UL;
423 0 : fd_memset( &gui->shreds.builder, 0, sizeof(gui->shreds.builder) );
424 0 : gui->shreds.closed_slot_wmark = 0UL;
425 0 : gui->shreds.fec_marker_sequence = 0UL;
426 0 : gui->shreds.fec_insert_time_ns = 0L;
427 0 : gui->shreds.dropped_fec_event_cnt = 0UL;
428 0 : gui->shreds.clamped_fec_event_cnt = 0UL;
429 0 : gui->shreds.broadcast_watermark_ns = now;
430 0 : gui->summary.catch_up_repair_sz = 0UL;
431 0 : gui->summary.catch_up_turbine_sz = 0UL;
432 :
433 0 : fd_memset( &gui->snapsv, 0, sizeof(gui->snapsv) );
434 :
435 0 : return gui;
436 0 : }
437 :
438 : fd_gui_t *
439 0 : fd_gui_join( void * shmem ) {
440 0 : return (fd_gui_t *)shmem;
441 0 : }
442 :
443 : void
444 : fd_gui_set_identity( fd_gui_t * gui,
445 0 : uchar const * identity_pubkey ) {
446 0 : memcpy( gui->summary.identity_key->uc, identity_pubkey, 32UL );
447 0 : fd_base58_encode_32( identity_pubkey, NULL, gui->summary.identity_key_base58 );
448 0 : gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
449 :
450 0 : if( FD_LIKELY( gui->summary.is_voting ) ) gui->summary.vote_state = FD_GUI_VOTE_STATE_VOTING;
451 :
452 0 : gui->summary.slot_voted = ULONG_MAX;
453 :
454 0 : fd_gui_printf_identity_key( gui );
455 0 : fd_http_server_ws_broadcast( gui->http );
456 0 : fd_gui_printf_vote_slot( gui );
457 0 : fd_http_server_ws_broadcast( gui->http );
458 0 : fd_gui_printf_vote_state( gui );
459 0 : fd_http_server_ws_broadcast( gui->http );
460 0 : fd_gui_printf_missed_vote_history( gui, gui->epoch.current_epoch );
461 0 : fd_http_server_ws_broadcast( gui->http );
462 0 : }
463 :
464 : void
465 : fd_gui_handle_diag_snapshot( fd_gui_t * gui,
466 : void const * data,
467 0 : ulong data_sz ) {
468 0 : if( FD_UNLIKELY( !data ) ) return;
469 :
470 0 : if( FD_UNLIKELY( data_sz!=sizeof(fd_diag_system_resources_t) ) ) return;
471 :
472 0 : fd_diag_system_resources_t snapshot[ 1 ];
473 0 : fd_memcpy( snapshot, data, sizeof(snapshot) );
474 0 : if( FD_UNLIKELY( snapshot->cpu_cnt >FD_DIAG_SYSTEM_CPU_MAX ||
475 0 : snapshot->numa_mem_cnt>FD_DIAG_SYSTEM_NUMA_MAX ||
476 0 : snapshot->tile_mem_cnt>FD_DIAG_SYSTEM_TILE_MEM_MAX ||
477 0 : snapshot->mount_cnt >FD_DIAG_SYSTEM_FILE_MAX ||
478 0 : snapshot->file_cnt >FD_DIAG_SYSTEM_FILE_MAX ) ) return;
479 0 : for( ulong i=0UL; i<(ulong)snapshot->cpu_cnt; i++ ) {
480 0 : fd_diag_system_cpu_t const * cpu = &snapshot->cpu[ i ];
481 0 : if( FD_UNLIKELY( cpu->cpu_idx>=FD_DIAG_SYSTEM_CPU_MAX ) ) return;
482 0 : if( FD_UNLIKELY( cpu->die_idx!=USHORT_MAX && cpu->die_idx>=snapshot->cpu_cnt ) ) return;
483 0 : }
484 0 : for( ulong i=0UL; i<(ulong)snapshot->tile_mem_cnt; i++ ) {
485 0 : fd_diag_system_tile_mem_t const * tile = &snapshot->tile_mem[ i ];
486 0 : if( FD_UNLIKELY( tile->tile_idx>=gui->topo->tile_cnt ) ) return;
487 0 : }
488 0 : for( ulong i=0UL; i<(ulong)snapshot->mount_cnt; i++ ) {
489 0 : if( FD_UNLIKELY( !memchr( snapshot->mount[ i ].path, '\0', sizeof(snapshot->mount[ i ].path) ) ) ) return;
490 0 : }
491 0 : for( ulong i=0UL; i<(ulong)snapshot->file_cnt; i++ ) {
492 0 : fd_diag_system_file_t const * file = &snapshot->file[ i ];
493 0 : if( FD_UNLIKELY( file->mount_idx>=snapshot->mount_cnt ||
494 0 : file->path[ 0 ]!='/' ||
495 0 : !memchr( file->path, '\0', sizeof(file->path) ) ) ) return;
496 0 : }
497 :
498 0 : gui->system.resources = *snapshot;
499 0 : gui->system.valid = 1;
500 0 : fd_gui_printf_system_resources( gui );
501 0 : fd_http_server_ws_broadcast( gui->http );
502 0 : }
503 :
504 : void
505 : fd_gui_ws_open( fd_gui_t * gui,
506 : ulong ws_conn_id,
507 0 : long now ) {
508 0 : fd_gui_printf_is_alpenglow( gui );
509 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
510 :
511 0 : void (* printers[] )( fd_gui_t * gui ) = {
512 0 : fd_gui_printf_boot_progress,
513 0 : fd_gui_printf_version,
514 0 : fd_gui_printf_cluster,
515 0 : fd_gui_printf_commit_hash,
516 0 : fd_gui_printf_identity_key,
517 0 : fd_gui_printf_vote_key,
518 0 : fd_gui_printf_startup_time_nanos,
519 0 : fd_gui_printf_vote_state,
520 0 : fd_gui_printf_turbine_slot,
521 0 : fd_gui_printf_repair_slot,
522 0 : fd_gui_printf_slot_caught_up,
523 0 : fd_gui_printf_tps_history,
524 0 : fd_gui_printf_estimated_tps,
525 0 : fd_gui_printf_tiles,
526 0 : fd_gui_printf_schedule_strategy,
527 0 : fd_gui_printf_identity_balance,
528 0 : fd_gui_printf_vote_balance,
529 0 : fd_gui_printf_vote_commission,
530 0 : fd_gui_printf_estimated_slot_duration_nanos,
531 0 : fd_gui_printf_root_slot,
532 0 : fd_gui_printf_storage_slot,
533 0 : fd_gui_printf_reset_slot,
534 0 : fd_gui_printf_active_fork_cnt,
535 0 : fd_gui_printf_completed_slot,
536 0 : fd_gui_printf_estimated_slot,
537 0 : fd_gui_printf_live_tile_timers,
538 0 : fd_gui_printf_live_tile_metrics,
539 0 : fd_gui_printf_catch_up_history,
540 0 : fd_gui_printf_health
541 0 : };
542 :
543 0 : ulong printers_len = sizeof(printers) / sizeof(printers[0]);
544 0 : for( ulong i=0UL; i<printers_len; i++ ) {
545 0 : printers[ i ]( gui );
546 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
547 0 : }
548 :
549 0 : fd_gui_printf_finalized_slot( gui );
550 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
551 0 : fd_gui_printf_notarized_slot( gui );
552 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
553 0 : fd_gui_printf_vote_slot( gui );
554 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
555 :
556 0 : if( FD_LIKELY( gui->system.valid ) ) {
557 0 : fd_gui_printf_system_resources( gui );
558 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
559 0 : }
560 :
561 0 : {
562 0 : fd_gui_printf_live_program_cache( gui );
563 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
564 :
565 0 : if( FD_LIKELY( gui->summary.accounts_stats_have_reference ) ) {
566 0 : fd_gui_printf_accounts_stats( gui );
567 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
568 0 : }
569 0 : }
570 :
571 0 : if( FD_LIKELY( gui->block_engine.has_block_engine ) ) {
572 0 : fd_gui_printf_block_engine( gui );
573 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
574 0 : }
575 :
576 0 : if( FD_LIKELY( gui->epoch.current_epoch!=ULONG_MAX ) ) {
577 0 : fd_gui_printf_skipped_history( gui, gui->epoch.current_epoch );
578 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
579 0 : fd_gui_printf_skipped_history_cluster( gui, gui->epoch.current_epoch );
580 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
581 :
582 0 : fd_gui_printf_missed_vote_history( gui, gui->epoch.current_epoch );
583 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
584 0 : }
585 :
586 : /* rebroadcast 10s of historical shred data */
587 0 : long const shred_history_start = now-10L*1000L*1000L*1000L;
588 0 : if( FD_LIKELY( !fd_gui_shred_window_is_empty( gui, shred_history_start, now ) ) ) {
589 0 : fd_gui_printf_shred_rebroadcast( gui, shred_history_start, now );
590 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
591 0 : }
592 0 : }
593 :
594 :
595 :
596 : static inline ushort
597 0 : fd_gui_tile_timers_pct( ulong delta, ulong total ) {
598 0 : if( FD_UNLIKELY( !total ) ) return USHORT_MAX;
599 0 : double percent = ( (double)delta / (double)total ) * 100.0;
600 0 : long hundredths = (long)( percent * 100.0 );
601 0 : if( FD_UNLIKELY( hundredths<0L ) ) hundredths = 0L;
602 0 : if( FD_UNLIKELY( hundredths>(USHORT_MAX-1U) ) ) hundredths = (USHORT_MAX-1U);
603 0 : return (ushort)hundredths;
604 0 : }
605 :
606 : void
607 : fd_gui_tile_timers_diff( fd_gui_tile_timers_hist_t * out,
608 : fd_gui_tile_timers_t const * prev,
609 : fd_gui_tile_timers_t const * cur,
610 : ulong tile_idx,
611 0 : long sample_time_nanos ) {
612 0 : memset( out, 0, sizeof(*out) );
613 0 : out->sample_time_nanos = sample_time_nanos;
614 0 : out->tile_idx = (ushort)tile_idx;
615 :
616 0 : ulong cur_total = 0UL, prev_total = 0UL;
617 0 : for( ulong j=0UL; j<FD_METRICS_ENUM_TILE_REGIME_CNT; j++ ) {
618 0 : cur_total += cur->timers[ j ]; prev_total += prev->timers[ j ];
619 0 : }
620 0 : ulong busy = cur_total - prev_total;
621 0 : for( ulong j=0UL; j<FD_METRICS_ENUM_TILE_REGIME_CNT; j++ ) {
622 0 : out->timers[ j ] = fd_gui_tile_timers_pct( cur->timers[ j ] - prev->timers[ j ], busy );
623 0 : }
624 0 : if( FD_UNLIKELY( !busy ) ) {
625 0 : out->idle_ratio = USHORT_MAX;
626 0 : } else {
627 0 : ulong mask = FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK | FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK;
628 0 : ulong idle = fd_metrics_enum_group_sum( cur->timers, mask ) - fd_metrics_enum_group_sum( prev->timers, mask );
629 0 : out->idle_ratio = fd_gui_tile_timers_pct( idle, busy );
630 0 : }
631 :
632 0 : ulong cur_ctot = 0UL, prev_ctot = 0UL;
633 0 : for( ulong j=0UL; j<FD_METRICS_ENUM_THREAD_REGIME_CNT; j++ ) { cur_ctot += cur->sched_timers[ j ]; prev_ctot += prev->sched_timers[ j ]; }
634 0 : ulong cbusy = cur_ctot - prev_ctot;
635 0 : for( ulong j=0UL; j<FD_METRICS_ENUM_THREAD_REGIME_CNT; j++ ) {
636 0 : out->sched_timers[ j ] = fd_gui_tile_timers_pct( cur->sched_timers[ j ] - prev->sched_timers[ j ], cbusy );
637 0 : }
638 :
639 0 : out->alive = (uchar)fd_ulong_if( cur->status==2U, 2UL, (ulong)( cur->heartbeat>prev->heartbeat ) );
640 0 : out->in_backp = (uchar)( !!cur->in_backp );
641 0 : out->last_cpu = cur->last_cpu;
642 :
643 0 : out->backp_msgs = cur->backp_cnt;
644 0 : out->nvcsw = cur->nvcsw;
645 0 : out->nivcsw = cur->nivcsw;
646 0 : out->minflt = cur->minflt;
647 0 : out->majflt = cur->majflt;
648 0 : out->interrupts = cur->interrupts;
649 0 : out->tlb_shootdowns = cur->tlb_shootdowns;
650 0 : out->timer_ticks = cur->timer_ticks;
651 0 : }
652 :
653 : static void
654 0 : fd_gui_tile_timers_snap( fd_gui_t * gui, long now ) {
655 0 : fd_gui_tile_timers_t * cur = gui->summary.tile_timers_current;
656 0 : fd_memcpy( gui->summary.tile_timers_reference, cur, gui->tile_cnt * sizeof(fd_gui_tile_timers_t) );
657 0 : for( ulong i=0UL; i<gui->topo->tile_cnt; i++ ) {
658 0 : fd_topo_tile_t const * tile = &gui->topo->tiles[ i ];
659 : /* NULL when the tile's metrics live in a workspace not mapped to
660 : this tile (e.g. bench tiles use the "bench" workspace, not
661 : "metric_in"). */
662 0 : if( FD_UNLIKELY( !tile->metrics ) ) continue;
663 0 : volatile ulong const * tile_metrics = fd_metrics_tile( tile->metrics );
664 :
665 0 : cur[ i ].sample_time_nanos = now;
666 :
667 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 ) ];
668 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_HOUSEKEEPING ) ];
669 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_HOUSEKEEPING ) ];
670 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 ) ];
671 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_PREFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_PREFRAG ) ];
672 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
673 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 ) ];
674 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_POSTFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_POSTFRAG ) ];
675 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_CAUGHT_UP_SLEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_SLEEPING ) ];
676 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_SLEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_SLEEPING ) ];
677 :
678 0 : cur[ i ].sched_timers[ FD_METRICS_ENUM_THREAD_REGIME_V_WAIT_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, THREAD_DURATION_NANOS_WAIT ) ];
679 0 : cur[ i ].sched_timers[ FD_METRICS_ENUM_THREAD_REGIME_V_USER_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, THREAD_DURATION_NANOS_USER ) ];
680 0 : cur[ i ].sched_timers[ FD_METRICS_ENUM_THREAD_REGIME_V_SYSTEM_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, THREAD_DURATION_NANOS_SYSTEM ) ];
681 0 : cur[ i ].sched_timers[ FD_METRICS_ENUM_THREAD_REGIME_V_IDLE_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, THREAD_DURATION_NANOS_IDLE ) ];
682 0 : cur[ i ].sched_timers[ FD_METRICS_ENUM_THREAD_REGIME_V_INTERRUPT_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, THREAD_DURATION_NANOS_INTERRUPT ) ];
683 :
684 0 : cur[ i ].in_backp = (int)tile_metrics[ MIDX(GAUGE, TILE, IS_BACKPRESSURED) ];
685 0 : cur[ i ].status = (uchar)tile_metrics[ MIDX( GAUGE, TILE, STATE ) ];
686 0 : cur[ i ].heartbeat = tile_metrics[ MIDX( GAUGE, TILE, HEARTBEAT_TIME ) ];
687 0 : cur[ i ].backp_cnt = tile_metrics[ MIDX( COUNTER, TILE, BACKPRESSURE ) ];
688 0 : cur[ i ].nvcsw = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_VOLUNTARY ) ];
689 0 : cur[ i ].nivcsw = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_INVOLUNTARY ) ];
690 0 : cur[ i ].minflt = tile_metrics[ MIDX( COUNTER, TILE, PAGE_FAULT_MINOR ) ];
691 0 : cur[ i ].majflt = tile_metrics[ MIDX( COUNTER, TILE, PAGE_FAULT_MAJOR ) ];
692 0 : cur[ i ].last_cpu = (ushort)tile_metrics[ MIDX( GAUGE, TILE, LAST_CPU_INDEX ) ];
693 0 : cur[ i ].interrupts = tile_metrics[ MIDX( COUNTER, TILE, DEVICE_IRQ ) ];
694 0 : cur[ i ].tlb_shootdowns = tile_metrics[ MIDX( COUNTER, TILE, TLB_SHOOTDOWN ) ];
695 0 : cur[ i ].timer_ticks = tile_metrics[ MIDX( COUNTER, TILE, TIMER_IRQ ) ];
696 0 : }
697 :
698 0 : for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
699 0 : cur[ i ].tile_idx = i;
700 0 : fd_gui_tile_timers_diff( &gui->summary.tile_timers_packed[ i ], &gui->summary.tile_timers_reference[ i ], &cur[ i ], i, now );
701 0 : }
702 0 : }
703 :
704 : static void
705 0 : fd_gui_scheduler_counts_snap( fd_gui_t * gui, long now ) {
706 0 : ulong pack_tile_idx = fd_topo_find_tile( gui->topo, "pack", 0UL );
707 0 : if( FD_UNLIKELY( pack_tile_idx==ULONG_MAX ) ) return;
708 :
709 0 : fd_gui_scheduler_counts_t cur[ 1 ];
710 :
711 0 : fd_topo_tile_t const * pack = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "pack", 0UL ) ];
712 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
713 :
714 0 : cur->sample_time_ns = now;
715 :
716 0 : cur->regular = pack_metrics[ MIDX( GAUGE, PACK, TXN_PENDING_USED_REGULAR ) ];
717 0 : cur->votes = pack_metrics[ MIDX( GAUGE, PACK, TXN_PENDING_USED_VOTE ) ];
718 0 : cur->conflicting = pack_metrics[ MIDX( GAUGE, PACK, TXN_PENDING_USED_CONFLICTING ) ];
719 0 : cur->bundles = pack_metrics[ MIDX( GAUGE, PACK, TXN_PENDING_USED_BUNDLE ) ];
720 0 : cur->next_auction = pack_metrics[ MIDX( GAUGE, PACK, TXN_PENDING_USED_NEXT_AUCTION ) ];
721 :
722 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_SCHEDULER_COUNTS, cur );
723 0 : }
724 :
725 : static void
726 0 : fd_gui_estimated_tps_snap( fd_gui_t * gui ) {
727 0 : ulong vote_failed = 0UL;
728 0 : ulong vote_success = 0UL;
729 0 : ulong nonvote_success = 0UL;
730 0 : ulong nonvote_failed = 0UL;
731 :
732 0 : if( FD_LIKELY( gui->summary.slot_tower==ULONG_MAX ) ) return;
733 0 : ulong first_replay_slot = fd_gui_first_replay_slot( gui );
734 0 : for( ulong i=0UL; i<fd_ulong_min( gui->summary.slot_tower+1UL, MAX_SLOTS_PER_EPOCH ); i++ ) {
735 0 : ulong _slot = gui->summary.slot_tower-i;
736 0 : if( FD_UNLIKELY( first_replay_slot!=ULONG_MAX && _slot<first_replay_slot ) ) break;
737 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon( gui, _slot );
738 0 : if( FD_UNLIKELY( !slot ) ) continue;
739 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. */
740 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. */
741 0 : if( FD_UNLIKELY( slot->skip!=FD_GUI_SKIP_STATUS_NOT_SKIPPED ) ) continue; /* Skipped slots don't count to TPS. */
742 0 : if( FD_UNLIKELY( slot->vote_failed==UINT_MAX ) ) continue; /* Slot transaction counts not yet populated. */
743 0 : vote_failed += slot->vote_failed;
744 0 : vote_success += slot->vote_success;
745 0 : nonvote_success += slot->nonvote_success;
746 0 : nonvote_failed += slot->nonvote_failed;
747 0 : }
748 :
749 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].vote_failed = vote_failed;
750 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].vote_success = vote_success;
751 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].nonvote_success = nonvote_success;
752 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ].nonvote_failed = nonvote_failed;
753 0 : gui->summary.estimated_tps_history_idx = (gui->summary.estimated_tps_history_idx+1UL) % FD_GUI_TPS_HISTORY_SAMPLE_CNT;
754 0 : }
755 :
756 : static void
757 : fd_gui_network_stats_snap_egress( fd_topo_t const * topo,
758 : char const * tile_name,
759 0 : fd_gui_network_stats_t * cur ) {
760 0 : ulong tile_cnt = fd_topo_tile_name_cnt( topo, tile_name );
761 0 : for( ulong i=0UL; i<tile_cnt; i++ ) {
762 0 : ulong tile_idx = fd_topo_find_tile( topo, tile_name, i );
763 0 : if( FD_UNLIKELY( tile_idx==ULONG_MAX ) ) continue;
764 0 : fd_topo_tile_t const * tile = &topo->tiles[ tile_idx ];
765 0 : for( ulong j=0UL; j<tile->in_cnt; j++ ) {
766 0 : ulong bytes = fd_metrics_link_in( tile->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
767 0 : char const * link_name = topo->links[ tile->in_link_id[ j ] ].name;
768 0 : if( FD_UNLIKELY( !strcmp( link_name, "shred_net" ) ) ) cur->out.turbine += bytes;
769 0 : if( FD_UNLIKELY( !strcmp( link_name, "repair_net" ) ) ) cur->out.repair += bytes;
770 0 : if( FD_UNLIKELY( !strcmp( link_name, "rserve_net" ) ) ) cur->out.rserve += bytes;
771 0 : if( FD_UNLIKELY( !strcmp( link_name, "votor_net" ) ) ) cur->out.votor += bytes;
772 0 : }
773 0 : }
774 0 : }
775 :
776 : static void
777 : fd_gui_network_stats_snap( fd_gui_t * gui,
778 0 : fd_gui_network_stats_t * cur ) {
779 0 : fd_topo_t const * topo = gui->topo;
780 0 : ulong gossvf_tile_cnt = fd_topo_tile_name_cnt( topo, "gossvf" );
781 0 : ulong gossip_tile_cnt = fd_topo_tile_name_cnt( topo, "gossip" );
782 0 : ulong shred_tile_cnt = fd_topo_tile_name_cnt( topo, "shred" );
783 0 : ulong quic_tile_cnt = fd_topo_tile_name_cnt( topo, "quic" );
784 0 : ulong snapsv_tile_cnt = fd_topo_tile_name_cnt( topo, "snapsv" );
785 :
786 0 : cur->in.gossip = fd_gui_metrics_gossip_total_ingress_bytes( topo, gossvf_tile_cnt );
787 0 : cur->out.gossip = fd_gui_metrics_gossip_total_egress_bytes( topo, gossip_tile_cnt );
788 0 : cur->in.turbine = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, TURBINE_RX_BYTES ) );
789 :
790 0 : cur->out.turbine = 0UL;
791 0 : cur->out.repair = 0UL;
792 0 : cur->out.rserve = 0UL;
793 0 : cur->out.tpu = 0UL;
794 0 : cur->out.votor = 0UL;
795 0 : cur->in.votor = 0UL;
796 0 : fd_gui_network_stats_snap_egress( topo, "net", cur );
797 0 : fd_gui_network_stats_snap_egress( topo, "mlx5", cur );
798 0 : fd_gui_network_stats_snap_egress( topo, "iavf", cur );
799 :
800 0 : ulong votor_tile_idx = fd_topo_find_tile( topo, "votor", 0UL );
801 0 : if( FD_UNLIKELY( votor_tile_idx!=ULONG_MAX ) ) {
802 0 : fd_topo_tile_t const * votor = &topo->tiles[ votor_tile_idx ];
803 0 : for( ulong i=0UL; i<votor->in_cnt; i++ ) {
804 0 : if( FD_UNLIKELY( !strcmp( topo->links[ votor->in_link_id[ i ] ].name, "net_votor" ) ) ) {
805 0 : cur->in.votor += fd_metrics_link_in( votor->metrics, i )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
806 0 : }
807 0 : }
808 0 : }
809 :
810 0 : cur->in.repair = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, REPAIR_RX_BYTES ) );
811 0 : ulong repair_tile_idx = fd_topo_find_tile( topo, "repair", 0UL );
812 0 : if( FD_LIKELY( repair_tile_idx!=ULONG_MAX ) ) {
813 0 : fd_topo_tile_t const * repair = &topo->tiles[ repair_tile_idx ];
814 :
815 0 : for( ulong i=0UL; i<repair->in_cnt; i++ ) {
816 0 : if( FD_UNLIKELY( !strcmp( topo->links[ repair->in_link_id[ i ] ].name, "shred_repair" ) ) ) {
817 0 : cur->in.repair += fd_metrics_link_in( repair->metrics, i )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
818 0 : }
819 0 : }
820 0 : }
821 :
822 0 : cur->in.rserve = 0UL;
823 0 : ulong rserve_tile_idx = fd_topo_find_tile( topo, "rserve", 0UL );
824 0 : if( FD_LIKELY( rserve_tile_idx!=ULONG_MAX ) ) {
825 0 : fd_topo_tile_t const * rserve = &topo->tiles[ rserve_tile_idx ];
826 :
827 0 : for( ulong i=0UL; i<rserve->in_cnt; i++ ) {
828 0 : if( FD_UNLIKELY( !strcmp( topo->links[ rserve->in_link_id[ i ] ].name, "net_rserve" ) ) ) {
829 0 : cur->in.rserve += fd_metrics_link_in( rserve->metrics, i )[ FD_METRICS_COUNTER_LINK_FRAG_CONSUMED_BYTES_OFF ];
830 0 : }
831 0 : }
832 0 : }
833 :
834 0 : cur->in.tpu = 0UL;
835 0 : for( ulong i=0UL; i<quic_tile_cnt; i++ ) {
836 0 : ulong quic_tile_idx = fd_topo_find_tile( topo, "quic", i );
837 0 : if( FD_UNLIKELY( quic_tile_idx==ULONG_MAX ) ) continue;
838 0 : fd_topo_tile_t const * quic = &topo->tiles[ quic_tile_idx ];
839 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
840 0 : cur->in.tpu += quic_metrics[ MIDX( COUNTER, QUIC, PKT_RX_BYTES ) ];
841 0 : }
842 :
843 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
844 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
845 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
846 0 : volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
847 0 : cur->in.tpu += bundle_metrics[ MIDX( COUNTER, BUNDLE, PROTOBUF_RX_BYTES ) ];
848 0 : }
849 :
850 0 : ulong metric_tile_idx = fd_topo_find_tile( topo, "metric", 0UL );
851 0 : if( FD_LIKELY( metric_tile_idx!=ULONG_MAX ) ) {
852 0 : fd_topo_tile_t const * metric = &topo->tiles[ metric_tile_idx ];
853 0 : volatile ulong * metric_metrics = fd_metrics_tile( metric->metrics );
854 0 : cur->in.metric = metric_metrics[ MIDX( COUNTER, METRIC, CONN_RX_BYTES ) ];
855 0 : cur->out.metric = metric_metrics[ MIDX( COUNTER, METRIC, CONN_TX_BYTES ) ];
856 0 : } else {
857 0 : cur->in.metric = 0UL;
858 0 : cur->out.metric = 0UL;
859 0 : }
860 :
861 0 : cur->in.snapsv = fd_gui_metrics_sum_tiles_counter( topo, "snapsv", snapsv_tile_cnt, MIDX( COUNTER, SNAPSV, HTTP_RX_BYTES ) );
862 0 : cur->out.snapsv = fd_gui_metrics_sum_tiles_counter( topo, "snapsv", snapsv_tile_cnt, MIDX( COUNTER, SNAPSV, HTTP_TX_BYTES ) );
863 0 : }
864 :
865 : static void
866 : fd_gui_network_rate_max_update( fd_gui_t * gui,
867 0 : long now ) {
868 0 : fd_gui_network_stats_t * cur = gui->summary.network_stats_current;
869 0 : fd_gui_network_stats_t * prev = gui->summary.network_stats_prev;
870 :
871 : /* On the first sample we have no previous value. */
872 0 : if( FD_UNLIKELY( !gui->summary.network_stats_has_prev ) ) {
873 0 : *prev = *cur;
874 0 : gui->summary.network_stats_has_prev = 1;
875 0 : gui->summary.net_rate_prev_ts = now;
876 0 : return;
877 0 : }
878 :
879 0 : ulong d_in[ FD_GUI_NET_PROTO_CNT ];
880 0 : d_in[ 0 ] = fd_ulong_sat_sub( cur->in.turbine, prev->in.turbine );
881 0 : d_in[ 1 ] = fd_ulong_sat_sub( cur->in.gossip, prev->in.gossip );
882 0 : d_in[ 2 ] = fd_ulong_sat_sub( cur->in.tpu, prev->in.tpu );
883 0 : d_in[ 3 ] = fd_ulong_sat_sub( cur->in.repair, prev->in.repair );
884 0 : d_in[ 4 ] = fd_ulong_sat_sub( cur->in.rserve, prev->in.rserve );
885 0 : d_in[ 5 ] = fd_ulong_sat_sub( cur->in.metric, prev->in.metric );
886 0 : d_in[ 6 ] = fd_ulong_sat_sub( cur->in.votor, prev->in.votor );
887 0 : d_in[ 7 ] = fd_ulong_sat_sub( cur->in.snapsv, prev->in.snapsv );
888 :
889 0 : ulong d_out[ FD_GUI_NET_PROTO_CNT ];
890 0 : d_out[ 0 ] = fd_ulong_sat_sub( cur->out.turbine, prev->out.turbine );
891 0 : d_out[ 1 ] = fd_ulong_sat_sub( cur->out.gossip, prev->out.gossip );
892 0 : d_out[ 2 ] = fd_ulong_sat_sub( cur->out.tpu, prev->out.tpu );
893 0 : d_out[ 3 ] = fd_ulong_sat_sub( cur->out.repair, prev->out.repair );
894 0 : d_out[ 4 ] = fd_ulong_sat_sub( cur->out.rserve, prev->out.rserve );
895 0 : d_out[ 5 ] = fd_ulong_sat_sub( cur->out.metric, prev->out.metric );
896 0 : d_out[ 6 ] = fd_ulong_sat_sub( cur->out.votor, prev->out.votor );
897 0 : d_out[ 7 ] = fd_ulong_sat_sub( cur->out.snapsv, prev->out.snapsv );
898 :
899 : /* Compute per-protocol instantaneous bytes/sec rate and feed the EMA. */
900 0 : long dt_ns = now - gui->summary.net_rate_prev_ts;
901 0 : if( FD_LIKELY( dt_ns>0L ) ) {
902 0 : double dt_sec = (double)dt_ns / 1.0e9;
903 :
904 0 : for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) {
905 0 : double rate_in = (double)d_in[ i ] / dt_sec;
906 0 : double rate_out = (double)d_out[ i ] / dt_sec;
907 :
908 0 : fd_gui_ema_advance( &gui->summary.ingress_ema[ i ], now, rate_in );
909 0 : fd_gui_ema_advance( &gui->summary.egress_ema [ i ], now, rate_out );
910 0 : }
911 0 : }
912 0 : gui->summary.net_rate_prev_ts = now;
913 :
914 : /* Track max total EMA in a rolling 5-minute window using monotonic
915 : deques.
916 :
917 : Invariant: deque entries are strictly decreasing in value from
918 : head to tail. The head is always the current window maximum.
919 :
920 : Insert: pop tail entries whose value <= new value (they can
921 : never become the maximum), then push the new entry.
922 : Expire: pop head entries older than 5 minutes. */
923 0 : if( FD_LIKELY( gui->summary.ingress_ema[ 0 ].last_update_nanos ) ) {
924 0 : double sum_in = 0.0;
925 0 : double sum_out = 0.0;
926 0 : for( ulong i=0UL; i<FD_GUI_NET_PROTO_CNT; i++ ) {
927 0 : sum_in += gui->summary.ingress_ema[ i ].value;
928 0 : sum_out += gui->summary.egress_ema[ i ].value;
929 0 : }
930 :
931 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 ) {
932 0 : fd_gui_rate_deque_pop_head( gui->summary.ingress_maxq );
933 0 : }
934 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 ) {
935 0 : fd_gui_rate_deque_pop_tail( gui->summary.ingress_maxq );
936 0 : }
937 0 : if( FD_UNLIKELY( fd_gui_rate_deque_full( gui->summary.ingress_maxq ) ) ) {
938 0 : fd_gui_rate_deque_pop_tail( gui->summary.ingress_maxq );
939 0 : }
940 0 : fd_gui_rate_deque_push_tail( gui->summary.ingress_maxq, (fd_gui_rate_entry_t){ .ts_nanos=now, .value=sum_in } );
941 :
942 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 ) {
943 0 : fd_gui_rate_deque_pop_head( gui->summary.egress_maxq );
944 0 : }
945 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 ) {
946 0 : fd_gui_rate_deque_pop_tail( gui->summary.egress_maxq );
947 0 : }
948 0 : if( FD_UNLIKELY( fd_gui_rate_deque_full( gui->summary.egress_maxq ) ) ) {
949 0 : fd_gui_rate_deque_pop_tail( gui->summary.egress_maxq );
950 0 : }
951 0 : fd_gui_rate_deque_push_tail( gui->summary.egress_maxq, (fd_gui_rate_entry_t){ .ts_nanos=now, .value=sum_out } );
952 0 : }
953 :
954 0 : *prev = *cur;
955 0 : }
956 :
957 : /* Snapshot accdb statistics by reading the accdb tile's metric page
958 : (for gauges) and summing counters across all tiles that join accdb
959 : (executors, replay, rpc, resolv, plus the accdb tile itself).
960 : The result feeds the GUI "Accounts" page. */
961 :
962 : static void
963 : fd_gui_accounts_stats_snap( fd_gui_t * gui,
964 0 : fd_gui_accounts_stats_t * cur ) {
965 0 : fd_topo_t const * topo = gui->topo;
966 :
967 0 : memset( cur, 0, sizeof(*cur) );
968 0 : cur->sample_time_nanos = fd_log_wallclock();
969 :
970 0 : ulong accdb_tile_idx = fd_topo_find_tile( topo, "accdb", 0UL );
971 0 : if( FD_UNLIKELY( accdb_tile_idx==ULONG_MAX ) ) return;
972 :
973 : /* Gauges + accdb-tile-only counters. */
974 0 : fd_topo_tile_t const * accdb = &topo->tiles[ accdb_tile_idx ];
975 0 : volatile ulong const * am = fd_metrics_tile( accdb->metrics );
976 :
977 0 : cur->accounts_total = am[ MIDX( GAUGE, ACCDB, ACCOUNT_USED ) ];
978 0 : cur->accounts_capacity = am[ MIDX( GAUGE, ACCDB, ACCOUNT_CAPACITY ) ];
979 0 : cur->disk_allocated_bytes = am[ MIDX( GAUGE, ACCDB, DISK_ALLOCATED_BYTES ) ];
980 0 : cur->disk_current_bytes = am[ MIDX( GAUGE, ACCDB, DISK_CONSUMED_BYTES ) ];
981 0 : cur->disk_used_bytes = am[ MIDX( GAUGE, ACCDB, DISK_USED_BYTES ) ];
982 0 : cur->in_compaction = am[ MIDX( GAUGE, ACCDB, IS_COMPACTING ) ];
983 0 : cur->compactions_requested = am[ MIDX( COUNTER, ACCDB, COMPACTION_REQUESTED ) ];
984 0 : cur->compactions_completed = am[ MIDX( COUNTER, ACCDB, COMPACTION_COMPLETED ) ];
985 0 : cur->accounts_relocated_bytes = am[ MIDX( COUNTER, ACCDB, ACCOUNT_RELOCATED_BYTES ) ];
986 0 : cur->bytes_written_accdb = am[ MIDX( COUNTER, ACCDB, DISK_WRITTEN_BYTES ) ];
987 :
988 : /* The accdb tile owns the prewrite and compaction writes; include
989 : those in the aggregate bytes_written / write_ops so the IO panel
990 : reflects all on-disk write activity, not just consumer-driven
991 : commits. */
992 0 : cur->bytes_written += am[ MIDX( COUNTER, ACCDB, DISK_WRITTEN_BYTES ) ];
993 0 : cur->write_ops += am[ MIDX( COUNTER, ACCDB, WRITEBACK_WRITTEN ) ];
994 :
995 0 : for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {
996 0 : cur->cache_class_used [ c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_USED ) + c ];
997 0 : cur->cache_class_max [ c ] = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_CAPACITY ) + c ];
998 0 : int tracked = !!am[ MIDX( GAUGE, ACCDB, IS_CACHE_CLASS_RESERVATION_TRACKED ) + c ];
999 0 : cur->cache_class_reserved [ c ] = fd_ulong_if( tracked, am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_RESERVED ) + c ], ULONG_MAX );
1000 0 : ulong free_target = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_FREE_TARGET ) + c ];
1001 0 : ulong free_low_water = am[ MIDX( GAUGE, ACCDB, CACHE_CLASS_FREE_LOW_WATER ) + c ];
1002 0 : cur->cache_class_target_used [ c ] = fd_ulong_sat_sub( cur->cache_class_max[ c ], free_target );
1003 0 : cur->cache_class_low_water_used[c ] = fd_ulong_sat_sub( cur->cache_class_max[ c ], free_low_water );
1004 0 : cur->preevicted_per_class [ c ] = am[ MIDX( COUNTER, ACCDB, ACCOUNT_PREEVICTED ) + c ];
1005 0 : }
1006 :
1007 : /* Walk the per-tile slot table built at init. Each slot reads its
1008 : tile's accdb counters according to its kind (RW, RO, or ACCDB),
1009 : accumulates into the aggregate (cur->*), and stashes the per-tile
1010 : cumulative values into gui->summary.accdb->tile_cur_* for the
1011 : per-tile rate window pushes done later in
1012 : fd_gui_accounts_stats_window_push. */
1013 0 : for( ulong s=0UL; s<gui->summary.accdb->accdb_tile_cnt; s++ ) {
1014 0 : ulong t_idx = (ulong)gui->summary.accdb->accdb_tile_topo_idx[ s ];
1015 0 : uchar kind = gui->summary.accdb->accdb_tile_kind[ s ];
1016 0 : volatile ulong const * m = fd_metrics_tile( topo->tiles[ t_idx ].metrics );
1017 :
1018 0 : gui->summary.accdb->tile_cur_status[ s ] = (uchar)m[ MIDX( GAUGE, TILE, STATE ) ];
1019 :
1020 0 : ulong t_acq=0UL, t_acw=0UL, t_misses=0UL, t_evicted=0UL, t_committed=0UL;
1021 0 : ulong t_bytes_read=0UL, t_bytes_copied=0UL, t_bytes_written=0UL;
1022 0 : ulong t_read_ops=0UL, t_write_ops=0UL;
1023 0 : ulong t_acquire_calls=0UL;
1024 :
1025 0 : switch( kind ) {
1026 0 : # define DO_RW( TILE_UPPER ) \
1027 0 : t_bytes_read = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_DISK_READ_BYTES ) ]; \
1028 0 : t_bytes_copied = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_COPIED_BYTES ) ]; \
1029 0 : t_bytes_written = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_DISK_WRITTEN_BYTES ) ]; \
1030 0 : t_read_ops = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_DISK_READ ) ]; \
1031 0 : t_write_ops = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_DISK_WRITTEN ) ]; \
1032 0 : t_acquire_calls = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_BATCH_ACQUIRED ) ]; \
1033 0 : for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) { \
1034 0 : ulong _acq = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_READONLY_ACQUIRED ) + c ]; \
1035 0 : ulong _acw = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_WRITABLE_ACQUIRED ) + c ]; \
1036 0 : ulong _nf = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_CACHE_MISSED ) + c ]; \
1037 0 : ulong _ev = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_EVICTED ) + c ]; \
1038 0 : ulong _cn = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_NEW_COMMITTED ) + c ]; \
1039 0 : ulong _co = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_OVERWRITE_COMMITTED ) + c ]; \
1040 0 : t_acq+=_acq; t_acw+=_acw; t_misses+=_nf; t_evicted+=_ev; t_committed+=_cn+_co; \
1041 0 : cur->acquired_per_class [ c ] += _acq; \
1042 0 : cur->acquired_writable_per_class [ c ] += _acw; \
1043 0 : cur->not_found_per_class [ c ] += _nf; \
1044 0 : cur->evicted_per_class [ c ] += _ev; \
1045 0 : cur->committed_new_per_class [ c ] += _cn; \
1046 0 : cur->committed_overwrite_per_class [ c ] += _co; \
1047 0 : }
1048 0 : case FD_GUI_ACCDB_TILE_KIND_RW:
1049 0 : if( !strcmp( topo->tiles[ t_idx ].name, "execle" ) ) { DO_RW( EXECLE ); }
1050 0 : else if( !strcmp( topo->tiles[ t_idx ].name, "execrp" ) ) { DO_RW( EXECRP ); }
1051 0 : else if( !strcmp( topo->tiles[ t_idx ].name, "replay" ) ) { DO_RW( REPLAY ); }
1052 0 : cur->acquired += t_acq;
1053 0 : cur->acquired_writable += t_acw;
1054 0 : cur->bytes_read += t_bytes_read;
1055 0 : cur->bytes_copied += t_bytes_copied;
1056 0 : cur->bytes_written += t_bytes_written;
1057 0 : cur->read_ops += t_read_ops;
1058 0 : cur->write_ops += t_write_ops;
1059 0 : break;
1060 0 : # undef DO_RW
1061 :
1062 0 : # define DO_RO( TILE_UPPER ) \
1063 0 : t_bytes_read = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_DISK_READ_BYTES ) ]; \
1064 0 : t_bytes_copied = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_COPIED_BYTES ) ]; \
1065 0 : t_read_ops = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_DISK_READ ) ]; \
1066 0 : for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) { \
1067 0 : ulong _acq = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_READONLY_ACQUIRED ) + c ]; \
1068 0 : ulong _nf = m[ MIDX( COUNTER, TILE_UPPER, ACCDB_ACCOUNT_CACHE_MISSED ) + c ]; \
1069 0 : t_acq+=_acq; t_misses+=_nf; \
1070 0 : cur->acquired_per_class [ c ] += _acq; \
1071 0 : cur->not_found_per_class[ c ] += _nf; \
1072 0 : }
1073 0 : case FD_GUI_ACCDB_TILE_KIND_RO:
1074 0 : if( !strcmp( topo->tiles[ t_idx ].name, "rpc" ) ) { DO_RO( RPC ); }
1075 0 : else if( !strcmp( topo->tiles[ t_idx ].name, "resolv" ) ) { DO_RO( RESOLV ); }
1076 0 : cur->acquired += t_acq;
1077 0 : cur->bytes_read += t_bytes_read;
1078 0 : cur->bytes_copied += t_bytes_copied;
1079 0 : cur->read_ops += t_read_ops;
1080 0 : break;
1081 0 : # undef DO_RO
1082 :
1083 0 : case FD_GUI_ACCDB_TILE_KIND_SNAPIN:
1084 : /* snapin writes account data to disk directly during snapshot
1085 : load. */
1086 0 : t_bytes_written = m[ MIDX( COUNTER, SNAPIN, DISK_WRITTEN_BYTES ) ];
1087 0 : cur->bytes_written += t_bytes_written;
1088 0 : break;
1089 :
1090 0 : case FD_GUI_ACCDB_TILE_KIND_ACCDB:
1091 : /* The accdb tile owns prewrite and compaction writes. Its own
1092 : bytes_written/write_ops were already folded into the aggregate
1093 : above (see ACCDB_DISK_WRITTEN_BYTES / ACCDB_WRITE_OPS reads). Here
1094 : we only stash per-slot values so the per-tile row reflects
1095 : them; do not re-add to cur->* or we'd double-count. The accdb
1096 : tile does not expose acquired/not_found/committed (no account
1097 : joiner) or read_ops/bytes_copied. Preevicts are owned by the
1098 : accdb tile's background preevict pass, so map them to the
1099 : per-tile evicted column for this row. */
1100 0 : t_bytes_read = m[ MIDX( COUNTER, ACCDB, DISK_READ_BYTES ) ];
1101 0 : t_bytes_written = m[ MIDX( COUNTER, ACCDB, DISK_WRITTEN_BYTES ) ];
1102 0 : t_write_ops = m[ MIDX( COUNTER, ACCDB, WRITEBACK_WRITTEN ) ];
1103 0 : for( ulong c=0UL; c<FD_ACCDB_CACHE_CLASS_CNT; c++ ) {
1104 0 : t_evicted += m[ MIDX( COUNTER, ACCDB, ACCOUNT_PREEVICTED ) + c ];
1105 0 : }
1106 0 : break;
1107 0 : }
1108 :
1109 0 : gui->summary.accdb->tile_cur_acquired [ s ] = t_acq;
1110 0 : gui->summary.accdb->tile_cur_acquired_writable[ s ] = t_acw;
1111 0 : gui->summary.accdb->tile_cur_bytes_read [ s ] = t_bytes_read;
1112 0 : gui->summary.accdb->tile_cur_bytes_copied [ s ] = t_bytes_copied;
1113 0 : gui->summary.accdb->tile_cur_bytes_written [ s ] = t_bytes_written;
1114 0 : gui->summary.accdb->tile_cur_read_ops [ s ] = t_read_ops;
1115 0 : gui->summary.accdb->tile_cur_write_ops [ s ] = t_write_ops;
1116 0 : gui->summary.accdb->tile_cur_misses [ s ] = t_misses;
1117 0 : gui->summary.accdb->tile_cur_evicted [ s ] = t_evicted;
1118 0 : gui->summary.accdb->tile_cur_committed [ s ] = t_committed;
1119 0 : gui->summary.accdb->tile_cur_acquire_calls [ s ] = t_acquire_calls;
1120 0 : }
1121 :
1122 0 : if( FD_UNLIKELY( !gui->accdb_shmem ) ) return;
1123 :
1124 : /* Snapshot per-partition utilization and fragmentation and also
1125 : their respective per-tier rate of growth. Actively-compacting
1126 : partitions excluded so relocation churn does not degrade estimates. */
1127 0 : ulong pcnt = fd_ulong_min( fd_accdb_shmem_partition_max( gui->accdb_shmem ), FD_GUI_MAX_PARTITIONS );
1128 0 : gui->summary.accdb->partition_cnt = pcnt;
1129 :
1130 0 : double tier_fill_delta[ FD_ACCDB_COMPACTION_LAYER_CNT ] = { 0.0 };
1131 0 : double tier_free_delta[ FD_ACCDB_COMPACTION_LAYER_CNT ] = { 0.0 };
1132 0 : ulong compaction_idx = ULONG_MAX;
1133 0 : ulong compaction_layer = FD_ACCDB_COMPACTION_LAYER_CNT;
1134 0 : ulong compaction_state = 0UL;
1135 0 : for( ulong p=0UL; p<pcnt; p++ ) {
1136 0 : fd_accdb_shmem_partition_info_t prev_info = gui->summary.accdb->partitions[ p ];
1137 0 : fd_accdb_shmem_partition_info_t * info = &gui->summary.accdb->partitions[ p ];
1138 0 : fd_accdb_shmem_partition_info( gui->accdb_shmem, p, info );
1139 :
1140 0 : if( FD_UNLIKELY( info->compaction_state && ( compaction_state<info->compaction_state || ( compaction_state==info->compaction_state && info->layer<compaction_layer ) ) ) ) {
1141 0 : compaction_idx = p;
1142 0 : compaction_layer = info->layer;
1143 0 : compaction_state = info->compaction_state;
1144 0 : }
1145 :
1146 0 : if( FD_LIKELY( info->layer<FD_ACCDB_COMPACTION_LAYER_CNT ) ) {
1147 : /* Only the <=3 write-head partitions advance, and freed bytes
1148 : land in a handful of partitions per 100ms snap. */
1149 0 : if( FD_UNLIKELY( info->write_offset>prev_info.write_offset ) )
1150 0 : tier_fill_delta[ info->layer ] += (double)(info->write_offset-prev_info.write_offset);
1151 0 : if( FD_UNLIKELY( info->compaction_state!=2 && info->bytes_freed>prev_info.bytes_freed ) )
1152 0 : tier_free_delta[ info->layer ] += (double)(info->bytes_freed-prev_info.bytes_freed);
1153 0 : }
1154 0 : }
1155 :
1156 : /* First snap has no valid deltas. */
1157 0 : if( FD_LIKELY( gui->summary.accdb->tier_sample_nanos!=LONG_MAX ) ) {
1158 0 : double dt_sec = (double)(cur->sample_time_nanos-gui->summary.accdb->tier_sample_nanos)/1e9;
1159 0 : if( FD_LIKELY( dt_sec>0.0 ) ) {
1160 0 : for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
1161 0 : fd_gui_ema_advance( &gui->summary.accdb->tier_fill_bps_ema[ k ], cur->sample_time_nanos, tier_fill_delta[ k ]/dt_sec );
1162 0 : fd_gui_ema_advance( &gui->summary.accdb->tier_free_bps_ema[ k ], cur->sample_time_nanos, tier_free_delta[ k ]/dt_sec );
1163 0 : }
1164 0 : }
1165 0 : }
1166 0 : gui->summary.accdb->tier_sample_nanos = cur->sample_time_nanos;
1167 :
1168 : /* Estimate next compaction time/partition. */
1169 0 : double next_secs = 0.0;
1170 0 : ulong next_idx = ULONG_MAX;
1171 0 : double partition_sz = (double)fd_accdb_shmem_partition_sz( gui->accdb_shmem );
1172 0 : double tier_live_bytes[ FD_ACCDB_COMPACTION_LAYER_CNT ] = { 0.0 };
1173 0 : for( ulong p=0UL; p<pcnt; p++ ) {
1174 0 : fd_accdb_shmem_partition_info_t const * info = &gui->summary.accdb->partitions[ p ];
1175 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 )
1176 0 : tier_live_bytes[ info->layer ] += (double)(info->write_offset-info->bytes_freed);
1177 0 : }
1178 0 : for( ulong p=0UL; p<pcnt; p++ ) {
1179 0 : fd_accdb_shmem_partition_info_t const * info = &gui->summary.accdb->partitions[ p ];
1180 0 : if( FD_LIKELY( info->compaction_state || !info->write_offset ) ) continue;
1181 0 : if( FD_UNLIKELY( info->layer>=FD_ACCDB_COMPACTION_LAYER_CNT ) ) continue;
1182 0 : if( FD_UNLIKELY( info->compaction_offset>=info->write_offset ) ) continue; /* compacted, awaiting reclaim */
1183 :
1184 0 : double free_bps = gui->summary.accdb->tier_free_bps_ema[ info->layer ].value;
1185 0 : double live = info->write_offset>info->bytes_freed ? (double)(info->write_offset-info->bytes_freed) : 0.0;
1186 0 : double frag_rate = tier_live_bytes[ info->layer ]>0.0 ? free_bps*live/tier_live_bytes[ info->layer ] : 0.0;
1187 0 : double deficit = (double)FD_ACCDB_COMPACTION_THRESHOLD_PCT/100.0*partition_sz - (double)info->bytes_freed;
1188 0 : double frag_secs = deficit<=0.0 ? 0.0 : ( frag_rate>0.0 ? deficit/frag_rate : -1.0 );
1189 0 : double fill_secs = 0.0;
1190 0 : if( FD_UNLIKELY( info->is_write_head ) ) {
1191 0 : double fill_bps = gui->summary.accdb->tier_fill_bps_ema[ info->layer ].value;
1192 0 : fill_secs = fill_bps>0.0 ? (partition_sz-(double)info->write_offset)/fill_bps : -1.0;
1193 0 : }
1194 :
1195 0 : if( FD_UNLIKELY( frag_secs<0.0 || fill_secs<0.0 ) ) continue; /* no usable rate estimate (EMA warm-up) */
1196 0 : double est = fmax( frag_secs, fill_secs );
1197 0 : if( next_idx==ULONG_MAX || est<next_secs ) {
1198 0 : next_secs = est;
1199 0 : next_idx = p;
1200 0 : }
1201 0 : }
1202 :
1203 0 : int has_compaction = compaction_idx!=ULONG_MAX;
1204 0 : gui->summary.accdb->next_compaction_remaining_secs = fd_double_if( has_compaction, 0.0, next_secs );
1205 0 : gui->summary.accdb->next_compaction_partition_idx = fd_ulong_if( has_compaction, compaction_idx, next_idx );
1206 0 : }
1207 :
1208 : /* Snapshot all of the data from metrics to construct a view of the
1209 : transaction waterfall.
1210 :
1211 : Tiles are sampled in reverse pipeline order: this helps prevent data
1212 : discrepancies where a later tile has "seen" more transactions than an
1213 : earlier tile, which shouldn't typically happen. */
1214 :
1215 : static void
1216 : fd_gui_txn_waterfall_snap( fd_gui_t * gui,
1217 6 : fd_gui_txn_waterfall_t * cur ) {
1218 6 : memset( cur, 0, sizeof(fd_gui_txn_waterfall_t) );
1219 6 : fd_topo_t const * topo = gui->topo;
1220 :
1221 6 : for( ulong i=0UL; i<gui->summary.execle_tile_cnt; i++ ) {
1222 0 : fd_topo_tile_t const * execle = &topo->tiles[ fd_topo_find_tile( topo, "execle", i ) ];
1223 :
1224 0 : volatile ulong const * execle_metrics = fd_metrics_tile( execle->metrics );
1225 :
1226 0 : cur->out.block_success += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_PROCESSED_BY_LANDING_SUCCESS ) ];
1227 0 : cur->out.block_fail +=
1228 0 : execle_metrics[ MIDX( COUNTER, EXECLE, TXN_PROCESSED_BY_LANDING_FEES_ONLY ) ]
1229 0 : + execle_metrics[ MIDX( COUNTER, EXECLE, TXN_PROCESSED_BY_LANDING_FAILED ) ];
1230 0 : cur->out.bank_invalid += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_PROCESSED_BY_LANDING_DROPPED ) ];
1231 :
1232 0 : cur->out.bank_nonce_already_advanced += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_PROCESSED_NONCE_ALREADY_ADVANCED ) ];
1233 0 : cur->out.bank_nonce_advance_failed += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_PROCESSED_NONCE_ADVANCE_FAILED ) ];
1234 0 : cur->out.bank_nonce_wrong_blockhash += execle_metrics[ MIDX( COUNTER, EXECLE, TXN_PROCESSED_NONCE_WRONG_BLOCKHASH ) ];
1235 0 : }
1236 :
1237 6 : ulong pack_tile_idx = fd_topo_find_tile( topo, "pack", 0UL );
1238 6 : if( pack_tile_idx!=ULONG_MAX ) {
1239 0 : fd_topo_tile_t const * pack = &topo->tiles[ pack_tile_idx ];
1240 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
1241 :
1242 0 : cur->out.pack_invalid_bundle =
1243 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_DROPPED_PARTIAL_BUNDLE ) ]
1244 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_ATTEMPTED_INSERTION_FAILED ) ]
1245 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_ATTEMPTED_CREATION_FAILED ) ];
1246 :
1247 0 : cur->out.pack_invalid =
1248 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_INSTR_TOO_MANY_ACCOUNTS ) ]
1249 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_NONCE_CONFLICT ) ]
1250 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_BUNDLE_BLOCKLISTED ) ]
1251 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_INVALID_NONCE ) ]
1252 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_WRITE_SYSVAR ) ]
1253 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_ESTIMATION_FAILED ) ]
1254 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_DUPLICATE_ACCOUNT ) ]
1255 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_TOO_MANY_ACCOUNTS ) ]
1256 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_TOO_MANY_CU ) ]
1257 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_LUT_UNSUPPORTED ) ]
1258 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_UNAFFORDABLE ) ]
1259 0 : + pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_DUPLICATE ) ]
1260 0 : - pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_ATTEMPTED_INSERTION_FAILED ) ]; /* so we don't double count this, since its already accounted for in invalid_bundle */
1261 :
1262 0 : cur->out.pack_expired = pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_EXPIRED ) ] +
1263 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_DROPPED_EXPIRED ) ] +
1264 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_EVICTED ) ] +
1265 0 : pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_NONCE_PRIORITY_TOO_LOW ) ];
1266 :
1267 0 : cur->out.pack_already_executed = pack_metrics[ MIDX( COUNTER, PACK, TXN_DROPPED_ALREADY_EXECUTED ) ];
1268 :
1269 0 : cur->out.pack_leader_slow = pack_metrics[ MIDX( COUNTER, PACK, TXN_INSERT_ATTEMPTED_PRIORITY_TOO_LOW ) ];
1270 :
1271 0 : cur->out.pack_retained = fd_metrics_enum_group_sum( pack_metrics+MIDX( GAUGE, PACK, TXN_PENDING_USED ), FD_METRICS_ENUM_PENDING_TXN_TYPE_G_ALL_MASK );
1272 :
1273 0 : cur->in.pack_cranked =
1274 0 : pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_ATTEMPTED_INSERTED ) ]
1275 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_ATTEMPTED_INSERTION_FAILED ) ]
1276 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_ATTEMPTED_CREATION_FAILED ) ];
1277 0 : }
1278 :
1279 6 : for( ulong i=0UL; i<gui->summary.resolv_tile_cnt; i++ ) {
1280 0 : fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolv", i ) ];
1281 0 : volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
1282 :
1283 0 : cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_DROPPED_NO_BANK ) ];
1284 0 : cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_DROPPED_BLOCKHASH_EXPIRED ) ]
1285 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_DROPPED_BUNDLE_PEER_FAILED ) ];
1286 0 : cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_LUT_RESOLVE_ATTEMPTED_ACCOUNT_NOT_FOUND ) ]
1287 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_LUT_RESOLVE_ATTEMPTED_INVALID_ACCOUNT_OWNER ) ]
1288 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_LUT_RESOLVE_ATTEMPTED_INVALID_ACCOUNT_DATA ) ]
1289 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_LUT_RESOLVE_ATTEMPTED_ACCOUNT_UNINITIALIZED ) ]
1290 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, TXN_LUT_RESOLVE_ATTEMPTED_INVALID_LOOKUP_INDEX ) ];
1291 0 : cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_TXN_REMOVED_EVICTED ) ];
1292 :
1293 0 : ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_TXN_INSERTED ) ];
1294 0 : ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_TXN_REMOVED_EVICTED ) ]
1295 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_TXN_REMOVED_PUBLISHED ) ]
1296 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_TXN_REMOVED_FAILED ) ];
1297 0 : cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
1298 0 : }
1299 :
1300 6 : cur->out.dedup_duplicate = 0UL;
1301 6 : for( ulong i=0UL; i<fd_topo_tile_name_cnt( topo, "dedup" ); i++ ) {
1302 0 : fd_topo_tile_t const * dedup = &topo->tiles[ fd_topo_find_tile( topo, "dedup", i ) ];
1303 0 : volatile ulong const * dedup_metrics = fd_metrics_tile( dedup->metrics );
1304 :
1305 0 : cur->out.dedup_duplicate += dedup_metrics[ MIDX( COUNTER, DEDUP, TXN_PROCESSED_DUPLICATE ) ]
1306 0 : + dedup_metrics[ MIDX( COUNTER, DEDUP, TXN_PROCESSED_BUNDLE_PEER_FAILED ) ];
1307 0 : }
1308 :
1309 6 : for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
1310 0 : fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
1311 0 : volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
1312 :
1313 0 : for( ulong j=0UL; j<gui->summary.quic_tile_cnt; j++ ) {
1314 : /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this verify tile. */
1315 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;
1316 0 : cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_READING_OVERRUN_OFF ];
1317 0 : }
1318 :
1319 0 : cur->out.verify_failed += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_PROCESSED_SIGNATURE_FAILED ) ] +
1320 0 : verify_metrics[ MIDX( COUNTER, VERIFY, TXN_PROCESSED_BUNDLE_PEER_FAILED ) ];
1321 0 : cur->out.verify_parse += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_PROCESSED_PARSE_FAILED ) ];
1322 0 : cur->out.verify_duplicate += verify_metrics[ MIDX( COUNTER, VERIFY, TXN_PROCESSED_DUPLICATE ) ];
1323 0 : }
1324 :
1325 6 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
1326 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
1327 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
1328 :
1329 0 : cur->out.tpu_udp_invalid += quic_metrics[ MIDX( COUNTER, QUIC, UDP_TXN_UNDERSIZE_DROPPED ) ];
1330 0 : cur->out.tpu_udp_invalid += quic_metrics[ MIDX( COUNTER, QUIC, UDP_TXN_OVERSIZE_DROPPED ) ];
1331 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_DROPPED )+FD_METRICS_ENUM_QUIC_PKT_DROP_REASON_V_UNDERSIZE_IDX ];
1332 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_DROPPED )+FD_METRICS_ENUM_QUIC_PKT_DROP_REASON_V_OVERSIZE_IDX ];
1333 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, TXN_OVERSIZE_DROPPED ) ];
1334 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_DECRYPT_FAILED ) ];
1335 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NO_CONN_DROPPED ) ];
1336 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_DROPPED )+FD_METRICS_ENUM_QUIC_PKT_DROP_REASON_V_SRC_IP_MISMATCH_IDX ];
1337 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_DROPPED )+FD_METRICS_ENUM_QUIC_PKT_DROP_REASON_V_NET_HEADER_INVALID_IDX ];
1338 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_DROPPED )+FD_METRICS_ENUM_QUIC_PKT_DROP_REASON_V_HEADER_INVALID_IDX ];
1339 0 : cur->out.quic_abandoned += quic_metrics[ MIDX( COUNTER, QUIC, TXN_REASSEMBLY_ABANDONED ) ];
1340 0 : cur->out.quic_frag_drop += quic_metrics[ MIDX( COUNTER, QUIC, TXN_REASSEMBLY_EVICTED ) ];
1341 :
1342 0 : for( ulong j=0UL; j<gui->summary.sock_tile_cnt+gui->summary.net_tile_cnt+gui->summary.mlx5_tile_cnt+gui->summary.iavf_tile_cnt; j++ ) {
1343 : /* TODO: Not precise... net frags that were skipped might not have been destined for QUIC tile */
1344 : /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this QUIC tile */
1345 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;
1346 0 : cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_FRAG_READING_OVERRUN_OFF ];
1347 0 : }
1348 0 : }
1349 :
1350 6 : for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
1351 0 : fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
1352 0 : volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
1353 :
1354 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_RING_FULL_DROPPED ) ];
1355 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_OTHER_DROPPED ) ];
1356 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_FILL_RING_EMPTY ) ];
1357 0 : }
1358 6 : ulong bundle_txns_received = 0UL;
1359 6 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
1360 6 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
1361 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
1362 0 : volatile ulong const * bundle_metrics = fd_metrics_tile( bundle->metrics );
1363 :
1364 0 : bundle_txns_received = bundle_metrics[ MIDX( COUNTER, BUNDLE, TXN_RX ) ];
1365 0 : }
1366 :
1367 6 : cur->in.quic = cur->out.tpu_quic_invalid +
1368 6 : cur->out.quic_overrun +
1369 6 : cur->out.quic_frag_drop +
1370 6 : cur->out.quic_abandoned +
1371 6 : cur->out.net_overrun;
1372 6 : cur->in.udp = cur->out.tpu_udp_invalid;
1373 6 : cur->in.block_engine = bundle_txns_received;
1374 6 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
1375 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
1376 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
1377 :
1378 0 : cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_QUIC_FAST ) ];
1379 0 : cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_QUIC_FRAG ) ];
1380 0 : cur->in.udp += quic_metrics[ MIDX( COUNTER, QUIC, TXN_RX_UDP ) ];
1381 0 : }
1382 6 : }
1383 :
1384 : static void
1385 : fd_gui_tile_stats_snap( fd_gui_t * gui,
1386 : fd_gui_txn_waterfall_t const * waterfall,
1387 : fd_gui_tile_stats_t * stats,
1388 0 : long now ) {
1389 0 : memset( stats, 0, sizeof(fd_gui_tile_stats_t) );
1390 0 : fd_topo_t const * topo = gui->topo;
1391 :
1392 0 : stats->sample_time_nanos = now;
1393 :
1394 0 : for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
1395 0 : fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
1396 0 : volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
1397 :
1398 0 : stats->net_in_rx_bytes += net_metrics[ MIDX( COUNTER, NET, PKT_RX_BYTES ) ];
1399 0 : stats->net_out_tx_bytes += net_metrics[ MIDX( COUNTER, NET, PKT_TX_SUBMITTED_BYTES ) ];
1400 0 : }
1401 :
1402 0 : for( ulong i=0UL; i<gui->summary.sock_tile_cnt; i++ ) {
1403 0 : fd_topo_tile_t const * sock = &topo->tiles[ fd_topo_find_tile( topo, "sock", i ) ];
1404 0 : volatile ulong * sock_metrics = fd_metrics_tile( sock->metrics );
1405 :
1406 0 : stats->net_in_rx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, PKT_RX_BYTES ) ];
1407 0 : stats->net_out_tx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, PKT_TX_BYTES ) ];
1408 0 : }
1409 :
1410 0 : for( ulong i=0UL; i<gui->summary.mlx5_tile_cnt; i++ ) {
1411 0 : fd_topo_tile_t const * mlx5 = &topo->tiles[ fd_topo_find_tile( topo, "mlx5", i ) ];
1412 0 : volatile ulong * mlx5_metrics = fd_metrics_tile( mlx5->metrics );
1413 :
1414 0 : stats->net_in_rx_bytes += mlx5_metrics[ MIDX( COUNTER, MLX5, PKT_RX_BYTES ) ];
1415 0 : stats->net_out_tx_bytes += mlx5_metrics[ MIDX( COUNTER, MLX5, PKT_TX_COMPLETED_BYTES ) ];
1416 0 : }
1417 :
1418 0 : for( ulong i=0UL; i<gui->summary.iavf_tile_cnt; i++ ) {
1419 0 : fd_topo_tile_t const * iavf = &topo->tiles[ fd_topo_find_tile( topo, "iavf", i ) ];
1420 0 : volatile ulong * iavf_metrics = fd_metrics_tile( iavf->metrics );
1421 0 : stats->net_in_rx_bytes += iavf_metrics[ MIDX( COUNTER, IAVF, PKT_RX_BYTES ) ];
1422 0 : stats->net_out_tx_bytes += iavf_metrics[ MIDX( COUNTER, IAVF, PKT_TX_COMPLETED_BYTES ) ];
1423 0 : }
1424 :
1425 0 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
1426 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
1427 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
1428 :
1429 0 : for( ulong s=0UL; s<FD_METRICS_ENUM_QUIC_CONN_STATE_CNT; s++ ) stats->quic_conn_cnt += quic_metrics[ MIDX( GAUGE, QUIC, CONN_USED )+s ];
1430 0 : }
1431 :
1432 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
1433 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
1434 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
1435 0 : volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
1436 0 : stats->bundle_rtt_smoothed_nanos = bundle_metrics[ MIDX( GAUGE, BUNDLE, RTT_SMOOTHED_NANOS ) ];
1437 :
1438 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 ) );
1439 0 : stats->bundle_rx_delay_hist.sum = bundle_metrics[ MIDX( HISTOGRAM, BUNDLE, MESSAGE_RX_DELAY_NANOS ) + FD_HISTF_BUCKET_CNT ];
1440 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 ];
1441 0 : }
1442 :
1443 0 : stats->verify_drop_cnt = waterfall->out.verify_duplicate +
1444 0 : waterfall->out.verify_parse +
1445 0 : waterfall->out.verify_failed;
1446 0 : stats->verify_total_cnt = waterfall->in.quic +
1447 0 : waterfall->in.udp -
1448 0 : waterfall->out.net_overrun -
1449 0 : waterfall->out.tpu_quic_invalid -
1450 0 : waterfall->out.tpu_udp_invalid -
1451 0 : waterfall->out.quic_abandoned -
1452 0 : waterfall->out.quic_frag_drop -
1453 0 : waterfall->out.quic_overrun -
1454 0 : waterfall->out.verify_overrun;
1455 0 : stats->dedup_drop_cnt = waterfall->out.dedup_duplicate;
1456 0 : stats->dedup_total_cnt = stats->verify_total_cnt -
1457 0 : waterfall->out.verify_duplicate -
1458 0 : waterfall->out.verify_parse -
1459 0 : waterfall->out.verify_failed;
1460 :
1461 0 : ulong pack_tile_idx = fd_topo_find_tile( topo, "pack", 0UL );
1462 0 : if( pack_tile_idx!=ULONG_MAX ) {
1463 0 : fd_topo_tile_t const * pack = &topo->tiles[ pack_tile_idx ];
1464 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
1465 0 : stats->pack_buffer_cnt = fd_metrics_enum_group_sum( pack_metrics+MIDX( GAUGE, PACK, TXN_PENDING_USED ), FD_METRICS_ENUM_PENDING_TXN_TYPE_G_ALL_MASK );
1466 0 : stats->pack_buffer_capacity = pack->pack.max_pending_transactions;
1467 0 : }
1468 :
1469 0 : stats->bank_txn_exec_cnt = waterfall->out.block_fail + waterfall->out.block_success;
1470 :
1471 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_STATS, stats );
1472 0 : }
1473 :
1474 : static void
1475 0 : fd_gui_run_boot_progress( fd_gui_t * gui, long now ) {
1476 0 : fd_topo_tile_t const * snapct = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapct", 0UL ) ];
1477 0 : volatile ulong * snapct_metrics = fd_metrics_tile( snapct->metrics );
1478 :
1479 0 : ulong snapdc_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "snapdc" );
1480 0 : ulong snapin_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "snapin" );
1481 :
1482 : /* Backtest topologies have no gossip tile; treat wait-for-supermajority
1483 : as done. */
1484 0 : ulong wfs_state = FD_GOSSIP_WFS_STATE_DONE;
1485 0 : volatile ulong * gossip_metrics = NULL;
1486 0 : ulong gossip_tile_idx = fd_topo_find_tile( gui->topo, "gossip", 0UL );
1487 0 : if( FD_LIKELY( gossip_tile_idx!=ULONG_MAX ) ) {
1488 0 : fd_topo_tile_t const * gossip = &gui->topo->tiles[ gossip_tile_idx ];
1489 0 : gossip_metrics = fd_metrics_tile( gossip->metrics );
1490 0 : wfs_state = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STATE ) ];
1491 0 : }
1492 :
1493 0 : ulong snapshot_phase = snapct_metrics[ MIDX( GAUGE, SNAPCT, LOAD_STATE ) ];
1494 :
1495 : /* Backtest topologies have no turbine, so the regular catch-up
1496 : detection (turbine slot vs. replayed slot) can never trigger.
1497 : Consider replay caught up at the first reset slot after the
1498 : snapshot finishes loading. */
1499 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX &&
1500 0 : snapshot_phase==FD_SNAPCT_STATE_SHUTDOWN &&
1501 0 : gui->summary.slot_tower!=ULONG_MAX &&
1502 0 : fd_topo_find_tile( gui->topo, "backt", 0UL )!=ULONG_MAX ) ) {
1503 0 : gui->summary.slot_caught_up = gui->summary.slot_tower;
1504 0 : gui->summary.boot_progress.catching_up_time_nanos = now;
1505 :
1506 0 : fd_gui_printf_slot_caught_up( gui );
1507 0 : fd_http_server_ws_broadcast( gui->http );
1508 0 : }
1509 :
1510 : /* state transitions */
1511 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
1512 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
1513 0 : for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
1514 0 : fd_gui_ema_init( &gui->summary.accdb->tier_fill_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
1515 0 : fd_gui_ema_init( &gui->summary.accdb->tier_free_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
1516 0 : }
1517 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_turbine!=ULONG_MAX ) && gui->summary.slot_tower!=ULONG_MAX ) ) {
1518 0 : if( FD_UNLIKELY( fd_gui_wfs_mode( gui )==FD_WFS_MODE_MATCH ) ) {
1519 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) {
1520 0 : gui->summary.slot_caught_up = fd_gui_boot_snapshot_slot( gui );
1521 0 : gui->summary.boot_progress.catching_up_time_nanos = now;
1522 :
1523 0 : fd_gui_printf_slot_caught_up( gui );
1524 0 : fd_http_server_ws_broadcast( gui->http );
1525 0 : }
1526 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
1527 0 : for( ulong k=0UL; k<FD_ACCDB_COMPACTION_LAYER_CNT; k++ ) {
1528 0 : fd_gui_ema_init( &gui->summary.accdb->tier_fill_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
1529 0 : fd_gui_ema_init( &gui->summary.accdb->tier_free_bps_ema[ k ], now, FD_GUI_ACCDB_EMA_HALF_LIFE_NS );
1530 0 : }
1531 0 : } else {
1532 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP;
1533 0 : }
1534 0 : } else if( FD_UNLIKELY( snapshot_phase == FD_SNAPCT_STATE_SHUTDOWN && wfs_state==FD_GOSSIP_WFS_STATE_WAIT ) ) {
1535 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY;
1536 0 : } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_FULL_FILE
1537 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_FILE_FINI
1538 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_FILE_DONE
1539 0 : || snapshot_phase==FD_SNAPCT_STATE_READING_FULL_HTTP
1540 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_FINI
1541 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_DONE ) ) {
1542 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT;
1543 0 : } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_FILE
1544 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_FINI
1545 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_DONE
1546 0 : || snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_HTTP
1547 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_FINI
1548 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_DONE ) ) {
1549 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
1550 0 : }
1551 :
1552 : /* It's possible for the incremental snapshot phase to be skipped, or
1553 : complete before we can sample it. This ensures we always get at
1554 : least one pass of the metrics. */
1555 0 : if( FD_UNLIKELY( gui->summary.boot_progress.phase==FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP
1556 0 : && gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].reset_cnt==ULONG_MAX ) ) {
1557 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
1558 0 : }
1559 :
1560 0 : switch ( gui->summary.boot_progress.phase ) {
1561 0 : case FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP: {
1562 0 : gui->summary.boot_progress.joining_gossip_time_nanos = now;
1563 0 : break;
1564 0 : }
1565 0 : case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT:
1566 0 : case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT: {
1567 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 );
1568 0 : ulong _retry_cnt = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( COUNTER, SNAPCT, LOAD_RETRIED_FULL ) ], snapct_metrics[ MIDX( COUNTER, SNAPCT, LOAD_RETRIED_INCREMENTAL ) ]);
1569 :
1570 : /* reset boot state if necessary */
1571 0 : if( FD_UNLIKELY( gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt!=_retry_cnt ) ) {
1572 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_time_nanos = now;
1573 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt = _retry_cnt;
1574 0 : }
1575 :
1576 0 : ulong _total_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, READ_EXPECTED_BYTES_FULL ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, READ_EXPECTED_BYTES_INCREMENTAL ) ] );
1577 0 : ulong _read_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, READ_PROGRESS_BYTES_FULL ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, READ_PROGRESS_BYTES_INCREMENTAL ) ] );
1578 0 : ulong _decompress_decompressed_bytes = fd_gui_metrics_sum_tiles_counter( gui->topo, "snapdc", snapdc_tile_cnt, fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, MIDX( GAUGE, SNAPDC, DECOMPRESSED_PROGRESS_BYTES_FULL ), MIDX( GAUGE, SNAPDC, DECOMPRESSED_PROGRESS_BYTES_INCREMENTAL ) ) );
1579 0 : ulong _decompress_compressed_bytes = fd_gui_metrics_sum_tiles_counter( gui->topo, "snapdc", snapdc_tile_cnt, fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, MIDX( GAUGE, SNAPDC, COMPRESSED_PROGRESS_BYTES_FULL ), MIDX( GAUGE, SNAPDC, COMPRESSED_PROGRESS_BYTES_INCREMENTAL ) ) );
1580 0 : ulong _insert_metric = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, MIDX( GAUGE, SNAPIN, PARSE_PROGRESS_BYTES_FULL ), MIDX( GAUGE, SNAPIN, PARSE_PROGRESS_BYTES_INCREMENTAL ) );
1581 0 : ulong _insert_bytes = ULONG_MAX;
1582 0 : for( ulong i=0UL; i<snapin_tile_cnt; i++ ) {
1583 0 : fd_topo_tile_t const * snapin = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapin", i ) ];
1584 0 : volatile ulong const * snapin_metrics = fd_metrics_tile( snapin->metrics );
1585 0 : _insert_bytes = fd_ulong_min( _insert_bytes, snapin_metrics[ _insert_metric ] );
1586 0 : }
1587 :
1588 0 : ulong _insert_accounts_total = fd_gui_metrics_sum_tiles_counter( gui->topo, "snapin", snapin_tile_cnt, MIDX( GAUGE, SNAPIN, ACCOUNT_PROGRESS_NEW ) );
1589 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 );
1590 0 : ulong _insert_accounts = fd_ulong_sat_sub( _insert_accounts_total, _insert_accounts_baseline );
1591 :
1592 : /* metadata */
1593 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].total_bytes_compressed = _total_bytes;
1594 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].sample_time_nanos = now;
1595 :
1596 : /* read stage */
1597 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_bytes_compressed = _read_bytes;
1598 :
1599 : /* decompress stage */
1600 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_compressed = _decompress_compressed_bytes;
1601 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_decompressed = _decompress_decompressed_bytes;
1602 :
1603 : /* insert stage */
1604 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_bytes_decompressed = _insert_bytes;
1605 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_accounts_current = _insert_accounts;
1606 :
1607 0 : break;
1608 0 : }
1609 0 : case FD_GUI_BOOT_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY: {
1610 : /* Only reachable when the topology has a gossip tile. */
1611 0 : gui->summary.boot_progress.wfs_total_stake = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKE_TRACKED_LAMPORTS ) ];
1612 0 : gui->summary.boot_progress.wfs_connected_stake = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKE_ONLINE_LAMPORTS ) ];
1613 0 : gui->summary.boot_progress.wfs_total_peers = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKED_PEER_COUNT ) ];
1614 0 : gui->summary.boot_progress.wfs_connected_peers = gossip_metrics[ MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKED_PEER_ONLINE ) ];
1615 0 : break;
1616 0 : }
1617 0 : case FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP: {
1618 0 : gui->summary.boot_progress.catching_up_time_nanos = now;
1619 0 : break;
1620 0 : }
1621 0 : case FD_GUI_BOOT_PROGRESS_TYPE_RUNNING: break;
1622 0 : default: FD_LOG_ERR(( "unknown boot progress phase: %d", gui->summary.boot_progress.phase ));
1623 0 : }
1624 0 : }
1625 :
1626 : static inline int
1627 27 : fd_gui_ephemeral_slots_contains( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot ) {
1628 120 : for( ulong i=0UL; i<slots_sz; i++ ) {
1629 114 : if( FD_UNLIKELY( slots[ i ].slot==ULONG_MAX ) ) break;
1630 102 : if( FD_UNLIKELY( slots[ i ].slot==slot ) ) return 1;
1631 102 : }
1632 18 : return 0;
1633 27 : }
1634 :
1635 : #define SORT_NAME fd_gui_ephemeral_slot_sort
1636 525 : #define SORT_KEY_T fd_gui_ephemeral_slot_t
1637 345 : #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 ) ) )
1638 : #include "../../util/tmpl/fd_sort.c"
1639 :
1640 : static inline void
1641 21 : fd_gui_try_insert_ephemeral_slot( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot, long now ) {
1642 21 : int already_present = 0;
1643 273 : for( ulong i=0UL; i<slots_sz; i++ ) {
1644 : /* evict any slots older than 4.8 seconds */
1645 252 : if( FD_UNLIKELY( slots[ i ].slot!=ULONG_MAX && now-slots[ i ].timestamp_arrival_nanos>4800000000L ) ) {
1646 72 : slots[ i ].slot = ULONG_MAX;
1647 72 : continue;
1648 72 : }
1649 :
1650 : /* if we've already seen this slot, just update the timestamp */
1651 180 : if( FD_UNLIKELY( slots[ i ].slot==slot ) ) {
1652 6 : slots[ i ].timestamp_arrival_nanos = now;
1653 6 : already_present = 1;
1654 6 : }
1655 180 : }
1656 21 : if( FD_LIKELY( already_present ) ) return;
1657 :
1658 : /* Insert the new slot number, evicting a smaller slot if necessary */
1659 15 : slots[ slots_sz ].timestamp_arrival_nanos = now;
1660 15 : slots[ slots_sz ].slot = slot;
1661 15 : fd_gui_ephemeral_slot_sort_insert( slots, slots_sz+1UL );
1662 15 : }
1663 :
1664 : static inline void
1665 0 : fd_gui_try_insert_run_length_slot( ulong * slots, ulong capacity, ulong * slots_sz, ulong slot ) {
1666 : /* catch up history is run-length encoded */
1667 0 : ulong range_idx = fd_sort_up_ulong_split( slots, *slots_sz, slot );
1668 0 : if( FD_UNLIKELY( range_idx<(*slots_sz)-1UL && range_idx%2UL==0UL && slots[ range_idx ]<=slot && slots[ range_idx+1UL ]>=slot ) ) return;
1669 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;
1670 :
1671 0 : slots[ (*slots_sz)++ ] = slot;
1672 0 : slots[ (*slots_sz)++ ] = slot;
1673 :
1674 0 : fd_sort_up_ulong_insert( slots, (*slots_sz) );
1675 :
1676 : /* colesce ranges */
1677 0 : ulong removed = 0UL;
1678 0 : for( ulong i=1UL; i<(*slots_sz)-1UL; i+=2 ) {
1679 0 : if( FD_UNLIKELY( slots[ i ]+1UL==slots[ i+1UL ] ) ) {
1680 0 : slots[ i ] = ULONG_MAX;
1681 0 : slots[ i+1UL ] = ULONG_MAX;
1682 0 : removed += 2;
1683 0 : }
1684 0 : }
1685 :
1686 0 : if( FD_UNLIKELY( (*slots_sz)>=removed+capacity-2UL && (*slots_sz)>=4UL ) ) {
1687 : /* We are at capacity, start coalescing earlier intervals. */
1688 0 : slots[ 1 ] = ULONG_MAX;
1689 0 : slots[ 2 ] = ULONG_MAX;
1690 0 : removed += 2;
1691 0 : }
1692 :
1693 0 : fd_sort_up_ulong_insert( slots, (*slots_sz) );
1694 0 : (*slots_sz) -= removed;
1695 0 : }
1696 :
1697 : void
1698 0 : fd_gui_handle_repair_slot( fd_gui_t * gui, ulong slot, long now ) {
1699 0 : int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot );
1700 0 : fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot, now );
1701 :
1702 0 : if( FD_UNLIKELY( !was_sent && slot!=gui->summary.slot_repair ) ) {
1703 0 : gui->summary.slot_repair = slot;
1704 :
1705 0 : fd_gui_printf_repair_slot( gui );
1706 0 : fd_http_server_ws_broadcast( gui->http );
1707 :
1708 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 );
1709 0 : }
1710 0 : }
1711 :
1712 : static void
1713 0 : fd_gui_sample_repair_slot( fd_gui_t * gui, long now ) {
1714 0 : ulong slot;
1715 :
1716 0 : ulong repair_tile_idx = fd_topo_find_tile( gui->topo, "repair", 0UL );
1717 0 : if( FD_UNLIKELY( repair_tile_idx==ULONG_MAX ) ) return;
1718 0 : fd_topo_tile_t const * repair = &gui->topo->tiles[ repair_tile_idx ];
1719 0 : volatile ulong const * repair_metrics = fd_metrics_tile( repair->metrics );
1720 0 : slot = repair_metrics[ MIDX( GAUGE, REPAIR, HIGHEST_DELIVERED_SLOT ) ];
1721 :
1722 0 : fd_gui_handle_repair_slot( gui, slot, now );
1723 0 : }
1724 :
1725 : static void
1726 0 : fd_gui_sample_catchup_slot( fd_gui_t * gui ) {
1727 0 : if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) return;
1728 0 : ulong repair_tile_idx = fd_topo_find_tile( gui->topo, "repair", 0UL );
1729 0 : if( FD_UNLIKELY( repair_tile_idx==ULONG_MAX ) ) return;
1730 0 : fd_topo_tile_t const * repair = &gui->topo->tiles[ repair_tile_idx ];
1731 0 : volatile ulong const * repair_metrics = fd_metrics_tile( repair->metrics );
1732 0 : ulong slot = repair_metrics[ MIDX( GAUGE, REPAIR, CATCHUP_SLOT ) ];
1733 0 : if( FD_LIKELY( !slot || ( gui->summary.slot_turbine!=ULONG_MAX && slot<=gui->summary.slot_turbine ) ) ) return;
1734 :
1735 0 : gui->summary.slot_turbine = slot;
1736 0 : fd_gui_printf_turbine_slot( gui );
1737 0 : fd_http_server_ws_broadcast( gui->http );
1738 0 : 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 );
1739 0 : }
1740 :
1741 : void
1742 6 : fd_gui_handle_repair_request( fd_gui_t * gui, ulong slot, ulong shred_idx, long tsorig, long now ) {
1743 6 : fd_gui_shred_event_append( gui, slot, shred_idx, FD_GUI_SLOT_SHRED_REPAIR_REQUEST, tsorig, now );
1744 6 : fd_gui_fec_event_append( gui, slot, shred_idx/FD_FEC_SHRED_CNT, FD_GUI_SLOT_SHRED_REPAIR_REQUEST, tsorig, now );
1745 6 : }
1746 :
1747 : static void
1748 0 : fd_gui_progcache_sample( fd_gui_t * gui ) {
1749 0 : fd_topo_t const * topo = gui->topo;
1750 :
1751 0 : ulong hits = 0UL;
1752 0 : ulong lookups = 0UL;
1753 :
1754 0 : for( ulong i=0UL; i<gui->summary.execrp_tile_cnt; i++ ) {
1755 0 : fd_topo_tile_t const * execrp = &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ];
1756 0 : volatile ulong const * metrics = fd_metrics_tile( execrp->metrics );
1757 :
1758 0 : lookups += metrics[ MIDX( COUNTER, EXECRP, PROGCACHE_LOOKED_UP ) ];
1759 0 : hits += fd_metrics_enum_group_sum( metrics+MIDX( COUNTER, EXECRP, PROGCACHE_HIT ), FD_METRICS_ENUM_PROGCACHE_CLASS_G_ALL_MASK );
1760 0 : }
1761 :
1762 : /* The execrp tile writes lookups before hits in metrics_write, so
1763 : reading lookups first then hits here means we may observe the
1764 : new hits before the new lookups, giving hits > lookups
1765 : momentarily. Clamp to maintain the invariant hits <= lookups. */
1766 :
1767 0 : hits = fd_ulong_min( hits, lookups );
1768 :
1769 0 : ulong ring_idx = gui->summary.progcache_history_idx % FD_GUI_PROGCACHE_HISTORY_CNT;
1770 0 : ulong oldest_hits = gui->summary.progcache_hits_history [ ring_idx ];
1771 0 : ulong oldest_lookups = gui->summary.progcache_lookups_history[ ring_idx ];
1772 :
1773 0 : gui->summary.progcache_hits_history [ ring_idx ] = hits;
1774 0 : gui->summary.progcache_lookups_history[ ring_idx ] = lookups;
1775 0 : gui->summary.progcache_history_idx = gui->summary.progcache_history_idx + 1UL;
1776 :
1777 0 : ulong hits_1min = hits - oldest_hits;
1778 0 : ulong lookups_1min = lookups - oldest_lookups;
1779 0 : hits_1min = fd_ulong_min( hits_1min, lookups_1min );
1780 :
1781 0 : gui->summary.progcache_hits_1min = hits_1min;
1782 0 : gui->summary.progcache_lookups_1min = lookups_1min;
1783 0 : }
1784 :
1785 : long
1786 0 : fd_gui_next_deadline( fd_gui_t const * gui ) {
1787 0 : long due = gui->next_sample_1sec;
1788 0 : due = fd_long_min( due, gui->next_sample_200millis );
1789 0 : due = fd_long_min( due, gui->next_sample_100millis );
1790 0 : due = fd_long_min( due, gui->next_sample_50millis );
1791 0 : due = fd_long_min( due, gui->next_sample_40millis );
1792 0 : due = fd_long_min( due, gui->next_sample_25millis );
1793 0 : due = fd_long_min( due, gui->next_sample_10millis );
1794 0 : return due+1L; /* the samplers fire on now>next */
1795 0 : }
1796 :
1797 : int
1798 0 : fd_gui_poll( fd_gui_t * gui, long now ) {
1799 0 : if( FD_LIKELY( now>gui->next_sample_1sec ) ) {
1800 0 : for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
1801 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_TIMERS, &gui->summary.tile_timers_packed[ i ] );
1802 0 : }
1803 :
1804 0 : gui->next_sample_1sec += 1000L*1000L*1000L;
1805 0 : return 1;
1806 0 : }
1807 :
1808 0 : if( FD_LIKELY( now>gui->next_sample_200millis ) ) {
1809 0 : fd_gui_estimated_tps_snap( gui );
1810 0 : fd_gui_printf_estimated_tps( gui );
1811 0 : fd_http_server_ws_broadcast( gui->http );
1812 :
1813 0 : if( FD_LIKELY( gui->leader_begin_slot<=gui->leader_end_slot ) ) {
1814 0 : for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
1815 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_TIMERS, &gui->summary.tile_timers_packed[ i ] );
1816 0 : }
1817 0 : }
1818 :
1819 0 : gui->next_sample_200millis += 200L*1000L*1000L;
1820 0 : return 1;
1821 0 : }
1822 :
1823 0 : if( FD_LIKELY( now>gui->next_sample_100millis ) ) {
1824 0 : fd_gui_txn_waterfall_snap( gui, gui->summary.txn_waterfall_current );
1825 0 : fd_gui_printf_live_txn_waterfall( gui, gui->summary.txn_waterfall_reference, gui->summary.txn_waterfall_current, 0UL /* TODO: REAL NEXT LEADER SLOT */ );
1826 0 : fd_http_server_ws_broadcast( gui->http );
1827 :
1828 0 : if( FD_LIKELY( gui->leader_begin_slot>gui->leader_end_slot ) ) {
1829 0 : gui->summary.txn_waterfall_current->sample_time_nanos = now;
1830 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TXN_WATERFALL, gui->summary.txn_waterfall_current );
1831 0 : }
1832 :
1833 0 : fd_gui_network_stats_snap( gui, gui->summary.network_stats_current );
1834 0 : fd_gui_network_rate_max_update( gui, now );
1835 0 : fd_gui_printf_live_network_metrics( gui, gui->summary.network_stats_current );
1836 0 : fd_http_server_ws_broadcast( gui->http );
1837 :
1838 0 : *gui->summary.tile_stats_reference = *gui->summary.tile_stats_current;
1839 0 : fd_gui_tile_stats_snap( gui, gui->summary.txn_waterfall_current, gui->summary.tile_stats_current, now );
1840 0 : fd_gui_printf_live_tile_stats( gui, gui->summary.tile_stats_reference, gui->summary.tile_stats_current );
1841 0 : fd_http_server_ws_broadcast( gui->http );
1842 :
1843 0 : {
1844 0 : fd_gui_progcache_sample( gui );
1845 0 : fd_gui_printf_live_program_cache( gui );
1846 0 : fd_http_server_ws_broadcast( gui->http );
1847 :
1848 0 : *gui->summary.accounts_stats_reference = *gui->summary.accounts_stats_current;
1849 0 : fd_gui_accounts_stats_snap( gui, gui->summary.accounts_stats_current );
1850 0 : fd_gui_accounts_stats_window_push( gui );
1851 0 : fd_gui_printf_accounts_stats( gui );
1852 0 : fd_http_server_ws_broadcast( gui->http );
1853 0 : gui->summary.accounts_stats_have_reference = 1;
1854 0 : }
1855 :
1856 0 : if( FD_UNLIKELY( gui->summary.boot_progress.phase!=FD_GUI_BOOT_PROGRESS_TYPE_RUNNING ) ) {
1857 0 : fd_gui_sample_catchup_slot( gui );
1858 0 : fd_gui_run_boot_progress( gui, now );
1859 0 : if( FD_UNLIKELY( memcmp( &gui->summary.boot_progress, &gui->summary.prev_boot_progress, sizeof(fd_gui_boot_progress_t) ) ) ) {
1860 0 : gui->summary.prev_boot_progress = gui->summary.boot_progress;
1861 0 : fd_gui_printf_boot_progress( gui );
1862 0 : fd_http_server_ws_broadcast( gui->http );
1863 0 : }
1864 0 : }
1865 :
1866 0 : ulong bundle_tile_idx = fd_topo_find_tile( gui->topo, "bundle", 0UL );
1867 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
1868 0 : volatile ulong const * bundle_metrics = fd_metrics_tile( gui->topo->tiles[ bundle_tile_idx ].metrics );
1869 0 : int cur_state = (int)bundle_metrics[ MIDX( GAUGE, BUNDLE, CONN_STATE ) ];
1870 0 : if( FD_UNLIKELY( cur_state != gui->block_engine.status ) ) {
1871 0 : gui->block_engine.status = cur_state;
1872 0 : fd_gui_printf_block_engine( gui );
1873 0 : fd_http_server_ws_broadcast( gui->http );
1874 0 : }
1875 0 : }
1876 :
1877 0 : fd_gui_printf_health( gui );
1878 0 : fd_http_server_ws_broadcast( gui->http );
1879 :
1880 0 : if( FD_UNLIKELY( gui->epoch.missed_vote_history_dirty!=ULONG_MAX ) ) {
1881 0 : fd_gui_printf_missed_vote_history( gui, gui->epoch.missed_vote_history_dirty );
1882 0 : fd_http_server_ws_broadcast( gui->http );
1883 0 : gui->epoch.missed_vote_history_dirty = ULONG_MAX;
1884 0 : }
1885 :
1886 0 : gui->next_sample_100millis += 100L*1000L*1000L;
1887 0 : return 1;
1888 0 : }
1889 :
1890 0 : if( FD_LIKELY( now>gui->next_sample_50millis ) ) {
1891 0 : fd_gui_shred_flush( gui, now );
1892 0 : if( FD_LIKELY( !fd_gui_shred_window_is_empty( gui, gui->shreds.broadcast_watermark_ns, now-1L ) ) ) {
1893 0 : fd_gui_printf_shred_updates( gui, gui->shreds.broadcast_watermark_ns, now-1L );
1894 0 : fd_http_server_ws_broadcast( gui->http );
1895 0 : }
1896 0 : gui->shreds.broadcast_watermark_ns = now;
1897 :
1898 : /* We get the repair slot from the sampled metric after catching up
1899 : and from incoming shred data before catchup. This makes the
1900 : catchup progress bar look complete while also keeping the
1901 : overview slots vis correct. TODO: do this properly using frags
1902 : sent over a link */
1903 0 : if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) fd_gui_sample_repair_slot( gui, now );
1904 :
1905 0 : if( FD_UNLIKELY( gui->snapsv.pending_cnt ) ) {
1906 0 : fd_gui_printf_snapshot_transfers( gui );
1907 0 : fd_http_server_ws_broadcast( gui->http );
1908 0 : gui->snapsv.pending_cnt = 0UL;
1909 0 : }
1910 :
1911 0 : gui->next_sample_50millis += 50L*1000L*1000L;
1912 0 : return 1;
1913 0 : }
1914 :
1915 0 : if( FD_LIKELY( now>gui->next_sample_40millis ) ) {
1916 0 : fd_gui_tile_timers_snap( gui, now );
1917 :
1918 0 : fd_gui_printf_live_tile_timers( gui );
1919 0 : fd_http_server_ws_broadcast( gui->http );
1920 :
1921 0 : fd_gui_printf_live_tile_metrics( gui );
1922 0 : fd_http_server_ws_broadcast( gui->http );
1923 :
1924 0 : if( FD_LIKELY( gui->leader_begin_slot>gui->leader_end_slot ) ) {
1925 0 : for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
1926 0 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_TILE_TIMERS, &gui->summary.tile_timers_packed[ i ] );
1927 0 : }
1928 0 : }
1929 :
1930 0 : gui->next_sample_40millis += 40L*1000L*1000L;
1931 0 : return 1;
1932 0 : }
1933 :
1934 0 : if( FD_LIKELY( now>gui->next_sample_25millis ) ) {
1935 0 : fd_gui_cpu_util_snap( gui, now );
1936 0 : gui->next_sample_25millis += 25L*1000L*1000L;
1937 0 : return 1;
1938 0 : }
1939 :
1940 0 : if( FD_LIKELY( now>gui->next_sample_10millis ) ) {
1941 0 : if( FD_UNLIKELY( gui->leader_begin_slot>gui->leader_end_slot ) ) fd_gui_scheduler_counts_snap( gui, now );
1942 :
1943 0 : fd_gui_printf_server_time_nanos( gui, now );
1944 0 : fd_http_server_ws_broadcast( gui->http );
1945 :
1946 : /* Lazy eviction must outpace ingest: ~1 ms of batches per tick */
1947 0 : long evict_end = fd_tickcount() + (long)( 1e6*gui->tick_per_ns );
1948 0 : for(;;) {
1949 0 : ulong archived = fd_gui_fec_archive( gui, 512UL );
1950 0 : int evicted = fd_gui_hist_evict_step( gui );
1951 0 : if( (!archived && !evicted) || fd_tickcount()>=evict_end ) break;
1952 0 : }
1953 :
1954 0 : gui->next_sample_10millis += 10L*1000L*1000L;
1955 0 : return 1;
1956 0 : }
1957 :
1958 0 : return 0;
1959 0 : }
1960 :
1961 : int
1962 : fd_gui_request_slot( fd_gui_t * gui,
1963 : ulong ws_conn_id,
1964 : ulong request_id,
1965 : char const * params,
1966 0 : ulong params_sz ) {
1967 0 : ulong _slot = 0UL; int has_slot = 0;
1968 0 : fd_jtok_t j[1]; fd_jtok_init( j, params, params_sz );
1969 0 : fd_jtok_str_t key;
1970 0 : fd_jtok_obj_enter( j );
1971 0 : while( fd_jtok_obj_next( j, &key ) ) {
1972 0 : if( fd_jtok_str_eq( &key, "slot" ) ) { fd_jtok_ulong( j, &_slot ); has_slot = 1; }
1973 0 : }
1974 0 : if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_slot ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1975 :
1976 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, _slot );
1977 0 : int known = slot && ( slot->skip!=FD_GUI_SKIP_STATUS_UNKNOWN || fd_gui_ag_slot_is_skip_notarized( gui, _slot ) );
1978 0 : if( FD_UNLIKELY( !known ) ) {
1979 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query", request_id );
1980 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1981 0 : return 0;
1982 0 : }
1983 :
1984 0 : fd_gui_printf_slot_request( gui, _slot, request_id, slot );
1985 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1986 0 : return 0;
1987 0 : }
1988 :
1989 : int
1990 : fd_gui_request_slot_transactions( fd_gui_t * gui,
1991 : ulong ws_conn_id,
1992 : ulong request_id,
1993 : char const * params,
1994 0 : ulong params_sz ) {
1995 0 : ulong _slot = 0UL; int has_slot = 0;
1996 0 : fd_jtok_t j[1]; fd_jtok_init( j, params, params_sz );
1997 0 : fd_jtok_str_t key;
1998 0 : fd_jtok_obj_enter( j );
1999 0 : while( fd_jtok_obj_next( j, &key ) ) {
2000 0 : if( fd_jtok_str_eq( &key, "slot" ) ) { fd_jtok_ulong( j, &_slot ); has_slot = 1; }
2001 0 : }
2002 0 : if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_slot ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2003 :
2004 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, _slot );
2005 0 : if( FD_UNLIKELY( !slot || slot->skip==FD_GUI_SKIP_STATUS_UNKNOWN ) ) {
2006 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query_transactions", request_id );
2007 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2008 0 : return 0;
2009 0 : }
2010 :
2011 0 : fd_gui_printf_slot_transactions_request( gui, _slot, request_id, slot );
2012 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2013 0 : return 0;
2014 0 : }
2015 :
2016 : int
2017 : fd_gui_request_slot_detailed( fd_gui_t * gui,
2018 : ulong ws_conn_id,
2019 : ulong request_id,
2020 : char const * params,
2021 0 : ulong params_sz ) {
2022 0 : ulong _slot = 0UL; int has_slot = 0;
2023 0 : fd_jtok_t j[1]; fd_jtok_init( j, params, params_sz );
2024 0 : fd_jtok_str_t key;
2025 0 : fd_jtok_obj_enter( j );
2026 0 : while( fd_jtok_obj_next( j, &key ) ) {
2027 0 : if( fd_jtok_str_eq( &key, "slot" ) ) { fd_jtok_ulong( j, &_slot ); has_slot = 1; }
2028 0 : }
2029 0 : if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_slot ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2030 :
2031 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, _slot );
2032 0 : int known = slot && ( slot->skip!=FD_GUI_SKIP_STATUS_UNKNOWN || fd_gui_ag_slot_is_skip_notarized( gui, _slot ) );
2033 0 : if( FD_UNLIKELY( !known ) ) {
2034 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query_detailed", request_id );
2035 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2036 0 : return 0;
2037 0 : }
2038 :
2039 0 : fd_gui_printf_slot_request_detailed( gui, _slot, request_id, slot );
2040 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2041 0 : return 0;
2042 0 : }
2043 :
2044 : static inline ulong
2045 0 : fd_gui_slot_duration( fd_gui_t * gui, fd_gui_slot_t const * cur ) {
2046 0 : if( FD_UNLIKELY( cur->skip==FD_GUI_SKIP_STATUS_FINALIZED || cur->completed_time==LONG_MAX ) ) return ULONG_MAX;
2047 0 : fd_gui_slot_t const * prev = fd_gui_slot_get_any( gui, cur->slot-1UL );
2048 0 : long parent_completed_time = LONG_MAX;
2049 0 : if( FD_LIKELY( prev && prev->skip!=FD_GUI_SKIP_STATUS_FINALIZED ) ) parent_completed_time = prev->completed_time;
2050 0 : if( FD_UNLIKELY( parent_completed_time==LONG_MAX ) ) return ULONG_MAX;
2051 :
2052 0 : return (ulong)(cur->completed_time - parent_completed_time);
2053 0 : }
2054 :
2055 : /* All rankings are initialized / reset to ULONG_MAX. These sentinels
2056 : sort AFTER non-sentinel ranking entries. Equal slots are sorted by
2057 : oldest slot AFTER. Otherwise sort by value according to ranking
2058 : type. */
2059 0 : #define RANKING_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 ) ) ) )
2060 :
2061 : /* ranking_insert places e in the sorted top FD_GUI_SLOT_RANKINGS_SZ of
2062 : arr, or drops it if it sorts after the last entry. */
2063 :
2064 : static inline void
2065 : ranking_insert( fd_gui_slot_ranking_t * arr,
2066 0 : fd_gui_slot_ranking_t e ) {
2067 0 : if( FD_LIKELY( !RANKING_BEFORE( e, arr[ FD_GUI_SLOT_RANKINGS_SZ-1UL ] ) ) ) return;
2068 0 : ulong i = FD_GUI_SLOT_RANKINGS_SZ-1UL;
2069 0 : while( i && RANKING_BEFORE( e, arr[ i-1UL ] ) ) { arr[ i ] = arr[ i-1UL ]; i--; }
2070 0 : arr[ i ] = e;
2071 0 : }
2072 :
2073 : static inline void
2074 : fd_gui_try_insert_ranking( fd_gui_t * gui,
2075 : fd_gui_slot_rankings_t * rankings,
2076 0 : fd_gui_slot_t const * slot ) {
2077 0 : #define TRY_INSERT_SLOT( ranking_name, ranking_slot, ranking_value ) \
2078 0 : do { \
2079 0 : ranking_insert( rankings->FD_CONCAT2(largest_, ranking_name), (fd_gui_slot_ranking_t){ .slot = (ranking_slot), .value = (ranking_value), .type = FD_GUI_SLOT_RANKING_TYPE_DESC } ); \
2080 0 : ranking_insert( rankings->FD_CONCAT2(smallest_, ranking_name), (fd_gui_slot_ranking_t){ .slot = (ranking_slot), .value = (ranking_value), .type = FD_GUI_SLOT_RANKING_TYPE_ASC } ); \
2081 0 : } while (0)
2082 :
2083 0 : if( slot->skip==FD_GUI_SKIP_STATUS_FINALIZED ) {
2084 0 : TRY_INSERT_SLOT( skipped, slot->slot, slot->slot );
2085 0 : return;
2086 0 : }
2087 :
2088 0 : ulong dur = fd_gui_slot_duration( gui, slot );
2089 0 : if( FD_LIKELY( dur!=ULONG_MAX ) ) TRY_INSERT_SLOT( duration, slot->slot, dur );
2090 0 : if( FD_LIKELY( slot->tips!=ULONG_MAX ) ) TRY_INSERT_SLOT( tips, slot->slot, slot->tips );
2091 0 : if( FD_LIKELY( slot->priority_fee!=ULONG_MAX && slot->transaction_fee!=ULONG_MAX ) ) {
2092 0 : ulong fees = slot->priority_fee + slot->transaction_fee;
2093 0 : TRY_INSERT_SLOT( fees, slot->slot, fees );
2094 0 : if( FD_LIKELY( slot->tips!=ULONG_MAX ) ) {
2095 0 : ulong rewards = slot->tips + fees;
2096 0 : TRY_INSERT_SLOT( rewards, slot->slot, rewards );
2097 0 : TRY_INSERT_SLOT( rewards_per_cu, slot->slot, slot->compute_units==0UL ? 0UL : rewards / slot->compute_units );
2098 0 : }
2099 0 : }
2100 0 : TRY_INSERT_SLOT( compute_units, slot->slot, slot->compute_units );
2101 0 : #undef TRY_INSERT_SLOT
2102 0 : }
2103 :
2104 : static void
2105 0 : fd_gui_update_slot_rankings( fd_gui_t * gui ) {
2106 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) return;
2107 0 : ulong first_replay_slot = fd_gui_first_replay_slot( gui );
2108 0 : if( FD_UNLIKELY( first_replay_slot==ULONG_MAX ) ) return;
2109 0 : if( FD_UNLIKELY( gui->summary.slot_rooted==ULONG_MAX ) ) return;
2110 :
2111 0 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, gui->summary.slot_rooted );
2112 0 : if( FD_UNLIKELY( !epoch ) ) return;
2113 :
2114 : /* No new slots since the last update */
2115 0 : if( FD_UNLIKELY( epoch->rankings_slot>gui->summary.slot_rooted ) ) return;
2116 :
2117 : /* Slots before first_replay_slot are unavailable. */
2118 0 : epoch->rankings_slot = fd_ulong_max( epoch->rankings_slot, first_replay_slot );
2119 :
2120 : /* Update the rankings. Only look through slots we haven't already. */
2121 0 : for( ulong s = gui->summary.slot_rooted; s>=epoch->rankings_slot; s--) {
2122 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_canon_safe( gui, s );
2123 0 : if( FD_UNLIKELY( slot->skip==FD_GUI_SKIP_STATUS_UNKNOWN ) ) break;
2124 :
2125 0 : fd_gui_try_insert_ranking( gui, epoch->rankings, slot );
2126 0 : if( FD_UNLIKELY( slot->mine ) ) fd_gui_try_insert_ranking( gui, epoch->my_rankings, slot );
2127 0 : }
2128 :
2129 0 : epoch->rankings_slot = gui->summary.slot_rooted + 1UL;
2130 0 : }
2131 :
2132 : int
2133 : fd_gui_request_slot_rankings( fd_gui_t * gui,
2134 : ulong ws_conn_id,
2135 : ulong request_id,
2136 : char const * params,
2137 0 : ulong params_sz ) {
2138 0 : int mine = 0; int has_mine = 0;
2139 0 : fd_jtok_t j[1]; fd_jtok_init( j, params, params_sz );
2140 0 : fd_jtok_str_t key;
2141 0 : fd_jtok_obj_enter( j );
2142 0 : while( fd_jtok_obj_next( j, &key ) ) {
2143 0 : if( fd_jtok_str_eq( &key, "mine" ) ) { fd_jtok_bool( j, &mine ); has_mine = 1; }
2144 0 : }
2145 0 : if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_mine ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2146 :
2147 0 : fd_gui_update_slot_rankings( gui );
2148 0 : fd_gui_printf_slot_rankings_request( gui, request_id, mine );
2149 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2150 0 : return 0;
2151 0 : }
2152 :
2153 : /* fd_gui_jtok_parse_ns consumes a canonical nonnegative decimal string
2154 : into *out. Returns 0 on success, -1 for invalid values or values at
2155 : or above LONG_MAX. */
2156 :
2157 : static inline int
2158 : fd_gui_jtok_parse_ns( fd_jtok_t * j,
2159 204 : long * out ) {
2160 204 : char value[ 20UL ];
2161 204 : fd_jtok_cstr( j, value, sizeof(value) );
2162 204 : if( FD_UNLIKELY( fd_jtok_err( j ) ) ) return -1;
2163 :
2164 204 : ulong value_len = strlen( value );
2165 204 : if( FD_UNLIKELY( !value_len ) ) return -1;
2166 204 : if( FD_UNLIKELY( value_len>1UL && value[ 0 ]=='0' ) ) return -1;
2167 :
2168 1140 : for( ulong i=0UL; i<value_len; i++ ) {
2169 936 : if( FD_UNLIKELY( value[ i ]<'0' || value[ i ]>'9' ) ) return -1;
2170 936 : }
2171 :
2172 204 : long parsed = fd_cstr_to_long( value );
2173 204 : if( FD_UNLIKELY( parsed==LONG_MAX ) ) return -1;
2174 204 : *out = parsed;
2175 204 : return 0;
2176 204 : }
2177 :
2178 : static int
2179 : fd_gui_request_timeline( fd_gui_t * gui,
2180 : ulong ws_conn_id,
2181 : char const * key,
2182 : ulong id,
2183 : char const * params,
2184 102 : ulong params_sz ) {
2185 102 : long start_ns = 0L; int has_start = 0;
2186 102 : long end_ns = 0L; int has_end = 0;
2187 102 : char name[ 32UL ] = {0};
2188 102 : ulong tiles[ FD_TOPO_MAX_TILES ]; ulong tile_cnt = 0UL;
2189 102 : fd_jtok_t j[1]; fd_jtok_init( j, params, params_sz );
2190 102 : fd_jtok_str_t member;
2191 102 : fd_jtok_obj_enter( j );
2192 435 : while( fd_jtok_obj_next( j, &member ) ) {
2193 336 : if( fd_jtok_str_eq( &member, "start_ns" ) ) {
2194 102 : if( FD_UNLIKELY( fd_gui_jtok_parse_ns( j, &start_ns ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2195 102 : has_start = 1;
2196 234 : } else if( fd_jtok_str_eq( &member, "end_ns" ) ) {
2197 102 : if( FD_UNLIKELY( fd_gui_jtok_parse_ns( j, &end_ns ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2198 102 : has_end = 1;
2199 132 : } else if( fd_jtok_str_eq( &member, "granularity" ) ) {
2200 90 : fd_jtok_cstr( j, name, sizeof(name) );
2201 90 : } else if( fd_jtok_str_eq( &member, "tiles" ) ) {
2202 42 : fd_jtok_arr_enter( j );
2203 855 : while( fd_jtok_arr_next( j ) ) {
2204 816 : if( FD_UNLIKELY( tile_cnt>=FD_TOPO_MAX_TILES ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2205 813 : fd_jtok_ulong( j, &tiles[ tile_cnt++ ] );
2206 813 : }
2207 42 : }
2208 336 : }
2209 99 : if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_start || !has_end || end_ns<=start_ns ) ) {
2210 12 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2211 12 : }
2212 87 : int err;
2213 87 : if( !strcmp( key, "query_slots" ) ) {
2214 0 : err = fd_gui_printf_timeline_query_slots( gui, start_ns, end_ns, id );
2215 87 : } else if( !strcmp( key, "query_events" ) ) {
2216 0 : err = fd_gui_printf_timeline_query_events( gui, start_ns, end_ns, id );
2217 87 : } else if( !strcmp( key, "query_shreds" ) ) {
2218 0 : if( !strcmp( name, "shred" ) ) err = fd_gui_printf_timeline_query_shreds( gui, start_ns, end_ns, id );
2219 0 : else if( !strcmp( name, "fec" ) ) err = fd_gui_printf_timeline_query_fec_events( gui, start_ns, end_ns, id );
2220 0 : else return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2221 87 : } else {
2222 87 : ulong g = 0UL;
2223 1008 : while( g<FD_GUI_TIMELINE_GRANULARITY_CNT && strcmp( name, fd_gui_timeline_granularities[ g ].name ) ) g++;
2224 87 : if( FD_UNLIKELY( g==FD_GUI_TIMELINE_GRANULARITY_CNT ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2225 54 : int stored;
2226 54 : ulong merge_cnt;
2227 54 : if( FD_UNLIKELY( fd_gui_timeline_tier( key, g, &stored, &merge_cnt ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2228 42 : ulong ns = fd_gui_timeline_granularity_ns( g );
2229 42 : ulong first = (ulong)start_ns / ns;
2230 42 : ulong reference = first*ns;
2231 42 : ulong count = ((ulong)end_ns-1UL)/ns - first + 1UL;
2232 42 : if( FD_UNLIKELY( count>FD_GUI_TIMELINE_QUERY_MAX_BUCKETS || count*ns>=(ulong)LONG_MAX-reference ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2233 30 : if( !strcmp( key, "query_agg_cpu" ) ) err = fd_gui_printf_timeline_query_agg_cpu( gui, name, g, (long)reference, count, tiles, tile_cnt, id );
2234 24 : else err = fd_gui_printf_timeline_query_agg( gui, key, name, g, (long)reference, count, id );
2235 30 : }
2236 30 : if( FD_UNLIKELY( err ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2237 27 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2238 27 : return 0;
2239 27 : }
2240 :
2241 : void
2242 : fd_gui_ws_send_epochs( fd_gui_t * gui,
2243 0 : ulong ws_conn_id ) {
2244 0 : if( FD_UNLIKELY( gui->epoch.current_epoch==ULONG_MAX ) ) return;
2245 0 : for( ulong e=gui->epoch.current_epoch; e<=gui->epoch.current_epoch+1UL; e++ ) {
2246 0 : if( FD_LIKELY( fd_gui_epoch( gui, e ) ) ) {
2247 0 : fd_gui_printf_skip_rate( gui, e );
2248 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2249 0 : fd_gui_printf_epoch( gui, e );
2250 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2251 0 : }
2252 0 : }
2253 0 : }
2254 :
2255 : int
2256 : fd_gui_ws_message( fd_gui_t * gui,
2257 : ulong ws_conn_id,
2258 : uchar const * data,
2259 102 : ulong data_len ) {
2260 102 : ulong id = 0UL; int has_id = 0;
2261 102 : fd_jtok_str_t topic = {0};
2262 102 : fd_jtok_str_t key = {0};
2263 102 : char const * params = NULL;
2264 102 : ulong params_sz = 0UL;
2265 :
2266 102 : fd_jtok_t j[1]; fd_jtok_init( j, data, data_len );
2267 102 : fd_jtok_str_t member;
2268 102 : fd_jtok_obj_enter( j );
2269 510 : while( fd_jtok_obj_next( j, &member ) ) {
2270 408 : if( fd_jtok_str_eq( &member, "id" ) ) { fd_jtok_ulong( j, &id ); has_id = 1; }
2271 306 : else if( fd_jtok_str_eq( &member, "topic" ) ) fd_jtok_str( j, &topic );
2272 204 : else if( fd_jtok_str_eq( &member, "key" ) ) fd_jtok_str( j, &key );
2273 102 : else if( fd_jtok_str_eq( &member, "params" ) ) {
2274 102 : if( FD_UNLIKELY( fd_jtok_peek( j )!=FD_JTOK_OBJ ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2275 102 : fd_jtok_raw( j, ¶ms, ¶ms_sz );
2276 102 : }
2277 408 : }
2278 102 : if( FD_UNLIKELY( fd_jtok_fini( j ) || !has_id || !topic.ptr || !key.ptr ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2279 :
2280 102 : if( FD_LIKELY( fd_jtok_str_eq( &topic, "slot" ) && fd_jtok_str_eq( &key, "query" ) ) ) {
2281 0 : if( FD_UNLIKELY( !params ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2282 0 : return fd_gui_request_slot( gui, ws_conn_id, id, params, params_sz );
2283 102 : } else if( FD_LIKELY( fd_jtok_str_eq( &topic, "slot" ) && fd_jtok_str_eq( &key, "query_detailed" ) ) ) {
2284 0 : if( FD_UNLIKELY( !params ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2285 0 : return fd_gui_request_slot_detailed( gui, ws_conn_id, id, params, params_sz );
2286 102 : } else if( FD_LIKELY( fd_jtok_str_eq( &topic, "slot" ) && fd_jtok_str_eq( &key, "query_transactions" ) ) ) {
2287 0 : if( FD_UNLIKELY( !params ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2288 0 : return fd_gui_request_slot_transactions( gui, ws_conn_id, id, params, params_sz );
2289 102 : } else if( FD_LIKELY( fd_jtok_str_eq( &topic, "slot" ) && fd_jtok_str_eq( &key, "query_rankings" ) ) ) {
2290 0 : if( FD_UNLIKELY( !params ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2291 0 : return fd_gui_request_slot_rankings( gui, ws_conn_id, id, params, params_sz );
2292 102 : } else if( FD_LIKELY( fd_jtok_str_eq( &topic, "timeline" ) &&
2293 102 : (fd_jtok_str_eq( &key, "query_shreds" ) ||
2294 102 : fd_jtok_str_eq( &key, "query_slots" ) ||
2295 102 : fd_jtok_str_eq( &key, "query_events" ) ||
2296 102 : fd_jtok_str_eq( &key, "query_agg_slots" ) ||
2297 102 : fd_jtok_str_eq( &key, "query_agg_shreds" ) ||
2298 102 : fd_jtok_str_eq( &key, "query_agg_compute" ) ||
2299 102 : fd_jtok_str_eq( &key, "query_agg_revenue" ) ||
2300 102 : fd_jtok_str_eq( &key, "query_agg_txn" ) ||
2301 102 : fd_jtok_str_eq( &key, "query_agg_cpu" )) ) ) {
2302 102 : if( FD_UNLIKELY( !params ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2303 102 : char name[ 32UL ];
2304 102 : if( FD_UNLIKELY( fd_jtok_str_decode( &key, name, sizeof(name) )<0L ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
2305 102 : return fd_gui_request_timeline( gui, ws_conn_id, name, id, params, params_sz );
2306 102 : } else if( FD_LIKELY( fd_jtok_str_eq( &topic, "summary" ) && fd_jtok_str_eq( &key, "ping" ) ) ) {
2307 0 : fd_gui_printf_summary_ping( gui, id );
2308 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
2309 0 : return 0;
2310 0 : }
2311 :
2312 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_UNKNOWN_METHOD;
2313 102 : }
2314 :
2315 : static inline uchar
2316 18 : slot_get_skip_status( fd_gui_t * gui, ulong _slot ) {
2317 18 : ulong tower_slot = gui->summary.slot_tower;
2318 18 : if( FD_UNLIKELY( tower_slot==ULONG_MAX || _slot>=tower_slot ) ) return FD_GUI_SKIP_STATUS_UNKNOWN;
2319 :
2320 6 : ulong const max_consecutive_skips = gui->max_consecutive_skips;
2321 :
2322 : /* Find the nearest landed canonical descendant and walk its lineage
2323 : down to obtain positive skip proof. */
2324 6 : ulong anchor_slot = ULONG_MAX;
2325 6 : ulong anchor_bank_seq = ULONG_MAX;
2326 6 : ulong search_hi = fd_ulong_min( _slot+max_consecutive_skips, tower_slot );
2327 6 : for( ulong s=_slot+1UL; s<=search_hi; s++ ) {
2328 6 : fd_gui_hist_kv_slot_iter_t it[ 1 ];
2329 : /* Equivocation-safe */
2330 6 : for( fd_gui_hist_kv_iter_begin( gui, it, FD_GUI_HIST_SLOT, s ); it->rec; fd_gui_hist_kv_iter_next( it ) ) {
2331 6 : fd_gui_slot_t const * rec = (fd_gui_slot_t const *)it->rec;
2332 6 : if( FD_LIKELY( rec->skip==FD_GUI_SKIP_STATUS_NOT_SKIPPED ) ) {
2333 6 : anchor_slot = s;
2334 6 : anchor_bank_seq = it->bank_seq;
2335 6 : break;
2336 6 : }
2337 6 : }
2338 6 : if( FD_UNLIKELY( anchor_slot!=ULONG_MAX ) ) break;
2339 6 : }
2340 6 : if( FD_UNLIKELY( anchor_slot==ULONG_MAX ) ) return FD_GUI_SKIP_STATUS_UNKNOWN; /* no descendant found */
2341 :
2342 : /* Walk the canonical fork back up. */
2343 6 : ulong cur_slot = anchor_slot;
2344 6 : ulong cur_bank_seq = anchor_bank_seq;
2345 6 : for( ulong steps=0UL; steps<max_consecutive_skips; steps++ ) {
2346 6 : fd_gui_hist_slot_key_t key;
2347 6 : key.slot = cur_slot; key.bank_seq = cur_bank_seq;
2348 6 : fd_gui_slot_t const * cmeta = (fd_gui_slot_t const *)fd_gui_hist_kv_get( gui, FD_GUI_HIST_SLOT, &key );
2349 6 : if( FD_UNLIKELY( !cmeta ) ) return FD_GUI_SKIP_STATUS_UNKNOWN; /* lineage broken / aged out */
2350 :
2351 6 : ulong parent_slot = cmeta->parent_slot;
2352 6 : ulong parent_bank_seq = cmeta->parent_bank_seq;
2353 6 : if( FD_UNLIKELY( parent_slot==ULONG_MAX ) ) return FD_GUI_SKIP_STATUS_UNKNOWN; /* Couldn't find _slot */
2354 6 : if( FD_LIKELY( parent_slot==_slot ) ) return FD_GUI_SKIP_STATUS_NOT_SKIPPED; /* _slot is on this lineage */
2355 6 : if( FD_LIKELY( parent_slot< _slot ) ) return FD_GUI_SKIP_STATUS_FINALIZED; /* lineage steps over _slot: skipped */
2356 0 : cur_slot = parent_slot;
2357 0 : cur_bank_seq = parent_bank_seq;
2358 0 : }
2359 0 : return FD_GUI_SKIP_STATUS_UNKNOWN;
2360 6 : }
2361 :
2362 : fd_gui_slot_t *
2363 27 : fd_gui_slot_get_canon_safe( fd_gui_t * gui, ulong _slot ) {
2364 27 : fd_gui_slot_t * slot = fd_gui_slot_get_canon( gui, _slot );
2365 :
2366 27 : if( FD_LIKELY( slot ) ) {
2367 9 : return slot;
2368 18 : } else {
2369 18 : uchar level = FD_GUI_SLOT_LEVEL_COMPLETED;
2370 18 : if( FD_LIKELY( gui->summary.slot_rooted!=ULONG_MAX && _slot<gui->summary.slot_rooted ) ) level = FD_GUI_SLOT_LEVEL_ROOTED;
2371 :
2372 18 : *gui->skipped_scratch = (fd_gui_slot_t){
2373 18 : .slot = _slot,
2374 18 : .bank_seq = ULONG_MAX,
2375 18 : .parent_bank_seq = ULONG_MAX,
2376 18 : .parent_slot = ULONG_MAX,
2377 18 : .vote_slot = ULONG_MAX,
2378 18 : .completed_time = LONG_MAX,
2379 18 : .parent_completed_time = LONG_MAX,
2380 18 : .max_compute_units= UINT_MAX,
2381 18 : .mine = (uchar)(fd_gui_slot_is_mine( gui, _slot ) & 1),
2382 18 : .skip = slot_get_skip_status( gui, _slot ),
2383 18 : .level = level,
2384 18 : .compute_units = UINT_MAX,
2385 18 : .transaction_fee = ULONG_MAX,
2386 18 : .priority_fee = ULONG_MAX,
2387 18 : .tips = ULONG_MAX,
2388 18 : .shred_cnt = UINT_MAX,
2389 18 : .is_voter = FD_GUI_IS_VOTER_UNKNOWN,
2390 18 : .vote_rewarded = fd_gui_slot_vote_rewarded_state( gui, _slot ),
2391 18 : .vote_count = fd_gui_slot_vote_count( gui, _slot ),
2392 18 : .vote_success = UINT_MAX,
2393 18 : .vote_failed = UINT_MAX,
2394 18 : .nonvote_success = UINT_MAX,
2395 18 : .nonvote_failed = UINT_MAX,
2396 18 : };
2397 18 : fd_gui_slot_set_voter_state( gui->skipped_scratch, fd_gui_slot_voter_state( gui, _slot ) );
2398 18 : return gui->skipped_scratch;
2399 18 : }
2400 27 : }
2401 :
2402 : static void
2403 0 : fd_gui_update_boot_epoch_duration( fd_gui_t * gui ) {
2404 0 : ulong prev = gui->summary.boot_progress.boot_target_slot_duration_nanos;
2405 :
2406 0 : ulong slot = fd_gui_boot_snapshot_slot( gui );
2407 0 : if( FD_LIKELY( slot!=ULONG_MAX ) ) {
2408 0 : fd_gui_epoch_t const * epoch = fd_gui_get_epoch_by_slot( gui, slot );
2409 0 : if( FD_LIKELY( epoch && epoch->target_slot_duration_ns>0L ) ) {
2410 0 : gui->summary.boot_progress.boot_target_slot_duration_nanos = (ulong)epoch->target_slot_duration_ns;
2411 0 : }
2412 0 : }
2413 :
2414 0 : if( FD_UNLIKELY( prev!=gui->summary.boot_progress.boot_target_slot_duration_nanos ) ) {
2415 0 : gui->summary.prev_boot_progress = gui->summary.boot_progress;
2416 0 : fd_gui_printf_boot_progress( gui );
2417 0 : fd_http_server_ws_broadcast( gui->http );
2418 0 : }
2419 0 : }
2420 :
2421 : void
2422 : fd_gui_handle_epoch_info( fd_gui_t * gui,
2423 : fd_epoch_info_msg_t const * epoch_info,
2424 0 : long now ) {
2425 0 : FD_TEST( epoch_info->staked_vote_cnt<=MAX_STAKE_WEIGHTS );
2426 0 : FD_TEST( epoch_info->slot_cnt<=MAX_SLOTS_PER_EPOCH );
2427 0 : FD_TEST( epoch_info->staked_vote_cnt );
2428 :
2429 0 : if( FD_UNLIKELY( !gui->epoch.has_epoch_schedule ) ) {
2430 0 : gui->epoch.epoch_schedule = epoch_info->epoch_schedule;
2431 0 : gui->epoch.has_epoch_schedule = 1;
2432 0 : }
2433 :
2434 0 : fd_vote_stake_weight_t const * stake_weights = fd_epoch_info_msg_stake_weights( epoch_info );
2435 0 : fd_memcpy( gui->epoch.stakes_scratch, stake_weights, epoch_info->staked_vote_cnt*sizeof(fd_vote_stake_weight_t) );
2436 :
2437 0 : fd_epoch_leaders_t * lsched = fd_epoch_leaders_join( fd_epoch_leaders_new( gui->epoch.lsched_scratch,
2438 0 : epoch_info->epoch,
2439 0 : epoch_info->start_slot,
2440 0 : epoch_info->slot_cnt,
2441 0 : epoch_info->staked_vote_cnt,
2442 0 : gui->epoch.stakes_scratch,
2443 0 : fd_epoch_leaders_use_geo_aware( &epoch_info->features, &epoch_info->epoch_schedule, epoch_info->epoch ) ) );
2444 0 : FD_TEST( lsched );
2445 :
2446 0 : int created = 0;
2447 0 : fd_gui_epoch_t * epoch = fd_gui_epoch_get_or_create( gui, epoch_info->epoch, &created );
2448 0 : FD_TEST( epoch );
2449 :
2450 0 : if( FD_LIKELY( created ) ) {
2451 0 : epoch->epoch = epoch_info->epoch;
2452 0 : epoch->start_slot = epoch_info->start_slot;
2453 0 : epoch->slot_cnt = epoch_info->slot_cnt;
2454 0 : epoch->start_time = LONG_MAX;
2455 0 : epoch->end_time = LONG_MAX;
2456 0 : epoch->my_total_slots = 0UL;
2457 0 : epoch->my_skipped_slots = 0UL;
2458 0 : epoch->rankings_slot = epoch_info->start_slot;
2459 0 : epoch->timeline_slot_lo_idx = ULONG_MAX;
2460 0 : epoch->timeline_slot_hi_idx = ULONG_MAX;
2461 0 : epoch->timeline_slot_min_start_ns = LONG_MAX;
2462 0 : epoch->timeline_slot_max_end_ns = LONG_MIN;
2463 0 : memset( epoch->timeline_slot_state, 0, sizeof(epoch->timeline_slot_state) );
2464 0 : memset( epoch->timeline_slot_shred_cnt, 0xFF, sizeof(epoch->timeline_slot_shred_cnt) );
2465 0 : memset( epoch->rankings, (int)(UINT_MAX), sizeof(epoch->rankings) );
2466 0 : memset( epoch->my_rankings, (int)(UINT_MAX), sizeof(epoch->my_rankings) );
2467 0 : memset( epoch->is_voter, FD_GUI_IS_VOTER_UNKNOWN, sizeof(epoch->is_voter) );
2468 0 : memset( epoch->skipped, 0, sizeof(epoch->skipped) );
2469 0 : memset( epoch->vote_rewarded, FD_GUI_VOTE_REWARDED_UNKNOWN, sizeof(epoch->vote_rewarded) );
2470 0 : memset( epoch->vote_count, UCHAR_MAX, sizeof(epoch->vote_count) );
2471 0 : epoch->epoch_schedule = epoch_info->epoch_schedule;
2472 0 : epoch->pub_cnt = lsched->pub_cnt;
2473 0 : epoch->stakes_cnt = epoch_info->staked_vote_cnt;
2474 0 : fd_memcpy( epoch->pub, lsched->pub, epoch->pub_cnt*sizeof(fd_pubkey_t) );
2475 0 : fd_memcpy( epoch->sched, lsched->sched, fd_ulong_min( lsched->sched_cnt, FD_GUI_EPOCH_SCHED_CNT )*sizeof(uint) );
2476 0 : fd_memcpy( epoch->stakes, gui->epoch.stakes_scratch, epoch->stakes_cnt*sizeof(fd_vote_stake_weight_t) );
2477 0 : }
2478 :
2479 0 : epoch->target_slot_duration_ns = (long)epoch_info->ns_per_slot;
2480 :
2481 0 : fd_epoch_leaders_delete( fd_epoch_leaders_leave( lsched ) );
2482 :
2483 0 : if( FD_UNLIKELY( gui->epoch.current_epoch==ULONG_MAX ) ) {
2484 0 : gui->epoch.current_epoch = epoch_info->epoch;
2485 0 : } else {
2486 0 : gui->epoch.current_epoch = fd_ulong_max( gui->epoch.current_epoch, epoch_info->epoch>0UL ? epoch_info->epoch-1UL : 0UL );
2487 0 : }
2488 :
2489 0 : epoch->start_time = now;
2490 0 : for( ulong i=0UL; i<fd_ulong_min( fd_ulong_sat_sub( epoch_info->start_slot, 1UL ), MAX_SLOTS_PER_EPOCH ); i++ ) {
2491 0 : fd_gui_slot_t const * slot = fd_gui_slot_get_any( gui, epoch_info->start_slot-i );
2492 0 : if( FD_UNLIKELY( !slot ) ) break;
2493 0 : else if( FD_UNLIKELY( slot->skip==FD_GUI_SKIP_STATUS_FINALIZED ) ) continue;
2494 0 : epoch->start_time = slot->parent_completed_time;
2495 0 : break;
2496 0 : }
2497 :
2498 0 : fd_gui_update_boot_epoch_duration( gui );
2499 :
2500 0 : fd_gui_printf_epoch( gui, epoch_info->epoch );
2501 0 : fd_http_server_ws_broadcast( gui->http );
2502 0 : }
2503 :
2504 : void
2505 : fd_gui_handle_shred( fd_gui_t * gui,
2506 : ulong slot,
2507 : ulong shred_idx,
2508 : ulong fec_set_idx,
2509 : int is_turbine,
2510 : long tsorig,
2511 27 : long now ) {
2512 27 : int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot );
2513 27 : if( FD_LIKELY( is_turbine ) ) fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot, tsorig );
2514 :
2515 : /* If we haven't caught up yet, update repair slot using received
2516 : shreds. This is not technically correct, but close enough and will
2517 : make the progress bar look correct. */
2518 27 : if( FD_UNLIKELY( !is_turbine && gui->summary.slot_caught_up==ULONG_MAX ) ) fd_gui_handle_repair_slot( gui, slot, tsorig );
2519 :
2520 27 : if( FD_UNLIKELY( !was_sent && is_turbine && slot!=gui->summary.slot_turbine ) ) {
2521 15 : gui->summary.slot_turbine = slot;
2522 :
2523 15 : fd_gui_printf_turbine_slot( gui );
2524 15 : fd_http_server_ws_broadcast( gui->http );
2525 :
2526 15 : gui->turbine_slots[ slot % FD_GUI_TURBINE_RECV_TIMESTAMPS ].slot = slot;
2527 15 : gui->turbine_slots[ slot % FD_GUI_TURBINE_RECV_TIMESTAMPS ].timestamp = tsorig;
2528 :
2529 15 : ulong duration_sum = 0UL;
2530 15 : ulong slot_cnt = 0UL;
2531 :
2532 11265 : for( ulong i=0UL; i<FD_GUI_TURBINE_RECV_TIMESTAMPS; i++ ) {
2533 11250 : fd_gui_turbine_slot_t * cur = &gui->turbine_slots[ i ];
2534 11250 : fd_gui_turbine_slot_t * prev = &gui->turbine_slots[ (i+FD_GUI_TURBINE_RECV_TIMESTAMPS-1UL) % FD_GUI_TURBINE_RECV_TIMESTAMPS ];
2535 11250 : if( FD_UNLIKELY( cur->slot==ULONG_MAX || prev->slot==ULONG_MAX || cur->slot!=prev->slot+1UL ) ) continue;
2536 :
2537 0 : long slot_duration = cur->timestamp - prev->timestamp;
2538 0 : duration_sum += (ulong)fd_long_max( slot_duration, 0UL );
2539 0 : slot_cnt++;
2540 0 : }
2541 :
2542 15 : if( FD_LIKELY( slot_cnt>0 ) ) {
2543 0 : gui->summary.estimated_slot_duration_nanos = (ulong)(duration_sum / slot_cnt);
2544 0 : fd_gui_printf_estimated_slot_duration_nanos( gui );
2545 0 : fd_http_server_ws_broadcast( gui->http );
2546 0 : }
2547 :
2548 15 : 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 );
2549 15 : }
2550 :
2551 27 : uchar event = fd_uchar_if( is_turbine, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_TURBINE, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_REPAIR );
2552 27 : fd_gui_shred_event_append( gui, slot, shred_idx, event, tsorig, now );
2553 27 : fd_gui_fec_event_append( gui, slot, fec_set_idx/FD_FEC_SHRED_CNT, event, tsorig, now );
2554 27 : }
2555 :
2556 : void
2557 : fd_gui_handle_leader_fec( fd_gui_t * gui,
2558 : ulong slot,
2559 : ulong fec_shred_cnt,
2560 : int is_end_of_slot,
2561 : long tsorig,
2562 6 : long now ) {
2563 : /* Abandoned block detected */
2564 6 : if( FD_UNLIKELY( gui->shreds.leader_shred_slot!=slot ) ) {
2565 3 : gui->shreds.leader_shred_cnt = 0UL;
2566 3 : gui->shreds.leader_shred_slot = slot;
2567 3 : }
2568 :
2569 198 : for( ulong i=gui->shreds.leader_shred_cnt; i<gui->shreds.leader_shred_cnt+fec_shred_cnt; i++ ) {
2570 192 : fd_gui_shred_event_append( gui, slot, i, FD_GUI_SLOT_SHRED_SHRED_PUBLISHED, tsorig, now );
2571 : /* Every shred of a FEC set maps to the same FEC event. */
2572 192 : if( i==gui->shreds.leader_shred_cnt || !(i%FD_FEC_SHRED_CNT) ) {
2573 6 : fd_gui_fec_event_append( gui, slot, i/FD_FEC_SHRED_CNT, FD_GUI_SLOT_SHRED_SHRED_PUBLISHED, tsorig, now );
2574 6 : }
2575 192 : }
2576 6 : gui->shreds.leader_shred_cnt += fec_shred_cnt;
2577 6 : if( FD_UNLIKELY( is_end_of_slot ) ) gui->shreds.leader_shred_cnt = 0UL;
2578 6 : }
2579 :
2580 : void
2581 : fd_gui_handle_exec_txn_done( fd_gui_t * gui,
2582 : ulong slot,
2583 : ulong start_shred_idx,
2584 : ulong end_shred_idx,
2585 : long tsorig_ns FD_PARAM_UNUSED,
2586 : long tspub_ns,
2587 12000 : long now ) {
2588 : /* The frontend keeps the earliest exec done per shred: drop reports
2589 : that do not improve on the minimum seen so far. */
2590 12000 : ulong ring = slot%FD_GUI_EXEC_DONE_SLOT_CNT;
2591 12000 : long * ts = gui->exec_done.ts+ring*FD_SHRED_BLK_MAX;
2592 12000 : if( FD_UNLIKELY( gui->exec_done.slot[ ring ]!=slot ) ) {
2593 147 : gui->exec_done.slot[ ring ] = slot;
2594 2408595 : for( ulong i=0UL; i<FD_SHRED_BLK_MAX; i++ ) ts[ i ] = LONG_MAX;
2595 147 : }
2596 :
2597 12000 : ulong fec = ULONG_MAX;
2598 41553 : for( ulong i = start_shred_idx; i<end_shred_idx; i++ ) {
2599 : /*
2600 : We're leaving this state transition out due to its proximity to
2601 : FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE, but if we ever wanted
2602 : to send this data to the frontend we could.
2603 :
2604 : fd_gui_shred_event_append( gui, slot, i, FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_START, tsorig_ns, now );
2605 : */
2606 :
2607 29553 : if( FD_LIKELY( i<FD_SHRED_BLK_MAX ) ) {
2608 29553 : if( FD_LIKELY( tspub_ns>=ts[ i ] ) ) continue;
2609 10599 : ts[ i ] = tspub_ns;
2610 10599 : }
2611 10599 : fd_gui_shred_event_append( gui, slot, i, FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE, tspub_ns, now );
2612 : /* Every shred of a FEC set maps to the same FEC event, and all
2613 : carry the same timestamp, so one update per FEC set suffices. */
2614 10599 : if( fec!=i/FD_FEC_SHRED_CNT ) {
2615 5634 : fec = i/FD_FEC_SHRED_CNT;
2616 5634 : fd_gui_fec_event_append( gui, slot, fec, FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE, tspub_ns, now );
2617 5634 : }
2618 10599 : }
2619 12000 : }
2620 :
2621 : static void
2622 : fd_gui_timeline_root_block( fd_gui_t * gui,
2623 : fd_gui_slot_t const * c,
2624 : ulong prev_rooted,
2625 : long now );
2626 :
2627 : static void
2628 : fd_gui_persist_slot_skip( fd_gui_t * gui,
2629 : ulong slot,
2630 72 : ulong bank_seq ) {
2631 72 : fd_gui_hist_kv_slot_iter_t it[ 1 ];
2632 126 : for( fd_gui_hist_kv_iter_begin( gui, it, FD_GUI_HIST_SLOT, slot ); it->rec; fd_gui_hist_kv_iter_next( it ) ) {
2633 54 : ((fd_gui_slot_t *)it->rec)->skip = fd_uchar_if( it->bank_seq==bank_seq, FD_GUI_SKIP_STATUS_NOT_SKIPPED, FD_GUI_SKIP_STATUS_FINALIZED );
2634 54 : }
2635 72 : }
2636 :
2637 : void
2638 : fd_gui_handle_root_advanced( fd_gui_t * gui,
2639 : ulong _slot,
2640 : ulong bank_seq,
2641 15 : long now ) {
2642 15 : fd_gui_slot_t * root = fd_gui_slot_get( gui, _slot, bank_seq );
2643 15 : if( FD_UNLIKELY( !root ) ) return;
2644 :
2645 : /* Rooting only ever advances. */
2646 15 : if( FD_UNLIKELY( gui->summary.slot_rooted!=ULONG_MAX && _slot<=gui->summary.slot_rooted ) ) return;
2647 :
2648 15 : ulong prev_rooted = gui->summary.slot_rooted;
2649 :
2650 15 : gui->summary.slot_rooted = _slot;
2651 : /* Slots below the root can no longer change, so their FEC events can
2652 : be archived. Close one slot behind the root so events for older
2653 : slots still queued on other inputs (which are polled independently
2654 : of replay_out) are not dropped. */
2655 15 : fd_gui_event_closed_slot_wmark_advance( gui, fd_ulong_sat_sub( _slot, 1UL ) );
2656 15 : fd_gui_printf_root_slot( gui );
2657 15 : fd_http_server_ws_broadcast( gui->http );
2658 :
2659 48 : for( ulong cslot=_slot, cbank_seq=bank_seq; ; ) {
2660 48 : fd_gui_slot_t * c = fd_gui_slot_get( gui, cslot, cbank_seq );
2661 48 : if( FD_UNLIKELY( !c || c->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
2662 :
2663 42 : c->level = FD_GUI_SLOT_LEVEL_ROOTED;
2664 42 : fd_gui_persist_slot_skip( gui, cslot, cbank_seq );
2665 :
2666 42 : if( FD_UNLIKELY( c->finalization_kind==FD_GUI_AG_FINAL_NONE ) ) {
2667 42 : c->finalization_kind = FD_GUI_AG_FINAL_IMPLICIT;
2668 42 : }
2669 :
2670 42 : fd_gui_printf_slot( gui, cslot, c );
2671 42 : fd_http_server_ws_broadcast( gui->http );
2672 :
2673 42 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, cslot );
2674 42 : if( FD_LIKELY( epoch ) ) {
2675 42 : ulong cidx = cslot - epoch->start_slot;
2676 42 : if( FD_LIKELY( cidx<epoch->slot_cnt ) ) {
2677 42 : if( FD_UNLIKELY( epoch->is_voter[ cidx ]!=FD_GUI_IS_VOTER_UNKNOWN ) )
2678 0 : fd_gui_slot_set_voter_state( c, epoch->is_voter[ cidx ] );
2679 42 : epoch->is_voter[ cidx ] = c->is_voter;
2680 42 : epoch->vote_count[ cidx ] = c->vote_count;
2681 :
2682 : /* This slot is on the rooted fork, so it was not skipped. */
2683 42 : epoch->skipped[ cidx ] = 0;
2684 42 : }
2685 42 : }
2686 :
2687 42 : ulong pslot = c->parent_slot, pseq = c->parent_bank_seq;
2688 42 : fd_gui_slot_t cc = *c; /* the timeline write below can evict c */
2689 42 : if( FD_UNLIKELY( pslot==ULONG_MAX || pslot>=cslot ) ) break;
2690 :
2691 : /* Record and republish newly rooted skipped slots. */
2692 63 : for( ulong s=pslot+1UL; s<cslot; s++ ) {
2693 30 : if( FD_UNLIKELY( prev_rooted!=ULONG_MAX && s<=prev_rooted ) ) continue; /* already rooted earlier */
2694 :
2695 30 : fd_gui_persist_slot_skip( gui, s, ULONG_MAX );
2696 :
2697 30 : fd_gui_epoch_t * sepoch = fd_gui_get_epoch_by_slot( gui, s );
2698 30 : if( FD_LIKELY( sepoch ) ) {
2699 30 : ulong sidx = s - sepoch->start_slot;
2700 30 : if( FD_LIKELY( sidx<sepoch->slot_cnt ) ) sepoch->skipped[ sidx ] = 1;
2701 30 : }
2702 :
2703 30 : if( FD_UNLIKELY( prev_rooted==ULONG_MAX ) ) continue;
2704 :
2705 9 : fd_gui_slot_t const * skipped = fd_gui_slot_get_canon_safe( gui, s );
2706 9 : if( FD_UNLIKELY( skipped->skip!=FD_GUI_SKIP_STATUS_FINALIZED ) ) continue;
2707 0 : fd_gui_printf_slot( gui, s, skipped );
2708 0 : fd_http_server_ws_broadcast( gui->http );
2709 0 : }
2710 :
2711 33 : fd_gui_timeline_root_block( gui, &cc, prev_rooted, now );
2712 :
2713 33 : cslot = pslot; cbank_seq = pseq;
2714 33 : }
2715 15 : }
2716 :
2717 : static fd_gui_ag_slot_t *
2718 : fd_gui_ag_slot_entry( fd_gui_t * gui,
2719 57 : ulong slot ) {
2720 : /* TODO: correctly handle equivocating slots */
2721 57 : fd_gui_ag_slot_t * ent = &gui->ag.slot[ slot % gui->ag.slot_cnt ];
2722 57 : if( FD_UNLIKELY( ent->slot!=slot ) ) {
2723 24 : ent->slot = slot;
2724 24 : memset( ent->block_id.uc, 0, sizeof(fd_hash_t) );
2725 24 : ent->bank_seq = ULONG_MAX;
2726 24 : ent->notarization_kind = FD_GUI_AG_NOTAR_NONE;
2727 24 : ent->finalization_kind = FD_GUI_AG_FINAL_NONE;
2728 24 : ent->skip = FD_GUI_SKIP_STATUS_UNKNOWN;
2729 24 : }
2730 57 : return ent;
2731 57 : }
2732 :
2733 : static int
2734 57 : fd_gui_ag_slot_has_proof( fd_gui_ag_slot_t const * ent ) {
2735 57 : return ent->notarization_kind!=FD_GUI_AG_NOTAR_NONE || ent->finalization_kind!=FD_GUI_AG_FINAL_NONE;
2736 57 : }
2737 :
2738 : static fd_gui_ag_slot_t *
2739 : fd_gui_ag_slot_for_certificate( fd_gui_t * gui,
2740 : ulong slot,
2741 0 : fd_hash_t const * block_id ) {
2742 0 : fd_gui_ag_slot_t * ent = fd_gui_ag_slot_entry( gui, slot );
2743 0 : if( FD_UNLIKELY( !fd_hash_eq( &ent->block_id, block_id ) ) ) {
2744 0 : ent->block_id = *block_id;
2745 0 : ent->bank_seq = ULONG_MAX;
2746 0 : ent->notarization_kind = FD_GUI_AG_NOTAR_NONE;
2747 0 : ent->finalization_kind = FD_GUI_AG_FINAL_NONE;
2748 0 : }
2749 0 : return ent;
2750 0 : }
2751 :
2752 : static void
2753 : fd_gui_ag_slot_publish( fd_gui_t * gui,
2754 57 : fd_gui_ag_slot_t const * ent ) {
2755 57 : if( FD_UNLIKELY( ent->bank_seq==ULONG_MAX ) ) return; /* not replayed yet, applied when it is */
2756 :
2757 57 : fd_gui_slot_t * slot = fd_gui_slot_get( gui, ent->slot, ent->bank_seq );
2758 57 : if( FD_UNLIKELY( !slot ) ) return;
2759 :
2760 57 : uchar notar = fd_uchar_if( ent->notarization_kind>slot->notarization_kind, ent->notarization_kind, slot->notarization_kind );
2761 57 : uchar final = fd_uchar_if( ent->finalization_kind>slot->finalization_kind, ent->finalization_kind, slot->finalization_kind );
2762 57 : uchar level = slot->level;
2763 :
2764 : /* Increase confirmation, but don't root yet since that's handled by
2765 : fd_gui_handle_root_advanced. */
2766 57 : if( FD_LIKELY( notar!=FD_GUI_AG_NOTAR_NONE || final!=FD_GUI_AG_FINAL_NONE ) ) {
2767 0 : level = fd_uchar_if( level<FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED, FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED, level );
2768 0 : }
2769 :
2770 57 : if( FD_LIKELY( notar==slot->notarization_kind && final==slot->finalization_kind && level==slot->level ) ) return;
2771 :
2772 0 : slot->notarization_kind = notar;
2773 0 : slot->finalization_kind = final;
2774 0 : slot->level = level;
2775 :
2776 0 : fd_gui_slot_t * canon = fd_gui_slot_get_canon( gui, ent->slot );
2777 0 : fd_gui_printf_slot( gui, ent->slot, fd_ptr_if( !!canon, canon, slot ) );
2778 0 : fd_http_server_ws_broadcast( gui->http );
2779 0 : }
2780 :
2781 : static void
2782 : fd_gui_ag_update_notarized_slot( fd_gui_t * gui,
2783 0 : ulong slot ) {
2784 0 : if( FD_LIKELY( gui->summary.slot_notarized!=ULONG_MAX && slot<=gui->summary.slot_notarized ) ) return;
2785 :
2786 0 : gui->summary.slot_notarized = slot;
2787 0 : fd_gui_printf_notarized_slot( gui );
2788 0 : fd_http_server_ws_broadcast( gui->http );
2789 0 : }
2790 :
2791 : void
2792 : fd_gui_ag_register_block( fd_gui_t * gui,
2793 : ulong slot,
2794 : fd_hash_t const * block_id,
2795 57 : ulong bank_seq ) {
2796 57 : if( FD_UNLIKELY( !block_id ) ) return;
2797 :
2798 57 : fd_gui_ag_slot_t * ent = fd_gui_ag_slot_entry( gui, slot );
2799 57 : if( FD_UNLIKELY( fd_gui_ag_slot_has_proof( ent ) && !fd_hash_eq( &ent->block_id, block_id ) ) ) return;
2800 :
2801 57 : ent->block_id = *block_id;
2802 57 : ent->bank_seq = bank_seq;
2803 57 : fd_gui_ag_slot_publish( gui, ent );
2804 57 : }
2805 :
2806 : void
2807 : fd_gui_handle_ag_notarized( fd_gui_t * gui,
2808 : ulong slot,
2809 : fd_hash_t const * block_id,
2810 0 : uchar notarization_kind ) {
2811 0 : if( FD_UNLIKELY( !block_id ) ) return;
2812 :
2813 0 : fd_gui_ag_slot_t * ent = fd_gui_ag_slot_for_certificate( gui, slot, block_id );
2814 0 : ent->notarization_kind = fd_uchar_if( notarization_kind>ent->notarization_kind, notarization_kind, ent->notarization_kind );
2815 0 : fd_gui_ag_slot_publish( gui, ent );
2816 0 : fd_gui_ag_update_notarized_slot( gui, slot );
2817 0 : }
2818 :
2819 : void
2820 : fd_gui_handle_ag_finalized( fd_gui_t * gui,
2821 : ulong slot,
2822 : fd_hash_t const * block_id,
2823 0 : uchar finalization_kind ) {
2824 0 : if( FD_UNLIKELY( !block_id ) ) return;
2825 :
2826 0 : fd_gui_ag_slot_t * ent = fd_gui_ag_slot_for_certificate( gui, slot, block_id );
2827 0 : ent->finalization_kind = fd_uchar_if( finalization_kind>ent->finalization_kind, finalization_kind, ent->finalization_kind );
2828 :
2829 : /* Finalization implies regular notarization. */
2830 0 : ent->notarization_kind = FD_GUI_AG_NOTAR_REGULAR;
2831 :
2832 0 : fd_gui_ag_slot_publish( gui, ent );
2833 0 : fd_gui_ag_update_notarized_slot( gui, slot );
2834 :
2835 0 : if( FD_LIKELY( gui->summary.slot_finalized==ULONG_MAX || slot>gui->summary.slot_finalized ) ) {
2836 0 : gui->summary.slot_finalized = slot;
2837 0 : fd_gui_printf_finalized_slot( gui );
2838 0 : fd_http_server_ws_broadcast( gui->http );
2839 0 : }
2840 0 : }
2841 :
2842 : void
2843 : fd_gui_handle_ag_skip_cert( fd_gui_t * gui,
2844 0 : ulong slot ) {
2845 :
2846 0 : fd_gui_ag_slot_t * ent = fd_gui_ag_slot_entry( gui, slot );
2847 0 : if( FD_LIKELY( ent->skip>=FD_GUI_SKIP_STATUS_NOTARIZED ) ) return;
2848 0 : ent->skip = FD_GUI_SKIP_STATUS_NOTARIZED;
2849 :
2850 0 : fd_gui_printf_slot( gui, slot, fd_gui_slot_get_canon_safe( gui, slot ) );
2851 0 : fd_http_server_ws_broadcast( gui->http );
2852 0 : fd_gui_ag_update_notarized_slot( gui, slot );
2853 0 : }
2854 :
2855 : void
2856 : fd_gui_handle_ag_leader( fd_gui_t * gui,
2857 0 : ulong parent_slot ) {
2858 0 : if( FD_UNLIKELY( gui->summary.slot_reset==parent_slot ) ) return;
2859 :
2860 0 : gui->summary.slot_reset = parent_slot;
2861 0 : fd_gui_printf_reset_slot( gui );
2862 0 : fd_http_server_ws_broadcast( gui->http );
2863 0 : }
2864 :
2865 : int
2866 : fd_gui_ag_slot_is_skip_notarized( fd_gui_t const * gui,
2867 9 : ulong slot ) {
2868 9 : if( FD_UNLIKELY( slot==ULONG_MAX ) ) return 0;
2869 :
2870 9 : fd_gui_ag_slot_t const * ent = &gui->ag.slot[ slot % gui->ag.slot_cnt ];
2871 9 : return ent->slot==slot && ent->skip>=FD_GUI_SKIP_STATUS_NOTARIZED;
2872 9 : }
2873 :
2874 : static void
2875 : fd_gui_handle_ag_reward( fd_gui_t * gui,
2876 : ulong slot,
2877 : int voted,
2878 57 : ushort voted_rank ) {
2879 :
2880 57 : uchar vote_rewarded = fd_uchar_if( !!voted, FD_GUI_VOTE_REWARDED_YES, FD_GUI_VOTE_REWARDED_NO );
2881 57 : uchar is_voter = fd_uchar_if( voted_rank!=USHORT_MAX, FD_GUI_IS_VOTER_YES, FD_GUI_IS_VOTER_NO );
2882 :
2883 57 : int epoch_changed = 0;
2884 57 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, slot );
2885 57 : if( FD_LIKELY( epoch ) ) {
2886 6 : ulong idx = slot - epoch->start_slot;
2887 6 : if( FD_LIKELY( idx<epoch->slot_cnt && ( epoch->vote_rewarded[ idx ]!=vote_rewarded || epoch->is_voter[ idx ]!=is_voter ) ) ) {
2888 3 : int was_missed = epoch->vote_rewarded[ idx ]==FD_GUI_VOTE_REWARDED_NO && epoch->is_voter[ idx ]==FD_GUI_IS_VOTER_YES;
2889 3 : epoch_changed = 1;
2890 3 : epoch->vote_rewarded[ idx ] = vote_rewarded;
2891 3 : epoch->is_voter[ idx ] = is_voter;
2892 3 : int is_missed = vote_rewarded==FD_GUI_VOTE_REWARDED_NO && is_voter==FD_GUI_IS_VOTER_YES;
2893 :
2894 3 : if( FD_UNLIKELY( was_missed!=is_missed ) ) gui->epoch.missed_vote_history_dirty = epoch->epoch; /* coalesced into one broadcast per poll */
2895 3 : }
2896 6 : }
2897 :
2898 57 : fd_gui_slot_t * rec = fd_gui_slot_get_canon( gui, slot );
2899 57 : if( FD_UNLIKELY( !rec ) ) {
2900 57 : if( FD_UNLIKELY( epoch_changed ) ) {
2901 3 : fd_gui_slot_t const * skipped = fd_gui_slot_get_canon_safe( gui, slot );
2902 3 : if( FD_LIKELY( skipped->skip==FD_GUI_SKIP_STATUS_FINALIZED || fd_gui_ag_slot_is_skip_notarized( gui, slot ) ) ) {
2903 0 : fd_gui_printf_slot( gui, slot, skipped );
2904 0 : fd_http_server_ws_broadcast( gui->http );
2905 0 : }
2906 3 : }
2907 57 : return;
2908 57 : }
2909 :
2910 0 : int changed = rec->vote_rewarded!=vote_rewarded || rec->is_voter!=is_voter || epoch_changed;
2911 0 : rec->vote_rewarded = vote_rewarded;
2912 0 : fd_gui_slot_set_voter_state( rec, is_voter );
2913 0 : if( FD_UNLIKELY( !changed ) ) return;
2914 0 : fd_gui_printf_slot( gui, slot, rec );
2915 0 : fd_http_server_ws_broadcast( gui->http );
2916 0 : }
2917 :
2918 : fd_gui_timeline_granularity_t const fd_gui_timeline_granularities[ FD_GUI_TIMELINE_GRANULARITY_CNT ] = {
2919 : { "25ms", 25000000UL },
2920 : { "50ms", 50000000UL },
2921 : { "100ms", 100000000UL },
2922 : { "250ms", 250000000UL },
2923 : { "500ms", 500000000UL },
2924 : { "1s", 1000000000UL },
2925 : { "2s", 2000000000UL },
2926 : { "4s", 4000000000UL },
2927 : { "8s", 8000000000UL },
2928 : { "15s", 15000000000UL },
2929 : { "30s", 30000000000UL },
2930 : { "1m", 60000000000UL },
2931 : { "2m", 120000000000UL },
2932 : { "4m", 240000000000UL },
2933 : { "8m", 480000000000UL },
2934 : { "15m", 900000000000UL },
2935 : { "30m", 1800000000000UL },
2936 : { "1h", 3600000000000UL },
2937 : { "2h", 7200000000000UL },
2938 : { "4h", 14400000000000UL },
2939 : { "8h", 28800000000000UL },
2940 : { "12h", 43200000000000UL },
2941 : { "1d", 86400000000000UL }
2942 : };
2943 :
2944 : ulong const fd_gui_timeline_stored_granularity_ns[ FD_GUI_TIMELINE_STORED_GRANULARITY_CNT ] = {
2945 : [ FD_GUI_TIMELINE_GRANULARITY_25MS ] = 25000000UL,
2946 : [ FD_GUI_TIMELINE_GRANULARITY_250MS ] = 250000000UL,
2947 : [ FD_GUI_TIMELINE_GRANULARITY_2S ] = 2000000000UL,
2948 : [ FD_GUI_TIMELINE_GRANULARITY_15S ] = 15000000000UL,
2949 : [ FD_GUI_TIMELINE_GRANULARITY_2M ] = 120000000000UL,
2950 : [ FD_GUI_TIMELINE_GRANULARITY_15M ] = 900000000000UL,
2951 : [ FD_GUI_TIMELINE_GRANULARITY_2H ] = 7200000000000UL,
2952 : [ FD_GUI_TIMELINE_GRANULARITY_12H ] = 43200000000000UL
2953 : };
2954 :
2955 : /* Stored tiers available to each aggregate query. The shortest tier
2956 : is the query's minimum granularity. FD_GUI_TIMELINE_TIERS_DAY are
2957 : the tiers held by the day record. */
2958 :
2959 420 : #define FD_GUI_TIMELINE_TIERS_DAY ( (1UL<<FD_GUI_TIMELINE_GRANULARITY_250MS) | (1UL<<FD_GUI_TIMELINE_GRANULARITY_2S) | \
2960 420 : (1UL<<FD_GUI_TIMELINE_GRANULARITY_15S) | (1UL<<FD_GUI_TIMELINE_GRANULARITY_2M) | \
2961 420 : (1UL<<FD_GUI_TIMELINE_GRANULARITY_15M) | (1UL<<FD_GUI_TIMELINE_GRANULARITY_2H) | \
2962 420 : (1UL<<FD_GUI_TIMELINE_GRANULARITY_12H) )
2963 :
2964 : static ulong
2965 423 : fd_gui_timeline_tiers( char const * key ) {
2966 423 : if( !strcmp( key, "query_agg_cpu" ) ) return FD_GUI_TIMELINE_TIERS_DAY | (1UL<<FD_GUI_TIMELINE_GRANULARITY_25MS);
2967 294 : if( !strcmp( key, "query_agg_compute" ) ||
2968 294 : !strcmp( key, "query_agg_revenue" ) ||
2969 294 : !strcmp( key, "query_agg_txn" ) ||
2970 294 : !strcmp( key, "query_agg_shreds" ) ||
2971 294 : !strcmp( key, "query_agg_slots" ) ) return FD_GUI_TIMELINE_TIERS_DAY;
2972 3 : return 0UL;
2973 294 : }
2974 :
2975 : int
2976 : fd_gui_timeline_tier( char const * key,
2977 : ulong g,
2978 : int * stored,
2979 426 : ulong * merge_cnt ) {
2980 426 : if( FD_UNLIKELY( g>=FD_GUI_TIMELINE_GRANULARITY_CNT ) ) return -1;
2981 423 : ulong tiers = fd_gui_timeline_tiers( key );
2982 423 : if( FD_UNLIKELY( !tiers ) ) return -1;
2983 420 : ulong ns = fd_gui_timeline_granularity_ns( g );
2984 420 : if( FD_UNLIKELY( ns<fd_gui_timeline_stored_granularity_ns[ fd_ulong_find_lsb( tiers ) ] ) ) return -1;
2985 2121 : for( int t=(int)FD_GUI_TIMELINE_STORED_GRANULARITY_CNT-1; t>=0; t-- ) {
2986 2121 : if( !(tiers & (1UL<<t)) ) continue;
2987 2121 : ulong tier_ns = fd_gui_timeline_stored_granularity_ns[ t ];
2988 2121 : if( tier_ns>ns || ns%tier_ns ) continue;
2989 396 : *stored = t;
2990 396 : *merge_cnt = ns/tier_ns;
2991 396 : return 0;
2992 2121 : }
2993 0 : return -1;
2994 396 : }
2995 :
2996 : /* fd_gui_timeline_day_end_ns returns the end timestamp of the calendar
2997 : day day_idx. */
2998 :
2999 : static inline long
3000 417 : fd_gui_timeline_day_end_ns( ulong day_idx ) {
3001 417 : if( FD_UNLIKELY( day_idx>=(ulong)LONG_MAX/(ulong)FD_GUI_TIMELINE_DAY_NS ) ) return LONG_MAX;
3002 417 : return (long)((day_idx+1UL)*(ulong)FD_GUI_TIMELINE_DAY_NS);
3003 417 : }
3004 :
3005 : fd_gui_timeline_day_t *
3006 : fd_gui_timeline_day_get( fd_gui_t * gui,
3007 348 : ulong day_idx ) {
3008 348 : long end_time_ns = fd_gui_timeline_day_end_ns( day_idx );
3009 348 : if( FD_UNLIKELY( !gui->db || !gui->hist || end_time_ns==LONG_MAX ) ) return NULL;
3010 :
3011 348 : fd_gui_hist_iter_t it;
3012 348 : if( FD_UNLIKELY( fd_gui_hist_range_begin( gui, &it, FD_GUI_HIST_TIMELINE_DAY, end_time_ns, end_time_ns, NULL, NULL ) ) ) return NULL;
3013 348 : fd_gui_timeline_day_t * day = fd_gui_hist_range_next( &it ) ? (fd_gui_timeline_day_t *)it.rec : NULL;
3014 348 : fd_gui_hist_range_end( &it );
3015 348 : return day;
3016 348 : }
3017 :
3018 : /* fd_gui_timeline_cur_day returns the index of the newest day record
3019 : in the store, or ULONG_MAX if there is none. */
3020 :
3021 : static ulong
3022 36 : fd_gui_timeline_cur_day( fd_gui_t * gui ) {
3023 36 : long first, last;
3024 36 : if( FD_UNLIKELY( !fd_gui_store_ts_live_timestamp_bounds( gui->db, FD_GUI_HIST_TIMELINE_DAY, &first, &last ) ) ) return ULONG_MAX;
3025 6 : return (ulong)last/(ulong)FD_GUI_TIMELINE_DAY_NS-1UL;
3026 36 : }
3027 :
3028 : /* fd_gui_timeline_day_create_ok returns 1 if a new day record may be
3029 : created for day_idx, 0 otherwise. */
3030 :
3031 : static inline int
3032 : fd_gui_timeline_day_create_ok( ulong day_idx,
3033 : ulong cur_day,
3034 51 : long now ) {
3035 51 : if( FD_UNLIKELY( fd_gui_timeline_day_end_ns( day_idx )==LONG_MAX ) ) return 0;
3036 51 : if( FD_UNLIKELY( now<0L || day_idx>(ulong)now/(ulong)FD_GUI_TIMELINE_DAY_NS+1UL ) ) return 0;
3037 51 : return cur_day==ULONG_MAX || day_idx>cur_day;
3038 51 : }
3039 :
3040 : /* fd_gui_timeline_day_create returns the record for day_idx, creating
3041 : an empty one if it does not exist yet. Returns NULL if the
3042 : day cannot be created. */
3043 :
3044 : static fd_gui_timeline_day_t *
3045 : fd_gui_timeline_day_create( fd_gui_t * gui,
3046 : ulong day_idx,
3047 18 : long now ) {
3048 18 : long end_time_ns = fd_gui_timeline_day_end_ns( day_idx );
3049 18 : if( FD_UNLIKELY( !gui->db || !gui->hist || end_time_ns==LONG_MAX ) ) return NULL;
3050 18 : if( FD_UNLIKELY( !fd_gui_timeline_day_create_ok( day_idx, ULONG_MAX, now ) ) ) return NULL;
3051 :
3052 18 : fd_gui_timeline_day_t * day = fd_gui_timeline_day_get( gui, day_idx );
3053 18 : if( day ) return day;
3054 18 : if( FD_UNLIKELY( !fd_gui_timeline_day_create_ok( day_idx, fd_gui_timeline_cur_day( gui ), now ) ) ) return NULL;
3055 :
3056 18 : fd_gui_timeline_day_t * seed = fd_gui_hist_ts_emplace( gui, FD_GUI_HIST_TIMELINE_DAY, end_time_ns );
3057 18 : if( FD_UNLIKELY( !seed ) ) return NULL;
3058 18 : memset( seed, 0xFF, sizeof(fd_gui_timeline_day_t) );
3059 :
3060 18 : seed->insert_time_ns = now;
3061 18 : seed->end_time_ns = end_time_ns;
3062 18 : return fd_gui_timeline_day_get( gui, day_idx );
3063 18 : }
3064 :
3065 : /* fd_gui_timeline_day_for_event returns the record for the day an event
3066 : belongs to, creating it if needed. Returns NULL if the day is unavailable. */
3067 :
3068 : static fd_gui_timeline_day_t *
3069 : fd_gui_timeline_day_for_event( fd_gui_t * gui,
3070 : ulong day_idx,
3071 93 : long now ) {
3072 93 : fd_gui_timeline_day_t * day = fd_gui_timeline_day_get( gui, day_idx );
3073 93 : if( FD_LIKELY( day ) ) return day;
3074 18 : if( FD_UNLIKELY( !gui->db || !gui->hist ) ) return NULL;
3075 18 : ulong cur_day = fd_gui_timeline_cur_day( gui );
3076 18 : if( FD_UNLIKELY( day_idx && (cur_day==ULONG_MAX || day_idx>cur_day+1UL) ) ) {
3077 0 : fd_gui_timeline_day_create( gui, day_idx-1UL, now );
3078 0 : }
3079 18 : return fd_gui_timeline_day_create( gui, day_idx, now );
3080 18 : }
3081 :
3082 : /* fd_gui_timeline_count_add adds 1 to field in the bucket containing
3083 : ts_ns, at every stored granularity of day. */
3084 :
3085 : static void
3086 : fd_gui_timeline_count_add( fd_gui_timeline_day_t * day,
3087 : int field,
3088 39 : long ts_ns ) {
3089 39 : ulong day_ns = (ulong)ts_ns % (ulong)FD_GUI_TIMELINE_DAY_NS;
3090 312 : for( int g=FD_GUI_TIMELINE_GRANULARITY_250MS; g<(int)FD_GUI_TIMELINE_STORED_GRANULARITY_CNT; g++ ) {
3091 273 : fd_gui_timeline_field_accum( day, g, field, day_ns/fd_gui_timeline_stored_granularity_ns[ g ], 1UL );
3092 273 : }
3093 39 : }
3094 :
3095 : /* fd_gui_timeline_root_block records the timeline interval of newly
3096 : rooted block c and of the skipped slots between c and its parent.
3097 : Skipped slots at or below prev_rooted were recorded by an earlier
3098 : root. c must be a copy: creating day records can evict slot
3099 : records. */
3100 :
3101 : static void
3102 : fd_gui_timeline_root_block( fd_gui_t * gui,
3103 : fd_gui_slot_t const * c,
3104 : ulong prev_rooted,
3105 33 : long now ) {
3106 33 : long ct = c->completed_time;
3107 33 : long pt = c->parent_completed_time;
3108 33 : if( FD_UNLIKELY( ct<0L || ct==LONG_MAX || c->parent_slot>=c->slot ) ) return;
3109 33 : int have_pt = pt>=0L && pt<=ct;
3110 33 : ulong count = c->slot - c->parent_slot; /* slots advanced: count-1 skipped, then c */
3111 33 : ulong dur = fd_ulong_if( have_pt, (ulong)(ct-pt), 0UL );
3112 :
3113 96 : for( ulong k=1UL; k<=count; k++ ) {
3114 63 : ulong s = c->parent_slot + k;
3115 63 : if( prev_rooted!=ULONG_MAX && s<=prev_rooted ) continue;
3116 63 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, s );
3117 63 : if( FD_UNLIKELY( !epoch || s<epoch->start_slot || s-epoch->start_slot>=fd_ulong_min( epoch->slot_cnt, MAX_SLOTS_PER_EPOCH ) ) ) continue;
3118 63 : ulong idx = s - epoch->start_slot;
3119 63 : uchar state = epoch->timeline_slot_state[ idx ];
3120 63 : uchar flags = (uchar)(FD_GUI_TIMELINE_SLOT_STATE_VALID | (state & FD_GUI_TIMELINE_SLOT_STATE_STARTED));
3121 63 : long first = (state & FD_GUI_TIMELINE_SLOT_STATE_STARTED) ? epoch->timeline_slot_first_shred_ns[ idx ] : LONG_MAX;
3122 :
3123 63 : if( k==count ) {
3124 : /* c landed: first shred arrival to replay completion. */
3125 33 : epoch->timeline_slot_start_ns[ idx ] = first;
3126 33 : epoch->timeline_slot_end_ns[ idx ] = ct;
3127 33 : epoch->timeline_slot_shred_cnt[ idx ] = c->shred_cnt;
3128 33 : epoch->timeline_slot_state[ idx ] = (uchar)(flags | (c->mine ? FD_GUI_TIMELINE_SLOT_STATE_MINE : 0U));
3129 33 : fd_gui_epoch_timeline_slot_note( epoch, idx );
3130 33 : continue;
3131 33 : }
3132 :
3133 : /* s was skipped. If a fork of it replayed, use the earliest
3134 : completion; otherwise give it an even share of the parent -> c
3135 : gap. */
3136 30 : long end_ns = LONG_MAX;
3137 30 : uint shred_cnt = UINT_MAX;
3138 30 : fd_gui_hist_kv_slot_iter_t it[ 1 ];
3139 42 : for( fd_gui_hist_kv_iter_begin( gui, it, FD_GUI_HIST_SLOT, s ); it->rec; fd_gui_hist_kv_iter_next( it ) ) {
3140 12 : fd_gui_slot_t const * fork = (fd_gui_slot_t const *)it->rec;
3141 12 : if( fork->completed_time>=0L && fork->completed_time<end_ns ) { end_ns = fork->completed_time; shred_cnt = fork->shred_cnt; }
3142 12 : }
3143 30 : int replayed = end_ns!=LONG_MAX;
3144 30 : long lo = pt + (long)(((uint128)(k-1UL)*dur)/count);
3145 30 : long hi = pt + (long)(((uint128)k*dur)/count);
3146 30 : epoch->timeline_slot_start_ns[ idx ] = replayed ? first : (have_pt ? lo : LONG_MAX);
3147 30 : epoch->timeline_slot_end_ns[ idx ] = replayed ? end_ns : (have_pt ? hi : LONG_MAX);
3148 30 : epoch->timeline_slot_shred_cnt[ idx ] = replayed ? shred_cnt : UINT_MAX;
3149 : /* Our block for s replayed but did not land. Uses the current
3150 : identity, like query_events. */
3151 30 : int mine = replayed && fd_gui_slot_is_mine( gui, s );
3152 30 : epoch->timeline_slot_state[ idx ] = (uchar)(flags | FD_GUI_TIMELINE_SLOT_STATE_SKIPPED | (mine ? FD_GUI_TIMELINE_SLOT_STATE_MINE : 0U));
3153 30 : fd_gui_epoch_timeline_slot_note( epoch, idx );
3154 :
3155 : /* Day aggregates last, since creating a day can evict records. A
3156 : skip with no parent time has no midpoint and is not counted. */
3157 30 : if( have_pt ) {
3158 30 : long mid = lo+(hi-lo)/2L;
3159 30 : fd_gui_timeline_day_t * day = fd_gui_timeline_day_for_event( gui, (ulong)mid/(ulong)FD_GUI_TIMELINE_DAY_NS, now );
3160 30 : if( day ) fd_gui_timeline_count_add( day, FD_GUI_TIMELINE_FIELD_SKIPPED, mid );
3161 30 : }
3162 30 : if( mine ) {
3163 6 : fd_gui_timeline_day_t * day = fd_gui_timeline_day_for_event( gui, (ulong)end_ns/(ulong)FD_GUI_TIMELINE_DAY_NS, now );
3164 6 : if( day ) fd_gui_timeline_count_add( day, FD_GUI_TIMELINE_FIELD_MINE_SKIPPED, end_ns );
3165 6 : }
3166 30 : }
3167 33 : }
3168 :
3169 :
3170 : void
3171 : fd_gui_timeline_handle_fec( fd_gui_t * gui,
3172 : ulong slot,
3173 : int published,
3174 : long timestamp_ns,
3175 : ulong turbine,
3176 : ulong repair,
3177 : ulong reconstructed,
3178 30 : long now ) {
3179 30 : if( FD_UNLIKELY( slot==ULONG_MAX || timestamp_ns<0L || timestamp_ns==LONG_MAX ||
3180 30 : turbine>2UL*FD_FEC_SHRED_CNT || repair>2UL*FD_FEC_SHRED_CNT ||
3181 30 : reconstructed>2UL*FD_FEC_SHRED_CNT ) ) return;
3182 12 : fd_gui_timeline_day_t * day = fd_gui_timeline_day_for_event( gui, (ulong)timestamp_ns/(ulong)FD_GUI_TIMELINE_DAY_NS, now );
3183 12 : if( FD_UNLIKELY( !day ) ) return;
3184 12 : ulong day_ns = (ulong)timestamp_ns % (ulong)FD_GUI_TIMELINE_DAY_NS;
3185 96 : for( int g=FD_GUI_TIMELINE_GRANULARITY_250MS; g<(int)FD_GUI_TIMELINE_STORED_GRANULARITY_CNT; g++ ) {
3186 84 : ulong idx = day_ns / fd_gui_timeline_stored_granularity_ns[ g ];
3187 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_START_SLOT, idx, slot );
3188 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_END_SLOT, idx, slot );
3189 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_TURBINE, idx, turbine );
3190 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_REPAIR, idx, repair );
3191 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_RECONSTRUCTED, idx, reconstructed );
3192 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_PUBLISHED, idx, published ? 2UL*FD_FEC_SHRED_CNT : 0UL );
3193 84 : }
3194 12 : }
3195 :
3196 : /* fd_gui_timeline_duration_credit credits one block interval to the
3197 : buckets of one calendar day. The block interval is [parent,parent+gap)
3198 : and advances slot_units/FD_GUI_TIMELINE_SLOT_UNIT slots. [lo,hi) is the
3199 : part of the interval in this day. */
3200 :
3201 : static void
3202 : fd_gui_timeline_duration_credit( fd_gui_timeline_day_t * day,
3203 : ulong day_start,
3204 : ulong lo,
3205 : ulong hi,
3206 : ulong parent,
3207 : ulong gap,
3208 33 : ulong slot_units ) {
3209 : /* If gap*slot_units does not fit into ulong, the function shifts the
3210 : time offsets and gap right by the same amount. */
3211 33 : int sh = 0;
3212 69 : while( FD_UNLIKELY( (gap>>sh)>ULONG_MAX/slot_units ) ) sh++;
3213 29808 : #define SLOTS_AT(t) ( (((t)-parent)>>sh)*slot_units / (gap>>sh) )
3214 264 : for( int g=FD_GUI_TIMELINE_GRANULARITY_250MS; g<(int)FD_GUI_TIMELINE_STORED_GRANULARITY_CNT; g++ ) {
3215 231 : ulong w = fd_gui_timeline_stored_granularity_ns[ g ];
3216 15135 : for( ulong idx=(lo-day_start)/w; day_start+idx*w<hi; idx++ ) {
3217 14904 : ulong b0 = fd_ulong_max( lo, day_start+idx*w );
3218 14904 : ulong b1 = fd_ulong_min( hi, day_start+(idx+1UL)*w );
3219 14904 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_DURATION_WALL, idx, b1-b0 );
3220 14904 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_DURATION_SLOTS, idx, SLOTS_AT( b1 )-SLOTS_AT( b0 ) );
3221 14904 : }
3222 231 : }
3223 33 : #undef SLOTS_AT
3224 33 : }
3225 :
3226 : /* fd_gui_timeline_slot_duration spreads the slot progress of a replayed
3227 : block over the wall time since the completion of its parent. If the
3228 : day of the block completion does not exist, the function creates it.
3229 : It credits earlier days in the interval only if the store keeps them.
3230 : If a block advances more than gui->max_consecutive_skips slots, the
3231 : function credits only gui->max_consecutive_skips slots. The buckets
3232 : then show a slot duration that is too long, but the value is
3233 : finite. */
3234 :
3235 : static void
3236 : fd_gui_timeline_slot_duration( fd_gui_t * gui,
3237 : fd_gui_slot_t const * slot,
3238 57 : long now ) {
3239 57 : if( FD_UNLIKELY( slot->slot==ULONG_MAX || slot->parent_slot>=slot->slot ||
3240 57 : slot->parent_completed_time<0L || slot->parent_completed_time==LONG_MAX ||
3241 57 : slot->completed_time==LONG_MAX || slot->completed_time<=slot->parent_completed_time ) ) return;
3242 30 : if( FD_UNLIKELY( !gui->db || !gui->hist ) ) return;
3243 : /* Store operations can evict slot. After this point, use only local
3244 : copies. */
3245 30 : ulong parent = (ulong)slot->parent_completed_time;
3246 30 : ulong completed = (ulong)slot->completed_time;
3247 30 : ulong slot_units = fd_ulong_min( slot->slot-slot->parent_slot, gui->max_consecutive_skips )*FD_GUI_TIMELINE_SLOT_UNIT;
3248 30 : ulong last_day = (completed-1UL)/(ulong)FD_GUI_TIMELINE_DAY_NS;
3249 30 : if( FD_UNLIKELY( !fd_gui_timeline_day_for_event( gui, last_day, now ) ) ) return;
3250 :
3251 : /* Do not look up days that are older than the oldest retained day. */
3252 30 : long first, last;
3253 30 : if( FD_UNLIKELY( !fd_gui_store_ts_live_timestamp_bounds( gui->db, FD_GUI_HIST_TIMELINE_DAY, &first, &last ) ) ) return;
3254 30 : ulong first_day = fd_ulong_max( parent/(ulong)FD_GUI_TIMELINE_DAY_NS, (ulong)first/(ulong)FD_GUI_TIMELINE_DAY_NS-1UL );
3255 63 : for( ulong d=first_day; d<=last_day; d++ ) {
3256 33 : fd_gui_timeline_day_t * day = fd_gui_timeline_day_get( gui, d );
3257 33 : if( FD_UNLIKELY( !day ) ) continue;
3258 33 : ulong day_start = d*(ulong)FD_GUI_TIMELINE_DAY_NS;
3259 33 : ulong lo = fd_ulong_max( parent, day_start );
3260 33 : ulong hi = fd_ulong_min( completed, day_start+(ulong)FD_GUI_TIMELINE_DAY_NS );
3261 33 : fd_gui_timeline_duration_credit( day, day_start, lo, hi, parent, completed-parent, slot_units );
3262 33 : }
3263 30 : }
3264 :
3265 : static void
3266 : fd_gui_timeline_handle_txn( fd_gui_t * gui,
3267 : ulong slot,
3268 : long timestamp_ns,
3269 : ulong compute_units,
3270 : ulong max_compute_units,
3271 : ulong transaction_fee,
3272 : ulong priority_fee,
3273 : ulong tips,
3274 : int txn_succeeded,
3275 12 : long now ) {
3276 12 : if( FD_UNLIKELY( slot==ULONG_MAX || timestamp_ns<0L || timestamp_ns==LONG_MAX ) ) return;
3277 12 : fd_gui_timeline_day_t * day = fd_gui_timeline_day_for_event( gui, (ulong)timestamp_ns/(ulong)FD_GUI_TIMELINE_DAY_NS, now );
3278 12 : if( FD_UNLIKELY( !day ) ) return;
3279 12 : ulong day_ns = (ulong)timestamp_ns % (ulong)FD_GUI_TIMELINE_DAY_NS;
3280 96 : for( int g=FD_GUI_TIMELINE_GRANULARITY_250MS; g<(int)FD_GUI_TIMELINE_STORED_GRANULARITY_CNT; g++ ) {
3281 84 : ulong idx = day_ns / fd_gui_timeline_stored_granularity_ns[ g ];
3282 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_START_SLOT, idx, slot );
3283 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_END_SLOT, idx, slot );
3284 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_COMPUTE_UNITS, idx, compute_units );
3285 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_MAX_COMPUTE, idx, max_compute_units );
3286 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_TXN_FEES, idx, transaction_fee );
3287 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_PRIO_FEES, idx, priority_fee );
3288 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_TIPS, idx, tips );
3289 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_NONVOTE_SUCCESS, idx, !!txn_succeeded );
3290 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_NONVOTE_FAILED, idx, !txn_succeeded );
3291 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_VOTE_SUCCESS, idx, 0UL );
3292 84 : fd_gui_timeline_field_accum( day, g, FD_GUI_TIMELINE_FIELD_VOTE_FAILED, idx, 0UL );
3293 84 : }
3294 12 : }
3295 :
3296 : static int
3297 : fd_gui_timeline_mine_add( fd_gui_t * gui,
3298 : long timestamp_ns,
3299 3 : long now ) {
3300 3 : if( FD_UNLIKELY( timestamp_ns<0L || timestamp_ns==LONG_MAX ) ) return 0;
3301 3 : fd_gui_timeline_day_t * day = fd_gui_timeline_day_for_event( gui, (ulong)timestamp_ns/(ulong)FD_GUI_TIMELINE_DAY_NS, now );
3302 3 : if( FD_UNLIKELY( !day ) ) return 0;
3303 3 : fd_gui_timeline_count_add( day, FD_GUI_TIMELINE_FIELD_MINE, timestamp_ns );
3304 3 : return 1;
3305 3 : }
3306 :
3307 : fd_gui_timeline_tile_day_t *
3308 : fd_gui_timeline_tile_day_get( fd_gui_t * gui,
3309 : ulong day_idx,
3310 1590 : ulong tile_idx ) {
3311 1590 : if( FD_UNLIKELY( !gui->db || !gui->hist ) ) return NULL;
3312 1590 : fd_gui_hist_tile_day_key_t key = { .day_idx=day_idx, .tile_idx=tile_idx };
3313 1590 : return fd_gui_hist_kv_get( gui, FD_GUI_HIST_TIMELINE_TILE_DAY, &key );
3314 1590 : }
3315 :
3316 : int
3317 : fd_gui_timeline_tile_day_bounds( fd_gui_t * gui,
3318 : ulong * lo_day,
3319 42 : ulong * hi_day ) {
3320 42 : if( FD_UNLIKELY( !gui->db || !gui->hist ) ) return 0;
3321 42 : ulong lo = ULONG_MAX;
3322 42 : ulong hi = 0UL;
3323 42 : fd_gui_store_kv_scan_t it;
3324 42 : fd_gui_store_kv_scan_begin( gui->db, &it, FD_GUI_HIST_TIMELINE_TILE_DAY );
3325 147 : while( fd_gui_store_kv_scan_next( &it ) ) {
3326 105 : fd_gui_hist_tile_day_key_t const * key = it.rec; /* records start with their key */
3327 105 : lo = fd_ulong_min( lo, key->day_idx );
3328 105 : hi = fd_ulong_max( hi, key->day_idx );
3329 105 : }
3330 42 : if( lo==ULONG_MAX ) return 0;
3331 39 : *lo_day = lo;
3332 39 : *hi_day = hi;
3333 39 : return 1;
3334 42 : }
3335 :
3336 : /* fd_gui_timeline_tile_day_create creates the empty CPU record of
3337 : tile_idx for day_idx, which must not exist yet, under the same day
3338 : rules as the timeline day records. Returns NULL if the day is
3339 : unavailable. The ring's base regions hold today's and yesterday's
3340 : record for every tile, so today's records are never evicted (see
3341 : fd_gui_hist_base_regions). */
3342 :
3343 : static fd_gui_timeline_tile_day_t *
3344 : fd_gui_timeline_tile_day_create( fd_gui_t * gui,
3345 : ulong day_idx,
3346 : ulong tile_idx,
3347 15 : long now ) {
3348 15 : if( FD_UNLIKELY( !gui->db || !gui->hist ) ) return NULL;
3349 15 : ulong * cur_day = &gui->cpu_util.cur_day;
3350 15 : if( FD_UNLIKELY( *cur_day==ULONG_MAX ) ) {
3351 3 : ulong lo;
3352 3 : if( !fd_gui_timeline_tile_day_bounds( gui, &lo, cur_day ) ) *cur_day = ULONG_MAX;
3353 3 : }
3354 : /* Other tiles may still join the newest day; earlier days are closed. */
3355 15 : ulong closed_day = *cur_day==ULONG_MAX || !*cur_day ? ULONG_MAX : *cur_day-1UL;
3356 15 : if( FD_UNLIKELY( !fd_gui_timeline_day_create_ok( day_idx, closed_day, now ) ) ) return NULL;
3357 :
3358 15 : fd_gui_hist_tile_day_key_t key = { .day_idx=day_idx, .tile_idx=tile_idx };
3359 15 : fd_gui_timeline_tile_day_t * rec = fd_gui_hist_kv_get_or_create( gui, FD_GUI_HIST_TIMELINE_TILE_DAY, &key );
3360 15 : if( FD_UNLIKELY( !rec ) ) return NULL;
3361 : /* Creation can evict records, but never the newly reserved one. The
3362 : store sets the key; every other byte is written once. */
3363 15 : rec->insert_time_ns = now;
3364 15 : memset( rec->util_25ms, FD_GUI_CPU_UTIL_UNKNOWN, sizeof(rec->util_25ms) );
3365 15 : memset( rec->sum_250MS, 0, sizeof(fd_gui_timeline_tile_day_t)-offsetof( fd_gui_timeline_tile_day_t, sum_250MS ) );
3366 15 : *cur_day = fd_ulong_max( *cur_day==ULONG_MAX ? 0UL : *cur_day, day_idx );
3367 15 : return rec;
3368 15 : }
3369 :
3370 : void
3371 492 : fd_gui_cpu_util_snap( fd_gui_t * gui, long now ) {
3372 492 : if( FD_UNLIKELY( now<FD_GUI_CPU_UTIL_SAMPLE_NS ) ) return;
3373 492 : ulong slot = (ulong)now/(ulong)FD_GUI_CPU_UTIL_SAMPLE_NS - 1UL;
3374 492 : if( FD_UNLIKELY( gui->cpu_util.last_slot!=ULONG_MAX && slot<=gui->cpu_util.last_slot ) ) return;
3375 492 : gui->cpu_util.last_slot = slot;
3376 :
3377 492 : ulong start_ns = slot*(ulong)FD_GUI_CPU_UTIL_SAMPLE_NS;
3378 492 : ulong day_idx = start_ns/(ulong)FD_GUI_TIMELINE_DAY_NS;
3379 492 : ulong day_ns = start_ns%(ulong)FD_GUI_TIMELINE_DAY_NS;
3380 492 : ulong create_cnt = 0UL;
3381 22140 : for( ulong i=0UL; i<gui->tile_cnt; i++ ) {
3382 21648 : fd_topo_tile_t const * tile = &gui->topo->tiles[ i ];
3383 21648 : if( FD_UNLIKELY( !tile->metrics ) ) continue;
3384 984 : volatile ulong const * live = fd_metrics_tile( tile->metrics ) + MIDX( COUNTER, TILE, REGIME_DURATION_NANOS );
3385 984 : ulong timers[ FD_METRICS_ENUM_TILE_REGIME_CNT ];
3386 10824 : for( ulong j=0UL; j<FD_METRICS_ENUM_TILE_REGIME_CNT; j++ ) timers[ j ] = live[ j ];
3387 984 : ulong total = fd_metrics_enum_group_sum( timers, (1UL<<FD_METRICS_ENUM_TILE_REGIME_CNT)-1UL );
3388 984 : ulong idle = fd_metrics_enum_group_sum( timers, FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK | FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK );
3389 984 : ulong dt = total - gui->cpu_util.total[ i ];
3390 984 : ulong di = idle - gui->cpu_util.idle [ i ];
3391 : /* A tile that has not published since the last sample keeps its
3392 : reference, so its next sample covers the whole gap. */
3393 984 : if( FD_UNLIKELY( !dt ) ) continue;
3394 741 : if( FD_UNLIKELY( !gui->cpu_util.total[ i ] ) ) {
3395 6 : gui->cpu_util.total[ i ] = total;
3396 6 : gui->cpu_util.idle [ i ] = idle;
3397 6 : continue;
3398 6 : }
3399 :
3400 : /* Creating a record writes several MiB, so a day rollover is
3401 : spread over ticks. */
3402 735 : fd_gui_timeline_tile_day_t * rec = fd_gui_timeline_tile_day_get( gui, day_idx, i );
3403 735 : if( FD_UNLIKELY( !rec ) ) {
3404 21 : if( FD_UNLIKELY( create_cnt>=FD_GUI_CPU_UTIL_CREATE_MAX ) ) continue;
3405 15 : create_cnt++;
3406 15 : rec = fd_gui_timeline_tile_day_create( gui, day_idx, i, now );
3407 15 : }
3408 729 : gui->cpu_util.total[ i ] = total;
3409 729 : gui->cpu_util.idle [ i ] = idle;
3410 729 : if( FD_UNLIKELY( !rec ) ) continue;
3411 729 : ulong busy = dt - fd_ulong_min( di, dt );
3412 729 : uchar util = (uchar)( ( busy*FD_GUI_CPU_UTIL_MAX + dt/2UL )/dt );
3413 729 : ulong idx = day_ns/(ulong)FD_GUI_CPU_UTIL_SAMPLE_NS;
3414 729 : if( FD_UNLIKELY( rec->util_25ms[ idx ]!=FD_GUI_CPU_UTIL_UNKNOWN ) ) continue; /* already sampled */
3415 729 : rec->util_25ms[ idx ] = util;
3416 729 : fd_gui_timeline_cpu_add( rec, day_ns, util );
3417 729 : }
3418 492 : }
3419 :
3420 : void
3421 : fd_gui_handle_genesis_hash( fd_gui_t * gui,
3422 0 : fd_hash_t const * msg ) {
3423 0 : FD_BASE58_ENCODE_32_BYTES( msg->uc, hash_cstr );
3424 0 : ulong cluster = fd_genesis_cluster_identify(hash_cstr);
3425 0 : char const * cluster_name = fd_genesis_cluster_name(cluster);
3426 :
3427 0 : if( FD_LIKELY( strcmp( gui->summary.cluster, cluster_name ) ) ) {
3428 0 : gui->summary.cluster = fd_genesis_cluster_name(cluster);
3429 0 : fd_gui_printf_cluster( gui );
3430 0 : fd_http_server_ws_broadcast( gui->http );
3431 0 : }
3432 0 : }
3433 :
3434 : void
3435 : fd_gui_handle_block_engine_update( fd_gui_t * gui,
3436 0 : fd_bundle_block_engine_update_t const * update ) {
3437 0 : gui->block_engine.has_block_engine = 1;
3438 :
3439 : /* copy strings and ensure null termination within bounds */
3440 0 : FD_TEST( fd_cstr_nlen( update->name, sizeof(gui->block_engine.name ) ) < sizeof(gui->block_engine.name ) );
3441 0 : FD_TEST( fd_cstr_nlen( update->url, sizeof(gui->block_engine.url ) ) < sizeof(gui->block_engine.url ) );
3442 0 : FD_TEST( fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) ) < sizeof(gui->block_engine.ip_cstr) );
3443 0 : ulong name_len = fd_cstr_nlen( update->name, sizeof(gui->block_engine.name ) );
3444 0 : ulong url_len = fd_cstr_nlen( update->url, sizeof(gui->block_engine.url ) );
3445 0 : ulong ip_cstr_len = fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) );
3446 0 : fd_memcpy( gui->block_engine.name, update->name, name_len+1UL );
3447 0 : fd_memcpy( gui->block_engine.url, update->url, url_len+1UL );
3448 0 : fd_memcpy( gui->block_engine.ip_cstr, update->ip_cstr, ip_cstr_len+1UL );
3449 :
3450 0 : fd_gui_printf_block_engine( gui );
3451 0 : fd_http_server_ws_broadcast( gui->http );
3452 0 : }
3453 :
3454 : void
3455 : fd_gui_handle_snapshot_update( fd_gui_t * gui,
3456 0 : fd_snapct_update_t const * msg ) {
3457 0 : FD_TEST( msg && fd_cstr_nlen( msg->read_path, 1 ) );
3458 :
3459 0 : ulong prev_slot = fd_gui_boot_snapshot_slot( gui );
3460 0 : if( msg->type==FD_SNAPCT_SNAPSHOT_TYPE_FULL ) {
3461 0 : gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].slot = ULONG_MAX;
3462 0 : gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].read_path[ 0 ] = '\0';
3463 0 : }
3464 :
3465 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 );
3466 :
3467 0 : char const * filename = strrchr( msg->read_path, '/' );
3468 :
3469 : /* Skip the '/' */
3470 0 : if( FD_LIKELY( filename ) ) filename++;
3471 0 : else filename = msg->read_path;
3472 :
3473 0 : if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_INCREMENTAL) {
3474 0 : ulong slot1, slot2;
3475 0 : if ( FD_LIKELY( sscanf( filename, "incremental-snapshot-%lu-%lu-", &slot1, &slot2 )==2 ) )
3476 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot2;
3477 0 : else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
3478 0 : } else if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_FULL) {
3479 0 : ulong slot1;
3480 0 : if ( FD_LIKELY( sscanf( filename, "snapshot-%lu-", &slot1 )==1 ) )
3481 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot1;
3482 0 : else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
3483 0 : }
3484 :
3485 0 : if( prev_slot!=fd_gui_boot_snapshot_slot( gui ) ) gui->summary.boot_progress.boot_target_slot_duration_nanos = ULONG_MAX;
3486 :
3487 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 );
3488 0 : fd_gui_update_boot_epoch_duration( gui );
3489 0 : }
3490 :
3491 : void
3492 : fd_gui_handle_snapsv_update( fd_gui_t * gui,
3493 : ulong sig,
3494 : fd_snapsv_msg_t const * msg,
3495 : ulong sz,
3496 : int eom,
3497 0 : long now ) {
3498 0 : if( FD_UNLIKELY( sig!=FD_SNAPSV_MSG_SNAP || sz!=sizeof(fd_snapsv_msg_snap_t) ) ) return;
3499 0 : if( FD_UNLIKELY( gui->snapsv.pending_cnt>=FD_GUI_SNAPSV_PENDING_MAX ) ) return;
3500 0 : fd_gui_snapsv_pending_t * pending = &gui->snapsv.pending[ gui->snapsv.pending_cnt++ ];
3501 0 : pending->msg = msg->snap;
3502 0 : pending->sample_time_nanos = now;
3503 0 : pending->closed = eom;
3504 0 : }
3505 :
3506 : void
3507 : fd_gui_stage_snapshot_manifest( fd_gui_t * gui,
3508 0 : fd_snapshot_manifest_t const * manifest ) {
3509 0 : ulong attempt = 0UL;
3510 0 : for( ulong i=0UL; i<manifest->hard_fork_cnt; i++ ) {
3511 0 : if( FD_UNLIKELY( manifest->hard_forks[ i ].slot==manifest->slot ) ) {
3512 0 : attempt = manifest->hard_forks[ i ].cnt;
3513 0 : break;
3514 0 : }
3515 0 : }
3516 0 : gui->summary.boot_progress.wfs_attempt = attempt;
3517 0 : }
3518 :
3519 : static void
3520 : fd_gui_broadcast_skip_rate( fd_gui_t * gui,
3521 60 : ulong epoch ) {
3522 60 : fd_gui_epoch_t const * rec = fd_gui_epoch( gui, epoch );
3523 60 : if( FD_UNLIKELY( !rec ) ) return;
3524 :
3525 9 : ulong slot = epoch % 2UL;
3526 9 : if( FD_LIKELY( gui->summary.skip_rate[ slot ].epoch ==epoch
3527 9 : && gui->summary.skip_rate[ slot ].skipped==rec->my_skipped_slots
3528 9 : && gui->summary.skip_rate[ slot ].total ==rec->my_total_slots ) ) return;
3529 :
3530 3 : gui->summary.skip_rate[ slot ].epoch = epoch;
3531 3 : gui->summary.skip_rate[ slot ].skipped = rec->my_skipped_slots;
3532 3 : gui->summary.skip_rate[ slot ].total = rec->my_total_slots;
3533 :
3534 3 : fd_gui_printf_skip_rate( gui, epoch );
3535 3 : fd_http_server_ws_broadcast( gui->http );
3536 3 : }
3537 :
3538 : /* Returns 1 if the frontier was updated, and 0 otherwise. */
3539 :
3540 : static int
3541 57 : handle_tower_slot( fd_gui_t * gui, ulong reset_slot, ulong reset_bank_seq, long now FD_PARAM_UNUSED ) {
3542 57 : FD_TEST( reset_slot!=ULONG_MAX );
3543 :
3544 57 : ulong prev_reset_slot = gui->summary.slot_tower;
3545 57 : ulong prev_reset_bank_seq = gui->summary.slot_tower_bank_seq;
3546 :
3547 : /* Alpenglow drives this from replay completion rather than a
3548 : consensus-derived reset slot, so the record is not guaranteed. */
3549 57 : if( FD_UNLIKELY( !fd_gui_slot_get( gui, reset_slot, reset_bank_seq ) ) ) return 0;
3550 :
3551 : /* reset_slot has not changed */
3552 57 : if( FD_UNLIKELY( prev_reset_slot!=ULONG_MAX && reset_slot==prev_reset_slot && reset_bank_seq==prev_reset_bank_seq ) ) return 0;
3553 :
3554 : /* Alpenglow can complete a descendant before one of its ancestors.
3555 : Keep advertising the highest completed block on that fork. */
3556 27 : if( FD_UNLIKELY( prev_reset_slot!=ULONG_MAX && fd_gui_slot_is_ancestor( gui, reset_slot, reset_bank_seq, prev_reset_slot, prev_reset_bank_seq ) ) ) return 0;
3557 :
3558 27 : gui->summary.slot_tower = reset_slot;
3559 27 : gui->summary.slot_tower_bank_seq = reset_bank_seq;
3560 :
3561 27 : fd_gui_printf_completed_slot( gui );
3562 27 : fd_http_server_ws_broadcast( gui->http );
3563 :
3564 : /* ensure a history exists */
3565 27 : if( FD_UNLIKELY( prev_reset_slot==ULONG_MAX || gui->summary.slot_rooted==ULONG_MAX ) ) return 1;
3566 :
3567 : /* Switch forks. */
3568 27 : fd_gui_slot_t const * oc = fd_gui_slot_get( gui, prev_reset_slot, prev_reset_bank_seq );
3569 27 : fd_gui_slot_t const * nc = fd_gui_slot_get( gui, reset_slot, reset_bank_seq );
3570 30 : for( ulong slot=fd_ulong_max( gui->summary.slot_tower, prev_reset_slot ); slot>gui->summary.slot_rooted; slot-- ) {
3571 3 : while( oc && oc->slot>slot ) oc = fd_gui_slot_parent_get( gui, oc );
3572 3 : while( nc && nc->slot>slot ) nc = fd_gui_slot_parent_get( gui, nc );
3573 3 : ulong obank = oc && oc->slot==slot ? oc->bank_seq : ULONG_MAX;
3574 3 : ulong nbank = nc && nc->slot==slot ? nc->bank_seq : ULONG_MAX;
3575 :
3576 3 : 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 );
3577 3 : 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 );
3578 3 : if( FD_LIKELY( skipped_old!=skipped_new ) ) {
3579 0 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, slot );
3580 0 : if( FD_LIKELY( epoch && fd_gui_slot_is_mine( gui, slot ) ) ) {
3581 0 : if( skipped_new ) epoch->my_skipped_slots = fd_ulong_sat_add( epoch->my_skipped_slots, 1UL );
3582 0 : else epoch->my_skipped_slots = fd_ulong_sat_sub( epoch->my_skipped_slots, 1UL );
3583 0 : }
3584 0 : }
3585 :
3586 : /* Publish new/changed slots */
3587 3 : if( FD_LIKELY( skipped_old!=skipped_new || slot>prev_reset_slot || obank!=nbank ) ) {
3588 3 : fd_gui_printf_slot( gui, slot, fd_gui_slot_get_canon_safe( gui, slot ) );
3589 3 : fd_http_server_ws_broadcast( gui->http );
3590 3 : }
3591 :
3592 : /* Persist skip status */
3593 3 : fd_gui_slot_t * canon = fd_gui_slot_get_canon( gui, slot );
3594 3 : ulong canon_bank_seq = canon ? canon->bank_seq : ULONG_MAX; /* canon, if any, IS slot */
3595 3 : fd_gui_hist_kv_slot_iter_t it[ 1 ];
3596 6 : for( fd_gui_hist_kv_iter_begin( gui, it, FD_GUI_HIST_SLOT, slot ); it->rec; fd_gui_hist_kv_iter_next( it ) ) {
3597 3 : ((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_FINALIZED );
3598 3 : }
3599 3 : }
3600 :
3601 81 : for( ulong e=gui->epoch.current_epoch; e<=gui->epoch.current_epoch+1UL; e++ ) fd_gui_broadcast_skip_rate( gui, e );
3602 27 : return 1;
3603 27 : }
3604 :
3605 : static inline void
3606 : set_vote_state( fd_gui_t * gui,
3607 0 : int vote_state ) {
3608 0 : if( FD_UNLIKELY( gui->summary.vote_state!=vote_state ) ) {
3609 0 : gui->summary.vote_state = vote_state;
3610 0 : fd_gui_printf_vote_state( gui );
3611 0 : fd_http_server_ws_broadcast( gui->http );
3612 0 : }
3613 0 : }
3614 :
3615 : static long
3616 : fd_gui_tick_to_nanos( fd_gui_t const * gui,
3617 : long now,
3618 : long tick_now,
3619 99 : long tick ) {
3620 99 : if( tick==LONG_MAX ) return LONG_MAX;
3621 63 : return fd_long_sat_add( now, (long)((double)fd_long_sat_sub( tick, tick_now )/gui->tick_per_ns) );
3622 99 : }
3623 :
3624 : static void
3625 : fd_gui_record_replay_txn( fd_gui_t * gui,
3626 15 : fd_gui_store_replay_txn_t const * rec ) {
3627 15 : int landed = !!rec->is_committable;
3628 15 : int fees_paid = landed && rec->error_code!=5U && rec->error_code!=6U;
3629 15 : int tips_paid = landed && !rec->error_code;
3630 15 : ulong txn_fee = fees_paid ? rec->transaction_fee : 0UL;
3631 15 : ulong prio_fee = fees_paid ? rec->priority_fee : 0UL;
3632 15 : ulong tips = tips_paid ? rec->tips : 0UL;
3633 :
3634 15 : if( FD_LIKELY( landed ) ) fd_gui_timeline_handle_txn( gui, rec->slot, rec->commit_end_ns, rec->compute_units_consumed,
3635 12 : rec->block_compute_unit_limit, txn_fee, prio_fee,
3636 12 : tips, !rec->error_code, rec->insert_time_ns );
3637 15 : fd_gui_hist_ts_append( gui, FD_GUI_HIST_REPLAY_TXN, rec );
3638 15 : }
3639 :
3640 : void
3641 : fd_gui_handle_replay_txn( fd_gui_t * gui,
3642 : fd_replay_txn_executed_t const * txn,
3643 15 : long now ) {
3644 15 : if( FD_UNLIKELY( !gui->db || !gui->hist || txn->tick_sigverify_done==LONG_MAX || txn->tick_commit_end==LONG_MAX ) ) return;
3645 12 : long tick_now = fd_tickcount();
3646 12 : ulong requested = fd_pack_compute_cost( TXN( txn->txn ), txn->txn->payload, NULL, NULL, NULL, NULL, NULL );
3647 12 : fd_gui_store_replay_txn_t rec = {
3648 12 : .insert_time_ns = now,
3649 12 : .completion_time_ns = fd_gui_tick_to_nanos( gui, now, tick_now, fd_long_max( txn->tick_sigverify_done, txn->tick_commit_end ) ),
3650 12 : .block_compute_unit_limit = txn->max_compute_units,
3651 12 : .slot = txn->slot,
3652 12 : .txn_idx = txn->index_in_slot,
3653 12 : .txn_exec_idx = txn->exec_tile_idx,
3654 12 : .txn_sigverify_exec_idx = txn->sigverify_exec_tile_idx,
3655 12 : .txn_start_shred_idx = txn->txn->start_shred_idx,
3656 12 : .txn_end_shred_idx = txn->txn->end_shred_idx,
3657 12 : .sigverify_start_ns = fd_gui_tick_to_nanos( gui, now, tick_now, txn->tick_sigverify_disp ),
3658 12 : .sigverify_end_ns = fd_gui_tick_to_nanos( gui, now, tick_now, txn->tick_sigverify_done ),
3659 12 : .load_start_ns = fd_gui_tick_to_nanos( gui, now, tick_now, txn->tick_load_start ),
3660 12 : .check_start_ns = fd_gui_tick_to_nanos( gui, now, tick_now, txn->tick_check_start ),
3661 12 : .exec_start_ns = fd_gui_tick_to_nanos( gui, now, tick_now, txn->tick_exec_start ),
3662 12 : .commit_start_ns = fd_gui_tick_to_nanos( gui, now, tick_now, txn->tick_commit_start ),
3663 12 : .commit_end_ns = fd_gui_tick_to_nanos( gui, now, tick_now, txn->tick_commit_end ),
3664 12 : .transaction_fee = txn->transaction_fee,
3665 12 : .priority_fee = txn->priority_fee,
3666 12 : .tips = txn->tips,
3667 12 : .compute_units_requested = (uint)requested,
3668 12 : .compute_units_consumed = txn->compute_units_consumed,
3669 12 : .error_code = (uint)(-(long)txn->txn_err),
3670 12 : .is_committable = (uchar)!!txn->is_committable,
3671 12 : .is_fees_only = (uchar)!!txn->is_fees_only,
3672 12 : };
3673 12 : fd_memcpy( rec.signature, txn->txn->payload+TXN( txn->txn )->signature_off, FD_TXN_SIGNATURE_SZ );
3674 12 : fd_gui_record_replay_txn( gui, &rec );
3675 12 : }
3676 :
3677 : void
3678 : fd_gui_handle_replay_update( fd_gui_t * gui,
3679 : fd_replay_slot_completed_t const * slot_completed,
3680 57 : long now ) {
3681 57 : fd_gui_shred_event_slot_complete( gui, slot_completed->slot, slot_completed->completion_time_nanos, now );
3682 :
3683 57 : if( FD_LIKELY( gui->summary.slot_storage!=slot_completed->storage_slot ) ) {
3684 0 : gui->summary.slot_storage = slot_completed->storage_slot;
3685 0 : fd_gui_printf_storage_slot( gui );
3686 0 : fd_http_server_ws_broadcast( gui->http );
3687 0 : }
3688 :
3689 57 : if( FD_UNLIKELY( slot_completed->identity_balance!=ULONG_MAX && gui->summary.identity_account_balance!=slot_completed->identity_balance ) ) {
3690 0 : gui->summary.identity_account_balance = slot_completed->identity_balance;
3691 :
3692 0 : fd_gui_printf_identity_balance( gui );
3693 0 : fd_http_server_ws_broadcast( gui->http );
3694 0 : }
3695 :
3696 57 : if( FD_UNLIKELY( gui->summary.boot_progress.catching_up_first_replay_slot==ULONG_MAX ) ) {
3697 0 : gui->summary.boot_progress.catching_up_first_replay_slot = slot_completed->slot;
3698 0 : }
3699 :
3700 57 : fd_gui_slot_t * slot = fd_gui_slot_get_or_create( gui,
3701 57 : slot_completed->slot,
3702 57 : slot_completed->parent_slot,
3703 57 : slot_completed->bank_seq,
3704 57 : slot_completed->parent_bank_seq );
3705 57 : if( FD_UNLIKELY( !slot ) ) return; /* record could not be created / was evicted */
3706 :
3707 57 : slot->completed_time = slot_completed->completion_time_nanos;
3708 57 : slot->parent_slot = slot_completed->parent_slot;
3709 57 : 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 );
3710 :
3711 57 : fd_gui_slot_t const * parent = fd_gui_slot_parent_get( gui, slot );
3712 57 : slot->parent_completed_time = parent ? parent->completed_time : LONG_MAX;
3713 :
3714 57 : fd_gui_timeline_slot_duration( gui, slot, now );
3715 57 : slot = fd_gui_slot_get( gui, slot_completed->slot, slot_completed->bank_seq );
3716 57 : if( FD_UNLIKELY( !slot ) ) return;
3717 :
3718 57 : ulong vote_slot;
3719 57 : if( FD_UNLIKELY( slot_completed->voted && slot_completed->slot>=FD_NUM_SLOTS_FOR_REWARD ) ) {
3720 0 : vote_slot = slot_completed->slot-FD_NUM_SLOTS_FOR_REWARD;
3721 57 : } else {
3722 57 : vote_slot = gui->summary.slot_voted; /* TODO: inherit from parent so it's fork-correct. Requires tracking identity changes to be correct. */
3723 57 : }
3724 :
3725 : /* A slot may already be notarized by the time we replay it. */
3726 57 : if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_COMPLETED ) ) slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
3727 57 : slot->vote_failed = fd_uint_if( slot_completed->vote_failed==ULONG_MAX, slot->vote_failed, (uint)slot_completed->vote_failed );
3728 57 : slot->vote_success = fd_uint_if( slot_completed->vote_success==ULONG_MAX, slot->vote_success, (uint)slot_completed->vote_success );
3729 57 : slot->nonvote_success = fd_uint_if( slot_completed->nonvote_success==ULONG_MAX, slot->nonvote_success, (uint)slot_completed->nonvote_success );
3730 57 : slot->nonvote_failed = fd_uint_if( slot_completed->nonvote_failed==ULONG_MAX, slot->nonvote_failed, (uint)slot_completed->nonvote_failed );
3731 :
3732 57 : slot->transaction_fee = slot_completed->transaction_fee;
3733 57 : slot->priority_fee = slot_completed->priority_fee;
3734 57 : slot->tips = slot_completed->tips;
3735 57 : slot->compute_units = fd_uint_if( slot_completed->cost_tracker.block_cost==ULONG_MAX, slot->compute_units, (uint)slot_completed->cost_tracker.block_cost );
3736 57 : slot->shred_cnt = fd_uint_if( slot_completed->shred_cnt==ULONG_MAX, slot->shred_cnt, (uint)slot_completed->shred_cnt );
3737 57 : slot->vote_slot = vote_slot;
3738 57 : slot->block_hash = slot_completed->block_hash;
3739 :
3740 57 : fd_gui_epoch_t * epoch = fd_gui_get_epoch_by_slot( gui, slot_completed->slot );
3741 57 : if( FD_UNLIKELY( epoch && slot_completed->slot==epoch->start_slot+epoch->slot_cnt-1UL ) ) epoch->end_time = slot->completed_time;
3742 :
3743 57 : if( FD_UNLIKELY( slot->mine ) ) {
3744 6 : fd_gui_leader_slot_t * lmeta = fd_gui_slot_leader_get_or_create( gui, slot_completed->slot, slot_completed->bank_seq );
3745 6 : if( FD_LIKELY( lmeta ) ) lmeta->block_hash = slot_completed->block_hash;
3746 :
3747 6 : fd_gui_epoch_t const * epoch = fd_gui_get_epoch_by_slot( gui, slot_completed->slot );
3748 6 : if( FD_LIKELY( epoch ) ) fd_gui_broadcast_skip_rate( gui, epoch->epoch );
3749 6 : }
3750 :
3751 57 : slot = fd_gui_slot_get( gui, slot_completed->slot, slot_completed->bank_seq );
3752 57 : if( FD_UNLIKELY( !slot ) ) return;
3753 57 : if( slot->mine && !slot->timeline_mine_accounted ) {
3754 3 : int accounted = fd_gui_timeline_mine_add( gui, slot->completed_time, now );
3755 3 : slot = fd_gui_slot_get( gui, slot_completed->slot, slot_completed->bank_seq );
3756 3 : if( FD_UNLIKELY( !slot ) ) return;
3757 3 : slot->timeline_mine_accounted = (uchar)!!accounted;
3758 3 : }
3759 :
3760 : /* Set skip status based on the current canonical fork. */
3761 57 : fd_gui_slot_t * canon = fd_gui_slot_get_canon( gui, slot_completed->slot );
3762 57 : slot->skip = fd_uchar_if( canon && canon->bank_seq==slot_completed->bank_seq, FD_GUI_SKIP_STATUS_NOT_SKIPPED, FD_GUI_SKIP_STATUS_UNKNOWN );
3763 :
3764 : /* vote_count is keyed by the cert slot. The epoch copy is written
3765 : only on rooting, so it never holds a non-canonical bank's count. */
3766 57 : slot->vote_count = slot_completed->vote_count;
3767 :
3768 : /* fixes race if we just sample right after replay's SLOT_COMPLETE */
3769 57 : if( FD_LIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) fd_gui_sample_repair_slot( gui, now );
3770 :
3771 : /* Update slot_turbine when we are leader. */
3772 57 : if( FD_UNLIKELY( gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && slot_completed->slot > gui->summary.slots_max_turbine[ 0 ].slot ) ) {
3773 0 : fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot_completed->slot, now );
3774 0 : }
3775 :
3776 57 : int slot_turbine_hist_full = gui->summary.slots_max_turbine[ FD_GUI_TURBINE_SLOT_HISTORY_SZ-1UL ].slot!=ULONG_MAX;
3777 57 : 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) ) ) {
3778 0 : gui->summary.slot_caught_up = slot_completed->slot + 4UL;
3779 :
3780 0 : fd_gui_printf_slot_caught_up( gui );
3781 0 : fd_http_server_ws_broadcast( gui->http );
3782 0 : }
3783 :
3784 57 : if( FD_UNLIKELY( slot_completed->voted && slot_completed->slot>=FD_NUM_SLOTS_FOR_REWARD && ( gui->summary.slot_voted==ULONG_MAX || vote_slot>gui->summary.slot_voted ) ) ) {
3785 0 : gui->summary.slot_voted = vote_slot;
3786 0 : fd_gui_printf_vote_slot( gui );
3787 0 : fd_http_server_ws_broadcast( gui->http );
3788 0 : }
3789 :
3790 : /* Bind this bank only to certificates for the same block. */
3791 57 : fd_gui_ag_register_block( gui, slot_completed->slot, &slot_completed->block_id, slot_completed->bank_seq );
3792 :
3793 57 : if( FD_UNLIKELY( slot_completed->vote_balance!=ULONG_MAX && gui->summary.vote_account_balance!=slot_completed->vote_balance ) ) {
3794 0 : gui->summary.vote_account_balance = slot_completed->vote_balance;
3795 0 : fd_gui_printf_vote_balance( gui );
3796 0 : fd_http_server_ws_broadcast( gui->http );
3797 0 : }
3798 57 : if( FD_UNLIKELY( slot_completed->vote_commission!=USHORT_MAX && gui->summary.vote_commission!=slot_completed->vote_commission ) ) {
3799 0 : gui->summary.vote_commission = slot_completed->vote_commission;
3800 0 : fd_gui_printf_vote_commission( gui );
3801 0 : fd_http_server_ws_broadcast( gui->http );
3802 0 : }
3803 :
3804 57 : if( FD_LIKELY( slot_completed->slot>=FD_NUM_SLOTS_FOR_REWARD ) ) {
3805 57 : fd_gui_handle_ag_reward( gui, slot_completed->slot-FD_NUM_SLOTS_FOR_REWARD, slot_completed->voted, slot_completed->voted_rank );
3806 57 : }
3807 :
3808 57 : int frontier_updated = handle_tower_slot( gui, slot_completed->slot, slot_completed->bank_seq, now );
3809 :
3810 57 : if( FD_LIKELY( gui->summary.is_voting && slot_completed->slot>=FD_NUM_SLOTS_FOR_REWARD ) ) {
3811 0 : if( FD_UNLIKELY( slot_completed->voted_rank==USHORT_MAX ) ) {
3812 0 : set_vote_state( gui, FD_GUI_VOTE_STATE_NON_VOTING );
3813 0 : } else {
3814 0 : ulong s = gui->summary.slot_tower;
3815 0 : ulong voted = gui->summary.slot_voted;
3816 0 : int current = voted!=ULONG_MAX && fd_int_if( s>=128UL, voted+128UL>s, voted>0UL );
3817 0 : set_vote_state( gui, fd_int_if( current, FD_GUI_VOTE_STATE_VOTING, FD_GUI_VOTE_STATE_DELINQUENT ) );
3818 0 : }
3819 0 : }
3820 :
3821 57 : if( FD_UNLIKELY( frontier_updated && gui->summary.slot_estimated!=slot_completed->slot ) ) {
3822 24 : gui->summary.slot_estimated = slot_completed->slot;
3823 24 : fd_gui_printf_estimated_slot( gui );
3824 24 : fd_http_server_ws_broadcast( gui->http );
3825 24 : }
3826 57 : }
3827 :
3828 : void
3829 : fd_gui_became_leader( fd_gui_t * gui,
3830 : ulong _slot,
3831 : long start_time_nanos,
3832 : long end_time_nanos,
3833 : ulong max_compute_units,
3834 : ulong max_microblocks,
3835 15 : ulong bank_seq ) {
3836 15 : gui->leader_begin_slot = fd_ulong_max( gui->leader_begin_slot, _slot );
3837 :
3838 15 : fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_or_create( gui, _slot, bank_seq );
3839 15 : if( FD_UNLIKELY( !lslot ) ) return;
3840 :
3841 15 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, start_time_nanos, lslot->leader_start_time );
3842 15 : lslot->leader_end_time = end_time_nanos;
3843 15 : lslot->max_microblocks = max_microblocks;
3844 15 : lslot->max_compute_units = max_compute_units;
3845 15 : if( FD_LIKELY( lslot->microblocks_upper_bound==UINT_MAX ) ) lslot->microblocks_upper_bound = (uint)max_microblocks;
3846 15 : }
3847 :
3848 : void
3849 : fd_gui_unbecame_leader( fd_gui_t * gui,
3850 : ulong _slot,
3851 21 : fd_done_packing_t const * done_packing ) {
3852 21 : gui->leader_end_slot = fd_ulong_max( gui->leader_end_slot, _slot ); /* may arrive before its became_leader */
3853 :
3854 21 : fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_any( gui, _slot );
3855 21 : if( FD_UNLIKELY( !lslot ) ) return;
3856 18 : lslot->microblocks_upper_bound = (uint)done_packing->microblocks_in_slot;
3857 18 : fd_memcpy( lslot->scheduler_stats, done_packing, sizeof(fd_done_packing_t) );
3858 18 : lslot->unbecame_leader = 1;
3859 :
3860 18 : if( FD_LIKELY( !lslot->has_waterfall ) ) {
3861 15 : gui->leader_slot_pending = lslot->slot;
3862 15 : gui->leader_bank_seq_pending = lslot->bank_seq;
3863 15 : }
3864 18 : }
3865 :
3866 : void
3867 : fd_gui_done_draining( fd_gui_t * gui,
3868 9 : long now ) {
3869 9 : if( FD_UNLIKELY( gui->leader_slot_pending==ULONG_MAX ) ) return;
3870 :
3871 6 : fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get( gui, gui->leader_slot_pending, gui->leader_bank_seq_pending );
3872 6 : gui->leader_slot_pending = ULONG_MAX;
3873 6 : gui->leader_bank_seq_pending = ULONG_MAX;
3874 6 : if( FD_UNLIKELY( !lslot || lslot->has_waterfall ) ) return;
3875 :
3876 6 : fd_gui_txn_waterfall_t waterfall[ 1 ];
3877 6 : fd_gui_txn_waterfall_snap( gui, waterfall );
3878 6 : waterfall->sample_time_nanos = now;
3879 :
3880 6 : fd_memcpy( lslot->waterfall_reference, gui->summary.txn_waterfall_reference, sizeof(fd_gui_txn_waterfall_t) );
3881 6 : fd_memcpy( lslot->waterfall, waterfall, sizeof(fd_gui_txn_waterfall_t) );
3882 6 : lslot->has_waterfall = 1;
3883 :
3884 6 : fd_memcpy( gui->summary.txn_waterfall_reference, waterfall, sizeof(fd_gui_txn_waterfall_t) );
3885 6 : }
3886 :
3887 : void
3888 : fd_gui_microblock_execution_begin( fd_gui_t * gui,
3889 : long tspub_ns,
3890 : ulong _slot,
3891 : fd_txn_e_t * txns,
3892 : ulong txn_cnt,
3893 : uint microblock_idx,
3894 : ulong pack_txn_idx,
3895 : ulong bank_seq,
3896 15 : long now ) {
3897 15 : fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_or_create( gui, _slot, bank_seq );
3898 15 : if( FD_UNLIKELY( !lslot ) ) return;
3899 :
3900 15 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, tspub_ns, lslot->leader_start_time );
3901 :
3902 30 : for( ulong i=0UL; i<txn_cnt; i++ ) {
3903 15 : fd_txn_p_t * txn_payload = txns[ i ].txnp;
3904 15 : fd_txn_t * txn = TXN( txn_payload );
3905 :
3906 15 : ulong sig_rewards = FD_PACK_FEE_PER_SIGNATURE * txn->signature_cnt;
3907 15 : ulong priority_rewards = ULONG_MAX;
3908 15 : ulong requested_execution_cus = ULONG_MAX;
3909 15 : ulong precompile_sigs = ULONG_MAX;
3910 15 : ulong requested_loaded_accounts_data_cost = ULONG_MAX;
3911 15 : ulong allocated_data = ULONG_MAX;
3912 15 : ulong cost_estimate = fd_pack_compute_cost( txn, txn_payload->payload, &requested_execution_cus, &priority_rewards, &precompile_sigs, &requested_loaded_accounts_data_cost, &allocated_data );
3913 15 : sig_rewards += FD_PACK_FEE_PER_SIGNATURE * precompile_sigs;
3914 15 : sig_rewards = sig_rewards * FD_PACK_TXN_FEE_BURN_PCT / 100UL;
3915 :
3916 15 : ulong txn_idx = pack_txn_idx + i;
3917 15 : uchar flags = (uchar)FD_GUI_TXN_FLAGS_STARTED;
3918 15 : 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 );
3919 :
3920 15 : fd_gui_store_txn_start_t rec = {
3921 15 : .slot = _slot,
3922 15 : .bank_seq = bank_seq,
3923 15 : .insert_time_ns = now,
3924 15 : .txn_idx = txn_idx,
3925 15 : .transaction_fee = sig_rewards,
3926 15 : .priority_fee = priority_rewards,
3927 15 : .timestamp_arrival_nanos = txn_payload->scheduler_arrival_time_nanos,
3928 15 : .microblock_start_ns = tspub_ns,
3929 15 : .compute_units_requested = (uint)(cost_estimate & 0x1FFFFFU),
3930 15 : .microblock_idx = microblock_idx,
3931 15 : .source_ipv4 = txn_payload->source_ipv4,
3932 15 : .source_tpu = txn_payload->source_tpu,
3933 15 : .flags = flags
3934 15 : };
3935 15 : fd_memcpy( rec.signature, txn_payload->payload + txn->signature_off, FD_SHA512_HASH_SZ );
3936 15 : if( FD_LIKELY( !fd_gui_hist_ts_append( gui, FD_GUI_HIST_TXN_START, &rec ) ) ) {
3937 9 : lslot = fd_gui_slot_leader_get( gui, _slot, bank_seq );
3938 9 : if( FD_LIKELY( lslot ) ) {
3939 9 : lslot->txn_insert_time_min_ns = fd_long_min( lslot->txn_insert_time_min_ns, now );
3940 9 : lslot->txn_insert_time_max_ns = fd_long_max( lslot->txn_insert_time_max_ns, now );
3941 9 : }
3942 9 : }
3943 15 : }
3944 :
3945 : /* At the moment, bank publishes at most 1 transaction per microblock,
3946 : even if it received microblocks with multiple transactions
3947 : (i.e. a bundle). This means that we need to calculate microblock
3948 : count here based on the transaction count. */
3949 15 : lslot = fd_gui_slot_leader_get( gui, _slot, bank_seq );
3950 15 : if( FD_LIKELY( lslot ) ) lslot->begin_microblocks += (uint)txn_cnt;
3951 15 : }
3952 :
3953 : static inline long
3954 15 : fd_gui_ns_dt_float_to_long( float dt ) {
3955 15 : return (long)((double)dt+0.5);
3956 15 : }
3957 :
3958 : /* fd_gui_record_leader_txn converts a transaction executed by the
3959 : leader pipeline into a replay record, so leader and replayed
3960 : transactions are served from the same store. */
3961 :
3962 : static void
3963 : fd_gui_record_leader_txn( fd_gui_t * gui,
3964 : fd_txn_p_t * txn_p,
3965 : ulong txn_idx,
3966 : ulong bank_idx,
3967 : ulong slot,
3968 : ulong block_compute_unit_limit,
3969 : fd_txn_ns_dt_t txn_ns_dt,
3970 : long exec_end_ticks,
3971 : ulong tips,
3972 : uint error_code,
3973 3 : long now ) {
3974 3 : ulong priority_fee = 0UL;
3975 3 : ulong precompile_sig_cnt = 0UL;
3976 3 : ulong requested = fd_pack_compute_cost( TXN( txn_p ), txn_p->payload, NULL,
3977 3 : &priority_fee, &precompile_sig_cnt, NULL, NULL );
3978 3 : long commit_end_ns = fd_gui_tick_to_nanos( gui, now, fd_tickcount(), exec_end_ticks );
3979 3 : long start_ns = fd_long_sat_sub( commit_end_ns, fd_gui_ns_dt_float_to_long( txn_ns_dt.commit_end ) );
3980 3 : fd_gui_store_replay_txn_t replay = {
3981 3 : .insert_time_ns = now,
3982 3 : .completion_time_ns = commit_end_ns,
3983 3 : .block_compute_unit_limit = block_compute_unit_limit,
3984 3 : .slot = slot,
3985 3 : .txn_idx = txn_idx, /* pack index, not position in the produced block */
3986 3 : .txn_exec_idx = bank_idx,
3987 3 : .txn_sigverify_exec_idx = ULONG_MAX,
3988 3 : .txn_start_shred_idx = UINT_MAX, /* execle's union holds pack_alloc, not shred indices */
3989 3 : .txn_end_shred_idx = UINT_MAX,
3990 3 : .sigverify_start_ns = LONG_MAX,
3991 3 : .sigverify_end_ns = LONG_MAX,
3992 3 : .load_start_ns = fd_long_sat_add( start_ns, fd_gui_ns_dt_float_to_long( txn_ns_dt.load_start ) ),
3993 3 : .check_start_ns = fd_long_sat_add( start_ns, fd_gui_ns_dt_float_to_long( txn_ns_dt.check_start ) ),
3994 3 : .exec_start_ns = fd_long_sat_add( start_ns, fd_gui_ns_dt_float_to_long( txn_ns_dt.exec_start ) ),
3995 3 : .commit_start_ns = fd_long_sat_add( start_ns, fd_gui_ns_dt_float_to_long( txn_ns_dt.commit_start ) ),
3996 3 : .commit_end_ns = commit_end_ns,
3997 3 : .transaction_fee = FD_PACK_FEE_PER_SIGNATURE*(TXN( txn_p )->signature_cnt+precompile_sig_cnt), /* before burn, like replay */
3998 3 : .priority_fee = priority_fee,
3999 3 : .tips = tips,
4000 3 : .compute_units_requested = (uint)requested,
4001 3 : .compute_units_consumed = txn_p->execle_cu.actual_consumed_cus,
4002 3 : .error_code = error_code,
4003 3 : .is_committable = 1U,
4004 3 : .is_fees_only = (uchar)!!(txn_p->flags & FD_TXN_P_FLAGS_FEES_ONLY),
4005 3 : };
4006 3 : fd_memcpy( replay.signature, txn_p->payload+TXN( txn_p )->signature_off, FD_TXN_SIGNATURE_SZ );
4007 3 : fd_gui_record_replay_txn( gui, &replay );
4008 3 : }
4009 :
4010 : void
4011 : fd_gui_microblock_execution_end( fd_gui_t * gui,
4012 : long tspub_ns,
4013 : ulong bank_idx,
4014 : ulong _slot,
4015 : ulong txn_cnt,
4016 : fd_txn_p_t * txns,
4017 : ulong pack_txn_idx,
4018 : fd_txn_ns_dt_t txn_ns_dt,
4019 : long exec_end_ticks,
4020 : ulong tips,
4021 : ulong bank_seq,
4022 21 : long now ) {
4023 21 : if( FD_UNLIKELY( 1UL!=txn_cnt ) ) FD_LOG_ERR(( "gui expects 1 txn per microblock from bank, found %lu", txn_cnt ));
4024 :
4025 21 : fd_gui_leader_slot_t * lslot = fd_gui_slot_leader_get_or_create( gui, _slot, bank_seq );
4026 21 : if( FD_UNLIKELY( !lslot ) ) return;
4027 :
4028 21 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, tspub_ns, lslot->leader_start_time );
4029 :
4030 21 : ulong block_compute_unit_limit = lslot->max_compute_units;
4031 42 : for( ulong i=0UL; i<txn_cnt; i++ ) {
4032 21 : fd_txn_p_t * txn_p = &txns[ i ];
4033 21 : ulong txn_idx = pack_txn_idx + i;
4034 :
4035 21 : uint error_code = (txn_p->flags>>24) & 0xFFU;
4036 21 : uchar flags = (uchar)FD_GUI_TXN_FLAGS_ENDED;
4037 21 : flags |= (uchar)fd_uint_if( !!(txn_p->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS), FD_GUI_TXN_FLAGS_LANDED_IN_BLOCK, 0U );
4038 :
4039 21 : fd_gui_store_txn_end_t rec = {
4040 21 : .slot = _slot,
4041 21 : .bank_seq = bank_seq,
4042 21 : .insert_time_ns = now,
4043 21 : .txn_idx = txn_idx,
4044 21 : .timestamp_arrival_nanos = txn_p->scheduler_arrival_time_nanos,
4045 21 : .microblock_end_ns = tspub_ns,
4046 21 : .txn_ns_dt = txn_ns_dt,
4047 21 : .tips = tips,
4048 21 : .compute_units_consumed = (uint)(txn_p->execle_cu.actual_consumed_cus & 0x1FFFFFU),
4049 21 : .bank_idx = (uint)(bank_idx & 0x3FU),
4050 21 : .error_code = error_code,
4051 21 : .flags = flags
4052 21 : };
4053 21 : if( FD_LIKELY( !fd_gui_hist_ts_append( gui, FD_GUI_HIST_TXN_END, &rec ) ) ) {
4054 15 : lslot = fd_gui_slot_leader_get( gui, _slot, bank_seq );
4055 15 : if( FD_LIKELY( lslot ) ) {
4056 15 : lslot->txn_insert_time_min_ns = fd_long_min( lslot->txn_insert_time_min_ns, now );
4057 15 : lslot->txn_insert_time_max_ns = fd_long_max( lslot->txn_insert_time_max_ns, now );
4058 15 : }
4059 15 : }
4060 :
4061 21 : if( FD_LIKELY( gui->db && gui->hist && (txn_p->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS) && exec_end_ticks!=LONG_MAX ) ) {
4062 3 : fd_gui_record_leader_txn( gui, txn_p, txn_idx, bank_idx, _slot, block_compute_unit_limit, txn_ns_dt, exec_end_ticks, tips, error_code, now );
4063 3 : }
4064 21 : }
4065 :
4066 21 : lslot = fd_gui_slot_leader_get( gui, _slot, bank_seq );
4067 21 : if( FD_LIKELY( lslot ) ) lslot->end_microblocks += (uint)txn_cnt;
4068 21 : }
|