From 2b9be35afaa49a10493763f61cc681c71c199a82 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 3 Mar 2020 15:11:14 +0700 Subject: [PATCH] Fast forward the block fetching if backend has been offline for a while. --- backend/src/api/blocks.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index 89a719ace..018c78c4b 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -32,6 +32,11 @@ class Blocks { this.currentBlockHeight = this.blocks[this.blocks.length - 1].height; } + if (blockHeightTip - this.currentBlockHeight > config.INITIAL_BLOCK_AMOUNT * 2) { + console.log(`${blockHeightTip - this.currentBlockHeight} blocks since tip. Fast forwarding to the ${config.INITIAL_BLOCK_AMOUNT} recent blocks`); + this.currentBlockHeight = blockHeightTip - config.INITIAL_BLOCK_AMOUNT; + } + while (this.currentBlockHeight < blockHeightTip) { if (this.currentBlockHeight === 0) { this.currentBlockHeight = blockHeightTip;