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