Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved subscribe and filter into network controller #16693

Merged
merged 6 commits into from
Dec 20, 2022

Conversation

BelfordZ
Copy link
Contributor

@BelfordZ BelfordZ commented Nov 25, 2022

Our middleware for handling subscription and filter-related methods (eth-json-rpc-filters) currently lives in our RPC pipeline ahead of the network stack. This commit moves this middleware to the network client middleware instead. There are two reasons for this change. First, this middleware wraps RPC methods that are supported by the network. Second, it is necessary for this middleware to live with the network client so that it will aid us in unifying the NetworkController in this repo and the NetworkController in the controllers repo.


Fixes: #16573

@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot
Copy link
Collaborator

Builds ready [6ad94ca]
Page Load Metrics (1988 ± 107 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint93142110136
domContentLoaded156422891964212102
load156423581988222107
domInteractive156422881964212102
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 554 bytes
  • ui: 0 bytes
  • common: 0 bytes

@BelfordZ BelfordZ force-pushed the fix/sub-filter-into-network branch from 6ad94ca to 4f2b0d0 Compare November 25, 2022 21:00
@BelfordZ BelfordZ force-pushed the fix/sub-filter-into-network branch from 4f2b0d0 to fc3011a Compare November 25, 2022 21:01
@metamaskbot
Copy link
Collaborator

Builds ready [fc3011a]
Page Load Metrics (2242 ± 138 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1121881402110
domContentLoaded159226592235288138
load159226592242288138
domInteractive159226592235288138
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 554 bytes
  • ui: 0 bytes
  • common: 0 bytes

@BelfordZ BelfordZ requested a review from Gudahtt November 29, 2022 17:39
@BelfordZ BelfordZ marked this pull request as ready for review November 29, 2022 18:34
@BelfordZ BelfordZ requested a review from a team as a code owner November 29, 2022 18:34
Gudahtt
Gudahtt previously approved these changes Dec 6, 2022
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Though we should manually test that this works (I haven't done that yet). I don't think these methods are covered by any e2e tests or our test dapp, unfortunately.

app/scripts/controllers/network/createJsonRpcClient.js Outdated Show resolved Hide resolved
@Gudahtt Gudahtt added the needs-qa Label will automate into QA workspace label Dec 6, 2022
@Gudahtt
Copy link
Member

Gudahtt commented Dec 8, 2022

We should come up with test instructions so that QA has something to go by.

mcmire
mcmire previously requested changes Dec 9, 2022
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything that we add to the network client files we need to make sure is covered in the network client integration tests.

I can work on this.

@Gudahtt
Copy link
Member

Gudahtt commented Dec 9, 2022

I agree that we need tests. It looks like mobile supports these methods via web3-provider-engine, they're part of the provider mobile uses from that package. So perhaps we can consider adding tests as a blocker for replacing web3-provider-engine.

I don't think it needs to block this PR though. The network client tests are already not exhaustive.

@mcmire
Copy link
Contributor

mcmire commented Dec 9, 2022

@Gudahtt Sure, as long as we don't forget about it.

@mcmire mcmire dismissed their stale review December 9, 2022 22:21

Dismissing the change requests as we can write tests later.

@Gudahtt
Copy link
Member

Gudahtt commented Dec 9, 2022

@mcmire I added a ticket here: #16899 and added it to the merge network controllers epic.

@brad-decker
Copy link
Contributor

@BelfordZ is this ready to be merged?

@mcmire
Copy link
Contributor

mcmire commented Dec 15, 2022

I was asked to help with manually testing this PR, and to do this, I've been adding some more buttons and things to the test dapp so we can test the filter and subscription middleware. However, I don't think all of the filter middleware works as intended. I've added a couple of issues around this: MetaMask/eth-json-rpc-filters#80, MetaMask/eth-json-rpc-filters#81. So I'm not able to test all of the functionality but only some of it. I haven't tested the subscription middleware yet, but I will do that tomorrow.

@mcmire
Copy link
Contributor

mcmire commented Dec 16, 2022

Here are the changes for the test dapp which allow us to test filters and subscriptions: MetaMask/test-dapp#202

I used this on this branch and it seems that there are some issues:

  • When creating a log filter, I get this JSON-RPC response: {"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid json request"}}
  • Creating a block filter works just fine
  • When creating a subscription (either way), I get this response: The method "eth_subscribe" does not exist / is not available.

mcmire
mcmire previously requested changes Dec 16, 2022
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking this as changes requested. I can look into this tomorrow.

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the subscription middleware is failing because it used to be before the permission middleware, but now it's after, and the subscription methods are missing from the list of unrestricted methods (in app/scripts/controllers/permissions/specifications.js, the unrestrictedMethods variable).

app/scripts/controllers/network/createInfuraClient.js Outdated Show resolved Hide resolved
app/scripts/controllers/network/createJsonRpcClient.js Outdated Show resolved Hide resolved
@Gudahtt
Copy link
Member

Gudahtt commented Dec 16, 2022

In testing out this PR, even with the suggestions I made above applied locally, I'm still having trouble getting subscriptions to work. It looks like there are two distinct problems: notifications are not propagating correctly from the network client to the dapp, and we're seeing occasional empty block responses from Infura that are resulting in the request failing.

For the empty block responses problem, this is happening due to a race condition between getLatestBlock and getBlockByNumber - there's a period of time during which the latest block number cannot be retrieved by getBlockByNumber,it lags behind slightly. This is what the retryOnEmpty middleware was doing for us - it would automatically retry.

We'll need to move these middleware up a level, into the network controller, so that we can pass them a provider that includes the retryOnEmpty middleware.

@metamaskbot
Copy link
Collaborator

Builds ready [9c2b960]
Page Load Metrics (2055 ± 105 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint981981222411
domContentLoaded156923912026221106
load157223912055219105
domInteractive156923912026221106
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 106 bytes
  • ui: 0 bytes
  • common: 0 bytes

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mcmire mcmire dismissed their stale review December 19, 2022 20:50

Made the requested changes.

@metamaskbot
Copy link
Collaborator

Builds ready [911667c]
Page Load Metrics (2329 ± 226 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1113191454220
domContentLoaded170336472310457219
load170336472329471226
domInteractive170336472310457219
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 106 bytes
  • ui: 0 bytes
  • common: 0 bytes

@mcmire mcmire merged commit 6f6984f into develop Dec 20, 2022
@mcmire mcmire deleted the fix/sub-filter-into-network branch December 20, 2022 17:28
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-qa Label will automate into QA workspace
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move subscription/filter middleware into network client
6 participants