Skip to content

Conversation

@Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Mar 13, 2023

This reverts commit 6f6984f. That commit was an RPC middleware refactor intended to move the subscribe and filter middleware into the network controller, to simplify the process of sharing this middleware between clients.

This refactor resulted in eth_subscribe notifications being sent on the wrong connections, causing the UI to break in some cases (the UI provider connection does not support notifications). This happened because the setupProviderEngine function runs per-connection, whereas the engine setup inside the network controller is global. The global network client cannot support notifications because it has no way to route them; they'll need to stay in the per-connection provider engine.

Closes #17467

Manual Testing Steps

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@metamaskbot
Copy link
Collaborator

Builds ready [ebb6288]
Page Load Metrics (1564 ± 46 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint972891234120
domContentLoaded1429181615479546
load1458181615649646
domInteractive1429181615479546
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -107 bytes
  • ui: 0 bytes
  • common: 0 bytes

@codecov
Copy link

codecov bot commented Mar 13, 2023

Codecov Report

Merging #18129 (850b47e) into develop (7215fc2) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 850b47e differs from pull request most recent head fde1a64. Consider uploading reports for the commit fde1a64 to get more accurate results

@@             Coverage Diff             @@
##           develop   #18129      +/-   ##
===========================================
- Coverage    64.00%   64.00%   -0.00%     
===========================================
  Files          910      910              
  Lines        35505    35499       -6     
  Branches      9002     9001       -1     
===========================================
- Hits         22724    22719       -5     
+ Misses       12781    12780       -1     
Impacted Files Coverage Δ
.../scripts/controllers/network/network-controller.js 86.27% <ø> (-1.16%) ⬇️
.../scripts/controllers/permissions/specifications.js 73.63% <ø> (ø)
app/scripts/metamask-controller.js 62.32% <100.00%> (+0.42%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Gudahtt Gudahtt marked this pull request as ready for review March 13, 2023 21:41
@Gudahtt Gudahtt requested a review from a team as a code owner March 13, 2023 21:41
@Gudahtt Gudahtt requested a review from chloeYue March 13, 2023 21:41
@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 13, 2023

Sufficient automated test coverage has been added

We should be able to cover this with an e2e test. I'll have to give that some thought. I don't think it'd be feasible to capture this error in a unit test, since it's more of an integration problem.

Edit: This is now covered by an e2e test.

@seaona
Copy link
Member

seaona commented Mar 14, 2023

Looks like this fixed it. I cannot reproduce the error anymore @Gudahtt

This reverts commit 6f6984f. That
commit was an RPC middleware refactor intended to move the subscribe
and filter middleware into the network controller, to simplify the
process of sharing this middleware between clients.

This refactor resulted in `eth_subscribe` notifications being sent on
the wrong connections, causing the UI to break in some cases (the UI
`provider` connection does not support notifications). This happened
because the `setupProviderEngine` function runs per-connection,
whereas the engine setup inside the network controller is global. The
global network client cannot support notifications because it has no
way to route them; they'll need to stay in the per-connection provider
engine.

Closes #17467
An e2e test has been added that confirms subscriptions are only
broadcast to the site that registered them. This test fails on
`develop`.
@Gudahtt Gudahtt force-pushed the revert-filter-subscribe-refactor branch from ebb6288 to 850b47e Compare March 14, 2023 17:54
@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 14, 2023

An e2e test has been added to confirm that this is working. It doesn't test the UI breakage, but it detects the problematic behavior by ensuring subscriptions from one dapp don't leak to another. Testing the UI directly didn't seem ideal because we may want to restore UI support for RPC notifications at some point.

});
`);

// Verify that new block is seen on first dapp
Copy link
Member Author

@Gudahtt Gudahtt Mar 14, 2023

Choose a reason for hiding this comment

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

We use a default block time of 2 seconds in our Ganache setup. Our findElement timeout is more than long enough to wait for this, but in the future we can improve this test by explicitly mining a block here using the evm_mine method enabled by this PR: #18149

await driver.openNewPage('http://127.0.0.1:8080/');

const setupSubscriptionListener = `
const responseContainer = document.createElement('div');
Copy link
Member Author

Choose a reason for hiding this comment

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

We can replace this with the built-in test dapp subscribe functionality after this PR is merged: MetaMask/test-dapp#202

@adonesky1
Copy link
Contributor

Test that the filter and subscribe methods work correctly
I'd recommend running this branch of the test-dapp locally to help with testing: https://github.com/MetaMask/test-
dapp/pull/202

I tried this both on this branch and on develop and it worked on both...

adonesky1
adonesky1 previously approved these changes Mar 14, 2023
Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM! Tested and verified that eth_subscribe subscription messages are no longer broadcast to all pages where we inject our provider

@metamaskbot
Copy link
Collaborator

Builds ready [850b47e]
Page Load Metrics (1568 ± 50 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint93133116126
domContentLoaded13861794155510852
load13861815156810550
domInteractive13861794155510852
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -107 bytes
  • ui: 0 bytes
  • common: 0 bytes

@metamaskbot
Copy link
Collaborator

Builds ready [850b47e]
Page Load Metrics (1568 ± 50 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint93133116126
domContentLoaded13861794155510852
load13861815156810550
domInteractive13861794155510852
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -107 bytes
  • ui: 0 bytes
  • common: 0 bytes

Copy link
Contributor

@chloeYue chloeYue left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@metamaskbot
Copy link
Collaborator

Builds ready [fde1a64]
Page Load Metrics (1640 ± 62 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint96151117136
domContentLoaded14551879161910952
load14552010164012962
domInteractive14551879161910952
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -107 bytes
  • ui: 0 bytes
  • common: 0 bytes

@Gudahtt Gudahtt merged commit bd23a49 into develop Mar 15, 2023
@Gudahtt Gudahtt deleted the revert-filter-subscribe-refactor branch March 15, 2023 14:46
@github-actions github-actions bot locked and limited conversation to collaborators Mar 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

7 participants