From 3dc6b494580b3c4ae4ad5643df2d19e79453b3f2 Mon Sep 17 00:00:00 2001 From: Erwan Date: Tue, 14 Nov 2023 15:04:20 -0500 Subject: [PATCH] staking: remove next rate api Co-authored-by: Finch Foner --- .../core/component/stake/src/component/rpc.rs | 36 ++----------------- .../core/component/stake/src/identity_key.rs | 21 +---------- crates/core/component/stake/src/rate.rs | 24 +------------ 3 files changed, 5 insertions(+), 76 deletions(-) diff --git a/crates/core/component/stake/src/component/rpc.rs b/crates/core/component/stake/src/component/rpc.rs index 9c4ad21618..e294523e39 100644 --- a/crates/core/component/stake/src/component/rpc.rs +++ b/crates/core/component/stake/src/component/rpc.rs @@ -6,9 +6,9 @@ use penumbra_chain::component::StateReadExt as _; use penumbra_proto::{ core::component::stake::v1alpha1::{ query_service_server::QueryService, CurrentValidatorRateRequest, - CurrentValidatorRateResponse, NextValidatorRateRequest, NextValidatorRateResponse, - ValidatorInfoRequest, ValidatorInfoResponse, ValidatorPenaltyRequest, - ValidatorPenaltyResponse, ValidatorStatusRequest, ValidatorStatusResponse, + CurrentValidatorRateResponse, ValidatorInfoRequest, ValidatorInfoResponse, + ValidatorPenaltyRequest, ValidatorPenaltyResponse, ValidatorStatusRequest, + ValidatorStatusResponse, }, DomainType, }; @@ -168,34 +168,4 @@ impl QueryService for Server { None => Err(Status::not_found("current validator rate not found")), } } - - #[instrument(skip(self, request))] - async fn next_validator_rate( - &self, - request: tonic::Request, - ) -> Result, Status> { - let state = self.storage.latest_snapshot(); - state - .check_chain_id(&request.get_ref().chain_id) - .await - .map_err(|e| tonic::Status::unknown(format!("chain_id not OK: {e}")))?; - let identity_key = request - .into_inner() - .identity_key - .ok_or_else(|| tonic::Status::invalid_argument("empty message"))? - .try_into() - .map_err(|_| tonic::Status::invalid_argument("invalid identity key"))?; - - let rate_data = state - .next_validator_rate(&identity_key) - .await - .map_err(|e| tonic::Status::internal(e.to_string()))?; - - match rate_data { - Some(r) => Ok(tonic::Response::new(NextValidatorRateResponse { - data: Some(r.into()), - })), - None => Err(Status::not_found("next validator rate not found")), - } - } } diff --git a/crates/core/component/stake/src/identity_key.rs b/crates/core/component/stake/src/identity_key.rs index bbb0c669f1..2026e6674b 100644 --- a/crates/core/component/stake/src/identity_key.rs +++ b/crates/core/component/stake/src/identity_key.rs @@ -1,5 +1,5 @@ use penumbra_proto::{ - core::component::stake::v1alpha1::{CurrentValidatorRateRequest, NextValidatorRateRequest}, + core::component::stake::v1alpha1::CurrentValidatorRateRequest, // TODO: why is this not in the keys crate? core::keys::v1alpha1 as pb, serializers::bech32str::{self, validator_identity_key::BECH32_PREFIX}, @@ -72,25 +72,6 @@ impl TryFrom for IdentityKey { } } -impl From for NextValidatorRateRequest { - fn from(k: IdentityKey) -> Self { - NextValidatorRateRequest { - identity_key: Some(k.into()), - chain_id: Default::default(), - } - } -} - -impl TryFrom for IdentityKey { - type Error = anyhow::Error; - fn try_from(value: NextValidatorRateRequest) -> Result { - value - .identity_key - .ok_or_else(|| anyhow::anyhow!("empty NextValidatorRateRequest message"))? - .try_into() - } -} - impl From for CurrentValidatorRateRequest { fn from(k: IdentityKey) -> Self { CurrentValidatorRateRequest { diff --git a/crates/core/component/stake/src/rate.rs b/crates/core/component/stake/src/rate.rs index e0e6f8712b..f88a57862c 100644 --- a/crates/core/component/stake/src/rate.rs +++ b/crates/core/component/stake/src/rate.rs @@ -2,10 +2,7 @@ use penumbra_num::Amount; use penumbra_proto::core::component::stake::v1alpha1::CurrentValidatorRateResponse; -use penumbra_proto::{ - core::component::stake::v1alpha1::NextValidatorRateResponse, - penumbra::core::component::stake::v1alpha1 as pb, DomainType, TypeUrl, -}; +use penumbra_proto::{penumbra::core::component::stake::v1alpha1 as pb, DomainType, TypeUrl}; use serde::{Deserialize, Serialize}; use crate::{validator::State, FundingStream, IdentityKey}; @@ -254,25 +251,6 @@ impl TryFrom for BaseRateData { } } -impl From for NextValidatorRateResponse { - fn from(r: RateData) -> Self { - NextValidatorRateResponse { - data: Some(r.into()), - } - } -} - -impl TryFrom for RateData { - type Error = anyhow::Error; - - fn try_from(value: NextValidatorRateResponse) -> Result { - value - .data - .ok_or_else(|| anyhow::anyhow!("empty NextValidatorRateResponse message"))? - .try_into() - } -} - impl From for CurrentValidatorRateResponse { fn from(r: RateData) -> Self { CurrentValidatorRateResponse {