diff options
author | Frankie <frankie.diamond@gmail.com> | 2018-05-23 07:08:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-23 07:08:33 +0800 |
commit | ed01c6c8264a860cdc4248991839954bdf22e2ef (patch) | |
tree | 6eba6e2a49a029f235e5095a3cd5e2a288b7087c /app | |
parent | cee55b47d03006630b1dbe038c6008654ca8f674 (diff) | |
parent | fa37ba39927e5e8a28a98f72a9208170ff0f2900 (diff) | |
download | tangerine-wallet-browser-ed01c6c8264a860cdc4248991839954bdf22e2ef.tar tangerine-wallet-browser-ed01c6c8264a860cdc4248991839954bdf22e2ef.tar.gz tangerine-wallet-browser-ed01c6c8264a860cdc4248991839954bdf22e2ef.tar.bz2 tangerine-wallet-browser-ed01c6c8264a860cdc4248991839954bdf22e2ef.tar.lz tangerine-wallet-browser-ed01c6c8264a860cdc4248991839954bdf22e2ef.tar.xz tangerine-wallet-browser-ed01c6c8264a860cdc4248991839954bdf22e2ef.tar.zst tangerine-wallet-browser-ed01c6c8264a860cdc4248991839954bdf22e2ef.zip |
Merge pull request #4337 from MetaMask/recent-blocks-parallel
controllers - recent-blocks - pull first historical blocks in parallel
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/controllers/recent-blocks.js | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/app/scripts/controllers/recent-blocks.js b/app/scripts/controllers/recent-blocks.js index 1377c1ba9..033ef1d7e 100644 --- a/app/scripts/controllers/recent-blocks.js +++ b/app/scripts/controllers/recent-blocks.js @@ -119,29 +119,21 @@ class RecentBlocksController { */ async backfill() { this.blockTracker.once('block', async (block) => { - let blockNum = block.number - let recentBlocks - let state = this.store.getState() - recentBlocks = state.recentBlocks - - while (recentBlocks.length < this.historyLength) { + const currentBlockNumber = Number.parseInt(block.number, 16) + const blocksToFetch = Math.min(currentBlockNumber, this.historyLength) + const prevBlockNumber = currentBlockNumber - 1 + const targetBlockNumbers = Array(blocksToFetch).fill().map((_, index) => prevBlockNumber - index) + await Promise.all(targetBlockNumbers.map(async (targetBlockNumber) => { try { - let blockNumBn = new BN(blockNum.substr(2), 16) - const newNum = blockNumBn.subn(1).toString(10) - const newBlock = await this.getBlockByNumber(newNum) + const newBlock = await this.getBlockByNumber(targetBlockNumber) if (newBlock) { this.backfillBlock(newBlock) - blockNum = newBlock.number } - - state = this.store.getState() - recentBlocks = state.recentBlocks } catch (e) { log.error(e) } - await this.wait() - } + })) }) } |