Line data Source code
1 : #ifndef HEADER_fd_src_choreo_voter_fd_voter_h 2 : #define HEADER_fd_src_choreo_voter_fd_voter_h 3 : 4 : /* fd_voter provides APIs for zero-copy serializing and deserializing 5 : on-chain vote accounts. Vote accounts contain "vote states" which 6 : store a voter's metadata and tower. */ 7 : 8 : #include "../fd_choreo_base.h" 9 : 10 : /* FD_VOTER_USE_HANDHOLDING: Define this to non-zero at compile time 11 : to turn on additional runtime checks and logging. */ 12 : 13 : #ifndef FD_VOTER_USE_HANDHOLDING 14 : #define FD_VOTER_USE_HANDHOLDING 1 15 : #endif 16 : 17 0 : #define FD_VOTER_V2 (1) 18 642 : #define FD_VOTER_V3 (2) 19 0 : #define FD_VOTER_V4 (3) 20 : FD_STATIC_ASSERT( FD_VOTER_V2==fd_vote_state_versioned_enum_v1_14_11, FD_VOTER_V2 ); 21 : FD_STATIC_ASSERT( FD_VOTER_V3==fd_vote_state_versioned_enum_v3, FD_VOTER_V3 ); 22 : FD_STATIC_ASSERT( FD_VOTER_V4==fd_vote_state_versioned_enum_v4, FD_VOTER_V4 ); 23 : 24 : /* TODO: Update for vote state v4 25 : 26 : fd_voter describes the layout of a vote state stored in a vote 27 : account. These structs are used to support zero-copy access (direct 28 : casts) of byte arrays containing the vote account data. 29 : 30 : fd_voter is versioned, and the serialized formats differ depending on 31 : this. They correspond to Agave's VoteState0_23_5, VoteState1_14_11 32 : and VoteState structs. 33 : 34 : VoteStatev0_23_5 is deprecated and there are no longer vote accounts 35 : of that version on testnet / mainnet. VoteState1_14_11 corresponds 36 : to FD_VOTER_V2 and VoteState corresponds to FD_VOTER_V3. The only 37 : difference between the two is the votes in V3 contain an additional 38 : uchar field `latency`. 39 : 40 : The binary layout begins with metadata in the vote account, followed by the voter's votes (tower), and terminates with the root. */ 41 : 42 : struct __attribute__((packed)) fd_voter_vote { 43 : uchar latency; 44 : ulong slot; 45 : uint conf; 46 : }; 47 : typedef struct fd_voter_vote fd_voter_vote_t; 48 : 49 : struct __attribute__((packed)) fd_voter { 50 : uint kind; 51 : union __attribute__((packed)) { 52 : struct __attribute__((packed)) { 53 : fd_pubkey_t node_pubkey; 54 : fd_pubkey_t authorized_withdrawer; 55 : uchar commission; 56 : ulong votes_cnt; 57 : struct __attribute__((packed)) { 58 : ulong slot; 59 : uint conf; 60 : } votes[31]; /* variable-length */ 61 : /* uchar root_option */ 62 : /* ulong root */ 63 : } v2; 64 : 65 : struct __attribute__((packed)) { 66 : fd_pubkey_t node_pubkey; 67 : fd_pubkey_t authorized_withdrawer; 68 : uchar commission; 69 : ulong votes_cnt; 70 : fd_voter_vote_t votes[31]; /* variable-length */ 71 : /* uchar root_option */ 72 : /* ulong root */ 73 : } v3; 74 : 75 : struct __attribute__((packed)) { 76 : fd_pubkey_t node_pubkey; 77 : fd_pubkey_t authorized_withdrawer; 78 : fd_pubkey_t inflation_rewards_collector; 79 : fd_pubkey_t block_revenue_collector; 80 : ushort inflation_rewards_commission_bps; 81 : ushort block_revenue_commission_bps; 82 : ulong pending_delegator_rewards; 83 : uchar has_bls_pubkey_compressed; 84 : uchar bls_pubkey_compressed[48]; 85 : /* ulong votes_cnt; */ 86 : /* fd_voter_vote_t votes[31]; */ 87 : /* uchar root_option */ 88 : /* ulong root */ 89 : } v4; 90 : }; 91 : }; 92 : typedef struct fd_voter fd_voter_t; 93 : 94 : FD_FN_PURE ulong 95 : fd_voter_votes_cnt( uchar const * vote_account_data ); 96 : 97 : /* fd_voter_vote_slot takes a voter's vote account data and returns the 98 : voter's most recent vote slot in the tower. Returns ULONG_MAX if 99 : they have an empty tower. */ 100 : 101 : FD_FN_PURE ulong 102 : fd_voter_vote_slot( uchar const * vote_account_data ); 103 : 104 : /* fd_voter_root_slot takes a voter's vote account data and returns the 105 : voter's root slot. Returns ULONG_MAX if they don't have a root. */ 106 : 107 : FD_FN_PURE ulong 108 : fd_voter_root_slot( uchar const * vote_account_data ); 109 : 110 : #endif /* HEADER_fd_src_choreo_voter_fd_voter_h */