Skip to content

Commit

Permalink
Add an AssetMetadataByIds method to the shielded pool query RPC (#4201)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepinho authored Apr 19, 2024
1 parent 3852420 commit 8d14c47
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/core/component/shielded-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ decaf377 = {workspace = true, features = ["r1cs"], default-features = true}
decaf377-fmd = {workspace = true}
decaf377-ka = {workspace = true}
decaf377-rdsa = {workspace = true}
futures = {workspace = true}
hex = {workspace = true}
ibc-types = {workspace = true, default-features = false}
im = {workspace = true}
Expand Down
14 changes: 14 additions & 0 deletions crates/core/component/shielded-pool/src/component/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::pin::Pin;

use cnidarium::Storage;
use penumbra_asset::asset;
use penumbra_proto::core::component::shielded_pool::v1::{
query_service_server::QueryService, AssetMetadataByIdRequest, AssetMetadataByIdResponse,
AssetMetadataByIdsRequest, AssetMetadataByIdsResponse,
};

use tonic::Status;
Expand All @@ -22,6 +25,10 @@ impl Server {

#[tonic::async_trait]
impl QueryService for Server {
type AssetMetadataByIdsStream = Pin<
Box<dyn futures::Stream<Item = Result<AssetMetadataByIdsResponse, tonic::Status>> + Send>,
>;

#[instrument(skip(self, request))]
async fn asset_metadata_by_id(
&self,
Expand Down Expand Up @@ -53,4 +60,11 @@ impl QueryService for Server {

Ok(tonic::Response::new(rsp))
}

async fn asset_metadata_by_ids(
&self,
_request: tonic::Request<AssetMetadataByIdsRequest>,
) -> Result<tonic::Response<Self::AssetMetadataByIdsStream>, tonic::Status> {
unimplemented!("asset_metadata_by_ids not yet implemented")
}
}
139 changes: 139 additions & 0 deletions crates/proto/src/gen/penumbra.core.component.shielded_pool.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,40 @@ impl ::prost::Name for AssetMetadataByIdResponse {
)
}
}
/// Requests information on an asset by multiple asset ids
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AssetMetadataByIdsRequest {
/// The asset IDs to request information on. Note that node is neither required
/// nor expected to stream responses in the same order as this array.
#[prost(message, repeated, tag = "1")]
pub asset_id: ::prost::alloc::vec::Vec<super::super::super::asset::v1::AssetId>,
}
impl ::prost::Name for AssetMetadataByIdsRequest {
const NAME: &'static str = "AssetMetadataByIdsRequest";
const PACKAGE: &'static str = "penumbra.core.component.shielded_pool.v1";
fn full_name() -> ::prost::alloc::string::String {
::prost::alloc::format!(
"penumbra.core.component.shielded_pool.v1.{}", Self::NAME
)
}
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AssetMetadataByIdsResponse {
/// A single asset metadata streamed from the node.
#[prost(message, optional, tag = "1")]
pub denom_metadata: ::core::option::Option<super::super::super::asset::v1::Metadata>,
}
impl ::prost::Name for AssetMetadataByIdsResponse {
const NAME: &'static str = "AssetMetadataByIdsResponse";
const PACKAGE: &'static str = "penumbra.core.component.shielded_pool.v1";
fn full_name() -> ::prost::alloc::string::String {
::prost::alloc::format!(
"penumbra.core.component.shielded_pool.v1.{}", Self::NAME
)
}
}
/// Generated client implementations.
#[cfg(feature = "rpc")]
pub mod query_service_client {
Expand Down Expand Up @@ -678,6 +712,41 @@ pub mod query_service_client {
);
self.inner.unary(req, path, codec).await
}
/// Requests a stream of asset metadata, given an array of asset IDs. Responses
/// may be streamed in a different order from that of the asset IDs in the
/// request, and asset IDs unknown to the node will not receive any response
/// objects -- that is, the number of responses may be smaller than the length
/// of the asset IDs array.
pub async fn asset_metadata_by_ids(
&mut self,
request: impl tonic::IntoRequest<super::AssetMetadataByIdsRequest>,
) -> std::result::Result<
tonic::Response<tonic::codec::Streaming<super::AssetMetadataByIdsResponse>>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/penumbra.core.component.shielded_pool.v1.QueryService/AssetMetadataByIds",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"penumbra.core.component.shielded_pool.v1.QueryService",
"AssetMetadataByIds",
),
);
self.inner.server_streaming(req, path, codec).await
}
}
}
/// Generated server implementations.
Expand All @@ -695,6 +764,27 @@ pub mod query_service_server {
tonic::Response<super::AssetMetadataByIdResponse>,
tonic::Status,
>;
/// Server streaming response type for the AssetMetadataByIds method.
type AssetMetadataByIdsStream: tonic::codegen::tokio_stream::Stream<
Item = std::result::Result<
super::AssetMetadataByIdsResponse,
tonic::Status,
>,
>
+ Send
+ 'static;
/// Requests a stream of asset metadata, given an array of asset IDs. Responses
/// may be streamed in a different order from that of the asset IDs in the
/// request, and asset IDs unknown to the node will not receive any response
/// objects -- that is, the number of responses may be smaller than the length
/// of the asset IDs array.
async fn asset_metadata_by_ids(
&self,
request: tonic::Request<super::AssetMetadataByIdsRequest>,
) -> std::result::Result<
tonic::Response<Self::AssetMetadataByIdsStream>,
tonic::Status,
>;
}
/// Query operations for the shielded pool component.
#[derive(Debug)]
Expand Down Expand Up @@ -823,6 +913,55 @@ pub mod query_service_server {
};
Box::pin(fut)
}
"/penumbra.core.component.shielded_pool.v1.QueryService/AssetMetadataByIds" => {
#[allow(non_camel_case_types)]
struct AssetMetadataByIdsSvc<T: QueryService>(pub Arc<T>);
impl<
T: QueryService,
> tonic::server::ServerStreamingService<
super::AssetMetadataByIdsRequest,
> for AssetMetadataByIdsSvc<T> {
type Response = super::AssetMetadataByIdsResponse;
type ResponseStream = T::AssetMetadataByIdsStream;
type Future = BoxFuture<
tonic::Response<Self::ResponseStream>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::AssetMetadataByIdsRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as QueryService>::asset_metadata_by_ids(&inner, request)
.await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = AssetMetadataByIdsSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.server_streaming(method, req).await;
Ok(res)
};
Box::pin(fut)
}
_ => {
Box::pin(async move {
Ok(
Expand Down
Loading

0 comments on commit 8d14c47

Please sign in to comment.