Line data Source code
1 : #ifndef HEADER_fd_src_disco_gui_fd_gui_h
2 : #define HEADER_fd_src_disco_gui_fd_gui_h
3 :
4 : #include "fd_gui_peers.h"
5 :
6 : #include "../topo/fd_topo.h"
7 :
8 : #include "../../ballet/txn/fd_txn.h"
9 : #include "../../disco/tiles.h"
10 : #include "../../disco/fd_txn_p.h"
11 : #include "../../discof/restore/fd_snapct_tile.h"
12 : #include "../../discof/tower/fd_tower_tile.h"
13 : #include "../../flamenco/leaders/fd_leaders.h"
14 : #include "../../flamenco/types/fd_types_custom.h"
15 : #include "../../util/fd_util_base.h"
16 : #include "../../util/hist/fd_histf.h"
17 : #include "../../waltz/http/fd_http_server.h"
18 :
19 : /* frankendancer only */
20 : #define FD_GUI_MAX_PEER_CNT ( 40200UL)
21 :
22 : /* frankendancer only */
23 0 : #define FD_GUI_START_PROGRESS_TYPE_INITIALIZING ( 0)
24 0 : #define FD_GUI_START_PROGRESS_TYPE_SEARCHING_FOR_FULL_SNAPSHOT ( 1)
25 0 : #define FD_GUI_START_PROGRESS_TYPE_DOWNLOADING_FULL_SNAPSHOT ( 2)
26 0 : #define FD_GUI_START_PROGRESS_TYPE_SEARCHING_FOR_INCREMENTAL_SNAPSHOT ( 3)
27 0 : #define FD_GUI_START_PROGRESS_TYPE_DOWNLOADING_INCREMENTAL_SNAPSHOT ( 4)
28 0 : #define FD_GUI_START_PROGRESS_TYPE_CLEANING_BLOCK_STORE ( 5)
29 0 : #define FD_GUI_START_PROGRESS_TYPE_CLEANING_ACCOUNTS ( 6)
30 0 : #define FD_GUI_START_PROGRESS_TYPE_LOADING_LEDGER ( 7)
31 0 : #define FD_GUI_START_PROGRESS_TYPE_PROCESSING_LEDGER ( 8)
32 0 : #define FD_GUI_START_PROGRESS_TYPE_STARTING_SERVICES ( 9)
33 0 : #define FD_GUI_START_PROGRESS_TYPE_HALTED (10)
34 0 : #define FD_GUI_START_PROGRESS_TYPE_WAITING_FOR_SUPERMAJORITY (11)
35 0 : #define FD_GUI_START_PROGRESS_TYPE_RUNNING (12)
36 :
37 : /* frankendancer only */
38 : struct fd_gui_gossip_peer {
39 : fd_pubkey_t pubkey[ 1 ];
40 : ulong wallclock;
41 : ushort shred_version;
42 :
43 : int has_version;
44 : struct {
45 : ushort major;
46 : ushort minor;
47 : ushort patch;
48 :
49 : int has_commit;
50 : uint commit;
51 :
52 : uint feature_set;
53 : } version;
54 :
55 : struct {
56 : uint ipv4;
57 : ushort port;
58 : } sockets[ 12 ];
59 : };
60 :
61 : /* frankendancer only */
62 : struct fd_gui_vote_account {
63 : fd_pubkey_t pubkey[ 1 ];
64 : fd_pubkey_t vote_account[ 1 ];
65 :
66 : ulong activated_stake;
67 : ulong last_vote;
68 : ulong root_slot;
69 : ulong epoch_credits;
70 : uchar commission;
71 : int delinquent;
72 : };
73 :
74 : /* frankendancer only */
75 : struct fd_gui_validator_info {
76 : fd_pubkey_t pubkey[ 1 ];
77 :
78 : char name[ 64 ];
79 : char website[ 128 ];
80 : char details[ 256 ];
81 : char icon_uri[ 128 ];
82 : };
83 :
84 : /* frankendancer only */
85 : #define FD_GUI_SLOT_LEADER_UNSTARTED (0UL)
86 : #define FD_GUI_SLOT_LEADER_STARTED (1UL)
87 : #define FD_GUI_SLOT_LEADER_ENDED (2UL)
88 :
89 0 : #define FD_GUI_SLOTS_CNT (864000UL) /* 2x 432000 */
90 0 : #define FD_GUI_LEADER_CNT (4096UL)
91 :
92 0 : #define FD_GUI_TPS_HISTORY_WINDOW_DURATION_SECONDS (10L)
93 0 : #define FD_GUI_TPS_HISTORY_SAMPLE_CNT (150UL)
94 :
95 0 : #define FD_GUI_TILE_TIMER_SNAP_CNT (512UL)
96 : #define FD_GUI_TILE_TIMER_LEADER_DOWNSAMPLE_CNT (50UL) /* 500ms / 10ms */
97 0 : #define FD_GUI_SCHEDULER_COUNT_SNAP_CNT (512UL)
98 : #define FD_GUI_SCHEDULER_COUNT_LEADER_DOWNSAMPLE_CNT (50UL) /* 500ms / 10ms */
99 : #define FD_GUI_TILE_TIMER_TILE_CNT (256UL)
100 :
101 0 : #define FD_GUI_VOTE_STATE_NON_VOTING (0)
102 0 : #define FD_GUI_VOTE_STATE_VOTING (1)
103 0 : #define FD_GUI_VOTE_STATE_DELINQUENT (2)
104 :
105 0 : #define FD_GUI_BOOT_PROGRESS_TYPE_JOINING_GOSSIP (1)
106 0 : #define FD_GUI_BOOT_PROGRESS_TYPE_LOADING_FULL_SNAPSHOT (2)
107 0 : #define FD_GUI_BOOT_PROGRESS_TYPE_LOADING_INCREMENTAL_SNAPSHOT (3)
108 0 : #define FD_GUI_BOOT_PROGRESS_TYPE_CATCHING_UP (4)
109 0 : #define FD_GUI_BOOT_PROGRESS_TYPE_RUNNING (5)
110 :
111 0 : #define FD_GUI_BOOT_PROGRESS_FULL_SNAPSHOT_IDX (0UL)
112 0 : #define FD_GUI_BOOT_PROGRESS_INCREMENTAL_SNAPSHOT_IDX (1UL)
113 0 : #define FD_GUI_BOOT_PROGRESS_SNAPSHOT_CNT (2UL)
114 :
115 0 : #define FD_GUI_SLOT_LEVEL_INCOMPLETE (0)
116 0 : #define FD_GUI_SLOT_LEVEL_COMPLETED (1)
117 0 : #define FD_GUI_SLOT_LEVEL_OPTIMISTICALLY_CONFIRMED (2)
118 0 : #define FD_GUI_SLOT_LEVEL_ROOTED (3)
119 0 : #define FD_GUI_SLOT_LEVEL_FINALIZED (4)
120 :
121 : /* Ideally, we would store an entire epoch's worth of transactions. If
122 : we assume any given validator will have at most 5% stake, and average
123 : transactions per slot is around 10_000, then an epoch will have about
124 : 432_000*10_000*0.05 transactions (~2^28).
125 :
126 : Unfortunately, the transaction struct is 100+ bytes. If we sized the
127 : array to 2^28 entries then the memory required would be ~26GB. In
128 : order to keep memory usage to a more reasonable level, we'll
129 : arbitrarily use a fourth of that size. */
130 0 : #define FD_GUI_TXN_HISTORY_SZ (1UL<<26UL)
131 :
132 0 : #define FD_GUI_TXN_FLAGS_STARTED ( 1U)
133 0 : #define FD_GUI_TXN_FLAGS_ENDED ( 2U)
134 0 : #define FD_GUI_TXN_FLAGS_IS_SIMPLE_VOTE ( 4U)
135 0 : #define FD_GUI_TXN_FLAGS_FROM_BUNDLE ( 8U)
136 0 : #define FD_GUI_TXN_FLAGS_LANDED_IN_BLOCK (16U)
137 :
138 0 : #define FD_GUI_TURBINE_RECV_TIMESTAMPS (750UL)
139 :
140 : /* One use case for tracking ingress shred slot is to estimate when we
141 : have caught up to the tip of the blockchain. A naive approach would
142 : be to track the maximum seen slot.
143 :
144 : maximum_seen_slot = fd_ulong_max( maximum_seen_slot, new_slot_from_shred_tile );
145 :
146 : Unfortunately, this doesn't always work because a validator can send
147 : a slot number that is arbitrarily large on a false fork. Also, these
148 : shreds can be for a repair response, which can be arbitrarily small.
149 :
150 : The prospects here seem bleak, but not all hope is lost! We know
151 : that for a sufficiently large historical time window there is a high
152 : probability that at least some of the slots we observe will be valid
153 : recent turbine slots. For a sufficiently small window there is a high
154 : probability that all the observed shred slots are non-malicious (i.e.
155 : not arbitrarily large).
156 :
157 : In practice shred slots are almost always non-malicious. We can keep
158 : a history of the 12 largest slots we've seen in the past 4.8 seconds.
159 : We'll consider the "tip" of the blockchain to be the maximum slot in
160 : our history. This way, if we receive maliciously large slot number,
161 : it will be evicted after 4.8 seconds. If we receive a small slot from
162 : a repair response it will be ignored because we've seen other larger
163 : slots, meaning that our estimate is eventually consistent. For
164 : monitoring purposes this is sufficient.
165 :
166 : The worst case scenario is that this validator receives an incorrect
167 : shred slot slot more than once every 3 leader rotations. Before the
168 : previous incorrect slot is evicted from the history, a new one takes
169 : it's place and we wouldn't never get a correct estimate of the tip of
170 : the chain. We also would indefinitely think that that we haven't
171 : caught up. This would require the chain having perpetually malicious
172 : leaders with adjacent rotations. If this happens, Solana has bigger
173 : problems. */
174 0 : #define FD_GUI_TURBINE_SLOT_HISTORY_SZ ( 12UL )
175 :
176 : /* Like the turbine slot, the latest repair slot can also swing to
177 : arbitrarily large values due to a malicious fork switch. The gui
178 : provides the same guarantees for freshness and accuracy. This
179 : history is somewhat larger to handle the increased repair bandwidth
180 : during catch up. */
181 0 : #define FD_GUI_REPAIR_SLOT_HISTORY_SZ ( 512UL )
182 :
183 : /* FD_GUI_*_CATCH_UP_HISTORY_SZ is the capacity of the record of slots
184 : seen from repair or turbine during the catch up stage at startup.
185 : These buffers are run-length encoded, so they will typically be very
186 : small. The worst-case scenario is unbounded, so bounds here are
187 : determined heuristically. */
188 0 : #define FD_GUI_REPAIR_CATCH_UP_HISTORY_SZ (4096UL)
189 0 : #define FD_GUI_TURBINE_CATCH_UP_HISTORY_SZ (4096UL)
190 :
191 : /* FD_GUI_SHREDS_STAGING_SZ is number of shred events we'll retain in
192 : in a small staging area. The lifecycle of a shred looks something
193 : like the following
194 :
195 : states] turbine -> repairing (optional) -> processing -> waiting_for_siblings -> slot_complete
196 : events] ^-repair_requested ^-shred_received/shred_repaired ^-shred_replayed ^-max(shred_replayed)
197 :
198 : We're interested in recording timestamps for state transitions (which
199 : these docs call "shred events"). Unfortunately, due to forking,
200 : duplicate packets, etc we can't make any guarantees about ordering or
201 : uniqueness for these event timestamps. Instead the GUI just records
202 : timestamps for all events as they occur and put them into an array.
203 : Newly recorded event timestamps are also broadcast live to WebSocket
204 : consumers.
205 :
206 : The amount of shred events for non-finalized blocks can't really be
207 : bounded, so we use generous estimates here to set a memory bound. */
208 0 : #define FD_GUI_MAX_SHREDS_PER_BLOCK (32UL*1024UL)
209 0 : #define FD_GUI_MAX_EVENTS_PER_SHRED ( 32UL)
210 0 : #define FD_GUI_SHREDS_STAGING_SZ (32UL * FD_GUI_MAX_SHREDS_PER_BLOCK * FD_GUI_MAX_EVENTS_PER_SHRED)
211 :
212 : /* FD_GUI_SHREDS_HISTORY_SZ the number of shred events in our historical
213 : shred store. Shred events here belong to finalized slots which means
214 : we won't record any additional shred updates for these slots.
215 :
216 : All shred events for a given slot will be places in a contiguous
217 : chunk in the array, and the bounding indicies are stored in the
218 : fd_gui_slot_t slot history. Within a slot chunk, shred events are
219 : ordered in the ordered they were recorded by the gui tile.
220 :
221 : Ideally, we have enough space to store an epoch's worth of events,
222 : but we are limited by realistic memory consumption. Instead, we pick
223 : bound heuristically. */
224 0 : #define FD_GUI_SHREDS_HISTORY_SZ (432000UL*2000UL*4UL / 6UL)
225 :
226 0 : #define FD_GUI_SLOT_SHRED_REPAIR_REQUEST (0UL)
227 0 : #define FD_GUI_SLOT_SHRED_SHRED_RECEIVED_TURBINE (1UL)
228 0 : #define FD_GUI_SLOT_SHRED_SHRED_RECEIVED_REPAIR (2UL)
229 0 : #define FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_DONE (3UL)
230 0 : #define FD_GUI_SLOT_SHRED_SHRED_SLOT_COMPLETE (4UL)
231 : /* #define FD_GUI_SLOT_SHRED_SHRED_REPLAY_EXEC_START (5UL) // UNUSED */
232 0 : #define FD_GUI_SLOT_SHRED_SHRED_PUBLISHED (6UL)
233 :
234 0 : #define FD_GUI_SLOT_RANKINGS_SZ (100UL)
235 0 : #define FD_GUI_SLOT_RANKING_TYPE_ASC (0)
236 0 : #define FD_GUI_SLOT_RANKING_TYPE_DESC (1)
237 :
238 : struct fd_gui_tile_timers {
239 : ulong timers[ FD_METRICS_ENUM_TILE_REGIME_CNT ];
240 : int in_backp;
241 : uint status;
242 : ulong heartbeat;
243 : ulong backp_cnt;
244 : ulong nvcsw;
245 : ulong nivcsw;
246 : };
247 :
248 : typedef struct fd_gui_tile_timers fd_gui_tile_timers_t;
249 :
250 : struct fd_gui_scheduler_counts {
251 : long sample_time_ns;
252 : ulong regular;
253 : ulong votes;
254 : ulong conflicting;
255 : ulong bundles;
256 : };
257 :
258 : typedef struct fd_gui_scheduler_counts fd_gui_scheduler_counts_t;
259 :
260 : struct fd_gui_network_stats {
261 : /* total bytes accumulated */
262 : struct {
263 : ulong turbine;
264 : ulong gossip;
265 : ulong tpu;
266 : ulong repair;
267 : ulong metric;
268 : } in, out;
269 : };
270 :
271 : typedef struct fd_gui_network_stats fd_gui_network_stats_t;
272 :
273 : struct fd_gui_leader_slot {
274 : ulong slot;
275 : fd_hash_t block_hash;
276 : long leader_start_time; /* UNIX timestamp of when we first became leader in this slot */
277 : long leader_end_time; /* UNIX timestamp of when we stopped being leader in this slot */
278 :
279 : /* Stem tiles can exist in one of 8 distinct activity regimes at any
280 : given moment. One of these regimes, caughtup_postfrag, is the
281 : only regime where a tile is in a spin loop without doing any
282 : useful work. This info is useful from a monitoring perspective
283 : because it lets us estimate CPU utilization on a pinned core.
284 :
285 : Every 10ms, the gui tile samples the amount of time tiles spent
286 : in each regime in the past 10ms. This sample is used to infer
287 : the CPU utilization in the past 10ms. This utilization is
288 : streamed live to WebSocket clients.
289 :
290 : In additional to live utilization, we are interested in recording
291 : utilization during one of this validator's leader slots. The gui
292 : tile is continuously recording samples to storage with capacity
293 : FD_GUI_TILE_TIMER_SNAP_CNT. The sample index is recorded at the
294 : start and end of a leader slot, and the number of samples is
295 : downsampled to be at most FD_GUI_TILE_TIMER_LEADER_DOWNSAMPLE_CNT
296 : samples (e.g. if there was an unusually long leader slot) and
297 : inserted into historical storage with capacity FD_GUI_LEADER_CNT.
298 : FD_GUI_TILE_TIMER_TILE_CNT is the maximum number of tiles supported. */
299 : fd_gui_tile_timers_t tile_timers[ FD_GUI_TILE_TIMER_LEADER_DOWNSAMPLE_CNT ][ FD_GUI_TILE_TIMER_TILE_CNT ];
300 : ulong tile_timers_sample_cnt;
301 :
302 : fd_gui_scheduler_counts_t scheduler_counts[ FD_GUI_SCHEDULER_COUNT_LEADER_DOWNSAMPLE_CNT ][ 1 ];
303 : ulong scheduler_counts_sample_cnt;
304 :
305 : struct {
306 : uint microblocks_upper_bound; /* An upper bound on the number of microblocks in the slot. If the number of
307 : microblocks observed is equal to this, the slot can be considered over.
308 : Generally, the bound is set to a "final" state by a done packing message,
309 : which sets it to the exact number of microblocks, but sometimes this message
310 : is not sent, if the max upper bound published by poh was already correct. */
311 : uint begin_microblocks; /* The number of microblocks we have seen be started (sent) from pack to banks. */
312 : uint end_microblocks; /* The number of microblocks we have seen be ended (sent) from banks to poh. The
313 : slot is only considered over if the begin and end microblocks seen are both equal
314 : to the microblock upper bound. */
315 :
316 : ulong start_offset; /* The smallest pack transaction index for this slot. The first transaction for this slot will
317 : be written to gui->txs[ start_offset%FD_GUI_TXN_HISTORY_SZ ]. */
318 : ulong end_offset; /* The largest pack transaction index for this slot, plus 1. The last transaction for this
319 : slot will be written to gui->txs[ (start_offset-1)%FD_GUI_TXN_HISTORY_SZ ]. */
320 : } txs;
321 :
322 : fd_done_packing_t scheduler_stats[ 1 ];
323 :
324 : uchar unbecame_leader: 1;
325 : };
326 :
327 : typedef struct fd_gui_leader_slot fd_gui_leader_slot_t;
328 :
329 : struct fd_gui_turbine_slot {
330 : ulong slot;
331 : long timestamp;
332 : };
333 :
334 : typedef struct fd_gui_turbine_slot fd_gui_turbine_slot_t;
335 :
336 : struct fd_gui_slot_completed {
337 : ulong slot;
338 : long completed_time;
339 : ulong parent_slot;
340 : uint max_compute_units;
341 : uint total_txn_cnt;
342 : uint vote_txn_cnt;
343 : uint failed_txn_cnt;
344 : uint nonvote_failed_txn_cnt;
345 : ulong transaction_fee;
346 : ulong priority_fee;
347 : ulong tips;
348 : uint compute_units;
349 : uint shred_cnt;
350 : };
351 :
352 : typedef struct fd_gui_slot_completed fd_gui_slot_completed_t;
353 :
354 : struct fd_gui_slot_staged_shred_event {
355 : long timestamp;
356 : ulong slot;
357 : ushort shred_idx;
358 : uchar event;
359 : };
360 :
361 : typedef struct fd_gui_slot_staged_shred_event fd_gui_slot_staged_shred_event_t;
362 :
363 : struct __attribute__((packed)) fd_gui_slot_history_shred_event {
364 : long timestamp;
365 : ushort shred_idx;
366 : uchar event;
367 : };
368 :
369 : typedef struct fd_gui_slot_history_shred_event fd_gui_slot_history_shred_event_t;
370 :
371 : struct fd_gui_slot_ranking {
372 : ulong slot;
373 : ulong value;
374 : int type;
375 : };
376 : typedef struct fd_gui_slot_ranking fd_gui_slot_ranking_t;
377 :
378 : struct fd_gui_slot_rankings {
379 : fd_gui_slot_ranking_t largest_tips [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
380 : fd_gui_slot_ranking_t largest_fees [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
381 : fd_gui_slot_ranking_t largest_rewards [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
382 : fd_gui_slot_ranking_t largest_duration [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
383 : fd_gui_slot_ranking_t largest_compute_units [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
384 : fd_gui_slot_ranking_t largest_skipped [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
385 : fd_gui_slot_ranking_t largest_rewards_per_cu [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
386 : fd_gui_slot_ranking_t smallest_tips [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
387 : fd_gui_slot_ranking_t smallest_fees [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
388 : fd_gui_slot_ranking_t smallest_rewards [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
389 : fd_gui_slot_ranking_t smallest_rewards_per_cu[ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
390 : fd_gui_slot_ranking_t smallest_duration [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
391 : fd_gui_slot_ranking_t smallest_compute_units [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
392 : fd_gui_slot_ranking_t smallest_skipped [ FD_GUI_SLOT_RANKINGS_SZ+1UL ];
393 : };
394 :
395 : typedef struct fd_gui_slot_rankings fd_gui_slot_rankings_t;
396 :
397 : struct fd_gui_ephemeral_slot {
398 : ulong slot; /* ULONG_MAX indicates invalid/evicted */
399 : long timestamp_arrival_nanos;
400 : };
401 : typedef struct fd_gui_ephemeral_slot fd_gui_ephemeral_slot_t;
402 :
403 : struct __attribute__((packed)) fd_gui_txn {
404 : uchar signature[ FD_TXN_SIGNATURE_SZ ];
405 : ulong transaction_fee;
406 : ulong priority_fee;
407 : ulong tips;
408 : long timestamp_arrival_nanos;
409 :
410 : /* compute_units_requested has both execution and non-execution cus */
411 : uint compute_units_requested : 21; /* <= 1.4M */
412 : uint compute_units_consumed : 21; /* <= 1.4M */
413 : uint bank_idx : 6; /* in [0, 64) */
414 : uint error_code : 6; /* in [0, 64) */
415 : int timestamp_delta_start_nanos;
416 : int timestamp_delta_end_nanos;
417 :
418 : /* txn_{}_pct is used as a fraction of the total microblock
419 : duration. For example, txn_load_end_pct can be used to find the
420 : time when this transaction started executing:
421 :
422 : timestamp_delta_start_exec_nanos = (
423 : (timestamp_delta_end_nanos-timestamp_delta_start_nanos) *
424 : ((double)txn_{}_pct/USHORT_MAX)
425 : ) */
426 : uchar txn_start_pct;
427 : uchar txn_load_end_pct;
428 : uchar txn_end_pct;
429 : uchar txn_preload_end_pct;
430 : uchar flags; /* assigned with the FD_GUI_TXN_FLAGS_* macros */
431 : uchar source_tpu; /* FD_TXN_M_TPU_SOURCE_* */
432 : uint source_ipv4;
433 : uint microblock_idx;
434 : };
435 :
436 : typedef struct fd_gui_txn fd_gui_txn_t;
437 :
438 : struct fd_gui_txn_waterfall {
439 : struct {
440 : ulong quic;
441 : ulong udp;
442 : ulong gossip;
443 : ulong block_engine;
444 : ulong pack_cranked;
445 : } in;
446 :
447 : struct {
448 : ulong net_overrun;
449 : ulong quic_overrun;
450 : ulong quic_frag_drop;
451 : ulong quic_abandoned;
452 : ulong tpu_quic_invalid;
453 : ulong tpu_udp_invalid;
454 : ulong verify_overrun;
455 : ulong verify_parse;
456 : ulong verify_failed;
457 : ulong verify_duplicate;
458 : ulong dedup_duplicate;
459 : ulong resolv_lut_failed;
460 : ulong resolv_expired;
461 : ulong resolv_ancient;
462 : ulong resolv_no_ledger;
463 : ulong resolv_retained;
464 : ulong pack_invalid;
465 : ulong pack_invalid_bundle;
466 : ulong pack_expired;
467 : ulong pack_already_executed;
468 : ulong pack_retained;
469 : ulong pack_wait_full;
470 : ulong pack_leader_slow;
471 : ulong bank_invalid;
472 : ulong bank_nonce_already_advanced;
473 : ulong bank_nonce_advance_failed;
474 : ulong bank_nonce_wrong_blockhash;
475 : ulong block_success;
476 : ulong block_fail;
477 : } out;
478 : };
479 :
480 : typedef struct fd_gui_txn_waterfall fd_gui_txn_waterfall_t;
481 :
482 : struct fd_gui_tile_stats {
483 : long sample_time_nanos;
484 :
485 : ulong net_in_rx_bytes; /* Number of bytes received by the net or sock tile*/
486 : ulong quic_conn_cnt; /* Number of active QUIC connections */
487 : fd_histf_t bundle_rx_delay_hist; /* Histogram of bundle rx delay */
488 : ulong bundle_rtt_smoothed_nanos; /* RTT (nanoseconds) moving average */
489 : ulong verify_drop_cnt; /* Number of transactions dropped by verify tiles */
490 : ulong verify_total_cnt; /* Number of transactions received by verify tiles */
491 : ulong dedup_drop_cnt; /* Number of transactions dropped by dedup tile */
492 : ulong dedup_total_cnt; /* Number of transactions received by dedup tile */
493 : ulong pack_buffer_cnt; /* Number of buffered transactions in the pack tile */
494 : ulong pack_buffer_capacity; /* Total size of the pack transaction buffer */
495 : ulong bank_txn_exec_cnt; /* Number of transactions processed by the bank tile */
496 : ulong net_out_tx_bytes; /* Number of bytes sent by the net or sock tile */
497 : };
498 :
499 : typedef struct fd_gui_tile_stats fd_gui_tile_stats_t;
500 :
501 : struct fd_gui_slot {
502 : ulong slot;
503 : ulong parent_slot;
504 : ulong vote_slot;
505 : ulong reset_slot;
506 : uint max_compute_units;
507 : long completed_time;
508 : int mine;
509 : int skipped;
510 : int must_republish;
511 : int level;
512 : uint total_txn_cnt;
513 : uint vote_txn_cnt;
514 : uint failed_txn_cnt;
515 : uint nonvote_failed_txn_cnt;
516 : uint compute_units;
517 : ulong transaction_fee;
518 : ulong priority_fee;
519 : ulong tips;
520 : uint shred_cnt;
521 :
522 : /* Some slot info is only tracked for our own leader slots. These
523 : slots are kept in a separate buffer. */
524 : ulong leader_history_idx;
525 :
526 : fd_gui_txn_waterfall_t waterfall_begin[ 1 ];
527 : fd_gui_txn_waterfall_t waterfall_end[ 1 ];
528 :
529 : fd_gui_tile_stats_t tile_stats_begin[ 1 ];
530 : fd_gui_tile_stats_t tile_stats_end[ 1 ];
531 :
532 : struct {
533 : ulong start_offset; /* gui->shreds.history[ start_offset % FD_GUI_SHREDS_HISTORY_SZ ] is the first shred event in
534 : contiguous chunk of events in the shred history corresponding to this slot. */
535 : ulong end_offset; /* gui->shreds.history[ end_offset % FD_GUI_SHREDS_HISTORY_SZ ] is the last shred event in
536 : contiguous chunk of events in the shred history corresponding to this slot. */
537 : } shreds;
538 : };
539 :
540 : typedef struct fd_gui_slot fd_gui_slot_t;
541 :
542 : struct fd_gui {
543 : fd_http_server_t * http;
544 : fd_topo_t * topo;
545 :
546 : long next_sample_400millis;
547 : long next_sample_100millis;
548 : long next_sample_50millis;
549 : long next_sample_12_5millis;
550 : long next_sample_10millis;
551 :
552 : ulong leader_slot;
553 :
554 : struct {
555 : fd_pubkey_t identity_key[ 1 ];
556 : int has_vote_key;
557 : fd_pubkey_t vote_key[ 1 ];
558 : char vote_key_base58[ FD_BASE58_ENCODED_32_SZ ];
559 : char identity_key_base58[ FD_BASE58_ENCODED_32_SZ ];
560 :
561 : int is_full_client;
562 : char const * version;
563 : char const * cluster;
564 :
565 : ulong vote_distance;
566 : int vote_state;
567 :
568 : long startup_time_nanos;
569 :
570 : union {
571 : struct { /* frankendancer only */
572 : uchar phase;
573 : int startup_got_full_snapshot;
574 :
575 : ulong startup_incremental_snapshot_slot;
576 : uint startup_incremental_snapshot_peer_ip_addr;
577 : ushort startup_incremental_snapshot_peer_port;
578 : double startup_incremental_snapshot_elapsed_secs;
579 : double startup_incremental_snapshot_remaining_secs;
580 : double startup_incremental_snapshot_throughput;
581 : ulong startup_incremental_snapshot_total_bytes;
582 : ulong startup_incremental_snapshot_current_bytes;
583 :
584 : ulong startup_full_snapshot_slot;
585 : uint startup_full_snapshot_peer_ip_addr;
586 : ushort startup_full_snapshot_peer_port;
587 : double startup_full_snapshot_elapsed_secs;
588 : double startup_full_snapshot_remaining_secs;
589 : double startup_full_snapshot_throughput;
590 : ulong startup_full_snapshot_total_bytes;
591 : ulong startup_full_snapshot_current_bytes;
592 :
593 : ulong startup_ledger_slot;
594 : ulong startup_ledger_max_slot;
595 :
596 : ulong startup_waiting_for_supermajority_slot;
597 : ulong startup_waiting_for_supermajority_stake_pct;
598 : } startup_progress;
599 : struct { /* used in the full client */
600 : uchar phase;
601 : long joining_gossip_time_nanos;
602 : struct {
603 : ulong slot;
604 : uint peer_addr;
605 : ushort peer_port;
606 : ulong total_bytes_compressed;
607 : long reset_time_nanos; /* UNIX nanosecond timestamp */
608 : long sample_time_nanos;
609 : ulong reset_cnt;
610 :
611 : ulong read_bytes_compressed;
612 : char read_path[ PATH_MAX+30UL ]; /* URL or filesystem path. 30 is fd_cstr_nlen( "https://255.255.255.255:12345/", ULONG_MAX ) */
613 :
614 : ulong decompress_bytes_decompressed;
615 : ulong decompress_bytes_compressed;
616 :
617 : ulong insert_bytes_decompressed;
618 : char insert_path[ PATH_MAX ];
619 : ulong insert_accounts_current;
620 : } loading_snapshot[ FD_GUI_BOOT_PROGRESS_SNAPSHOT_CNT ];
621 :
622 : long catching_up_time_nanos;
623 : ulong catching_up_first_replay_slot;
624 : } boot_progress;
625 : };
626 :
627 : int schedule_strategy;
628 :
629 : ulong identity_account_balance;
630 : ulong vote_account_balance;
631 : ulong estimated_slot_duration_nanos;
632 :
633 : ulong sock_tile_cnt;
634 : ulong net_tile_cnt;
635 : ulong quic_tile_cnt;
636 : ulong verify_tile_cnt;
637 : ulong resolv_tile_cnt;
638 : ulong bank_tile_cnt;
639 : ulong shred_tile_cnt;
640 :
641 : ulong slot_rooted;
642 : ulong slot_optimistically_confirmed;
643 : ulong slot_completed;
644 : ulong slot_estimated;
645 : ulong slot_caught_up;
646 : ulong slot_repair;
647 : ulong slot_turbine;
648 : ulong slot_reset;
649 : ulong slot_storage;
650 : ulong active_fork_cnt;
651 :
652 : fd_gui_ephemeral_slot_t slots_max_turbine[ FD_GUI_TURBINE_SLOT_HISTORY_SZ+1UL ];
653 : fd_gui_ephemeral_slot_t slots_max_repair [ FD_GUI_REPAIR_SLOT_HISTORY_SZ +1UL ];
654 :
655 : /* catchup_* is run-length encoded. i.e. adjacent pairs represent
656 : contiguous runs */
657 : ulong catch_up_turbine[ FD_GUI_TURBINE_CATCH_UP_HISTORY_SZ ];
658 : ulong catch_up_turbine_sz;
659 :
660 : ulong catch_up_repair[ FD_GUI_REPAIR_CATCH_UP_HISTORY_SZ ];
661 : ulong catch_up_repair_sz;
662 :
663 : ulong estimated_tps_history_idx;
664 : ulong estimated_tps_history[ FD_GUI_TPS_HISTORY_SAMPLE_CNT ][ 3UL ];
665 :
666 : fd_gui_network_stats_t network_stats_current[ 1 ];
667 :
668 : fd_gui_txn_waterfall_t txn_waterfall_reference[ 1 ];
669 : fd_gui_txn_waterfall_t txn_waterfall_current[ 1 ];
670 :
671 : fd_gui_tile_stats_t tile_stats_reference[ 1 ];
672 : fd_gui_tile_stats_t tile_stats_current[ 1 ];
673 :
674 : ulong tile_timers_snap_idx;
675 : ulong tile_timers_snap_idx_slot_start;
676 : /* Temporary storage for samples. Will be downsampled into leader history on slot end. */
677 : fd_gui_tile_timers_t tile_timers_snap[ FD_GUI_TILE_TIMER_SNAP_CNT ][ FD_GUI_TILE_TIMER_TILE_CNT ];
678 :
679 : ulong scheduler_counts_snap_idx;
680 : ulong scheduler_counts_snap_idx_slot_start;
681 : /* Temporary storage for samples. Will be downsampled into leader history on slot end. */
682 : fd_gui_scheduler_counts_t scheduler_counts_snap[ FD_GUI_SCHEDULER_COUNT_SNAP_CNT ][ 1 ];
683 : } summary;
684 :
685 : fd_gui_slot_t slots[ FD_GUI_SLOTS_CNT ][ 1 ];
686 :
687 : /* used for estimating slot duration */
688 : fd_gui_turbine_slot_t turbine_slots[ FD_GUI_TURBINE_RECV_TIMESTAMPS ];
689 :
690 : fd_gui_leader_slot_t leader_slots[ FD_GUI_LEADER_CNT ][ 1 ];
691 : ulong leader_slots_cnt;
692 :
693 : fd_gui_txn_t txs[ FD_GUI_TXN_HISTORY_SZ ][ 1 ];
694 : ulong pack_txn_idx; /* The pack index of the most recently received transaction */
695 :
696 : struct {
697 : int has_block_engine;
698 : char name[ 16 ];
699 : char url[ 256 ];
700 : char ip_cstr[ 40 ]; /* IPv4 or IPv6 cstr */
701 : int status;
702 : } block_engine;
703 :
704 : struct {
705 : int has_epoch[ 2 ];
706 :
707 : struct {
708 : ulong epoch;
709 : long start_time;
710 : long end_time;
711 :
712 : ulong my_total_slots;
713 : ulong my_skipped_slots;
714 :
715 : ulong start_slot;
716 : ulong end_slot;
717 : ulong excluded_stake;
718 : fd_epoch_leaders_t * lsched;
719 : uchar __attribute__((aligned(FD_EPOCH_LEADERS_ALIGN))) _lsched[ FD_EPOCH_LEADERS_FOOTPRINT(MAX_STAKED_LEADERS, MAX_SLOTS_PER_EPOCH) ];
720 : fd_vote_stake_weight_t stakes[ MAX_STAKED_LEADERS ];
721 :
722 : ulong rankings_slot; /* One more than the largest slot we've processed into our rankings */
723 : fd_gui_slot_rankings_t rankings[ 1 ]; /* global slot rankings */
724 : fd_gui_slot_rankings_t my_rankings[ 1 ]; /* my slots only */
725 : } epochs[ 2 ];
726 : } epoch;
727 :
728 : struct { /* frankendancer only */
729 : ulong peer_cnt;
730 : struct fd_gui_gossip_peer peers[ FD_GUI_MAX_PEER_CNT ];
731 : } gossip;
732 :
733 : struct { /* frankendancer only */
734 : ulong vote_account_cnt;
735 : struct fd_gui_vote_account vote_accounts[ FD_GUI_MAX_PEER_CNT ];
736 : } vote_account;
737 :
738 : struct { /* frankendancer only */
739 : ulong info_cnt;
740 : struct fd_gui_validator_info info[ FD_GUI_MAX_PEER_CNT ];
741 : } validator_info;
742 :
743 : fd_gui_peers_ctx_t * peers; /* full-client */
744 :
745 : struct {
746 : ulong leader_shred_cnt; /* A gauge counting the number of leader shreds seen on the SHRED_OUT link. Resets at
747 : the end of a leader slot. This works because leader fecs are published in order. */
748 : ulong staged_next_broadcast; /* staged[ staged_next_broadcast % FD_GUI_SHREDS_STAGING_SZ ] is the first shred event
749 : that hasn't yet been broadcast to WebSocket clients */
750 : ulong staged_head; /* staged_head % FD_GUI_SHREDS_STAGING_SZ is the first valid event in staged */
751 : ulong staged_tail; /* staged_tail % FD_GUI_SHREDS_STAGING_SZ is one past the last valid event in staged */
752 : fd_gui_slot_staged_shred_event_t staged [ FD_GUI_SHREDS_STAGING_SZ ];
753 :
754 : ulong history_slot; /* the largest slot store in history */
755 : ulong history_tail; /* history_tail % FD_GUI_SHREDS_HISTORY_SZ is one past the last valid event in history */
756 : fd_gui_slot_history_shred_event_t history[ FD_GUI_SHREDS_HISTORY_SZ ];
757 :
758 : /* scratch space for stable sorts */
759 : fd_gui_slot_staged_shred_event_t _staged_scratch [ FD_GUI_SHREDS_STAGING_SZ ];
760 : fd_gui_slot_staged_shred_event_t _staged_scratch2[ FD_GUI_SHREDS_STAGING_SZ ];
761 : } shreds; /* full client */
762 : };
763 :
764 : typedef struct fd_gui fd_gui_t;
765 :
766 : FD_PROTOTYPES_BEGIN
767 :
768 : FD_FN_CONST ulong
769 : fd_gui_align( void );
770 :
771 : FD_FN_CONST ulong
772 : fd_gui_footprint( void );
773 :
774 : void *
775 : fd_gui_new( void * shmem,
776 : fd_http_server_t * http,
777 : char const * version,
778 : char const * cluster,
779 : uchar const * identity_key,
780 : int has_vote_key,
781 : uchar const * vote_key,
782 : int is_full_client,
783 : int snapshots_enabled,
784 : int is_voting,
785 : int schedule_strategy,
786 : fd_topo_t * topo,
787 : long now );
788 :
789 : fd_gui_t *
790 : fd_gui_join( void * shmem );
791 :
792 : void
793 : fd_gui_set_identity( fd_gui_t * gui,
794 : uchar const * identity_pubkey );
795 :
796 : void
797 : fd_gui_ws_open( fd_gui_t * gui,
798 : ulong conn_id );
799 :
800 : int
801 : fd_gui_ws_message( fd_gui_t * gui,
802 : ulong ws_conn_id,
803 : uchar const * data,
804 : ulong data_len );
805 :
806 : void
807 : fd_gui_plugin_message( fd_gui_t * gui,
808 : ulong plugin_msg,
809 : uchar const * msg,
810 : long now );
811 :
812 : void
813 : fd_gui_became_leader( fd_gui_t * gui,
814 : ulong slot,
815 : long start_time_nanos,
816 : long end_time_nanos,
817 : ulong max_compute_units,
818 : ulong max_microblocks );
819 :
820 : void
821 : fd_gui_unbecame_leader( fd_gui_t * gui,
822 : ulong _slot,
823 : fd_done_packing_t const * done_packing,
824 : long now );
825 :
826 : void
827 : fd_gui_microblock_execution_begin( fd_gui_t * gui,
828 : long now,
829 : ulong _slot,
830 : fd_txn_p_t * txns,
831 : ulong txn_cnt,
832 : uint microblock_idx,
833 : ulong pack_txn_idx );
834 :
835 : void
836 : fd_gui_microblock_execution_end( fd_gui_t * gui,
837 : long now,
838 : ulong bank_idx,
839 : ulong _slot,
840 : ulong txn_cnt,
841 : fd_txn_p_t * txns,
842 : ulong pack_txn_idx,
843 : uchar txn_start_pct,
844 : uchar txn_load_end_pct,
845 : uchar txn_end_pct,
846 : uchar txn_preload_end_pct,
847 : ulong tips );
848 :
849 : int
850 : fd_gui_poll( fd_gui_t * gui, long now );
851 :
852 : void
853 : fd_gui_handle_shred( fd_gui_t * gui,
854 : ulong slot,
855 : ulong shred_idx,
856 : int is_turbine,
857 : long tsorig );
858 :
859 : void
860 : fd_gui_handle_leader_fec( fd_gui_t * gui,
861 : ulong slot,
862 : ulong fec_shred_cnt,
863 : int is_end_of_slot,
864 : long tsorig );
865 :
866 : void
867 : fd_gui_handle_exec_txn_done( fd_gui_t * gui,
868 : ulong slot,
869 : ulong start_shred_idx,
870 : ulong end_shred_idx,
871 : long tsorig_ns,
872 : long tspub_ns );
873 :
874 : void
875 : fd_gui_handle_repair_slot( fd_gui_t * gui, ulong slot, long now );
876 :
877 : void
878 : fd_gui_handle_repair_request( fd_gui_t * gui, ulong slot, ulong shred_idx, long now );
879 :
880 : void
881 : fd_gui_handle_snapshot_update( fd_gui_t * gui,
882 : fd_snapct_update_t const * msg );
883 :
884 : void
885 : fd_gui_handle_leader_schedule( fd_gui_t * gui,
886 : fd_stake_weight_msg_t const * leader_schedule,
887 : long now );
888 :
889 : void
890 : fd_gui_handle_notarization_update( fd_gui_t * gui,
891 : fd_tower_slot_confirmed_t const * notar );
892 :
893 : void
894 : fd_gui_handle_tower_update( fd_gui_t * gui,
895 : fd_tower_slot_done_t const * msg,
896 : long now );
897 :
898 : void
899 : fd_gui_handle_replay_update( fd_gui_t * gui,
900 : fd_gui_slot_completed_t * slot_completed,
901 : fd_hash_t const * block_hash,
902 : ulong vote_slot,
903 : ulong storage_slot,
904 : ulong identity_balance,
905 : long now );
906 :
907 : void
908 : fd_gui_handle_genesis_hash( fd_gui_t * gui,
909 : uchar const * msg );
910 :
911 : static inline fd_gui_slot_t *
912 0 : fd_gui_get_slot( fd_gui_t const * gui, ulong _slot ) {
913 0 : fd_gui_slot_t const * slot = gui->slots[ _slot % FD_GUI_SLOTS_CNT ];
914 0 : if( FD_UNLIKELY( slot->slot==ULONG_MAX || _slot==ULONG_MAX || slot->slot!=_slot ) ) return NULL;
915 0 : return (fd_gui_slot_t *)slot;
916 0 : }
917 :
918 : static inline fd_gui_slot_t const *
919 0 : fd_gui_get_slot_const( fd_gui_t const * gui, ulong _slot ) {
920 0 : return fd_gui_get_slot( gui, _slot );
921 0 : }
922 :
923 : static inline fd_gui_leader_slot_t *
924 0 : fd_gui_get_leader_slot( fd_gui_t const * gui, ulong _slot ) {
925 0 : fd_gui_slot_t const * slot = fd_gui_get_slot( gui, _slot );
926 0 : if( FD_UNLIKELY( !slot
927 0 : || !slot->mine
928 0 : || slot->leader_history_idx==ULONG_MAX
929 0 : || slot->leader_history_idx + FD_GUI_LEADER_CNT < gui->leader_slots_cnt
930 0 : || gui->leader_slots[ slot->leader_history_idx % FD_GUI_LEADER_CNT ]->slot!=_slot ) ) return NULL;
931 0 : return (fd_gui_leader_slot_t *)gui->leader_slots[ slot->leader_history_idx % FD_GUI_LEADER_CNT ];
932 0 : }
933 :
934 : static inline fd_gui_leader_slot_t const *
935 0 : fd_gui_get_leader_slot_const( fd_gui_t const * gui, ulong _slot ) {
936 0 : return fd_gui_get_leader_slot( gui, _slot );
937 0 : }
938 :
939 : /* fd_gui_get_root_slot returns a handle to the closest ancestor of slot
940 : that is a root, if available, otherwise NULL. */
941 : static inline fd_gui_slot_t *
942 : fd_gui_get_root_slot( fd_gui_t const * gui,
943 0 : ulong slot ) {
944 0 : fd_gui_slot_t * c = fd_gui_get_slot( gui, slot );
945 0 : while( c ) {
946 0 : if( FD_UNLIKELY( c->level>=FD_GUI_SLOT_LEVEL_ROOTED ) ) return c;
947 0 : c = fd_gui_get_slot( gui, c->parent_slot );
948 0 : }
949 0 : return NULL;
950 0 : }
951 :
952 : /* fd_gui_slot_is_ancestor returns 1 if anc is known to be an ancestor
953 : of slot (on the same fork), 0 otherwise. */
954 : static inline int
955 : fd_gui_slot_is_ancestor( fd_gui_t const * gui,
956 : ulong anc,
957 0 : ulong slot ) {
958 0 : fd_gui_slot_t * c = fd_gui_get_slot( gui, slot );
959 0 : while( c ) {
960 0 : if( FD_UNLIKELY( c->slot==anc ) ) return 1;
961 0 : c = fd_gui_get_slot( gui, c->parent_slot );
962 0 : }
963 0 : return 0;
964 0 : }
965 :
966 : /* fd_gui_get_parent_slot_on_fork returns a handle to the parent of slot
967 : on the fork ending on frontier_slot. If slot is unknown or skipped,
968 : the closest (by slot number) valid parent on the fork is returned.
969 :
970 : NULL if slot is not an ancestor of frontier slot or if the parent is
971 : unknown. */
972 : static inline fd_gui_slot_t *
973 : fd_gui_get_parent_slot_on_fork( fd_gui_t const * gui,
974 : ulong frontier_slot,
975 0 : ulong slot ) {
976 0 : fd_gui_slot_t * c = fd_gui_get_slot( gui, frontier_slot );
977 0 : while( c ) {
978 0 : if( FD_UNLIKELY( c->slot<=slot ) ) return NULL;
979 0 : fd_gui_slot_t * p = fd_gui_get_slot( gui, c->parent_slot );
980 0 : if( FD_UNLIKELY( p && p->slot<=slot-1UL ) ) return p;
981 0 : c = p;
982 0 : }
983 0 : return NULL;
984 0 : }
985 :
986 : /* fd_gui_is_skipped_on_fork returns 1 if slot is skipped on the fork
987 : starting at anc and ending at des, 0 otherwise. */
988 : static inline int
989 : fd_gui_is_skipped_on_fork( fd_gui_t const * gui,
990 : ulong anc,
991 : ulong des,
992 0 : ulong slot ) {
993 0 : fd_gui_slot_t const * c = fd_gui_get_slot( gui, des );
994 0 : while( c ) {
995 0 : if( FD_UNLIKELY( anc==c->slot ) ) return 0; /* on the fork, not skipped */
996 0 : fd_gui_slot_t const * p = fd_gui_get_slot( gui, c->parent_slot );
997 0 : if( FD_UNLIKELY( p && p->slot<slot && c->slot>slot ) ) return 1; /* in-between two nodes, skipped */
998 0 : c = p;
999 0 : }
1000 :
1001 0 : return 0; /* slot not between anc and des, or is unknown */
1002 0 : }
1003 :
1004 : FD_PROTOTYPES_END
1005 :
1006 : #endif /* HEADER_fd_src_disco_gui_fd_gui_h */
|