diff --git a/.gitignore b/.gitignore index 7eb8fcc..efeefb6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ tests/tmp/** .vscode/*.json /0g-storage-contracts-dev /run/.env + +**.bin diff --git a/Cargo.lock b/Cargo.lock index a74e8c7..571a1e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7015,6 +7015,7 @@ dependencies = [ "tokio", "tonic 0.9.2", "tonic-build", + "tonic-reflection", "tracing", ] @@ -8385,6 +8386,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "tonic-reflection" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0543d7092032041fbeac1f2c84304537553421a11a623c2301b12ef0264862c7" +dependencies = [ + "prost 0.11.9", + "prost-types 0.11.9", + "tokio", + "tokio-stream", + "tonic 0.9.2", +] + [[package]] name = "tower" version = "0.4.13" diff --git a/node/rpc/Cargo.toml b/node/rpc/Cargo.toml index d253ade..664c31d 100644 --- a/node/rpc/Cargo.toml +++ b/node/rpc/Cargo.toml @@ -32,6 +32,7 @@ parking_lot = "0.12.3" tonic = { version = "0.9.2", features = ["transport"] } prost = "0.11.9" prost-types = "0.11.9" +tonic-reflection = "0.9.2" [build-dependencies] tonic-build = "0.9.2" diff --git a/node/rpc/build.rs b/node/rpc/build.rs index 6a7499a..ec93d3f 100644 --- a/node/rpc/build.rs +++ b/node/rpc/build.rs @@ -1,5 +1,7 @@ fn main() -> Result<(), Box> { // Compile proto/my_service.proto - tonic_build::compile_protos("proto/zgs_grpc.proto")?; + tonic_build::configure() + .file_descriptor_set_path("proto/zgs_grpc_descriptor.bin") + .compile(&["proto/zgs_grpc.proto"], &["proto"])?; Ok(()) } diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index 0cc05ca..6218370 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -34,6 +34,9 @@ pub use admin::RpcClient as ZgsAdminRpcClient; pub use config::Config as RPCConfig; pub use miner::RpcClient as ZgsMinerRpcClient; pub use zgs::RpcClient as ZgsRPCClient; +// bring in the reflection-builder +use tonic_reflection::server::Builder as ReflectionBuilder; + pub mod zgs_grpc_proto { tonic::include_proto!("zgs_grpc"); @@ -43,6 +46,8 @@ mod zgs_grpc; use tonic::transport::Server; +const DESCRIPTOR_SET: &[u8] = include_bytes!("../proto/zgs_grpc_descriptor.bin"); + /// A wrapper around all the items required to spawn the HTTP server. /// /// The server will gracefully handle the case where any fields are `None`. @@ -146,9 +151,14 @@ async fn run_server_public_private( pub async fn run_grpc_server(ctx: Context) -> Result<(), Box> { let grpc_addr = ctx.config.listen_address_grpc; + let reflection = ReflectionBuilder::configure() + .register_encoded_file_descriptor_set(DESCRIPTOR_SET) + .build()?; + let server = ZgsGrpcServiceServer::new(ZgsGrpcServiceImpl { ctx }); Server::builder() .add_service(server) + .add_service(reflection) .serve(grpc_addr) .await?; Ok(())