Skip to content

Commit

Permalink
Merge pull request #834 from nervosnetwork/fix-check-range
Browse files Browse the repository at this point in the history
fix: not throw when push check range
  • Loading branch information
classicalliu committed Aug 6, 2019
2 parents edc5421 + e2e6c90 commit 5b20d64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions packages/neuron-wallet/src/services/sync/get-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Block[]> => {
const blocks: Block[] = await Promise.all(
blockNumbers.map(async num => {
Expand All @@ -42,7 +41,6 @@ export default class GetBlocks {
})
}

// TODO: if get any error after retry, should pause queue
public retryGetBlock = async (num: string): Promise<Block> => {
const block: Block = await Utils.retry(this.retryTime, this.retryInterval, async () => {
const b: Block = await GetBlocks.getBlockByNumber(num)
Expand Down
10 changes: 7 additions & 3 deletions packages/neuron-wallet/src/services/sync/range-for-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down

0 comments on commit 5b20d64

Please sign in to comment.