From e2e6c9097ea628f5d9c7cd8ddf29eab78d8cf8da Mon Sep 17 00:00:00 2001 From: classicalliu Date: Tue, 6 Aug 2019 19:16:56 +0800 Subject: [PATCH] fix: not throw when push check range --- packages/neuron-wallet/src/services/sync/get-blocks.ts | 2 -- .../neuron-wallet/src/services/sync/range-for-check.ts | 10 +++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/neuron-wallet/src/services/sync/get-blocks.ts b/packages/neuron-wallet/src/services/sync/get-blocks.ts index d18e10a0f0..5d639958c5 100644 --- a/packages/neuron-wallet/src/services/sync/get-blocks.ts +++ b/packages/neuron-wallet/src/services/sync/get-blocks.ts @@ -24,7 +24,6 @@ export default class GetBlocks { this.retryInterval = retryInterval } - // TODO: if retryGetBlock() failed, this will also failed public getRangeBlocks = async (blockNumbers: string[]): Promise => { const blocks: Block[] = await Promise.all( blockNumbers.map(async num => { @@ -42,7 +41,6 @@ export default class GetBlocks { }) } - // TODO: if get any error after retry, should pause queue public retryGetBlock = async (num: string): Promise => { const block: Block = await Utils.retry(this.retryTime, this.retryInterval, async () => { const b: Block = await GetBlocks.getBlockByNumber(num) diff --git a/packages/neuron-wallet/src/services/sync/range-for-check.ts b/packages/neuron-wallet/src/services/sync/range-for-check.ts index 140f2bf96e..1b22790737 100644 --- a/packages/neuron-wallet/src/services/sync/range-for-check.ts +++ b/packages/neuron-wallet/src/services/sync/range-for-check.ts @@ -47,11 +47,15 @@ export default class RangeForCheck { const lastBlockHeader = this.range[this.range.length - 1] const firstBlockHeader = range[0] if (lastBlockHeader.hash !== firstBlockHeader.parentHash) { - // TODO: should re generate range here, should ensure currentBlockNumber before - throw new Error('not match') + this.clearRange() + return } } - this.range = this.range.slice(range.length).concat(range) + if (this.range.length >= this.checkSize) { + this.range = this.range.slice(range.length).concat(range) + } else { + this.range = this.range.concat(range) + } } public check = (blockHeaders: BlockHeader[]) => {