1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Remove unnecessary tx meta properties (#8489)

* Remove `estimatedGas` property from `txMeta`

The `estimatedGas` property was a cache of the gas value estimated for
a transaction when the default gas limit was set. This property wasn't
used anywhere. It may have been useful for debugging purposes, but the
same gas estimate is already stored on the `history` property so it
should be present in state logs regardless.

* Remove `gasLimitSpecified` txMeta property

The `gasLimitSpecified` property of `txMeta` wasn't used for anything.
It might have been useful for debugging purposes, but whether or not
the gas limit was specified can also be determined from looking at the
transaction history, so it's not a huge loss.

* Remove `gasPriceSpecified` txMeta property

The `gasPriceSpecified` property of `txMeta` wasn't used for anything.
It might have been useful for debugging purposes, but whether or not
the gas price was specified can also be determined from looking at the
transaction history, so it's not a huge loss.

* Remove `simpleSend` txMeta property

The `simpleSend` property of `txMeta` was used to ensure a buffer was
not added to the gas limit during gas estimation for simple send
transactions. It was made redundant by #8484, which accomplishes this
without the use of this property.
This commit is contained in:
Mark Stacey 2020-05-01 08:44:05 -03:00 committed by GitHub
parent 92592fc905
commit 165666b315
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 35 additions and 614 deletions

View File

@ -84,9 +84,6 @@ initialize().catch(log.error)
* @property {boolean} loadingDefaults - TODO: Document
* @property {Object} txParams - The tx params as passed to the network provider.
* @property {Object[]} history - A history of mutations to this TransactionMeta object.
* @property {boolean} gasPriceSpecified - True if the suggesting dapp specified a gas price, prevents auto-estimation.
* @property {boolean} gasLimitSpecified - True if the suggesting dapp specified a gas limit, prevents auto-estimation.
* @property {string} estimatedGas - A hex string represented the estimated gas limit required to complete the transaction.
* @property {string} origin - A string representing the interface that suggested the transaction.
* @property {Object} nonceDetails - A metadata object containing information used to derive the suggested nonce, useful for debugging nonce issues.
* @property {string} rawTx - A hex string of the final signed transaction, ready to submit to the network.

View File

@ -59,9 +59,6 @@ txMeta = {
"value": "0x3b9aca00"
},
...], // I've removed most of history for this
"gasPriceSpecified": false, //whether or not the user/dapp has specified gasPrice
"gasLimitSpecified": false, //whether or not the user/dapp has specified gas
"estimatedGas": "5208",
"origin": "MetaMask", //debug
"nonceDetails": {
"params": {

View File

@ -268,7 +268,6 @@ export default class TransactionController extends EventEmitter {
async addTxGasDefaults (txMeta, getCodeResponse) {
const txParams = txMeta.txParams
txMeta.gasPriceSpecified = Boolean(txParams.gasPrice)
let gasPrice = txParams.gasPrice
if (!gasPrice) {
gasPrice = this.getGasPrice ? this.getGasPrice() : await this.query.gasPrice()
@ -278,8 +277,6 @@ export default class TransactionController extends EventEmitter {
// set gasLimit
if (txParams.gas) {
txMeta.estimatedGas = txParams.gas
txMeta.gasLimitSpecified = Boolean(txParams.gas)
return txMeta
} else if (
txParams.to &&
@ -298,9 +295,6 @@ export default class TransactionController extends EventEmitter {
// This is a standard ether simple send, gas requirement is exactly 21k
txParams.gas = SIMPLE_GAS_COST
txMeta.estimatedGas = SIMPLE_GAS_COST
txMeta.simpleSend = true
txMeta.gasLimitSpecified = Boolean(txParams.gas)
return txMeta
}

View File

@ -72,12 +72,11 @@ export default class TxGasUtil {
@param {string} estimatedGasHex - the estimated gas hex
*/
setTxGas (txMeta, blockGasLimitHex, estimatedGasHex) {
txMeta.estimatedGas = addHexPrefix(estimatedGasHex)
const txParams = txMeta.txParams
// if gasLimit not originally specified,
// try adding an additional gas buffer to our estimation for safety
const recommendedGasHex = this.addGasBuffer(txMeta.estimatedGas, blockGasLimitHex)
const recommendedGasHex = this.addGasBuffer(addHexPrefix(estimatedGasHex), blockGasLimitHex)
txParams.gas = recommendedGasHex
return
}

View File

@ -76,9 +76,6 @@
"message": "Error: intrinsic gas too low",
"stack": "Error: some error"
},
"estimatedGas": "0xcf08",
"gasLimitSpecified": true,
"gasPriceSpecified": true,
"history": [
{
"id": 4068311466147836,
@ -99,21 +96,6 @@
"op": "replace",
"path": "/loadingDefaults",
"value": false
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0xcf08"
}
],
[
@ -270,21 +252,6 @@
"op": "replace",
"path": "/loadingDefaults",
"value": false
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0xcf08"
}
],
[
@ -303,16 +270,10 @@
"note": "txStateManager: setting status to approved"
}
]
],
"gasPriceSpecified": true,
"gasLimitSpecified": true,
"estimatedGas": "0xcf08"
]
},
{
"estimatedGas": "8d41",
"firstRetryBlockNumber": "0x2cbc70",
"gasLimitSpecified": false,
"gasPriceSpecified": false,
"hash": "0xfbd997bf9bb85ca1598952ca23e7910502d527e06cb6ee1bbe7e7dd59d6909cd",
"history": [
{
@ -347,21 +308,6 @@
"op": "replace",
"path": "/loadingDefaults",
"value": false
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": false
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": false
},
{
"op": "add",
"path": "/estimatedGas",
"value": "8d41"
}
],
[
@ -517,10 +463,7 @@
}
},
{
"estimatedGas": "8d41",
"firstRetryBlockNumber": "0x2cbc70",
"gasLimitSpecified": false,
"gasPriceSpecified": false,
"hash": "0xfbd997bf9bb85ca1598952ca23e7910502d527e06cb6ee1bbe7e7dd59d6909cd",
"history": [
{
@ -555,21 +498,6 @@
"op": "replace",
"path": "/loadingDefaults",
"value": false
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": false
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": false
},
{
"op": "add",
"path": "/estimatedGas",
"value": "8d41"
}
],
[
@ -759,21 +687,6 @@
"op": "replace",
"path": "/loadingDefaults",
"value": false
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0xcf08"
}
],
[],
@ -873,9 +786,6 @@
}
]
],
"gasPriceSpecified": true,
"gasLimitSpecified": true,
"estimatedGas": "0xcf08",
"nonceDetails": {
"params": {
"highestLocalNonce": 3,
@ -936,27 +846,9 @@
"op": "replace",
"path": "/loadingDefaults",
"value": false
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0xcf08"
}
]
],
"gasPriceSpecified": true,
"gasLimitSpecified": true,
"estimatedGas": "0xcf08"
]
}
],
"unapprovedTxs": {
@ -993,27 +885,9 @@
"op": "replace",
"path": "/loadingDefaults",
"value": false
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0xcf08"
}
]
],
"gasPriceSpecified": true,
"gasLimitSpecified": true,
"estimatedGas": "0xcf08"
]
}
},
"unapprovedMsgs": {

View File

@ -51,21 +51,6 @@
"path": "/loadingDefaults",
"value": false,
"timestamp": 1536268017685
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0x5208"
}
],
[
@ -78,9 +63,6 @@
}
]
],
"gasPriceSpecified": true,
"gasLimitSpecified": true,
"estimatedGas": "0x5208",
"origin": "MetaMask"
}
},
@ -193,21 +175,6 @@
"path": "/loadingDefaults",
"value": false,
"timestamp": 1528133130666
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0xcf08"
}
],
[
@ -325,9 +292,6 @@
}
]
],
"gasPriceSpecified": true,
"gasLimitSpecified": true,
"estimatedGas": "0xcf08",
"origin": "MetaMask",
"nonceDetails": {
"params": {
@ -391,21 +355,6 @@
"path": "/loadingDefaults",
"value": false,
"timestamp": 1528133150011
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0xcf08"
}
],
[
@ -523,9 +472,6 @@
}
]
],
"gasPriceSpecified": true,
"gasLimitSpecified": true,
"estimatedGas": "0xcf08",
"origin": "MetaMask",
"nonceDetails": {
"params": {
@ -589,21 +535,6 @@
"path": "/loadingDefaults",
"value": false,
"timestamp": 1528133180720
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0xcf08"
}
],
[
@ -721,9 +652,6 @@
}
]
],
"gasPriceSpecified": true,
"gasLimitSpecified": true,
"estimatedGas": "0xcf08",
"origin": "MetaMask",
"nonceDetails": {
"params": {
@ -793,32 +721,11 @@
"op": "replace",
"path": "/loadingDefaults",
"value": false
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": false
},
{
"op": "add",
"path": "/estimatedGas",
"value": "40f14"
}
],
[
{
"op": "replace",
"path": "/estimatedGas",
"value": "40f14",
"note": "#newUnapprovedTransaction - adding the origin",
"timestamp": 1528133225492
},
{
"op": "add",
"path": "/origin",
"value": "crypko.ai"
@ -930,9 +837,6 @@
}
]
],
"gasPriceSpecified": true,
"gasLimitSpecified": false,
"estimatedGas": "40f14",
"origin": "crypko.ai",
"nonceDetails": {
"params": {
@ -998,21 +902,6 @@
"path": "/loadingDefaults",
"value": false,
"timestamp": 1528133291486
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": true
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0xd508"
}
],
[
@ -1130,9 +1019,6 @@
}
]
],
"gasPriceSpecified": true,
"gasLimitSpecified": true,
"estimatedGas": "0xd508",
"origin": "MetaMask",
"nonceDetails": {
"params": {
@ -1207,26 +1093,6 @@
"op": "replace",
"path": "/loadingDefaults",
"value": false
},
{
"op": "add",
"path": "/gasPriceSpecified",
"value": false
},
{
"op": "add",
"path": "/gasLimitSpecified",
"value": false
},
{
"op": "add",
"path": "/simpleSend",
"value": true
},
{
"op": "add",
"path": "/estimatedGas",
"value": "0x5208"
}
],
[
@ -1248,10 +1114,6 @@
}
]
],
"gasPriceSpecified": false,
"gasLimitSpecified": false,
"simpleSend": true,
"estimatedGas": "0x5208",
"origin": "tmashuang.github.io"
}
]

