This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
cli: stake-account/stakes: Use GetStakeActivation #13497
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ use solana_cli_output::{ | |
| return_signers, CliEpochReward, CliStakeHistory, CliStakeHistoryEntry, CliStakeState, | ||
| CliStakeType, | ||
| }; | ||
| use solana_client::rpc_response::{RpcStakeActivation, StakeActivationState}; | ||
| use solana_client::{ | ||
| blockhash_query::BlockhashQuery, | ||
| client_error::{ClientError, ClientErrorKind}, | ||
|
|
@@ -1499,7 +1500,7 @@ pub fn build_stake_state( | |
| account_balance: u64, | ||
| stake_state: &StakeState, | ||
| use_lamports_unit: bool, | ||
| stake_history: &StakeHistory, | ||
| stake_activation: &RpcStakeActivation, | ||
| clock: &Clock, | ||
| ) -> CliStakeState { | ||
| match stake_state { | ||
|
|
@@ -1512,9 +1513,17 @@ pub fn build_stake_state( | |
| stake, | ||
| ) => { | ||
| let current_epoch = clock.epoch; | ||
| let (active_stake, activating_stake, deactivating_stake) = stake | ||
| .delegation | ||
| .stake_activating_and_deactivating(current_epoch, Some(stake_history)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👋 |
||
| let (active_stake, activating_stake, deactivating_stake) = match stake_activation.state | ||
| { | ||
| StakeActivationState::Active => (stake_activation.active, 0, 0), | ||
| StakeActivationState::Inactive => (0, 0, 0), | ||
| StakeActivationState::Activating => { | ||
| (stake_activation.active, stake_activation.inactive, 0) | ||
| } | ||
| StakeActivationState::Deactivating => { | ||
| (stake_activation.active, 0, stake_activation.inactive) | ||
| } | ||
|
Comment on lines
+1518
to
+1525
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shameless inverse conversion from RpcStakeActivation back to the original stake tuple ( |
||
| }; | ||
| let lockup = if lockup.is_in_force(clock, None) { | ||
| Some(lockup.into()) | ||
| } else { | ||
|
|
@@ -1695,20 +1704,17 @@ pub fn process_show_stake_account( | |
| } | ||
| match stake_account.state() { | ||
| Ok(stake_state) => { | ||
| let stake_history_account = rpc_client.get_account(&stake_history::id())?; | ||
| let stake_history = from_account(&stake_history_account).ok_or_else(|| { | ||
| CliError::RpcRequestError("Failed to deserialize stake history".to_string()) | ||
| })?; | ||
| let clock_account = rpc_client.get_account(&clock::id())?; | ||
| let clock: Clock = from_account(&clock_account).ok_or_else(|| { | ||
| CliError::RpcRequestError("Failed to deserialize clock sysvar".to_string()) | ||
| })?; | ||
| let stake_activation = rpc_client.get_stake_activation(stake_account_address)?; | ||
|
|
||
| let mut state = build_stake_state( | ||
| stake_account.lamports, | ||
| &stake_state, | ||
| use_lamports_unit, | ||
| &stake_history, | ||
| &stake_activation, | ||
| &clock, | ||
| ); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -474,6 +474,13 @@ impl RpcClient { | |
| self.get_epoch_info_with_commitment(CommitmentConfig::default()) | ||
| } | ||
|
|
||
| pub fn get_stake_activation(&self, pubkey: &Pubkey) -> ClientResult<RpcStakeActivation> { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think adding new |
||
| self.send( | ||
| RpcRequest::GetStakeActivation, | ||
| json!([pubkey.to_string(), CommitmentConfig::default()]), | ||
| ) | ||
| } | ||
|
|
||
| pub fn get_epoch_info_with_commitment( | ||
| &self, | ||
| commitment_config: CommitmentConfig, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this doesn't quite work. If a stake account is undelegated,
getStakeActivationreturns a JSON-rpc error:{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid param: stake account has not been delegated"},"id":1}...which errors out here and breaks the loop (or in the case of
solana stake-account, prevents the account info being shown).A simple (naive) fix might be to write this as:
although that would disguise other types of errors.