Skip to content

Commit 099844f

Browse files
committed
enable StableAbi in Vote, VoteUpdate and TowerSync
1 parent 9af843b commit 099844f

File tree

1 file changed

+68
-7
lines changed

1 file changed

+68
-7
lines changed

vote-interface/src/state/vote_instruction_data.rs

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[cfg(feature = "frozen-abi")]
2-
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
2+
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};
33
use {
44
crate::state::{
55
Lockout, BLS_PROOF_OF_POSSESSION_COMPRESSED_SIZE, BLS_PUBLIC_KEY_COMPRESSED_SIZE,
@@ -18,8 +18,11 @@ use {
1818

1919
#[cfg_attr(
2020
feature = "frozen-abi",
21-
frozen_abi(digest = "GvUzgtcxhKVVxPAjSntXGPqjLZK5ovgZzCiUP1tDpB9q"),
22-
derive(AbiExample)
21+
frozen_abi(
22+
api_digest = "GvUzgtcxhKVVxPAjSntXGPqjLZK5ovgZzCiUP1tDpB9q",
23+
abi_digest = "BbtfeZFE7Fesk4LdkMAu2NCp4DpMLTAmAd31mcuewGJn"
24+
),
25+
derive(AbiExample, StableAbi)
2326
)]
2427
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
2528
#[derive(Default, Debug, PartialEq, Eq, Clone)]
@@ -32,6 +35,23 @@ pub struct Vote {
3235
pub timestamp: Option<UnixTimestamp>,
3336
}
3437

38+
#[cfg(feature = "frozen-abi")]
39+
impl solana_frozen_abi::rand::prelude::Distribution<Vote>
40+
for solana_frozen_abi::rand::distributions::Standard
41+
{
42+
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> Vote {
43+
let slots: Vec<Slot> = (0..rng.r#gen_range(0..1000))
44+
.map(|_| rng.r#gen::<u64>().into())
45+
.collect();
46+
47+
Vote {
48+
slots,
49+
hash: Hash::new_from_array(rng.r#gen()),
50+
timestamp: Some(rng.r#gen()),
51+
}
52+
}
53+
}
54+
3555
impl Vote {
3656
pub fn new(slots: Vec<Slot>, hash: Hash) -> Self {
3757
Self {
@@ -48,8 +68,11 @@ impl Vote {
4868

4969
#[cfg_attr(
5070
feature = "frozen-abi",
51-
frozen_abi(digest = "CxyuwbaEdzP7jDCZyxjgQvLGXadBUZF3LoUvbSpQ6tYN"),
52-
derive(AbiExample)
71+
frozen_abi(
72+
api_digest = "CxyuwbaEdzP7jDCZyxjgQvLGXadBUZF3LoUvbSpQ6tYN",
73+
abi_digest = "7zwscqJMVfyoS4cJdcZa4fuCgwKYM3GUZhvQsFfpKm7e"
74+
),
75+
derive(AbiExample, StableAbi)
5376
)]
5477
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
5578
#[derive(Default, Debug, PartialEq, Eq, Clone)]
@@ -64,6 +87,23 @@ pub struct VoteStateUpdate {
6487
pub timestamp: Option<UnixTimestamp>,
6588
}
6689

90+
#[cfg(feature = "frozen-abi")]
91+
impl solana_frozen_abi::rand::prelude::Distribution<VoteStateUpdate>
92+
for solana_frozen_abi::rand::distributions::Standard
93+
{
94+
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> VoteStateUpdate {
95+
let lockouts: VecDeque<_> = (0..rng.r#gen_range(0..1000))
96+
.map(|_| Lockout::new(rng.r#gen()))
97+
.collect();
98+
VoteStateUpdate {
99+
lockouts,
100+
root: Some(rng.r#gen::<u64>().into()),
101+
hash: Hash::new_from_array(rng.r#gen()),
102+
timestamp: Some(rng.r#gen()),
103+
}
104+
}
105+
}
106+
67107
impl From<Vec<(Slot, u32)>> for VoteStateUpdate {
68108
fn from(recent_slots: Vec<(Slot, u32)>) -> Self {
69109
let lockouts: VecDeque<Lockout> = recent_slots
@@ -102,8 +142,11 @@ impl VoteStateUpdate {
102142

103143
#[cfg_attr(
104144
feature = "frozen-abi",
105-
frozen_abi(digest = "6UDiQMH4wbNwkMHosPMtekMYu2Qa6CHPZ2ymK4mc6FGu"),
106-
derive(AbiExample)
145+
frozen_abi(
146+
api_digest = "6UDiQMH4wbNwkMHosPMtekMYu2Qa6CHPZ2ymK4mc6FGu",
147+
abi_digest = "H4XQ8ftqobHG3jNoCnVgJN4wRJJq1wnUQy8vGK3mp9PX"
148+
),
149+
derive(AbiExample, StableAbi)
107150
)]
108151
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
109152
#[derive(Default, Debug, PartialEq, Eq, Clone)]
@@ -122,6 +165,24 @@ pub struct TowerSync {
122165
pub block_id: Hash,
123166
}
124167

168+
#[cfg(feature = "frozen-abi")]
169+
impl solana_frozen_abi::rand::prelude::Distribution<TowerSync>
170+
for solana_frozen_abi::rand::distributions::Standard
171+
{
172+
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> TowerSync {
173+
let lockouts: VecDeque<_> = (0..rng.r#gen_range(0..1000))
174+
.map(|_| Lockout::new(rng.r#gen()))
175+
.collect();
176+
TowerSync {
177+
lockouts,
178+
root: Some(rng.r#gen()),
179+
hash: Hash::new_from_array(rng.r#gen()),
180+
timestamp: Some(rng.r#gen()),
181+
block_id: Hash::new_from_array(rng.r#gen()),
182+
}
183+
}
184+
}
185+
125186
impl From<Vec<(Slot, u32)>> for TowerSync {
126187
fn from(recent_slots: Vec<(Slot, u32)>) -> Self {
127188
let lockouts: VecDeque<Lockout> = recent_slots

0 commit comments

Comments
 (0)