Skip to content

Commit

Permalink
stake: Rename StakeStateWithFlags -> StakeStateV2 (#32795)
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque authored Aug 10, 2023
1 parent 35ec7bf commit c73a56f
Show file tree
Hide file tree
Showing 24 changed files with 472 additions and 570 deletions.
20 changes: 10 additions & 10 deletions account-decoder/src/parse_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ use {
bincode::deserialize,
solana_sdk::{
clock::{Epoch, UnixTimestamp},
stake::state::{Authorized, Delegation, Lockup, Meta, Stake, StakeStateWithFlags},
stake::state::{Authorized, Delegation, Lockup, Meta, Stake, StakeStateV2},
},
};

pub fn parse_stake(data: &[u8]) -> Result<StakeAccountType, ParseAccountError> {
let stake_state: StakeStateWithFlags = deserialize(data)
let stake_state: StakeStateV2 = deserialize(data)
.map_err(|_| ParseAccountError::AccountNotParsable(ParsableAccount::Stake))?;
let parsed_account = match stake_state {
StakeStateWithFlags::Uninitialized => StakeAccountType::Uninitialized,
StakeStateWithFlags::Initialized(meta) => StakeAccountType::Initialized(UiStakeAccount {
StakeStateV2::Uninitialized => StakeAccountType::Uninitialized,
StakeStateV2::Initialized(meta) => StakeAccountType::Initialized(UiStakeAccount {
meta: meta.into(),
stake: None,
}),
StakeStateWithFlags::Stake(meta, stake, _) => StakeAccountType::Delegated(UiStakeAccount {
StakeStateV2::Stake(meta, stake, _) => StakeAccountType::Delegated(UiStakeAccount {
meta: meta.into(),
stake: Some(stake.into()),
}),
StakeStateWithFlags::RewardsPool => StakeAccountType::RewardsPool,
StakeStateV2::RewardsPool => StakeAccountType::RewardsPool,
};
Ok(parsed_account)
}
Expand Down Expand Up @@ -146,7 +146,7 @@ mod test {
#[test]
#[allow(deprecated)]
fn test_parse_stake() {
let stake_state = StakeStateWithFlags::Uninitialized;
let stake_state = StakeStateV2::Uninitialized;
let stake_data = serialize(&stake_state).unwrap();
assert_eq!(
parse_stake(&stake_data).unwrap(),
Expand All @@ -167,7 +167,7 @@ mod test {
lockup,
};

let stake_state = StakeStateWithFlags::Initialized(meta);
let stake_state = StakeStateV2::Initialized(meta);
let stake_data = serialize(&stake_state).unwrap();
assert_eq!(
parse_stake(&stake_data).unwrap(),
Expand Down Expand Up @@ -200,7 +200,7 @@ mod test {
credits_observed: 10,
};

let stake_state = StakeStateWithFlags::Stake(meta, stake, StakeFlags::empty());
let stake_state = StakeStateV2::Stake(meta, stake, StakeFlags::empty());
let stake_data = serialize(&stake_state).unwrap();
assert_eq!(
parse_stake(&stake_data).unwrap(),
Expand Down Expand Up @@ -230,7 +230,7 @@ mod test {
})
);

let stake_state = StakeStateWithFlags::RewardsPool;
let stake_state = StakeStateV2::RewardsPool;
let stake_data = serialize(&stake_state).unwrap();
assert_eq!(
parse_stake(&stake_data).unwrap(),
Expand Down
10 changes: 5 additions & 5 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use {
rpc_port::DEFAULT_RPC_PORT_STR,
signature::Signature,
slot_history,
stake::{self, state::StakeStateWithFlags},
stake::{self, state::StakeStateV2},
system_instruction,
sysvar::{
self,
Expand Down Expand Up @@ -1768,7 +1768,7 @@ pub fn process_show_stakes(
// Use server-side filtering if only one vote account is provided
if vote_account_pubkeys.len() == 1 {
program_accounts_config.filters = Some(vec![
// Filter by `StakeStateWithFlags::Stake(_, _)`
// Filter by `StakeStateV2::Stake(_, _)`
RpcFilterType::Memcmp(Memcmp::new_base58_encoded(0, &[2, 0, 0, 0])),
// Filter by `Delegation::voter_pubkey`, which begins at byte offset 124
RpcFilterType::Memcmp(Memcmp::new_base58_encoded(
Expand Down Expand Up @@ -1809,7 +1809,7 @@ pub fn process_show_stakes(
for (stake_pubkey, stake_account) in all_stake_accounts {
if let Ok(stake_state) = stake_account.state() {
match stake_state {
StakeStateWithFlags::Initialized(_) => {
StakeStateV2::Initialized(_) => {
if vote_account_pubkeys.is_none() {
stake_accounts.push(CliKeyedStakeState {
stake_pubkey: stake_pubkey.to_string(),
Expand All @@ -1824,7 +1824,7 @@ pub fn process_show_stakes(
});
}
}
StakeStateWithFlags::Stake(_, stake, _) => {
StakeStateV2::Stake(_, stake, _) => {
if vote_account_pubkeys.is_none()
|| vote_account_pubkeys
.unwrap()
Expand Down Expand Up @@ -2157,7 +2157,7 @@ impl RentLengthValue {
pub fn length(&self) -> usize {
match self {
Self::Nonce => NonceState::size(),
Self::Stake => StakeStateWithFlags::size_of(),
Self::Stake => StakeStateV2::size_of(),
Self::System => 0,
Self::Vote => VoteState::size_of(),
Self::Bytes(l) => *l,
Expand Down
29 changes: 14 additions & 15 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ use {
self,
instruction::{self as stake_instruction, LockupArgs, StakeError},
state::{
Authorized, Lockup, Meta, StakeActivationStatus, StakeAuthorize,
StakeStateWithFlags,
Authorized, Lockup, Meta, StakeActivationStatus, StakeAuthorize, StakeStateV2,
},
tools::{acceptable_reference_epoch_credits, eligible_for_deactivate_delinquent},
},
Expand Down Expand Up @@ -1425,7 +1424,7 @@ pub fn process_create_stake_account(
}

let minimum_balance =
rpc_client.get_minimum_balance_for_rent_exemption(StakeStateWithFlags::size_of())?;
rpc_client.get_minimum_balance_for_rent_exemption(StakeStateV2::size_of())?;

if lamports < minimum_balance {
return Err(CliError::BadParameter(format!(
Expand Down Expand Up @@ -1503,8 +1502,8 @@ pub fn process_stake_authorize(
let authority = config.signers[*authority];
if let Some(current_stake_account) = current_stake_account {
let authorized = match current_stake_account {
StakeStateWithFlags::Stake(Meta { authorized, .. }, ..) => Some(authorized),
StakeStateWithFlags::Initialized(Meta { authorized, .. }) => Some(authorized),
StakeStateV2::Stake(Meta { authorized, .. }, ..) => Some(authorized),
StakeStateV2::Initialized(Meta { authorized, .. }) => Some(authorized),
_ => None,
};
if let Some(authorized) = authorized {
Expand Down Expand Up @@ -1633,7 +1632,7 @@ pub fn process_deactivate_stake_account(

let vote_account_address = match stake_account.state() {
Ok(stake_state) => match stake_state {
StakeStateWithFlags::Stake(_, stake, _) => stake.delegation.voter_pubkey,
StakeStateV2::Stake(_, stake, _) => stake.delegation.voter_pubkey,
_ => {
return Err(CliError::BadParameter(format!(
"{stake_account_address} is not a delegated stake account",
Expand Down Expand Up @@ -1898,7 +1897,7 @@ pub fn process_split_stake(
}

let minimum_balance =
rpc_client.get_minimum_balance_for_rent_exemption(StakeStateWithFlags::size_of())?;
rpc_client.get_minimum_balance_for_rent_exemption(StakeStateV2::size_of())?;

if lamports < minimum_balance {
return Err(CliError::BadParameter(format!(
Expand Down Expand Up @@ -2119,8 +2118,8 @@ pub fn process_stake_set_lockup(
if !sign_only {
let state = get_stake_account_state(rpc_client, stake_account_pubkey, config.commitment)?;
let lockup = match state {
StakeStateWithFlags::Stake(Meta { lockup, .. }, ..) => Some(lockup),
StakeStateWithFlags::Initialized(Meta { lockup, .. }) => Some(lockup),
StakeStateV2::Stake(Meta { lockup, .. }, ..) => Some(lockup),
StakeStateV2::Initialized(Meta { lockup, .. }) => Some(lockup),
_ => None,
};
if let Some(lockup) = lockup {
Expand Down Expand Up @@ -2187,14 +2186,14 @@ fn u64_some_if_not_zero(n: u64) -> Option<u64> {

pub fn build_stake_state(
account_balance: u64,
stake_state: &StakeStateWithFlags,
stake_state: &StakeStateV2,
use_lamports_unit: bool,
stake_history: &StakeHistory,
clock: &Clock,
new_rate_activation_epoch: Option<Epoch>,
) -> CliStakeState {
match stake_state {
StakeStateWithFlags::Stake(
StakeStateV2::Stake(
Meta {
rent_exempt_reserve,
authorized,
Expand Down Expand Up @@ -2251,16 +2250,16 @@ pub fn build_stake_state(
..CliStakeState::default()
}
}
StakeStateWithFlags::RewardsPool => CliStakeState {
StakeStateV2::RewardsPool => CliStakeState {
stake_type: CliStakeType::RewardsPool,
account_balance,
..CliStakeState::default()
},
StakeStateWithFlags::Uninitialized => CliStakeState {
StakeStateV2::Uninitialized => CliStakeState {
account_balance,
..CliStakeState::default()
},
StakeStateWithFlags::Initialized(Meta {
StakeStateV2::Initialized(Meta {
rent_exempt_reserve,
authorized,
lockup,
Expand Down Expand Up @@ -2288,7 +2287,7 @@ fn get_stake_account_state(
rpc_client: &RpcClient,
stake_account_pubkey: &Pubkey,
commitment_config: CommitmentConfig,
) -> Result<StakeStateWithFlags, Box<dyn std::error::Error>> {
) -> Result<StakeStateV2, Box<dyn std::error::Error>> {
let stake_account = rpc_client
.get_account_with_commitment(stake_account_pubkey, commitment_config)?
.value
Expand Down
Loading

0 comments on commit c73a56f

Please sign in to comment.