set base fee to 0 in non-validating mode

This commit is contained in:
Sina Mahmoodi 2024-06-06 19:03:35 +02:00
parent d7cd3a0b6f
commit 399812ad37
2 changed files with 96 additions and 1 deletions

View file

@ -1902,6 +1902,95 @@ func TestSimulateV1(t *testing.T) {
}}, }},
}}, }},
}, },
{
name: "basefee-non-validation",
tag: latest,
blocks: []simBlock{{
StateOverrides: &StateOverride{
randomAccounts[2].addr: {
Code: hex2Bytes("3a489060005260205260406000f3"),
},
},
Calls: []TransactionArgs{{
From: &accounts[0].addr,
To: &randomAccounts[2].addr,
// 0 gas price
}, {
From: &accounts[0].addr,
To: &randomAccounts[2].addr,
// non-zero gas price
MaxPriorityFeePerGas: newInt(1),
MaxFeePerGas: newInt(2),
},
},
}, {
BlockOverrides: &BlockOverrides{
BaseFeePerGas: (*hexutil.Big)(big.NewInt(1)),
},
Calls: []TransactionArgs{{
From: &accounts[0].addr,
To: &randomAccounts[2].addr,
// 0 gas price
}, {
From: &accounts[0].addr,
To: &randomAccounts[2].addr,
// non-zero gas price
MaxPriorityFeePerGas: newInt(1),
MaxFeePerGas: newInt(2),
},
},
}, {
// Base fee should be 0 to zero even if it was set in previous block.
Calls: []TransactionArgs{{
From: &accounts[0].addr,
To: &randomAccounts[2].addr,
}},
}},
want: []blockRes{{
Number: "0xb",
GasLimit: "0x47e7c4",
GasUsed: "0xa44e",
Miner: coinbase,
Calls: []callRes{{
ReturnValue: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
GasUsed: "0x5227",
Logs: []log{},
Status: "0x1",
}, {
ReturnValue: "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000",
GasUsed: "0x5227",
Logs: []log{},
Status: "0x1",
}},
}, {
Number: "0xc",
GasLimit: "0x47e7c4",
GasUsed: "0xa44e",
Miner: coinbase,
Calls: []callRes{{
ReturnValue: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
GasUsed: "0x5227",
Logs: []log{},
Status: "0x1",
}, {
ReturnValue: "0x00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001",
GasUsed: "0x5227",
Logs: []log{},
Status: "0x1",
}},
}, {
Number: "0xd",
GasLimit: "0x47e7c4",
GasUsed: "0x5227",
Miner: coinbase,
Calls: []callRes{{
ReturnValue: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
GasUsed: "0x5227",
Logs: []log{},
Status: "0x1",
}},
}},
},
} }
for _, tc := range testSuite { for _, tc := range testSuite {

View file

@ -136,9 +136,15 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
// Parent hash is needed for evm.GetHashFn to work. // Parent hash is needed for evm.GetHashFn to work.
header.ParentHash = parent.Hash() header.ParentHash = parent.Hash()
if config.IsLondon(header.Number) { if config.IsLondon(header.Number) {
// In non-validation mode base fee is set to 0 if it is not overridden.
// This is because it creates an edge case in EVM where gasPrice < baseFee.
// Base fee could have been overridden. // Base fee could have been overridden.
if header.BaseFee == nil { if header.BaseFee == nil {
if sim.validate {
header.BaseFee = eip1559.CalcBaseFee(config, parent) header.BaseFee = eip1559.CalcBaseFee(config, parent)
} else {
header.BaseFee = big.NewInt(0)
}
} }
} }
if config.IsCancun(header.Number, header.Time) { if config.IsCancun(header.Number, header.Time) {