Skip to content

Commit

Permalink
proto: split RPCs into per-component QueryServices
Browse files Browse the repository at this point in the history
Closes #3083.

Still outstanding work to do:

- [ ] Split up the server-side implementations currently in `pd`.
- [ ] Resolve the governance issues.

On the latter point, I discovered that large parts of the governance code don't
have any RPCs defined, and instead rely on having knowledge of the Rust code to
layer together raw state accesses.  This is practically impossible for any
third party client to do, so it's not an acceptable solution.  The shim code
that enabled this was removed as part of the refactoring, so we'll either need
to define the relevant RPCs, or leave that functionality disabled until we do.
  • Loading branch information
hdevalence committed Sep 23, 2023
1 parent 18fc67a commit 964a3d0
Show file tree
Hide file tree
Showing 118 changed files with 23,846 additions and 22,088 deletions.
1 change: 1 addition & 0 deletions .github/workflows/buf-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
./deployments/scripts/protobuf-codegen
# https://github.com/penumbra-zone/penumbra/issues/3038#issuecomment-1722534133
git checkout crates/proto/src/gen/proto_descriptor.bin.no_lfs
git checkout crates/storage/src/gen/proto_descriptor.bin.no_lfs
s="$(git status --porcelain)"
if [[ -n "$s" ]]; then
echo "ERROR: protobuf files must be regenerated and committed."
Expand Down
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions crates/bin/pcli/src/command/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ impl QueryCmd {
QueryCmd::Key { key } => key.clone(),
};

let mut client = app.specific_client().await?;
let req = penumbra_proto::client::v1alpha1::KeyValueRequest {
use penumbra_proto::core::app::v1alpha1::query_service_client::QueryServiceClient;
let mut client = QueryServiceClient::new(app.pd_channel().await?);

let req = penumbra_proto::core::app::v1alpha1::KeyValueRequest {
key: key.clone(),
..Default::default()
};
Expand Down
46 changes: 28 additions & 18 deletions crates/bin/pcli/src/command/query/chain.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
use anyhow::{Context, Result};
use anyhow::{anyhow, Context, Result};
use comfy_table::{presets, Table};
use futures::TryStreamExt;
use penumbra_chain::params::ChainParameters;
use penumbra_proto::client::v1alpha1::{ChainParametersRequest, EpochByHeightRequest, InfoRequest};
use penumbra_proto::{
core::app::v1alpha1::{
query_service_client::QueryServiceClient as AppQueryServiceClient, ChainParametersRequest,
},
core::component::chain::v1alpha1::{
query_service_client::QueryServiceClient as ChainQueryServiceClient, EpochByHeightRequest,
},
core::component::stake::v1alpha1::{
query_service_client::QueryServiceClient as StakeQueryServiceClient, ValidatorInfoRequest,
},
util::tendermint_proxy::v1alpha1::{
tendermint_proxy_service_client::TendermintProxyServiceClient, GetStatusRequest,
},
};
use penumbra_stake::validator;

// TODO: remove this subcommand and merge into `pcli q`
Expand Down Expand Up @@ -34,9 +47,8 @@ pub struct Stats {

impl ChainCmd {
pub async fn print_chain_params(&self, app: &mut App) -> Result<()> {
let mut oblivious_client = app.oblivious_client().await?;

let params: ChainParameters = oblivious_client
let mut client = AppQueryServiceClient::new(app.pd_channel().await?);
let params: ChainParameters = client
.chain_parameters(tonic::Request::new(ChainParametersRequest {
chain_id: "".to_string(),
}))
Expand Down Expand Up @@ -104,22 +116,18 @@ impl ChainCmd {
}

pub async fn get_stats(&self, app: &mut App) -> Result<Stats> {
use penumbra_proto::client::v1alpha1::ValidatorInfoRequest;

let mut client = app.oblivious_client().await?;
let channel = app.pd_channel().await?;

// TODO: is it possible to use the TendermintProxyService instead here??
let info = client
.info(InfoRequest {
version: "".to_string(),
block_version: 0,
p2p_version: 0,
abci_version: "".to_string(),
})
let mut client = TendermintProxyServiceClient::new(channel.clone());
let current_block_height = client
.get_status(GetStatusRequest::default())
.await?
.into_inner();
.into_inner()
.sync_info
.ok_or_else(|| anyhow!("missing sync_info"))?
.latest_block_height;

let current_block_height = info.last_block_height;
let mut client = ChainQueryServiceClient::new(channel.clone());
let current_epoch: u64 = client
.epoch_by_height(tonic::Request::new(EpochByHeightRequest {
height: current_block_height.clone(),
Expand All @@ -130,6 +138,7 @@ impl ChainCmd {
.context("failed to find EpochByHeight message")?
.index;

let mut client = AppQueryServiceClient::new(channel.clone());
let chain_params = client
.chain_parameters(tonic::Request::new(ChainParametersRequest {
chain_id: "".to_string(),
Expand All @@ -140,6 +149,7 @@ impl ChainCmd {
.ok_or_else(|| anyhow::anyhow!("empty ChainParametersResponse message"))?;

// Fetch validators.
let mut client = StakeQueryServiceClient::new(channel.clone());
let validators = client
.validator_info(ValidatorInfoRequest {
show_inactive: true,
Expand Down
13 changes: 11 additions & 2 deletions crates/bin/pcli/src/command/query/dao.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anyhow::{Context, Result};
use anyhow::Result;
//use anyhow::{Context, Result};
/*
use futures::TryStreamExt;
//use penumbra_app::dao;
use penumbra_dao::component::state_key;
Expand All @@ -8,6 +10,8 @@ use penumbra_num::Amount;
use penumbra_view::ViewClient;
use crate::{command::query::dao, App};
*/
use crate::App;

#[derive(Debug, clap::Subcommand)]
pub enum DaoCmd {
Expand All @@ -25,7 +29,11 @@ impl DaoCmd {
}
}

pub async fn print_balance(&self, app: &mut App, asset: &Option<String>) -> Result<()> {
pub async fn print_balance(&self, _app: &mut App, _asset: &Option<String>) -> Result<()> {
unimplemented!("dao component needs an RPC defined");
// below code is not usable outside of our own crates because
// it does raw state key access
/*
let asset_id = asset.as_ref().map(|asset| {
// Try to parse as an asset ID, then if it's not an asset ID, assume it's a unit name
if let Ok(asset_id) = asset.parse() {
Expand Down Expand Up @@ -69,5 +77,6 @@ impl DaoCmd {
};
Ok(())
*/
}
}
41 changes: 25 additions & 16 deletions crates/bin/pcli/src/command/query/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ use penumbra_dex::{
lp::position::{self, Position},
BatchSwapOutputData, DirectedTradingPair, SwapExecution, TradingPair,
};
use penumbra_proto::client::v1alpha1::{
specific_query_service_client::SpecificQueryServiceClient, ArbExecutionRequest,
BatchSwapOutputDataRequest, DenomMetadataByIdRequest, LiquidityPositionByIdRequest,
LiquidityPositionsByPriceRequest, LiquidityPositionsRequest, SimulateTradeRequest,
SwapExecutionRequest,
use penumbra_proto::core::component::{
dex::v1alpha1::{
query_service_client::QueryServiceClient as DexQueryServiceClient,
simulation_service_client::SimulationServiceClient, ArbExecutionRequest,
BatchSwapOutputDataRequest, LiquidityPositionByIdRequest, LiquidityPositionsByPriceRequest,
LiquidityPositionsRequest, SimulateTradeRequest, SwapExecutionRequest,
},
shielded_pool::v1alpha1::{
query_service_client::QueryServiceClient as ShieldedPoolQueryServiceClient,
DenomMetadataByIdRequest,
},
};
use penumbra_view::ViewClient;
use tonic::transport::Channel;
Expand Down Expand Up @@ -94,7 +100,7 @@ impl DexCmd {
height: &u64,
trading_pair: &TradingPair,
) -> Result<BatchSwapOutputData> {
let mut client = app.specific_client().await?;
let mut client = DexQueryServiceClient::new(app.pd_channel().await?);
client
.batch_swap_output_data(BatchSwapOutputDataRequest {
height: *height,
Expand All @@ -113,7 +119,8 @@ impl DexCmd {
height: &u64,
trading_pair: &DirectedTradingPair,
) -> Result<SwapExecution> {
let mut client = app.specific_client().await?;
let mut client = DexQueryServiceClient::new(app.pd_channel().await?);

client
.swap_execution(SwapExecutionRequest {
height: *height,
Expand All @@ -129,7 +136,7 @@ impl DexCmd {
}

pub async fn get_arb_execution(&self, app: &mut App, height: &u64) -> Result<SwapExecution> {
let mut client = app.specific_client().await?;
let mut client = DexQueryServiceClient::new(app.pd_channel().await?);
client
.arb_execution(ArbExecutionRequest {
height: *height,
Expand All @@ -149,8 +156,10 @@ impl DexCmd {
input: Value,
output: asset::Id,
) -> Result<SwapExecution> {
use penumbra_proto::client::v1alpha1::simulate_trade_request::{routing::Setting, Routing};
let mut client = app.specific_client().await?;
use penumbra_proto::core::component::dex::v1alpha1::simulate_trade_request::{
routing::Setting, Routing,
};
let mut client = SimulationServiceClient::new(app.pd_channel().await?);
client
.simulate_trade(SimulateTradeRequest {
input: Some(input.into()),
Expand All @@ -169,7 +178,7 @@ impl DexCmd {

pub async fn get_all_liquidity_positions(
&self,
mut client: SpecificQueryServiceClient<Channel>,
mut client: DexQueryServiceClient<Channel>,
include_closed: bool,
chain_id: Option<String>,
) -> Result<Pin<Box<dyn Stream<Item = Result<Position>> + Send + 'static>>> {
Expand All @@ -191,7 +200,7 @@ impl DexCmd {

pub async fn get_liquidity_positions_by_price(
&self,
mut client: SpecificQueryServiceClient<Channel>,
mut client: DexQueryServiceClient<Channel>,
pair: DirectedTradingPair,
limit: Option<u64>,
) -> Result<Pin<Box<dyn Stream<Item = Result<Position>> + Send + 'static>>> {
Expand Down Expand Up @@ -301,7 +310,7 @@ impl DexCmd {
height: &u64,
trading_pair: &TradingPair,
) -> Result<()> {
let mut client = app.specific_client().await?;
let mut client = ShieldedPoolQueryServiceClient::new(app.pd_channel().await?);

let chain_id = app.view().chain_params().await?.chain_id;

Expand Down Expand Up @@ -398,7 +407,7 @@ impl DexCmd {
self.print_swap_execution(app, &swap_execution).await?;
}
DexCmd::AllPositions { include_closed } => {
let client = app.specific_client().await?;
let client = DexQueryServiceClient::new(app.pd_channel().await?);
let chain_id = app.view().chain_params().await?.chain_id;

let positions_stream = self
Expand All @@ -415,7 +424,7 @@ impl DexCmd {
trading_pair,
limit,
} => {
let client = app.specific_client().await?;
let client = DexQueryServiceClient::new(app.pd_channel().await?);
let positions = self
.get_liquidity_positions_by_price(client, *trading_pair, *limit)
.await?
Expand All @@ -425,7 +434,7 @@ impl DexCmd {
println!("{}", render_positions(&asset_cache, &positions));
}
DexCmd::Position { id, raw } => {
let mut client = app.specific_client().await?;
let mut client = DexQueryServiceClient::new(app.pd_channel().await?);
let position: Position = client
.liquidity_position_by_id(LiquidityPositionByIdRequest {
position_id: Some((*id).into()),
Expand Down
Loading

0 comments on commit 964a3d0

Please sign in to comment.