From c5432da567b9953c1294e0bf598a0310127bf808 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 20 May 2017 20:37:47 -0700 Subject: [PATCH 1/7] Add new streaming subprovider but getting a loop Regarding #1458 Uses a new streaming subprovider architecture on an experimental branch of StreamProvider: https://github.com/flyswatter/web3-stream-provider/tree/StreamSubprovider --- app/scripts/lib/inpage-provider.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index e5e398e24..88d81cca5 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -1,5 +1,6 @@ const pipe = require('pump') -const StreamProvider = require('web3-stream-provider') +const StreamSubprovider = require('web3-stream-provider/stream-subprovider') +const ProviderEngine = require('web3-provider-engine') const LocalStorageStore = require('obs-store') const ObjectMultiplex = require('./obj-multiplex') const createRandomId = require('./random-id') @@ -27,14 +28,21 @@ function MetamaskInpageProvider (connectionStream) { ) // connect to async provider - const asyncProvider = self.asyncProvider = new StreamProvider() + const engine = self.asyncProvider = new ProviderEngine() + + const stream = self.stream = new StreamSubprovider() + engine.addProvider(stream) + pipe( - asyncProvider, + stream, multiStream.createStream('provider'), - asyncProvider, + stream, (err) => logStreamDisconnectWarning('MetaMask RpcProvider', err) ) + // start polling + engine.start() + self.idMap = {} // handle sendAsync requests via asyncProvider self.sendAsync = function (payload, cb) { @@ -46,7 +54,9 @@ function MetamaskInpageProvider (connectionStream) { return message }) // forward to asyncProvider - asyncProvider.sendAsync(request, function (err, res) { + console.log('sending async to engine', request) + engine.sendAsync(request, function (err, res) { + console.log('send async returned !!', err, res) if (err) return cb(err) // transform messages to original ids eachJsonMessage(res, (message) => { From 709c0eb307e2cda9aa16b67191a43e99e1b22fa0 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 22 May 2017 15:21:25 -0700 Subject: [PATCH 2/7] Use stream-provider v3 api --- app/scripts/popup-core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/popup-core.js b/app/scripts/popup-core.js index f1eb394d7..7de1a6fda 100644 --- a/app/scripts/popup-core.js +++ b/app/scripts/popup-core.js @@ -29,9 +29,9 @@ function connectToAccountManager (connectionStream, cb) { function setupWeb3Connection (connectionStream) { var providerStream = new StreamProvider() - providerStream.pipe(connectionStream).pipe(providerStream) + providerStream.stream.pipe(connectionStream).pipe(providerStream.stream) connectionStream.on('error', console.error.bind(console)) - providerStream.on('error', console.error.bind(console)) + providerStream.stream.on('error', console.error.bind(console)) global.ethereumProvider = providerStream global.ethQuery = new EthQuery(providerStream) } From 48d9a2107130e3850077c6c1789b29a09634b168 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 22 May 2017 15:23:29 -0700 Subject: [PATCH 3/7] Use filter subprovider in-page to avoid filter leaks --- app/scripts/lib/inpage-provider.js | 8 ++++++-- package.json | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 88d81cca5..9dea05dbb 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -1,6 +1,7 @@ const pipe = require('pump') -const StreamSubprovider = require('web3-stream-provider/stream-subprovider') const ProviderEngine = require('web3-provider-engine') +const FilterSubprovider = require('web3-provider-engine/subproviders/filters') +const StreamSubprovider = require('web3-stream-provider/stream-subprovider') const LocalStorageStore = require('obs-store') const ObjectMultiplex = require('./obj-multiplex') const createRandomId = require('./random-id') @@ -28,7 +29,10 @@ function MetamaskInpageProvider (connectionStream) { ) // connect to async provider - const engine = self.asyncProvider = new ProviderEngine() + const engine = new ProviderEngine() + + const filterSubprovider = new FilterSubprovider() + engine.addProvider(filterSubprovider) const stream = self.stream = new StreamSubprovider() engine.addProvider(stream) diff --git a/package.json b/package.json index 14ddd2886..5512fa6a4 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,7 @@ "vreme": "^3.0.2", "web3": "0.18.2", "web3-provider-engine": "^12.0.6", - "web3-stream-provider": "^2.0.6", + "web3-stream-provider": "^3.0.0", "xtend": "^4.0.1" }, "devDependencies": { From 39f9ffa18ab76fe154f9d5d4b3b2e5631d95fdc4 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 22 May 2017 15:25:31 -0700 Subject: [PATCH 4/7] Bump changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 371b348ca..c31f26f04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Master +- Fix bug where website filters would pile up and not deallocate when leaving a site. + ## 3.6.5 2017-5-17 - Fix bug where edited gas parameters would not take effect. From cbfaa6f56f685d515e170de2bf305da76b8ec1e0 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 22 May 2017 15:41:13 -0700 Subject: [PATCH 5/7] Rename stream to streamSubprovider --- app/scripts/lib/inpage-provider.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 9dea05dbb..3b60756b9 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -34,13 +34,13 @@ function MetamaskInpageProvider (connectionStream) { const filterSubprovider = new FilterSubprovider() engine.addProvider(filterSubprovider) - const stream = self.stream = new StreamSubprovider() - engine.addProvider(stream) + const streamSubprovider = new StreamSubprovider() + engine.addProvider(streamSubprovider) pipe( - stream, + streamSubprovider, multiStream.createStream('provider'), - stream, + streamSubprovider, (err) => logStreamDisconnectWarning('MetaMask RpcProvider', err) ) From 1c1400b584a97e05e3f39748e5f44f076328d89b Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 22 May 2017 15:59:07 -0700 Subject: [PATCH 6/7] deps - use stream-subprovider from provider-engine --- app/scripts/lib/inpage-provider.js | 2 +- app/scripts/popup-core.js | 4 ++-- package.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 3b60756b9..d24121ade 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -1,7 +1,7 @@ const pipe = require('pump') const ProviderEngine = require('web3-provider-engine') const FilterSubprovider = require('web3-provider-engine/subproviders/filters') -const StreamSubprovider = require('web3-stream-provider/stream-subprovider') +const StreamSubprovider = require('web3-provider-engine/subproviders/stream') const LocalStorageStore = require('obs-store') const ObjectMultiplex = require('./obj-multiplex') const createRandomId = require('./random-id') diff --git a/app/scripts/popup-core.js b/app/scripts/popup-core.js index 7de1a6fda..f1eb394d7 100644 --- a/app/scripts/popup-core.js +++ b/app/scripts/popup-core.js @@ -29,9 +29,9 @@ function connectToAccountManager (connectionStream, cb) { function setupWeb3Connection (connectionStream) { var providerStream = new StreamProvider() - providerStream.stream.pipe(connectionStream).pipe(providerStream.stream) + providerStream.pipe(connectionStream).pipe(providerStream) connectionStream.on('error', console.error.bind(console)) - providerStream.stream.on('error', console.error.bind(console)) + providerStream.on('error', console.error.bind(console)) global.ethereumProvider = providerStream global.ethQuery = new EthQuery(providerStream) } diff --git a/package.json b/package.json index 5512fa6a4..dba82d17c 100644 --- a/package.json +++ b/package.json @@ -121,8 +121,8 @@ "valid-url": "^1.0.9", "vreme": "^3.0.2", "web3": "0.18.2", - "web3-provider-engine": "^12.0.6", - "web3-stream-provider": "^3.0.0", + "web3-provider-engine": "^12.1.0", + "web3-stream-provider": "^2.0.6", "xtend": "^4.0.1" }, "devDependencies": { From b217ad1ae8109e9648da948bde06cdc88317396a Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 22 May 2017 16:06:22 -0700 Subject: [PATCH 7/7] clean - remove console logs --- app/scripts/lib/inpage-provider.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index d24121ade..e54f547bd 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -58,9 +58,7 @@ function MetamaskInpageProvider (connectionStream) { return message }) // forward to asyncProvider - console.log('sending async to engine', request) engine.sendAsync(request, function (err, res) { - console.log('send async returned !!', err, res) if (err) return cb(err) // transform messages to original ids eachJsonMessage(res, (message) => {