Skip to content

Conversation

@Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Oct 24, 2025

Explanation

These will be used indirectly by the UserOperationController to emulate adding and updating a transaction, in response to user operations.

References

This came up as a blocker to MetaMask/metamask-extension#31843 because currently the extension is directly publishing TransactionController events, which will no longer be allowed with the new messenger.

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 communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

Note

Add emulateNewTransaction and emulateTransactionUpdate actions to TransactionController, emitting relevant swap/update events and updating state via messenger.

  • Transaction Controller
    • New Actions: Add TransactionController:emulateNewTransaction and TransactionController:emulateTransactionUpdate.
      • emulateNewTransaction: Publishes TransactionController:transactionNewSwap or TransactionController:transactionNewSwapApproval based on the transaction type.
      • emulateTransactionUpdate: Sets txParams.from to the selected account, adds transaction if missing, updates it, and publishes TransactionController:transactionStatusUpdated.
    • Messenger: Register handlers for emulateNewTransaction and emulateTransactionUpdate.
    • Exports: Export new action types from src/index.ts.
  • Tests: Add unit tests covering new actions, event publishing, and state updates.
  • Changelog: Note added actions under Unreleased.

Written by Cursor Bugbot for commit 357add4. This will update automatically on new commits. Configure here.

@Gudahtt Gudahtt force-pushed the add-transaction-emulation-methods branch from c78a111 to b0c8f59 Compare October 24, 2025 12:47
Gudahtt and others added 2 commits October 24, 2025 15:06
These will be used indirectly by the UserOperationController to emulate
adding and updating a transaction, in response to user operations.
@pedronfigueiredo pedronfigueiredo force-pushed the add-transaction-emulation-methods branch from b0c8f59 to 93ebaac Compare October 24, 2025 14:06
@pedronfigueiredo pedronfigueiredo force-pushed the add-transaction-emulation-methods branch from 93ebaac to a191ae8 Compare October 24, 2025 14:07
@Gudahtt Gudahtt marked this pull request as ready for review October 24, 2025 14:49
@Gudahtt Gudahtt requested review from a team as code owners October 24, 2025 14:49
'TransactionController:transactionStatusUpdated',
{ transactionMeta: updatedTransactionMeta },
);
}
Copy link

Choose a reason for hiding this comment

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

Bug: Event Publishes Incomplete Transaction Data

In emulateTransactionUpdate, the transactionStatusUpdated event publishes transaction metadata before it's fully normalized by updateTransaction. This means event listeners receive data (e.g., missing value: '0x0') that differs from what's ultimately stored in the controller's state, leading to inconsistency.

Fix in Cursor Fix in Web

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 does seem kinda broken, but, this is the pre-existing behavior

Copy link
Member

Choose a reason for hiding this comment

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

Again, likely not used, so low risk we can address in a future PR.

this.update((state) => {
state.transactions.push(updatedTransactionMeta);
});
}
Copy link

Choose a reason for hiding this comment

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

Bug: Transaction History Limit Bypass

When adding a transaction that doesn't exist, the code directly pushes updatedTransactionMeta to state without using #trimTransactionsForState(). This bypasses the transaction history limit enforcement that is used everywhere else in the controller (e.g., in #addMetadata at line 2876-2880). This could cause the state to exceed the configured transactionHistoryLimit, leading to unbounded memory growth.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

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

Again, this does seem like a legitimate bug, but it's a pre-existing problem

Copy link
Member

Choose a reason for hiding this comment

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

Likely not used at all currently so very very low risk.

@Gudahtt Gudahtt merged commit 0867eae into main Oct 24, 2025
257 checks passed
@Gudahtt Gudahtt deleted the add-transaction-emulation-methods branch October 24, 2025 15:04
Gudahtt added a commit that referenced this pull request Oct 24, 2025
…r/multichain-transactions-controller

* origin/main: (35 commits)
  feat: `JsonRpcEngineV2` (#6176)
  Release 641.0.0 (#6940)
  feat: Add transaction emulation actions (#6935)
  Release/640.0.0 (#6934)
  fix(core-backend): control randomness to fix flaky test (#6936)
  chore: Add `@metamask-previews/*` to NPM age gate exceptions (#6937)
  Release/639.0.0 (#6931)
  feat: make getCryptoApproveTransactionParams synchronous (#6930)
  feat: add new actions to `KeyringController` (#6928)
  feat: add `getAccounts` to `AccountsController` (#6927)
  chore: remove `Monad Mainnet` single call balance contract and add into account v4 (#6929)
  Release/638.0.0 (#6923)
  fix: Downgrade `multiformats` to `^9.9.0` to avoid ESM-only dependency (#6920)
  Release/637.0.0 (#6919)
  feat(account-tree-controller): add callbacks for hidden and pinned data (#6910)
  Release 636.0.0 (#6918)
  fix(core-backend): reconnection logic (#6861)
  fix:  Tx state listener and signature coverage (#6906)
  Release/635.0.0 (#6917)
  fix(base-controller): add TypeScript declaration file for legacy module resolution (#6915)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants