Skip to content

Commit

Permalink
getStakeActivation now correctly returns the inactivate lamports for …
Browse files Browse the repository at this point in the history
…deactivat{ed,ing} stake account in all cases
  • Loading branch information
mvines committed Jul 12, 2022
1 parent 9d31216 commit 96eaccf
Showing 1 changed file with 23 additions and 19 deletions.
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

0 comments on commit 96eaccf

Please sign in to comment.