Skip to content

Commit

Permalink
Reconnect L1 WS stream if disconnected (#2287)
Browse files Browse the repository at this point in the history
* Reconnect L1 WS stream if disconnected

Ethers internally tries to reconnect once, but if that fails, it
gives up and shuts down the whole provider backend. This is not
good in the case of extended outages of the L1 server.

This change handles errors from the underlying RPC client indicating
that the connection is closed by spawning a task to reestablish the
connection. This task tries until it succceeds.

* Cancel reconnect task if L1 client is shut down

* Rename L1 client lifecycle methods
  • Loading branch information
jbearer authored Nov 18, 2024
1 parent 57f1493 commit 5ad4da1
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 25 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions sequencer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, V: Versions> Sequence
.set(instance_state.node_id as usize);

// Start L1 client if it isn't already.
instance_state.l1_client.start().await;
instance_state.l1_client.spawn_tasks().await;

// Load saved consensus state from storage.
let (initializer, anchor_view) = persistence
Expand Down Expand Up @@ -325,7 +325,7 @@ impl<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, V: Versions> Sequence
tracing::info!("shutting down SequencerContext");
self.handle.write().await.shut_down().await;
self.tasks.shut_down();
self.node_state.l1_client.stop().await;
self.node_state.l1_client.shut_down_tasks().await;

// Since we've already shut down, we can set `detached` so the drop
// handler doesn't call `shut_down` again.
Expand Down Expand Up @@ -366,7 +366,7 @@ impl<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, V: Versions> Drop
tracing::info!("shutting down SequencerContext");
handle_clone.write().await.shut_down().await;
tasks_clone.shut_down();
node_state_clone.l1_client.stop().await;
node_state_clone.l1_client.shut_down_tasks().await;
});

// Set `detached` so the drop handler doesn't call `shut_down` again.
Expand Down
2 changes: 1 addition & 1 deletion sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ pub async fn init_node<P: PersistenceOptions, V: Versions>(
}

let l1_client = l1_params.options.connect(l1_params.url).await?;
l1_client.start().await;
l1_client.spawn_tasks().await;
let l1_genesis = match genesis.l1_finalized {
L1Finalized::Block(b) => b,
L1Finalized::Number { number } => l1_client.wait_for_finalized_block(number).await,
Expand Down
3 changes: 3 additions & 0 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ tracing = { workspace = true }
url = { workspace = true }
vbs = { workspace = true }

[dev-dependencies]
portpicker = { workspace = true }

[package.metadata.cargo-machete]
ignored = ["base64_bytes", "hotshot_testing"]
Loading

0 comments on commit 5ad4da1

Please sign in to comment.