Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: getStakeActivation now correctly returns the inactivate lamports for deactivat{ed,ing} stake account in all cases #26595

Merged
merged 1 commit into from
Jul 13, 2022
Merged
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
42 changes: 23 additions & 19 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,24 +1739,24 @@ impl JsonRpcRequestProcessor {
.state()
.map_err(|_| Error::invalid_params("Invalid param: not a stake account".to_string()))?;
let delegation = stake_state.delegation();
if delegation.is_none() {
match stake_state.meta() {
None => {
return Err(Error::invalid_params(
"Invalid param: stake account not initialized".to_string(),
));
}
Some(meta) => {
let rent_exempt_reserve = meta.rent_exempt_reserve;
return Ok(RpcStakeActivation {
state: StakeActivationState::Inactive,
active: 0,
inactive: stake_account.lamports().saturating_sub(rent_exempt_reserve),
});
}

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),
})
}
}
let delegation = delegation.unwrap();
Some(delegation) => delegation,
};

let stake_history_account = bank
.get_account(&stake_history::id())
Expand All @@ -1782,8 +1782,12 @@ impl JsonRpcRequestProcessor {
let inactive_stake = match stake_activation_state {
StakeActivationState::Activating => activating,
StakeActivationState::Active => 0,
StakeActivationState::Deactivating => delegation.stake.saturating_sub(effective),
StakeActivationState::Inactive => delegation.stake,
StakeActivationState::Deactivating => stake_account
.lamports()
.saturating_sub(effective + rent_exempt_reserve),
StakeActivationState::Inactive => {
stake_account.lamports().saturating_sub(rent_exempt_reserve)
}
};
Ok(RpcStakeActivation {
state: stake_activation_state,
Expand Down