Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 68 additions & 7 deletions vote-interface/src/state/vote_instruction_data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};
use {
crate::state::{
Lockout, BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE, BLS_PUBLIC_KEY_COMPRESSED_SIZE,
Expand All @@ -18,8 +18,11 @@ use {

#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "GvUzgtcxhKVVxPAjSntXGPqjLZK5ovgZzCiUP1tDpB9q"),
derive(AbiExample)
frozen_abi(
api_digest = "GvUzgtcxhKVVxPAjSntXGPqjLZK5ovgZzCiUP1tDpB9q",
abi_digest = "2xEB2gzHSousWedFa7H6LYEK1m5GYzWYf95WYnogxKkS"
),
derive(AbiExample, StableAbi)
)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Default, Debug, PartialEq, Eq, Clone)]
Expand All @@ -32,6 +35,23 @@ pub struct Vote {
pub timestamp: Option<UnixTimestamp>,
}

#[cfg(feature = "frozen-abi")]
impl solana_frozen_abi::rand::prelude::Distribution<Vote>
for solana_frozen_abi::rand::distr::StandardUniform
{
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> Vote {
let slots: Vec<Slot> = (0..rng.random_range(0..1000))
.map(|_| rng.random::<u64>())
.collect();

Vote {
slots,
hash: Hash::new_from_array(rng.random()),
timestamp: Some(rng.random()),
}
}
}

impl Vote {
pub fn new(slots: Vec<Slot>, hash: Hash) -> Self {
Self {
Expand All @@ -48,8 +68,11 @@ impl Vote {

#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "CxyuwbaEdzP7jDCZyxjgQvLGXadBUZF3LoUvbSpQ6tYN"),
derive(AbiExample)
frozen_abi(
api_digest = "CxyuwbaEdzP7jDCZyxjgQvLGXadBUZF3LoUvbSpQ6tYN",
abi_digest = "7oYbjCjdk8eVvp3wej7s3kPKSRUwRhmC9qWPRsW2RNtM"
),
derive(AbiExample, StableAbi)
)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Default, Debug, PartialEq, Eq, Clone)]
Expand All @@ -64,6 +87,23 @@ pub struct VoteStateUpdate {
pub timestamp: Option<UnixTimestamp>,
}

#[cfg(feature = "frozen-abi")]
impl solana_frozen_abi::rand::prelude::Distribution<VoteStateUpdate>
for solana_frozen_abi::rand::distr::StandardUniform
{
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> VoteStateUpdate {
let lockouts: VecDeque<_> = (0..rng.random_range(0..1000))
.map(|_| Lockout::new(rng.random()))
.collect();
VoteStateUpdate {
lockouts,
root: Some(rng.random::<u64>()),
hash: Hash::new_from_array(rng.random()),
timestamp: Some(rng.random()),
}
}
}

impl From<Vec<(Slot, u32)>> for VoteStateUpdate {
fn from(recent_slots: Vec<(Slot, u32)>) -> Self {
let lockouts: VecDeque<Lockout> = recent_slots
Expand Down Expand Up @@ -102,8 +142,11 @@ impl VoteStateUpdate {

#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "6UDiQMH4wbNwkMHosPMtekMYu2Qa6CHPZ2ymK4mc6FGu"),
derive(AbiExample)
frozen_abi(
api_digest = "6UDiQMH4wbNwkMHosPMtekMYu2Qa6CHPZ2ymK4mc6FGu",
abi_digest = "5WwSB17ze8us9dwhJWXGR7yzaXseHHWFkpT5TCuBgca3"
),
derive(AbiExample, StableAbi)
)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Default, Debug, PartialEq, Eq, Clone)]
Expand All @@ -122,6 +165,24 @@ pub struct TowerSync {
pub block_id: Hash,
}

#[cfg(feature = "frozen-abi")]
impl solana_frozen_abi::rand::prelude::Distribution<TowerSync>
for solana_frozen_abi::rand::distr::StandardUniform
{
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> TowerSync {
let lockouts: VecDeque<_> = (0..rng.random_range(0..1000))
.map(|_| Lockout::new(rng.random()))
.collect();
TowerSync {
lockouts,
root: Some(rng.random()),
hash: Hash::new_from_array(rng.random()),
timestamp: Some(rng.random()),
block_id: Hash::new_from_array(rng.random()),
}
}
}

impl From<Vec<(Slot, u32)>> for TowerSync {
fn from(recent_slots: Vec<(Slot, u32)>) -> Self {
let lockouts: VecDeque<Lockout> = recent_slots
Expand Down
50 changes: 48 additions & 2 deletions vote-interface/src/state/vote_state_1_14_11.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
use super::*;
#[cfg(feature = "dev-context-only-utils")]
use arbitrary::Arbitrary;
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};

// Offset used for VoteState version 1_14_11
const DEFAULT_PRIOR_VOTERS_OFFSET: usize = 82;

#[cfg_attr(
feature = "frozen-abi",
solana_frozen_abi_macro::frozen_abi(digest = "2rjXSWaNeAdoUNJDC5otC7NPR1qXHvLMuAs5faE4DPEt"),
derive(solana_frozen_abi_macro::AbiExample)
frozen_abi(
api_digest = "2rjXSWaNeAdoUNJDC5otC7NPR1qXHvLMuAs5faE4DPEt",
abi_digest = "GQvUnzypqWVwtedNSVWrhtr3Uy4vUor4mbvzsoUEV79R"
),
derive(AbiExample, StableAbi)
)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Debug, Default, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -45,6 +50,47 @@ pub struct VoteState1_14_11 {
pub last_timestamp: BlockTimestamp,
}

#[cfg(feature = "frozen-abi")]
impl solana_frozen_abi::rand::prelude::Distribution<VoteState1_14_11>
for solana_frozen_abi::rand::distr::StandardUniform
{
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> VoteState1_14_11 {
let votes: VecDeque<_> = (0..rng.random_range(0..1000))
.map(|_| Lockout::new(rng.random()))
.collect();

let mut prior_voters: CircBuf<(Pubkey, Epoch, Epoch)> = CircBuf::default();
for _ in 0..rng.random_range(0..1000) {
prior_voters.append((
Pubkey::new_from_array(rng.random()),
rng.random(),
rng.random(),
));
}
let epoch_credits: Vec<_> = (0..rng.random_range(0..1000))
.map(|_| (rng.random(), rng.random(), rng.random()))
.collect();

VoteState1_14_11 {
node_pubkey: Pubkey::new_from_array(rng.random()),
authorized_withdrawer: Pubkey::new_from_array(rng.random()),
commission: rng.random(),
votes,
root_slot: Some(rng.random()),
authorized_voters: AuthorizedVoters::new(
rng.random(),
Pubkey::new_from_array(rng.random()),
),
prior_voters,
epoch_credits,
last_timestamp: BlockTimestamp {
slot: rng.random(),
timestamp: rng.random(),
},
}
}
}

impl VoteState1_14_11 {
pub fn get_rent_exempt_reserve(rent: &Rent) -> u64 {
rent.minimum_balance(Self::size_of())
Expand Down
53 changes: 50 additions & 3 deletions vote-interface/src/state/vote_state_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use arbitrary::Arbitrary;
#[cfg(feature = "serde")]
use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};
#[cfg(any(target_os = "solana", feature = "bincode"))]
use solana_instruction_error::InstructionError;
use {
Expand All @@ -21,8 +21,11 @@ use {

#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "pZqasQc6duzMYzpzU7eriHH9cMXmubuUP4NmCrkWZjt"),
derive(AbiExample)
frozen_abi(
api_digest = "pZqasQc6duzMYzpzU7eriHH9cMXmubuUP4NmCrkWZjt",
abi_digest = "GYS8SRmr3HQnLdd7Dr4dDraWj9sratTP1UchASh1BT3D"
),
derive(AbiExample, StableAbi)
)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Debug, Default, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -59,6 +62,50 @@ pub struct VoteStateV3 {
pub last_timestamp: BlockTimestamp,
}

#[cfg(feature = "frozen-abi")]
impl solana_frozen_abi::rand::prelude::Distribution<VoteStateV3>
for solana_frozen_abi::rand::distr::StandardUniform
{
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> VoteStateV3 {
let votes: VecDeque<_> = (0..rng.random_range(0..1000))
.map(|_| LandedVote {
latency: rng.random(),
lockout: crate::state::Lockout::new(rng.random()),
})
.collect();

let mut prior_voters: CircBuf<(Pubkey, Epoch, Epoch)> = CircBuf::default();
for _ in 0..rng.random_range(0..1000) {
prior_voters.append((
Pubkey::new_from_array(rng.random()),
rng.random(),
rng.random(),
));
}
let epoch_credits: Vec<_> = (0..rng.random_range(0..1000))
.map(|_| (rng.random(), rng.random(), rng.random()))
.collect();

VoteStateV3 {
node_pubkey: Pubkey::new_from_array(rng.random()),
authorized_withdrawer: Pubkey::new_from_array(rng.random()),
commission: rng.random(),
votes,
root_slot: Some(rng.random()),
authorized_voters: AuthorizedVoters::new(
rng.random(),
Pubkey::new_from_array(rng.random()),
),
prior_voters,
epoch_credits,
last_timestamp: BlockTimestamp {
slot: rng.random(),
timestamp: rng.random(),
},
}
}
}

impl VoteStateV3 {
pub fn new(vote_init: &VoteInit, clock: &Clock) -> Self {
Self {
Expand Down
49 changes: 46 additions & 3 deletions vote-interface/src/state/vote_state_v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "serde")]
use serde_with::serde_as;
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};
#[cfg(any(target_os = "solana", feature = "bincode"))]
use solana_instruction::error::InstructionError;
use {
Expand All @@ -20,8 +20,11 @@ use {

#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "2H9WgTh7LgdnpinvEwxzP3HF6SDuKp6qdwFmJk9jHDRP"),
derive(AbiExample)
frozen_abi(
api_digest = "2H9WgTh7LgdnpinvEwxzP3HF6SDuKp6qdwFmJk9jHDRP",
abi_digest = "CFpc8LMQhpYBsNctM4n9o6rn6BQJ4mcTx6pveGtb7YcM"
),
derive(AbiExample, StableAbi)
)]
#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_as)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
Expand Down Expand Up @@ -70,6 +73,46 @@ pub struct VoteStateV4 {
pub last_timestamp: BlockTimestamp,
}

#[cfg(feature = "frozen-abi")]
impl solana_frozen_abi::rand::prelude::Distribution<VoteStateV4>
for solana_frozen_abi::rand::distr::StandardUniform
{
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> VoteStateV4 {
let bls_pubkey_compressed = Some(std::array::from_fn(|_| rng.random()));
let votes: VecDeque<_> = (0..rng.random_range(0..1000))
.map(|_| LandedVote {
latency: rng.random(),
lockout: crate::state::Lockout::new(rng.random()),
})
.collect();
let epoch_credits: Vec<_> = (0..rng.random_range(0..1000))
.map(|_| (rng.random(), rng.random(), rng.random()))
.collect();

VoteStateV4 {
node_pubkey: Pubkey::new_from_array(rng.random()),
authorized_withdrawer: Pubkey::new_from_array(rng.random()),
inflation_rewards_collector: Pubkey::new_from_array(rng.random()),
block_revenue_collector: Pubkey::new_from_array(rng.random()),
inflation_rewards_commission_bps: rng.random(),
block_revenue_commission_bps: rng.random(),
pending_delegator_rewards: rng.random(),
bls_pubkey_compressed,
votes,
root_slot: Some(rng.random()),
authorized_voters: AuthorizedVoters::new(
rng.random(),
Pubkey::new_from_array(rng.random()),
),
epoch_credits,
last_timestamp: BlockTimestamp {
slot: rng.random(),
timestamp: rng.random(),
},
}
}
}

impl VoteStateV4 {
/// Upper limit on the size of the Vote State
/// when votes.len() is MAX_LOCKOUT_HISTORY.
Expand Down