Line data Source code
1 : #include "fd_gui.h"
2 : #include "fd_gui_peers.h"
3 : #include "fd_gui_printf.h"
4 : #include "fd_gui_metrics.h"
5 :
6 : #include "../metrics/fd_metrics.h"
7 : #include "../plugin/fd_plugin.h"
8 :
9 : #include "../../ballet/base58/fd_base58.h"
10 : #include "../../ballet/json/cJSON.h"
11 : #include "../../disco/genesis/fd_genesis_cluster.h"
12 : #include "../../disco/pack/fd_pack.h"
13 : #include "../../disco/pack/fd_pack_cost.h"
14 :
15 : #include <stdio.h>
16 :
17 : FD_FN_CONST ulong
18 0 : fd_gui_align( void ) {
19 0 : return 128UL;
20 0 : }
21 :
22 : FD_FN_CONST ulong
23 0 : fd_gui_footprint( void ) {
24 0 : ulong l = FD_LAYOUT_INIT;
25 0 : l = FD_LAYOUT_APPEND( l, fd_gui_align(), sizeof( fd_gui_t ) );
26 0 : return FD_LAYOUT_FINI( l, fd_gui_align() );
27 0 : }
28 :
29 : void *
30 : fd_gui_new( void * shmem,
31 : fd_http_server_t * http,
32 : char const * version,
33 : char const * cluster,
34 : uchar const * identity_key,
35 : int has_vote_key,
36 : uchar const * vote_key,
37 : int is_full_client,
38 : int snapshots_enabled,
39 : int is_voting,
40 : int schedule_strategy,
41 : fd_topo_t * topo,
42 0 : long now ) {
43 :
44 0 : if( FD_UNLIKELY( !shmem ) ) {
45 0 : FD_LOG_WARNING(( "NULL shmem" ));
46 0 : return NULL;
47 0 : }
48 :
49 0 : if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmem, fd_gui_align() ) ) ) {
50 0 : FD_LOG_WARNING(( "misaligned shmem" ));
51 0 : return NULL;
52 0 : }
53 :
54 0 : if( FD_UNLIKELY( topo->tile_cnt>FD_GUI_TILE_TIMER_TILE_CNT ) ) {
55 0 : FD_LOG_WARNING(( "too many tiles" ));
56 0 : return NULL;
57 0 : }
58 :
59 0 : FD_SCRATCH_ALLOC_INIT( l, shmem );
60 0 : fd_gui_t * gui = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(), sizeof(fd_gui_t) );
61 :
62 0 : gui->http = http;
63 0 : gui->topo = topo;
64 :
65 0 : gui->leader_slot = ULONG_MAX;
66 0 : gui->summary.schedule_strategy = schedule_strategy;
67 :
68 :
69 0 : gui->next_sample_400millis = now;
70 0 : gui->next_sample_100millis = now;
71 0 : gui->next_sample_10millis = now;
72 :
73 0 : memcpy( gui->summary.identity_key->uc, identity_key, 32UL );
74 0 : fd_base58_encode_32( identity_key, NULL, gui->summary.identity_key_base58 );
75 0 : gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
76 :
77 0 : if( FD_LIKELY( has_vote_key ) ) {
78 0 : gui->summary.has_vote_key = 1;
79 0 : memcpy( gui->summary.vote_key->uc, vote_key, 32UL );
80 0 : fd_base58_encode_32( vote_key, NULL, gui->summary.vote_key_base58 );
81 0 : gui->summary.vote_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
82 0 : } else {
83 0 : gui->summary.has_vote_key = 0;
84 0 : memset( gui->summary.vote_key_base58, 0, sizeof(gui->summary.vote_key_base58) );
85 0 : }
86 :
87 0 : gui->summary.is_full_client = is_full_client;
88 0 : gui->summary.version = version;
89 0 : gui->summary.cluster = cluster;
90 0 : gui->summary.startup_time_nanos = gui->next_sample_400millis;
91 :
92 0 : if( FD_UNLIKELY( is_full_client ) ) {
93 0 : if( FD_UNLIKELY( snapshots_enabled ) ) {
94 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP;
95 0 : gui->summary.boot_progress.joining_gossip_time_nanos = gui->next_sample_400millis;
96 0 : for( ulong i=0UL; i<FD_GUI_BOOT_PROGRESS_SNAPSHOT_CNT; i++ ) {
97 0 : gui->summary.boot_progress.loading_snapshot[ i ].reset_cnt = ULONG_MAX; /* ensures other fields are reset initially */
98 0 : gui->summary.boot_progress.loading_snapshot[ i ].read_path[ 0 ] = '\0';
99 0 : gui->summary.boot_progress.loading_snapshot[ i ].insert_path[ 0 ] = '\0';
100 0 : }
101 0 : gui->summary.boot_progress.catching_up_time_nanos = 0L;
102 0 : gui->summary.boot_progress.catching_up_first_replay_slot = ULONG_MAX;
103 0 : } else {
104 0 : fd_memset( &gui->summary.boot_progress, 0, sizeof(gui->summary.boot_progress) );
105 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
106 0 : }
107 0 : } else {
108 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_INITIALIZING;
109 0 : gui->summary.startup_progress.startup_got_full_snapshot = 0;
110 0 : gui->summary.startup_progress.startup_full_snapshot_slot = 0;
111 0 : gui->summary.startup_progress.startup_incremental_snapshot_slot = 0;
112 0 : gui->summary.startup_progress.startup_waiting_for_supermajority_slot = ULONG_MAX;
113 0 : gui->summary.startup_progress.startup_ledger_max_slot = ULONG_MAX;
114 0 : }
115 :
116 0 : gui->summary.identity_account_balance = 0UL;
117 0 : gui->summary.vote_account_balance = 0UL;
118 0 : gui->summary.estimated_slot_duration_nanos = 0UL;
119 :
120 0 : gui->summary.vote_distance = 0UL;
121 0 : gui->summary.vote_state = is_voting ? FD_GUI_VOTE_STATE_VOTING : FD_GUI_VOTE_STATE_NON_VOTING;
122 :
123 0 : gui->summary.sock_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "sock" );
124 0 : gui->summary.net_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "net" );
125 0 : gui->summary.quic_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "quic" );
126 0 : gui->summary.verify_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "verify" );
127 0 : gui->summary.resolv_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "resolv" );
128 0 : gui->summary.bank_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "bank" );
129 0 : gui->summary.shred_tile_cnt = fd_topo_tile_name_cnt( gui->topo, "shred" );
130 :
131 0 : gui->summary.slot_rooted = ULONG_MAX;
132 0 : gui->summary.slot_optimistically_confirmed = ULONG_MAX;
133 0 : gui->summary.slot_completed = ULONG_MAX;
134 0 : gui->summary.slot_estimated = ULONG_MAX;
135 0 : gui->summary.slot_caught_up = ULONG_MAX;
136 0 : gui->summary.slot_repair = ULONG_MAX;
137 0 : gui->summary.slot_turbine = ULONG_MAX;
138 0 : gui->summary.slot_reset = ULONG_MAX;
139 0 : gui->summary.slot_storage = ULONG_MAX;
140 :
141 0 : for( ulong i=0UL; i < (FD_GUI_REPAIR_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_repair[ i ].slot = ULONG_MAX;
142 0 : for( ulong i=0UL; i < (FD_GUI_TURBINE_SLOT_HISTORY_SZ+1UL); i++ ) gui->summary.slots_max_turbine[ i ].slot = ULONG_MAX;
143 :
144 0 : gui->summary.estimated_tps_history_idx = 0UL;
145 0 : memset( gui->summary.estimated_tps_history, 0, sizeof(gui->summary.estimated_tps_history) );
146 :
147 0 : memset( gui->summary.txn_waterfall_reference, 0, sizeof(gui->summary.txn_waterfall_reference) );
148 0 : memset( gui->summary.txn_waterfall_current, 0, sizeof(gui->summary.txn_waterfall_current) );
149 :
150 0 : memset( gui->summary.tile_stats_reference, 0, sizeof(gui->summary.tile_stats_reference) );
151 0 : memset( gui->summary.tile_stats_current, 0, sizeof(gui->summary.tile_stats_current) );
152 :
153 0 : memset( gui->summary.tile_timers_snap[ 0 ], 0, sizeof(gui->summary.tile_timers_snap[ 0 ]) );
154 0 : memset( gui->summary.tile_timers_snap[ 1 ], 0, sizeof(gui->summary.tile_timers_snap[ 1 ]) );
155 0 : gui->summary.tile_timers_snap_idx = 2UL;
156 :
157 0 : memset( gui->summary.scheduler_counts_snap[ 0 ], 0, sizeof(gui->summary.scheduler_counts_snap[ 0 ]) );
158 0 : memset( gui->summary.scheduler_counts_snap[ 1 ], 0, sizeof(gui->summary.scheduler_counts_snap[ 1 ]) );
159 0 : gui->summary.scheduler_counts_snap_idx = 2UL;
160 :
161 0 : for( ulong i=0UL; i<FD_GUI_SLOTS_CNT; i++ ) gui->slots[ i ]->slot = ULONG_MAX;
162 0 : for( ulong i=0UL; i<FD_GUI_LEADER_CNT; i++ ) gui->leader_slots[ i ]->slot = ULONG_MAX;
163 0 : gui->leader_slots_cnt = 0UL;
164 :
165 0 : gui->block_engine.has_block_engine = 0;
166 :
167 0 : gui->epoch.has_epoch[ 0 ] = 0;
168 0 : gui->epoch.has_epoch[ 1 ] = 0;
169 :
170 0 : gui->gossip.peer_cnt = 0UL;
171 0 : gui->vote_account.vote_account_cnt = 0UL;
172 0 : gui->validator_info.info_cnt = 0UL;
173 :
174 0 : gui->pack_txn_idx = 0UL;
175 :
176 0 : gui->shreds.staged_next_broadcast = 0UL;
177 0 : gui->shreds.staged_head = 0UL;
178 0 : gui->shreds.staged_tail = 0UL;
179 0 : gui->shreds.history_tail = 0UL;
180 0 : gui->shreds.history_slot = ULONG_MAX;
181 0 : gui->summary.catch_up_repair_sz = 0UL;
182 0 : gui->summary.catch_up_turbine_sz = 0UL;
183 :
184 0 : return gui;
185 0 : }
186 :
187 : fd_gui_t *
188 0 : fd_gui_join( void * shmem ) {
189 0 : return (fd_gui_t *)shmem;
190 0 : }
191 :
192 : void
193 : fd_gui_set_identity( fd_gui_t * gui,
194 0 : uchar const * identity_pubkey ) {
195 0 : memcpy( gui->summary.identity_key->uc, identity_pubkey, 32UL );
196 0 : fd_base58_encode_32( identity_pubkey, NULL, gui->summary.identity_key_base58 );
197 0 : gui->summary.identity_key_base58[ FD_BASE58_ENCODED_32_SZ-1UL ] = '\0';
198 :
199 0 : fd_gui_printf_identity_key( gui );
200 0 : fd_http_server_ws_broadcast( gui->http );
201 :
202 0 : fd_gui_printf_identity_balance( gui );
203 0 : fd_http_server_ws_broadcast( gui->http );
204 0 : }
205 :
206 : void
207 : fd_gui_ws_open( fd_gui_t * gui,
208 0 : ulong ws_conn_id ) {
209 0 : void (* printers[] )( fd_gui_t * gui ) = {
210 0 : gui->summary.is_full_client ? fd_gui_printf_boot_progress : fd_gui_printf_startup_progress,
211 0 : fd_gui_printf_version,
212 0 : fd_gui_printf_cluster,
213 0 : fd_gui_printf_commit_hash,
214 0 : fd_gui_printf_identity_key,
215 0 : fd_gui_printf_vote_key,
216 0 : fd_gui_printf_startup_time_nanos,
217 0 : fd_gui_printf_vote_state,
218 0 : fd_gui_printf_vote_distance,
219 0 : fd_gui_printf_turbine_slot,
220 0 : fd_gui_printf_repair_slot,
221 0 : fd_gui_printf_slot_caught_up,
222 0 : fd_gui_printf_skipped_history,
223 0 : fd_gui_printf_skipped_history_cluster,
224 0 : fd_gui_printf_tps_history,
225 0 : fd_gui_printf_tiles,
226 0 : fd_gui_printf_schedule_strategy,
227 0 : fd_gui_printf_identity_balance,
228 0 : fd_gui_printf_vote_balance,
229 0 : fd_gui_printf_estimated_slot_duration_nanos,
230 0 : fd_gui_printf_root_slot,
231 0 : fd_gui_printf_optimistically_confirmed_slot,
232 0 : fd_gui_printf_completed_slot,
233 0 : fd_gui_printf_estimated_slot,
234 0 : fd_gui_printf_live_tile_timers,
235 0 : fd_gui_printf_live_tile_metrics,
236 0 : fd_gui_printf_catch_up_history,
237 0 : };
238 :
239 0 : ulong printers_len = sizeof(printers) / sizeof(printers[0]);
240 0 : for( ulong i=0UL; i<printers_len; i++ ) {
241 0 : printers[ i ]( gui );
242 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
243 0 : }
244 :
245 0 : if( FD_LIKELY( gui->block_engine.has_block_engine ) ) {
246 0 : fd_gui_printf_block_engine( gui );
247 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
248 0 : }
249 :
250 0 : for( ulong i=0UL; i<2UL; i++ ) {
251 0 : if( FD_LIKELY( gui->epoch.has_epoch[ i ] ) ) {
252 0 : fd_gui_printf_skip_rate( gui, i );
253 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
254 0 : fd_gui_printf_epoch( gui, i );
255 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
256 0 : }
257 0 : }
258 :
259 : /* Print peers last because it's the largest message and would
260 : block other information. */
261 0 : fd_gui_printf_peers_all( gui );
262 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
263 0 : }
264 :
265 : static void
266 0 : fd_gui_tile_timers_snap( fd_gui_t * gui ) {
267 0 : fd_gui_tile_timers_t * cur = gui->summary.tile_timers_snap[ gui->summary.tile_timers_snap_idx ];
268 0 : gui->summary.tile_timers_snap_idx = (gui->summary.tile_timers_snap_idx+1UL)%FD_GUI_TILE_TIMER_SNAP_CNT;
269 0 : for( ulong i=0UL; i<gui->topo->tile_cnt; i++ ) {
270 0 : fd_topo_tile_t * tile = &gui->topo->tiles[ i ];
271 0 : if ( FD_UNLIKELY( !tile->metrics ) ) {
272 : /* bench tiles might not have been booted initially.
273 : This check shouldn't be necessary if all tiles barrier after boot. */
274 : // TODO(FIXME) this probably isn't the right fix but it makes fddev bench work for now
275 0 : return;
276 0 : }
277 0 : volatile ulong const * tile_metrics = fd_metrics_tile( tile->metrics );
278 :
279 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 ) ];
280 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_HOUSEKEEPING ) ];
281 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_HOUSEKEEPING_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_HOUSEKEEPING ) ];
282 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 ) ];
283 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_PREFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_PREFRAG ) ];
284 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_BACKPRESSURE_PREFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
285 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 ) ];
286 0 : cur[ i ].timers[ FD_METRICS_ENUM_TILE_REGIME_V_PROCESSING_POSTFRAG_IDX ] = tile_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_PROCESSING_POSTFRAG ) ];
287 :
288 0 : cur[ i ].in_backp = (int)tile_metrics[ MIDX(GAUGE, TILE, IN_BACKPRESSURE) ];
289 0 : cur[ i ].heartbeat = tile_metrics[ FD_METRICS_GAUGE_TILE_HEARTBEAT_OFF ];
290 0 : cur[ i ].backp_cnt = tile_metrics[ MIDX( COUNTER, TILE, BACKPRESSURE_COUNT ) ];
291 0 : cur[ i ].nvcsw = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_VOLUNTARY_COUNT ) ];
292 0 : cur[ i ].nivcsw = tile_metrics[ MIDX( COUNTER, TILE, CONTEXT_SWITCH_INVOLUNTARY_COUNT ) ];
293 0 : }
294 0 : }
295 :
296 : static void
297 0 : fd_gui_scheduler_counts_snap( fd_gui_t * gui, long now ) {
298 0 : fd_gui_scheduler_counts_t * cur = gui->summary.scheduler_counts_snap[ gui->summary.scheduler_counts_snap_idx ];
299 0 : gui->summary.scheduler_counts_snap_idx = (gui->summary.scheduler_counts_snap_idx+1UL)%FD_GUI_SCHEDULER_COUNT_SNAP_CNT;
300 :
301 0 : fd_topo_tile_t const * pack = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "pack", 0UL ) ];
302 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
303 :
304 0 : cur->sample_time_ns = now;
305 :
306 0 : cur->regular = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_REGULAR ) ];
307 0 : cur->votes = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_VOTES ) ];
308 0 : cur->conflicting = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_CONFLICTING ) ];
309 0 : cur->bundles = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS_BUNDLES ) ];
310 0 : }
311 :
312 : static void
313 0 : fd_gui_estimated_tps_snap( fd_gui_t * gui ) {
314 0 : ulong total_txn_cnt = 0UL;
315 0 : ulong vote_txn_cnt = 0UL;
316 0 : ulong nonvote_failed_txn_cnt = 0UL;
317 :
318 0 : if( FD_LIKELY( gui->summary.slot_completed==ULONG_MAX ) ) return;
319 0 : for( ulong i=0UL; i<fd_ulong_min( gui->summary.slot_completed+1UL, FD_GUI_SLOTS_CNT ); i++ ) {
320 0 : ulong _slot = gui->summary.slot_completed-i;
321 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
322 0 : if( FD_UNLIKELY( !slot ) ) break; /* Slot no longer exists, no TPS. */
323 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. */
324 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. */
325 0 : if( FD_UNLIKELY( slot->skipped ) ) continue; /* Skipped slots don't count to TPS. */
326 :
327 0 : total_txn_cnt += slot->total_txn_cnt;
328 0 : vote_txn_cnt += slot->vote_txn_cnt;
329 0 : nonvote_failed_txn_cnt += slot->nonvote_failed_txn_cnt;
330 0 : }
331 :
332 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ][ 0 ] = total_txn_cnt;
333 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ][ 1 ] = vote_txn_cnt;
334 0 : gui->summary.estimated_tps_history[ gui->summary.estimated_tps_history_idx ][ 2 ] = nonvote_failed_txn_cnt;
335 0 : gui->summary.estimated_tps_history_idx = (gui->summary.estimated_tps_history_idx+1UL) % FD_GUI_TPS_HISTORY_SAMPLE_CNT;
336 0 : }
337 :
338 : static void
339 : fd_gui_network_stats_snap( fd_gui_t * gui,
340 0 : fd_gui_network_stats_t * cur ) {
341 0 : fd_topo_t * topo = gui->topo;
342 0 : ulong gossvf_tile_cnt = fd_topo_tile_name_cnt( topo, "gossvf" );
343 0 : ulong gossip_tile_cnt = fd_topo_tile_name_cnt( topo, "gossip" );
344 0 : ulong shred_tile_cnt = fd_topo_tile_name_cnt( topo, "shred" );
345 0 : ulong net_tile_cnt = fd_topo_tile_name_cnt( topo, "net" );
346 0 : ulong quic_tile_cnt = fd_topo_tile_name_cnt( topo, "quic" );
347 :
348 0 : cur->in.gossip = fd_gui_metrics_gossip_total_ingress_bytes( topo, gossvf_tile_cnt );
349 0 : cur->out.gossip = fd_gui_metrics_gosip_total_egress_bytes( topo, gossip_tile_cnt );
350 0 : cur->in.turbine = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_TURBINE_RCV_BYTES ) );
351 :
352 0 : cur->out.turbine = 0UL;
353 0 : cur->out.repair = 0UL;
354 0 : cur->out.tpu = 0UL;
355 0 : for( ulong i=0UL; i<net_tile_cnt; i++ ) {
356 0 : ulong net_tile_idx = fd_topo_find_tile( topo, "net", i );
357 0 : if( FD_UNLIKELY( net_tile_idx==ULONG_MAX ) ) continue;
358 0 : fd_topo_tile_t const * net = &topo->tiles[ net_tile_idx ];
359 0 : for( ulong j=0UL; j<net->in_cnt; j++ ) {
360 0 : if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "shred_net" ) ) ) {
361 0 : cur->out.turbine += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
362 0 : }
363 :
364 0 : if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "repair_net" ) ) ) {
365 0 : cur->out.repair += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
366 0 : }
367 :
368 0 : if( FD_UNLIKELY( !strcmp( topo->links[ net->in_link_id[ j ] ].name, "send_net" ) ) ) {
369 0 : cur->out.tpu += fd_metrics_link_in( net->metrics, j )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
370 0 : }
371 0 : }
372 0 : }
373 :
374 0 : cur->in.repair = fd_gui_metrics_sum_tiles_counter( topo, "shred", shred_tile_cnt, MIDX( COUNTER, SHRED, SHRED_OUT_RCV_BYTES ) );
375 0 : ulong repair_tile_idx = fd_topo_find_tile( topo, "repair", 0UL );
376 0 : if( FD_LIKELY( repair_tile_idx!=ULONG_MAX ) ) {
377 0 : fd_topo_tile_t const * repair = &topo->tiles[ repair_tile_idx ];
378 :
379 0 : for( ulong i=0UL; i<repair->in_cnt; i++ ) {
380 0 : if( FD_UNLIKELY( !strcmp( topo->links[ repair->in_link_id[ i ] ].name, "net_repair" ) ) ) {
381 0 : cur->in.repair += fd_metrics_link_in( repair->metrics, i )[ FD_METRICS_COUNTER_LINK_CONSUMED_SIZE_BYTES_OFF ];
382 0 : }
383 0 : }
384 0 : }
385 :
386 0 : cur->in.tpu = 0UL;
387 0 : for( ulong i=0UL; i<quic_tile_cnt; i++ ) {
388 0 : ulong quic_tile_idx = fd_topo_find_tile( topo, "quic", i );
389 0 : if( FD_UNLIKELY( quic_tile_idx==ULONG_MAX ) ) continue;
390 0 : fd_topo_tile_t const * quic = &topo->tiles[ quic_tile_idx ];
391 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
392 0 : cur->in.tpu += quic_metrics[ MIDX( COUNTER, QUIC, RECEIVED_BYTES ) ];
393 0 : }
394 :
395 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
396 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
397 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
398 0 : volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
399 0 : cur->in.tpu += bundle_metrics[ MIDX( COUNTER, BUNDLE, PROTO_RECEIVED_BYTES ) ];
400 0 : }
401 :
402 0 : ulong metric_tile_idx = fd_topo_find_tile( topo, "metric", 0UL );
403 0 : if( FD_LIKELY( metric_tile_idx!=ULONG_MAX ) ) {
404 0 : fd_topo_tile_t const * metric = &topo->tiles[ metric_tile_idx ];
405 0 : volatile ulong * metric_metrics = fd_metrics_tile( metric->metrics );
406 0 : cur->in.metric = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_READ ) ];
407 0 : cur->out.metric = metric_metrics[ MIDX( COUNTER, METRIC, BYTES_WRITTEN ) ];
408 0 : } else {
409 0 : cur->in.metric = 0UL;
410 0 : cur->out.metric = 0UL;
411 0 : }
412 0 : }
413 :
414 : /* Snapshot all of the data from metrics to construct a view of the
415 : transaction waterfall.
416 :
417 : Tiles are sampled in reverse pipeline order: this helps prevent data
418 : discrepancies where a later tile has "seen" more transactions than an
419 : earlier tile, which shouldn't typically happen. */
420 :
421 : static void
422 : fd_gui_txn_waterfall_snap( fd_gui_t * gui,
423 0 : fd_gui_txn_waterfall_t * cur ) {
424 0 : fd_topo_t * topo = gui->topo;
425 :
426 0 : cur->out.block_success = 0UL;
427 0 : cur->out.block_fail = 0UL;
428 :
429 0 : cur->out.bank_invalid = 0UL;
430 0 : for( ulong i=0UL; i<gui->summary.bank_tile_cnt; i++ ) {
431 0 : fd_topo_tile_t const * bank = &topo->tiles[ fd_topo_find_tile( topo, "bank", i ) ];
432 :
433 0 : volatile ulong const * bank_metrics = fd_metrics_tile( bank->metrics );
434 0 : if( FD_LIKELY( !gui->summary.is_full_client ) ) {
435 0 : cur->out.block_success += bank_metrics[ MIDX( COUNTER, BANK, SUCCESSFUL_TRANSACTIONS ) ];
436 :
437 0 : cur->out.block_fail +=
438 0 : bank_metrics[ MIDX( COUNTER, BANK, EXECUTED_FAILED_TRANSACTIONS ) ]
439 0 : + bank_metrics[ MIDX( COUNTER, BANK, FEE_ONLY_TRANSACTIONS ) ];
440 :
441 0 : cur->out.bank_invalid +=
442 0 : bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_ACCOUNT_UNINITIALIZED ) ]
443 0 : + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_ACCOUNT_NOT_FOUND ) ]
444 0 : + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_INVALID_ACCOUNT_OWNER ) ]
445 0 : + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_INVALID_ACCOUNT_DATA ) ]
446 0 : + bank_metrics[ MIDX( COUNTER, BANK, TRANSACTION_LOAD_ADDRESS_TABLES_INVALID_LOOKUP_INDEX ) ];
447 :
448 0 : cur->out.bank_invalid +=
449 0 : bank_metrics[ MIDX( COUNTER, BANK, PROCESSING_FAILED ) ];
450 :
451 : /* These branches are unused in Frankendancer */
452 0 : cur->out.bank_nonce_already_advanced = 0UL;
453 0 : cur->out.bank_nonce_advance_failed = 0UL;
454 0 : cur->out.bank_nonce_wrong_blockhash = 0UL;
455 0 : } else {
456 0 : cur->out.block_success += bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_LANDED_LANDED_SUCCESS ) ];
457 0 : cur->out.block_fail +=
458 0 : bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_LANDED_LANDED_FEES_ONLY ) ]
459 0 : + bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_LANDED_LANDED_FAILED ) ];
460 0 : cur->out.bank_invalid += bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_LANDED_UNLANDED ) ];
461 :
462 0 : cur->out.bank_nonce_already_advanced = bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_RESULT_NONCE_ALREADY_ADVANCED ) ];
463 0 : cur->out.bank_nonce_advance_failed = bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_RESULT_NONCE_ADVANCE_FAILED ) ];
464 0 : cur->out.bank_nonce_wrong_blockhash = bank_metrics[ MIDX( COUNTER, BANKF, TRANSACTION_RESULT_NONCE_WRONG_BLOCKHASH ) ];
465 0 : }
466 0 : }
467 :
468 :
469 0 : fd_topo_tile_t const * pack = &topo->tiles[ fd_topo_find_tile( topo, "pack", 0UL ) ];
470 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
471 :
472 0 : cur->out.pack_invalid_bundle =
473 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DROPPED_PARTIAL_BUNDLE ) ]
474 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTION_FAILED ) ]
475 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_CREATION_FAILED ) ];
476 :
477 0 : cur->out.pack_invalid =
478 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_NONCE_CONFLICT ) ]
479 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_BUNDLE_BLACKLIST ) ]
480 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_INVALID_NONCE ) ]
481 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_WRITE_SYSVAR ) ]
482 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_ESTIMATION_FAIL ) ]
483 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_DUPLICATE_ACCOUNT ) ]
484 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_TOO_MANY_ACCOUNTS ) ]
485 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_TOO_LARGE ) ]
486 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_ADDR_LUT ) ]
487 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_UNAFFORDABLE ) ]
488 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_DUPLICATE ) ]
489 0 : - pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTION_FAILED ) ]; /* so we don't double count this, since its already accounted for in invalid_bundle */
490 :
491 0 : cur->out.pack_expired = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_EXPIRED ) ] +
492 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_EXPIRED ) ] +
493 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DELETED ) ] +
494 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_NONCE_PRIORITY ) ];
495 :
496 0 : cur->out.pack_already_executed = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_ALREADY_EXECUTED ) ];
497 :
498 0 : cur->out.pack_leader_slow = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_PRIORITY ) ];
499 :
500 0 : cur->out.pack_wait_full =
501 0 : pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DROPPED_FROM_EXTRA ) ];
502 :
503 0 : cur->out.pack_retained = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS ) ];
504 :
505 0 : ulong inserted_to_extra = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_TO_EXTRA ) ];
506 0 : ulong inserted_from_extra = pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_INSERTED_FROM_EXTRA ) ]
507 0 : + pack_metrics[ MIDX( COUNTER, PACK, TRANSACTION_DROPPED_FROM_EXTRA ) ];
508 0 : cur->out.pack_retained += fd_ulong_if( inserted_to_extra>=inserted_from_extra, inserted_to_extra-inserted_from_extra, 0UL );
509 :
510 0 : cur->out.resolv_lut_failed = 0UL;
511 0 : cur->out.resolv_expired = 0UL;
512 0 : cur->out.resolv_ancient = 0UL;
513 0 : cur->out.resolv_no_ledger = 0UL;
514 0 : cur->out.resolv_retained = 0UL;
515 0 : for( ulong i=0UL; i<gui->summary.resolv_tile_cnt; i++ ) {
516 0 : fd_topo_tile_t const * resolv = &topo->tiles[ fd_topo_find_tile( topo, "resolv", i ) ];
517 0 : volatile ulong const * resolv_metrics = fd_metrics_tile( resolv->metrics );
518 :
519 0 : if( FD_LIKELY( !gui->summary.is_full_client ) ) {
520 0 : cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLV, NO_BANK_DROP ) ];
521 0 : cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLV, BLOCKHASH_EXPIRED ) ]
522 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, TRANSACTION_BUNDLE_PEER_FAILURE ) ];
523 0 : cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
524 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
525 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
526 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
527 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
528 0 : cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ];
529 :
530 0 : ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_INSERTED ) ];
531 0 : ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_OVERRUN ) ]
532 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_PUBLISHED ) ]
533 0 : + resolv_metrics[ MIDX( COUNTER, RESOLV, STASH_OPERATION_REMOVED ) ];
534 0 : cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
535 0 : } else {
536 0 : cur->out.resolv_no_ledger += resolv_metrics[ MIDX( COUNTER, RESOLF, NO_BANK_DROP ) ];
537 0 : cur->out.resolv_expired += resolv_metrics[ MIDX( COUNTER, RESOLF, BLOCKHASH_EXPIRED ) ]
538 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, TRANSACTION_BUNDLE_PEER_FAILURE ) ];
539 0 : cur->out.resolv_lut_failed += resolv_metrics[ MIDX( COUNTER, RESOLF, LUT_RESOLVED_ACCOUNT_NOT_FOUND ) ]
540 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, LUT_RESOLVED_INVALID_ACCOUNT_OWNER ) ]
541 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, LUT_RESOLVED_INVALID_ACCOUNT_DATA ) ]
542 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, LUT_RESOLVED_ACCOUNT_UNINITIALIZED ) ]
543 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, LUT_RESOLVED_INVALID_LOOKUP_INDEX ) ];
544 0 : cur->out.resolv_ancient += resolv_metrics[ MIDX( COUNTER, RESOLF, STASH_OPERATION_OVERRUN ) ];
545 :
546 0 : ulong inserted_to_resolv = resolv_metrics[ MIDX( COUNTER, RESOLF, STASH_OPERATION_INSERTED ) ];
547 0 : ulong removed_from_resolv = resolv_metrics[ MIDX( COUNTER, RESOLF, STASH_OPERATION_OVERRUN ) ]
548 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, STASH_OPERATION_PUBLISHED ) ]
549 0 : + resolv_metrics[ MIDX( COUNTER, RESOLF, STASH_OPERATION_REMOVED ) ];
550 0 : cur->out.resolv_retained += fd_ulong_if( inserted_to_resolv>=removed_from_resolv, inserted_to_resolv-removed_from_resolv, 0UL );
551 0 : }
552 0 : }
553 :
554 :
555 0 : fd_topo_tile_t const * dedup = &topo->tiles[ fd_topo_find_tile( topo, "dedup", 0UL ) ];
556 0 : volatile ulong const * dedup_metrics = fd_metrics_tile( dedup->metrics );
557 :
558 0 : cur->out.dedup_duplicate = dedup_metrics[ MIDX( COUNTER, DEDUP, TRANSACTION_DEDUP_FAILURE ) ]
559 0 : + dedup_metrics[ MIDX( COUNTER, DEDUP, TRANSACTION_BUNDLE_PEER_FAILURE ) ];
560 :
561 :
562 0 : cur->out.verify_overrun = 0UL;
563 0 : cur->out.verify_duplicate = 0UL;
564 0 : cur->out.verify_parse = 0UL;
565 0 : cur->out.verify_failed = 0UL;
566 :
567 0 : for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
568 0 : fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
569 0 : volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
570 :
571 0 : for( ulong j=0UL; j<gui->summary.quic_tile_cnt; j++ ) {
572 : /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this verify tile. */
573 0 : cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_POLLING_FRAG_COUNT_OFF ] / gui->summary.verify_tile_cnt;
574 0 : cur->out.verify_overrun += fd_metrics_link_in( verify->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_READING_FRAG_COUNT_OFF ];
575 0 : }
576 :
577 0 : cur->out.verify_failed += verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_VERIFY_FAILURE ) ] +
578 0 : verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_BUNDLE_PEER_FAILURE ) ];
579 0 : cur->out.verify_parse += verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_PARSE_FAILURE ) ];
580 0 : cur->out.verify_duplicate += verify_metrics[ MIDX( COUNTER, VERIFY, TRANSACTION_DEDUP_FAILURE ) ];
581 0 : }
582 :
583 :
584 0 : cur->out.quic_overrun = 0UL;
585 0 : cur->out.quic_frag_drop = 0UL;
586 0 : cur->out.quic_abandoned = 0UL;
587 0 : cur->out.tpu_quic_invalid = 0UL;
588 0 : cur->out.tpu_udp_invalid = 0UL;
589 0 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
590 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
591 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
592 :
593 0 : cur->out.tpu_udp_invalid += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_UNDERSZ ) ];
594 0 : cur->out.tpu_udp_invalid += quic_metrics[ MIDX( COUNTER, QUIC, LEGACY_TXN_OVERSZ ) ];
595 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_UNDERSZ ) ];
596 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_OVERSZ ) ];
597 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, TXN_OVERSZ ) ];
598 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_CRYPTO_FAILED ) ];
599 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NO_CONN ) ];
600 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_NET_HEADER_INVALID ) ];
601 0 : cur->out.tpu_quic_invalid += quic_metrics[ MIDX( COUNTER, QUIC, PKT_QUIC_HEADER_INVALID ) ];
602 0 : cur->out.quic_abandoned += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_ABANDONED ) ];
603 0 : cur->out.quic_frag_drop += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_OVERRUN ) ];
604 :
605 0 : for( ulong j=0UL; j<gui->summary.net_tile_cnt; j++ ) {
606 : /* TODO: Not precise... net frags that were skipped might not have been destined for QUIC tile */
607 : /* TODO: Not precise... even if 1 frag gets skipped, it could have been for this QUIC tile */
608 0 : cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_POLLING_FRAG_COUNT_OFF ] / gui->summary.quic_tile_cnt;
609 0 : cur->out.quic_overrun += fd_metrics_link_in( quic->metrics, j )[ FD_METRICS_COUNTER_LINK_OVERRUN_READING_FRAG_COUNT_OFF ];
610 0 : }
611 0 : }
612 :
613 0 : cur->out.net_overrun = 0UL;
614 0 : for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
615 0 : fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
616 0 : volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
617 :
618 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_RING_FULL ) ];
619 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_DROPPED_OTHER ) ];
620 0 : cur->out.net_overrun += net_metrics[ MIDX( COUNTER, NET, XDP_RX_FILL_RING_EMPTY_DESCS ) ];
621 0 : }
622 :
623 0 : ulong bundle_txns_received = 0UL;
624 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
625 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
626 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
627 0 : volatile ulong const * bundle_metrics = fd_metrics_tile( bundle->metrics );
628 :
629 0 : bundle_txns_received = bundle_metrics[ MIDX( COUNTER, BUNDLE, TRANSACTION_RECEIVED ) ];
630 0 : }
631 :
632 0 : cur->in.pack_cranked =
633 0 : pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTED ) ]
634 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_INSERTION_FAILED ) ]
635 0 : + pack_metrics[ MIDX( COUNTER, PACK, BUNDLE_CRANK_STATUS_CREATION_FAILED ) ];
636 :
637 0 : if( FD_UNLIKELY( gui->summary.is_full_client ) ) {
638 0 : cur->in.gossip = 0UL;
639 0 : for( ulong i=0UL; i<gui->summary.verify_tile_cnt; i++ ) {
640 0 : fd_topo_tile_t const * verify = &topo->tiles[ fd_topo_find_tile( topo, "verify", i ) ];
641 0 : volatile ulong const * verify_metrics = fd_metrics_tile( verify->metrics );
642 0 : cur->in.gossip += verify_metrics[ MIDX( COUNTER, VERIFY, GOSSIPED_VOTES_RECEIVED ) ];
643 0 : }
644 0 : } else {
645 0 : cur->in.gossip = dedup_metrics[ MIDX( COUNTER, DEDUP, GOSSIPED_VOTES_RECEIVED ) ];
646 0 : }
647 :
648 0 : cur->in.quic = cur->out.tpu_quic_invalid +
649 0 : cur->out.quic_overrun +
650 0 : cur->out.quic_frag_drop +
651 0 : cur->out.quic_abandoned +
652 0 : cur->out.net_overrun;
653 0 : cur->in.udp = cur->out.tpu_udp_invalid;
654 0 : cur->in.block_engine = bundle_txns_received;
655 0 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
656 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
657 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
658 :
659 0 : cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_RECEIVED_QUIC_FAST ) ];
660 0 : cur->in.quic += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_RECEIVED_QUIC_FRAG ) ];
661 0 : cur->in.udp += quic_metrics[ MIDX( COUNTER, QUIC, TXNS_RECEIVED_UDP ) ];
662 0 : }
663 0 : }
664 :
665 : static void
666 : fd_gui_tile_stats_snap( fd_gui_t * gui,
667 : fd_gui_txn_waterfall_t const * waterfall,
668 : fd_gui_tile_stats_t * stats,
669 0 : long now ) {
670 0 : fd_topo_t const * topo = gui->topo;
671 :
672 0 : stats->sample_time_nanos = now;
673 :
674 0 : stats->net_in_rx_bytes = 0UL;
675 0 : stats->net_out_tx_bytes = 0UL;
676 0 : for( ulong i=0UL; i<gui->summary.net_tile_cnt; i++ ) {
677 0 : fd_topo_tile_t const * net = &topo->tiles[ fd_topo_find_tile( topo, "net", i ) ];
678 0 : volatile ulong * net_metrics = fd_metrics_tile( net->metrics );
679 :
680 0 : stats->net_in_rx_bytes += net_metrics[ MIDX( COUNTER, NET, RX_BYTES_TOTAL ) ];
681 0 : stats->net_out_tx_bytes += net_metrics[ MIDX( COUNTER, NET, TX_BYTES_TOTAL ) ];
682 0 : }
683 :
684 0 : for( ulong i=0UL; i<gui->summary.sock_tile_cnt; i++ ) {
685 0 : fd_topo_tile_t const * sock = &topo->tiles[ fd_topo_find_tile( topo, "sock", i ) ];
686 0 : volatile ulong * sock_metrics = fd_metrics_tile( sock->metrics );
687 :
688 0 : stats->net_in_rx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, RX_BYTES_TOTAL ) ];
689 0 : stats->net_out_tx_bytes += sock_metrics[ MIDX( COUNTER, SOCK, TX_BYTES_TOTAL ) ];
690 0 : }
691 :
692 0 : stats->quic_conn_cnt = 0UL;
693 0 : for( ulong i=0UL; i<gui->summary.quic_tile_cnt; i++ ) {
694 0 : fd_topo_tile_t const * quic = &topo->tiles[ fd_topo_find_tile( topo, "quic", i ) ];
695 0 : volatile ulong * quic_metrics = fd_metrics_tile( quic->metrics );
696 :
697 0 : stats->quic_conn_cnt += quic_metrics[ MIDX( GAUGE, QUIC, CONNECTIONS_ALLOC ) ];
698 0 : }
699 :
700 0 : ulong bundle_tile_idx = fd_topo_find_tile( topo, "bundle", 0UL );
701 0 : if( FD_LIKELY( bundle_tile_idx!=ULONG_MAX ) ) {
702 0 : fd_topo_tile_t const * bundle = &topo->tiles[ bundle_tile_idx ];
703 0 : volatile ulong * bundle_metrics = fd_metrics_tile( bundle->metrics );
704 0 : stats->bundle_rtt_smoothed_nanos = bundle_metrics[ MIDX( GAUGE, BUNDLE, RTT_SMOOTHED ) ];
705 :
706 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 ) );
707 0 : stats->bundle_rx_delay_hist.sum = bundle_metrics[ MIDX( HISTOGRAM, BUNDLE, MESSAGE_RX_DELAY_NANOS ) + FD_HISTF_BUCKET_CNT ];
708 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 ];
709 0 : }
710 :
711 0 : stats->verify_drop_cnt = waterfall->out.verify_duplicate +
712 0 : waterfall->out.verify_parse +
713 0 : waterfall->out.verify_failed;
714 0 : stats->verify_total_cnt = waterfall->in.gossip +
715 0 : waterfall->in.quic +
716 0 : waterfall->in.udp -
717 0 : waterfall->out.net_overrun -
718 0 : waterfall->out.tpu_quic_invalid -
719 0 : waterfall->out.tpu_udp_invalid -
720 0 : waterfall->out.quic_abandoned -
721 0 : waterfall->out.quic_frag_drop -
722 0 : waterfall->out.quic_overrun -
723 0 : waterfall->out.verify_overrun;
724 0 : stats->dedup_drop_cnt = waterfall->out.dedup_duplicate;
725 0 : stats->dedup_total_cnt = stats->verify_total_cnt -
726 0 : waterfall->out.verify_duplicate -
727 0 : waterfall->out.verify_parse -
728 0 : waterfall->out.verify_failed;
729 :
730 0 : fd_topo_tile_t const * pack = &topo->tiles[ fd_topo_find_tile( topo, "pack", 0UL ) ];
731 0 : volatile ulong const * pack_metrics = fd_metrics_tile( pack->metrics );
732 0 : stats->pack_buffer_cnt = pack_metrics[ MIDX( GAUGE, PACK, AVAILABLE_TRANSACTIONS ) ];
733 0 : stats->pack_buffer_capacity = pack->pack.max_pending_transactions;
734 :
735 0 : stats->bank_txn_exec_cnt = waterfall->out.block_fail + waterfall->out.block_success;
736 0 : }
737 :
738 : static void
739 0 : fd_gui_run_boot_progress( fd_gui_t * gui, long now ) {
740 0 : fd_topo_tile_t const * snapct = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapct", 0UL ) ];
741 0 : volatile ulong * snapct_metrics = fd_metrics_tile( snapct->metrics );
742 :
743 0 : fd_topo_tile_t const * snapdc = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapdc", 0UL ) ];
744 0 : volatile ulong * snapdc_metrics = fd_metrics_tile( snapdc->metrics );
745 :
746 0 : fd_topo_tile_t const * snapin = &gui->topo->tiles[ fd_topo_find_tile( gui->topo, "snapin", 0UL ) ];
747 0 : volatile ulong * snapin_metrics = fd_metrics_tile( snapin->metrics );
748 :
749 0 : ulong snapshot_phase = snapct_metrics[ MIDX( GAUGE, SNAPCT, STATE ) ];
750 :
751 : /* state transitions */
752 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up!=ULONG_MAX ) ) {
753 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_RUNNING;
754 0 : } else if( FD_LIKELY( snapshot_phase == FD_SNAPCT_STATE_SHUTDOWN && gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && gui->summary.slot_completed!=ULONG_MAX ) ) {
755 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP;
756 0 : } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_FULL_FILE
757 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_FILE
758 0 : || snapshot_phase==FD_SNAPCT_STATE_READING_FULL_HTTP
759 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_FULL_HTTP ) ) {
760 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT;
761 0 : } else if( FD_LIKELY( snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_FILE
762 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE
763 0 : || snapshot_phase==FD_SNAPCT_STATE_READING_INCREMENTAL_HTTP
764 0 : || snapshot_phase==FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP ) ) {
765 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
766 0 : }
767 :
768 : /* It's possible for the incremental snapshot phase to be skipped, or
769 : complete before we can sample it. This ensures we always get at
770 : least one pass of the metrics. */
771 0 : if( FD_UNLIKELY( gui->summary.boot_progress.phase==FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP
772 0 : && gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].reset_cnt==ULONG_MAX ) ) {
773 0 : gui->summary.boot_progress.phase = FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT;
774 0 : }
775 :
776 0 : switch ( gui->summary.boot_progress.phase ) {
777 0 : case FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP: {
778 0 : gui->summary.boot_progress.joining_gossip_time_nanos = now;
779 0 : break;
780 0 : }
781 0 : case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT:
782 0 : case FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT: {
783 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 );
784 0 : ulong _retry_cnt = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_DOWNLOAD_RETRIES ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_DOWNLOAD_RETRIES ) ]);
785 :
786 : /* reset boot state if necessary */
787 0 : if( FD_UNLIKELY( gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt!=_retry_cnt ) ) {
788 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_time_nanos = now;
789 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].reset_cnt = _retry_cnt;
790 0 : }
791 :
792 0 : ulong _total_bytes = fd_ulong_if( snapshot_idx==FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX, snapct_metrics[ MIDX( GAUGE, SNAPCT, FULL_BYTES_TOTAL ) ], snapct_metrics[ MIDX( GAUGE, SNAPCT, INCREMENTAL_BYTES_TOTAL ) ] );
793 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 ) ] );
794 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 ) ] );
795 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 ) ] );
796 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 ) ] );
797 0 : ulong _insert_accounts = snapin_metrics[ MIDX( GAUGE, SNAPIN, ACCOUNTS_INSERTED ) ];
798 :
799 : /* metadata */
800 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].total_bytes_compressed = _total_bytes;
801 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].sample_time_nanos = now;
802 :
803 : /* read stage */
804 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].read_bytes_compressed = _read_bytes;
805 :
806 : /* decompress stage */
807 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_compressed = _decompress_compressed_bytes;
808 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].decompress_bytes_decompressed = _decompress_decompressed_bytes;
809 :
810 : /* insert stage */
811 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_bytes_decompressed = _insert_bytes;
812 :
813 : /* Use the latest compression ratio to estimate decompressed size */
814 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].insert_accounts_current = _insert_accounts;
815 :
816 0 : break;
817 0 : }
818 0 : case FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP: {
819 0 : gui->summary.boot_progress.catching_up_time_nanos = now;
820 0 : break;
821 0 : }
822 0 : case FD_GUI_BOOT_PROGRESS_TYPE_RUNNING: break;
823 0 : default: FD_LOG_ERR(( "unknown boot progress phase: %d", gui->summary.boot_progress.phase ));
824 0 : }
825 0 : }
826 :
827 : int
828 0 : fd_gui_poll( fd_gui_t * gui, long now ) {
829 0 : int did_work = 0;
830 :
831 0 : if( FD_LIKELY( now>gui->next_sample_400millis ) ) {
832 0 : fd_gui_estimated_tps_snap( gui );
833 0 : fd_gui_printf_estimated_tps( gui );
834 0 : fd_http_server_ws_broadcast( gui->http );
835 :
836 0 : gui->next_sample_400millis += 400L*1000L*1000L;
837 0 : did_work = 1;
838 0 : }
839 :
840 0 : if( FD_LIKELY( now>gui->next_sample_100millis ) ) {
841 0 : fd_gui_txn_waterfall_snap( gui, gui->summary.txn_waterfall_current );
842 0 : fd_gui_printf_live_txn_waterfall( gui, gui->summary.txn_waterfall_reference, gui->summary.txn_waterfall_current, 0UL /* TODO: REAL NEXT LEADER SLOT */ );
843 0 : fd_http_server_ws_broadcast( gui->http );
844 :
845 0 : fd_gui_network_stats_snap( gui, gui->summary.network_stats_current );
846 0 : fd_gui_printf_live_network_metrics( gui, gui->summary.network_stats_current );
847 0 : fd_http_server_ws_broadcast( gui->http );
848 :
849 0 : *gui->summary.tile_stats_reference = *gui->summary.tile_stats_current;
850 0 : fd_gui_tile_stats_snap( gui, gui->summary.txn_waterfall_current, gui->summary.tile_stats_current, now );
851 0 : fd_gui_printf_live_tile_stats( gui, gui->summary.tile_stats_reference, gui->summary.tile_stats_current );
852 0 : fd_http_server_ws_broadcast( gui->http );
853 :
854 0 : if( FD_UNLIKELY( gui->summary.is_full_client && gui->summary.boot_progress.phase!=FD_GUI_BOOT_PROGRESS_TYPE_RUNNING ) ) {
855 0 : fd_gui_run_boot_progress( gui, now );
856 0 : fd_gui_printf_boot_progress( gui );
857 0 : fd_http_server_ws_broadcast( gui->http );
858 0 : }
859 :
860 0 : gui->next_sample_100millis += 100L*1000L*1000L;
861 0 : did_work = 1;
862 0 : }
863 :
864 0 : if( FD_LIKELY( now>gui->next_sample_10millis ) ) {
865 0 : fd_gui_tile_timers_snap( gui );
866 :
867 0 : fd_gui_printf_live_tile_timers( gui );
868 0 : fd_http_server_ws_broadcast( gui->http );
869 :
870 0 : fd_gui_printf_live_tile_metrics( gui );
871 0 : fd_http_server_ws_broadcast( gui->http );
872 :
873 0 : fd_gui_scheduler_counts_snap( gui, now );
874 :
875 0 : if( FD_LIKELY( gui->summary.is_full_client && gui->shreds.staged_next_broadcast<gui->shreds.staged_tail ) ) {
876 0 : fd_gui_printf_shred_updates( gui );
877 0 : fd_http_server_ws_broadcast( gui->http );
878 0 : gui->shreds.staged_next_broadcast = gui->shreds.staged_tail;
879 0 : }
880 :
881 0 : gui->next_sample_10millis += 10L*1000L*1000L;
882 0 : did_work = 1;
883 0 : }
884 :
885 0 : return did_work;
886 0 : }
887 :
888 : static void
889 : fd_gui_handle_gossip_update( fd_gui_t * gui,
890 0 : uchar const * msg ) {
891 : /* `gui->gossip.peer_cnt` is guaranteed to be in [0, FD_GUI_MAX_PEER_CNT], because
892 : `peer_cnt` is FD_TEST-ed to be less than or equal FD_GUI_MAX_PEER_CNT.
893 : For every new peer that is added an existing peer will be removed or was still free.
894 : And adding a new peer is done at most `peer_cnt` times. */
895 0 : ulong const * header = (ulong const *)fd_type_pun_const( msg );
896 0 : ulong peer_cnt = header[ 0 ];
897 :
898 0 : FD_TEST( peer_cnt<=FD_GUI_MAX_PEER_CNT );
899 :
900 0 : ulong added_cnt = 0UL;
901 0 : ulong added[ FD_GUI_MAX_PEER_CNT ] = {0};
902 :
903 0 : ulong update_cnt = 0UL;
904 0 : ulong updated[ FD_GUI_MAX_PEER_CNT ] = {0};
905 :
906 0 : ulong removed_cnt = 0UL;
907 0 : fd_pubkey_t removed[ FD_GUI_MAX_PEER_CNT ] = {0};
908 :
909 0 : uchar const * data = (uchar const *)(header+1UL);
910 0 : for( ulong i=0UL; i<gui->gossip.peer_cnt; i++ ) {
911 0 : int found = 0;
912 0 : for( ulong j=0UL; j<peer_cnt; j++ ) {
913 0 : if( FD_UNLIKELY( !memcmp( gui->gossip.peers[ i ].pubkey, data+j*(58UL+12UL*6UL), 32UL ) ) ) {
914 0 : found = 1;
915 0 : break;
916 0 : }
917 0 : }
918 :
919 0 : if( FD_UNLIKELY( !found ) ) {
920 0 : fd_memcpy( removed[ removed_cnt++ ].uc, gui->gossip.peers[ i ].pubkey->uc, 32UL );
921 0 : if( FD_LIKELY( i+1UL!=gui->gossip.peer_cnt ) ) {
922 0 : gui->gossip.peers[ i ] = gui->gossip.peers[ gui->gossip.peer_cnt-1UL ];
923 0 : i--;
924 0 : }
925 0 : gui->gossip.peer_cnt--;
926 0 : }
927 0 : }
928 :
929 0 : ulong before_peer_cnt = gui->gossip.peer_cnt;
930 0 : for( ulong i=0UL; i<peer_cnt; i++ ) {
931 0 : int found = 0;
932 0 : ulong found_idx = 0;
933 0 : for( ulong j=0UL; j<gui->gossip.peer_cnt; j++ ) {
934 0 : if( FD_UNLIKELY( !memcmp( gui->gossip.peers[ j ].pubkey, data+i*(58UL+12UL*6UL), 32UL ) ) ) {
935 0 : found_idx = j;
936 0 : found = 1;
937 0 : break;
938 0 : }
939 0 : }
940 :
941 0 : if( FD_UNLIKELY( !found ) ) {
942 0 : fd_memcpy( gui->gossip.peers[ gui->gossip.peer_cnt ].pubkey->uc, data+i*(58UL+12UL*6UL), 32UL );
943 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].wallclock = *(ulong const *)(data+i*(58UL+12UL*6UL)+32UL);
944 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].shred_version = *(ushort const *)(data+i*(58UL+12UL*6UL)+40UL);
945 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].has_version = *(data+i*(58UL+12UL*6UL)+42UL);
946 0 : if( FD_LIKELY( gui->gossip.peers[ gui->gossip.peer_cnt ].has_version ) ) {
947 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.major = *(ushort const *)(data+i*(58UL+12UL*6UL)+43UL);
948 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.minor = *(ushort const *)(data+i*(58UL+12UL*6UL)+45UL);
949 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.patch = *(ushort const *)(data+i*(58UL+12UL*6UL)+47UL);
950 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.has_commit = *(data+i*(58UL+12UL*6UL)+49UL);
951 0 : if( FD_LIKELY( gui->gossip.peers[ gui->gossip.peer_cnt ].version.has_commit ) ) {
952 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.commit = *(uint const *)(data+i*(58UL+12UL*6UL)+50UL);
953 0 : }
954 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].version.feature_set = *(uint const *)(data+i*(58UL+12UL*6UL)+54UL);
955 0 : }
956 :
957 0 : for( ulong j=0UL; j<12UL; j++ ) {
958 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].sockets[ j ].ipv4 = *(uint const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL);
959 0 : gui->gossip.peers[ gui->gossip.peer_cnt ].sockets[ j ].port = *(ushort const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL+4UL);
960 0 : }
961 :
962 0 : gui->gossip.peer_cnt++;
963 0 : } else {
964 0 : int peer_updated = gui->gossip.peers[ found_idx ].shred_version!=*(ushort const *)(data+i*(58UL+12UL*6UL)+40UL) ||
965 : // gui->gossip.peers[ found_idx ].wallclock!=*(ulong const *)(data+i*(58UL+12UL*6UL)+32UL) ||
966 0 : gui->gossip.peers[ found_idx ].has_version!=*(data+i*(58UL+12UL*6UL)+42UL);
967 :
968 0 : if( FD_LIKELY( !peer_updated && gui->gossip.peers[ found_idx ].has_version ) ) {
969 0 : peer_updated = gui->gossip.peers[ found_idx ].version.major!=*(ushort const *)(data+i*(58UL+12UL*6UL)+43UL) ||
970 0 : gui->gossip.peers[ found_idx ].version.minor!=*(ushort const *)(data+i*(58UL+12UL*6UL)+45UL) ||
971 0 : gui->gossip.peers[ found_idx ].version.patch!=*(ushort const *)(data+i*(58UL+12UL*6UL)+47UL) ||
972 0 : gui->gossip.peers[ found_idx ].version.has_commit!=*(data+i*(58UL+12UL*6UL)+49UL) ||
973 0 : (gui->gossip.peers[ found_idx ].version.has_commit && gui->gossip.peers[ found_idx ].version.commit!=*(uint const *)(data+i*(58UL+12UL*6UL)+50UL)) ||
974 0 : gui->gossip.peers[ found_idx ].version.feature_set!=*(uint const *)(data+i*(58UL+12UL*6UL)+54UL);
975 0 : }
976 :
977 0 : if( FD_LIKELY( !peer_updated ) ) {
978 0 : for( ulong j=0UL; j<12UL; j++ ) {
979 0 : peer_updated = gui->gossip.peers[ found_idx ].sockets[ j ].ipv4!=*(uint const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL) ||
980 0 : gui->gossip.peers[ found_idx ].sockets[ j ].port!=*(ushort const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL+4UL);
981 0 : if( FD_LIKELY( peer_updated ) ) break;
982 0 : }
983 0 : }
984 :
985 0 : if( FD_UNLIKELY( peer_updated ) ) {
986 0 : updated[ update_cnt++ ] = found_idx;
987 0 : gui->gossip.peers[ found_idx ].shred_version = *(ushort const *)(data+i*(58UL+12UL*6UL)+40UL);
988 0 : gui->gossip.peers[ found_idx ].wallclock = *(ulong const *)(data+i*(58UL+12UL*6UL)+32UL);
989 0 : gui->gossip.peers[ found_idx ].has_version = *(data+i*(58UL+12UL*6UL)+42UL);
990 0 : if( FD_LIKELY( gui->gossip.peers[ found_idx ].has_version ) ) {
991 0 : gui->gossip.peers[ found_idx ].version.major = *(ushort const *)(data+i*(58UL+12UL*6UL)+43UL);
992 0 : gui->gossip.peers[ found_idx ].version.minor = *(ushort const *)(data+i*(58UL+12UL*6UL)+45UL);
993 0 : gui->gossip.peers[ found_idx ].version.patch = *(ushort const *)(data+i*(58UL+12UL*6UL)+47UL);
994 0 : gui->gossip.peers[ found_idx ].version.has_commit = *(data+i*(58UL+12UL*6UL)+49UL);
995 0 : if( FD_LIKELY( gui->gossip.peers[ found_idx ].version.has_commit ) ) {
996 0 : gui->gossip.peers[ found_idx ].version.commit = *(uint const *)(data+i*(58UL+12UL*6UL)+50UL);
997 0 : }
998 0 : gui->gossip.peers[ found_idx ].version.feature_set = *(uint const *)(data+i*(58UL+12UL*6UL)+54UL);
999 0 : }
1000 :
1001 0 : for( ulong j=0UL; j<12UL; j++ ) {
1002 0 : gui->gossip.peers[ found_idx ].sockets[ j ].ipv4 = *(uint const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL);
1003 0 : gui->gossip.peers[ found_idx ].sockets[ j ].port = *(ushort const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL+4UL);
1004 0 : }
1005 0 : }
1006 0 : }
1007 0 : }
1008 :
1009 0 : added_cnt = gui->gossip.peer_cnt - before_peer_cnt;
1010 0 : for( ulong i=before_peer_cnt; i<gui->gossip.peer_cnt; i++ ) added[ i-before_peer_cnt ] = i;
1011 :
1012 0 : fd_gui_printf_peers_gossip_update( gui, updated, update_cnt, removed, removed_cnt, added, added_cnt );
1013 0 : fd_http_server_ws_broadcast( gui->http );
1014 0 : }
1015 :
1016 : static void
1017 : fd_gui_handle_vote_account_update( fd_gui_t * gui,
1018 0 : uchar const * msg ) {
1019 : /* See fd_gui_handle_gossip_update for why `gui->vote_account.vote_account_cnt`
1020 : is guaranteed to be in [0, FD_GUI_MAX_PEER_CNT]. */
1021 0 : ulong const * header = (ulong const *)fd_type_pun_const( msg );
1022 0 : ulong peer_cnt = header[ 0 ];
1023 :
1024 0 : FD_TEST( peer_cnt<=FD_GUI_MAX_PEER_CNT );
1025 :
1026 0 : ulong added_cnt = 0UL;
1027 0 : ulong added[ FD_GUI_MAX_PEER_CNT ] = {0};
1028 :
1029 0 : ulong update_cnt = 0UL;
1030 0 : ulong updated[ FD_GUI_MAX_PEER_CNT ] = {0};
1031 :
1032 0 : ulong removed_cnt = 0UL;
1033 0 : fd_pubkey_t removed[ FD_GUI_MAX_PEER_CNT ] = {0};
1034 :
1035 0 : uchar const * data = (uchar const *)(header+1UL);
1036 0 : for( ulong i=0UL; i<gui->vote_account.vote_account_cnt; i++ ) {
1037 0 : int found = 0;
1038 0 : for( ulong j=0UL; j<peer_cnt; j++ ) {
1039 0 : if( FD_UNLIKELY( !memcmp( gui->vote_account.vote_accounts[ i ].vote_account, data+j*112UL, 32UL ) ) ) {
1040 0 : found = 1;
1041 0 : break;
1042 0 : }
1043 0 : }
1044 :
1045 0 : if( FD_UNLIKELY( !found ) ) {
1046 0 : fd_memcpy( removed[ removed_cnt++ ].uc, gui->vote_account.vote_accounts[ i ].vote_account->uc, 32UL );
1047 0 : if( FD_LIKELY( i+1UL!=gui->vote_account.vote_account_cnt ) ) {
1048 0 : gui->vote_account.vote_accounts[ i ] = gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt-1UL ];
1049 0 : i--;
1050 0 : }
1051 0 : gui->vote_account.vote_account_cnt--;
1052 0 : }
1053 0 : }
1054 :
1055 0 : ulong before_peer_cnt = gui->vote_account.vote_account_cnt;
1056 0 : for( ulong i=0UL; i<peer_cnt; i++ ) {
1057 0 : int found = 0;
1058 0 : ulong found_idx;
1059 0 : for( ulong j=0UL; j<gui->vote_account.vote_account_cnt; j++ ) {
1060 0 : if( FD_UNLIKELY( !memcmp( gui->vote_account.vote_accounts[ j ].vote_account, data+i*112UL, 32UL ) ) ) {
1061 0 : found_idx = j;
1062 0 : found = 1;
1063 0 : break;
1064 0 : }
1065 0 : }
1066 :
1067 0 : if( FD_UNLIKELY( !found ) ) {
1068 0 : fd_memcpy( gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].vote_account->uc, data+i*112UL, 32UL );
1069 0 : fd_memcpy( gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].pubkey->uc, data+i*112UL+32UL, 32UL );
1070 :
1071 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].activated_stake = *(ulong const *)(data+i*112UL+64UL);
1072 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].last_vote = *(ulong const *)(data+i*112UL+72UL);
1073 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].root_slot = *(ulong const *)(data+i*112UL+80UL);
1074 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].epoch_credits = *(ulong const *)(data+i*112UL+88UL);
1075 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].commission = *(data+i*112UL+96UL);
1076 0 : gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].delinquent = *(data+i*112UL+97UL);
1077 :
1078 0 : gui->vote_account.vote_account_cnt++;
1079 0 : } else {
1080 0 : int peer_updated =
1081 0 : memcmp( gui->vote_account.vote_accounts[ found_idx ].pubkey->uc, data+i*112UL+32UL, 32UL ) ||
1082 0 : gui->vote_account.vote_accounts[ found_idx ].activated_stake != *(ulong const *)(data+i*112UL+64UL) ||
1083 : // gui->vote_account.vote_accounts[ found_idx ].last_vote != *(ulong const *)(data+i*112UL+72UL) ||
1084 : // gui->vote_account.vote_accounts[ found_idx ].root_slot != *(ulong const *)(data+i*112UL+80UL) ||
1085 : // gui->vote_account.vote_accounts[ found_idx ].epoch_credits != *(ulong const *)(data+i*112UL+88UL) ||
1086 0 : gui->vote_account.vote_accounts[ found_idx ].commission != *(data+i*112UL+96UL) ||
1087 0 : gui->vote_account.vote_accounts[ found_idx ].delinquent != *(data+i*112UL+97UL);
1088 :
1089 0 : if( FD_UNLIKELY( peer_updated ) ) {
1090 0 : updated[ update_cnt++ ] = found_idx;
1091 :
1092 0 : fd_memcpy( gui->vote_account.vote_accounts[ found_idx ].pubkey->uc, data+i*112UL+32UL, 32UL );
1093 0 : gui->vote_account.vote_accounts[ found_idx ].activated_stake = *(ulong const *)(data+i*112UL+64UL);
1094 0 : gui->vote_account.vote_accounts[ found_idx ].last_vote = *(ulong const *)(data+i*112UL+72UL);
1095 0 : gui->vote_account.vote_accounts[ found_idx ].root_slot = *(ulong const *)(data+i*112UL+80UL);
1096 0 : gui->vote_account.vote_accounts[ found_idx ].epoch_credits = *(ulong const *)(data+i*112UL+88UL);
1097 0 : gui->vote_account.vote_accounts[ found_idx ].commission = *(data+i*112UL+96UL);
1098 0 : gui->vote_account.vote_accounts[ found_idx ].delinquent = *(data+i*112UL+97UL);
1099 0 : }
1100 0 : }
1101 0 : }
1102 :
1103 0 : added_cnt = gui->vote_account.vote_account_cnt - before_peer_cnt;
1104 0 : for( ulong i=before_peer_cnt; i<gui->vote_account.vote_account_cnt; i++ ) added[ i-before_peer_cnt ] = i;
1105 :
1106 0 : fd_gui_printf_peers_vote_account_update( gui, updated, update_cnt, removed, removed_cnt, added, added_cnt );
1107 0 : fd_http_server_ws_broadcast( gui->http );
1108 0 : }
1109 :
1110 : static void
1111 : fd_gui_handle_validator_info_update( fd_gui_t * gui,
1112 0 : uchar const * msg ) {
1113 0 : if( FD_UNLIKELY( gui->validator_info.info_cnt == FD_GUI_MAX_PEER_CNT ) ) {
1114 0 : FD_LOG_DEBUG(("validator info cnt exceeds 40200 %lu, ignoring additional entries", gui->validator_info.info_cnt ));
1115 0 : return;
1116 0 : }
1117 0 : uchar const * data = (uchar const *)fd_type_pun_const( msg );
1118 :
1119 0 : ulong added_cnt = 0UL;
1120 0 : ulong added[ 1 ] = {0};
1121 :
1122 0 : ulong update_cnt = 0UL;
1123 0 : ulong updated[ 1 ] = {0};
1124 :
1125 0 : ulong removed_cnt = 0UL;
1126 : /* Unlike gossip or vote account updates, validator info messages come
1127 : in as info is discovered, and may contain as little as 1 validator
1128 : per message. Therefore, it doesn't make sense to use the remove
1129 : mechanism. */
1130 :
1131 0 : ulong before_peer_cnt = gui->validator_info.info_cnt;
1132 0 : int found = 0;
1133 0 : ulong found_idx;
1134 0 : for( ulong j=0UL; j<gui->validator_info.info_cnt; j++ ) {
1135 0 : if( FD_UNLIKELY( !memcmp( gui->validator_info.info[ j ].pubkey, data, 32UL ) ) ) {
1136 0 : found_idx = j;
1137 0 : found = 1;
1138 0 : break;
1139 0 : }
1140 0 : }
1141 :
1142 0 : if( FD_UNLIKELY( !found ) ) {
1143 0 : fd_memcpy( gui->validator_info.info[ gui->validator_info.info_cnt ].pubkey->uc, data, 32UL );
1144 :
1145 0 : strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].name, (char const *)(data+32UL), 64 );
1146 0 : gui->validator_info.info[ gui->validator_info.info_cnt ].name[ 63 ] = '\0';
1147 :
1148 0 : strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].website, (char const *)(data+96UL), 128 );
1149 0 : gui->validator_info.info[ gui->validator_info.info_cnt ].website[ 127 ] = '\0';
1150 :
1151 0 : strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].details, (char const *)(data+224UL), 256 );
1152 0 : gui->validator_info.info[ gui->validator_info.info_cnt ].details[ 255 ] = '\0';
1153 :
1154 0 : strncpy( gui->validator_info.info[ gui->validator_info.info_cnt ].icon_uri, (char const *)(data+480UL), 128 );
1155 0 : gui->validator_info.info[ gui->validator_info.info_cnt ].icon_uri[ 127 ] = '\0';
1156 :
1157 0 : gui->validator_info.info_cnt++;
1158 0 : } else {
1159 0 : int peer_updated =
1160 0 : memcmp( gui->validator_info.info[ found_idx ].pubkey->uc, data, 32UL ) ||
1161 0 : strncmp( gui->validator_info.info[ found_idx ].name, (char const *)(data+32UL), 64 ) ||
1162 0 : strncmp( gui->validator_info.info[ found_idx ].website, (char const *)(data+96UL), 128 ) ||
1163 0 : strncmp( gui->validator_info.info[ found_idx ].details, (char const *)(data+224UL), 256 ) ||
1164 0 : strncmp( gui->validator_info.info[ found_idx ].icon_uri, (char const *)(data+480UL), 128 );
1165 :
1166 0 : if( FD_UNLIKELY( peer_updated ) ) {
1167 0 : updated[ update_cnt++ ] = found_idx;
1168 :
1169 0 : fd_memcpy( gui->validator_info.info[ found_idx ].pubkey->uc, data, 32UL );
1170 :
1171 0 : strncpy( gui->validator_info.info[ found_idx ].name, (char const *)(data+32UL), 64 );
1172 0 : gui->validator_info.info[ found_idx ].name[ 63 ] = '\0';
1173 :
1174 0 : strncpy( gui->validator_info.info[ found_idx ].website, (char const *)(data+96UL), 128 );
1175 0 : gui->validator_info.info[ found_idx ].website[ 127 ] = '\0';
1176 :
1177 0 : strncpy( gui->validator_info.info[ found_idx ].details, (char const *)(data+224UL), 256 );
1178 0 : gui->validator_info.info[ found_idx ].details[ 255 ] = '\0';
1179 :
1180 0 : strncpy( gui->validator_info.info[ found_idx ].icon_uri, (char const *)(data+480UL), 128 );
1181 0 : gui->validator_info.info[ found_idx ].icon_uri[ 127 ] = '\0';
1182 0 : }
1183 0 : }
1184 :
1185 0 : added_cnt = gui->validator_info.info_cnt - before_peer_cnt;
1186 0 : for( ulong i=before_peer_cnt; i<gui->validator_info.info_cnt; i++ ) added[ i-before_peer_cnt ] = i;
1187 :
1188 0 : fd_gui_printf_peers_validator_info_update( gui, updated, update_cnt, NULL, removed_cnt, added, added_cnt );
1189 0 : fd_http_server_ws_broadcast( gui->http );
1190 0 : }
1191 :
1192 : int
1193 : fd_gui_request_slot( fd_gui_t * gui,
1194 : ulong ws_conn_id,
1195 : ulong request_id,
1196 0 : cJSON const * params ) {
1197 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1198 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1199 :
1200 0 : ulong _slot = slot_param->valueulong;
1201 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
1202 0 : if( FD_UNLIKELY( !slot ) ) {
1203 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query", request_id );
1204 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1205 0 : return 0;
1206 0 : }
1207 :
1208 0 : fd_gui_printf_slot_request( gui, _slot, request_id );
1209 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1210 0 : return 0;
1211 0 : }
1212 :
1213 : int
1214 : fd_gui_request_slot_transactions( fd_gui_t * gui,
1215 : ulong ws_conn_id,
1216 : ulong request_id,
1217 0 : cJSON const * params ) {
1218 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1219 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1220 :
1221 0 : ulong _slot = slot_param->valueulong;
1222 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
1223 0 : if( FD_UNLIKELY( !slot ) ) {
1224 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query", request_id );
1225 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1226 0 : return 0;
1227 0 : }
1228 :
1229 0 : fd_gui_printf_slot_transactions_request( gui, _slot, request_id );
1230 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1231 0 : return 0;
1232 0 : }
1233 :
1234 : int
1235 : fd_gui_request_slot_detailed( fd_gui_t * gui,
1236 : ulong ws_conn_id,
1237 : ulong request_id,
1238 0 : cJSON const * params ) {
1239 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1240 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1241 :
1242 0 : ulong _slot = slot_param->valueulong;
1243 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, _slot );
1244 0 : if( FD_UNLIKELY( !slot ) ) {
1245 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query", request_id );
1246 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1247 0 : return 0;
1248 0 : }
1249 :
1250 0 : fd_gui_printf_slot_request_detailed( gui, _slot, request_id );
1251 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1252 0 : return 0;
1253 0 : }
1254 :
1255 : static inline ulong
1256 0 : fd_gui_slot_duration( fd_gui_t const * gui, fd_gui_slot_t const * cur ) {
1257 0 : fd_gui_slot_t const * prev = fd_gui_get_slot_const( gui, cur->slot-1UL );
1258 0 : if( FD_UNLIKELY( !prev ||
1259 0 : prev->skipped ||
1260 0 : prev->completed_time == LONG_MAX ||
1261 0 : prev->slot != (cur->slot - 1UL) ||
1262 0 : cur->skipped ||
1263 0 : cur->completed_time == LONG_MAX ) ) return ULONG_MAX;
1264 :
1265 0 : return (ulong)(cur->completed_time - prev->completed_time);
1266 0 : }
1267 :
1268 : /* All rankings are initialized / reset to ULONG_MAX. These sentinels
1269 : sort AFTER non-sentinel ranking entries. Equal slots are sorted by
1270 : oldest slot AFTER. Otherwise sort by value according to ranking
1271 : type. */
1272 : #define SORT_NAME fd_gui_slot_ranking_sort
1273 0 : #define SORT_KEY_T fd_gui_slot_ranking_t
1274 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 ) ) ) )
1275 : #include "../../util/tmpl/fd_sort.c"
1276 :
1277 : static inline void
1278 : fd_gui_try_insert_ranking( fd_gui_t * gui,
1279 : fd_gui_slot_rankings_t * rankings,
1280 0 : fd_gui_slot_t const * slot ) {
1281 : /* Rankings are inserted into an extra slot at the end of the ranking
1282 : array, then the array is sorted. */
1283 0 : #define TRY_INSERT_SLOT( ranking_name, ranking_slot, ranking_value ) \
1284 0 : do { \
1285 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 }; \
1286 0 : fd_gui_slot_ranking_sort_insert( rankings->FD_CONCAT2(largest_, ranking_name), FD_GUI_SLOT_RANKINGS_SZ+1UL ); \
1287 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 }; \
1288 0 : fd_gui_slot_ranking_sort_insert( rankings->FD_CONCAT2(smallest_, ranking_name), FD_GUI_SLOT_RANKINGS_SZ+1UL ); \
1289 0 : } while (0)
1290 :
1291 0 : if( slot->skipped ) {
1292 0 : TRY_INSERT_SLOT( skipped, slot->slot, slot->slot );
1293 0 : return;
1294 0 : }
1295 :
1296 0 : ulong dur = fd_gui_slot_duration( gui, slot );
1297 0 : if( FD_LIKELY( dur!=ULONG_MAX ) ) TRY_INSERT_SLOT( duration, slot->slot, dur );
1298 0 : TRY_INSERT_SLOT( tips, slot->slot, slot->tips );
1299 0 : TRY_INSERT_SLOT( fees, slot->slot, slot->priority_fee + slot->transaction_fee );
1300 0 : TRY_INSERT_SLOT( rewards, slot->slot, slot->tips + slot->priority_fee + slot->transaction_fee );
1301 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 );
1302 0 : TRY_INSERT_SLOT( compute_units, slot->slot, slot->compute_units );
1303 0 : #undef TRY_INSERT_SLOT
1304 0 : }
1305 :
1306 : static void
1307 0 : fd_gui_update_slot_rankings( fd_gui_t * gui ) {
1308 0 : ulong first_replay_slot = ULONG_MAX;
1309 0 : if( FD_LIKELY( gui->summary.is_full_client ) ) {
1310 0 : ulong slot_caught_up = gui->summary.slot_caught_up;
1311 0 : ulong slot_incremental = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX ].slot;
1312 0 : ulong slot_full = gui->summary.boot_progress.loading_snapshot[ FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX ].slot;
1313 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 );
1314 0 : } else {
1315 0 : first_replay_slot = gui->summary.startup_progress.startup_ledger_max_slot;
1316 0 : }
1317 0 : if( FD_UNLIKELY( first_replay_slot==ULONG_MAX ) ) return;
1318 0 : if( FD_UNLIKELY( gui->summary.slot_rooted ==ULONG_MAX ) ) return;
1319 :
1320 0 : ulong epoch_start_slot = ULONG_MAX;
1321 0 : ulong epoch = ULONG_MAX;
1322 0 : for( ulong i = 0UL; i<2UL; i++ ) {
1323 0 : if( FD_LIKELY( gui->epoch.has_epoch[ i ] ) ) {
1324 : /* the "current" epoch is the smallest */
1325 0 : epoch_start_slot = fd_ulong_min( epoch_start_slot, gui->epoch.epochs[ i ].start_slot );
1326 0 : epoch = fd_ulong_min( epoch, gui->epoch.epochs[ i ].epoch );
1327 0 : }
1328 0 : }
1329 :
1330 0 : if( FD_UNLIKELY( epoch==ULONG_MAX ) ) return;
1331 0 : ulong epoch_idx = epoch % 2UL;
1332 :
1333 : /* No new slots since the last update */
1334 0 : if( FD_UNLIKELY( gui->epoch.epochs[ epoch_idx ].rankings_slot>gui->summary.slot_rooted ) ) return;
1335 :
1336 : /* Slots before first_replay_slot are unavailable. */
1337 0 : gui->epoch.epochs[ epoch_idx ].rankings_slot = fd_ulong_max( gui->epoch.epochs[ epoch_idx ].rankings_slot, first_replay_slot );
1338 :
1339 : /* Update the rankings. Only look through slots we haven't already. */
1340 0 : for( ulong s = gui->summary.slot_rooted; s>=gui->epoch.epochs[ epoch_idx ].rankings_slot; s--) {
1341 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, s );
1342 0 : if( FD_UNLIKELY( !slot ) ) break;
1343 :
1344 0 : fd_gui_try_insert_ranking( gui, gui->epoch.epochs[ epoch_idx ].rankings, slot );
1345 0 : if( FD_UNLIKELY( slot->mine ) ) fd_gui_try_insert_ranking( gui, gui->epoch.epochs[ epoch_idx ].my_rankings, slot );
1346 0 : }
1347 :
1348 0 : gui->epoch.epochs[ epoch_idx ].rankings_slot = gui->summary.slot_rooted + 1UL;
1349 0 : }
1350 :
1351 : int
1352 : fd_gui_request_slot_rankings( fd_gui_t * gui,
1353 : ulong ws_conn_id,
1354 : ulong request_id,
1355 0 : cJSON const * params ) {
1356 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "mine" );
1357 0 : if( FD_UNLIKELY( !cJSON_IsBool( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1358 :
1359 0 : int mine = !!(slot_param->type & cJSON_True);
1360 0 : fd_gui_update_slot_rankings( gui );
1361 0 : fd_gui_printf_slot_rankings_request( gui, request_id, mine );
1362 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1363 0 : return 0;
1364 0 : }
1365 :
1366 : int
1367 : fd_gui_request_slot_shreds( fd_gui_t * gui,
1368 : ulong ws_conn_id,
1369 : ulong request_id,
1370 0 : cJSON const * params ) {
1371 0 : const cJSON * slot_param = cJSON_GetObjectItemCaseSensitive( params, "slot" );
1372 0 : if( FD_UNLIKELY( !cJSON_IsNumber( slot_param ) ) ) return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1373 :
1374 0 : ulong _slot = slot_param->valueulong;
1375 :
1376 0 : fd_gui_slot_t const * slot = fd_gui_get_slot( gui, _slot );
1377 0 : if( FD_UNLIKELY( !slot || gui->shreds.history_tail > slot->shreds.end_offset + FD_GUI_SHREDS_HISTORY_SZ ) ) {
1378 0 : fd_gui_printf_null_query_response( gui->http, "slot", "query_shreds", request_id );
1379 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1380 0 : return 0;
1381 0 : }
1382 :
1383 0 : fd_gui_printf_slot_shred_updates( gui, _slot, request_id );
1384 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1385 0 : return 0;
1386 0 : }
1387 :
1388 : int
1389 : fd_gui_ws_message( fd_gui_t * gui,
1390 : ulong ws_conn_id,
1391 : uchar const * data,
1392 0 : ulong data_len ) {
1393 : /* TODO: cJSON allocates, might fail SIGSYS due to brk(2)...
1394 : switch off this (or use wksp allocator) */
1395 0 : const char * parse_end;
1396 0 : cJSON * json = cJSON_ParseWithLengthOpts( (char *)data, data_len, &parse_end, 0 );
1397 0 : if( FD_UNLIKELY( !json ) ) {
1398 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1399 0 : }
1400 :
1401 0 : const cJSON * node = cJSON_GetObjectItemCaseSensitive( json, "id" );
1402 0 : if( FD_UNLIKELY( !cJSON_IsNumber( node ) ) ) {
1403 0 : cJSON_Delete( json );
1404 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1405 0 : }
1406 0 : ulong id = node->valueulong;
1407 :
1408 0 : const cJSON * topic = cJSON_GetObjectItemCaseSensitive( json, "topic" );
1409 0 : if( FD_UNLIKELY( !cJSON_IsString( topic ) || topic->valuestring==NULL ) ) {
1410 0 : cJSON_Delete( json );
1411 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1412 0 : }
1413 :
1414 0 : const cJSON * key = cJSON_GetObjectItemCaseSensitive( json, "key" );
1415 0 : if( FD_UNLIKELY( !cJSON_IsString( key ) || key->valuestring==NULL ) ) {
1416 0 : cJSON_Delete( json );
1417 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1418 0 : }
1419 :
1420 0 : if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query" ) ) ) {
1421 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
1422 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
1423 0 : cJSON_Delete( json );
1424 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1425 0 : }
1426 :
1427 0 : int result = fd_gui_request_slot( gui, ws_conn_id, id, params );
1428 0 : cJSON_Delete( json );
1429 0 : return result;
1430 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_detailed" ) ) ) {
1431 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
1432 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
1433 0 : cJSON_Delete( json );
1434 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1435 0 : }
1436 :
1437 0 : int result = fd_gui_request_slot_detailed( gui, ws_conn_id, id, params );
1438 0 : cJSON_Delete( json );
1439 0 : return result;
1440 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_transactions" ) ) ) {
1441 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
1442 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
1443 0 : cJSON_Delete( json );
1444 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1445 0 : }
1446 :
1447 0 : int result = fd_gui_request_slot_transactions( gui, ws_conn_id, id, params );
1448 0 : cJSON_Delete( json );
1449 0 : return result;
1450 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_rankings" ) ) ) {
1451 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
1452 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
1453 0 : cJSON_Delete( json );
1454 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1455 0 : }
1456 :
1457 0 : int result = fd_gui_request_slot_rankings( gui, ws_conn_id, id, params );
1458 0 : cJSON_Delete( json );
1459 0 : return result;
1460 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "slot" ) && !strcmp( key->valuestring, "query_shreds" ) ) ) {
1461 0 : const cJSON * params = cJSON_GetObjectItemCaseSensitive( json, "params" );
1462 0 : if( FD_UNLIKELY( !cJSON_IsObject( params ) ) ) {
1463 0 : cJSON_Delete( json );
1464 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_BAD_REQUEST;
1465 0 : }
1466 :
1467 0 : int result = fd_gui_request_slot_shreds( gui, ws_conn_id, id, params );
1468 0 : cJSON_Delete( json );
1469 0 : return result;
1470 0 : } else if( FD_LIKELY( !strcmp( topic->valuestring, "summary" ) && !strcmp( key->valuestring, "ping" ) ) ) {
1471 0 : fd_gui_printf_summary_ping( gui, id );
1472 0 : FD_TEST( !fd_http_server_ws_send( gui->http, ws_conn_id ) );
1473 :
1474 0 : cJSON_Delete( json );
1475 0 : return 0;
1476 0 : }
1477 :
1478 0 : cJSON_Delete( json );
1479 0 : return FD_HTTP_SERVER_CONNECTION_CLOSE_UNKNOWN_METHOD;
1480 0 : }
1481 :
1482 : static fd_gui_slot_t *
1483 : fd_gui_clear_slot( fd_gui_t * gui,
1484 : ulong _slot,
1485 0 : ulong _parent_slot ) {
1486 0 : fd_gui_slot_t * slot = gui->slots[ _slot % FD_GUI_SLOTS_CNT ];
1487 :
1488 0 : int mine = 0;
1489 0 : ulong epoch_idx = 0UL;
1490 0 : for( ulong i=0UL; i<2UL; i++) {
1491 0 : if( FD_UNLIKELY( !gui->epoch.has_epoch[ i ] ) ) continue;
1492 0 : if( FD_LIKELY( _slot>=gui->epoch.epochs[ i ].start_slot && _slot<=gui->epoch.epochs[ i ].end_slot ) ) {
1493 0 : fd_pubkey_t const * slot_leader = fd_epoch_leaders_get( gui->epoch.epochs[ i ].lsched, _slot );
1494 0 : mine = !memcmp( slot_leader->uc, gui->summary.identity_key->uc, 32UL );
1495 0 : epoch_idx = i;
1496 0 : break;
1497 0 : }
1498 0 : }
1499 :
1500 0 : slot->slot = _slot;
1501 0 : slot->parent_slot = _parent_slot;
1502 0 : slot->vote_slot = ULONG_MAX;
1503 0 : slot->reset_slot = ULONG_MAX;
1504 0 : slot->max_compute_units = UINT_MAX;
1505 0 : slot->completed_time = LONG_MAX;
1506 0 : slot->mine = mine;
1507 0 : slot->skipped = 0;
1508 0 : slot->must_republish = 1;
1509 0 : slot->level = FD_GUI_SLOT_LEVEL_INCOMPLETE;
1510 0 : slot->total_txn_cnt = UINT_MAX;
1511 0 : slot->vote_txn_cnt = UINT_MAX;
1512 0 : slot->failed_txn_cnt = UINT_MAX;
1513 0 : slot->nonvote_failed_txn_cnt = UINT_MAX;
1514 0 : slot->compute_units = UINT_MAX;
1515 0 : slot->transaction_fee = ULONG_MAX;
1516 0 : slot->priority_fee = ULONG_MAX;
1517 0 : slot->tips = ULONG_MAX;
1518 0 : slot->shred_cnt = UINT_MAX;
1519 0 : slot->shreds.start_offset = ULONG_MAX;
1520 0 : slot->shreds.end_offset = ULONG_MAX;
1521 :
1522 0 : if( FD_LIKELY( slot->mine ) ) {
1523 : /* All slots start off not skipped, until we see it get off the reset
1524 : chain. */
1525 0 : gui->epoch.epochs[ epoch_idx ].my_total_slots++;
1526 :
1527 0 : slot->leader_history_idx = gui->leader_slots_cnt++;
1528 0 : fd_gui_leader_slot_t * lslot = gui->leader_slots[ slot->leader_history_idx % FD_GUI_LEADER_CNT ];
1529 :
1530 0 : lslot->slot = _slot;
1531 0 : memset( lslot->block_hash.uc, 0, sizeof(fd_hash_t) );
1532 0 : lslot->leader_start_time = LONG_MAX;
1533 0 : lslot->leader_end_time = LONG_MAX;
1534 0 : lslot->tile_timers_sample_cnt = 0UL;
1535 0 : lslot->scheduler_counts_sample_cnt = 0UL;
1536 0 : lslot->txs.microblocks_upper_bound = USHORT_MAX;
1537 0 : lslot->txs.begin_microblocks = 0U;
1538 0 : lslot->txs.end_microblocks = 0U;
1539 0 : lslot->txs.start_offset = ULONG_MAX;
1540 0 : lslot->txs.end_offset = ULONG_MAX;
1541 0 : }
1542 :
1543 0 : if( FD_UNLIKELY( !_slot ) ) {
1544 : /* Slot 0 is always rooted */
1545 0 : slot->level = FD_GUI_SLOT_LEVEL_ROOTED;
1546 0 : }
1547 :
1548 0 : return slot;
1549 0 : }
1550 :
1551 : void
1552 : fd_gui_handle_leader_schedule( fd_gui_t * gui,
1553 : fd_stake_weight_msg_t const * leader_schedule,
1554 0 : long now ) {
1555 0 : FD_TEST( leader_schedule->staked_cnt<=MAX_STAKED_LEADERS );
1556 0 : FD_TEST( leader_schedule->slot_cnt<=MAX_SLOTS_PER_EPOCH );
1557 :
1558 0 : ulong idx = leader_schedule->epoch % 2UL;
1559 0 : gui->epoch.has_epoch[ idx ] = 1;
1560 :
1561 0 : gui->epoch.epochs[ idx ].epoch = leader_schedule->epoch;
1562 0 : gui->epoch.epochs[ idx ].start_slot = leader_schedule->start_slot;
1563 0 : gui->epoch.epochs[ idx ].end_slot = leader_schedule->start_slot + leader_schedule->slot_cnt - 1; // end_slot is inclusive.
1564 0 : gui->epoch.epochs[ idx ].excluded_stake = leader_schedule->excluded_stake;
1565 0 : gui->epoch.epochs[ idx ].my_total_slots = 0UL;
1566 0 : gui->epoch.epochs[ idx ].my_skipped_slots = 0UL;
1567 :
1568 0 : memset( gui->epoch.epochs[ idx ].rankings, (int)(UINT_MAX), sizeof(gui->epoch.epochs[ idx ].rankings) );
1569 0 : memset( gui->epoch.epochs[ idx ].my_rankings, (int)(UINT_MAX), sizeof(gui->epoch.epochs[ idx ].my_rankings) );
1570 :
1571 0 : gui->epoch.epochs[ idx ].rankings_slot = leader_schedule->start_slot;
1572 :
1573 0 : fd_vote_stake_weight_t const * stake_weights = leader_schedule->weights;
1574 0 : fd_memcpy( gui->epoch.epochs[ idx ].stakes, stake_weights, leader_schedule->staked_cnt*sizeof(fd_vote_stake_weight_t) );
1575 :
1576 0 : fd_epoch_leaders_delete( fd_epoch_leaders_leave( gui->epoch.epochs[ idx ].lsched ) );
1577 0 : gui->epoch.epochs[idx].lsched = fd_epoch_leaders_join( fd_epoch_leaders_new( gui->epoch.epochs[ idx ]._lsched,
1578 0 : leader_schedule->epoch,
1579 0 : gui->epoch.epochs[ idx ].start_slot,
1580 0 : leader_schedule->slot_cnt,
1581 0 : leader_schedule->staked_cnt,
1582 0 : gui->epoch.epochs[ idx ].stakes,
1583 0 : leader_schedule->excluded_stake,
1584 0 : leader_schedule->vote_keyed_lsched ) );
1585 :
1586 0 : if( FD_UNLIKELY( leader_schedule->start_slot==0UL ) ) {
1587 0 : gui->epoch.epochs[ 0 ].start_time = now;
1588 0 : } else {
1589 0 : gui->epoch.epochs[ idx ].start_time = LONG_MAX;
1590 :
1591 0 : for( ulong i=0UL; i<fd_ulong_min( leader_schedule->start_slot-1UL, FD_GUI_SLOTS_CNT ); i++ ) {
1592 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, leader_schedule->start_slot-i );
1593 0 : if( FD_UNLIKELY( !slot ) ) break;
1594 0 : else if( FD_UNLIKELY( slot->skipped ) ) continue;
1595 :
1596 0 : gui->epoch.epochs[ idx ].start_time = slot->completed_time;
1597 0 : break;
1598 0 : }
1599 0 : }
1600 :
1601 0 : fd_gui_printf_epoch( gui, idx );
1602 0 : fd_http_server_ws_broadcast( gui->http );
1603 0 : }
1604 :
1605 : static void
1606 : fd_gui_handle_slot_start( fd_gui_t * gui,
1607 : ulong _slot,
1608 : ulong parent_slot,
1609 0 : long now ) {
1610 0 : FD_TEST( gui->leader_slot==ULONG_MAX );
1611 0 : gui->leader_slot = _slot;
1612 :
1613 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
1614 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, parent_slot );
1615 :
1616 0 : fd_gui_tile_timers_snap( gui );
1617 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;
1618 :
1619 0 : fd_gui_scheduler_counts_snap( gui, now );
1620 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;
1621 :
1622 0 : fd_gui_txn_waterfall_t waterfall[ 1 ];
1623 0 : fd_gui_txn_waterfall_snap( gui, waterfall );
1624 0 : fd_gui_tile_stats_snap( gui, waterfall, slot->tile_stats_begin, now );
1625 0 : }
1626 :
1627 : static void
1628 : fd_gui_handle_slot_end( fd_gui_t * gui,
1629 : ulong _slot,
1630 : ulong _cus_used,
1631 0 : long now ) {
1632 0 : if( FD_UNLIKELY( !gui->summary.is_full_client && gui->leader_slot!=_slot ) ) {
1633 0 : FD_LOG_ERR(( "gui->leader_slot %lu _slot %lu", gui->leader_slot, _slot ));
1634 0 : }
1635 0 : gui->leader_slot = ULONG_MAX;
1636 :
1637 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
1638 0 : if( FD_UNLIKELY( !slot ) ) return;
1639 :
1640 0 : if( FD_UNLIKELY( !gui->summary.is_full_client ) ) slot->compute_units = (uint)_cus_used;
1641 :
1642 0 : fd_gui_tile_timers_snap( gui );
1643 :
1644 0 : fd_gui_scheduler_counts_snap( gui, now );
1645 :
1646 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
1647 0 : if( FD_LIKELY( lslot ) ) {
1648 0 : fd_rng_t rng[ 1 ];
1649 0 : fd_rng_new( rng, 0UL, 0UL);
1650 :
1651 : /* Sampling at radom from the list of samples. By using a random
1652 : sample stride instead of a integral stride, we can downsample
1653 : more evenly over the duration of the entire block. */
1654 0 : ulong sample_count = 0UL;
1655 0 : ulong end = gui->summary.tile_timers_snap_idx;
1656 0 : end = fd_ulong_if( end<gui->summary.tile_timers_snap_idx_slot_start, end+FD_GUI_TILE_TIMER_SNAP_CNT, end );
1657 0 : for( ulong sample_snap_idx=gui->summary.tile_timers_snap_idx_slot_start; sample_snap_idx<end && sample_count<FD_GUI_TILE_TIMER_SNAP_CNT; sample_snap_idx++ ) {
1658 0 : if( FD_UNLIKELY( fd_rng_float_robust( rng ) > (float)(FD_GUI_TILE_TIMER_SNAP_CNT-sample_count) / (float)(end-gui->summary.tile_timers_snap_idx_slot_start-sample_count) ) ) continue;
1659 :
1660 0 : fd_memcpy( lslot->tile_timers[ sample_count ], gui->summary.tile_timers_snap[ sample_snap_idx%FD_GUI_TILE_TIMER_SNAP_CNT ], sizeof(lslot->tile_timers[ sample_count ]) );
1661 0 : sample_count++;
1662 0 : }
1663 0 : lslot->tile_timers_sample_cnt = sample_count;
1664 :
1665 0 : sample_count = 0UL;
1666 0 : end = gui->summary.scheduler_counts_snap_idx;
1667 0 : end = fd_ulong_if( end<gui->summary.scheduler_counts_snap_idx_slot_start, end+FD_GUI_SCHEDULER_COUNT_SNAP_CNT, end );
1668 0 : for( ulong sample_snap_idx=gui->summary.scheduler_counts_snap_idx_slot_start; sample_snap_idx<end && sample_count<FD_GUI_SCHEDULER_COUNT_SNAP_CNT; sample_snap_idx++ ) {
1669 0 : if( FD_UNLIKELY( fd_rng_float_robust( rng ) > (float)(FD_GUI_SCHEDULER_COUNT_SNAP_CNT-sample_count) / (float)(end-gui->summary.scheduler_counts_snap_idx_slot_start-sample_count) ) ) continue;
1670 :
1671 0 : fd_memcpy( lslot->scheduler_counts[ sample_count ], gui->summary.scheduler_counts_snap[ sample_snap_idx%FD_GUI_SCHEDULER_COUNT_SNAP_CNT ], sizeof(lslot->scheduler_counts[ sample_count ]) );
1672 0 : sample_count++;
1673 0 : }
1674 0 : lslot->scheduler_counts_sample_cnt = sample_count;
1675 0 : }
1676 :
1677 : /* When a slot ends, snap the state of the waterfall and save it into
1678 : that slot, and also reset the reference counters to the end of the
1679 : slot. */
1680 :
1681 0 : fd_gui_txn_waterfall_snap( gui, slot->waterfall_end );
1682 0 : memcpy( slot->waterfall_begin, gui->summary.txn_waterfall_reference, sizeof(slot->waterfall_begin) );
1683 0 : memcpy( gui->summary.txn_waterfall_reference, slot->waterfall_end, sizeof(gui->summary.txn_waterfall_reference) );
1684 :
1685 0 : fd_gui_tile_stats_snap( gui, slot->waterfall_end, slot->tile_stats_end, now );
1686 0 : }
1687 :
1688 : #define SORT_NAME fd_gui_ephemeral_slot_sort
1689 0 : #define SORT_KEY_T fd_gui_ephemeral_slot_t
1690 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 ) ) )
1691 : #include "../../util/tmpl/fd_sort.c"
1692 :
1693 : static inline void
1694 0 : fd_gui_try_insert_ephemeral_slot( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot, long now ) {
1695 0 : int already_present = 0;
1696 0 : for( ulong i=0UL; i<slots_sz; i++ ) {
1697 : /* evict any slots older than 4.8 seconds */
1698 0 : if( FD_UNLIKELY( slots[ i ].slot!=ULONG_MAX && now-slots[ i ].timestamp_arrival_nanos>4800000000L ) ) {
1699 0 : slots[ i ].slot = ULONG_MAX;
1700 0 : continue;
1701 0 : }
1702 :
1703 : /* if we've already seen this slot, just update the timestamp */
1704 0 : if( FD_UNLIKELY( slots[ i ].slot==slot ) ) {
1705 0 : slots[ i ].timestamp_arrival_nanos = now;
1706 0 : already_present = 1;
1707 0 : }
1708 0 : }
1709 0 : if( FD_LIKELY( already_present ) ) return;
1710 :
1711 : /* Insert the new slot number, evicting a smaller slot if necessary */
1712 0 : slots[ slots_sz ].timestamp_arrival_nanos = now;
1713 0 : slots[ slots_sz ].slot = slot;
1714 0 : fd_gui_ephemeral_slot_sort_insert( slots, slots_sz+1UL );
1715 0 : }
1716 :
1717 : static inline void
1718 0 : fd_gui_try_insert_catch_up_slot( ulong * slots, ulong * slots_sz, ulong slot ) {
1719 : /* catch up history is run-length encoded */
1720 0 : int inserted = 0;
1721 0 : for( ulong i=0UL; i<*slots_sz; i++ ) {
1722 0 : if( FD_UNLIKELY( i%2UL==1UL && slots[ i ]==slot-1UL ) ) {
1723 0 : slots[ i ]++;
1724 0 : inserted = 1;
1725 0 : break;
1726 0 : } else if( FD_UNLIKELY( i%2UL==0UL && slots[ i ]==slot+1UL ) ) {
1727 0 : slots[ i ]--;
1728 0 : inserted = 1;
1729 0 : break;
1730 0 : }
1731 0 : }
1732 0 : if( FD_LIKELY( !inserted ) ) {
1733 0 : slots[ (*slots_sz)++ ] = slot;
1734 0 : slots[ (*slots_sz)++ ] = slot;
1735 0 : }
1736 :
1737 : /* colesce intervals that touch */
1738 0 : ulong removed = 0UL;
1739 0 : for( ulong i=1UL; i<(*slots_sz)-1UL; i+=2 ) {
1740 0 : if( FD_UNLIKELY( slots[ i ]==slots[ i+1UL ] ) ) {
1741 0 : slots[ i ] = ULONG_MAX;
1742 0 : slots[ i+1UL ] = ULONG_MAX;
1743 0 : removed += 2;
1744 0 : }
1745 0 : }
1746 :
1747 0 : fd_sort_up_ulong_insert( slots, (*slots_sz) );
1748 0 : (*slots_sz) -= removed;
1749 0 : }
1750 :
1751 : static inline int
1752 0 : fd_gui_ephemeral_slots_contains( fd_gui_ephemeral_slot_t * slots, ulong slots_sz, ulong slot ) {
1753 0 : for( ulong i=0UL; i<slots_sz; i++ ) {
1754 0 : if( FD_UNLIKELY( slots[ i ].slot==ULONG_MAX ) ) break;
1755 0 : if( FD_UNLIKELY( slots[ i ].slot==slot ) ) return 1;
1756 0 : }
1757 0 : return 0;
1758 0 : }
1759 :
1760 : void
1761 : fd_gui_handle_shred( fd_gui_t * gui,
1762 : ulong slot,
1763 : ulong shred_idx,
1764 : int is_turbine,
1765 0 : long tsorig ) {
1766 0 : int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, slot );
1767 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 );
1768 :
1769 0 : if( FD_UNLIKELY( !was_sent && is_turbine && slot!=gui->summary.slot_turbine ) ) {
1770 0 : gui->summary.slot_turbine = slot;
1771 :
1772 0 : fd_gui_printf_turbine_slot( gui );
1773 0 : fd_http_server_ws_broadcast( gui->http );
1774 :
1775 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) fd_gui_try_insert_catch_up_slot( gui->summary.catch_up_turbine, &gui->summary.catch_up_turbine_sz, slot );
1776 0 : }
1777 :
1778 0 : fd_gui_slot_staged_shred_event_t * recv_event = &gui->shreds.staged[ gui->shreds.staged_tail % FD_GUI_SHREDS_STAGING_SZ ];
1779 0 : gui->shreds.staged_tail++;
1780 0 : recv_event->timestamp = tsorig;
1781 0 : recv_event->shred_idx = (ushort)shred_idx;
1782 0 : recv_event->slot = slot;
1783 0 : recv_event->event = fd_uchar_if( is_turbine, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_TURBINE, FD_GUI_SLOT_SHRED_SHRED_RECEIVED_REPAIR );
1784 0 : }
1785 :
1786 : void
1787 : fd_gui_handle_exec_txn_done( fd_gui_t * gui,
1788 : ulong slot,
1789 : ulong start_shred_idx,
1790 : ulong end_shred_idx,
1791 : long tsorig_ns FD_PARAM_UNUSED,
1792 0 : long tspub_ns ) {
1793 0 : for( ulong i = start_shred_idx; i<end_shred_idx; i++ ) {
1794 : /*
1795 : We're leaving this state transition out due to its proximity to
1796 : FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE, but if we ever wanted
1797 : to send this data to the frontend we could.
1798 :
1799 : fd_gui_slot_staged_shred_event_t * exec_start_event = &gui->shreds.staged[ gui->shreds.staged_tail % FD_GUI_SHREDS_STAGING_SZ ];
1800 : gui->shreds.staged_tail++;
1801 : exec_start_event->timestamp = tsorig_ns;
1802 : exec_start_event->shred_idx = (ushort)i;
1803 : exec_start_event->slot = slot;
1804 : exec_start_event->event = FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_START;
1805 : */
1806 :
1807 0 : fd_gui_slot_staged_shred_event_t * exec_end_event = &gui->shreds.staged[ gui->shreds.staged_tail % FD_GUI_SHREDS_STAGING_SZ ];
1808 0 : gui->shreds.staged_tail++;
1809 0 : exec_end_event->timestamp = tspub_ns;
1810 0 : exec_end_event->shred_idx = (ushort)i;
1811 0 : exec_end_event->slot = slot;
1812 0 : exec_end_event->event = FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE;
1813 0 : }
1814 0 : }
1815 :
1816 : void
1817 0 : fd_gui_handle_repair_slot( fd_gui_t * gui, ulong slot, long now ) {
1818 0 : int was_sent = fd_gui_ephemeral_slots_contains( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot );
1819 0 : fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_repair, FD_GUI_REPAIR_SLOT_HISTORY_SZ, slot, now );
1820 :
1821 0 : if( FD_UNLIKELY( !was_sent && slot!=gui->summary.slot_repair ) ) {
1822 0 : gui->summary.slot_repair = slot;
1823 :
1824 0 : fd_gui_printf_repair_slot( gui );
1825 0 : fd_http_server_ws_broadcast( gui->http );
1826 :
1827 0 : if( FD_UNLIKELY( gui->summary.slot_caught_up==ULONG_MAX ) ) fd_gui_try_insert_catch_up_slot( gui->summary.catch_up_repair, &gui->summary.catch_up_repair_sz, slot );
1828 0 : }
1829 0 : }
1830 :
1831 : static void
1832 : fd_gui_handle_reset_slot_legacy( fd_gui_t * gui,
1833 : ulong * msg,
1834 0 : long now ) {
1835 0 : ulong last_landed_vote = msg[ 0 ];
1836 :
1837 0 : ulong parent_cnt = msg[ 1 ];
1838 0 : FD_TEST( parent_cnt<4096UL );
1839 :
1840 0 : ulong _slot = msg[ 2 ];
1841 :
1842 0 : for( ulong i=0UL; i<parent_cnt; i++ ) {
1843 0 : ulong parent_slot = msg[2UL+i];
1844 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
1845 0 : if( FD_UNLIKELY( !slot ) ) {
1846 0 : ulong parent_parent_slot = ULONG_MAX;
1847 0 : if( FD_UNLIKELY( i!=parent_cnt-1UL) ) parent_parent_slot = msg[ 3UL+i ];
1848 0 : fd_gui_clear_slot( gui, parent_slot, parent_parent_slot );
1849 0 : }
1850 0 : }
1851 :
1852 0 : if( FD_UNLIKELY( gui->summary.vote_distance!=_slot-last_landed_vote ) ) {
1853 0 : gui->summary.vote_distance = _slot-last_landed_vote;
1854 0 : fd_gui_printf_vote_distance( gui );
1855 0 : fd_http_server_ws_broadcast( gui->http );
1856 0 : }
1857 :
1858 0 : if( FD_LIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_NON_VOTING ) ) {
1859 0 : if( FD_UNLIKELY( last_landed_vote==ULONG_MAX || (last_landed_vote+150UL)<_slot ) ) {
1860 0 : if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_DELINQUENT ) ) {
1861 0 : gui->summary.vote_state = FD_GUI_VOTE_STATE_DELINQUENT;
1862 0 : fd_gui_printf_vote_state( gui );
1863 0 : fd_http_server_ws_broadcast( gui->http );
1864 0 : }
1865 0 : } else {
1866 0 : if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_VOTING ) ) {
1867 0 : gui->summary.vote_state = FD_GUI_VOTE_STATE_VOTING;
1868 0 : fd_gui_printf_vote_state( gui );
1869 0 : fd_http_server_ws_broadcast( gui->http );
1870 0 : }
1871 0 : }
1872 0 : }
1873 :
1874 0 : ulong parent_slot_idx = 0UL;
1875 :
1876 0 : int republish_skip_rate[ 2 ] = {0};
1877 :
1878 0 : for( ulong i=0UL; i<fd_ulong_min( _slot+1, FD_GUI_SLOTS_CNT ); i++ ) {
1879 0 : ulong parent_slot = _slot - i;
1880 :
1881 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
1882 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, parent_slot, ULONG_MAX );
1883 :
1884 : /* The chain of parents may stretch into already rooted slots if
1885 : they haven't been squashed yet, if we reach one of them we can
1886 : just exit, all the information prior to the root is already
1887 : correct. */
1888 :
1889 0 : if( FD_LIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
1890 :
1891 0 : int should_republish = slot->must_republish;
1892 0 : slot->must_republish = 0;
1893 :
1894 0 : if( FD_UNLIKELY( parent_slot!=msg[2UL+parent_slot_idx] ) ) {
1895 : /* We are between two parents in the rooted chain, which means
1896 : we were skipped. */
1897 0 : if( FD_UNLIKELY( !slot->skipped ) ) {
1898 0 : slot->skipped = 1;
1899 0 : should_republish = 1;
1900 0 : if( FD_LIKELY( slot->mine ) ) {
1901 0 : for( ulong i=0UL; i<2UL; i++ ) {
1902 0 : if( FD_LIKELY( parent_slot>=gui->epoch.epochs[ i ].start_slot && parent_slot<=gui->epoch.epochs[ i ].end_slot ) ) {
1903 0 : gui->epoch.epochs[ i ].my_skipped_slots++;
1904 0 : republish_skip_rate[ i ] = 1;
1905 0 : break;
1906 0 : }
1907 0 : }
1908 0 : }
1909 0 : }
1910 0 : } else {
1911 : /* Reached the next parent... */
1912 0 : if( FD_UNLIKELY( slot->skipped ) ) {
1913 0 : slot->skipped = 0;
1914 0 : should_republish = 1;
1915 0 : if( FD_LIKELY( slot->mine ) ) {
1916 0 : for( ulong i=0UL; i<2UL; i++ ) {
1917 0 : if( FD_LIKELY( parent_slot>=gui->epoch.epochs[ i ].start_slot && parent_slot<=gui->epoch.epochs[ i ].end_slot ) ) {
1918 0 : gui->epoch.epochs[ i ].my_skipped_slots--;
1919 0 : republish_skip_rate[ i ] = 1;
1920 0 : break;
1921 0 : }
1922 0 : }
1923 0 : }
1924 0 : }
1925 0 : parent_slot_idx++;
1926 0 : }
1927 :
1928 0 : if( FD_LIKELY( should_republish ) ) {
1929 0 : fd_gui_printf_slot( gui, parent_slot );
1930 0 : fd_http_server_ws_broadcast( gui->http );
1931 0 : }
1932 :
1933 : /* We reached the last parent in the chain, everything above this
1934 : must have already been rooted, so we can exit. */
1935 :
1936 0 : if( FD_UNLIKELY( parent_slot_idx>=parent_cnt ) ) break;
1937 0 : }
1938 :
1939 0 : ulong duration_sum = 0UL;
1940 0 : ulong slot_cnt = 0UL;
1941 :
1942 : /* If we've just caught up we should truncate our slot history to avoid including catch-up slots */
1943 0 : int just_caught_up = gui->summary.slot_caught_up!=ULONG_MAX && _slot>gui->summary.slot_caught_up && _slot<gui->summary.slot_caught_up+750UL;
1944 0 : ulong slot_duration_history_sz = fd_ulong_if( just_caught_up, _slot-gui->summary.slot_caught_up, 750UL );
1945 0 : for( ulong i=0UL; i<fd_ulong_min( _slot+1, slot_duration_history_sz ); i++ ) {
1946 0 : ulong parent_slot = _slot - i;
1947 :
1948 0 : fd_gui_slot_t const * slot = fd_gui_get_slot_const( gui, parent_slot );
1949 0 : if( FD_UNLIKELY( !slot) ) break;
1950 0 : if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
1951 0 : FD_LOG_ERR(( "_slot %lu i %lu we expect _slot-i %lu got slot->slot %lu", _slot, i, _slot-i, slot->slot ));
1952 0 : }
1953 :
1954 0 : ulong slot_duration = fd_gui_slot_duration( gui, slot );
1955 0 : if( FD_LIKELY( slot_duration!=ULONG_MAX ) ) {
1956 0 : duration_sum += slot_duration;
1957 0 : slot_cnt++;
1958 0 : }
1959 0 : }
1960 :
1961 0 : if( FD_LIKELY( slot_cnt>0 )) {
1962 0 : gui->summary.estimated_slot_duration_nanos = (ulong)(duration_sum / slot_cnt);
1963 0 : fd_gui_printf_estimated_slot_duration_nanos( gui );
1964 0 : fd_http_server_ws_broadcast( gui->http );
1965 0 : }
1966 :
1967 0 : if( FD_LIKELY( gui->summary.slot_completed==ULONG_MAX || _slot!=gui->summary.slot_completed ) ) {
1968 0 : gui->summary.slot_completed = _slot;
1969 0 : fd_gui_printf_completed_slot( gui );
1970 0 : fd_http_server_ws_broadcast( gui->http );
1971 :
1972 : /* Also update slot_turbine which could be larger than the max
1973 : turbine slot if we are leader */
1974 0 : if( FD_UNLIKELY( gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && gui->summary.slot_completed!=ULONG_MAX && gui->summary.slot_completed>gui->summary.slots_max_turbine[ 0 ].slot ) ) {
1975 0 : fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, gui->summary.slot_completed, now );
1976 0 : }
1977 :
1978 0 : int slot_turbine_hist_full = gui->summary.slots_max_turbine[ FD_GUI_TURBINE_SLOT_HISTORY_SZ-1UL ].slot!=ULONG_MAX;
1979 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) ) ) {
1980 0 : gui->summary.slot_caught_up = gui->summary.slot_completed + 4UL;
1981 :
1982 0 : fd_gui_printf_slot_caught_up( gui );
1983 0 : fd_http_server_ws_broadcast( gui->http );
1984 0 : }
1985 0 : }
1986 :
1987 0 : for( ulong i=0UL; i<2UL; i++ ) {
1988 0 : if( FD_LIKELY( republish_skip_rate[ i ] ) ) {
1989 0 : fd_gui_printf_skip_rate( gui, i );
1990 0 : fd_http_server_ws_broadcast( gui->http );
1991 0 : }
1992 0 : }
1993 0 : }
1994 :
1995 : static void
1996 : fd_gui_handle_completed_slot( fd_gui_t * gui,
1997 : ulong * msg,
1998 0 : long now ) {
1999 0 : ulong _slot = msg[ 0 ];
2000 0 : uint total_txn_count = (uint)msg[ 1 ];
2001 0 : uint nonvote_txn_count = (uint)msg[ 2 ];
2002 0 : uint failed_txn_count = (uint)msg[ 3 ];
2003 0 : uint nonvote_failed_txn_count = (uint)msg[ 4 ];
2004 0 : uint compute_units = (uint)msg[ 5 ];
2005 0 : ulong transaction_fee = msg[ 6 ];
2006 0 : ulong priority_fee = msg[ 7 ];
2007 0 : ulong tips = msg[ 8 ];
2008 0 : ulong _parent_slot = msg[ 9 ];
2009 0 : ulong max_compute_units = msg[ 10 ];
2010 :
2011 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2012 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, _parent_slot );
2013 :
2014 0 : slot->completed_time = now;
2015 0 : slot->parent_slot = _parent_slot;
2016 0 : slot->max_compute_units = (uint)max_compute_units;
2017 0 : if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_COMPLETED ) ) {
2018 : /* Typically a slot goes from INCOMPLETE to COMPLETED but it can
2019 : happen that it starts higher. One such case is when we
2020 : optimistically confirm a higher slot that skips this one, but
2021 : then later we replay this one anyway to track the bank fork. */
2022 :
2023 0 : if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && _slot<gui->summary.slot_optimistically_confirmed ) ) {
2024 : /* Cluster might have already optimistically confirmed by the time
2025 : we finish replaying it. */
2026 0 : slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
2027 0 : } else {
2028 0 : slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
2029 0 : }
2030 0 : }
2031 0 : slot->total_txn_cnt = total_txn_count;
2032 0 : slot->vote_txn_cnt = total_txn_count - nonvote_txn_count;
2033 0 : slot->failed_txn_cnt = failed_txn_count;
2034 0 : slot->nonvote_failed_txn_cnt = nonvote_failed_txn_count;
2035 0 : slot->transaction_fee = transaction_fee;
2036 0 : slot->priority_fee = priority_fee;
2037 0 : slot->tips = tips;
2038 :
2039 : /* In Frankendancer, CUs come from our own leader pipeline (the field
2040 : sent from the Agave codepath is zero'd out) */
2041 0 : slot->compute_units = fd_uint_if( !gui->summary.is_full_client && slot->mine, slot->compute_units, compute_units );
2042 :
2043 0 : if( FD_UNLIKELY( gui->epoch.has_epoch[ 0 ] && _slot==gui->epoch.epochs[ 0 ].end_slot ) ) {
2044 0 : gui->epoch.epochs[ 0 ].end_time = slot->completed_time;
2045 0 : } else if( FD_UNLIKELY( gui->epoch.has_epoch[ 1 ] && _slot==gui->epoch.epochs[ 1 ].end_slot ) ) {
2046 0 : gui->epoch.epochs[ 1 ].end_time = slot->completed_time;
2047 0 : }
2048 :
2049 : /* Broadcast new skip rate if one of our slots got completed. */
2050 0 : if( FD_LIKELY( slot->mine ) ) {
2051 0 : for( ulong i=0UL; i<2UL; i++ ) {
2052 0 : if( FD_LIKELY( _slot>=gui->epoch.epochs[ i ].start_slot && _slot<=gui->epoch.epochs[ i ].end_slot ) ) {
2053 0 : fd_gui_printf_skip_rate( gui, i );
2054 0 : fd_http_server_ws_broadcast( gui->http );
2055 0 : break;
2056 0 : }
2057 0 : }
2058 0 : }
2059 0 : }
2060 :
2061 : static void
2062 : fd_gui_handle_rooted_slot_legacy( fd_gui_t * gui,
2063 0 : ulong * msg ) {
2064 0 : ulong _slot = msg[ 0 ];
2065 :
2066 : // FD_LOG_WARNING(( "Got rooted slot %lu", _slot ));
2067 :
2068 : /* Slot 0 is always rooted. No need to iterate all the way back to
2069 : i==_slot */
2070 0 : for( ulong i=0UL; i<fd_ulong_min( _slot, FD_GUI_SLOTS_CNT ); i++ ) {
2071 0 : ulong parent_slot = _slot - i;
2072 :
2073 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
2074 0 : if( FD_UNLIKELY( !slot ) ) break;
2075 :
2076 0 : if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
2077 0 : FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", _slot, i, parent_slot, slot->slot ));
2078 0 : }
2079 0 : if( FD_UNLIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
2080 :
2081 0 : slot->level = FD_GUI_SLOT_LEVEL_ROOTED;
2082 0 : fd_gui_printf_slot( gui, parent_slot );
2083 0 : fd_http_server_ws_broadcast( gui->http );
2084 0 : }
2085 :
2086 0 : gui->summary.slot_rooted = _slot;
2087 0 : fd_gui_printf_root_slot( gui );
2088 0 : fd_http_server_ws_broadcast( gui->http );
2089 0 : }
2090 :
2091 : static void
2092 : fd_gui_handle_optimistically_confirmed_slot( fd_gui_t * gui,
2093 0 : ulong _slot ) {
2094 : /* Slot 0 is always rooted. No need to iterate all the way back to
2095 : i==_slot */
2096 0 : for( ulong i=0UL; i<fd_ulong_min( _slot, FD_GUI_SLOTS_CNT ); i++ ) {
2097 0 : ulong parent_slot = _slot - i;
2098 :
2099 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
2100 0 : if( FD_UNLIKELY( !slot) ) break;
2101 :
2102 0 : if( FD_UNLIKELY( slot->slot>parent_slot ) ) {
2103 0 : FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", _slot, i, parent_slot, slot->slot ));
2104 0 : } else if( FD_UNLIKELY( slot->slot<parent_slot ) ) {
2105 : /* Slot not even replayed yet ... will come out as optimistically confirmed */
2106 0 : continue;
2107 0 : }
2108 0 : if( FD_UNLIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
2109 :
2110 0 : if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED ) ) {
2111 0 : slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
2112 0 : fd_gui_printf_slot( gui, parent_slot );
2113 0 : fd_http_server_ws_broadcast( gui->http );
2114 0 : }
2115 0 : }
2116 :
2117 0 : if( FD_UNLIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && _slot<gui->summary.slot_optimistically_confirmed ) ) {
2118 : /* Optimistically confirmed slot went backwards ... mark some slots as no
2119 : longer optimistically confirmed. */
2120 0 : for( ulong i=gui->summary.slot_optimistically_confirmed; i>=_slot; i-- ) {
2121 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, i );
2122 0 : if( FD_UNLIKELY( !slot ) ) break;
2123 0 : if( FD_LIKELY( slot->slot==i ) ) {
2124 : /* It's possible for the optimistically confirmed slot to skip
2125 : backwards between two slots that we haven't yet replayed. In
2126 : that case we don't need to change anything, since they will
2127 : get marked properly when they get completed. */
2128 0 : slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
2129 0 : fd_gui_printf_slot( gui, i );
2130 0 : fd_http_server_ws_broadcast( gui->http );
2131 0 : }
2132 0 : }
2133 0 : }
2134 :
2135 0 : gui->summary.slot_optimistically_confirmed = _slot;
2136 0 : fd_gui_printf_optimistically_confirmed_slot( gui );
2137 0 : fd_http_server_ws_broadcast( gui->http );
2138 0 : }
2139 :
2140 : static void
2141 : fd_gui_handle_balance_update( fd_gui_t * gui,
2142 0 : ulong const * msg ) {
2143 0 : switch( msg[ 0 ] ) {
2144 0 : case 0UL:
2145 0 : gui->summary.identity_account_balance = msg[ 1 ];
2146 0 : fd_gui_printf_identity_balance( gui );
2147 0 : fd_http_server_ws_broadcast( gui->http );
2148 0 : break;
2149 0 : case 1UL:
2150 0 : gui->summary.vote_account_balance = msg[ 1 ];
2151 0 : fd_gui_printf_vote_balance( gui );
2152 0 : fd_http_server_ws_broadcast( gui->http );
2153 0 : break;
2154 0 : default:
2155 0 : FD_LOG_ERR(( "balance: unknown account type: %lu", msg[ 0 ] ));
2156 0 : }
2157 0 : }
2158 :
2159 : static void
2160 : fd_gui_handle_start_progress( fd_gui_t * gui,
2161 0 : uchar const * msg ) {
2162 0 : uchar type = msg[ 0 ];
2163 :
2164 0 : switch (type) {
2165 0 : case 0:
2166 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_INITIALIZING;
2167 0 : FD_LOG_INFO(( "progress: initializing" ));
2168 0 : break;
2169 0 : case 1: {
2170 0 : char const * snapshot_type;
2171 0 : if( FD_UNLIKELY( gui->summary.startup_progress.startup_got_full_snapshot ) ) {
2172 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_SEARCHING_FOR_INCREMENTAL_SNAPSHOT;
2173 0 : snapshot_type = "incremental";
2174 0 : } else {
2175 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_SEARCHING_FOR_FULL_SNAPSHOT;
2176 0 : snapshot_type = "full";
2177 0 : }
2178 0 : FD_LOG_INFO(( "progress: searching for %s snapshot", snapshot_type ));
2179 0 : break;
2180 0 : }
2181 0 : case 2: {
2182 0 : uchar is_full_snapshot = msg[ 1 ];
2183 0 : if( FD_LIKELY( is_full_snapshot ) ) {
2184 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_DOWNLOADING_FULL_SNAPSHOT;
2185 0 : gui->summary.startup_progress.startup_full_snapshot_slot = *((ulong *)(msg + 2));
2186 0 : gui->summary.startup_progress.startup_full_snapshot_peer_ip_addr = *((uint *)(msg + 10));
2187 0 : gui->summary.startup_progress.startup_full_snapshot_peer_port = *((ushort *)(msg + 14));
2188 0 : gui->summary.startup_progress.startup_full_snapshot_total_bytes = *((ulong *)(msg + 16));
2189 0 : gui->summary.startup_progress.startup_full_snapshot_current_bytes = *((ulong *)(msg + 24));
2190 0 : gui->summary.startup_progress.startup_full_snapshot_elapsed_secs = *((double *)(msg + 32));
2191 0 : gui->summary.startup_progress.startup_full_snapshot_remaining_secs = *((double *)(msg + 40));
2192 0 : gui->summary.startup_progress.startup_full_snapshot_throughput = *((double *)(msg + 48));
2193 0 : FD_LOG_INFO(( "progress: downloading full snapshot: slot=%lu", gui->summary.startup_progress.startup_full_snapshot_slot ));
2194 0 : } else {
2195 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_DOWNLOADING_INCREMENTAL_SNAPSHOT;
2196 0 : gui->summary.startup_progress.startup_incremental_snapshot_slot = *((ulong *)(msg + 2));
2197 0 : gui->summary.startup_progress.startup_incremental_snapshot_peer_ip_addr = *((uint *)(msg + 10));
2198 0 : gui->summary.startup_progress.startup_incremental_snapshot_peer_port = *((ushort *)(msg + 14));
2199 0 : gui->summary.startup_progress.startup_incremental_snapshot_total_bytes = *((ulong *)(msg + 16));
2200 0 : gui->summary.startup_progress.startup_incremental_snapshot_current_bytes = *((ulong *)(msg + 24));
2201 0 : gui->summary.startup_progress.startup_incremental_snapshot_elapsed_secs = *((double *)(msg + 32));
2202 0 : gui->summary.startup_progress.startup_incremental_snapshot_remaining_secs = *((double *)(msg + 40));
2203 0 : gui->summary.startup_progress.startup_incremental_snapshot_throughput = *((double *)(msg + 48));
2204 0 : FD_LOG_INFO(( "progress: downloading incremental snapshot: slot=%lu", gui->summary.startup_progress.startup_incremental_snapshot_slot ));
2205 0 : }
2206 0 : break;
2207 0 : }
2208 0 : case 3: {
2209 0 : gui->summary.startup_progress.startup_got_full_snapshot = 1;
2210 0 : break;
2211 0 : }
2212 0 : case 4:
2213 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_CLEANING_BLOCK_STORE;
2214 0 : FD_LOG_INFO(( "progress: cleaning block store" ));
2215 0 : break;
2216 0 : case 5:
2217 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_CLEANING_ACCOUNTS;
2218 0 : FD_LOG_INFO(( "progress: cleaning accounts" ));
2219 0 : break;
2220 0 : case 6:
2221 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_LOADING_LEDGER;
2222 0 : FD_LOG_INFO(( "progress: loading ledger" ));
2223 0 : break;
2224 0 : case 7: {
2225 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_PROCESSING_LEDGER;
2226 0 : gui->summary.startup_progress.startup_ledger_slot = fd_ulong_load_8( msg + 1 );
2227 0 : gui->summary.startup_progress.startup_ledger_max_slot = fd_ulong_load_8( msg + 9 );
2228 0 : FD_LOG_INFO(( "progress: processing ledger: slot=%lu, max_slot=%lu", gui->summary.startup_progress.startup_ledger_slot, gui->summary.startup_progress.startup_ledger_max_slot ));
2229 0 : break;
2230 0 : }
2231 0 : case 8:
2232 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_STARTING_SERVICES;
2233 0 : FD_LOG_INFO(( "progress: starting services" ));
2234 0 : break;
2235 0 : case 9:
2236 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_HALTED;
2237 0 : FD_LOG_INFO(( "progress: halted" ));
2238 0 : break;
2239 0 : case 10: {
2240 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY;
2241 0 : gui->summary.startup_progress.startup_waiting_for_supermajority_slot = fd_ulong_load_8( msg + 1 );
2242 0 : gui->summary.startup_progress.startup_waiting_for_supermajority_stake_pct = fd_ulong_load_8( msg + 9 );
2243 0 : FD_LOG_INFO(( "progress: waiting for supermajority: slot=%lu, gossip_stake_percent=%lu", gui->summary.startup_progress.startup_waiting_for_supermajority_slot, gui->summary.startup_progress.startup_waiting_for_supermajority_stake_pct ));
2244 0 : break;
2245 0 : }
2246 0 : case 11:
2247 0 : gui->summary.startup_progress.phase = FD_GUI_START_PROGRESS_TYPE_RUNNING;
2248 0 : FD_LOG_INFO(( "progress: running" ));
2249 0 : break;
2250 0 : default:
2251 0 : FD_LOG_ERR(( "progress: unknown type: %u", type ));
2252 0 : }
2253 :
2254 0 : fd_gui_printf_startup_progress( gui );
2255 0 : fd_http_server_ws_broadcast( gui->http );
2256 0 : }
2257 :
2258 : void
2259 : fd_gui_handle_genesis_hash( fd_gui_t * gui,
2260 0 : uchar const * msg ) {
2261 0 : FD_BASE58_ENCODE_32_BYTES(msg, hash_cstr);
2262 0 : ulong cluster = fd_genesis_cluster_identify(hash_cstr);
2263 0 : char const * cluster_name = fd_genesis_cluster_name(cluster);
2264 :
2265 0 : if( FD_LIKELY( strcmp( gui->summary.cluster, cluster_name ) ) ) {
2266 0 : gui->summary.cluster = fd_genesis_cluster_name(cluster);
2267 0 : fd_gui_printf_cluster( gui );
2268 0 : fd_http_server_ws_broadcast( gui->http );
2269 0 : }
2270 0 : }
2271 :
2272 : static void
2273 : fd_gui_handle_block_engine_update( fd_gui_t * gui,
2274 0 : uchar const * msg ) {
2275 0 : fd_plugin_msg_block_engine_update_t const * update = (fd_plugin_msg_block_engine_update_t const *)msg;
2276 :
2277 0 : gui->block_engine.has_block_engine = 1;
2278 :
2279 : /* copy strings and ensure null termination within bounds */
2280 0 : FD_TEST( fd_cstr_nlen( update->name, sizeof(gui->block_engine.name ) ) < sizeof(gui->block_engine.name ) );
2281 0 : FD_TEST( fd_cstr_nlen( update->url, sizeof(gui->block_engine.url ) ) < sizeof(gui->block_engine.url ) );
2282 0 : FD_TEST( fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) ) < sizeof(gui->block_engine.ip_cstr) );
2283 0 : ulong name_len = fd_cstr_nlen( update->name, sizeof(gui->block_engine.name ) );
2284 0 : ulong url_len = fd_cstr_nlen( update->url, sizeof(gui->block_engine.url ) );
2285 0 : ulong ip_cstr_len = fd_cstr_nlen( update->ip_cstr, sizeof(gui->block_engine.ip_cstr) );
2286 0 : fd_memcpy( gui->block_engine.name, update->name, name_len+1UL );
2287 0 : fd_memcpy( gui->block_engine.url, update->url, url_len+1UL );
2288 0 : fd_memcpy( gui->block_engine.ip_cstr, update->ip_cstr, ip_cstr_len+1UL );
2289 :
2290 0 : gui->block_engine.status = update->status;
2291 :
2292 0 : fd_gui_printf_block_engine( gui );
2293 0 : fd_http_server_ws_broadcast( gui->http );
2294 0 : }
2295 :
2296 : void
2297 : fd_gui_handle_snapshot_update( fd_gui_t * gui,
2298 0 : fd_snapct_update_t const * msg ) {
2299 0 : FD_TEST( msg && fd_cstr_nlen( msg->read_path, 1 ) );
2300 :
2301 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 );
2302 :
2303 0 : char const * filename = strrchr(msg->read_path, '/');
2304 :
2305 : /* Skip the '/' */
2306 0 : if( FD_UNLIKELY( filename ) ) filename++;
2307 :
2308 0 : if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_INCREMENTAL) {
2309 0 : ulong slot1, slot2;
2310 0 : if ( FD_LIKELY( sscanf( filename, "incremental-snapshot-%lu-%lu-", &slot1, &slot2 )==2 ) )
2311 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot2;
2312 0 : else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
2313 0 : } else if (msg->type == FD_SNAPCT_SNAPSHOT_TYPE_FULL) {
2314 0 : ulong slot1;
2315 0 : if ( FD_LIKELY( sscanf( filename, "snapshot-%lu-", &slot1 )==1 ) )
2316 0 : gui->summary.boot_progress.loading_snapshot[ snapshot_idx ].slot = slot1;
2317 0 : else FD_LOG_ERR(("failed to scan filename: %s parsed from %s", filename, msg->read_path ));
2318 0 : }
2319 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 );
2320 0 : }
2321 :
2322 : static void
2323 0 : fd_gui_handle_reset_slot( fd_gui_t * gui, ulong reset_slot, long now ) {
2324 0 : FD_TEST( reset_slot!=ULONG_MAX );
2325 :
2326 : /* reset_slot has not changed */
2327 0 : if( FD_UNLIKELY( gui->summary.slot_completed!=ULONG_MAX && reset_slot==gui->summary.slot_completed ) ) return;
2328 :
2329 0 : ulong prev_slot_completed = gui->summary.slot_completed;
2330 0 : gui->summary.slot_completed = reset_slot;
2331 :
2332 0 : if( FD_LIKELY( fd_gui_get_slot( gui, gui->summary.slot_completed ) ) ) {
2333 0 : fd_gui_printf_slot( gui, gui->summary.slot_completed );
2334 0 : fd_http_server_ws_broadcast( gui->http );
2335 0 : }
2336 :
2337 0 : fd_gui_printf_completed_slot( gui );
2338 0 : fd_http_server_ws_broadcast( gui->http );
2339 :
2340 : /* Also update slot_turbine which could be larger than the max
2341 : turbine slot if we are leader */
2342 0 : if( FD_UNLIKELY( gui->summary.slots_max_turbine[ 0 ].slot!=ULONG_MAX && gui->summary.slot_completed > gui->summary.slots_max_turbine[ 0 ].slot ) ) {
2343 0 : fd_gui_try_insert_ephemeral_slot( gui->summary.slots_max_turbine, FD_GUI_TURBINE_SLOT_HISTORY_SZ, gui->summary.slot_completed, now );
2344 0 : }
2345 :
2346 0 : int slot_turbine_hist_full = gui->summary.slots_max_turbine[ FD_GUI_TURBINE_SLOT_HISTORY_SZ-1UL ].slot!=ULONG_MAX;
2347 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) ) ) {
2348 0 : gui->summary.slot_caught_up = gui->summary.slot_completed + 4UL;
2349 :
2350 0 : fd_gui_printf_slot_caught_up( gui );
2351 0 : fd_http_server_ws_broadcast( gui->http );
2352 0 : }
2353 :
2354 : /* ensure a history exists */
2355 0 : if( FD_UNLIKELY( prev_slot_completed==ULONG_MAX || gui->summary.slot_rooted==ULONG_MAX ) ) return;
2356 :
2357 : /* slot complete recieved out of order on the same fork? */
2358 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 ) );
2359 :
2360 : /* fork switch: we need to "undo" the previous fork */
2361 0 : int republish_skip_rate[ 2 ] = {0};
2362 0 : if( FD_UNLIKELY( !fd_gui_slot_is_ancestor( gui, prev_slot_completed, gui->summary.slot_completed ) ) ) {
2363 : /* The handling for skipped slot on a fork switch is tricky. We
2364 : want to rebate back any slots that were skipped but are no
2365 : longer. We also need to make sure we count skipped slots
2366 : towards the correct epoch. */
2367 0 : for( ulong i=fd_ulong_max( gui->summary.slot_completed, prev_slot_completed); i>gui->summary.slot_rooted; i-- ) {
2368 :
2369 0 : int is_skipped_on_old_fork = i<=prev_slot_completed && fd_gui_is_skipped_on_fork( gui, gui->summary.slot_rooted, prev_slot_completed, i );
2370 0 : int is_skipped_on_new_fork = i<=gui->summary.slot_completed && fd_gui_is_skipped_on_fork( gui, gui->summary.slot_rooted, gui->summary.slot_completed, i );
2371 :
2372 0 : if( FD_LIKELY( is_skipped_on_old_fork && !is_skipped_on_new_fork ) ) {
2373 0 : fd_gui_slot_t * skipped = fd_gui_get_slot( gui, i );
2374 0 : if( FD_LIKELY( !skipped ) ) {
2375 0 : fd_gui_slot_t * p = fd_gui_get_parent_slot_on_fork( gui, prev_slot_completed, i );
2376 0 : skipped = fd_gui_clear_slot( gui, i, p ? p->slot : ULONG_MAX );
2377 0 : }
2378 :
2379 0 : skipped->skipped = 0;
2380 0 : fd_gui_printf_slot( gui, skipped->slot );
2381 0 : fd_http_server_ws_broadcast( gui->http );
2382 0 : skipped->must_republish = 0;
2383 :
2384 0 : if( FD_LIKELY( skipped->mine ) ) {
2385 0 : for( ulong i=0UL; i<2UL; i++ ) {
2386 0 : if( FD_LIKELY( i>=gui->epoch.epochs[ i ].start_slot && i<=gui->epoch.epochs[ i ].end_slot ) ) {
2387 0 : gui->epoch.epochs[ i ].my_skipped_slots--;
2388 0 : republish_skip_rate[ i ] = 1;
2389 0 : break;
2390 0 : }
2391 0 : }
2392 0 : }
2393 0 : }
2394 :
2395 0 : if( FD_LIKELY( !is_skipped_on_old_fork && is_skipped_on_new_fork ) ) {
2396 0 : fd_gui_slot_t * skipped = fd_gui_get_slot( gui, i );
2397 0 : if( FD_LIKELY( !skipped ) ) {
2398 0 : fd_gui_slot_t * p = fd_gui_get_parent_slot_on_fork( gui, prev_slot_completed, i );
2399 0 : skipped = fd_gui_clear_slot( gui, i, p ? p->slot : ULONG_MAX );
2400 0 : }
2401 :
2402 0 : skipped->skipped = 1;
2403 0 : fd_gui_printf_slot( gui, skipped->slot );
2404 0 : fd_http_server_ws_broadcast( gui->http );
2405 0 : skipped->must_republish = 0;
2406 :
2407 0 : if( FD_LIKELY( skipped->mine ) ) {
2408 0 : for( ulong i=0UL; i<2UL; i++ ) {
2409 0 : if( FD_LIKELY( i>=gui->epoch.epochs[ i ].start_slot && i<=gui->epoch.epochs[ i ].end_slot ) ) {
2410 0 : gui->epoch.epochs[ i ].my_skipped_slots++;
2411 0 : republish_skip_rate[ i ] = 1;
2412 0 : break;
2413 0 : }
2414 0 : }
2415 0 : }
2416 0 : }
2417 0 : }
2418 0 : } else {
2419 : /* publish new skipped slots */
2420 0 : fd_gui_slot_t * s = fd_gui_get_slot( gui, gui->summary.slot_completed );
2421 0 : while( s && s->slot>=prev_slot_completed ) {
2422 0 : fd_gui_slot_t * p = fd_gui_get_slot( gui, s->parent_slot );
2423 0 : if( FD_UNLIKELY( !p ) ) break;
2424 0 : for( ulong i=p->slot+1; i<s->slot; i++ ) {
2425 0 : fd_gui_slot_t * skipped = fd_gui_get_slot( gui, i );
2426 0 : if( FD_LIKELY( !skipped ) ) {
2427 0 : fd_gui_slot_t * p = fd_gui_get_parent_slot_on_fork( gui, gui->summary.slot_completed, i );
2428 0 : skipped = fd_gui_clear_slot( gui, i, p ? p->slot : ULONG_MAX );
2429 0 : }
2430 0 : skipped->skipped = 1;
2431 0 : fd_gui_printf_slot( gui, skipped->slot );
2432 0 : fd_http_server_ws_broadcast( gui->http );
2433 0 : skipped->must_republish = 0;
2434 0 : if( FD_LIKELY( skipped->mine ) ) {
2435 0 : for( ulong i=0UL; i<2UL; i++ ) {
2436 0 : if( FD_LIKELY( i>=gui->epoch.epochs[ i ].start_slot && i<=gui->epoch.epochs[ i ].end_slot ) ) {
2437 0 : gui->epoch.epochs[ i ].my_skipped_slots++;
2438 0 : republish_skip_rate[ i ] = 1;
2439 0 : break;
2440 0 : }
2441 0 : }
2442 0 : }
2443 0 : }
2444 0 : s = p;
2445 0 : }
2446 0 : }
2447 :
2448 0 : for( ulong i=0UL; i<2UL; i++ ) {
2449 0 : if( FD_LIKELY( republish_skip_rate[ i ] ) ) {
2450 0 : fd_gui_printf_skip_rate( gui, i );
2451 0 : fd_http_server_ws_broadcast( gui->http );
2452 0 : }
2453 0 : }
2454 0 : }
2455 :
2456 : #define SORT_NAME fd_gui_slot_staged_shred_event_evict_sort
2457 : #define SORT_KEY_T fd_gui_slot_staged_shred_event_t
2458 : #define SORT_BEFORE(a,b) (__extension__({ (void)(b); (a).slot==ULONG_MAX; }))
2459 : #include "../../util/tmpl/fd_sort.c"
2460 :
2461 : #define SORT_NAME fd_gui_slot_staged_shred_event_slot_sort
2462 0 : #define SORT_KEY_T fd_gui_slot_staged_shred_event_t
2463 0 : #define SORT_BEFORE(a,b) ((a).slot<(b).slot)
2464 : #include "../../util/tmpl/fd_sort.c"
2465 :
2466 : static void
2467 0 : fd_gui_handle_rooted_slot( fd_gui_t * gui, ulong root_slot ) {
2468 : /* start at the new root and move backwards towards the old root,
2469 : rooting everything in-between */
2470 0 : for( ulong i=0UL; i<fd_ulong_min( root_slot, FD_GUI_SLOTS_CNT ); i++ ) {
2471 0 : ulong parent_slot = root_slot - i;
2472 :
2473 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, parent_slot );
2474 0 : if( FD_UNLIKELY( !slot ) ) break;
2475 :
2476 0 : if( FD_UNLIKELY( slot->slot!=parent_slot ) ) {
2477 0 : FD_LOG_ERR(( "_slot %lu i %lu we expect parent_slot %lu got slot->slot %lu", root_slot, i, parent_slot, slot->slot ));
2478 0 : }
2479 0 : if( FD_UNLIKELY( slot->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) break;
2480 :
2481 : /* change notarization levels and rebroadcast */
2482 0 : slot->level = FD_GUI_SLOT_LEVEL_ROOTED;
2483 0 : fd_gui_printf_slot( gui, parent_slot );
2484 0 : fd_http_server_ws_broadcast( gui->http );
2485 0 : }
2486 :
2487 : /* archive root shred events. We want to avoid n^2 iteration here
2488 : since it can significantly slow things down. Instead, we copy
2489 : over all rooted shreds to a scratch space, stable sort by slot,
2490 : copy the sorted arrays to the shred history. */
2491 0 : ulong archive_cnt = 0UL;
2492 0 : ulong kept_cnt = 0UL;
2493 0 : ulong kept_before_next_cnt = 0UL;
2494 :
2495 0 : for( ulong i=gui->shreds.staged_head; i<gui->shreds.staged_tail; i++ ) {
2496 0 : fd_gui_slot_staged_shred_event_t const * src = &gui->shreds.staged[ i % FD_GUI_SHREDS_STAGING_SZ ];
2497 :
2498 0 : if( FD_UNLIKELY( gui->shreds.history_slot!=ULONG_MAX && src->slot<=gui->shreds.history_slot ) ) continue;
2499 :
2500 0 : if( FD_UNLIKELY( src->slot<=root_slot ) ) {
2501 0 : gui->shreds._staged_scratch[ archive_cnt++ ] = *src;
2502 0 : continue;
2503 0 : }
2504 :
2505 : /* The entries from the staging area are evicted by setting their
2506 : slot field to ULONG MAX, then sorting the staging area.
2507 :
2508 : IMPORTANT: this sort needs to be stable since we always keep
2509 : valid un-broadcast events at the end of the ring buffer */
2510 0 : if( FD_UNLIKELY( i<gui->shreds.staged_next_broadcast ) ) kept_before_next_cnt++;
2511 0 : gui->shreds._staged_scratch2[ kept_cnt++ ] = *src;
2512 0 : }
2513 :
2514 : /* copy shred events to archive */
2515 0 : for( ulong j=0UL; j<kept_cnt; j++ ) gui->shreds.staged[ (gui->shreds.staged_head + j) % FD_GUI_SHREDS_STAGING_SZ ] = gui->shreds._staged_scratch2[ j ];
2516 0 : gui->shreds.staged_tail = gui->shreds.staged_head + kept_cnt;
2517 : /* Remap next_broadcast to preserve continuity after compaction */
2518 0 : gui->shreds.staged_next_broadcast = gui->shreds.staged_head + kept_before_next_cnt;
2519 :
2520 : /* sort scratch by slot increasing */
2521 0 : if( FD_LIKELY( archive_cnt ) ) {
2522 0 : fd_gui_slot_staged_shred_event_slot_sort_stable( gui->shreds._staged_scratch, archive_cnt, gui->shreds._staged_scratch2 );
2523 :
2524 0 : for( ulong i=0UL; i<archive_cnt; i++ ) {
2525 0 : if( FD_UNLIKELY( gui->shreds._staged_scratch[ i ].slot!=gui->shreds.history_slot ) ) {
2526 0 : fd_gui_slot_t * prev_slot = fd_gui_get_slot( gui, gui->shreds.history_slot );
2527 0 : if( FD_LIKELY( prev_slot ) ) prev_slot->shreds.end_offset = gui->shreds.history_tail;
2528 :
2529 0 : gui->shreds.history_slot = gui->shreds._staged_scratch[ i ].slot;
2530 :
2531 0 : fd_gui_slot_t * next_slot = fd_gui_get_slot( gui, gui->shreds.history_slot );
2532 0 : if( FD_LIKELY( next_slot ) ) next_slot->shreds.start_offset = gui->shreds.history_tail;
2533 0 : }
2534 :
2535 0 : gui->shreds.history[ gui->shreds.history_tail % FD_GUI_SHREDS_HISTORY_SZ ].timestamp = gui->shreds._staged_scratch[ i ].timestamp;
2536 0 : gui->shreds.history[ gui->shreds.history_tail % FD_GUI_SHREDS_HISTORY_SZ ].shred_idx = gui->shreds._staged_scratch[ i ].shred_idx;
2537 0 : gui->shreds.history[ gui->shreds.history_tail % FD_GUI_SHREDS_HISTORY_SZ ].event = gui->shreds._staged_scratch[ i ].event;
2538 :
2539 0 : gui->shreds.history_tail++;
2540 0 : }
2541 0 : }
2542 :
2543 0 : gui->summary.slot_rooted = root_slot;
2544 0 : fd_gui_printf_root_slot( gui );
2545 0 : fd_http_server_ws_broadcast( gui->http );
2546 0 : }
2547 :
2548 : void
2549 : fd_gui_handle_notarization_update( fd_gui_t * gui,
2550 0 : fd_tower_slot_confirmed_t const * notar ) {
2551 0 : if( FD_UNLIKELY( notar->slot!=ULONG_MAX && gui->summary.slot_optimistically_confirmed!=notar->slot && notar->kind==FD_TOWER_SLOT_CONFIRMED_CLUSTER ) ) {
2552 0 : fd_gui_handle_optimistically_confirmed_slot( gui, notar->slot );
2553 0 : }
2554 0 : }
2555 :
2556 : static inline void
2557 0 : try_publish_vote_status( fd_gui_t * gui, ulong _slot ) {
2558 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2559 :
2560 : /* For unstaked nodes, slot->vote_slot will always be ULONG_MAX */
2561 0 : if( FD_UNLIKELY( !slot || slot->vote_slot==ULONG_MAX || slot->reset_slot==ULONG_MAX ) ) return;
2562 :
2563 0 : ulong vote_distance = slot->reset_slot-slot->vote_slot;
2564 0 : if( FD_LIKELY( vote_distance<FD_GUI_SLOTS_CNT ) ) {
2565 0 : for( ulong s=slot->vote_slot; s<slot->reset_slot; s++ ) {
2566 0 : fd_gui_slot_t * cur = fd_gui_get_slot( gui, s );
2567 0 : if( FD_UNLIKELY( cur && cur->skipped ) ) vote_distance--;
2568 0 : }
2569 0 : }
2570 :
2571 0 : if( FD_UNLIKELY( gui->summary.vote_distance!=vote_distance ) ) {
2572 0 : gui->summary.vote_distance = vote_distance;
2573 0 : fd_gui_printf_vote_distance( gui );
2574 0 : fd_http_server_ws_broadcast( gui->http );
2575 0 : }
2576 :
2577 0 : if( FD_LIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_NON_VOTING ) ) {
2578 0 : if( FD_UNLIKELY( slot->vote_slot==ULONG_MAX || vote_distance>150UL ) ) {
2579 0 : if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_DELINQUENT ) ) {
2580 0 : gui->summary.vote_state = FD_GUI_VOTE_STATE_DELINQUENT;
2581 0 : fd_gui_printf_vote_state( gui );
2582 0 : fd_http_server_ws_broadcast( gui->http );
2583 0 : }
2584 0 : } else {
2585 0 : if( FD_UNLIKELY( gui->summary.vote_state!=FD_GUI_VOTE_STATE_VOTING ) ) {
2586 0 : gui->summary.vote_state = FD_GUI_VOTE_STATE_VOTING;
2587 0 : fd_gui_printf_vote_state( gui );
2588 0 : fd_http_server_ws_broadcast( gui->http );
2589 0 : }
2590 0 : }
2591 0 : }
2592 0 : }
2593 :
2594 : /* fd_gui_handle_tower_update handles updates from the tower tile, which
2595 : manages consensus related fork switching, rooting, slot confirmation. */
2596 : void
2597 : fd_gui_handle_tower_update( fd_gui_t * gui,
2598 : fd_tower_slot_done_t const * tower,
2599 0 : long now ) {
2600 0 : (void)now;
2601 :
2602 : /* handle new root */
2603 0 : if( FD_LIKELY( tower->root_slot!=ULONG_MAX && gui->summary.slot_rooted!=tower->root_slot ) ) {
2604 0 : fd_gui_handle_rooted_slot( gui, tower->root_slot );
2605 0 : }
2606 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, tower->replay_slot );
2607 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, tower->replay_slot, ULONG_MAX );
2608 0 : slot->reset_slot = tower->reset_slot;
2609 :
2610 0 : try_publish_vote_status( gui, tower->replay_slot );
2611 :
2612 0 : if( FD_LIKELY( gui->summary.slot_reset!=tower->reset_slot ) ) {
2613 0 : gui->summary.slot_reset = tower->reset_slot;
2614 0 : fd_gui_printf_reset_slot( gui );
2615 0 : fd_http_server_ws_broadcast( gui->http );
2616 0 : }
2617 0 : }
2618 :
2619 : void
2620 : fd_gui_handle_replay_update( fd_gui_t * gui,
2621 : fd_gui_slot_completed_t * slot_completed,
2622 : fd_hash_t const * block_hash,
2623 : ulong vote_slot,
2624 : ulong storage_slot,
2625 : ulong identity_balance,
2626 0 : long now ) {
2627 0 : (void)now;
2628 0 : if( FD_LIKELY( gui->summary.slot_storage!=storage_slot ) ) {
2629 0 : gui->summary.slot_storage = storage_slot;
2630 0 : fd_gui_printf_storage_slot( gui );
2631 0 : fd_http_server_ws_broadcast( gui->http );
2632 0 : }
2633 :
2634 0 : if( FD_UNLIKELY( identity_balance!=ULONG_MAX && gui->summary.identity_account_balance!=identity_balance ) ) {
2635 0 : gui->summary.identity_account_balance = identity_balance;
2636 :
2637 0 : fd_gui_printf_identity_balance( gui );
2638 0 : fd_http_server_ws_broadcast( gui->http );
2639 0 : }
2640 :
2641 0 : if( FD_UNLIKELY( gui->summary.boot_progress.catching_up_first_replay_slot==ULONG_MAX ) ) {
2642 0 : gui->summary.boot_progress.catching_up_first_replay_slot = slot_completed->slot;
2643 0 : }
2644 :
2645 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, slot_completed->slot );
2646 0 : if( FD_UNLIKELY( slot ) ) {
2647 : /* Its possible that this slot was labeled as skipped by another
2648 : consensus fork at some point in the past. In this case no need to
2649 : clear it, but we should update parent_slot */
2650 0 : slot->parent_slot = slot_completed->parent_slot;
2651 0 : } else {
2652 0 : slot = fd_gui_clear_slot( gui, slot_completed->slot, slot_completed->parent_slot );
2653 0 : }
2654 :
2655 0 : if( FD_UNLIKELY( slot->mine ) ) {
2656 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, slot->slot );
2657 0 : if( FD_LIKELY( lslot ) ) fd_memcpy( lslot->block_hash.uc, block_hash->uc, sizeof(fd_hash_t) );
2658 0 : }
2659 :
2660 0 : slot->completed_time = slot_completed->completed_time;
2661 0 : slot->parent_slot = slot_completed->parent_slot;
2662 0 : slot->max_compute_units = fd_uint_if( slot_completed->max_compute_units==UINT_MAX, slot->max_compute_units, slot_completed->max_compute_units );
2663 0 : if( FD_LIKELY( slot->level<FD_GUI_SLOT_LEVEL_COMPLETED ) ) {
2664 : /* Typically a slot goes from INCOMPLETE to COMPLETED but it can
2665 : happen that it starts higher. One such case is when we
2666 : optimistically confirm a higher slot that skips this one, but
2667 : then later we replay this one anyway to track the bank fork. */
2668 :
2669 0 : if( FD_LIKELY( gui->summary.slot_optimistically_confirmed!=ULONG_MAX && slot->slot<gui->summary.slot_optimistically_confirmed ) ) {
2670 : /* Cluster might have already optimistically confirmed by the time
2671 : we finish replaying it. */
2672 0 : slot->level = FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED;
2673 0 : } else {
2674 0 : slot->level = FD_GUI_SLOT_LEVEL_COMPLETED;
2675 0 : }
2676 0 : }
2677 0 : slot->total_txn_cnt = slot_completed->total_txn_cnt;
2678 0 : slot->vote_txn_cnt = slot_completed->vote_txn_cnt;
2679 0 : slot->failed_txn_cnt = slot_completed->failed_txn_cnt;
2680 0 : slot->nonvote_failed_txn_cnt = slot_completed->nonvote_failed_txn_cnt;
2681 0 : slot->transaction_fee = slot_completed->transaction_fee;
2682 0 : slot->priority_fee = slot_completed->priority_fee;
2683 0 : slot->tips = slot_completed->tips;
2684 0 : slot->compute_units = slot_completed->compute_units;
2685 0 : slot->shred_cnt = slot_completed->shred_cnt;
2686 0 : slot->vote_slot = vote_slot;
2687 :
2688 0 : try_publish_vote_status( gui, slot_completed->slot );
2689 :
2690 0 : if( FD_UNLIKELY( gui->epoch.has_epoch[ 0 ] && slot->slot==gui->epoch.epochs[ 0 ].end_slot ) ) {
2691 0 : gui->epoch.epochs[ 0 ].end_time = slot->completed_time;
2692 0 : } else if( FD_UNLIKELY( gui->epoch.has_epoch[ 1 ] && slot->slot==gui->epoch.epochs[ 1 ].end_slot ) ) {
2693 0 : gui->epoch.epochs[ 1 ].end_time = slot->completed_time;
2694 0 : }
2695 :
2696 : /* Broadcast new skip rate if one of our slots got completed. */
2697 0 : if( FD_LIKELY( slot->mine ) ) {
2698 0 : for( ulong i=0UL; i<2UL; i++ ) {
2699 0 : if( FD_LIKELY( slot->slot>=gui->epoch.epochs[ i ].start_slot && slot->slot<=gui->epoch.epochs[ i ].end_slot ) ) {
2700 0 : fd_gui_printf_skip_rate( gui, i );
2701 0 : fd_http_server_ws_broadcast( gui->http );
2702 0 : break;
2703 0 : }
2704 0 : }
2705 0 : }
2706 :
2707 : /* We'll treat the latest slot_complete from replay as the reset slot.
2708 : We get an explicit reset_slot from tower, but that message may come
2709 : in before we get the slot_complete from replay. */
2710 0 : if( FD_UNLIKELY( gui->summary.slot_completed!=slot->slot ) ) {
2711 0 : fd_gui_handle_reset_slot( gui, slot->slot, now );
2712 0 : }
2713 :
2714 : /* Add a "slot complete" event for all of the shreds in this slot */
2715 0 : if( FD_UNLIKELY( slot->shred_cnt > FD_GUI_MAX_SHREDS_PER_BLOCK ) ) FD_LOG_ERR(( "unexpected shred_cnt=%lu", (ulong)slot->shred_cnt ));
2716 0 : fd_gui_slot_staged_shred_event_t * slot_complete_event = &gui->shreds.staged[ gui->shreds.staged_tail % FD_GUI_SHREDS_STAGING_SZ ];
2717 0 : gui->shreds.staged_tail++;
2718 0 : slot_complete_event->event = FD_GUI_SLOT_SHRED_SHRED_SLOT_COMPLETE;
2719 0 : slot_complete_event->timestamp = slot_completed->completed_time;
2720 0 : slot_complete_event->shred_idx = USHORT_MAX;
2721 0 : slot_complete_event->slot = slot->slot;
2722 0 : }
2723 :
2724 : void
2725 : fd_gui_plugin_message( fd_gui_t * gui,
2726 : ulong plugin_msg,
2727 : uchar const * msg,
2728 0 : long now ) {
2729 :
2730 0 : switch( plugin_msg ) {
2731 0 : case FD_PLUGIN_MSG_SLOT_ROOTED:
2732 0 : fd_gui_handle_rooted_slot_legacy( gui, (ulong *)msg );
2733 0 : break;
2734 0 : case FD_PLUGIN_MSG_SLOT_OPTIMISTICALLY_CONFIRMED:
2735 0 : fd_gui_handle_optimistically_confirmed_slot( gui, ((ulong *)msg)[0] );
2736 0 : break;
2737 0 : case FD_PLUGIN_MSG_SLOT_COMPLETED: {
2738 0 : fd_gui_handle_completed_slot( gui, (ulong *)msg, now );
2739 0 : break;
2740 0 : }
2741 0 : case FD_PLUGIN_MSG_LEADER_SCHEDULE: {
2742 0 : FD_STATIC_ASSERT( sizeof(fd_stake_weight_msg_t)==6*sizeof(ulong), "new fields breaks things" );
2743 0 : fd_gui_handle_leader_schedule( gui, (fd_stake_weight_msg_t *)msg, now );
2744 0 : break;
2745 0 : }
2746 0 : case FD_PLUGIN_MSG_SLOT_START: {
2747 0 : ulong slot = ((ulong *)msg)[ 0 ];
2748 0 : ulong parent_slot = ((ulong *)msg)[ 1 ];
2749 0 : fd_gui_handle_slot_start( gui, slot, parent_slot, now );
2750 0 : break;
2751 0 : }
2752 0 : case FD_PLUGIN_MSG_SLOT_END: {
2753 0 : ulong slot = ((ulong *)msg)[ 0 ];
2754 0 : ulong cus_used = ((ulong *)msg)[ 1 ];
2755 0 : fd_gui_handle_slot_end( gui, slot, cus_used, now );
2756 0 : break;
2757 0 : }
2758 0 : case FD_PLUGIN_MSG_GOSSIP_UPDATE: {
2759 0 : fd_gui_handle_gossip_update( gui, msg );
2760 0 : break;
2761 0 : }
2762 0 : case FD_PLUGIN_MSG_VOTE_ACCOUNT_UPDATE: {
2763 0 : fd_gui_handle_vote_account_update( gui, msg );
2764 0 : break;
2765 0 : }
2766 0 : case FD_PLUGIN_MSG_VALIDATOR_INFO: {
2767 0 : fd_gui_handle_validator_info_update( gui, msg );
2768 0 : break;
2769 0 : }
2770 0 : case FD_PLUGIN_MSG_SLOT_RESET: {
2771 0 : fd_gui_handle_reset_slot_legacy( gui, (ulong *)msg, now );
2772 0 : break;
2773 0 : }
2774 0 : case FD_PLUGIN_MSG_BALANCE: {
2775 0 : fd_gui_handle_balance_update( gui, (ulong *)msg );
2776 0 : break;
2777 0 : }
2778 0 : case FD_PLUGIN_MSG_START_PROGRESS: {
2779 0 : fd_gui_handle_start_progress( gui, msg );
2780 0 : break;
2781 0 : }
2782 0 : case FD_PLUGIN_MSG_GENESIS_HASH_KNOWN: {
2783 0 : fd_gui_handle_genesis_hash( gui, msg );
2784 0 : break;
2785 0 : }
2786 0 : case FD_PLUGIN_MSG_BLOCK_ENGINE_UPDATE: {
2787 0 : fd_gui_handle_block_engine_update( gui, msg );
2788 0 : break;
2789 0 : }
2790 0 : default:
2791 0 : FD_LOG_ERR(( "Unhandled plugin msg: 0x%lx", plugin_msg ));
2792 0 : break;
2793 0 : }
2794 0 : }
2795 :
2796 : void
2797 : fd_gui_became_leader( fd_gui_t * gui,
2798 : ulong _slot,
2799 : long start_time_nanos,
2800 : long end_time_nanos,
2801 : ulong max_compute_units,
2802 0 : ulong max_microblocks ) {
2803 0 : if( FD_LIKELY( gui->summary.is_full_client && gui->leader_slot!=ULONG_MAX ) ) {
2804 : /* stop sampling for other leader slot in progress */
2805 0 : fd_gui_handle_slot_end( gui, gui->leader_slot, ULONG_MAX, start_time_nanos );
2806 0 : }
2807 :
2808 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2809 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
2810 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
2811 0 : if( FD_UNLIKELY( !lslot ) ) return;
2812 :
2813 0 : slot->max_compute_units = (uint)max_compute_units;
2814 0 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, start_time_nanos, lslot->leader_start_time );
2815 0 : lslot->leader_end_time = end_time_nanos;
2816 0 : if( FD_LIKELY( lslot->txs.microblocks_upper_bound==USHORT_MAX ) ) lslot->txs.microblocks_upper_bound = (ushort)max_microblocks;
2817 :
2818 0 : if( FD_UNLIKELY( gui->summary.is_full_client ) ) fd_gui_handle_slot_start( gui, slot->slot, slot->parent_slot, start_time_nanos );
2819 0 : }
2820 :
2821 : void
2822 : fd_gui_unbecame_leader( fd_gui_t * gui,
2823 : ulong _slot,
2824 : fd_done_packing_t const * done_packing,
2825 0 : long now ) {
2826 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2827 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
2828 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
2829 0 : if( FD_LIKELY( !lslot ) ) return;
2830 0 : lslot->txs.microblocks_upper_bound = (uint)done_packing->microblocks_in_slot;
2831 0 : fd_memcpy( lslot->scheduler_stats, done_packing, sizeof(fd_done_packing_t) );
2832 :
2833 : /* fd_gui_handle_slot_end may have already been called in response to
2834 : a "became_leader" message for a subseqeunt slot. */
2835 0 : if( FD_UNLIKELY( gui->summary.is_full_client && gui->leader_slot==_slot ) ) fd_gui_handle_slot_end( gui, slot->slot, ULONG_MAX, now );
2836 0 : }
2837 :
2838 : void
2839 : fd_gui_microblock_execution_begin( fd_gui_t * gui,
2840 : long now,
2841 : ulong _slot,
2842 : fd_txn_p_t * txns,
2843 : ulong txn_cnt,
2844 : uint microblock_idx,
2845 0 : ulong pack_txn_idx ) {
2846 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2847 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
2848 :
2849 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
2850 0 : if( FD_UNLIKELY( !lslot ) ) return;
2851 :
2852 0 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, now, lslot->leader_start_time );
2853 :
2854 0 : if( FD_UNLIKELY( lslot->txs.start_offset==ULONG_MAX ) ) lslot->txs.start_offset = pack_txn_idx;
2855 0 : else lslot->txs.start_offset = fd_ulong_min( lslot->txs.start_offset, pack_txn_idx );
2856 :
2857 0 : gui->pack_txn_idx = fd_ulong_max( gui->pack_txn_idx, pack_txn_idx+txn_cnt-1UL );
2858 :
2859 0 : for( ulong i=0UL; i<txn_cnt; i++ ) {
2860 0 : fd_txn_p_t * txn_payload = &txns[ i ];
2861 0 : fd_txn_t * txn = TXN( txn_payload );
2862 :
2863 0 : ulong sig_rewards = FD_PACK_FEE_PER_SIGNATURE * txn->signature_cnt;
2864 0 : ulong priority_rewards = ULONG_MAX;
2865 0 : ulong requested_execution_cus = ULONG_MAX;
2866 0 : ulong precompile_sigs = ULONG_MAX;
2867 0 : ulong requested_loaded_accounts_data_cost = ULONG_MAX;
2868 0 : uint _flags;
2869 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 );
2870 0 : sig_rewards += FD_PACK_FEE_PER_SIGNATURE * precompile_sigs;
2871 0 : sig_rewards = sig_rewards * FD_PACK_TXN_FEE_BURN_PCT / 100UL;
2872 :
2873 0 : fd_gui_txn_t * txn_entry = gui->txs[ (pack_txn_idx + i)%FD_GUI_TXN_HISTORY_SZ ];
2874 0 : fd_memcpy(txn_entry->signature, txn_payload->payload + txn->signature_off, FD_SHA512_HASH_SZ);
2875 0 : txn_entry->timestamp_arrival_nanos = txn_payload->scheduler_arrival_time_nanos;
2876 0 : txn_entry->compute_units_requested = cost_estimate & 0x1FFFFFU;
2877 0 : txn_entry->priority_fee = priority_rewards;
2878 0 : txn_entry->transaction_fee = sig_rewards;
2879 0 : txn_entry->timestamp_delta_start_nanos = (int)(now - lslot->leader_start_time);
2880 0 : txn_entry->source_ipv4 = txn_payload->source_ipv4;
2881 0 : txn_entry->source_tpu = txn_payload->source_tpu;
2882 0 : txn_entry->microblock_idx = microblock_idx;
2883 0 : txn_entry->flags |= (uchar)FD_GUI_TXN_FLAGS_STARTED;
2884 0 : txn_entry->flags &= (uchar)(~(uchar)(FD_GUI_TXN_FLAGS_IS_SIMPLE_VOTE | FD_GUI_TXN_FLAGS_FROM_BUNDLE));
2885 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);
2886 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);
2887 0 : }
2888 :
2889 : /* At the moment, bank publishes at most 1 transaction per microblock,
2890 : even if it received microblocks with multiple transactions
2891 : (i.e. a bundle). This means that we need to calculate microblock
2892 : count here based on the transaction count. */
2893 0 : lslot->txs.begin_microblocks += (uint)txn_cnt;
2894 0 : }
2895 :
2896 : void
2897 : fd_gui_microblock_execution_end( fd_gui_t * gui,
2898 : long now,
2899 : ulong bank_idx,
2900 : ulong _slot,
2901 : ulong txn_cnt,
2902 : fd_txn_p_t * txns,
2903 : ulong pack_txn_idx,
2904 : uchar txn_start_pct,
2905 : uchar txn_load_end_pct,
2906 : uchar txn_end_pct,
2907 : uchar txn_preload_end_pct,
2908 0 : ulong tips ) {
2909 0 : if( FD_UNLIKELY( 1UL!=txn_cnt ) ) FD_LOG_ERR(( "gui expects 1 txn per microblock from bank, found %lu", txn_cnt ));
2910 :
2911 0 : fd_gui_slot_t * slot = fd_gui_get_slot( gui, _slot );
2912 0 : if( FD_UNLIKELY( !slot ) ) slot = fd_gui_clear_slot( gui, _slot, ULONG_MAX );
2913 :
2914 0 : fd_gui_leader_slot_t * lslot = fd_gui_get_leader_slot( gui, _slot );
2915 0 : if( FD_UNLIKELY( !lslot ) ) return;
2916 :
2917 0 : lslot->leader_start_time = fd_long_if( lslot->leader_start_time==LONG_MAX, now, lslot->leader_start_time );
2918 :
2919 0 : if( FD_UNLIKELY( lslot->txs.end_offset==ULONG_MAX ) ) lslot->txs.end_offset = pack_txn_idx + txn_cnt;
2920 0 : else lslot->txs.end_offset = fd_ulong_max( lslot->txs.end_offset, pack_txn_idx+txn_cnt );
2921 :
2922 0 : gui->pack_txn_idx = fd_ulong_max( gui->pack_txn_idx, pack_txn_idx+txn_cnt-1UL );
2923 :
2924 0 : for( ulong i=0UL; i<txn_cnt; i++ ) {
2925 0 : fd_txn_p_t * txn_p = &txns[ i ];
2926 :
2927 0 : fd_gui_txn_t * txn_entry = gui->txs[ (pack_txn_idx + i)%FD_GUI_TXN_HISTORY_SZ ];
2928 0 : txn_entry->bank_idx = bank_idx & 0x3FU;
2929 0 : txn_entry->compute_units_consumed = txn_p->bank_cu.actual_consumed_cus & 0x1FFFFFU;
2930 0 : txn_entry->error_code = (txn_p->flags >> 24) & 0x3FU;
2931 0 : txn_entry->timestamp_delta_end_nanos = (int)(now - lslot->leader_start_time);
2932 0 : txn_entry->txn_start_pct = txn_start_pct;
2933 0 : txn_entry->txn_load_end_pct = txn_load_end_pct;
2934 0 : txn_entry->txn_end_pct = txn_end_pct;
2935 0 : txn_entry->txn_preload_end_pct = txn_preload_end_pct;
2936 0 : txn_entry->tips = tips;
2937 0 : txn_entry->flags |= (uchar)FD_GUI_TXN_FLAGS_ENDED;
2938 0 : txn_entry->flags &= (uchar)(~(uchar)FD_GUI_TXN_FLAGS_LANDED_IN_BLOCK);
2939 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);
2940 0 : }
2941 :
2942 0 : lslot->txs.end_microblocks = lslot->txs.end_microblocks + (uint)txn_cnt;
2943 0 : }
|