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

feat: Add QueuedRequestController batching #22865

Merged
merged 6 commits into from
Mar 21, 2024
Merged

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Feb 8, 2024

Description

The QueuedRequestController will now batch requests by origin. Requests from the same UI now get shown together, just as they were before this queuing feature was added. The only remaining difference is that we no longer show requests from different origins in the same batch, which we view as a security/usability improvement.

Related issues

Fixes:

Manual testing steps

important make sure any dapp used for testing has a permission (eth_accounts for example), as well as the per-domain network feature flag turned on, then refresh the dapp before begining testing.

make sure to also test that everything works unchanged with the feature flag off

  1. Turn on per-domain network feature flag
  2. go to test dapp and connect
  3. refresh the test dapp
  4. go to any other website (msn.com for example)
  5. in the devtools, run this:
await window.ethereum.request({
  "method": "wallet_requestPermissions",
  "params": [
    {
      "eth_accounts": {}
    }
  ]
});
  1. go back to the testdapp tab, make 2 or 3 send transaction calls
  2. ensure that the UI displays the number of transactions being processed, and allows you to go back and forward through the transactions.
  3. before confirming or rejecting any of those transactions, switch to the tab with msn.ca and run this 2-3 times:
await window.ethereum.request({
  "method": "eth_sendTransaction",
  "params": [
    {
      "to": "0x77ff877eE79c3f8C5aD244c037e5580EdCC6eF2c",
      "from": "your address",
      "value": "0x1"
    }
  ]
});
  1. ensure that the you are still only able to scrub through the 3 transactions. Reject each of them.
  2. You should now see the next set of 3 (from the domain msn.com).

Screenshots/Recordings

Before

After

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@Gudahtt Gudahtt force-pushed the test-queue-updates branch 3 times, most recently from 3729bc0 to bb0c1f8 Compare February 14, 2024 06:13
@Gudahtt

This comment was marked as outdated.

@metamaskbot

This comment was marked as outdated.

@metamaskbot

This comment was marked as outdated.

@Gudahtt Gudahtt force-pushed the test-queue-updates branch 2 times, most recently from 7609fc7 to 8d996b5 Compare February 27, 2024 19:11
@Gudahtt

This comment was marked as outdated.

@metamaskbot

This comment was marked as outdated.

@Gudahtt Gudahtt force-pushed the test-queue-updates branch 2 times, most recently from b48f306 to d0d4e69 Compare February 29, 2024 15:32
@Gudahtt

This comment was marked as outdated.

@metamaskbot

This comment was marked as outdated.

@Gudahtt Gudahtt force-pushed the test-queue-updates branch 3 times, most recently from 0edb792 to 589b95d Compare February 29, 2024 17:33
@Gudahtt
Copy link
Member Author

Gudahtt commented Feb 29, 2024

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated

@Gudahtt

This comment was marked as outdated.

@metamaskbot

This comment was marked as outdated.

Copy link

socket-security bot commented Mar 12, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/queued-request-controller@0.6.1 Transitive: filesystem +5 2.78 MB metamaskbot

🚮 Removed packages: npm/@metamask/queued-request-controller@0.3.0

View full report↗︎

@@ -286,7 +286,7 @@
"@metamask/post-message-stream": "^8.0.0",
"@metamask/ppom-validator": "^0.27.0",
"@metamask/providers": "^14.0.2",
"@metamask/queued-request-controller": "^0.3.0",
"@metamask/queued-request-controller": "^0.6.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

This is resulting in a bunch of peer dependency warnings

TODO: Validate that they're safe to ignore, or bump the other packages as well in the same PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like theres only the one warning about queued request controller using a different version of selected network controller:

@metamask/selected-network-controller is listed by your project with version 9.0.0, which doesn't satisfy what @metamask/queued-request-controller (p81a9c) requests (^10.0.0).

the main change in 10.x.x is the update to base controller. The API afaik is the same, the typings have changed a bit here and there, but we arent getting any type errors so I think we are good to go.

https://github.com/MetaMask/core/blob/main/packages/selected-network-controller/CHANGELOG.md#1000

Copy link
Member Author

Choose a reason for hiding this comment

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

The test description here talks about showing network confirmations, but we don't show confirmations on switch anymore.

Perhaps we should update this test to show that the network is switching, and leave about the "confirmations" part.

Copy link
Member Author

Choose a reason for hiding this comment

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

The same goes for the other request queuing test suite as well

@BelfordZ
Copy link
Contributor

update: Ive re-tested the 2nd issue and it doesn't seem to be a problem anymore. Not sure what was going on before, but it seems to work as expected now. (just make sure the dapp has permissions, otherwise everything is pretty messed up)

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.

@BelfordZ
Copy link
Contributor

Rebased to resolve conflicts

@BelfordZ
Copy link
Contributor

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated

@BelfordZ BelfordZ marked this pull request as ready for review March 19, 2024 19:29
@BelfordZ BelfordZ requested review from a team as code owners March 19, 2024 19:29
@jiexi
Copy link
Contributor

jiexi commented Mar 19, 2024

Scenario works for me

jiexi
jiexi previously approved these changes Mar 19, 2024
Gudahtt and others added 4 commits March 20, 2024 11:17
The `QueuedRequestController` will now batch requests by origin.
Requests from the same UI now get shown together, just as they were
before this queuing feature was added. The only remaining difference
is that we no longer show requests from different origins in the same
batch, which we view as a security/usability improvement.
@BelfordZ
Copy link
Contributor

Rebased again!

@metamaskbot
Copy link
Collaborator

Builds ready [633db2b]
Page Load Metrics (474 ± 375 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint642621165124
domContentLoaded97026189
load512299474781375
domInteractive97026189
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 10.81 KiB (0.29%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [6a238e1]
Page Load Metrics (877 ± 516 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint612901245426
domContentLoaded1091302210
load4827698771076516
domInteractive1091302210
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 10.81 KiB (0.29%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 21, 2024

I have re-reviewed the recent changes, LGTM!

@Gudahtt Gudahtt merged commit 1bb5dcd into develop Mar 21, 2024
65 of 66 checks passed
@Gudahtt Gudahtt deleted the test-queue-updates branch March 21, 2024 12:24
@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2024
@metamaskbot metamaskbot added the release-11.14.0 Issue or pull request that will be included in release 11.14.0 label Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-11.14.0 Issue or pull request that will be included in release 11.14.0 team-wallet-api-platform team-wallet-framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants