From 2cf087389d8287a34cec7437ddd34cfbd101eb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Tkaczy=C5=84ski?= Date: Tue, 30 Jul 2024 09:39:38 +0200 Subject: [PATCH] fix: restore preloaded block on error (#312) When processing preloaded block and error happens we need to put it back into preloadedBlocks array (similar as with checkpoint block). --- src/checkpoint.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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); }