Skip to content

Commit 4fe6a2f

Browse files
fix: ignore incoming transactions in duplicate nonce check (#7097)
## Explanation Ignore transactions with `isTransfer` set when checking for duplicate nonces in `PendingTransactionTracker`. ## References Related to [#6135](MetaMask/MetaMask-planning#6135) ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Prevents pending transactions from being marked dropped when their nonce matches an incoming/transfer transaction by refining the nonce-taken check. > > - **PendingTransactionTracker**: > - Refine `#isNonceTaken` to exclude transactions where `tx.type !== incoming` AND `tx.isTransfer !== undefined`, avoiding false duplicate-nonce drops from incoming/transfer transactions. > - Add unit test ensuring no `transaction-dropped` event when a matching nonce belongs to an incoming transaction. > - **Changelog**: > - Document fix: prevent transactions marked as `dropped` if nonce matches incoming transaction. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 77e52f5. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 62eab6c commit 4fe6a2f

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

packages/transaction-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Calculate operator fee for OP stack networks and include it in `layer1GasFee` ([#6979](https://github.com/MetaMask/core/pull/6979))
1313
- Add support for `isGasFeeSponsored` field in transaction batch and add transaction options ([#7064](https://github.com/MetaMask/core/pull/7064))
1414

15+
### Fixed
16+
17+
- Prevent transactions marked as `dropped` if nonce matches incoming transaction ([#7097](https://github.com/MetaMask/core/pull/7097))
18+
1519
## [61.1.0]
1620

1721
### Added

packages/transaction-controller/src/helpers/PendingTransactionTracker.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,38 @@ describe('PendingTransactionTracker', () => {
565565

566566
expect(listener).not.toHaveBeenCalled();
567567
});
568+
569+
it('unless incoming transaction', async () => {
570+
const listener = jest.fn();
571+
572+
const confirmedTransactionMetaMock = {
573+
...TRANSACTION_SUBMITTED_MOCK,
574+
id: `${ID_MOCK}2`,
575+
status: TransactionStatus.confirmed,
576+
isTransfer: false,
577+
} as unknown as TransactionMeta;
578+
579+
const submittedTransactionMetaMock = {
580+
...TRANSACTION_SUBMITTED_MOCK,
581+
};
582+
583+
pendingTransactionTracker = new PendingTransactionTracker({
584+
...options,
585+
getTransactions: () => [
586+
confirmedTransactionMetaMock,
587+
submittedTransactionMetaMock,
588+
],
589+
});
590+
591+
pendingTransactionTracker.hub.addListener(
592+
'transaction-dropped',
593+
listener,
594+
);
595+
596+
await onPoll();
597+
598+
expect(listener).not.toHaveBeenCalled();
599+
});
568600
});
569601

570602
describe('fires confirmed event', () => {

packages/transaction-controller/src/helpers/PendingTransactionTracker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ export class PendingTransactionTracker {
543543
tx.status === TransactionStatus.confirmed &&
544544
tx.txParams.nonce &&
545545
tx.txParams.nonce === txParams.nonce &&
546-
tx.type !== TransactionType.incoming,
546+
tx.type !== TransactionType.incoming &&
547+
tx.isTransfer === undefined,
547548
);
548549
}
549550

0 commit comments

Comments
 (0)