File diff suppressed because it is too large Load Diff

View File

@ -88,8 +88,6 @@
"nonce":"0x0",
"gasLimit":"0x5209"
},
"gasLimitSpecified":false,
"estimatedGas":"0x5209",
"txFee":"17e0186e60800",
"txValue":"de0b6b3a7640000",
"maxCost":"de234b52e4a0800",
@ -112,8 +110,6 @@
"gasPrice":"0x04a817c800",
"gasLimit":"0x5209"
},
"gasLimitSpecified":false,
"estimatedGas":"0x5209",
"txFee":"17e0186e60800",
"txValue":"de0b6b3a7640000",
"maxCost":"de234b52e4a0800",
@ -133,8 +129,6 @@
"metamaskNetworkId":"3",
"gas":"0x5209"
},
"gasLimitSpecified":false,
"estimatedGas":"0x5209",
"txFee":"17e0186e60800",
"txValue":"de0b6b3a7640000",
"maxCost":"de234b52e4a0800"

View File

@ -7,10 +7,7 @@ export default {}
// for pending middlewares test
export const txMetaStub = {
'estimatedGas': '0x5208',
'firstRetryBlockNumber': '0x51a402',
'gasLimitSpecified': true,
'gasPriceSpecified': true,
'hash': '0x2cc5a25744486f7383edebbf32003e5a66e18135799593d6b5cdd2bb43674f09',
'history': [
{
@ -36,21 +33,6 @@ export const txMetaStub = {
'timestamp': 1572395156645,
'value': false,
},
{
'op': 'add',
'path': '/gasPriceSpecified',
'value': true,
},
{
'op': 'add',
'path': '/gasLimitSpecified',
'value': true,
},
{
'op': 'add',
'path': '/estimatedGas',
'value': '0x5208',
},
],
[
{

View File

@ -10,7 +10,6 @@ describe('TransactionActivityLog utils', function () {
it('should return activities for an array of transactions', function () {
const transactions = [
{
estimatedGas: '0x5208',
hash: '0xa14f13d36b3901e352ce3a7acb9b47b001e5a3370f06232a0953c6fc6fad91b3',
history: [
{
@ -171,21 +170,6 @@ describe('TransactionActivityLog utils', function () {
timestamp: 1535507561515,
value: false,
},
{
op: 'add',
path: '/gasPriceSpecified',
value: true,
},
{
op: 'add',
path: '/gasLimitSpecified',
value: true,
},
{
op: 'add',
path: '/estimatedGas',
value: '0x5208',
},
],
[
{

View File

@ -514,15 +514,11 @@ describe('Confirm Transaction Duck', function () {
tokenSymbol: '',
},
txData: {
estimatedGas: '0x5208',
gasLimitSpecified: false,
gasPriceSpecified: false,
history: [],
id: 2603411941761054,
loadingDefaults: false,
metamaskNetworkId: '3',
origin: 'faucet.metamask.io',
simpleSend: true,
status: 'unapproved',
time: 1530838113716,
},
@ -548,15 +544,11 @@ describe('Confirm Transaction Duck', function () {
it('updates txData and updates gas values in confirmTransaction', function () {
const txData = {
estimatedGas: '0x5208',
gasLimitSpecified: false,
gasPriceSpecified: false,
history: [],
id: 2603411941761054,
loadingDefaults: false,
metamaskNetworkId: '3',
origin: 'faucet.metamask.io',
simpleSend: true,
status: 'unapproved',
time: 1530838113716,
txParams: {
@ -622,15 +614,11 @@ describe('Confirm Transaction Duck', function () {
network: '3',
unapprovedTxs: {
2603411941761054: {
estimatedGas: '0x5208',
gasLimitSpecified: false,
gasPriceSpecified: false,
history: [],
id: 2603411941761054,
loadingDefaults: false,
metamaskNetworkId: '3',
origin: 'faucet.metamask.io',
simpleSend: true,
status: 'unapproved',
time: 1530838113716,
txParams: {

View File

@ -193,8 +193,6 @@ export default {
'metamaskNetworkId': '3',
'gas': '0x5209',
},
'gasLimitSpecified': false,
'estimatedGas': '0x5209',
'txFee': '17e0186e60800',
'txValue': 'de0b6b3a7640000',
'maxCost': 'de234b52e4a0800',

View File

@ -511,8 +511,6 @@ describe('send selectors', function () {
metamaskNetworkId: '3',
gas: '0x5209',
},
gasLimitSpecified: false,
estimatedGas: '0x5209',
txFee: '17e0186e60800',
txValue: 'de0b6b3a7640000',
maxCost: 'de234b52e4a0800',

View File

@ -194,8 +194,6 @@ export default {
'metamaskNetworkId': '3',
'gas': '0x5209',
},
'gasLimitSpecified': false,
'estimatedGas': '0x5209',
'txFee': '17e0186e60800',
'txValue': 'de0b6b3a7640000',
'maxCost': 'de234b52e4a0800',