diff --git a/vote-interface/src/state/vote_instruction_data.rs b/vote-interface/src/state/vote_instruction_data.rs index 262293c9c..8e2a27ce0 100644 --- a/vote-interface/src/state/vote_instruction_data.rs +++ b/vote-interface/src/state/vote_instruction_data.rs @@ -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, @@ -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)] @@ -32,6 +35,23 @@ pub struct Vote { pub timestamp: Option, } +#[cfg(feature = "frozen-abi")] +impl solana_frozen_abi::rand::prelude::Distribution + for solana_frozen_abi::rand::distr::StandardUniform +{ + fn sample(&self, rng: &mut R) -> Vote { + let slots: Vec = (0..rng.random_range(0..1000)) + .map(|_| rng.random::()) + .collect(); + + Vote { + slots, + hash: Hash::new_from_array(rng.random()), + timestamp: Some(rng.random()), + } + } +} + impl Vote { pub fn new(slots: Vec, hash: Hash) -> Self { Self { @@ -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)] @@ -64,6 +87,23 @@ pub struct VoteStateUpdate { pub timestamp: Option, } +#[cfg(feature = "frozen-abi")] +impl solana_frozen_abi::rand::prelude::Distribution + for solana_frozen_abi::rand::distr::StandardUniform +{ + fn sample(&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::()), + hash: Hash::new_from_array(rng.random()), + timestamp: Some(rng.random()), + } + } +} + impl From> for VoteStateUpdate { fn from(recent_slots: Vec<(Slot, u32)>) -> Self { let lockouts: VecDeque = recent_slots @@ -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)] @@ -122,6 +165,24 @@ pub struct TowerSync { pub block_id: Hash, } +#[cfg(feature = "frozen-abi")] +impl solana_frozen_abi::rand::prelude::Distribution + for solana_frozen_abi::rand::distr::StandardUniform +{ + fn sample(&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> for TowerSync { fn from(recent_slots: Vec<(Slot, u32)>) -> Self { let lockouts: VecDeque = recent_slots diff --git a/vote-interface/src/state/vote_state_1_14_11.rs b/vote-interface/src/state/vote_state_1_14_11.rs index 6d7606f84..e7b13c952 100644 --- a/vote-interface/src/state/vote_state_1_14_11.rs +++ b/vote-interface/src/state/vote_state_1_14_11.rs @@ -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)] @@ -45,6 +50,47 @@ pub struct VoteState1_14_11 { pub last_timestamp: BlockTimestamp, } +#[cfg(feature = "frozen-abi")] +impl solana_frozen_abi::rand::prelude::Distribution + for solana_frozen_abi::rand::distr::StandardUniform +{ + fn sample(&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()) diff --git a/vote-interface/src/state/vote_state_v3.rs b/vote-interface/src/state/vote_state_v3.rs index 38e956584..ef8e77f0a 100644 --- a/vote-interface/src/state/vote_state_v3.rs +++ b/vote-interface/src/state/vote_state_v3.rs @@ -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 { @@ -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)] @@ -59,6 +62,50 @@ pub struct VoteStateV3 { pub last_timestamp: BlockTimestamp, } +#[cfg(feature = "frozen-abi")] +impl solana_frozen_abi::rand::prelude::Distribution + for solana_frozen_abi::rand::distr::StandardUniform +{ + fn sample(&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 { diff --git a/vote-interface/src/state/vote_state_v4.rs b/vote-interface/src/state/vote_state_v4.rs index e15d3465c..608ebc1bd 100644 --- a/vote-interface/src/state/vote_state_v4.rs +++ b/vote-interface/src/state/vote_state_v4.rs @@ -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 { @@ -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))] @@ -70,6 +73,46 @@ pub struct VoteStateV4 { pub last_timestamp: BlockTimestamp, } +#[cfg(feature = "frozen-abi")] +impl solana_frozen_abi::rand::prelude::Distribution + for solana_frozen_abi::rand::distr::StandardUniform +{ + fn sample(&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.