From 7d91515e8d69bba6f51b534e6f87619b4953f5d5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 19 Mar 2021 22:07:30 +0000 Subject: [PATCH] Make getStakeActivation response consistent for undelegated accounts (#16038) (#16040) (cherry picked from commit 2ec24d438f9ec722d68165bbdd30151065c2cca7) Co-authored-by: Tyera Eulberg --- core/src/rpc.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/core/src/rpc.rs b/core/src/rpc.rs index fcb476d192..e16569974a 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -1157,9 +1157,25 @@ impl JsonRpcRequestProcessor { let stake_state: StakeState = stake_account .state() .map_err(|_| Error::invalid_params("Invalid param: not a stake account".to_string()))?; - let delegation = stake_state.delegation().ok_or_else(|| { - Error::invalid_params("Invalid param: stake account has not been delegated".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 delegation = delegation.unwrap(); let stake_history_account = bank .get_account(&stake_history::id())