Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

EIP1559 #4155

Merged
merged 42 commits into from
Jul 21, 2021
Merged

EIP1559 #4155

Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ec47e41
npm run build for 1.4.0-rc.0
spacesailor24 Jun 18, 2021
d50f17a
v1.4.0-rc.0
spacesailor24 Jun 18, 2021
87738b7
Update scripts/e2e.geth.instamine.sh to use v1.10.3 of Geth
spacesailor24 Jun 24, 2021
059be6d
Update scripts/e2e.geth.instamine.sh to use v1.10.3 of Geth
spacesailor24 Jun 24, 2021
7b2acdf
Fix typo
spacesailor24 Jun 24, 2021
bc8a427
Fix merge conflict
spacesailor24 Jun 24, 2021
5c11080
WIP
spacesailor24 Jun 25, 2021
c53a87e
Merge branch '1.x' into wyatt/eip1559
spacesailor24 Jun 25, 2021
f963659
Fix type in error catch
spacesailor24 Jun 28, 2021
3e4fcbe
Remove commented code
spacesailor24 Jun 30, 2021
7681019
Update index for tx pricing info
spacesailor24 Jun 30, 2021
3212c05
Correct order of if statements to properly assign tx type
spacesailor24 Jun 30, 2021
43a755f
Update maxFeePerGas calculation
spacesailor24 Jun 30, 2021
51f030e
Init _handleTxType function
spacesailor24 Jun 30, 2021
3b3efb2
Update _handleTxPricing to use gasPrice for eip-1559 txs
spacesailor24 Jun 30, 2021
b458b63
Fix bugs in _handleTxPricing
spacesailor24 Jun 30, 2021
1b66314
Update tests for eip-1559 changes
spacesailor24 Jun 30, 2021
ad5a22e
Fix BN bug: .mul only accepts BN instances
spacesailor24 Jun 30, 2021
4ebd78a
eth.accounts.signTransaction: Add London tests
spacesailor24 Jun 30, 2021
cd490a8
Fix merge conflicts
spacesailor24 Jul 3, 2021
43fc7aa
Add EIP-1559 test without AccessList
spacesailor24 Jul 3, 2021
5c5a517
Add tx.common.hardfork check to _handleTxType
spacesailor24 Jul 3, 2021
34e5cf6
Bug fixes
spacesailor24 Jul 3, 2021
72c9898
Add additional undefined check in _handleTxType
spacesailor24 Jul 3, 2021
073be03
Add additional check for tx.hardfork in _handleTxType
spacesailor24 Jul 3, 2021
1e3d662
Add additional check for tx.hardfork in _handleTxType
spacesailor24 Jul 3, 2021
2bb8c63
Update CHANGELOG
spacesailor24 Jul 3, 2021
572e416
Handling EIP1559 transactions in outputTransactionFormatter (#4167)
corymsmith Jul 7, 2021
abbc390
Revert geth docker version tag
spacesailor24 Jul 8, 2021
ef39538
Add additional EIP-2930 and EIP-1559 tests
spacesailor24 Jul 8, 2021
494f260
Merge branch '1.x' into wyatt/eip1559
spacesailor24 Jul 10, 2021
2437073
Merge branch 'wyatt/eip1559' of github.com:ChainSafe/web3.js into wya…
spacesailor24 Jul 10, 2021
b3ab709
EIP 1559 Debug #2 (#4171)
spacesailor24 Jul 19, 2021
dc810b3
Mergin conflicts
spacesailor24 Jul 19, 2021
e7d3833
Update error message
spacesailor24 Jul 20, 2021
d9c509a
Update error message
spacesailor24 Jul 20, 2021
2a90980
Merge branch 'wyatt/eip1559' of github.com:ChainSafe/web3.js into wya…
spacesailor24 Jul 20, 2021
7324eec
Update use of tx.type
spacesailor24 Jul 21, 2021
d4f1363
Replace hardfork strings with enum
spacesailor24 Jul 21, 2021
f2ca0d8
Type check refactors for _handleTxPricing
spacesailor24 Jul 21, 2021
e0e19f7
Resolve tx.gasPrice if set and tx.type < 0x2 in _handleTxPricing
spacesailor24 Jul 21, 2021
c5be542
Fix _handleTxType logic
spacesailor24 Jul 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions dist/web3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/web3.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.3.6",
"version": "1.4.0-rc.0",
"lerna": "2.0.0",
"command": {
"init": {
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-bzz/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/web3-bzz/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-bzz",
"version": "1.3.6",
"version": "1.4.0-rc.0",
"description": "Web3 module to interact with the Swarm network.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-bzz",
"license": "LGPL-3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core-helpers/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/web3-core-helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-core-helpers",
"version": "1.3.6",
"version": "1.4.0-rc.0",
"description": "Web3 core tools helper for sub packages. This is an internal package.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-helpers",
"license": "LGPL-3.0",
Expand All @@ -15,8 +15,8 @@
"main": "lib/index.js",
"dependencies": {
"underscore": "1.12.1",
"web3-eth-iban": "1.3.6",
"web3-utils": "1.3.6"
"web3-eth-iban": "1.4.0-rc.0",
"web3-utils": "1.4.0-rc.0"
},
"devDependencies": {
"@types/node": "^12.12.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core-method/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions packages/web3-core-method/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-core-method",
"version": "1.3.6",
"version": "1.4.0-rc.0",
"description": "Creates the methods on the web3 modules. This is an internal package.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-method",
"license": "LGPL-3.0",
Expand All @@ -16,10 +16,10 @@
"dependencies": {
"@ethersproject/transactions": "^5.0.0-beta.135",
"underscore": "1.12.1",
"web3-core-helpers": "1.3.6",
"web3-core-promievent": "1.3.6",
"web3-core-subscriptions": "1.3.6",
"web3-utils": "1.3.6"
"web3-core-helpers": "1.4.0-rc.0",
"web3-core-promievent": "1.4.0-rc.0",
"web3-core-subscriptions": "1.4.0-rc.0",
"web3-utils": "1.4.0-rc.0"
},
"devDependencies": {
"dtslint": "^3.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core-promievent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-core-promievent",
"version": "1.3.6",
"version": "1.4.0-rc.0",
"description": "This package extends the EventEmitter with the Promise class to allow chaining as well as multiple final states of a function.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-promievent",
"license": "LGPL-3.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/web3-core-requestmanager/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-core-requestmanager",
"version": "1.3.6",
"version": "1.4.0-rc.0",
"description": "Web3 module to handle requests to external providers.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-requestmanager",
"license": "LGPL-3.0",
Expand All @@ -14,9 +14,9 @@
"dependencies": {
"underscore": "1.12.1",
"util": "^0.12.0",
"web3-core-helpers": "1.3.6",
"web3-providers-http": "1.3.6",
"web3-providers-ipc": "1.3.6",
"web3-providers-ws": "1.3.6"
"web3-core-helpers": "1.4.0-rc.0",
"web3-providers-http": "1.4.0-rc.0",
"web3-providers-ipc": "1.4.0-rc.0",
"web3-providers-ws": "1.4.0-rc.0"
}
}
2 changes: 1 addition & 1 deletion packages/web3-core-subscriptions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/web3-core-subscriptions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-core-subscriptions",
"version": "1.3.6",
"version": "1.4.0-rc.0",
"description": "Manages web3 subscriptions. This is an internal package.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core-subscriptions",
"license": "LGPL-3.0",
Expand All @@ -16,7 +16,7 @@
"dependencies": {
"eventemitter3": "4.0.4",
"underscore": "1.12.1",
"web3-core-helpers": "1.3.6"
"web3-core-helpers": "1.4.0-rc.0"
},
"devDependencies": {
"dtslint": "^3.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions packages/web3-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-core",
"version": "1.3.6",
"version": "1.4.0-rc.0",
"description": "Web3 core tools for sub-packages. This is an internal package.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-core",
"license": "LGPL-3.0",
Expand All @@ -17,10 +17,10 @@
"@types/bn.js": "^4.11.5",
"@types/node": "^12.12.6",
"bignumber.js": "^9.0.0",
"web3-core-helpers": "1.3.6",
"web3-core-method": "1.3.6",
"web3-core-requestmanager": "1.3.6",
"web3-utils": "1.3.6"
"web3-core-helpers": "1.4.0-rc.0",
"web3-core-method": "1.4.0-rc.0",
"web3-core-requestmanager": "1.4.0-rc.0",
"web3-utils": "1.4.0-rc.0"
},
"devDependencies": {
"dtslint": "^3.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/web3-eth-abi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-eth-abi",
"version": "1.3.6",
"version": "1.4.0-rc.0",
"description": "Web3 module encode and decode EVM in/output.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth-abi",
"license": "LGPL-3.0",
Expand All @@ -16,7 +16,7 @@
"dependencies": {
"@ethersproject/abi": "5.0.7",
"underscore": "1.12.1",
"web3-utils": "1.3.6"
"web3-utils": "1.4.0-rc.0"
},
"devDependencies": {
"dtslint": "^3.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions packages/web3-eth-accounts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-eth-accounts",
"version": "1.3.6",
"version": "1.4.0-rc.0",
"description": "Web3 module to generate Ethereum accounts and sign data and transactions.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth-accounts",
"license": "LGPL-3.0",
Expand All @@ -22,10 +22,10 @@
"scrypt-js": "^3.0.1",
"underscore": "1.12.1",
"uuid": "3.3.2",
"web3-core": "1.3.6",
"web3-core-helpers": "1.3.6",
"web3-core-method": "1.3.6",
"web3-utils": "1.3.6"
"web3-core": "1.4.0-rc.0",
"web3-core-helpers": "1.4.0-rc.0",
"web3-core-method": "1.4.0-rc.0",
"web3-utils": "1.4.0-rc.0"
},
"devDependencies": {
"dtslint": "^3.4.1",
Expand Down
69 changes: 63 additions & 6 deletions packages/web3-eth-accounts/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ var Accounts = function Accounts() {
}, function() {
return 'latest';
}]
})
}),
new Method({
name: 'getBlockByNumber',
call: 'eth_getBlockByNumber',
params: 2,
inputFormatter: [function(blockNumber) {
return blockNumber ? utils.toHex(blockNumber) : 'latest'
}, function() {
return false
}]
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a new method?

Copy link
Contributor Author

@spacesailor24 spacesailor24 Jun 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorta, this package doesn't make use of the RPC wrappers found in web3-eth, instead needed methods are redefined in the package. I added this method to be able to get a block to find the baseFeePerGas

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean we can't leverage the getBlock (also refs blockCall) because it's defined in the web3-eth package and not accessible from web3-eth-accounts?
In this case don't we have a dependency or at least a DRY issue that could be addressed somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndreMiras Yes, and we plan to address the problematic architecture in 4.x (our rewrite), so for now it's just about making the least amount of change to 1.x as possible, to refrain from introducing additional bugs

];
// attach methods to this._ethereumCall
this._ethereumCall = {};
Expand Down Expand Up @@ -162,6 +172,9 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
if (transaction.accessList) {
// EIP-2930
transaction.type = "0x01"
} else if (transaction.maxPriorityFeePerGas || transaction.maxFeePerGas) {
// EIP-1559
transaction.type = "0x02"
}

// Because tx has no @ethereumjs/tx signing options we use fetched vals.
Expand All @@ -173,7 +186,7 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
networkId: transaction.networkId,
chainId: transaction.chainId
},
transaction.hardfork || "berlin"
transaction.hardfork || "london"
);

