Merge branch 'develop' of github.com:MetaMask/metamask-extension into network-remove-provider-engine

feature/default_network_editable
kumavis 7 years ago
commit 145016be4c
  1. 22
      app/scripts/controllers/recent-blocks.js

@ -3,7 +3,6 @@ const extend = require('xtend')
const EthQuery = require('eth-query') const EthQuery = require('eth-query')
const log = require('loglevel') const log = require('loglevel')
const pify = require('pify') const pify = require('pify')
const timeout = (duration) => new Promise(resolve => setTimeout(resolve, duration))
class RecentBlocksController { class RecentBlocksController {
@ -123,28 +122,21 @@ class RecentBlocksController {
*/ */
async backfill() { async backfill() {
this.blockTracker.once('latest', async (blockNumberHex) => { this.blockTracker.once('latest', async (blockNumberHex) => {
let recentBlocks const currentBlockNumber = Number.parseInt(blockNumberHex, 16)
let blockNumber = Number.parseInt(blockNumberHex, 16) const blocksToFetch = Math.min(currentBlockNumber, this.historyLength)
let state = this.store.getState() const prevBlockNumber = currentBlockNumber - 1
recentBlocks = state.recentBlocks const targetBlockNumbers = Array(blocksToFetch).fill().map((_, index) => prevBlockNumber - index)
await Promise.all(targetBlockNumbers.map(async (targetBlockNumber) => {
while (recentBlocks.length < this.historyLength) {
try { try {
const prevBlockNumber = blockNumber - 1 const newBlock = await this.getBlockByNumber(targetBlockNumber)
const newBlock = await this.getBlockByNumber(prevBlockNumber)
if (newBlock) { if (newBlock) {
this.backfillBlock(newBlock) this.backfillBlock(newBlock)
blockNumber = Number.parseInt(newBlock.number, 16)
} }
state = this.store.getState()
recentBlocks = state.recentBlocks
} catch (e) { } catch (e) {
log.error(e) log.error(e)
} }
await timeout(100) }))
}
}) })
} }

Loading…
Cancel
Save