This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 683
feat: london #1135
Merged
Merged
feat: london #1135
Changes from 32 commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
1fccc78
add eip1559 raw and rpc types
MicaiahReid 6239952
add eip 1559 tx type
MicaiahReid 48762ec
add standardized gas price across tx types
MicaiahReid 496a187
add london hardfork
MicaiahReid cd5fedd
add eip1559 to vm tx type
MicaiahReid 21ec3af
add base fee per gas to block
MicaiahReid 3b9c179
use standardized gas price func
MicaiahReid 6fc7af0
normalize type2 txs to legacy pre-berlin
MicaiahReid 20cd47f
dont allow nullable nonce
MicaiahReid d5d7df1
refine baseFeePerGas formula
MicaiahReid f100fc5
normalize txs to type 1559 when appropriate
MicaiahReid 079275e
eip1559 tests
MicaiahReid 44f7163
export eip1559 txs with @ganache/ethereum-tx
MicaiahReid 333a433
remove unused receipt params
MicaiahReid 4215ae9
add tests for calculating baseFeePerGas
MicaiahReid dd917ed
fix bug with block.toJSON
MicaiahReid abd99ba
add effectiveGasPrice and methods to update
MicaiahReid 8e1d289
order/reorder tx pool based off of effectiveGasPrice
MicaiahReid e4010e1
add capacity enum to miner
MicaiahReid 13a81fa
remove unnecessary data
MicaiahReid ee49a30
remove instamine from miner. have calcNextBaseFee to return buff
MicaiahReid 8ca42e7
add back gasPrice to receipt
MicaiahReid c80a003
test for miner and txPool ordering post london
MicaiahReid 84184b4
add miner design decisions
MicaiahReid 9ad02e6
initialize baseFeePerGas as an estimate on eip1559 tx
MicaiahReid 4143a46
fix test that broke due to typed tx hash fix.
MicaiahReid 2a6b1df
remove todo
MicaiahReid 9196e8b
add `london` to `TRANSACTION_DATA_NON_ZERO_GAS`
davidmurdoch 10aceb4
remove to-do and unnecessary conversion of datatype
MicaiahReid 39791ec
improving "it" statements in tests
MicaiahReid 53d841a
clarify comments in test
MicaiahReid 4ba7e37
remove .only from test 😬
MicaiahReid 4534884
add JSDOC for Heap.prototype.refresh and refresher
davidmurdoch 43e3c77
set higher gas price for in revert test so CI will run
davidmurdoch 3054f48
make tests pass
davidmurdoch e5ba47c
Fix genesis block parent hash
davidmurdoch eb2e95f
tx 1 and 2 tests shouldn't include 27 in their v values
davidmurdoch 6fe0fd0
make transaction logging easier to read
davidmurdoch d7bc2c9
fix racey test
davidmurdoch cbecdfc
fix test comment typo
davidmurdoch 874e9db
ignore logging output on chatty block test
davidmurdoch 6489b60
update docs
davidmurdoch 8f22af5
remove unused import
davidmurdoch 93f50b1
undo some unnecessary changes
davidmurdoch 0c7a271
add JSDOC to miner's new Capacity enum
davidmurdoch ca50436
use blockchain var
davidmurdoch d6206ad
use `Capacity` enum for call to `mine`
davidmurdoch 1ec93f5
remove unused imports
davidmurdoch 3e6b59a
fix comment typo
davidmurdoch c5e83d0
remove infinite test timeout
davidmurdoch e6e3571
remove unused dep
davidmurdoch ded9da3
fix type
davidmurdoch 89a2657
don't skip all the tests :facepalm:
davidmurdoch 90a4784
remove testing promise thing
davidmurdoch 4931230
revert back to ignoring
davidmurdoch 27e39ec
update docs
davidmurdoch bd7e6db
Remove unused import
MicaiahReid ab01639
remove test
davidmurdoch 108240f
update docs
davidmurdoch 1a556f0
Merge branch 'feat/eip-1559-tx-david-temp' of github.com:trufflesuite…
davidmurdoch f272389
fix comment typo
davidmurdoch 641c60f
move miner's `refresher` off fthe miner class
davidmurdoch f93d1b6
try to fix github actions auth issue
davidmurdoch dd52708
short circuit in Wuantity.toBuffer
davidmurdoch b80b6fe
use bigint when doing gas math stuff
davidmurdoch dab86c0
fix tx type 1 signing error
davidmurdoch d75de71
always validate signature recovery ID
davidmurdoch 7c73c80
update docs
davidmurdoch 2f3ebca
rename repo-token to token in github actions
davidmurdoch 7ec7b01
fix typo in github action config
davidmurdoch 0c61590
fix typos
davidmurdoch 67a48a5
fix typos
davidmurdoch d2e3a09
don't allow unlimited time in test
davidmurdoch 68f6b53
use static eth_gasPrice for gas price in test
davidmurdoch 8d583ee
undo whitespace change
davidmurdoch 81bb0fd
Add error for transaction decode failure.
davidmurdoch 34e702f
Update src/packages/utils/src/utils/heap.ts
davidmurdoch 98324f0
rename lastMaxBlockBaseFee to maxPossibleBaseFee
davidmurdoch b3a22ae
rename calcMaxNBlocksBaseFee to calcNBlocksMaxBaseFee
davidmurdoch cb5feba
Merge branch 'feat/eip-1559-tx-david-temp' of github.com:trufflesuite…
davidmurdoch 958cc40
move type def from runtime-block to block
davidmurdoch 34d2240
update error message in test failure
davidmurdoch 77b9561
update docs
davidmurdoch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// NOTE these params may need to be changed at each hardfork | ||
// they can be tracked here: https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/hardforks/ | ||
|
||
import { Quantity } from "@ganache/utils"; | ||
|
||
export const BlockParams = { | ||
/** | ||
* Base fee per gas for blocks without a parent containing a base fee per gas. | ||
*/ | ||
INITIAL_BASE_FEE_PER_GAS: 1000000000n, | ||
/** | ||
* Divisor used to set a block's target gas usage. | ||
*/ | ||
ELASTICITY: 2n, | ||
|
||
/** | ||
* Divisor used to limit the amount the base fee per gas can change from one block to another. | ||
*/ | ||
BASE_FEE_MAX_CHANGE_DENOMINATOR: 8n | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,103 @@ | ||
import assert from "assert"; | ||
import ethereumBlock from "../"; | ||
import { Address } from "@ganache/ethereum-address"; | ||
import { BUFFER_ZERO, Data, Quantity } from "@ganache/utils"; | ||
import Common from "@ethereumjs/common"; | ||
import Wallet from "../../ethereum/src/wallet"; | ||
import { TransactionFactory } from "@ganache/ethereum-transaction"; | ||
import { TypedRpcTransaction } from "@ganache/ethereum-transaction"; | ||
import Blockchain from "../../ethereum/src/blockchain"; | ||
import { EthereumOptionsConfig } from "../../options/src/index"; | ||
|
||
describe("@ganache/ethereum-block", () => { | ||
it("needs tests"); | ||
describe("@ganache/ethereum-block", async () => { | ||
describe("baseFeePerGas calculations", () => { | ||
let blockchain: Blockchain; | ||
before(async function () { | ||
this.timeout(0); | ||
const privKey = `0x${"46".repeat(32)}`; | ||
const privKeyData = Data.from(privKey); | ||
const options = EthereumOptionsConfig.normalize({ | ||
wallet: { | ||
accounts: [ | ||
{ secretKey: privKey, balance: 1000000000000000000000n }, | ||
{ | ||
secretKey: `0x${"46".repeat(31)}47`, | ||
balance: 1000000000000000000000n | ||
} | ||
] | ||
}, | ||
miner: { | ||
blockGasLimit: "0xB749E0" | ||
}, | ||
chain: { chainId: 1337 } | ||
}); | ||
const wallet = new Wallet(options.wallet); | ||
const [from, to] = wallet.addresses; | ||
const fromAddress = new Address(from); | ||
const tx: TypedRpcTransaction = { | ||
type: "0x2", | ||
from: from, | ||
to: to, | ||
maxFeePerGas: "0x344221FFF", | ||
chainId: "0x539", | ||
gas: "0x5208" | ||
}; | ||
|
||
const common = Common.forCustomChain( | ||
"mainnet", | ||
{ | ||
name: "ganache", | ||
chainId: 1337, | ||
comment: "Local test network", | ||
bootstrapNodes: [] | ||
}, | ||
"london" | ||
); | ||
blockchain = new Blockchain(options, fromAddress); | ||
await blockchain.initialize(wallet.initialAccounts); | ||
// to verify our calculations for the block's baseFeePerGas, | ||
// we're comparing our data to geth. Geth's gasLimit changes | ||
// every block, so we need to set those values here according | ||
// to what geth had. We'll need to reset each time a block is | ||
// mined and we'll need to mine blocks such that we have one | ||
// with each of the cases: 1. gasUsed < gasTarget, 2. gasUsed > | ||
// gasTarget, gasUsed = gasTarget. | ||
const gethBlockData = [ | ||
{ txCount: 286, newGasLimit: 12000271 }, | ||
{ txCount: 290, newGasLimit: 11988553 }, | ||
{ txCount: 10, newGasLimit: 11976847 }, | ||
// because we use the previous block to calculate the base fee, | ||
// send/mine one more tx so we can see what the reulting base fee | ||
// is from the previous block | ||
{ txCount: 1, newGasLimit: 11965152 } | ||
]; | ||
|
||
for (let i = 0; i < gethBlockData.length; i++) { | ||
const data = gethBlockData[i]; | ||
options.miner.blockGasLimit = Quantity.from(data.newGasLimit); | ||
blockchain.pause(); | ||
for (let j = 0; j < data.txCount; j++) { | ||
const feeMarketTx = TransactionFactory.fromRpc(tx, common); | ||
await blockchain.queueTransaction(feeMarketTx, privKeyData); | ||
} | ||
// mine all txs in that group before moving onto the next block | ||
await blockchain.resume(); | ||
} | ||
}); | ||
it("has initial baseFeePerGas of 1000000000 for genesis block", async () => { | ||
const block = await blockchain.blocks.get(BUFFER_ZERO); | ||
assert.strictEqual(block.header.baseFeePerGas.toNumber(), 1000000000); | ||
}); | ||
it("calculates baseFeePerGas correctly when gasUsed is equal to gasTarget", async () => { | ||
const block = await blockchain.blocks.get(Buffer.from([2])); | ||
assert.strictEqual(block.header.baseFeePerGas.toNumber(), 875106911); | ||
}); | ||
it("calculates baseFeePerGas correctly when gasUsed is above gasTarget", async () => { | ||
const block = await blockchain.blocks.get(Buffer.from([3])); | ||
assert.strictEqual(block.header.baseFeePerGas.toNumber(), 876853759); | ||
}); | ||
it("calculates baseFeePerGas correctly when gasUsed is below gasTarget", async () => { | ||
const block = await blockchain.blocks.get(Buffer.from([4])); | ||
assert.strictEqual(block.header.baseFeePerGas.toNumber(), 771090691); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this
already has access tocommon
, but sometimes when we initialize a block, we don't set common to save some extra work that would be done when it's set. (see comment on lines 184-187 ofruntime-block.ts
for more info on that.)So instead, we pass in common to this function. Any thoughts on always passing common into the
block
constructor, allowing us to usethis._common
here? @davidmurdochThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably fine to leave it as is and fix when we re-organize the transactions classes