Skip to content

Commit

Permalink
fix: patch transaction controller in mobile to add fallback gas estim…
Browse files Browse the repository at this point in the history
…ation (#8707)

## **Description**
Diff in core repo corresponding to this patch:
MetaMask/core@0c09517

This patches transaction-controller 6.1.0, introducing a fallback for
gas estimations. In cases of failed gas estimation, the transaction will
default to using 95% of the latest block gas limit. This ensures that
transactions have viable gas.
 
Previously, if gas estimation for a transaction failed (for example, due
to the transaction being reverted), the gasHex value would remain
undefined. This issue led to the transaction being assigned zero gas,
causing it to be submitted to the mempool where it would get "stuck".
 
This change is specific to version 6.1.0 of the transaction-controller.
Later versions of the TransactionController include this fix.


<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **Related issues**

Fixes: #8533

## **Manual testing steps**

1. Go to https://mmsdk-polygon-swap.vercel.app/
2. Add Polygon chain and switch to network
3. Click "Send Transaction"
4. Try again if you get a JSON-RPC error (unrelated issue)

Transaction should submit and fail... but not get stuck in "submitted"
state as in #8533.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
dbrans authored Feb 26, 2024
1 parent 0e2c734 commit 4869690
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions patches/@metamask+transaction-controller+6.1.0.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
diff --git a/node_modules/@metamask/transaction-controller/dist/.patch.txt b/node_modules/@metamask/transaction-controller/dist/.patch.txt
new file mode 100644
index 0000000..e8035ba
index 0000000..550de56
--- /dev/null
+++ b/node_modules/@metamask/transaction-controller/dist/.patch.txt
@@ -0,0 +1,7 @@
Expand Down Expand Up @@ -811,7 +811,7 @@ index 236aaf1..0000000
-{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAKtC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAsB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGtE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,EACT,MAAM,8BAA8B,CAAC;AActC,OAAO,EACL,aAAa,IAAI,qBAAqB,EACtC,kBAAkB,EAClB,aAAa,IAAI,qBAAqB,EACvC,MAAM,+BAA+B,CAAC;AAkBvC;;;;GAIG;AACH,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,eAAe,EAAE,eAAe,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IA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,CAAC,iBAAiB;YAOX,eAAe;IAyB7B,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,aAAa;CAGtB;AAED,eAAe,qBAAqB,CAAC"}
\ No newline at end of file
diff --git a/node_modules/@metamask/transaction-controller/dist/TransactionController.js b/node_modules/@metamask/transaction-controller/dist/TransactionController.js
index 3edd9c2..28a1c63 100644
index 3edd9c2..f173f21 100644
--- a/node_modules/@metamask/transaction-controller/dist/TransactionController.js
+++ b/node_modules/@metamask/transaction-controller/dist/TransactionController.js
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Expand Down Expand Up @@ -1234,7 +1234,16 @@ index 3edd9c2..28a1c63 100644
const baseTransactionMeta = Object.assign(Object.assign({}, transactionMeta), { id: (0, uuid_1.v1)(), time: Date.now(), transactionHash });
const newTransactionMeta = newMaxFeePerGas && newMaxPriorityFeePerGas
? Object.assign(Object.assign({}, baseTransactionMeta), { transaction: Object.assign(Object.assign({}, transactionMeta.transaction), { maxFeePerGas: newMaxFeePerGas, maxPriorityFeePerGas: newMaxPriorityFeePerGas }) }) : Object.assign(Object.assign({}, baseTransactionMeta), { transaction: Object.assign(Object.assign({}, transactionMeta.transaction), { gasPrice: newGasPrice }) });
@@ -661,6 +501,23 @@ class TransactionController extends base_controller_1.BaseController {
@@ -596,6 +436,8 @@ class TransactionController extends base_controller_1.BaseController {
}
catch (error) {
estimateGasError = utils_1.ESTIMATE_GAS_ERROR;
+ // Fallback to 95% of the block gasLimit.
+ gasHex = estimatedTransaction.gas;
}
// 4. Pad estimated gas without exceeding the most recent block gasLimit. If the network is a
// a custom network then return the eth_estimateGas value.
@@ -661,6 +503,23 @@ class TransactionController extends base_controller_1.BaseController {
transactions[index] = transactionMeta;
this.update({ transactions: this.trimTransactionsForState(transactions) });
}
Expand All @@ -1258,7 +1267,7 @@ index 3edd9c2..28a1c63 100644
/**
* Removes all transactions from state, optionally based on the current network.
*
@@ -686,67 +543,15 @@ class TransactionController extends base_controller_1.BaseController {
@@ -686,67 +545,15 @@ class TransactionController extends base_controller_1.BaseController {
});
}
/**
Expand Down Expand Up @@ -1332,7 +1341,7 @@ index 3edd9c2..28a1c63 100644
});
}
/**
@@ -765,7 +570,9 @@ class TransactionController extends base_controller_1.BaseController {
@@ -765,7 +572,9 @@ class TransactionController extends base_controller_1.BaseController {
*/
trimTransactionsForState(transactions) {
const nonceNetworkSet = new Set();
Expand All @@ -1343,7 +1352,7 @@ index 3edd9c2..28a1c63 100644
const { chainId, networkID, status, transaction, time } = tx;
if (transaction) {
const key = `${transaction.nonce}-${chainId ? (0, controller_utils_1.convertHexToDecimal)(chainId) : networkID}-${new Date(time).toDateString()}`;
@@ -780,7 +587,7 @@ class TransactionController extends base_controller_1.BaseController {
@@ -780,7 +589,7 @@ class TransactionController extends base_controller_1.BaseController {
}
return false;
});
Expand All @@ -1352,7 +1361,7 @@ index 3edd9c2..28a1c63 100644
return txsToKeep;
}
/**
@@ -790,10 +597,10 @@ class TransactionController extends base_controller_1.BaseController {
@@ -790,10 +599,10 @@ class TransactionController extends base_controller_1.BaseController {
* @returns Whether the transaction is in a final state.
*/
isFinalState(status) {
Expand All @@ -1367,7 +1376,7 @@ index 3edd9c2..28a1c63 100644
}
/**
* Method to verify the state of a transaction using the Blockchain as a source of truth.
@@ -805,7 +612,7 @@ class TransactionController extends base_controller_1.BaseController {
@@ -805,7 +614,7 @@ class TransactionController extends base_controller_1.BaseController {
return __awaiter(this, void 0, void 0, function* () {
const { status, transactionHash } = meta;
switch (status) {
Expand All @@ -1376,7 +1385,7 @@ index 3edd9c2..28a1c63 100644
const txReceipt = yield (0, controller_utils_1.query)(this.ethQuery, 'getTransactionReceipt', [
transactionHash,
]);
@@ -822,7 +629,7 @@ class TransactionController extends base_controller_1.BaseController {
@@ -822,7 +631,7 @@ class TransactionController extends base_controller_1.BaseController {
return [meta, false];
}
return [meta, true];
Expand All @@ -1385,7 +1394,7 @@ index 3edd9c2..28a1c63 100644
const txObj = yield (0, controller_utils_1.query)(this.ethQuery, 'getTransactionByHash', [
transactionHash,
]);
@@ -837,9 +644,17 @@ class TransactionController extends base_controller_1.BaseController {
@@ -837,9 +646,17 @@ class TransactionController extends base_controller_1.BaseController {
}
/* istanbul ignore next */
if (txObj === null || txObj === void 0 ? void 0 : txObj.blockNumber) {
Expand All @@ -1406,7 +1415,7 @@ index 3edd9c2..28a1c63 100644
}
return [meta, false];
default:
@@ -868,128 +683,233 @@ class TransactionController extends base_controller_1.BaseController {
@@ -868,128 +685,233 @@ class TransactionController extends base_controller_1.BaseController {
return Number(txReceipt.status) === 0;
});
}
Expand Down

0 comments on commit 4869690

Please sign in to comment.