From c3c4ce48af066b64fe28ab8fce900d2c5df99201 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Fri, 19 Mar 2021 15:51:40 -0600 Subject: [PATCH] Make getStakeActivation response consistent for undelegated accounts (#16039) --- 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 98cfa79924..3e486acd04 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -1177,9 +1177,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())