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