diff --git a/src/checkpoint.ts b/src/checkpoint.ts index 24a29d7..d6dd1eb 100644 --- a/src/checkpoint.ts +++ b/src/checkpoint.ts @@ -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; } } @@ -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); }