Commit 7a01c95
authored
feat: stop polling when bridge history item is stale or has an invalid src hash (MetaMask#8479)
## Explanation
<!--
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?
-->
### Problem
Bridge txHistory persists invalid or premature src tx hashes (specially
STX), and pending items could be polled indefinitely, spamming providers
and leaving bad state after restarts.
### Solution
- Subscribe to TransactionController:transactionStatusUpdated instead of
transactionFailed / transactionConfirmed, and update history item
matching the tx id, action id, hash, batch, or approval
- Skips persisting STX src hashes on submit. Set the hash when the tx is
confirmed, or backfill from TransactionController as needed
- If a transaction is deemed "too old", fetch the status once, then
check if the tx has been mined on chain. If The src hash is nonexistent,
stop polling and delete the history item to prevent re-polling on the
next restart
## 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?
Are there client or consumer pull requests to adopt any breaking
changes?
For example:
* Fixes #12345
* Related to #67890
-->
Fixes https://consensyssoftware.atlassian.net/browse/SWAPS-4380
## 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](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes bridge status polling/state management and switches to
`TransactionController:transactionStatusUpdated`, which can affect
analytics, history reconciliation, and when polling starts/stops. Also
deletes old pending history entries based on a remote-configured age
threshold, so misconfiguration or matching bugs could drop legitimate
items.
>
> **Overview**
> Prevents indefinite bridge status polling by introducing an age
threshold (`maxPendingHistoryItemAgeMs`, default 2 days) sourced from
remote feature flags and, for stale pending items, fetching status once
then checking `eth_getTransactionReceipt`; if the src hash appears
invalid, polling is stopped, a new `invalid_transaction_hash` polling
reason is tracked, and the history entry is removed to avoid re-polling
on restart.
>
> Refactors BridgeStatusController transaction subscriptions to use
`TransactionController:transactionStatusUpdated` (replacing
`transactionFailed`/`transactionConfirmed`), adds more robust history
matching (by `id`, `actionId`, `batchId`, `txHash`, and `approvalTxId`),
and avoids persisting smart-transaction src hashes until a finalized
status is observed; metrics generation is updated accordingly
(centralized polling-status properties and improved `error_message`
formatting).
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
dbfbe65. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent f941345 commit 7a01c95
17 files changed
Lines changed: 1628 additions & 830 deletions
File tree
- packages
- bridge-controller
- src/utils
- metrics
- bridge-status-controller
- src
- __snapshots__
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| 192 | + | |
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| |||
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
31 | 41 | | |
32 | 42 | | |
33 | 43 | | |
| |||
0 commit comments