Skip to content

Commit 15d58bd

Browse files
authored
fix: use signature as txhistory key for Solana bridge transactions (#6424)
## Explanation This change fixes a bug in Solana post-submission logic in which the txHistory key is set to a random uuid instead of the tx hash. This causes txHistory lookups by txHash (for Solana transactions) to fail on the clients This is not a breaking change, but requires a migration on the clients to set the txHistory key to the `historyItem.status?.srcChain?.txHash` value for Solana transactions. This fixes txHistory items created prior to this version of the bridge-status-controller Migration script for extension: https://github.com/MetaMask/metamask-extension/pull/35539/files#diff-3cd53aba68cf73714b1dbe70345a0b896589f13d8c3cc370d04393a5c6b4f0d8 This PR also fixes properties for the swap Completed events so that they read data from the txHistory, if it exists <!-- 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? 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-2595 ## 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/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent 6cac875 commit 15d58bd

File tree

6 files changed

+19
-18
lines changed

6 files changed

+19
-18
lines changed

packages/bridge-status-controller/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Set the Solana tx signature as the `txHistory` key to support lookups by hash ([#6424](https://github.com/MetaMask/core/pull/6424))
13+
- Read Completed swap properties from `txHistory` for consistency with bridge transactions ([#6424](https://github.com/MetaMask/core/pull/6424))
14+
1015
## [40.2.0]
1116

1217
### Added

packages/bridge-status-controller/src/__snapshots__/bridge-status-controller.test.ts.snap

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,7 @@ Object {
31103110
"destinationTokenDecimals": 18,
31113111
"destinationTokenSymbol": "ETH",
31123112
"hash": "signature",
3113-
"id": "test-uuid-1234",
3113+
"id": "signature",
31143114
"isBridgeTx": true,
31153115
"isSolana": true,
31163116
"networkClientId": "test-snap",
@@ -3132,7 +3132,7 @@ Object {
31323132

31333133
exports[`BridgeStatusController submitTx: Solana bridge should successfully submit a transaction 3`] = `
31343134
Object {
3135-
"bridgeTxMetaId": "test-uuid-1234",
3135+
"bridgeTxMetaId": "signature",
31363136
}
31373137
`;
31383138

@@ -3233,7 +3233,7 @@ Object {
32333233
"status": "PENDING",
32343234
},
32353235
"targetContractAddress": undefined,
3236-
"txMetaId": "test-uuid-1234",
3236+
"txMetaId": "signature",
32373237
}
32383238
`;
32393239

@@ -3439,7 +3439,7 @@ Object {
34393439
"destinationTokenDecimals": 18,
34403440
"destinationTokenSymbol": "USDC",
34413441
"hash": "signature",
3442-
"id": "test-uuid-1234",
3442+
"id": "signature",
34433443
"isBridgeTx": false,
34443444
"isSolana": true,
34453445
"networkClientId": "test-snap",
@@ -3554,7 +3554,7 @@ Object {
35543554
"status": "PENDING",
35553555
},
35563556
"targetContractAddress": undefined,
3557-
"txMetaId": "test-uuid-1234",
3557+
"txMetaId": "signature",
35583558
}
35593559
`;
35603560

@@ -3681,7 +3681,6 @@ Array [
36813681
"chain_id_source": "eip155:42161",
36823682
"custom_slippage": true,
36833683
"destination_transaction": "PENDING",
3684-
"error_message": undefined,
36853684
"gas_included": false,
36863685
"is_hardware_wallet": false,
36873686
"price_impact": 0,
@@ -3727,7 +3726,7 @@ Array [
37273726
"chain_id_source": "eip155:42161",
37283727
"custom_slippage": true,
37293728
"destination_transaction": "FAILED",
3730-
"error_message": undefined,
3729+
"error_message": "",
37313730
"gas_included": false,
37323731
"is_hardware_wallet": false,
37333732
"price_impact": 0,
@@ -3763,7 +3762,7 @@ Array [
37633762
"chain_id_destination": "eip155:42161",
37643763
"chain_id_source": "eip155:42161",
37653764
"custom_slippage": false,
3766-
"error_message": undefined,
3765+
"error_message": "",
37673766
"gas_included": false,
37683767
"is_hardware_wallet": false,
37693768
"price_impact": 0,
@@ -3799,7 +3798,7 @@ Array [
37993798
"chain_id_destination": "eip155:42161",
38003799
"chain_id_source": "eip155:42161",
38013800
"custom_slippage": false,
3802-
"error_message": undefined,
3801+
"error_message": "",
38033802
"gas_included": false,
38043803
"is_hardware_wallet": false,
38053804
"price_impact": 0,
@@ -3846,7 +3845,7 @@ Array [
38463845
"chain_id_source": "eip155:42161",
38473846
"custom_slippage": true,
38483847
"destination_transaction": "FAILED",
3849-
"error_message": undefined,
3848+
"error_message": "",
38503849
"gas_included": false,
38513850
"is_hardware_wallet": false,
38523851
"price_impact": 0,
@@ -3883,7 +3882,7 @@ Array [
38833882
"chain_id_destination": "eip155:42161",
38843883
"chain_id_source": "eip155:42161",
38853884
"custom_slippage": false,
3886-
"error_message": undefined,
3885+
"error_message": "",
38873886
"gas_included": false,
38883887
"is_hardware_wallet": false,
38893888
"price_impact": 0,

packages/bridge-status-controller/src/bridge-status-controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
229229
this.#trackUnifiedSwapBridgeEvent(
230230
UnifiedSwapBridgeEventName.Completed,
231231
id,
232-
getEVMTxPropertiesFromTransactionMeta(transactionMeta),
233232
);
234233
}
235234
if (type === TransactionType.bridge && !isSolanaChainId(chainId)) {

packages/bridge-status-controller/src/utils/metrics.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ describe('metrics utils', () => {
985985
it('should return correct properties for a successful swap transaction', () => {
986986
const result = getEVMTxPropertiesFromTransactionMeta(mockTransactionMeta);
987987
expect(result).toStrictEqual({
988-
error_message: undefined,
988+
error_message: '',
989989
chain_id_source: 'eip155:1',
990990
chain_id_destination: 'eip155:1',
991991
token_symbol_source: 'ETH',
@@ -1027,7 +1027,7 @@ describe('metrics utils', () => {
10271027
const result = getEVMTxPropertiesFromTransactionMeta(
10281028
failedTransactionMeta,
10291029
);
1030-
expect(result.error_message).toBe('Failed to finalize swap tx');
1030+
expect(result.error_message).toBe('Transaction failed');
10311031
expect(result.source_transaction).toBe('FAILED');
10321032
});
10331033

packages/bridge-status-controller/src/utils/metrics.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,7 @@ export const getEVMTxPropertiesFromTransactionMeta = (
247247
].includes(transactionMeta.status)
248248
? StatusTypes.FAILED
249249
: StatusTypes.COMPLETE,
250-
error_message: transactionMeta.error?.message
251-
? 'Failed to finalize swap tx'
252-
: undefined,
250+
error_message: transactionMeta.error?.message ?? '',
253251
chain_id_source: formatChainIdToCaip(transactionMeta.chainId),
254252
chain_id_destination: formatChainIdToCaip(transactionMeta.chainId),
255253
token_symbol_source: transactionMeta.sourceTokenSymbol ?? '',

packages/bridge-status-controller/src/utils/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export const handleSolanaTxResponse = (
148148
return {
149149
...getTxMetaFields(quoteResponse),
150150
time: Date.now(),
151-
id: uuid(),
151+
id: hash ?? uuid(),
152152
chainId: hexChainId,
153153
networkClientId: snapId ?? hexChainId,
154154
txParams: { from: selectedAccountAddress, data: quoteResponse.trade },

0 commit comments

Comments
 (0)