miraland_program/vote/state/
vote_state_1_14_11.rs

1use super::*;
2#[cfg(test)]
3use arbitrary::Arbitrary;
4
5// Offset used for VoteState version 1_14_11
6const DEFAULT_PRIOR_VOTERS_OFFSET: usize = 82;
7
8#[frozen_abi(digest = "CZTgLymuevXjAx6tM8X8T5J3MCx9AkEsFSmu4FJrEpkG")]
9#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq, Clone, AbiExample)]
10#[cfg_attr(test, derive(Arbitrary))]
11pub struct VoteState1_14_11 {
12    /// the node that votes in this account
13    pub node_pubkey: Pubkey,
14
15    /// the signer for withdrawals
16    pub authorized_withdrawer: Pubkey,
17    /// percentage (0-100) that represents what part of a rewards
18    ///  payout should be given to this VoteAccount
19    pub commission: u8,
20
21    pub votes: VecDeque<Lockout>,
22
23    // This usually the last Lockout which was popped from self.votes.
24    // However, it can be arbitrary slot, when being used inside Tower
25    pub root_slot: Option<Slot>,
26
27    /// the signer for vote transactions
28    pub authorized_voters: AuthorizedVoters,
29
30    /// history of prior authorized voters and the epochs for which
31    /// they were set, the bottom end of the range is inclusive,
32    /// the top of the range is exclusive
33    pub prior_voters: CircBuf<(Pubkey, Epoch, Epoch)>,
34
35    /// history of how many credits earned by the end of each epoch
36    ///  each tuple is (Epoch, credits, prev_credits)
37    pub epoch_credits: Vec<(Epoch, u64, u64)>,
38
39    /// most recent timestamp submitted with a vote
40    pub last_timestamp: BlockTimestamp,
41}
42
43impl VoteState1_14_11 {
44    pub fn get_rent_exempt_reserve(rent: &Rent) -> u64 {
45        rent.minimum_balance(Self::size_of())
46    }
47
48    /// Upper limit on the size of the Vote State
49    /// when votes.len() is MAX_LOCKOUT_HISTORY.
50    pub fn size_of() -> usize {
51        3731 // see test_vote_state_size_of
52    }
53
54    pub fn is_correct_size_and_initialized(data: &[u8]) -> bool {
55        const VERSION_OFFSET: usize = 4;
56        const DEFAULT_PRIOR_VOTERS_END: usize = VERSION_OFFSET + DEFAULT_PRIOR_VOTERS_OFFSET;
57        data.len() == VoteState1_14_11::size_of()
58            && data[VERSION_OFFSET..DEFAULT_PRIOR_VOTERS_END] != [0; DEFAULT_PRIOR_VOTERS_OFFSET]
59    }
60}
61
62impl From<VoteState> for VoteState1_14_11 {
63    fn from(vote_state: VoteState) -> Self {
64        Self {
65            node_pubkey: vote_state.node_pubkey,
66            authorized_withdrawer: vote_state.authorized_withdrawer,
67            commission: vote_state.commission,
68            votes: vote_state
69                .votes
70                .into_iter()
71                .map(|landed_vote| landed_vote.into())
72                .collect(),
73            root_slot: vote_state.root_slot,
74            authorized_voters: vote_state.authorized_voters,
75            prior_voters: vote_state.prior_voters,
76            epoch_credits: vote_state.epoch_credits,
77            last_timestamp: vote_state.last_timestamp,
78        }
79    }
80}