Skip to content

Commit

Permalink
staking: remove next rate api
Browse files Browse the repository at this point in the history
Co-authored-by: Finch Foner <[email protected]>
  • Loading branch information
erwanor and plaidfinch committed Nov 14, 2023
1 parent ec58851 commit 3dc6b49
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 76 deletions.
36 changes: 3 additions & 33 deletions crates/core/component/stake/src/component/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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<NextValidatorRateRequest>,
) -> Result<tonic::Response<NextValidatorRateResponse>, 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")),
}
}
}
21 changes: 1 addition & 20 deletions crates/core/component/stake/src/identity_key.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -72,25 +72,6 @@ impl TryFrom<pb::IdentityKey> for IdentityKey {
}
}

impl From<IdentityKey> for NextValidatorRateRequest {
fn from(k: IdentityKey) -> Self {
NextValidatorRateRequest {
identity_key: Some(k.into()),
chain_id: Default::default(),
}
}
}

impl TryFrom<NextValidatorRateRequest> for IdentityKey {
type Error = anyhow::Error;
fn try_from(value: NextValidatorRateRequest) -> Result<Self, Self::Error> {
value
.identity_key
.ok_or_else(|| anyhow::anyhow!("empty NextValidatorRateRequest message"))?
.try_into()
}
}

impl From<IdentityKey> for CurrentValidatorRateRequest {
fn from(k: IdentityKey) -> Self {
CurrentValidatorRateRequest {
Expand Down
24 changes: 1 addition & 23 deletions crates/core/component/stake/src/rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -254,25 +251,6 @@ impl TryFrom<pb::BaseRateData> for BaseRateData {
}
}

impl From<RateData> for NextValidatorRateResponse {
fn from(r: RateData) -> Self {
NextValidatorRateResponse {
data: Some(r.into()),
}
}
}

impl TryFrom<NextValidatorRateResponse> for RateData {
type Error = anyhow::Error;

fn try_from(value: NextValidatorRateResponse) -> Result<Self, Self::Error> {
value
.data
.ok_or_else(|| anyhow::anyhow!("empty NextValidatorRateResponse message"))?
.try_into()
}
}

impl From<RateData> for CurrentValidatorRateResponse {
fn from(r: RateData) -> Self {
CurrentValidatorRateResponse {
Expand Down

0 comments on commit 3dc6b49

Please sign in to comment.