Skip to content

Commit

Permalink
fix: restore cpBlocksCache if processing failed (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekhmet authored Sep 27, 2023
1 parent dd393da commit 71473ab
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,10 @@ export default class Checkpoint {
private async next(blockNum: number) {
if (!this.prefetchEndBlock) throw new Error('prefetchEndBlock is not set');

let checkpointBlock;
if (!this.config.disable_checkpoints && !this.config.tx_fn && !this.config.global_events) {
if (blockNum <= this.prefetchEndBlock) {
const checkpointBlock = await this.getNextCheckpointBlock(blockNum);
checkpointBlock = await this.getNextCheckpointBlock(blockNum);

if (checkpointBlock) {
blockNum = checkpointBlock;
Expand Down Expand Up @@ -388,6 +389,10 @@ export default class Checkpoint {
this.log.error({ blockNumber: blockNum, err }, 'error occurred during block processing');
}

if (checkpointBlock && this.cpBlocksCache) {
this.cpBlocksCache.unshift(checkpointBlock);
}

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

0 comments on commit 71473ab

Please sign in to comment.