From 30791818e0769a252966f5733f0f4f63a9d1a4ca Mon Sep 17 00:00:00 2001 From: Tyera Date: Mon, 8 Jul 2024 15:38:08 -0600 Subject: [PATCH] Remove get_stake_activation methods from RpcClient (#2036) * Remove dangling JsonRpcRequestProcessor method * Remove get_stake_activation methods from RpcClient * Remove getStakeActivation from mock_sender * Remove unused rpc response type --- rpc-client-api/src/request.rs | 10 +-- rpc-client-api/src/response.rs | 8 -- rpc-client/src/mock_sender.rs | 9 +- rpc-client/src/nonblocking/rpc_client.rs | 100 ----------------------- rpc-client/src/rpc_client.rs | 86 ------------------- rpc/src/rpc.rs | 85 ------------------- 6 files changed, 3 insertions(+), 295 deletions(-) diff --git a/rpc-client-api/src/request.rs b/rpc-client-api/src/request.rs index f26024e7afbb19..fe032a858deb47 100644 --- a/rpc-client-api/src/request.rs +++ b/rpc-client-api/src/request.rs @@ -8,9 +8,7 @@ use { #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum RpcRequest { - Custom { - method: &'static str, - }, + Custom { method: &'static str }, DeregisterNode, GetAccountInfo, GetBalance, @@ -50,11 +48,6 @@ pub enum RpcRequest { GetStorageTurn, GetStorageTurnRate, GetSlotsPerSegment, - #[deprecated( - since = "1.18.18", - note = "Do not use; getStakeActivation is not supported by the JSON-RPC server." - )] - GetStakeActivation, GetStakeMinimumDelegation, GetStoragePubkeysForSlot, GetSupply, @@ -117,7 +110,6 @@ impl fmt::Display for RpcRequest { RpcRequest::GetSlot => "getSlot", RpcRequest::GetSlotLeader => "getSlotLeader", RpcRequest::GetSlotLeaders => "getSlotLeaders", - RpcRequest::GetStakeActivation => "getStakeActivation", RpcRequest::GetStakeMinimumDelegation => "getStakeMinimumDelegation", RpcRequest::GetStorageTurn => "getStorageTurn", RpcRequest::GetStorageTurnRate => "getStorageTurnRate", diff --git a/rpc-client-api/src/response.rs b/rpc-client-api/src/response.rs index ca43bd3b5cd557..fcb330103057e4 100644 --- a/rpc-client-api/src/response.rs +++ b/rpc-client-api/src/response.rs @@ -443,14 +443,6 @@ pub enum StakeActivationState { Inactive, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] -#[serde(rename_all = "camelCase")] -pub struct RpcStakeActivation { - pub state: StakeActivationState, - pub active: u64, - pub inactive: u64, -} - #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[serde(rename_all = "camelCase")] pub struct RpcTokenAccountBalance { diff --git a/rpc-client/src/mock_sender.rs b/rpc-client/src/mock_sender.rs index f5956059bbc4d2..9730a6ff24a983 100644 --- a/rpc-client/src/mock_sender.rs +++ b/rpc-client/src/mock_sender.rs @@ -15,8 +15,8 @@ use { RpcConfirmedTransactionStatusWithSignature, RpcContactInfo, RpcIdentity, RpcInflationGovernor, RpcInflationRate, RpcInflationReward, RpcKeyedAccount, RpcPerfSample, RpcPrioritizationFee, RpcResponseContext, RpcSimulateTransactionResult, - RpcSnapshotSlotInfo, RpcStakeActivation, RpcSupply, RpcVersionInfo, RpcVoteAccountInfo, - RpcVoteAccountStatus, StakeActivationState, + RpcSnapshotSlotInfo, RpcSupply, RpcVersionInfo, RpcVoteAccountInfo, + RpcVoteAccountStatus, }, }, solana_sdk::{ @@ -253,11 +253,6 @@ impl RpcSender for MockSender { }) } } - "getStakeActivation" => json!(RpcStakeActivation { - state: StakeActivationState::Activating, - active: 123, - inactive: 12, - }), "getStakeMinimumDelegation" => json!(Response { context: RpcResponseContext { slot: 1, api_version: None }, value: 123_456_789, diff --git a/rpc-client/src/nonblocking/rpc_client.rs b/rpc-client/src/nonblocking/rpc_client.rs index 532b6176032e5e..a7c5359d196ccc 100644 --- a/rpc-client/src/nonblocking/rpc_client.rs +++ b/rpc-client/src/nonblocking/rpc_client.rs @@ -2002,106 +2002,6 @@ impl RpcClient { .await } - /// Returns epoch activation information for a stake account. - /// - /// This method uses the configured [commitment level]. - /// - /// [cl]: https://solana.com/docs/rpc#configuring-state-commitment - /// - /// # RPC Reference - /// - /// This method corresponds directly to the [`getStakeActivation`] RPC method. - /// - /// [`getStakeActivation`]: https://solana.com/docs/rpc/http/getstakeactivation - /// - /// # Examples - /// - /// ``` - /// # use solana_rpc_client_api::{ - /// # client_error::Error, - /// # response::StakeActivationState, - /// # }; - /// # use solana_rpc_client::nonblocking::rpc_client::RpcClient; - /// # use solana_sdk::{ - /// # signer::keypair::Keypair, - /// # signature::Signer, - /// # pubkey::Pubkey, - /// # stake, - /// # stake::state::{Authorized, Lockup}, - /// # transaction::Transaction - /// # }; - /// # use std::str::FromStr; - /// # futures::executor::block_on(async { - /// # let alice = Keypair::new(); - /// # let rpc_client = RpcClient::new_mock("succeeds".to_string()); - /// // Find some vote account to delegate to - /// let vote_accounts = rpc_client.get_vote_accounts().await?; - /// let vote_account = vote_accounts.current.get(0).unwrap_or_else(|| &vote_accounts.delinquent[0]); - /// let vote_account_pubkey = &vote_account.vote_pubkey; - /// let vote_account_pubkey = Pubkey::from_str(vote_account_pubkey).expect("pubkey"); - /// - /// // Create a stake account - /// let stake_account = Keypair::new(); - /// let stake_account_pubkey = stake_account.pubkey(); - /// - /// // Build the instructions to create new stake account, - /// // funded by alice, and delegate to a validator's vote account. - /// let instrs = stake::instruction::create_account_and_delegate_stake( - /// &alice.pubkey(), - /// &stake_account_pubkey, - /// &vote_account_pubkey, - /// &Authorized::auto(&stake_account_pubkey), - /// &Lockup::default(), - /// 1_000_000, - /// ); - /// - /// let latest_blockhash = rpc_client.get_latest_blockhash().await?; - /// let tx = Transaction::new_signed_with_payer( - /// &instrs, - /// Some(&alice.pubkey()), - /// &[&alice, &stake_account], - /// latest_blockhash, - /// ); - /// - /// rpc_client.send_and_confirm_transaction(&tx).await?; - /// - /// let epoch_info = rpc_client.get_epoch_info().await?; - /// let activation = rpc_client.get_stake_activation( - /// stake_account_pubkey, - /// Some(epoch_info.epoch), - /// ).await?; - /// - /// assert_eq!(activation.state, StakeActivationState::Activating); - /// # Ok::<(), Error>(()) - /// # })?; - /// # Ok::<(), Error>(()) - /// ``` - #[deprecated( - since = "1.18.18", - note = "Do not use; getStakeActivation is not supported by the JSON-RPC server. Please \ - use the stake account and StakeHistory sysvar to call \ - `Delegation::stake_activating_and_deactivating()` instead" - )] - #[allow(deprecated)] - pub async fn get_stake_activation( - &self, - stake_account: Pubkey, - epoch: Option, - ) -> ClientResult { - self.send( - RpcRequest::GetStakeActivation, - json!([ - stake_account.to_string(), - RpcEpochConfig { - epoch, - commitment: Some(self.commitment()), - min_context_slot: None, - } - ]), - ) - .await - } - /// Returns information about the current supply. /// /// This method uses the configured [commitment level][cl]. diff --git a/rpc-client/src/rpc_client.rs b/rpc-client/src/rpc_client.rs index d81a0e5067efcd..32bd08cef49f03 100644 --- a/rpc-client/src/rpc_client.rs +++ b/rpc-client/src/rpc_client.rs @@ -1703,92 +1703,6 @@ impl RpcClient { self.invoke((self.rpc_client.as_ref()).get_block_production_with_config(config)) } - /// Returns epoch activation information for a stake account. - /// - /// This method uses the configured [commitment level]. - /// - /// [cl]: https://solana.com/docs/rpc#configuring-state-commitment - /// - /// # RPC Reference - /// - /// This method corresponds directly to the [`getStakeActivation`] RPC method. - /// - /// [`getStakeActivation`]: https://solana.com/docs/rpc/http/getstakeactivation - /// - /// # Examples - /// - /// ``` - /// # use solana_rpc_client_api::{ - /// # client_error::Error, - /// # response::StakeActivationState, - /// # }; - /// # use solana_rpc_client::rpc_client::RpcClient; - /// # use solana_sdk::{ - /// # signer::keypair::Keypair, - /// # signature::Signer, - /// # pubkey::Pubkey, - /// # stake, - /// # stake::state::{Authorized, Lockup}, - /// # transaction::Transaction - /// # }; - /// # use std::str::FromStr; - /// # let alice = Keypair::new(); - /// # let rpc_client = RpcClient::new_mock("succeeds".to_string()); - /// // Find some vote account to delegate to - /// let vote_accounts = rpc_client.get_vote_accounts()?; - /// let vote_account = vote_accounts.current.get(0).unwrap_or_else(|| &vote_accounts.delinquent[0]); - /// let vote_account_pubkey = &vote_account.vote_pubkey; - /// let vote_account_pubkey = Pubkey::from_str(vote_account_pubkey).expect("pubkey"); - /// - /// // Create a stake account - /// let stake_account = Keypair::new(); - /// let stake_account_pubkey = stake_account.pubkey(); - /// - /// // Build the instructions to create new stake account, - /// // funded by alice, and delegate to a validator's vote account. - /// let instrs = stake::instruction::create_account_and_delegate_stake( - /// &alice.pubkey(), - /// &stake_account_pubkey, - /// &vote_account_pubkey, - /// &Authorized::auto(&stake_account_pubkey), - /// &Lockup::default(), - /// 1_000_000, - /// ); - /// - /// let latest_blockhash = rpc_client.get_latest_blockhash()?; - /// let tx = Transaction::new_signed_with_payer( - /// &instrs, - /// Some(&alice.pubkey()), - /// &[&alice, &stake_account], - /// latest_blockhash, - /// ); - /// - /// rpc_client.send_and_confirm_transaction(&tx)?; - /// - /// let epoch_info = rpc_client.get_epoch_info()?; - /// let activation = rpc_client.get_stake_activation( - /// stake_account_pubkey, - /// Some(epoch_info.epoch), - /// )?; - /// - /// assert_eq!(activation.state, StakeActivationState::Activating); - /// # Ok::<(), Error>(()) - /// ``` - #[deprecated( - since = "1.18.18", - note = "Do not use; getStakeActivation is not supported by the JSON-RPC server. Please \ - use the stake account and StakeHistory sysvar to call \ - `Delegation::stake_activating_and_deactivating()` instead" - )] - #[allow(deprecated)] - pub fn get_stake_activation( - &self, - stake_account: Pubkey, - epoch: Option, - ) -> ClientResult { - self.invoke((self.rpc_client.as_ref()).get_stake_activation(stake_account, epoch)) - } - /// Returns information about the current supply. /// /// This method uses the configured [commitment level][cl]. diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 2fa8a036cfc201..5a022e5972711b 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -61,7 +61,6 @@ use { }, solana_sdk::{ account::{AccountSharedData, ReadableAccount}, - account_utils::StateMut, clock::{Slot, UnixTimestamp, MAX_PROCESSING_AGE}, commitment_config::{CommitmentConfig, CommitmentLevel}, epoch_info::EpochInfo, @@ -73,10 +72,7 @@ use { message::SanitizedMessage, pubkey::{Pubkey, PUBKEY_BYTES}, signature::{Keypair, Signature, Signer}, - stake::state::{StakeActivationStatus, StakeStateV2}, - stake_history::StakeHistory, system_instruction, - sysvar::stake_history, transaction::{ self, AddressLoader, MessageHash, SanitizedTransaction, TransactionError, VersionedTransaction, MAX_TX_ACCOUNT_LOCKS, @@ -1813,87 +1809,6 @@ impl JsonRpcRequestProcessor { slot } - pub fn get_stake_activation( - &self, - pubkey: &Pubkey, - config: Option, - ) -> Result { - let config = config.unwrap_or_default(); - let bank = self.get_bank_with_config(RpcContextConfig { - commitment: config.commitment, - min_context_slot: config.min_context_slot, - })?; - let epoch = config.epoch.unwrap_or_else(|| bank.epoch()); - if epoch != bank.epoch() { - return Err(Error::invalid_params(format!( - "Invalid param: epoch {epoch:?}. Only the current epoch ({:?}) is supported", - bank.epoch() - ))); - } - - let stake_account = bank - .get_account(pubkey) - .ok_or_else(|| Error::invalid_params("Invalid param: account not found".to_string()))?; - 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(); - - let rent_exempt_reserve = stake_state - .meta() - .ok_or_else(|| { - Error::invalid_params("Invalid param: stake account not initialized".to_string()) - })? - .rent_exempt_reserve; - - let delegation = match delegation { - None => { - return Ok(RpcStakeActivation { - state: StakeActivationState::Inactive, - active: 0, - inactive: stake_account.lamports().saturating_sub(rent_exempt_reserve), - }) - } - Some(delegation) => delegation, - }; - - let stake_history_account = bank - .get_account(&stake_history::id()) - .ok_or_else(Error::internal_error)?; - let stake_history = - solana_sdk::account::from_account::(&stake_history_account) - .ok_or_else(Error::internal_error)?; - let new_rate_activation_epoch = bank.new_warmup_cooldown_rate_epoch(); - - let StakeActivationStatus { - effective, - activating, - deactivating, - } = delegation.stake_activating_and_deactivating( - epoch, - &stake_history, - new_rate_activation_epoch, - ); - let stake_activation_state = if deactivating > 0 { - StakeActivationState::Deactivating - } else if activating > 0 { - StakeActivationState::Activating - } else if effective > 0 { - StakeActivationState::Active - } else { - StakeActivationState::Inactive - }; - let inactive_stake = stake_account - .lamports() - .saturating_sub(effective) - .saturating_sub(rent_exempt_reserve); - Ok(RpcStakeActivation { - state: stake_activation_state, - active: effective, - inactive: inactive_stake, - }) - } - pub fn get_token_account_balance( &self, pubkey: &Pubkey,