Skip to content

Commit

Permalink
fix(conductor): keep wsclient alive (#762)
Browse files Browse the repository at this point in the history
## Summary
Updates to keep the client alive so that the subscription is kept alive.

## Background
Websocket connection was terminated after retry return, causing
subscription to fail.

## Changes
- Return both subscription + client when subscribing to celestia
headers.

## Testing
Built and manually run in dev-cluster
  • Loading branch information
joroshiba authored Feb 16, 2024
1 parent 4418df6 commit 37b52f5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/astria-conductor/src/celestia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl Reader {
"setting up celestia reader",
);

let mut headers =
let (mut _wsclient, mut headers) =
subscribe_to_celestia_headers(&self.celestia_ws_endpoint, &self.celestia_auth_token)
.await
.wrap_err("failed to subscribe to celestia headers")?;
Expand Down Expand Up @@ -241,7 +241,7 @@ impl Reader {

new_subscription = &mut resubscribing, if !resubscribing.is_terminated() => {
match new_subscription {
Ok(new_subscription) => headers = new_subscription,
Ok(new_subscription) => (_wsclient, headers) = new_subscription,
Err(e) => return Err(e).wrap_err("resubscribing to celestia headers ultimately failed"),
}
}
Expand Down Expand Up @@ -565,7 +565,7 @@ impl SequencerHeightToCelestiaHeight {
async fn subscribe_to_celestia_headers(
endpoint: &str,
token: &str,
) -> eyre::Result<Subscription<ExtendedHeader>> {
) -> eyre::Result<(WsClient, Subscription<ExtendedHeader>)> {
use celestia_client::celestia_rpc::HeaderClient as _;

async fn connect(endpoint: &str, token: &str) -> Result<WsClient, celestia_rpc::Error> {
Expand Down Expand Up @@ -597,10 +597,11 @@ async fn subscribe_to_celestia_headers(
let client = connect(endpoint, token)
.await
.wrap_err("failed to connect to Celestia Websocket RPC")?;
client
let headers = client
.header_subscribe()
.await
.wrap_err("failed to subscribe to Celestia headers")
.wrap_err("failed to subscribe to Celestia headers")?;
Ok((client, headers))
})
.with_config(retry_config)
.await
Expand Down

0 comments on commit 37b52f5

Please sign in to comment.