Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 8e4a9a9

Browse files
authored
sdk: Add new version of StakeState to avoid breaking downstream users (#32736)
* sdk: Rename `StakeState` -> `StakeStateWithFlags` * Add back `StakeFlags` with a deprecation warning
1 parent ef318c2 commit 8e4a9a9

File tree

24 files changed

+782
-466
lines changed

24 files changed

+782
-466
lines changed

account-decoder/src/parse_stake.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ use {
66
bincode::deserialize,
77
solana_sdk::{
88
clock::{Epoch, UnixTimestamp},
9-
stake::state::{Authorized, Delegation, Lockup, Meta, Stake, StakeState},
9+
stake::state::{Authorized, Delegation, Lockup, Meta, Stake, StakeStateWithFlags},
1010
},
1111
};
1212

1313
pub fn parse_stake(data: &[u8]) -> Result<StakeAccountType, ParseAccountError> {
14-
let stake_state: StakeState = deserialize(data)
14+
let stake_state: StakeStateWithFlags = deserialize(data)
1515
.map_err(|_| ParseAccountError::AccountNotParsable(ParsableAccount::Stake))?;
1616
let parsed_account = match stake_state {
17-
StakeState::Uninitialized => StakeAccountType::Uninitialized,
18-
StakeState::Initialized(meta) => StakeAccountType::Initialized(UiStakeAccount {
17+
StakeStateWithFlags::Uninitialized => StakeAccountType::Uninitialized,
18+
StakeStateWithFlags::Initialized(meta) => StakeAccountType::Initialized(UiStakeAccount {
1919
meta: meta.into(),
2020
stake: None,
2121
}),
22-
StakeState::Stake(meta, stake, _) => StakeAccountType::Delegated(UiStakeAccount {
22+
StakeStateWithFlags::Stake(meta, stake, _) => StakeAccountType::Delegated(UiStakeAccount {
2323
meta: meta.into(),
2424
stake: Some(stake.into()),
2525
}),
26-
StakeState::RewardsPool => StakeAccountType::RewardsPool,
26+
StakeStateWithFlags::RewardsPool => StakeAccountType::RewardsPool,
2727
};
2828
Ok(parsed_account)
2929
}
@@ -146,7 +146,7 @@ mod test {
146146
#[test]
147147
#[allow(deprecated)]
148148
fn test_parse_stake() {
149-
let stake_state = StakeState::Uninitialized;
149+
let stake_state = StakeStateWithFlags::Uninitialized;
150150
let stake_data = serialize(&stake_state).unwrap();
151151
assert_eq!(
152152
parse_stake(&stake_data).unwrap(),
@@ -167,7 +167,7 @@ mod test {
167167
lockup,
168168
};
169169

170-
let stake_state = StakeState::Initialized(meta);
170+
let stake_state = StakeStateWithFlags::Initialized(meta);
171171
let stake_data = serialize(&stake_state).unwrap();
172172
assert_eq!(
173173
parse_stake(&stake_data).unwrap(),
@@ -200,7 +200,7 @@ mod test {
200200
credits_observed: 10,
201201
};
202202

203-
let stake_state = StakeState::Stake(meta, stake, StakeFlags::empty());
203+
let stake_state = StakeStateWithFlags::Stake(meta, stake, StakeFlags::empty());
204204
let stake_data = serialize(&stake_state).unwrap();
205205
assert_eq!(
206206
parse_stake(&stake_data).unwrap(),
@@ -230,7 +230,7 @@ mod test {
230230
})
231231
);
232232

233-
let stake_state = StakeState::RewardsPool;
233+
let stake_state = StakeStateWithFlags::RewardsPool;
234234
let stake_data = serialize(&stake_state).unwrap();
235235
assert_eq!(
236236
parse_stake(&stake_data).unwrap(),

cli/src/cluster_query.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use {
5454
rpc_port::DEFAULT_RPC_PORT_STR,
5555
signature::Signature,
5656
slot_history,
57-
stake::{self, state::StakeState},
57+
stake::{self, state::StakeStateWithFlags},
5858
system_instruction,
5959
sysvar::{
6060
self,
@@ -1768,7 +1768,7 @@ pub fn process_show_stakes(
17681768
// Use server-side filtering if only one vote account is provided
17691769
if vote_account_pubkeys.len() == 1 {
17701770
program_accounts_config.filters = Some(vec![
1771-
// Filter by `StakeState::Stake(_, _)`
1771+
// Filter by `StakeStateWithFlags::Stake(_, _)`
17721772
RpcFilterType::Memcmp(Memcmp::new_base58_encoded(0, &[2, 0, 0, 0])),
17731773
// Filter by `Delegation::voter_pubkey`, which begins at byte offset 124
17741774
RpcFilterType::Memcmp(Memcmp::new_base58_encoded(
@@ -1809,7 +1809,7 @@ pub fn process_show_stakes(
18091809
for (stake_pubkey, stake_account) in all_stake_accounts {
18101810
if let Ok(stake_state) = stake_account.state() {
18111811
match stake_state {
1812-
StakeState::Initialized(_) => {
1812+
StakeStateWithFlags::Initialized(_) => {
18131813
if vote_account_pubkeys.is_none() {
18141814
stake_accounts.push(CliKeyedStakeState {
18151815
stake_pubkey: stake_pubkey.to_string(),
@@ -1824,7 +1824,7 @@ pub fn process_show_stakes(
18241824
});
18251825
}
18261826
}
1827-
StakeState::Stake(_, stake, _) => {
1827+
StakeStateWithFlags::Stake(_, stake, _) => {
18281828
if vote_account_pubkeys.is_none()
18291829
|| vote_account_pubkeys
18301830
.unwrap()
@@ -2157,7 +2157,7 @@ impl RentLengthValue {
21572157
pub fn length(&self) -> usize {
21582158
match self {
21592159
Self::Nonce => NonceState::size(),
2160-
Self::Stake => StakeState::size_of(),
2160+
Self::Stake => StakeStateWithFlags::size_of(),
21612161
Self::System => 0,
21622162
Self::Vote => VoteState::size_of(),
21632163
Self::Bytes(l) => *l,

cli/src/stake.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ use {
4747
stake::{
4848
self,
4949
instruction::{self as stake_instruction, LockupArgs, StakeError},
50-
state::{Authorized, Lockup, Meta, StakeActivationStatus, StakeAuthorize, StakeState},
50+
state::{
51+
Authorized, Lockup, Meta, StakeActivationStatus, StakeAuthorize,
52+
StakeStateWithFlags,
53+
},
5154
tools::{acceptable_reference_epoch_credits, eligible_for_deactivate_delinquent},
5255
},
5356
stake_history::{Epoch, StakeHistory},
@@ -1422,7 +1425,7 @@ pub fn process_create_stake_account(
14221425
}
14231426

14241427
let minimum_balance =
1425-
rpc_client.get_minimum_balance_for_rent_exemption(StakeState::size_of())?;
1428+
rpc_client.get_minimum_balance_for_rent_exemption(StakeStateWithFlags::size_of())?;
14261429

14271430
if lamports < minimum_balance {
14281431
return Err(CliError::BadParameter(format!(
@@ -1500,8 +1503,8 @@ pub fn process_stake_authorize(
15001503
let authority = config.signers[*authority];
15011504
if let Some(current_stake_account) = current_stake_account {
15021505
let authorized = match current_stake_account {
1503-
StakeState::Stake(Meta { authorized, .. }, ..) => Some(authorized),
1504-
StakeState::Initialized(Meta { authorized, .. }) => Some(authorized),
1506+
StakeStateWithFlags::Stake(Meta { authorized, .. }, ..) => Some(authorized),
1507+
StakeStateWithFlags::Initialized(Meta { authorized, .. }) => Some(authorized),
15051508
_ => None,
15061509
};
15071510
if let Some(authorized) = authorized {
@@ -1630,7 +1633,7 @@ pub fn process_deactivate_stake_account(
16301633

16311634
let vote_account_address = match stake_account.state() {
16321635
Ok(stake_state) => match stake_state {
1633-
StakeState::Stake(_, stake, _) => stake.delegation.voter_pubkey,
1636+
StakeStateWithFlags::Stake(_, stake, _) => stake.delegation.voter_pubkey,
16341637
_ => {
16351638
return Err(CliError::BadParameter(format!(
16361639
"{stake_account_address} is not a delegated stake account",
@@ -1895,7 +1898,7 @@ pub fn process_split_stake(
18951898
}
18961899

18971900
let minimum_balance =
1898-
rpc_client.get_minimum_balance_for_rent_exemption(StakeState::size_of())?;
1901+
rpc_client.get_minimum_balance_for_rent_exemption(StakeStateWithFlags::size_of())?;
18991902

19001903
if lamports < minimum_balance {
19011904
return Err(CliError::BadParameter(format!(
@@ -2116,8 +2119,8 @@ pub fn process_stake_set_lockup(
21162119
if !sign_only {
21172120
let state = get_stake_account_state(rpc_client, stake_account_pubkey, config.commitment)?;
21182121
let lockup = match state {
2119-
StakeState::Stake(Meta { lockup, .. }, ..) => Some(lockup),
2120-
StakeState::Initialized(Meta { lockup, .. }) => Some(lockup),
2122+
StakeStateWithFlags::Stake(Meta { lockup, .. }, ..) => Some(lockup),
2123+
StakeStateWithFlags::Initialized(Meta { lockup, .. }) => Some(lockup),
21212124
_ => None,
21222125
};
21232126
if let Some(lockup) = lockup {
@@ -2184,14 +2187,14 @@ fn u64_some_if_not_zero(n: u64) -> Option<u64> {
21842187

21852188
pub fn build_stake_state(
21862189
account_balance: u64,
2187-
stake_state: &StakeState,
2190+
stake_state: &StakeStateWithFlags,
21882191
use_lamports_unit: bool,
21892192
stake_history: &StakeHistory,
21902193
clock: &Clock,
21912194
new_rate_activation_epoch: Option<Epoch>,
21922195
) -> CliStakeState {
21932196
match stake_state {
2194-
StakeState::Stake(
2197+
StakeStateWithFlags::Stake(
21952198
Meta {
21962199
rent_exempt_reserve,
21972200
authorized,
@@ -2248,16 +2251,16 @@ pub fn build_stake_state(
22482251
..CliStakeState::default()
22492252
}
22502253
}
2251-
StakeState::RewardsPool => CliStakeState {
2254+
StakeStateWithFlags::RewardsPool => CliStakeState {
22522255
stake_type: CliStakeType::RewardsPool,
22532256
account_balance,
22542257
..CliStakeState::default()
22552258
},
2256-
StakeState::Uninitialized => CliStakeState {
2259+
StakeStateWithFlags::Uninitialized => CliStakeState {
22572260
account_balance,
22582261
..CliStakeState::default()
22592262
},
2260-
StakeState::Initialized(Meta {
2263+
StakeStateWithFlags::Initialized(Meta {
22612264
rent_exempt_reserve,
22622265
authorized,
22632266
lockup,
@@ -2285,7 +2288,7 @@ fn get_stake_account_state(
22852288
rpc_client: &RpcClient,
22862289
stake_account_pubkey: &Pubkey,
22872290
commitment_config: CommitmentConfig,
2288-
) -> Result<StakeState, Box<dyn std::error::Error>> {
2291+
) -> Result<StakeStateWithFlags, Box<dyn std::error::Error>> {
22892292
let stake_account = rpc_client
22902293
.get_account_with_commitment(stake_account_pubkey, commitment_config)?
22912294
.value

0 commit comments

Comments
 (0)