Skip to content

Commit

Permalink
fix: restore preloaded block on error
Browse files Browse the repository at this point in the history
When processing preloaded block and error happens we need to put it
back into preloadedBlocks array (similar as with checkpoint block).
  • Loading branch information
Sekhmet committed Jul 29, 2024
1 parent 4855375 commit 9d0a573
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,14 @@ export default class Checkpoint {
}

private async next(blockNum: number) {
let checkpointBlock;
let checkpointBlock, preloadedBlock;
if (!this.config.tx_fn && !this.config.global_events) {
checkpointBlock = await this.getNextCheckpointBlock(blockNum);

if (checkpointBlock) {
blockNum = checkpointBlock;
} else if (blockNum <= this.preloadEndBlock) {
const preloadedBlock = await this.preload(blockNum);
preloadedBlock = await this.preload(blockNum);
blockNum = preloadedBlock || this.preloadEndBlock + 1;
}
}
Expand Down Expand Up @@ -390,6 +390,10 @@ export default class Checkpoint {
this.cpBlocksCache.unshift(checkpointBlock);
}

if (preloadedBlock && this.preloadedBlocks) {
this.preloadedBlocks.unshift(preloadedBlock);
}

await sleep(this.opts?.fetchInterval || DEFAULT_FETCH_INTERVAL);
return this.next(blockNum);
}
Expand Down

0 comments on commit 9d0a573

Please sign in to comment.