Skip to content

Commit 3791768

Browse files
committed
enable StableAbi for frozen-abi types
1 parent 45d6d88 commit 3791768

File tree

4 files changed

+213
-15
lines changed

4 files changed

+213
-15
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 = "2xEB2gzHSousWedFa7H6LYEK1m5GYzWYf95WYnogxKkS"
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::distr::StandardUniform
41+
{
42+
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> Vote {
43+
let slots: Vec<Slot> = (0..rng.random_range(0..1000))
44+
.map(|_| rng.random::<u64>().into())
45+
.collect();
46+
47+
Vote {
48+
slots,
49+
hash: Hash::new_from_array(rng.random()),
50+
timestamp: Some(rng.random()),
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 = "7oYbjCjdk8eVvp3wej7s3kPKSRUwRhmC9qWPRsW2RNtM"
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::distr::StandardUniform
93+
{
94+
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> VoteStateUpdate {
95+
let lockouts: VecDeque<_> = (0..rng.random_range(0..1000))
96+
.map(|_| Lockout::new(rng.random()))
97+
.collect();
98+
VoteStateUpdate {
99+
lockouts,
100+
root: Some(rng.random::<u64>().into()),
101+
hash: Hash::new_from_array(rng.random()),
102+
timestamp: Some(rng.random()),
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 = "5WwSB17ze8us9dwhJWXGR7yzaXseHHWFkpT5TCuBgca3"
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::distr::StandardUniform
171+
{
172+
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> TowerSync {
173+
let lockouts: VecDeque<_> = (0..rng.random_range(0..1000))
174+
.map(|_| Lockout::new(rng.random()))
175+
.collect();
176+
TowerSync {
177+
lockouts,
178+
root: Some(rng.random()),
179+
hash: Hash::new_from_array(rng.random()),
180+
timestamp: Some(rng.random()),
181+
block_id: Hash::new_from_array(rng.random()),
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

vote-interface/src/state/vote_state_1_14_11.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ use super::*;
22
#[cfg(feature = "dev-context-only-utils")]
33
use arbitrary::Arbitrary;
44

5+
#[cfg(feature = "frozen-abi")]
6+
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};
7+
58
// Offset used for VoteState version 1_14_11
69
const DEFAULT_PRIOR_VOTERS_OFFSET: usize = 82;
710

811
#[cfg_attr(
912
feature = "frozen-abi",
10-
solana_frozen_abi_macro::frozen_abi(digest = "2rjXSWaNeAdoUNJDC5otC7NPR1qXHvLMuAs5faE4DPEt"),
11-
derive(solana_frozen_abi_macro::AbiExample)
13+
frozen_abi(
14+
api_digest = "2rjXSWaNeAdoUNJDC5otC7NPR1qXHvLMuAs5faE4DPEt",
15+
abi_digest = "GQvUnzypqWVwtedNSVWrhtr3Uy4vUor4mbvzsoUEV79R"
16+
),
17+
derive(AbiExample, StableAbi)
1218
)]
1319
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
1420
#[derive(Debug, Default, PartialEq, Eq, Clone)]
@@ -45,6 +51,47 @@ pub struct VoteState1_14_11 {
4551
pub last_timestamp: BlockTimestamp,
4652
}
4753

54+
#[cfg(feature = "frozen-abi")]
55+
impl solana_frozen_abi::rand::prelude::Distribution<VoteState1_14_11>
56+
for solana_frozen_abi::rand::distr::StandardUniform
57+
{
58+
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> VoteState1_14_11 {
59+
let votes: VecDeque<_> = (0..rng.random_range(0..1000))
60+
.map(|_| Lockout::new(rng.random()))
61+
.collect();
62+
63+
let mut prior_voters: CircBuf<(Pubkey, Epoch, Epoch)> = CircBuf::default();
64+
for _ in 0..rng.random_range(0..1000) {
65+
prior_voters.append((
66+
Pubkey::new_from_array(rng.random()),
67+
rng.random(),
68+
rng.random(),
69+
));
70+
}
71+
let epoch_credits: Vec<_> = (0..rng.random_range(0..1000))
72+
.map(|_| (rng.random(), rng.random(), rng.random()))
73+
.collect();
74+
75+
VoteState1_14_11 {
76+
node_pubkey: Pubkey::new_from_array(rng.random()),
77+
authorized_withdrawer: Pubkey::new_from_array(rng.random()),
78+
commission: rng.random(),
79+
votes,
80+
root_slot: Some(rng.random()),
81+
authorized_voters: AuthorizedVoters::new(
82+
rng.random(),
83+
Pubkey::new_from_array(rng.random()),
84+
),
85+
prior_voters,
86+
epoch_credits,
87+
last_timestamp: BlockTimestamp {
88+
slot: rng.random(),
89+
timestamp: rng.random(),
90+
},
91+
}
92+
}
93+
}
94+
4895
impl VoteState1_14_11 {
4996
pub fn get_rent_exempt_reserve(rent: &Rent) -> u64 {
5097
rent.minimum_balance(Self::size_of())

vote-interface/src/state/vote_state_v3.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use arbitrary::Arbitrary;
77
#[cfg(feature = "serde")]
88
use serde_derive::{Deserialize, Serialize};
99
#[cfg(feature = "frozen-abi")]
10-
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
10+
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};
1111
#[cfg(any(target_os = "solana", feature = "bincode"))]
1212
use solana_instruction_error::InstructionError;
1313
use {
@@ -21,8 +21,11 @@ use {
2121

2222
#[cfg_attr(
2323
feature = "frozen-abi",
24-
frozen_abi(digest = "pZqasQc6duzMYzpzU7eriHH9cMXmubuUP4NmCrkWZjt"),
25-
derive(AbiExample)
24+
frozen_abi(
25+
api_digest = "pZqasQc6duzMYzpzU7eriHH9cMXmubuUP4NmCrkWZjt",
26+
abi_digest = "GYS8SRmr3HQnLdd7Dr4dDraWj9sratTP1UchASh1BT3D"
27+
),
28+
derive(AbiExample, StableAbi)
2629
)]
2730
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
2831
#[derive(Debug, Default, PartialEq, Eq, Clone)]
@@ -59,6 +62,50 @@ pub struct VoteStateV3 {
5962
pub last_timestamp: BlockTimestamp,
6063
}
6164

65+
#[cfg(feature = "frozen-abi")]
66+
impl solana_frozen_abi::rand::prelude::Distribution<VoteStateV3>
67+
for solana_frozen_abi::rand::distr::StandardUniform
68+
{
69+
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> VoteStateV3 {
70+
let votes: VecDeque<_> = (0..rng.random_range(0..1000))
71+
.map(|_| LandedVote {
72+
latency: rng.random(),
73+
lockout: crate::state::Lockout::new(rng.random()),
74+
})
75+
.collect();
76+
77+
let mut prior_voters: CircBuf<(Pubkey, Epoch, Epoch)> = CircBuf::default();
78+
for _ in 0..rng.random_range(0..1000) {
79+
prior_voters.append((
80+
Pubkey::new_from_array(rng.random()),
81+
rng.random(),
82+
rng.random(),
83+
));
84+
}
85+
let epoch_credits: Vec<_> = (0..rng.random_range(0..1000))
86+
.map(|_| (rng.random(), rng.random(), rng.random()))
87+
.collect();
88+
89+
VoteStateV3 {
90+
node_pubkey: Pubkey::new_from_array(rng.random()),
91+
authorized_withdrawer: Pubkey::new_from_array(rng.random()),
92+
commission: rng.random(),
93+
votes,
94+
root_slot: Some(rng.random()),
95+
authorized_voters: AuthorizedVoters::new(
96+
rng.random(),
97+
Pubkey::new_from_array(rng.random()),
98+
),
99+
prior_voters,
100+
epoch_credits,
101+
last_timestamp: BlockTimestamp {
102+
slot: rng.random(),
103+
timestamp: rng.random(),
104+
},
105+
}
106+
}
107+
}
108+
62109
impl VoteStateV3 {
63110
pub fn new(vote_init: &VoteInit, clock: &Clock) -> Self {
64111
Self {

vote-interface/src/state/vote_state_v4.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde_derive::{Deserialize, Serialize};
77
#[cfg(feature = "serde")]
88
use serde_with::serde_as;
99
#[cfg(feature = "frozen-abi")]
10-
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
10+
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};
1111
#[cfg(any(target_os = "solana", feature = "bincode"))]
1212
use solana_instruction::error::InstructionError;
1313
use {
@@ -20,8 +20,11 @@ use {
2020

2121
#[cfg_attr(
2222
feature = "frozen-abi",
23-
frozen_abi(digest = "2H9WgTh7LgdnpinvEwxzP3HF6SDuKp6qdwFmJk9jHDRP"),
24-
derive(AbiExample)
23+
frozen_abi(
24+
api_digest = "2H9WgTh7LgdnpinvEwxzP3HF6SDuKp6qdwFmJk9jHDRP",
25+
abi_digest = "CFpc8LMQhpYBsNctM4n9o6rn6BQJ4mcTx6pveGtb7YcM"
26+
),
27+
derive(AbiExample, StableAbi)
2528
)]
2629
#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_as)]
2730
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
@@ -70,6 +73,46 @@ pub struct VoteStateV4 {
7073
pub last_timestamp: BlockTimestamp,
7174
}
7275

76+
#[cfg(feature = "frozen-abi")]
77+
impl solana_frozen_abi::rand::prelude::Distribution<VoteStateV4>
78+
for solana_frozen_abi::rand::distr::StandardUniform
79+
{
80+
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> VoteStateV4 {
81+
let bls_pubkey_compressed = Some(std::array::from_fn(|_| rng.random()));
82+
let votes: VecDeque<_> = (0..rng.random_range(0..1000))
83+
.map(|_| LandedVote {
84+
latency: rng.random(),
85+
lockout: crate::state::Lockout::new(rng.random()),
86+
})
87+
.collect();
88+
let epoch_credits: Vec<_> = (0..rng.random_range(0..1000))
89+
.map(|_| (rng.random(), rng.random(), rng.random()))
90+
.collect();
91+
92+
VoteStateV4 {
93+
node_pubkey: Pubkey::new_from_array(rng.random()),
94+
authorized_withdrawer: Pubkey::new_from_array(rng.random()),
95+
inflation_rewards_collector: Pubkey::new_from_array(rng.random()),
96+
block_revenue_collector: Pubkey::new_from_array(rng.random()),
97+
inflation_rewards_commission_bps: rng.random(),
98+
block_revenue_commission_bps: rng.random(),
99+
pending_delegator_rewards: rng.random(),
100+
bls_pubkey_compressed,
101+
votes,
102+
root_slot: Some(rng.random()),
103+
authorized_voters: AuthorizedVoters::new(
104+
rng.random(),
105+
Pubkey::new_from_array(rng.random()),
106+
),
107+
epoch_credits,
108+
last_timestamp: BlockTimestamp {
109+
slot: rng.random(),
110+
timestamp: rng.random(),
111+
},
112+
}
113+
}
114+
}
115+
73116
impl VoteStateV4 {
74117
/// Upper limit on the size of the Vote State
75118
/// when votes.len() is MAX_LOCKOUT_HISTORY.

0 commit comments

Comments
 (0)