From 275a2e344c12fb1d75206261c763c0daedfb6916 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 19 Dec 2024 13:24:32 -0300 Subject: [PATCH] fix: Do not abort blockstream loop during sync (#10884) The L2 blockstream is expected to download blocks continuously until reaching the source's block number. However, to exit from that loop when the service is stopped, we continuously check for the isRunning flag and abort if it is not set. This means that in a sync, which happens outside the running loop, we end up cutting that loop short. This provides a quick and dirty fix for that. --- .../src/l2_block_downloader/l2_block_stream.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/yarn-project/circuit-types/src/l2_block_downloader/l2_block_stream.ts b/yarn-project/circuit-types/src/l2_block_downloader/l2_block_stream.ts index 10724c9b545..7597f27c284 100644 --- a/yarn-project/circuit-types/src/l2_block_downloader/l2_block_stream.ts +++ b/yarn-project/circuit-types/src/l2_block_downloader/l2_block_stream.ts @@ -8,6 +8,7 @@ import { type L2BlockId, type L2BlockSource, type L2Tips } from '../l2_block_sou /** Creates a stream of events for new blocks, chain tips updates, and reorgs, out of polling an archiver or a node. */ export class L2BlockStream { private readonly runningPromise: RunningPromise; + private isSyncing = false; constructor( private l2BlockSource: Pick, @@ -37,8 +38,10 @@ export class L2BlockStream { return this.runningPromise.isRunning(); } - public sync() { - return this.runningPromise.trigger(); + public async sync() { + this.isSyncing = true; + await this.runningPromise.trigger(); + this.isSyncing = false; } protected async work() { @@ -132,7 +135,7 @@ export class L2BlockStream { `Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.blockNumber})`, ); await this.handler.handleBlockStreamEvent(event); - if (!this.isRunning()) { + if (!this.isRunning() && !this.isSyncing) { throw new AbortError(); } }