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: TransactionController afterSign hook should be allowed to modify the transaction #4343

Merged
merged 2 commits into from
May 31, 2024

Conversation

dbrans
Copy link
Contributor

@dbrans dbrans commented May 30, 2024

Note

This change is intended to be cherry-picked into MetaMask/extension v11.17.0 via an upgrade to the @metamask/transaction-controller package.

Explanation

Issue:
A recent update to the transaction-controller has made the TransactionMeta object passed to the afterSign hook frozen. This change prevents adding new properties, leading to the error: “Cannot add property custodyId, object is not extensible.” This bug is breaking all transactions for MMI as the original txMeta cannot store required properties like custodyId.

Fix:
We deep clone the transaction meta before passing it to the hook. A deep clone is used because transactionMeta is recursively frozen by immer. This fix was intended to minimize the change for the cherry-pick going into v11.17.0. A longer term solution might involve using immer more throughout the TransactionController.ts file to make it clearer when a transactionMeta is being mutated and how.

Testing:
This fix was applied to and verified with the MMI extension.

References

Changelog

@metamask/transaction-controller

  • FIXED: afterSign hook is now able to modify the transaction

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

@dbrans dbrans added the team-transactions Transactions team label May 30, 2024
@dbrans dbrans marked this pull request as ready for review May 30, 2024 19:51
@dbrans dbrans requested a review from a team as a code owner May 30, 2024 19:51
@dbrans
Copy link
Contributor Author

dbrans commented May 30, 2024

@metamaskbot publish-preview

Copy link
Contributor

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": "14.0.0-preview-4a95e5f",
  "@metamask-previews/address-book-controller": "4.0.1-preview-4a95e5f",
  "@metamask-previews/announcement-controller": "6.1.0-preview-4a95e5f",
  "@metamask-previews/approval-controller": "6.0.2-preview-4a95e5f",
  "@metamask-previews/assets-controllers": "30.0.0-preview-4a95e5f",
  "@metamask-previews/base-controller": "5.0.2-preview-4a95e5f",
  "@metamask-previews/build-utils": "2.0.1-preview-4a95e5f",
  "@metamask-previews/chain-controller": "0.0.0-preview-4a95e5f",
  "@metamask-previews/composable-controller": "6.0.1-preview-4a95e5f",
  "@metamask-previews/controller-utils": "10.0.0-preview-4a95e5f",
  "@metamask-previews/ens-controller": "10.0.1-preview-4a95e5f",
  "@metamask-previews/eth-json-rpc-provider": "3.0.2-preview-4a95e5f",
  "@metamask-previews/gas-fee-controller": "15.1.2-preview-4a95e5f",
  "@metamask-previews/json-rpc-engine": "8.0.2-preview-4a95e5f",
  "@metamask-previews/json-rpc-middleware-stream": "7.0.1-preview-4a95e5f",
  "@metamask-previews/keyring-controller": "16.0.0-preview-4a95e5f",
  "@metamask-previews/logging-controller": "3.0.1-preview-4a95e5f",
  "@metamask-previews/message-manager": "8.0.2-preview-4a95e5f",
  "@metamask-previews/name-controller": "6.0.1-preview-4a95e5f",
  "@metamask-previews/network-controller": "18.1.2-preview-4a95e5f",
  "@metamask-previews/notification-controller": "5.0.1-preview-4a95e5f",
  "@metamask-previews/permission-controller": "9.1.0-preview-4a95e5f",
  "@metamask-previews/permission-log-controller": "2.0.1-preview-4a95e5f",
  "@metamask-previews/phishing-controller": "9.0.3-preview-4a95e5f",
  "@metamask-previews/polling-controller": "6.0.2-preview-4a95e5f",
  "@metamask-previews/preferences-controller": "11.0.0-preview-4a95e5f",
  "@metamask-previews/profile-sync-controller": "0.0.0-preview-4a95e5f",
  "@metamask-previews/queued-request-controller": "0.10.0-preview-4a95e5f",
  "@metamask-previews/rate-limit-controller": "5.0.1-preview-4a95e5f",
  "@metamask-previews/selected-network-controller": "13.0.0-preview-4a95e5f",
  "@metamask-previews/signature-controller": "16.0.0-preview-4a95e5f",
  "@metamask-previews/transaction-controller": "30.0.0-preview-4a95e5f",
  "@metamask-previews/user-operation-controller": "10.0.0-preview-4a95e5f"
}

