Fast forward the block fetching if backend has been offline for a while.

This commit is contained in:
softsimon 2020-03-03 15:11:14 +07:00
parent 4ae6b982e0
commit 2b9be35afa

View file

@ -32,6 +32,11 @@ class Blocks {
this.currentBlockHeight = this.blocks[this.blocks.length - 1].height; 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) { while (this.currentBlockHeight < blockHeightTip) {
if (this.currentBlockHeight === 0) { if (this.currentBlockHeight === 0) {
this.currentBlockHeight = blockHeightTip; this.currentBlockHeight = blockHeightTip;