Skip to content

fix: preserve transaction type of batched transactions #6056

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

Merged
merged 15 commits into from
Jul 23, 2025
Merged

Conversation

micaelae
Copy link
Member

@micaelae micaelae commented Jul 1, 2025

Explanation

When a batch of transactions with specific TransactionType values is submitted (example: bridgeApproval, swap, bridge), the txs get published with generic types like contractInteraction and approve, and the requested types are not preserved

The type values are needed in the swaps and bridge experiences in order to track and display accurate transaction statuses so they need to be propagated

References

Changelog

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

@micaelae micaelae requested review from a team as code owners July 1, 2025 20:53
cursor[bot]

This comment was marked as outdated.

bfullam
bfullam previously approved these changes Jul 1, 2025
@bfullam
Copy link
Contributor

bfullam commented Jul 2, 2025

@metamaskbot publish-preview

Copy link
Contributor

github-actions bot commented Jul 2, 2025

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

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "0.4.0-preview-9cc92e6f",
  "@metamask-previews/accounts-controller": "31.0.0-preview-9cc92e6f",
  "@metamask-previews/address-book-controller": "6.1.0-preview-9cc92e6f",
  "@metamask-previews/announcement-controller": "7.0.3-preview-9cc92e6f",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-9cc92e6f",
  "@metamask-previews/approval-controller": "7.1.3-preview-9cc92e6f",
  "@metamask-previews/assets-controllers": "69.0.0-preview-9cc92e6f",
  "@metamask-previews/base-controller": "8.0.1-preview-9cc92e6f",
  "@metamask-previews/bridge-controller": "34.0.0-preview-9cc92e6f",
  "@metamask-previews/bridge-status-controller": "33.0.0-preview-9cc92e6f",
  "@metamask-previews/build-utils": "3.0.3-preview-9cc92e6f",
  "@metamask-previews/chain-agnostic-permission": "1.0.0-preview-9cc92e6f",
  "@metamask-previews/composable-controller": "11.0.0-preview-9cc92e6f",
  "@metamask-previews/controller-utils": "11.10.0-preview-9cc92e6f",
  "@metamask-previews/delegation-controller": "0.5.0-preview-9cc92e6f",
  "@metamask-previews/earn-controller": "2.0.1-preview-9cc92e6f",
  "@metamask-previews/eip1193-permission-middleware": "1.0.0-preview-9cc92e6f",
  "@metamask-previews/ens-controller": "17.0.0-preview-9cc92e6f",
  "@metamask-previews/error-reporting-service": "2.0.0-preview-9cc92e6f",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-9cc92e6f",
  "@metamask-previews/foundryup": "1.0.0-preview-9cc92e6f",
  "@metamask-previews/gas-fee-controller": "24.0.0-preview-9cc92e6f",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-9cc92e6f",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-9cc92e6f",
  "@metamask-previews/keyring-controller": "22.0.2-preview-9cc92e6f",
  "@metamask-previews/logging-controller": "6.0.4-preview-9cc92e6f",
  "@metamask-previews/message-manager": "12.0.1-preview-9cc92e6f",
  "@metamask-previews/multichain-api-middleware": "1.0.0-preview-9cc92e6f",
  "@metamask-previews/multichain-network-controller": "0.9.0-preview-9cc92e6f",
  "@metamask-previews/multichain-transactions-controller": "3.0.0-preview-9cc92e6f",
  "@metamask-previews/name-controller": "8.0.3-preview-9cc92e6f",
  "@metamask-previews/network-controller": "24.0.0-preview-9cc92e6f",
  "@metamask-previews/notification-services-controller": "12.0.0-preview-9cc92e6f",
  "@metamask-previews/permission-controller": "11.0.6-preview-9cc92e6f",
  "@metamask-previews/permission-log-controller": "3.0.3-preview-9cc92e6f",
  "@metamask-previews/phishing-controller": "12.6.0-preview-9cc92e6f",
  "@metamask-previews/polling-controller": "14.0.0-preview-9cc92e6f",
  "@metamask-previews/preferences-controller": "18.4.0-preview-9cc92e6f",
  "@metamask-previews/profile-sync-controller": "19.0.0-preview-9cc92e6f",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-9cc92e6f",
  "@metamask-previews/remote-feature-flag-controller": "1.6.0-preview-9cc92e6f",
  "@metamask-previews/sample-controllers": "1.0.0-preview-9cc92e6f",
  "@metamask-previews/seedless-onboarding-controller": "1.0.0-preview-9cc92e6f",
  "@metamask-previews/selected-network-controller": "23.0.0-preview-9cc92e6f",
  "@metamask-previews/signature-controller": "31.0.0-preview-9cc92e6f",
  "@metamask-previews/token-search-discovery-controller": "3.3.0-preview-9cc92e6f",
  "@metamask-previews/transaction-controller": "58.1.0-preview-9cc92e6f",
  "@metamask-previews/user-operation-controller": "37.0.0-preview-9cc92e6f"
}

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

