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

fix: transaction controller startup #4658

Merged
merged 9 commits into from
Sep 13, 2024

Conversation

matthewwalsh0
Copy link
Member

@matthewwalsh0 matthewwalsh0 commented Sep 5, 2024

Explanation

Refactor the handling of incomplete transactions when initialising the TransactionController.

  • unapproved transactions are now removed entirely and the initApprovals method has been removed.
    • Previously this initApprovals method allowed the clients to re-trigger approval requests and ultimately transaction confirmations.
    • This was only used in the extension, plus is a rare use case, since unapproved transactions are automatically rejected when closing the popup.
    • Unapproved transactions were never handled in mobile and resulted in error scenarios and unnecessary background requests.
  • approved transactions are now marked as failed.
    • Previously approved transactions were automatically signed and submitted to support MV3.
    • This poses a potential security issue and undesired UX and is also a rare scenario.
  • signed transactions are now marked as failed.
    • These transactions were not handled previously and appear to be the primary cause of #23361.

In addition:

  • Remove approveTransaction flow in PendingTransactionTracker.
  • Add updated rawTx to cancel and speed up transactions.
  • Skip normalization and validation when marking transaction as failed.
  • Fix transaction resubmit if a single transaction fails.

References

Fixes #23361

Changelog

@metamask/transaction-controller

  • BREAKING: Remove initApprovals method.
  • BREAKING: Remove beforeApproveOnInit hook.
  • CHANGED: Remove unapproved transactions during initialisation.
  • CHANGED: Fail approved and signed transactions during initialisation.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

Sorry, something went wrong.

Remove initApprovals method.
Export mobile constants.
Fail approved transactions on startup.
Improve gas fee poller error logging.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Skip validation when failing transaction.
Remove approve during resubmit.
Add updated rawTx to retry transactions.
Fix resubmit after transaction fails.
@matthewwalsh0
Copy link
Member Author

@metamaskbot publish-preview

Copy link
Contributor

github-actions bot commented Sep 6, 2024

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.1.1-preview-37450416",
  "@metamask-previews/address-book-controller": "6.0.0-preview-37450416",
  "@metamask-previews/announcement-controller": "7.0.0-preview-37450416",
  "@metamask-previews/approval-controller": "7.0.3-preview-37450416",
  "@metamask-previews/assets-controllers": "38.0.0-preview-37450416",
  "@metamask-previews/base-controller": "7.0.0-preview-37450416",
  "@metamask-previews/build-utils": "3.0.0-preview-37450416",
  "@metamask-previews/chain-controller": "0.1.1-preview-37450416",
  "@metamask-previews/composable-controller": "9.0.0-preview-37450416",
  "@metamask-previews/controller-utils": "11.2.0-preview-37450416",
  "@metamask-previews/ens-controller": "14.0.0-preview-37450416",
  "@metamask-previews/eth-json-rpc-provider": "4.1.3-preview-37450416",
  "@metamask-previews/gas-fee-controller": "20.0.0-preview-37450416",
  "@metamask-previews/json-rpc-engine": "9.0.2-preview-37450416",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.2-preview-37450416",
  "@metamask-previews/keyring-controller": "17.2.0-preview-37450416",
  "@metamask-previews/logging-controller": "6.0.0-preview-37450416",
  "@metamask-previews/message-manager": "10.1.0-preview-37450416",
  "@metamask-previews/name-controller": "8.0.0-preview-37450416",
  "@metamask-previews/network-controller": "21.0.0-preview-37450416",
  "@metamask-previews/notification-controller": "6.0.0-preview-37450416",
  "@metamask-previews/notification-services-controller": "0.3.0-preview-37450416",
  "@metamask-previews/permission-controller": "11.0.1-preview-37450416",
  "@metamask-previews/permission-log-controller": "3.0.0-preview-37450416",
  "@metamask-previews/phishing-controller": "12.0.1-preview-37450416",
  "@metamask-previews/polling-controller": "10.0.0-preview-37450416",
  "@metamask-previews/preferences-controller": "13.0.2-preview-37450416",
  "@metamask-previews/profile-sync-controller": "0.3.0-preview-37450416",
  "@metamask-previews/queued-request-controller": "5.0.0-preview-37450416",
  "@metamask-previews/rate-limit-controller": "6.0.0-preview-37450416",
  "@metamask-previews/selected-network-controller": "18.0.0-preview-37450416",
  "@metamask-previews/signature-controller": "19.0.0-preview-37450416",
  "@metamask-previews/transaction-controller": "36.0.0-preview-37450416",
  "@metamask-previews/user-operation-controller": "15.0.0-preview-37450416"
}

@Gudahtt
Copy link
Member

Gudahtt commented Sep 6, 2024

Thoughts on splitting this into multiple PRs? These changes seem like they would be easy to do separately, and seem unrelated to the initialization changes:

  • CHANGED: Change getPermittedAccounts constructor callback to optional.
  • ADDED: Add SPEED_UP_RATE, CHAIN_IDS, and ETHERSCAN_SUPPORTED_NETWORKS constants.

@matthewwalsh0
Copy link
Member Author

Thoughts on splitting this into multiple PRs? These changes seem like they would be easy to do separately, and seem unrelated to the initialization changes:

  • CHANGED: Change getPermittedAccounts constructor callback to optional.
  • ADDED: Add SPEED_UP_RATE, CHAIN_IDS, and ETHERSCAN_SUPPORTED_NETWORKS constants.

I absolutely can if required. But they are each just one line changes so wanted to avoid the admin overhead.

@Gudahtt
Copy link
Member

Gudahtt commented Sep 6, 2024

Since b both changes serve a distinct purpose, it would be preferred to make them separately even they are only 1-line changes, as suggested by the contributor docs.

Certainly these changes don't contribute much to the size of the PR, so they aren't problematic for that reason. But if we're reviewing the commit history to understand what changed, these would not appear. And similarly if we found a bug with the initialization refactor and wanted to revert it, it would also revert these two small changes unnecessarily, which is prevented by separating them.

@matthewwalsh0 matthewwalsh0 changed the title refactor: transaction controller startup fix: transaction controller startup Sep 10, 2024
@matthewwalsh0 matthewwalsh0 merged commit ccd95c8 into main Sep 13, 2024
116 checks passed
@matthewwalsh0 matthewwalsh0 deleted the refactor/transaction-controller-startup branch September 13, 2024 11:11
@matthewwalsh0 matthewwalsh0 mentioned this pull request Sep 14, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants