LCOV - code coverage report
Current view: top level - choreo/tower - fd_tower_serdes.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 3 0.0 %
Date: 2026-03-19 18:19:27 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_choreo_tower_fd_tower_serdes_h
       2             : #define HEADER_fd_src_choreo_tower_fd_tower_serdes_h
       3             : 
       4             : #include "../fd_choreo_base.h"
       5             : #include "../../ballet/txn/fd_txn.h"
       6             : 
       7             : #define FD_VOTE_IX_KIND_TOWER_SYNC        (14)
       8             : #define FD_VOTE_IX_KIND_TOWER_SYNC_SWITCH (15)
       9             : 
      10             : /* fd_compact_tower_sync_serde describes the serialization /
      11             :    deserialization schema of a CompactTowerSync vote instruction.  There
      12             :    are various legacy instructions for vote transactions, but current
      13             :    mainnet votes are almost exclusively this instruction. */
      14             : 
      15             : struct fd_compact_tower_sync_serde { /* CompactTowerSync */
      16             :   ulong root;                        /* u64              */
      17             :   struct {
      18             :     ushort lockouts_cnt;             /* ShortU16         */
      19             :     struct {
      20             :       ulong offset;                  /* VarInt           */
      21             :       uchar confirmation_count;      /* u8               */
      22             :     } lockouts[31];
      23             :   };
      24             :   fd_hash_t hash;                    /* [u8; 32]         */
      25             :   struct {
      26             :     uchar timestamp_option;          /* Option           */
      27             :     long  timestamp;                 /* UnixTimestamp    */
      28             :   };
      29             :   fd_hash_t block_id;                /* [u8; 32]         */
      30             : };
      31             : typedef struct fd_compact_tower_sync_serde fd_compact_tower_sync_serde_t;
      32             : 
      33             : /* fd_compact_tower_sync_ser serializes fd_compact_tower_sync_serde_t
      34             :    into a buffer.  Returns 0 on success, -1 if the lockouts_cnt is
      35             :    greater than FD_TOWER_VOTE_MAX or buf_sz is too small to fit the
      36             :    serialized data. */
      37             : int
      38             : fd_compact_tower_sync_ser( fd_compact_tower_sync_serde_t const * serde,
      39             :                            uchar *                               buf,
      40             :                            ulong                                 buf_max,
      41             :                            ulong *                               buf_sz );
      42             : 
      43             : /* fd_compact_tower_sync_de deserializes at most buf_sz of buf into
      44             :    fd_compact_tower_sync_serde_t.  Assumes buf is at least of size
      45             :    buf_sz. */
      46             : 
      47             : int
      48             : fd_compact_tower_sync_de( fd_compact_tower_sync_serde_t * serde,
      49             :                           uchar const *                   buf,
      50             :                           ulong                           buf_sz );
      51             : 
      52           0 : #define FD_VOTE_ACC_V2 (1)
      53           0 : #define FD_VOTE_ACC_V3 (2)
      54           0 : #define FD_VOTE_ACC_V4 (3)
      55             : FD_STATIC_ASSERT( FD_VOTE_ACC_V2==fd_vote_state_versioned_enum_v1_14_11, FD_VOTE_ACC_V2 );
      56             : FD_STATIC_ASSERT( FD_VOTE_ACC_V3==fd_vote_state_versioned_enum_v3,       FD_VOTE_ACC_V3 );
      57             : FD_STATIC_ASSERT( FD_VOTE_ACC_V4==fd_vote_state_versioned_enum_v4,       FD_VOTE_ACC_V4 );
      58             : 
      59             : /* TODO: Update for vote state v4
      60             : 
      61             :    fd_vote_acc describes the layout of a vote state stored in a vote
      62             :    account.  These structs are used to support zero-copy access (direct
      63             :    casts) of byte arrays containing the vote account data.
      64             : 
      65             :    fd_vote_acc is versioned, and the serialized formats differ depending on
      66             :    this.  They correspond to Agave's VoteState0_23_5, VoteState1_14_11
      67             :    and VoteState structs.
      68             : 
      69             :    VoteStatev0_23_5 is deprecated and there are no longer vote accounts
      70             :    of that version on testnet / mainnet.  VoteState1_14_11 corresponds
      71             :    to FD_VOTE_ACC_V2 and VoteState corresponds to FD_VOTE_ACC_V3.  The only
      72             :    difference between the two is the votes in V3 contain an additional
      73             :    uchar field `latency`.
      74             : 
      75             :    The binary layout begins with metadata in the vote account, followed by the voter's votes (tower), and terminates with the root. */
      76             : 
      77             : struct __attribute__((packed)) fd_vote_acc_vote {
      78             :   uchar latency;
      79             :   ulong slot;
      80             :   uint  conf;
      81             : };
      82             : typedef struct fd_vote_acc_vote fd_vote_acc_vote_t;
      83             : 
      84             : struct __attribute__((packed)) fd_vote_acc {
      85             :   uint kind;
      86             :   union __attribute__((packed)) {
      87             :     struct __attribute__((packed)) {
      88             :       fd_pubkey_t node_pubkey;
      89             :       fd_pubkey_t authorized_withdrawer;
      90             :       uchar       commission;
      91             :       ulong       votes_cnt;
      92             :       struct __attribute__((packed)) {
      93             :         ulong slot;
      94             :         uint  conf;
      95             :       } votes[31]; /* variable-length */
      96             :       /* uchar root_option */
      97             :       /* ulong root */
      98             :     } v2;
      99             : 
     100             :     struct __attribute__((packed)) {
     101             :       fd_pubkey_t        node_pubkey;
     102             :       fd_pubkey_t        authorized_withdrawer;
     103             :       uchar              commission;
     104             :       ulong              votes_cnt;
     105             :       fd_vote_acc_vote_t    votes[31]; /* variable-length */
     106             :       /* uchar root_option */
     107             :       /* ulong root */
     108             :     } v3;
     109             : 
     110             :     struct __attribute__((packed)) {
     111             :       fd_pubkey_t     node_pubkey;
     112             :       fd_pubkey_t     authorized_withdrawer;
     113             :       fd_pubkey_t     inflation_rewards_collector;
     114             :       fd_pubkey_t     block_revenue_collector;
     115             :       ushort          inflation_rewards_commission_bps;
     116             :       ushort          block_revenue_commission_bps;
     117             :       ulong           pending_delegator_rewards;
     118             :       uchar           has_bls_pubkey_compressed;
     119             :       uchar           bls_pubkey_compressed[48];
     120             :       /* ulong           votes_cnt; */
     121             :       /* fd_vote_acc_vote_t votes[31]; */
     122             :       /* uchar root_option */
     123             :       /* ulong root */
     124             :     } v4;
     125             :   };
     126             : };
     127             : typedef struct fd_vote_acc fd_vote_acc_t;
     128             : 
     129             : FD_FN_PURE ulong
     130             : fd_vote_acc_vote_cnt( uchar const * vote_account_data );
     131             : 
     132             : /* fd_vote_acc_vote_slot takes a voter's vote account data and returns the
     133             :    voter's most recent vote slot in the tower.  Returns ULONG_MAX if
     134             :    they have an empty tower. */
     135             : 
     136             : FD_FN_PURE ulong
     137             : fd_vote_acc_vote_slot( uchar const * vote_account_data );
     138             : 
     139             : /* fd_vote_acc_root_slot takes a voter's vote account data and returns the
     140             :    voter's root slot.  Returns ULONG_MAX if they don't have a root. */
     141             : 
     142             : FD_FN_PURE ulong
     143             : fd_vote_acc_root_slot( uchar const * vote_account_data );
     144             : 
     145             : /* fd_txn_parse_simple_vote optionally extracts the vote account pubkey,
     146             :    identity pubkey, and largest voted-for slot from a vote transaction. */
     147             : int
     148             : fd_txn_parse_simple_vote( fd_txn_t const * txn,
     149             :                           uchar    const * payload,
     150             :                           fd_pubkey_t *    opt_identity,
     151             :                           fd_pubkey_t *    opt_vote_acct,
     152             :                           ulong *          opt_vote_slot );
     153             : 
     154             : #endif /* HEADER_fd_src_choreo_tower_fd_tower_serdes_h */

Generated by: LCOV version 1.14