delete transaction.networkId;
Expand All @@ -186,7 +199,7 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
networkId: transaction.common.customChain.networkId,
chainId: transaction.common.customChain.chainId
},
transaction.common.hardfork || "berlin",
transaction.common.hardfork || "london",
);

delete transaction.common;
Expand Down Expand Up @@ -241,21 +254,41 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca


// Resolve immediately if nonce, chainId, price and signing options are provided
if (tx.nonce !== undefined && tx.chainId !== undefined && tx.gasPrice !== undefined && hasTxSigningOptions) {
if (
tx.nonce !== undefined &&
tx.chainId !== undefined &&
(
tx.gasPrice !== undefined ||
(
tx.maxFeePerGas !== undefined &&
tx.maxPriorityFeePerGas !== undefined
)
) &&
hasTxSigningOptions
) {
return Promise.resolve(signed(tx));
}

// Otherwise, get the missing info from the Ethereum Node
return Promise.all([
isNot(tx.chainId) ? _this._ethereumCall.getChainId() : tx.chainId,
isNot(tx.gasPrice) ? _this._ethereumCall.getGasPrice() : tx.gasPrice,
// isNot(tx.gasPrice) ? _this._ethereumCall.getGasPrice() : tx.gasPrice,
_handleTxPricing(tx),
isNot(tx.nonce) ? _this._ethereumCall.getTransactionCount(_this.privateKeyToAccount(privateKey).address) : tx.nonce,
isNot(hasTxSigningOptions) ? _this._ethereumCall.getNetworkId() : 1
]).then(function(args) {
if (isNot(args[0]) || isNot(args[1]) || isNot(args[2]) || isNot(args[3])) {
throw new Error('One of the values "chainId", "networkId", "gasPrice", or "nonce" couldn\'t be fetched: ' + JSON.stringify(args));
}
return signed(_.extend(tx, {chainId: args[0], gasPrice: args[1], nonce: args[2], networkId: args[3]}));
return signed(_.extend(
tx,
{
chainId: args[0],
nonce: args[2],
networkId: args[3],
...args[1] // Will either be gasPrice or maxFeePerGas and maxPriorityFeePerGas
}
));
});
};

