From 2407255bb3032dc17205ba0d648270357c98b713 Mon Sep 17 00:00:00 2001 From: Rez Date: Wed, 26 Feb 2025 17:13:38 +1100 Subject: [PATCH] Add support Update simulate.go Update simulate.go Update simulate.go Update consensus.go passed withdrawals - now state root mismartch working but withdrawals issue Added support --- internal/ethapi/override/override.go | 2 ++ internal/ethapi/simulate.go | 35 ++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/internal/ethapi/override/override.go b/internal/ethapi/override/override.go index f6a8a94ffd..394dbff560 100644 --- a/internal/ethapi/override/override.go +++ b/internal/ethapi/override/override.go @@ -128,6 +128,8 @@ type BlockOverrides struct { PrevRandao *common.Hash BaseFeePerGas *hexutil.Big BlobBaseFee *hexutil.Big + BeaconRoot *common.Hash + Withdrawals *types.Withdrawals } // Apply overrides the given header fields into the given block context. diff --git a/internal/ethapi/simulate.go b/internal/ethapi/simulate.go index ac76372424..297f19b033 100644 --- a/internal/ethapi/simulate.go +++ b/internal/ethapi/simulate.go @@ -209,6 +209,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header, if sim.chainConfig.IsPrague(header.Number, header.Time) || sim.chainConfig.IsVerkle(header.Number, header.Time) { core.ProcessParentBlockHash(header.ParentHash, evm) } + if block.BlockOverrides.BeaconRoot != nil { + core.ProcessBeaconBlockRoot(*block.BlockOverrides.BeaconRoot, evm) + } + var allLogs []*types.Log for i, call := range block.Calls { if err := ctx.Err(); err != nil { @@ -254,6 +258,11 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header, } callResults[i] = callRes } + header.GasUsed = gasUsed + if sim.chainConfig.IsCancun(header.Number, header.Time) { + header.BlobGasUsed = &blobGasUsed + } + var requests [][]byte // Process EIP-7685 requests if sim.chainConfig.IsPrague(header.Number, header.Time) { @@ -267,20 +276,26 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header, // EIP-7251 core.ProcessConsolidationQueue(&requests, evm) } - header.Root = sim.state.IntermediateRoot(true) - header.GasUsed = gasUsed - if sim.chainConfig.IsCancun(header.Number, header.Time) { - header.BlobGasUsed = &blobGasUsed - } - var withdrawals types.Withdrawals - if sim.chainConfig.IsShanghai(header.Number, header.Time) { - withdrawals = make([]*types.Withdrawal, 0) - } if requests != nil { reqHash := types.CalcRequestsHash(requests) header.RequestsHash = &reqHash } - b := types.NewBlock(header, &types.Body{Transactions: txes, Withdrawals: withdrawals}, receipts, trie.NewStackTrie(nil)) + var withdrawals types.Withdrawals + if sim.chainConfig.IsShanghai(header.Number, header.Time) { + if block.BlockOverrides.Withdrawals != nil { + withdrawals = *block.BlockOverrides.Withdrawals + } else { + withdrawals = make([]*types.Withdrawal, 0) + } + } + blockBody := &types.Body{Transactions: txes, Withdrawals: withdrawals} + if block.BlockOverrides.Withdrawals != nil { + // We assume that if the user provides Withdrawals, we're operating on Beacon consensus + // which can have nil ChainHeadReader + sim.b.Engine().Finalize(nil, header, sim.state, blockBody) + } + header.Root = sim.state.IntermediateRoot(true) + b := types.NewBlock(header, blockBody, receipts, trie.NewStackTrie(nil)) repairLogs(callResults, b.Hash()) return b, callResults, nil }