Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions rpc-client-api/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use {

#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum RpcRequest {
Custom {
method: &'static str,
},
Custom { method: &'static str },
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rustfmt, you are weird, you just changed this

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like when it touches lines that haven't otherwise been touched by the diff. it's good for the culture

DeregisterNode,
GetAccountInfo,
GetBalance,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 0 additions & 8 deletions rpc-client-api/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,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 {
Expand Down
9 changes: 2 additions & 7 deletions rpc-client/src/mock_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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,
Expand Down
100 changes: 0 additions & 100 deletions rpc-client/src/nonblocking/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Epoch>,
) -> ClientResult<RpcStakeActivation> {
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].
Expand Down
86 changes: 0 additions & 86 deletions rpc-client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Epoch>,
) -> ClientResult<RpcStakeActivation> {
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].
Expand Down
85 changes: 0 additions & 85 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -1813,87 +1809,6 @@ impl JsonRpcRequestProcessor {
slot
}

pub fn get_stake_activation(
&self,
pubkey: &Pubkey,
config: Option<RpcEpochConfig>,
) -> Result<RpcStakeActivation> {
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::<StakeHistory, _>(&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,
Expand Down