Skip to content

Commit

Permalink
chore(bridge-withdrawer): better grpc client construction (#1528)
Browse files Browse the repository at this point in the history
## Summary
Added error context to sequencer GRPC client construction.

## Background
https://github.com/astriaorg/astria/pull/1510/files#r1766478324

## Changes
- Added helper function for constructing the sequencer GRPC client and
switched from using `Endpoint::new()` to `connect_lazy()`.
- Added error context to sequencer GRPC client construction.

## Testing
Passing all tests

## Related Issues
closes #1527
closes #1542
  • Loading branch information
ethanoroshiba authored Sep 24, 2024
1 parent c1cc5e5 commit 0e889ef
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions crates/astria-bridge-withdrawer/src/bridge_withdrawer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
time::Duration,
};

use astria_core::generated::sequencerblock::v1alpha1::sequencer_service_client;
use astria_core::generated::sequencerblock::v1alpha1::sequencer_service_client::SequencerServiceClient;
use astria_eyre::eyre::{
self,
WrapErr as _,
Expand All @@ -15,6 +15,7 @@ use axum::{
Server,
};
use ethereum::watcher::Watcher;
use http::Uri;
use hyper::server::conn::AddrIncoming;
use startup::Startup;
use tokio::{
Expand Down Expand Up @@ -93,10 +94,10 @@ impl BridgeWithdrawer {
.parse()
.wrap_err("failed to parse sequencer bridge address")?;

let sequencer_grpc_connection =
tonic::transport::Endpoint::new(sequencer_grpc_endpoint)?.connect_lazy();
let sequencer_grpc_client =
sequencer_service_client::SequencerServiceClient::new(sequencer_grpc_connection);
let sequencer_grpc_client = connect_sequencer_grpc(&sequencer_grpc_endpoint)
.wrap_err_with(|| {
format!("failed to connect to Sequencer over gRPC at `{sequencer_grpc_endpoint}`")
})?;
let sequencer_cometbft_client =
sequencer_client::HttpClient::new(&*sequencer_cometbft_endpoint)
.wrap_err("failed constructing cometbft http client")?;
Expand Down Expand Up @@ -466,3 +467,14 @@ pub(crate) fn flatten_result<T>(res: Result<eyre::Result<T>, JoinError>) -> eyre
Err(err) => Err(err).wrap_err("task panicked"),
}
}

fn connect_sequencer_grpc(
sequencer_grpc_endpoint: &str,
) -> eyre::Result<SequencerServiceClient<tonic::transport::Channel>> {
let uri: Uri = sequencer_grpc_endpoint
.parse()
.wrap_err("failed to parse endpoint as URI")?;
Ok(SequencerServiceClient::new(
tonic::transport::Endpoint::from(uri).connect_lazy(),
))
}

0 comments on commit 0e889ef

Please sign in to comment.