From d7134894f11ff5fc4d65887bf01986a188a6d9b4 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 14 Aug 2021 12:08:09 -1000 Subject: [PATCH 01/10] Remove type = 0x0 default --- packages/web3-core-method/src/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 319d66ffc97..ca0e7d0263e 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -840,8 +840,6 @@ function _handleTxType(tx) { txType = utils.toHex(tx.type) } else if (tx.type === undefined && hasEip1559) { txType = '0x2' - } else { - txType = '0x0' } if (tx.gasPrice !== undefined && (txType === '0x2' || hasEip1559)) From 1520c4ce12dc72f4668d9643f01db006da791a82 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 14 Aug 2021 12:10:39 -1000 Subject: [PATCH 02/10] Update gasPrice short circuit check --- packages/web3-core-method/src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index ca0e7d0263e..74071688b8b 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -887,7 +887,10 @@ function _handleTxPricing(method, tx) { params: 0 })).createFunction(method.requestManager); - if (tx.type < '0x2' && tx.gasPrice !== undefined) { + if (( + tx.type === undefined || tx.type < '0x2') + && tx.gasPrice !== undefined + ) { // Legacy transaction, return provided gasPrice resolve({ gasPrice: tx.gasPrice }) } else { From 7056630bcdcd7f0ec9e12682374a8200693956f6 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 14 Aug 2021 12:42:12 -1000 Subject: [PATCH 03/10] Update tests - remove type: 0x0 --- test/contract.js | 3 +-- test/eth.sendTransaction.js | 3 +-- test/method.buildCall.js | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/test/contract.js b/test/contract.js index b5e5e427355..6ce8ff68a00 100644 --- a/test/contract.js +++ b/test/contract.js @@ -2678,8 +2678,7 @@ var runTests = function(contractFactory) { '0000000000000000000000000000000000000000000000000000000000000011' , to: addressLowercase, from: addressLowercase, - gasPrice: '0x45656456456456', - type: '0x0' + gasPrice: '0x45656456456456' }]); done(); diff --git a/test/eth.sendTransaction.js b/test/eth.sendTransaction.js index cc88b8b3092..e7afb741f83 100644 --- a/test/eth.sendTransaction.js +++ b/test/eth.sendTransaction.js @@ -68,8 +68,7 @@ var tests = [{ from: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", to: "0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", value: "0x11f71f76bb1", - gasPrice: "0x1234567", - type: "0x0" + gasPrice: "0x1234567" }], result3: '0x1234567' },{ diff --git a/test/method.buildCall.js b/test/method.buildCall.js index 07b354dd9dc..fce17319db4 100644 --- a/test/method.buildCall.js +++ b/test/method.buildCall.js @@ -209,8 +209,7 @@ describe('lib/web3/method', function () { from: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae', to: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae', data: '0xa123456', - gasPrice: '0x1234567453543456321456321', - type: '0x0' + gasPrice: '0x1234567453543456321456321' }]); done(); From 78bf5d95a77ce75a403804083b104b3f8e5fc06a Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 14 Aug 2021 12:57:05 -1000 Subject: [PATCH 04/10] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 753d57edac5..273977a5227 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -428,3 +428,7 @@ Released with 1.0.0-beta.37 code base. ## [Unreleased] ## [1.5.2] + +### Fixed + +- `type: 0x0` was being added to legacy transaction when using `eth.sendTransaction` or `eth_sendRawTransaction` (#4241) From a9029cade26a2ecc48896a107201c6621bcd510c Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 14 Aug 2021 13:18:06 -1000 Subject: [PATCH 05/10] Apply patch fix to web3-eth-accounts --- CHANGELOG.md | 2 +- packages/web3-eth-accounts/src/index.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 273977a5227..1d34674e009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -431,4 +431,4 @@ Released with 1.0.0-beta.37 code base. ### Fixed -- `type: 0x0` was being added to legacy transaction when using `eth.sendTransaction` or `eth_sendRawTransaction` (#4241) +- `type: 0x0` was being added to legacy transaction when using `eth.sendTransaction`, `eth.sendRawTransaction`, of `eth.signTransaction` (#4241) diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index 40f8e4532f3..7fa9e93678a 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -331,8 +331,6 @@ function _handleTxType(tx) { txType = utils.toHex(tx.type) } else if (tx.type === undefined && hasEip1559) { txType = '0x2' - } else { - txType = '0x0' } if (tx.gasPrice !== undefined && (txType === '0x2' || hasEip1559)) @@ -364,7 +362,10 @@ function _handleTxType(tx) { function _handleTxPricing(_this, tx) { return new Promise((resolve, reject) => { try { - if (tx.type < '0x2' && tx.gasPrice !== undefined) { + if ( + (tx.type === undefined || tx.type < '0x2') + && tx.gasPrice !== undefined + ) { // Legacy transaction, return provided gasPrice resolve({ gasPrice: tx.gasPrice }) } else { From 6fb9cf5cf2e95d6d4c1eb467a60564ded7e0cd57 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 14 Aug 2021 13:51:14 -1000 Subject: [PATCH 06/10] Remove tx type defaulting --- packages/web3-core-method/src/index.js | 114 +++++++------------------ 1 file changed, 31 insertions(+), 83 deletions(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 74071688b8b..7a12852d048 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -782,9 +782,6 @@ Method.prototype.buildCall = function () { ) ) ) { - if (typeof payload.params[0].type === 'undefined') - payload.params[0].type = _handleTxType(payload.params[0]); - _handleTxPricing(method, payload.params[0]).then(txPricing => { if (txPricing.gasPrice !== undefined) { payload.params[0].gasPrice = txPricing.gasPrice; @@ -830,44 +827,6 @@ Method.prototype.buildCall = function () { return send; }; -function _handleTxType(tx) { - // Taken from https://github.com/ethers-io/ethers.js/blob/2a7ce0e72a1e0c9469e10392b0329e75e341cf18/packages/abstract-signer/src.ts/index.ts#L215 - const hasEip1559 = (tx.maxFeePerGas !== undefined || tx.maxPriorityFeePerGas !== undefined); - - let txType; - - if (tx.type !== undefined) { - txType = utils.toHex(tx.type) - } else if (tx.type === undefined && hasEip1559) { - txType = '0x2' - } - - if (tx.gasPrice !== undefined && (txType === '0x2' || hasEip1559)) - throw Error("eip-1559 transactions don't support gasPrice"); - if ((txType === '0x1' || txType === '0x0') && hasEip1559) - throw Error("pre-eip-1559 transaction don't support maxFeePerGas/maxPriorityFeePerGas"); - - if ( - hasEip1559 || - ( - (tx.common && tx.common.hardfork && tx.common.hardfork.toLowerCase() === HardForks.London) || - (tx.hardfork && tx.hardfork.toLowerCase() === HardForks.London) - ) - ) { - txType = '0x2'; - } else if ( - tx.accessList || - ( - (tx.common && tx.common.hardfork && tx.common.hardfork.toLowerCase() === HardForks.Berlin) || - (tx.hardfork && tx.hardfork.toLowerCase() === HardForks.Berlin) - ) - ) { - txType = '0x1'; - } - - return txType -} - function _handleTxPricing(method, tx) { return new Promise((resolve, reject) => { try { @@ -887,50 +846,39 @@ function _handleTxPricing(method, tx) { params: 0 })).createFunction(method.requestManager); - if (( - tx.type === undefined || tx.type < '0x2') - && tx.gasPrice !== undefined - ) { - // Legacy transaction, return provided gasPrice - resolve({ gasPrice: tx.gasPrice }) - } else { - Promise.all([ - getBlockByNumber(), - getGasPrice() - ]).then(responses => { - const [block, gasPrice] = responses; - if ( - (tx.type === '0x2') && - block && block.baseFeePerGas - ) { - // The network supports EIP-1559 - - // Taken from https://github.com/ethers-io/ethers.js/blob/ba6854bdd5a912fe873d5da494cb5c62c190adde/packages/abstract-provider/src.ts/index.ts#L230 - let maxPriorityFeePerGas, maxFeePerGas; - - if (tx.gasPrice) { - // Using legacy gasPrice property on an eip-1559 network, - // so use gasPrice as both fee properties - maxPriorityFeePerGas = tx.gasPrice; - maxFeePerGas = tx.gasPrice; - delete tx.gasPrice; - } else { - maxPriorityFeePerGas = tx.maxPriorityFeePerGas || '0x3B9ACA00'; // 1 Gwei - maxFeePerGas = tx.maxFeePerGas || - utils.toHex( - utils.toBN(block.baseFeePerGas) - .mul(utils.toBN(2)) - .add(utils.toBN(maxPriorityFeePerGas)) - ); - } - resolve({ maxFeePerGas, maxPriorityFeePerGas }); + Promise.all([ + getBlockByNumber(), + getGasPrice() + ]).then(responses => { + const [block, gasPrice] = responses; + if (block && block.baseFeePerGas) { + // The network supports EIP-1559 + + // Taken from https://github.com/ethers-io/ethers.js/blob/ba6854bdd5a912fe873d5da494cb5c62c190adde/packages/abstract-provider/src.ts/index.ts#L230 + let maxPriorityFeePerGas, maxFeePerGas; + + if (tx.gasPrice) { + // Using legacy gasPrice property on an eip-1559 network, + // so use gasPrice as both fee properties + maxPriorityFeePerGas = tx.gasPrice; + maxFeePerGas = tx.gasPrice; + delete tx.gasPrice; } else { - if (tx.maxPriorityFeePerGas || tx.maxFeePerGas) - throw Error("Network doesn't support eip-1559") - resolve({ gasPrice }); + maxPriorityFeePerGas = tx.maxPriorityFeePerGas || '0x3B9ACA00'; // 1 Gwei + maxFeePerGas = tx.maxFeePerGas || + utils.toHex( + utils.toBN(block.baseFeePerGas) + .mul(utils.toBN(2)) + .add(utils.toBN(maxPriorityFeePerGas)) + ); } - }) - } + resolve({ maxFeePerGas, maxPriorityFeePerGas }); + } else { + if (tx.maxPriorityFeePerGas || tx.maxFeePerGas) + throw Error("Network doesn't support eip-1559") + resolve({ gasPrice }); + } + }) } catch (error) { reject(error) } From 0c87c06a0bdabc2a6d0f087310aa81a2dd71cb65 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 14 Aug 2021 13:52:59 -1000 Subject: [PATCH 07/10] update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d34674e009..802e81d0213 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -431,4 +431,5 @@ Released with 1.0.0-beta.37 code base. ### Fixed -- `type: 0x0` was being added to legacy transaction when using `eth.sendTransaction`, `eth.sendRawTransaction`, of `eth.signTransaction` (#4241) +- Remove transaction `type` defaulting for `eth.sendTransaction`, `eth.sendRawTransaction` (#4241) +- `type: 0x0` was being added to legacy transaction when using `eth.signTransaction` (#4241) From fcb8a564d258954ee56b5a7f422738259af5db0f Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 14 Aug 2021 13:58:16 -1000 Subject: [PATCH 08/10] update failing test --- test/contract.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/contract.js b/test/contract.js index 6ce8ff68a00..3b5bc735d5a 100644 --- a/test/contract.js +++ b/test/contract.js @@ -2678,7 +2678,8 @@ var runTests = function(contractFactory) { '0000000000000000000000000000000000000000000000000000000000000011' , to: addressLowercase, from: addressLowercase, - gasPrice: '0x45656456456456' + maxPriorityFeePerGas: '0x3B9ACA00', + maxFeePerGas: '0x3b9aca0e' }]); done(); From ce2de6dcbc8ebfa0228ebaaef25ee0acb62be598 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 14 Aug 2021 14:08:15 -1000 Subject: [PATCH 09/10] Remove unused import --- packages/web3-core-method/src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 7a12852d048..fddedbd0136 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -28,7 +28,6 @@ var formatters = require('web3-core-helpers').formatters; var utils = require('web3-utils'); var promiEvent = require('web3-core-promievent'); var Subscriptions = require('web3-core-subscriptions').subscriptions; -var HardForks = require('@ethereumjs/common').Hardfork; var EthersTransactionUtils = require('@ethersproject/transactions'); From b1167c25c947054776c1bc0b02e68fb3a6937bb5 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 14 Aug 2021 14:30:05 -1000 Subject: [PATCH 10/10] Add quick check that user can pass type, and it's retained --- test/method.buildCall.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/method.buildCall.js b/test/method.buildCall.js index fce17319db4..2454399c25c 100644 --- a/test/method.buildCall.js +++ b/test/method.buildCall.js @@ -209,7 +209,8 @@ describe('lib/web3/method', function () { from: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae', to: '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae', data: '0xa123456', - gasPrice: '0x1234567453543456321456321' + gasPrice: '0x1234567453543456321456321', + type: '0x2' }]); done(); @@ -220,7 +221,8 @@ describe('lib/web3/method', function () { send({ from: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', - data: '0xa123456' + data: '0xa123456', + type: '0x2' }); });