Skip to content

Commit

Permalink
cherry-pick from erigontech#9723
Browse files Browse the repository at this point in the history
  • Loading branch information
blxdyx committed Mar 19, 2024
1 parent b2a351c commit ef9779f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 40 deletions.
11 changes: 9 additions & 2 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ func NewEVMBlockContext(header *types.Header, blockHashFunc func(n uint64) libco
var prevRandDao *libcommon.Hash
if header.Difficulty.Cmp(merge.ProofOfStakeDifficulty) == 0 {
// EIP-4399. We use ProofOfStakeDifficulty (i.e. 0) as a telltale of Proof-of-Stake blocks.
prevRandDao = &header.MixDigest
prevRandDao = new(libcommon.Hash)
*prevRandDao = header.MixDigest
}

var excessBlobGas *uint64
if header.ExcessBlobGas != nil {
excessBlobGas = new(uint64)
*excessBlobGas = *header.ExcessBlobGas
}

var transferFunc evmtypes.TransferFunc
Expand All @@ -71,7 +78,7 @@ func NewEVMBlockContext(header *types.Header, blockHashFunc func(n uint64) libco
BaseFee: &baseFee,
GasLimit: header.GasLimit,
PrevRanDao: prevRandDao,
ExcessBlobGas: header.ExcessBlobGas,
ExcessBlobGas: excessBlobGas,
}
}

Expand Down
21 changes: 3 additions & 18 deletions turbo/jsonrpc/eth_callMany.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont
blockCtx evmtypes.BlockContext
txCtx evmtypes.TxContext
overrideBlockHash map[uint64]common.Hash
baseFee uint256.Int
)

overrideBlockHash = make(map[uint64]common.Hash)
Expand Down Expand Up @@ -138,9 +137,9 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont

st := state.New(stateReader)

parent := block.Header()
header := block.Header()

if parent == nil {
if header == nil {
return nil, fmt.Errorf("block %d(%x) not found", blockNum, hash)
}

Expand All @@ -155,21 +154,7 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont
return hash
}

if parent.BaseFee != nil {
baseFee.SetFromBig(parent.BaseFee)
}

blockCtx = evmtypes.BlockContext{
CanTransfer: core.CanTransfer,
Transfer: core.Transfer,
GetHash: getHash,
Coinbase: parent.Coinbase,
BlockNumber: parent.Number.Uint64(),
Time: parent.Time,
Difficulty: new(big.Int).Set(parent.Difficulty),
GasLimit: parent.GasLimit,
BaseFee: &baseFee,
}
blockCtx = core.NewEVMBlockContext(header, getHash, api.engine(), nil /* author */)

// Get a new instance of the EVM
evm = vm.NewEVM(blockCtx, txCtx, st, chainConfig, vm.Config{Debug: false})
Expand Down
24 changes: 4 additions & 20 deletions turbo/jsonrpc/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jsonrpc
import (
"context"
"fmt"
"math/big"
"time"

"github.com/holiman/uint256"
Expand Down Expand Up @@ -385,7 +384,6 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun
blockCtx evmtypes.BlockContext
txCtx evmtypes.TxContext
overrideBlockHash map[uint64]common.Hash
baseFee uint256.Int
)

if config == nil {
Expand Down Expand Up @@ -461,9 +459,9 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun

st := state.New(stateReader)

parent := block.Header()
header := block.Header()

if parent == nil {
if header == nil {
stream.WriteNil()
return fmt.Errorf("block %d(%x) not found", blockNum, hash)
}
Expand All @@ -479,21 +477,7 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun
return hash
}

if parent.BaseFee != nil {
baseFee.SetFromBig(parent.BaseFee)
}

blockCtx = evmtypes.BlockContext{
CanTransfer: core.CanTransfer,
Transfer: core.Transfer,
GetHash: getHash,
Coinbase: parent.Coinbase,
BlockNumber: parent.Number.Uint64(),
Time: parent.Time,
Difficulty: new(big.Int).Set(parent.Difficulty),
GasLimit: parent.GasLimit,
BaseFee: &baseFee,
}
blockCtx = core.NewEVMBlockContext(header, getHash, api.engine(), nil /* author */)

// Get a new instance of the EVM
evm = vm.NewEVM(blockCtx, txCtx, st, chainConfig, vm.Config{Debug: false})
Expand Down Expand Up @@ -548,7 +532,7 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun
}
txCtx = core.NewEVMTxContext(msg)
ibs := evm.IntraBlockState().(*state.IntraBlockState)
ibs.SetTxContext(common.Hash{}, parent.Hash(), txnIndex)
ibs.SetTxContext(common.Hash{}, header.Hash(), txnIndex)
err = transactions.TraceTx(ctx, msg, blockCtx, txCtx, evm.IntraBlockState(), config, chainConfig, stream, api.evmCallTimeout)
if err != nil {
stream.WriteArrayEnd()
Expand Down

0 comments on commit ef9779f

Please sign in to comment.