Skip to content

Commit

Permalink
feat(serve): add gRPC reflection (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Jan 9, 2024
1 parent 9bf4f71 commit 9b6ce5c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
23 changes: 22 additions & 1 deletion Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions src/serve/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)?;
Expand Down

0 comments on commit 9b6ce5c

Please sign in to comment.