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