This commit is contained in:
Sina Mahmoodi 2025-05-05 15:16:28 +02:00
parent 7006d616a8
commit a7d6d8c550

View file

@ -22,7 +22,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io"
"math/big" "math/big"
"os" "os"
"runtime" "runtime"
@ -780,12 +779,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
chainConfig, canon = overrideConfig(chainConfig, config.Overrides) chainConfig, canon = overrideConfig(chainConfig, config.Overrides)
} }
writer := bufio.NewWriter(io.Discard) evm := vm.NewEVM(vmctx, statedb, api.backend.ChainConfig(), vm.Config{})
tracer := logger.NewJSONLogger(&logConfig, writer)
evm := vm.NewEVM(vmctx, statedb, chainConfig, vm.Config{
Tracer: tracer,
EnablePreimageRecording: true,
})
if beaconRoot := block.BeaconRoot(); beaconRoot != nil { if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
core.ProcessBeaconBlockRoot(*beaconRoot, evm) core.ProcessBeaconBlockRoot(*beaconRoot, evm)
} }
@ -794,29 +788,39 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
} }
for i, tx := range block.Transactions() { for i, tx := range block.Transactions() {
// Prepare the transaction for un-traced execution // Prepare the transaction for un-traced execution
var ( msg, _ := core.TransactionToMessage(tx, signer, block.BaseFee())
msg, _ = core.TransactionToMessage(tx, signer, block.BaseFee()) if txHash != (common.Hash{}) && tx.Hash() != txHash {
dump *os.File // Process the tx to update state, but don't trace it.
err error _, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(msg.GasLimit))
)
// If the transaction needs tracing, swap out the configs
if tx.Hash() == txHash || txHash == (common.Hash{}) {
// Generate a unique temporary file to dump it into
prefix := fmt.Sprintf("block_%#x-%d-%#x-", block.Hash().Bytes()[:4], i, tx.Hash().Bytes()[:4])
if !canon {
prefix = fmt.Sprintf("%valt-", prefix)
}
dump, err = os.CreateTemp(os.TempDir(), prefix)
if err != nil { if err != nil {
return nil, err return dumps, err
} }
dumps = append(dumps, dump.Name()) // Finalize the state so any modifications are written to the trie
// Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect
// Swap out the noop logger to the standard tracer statedb.Finalise(evm.ChainConfig().IsEIP158(block.Number()))
writer = bufio.NewWriter(dump) continue
*tracer = *logger.NewJSONLogger(&logConfig, writer)
} }
// The transaction should be traced.
// Generate a unique temporary file to dump it into.
prefix := fmt.Sprintf("block_%#x-%d-%#x-", block.Hash().Bytes()[:4], i, tx.Hash().Bytes()[:4])
if !canon {
prefix = fmt.Sprintf("%valt-", prefix)
}
var dump *os.File
dump, err := os.CreateTemp(os.TempDir(), prefix)
if err != nil {
return nil, err
}
dumps = append(dumps, dump.Name())
// Set up the tracer and EVM for the transaction.
var (
writer = bufio.NewWriter(dump)
tracer = logger.NewJSONLogger(&logConfig, writer)
evm = vm.NewEVM(vmctx, statedb, chainConfig, vm.Config{
Tracer: tracer,
NoBaseFee: true,
})
)
// Execute the transaction and flush any traces to disk // Execute the transaction and flush any traces to disk
statedb.SetTxContext(tx.Hash(), i) statedb.SetTxContext(tx.Hash(), i)
if tracer.OnTxStart != nil { if tracer.OnTxStart != nil {