Browse Source

stake: Rename `StakeStateWithFlags` -> `StakeStateV2` (#32795)

Jon Cinque 2 years ago
parent
commit
c73a56faf8

+ 10 - 10
account-decoder/src/parse_stake.rs

@@ -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)
 }
@@ -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(),
@@ -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(),
@@ -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(),
@@ -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(),

+ 5 - 5
cli/src/cluster_query.rs

@@ -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,
@@ -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(
@@ -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(),
@@ -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()
@@ -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,

+ 14 - 15
cli/src/stake.rs

@@ -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},
         },
@@ -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!(
@@ -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 {
@@ -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",
@@ -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!(
@@ -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 {
@@ -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,
@@ -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,
@@ -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

+ 29 - 31
cli/tests/stake.rs

@@ -26,7 +26,7 @@ use {
         stake::{
             self,
             instruction::LockupArgs,
-            state::{Lockup, StakeAuthorize, StakeStateWithFlags},
+            state::{Lockup, StakeAuthorize, StakeStateV2},
         },
     },
     solana_streamer::socket::SocketAddrSpace,
@@ -162,10 +162,10 @@ fn test_stake_redelegation() {
 
     // `stake_keypair` should now be delegated to `vote_keypair` and fully activated
     let stake_account = rpc_client.get_account(&stake_keypair.pubkey()).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
 
     let rent_exempt_reserve = match stake_state {
-        StakeStateWithFlags::Stake(meta, stake, _) => {
+        StakeStateV2::Stake(meta, stake, _) => {
             assert_eq!(stake.delegation.voter_pubkey, vote_keypair.pubkey());
             meta.rent_exempt_reserve
         }
@@ -268,10 +268,10 @@ fn test_stake_redelegation() {
 
     // `stake2_keypair` should now be delegated to `vote2_keypair` and fully activated
     let stake2_account = rpc_client.get_account(&stake2_keypair.pubkey()).unwrap();
-    let stake2_state: StakeStateWithFlags = stake2_account.state().unwrap();
+    let stake2_state: StakeStateV2 = stake2_account.state().unwrap();
 
     match stake2_state {
-        StakeStateWithFlags::Stake(_meta, stake, _) => {
+        StakeStateV2::Stake(_meta, stake, _) => {
             assert_eq!(stake.delegation.voter_pubkey, vote2_keypair.pubkey());
         }
         _ => panic!("Unexpected stake2 state!"),
@@ -966,9 +966,9 @@ fn test_stake_authorize() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let current_authority = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => meta.authorized.staker,
+        StakeStateV2::Initialized(meta) => meta.authorized.staker,
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(current_authority, online_authority_pubkey);
@@ -1008,11 +1008,9 @@ fn test_stake_authorize() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let (current_staker, current_withdrawer) = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => {
-            (meta.authorized.staker, meta.authorized.withdrawer)
-        }
+        StakeStateV2::Initialized(meta) => (meta.authorized.staker, meta.authorized.withdrawer),
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(current_staker, online_authority2_pubkey);
@@ -1042,9 +1040,9 @@ fn test_stake_authorize() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let current_authority = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => meta.authorized.staker,
+        StakeStateV2::Initialized(meta) => meta.authorized.staker,
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(current_authority, offline_authority_pubkey);
@@ -1099,9 +1097,9 @@ fn test_stake_authorize() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let current_authority = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => meta.authorized.staker,
+        StakeStateV2::Initialized(meta) => meta.authorized.staker,
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(current_authority, nonced_authority_pubkey);
@@ -1186,9 +1184,9 @@ fn test_stake_authorize() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let current_authority = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => meta.authorized.staker,
+        StakeStateV2::Initialized(meta) => meta.authorized.staker,
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(current_authority, online_authority_pubkey);
@@ -1436,7 +1434,7 @@ fn test_stake_split() {
 
     // Create stake account, identity is authority
     let stake_balance = rpc_client
-        .get_minimum_balance_for_rent_exemption(StakeStateWithFlags::size_of())
+        .get_minimum_balance_for_rent_exemption(StakeStateV2::size_of())
         .unwrap()
         + 10_000_000_000;
     let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
@@ -1589,7 +1587,7 @@ fn test_stake_set_lockup() {
 
     // Create stake account, identity is authority
     let stake_balance = rpc_client
-        .get_minimum_balance_for_rent_exemption(StakeStateWithFlags::size_of())
+        .get_minimum_balance_for_rent_exemption(StakeStateV2::size_of())
         .unwrap()
         + 10_000_000_000;
 
@@ -1647,9 +1645,9 @@ fn test_stake_set_lockup() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let current_lockup = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => meta.lockup,
+        StakeStateV2::Initialized(meta) => meta.lockup,
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(
@@ -1706,9 +1704,9 @@ fn test_stake_set_lockup() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let current_lockup = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => meta.lockup,
+        StakeStateV2::Initialized(meta) => meta.lockup,
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(
@@ -1813,9 +1811,9 @@ fn test_stake_set_lockup() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let current_lockup = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => meta.lockup,
+        StakeStateV2::Initialized(meta) => meta.lockup,
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(
@@ -2189,9 +2187,9 @@ fn test_stake_checked_instructions() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let current_authority = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => meta.authorized.staker,
+        StakeStateV2::Initialized(meta) => meta.authorized.staker,
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(current_authority, staker_pubkey);
@@ -2246,9 +2244,9 @@ fn test_stake_checked_instructions() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let current_authority = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => meta.authorized.withdrawer,
+        StakeStateV2::Initialized(meta) => meta.authorized.withdrawer,
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(current_authority, new_withdrawer_pubkey);
@@ -2295,9 +2293,9 @@ fn test_stake_checked_instructions() {
     };
     process_command(&config).unwrap();
     let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
-    let stake_state: StakeStateWithFlags = stake_account.state().unwrap();
+    let stake_state: StakeStateV2 = stake_account.state().unwrap();
     let current_lockup = match stake_state {
-        StakeStateWithFlags::Initialized(meta) => meta.lockup,
+        StakeStateV2::Initialized(meta) => meta.lockup,
         _ => panic!("Unexpected stake state!"),
     };
     assert_eq!(

+ 2 - 2
docs/art/passive-staking-callflow.msc

@@ -11,8 +11,8 @@ msc {
 
   VoteSigner <:> Validator [label="register\n\n(optional)"];
   Validator => Cluster [label="VoteState::Initialize(VoteSigner)"];
-  StakerX => Cluster [label="StakeStateWithFlags::Delegate(Validator)"];
-  StakerY => Cluster [label="StakeStateWithFlags::Delegate(Validator)"];
+  StakerX => Cluster [label="StakeStateV2::Delegate(Validator)"];
+  StakerY => Cluster [label="StakeStateV2::Delegate(Validator)"];
 
      |||;
   Validator box Cluster [label="\nvalidate\n"];

+ 13 - 13
docs/src/cluster/stake-delegation-and-rewards.md

@@ -14,7 +14,7 @@ A separate Stake account \(created by a staker\) names a Vote account to which t
 
 Any number of Stake accounts can delegate to a single Vote account without an interactive action from the identity controlling the Vote account or submitting votes to the account.
 
-The total stake allocated to a Vote account can be calculated by the sum of all the Stake accounts that have the Vote account pubkey as the `StakeStateWithFlags::Stake::voter_pubkey`.
+The total stake allocated to a Vote account can be calculated by the sum of all the Stake accounts that have the Vote account pubkey as the `StakeStateV2::Stake::voter_pubkey`.
 
 ## Vote and Stake accounts
 
@@ -62,13 +62,13 @@ Updates the account with a new authorized voter or withdrawer, according to the
 - `account[1]` - RO - `sysvar::slot_hashes` A list of some N most recent slots and their hashes for the vote to be verified against.
 - `account[2]` - RO - `sysvar::clock` The current network time, expressed in slots, epochs.
 
-### StakeStateWithFlags
+### StakeStateV2
 
-A StakeStateWithFlags takes one of four forms, StakeStateWithFlags::Uninitialized, StakeStateWithFlags::Initialized, StakeStateWithFlags::Stake, and StakeStateWithFlags::RewardsPool. Only the first three forms are used in staking, but only StakeStateWithFlags::Stake is interesting. All RewardsPools are created at genesis.
+A StakeStateV2 takes one of four forms, StakeStateV2::Uninitialized, StakeStateV2::Initialized, StakeStateV2::Stake, and StakeStateV2::RewardsPool. Only the first three forms are used in staking, but only StakeStateV2::Stake is interesting. All RewardsPools are created at genesis.
 
-### StakeStateWithFlags::Stake
+### StakeStateV2::Stake
 
-StakeStateWithFlags::Stake is the current delegation preference of the **staker** and contains the following state information:
+StakeStateV2::Stake is the current delegation preference of the **staker** and contains the following state information:
 
 - Account::lamports - The lamports available for staking.
 - `stake` - the staked amount \(subject to warmup and cooldown\) for generating rewards, always less than or equal to Account::lamports.
@@ -79,7 +79,7 @@ StakeStateWithFlags::Stake is the current delegation preference of the **staker*
 - `authorized_staker` - the pubkey of the entity that must sign delegation, activation, and deactivation transactions.
 - `authorized_withdrawer` - the identity of the entity in charge of the lamports of this account, separate from the account's address, and the authorized staker.
 
-### StakeStateWithFlags::RewardsPool
+### StakeStateV2::RewardsPool
 
 To avoid a single network-wide lock or contention in redemption, 256 RewardsPools are part of genesis under pre-determined keys, each with std::u64::MAX credits to be able to satisfy redemptions according to point value.
 
@@ -87,9 +87,9 @@ The Stakes and the RewardsPool are accounts that are owned by the same `Stake` p
 
 ### StakeInstruction::DelegateStake
 
-The Stake account is moved from Initialized to StakeStateWithFlags::Stake form, or from a deactivated (i.e. fully cooled-down) StakeStateWithFlags::Stake to activated StakeStateWithFlags::Stake. This is how stakers choose the vote account and validator node to which their stake account lamports are delegated. The transaction must be signed by the stake's `authorized_staker`.
+The Stake account is moved from Initialized to StakeStateV2::Stake form, or from a deactivated (i.e. fully cooled-down) StakeStateV2::Stake to activated StakeStateV2::Stake. This is how stakers choose the vote account and validator node to which their stake account lamports are delegated. The transaction must be signed by the stake's `authorized_staker`.
 
-- `account[0]` - RW - The StakeStateWithFlags::Stake instance. `StakeStateWithFlags::Stake::credits_observed` is initialized to `VoteState::credits`, `StakeStateWithFlags::Stake::voter_pubkey` is initialized to `account[1]`. If this is the initial delegation of stake, `StakeStateWithFlags::Stake::stake` is initialized to the account's balance in lamports, `StakeStateWithFlags::Stake::activated` is initialized to the current Bank epoch, and `StakeStateWithFlags::Stake::deactivated` is initialized to std::u64::MAX
+- `account[0]` - RW - The StakeStateV2::Stake instance. `StakeStateV2::Stake::credits_observed` is initialized to `VoteState::credits`, `StakeStateV2::Stake::voter_pubkey` is initialized to `account[1]`. If this is the initial delegation of stake, `StakeStateV2::Stake::stake` is initialized to the account's balance in lamports, `StakeStateV2::Stake::activated` is initialized to the current Bank epoch, and `StakeStateV2::Stake::deactivated` is initialized to std::u64::MAX
 - `account[1]` - R - The VoteState instance.
 - `account[2]` - R - sysvar::clock account, carries information about current Bank epoch.
 - `account[3]` - R - sysvar::stakehistory account, carries information about stake history.
@@ -99,25 +99,25 @@ The Stake account is moved from Initialized to StakeStateWithFlags::Stake form,
 
 Updates the account with a new authorized staker or withdrawer, according to the StakeAuthorize parameter \(`Staker` or `Withdrawer`\). The transaction must be by signed by the Stakee account's current `authorized_staker` or `authorized_withdrawer`. Any stake lock-up must have expired, or the lock-up custodian must also sign the transaction.
 
-- `account[0]` - RW - The StakeStateWithFlags.
+- `account[0]` - RW - The StakeStateV2.
 
-  `StakeStateWithFlags::authorized_staker` or `authorized_withdrawer` is set to to `Pubkey`.
+  `StakeStateV2::authorized_staker` or `authorized_withdrawer` is set to to `Pubkey`.
 
 ### StakeInstruction::Deactivate
 
 A staker may wish to withdraw from the network. To do so he must first deactivate his stake, and wait for cooldown.
 The transaction must be signed by the stake's `authorized_staker`.
 
-- `account[0]` - RW - The StakeStateWithFlags::Stake instance that is deactivating.
+- `account[0]` - RW - The StakeStateV2::Stake instance that is deactivating.
 - `account[1]` - R - sysvar::clock account from the Bank that carries current epoch.
 
-StakeStateWithFlags::Stake::deactivated is set to the current epoch + cooldown. The account's stake will ramp down to zero by that epoch, and Account::lamports will be available for withdrawal.
+StakeStateV2::Stake::deactivated is set to the current epoch + cooldown. The account's stake will ramp down to zero by that epoch, and Account::lamports will be available for withdrawal.
 
 ### StakeInstruction::Withdraw\(u64\)
 
 Lamports build up over time in a Stake account and any excess over activated stake can be withdrawn. The transaction must be signed by the stake's `authorized_withdrawer`.
 
-- `account[0]` - RW - The StakeStateWithFlags::Stake from which to withdraw.
+- `account[0]` - RW - The StakeStateV2::Stake from which to withdraw.
 - `account[1]` - RW - Account that should be credited with the withdrawn lamports.
 - `account[2]` - R - sysvar::clock account from the Bank that carries current epoch, to calculate stake.
 - `account[3]` - R - sysvar::stake_history account from the Bank that carries stake warmup/cooldown history.

+ 3 - 3
genesis/src/main.rs

@@ -31,7 +31,7 @@ use {
         rent::Rent,
         signature::{Keypair, Signer},
         signer::keypair::read_keypair_file,
-        stake::state::StakeStateWithFlags,
+        stake::state::StakeStateV2,
         system_program, timing,
     },
     solana_stake_program::stake_state,
@@ -141,7 +141,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
         .to_string();
     // stake account
     let default_bootstrap_validator_stake_lamports = &sol_to_lamports(0.5)
-        .max(rent.minimum_balance(StakeStateWithFlags::size_of()))
+        .max(rent.minimum_balance(StakeStateV2::size_of()))
         .to_string();
 
     let default_target_tick_duration =
@@ -444,7 +444,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
     let bootstrap_validator_stake_lamports = rent_exempt_check(
         &matches,
         "bootstrap_validator_stake_lamports",
-        rent.minimum_balance(StakeStateWithFlags::size_of()),
+        rent.minimum_balance(StakeStateV2::size_of()),
     )?;
 
     let bootstrap_stake_authorized_pubkey =

+ 4 - 8
genesis/src/stakes.rs

@@ -11,7 +11,7 @@ use {
         pubkey::Pubkey,
         stake::{
             self,
-            state::{Authorized, Lockup, StakeStateWithFlags},
+            state::{Authorized, Lockup, StakeStateV2},
         },
         system_program,
         timing::years_as_slots,
@@ -107,9 +107,7 @@ pub fn create_and_add_stakes(
 
     let mut address_generator = AddressGenerator::new(&authorized.staker, &stake::program::id());
 
-    let stake_rent_reserve = genesis_config
-        .rent
-        .minimum_balance(StakeStateWithFlags::size_of());
+    let stake_rent_reserve = genesis_config.rent.minimum_balance(StakeStateV2::size_of());
 
     for unlock in unlocks {
         let lamports = unlock.amount(stakes_lamports);
@@ -195,9 +193,7 @@ mod tests {
             .iter()
             .all(|(_pubkey, account)| account.lamports <= granularity
                 || account.lamports - granularity
-                    <= genesis_config
-                        .rent
-                        .minimum_balance(StakeStateWithFlags::size_of())));
+                    <= genesis_config.rent.minimum_balance(StakeStateV2::size_of())));
     }
 
     //    #[ignore]
@@ -242,7 +238,7 @@ mod tests {
             ..Rent::default()
         };
 
-        let reserve = rent.minimum_balance(StakeStateWithFlags::size_of());
+        let reserve = rent.minimum_balance(StakeStateV2::size_of());
         let staker_reserve = rent.minimum_balance(0);
 
         // verify that a small remainder ends up in the last stake

+ 5 - 7
ledger-tool/src/main.rs

@@ -74,7 +74,7 @@ use {
         pubkey::Pubkey,
         rent::Rent,
         shred_version::compute_shred_version,
-        stake::{self, state::StakeStateWithFlags},
+        stake::{self, state::StakeStateV2},
         system_program,
         transaction::{
             MessageHash, SanitizedTransaction, SimpleAddressLoader, VersionedTransaction,
@@ -1293,7 +1293,7 @@ fn main() {
         .max(VoteState::get_rent_exempt_reserve(&rent))
         .to_string();
     let default_bootstrap_validator_stake_lamports = &sol_to_lamports(0.5)
-        .max(rent.minimum_balance(StakeStateWithFlags::size_of()))
+        .max(rent.minimum_balance(StakeStateV2::size_of()))
         .to_string();
     let default_graph_vote_account_mode = GraphVoteAccountMode::default();
 
@@ -2770,7 +2770,7 @@ fn main() {
                     value_t_or_exit!(arg_matches, "bootstrap_validator_lamports", u64);
                 let bootstrap_validator_stake_lamports =
                     value_t_or_exit!(arg_matches, "bootstrap_validator_stake_lamports", u64);
-                let minimum_stake_lamports = rent.minimum_balance(StakeStateWithFlags::size_of());
+                let minimum_stake_lamports = rent.minimum_balance(StakeStateV2::size_of());
                 if bootstrap_validator_stake_lamports < minimum_stake_lamports {
                     eprintln!(
                         "Error: insufficient --bootstrap-validator-stake-lamports. \
@@ -2998,9 +2998,7 @@ fn main() {
                                 .unwrap()
                                 .into_iter()
                             {
-                                if let Ok(StakeStateWithFlags::Stake(meta, stake, _)) =
-                                    account.state()
-                                {
+                                if let Ok(StakeStateV2::Stake(meta, stake, _)) = account.state() {
                                     if vote_accounts_to_destake
                                         .contains(&stake.delegation.voter_pubkey)
                                     {
@@ -3011,7 +3009,7 @@ fn main() {
                                             );
                                         }
                                         account
-                                            .set_state(&StakeStateWithFlags::Initialized(meta))
+                                            .set_state(&StakeStateV2::Initialized(meta))
                                             .unwrap();
                                         bank.store_account(&address, &account);
                                     }

+ 6 - 6
program-test/tests/warp.rs

@@ -18,7 +18,7 @@ use {
         signature::{Keypair, Signer},
         stake::{
             instruction as stake_instruction,
-            state::{Authorized, Lockup, StakeActivationStatus, StakeStateWithFlags},
+            state::{Authorized, Lockup, StakeActivationStatus, StakeStateV2},
         },
         system_instruction, system_program,
         sysvar::{
@@ -271,7 +271,7 @@ async fn stake_rewards_from_warp() {
         .expect("account exists")
         .unwrap();
 
-    let stake_state: StakeStateWithFlags = deserialize(&account.data).unwrap();
+    let stake_state: StakeStateV2 = deserialize(&account.data).unwrap();
     let stake_history: StakeHistory = deserialize(&stake_history_account.data).unwrap();
     let clock: Clock = deserialize(&clock_account.data).unwrap();
     let stake = stake_state.stake().unwrap();
@@ -387,7 +387,7 @@ async fn stake_rewards_filter_bench_core(num_stake_accounts: u64) {
         .expect("account exists")
         .unwrap();
 
-    let stake_state: StakeStateWithFlags = deserialize(&account.data).unwrap();
+    let stake_state: StakeStateV2 = deserialize(&account.data).unwrap();
     let stake_history: StakeHistory = deserialize(&stake_history_account.data).unwrap();
     let clock: Clock = deserialize(&clock_account.data).unwrap();
     let stake = stake_state.stake().unwrap();
@@ -409,7 +409,7 @@ async fn check_credits_observed(
         .await
         .unwrap()
         .unwrap();
-    let stake_state: StakeStateWithFlags = deserialize(&stake_account.data).unwrap();
+    let stake_state: StakeStateV2 = deserialize(&stake_account.data).unwrap();
     assert_eq!(
         stake_state.stake().unwrap().credits_observed,
         expected_credits
@@ -465,7 +465,7 @@ async fn stake_merge_immediately_after_activation() {
         .await
         .unwrap()
         .unwrap();
-    let stake_state: StakeStateWithFlags = deserialize(&stake_account.data).unwrap();
+    let stake_state: StakeStateV2 = deserialize(&stake_account.data).unwrap();
     assert_eq!(stake_state.stake().unwrap().credits_observed, 300);
     assert!(stake_account.lamports > stake_lamports);
 
@@ -476,7 +476,7 @@ async fn stake_merge_immediately_after_activation() {
         .await
         .unwrap()
         .unwrap();
-    let stake_state: StakeStateWithFlags = deserialize(&stake_account.data).unwrap();
+    let stake_state: StakeStateV2 = deserialize(&stake_account.data).unwrap();
     assert_eq!(stake_state.stake().unwrap().credits_observed, 300);
     assert_eq!(stake_account.lamports, stake_lamports);
 

File diff suppressed because it is too large
+ 143 - 174
programs/stake/src/stake_instruction.rs


+ 71 - 91
programs/stake/src/stake_state.rs

@@ -73,34 +73,28 @@ pub(crate) fn null_tracer() -> Option<impl Fn(&InflationPointCalculationEvent)>
 }
 
 // utility function, used by Stakes, tests
-pub fn from<T: ReadableAccount + StateMut<StakeStateWithFlags>>(
-    account: &T,
-) -> Option<StakeStateWithFlags> {
+pub fn from<T: ReadableAccount + StateMut<StakeStateV2>>(account: &T) -> Option<StakeStateV2> {
     account.state().ok()
 }
 
-pub fn stake_from<T: ReadableAccount + StateMut<StakeStateWithFlags>>(
-    account: &T,
-) -> Option<Stake> {
-    from(account).and_then(|state: StakeStateWithFlags| state.stake())
+pub fn stake_from<T: ReadableAccount + StateMut<StakeStateV2>>(account: &T) -> Option<Stake> {
+    from(account).and_then(|state: StakeStateV2| state.stake())
 }
 
 pub fn delegation_from(account: &AccountSharedData) -> Option<Delegation> {
-    from(account).and_then(|state: StakeStateWithFlags| state.delegation())
+    from(account).and_then(|state: StakeStateV2| state.delegation())
 }
 
 pub fn authorized_from(account: &AccountSharedData) -> Option<Authorized> {
-    from(account).and_then(|state: StakeStateWithFlags| state.authorized())
+    from(account).and_then(|state: StakeStateV2| state.authorized())
 }
 
-pub fn lockup_from<T: ReadableAccount + StateMut<StakeStateWithFlags>>(
-    account: &T,
-) -> Option<Lockup> {
-    from(account).and_then(|state: StakeStateWithFlags| state.lockup())
+pub fn lockup_from<T: ReadableAccount + StateMut<StakeStateV2>>(account: &T) -> Option<Lockup> {
+    from(account).and_then(|state: StakeStateV2| state.lockup())
 }
 
 pub fn meta_from(account: &AccountSharedData) -> Option<Meta> {
-    from(account).and_then(|state: StakeStateWithFlags| state.meta())
+    from(account).and_then(|state: StakeStateV2| state.meta())
 }
 
 pub(crate) fn new_warmup_cooldown_rate_epoch(invoke_context: &InvokeContext) -> Option<Epoch> {
@@ -476,13 +470,13 @@ pub fn initialize(
     lockup: &Lockup,
     rent: &Rent,
 ) -> Result<(), InstructionError> {
-    if stake_account.get_data().len() != StakeStateWithFlags::size_of() {
+    if stake_account.get_data().len() != StakeStateV2::size_of() {
         return Err(InstructionError::InvalidAccountData);
     }
-    if let StakeStateWithFlags::Uninitialized = stake_account.get_state()? {
+    if let StakeStateV2::Uninitialized = stake_account.get_state()? {
         let rent_exempt_reserve = rent.minimum_balance(stake_account.get_data().len());
         if stake_account.get_lamports() >= rent_exempt_reserve {
-            stake_account.set_state(&StakeStateWithFlags::Initialized(Meta {
+            stake_account.set_state(&StakeStateV2::Initialized(Meta {
                 rent_exempt_reserve,
                 authorized: *authorized,
                 lockup: *lockup,
@@ -508,7 +502,7 @@ pub fn authorize(
     custodian: Option<&Pubkey>,
 ) -> Result<(), InstructionError> {
     match stake_account.get_state()? {
-        StakeStateWithFlags::Stake(mut meta, stake, stake_flags) => {
+        StakeStateV2::Stake(mut meta, stake, stake_flags) => {
             meta.authorized.authorize(
                 signers,
                 new_authority,
@@ -519,9 +513,9 @@ pub fn authorize(
                     None
                 },
             )?;
-            stake_account.set_state(&StakeStateWithFlags::Stake(meta, stake, stake_flags))
+            stake_account.set_state(&StakeStateV2::Stake(meta, stake, stake_flags))
         }
-        StakeStateWithFlags::Initialized(mut meta) => {
+        StakeStateV2::Initialized(mut meta) => {
             meta.authorized.authorize(
                 signers,
                 new_authority,
@@ -532,7 +526,7 @@ pub fn authorize(
                     None
                 },
             )?;
-            stake_account.set_state(&StakeStateWithFlags::Initialized(meta))
+            stake_account.set_state(&StakeStateV2::Initialized(meta))
         }
         _ => Err(InstructionError::InvalidAccountData),
     }
@@ -599,7 +593,7 @@ pub fn delegate(
     let mut stake_account = instruction_context
         .try_borrow_instruction_account(transaction_context, stake_account_index)?;
     match stake_account.get_state()? {
-        StakeStateWithFlags::Initialized(meta) => {
+        StakeStateV2::Initialized(meta) => {
             meta.authorized.check(signers, StakeAuthorize::Staker)?;
             let ValidatedDelegatedInfo { stake_amount } =
                 validate_delegated_amount(&stake_account, &meta, feature_set)?;
@@ -609,13 +603,9 @@ pub fn delegate(
                 &vote_state?.convert_to_current(),
                 clock.epoch,
             );
-            stake_account.set_state(&StakeStateWithFlags::Stake(
-                meta,
-                stake,
-                StakeFlags::empty(),
-            ))
+            stake_account.set_state(&StakeStateV2::Stake(meta, stake, StakeFlags::empty()))
         }
-        StakeStateWithFlags::Stake(meta, mut stake, stake_flags) => {
+        StakeStateV2::Stake(meta, mut stake, stake_flags) => {
             meta.authorized.check(signers, StakeAuthorize::Staker)?;
             let ValidatedDelegatedInfo { stake_amount } =
                 validate_delegated_amount(&stake_account, &meta, feature_set)?;
@@ -628,7 +618,7 @@ pub fn delegate(
                 clock,
                 stake_history,
             )?;
-            stake_account.set_state(&StakeStateWithFlags::Stake(meta, stake, stake_flags))
+            stake_account.set_state(&StakeStateV2::Stake(meta, stake, stake_flags))
         }
         _ => Err(InstructionError::InvalidAccountData),
     }
@@ -639,11 +629,11 @@ pub fn deactivate(
     clock: &Clock,
     signers: &HashSet<Pubkey>,
 ) -> Result<(), InstructionError> {
-    if let StakeStateWithFlags::Stake(meta, mut stake, stake_flags) = stake_account.get_state()? {
+    if let StakeStateV2::Stake(meta, mut stake, stake_flags) = stake_account.get_state()? {
         meta.authorized.check(signers, StakeAuthorize::Staker)?;
         stake.deactivate(clock.epoch)?;
 
-        stake_account.set_state(&StakeStateWithFlags::Stake(meta, stake, stake_flags))
+        stake_account.set_state(&StakeStateV2::Stake(meta, stake, stake_flags))
     } else {
         Err(InstructionError::InvalidAccountData)
     }
@@ -656,13 +646,13 @@ pub fn set_lockup(
     clock: &Clock,
 ) -> Result<(), InstructionError> {
     match stake_account.get_state()? {
-        StakeStateWithFlags::Initialized(mut meta) => {
+        StakeStateV2::Initialized(mut meta) => {
             meta.set_lockup(lockup, signers, clock)?;
-            stake_account.set_state(&StakeStateWithFlags::Initialized(meta))
+            stake_account.set_state(&StakeStateV2::Initialized(meta))
         }
-        StakeStateWithFlags::Stake(mut meta, stake, stake_flags) => {
+        StakeStateV2::Stake(mut meta, stake, stake_flags) => {
             meta.set_lockup(lockup, signers, clock)?;
-            stake_account.set_state(&StakeStateWithFlags::Stake(meta, stake, stake_flags))
+            stake_account.set_state(&StakeStateV2::Stake(meta, stake, stake_flags))
         }
         _ => Err(InstructionError::InvalidAccountData),
     }
@@ -682,10 +672,10 @@ pub fn split(
     if *split.get_owner() != id() {
         return Err(InstructionError::IncorrectProgramId);
     }
-    if split.get_data().len() != StakeStateWithFlags::size_of() {
+    if split.get_data().len() != StakeStateV2::size_of() {
         return Err(InstructionError::InvalidAccountData);
     }
-    if !matches!(split.get_state()?, StakeStateWithFlags::Uninitialized) {
+    if !matches!(split.get_state()?, StakeStateV2::Uninitialized) {
         return Err(InstructionError::InvalidAccountData);
     }
     let split_lamport_balance = split.get_lamports();
@@ -699,7 +689,7 @@ pub fn split(
     drop(stake_account);
 
     match stake_state {
-        StakeStateWithFlags::Stake(meta, mut stake, stake_flags) => {
+        StakeStateV2::Stake(meta, mut stake, stake_flags) => {
             meta.authorized.check(signers, StakeAuthorize::Staker)?;
             let minimum_delegation = crate::get_minimum_delegation(&invoke_context.feature_set);
             let validated_split_info = validate_split_amount(
@@ -769,17 +759,13 @@ pub fn split(
 
             let mut stake_account = instruction_context
                 .try_borrow_instruction_account(transaction_context, stake_account_index)?;
-            stake_account.set_state(&StakeStateWithFlags::Stake(meta, stake, stake_flags))?;
+            stake_account.set_state(&StakeStateV2::Stake(meta, stake, stake_flags))?;
             drop(stake_account);
             let mut split = instruction_context
                 .try_borrow_instruction_account(transaction_context, split_index)?;
-            split.set_state(&StakeStateWithFlags::Stake(
-                split_meta,
-                split_stake,
-                stake_flags,
-            ))?;
+            split.set_state(&StakeStateV2::Stake(split_meta, split_stake, stake_flags))?;
         }
-        StakeStateWithFlags::Initialized(meta) => {
+        StakeStateV2::Initialized(meta) => {
             meta.authorized.check(signers, StakeAuthorize::Staker)?;
             let validated_split_info = validate_split_amount(
                 invoke_context,
@@ -796,9 +782,9 @@ pub fn split(
             split_meta.rent_exempt_reserve = validated_split_info.destination_rent_exempt_reserve;
             let mut split = instruction_context
                 .try_borrow_instruction_account(transaction_context, split_index)?;
-            split.set_state(&StakeStateWithFlags::Initialized(split_meta))?;
+            split.set_state(&StakeStateV2::Initialized(split_meta))?;
         }
-        StakeStateWithFlags::Uninitialized => {
+        StakeStateV2::Uninitialized => {
             let stake_pubkey = transaction_context.get_key_of_account_at_index(
                 instruction_context
                     .get_index_of_instruction_account_in_transaction(stake_account_index)?,
@@ -814,7 +800,7 @@ pub fn split(
     let mut stake_account = instruction_context
         .try_borrow_instruction_account(transaction_context, stake_account_index)?;
     if lamports == stake_account.get_lamports() {
-        stake_account.set_state(&StakeStateWithFlags::Uninitialized)?;
+        stake_account.set_state(&StakeStateV2::Uninitialized)?;
     }
     drop(stake_account);
 
@@ -884,7 +870,7 @@ pub fn merge(
     }
 
     // Source is about to be drained, deinitialize its state
-    source_account.set_state(&StakeStateWithFlags::Uninitialized)?;
+    source_account.set_state(&StakeStateV2::Uninitialized)?;
 
     // Drain the source stake account
     let lamports = source_account.get_lamports();
@@ -916,18 +902,18 @@ pub fn redelegate(
         );
         return Err(InstructionError::IncorrectProgramId);
     }
-    if uninitialized_stake_account.get_data().len() != StakeStateWithFlags::size_of() {
+    if uninitialized_stake_account.get_data().len() != StakeStateV2::size_of() {
         ic_msg!(
             invoke_context,
             "expected uninitialized stake account data len to be {}, not {}",
-            StakeStateWithFlags::size_of(),
+            StakeStateV2::size_of(),
             uninitialized_stake_account.get_data().len()
         );
         return Err(InstructionError::InvalidAccountData);
     }
     if !matches!(
         uninitialized_stake_account.get_state()?,
-        StakeStateWithFlags::Uninitialized
+        StakeStateV2::Uninitialized
     ) {
         ic_msg!(
             invoke_context,
@@ -952,7 +938,7 @@ pub fn redelegate(
     let vote_state = vote_account.get_state::<VoteStateVersions>()?;
 
     let (stake_meta, effective_stake) =
-        if let StakeStateWithFlags::Stake(meta, stake, _stake_flags) = stake_account.get_state()? {
+        if let StakeStateV2::Stake(meta, stake, _stake_flags) = stake_account.get_state()? {
             let stake_history = invoke_context.get_sysvar_cache().get_stake_history()?;
             let status = stake.delegation.stake_activating_and_deactivating(
                 clock.epoch,
@@ -1001,7 +987,7 @@ pub fn redelegate(
         &uninitialized_stake_meta,
         &invoke_context.feature_set,
     )?;
-    uninitialized_stake_account.set_state(&StakeStateWithFlags::Stake(
+    uninitialized_stake_account.set_state(&StakeStateV2::Stake(
         uninitialized_stake_meta,
         new_stake(
             stake_amount,
@@ -1041,7 +1027,7 @@ pub fn withdraw(
     let mut stake_account = instruction_context
         .try_borrow_instruction_account(transaction_context, stake_account_index)?;
     let (lockup, reserve, is_staked) = match stake_account.get_state()? {
-        StakeStateWithFlags::Stake(meta, stake, _stake_flag) => {
+        StakeStateV2::Stake(meta, stake, _stake_flag) => {
             meta.authorized
                 .check(&signers, StakeAuthorize::Withdrawer)?;
             // if we have a deactivation epoch and we're in cooldown
@@ -1059,13 +1045,13 @@ pub fn withdraw(
             let staked_and_reserve = checked_add(staked, meta.rent_exempt_reserve)?;
             (meta.lockup, staked_and_reserve, staked != 0)
         }
-        StakeStateWithFlags::Initialized(meta) => {
+        StakeStateV2::Initialized(meta) => {
             meta.authorized
                 .check(&signers, StakeAuthorize::Withdrawer)?;
             // stake accounts must have a balance >= rent_exempt_reserve
             (meta.lockup, meta.rent_exempt_reserve, false)
         }
-        StakeStateWithFlags::Uninitialized => {
+        StakeStateV2::Uninitialized => {
             if !signers.contains(stake_account.get_key()) {
                 return Err(InstructionError::MissingRequiredSignature);
             }
@@ -1111,7 +1097,7 @@ pub fn withdraw(
 
     // Deinitialize state upon zero balance
     if lamports == stake_account.get_lamports() {
-        stake_account.set_state(&StakeStateWithFlags::Uninitialized)?;
+        stake_account.set_state(&StakeStateV2::Uninitialized)?;
     }
 
     stake_account.checked_sub_lamports(lamports)?;
@@ -1156,7 +1142,7 @@ pub(crate) fn deactivate_delinquent(
         return Err(StakeError::InsufficientReferenceVotes.into());
     }
 
-    if let StakeStateWithFlags::Stake(meta, mut stake, stake_flags) = stake_account.get_state()? {
+    if let StakeStateV2::Stake(meta, mut stake, stake_flags) = stake_account.get_state()? {
         if stake.delegation.voter_pubkey != *delinquent_vote_account_pubkey {
             return Err(StakeError::VoteAddressMismatch.into());
         }
@@ -1165,7 +1151,7 @@ pub(crate) fn deactivate_delinquent(
         // voted in the last `MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION`
         if eligible_for_deactivate_delinquent(&delinquent_vote_state.epoch_credits, current_epoch) {
             stake.deactivate(current_epoch)?;
-            stake_account.set_state(&StakeStateWithFlags::Stake(meta, stake, stake_flags))
+            stake_account.set_state(&StakeStateV2::Stake(meta, stake, stake_flags))
         } else {
             Err(StakeError::MinimumDelinquentEpochsForDeactivationNotMet.into())
         }
@@ -1326,13 +1312,13 @@ impl MergeKind {
 
     fn get_if_mergeable(
         invoke_context: &InvokeContext,
-        stake_state: &StakeStateWithFlags,
+        stake_state: &StakeStateV2,
         stake_lamports: u64,
         clock: &Clock,
         stake_history: &StakeHistory,
     ) -> Result<Self, InstructionError> {
         match stake_state {
-            StakeStateWithFlags::Stake(meta, stake, stake_flags) => {
+            StakeStateV2::Stake(meta, stake, stake_flags) => {
                 // stake must not be in a transient state. Transient here meaning
                 // activating or deactivating with non-zero effective stake.
                 let status = stake.delegation.stake_activating_and_deactivating(
@@ -1352,7 +1338,7 @@ impl MergeKind {
                     }
                 }
             }
-            StakeStateWithFlags::Initialized(meta) => {
+            StakeStateV2::Initialized(meta) => {
                 Ok(Self::Inactive(*meta, stake_lamports, StakeFlags::empty()))
             }
             _ => Err(InstructionError::InvalidAccountData),
@@ -1426,7 +1412,7 @@ impl MergeKind {
         invoke_context: &InvokeContext,
         source: Self,
         clock: &Clock,
-    ) -> Result<Option<StakeStateWithFlags>, InstructionError> {
+    ) -> Result<Option<StakeStateV2>, InstructionError> {
         Self::metas_can_merge(invoke_context, self.meta(), source.meta(), clock)?;
         self.active_stake()
             .zip(source.active_stake())
@@ -1453,7 +1439,7 @@ impl MergeKind {
                 Self::Inactive(_, source_lamports, source_stake_flags),
             ) => {
                 stake.delegation.stake = checked_add(stake.delegation.stake, source_lamports)?;
-                Some(StakeStateWithFlags::Stake(
+                Some(StakeStateV2::Stake(
                     meta,
                     stake,
                     stake_flags.union(source_stake_flags),
@@ -1473,7 +1459,7 @@ impl MergeKind {
                     source_lamports,
                     source_stake.credits_observed,
                 )?;
-                Some(StakeStateWithFlags::Stake(
+                Some(StakeStateV2::Stake(
                     meta,
                     stake,
                     stake_flags.union(source_stake_flags),
@@ -1490,7 +1476,7 @@ impl MergeKind {
                     source_stake.delegation.stake,
                     source_stake.credits_observed,
                 )?;
-                Some(StakeStateWithFlags::Stake(meta, stake, StakeFlags::empty()))
+                Some(StakeStateV2::Stake(meta, stake, StakeFlags::empty()))
             }
             _ => return Err(StakeError::MergeMismatch.into()),
         };
@@ -1569,7 +1555,7 @@ fn stake_weighted_credits_observed(
 #[doc(hidden)]
 pub fn redeem_rewards(
     rewarded_epoch: Epoch,
-    stake_state: StakeStateWithFlags,
+    stake_state: StakeStateV2,
     stake_account: &mut AccountSharedData,
     vote_state: &VoteState,
     point_value: &PointValue,
@@ -1577,7 +1563,7 @@ pub fn redeem_rewards(
     inflation_point_calc_tracer: Option<impl Fn(&InflationPointCalculationEvent)>,
     new_rate_activation_epoch: Option<Epoch>,
 ) -> Result<(u64, u64), InstructionError> {
-    if let StakeStateWithFlags::Stake(meta, mut stake, stake_flags) = stake_state {
+    if let StakeStateV2::Stake(meta, mut stake, stake_flags) = stake_state {
         if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer.as_ref() {
             inflation_point_calc_tracer(
                 &InflationPointCalculationEvent::EffectiveStakeAtRewardedEpoch(stake.stake(
@@ -1604,7 +1590,7 @@ pub fn redeem_rewards(
             new_rate_activation_epoch,
         ) {
             stake_account.checked_add_lamports(stakers_reward)?;
-            stake_account.set_state(&StakeStateWithFlags::Stake(meta, stake, stake_flags))?;
+            stake_account.set_state(&StakeStateV2::Stake(meta, stake, stake_flags))?;
 
             Ok((stakers_reward, voters_reward))
         } else {
@@ -1618,12 +1604,12 @@ pub fn redeem_rewards(
 // utility function, used by runtime
 #[doc(hidden)]
 pub fn calculate_points(
-    stake_state: &StakeStateWithFlags,
+    stake_state: &StakeStateV2,
     vote_state: &VoteState,
     stake_history: Option<&StakeHistory>,
     new_rate_activation_epoch: Option<Epoch>,
 ) -> Result<u128, InstructionError> {
-    if let StakeStateWithFlags::Stake(_meta, stake, _stake_flags) = stake_state {
+    if let StakeStateV2::Stake(_meta, stake, _stake_flags) = stake_state {
         Ok(calculate_stake_points(
             stake,
             vote_state,
@@ -1692,7 +1678,7 @@ pub fn create_lockup_stake_account(
     rent: &Rent,
     lamports: u64,
 ) -> AccountSharedData {
-    let mut stake_account = AccountSharedData::new(lamports, StakeStateWithFlags::size_of(), &id());
+    let mut stake_account = AccountSharedData::new(lamports, StakeStateV2::size_of(), &id());
 
     let rent_exempt_reserve = rent.minimum_balance(stake_account.data().len());
     assert!(
@@ -1701,7 +1687,7 @@ pub fn create_lockup_stake_account(
     );
 
     stake_account
-        .set_state(&StakeStateWithFlags::Initialized(Meta {
+        .set_state(&StakeStateV2::Initialized(Meta {
             authorized: *authorized,
             lockup: *lockup,
             rent_exempt_reserve,
@@ -1756,14 +1742,14 @@ fn do_create_account(
     lamports: u64,
     activation_epoch: Epoch,
 ) -> AccountSharedData {
-    let mut stake_account = AccountSharedData::new(lamports, StakeStateWithFlags::size_of(), &id());
+    let mut stake_account = AccountSharedData::new(lamports, StakeStateV2::size_of(), &id());
 
     let vote_state = vote_state::from(vote_account).expect("vote_state");
 
     let rent_exempt_reserve = rent.minimum_balance(stake_account.data().len());
 
     stake_account
-        .set_state(&StakeStateWithFlags::Stake(
+        .set_state(&StakeStateV2::Stake(
             Meta {
                 authorized: Authorized::auto(authorized),
                 rent_exempt_reserve,
@@ -1939,10 +1925,10 @@ mod tests {
 
     #[test]
     fn test_stake_state_stake_from_fail() {
-        let mut stake_account = AccountSharedData::new(0, StakeStateWithFlags::size_of(), &id());
+        let mut stake_account = AccountSharedData::new(0, StakeStateV2::size_of(), &id());
 
         stake_account
-            .set_state(&StakeStateWithFlags::default())
+            .set_state(&StakeStateV2::default())
             .expect("set_state");
 
         assert_eq!(stake_from(&stake_account), None);
@@ -2999,7 +2985,7 @@ mod tests {
     #[ignore]
     #[should_panic]
     fn test_dbg_stake_minimum_balance() {
-        let minimum_balance = Rent::default().minimum_balance(StakeStateWithFlags::size_of());
+        let minimum_balance = Rent::default().minimum_balance(StakeStateV2::size_of());
         panic!(
             "stake minimum_balance: {} lamports, {} SOL",
             minimum_balance,
@@ -3244,7 +3230,7 @@ mod tests {
         let authority_pubkey = Pubkey::new_unique();
         let initial_lamports = 4242424242;
         let rent = Rent::default();
-        let rent_exempt_reserve = rent.minimum_balance(StakeStateWithFlags::size_of());
+        let rent_exempt_reserve = rent.minimum_balance(StakeStateV2::size_of());
         let stake_lamports = rent_exempt_reserve + initial_lamports;
         let new_rate_activation_epoch = Some(0);
 
@@ -3254,8 +3240,8 @@ mod tests {
         };
         let mut stake_account = AccountSharedData::new_data_with_space(
             stake_lamports,
-            &StakeStateWithFlags::Uninitialized,
-            StakeStateWithFlags::size_of(),
+            &StakeStateV2::Uninitialized,
+            StakeStateV2::size_of(),
             &id(),
         )
         .expect("stake_account");
@@ -3276,9 +3262,7 @@ mod tests {
         );
 
         // RewardsPool state fails
-        stake_account
-            .set_state(&StakeStateWithFlags::RewardsPool)
-            .unwrap();
+        stake_account.set_state(&StakeStateV2::RewardsPool).unwrap();
         assert_eq!(
             MergeKind::get_if_mergeable(
                 &invoke_context,
@@ -3293,7 +3277,7 @@ mod tests {
 
         // Initialized state succeeds
         stake_account
-            .set_state(&StakeStateWithFlags::Initialized(meta))
+            .set_state(&StakeStateV2::Initialized(meta))
             .unwrap();
         assert_eq!(
             MergeKind::get_if_mergeable(
@@ -3341,11 +3325,7 @@ mod tests {
             ..Stake::default()
         };
         stake_account
-            .set_state(&StakeStateWithFlags::Stake(
-                meta,
-                stake,
-                StakeFlags::empty(),
-            ))
+            .set_state(&StakeStateV2::Stake(meta, stake, StakeFlags::empty()))
             .unwrap();
         // activation_epoch succeeds
         assert_eq!(

+ 2 - 2
rpc/src/rpc.rs

@@ -69,7 +69,7 @@ use {
         message::SanitizedMessage,
         pubkey::{Pubkey, PUBKEY_BYTES},
         signature::{Keypair, Signature, Signer},
-        stake::state::{StakeActivationStatus, StakeStateWithFlags},
+        stake::state::{StakeActivationStatus, StakeStateV2},
         stake_history::StakeHistory,
         system_instruction,
         sysvar::stake_history,
@@ -1732,7 +1732,7 @@ impl JsonRpcRequestProcessor {
         let stake_account = bank
             .get_account(pubkey)
             .ok_or_else(|| Error::invalid_params("Invalid param: account not found".to_string()))?;
-        let stake_state: StakeStateWithFlags = stake_account
+        let stake_state: StakeStateV2 = stake_account
             .state()
             .map_err(|_| Error::invalid_params("Invalid param: not a stake account".to_string()))?;
         let delegation = stake_state.delegation();

+ 2 - 2
rpc/src/rpc_pubsub.rs

@@ -635,7 +635,7 @@ mod tests {
             signature::{Keypair, Signer},
             stake::{
                 self, instruction as stake_instruction,
-                state::{Authorized, Lockup, StakeAuthorize, StakeStateWithFlags},
+                state::{Authorized, Lockup, StakeAuthorize, StakeStateV2},
             },
             system_instruction, system_program, system_transaction,
             transaction::{self, Transaction},
@@ -907,7 +907,7 @@ mod tests {
         let balance = {
             let bank = bank_forks.read().unwrap().working_bank();
             let rent = &bank.rent_collector().rent;
-            rent.minimum_balance(StakeStateWithFlags::size_of())
+            rent.minimum_balance(StakeStateV2::size_of())
         };
 
         let tx = system_transaction::transfer(&alice, &from.pubkey(), balance, blockhash);

+ 3 - 3
runtime/src/bank.rs

@@ -176,7 +176,7 @@ use {
         },
     },
     solana_stake_program::stake_state::{
-        self, InflationPointCalculationEvent, PointValue, StakeStateWithFlags,
+        self, InflationPointCalculationEvent, PointValue, StakeStateV2,
     },
     solana_system_program::{get_system_account_kind, SystemAccountKind},
     solana_vote_program::vote_state::VoteState,
@@ -3090,7 +3090,7 @@ impl Bank {
 
                     let delegation = stake_account.delegation();
                     let (mut stake_account, stake_state) =
-                        <(AccountSharedData, StakeStateWithFlags)>::from(stake_account);
+                        <(AccountSharedData, StakeStateV2)>::from(stake_account);
                     let vote_pubkey = delegation.voter_pubkey;
                     let Some(vote_account) = get_vote_account(&vote_pubkey) else {
                         return None;
@@ -3221,7 +3221,7 @@ impl Bank {
                         }
                     });
                     let (mut stake_account, stake_state) =
-                        <(AccountSharedData, StakeStateWithFlags)>::from(stake_account);
+                        <(AccountSharedData, StakeStateV2)>::from(stake_account);
                     let redeemed = stake_state::redeem_rewards(
                         rewarded_epoch,
                         stake_state,

+ 2 - 2
runtime/src/bank/tests.rs

@@ -98,7 +98,7 @@ use {
         },
         transaction_context::{TransactionAccount, TransactionContext},
     },
-    solana_stake_program::stake_state::{self, StakeStateWithFlags},
+    solana_stake_program::stake_state::{self, StakeStateV2},
     solana_vote_program::{
         vote_instruction,
         vote_state::{
@@ -4373,7 +4373,7 @@ fn test_bank_cloned_stake_delegations() {
     let (vote_balance, stake_balance) = {
         let rent = &bank.rent_collector().rent;
         let vote_rent_exempt_reserve = rent.minimum_balance(VoteState::size_of());
-        let stake_rent_exempt_reserve = rent.minimum_balance(StakeStateWithFlags::size_of());
+        let stake_rent_exempt_reserve = rent.minimum_balance(StakeStateV2::size_of());
         let minimum_delegation = solana_stake_program::get_minimum_delegation(&bank.feature_set);
         (
             vote_rent_exempt_reserve,

+ 2 - 2
runtime/src/genesis_utils.rs

@@ -10,7 +10,7 @@ use {
         pubkey::Pubkey,
         rent::Rent,
         signature::{Keypair, Signer},
-        stake::state::StakeStateWithFlags,
+        stake::state::StakeStateV2,
         system_program,
     },
     solana_stake_program::stake_state,
@@ -23,7 +23,7 @@ const VALIDATOR_LAMPORTS: u64 = 42;
 
 // fun fact: rustc is very close to make this const fn.
 pub fn bootstrap_validator_stake_lamports() -> u64 {
-    Rent::default().minimum_balance(StakeStateWithFlags::size_of())
+    Rent::default().minimum_balance(StakeStateV2::size_of())
 }
 
 // Number of lamports automatically used for genesis accounts

+ 5 - 5
runtime/src/non_circulating_supply.rs

@@ -5,7 +5,7 @@ use {
     solana_sdk::{
         account::ReadableAccount,
         pubkey::Pubkey,
-        stake::{self, state::StakeStateWithFlags},
+        stake::{self, state::StakeStateV2},
     },
     solana_stake_program::stake_state,
     std::{collections::HashSet, sync::Arc},
@@ -51,14 +51,14 @@ pub fn calculate_non_circulating_supply(bank: &Arc<Bank>) -> ScanResult<NonCircu
     for (pubkey, account) in stake_accounts.iter() {
         let stake_account = stake_state::from(account).unwrap_or_default();
         match stake_account {
-            StakeStateWithFlags::Initialized(meta) => {
+            StakeStateV2::Initialized(meta) => {
                 if meta.lockup.is_in_force(&clock, None)
                     || withdraw_authority_list.contains(&meta.authorized.withdrawer)
                 {
                     non_circulating_accounts_set.insert(*pubkey);
                 }
             }
-            StakeStateWithFlags::Stake(meta, _stake, _stake_flags) => {
+            StakeStateV2::Stake(meta, _stake, _stake_flags) => {
                 if meta.lockup.is_in_force(&clock, None)
                     || withdraw_authority_list.contains(&meta.authorized.withdrawer)
                 {
@@ -262,8 +262,8 @@ mod tests {
             };
             let stake_account = Account::new_data_with_space(
                 balance,
-                &StakeStateWithFlags::Initialized(meta),
-                StakeStateWithFlags::size_of(),
+                &StakeStateV2::Initialized(meta),
+                StakeStateV2::size_of(),
                 &stake::program::id(),
             )
             .unwrap();

+ 7 - 7
runtime/src/stake_account.rs

@@ -6,7 +6,7 @@ use {
         account_utils::StateMut,
         instruction::InstructionError,
         pubkey::Pubkey,
-        stake::state::{Delegation, StakeStateWithFlags},
+        stake::state::{Delegation, StakeStateV2},
     },
     std::marker::PhantomData,
     thiserror::Error,
@@ -19,7 +19,7 @@ use {
 #[derive(Clone, Debug, Default)]
 pub struct StakeAccount<T> {
     account: AccountSharedData,
-    stake_state: StakeStateWithFlags,
+    stake_state: StakeStateV2,
     _phantom: PhantomData<T>,
 }
 
@@ -29,7 +29,7 @@ pub enum Error {
     #[error(transparent)]
     InstructionError(#[from] InstructionError),
     #[error("Invalid delegation: {0:?}")]
-    InvalidDelegation(Box<StakeStateWithFlags>),
+    InvalidDelegation(Box<StakeStateV2>),
     #[error("Invalid stake account owner: {0}")]
     InvalidOwner(/*owner:*/ Pubkey),
 }
@@ -41,7 +41,7 @@ impl<T> StakeAccount<T> {
     }
 
     #[inline]
-    pub(crate) fn stake_state(&self) -> &StakeStateWithFlags {
+    pub(crate) fn stake_state(&self) -> &StakeStateV2 {
         &self.stake_state
     }
 }
@@ -61,7 +61,7 @@ impl TryFrom<AccountSharedData> for StakeAccount<Delegation> {
         if account.owner() != &solana_stake_program::id() {
             return Err(Error::InvalidOwner(*account.owner()));
         }
-        let stake_state: StakeStateWithFlags = account.state()?;
+        let stake_state: StakeStateV2 = account.state()?;
         if stake_state.delegation().is_none() {
             return Err(Error::InvalidDelegation(Box::new(stake_state)));
         }
@@ -73,7 +73,7 @@ impl TryFrom<AccountSharedData> for StakeAccount<Delegation> {
     }
 }
 
-impl<T> From<StakeAccount<T>> for (AccountSharedData, StakeStateWithFlags) {
+impl<T> From<StakeAccount<T>> for (AccountSharedData, StakeStateV2) {
     #[inline]
     fn from(stake_account: StakeAccount<T>) -> Self {
         (stake_account.account, stake_account.stake_state)
@@ -102,7 +102,7 @@ impl AbiExample for StakeAccount<Delegation> {
             },
         };
         let stake_state =
-            StakeStateWithFlags::Stake(Meta::example(), Stake::example(), StakeFlags::example());
+            StakeStateV2::Stake(Meta::example(), Stake::example(), StakeFlags::example());
         let mut account = Account::example();
         account.data.resize(200, 0u8);
         account.owner = solana_stake_program::id();

+ 1 - 1
runtime/src/stakes.rs

@@ -179,7 +179,7 @@ impl StakesCache {
 /// [`Stakes<Delegation>`] is equivalent to the old code and is used for backward
 /// compatibility in [`crate::bank::BankFieldsToDeserialize`].
 /// But banks cache [`Stakes<StakeAccount>`] which includes the entire stake
-/// account and StakeStateWithFlags deserialized from the account. Doing so, will remove
+/// account and StakeStateV2 deserialized from the account. Doing so, will remove
 /// the need to load the stake account from accounts-db when working with
 /// stake-delegations.
 #[derive(Default, Clone, PartialEq, Debug, Deserialize, Serialize, AbiExample)]

+ 8 - 8
runtime/tests/stake.rs

@@ -19,7 +19,7 @@ use {
         signature::{Keypair, Signer},
         stake::{
             self, instruction as stake_instruction,
-            state::{Authorized, Lockup, StakeStateWithFlags},
+            state::{Authorized, Lockup, StakeStateV2},
         },
         sysvar::{self, stake_history::StakeHistory},
     },
@@ -145,7 +145,7 @@ fn test_stake_create_and_split_single_signature() {
 
     let lamports = {
         let rent = &bank.rent_collector().rent;
-        let rent_exempt_reserve = rent.minimum_balance(StakeStateWithFlags::size_of());
+        let rent_exempt_reserve = rent.minimum_balance(StakeStateV2::size_of());
         let minimum_delegation = solana_stake_program::get_minimum_delegation(&bank.feature_set);
         2 * (rent_exempt_reserve + minimum_delegation)
     };
@@ -221,7 +221,7 @@ fn test_stake_create_and_split_to_existing_system_account() {
 
     let lamports = {
         let rent = &bank.rent_collector().rent;
-        let rent_exempt_reserve = rent.minimum_balance(StakeStateWithFlags::size_of());
+        let rent_exempt_reserve = rent.minimum_balance(StakeStateV2::size_of());
         let minimum_delegation = solana_stake_program::get_minimum_delegation(&bank.feature_set);
         2 * (rent_exempt_reserve + minimum_delegation)
     };
@@ -314,7 +314,7 @@ fn test_stake_account_lifetime() {
         let rent = &bank.rent_collector().rent;
         (
             rent.minimum_balance(VoteState::size_of()),
-            rent.minimum_balance(StakeStateWithFlags::size_of()),
+            rent.minimum_balance(StakeStateV2::size_of()),
             solana_stake_program::get_minimum_delegation(&bank.feature_set),
         )
     };
@@ -367,7 +367,7 @@ fn test_stake_account_lifetime() {
     // Test that correct lamports are staked
     let account = bank.get_account(&stake_pubkey).expect("account not found");
     let stake_state = account.state().expect("couldn't unpack account data");
-    if let StakeStateWithFlags::Stake(_meta, stake, _stake_flags) = stake_state {
+    if let StakeStateV2::Stake(_meta, stake, _stake_flags) = stake_state {
         assert_eq!(stake.delegation.stake, stake_starting_delegation,);
     } else {
         panic!("wrong account type found")
@@ -391,7 +391,7 @@ fn test_stake_account_lifetime() {
     // Test that lamports are still staked
     let account = bank.get_account(&stake_pubkey).expect("account not found");
     let stake_state = account.state().expect("couldn't unpack account data");
-    if let StakeStateWithFlags::Stake(_meta, stake, _stake_flags) = stake_state {
+    if let StakeStateV2::Stake(_meta, stake, _stake_flags) = stake_state {
         assert_eq!(stake.delegation.stake, stake_starting_delegation,);
     } else {
         panic!("wrong account type found")
@@ -615,7 +615,7 @@ fn test_create_stake_account_from_seed() {
     let authorized = Authorized::auto(&mint_pubkey);
     let (balance, delegation) = {
         let rent = &bank.rent_collector().rent;
-        let rent_exempt_reserve = rent.minimum_balance(StakeStateWithFlags::size_of());
+        let rent_exempt_reserve = rent.minimum_balance(StakeStateV2::size_of());
         let minimum_delegation = solana_stake_program::get_minimum_delegation(&bank.feature_set);
         (rent_exempt_reserve + minimum_delegation, minimum_delegation)
     };
@@ -641,7 +641,7 @@ fn test_create_stake_account_from_seed() {
     // Test that correct lamports are staked
     let account = bank.get_account(&stake_pubkey).expect("account not found");
     let stake_state = account.state().expect("couldn't unpack account data");
-    if let StakeStateWithFlags::Stake(_meta, stake, _) = stake_state {
+    if let StakeStateV2::Stake(_meta, stake, _) = stake_state {
         assert_eq!(stake.delegation.stake, delegation);
     } else {
         panic!("wrong account type found")

+ 9 - 12
sdk/program/src/stake/instruction.rs

@@ -8,7 +8,7 @@ use {
         pubkey::Pubkey,
         stake::{
             program::id,
-            state::{Authorized, Lockup, StakeAuthorize, StakeStateWithFlags},
+            state::{Authorized, Lockup, StakeAuthorize, StakeStateV2},
         },
         system_instruction, sysvar,
     },
@@ -364,7 +364,7 @@ pub fn create_account_with_seed(
             base,
             seed,
             lamports,
-            StakeStateWithFlags::size_of() as u64,
+            StakeStateV2::size_of() as u64,
             &id(),
         ),
         initialize(stake_pubkey, authorized, lockup),
@@ -383,7 +383,7 @@ pub fn create_account(
             from_pubkey,
             stake_pubkey,
             lamports,
-            StakeStateWithFlags::size_of() as u64,
+            StakeStateV2::size_of() as u64,
             &id(),
         ),
         initialize(stake_pubkey, authorized, lockup),
@@ -405,7 +405,7 @@ pub fn create_account_with_seed_checked(
             base,
             seed,
             lamports,
-            StakeStateWithFlags::size_of() as u64,
+            StakeStateV2::size_of() as u64,
             &id(),
         ),
         initialize_checked(stake_pubkey, authorized),
@@ -423,7 +423,7 @@ pub fn create_account_checked(
             from_pubkey,
             stake_pubkey,
             lamports,
-            StakeStateWithFlags::size_of() as u64,
+            StakeStateV2::size_of() as u64,
             &id(),
         ),
         initialize_checked(stake_pubkey, authorized),
@@ -452,7 +452,7 @@ pub fn split(
     split_stake_pubkey: &Pubkey,
 ) -> Vec<Instruction> {
     vec![
-        system_instruction::allocate(split_stake_pubkey, StakeStateWithFlags::size_of() as u64),
+        system_instruction::allocate(split_stake_pubkey, StakeStateV2::size_of() as u64),
         system_instruction::assign(split_stake_pubkey, &id()),
         _split(
             stake_pubkey,
@@ -476,7 +476,7 @@ pub fn split_with_seed(
             split_stake_pubkey,
             base,
             seed,
-            StakeStateWithFlags::size_of() as u64,
+            StakeStateV2::size_of() as u64,
             &id(),
         ),
         _split(
@@ -796,10 +796,7 @@ pub fn redelegate(
     uninitialized_stake_pubkey: &Pubkey,
 ) -> Vec<Instruction> {
     vec![
-        system_instruction::allocate(
-            uninitialized_stake_pubkey,
-            StakeStateWithFlags::size_of() as u64,
-        ),
+        system_instruction::allocate(uninitialized_stake_pubkey, StakeStateV2::size_of() as u64),
         system_instruction::assign(uninitialized_stake_pubkey, &id()),
         _redelegate(
             stake_pubkey,
@@ -823,7 +820,7 @@ pub fn redelegate_with_seed(
             uninitialized_stake_pubkey,
             base,
             seed,
-            StakeStateWithFlags::size_of() as u64,
+            StakeStateV2::size_of() as u64,
             &id(),
         ),
         _redelegate(

+ 34 - 37
sdk/program/src/stake/state.rs

@@ -38,7 +38,7 @@ pub fn warmup_cooldown_rate(current_epoch: Epoch, new_rate_activation_epoch: Opt
 #[allow(clippy::large_enum_variant)]
 #[deprecated(
     since = "1.17.0",
-    note = "Please use `StakeStateWithFlags` instead, and match the third `StakeFlags` field when matching `StakeStateWithFlags::Stake` to resolve any breakage. For example, `if let StakeState::Stake(meta, stake)` becomes `if let StakeStateWithFlags::Stake(meta, stake, _stake_flags)`."
+    note = "Please use `StakeStateV2` instead, and match the third `StakeFlags` field when matching `StakeStateV2::Stake` to resolve any breakage. For example, `if let StakeState::Stake(meta, stake)` becomes `if let StakeStateV2::Stake(meta, stake, _stake_flags)`."
 )]
 pub enum StakeState {
     #[default]
@@ -129,7 +129,7 @@ impl StakeState {
 
 #[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone, Copy, AbiExample)]
 #[allow(clippy::large_enum_variant)]
-pub enum StakeStateWithFlags {
+pub enum StakeStateV2 {
     #[default]
     Uninitialized,
     Initialized(Meta),
@@ -137,22 +137,22 @@ pub enum StakeStateWithFlags {
     RewardsPool,
 }
 
-impl BorshDeserialize for StakeStateWithFlags {
+impl BorshDeserialize for StakeStateV2 {
     fn deserialize_reader<R: io::Read>(reader: &mut R) -> io::Result<Self> {
         let enum_value = u32::deserialize_reader(reader)?;
         match enum_value {
-            0 => Ok(StakeStateWithFlags::Uninitialized),
+            0 => Ok(StakeStateV2::Uninitialized),
             1 => {
                 let meta = Meta::deserialize_reader(reader)?;
-                Ok(StakeStateWithFlags::Initialized(meta))
+                Ok(StakeStateV2::Initialized(meta))
             }
             2 => {
                 let meta: Meta = BorshDeserialize::deserialize_reader(reader)?;
                 let stake: Stake = BorshDeserialize::deserialize_reader(reader)?;
                 let stake_flags: StakeFlags = BorshDeserialize::deserialize_reader(reader)?;
-                Ok(StakeStateWithFlags::Stake(meta, stake, stake_flags))
+                Ok(StakeStateV2::Stake(meta, stake, stake_flags))
             }
-            3 => Ok(StakeStateWithFlags::RewardsPool),
+            3 => Ok(StakeStateV2::RewardsPool),
             _ => Err(io::Error::new(
                 io::ErrorKind::InvalidData,
                 "Invalid enum value",
@@ -161,26 +161,26 @@ impl BorshDeserialize for StakeStateWithFlags {
     }
 }
 
-impl BorshSerialize for StakeStateWithFlags {
+impl BorshSerialize for StakeStateV2 {
     fn serialize<W: io::Write>(&self, writer: &mut W) -> io::Result<()> {
         match self {
-            StakeStateWithFlags::Uninitialized => writer.write_all(&0u32.to_le_bytes()),
-            StakeStateWithFlags::Initialized(meta) => {
+            StakeStateV2::Uninitialized => writer.write_all(&0u32.to_le_bytes()),
+            StakeStateV2::Initialized(meta) => {
                 writer.write_all(&1u32.to_le_bytes())?;
                 meta.serialize(writer)
             }
-            StakeStateWithFlags::Stake(meta, stake, stake_flags) => {
+            StakeStateV2::Stake(meta, stake, stake_flags) => {
                 writer.write_all(&2u32.to_le_bytes())?;
                 meta.serialize(writer)?;
                 stake.serialize(writer)?;
                 stake_flags.serialize(writer)
             }
-            StakeStateWithFlags::RewardsPool => writer.write_all(&3u32.to_le_bytes()),
+            StakeStateV2::RewardsPool => writer.write_all(&3u32.to_le_bytes()),
         }
     }
 }
 
-impl StakeStateWithFlags {
+impl StakeStateV2 {
     /// The fixed number of bytes used to serialize each stake account
     pub const fn size_of() -> usize {
         200 // see test_size_of
@@ -188,22 +188,22 @@ impl StakeStateWithFlags {
 
     pub fn stake(&self) -> Option<Stake> {
         match self {
-            StakeStateWithFlags::Stake(_meta, stake, _stake_flags) => Some(*stake),
+            StakeStateV2::Stake(_meta, stake, _stake_flags) => Some(*stake),
             _ => None,
         }
     }
 
     pub fn delegation(&self) -> Option<Delegation> {
         match self {
-            StakeStateWithFlags::Stake(_meta, stake, _stake_flags) => Some(stake.delegation),
+            StakeStateV2::Stake(_meta, stake, _stake_flags) => Some(stake.delegation),
             _ => None,
         }
     }
 
     pub fn authorized(&self) -> Option<Authorized> {
         match self {
-            StakeStateWithFlags::Stake(meta, _stake, _stake_flags) => Some(meta.authorized),
-            StakeStateWithFlags::Initialized(meta) => Some(meta.authorized),
+            StakeStateV2::Stake(meta, _stake, _stake_flags) => Some(meta.authorized),
+            StakeStateV2::Initialized(meta) => Some(meta.authorized),
             _ => None,
         }
     }
@@ -214,8 +214,8 @@ impl StakeStateWithFlags {
 
     pub fn meta(&self) -> Option<Meta> {
         match self {
-            StakeStateWithFlags::Stake(meta, _stake, _stake_flags) => Some(*meta),
-            StakeStateWithFlags::Initialized(meta) => Some(*meta),
+            StakeStateV2::Stake(meta, _stake, _stake_flags) => Some(*meta),
+            StakeStateV2::Initialized(meta) => Some(*meta),
             _ => None,
         }
     }
@@ -711,31 +711,28 @@ mod test {
         bincode::serialize,
     };
 
-    fn check_borsh_deserialization(stake: StakeStateWithFlags) {
+    fn check_borsh_deserialization(stake: StakeStateV2) {
         let serialized = serialize(&stake).unwrap();
-        let deserialized = StakeStateWithFlags::try_from_slice(&serialized).unwrap();
+        let deserialized = StakeStateV2::try_from_slice(&serialized).unwrap();
         assert_eq!(stake, deserialized);
     }
 
-    fn check_borsh_serialization(stake: StakeStateWithFlags) {
+    fn check_borsh_serialization(stake: StakeStateV2) {
         let bincode_serialized = serialize(&stake).unwrap();
-        let borsh_serialized = StakeStateWithFlags::try_to_vec(&stake).unwrap();
+        let borsh_serialized = StakeStateV2::try_to_vec(&stake).unwrap();
         assert_eq!(bincode_serialized, borsh_serialized);
     }
 
     #[test]
     fn test_size_of() {
-        assert_eq!(
-            StakeStateWithFlags::size_of(),
-            std::mem::size_of::<StakeStateWithFlags>()
-        );
+        assert_eq!(StakeStateV2::size_of(), std::mem::size_of::<StakeStateV2>());
     }
 
     #[test]
     fn bincode_vs_borsh_deserialization() {
-        check_borsh_deserialization(StakeStateWithFlags::Uninitialized);
-        check_borsh_deserialization(StakeStateWithFlags::RewardsPool);
-        check_borsh_deserialization(StakeStateWithFlags::Initialized(Meta {
+        check_borsh_deserialization(StakeStateV2::Uninitialized);
+        check_borsh_deserialization(StakeStateV2::RewardsPool);
+        check_borsh_deserialization(StakeStateV2::Initialized(Meta {
             rent_exempt_reserve: u64::MAX,
             authorized: Authorized {
                 staker: Pubkey::new_unique(),
@@ -743,7 +740,7 @@ mod test {
             },
             lockup: Lockup::default(),
         }));
-        check_borsh_deserialization(StakeStateWithFlags::Stake(
+        check_borsh_deserialization(StakeStateV2::Stake(
             Meta {
                 rent_exempt_reserve: 1,
                 authorized: Authorized {
@@ -768,9 +765,9 @@ mod test {
 
     #[test]
     fn bincode_vs_borsh_serialization() {
-        check_borsh_serialization(StakeStateWithFlags::Uninitialized);
-        check_borsh_serialization(StakeStateWithFlags::RewardsPool);
-        check_borsh_serialization(StakeStateWithFlags::Initialized(Meta {
+        check_borsh_serialization(StakeStateV2::Uninitialized);
+        check_borsh_serialization(StakeStateV2::RewardsPool);
+        check_borsh_serialization(StakeStateV2::Initialized(Meta {
             rent_exempt_reserve: u64::MAX,
             authorized: Authorized {
                 staker: Pubkey::new_unique(),
@@ -778,7 +775,7 @@ mod test {
             },
             lockup: Lockup::default(),
         }));
-        check_borsh_serialization(StakeStateWithFlags::Stake(
+        check_borsh_serialization(StakeStateV2::Stake(
             Meta {
                 rent_exempt_reserve: 1,
                 authorized: Authorized {
@@ -816,10 +813,10 @@ mod test {
         ];
         // As long as we get the 4-byte enum and the first field right, then
         // we're sure the rest works out
-        let deserialized = try_from_slice_unchecked::<StakeStateWithFlags>(&data).unwrap();
+        let deserialized = try_from_slice_unchecked::<StakeStateV2>(&data).unwrap();
         assert_matches!(
             deserialized,
-            StakeStateWithFlags::Initialized(Meta {
+            StakeStateV2::Initialized(Meta {
                 rent_exempt_reserve: 2282880,
                 ..
             })

+ 2 - 3
stake-accounts/src/stake_accounts.rs

@@ -289,7 +289,7 @@ mod tests {
             client::SyncClient,
             genesis_config::create_genesis_config,
             signature::{Keypair, Signer},
-            stake::state::StakeStateWithFlags,
+            stake::state::StakeStateV2,
         },
         solana_stake_program::stake_state,
     };
@@ -297,8 +297,7 @@ mod tests {
     fn create_bank(lamports: u64) -> (Bank, Keypair, u64, u64) {
         let (genesis_config, mint_keypair) = create_genesis_config(lamports);
         let bank = Bank::new_for_tests(&genesis_config);
-        let stake_rent =
-            bank.get_minimum_balance_for_rent_exemption(StakeStateWithFlags::size_of());
+        let stake_rent = bank.get_minimum_balance_for_rent_exemption(StakeStateV2::size_of());
         let system_rent = bank.get_minimum_balance_for_rent_exemption(0);
         (bank, mint_keypair, stake_rent, system_rent)
     }

Some files were not shown because too many files changed in this diff