penumbra_sdk_app/
rpc.rs

1mod query;
2
3// TODO: Once we migrate to Tonic 0.10.0, we'll be able to use the `Routes` structure to have each
4// component define a method that returns a `Routes` with all of its query services bundled inside.
5//
6// This means we won't have to import all this shit and recite every single service -- we can e.g.,
7// have the app crate assemble all of its components' query services into a single `Routes` and
8// then just add that to the gRPC server.
9use {
10    self::query::AppQueryServer,
11    crate::PenumbraHost,
12    anyhow::Context,
13    cnidarium::proto::v1::query_service_server::QueryServiceServer as StorageQueryServiceServer,
14    cnidarium::rpc::Server as StorageServer,
15    ibc_proto::{
16        cosmos::bank::v1beta1::query_server::QueryServer as TransferQueryServer,
17        ibc::{
18            applications::transfer::v1::query_server::QueryServer as BankQueryServer,
19            core::{
20                channel::v1::query_server::QueryServer as ChannelQueryServer,
21                client::v1::query_server::QueryServer as ClientQueryServer,
22                connection::v1::query_server::QueryServer as ConnectionQueryServer,
23            },
24        },
25    },
26    penumbra_sdk_auction::component::rpc::Server as AuctionServer,
27    penumbra_sdk_community_pool::component::rpc::Server as CommunityPoolServer,
28    penumbra_sdk_compact_block::component::rpc::Server as CompactBlockServer,
29    penumbra_sdk_dex::component::rpc::Server as DexServer,
30    penumbra_sdk_fee::component::rpc::Server as FeeServer,
31    penumbra_sdk_governance::component::rpc::Server as GovernanceServer,
32    penumbra_sdk_proto::{
33        core::{
34            app::v1::query_service_server::QueryServiceServer as AppQueryServiceServer,
35            component::{
36                auction::v1::query_service_server::QueryServiceServer as AuctionQueryServiceServer,
37                community_pool::v1::query_service_server::QueryServiceServer as CommunityPoolQueryServiceServer,
38                compact_block::v1::query_service_server::QueryServiceServer as CompactBlockQueryServiceServer,
39                dex::v1::{
40                    query_service_server::QueryServiceServer as DexQueryServiceServer,
41                    simulation_service_server::SimulationServiceServer,
42                },
43                fee::v1::query_service_server::QueryServiceServer as FeeQueryServiceServer,
44                governance::v1::query_service_server::QueryServiceServer as GovernanceQueryServiceServer,
45                sct::v1::query_service_server::QueryServiceServer as SctQueryServiceServer,
46                shielded_pool::v1::query_service_server::QueryServiceServer as ShieldedPoolQueryServiceServer,
47                stake::v1::query_service_server::QueryServiceServer as StakeQueryServiceServer,
48            },
49        },
50        util::tendermint_proxy::v1::tendermint_proxy_service_server::{
51            TendermintProxyService, TendermintProxyServiceServer,
52        },
53    },
54    penumbra_sdk_sct::component::rpc::Server as SctServer,
55    penumbra_sdk_shielded_pool::component::rpc::Server as ShieldedPoolServer,
56    penumbra_sdk_stake::component::rpc::Server as StakeServer,
57    tonic::service::Routes,
58    tonic_web::enable as we,
59};
60
61pub fn routes(
62    storage: &cnidarium::Storage,
63    tm_proxy: impl TendermintProxyService,
64    _enable_expensive_rpc: bool,
65) -> anyhow::Result<tonic::service::Routes> {
66    let ibc = penumbra_sdk_ibc::component::rpc::IbcQuery::<PenumbraHost>::new(storage.clone());
67
68    let mut builder = Routes::builder();
69    builder
70        // As part of #2932, we are disabling all timeouts until we circle back to our
71        // performance story.
72        // Sets a timeout for all gRPC requests, but note that in the case of streaming
73        // requests, the timeout is only applied to the initial request. This means that
74        // this does not prevent long lived streams, for example to allow clients to obtain
75        // new blocks.
76        // .timeout(std::time::Duration::from_secs(7))
77        // Wrap each of the gRPC services in a tonic-web proxy:
78        .add_service(we(StorageQueryServiceServer::new(StorageServer::new(
79            storage.clone(),
80        ))))
81        .add_service(we(AuctionQueryServiceServer::new(AuctionServer::new(
82            storage.clone(),
83        ))))
84        .add_service(we(AppQueryServiceServer::new(AppQueryServer::new(
85            storage.clone(),
86        ))))
87        .add_service(we(CompactBlockQueryServiceServer::new(
88            CompactBlockServer::new(storage.clone()),
89        )))
90        .add_service(we(DexQueryServiceServer::new(DexServer::new(
91            storage.clone(),
92        ))))
93        .add_service(we(FeeQueryServiceServer::new(FeeServer::new(
94            storage.clone(),
95        ))))
96        .add_service(we(GovernanceQueryServiceServer::new(
97            GovernanceServer::new(storage.clone()),
98        )))
99        .add_service(we(SctQueryServiceServer::new(SctServer::new(
100            storage.clone(),
101        ))))
102        .add_service(we(ShieldedPoolQueryServiceServer::new(
103            ShieldedPoolServer::new(storage.clone()),
104        )))
105        .add_service(we(TransferQueryServer::new(ShieldedPoolServer::new(
106            storage.clone(),
107        ))))
108        .add_service(we(BankQueryServer::new(ShieldedPoolServer::new(
109            storage.clone(),
110        ))))
111        .add_service(we(CommunityPoolQueryServiceServer::new(
112            CommunityPoolServer::new(storage.clone()),
113        )))
114        .add_service(we(StakeQueryServiceServer::new(StakeServer::new(
115            storage.clone(),
116        ))))
117        .add_service(we(ClientQueryServer::new(ibc.clone())))
118        .add_service(we(ChannelQueryServer::new(ibc.clone())))
119        .add_service(we(ConnectionQueryServer::new(ibc.clone())))
120        .add_service(we(TendermintProxyServiceServer::new(tm_proxy)))
121        .add_service(we(SimulationServiceServer::new(DexServer::new(
122            storage.clone(),
123        ))))
124        .add_service(we(tonic_reflection::server::Builder::configure()
125            .register_encoded_file_descriptor_set(penumbra_sdk_proto::FILE_DESCRIPTOR_SET)
126            .build_v1()
127            .with_context(|| "could not configure grpc reflection service")?));
128    Ok(builder.routes().prepare())
129}