Expand Down Expand Up @@ -287,6 +320,30 @@ function _validateTransactionForSigning(tx) {
return;
}

function _handleTxPricing(tx) {
new Promise((resolve, reject) => {
try {
Promise.all([
_this._ethereumCall.getBlockByNumber(),
_this._ethereumCall.getGasPrice()
]).then(responses => {
const [block, gasPrice] = responses;
if (block && block.baseFee) {
// Taken from https://github.com/ethers-io/ethers.js/blob/c5bca7767e3f3d43e3d0bd3c9e9420321ee9907a/packages/abstract-provider/src.ts/index.ts#L228
resolve({
maxFeePerGas: tx.maxFeePerGas || utils.toHex(utils.toBN(block.baseFee).mul(2)),
maxPriorityFeePerGas: tx.maxPriorityFeePerGas || '0x1'
});
} else {
resolve({ gasPrice });
}
})
} catch (error) {
reject(e)
}
})
}

/* jshint ignore:start */
Accounts.prototype.recoverTransaction = function recoverTransaction(rawTx, txOptions = {}) {
// Rely on EthereumJs/tx to determine the type of transaction
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-contract/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions packages/web3-eth-contract/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-eth-contract",
"version": "1.3.6",
"version": "1.4.0-rc.0",
"description": "Web3 module to interact with Ethereum smart contracts.",
"repository": "https://github.com/ethereum/web3.js/tree/1.x/packages/web3-eth-contract",
"license": "LGPL-3.0",
Expand All @@ -16,13 +16,13 @@
"dependencies": {
"@types/bn.js": "^4.11.5",
"underscore": "1.12.1",
"web3-core": "1.3.6",
"web3-core-helpers": "1.3.6",
"web3-core-method": "1.3.6",
"web3-core-promievent": "1.3.6",
"web3-core-subscriptions": "1.3.6",
"web3-eth-abi": "1.3.6",
"web3-utils": "1.3.6"
"web3-core": "1.4.0-rc.0",
"web3-core-helpers": "1.4.0-rc.0",
"web3-core-method": "1.4.0-rc.0",
"web3-core-promievent": "1.4.0-rc.0",
"web3-core-subscriptions": "1.4.0-rc.0",
"web3-eth-abi": "1.4.0-rc.0",
"web3-utils": "1.4.0-rc.0"
},
"devDependencies": {
"dtslint": "^3.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-ens/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading