LCOV - code coverage report
Current view: top level - choreo/votor - fd_votor_hist.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 13 0.0 %
Date: 2026-11-11 12:40:43 Functions: 0 46 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_choreo_votor_fd_votor_hist_h
       2             : #define HEADER_fd_src_choreo_votor_fd_votor_hist_h
       3             : 
       4             : /* fd_votor_hist serializes and deserializes a validator's own Alpenglow
       5             :    votes since a finality anchor, so another validator can adopt the
       6             :    same consensus state before voting as the same identity. */
       7             : 
       8             : #include "fd_votor_base.h"
       9             : 
      10           0 : #define FD_VOTOR_HIST_MAX (128UL) /* records per history, 32 leader windows */
      11             : 
      12           0 : #define FD_VOTOR_HIST_FLAG_VOTED       (1U) /* any own vote on the slot */
      13           0 : #define FD_VOTOR_HIST_FLAG_VOTED_NOTAR (2U) /* a notar vote, notar_hash is set */
      14           0 : #define FD_VOTOR_HIST_FLAG_BAD_WINDOW  (4U) /* no final vote may follow on this slot */
      15           0 : #define FD_VOTOR_HIST_FLAG_RETIRED     (8U) /* the slot is done */
      16             : #define FD_VOTOR_HIST_FLAG_MASK        (15U)
      17             : 
      18           0 : #define FD_VOTOR_HIST_HDR_SZ     (26UL) /* anchor u64, last_leader_slot u64, vote_bound u64, rec_cnt u16 */
      19           0 : #define FD_VOTOR_HIST_REC_MIN_SZ (9UL)  /* slot u64, flags u8 */
      20             : #define FD_VOTOR_HIST_REC_MAX_SZ (41UL) /* plus the 32 byte notar hash */
      21             : #define FD_VOTOR_HIST_SER_MAX    (FD_VOTOR_HIST_HDR_SZ+FD_VOTOR_HIST_MAX*FD_VOTOR_HIST_REC_MAX_SZ) /* 5274 */
      22             : 
      23             : struct fd_votor_hist_rec {
      24             :   ulong           slot;
      25             :   uchar           flags;      /* FD_VOTOR_HIST_FLAG_* */
      26             :   fd_block_hash_t notar_hash; /* only meaningful when FD_VOTOR_HIST_FLAG_VOTED_NOTAR is set */
      27             : };
      28             : typedef struct fd_votor_hist_rec fd_votor_hist_rec_t;
      29             : 
      30             : struct fd_votor_hist {
      31             :   ulong               anchor;                   /* exporter's highest_final_slot, raised when the export was truncated */
      32             :   ulong               last_leader_slot;         /* slot of the last LEADER the exporter published, ULONG_MAX when none */
      33             :   ulong               vote_bound;               /* the exporter casts no vote at or below this slot, ULONG_MAX when none */
      34             :   ulong               rec_cnt;
      35             :   fd_votor_hist_rec_t rec[ FD_VOTOR_HIST_MAX ]; /* ascending slots */
      36             : };
      37             : typedef struct fd_votor_hist fd_votor_hist_t;
      38             : 
      39             : FD_PROTOTYPES_BEGIN
      40             : 
      41             : /* fd_votor_hist_first_slot returns the lowest slot a history with this
      42             :    anchor may contain. */
      43             : 
      44             : FD_FN_CONST static inline ulong
      45           0 : fd_votor_hist_first_slot( ulong anchor ) {
      46           0 :   return fd_first_slot_in_window( fd_ulong_sat_sub( anchor, FD_VOTOR_REWARD_SLOT_DELTA ) );
      47           0 : }
      48             : 
      49             : /* fd_votor_hist_ser serializes self into buf.  Returns 0 on success, -1
      50             :    if self is invalid or buf_max is too small. */
      51             : 
      52             : int
      53             : fd_votor_hist_ser( fd_votor_hist_t const * self,
      54             :                    uchar *                 buf,
      55             :                    ulong                   buf_max,
      56             :                    ulong *                 out_sz );
      57             : 
      58             : /* fd_votor_hist_de deserializes exactly buf_sz bytes of buf into out.
      59             :    Returns 0 on success, -1 if the bytes are not a valid history. */
      60             : 
      61             : int
      62             : fd_votor_hist_de( uchar const *     buf,
      63             :                   ulong             buf_sz,
      64             :                   fd_votor_hist_t * out );
      65             : 
      66             : /* fd_votor_hist_tip returns the highest record slot, ULONG_MAX when the
      67             :    history is empty. */
      68             : 
      69             : FD_FN_PURE static inline ulong
      70           0 : fd_votor_hist_tip( fd_votor_hist_t const * self ) {
      71           0 :   return self->rec_cnt ? self->rec[ self->rec_cnt-1UL ].slot : ULONG_MAX;
      72           0 : }
      73             : 
      74             : FD_PROTOTYPES_END
      75             : 
      76             : #endif /* HEADER_fd_src_choreo_votor_fd_votor_hist_h */

Generated by: LCOV version 1.14