mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge branch 'develop' of github.com:MetaMask/metamask-extension into network-remove-provider-engine
This commit is contained in:
commit
145016be4c
@ -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…
x
Reference in New Issue
Block a user