diff --git a/Cargo.lock b/Cargo.lock index 24b5952a92..5267d3c629 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -577,6 +577,7 @@ dependencies = [ "tokio-test", "tokio-util 0.7.10", "tonic 0.10.2", + "tonic-health", "tracing", "tryhard", "wiremock", @@ -7824,6 +7825,19 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "tonic-health" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f80db390246dfb46553481f6024f0082ba00178ea495dbb99e70ba9a4fafb5e1" +dependencies = [ + "async-stream", + "prost 0.12.3", + "tokio", + "tokio-stream", + "tonic 0.10.2", +] + [[package]] name = "tower" version = "0.4.13" diff --git a/crates/astria-composer/Cargo.toml b/crates/astria-composer/Cargo.toml index cb65d26d01..7cfabc0603 100644 --- a/crates/astria-composer/Cargo.toml +++ b/crates/astria-composer/Cargo.toml @@ -50,6 +50,7 @@ tracing = { workspace = true, features = ["attributes"] } tryhard = { workspace = true } tonic = "0.10.2" tokio-stream = { version = "0.1.14", features = ["net"] } +tonic-health = "0.10.2" [dependencies.sequencer-client] package = "astria-sequencer-client" diff --git a/crates/astria-composer/src/collectors/grpc.rs b/crates/astria-composer/src/collectors/grpc.rs index e7f78741cd..cdf50aeb93 100644 --- a/crates/astria-composer/src/collectors/grpc.rs +++ b/crates/astria-composer/src/collectors/grpc.rs @@ -37,7 +37,10 @@ use tonic::{ Response, }; -use crate::executor; +use crate::{ + executor, + executor::Handle, +}; /// `GrpcCollector` listens for incoming gRPC requests and sends the Rollup transactions to the /// Executor. The Executor then sends the transactions to the Astria Shared Sequencer. @@ -65,7 +68,7 @@ impl Grpc { }) } - /// Returns the socker address the grpc collector is served over + /// Returns the socket address the grpc collector is served over /// # Errors /// Returns an error if the listener is not bound pub(crate) fn local_addr(&self) -> io::Result { @@ -73,8 +76,16 @@ impl Grpc { } pub(crate) async fn run_until_stopped(self) -> eyre::Result<()> { + let (mut health_reporter, health_service) = tonic_health::server::health_reporter(); + let composer_service = GrpcCollectorServiceServer::new(self.executor_handle); - let grpc_server = tonic::transport::Server::builder().add_service(composer_service); + let grpc_server = tonic::transport::Server::builder() + .add_service(health_service) + .add_service(composer_service); + + health_reporter + .set_serving::>() + .await; grpc_server .serve_with_incoming(tokio_stream::wrappers::TcpListenerStream::new( diff --git a/crates/astria-composer/src/composer.rs b/crates/astria-composer/src/composer.rs index f615d24f49..2edc3c3381 100644 --- a/crates/astria-composer/src/composer.rs +++ b/crates/astria-composer/src/composer.rs @@ -169,7 +169,7 @@ impl Composer { executor_handle, mut geth_collector_tasks, mut geth_collectors, - rollup_id_to_url: rollups, + rollup_id_to_url, mut geth_collector_statuses, grpc_collector, } = self; @@ -222,7 +222,7 @@ impl Composer { &mut geth_collector_statuses, &mut geth_collector_tasks, executor_handle.clone(), - &rollups, + &rollup_id_to_url, rollup, collector_exit, );