LCOV - code coverage report
Current view: top level - disco/gui - fd_gui.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 129 0.0 %
Date: 2026-03-19 18:19:27 Functions: 0 36 0.0 %

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

Generated by: LCOV version 1.14