Skip to content

Commit

Permalink
fix: Do not abort blockstream loop during sync (#10884)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spalladino authored and Maddiaa0 committed Dec 20, 2024
1 parent 133e507 commit 275a2e3
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<L2BlockSource, 'getBlocks' | 'getBlockHeader' | 'getL2Tips'>,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 275a2e3

Please sign in to comment.