Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

cli: stake-account/stakes: Use GetStakeActivation#13497

Closed
ryoqun wants to merge 2 commits intosolana-labs:masterfrom
ryoqun:cli-stake-activation-rpc
Closed

cli: stake-account/stakes: Use GetStakeActivation#13497
ryoqun wants to merge 2 commits intosolana-labs:masterfrom
ryoqun:cli-stake-activation-rpc

Conversation

@ryoqun
Copy link
Copy Markdown
Contributor

@ryoqun ryoqun commented Nov 10, 2020

Problem

CLI calculates stakes locally, which is very hard to properly feature-gate it. And it's not useful for fixing the stake calculation code.

Summary of Changes

Use aptly-provided getStakeActivation rpc endpoint.

based-on: #10902

Comment thread cli/src/stake.rs
let current_epoch = clock.epoch;
let (active_stake, activating_stake, deactivating_stake) = stake
.delegation
.stake_activating_and_deactivating(current_epoch, Some(stake_history));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👋

Comment thread cli/src/stake.rs
Comment on lines +1518 to +1525
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)
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

shameless inverse conversion from RpcStakeActivation back to the original stake tuple ((u64, u64, u64)). If I had more time, I would fix CliStakeState itself... ;)

Comment thread client/src/rpc_client.rs
self.get_epoch_info_with_commitment(CommitmentConfig::default())
}

pub fn get_stake_activation(&self, pubkey: &Pubkey) -> ClientResult<RpcStakeActivation> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think adding new fns is ok in terms of compatibility even with a patch release.

@ryoqun
Copy link
Copy Markdown
Contributor Author

ryoqun commented Nov 10, 2020

@CriesofCarrots Could you quick review this? Thanks!

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 10, 2020

Codecov Report

Merging #13497 (00d5f9f) into master (a97c04b) will decrease coverage by 0.0%.
The diff coverage is 0.0%.

@@            Coverage Diff            @@
##           master   #13497     +/-   ##
=========================================
- Coverage    82.1%    82.0%   -0.1%     
=========================================
  Files         378      378             
  Lines       90505    90525     +20     
=========================================
- Hits        74317    74314      -3     
- Misses      16188    16211     +23     

Comment thread cli/src/cluster_query.rs
let mut stake_accounts: Vec<CliKeyedStakeState> = vec![];
for (stake_pubkey, stake_account) in all_stake_accounts {
if let Ok(stake_state) = stake_account.state() {
let stake_activation = rpc_client.get_stake_activation(&stake_pubkey)?;
Copy link
Copy Markdown
Contributor

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, getStakeActivation returns 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:

Suggested change
let stake_activation = rpc_client.get_stake_activation(&stake_pubkey)?;
let stake_activation = rpc_client.get_stake_activation(&stake_pubkey).unwrap_or(
RpcStakeActivation {
state: StakeActivationState::Inactive,
active: 0,
inactive: 0,
}
);

although that would disguise other types of errors.

@CriesofCarrots
Copy link
Copy Markdown
Contributor

This change makes solana stakes prohibitively expensive: ~3min on mainnet-beta currently
Trying a different approach!

@ryoqun
Copy link
Copy Markdown
Contributor Author

ryoqun commented Nov 12, 2020

ref: similar change was incorporated into #13501

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants