mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
refactor
This commit is contained in:
parent
7006d616a8
commit
a7d6d8c550
1 changed files with 31 additions and 27 deletions
|
|
@ -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 err != nil {
|
||||||
// If the transaction needs tracing, swap out the configs
|
return dumps, err
|
||||||
if tx.Hash() == txHash || txHash == (common.Hash{}) {
|
}
|
||||||
// Generate a unique temporary file to dump it into
|
// 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
|
||||||
|
statedb.Finalise(evm.ChainConfig().IsEIP158(block.Number()))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// 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])
|
prefix := fmt.Sprintf("block_%#x-%d-%#x-", block.Hash().Bytes()[:4], i, tx.Hash().Bytes()[:4])
|
||||||
if !canon {
|
if !canon {
|
||||||
prefix = fmt.Sprintf("%valt-", prefix)
|
prefix = fmt.Sprintf("%valt-", prefix)
|
||||||
}
|
}
|
||||||
dump, err = os.CreateTemp(os.TempDir(), prefix)
|
var dump *os.File
|
||||||
|
dump, err := os.CreateTemp(os.TempDir(), prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dumps = append(dumps, dump.Name())
|
dumps = append(dumps, dump.Name())
|
||||||
|
// Set up the tracer and EVM for the transaction.
|
||||||
// Swap out the noop logger to the standard tracer
|
var (
|
||||||
writer = bufio.NewWriter(dump)
|
writer = bufio.NewWriter(dump)
|
||||||
*tracer = *logger.NewJSONLogger(&logConfig, writer)
|
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 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue