Skip to content

Commit

Permalink
pclientd: silly proxy fix workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalence committed Oct 10, 2023
1 parent 1cae217 commit bef01d0
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 18 deletions.
28 changes: 23 additions & 5 deletions crates/bin/pclientd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ use tonic::transport::Server;
use url::Url;

mod proxy;
pub use proxy::{ObliviousQueryProxy, SpecificQueryProxy, TendermintProxyProxy};
pub use proxy::{
AppQueryProxy, ChainQueryProxy, CompactBlockQueryProxy, DexQueryProxy, DexSimulationProxy,
GovernanceQueryProxy, SctQueryProxy, ShieldedPoolQueryProxy, StakeQueryProxy,
TendermintProxyProxy,
};

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -303,8 +307,15 @@ impl Opt {
.connect()
.await?;

let oblivious_query_proxy = ObliviousQueryProxy(proxy_channel.clone());
let specific_query_proxy = SpecificQueryProxy(proxy_channel.clone());
let app_query_proxy = AppQueryProxy(proxy_channel.clone());
let governance_query_proxy = GovernanceQueryProxy(proxy_channel.clone());
let dex_query_proxy = DexQueryProxy(proxy_channel.clone());
let dex_simulation_proxy = DexSimulationProxy(proxy_channel.clone());
let sct_query_proxy = SctQueryProxy(proxy_channel.clone());
let shielded_pool_query_proxy = ShieldedPoolQueryProxy(proxy_channel.clone());
let chain_query_proxy = ChainQueryProxy(proxy_channel.clone());
let stake_query_proxy = StakeQueryProxy(proxy_channel.clone());
let compact_block_query_proxy = CompactBlockQueryProxy(proxy_channel.clone());
let tendermint_proxy_proxy = TendermintProxyProxy(proxy_channel.clone());

let view_service = ViewProtocolServiceServer::new(
Expand All @@ -320,8 +331,15 @@ impl Opt {
.accept_http1(true)
.add_service(tonic_web::enable(view_service))
.add_optional_service(custody_service.map(tonic_web::enable))
.add_service(tonic_web::enable(oblivious_query_proxy))
.add_service(tonic_web::enable(specific_query_proxy))
.add_service(tonic_web::enable(app_query_proxy))
.add_service(tonic_web::enable(governance_query_proxy))
.add_service(tonic_web::enable(dex_query_proxy))
.add_service(tonic_web::enable(dex_simulation_proxy))
.add_service(tonic_web::enable(sct_query_proxy))
.add_service(tonic_web::enable(shielded_pool_query_proxy))
.add_service(tonic_web::enable(chain_query_proxy))
.add_service(tonic_web::enable(stake_query_proxy))
.add_service(tonic_web::enable(compact_block_query_proxy))
.add_service(tonic_web::enable(tendermint_proxy_proxy))
.add_service(tonic_web::enable(
tonic_reflection::server::Builder::configure()
Expand Down
180 changes: 167 additions & 13 deletions crates/bin/pclientd/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ use tonic::{
};
use tower::ServiceExt;

#[derive(Clone)]
pub struct ObliviousQueryProxy(pub Channel);

impl NamedService for ObliviousQueryProxy {
const NAME: &'static str = "penumbra.client.v1alpha1.ObliviousQueryService";
}

fn proxy(
channel: Channel,
req: http::Request<Body>,
Expand Down Expand Up @@ -48,7 +41,168 @@ fn proxy(
.boxed()
}

impl tower::Service<http::Request<Body>> for ObliviousQueryProxy {
#[derive(Clone)]
pub struct AppQueryProxy(pub Channel);

impl NamedService for AppQueryProxy {
const NAME: &'static str = "penumbra.core.app.v1alpha1.QueryService";
}

impl tower::Service<http::Request<Body>> for AppQueryProxy {
type Response = http::Response<BoxBody>;
type Error = Infallible;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn call(&mut self, req: http::Request<Body>) -> Self::Future {
proxy(self.0.clone(), req)
}
}

#[derive(Clone)]
pub struct GovernanceQueryProxy(pub Channel);

impl NamedService for GovernanceQueryProxy {
const NAME: &'static str = "penumbra.core.component.governance.v1alpha1.QueryService";
}

impl tower::Service<http::Request<Body>> for GovernanceQueryProxy {
type Response = http::Response<BoxBody>;
type Error = Infallible;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn call(&mut self, req: http::Request<Body>) -> Self::Future {
proxy(self.0.clone(), req)
}
}

#[derive(Clone)]
pub struct DexQueryProxy(pub Channel);

impl NamedService for DexQueryProxy {
const NAME: &'static str = "penumbra.core.component.dex.v1alpha1.QueryService";
}

impl tower::Service<http::Request<Body>> for DexQueryProxy {
type Response = http::Response<BoxBody>;
type Error = Infallible;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn call(&mut self, req: http::Request<Body>) -> Self::Future {
proxy(self.0.clone(), req)
}
}

#[derive(Clone)]
pub struct DexSimulationProxy(pub Channel);

impl NamedService for DexSimulationProxy {
const NAME: &'static str = "penumbra.core.component.dex.v1alpha1.SimulationService";
}

impl tower::Service<http::Request<Body>> for DexSimulationProxy {
type Response = http::Response<BoxBody>;
type Error = Infallible;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn call(&mut self, req: http::Request<Body>) -> Self::Future {
proxy(self.0.clone(), req)
}
}

#[derive(Clone)]
pub struct SctQueryProxy(pub Channel);

impl NamedService for SctQueryProxy {
const NAME: &'static str = "penumbra.core.component.sct.v1alpha1.QueryService";
}

impl tower::Service<http::Request<Body>> for SctQueryProxy {
type Response = http::Response<BoxBody>;
type Error = Infallible;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn call(&mut self, req: http::Request<Body>) -> Self::Future {
proxy(self.0.clone(), req)
}
}

#[derive(Clone)]
pub struct ShieldedPoolQueryProxy(pub Channel);

impl NamedService for ShieldedPoolQueryProxy {
const NAME: &'static str = "penumbra.core.component.shielded_pool.v1alpha1.QueryService";
}

impl tower::Service<http::Request<Body>> for ShieldedPoolQueryProxy {
type Response = http::Response<BoxBody>;
type Error = Infallible;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn call(&mut self, req: http::Request<Body>) -> Self::Future {
proxy(self.0.clone(), req)
}
}

#[derive(Clone)]
pub struct ChainQueryProxy(pub Channel);

impl NamedService for ChainQueryProxy {
const NAME: &'static str = "penumbra.core.component.chain.v1alpha1.QueryService";
}

impl tower::Service<http::Request<Body>> for ChainQueryProxy {
type Response = http::Response<BoxBody>;
type Error = Infallible;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;

fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn call(&mut self, req: http::Request<Body>) -> Self::Future {
proxy(self.0.clone(), req)
}
}

#[derive(Clone)]
pub struct StakeQueryProxy(pub Channel);

impl NamedService for StakeQueryProxy {
const NAME: &'static str = "penumbra.core.component.stake.v1alpha1.QueryService";
}

impl tower::Service<http::Request<Body>> for StakeQueryProxy {
type Response = http::Response<BoxBody>;
type Error = Infallible;
type Future =
Expand All @@ -64,13 +218,13 @@ impl tower::Service<http::Request<Body>> for ObliviousQueryProxy {
}

#[derive(Clone)]
pub struct SpecificQueryProxy(pub Channel);
pub struct CompactBlockQueryProxy(pub Channel);

impl NamedService for SpecificQueryProxy {
const NAME: &'static str = "penumbra.client.v1alpha1.SpecificQueryService";
impl NamedService for CompactBlockQueryProxy {
const NAME: &'static str = "penumbra.core.component.compact_block.v1alpha1.QueryService";
}

impl tower::Service<http::Request<Body>> for SpecificQueryProxy {
impl tower::Service<http::Request<Body>> for CompactBlockQueryProxy {
type Response = http::Response<BoxBody>;
type Error = Infallible;
type Future =
Expand All @@ -89,7 +243,7 @@ impl tower::Service<http::Request<Body>> for SpecificQueryProxy {
pub struct TendermintProxyProxy(pub Channel);

impl NamedService for TendermintProxyProxy {
const NAME: &'static str = "penumbra.client.v1alpha1.TendermintProxyService";
const NAME: &'static str = "penumbra.util.tendermint_proxy.v1alpha1.TendermintProxyService";
}

impl tower::Service<http::Request<Body>> for TendermintProxyProxy {
Expand Down

0 comments on commit bef01d0

Please sign in to comment.