@dbrans dbrans merged commit 0b3ed43 into main May 31, 2024
147 checks passed
@dbrans dbrans deleted the dbrans/txc-hook-draft branch May 31, 2024 14:14
mcmire pushed a commit that referenced this pull request May 31, 2024
… the transaction (#4343)

> [!NOTE]
> This change is intended to be cherry-picked into MetaMask/extension
v11.17.0 via an upgrade to the @metamask/transaction-controller package.
## Explanation
**Issue:**
A recent update to the transaction-controller has made the
TransactionMeta object passed to the `afterSign` hook frozen. This
change prevents adding new properties, leading to the error: “Cannot add
property custodyId, object is not extensible.” This bug is breaking all
transactions for MMI as the original txMeta cannot store required
properties like custodyId.

**Fix:**
We deep clone the transaction meta before passing it to the hook. A deep
clone is used because transactionMeta is recursively frozen by immer.
This fix was intended to minimize the change for the cherry-pick going
into v11.17.0. A longer term solution might involve using immer more
throughout the TransactionController.ts file to make it clearer when a
transactionMeta is being mutated and how.

**Testing:**
This fix was applied to and verified with the MMI extension.

<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

## References

<!--
Are there any issues that this pull request is tied to? Are there other
links that reviewers should consult to understand these changes better?

For example:

* Fixes #12345
* Related to #67890
-->

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/transaction-controller`

- **FIXED**: afterSign hook is now able to modify the transaction

## 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
zone-live added a commit to MetaMask/metamask-extension that referenced this pull request Jun 5, 2024
> [!NOTE]
> This PR is intended to be cherry-picked into RC 11.17.0 after being
merged into develop

## **Description**
Upgrade transaction-controller to get this fix:
MetaMask/core#4343

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24947?quickstart=1)

## **Related issues**

Fixes:
A recent update to the transaction-controller has made the
TransactionMeta object passed to the afterSign hook frozen. This change
prevents adding new properties, leading to the error: “Cannot add
property custodyId, object is not extensible.” This bug is breaking all
transactions for MMI as the original txMeta cannot store required
properties like custodyId.

Blocked by #24861 
Blocked by #24913

## **Manual testing steps**
I followed these steps to test the fix:
1. yarn && yarn start:mmi
2. create a new wallet
3. visit https://saturn-custody-ui.dev.metamask-institutional.io/ and
add two custodial addresses
4. send 0ETH from one custodial address to the other

You should see a popup with an Approve button. Before this fix, the
transaction would appear in the activity tab with an error.


## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

---------

Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
Co-authored-by: Antonio Regadas <antonio.regadas@consensys.net>
zone-live added a commit to MetaMask/metamask-extension that referenced this pull request Jun 6, 2024
> [!NOTE]
> This PR is intended to be cherry-picked into RC 11.17.0 after being
merged into develop

Upgrade transaction-controller to get this fix:
MetaMask/core#4343

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24947?quickstart=1)

Fixes:
A recent update to the transaction-controller has made the
TransactionMeta object passed to the afterSign hook frozen. This change
prevents adding new properties, leading to the error: “Cannot add
property custodyId, object is not extensible.” This bug is breaking all
transactions for MMI as the original txMeta cannot store required
properties like custodyId.

Blocked by #24861
Blocked by #24913

I followed these steps to test the fix:
1. yarn && yarn start:mmi
2. create a new wallet
3. visit https://saturn-custody-ui.dev.metamask-institutional.io/ and
add two custodial addresses
4. send 0ETH from one custodial address to the other

You should see a popup with an Approve button. Before this fix, the
transaction would appear in the activity tab with an error.

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

<!-- [screenshots/recordings] -->

<!-- [screenshots/recordings] -->

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] 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.

---------

Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
Co-authored-by: Antonio Regadas <antonio.regadas@consensys.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-transactions Transactions team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants