Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions yarn-project/archiver/src/modules/l1_synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,28 @@ export class ArchiverL1Synchronizer implements Traceable {

const checkpointsToUnwind = localPendingCheckpointNumber - provenCheckpointNumber;

const checkpointPromises = Array.from({ length: checkpointsToUnwind })
.fill(0)
.map((_, i) => this.store.getCheckpointData(CheckpointNumber(i + pruneFrom)));
const checkpoints = await Promise.all(checkpointPromises);

const blockPromises = await Promise.all(
checkpoints
.filter(isDefined)
.map(cp => this.store.getBlocksForCheckpoint(CheckpointNumber(cp.checkpointNumber))),
);
const newBlocks = blockPromises.filter(isDefined).flat();
// Fetch checkpoints and blocks in bounded batches to avoid unbounded concurrent
// promises when the gap between local pending and proven checkpoint numbers is large.
const BATCH_SIZE = 10;
const newBlocks = [];
for (let offset = 0; offset < checkpointsToUnwind; offset += BATCH_SIZE) {
const batchSize = Math.min(BATCH_SIZE, checkpointsToUnwind - offset);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chunk is your friend here

const checkpoints = (
await Promise.all(
Array.from({ length: batchSize }, (_, i) =>
this.store.getCheckpointData(CheckpointNumber(offset + i + pruneFrom)),
),
)
).filter(isDefined);

const batchBlocks = (
await Promise.all(
checkpoints.map(cp => this.store.getBlocksForCheckpoint(CheckpointNumber(cp.checkpointNumber))),
)
).filter(isDefined);

newBlocks.push(...batchBlocks.flat());
}

// Emit an event for listening services to react to the chain prune
this.events.emit(L2BlockSourceEvents.L2PruneUnproven, {
Expand Down
Loading