From 9b6ce5c4c0d7a3fb682cff15a15ac054bd4203f6 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Tue, 9 Jan 2024 12:05:21 -0300 Subject: [PATCH] feat(serve): add gRPC reflection (#147) --- Cargo.lock | 23 ++++++++++++++++++++++- Cargo.toml | 6 ++++-- src/serve/grpc/mod.rs | 8 ++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3c321b0..7b01e222 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -303,7 +303,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ "bitcoin_hashes", - "rand_core 0.5.1", + "rand_core 0.6.4", "serde", "unicode-normalization", ] @@ -797,6 +797,7 @@ dependencies = [ "miette", "mithril-client", "pallas", + "protoc-wkt", "rocksdb", "serde", "serde_json", @@ -806,6 +807,7 @@ dependencies = [ "tokio", "tokio-stream", "tonic", + "tonic-reflection", "tonic-web", "tracing", "tracing-subscriber", @@ -2375,6 +2377,12 @@ dependencies = [ "prost", ] +[[package]] +name = "protoc-wkt" +version = "1.0.0+3.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1d0fdc23ea945d58449259496ba12d3b520da1a45ce5011f631c990add9029" + [[package]] name = "quote" version = "1.0.33" @@ -3345,6 +3353,19 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic-reflection" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0543d7092032041fbeac1f2c84304537553421a11a623c2301b12ef0264862c7" +dependencies = [ + "prost", + "prost-types", + "tokio", + "tokio-stream", + "tonic", +] + [[package]] name = "tonic-web" version = "0.9.2" diff --git a/Cargo.toml b/Cargo.toml index 557e6ed5..698fabae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,15 +37,17 @@ bincode = "1.3.3" miette = { version = "5.9.0", features = ["fancy"] } tokio = { version = "1.28.2", features = ["rt", "rt-multi-thread"] } async-trait = "0.1.68" -tonic = { version = "0.9.2", features = ["tls"] } +tonic = { version = "^0.9", features = ["tls"] } +tonic-web = "^0.9" +tonic-reflection = "^0.9" bytes = "1.4.0" futures-core = "0.3.28" -tonic-web = "0.9.2" tokio-stream = { version = "0.1.14", features = ["sync"] } futures-util = "0.3.28" async-stream = "0.3.5" serde_with = "3.4.0" mithril-client = { version = "0.5.7", optional = true } +protoc-wkt = "1.0.0" [dev-dependencies] tempfile = "3.3.0" diff --git a/src/serve/grpc/mod.rs b/src/serve/grpc/mod.rs index 18b66d03..632032c6 100644 --- a/src/serve/grpc/mod.rs +++ b/src/serve/grpc/mod.rs @@ -22,6 +22,13 @@ pub async fn serve(config: Config, wal: wal::Store, chain: chain::Store) -> Resu let service = sync::ChainSyncServiceImpl::new(wal, chain); let service = ChainSyncServiceServer::new(service); + let reflection = tonic_reflection::server::Builder::configure() + .register_encoded_file_descriptor_set(utxorpc::proto::cardano::v1::FILE_DESCRIPTOR_SET) + .register_encoded_file_descriptor_set(utxorpc::proto::sync::v1::FILE_DESCRIPTOR_SET) + .register_encoded_file_descriptor_set(protoc_wkt::google::protobuf::FILE_DESCRIPTOR_SET) + .build() + .unwrap(); + let mut server = Server::builder().accept_http1(true); if let Some(pem) = config.tls_client_ca_root { @@ -39,6 +46,7 @@ pub async fn serve(config: Config, wal: wal::Store, chain: chain::Store) -> Resu server // GrpcWeb is over http1 so we must enable it. .add_service(tonic_web::enable(service)) + .add_service(reflection) .serve(addr) .await .map_err(Error::server)?;