From a00f2234ae43a07ec116a6d1b6f3122fd44be45f Mon Sep 17 00:00:00 2001 From: Roshan <48975233+Pythonberg1997@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:30:08 +0800 Subject: [PATCH] fix: add missing part when preparing env in `SimulateBundle` (#19) --- miner/miner.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/miner/miner.go b/miner/miner.go index bce84c8048..033700dccc 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -29,8 +29,10 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/misc/eip1559" + "github.com/ethereum/go-ethereum/consensus/misc/eip4844" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/systemcontracts" "github.com/ethereum/go-ethereum/core/txpool" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/downloader" @@ -327,6 +329,25 @@ func (miner *Miner) SimulateBundle(bundle *types.Bundle) (*big.Int, error) { return nil, err } + // Apply EIP-4844, EIP-4788. + if miner.worker.chainConfig.IsCancun(header.Number, header.Time) { + var excessBlobGas uint64 + if miner.worker.chainConfig.IsCancun(parent.Number, parent.Time) { + excessBlobGas = eip4844.CalcExcessBlobGas(*parent.ExcessBlobGas, *parent.BlobGasUsed) + } else { + // For the first post-fork block, both parent.data_gas_used and parent.excess_data_gas are evaluated as 0 + excessBlobGas = eip4844.CalcExcessBlobGas(0, 0) + } + header.BlobGasUsed = new(uint64) + header.ExcessBlobGas = &excessBlobGas + if miner.worker.chainConfig.Parlia != nil { + header.WithdrawalsHash = &types.EmptyWithdrawalsHash + } + // if miner.worker.chainConfig.Parlia == nil { + // header.ParentBeaconRoot = genParams.beaconRoot + // } + } + state, err := miner.eth.BlockChain().StateAt(parent.Root) if err != nil { return nil, err @@ -338,6 +359,11 @@ func (miner *Miner) SimulateBundle(bundle *types.Bundle) (*big.Int, error) { signer: types.MakeSigner(miner.worker.chainConfig, header.Number, header.Time), } + if !miner.worker.chainConfig.IsFeynman(header.Number, header.Time) { + // Handle upgrade build-in system contract code + systemcontracts.UpgradeBuildInSystemContract(miner.worker.chainConfig, header.Number, parent.Time, header.Time, env.state) + } + s, err := miner.worker.simulateBundles(env, []*types.Bundle{bundle}) if err != nil { return nil, err