mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 09:23:21 +01:00
Increment tx ids to avoid collisions
Fixes #791 It was possible for two requests to have the same ID, causing a crash and loss of StreamProvider connection. This new id generation strategy creates a random ID, and increments it for each request. In case the id generator is included from two different processes, I'm initializing the counter at a random number, and rolling it over a large number when it gets too big.
This commit is contained in:
parent
b0ccde66f6
commit
8eb91e89bf
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## Current Master
|
## Current Master
|
||||||
|
|
||||||
|
- Fix bug that would cause MetaMask to occasionally lose its StreamProvider connection and drop requests.
|
||||||
|
|
||||||
## 2.13.8 2016-11-16
|
## 2.13.8 2016-11-16
|
||||||
|
|
||||||
- Show a warning when a transaction fails during simulation.
|
- Show a warning when a transaction fails during simulation.
|
||||||
|
@ -7,7 +7,7 @@ const EthQuery = require('eth-query')
|
|||||||
const KeyStore = require('eth-lightwallet').keystore
|
const KeyStore = require('eth-lightwallet').keystore
|
||||||
const clone = require('clone')
|
const clone = require('clone')
|
||||||
const extend = require('xtend')
|
const extend = require('xtend')
|
||||||
const createId = require('web3-provider-engine/util/random-id')
|
const createId = require('./random-id')
|
||||||
const ethBinToOps = require('eth-bin-to-ops')
|
const ethBinToOps = require('eth-bin-to-ops')
|
||||||
const autoFaucet = require('./auto-faucet')
|
const autoFaucet = require('./auto-faucet')
|
||||||
const messageManager = require('./message-manager')
|
const messageManager = require('./message-manager')
|
||||||
|
@ -2,6 +2,7 @@ const Streams = require('mississippi')
|
|||||||
const StreamProvider = require('web3-stream-provider')
|
const StreamProvider = require('web3-stream-provider')
|
||||||
const ObjectMultiplex = require('./obj-multiplex')
|
const ObjectMultiplex = require('./obj-multiplex')
|
||||||
const RemoteStore = require('./remote-store.js').RemoteStore
|
const RemoteStore = require('./remote-store.js').RemoteStore
|
||||||
|
const createRandomId = require('./random-id')
|
||||||
|
|
||||||
module.exports = MetamaskInpageProvider
|
module.exports = MetamaskInpageProvider
|
||||||
|
|
||||||
@ -119,16 +120,6 @@ function remoteStoreWithLocalStorageCache (storageKey) {
|
|||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRandomId(){
|
|
||||||
const extraDigits = 3
|
|
||||||
// 13 time digits
|
|
||||||
const datePart = new Date().getTime() * Math.pow(10, extraDigits)
|
|
||||||
// 3 random digits
|
|
||||||
const extraPart = Math.floor(Math.random() * Math.pow(10, extraDigits))
|
|
||||||
// 16 digits
|
|
||||||
return datePart + extraPart
|
|
||||||
}
|
|
||||||
|
|
||||||
function eachJsonMessage(payload, transformFn){
|
function eachJsonMessage(payload, transformFn){
|
||||||
if (Array.isArray(payload)) {
|
if (Array.isArray(payload)) {
|
||||||
return payload.map(transformFn)
|
return payload.map(transformFn)
|
||||||
|
9
app/scripts/lib/random-id.js
Normal file
9
app/scripts/lib/random-id.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
const MAX = 1000000000
|
||||||
|
|
||||||
|
let idCounter = Math.round( Math.random() * MAX )
|
||||||
|
function createRandomId() {
|
||||||
|
idCounter = idCounter % MAX
|
||||||
|
return idCounter++
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = createRandomId
|
Loading…
Reference in New Issue
Block a user