Skip to content

Commit e2e6c90

Browse files
committed
fix: not throw when push check range
1 parent 8d7c45f commit e2e6c90

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

packages/neuron-wallet/src/services/sync/get-blocks.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export default class GetBlocks {
2424
this.retryInterval = retryInterval
2525
}
2626

27-
// TODO: if retryGetBlock() failed, this will also failed
2827
public getRangeBlocks = async (blockNumbers: string[]): Promise<Block[]> => {
2928
const blocks: Block[] = await Promise.all(
3029
blockNumbers.map(async num => {
@@ -42,7 +41,6 @@ export default class GetBlocks {
4241
})
4342
}
4443

45-
// TODO: if get any error after retry, should pause queue
4644
public retryGetBlock = async (num: string): Promise<Block> => {
4745
const block: Block = await Utils.retry(this.retryTime, this.retryInterval, async () => {
4846
const b: Block = await GetBlocks.getBlockByNumber(num)

packages/neuron-wallet/src/services/sync/range-for-check.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ export default class RangeForCheck {
4747
const lastBlockHeader = this.range[this.range.length - 1]
4848
const firstBlockHeader = range[0]
4949
if (lastBlockHeader.hash !== firstBlockHeader.parentHash) {
50-
// TODO: should re generate range here, should ensure currentBlockNumber before
51-
throw new Error('not match')
50+
this.clearRange()
51+
return
5252
}
5353
}
54-
this.range = this.range.slice(range.length).concat(range)
54+
if (this.range.length >= this.checkSize) {
55+
this.range = this.range.slice(range.length).concat(range)
56+
} else {
57+
this.range = this.range.concat(range)
58+
}
5559
}
5660

5761
public check = (blockHeaders: BlockHeader[]) => {

0 commit comments

Comments
 (0)