Skip to content

Commit

Permalink
Rename L1 client lifecycle methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jbearer committed Nov 18, 2024
1 parent 3063e67 commit d4388a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
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
10 changes: 5 additions & 5 deletions types/src/v0/impls/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl RpcClient {
})
}

async fn stop(&self) {
async fn shut_down(&self) {
if let Self::Ws { reconnect, .. } = self {
*reconnect.lock().await = L1ReconnectTask::Cancelled;
}
Expand Down Expand Up @@ -319,7 +319,7 @@ impl L1Client {
}

/// Start the background tasks which keep the L1 client up to date.
pub async fn start(&self) {
pub async fn spawn_tasks(&self) {
let mut update_task = self.update_task.0.lock().await;
if update_task.is_none() {
*update_task = Some(spawn(self.update_loop()));
Expand All @@ -330,11 +330,11 @@ impl L1Client {
///
/// The L1 client will still be usable, but will stop updating until [`start`](Self::start) is
/// called again.
pub async fn stop(&self) {
pub async fn shut_down_tasks(&self) {
if let Some(update_task) = self.update_task.0.lock().await.take() {
update_task.abort();
}
(*self.provider).as_ref().stop().await;
(*self.provider).as_ref().shut_down().await;
}

pub fn provider(&self) -> &impl Middleware<Error: 'static> {
Expand Down Expand Up @@ -794,7 +794,7 @@ mod test {
.await
.unwrap();

client.start().await;
client.spawn_tasks().await;
client
}

Expand Down

0 comments on commit d4388a0

Please sign in to comment.