vinistevam
vinistevam previously approved these changes Jul 11, 2025
@micaelae micaelae requested a review from a team as a code owner July 11, 2025 08:39
@micaelae micaelae enabled auto-merge (squash) July 11, 2025 08:40
expect(publishBatchHook.mock.calls[0][0].transactions[0].type).toBe(
TransactionType.swap,
);
expect(publishBatchHook.mock.calls[0][0].transactions[1].type).toBe(
Copy link
Member

Choose a reason for hiding this comment

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

Rather than asserting the hook is called with the type, ideally the hook wouldn't know, and instead we could verify that addTransaction is called multiple times with the correct types?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call - I updated the test to do this! I also removed the type key from the PublishBatchHookTransaction type, which I added for this test.

@@ -837,6 +932,50 @@ describe('Batch Utils', () => {
PUBLISH_BATCH_HOOK_PARAMS,
);
});
// const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn();
Copy link
Member

Choose a reason for hiding this comment

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

Accident?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure how this happened - will update

@@ -606,6 +607,7 @@ async function processTransactionWithHook(
networkClientId,
publishHook,
requireApproval: false,
type,
Copy link
Member

@OGPoyraz OGPoyraz Jul 23, 2025

Choose a reason for hiding this comment

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

Hey @micaelae , I was debugging the metric issues due to swaps and bridge transaction events and origin was also not preserving to the individual batched transactions. If you don't mind we could add origin here too. Otherwise source will be dapp in metrics which is incorrect.

Copy link
Member

Choose a reason for hiding this comment

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

Given the age of this PR, are we okay to do that in a separate PR @OGPoyraz ?

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 PR was merged before I could add this. Can you open a new PR for this change?

Copy link
Member

Choose a reason for hiding this comment

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

All good, we will do it in a separate fix!

@@ -606,6 +607,7 @@ async function processTransactionWithHook(
networkClientId,
publishHook,
requireApproval: false,
type,
Copy link
Member

@OGPoyraz OGPoyraz Jul 23, 2025

Choose a reason for hiding this comment

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

On another note if we are correctly preserving the type with this fix now - do we want to remove this temporary type update from bridge-status-controller? https://github.com/MetaMask/core/blob/main/packages/bridge-status-controller/src/utils/transaction.ts#L355

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! I have a draft for removing this, will just need to re-test once this version is published

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Inconsistent Transaction Type Handling

The processTransactionWithHook function has two issues concerning the type field:

  1. It inconsistently returns the type field: it's included for new transactions but omitted for existing ones, leading to inconsistent object shapes.
  2. Additionally, when the type field is returned, it creates a type mismatch with the hookTransactions array, which expects PublishBatchHookTransaction (a type intentionally designed to omit the type field).

packages/transaction-controller/src/utils/batch.ts#L564-L584

if (existingTransaction) {
const { id, onPublish, signedTransaction } = existingTransaction;
const transactionMeta = getTransaction(id);
updateTransaction({ transactionId: id }, (_transactionMeta) => {
_transactionMeta.batchId = batchId;
});
publishHook(transactionMeta, signedTransaction)
.then(onPublish)
.catch(() => {
// Intentionally empty
});
log('Processed existing transaction with hook', {
id,
params,
});
return {

packages/transaction-controller/src/utils/batch.ts#L636-L641

return {
id,
params: newParams,
type,
};

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@micaelae micaelae merged commit cb4c666 into main Jul 23, 2025
218 of 219 checks passed
@micaelae micaelae deleted the batched-tx-types branch July 23, 2025 14:19
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.

5 participants