mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
Revert "eth/tracers: fix standardTraceBlockToFile (#31763)"
This reverts commit 7705d13ed4.
This commit is contained in:
parent
7d7a246bb4
commit
8838ccfb21
2 changed files with 0 additions and 144 deletions
|
|
@ -1104,12 +1104,10 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
|
|||
if !canon {
|
||||
prefix = fmt.Sprintf("%valt-", prefix)
|
||||
}
|
||||
|
||||
dump, err = os.CreateTemp(os.TempDir(), prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dumps = append(dumps, dump.Name())
|
||||
|
||||
// Swap out the noop logger to the standard tracer
|
||||
|
|
@ -1118,33 +1116,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
|
|||
Tracer: logger.NewJSONLogger(&logConfig, writer),
|
||||
EnablePreimageRecording: true,
|
||||
}
|
||||
|
||||
// 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])
|
||||
if !canon {
|
||||
prefix = fmt.Sprintf("%valt-", prefix)
|
||||
}
|
||||
|
||||
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
|
||||
//nolint: nestif
|
||||
if stateSyncPresent && i == len(txs)-1 {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"reflect"
|
||||
"slices"
|
||||
"sync/atomic"
|
||||
|
|
@ -1376,118 +1375,3 @@ func TestTraceBlockWithBasefee(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStandardTraceBlockToFile(t *testing.T) {
|
||||
var (
|
||||
// A sender who makes transactions, has some funds
|
||||
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||
address = crypto.PubkeyToAddress(key.PublicKey)
|
||||
funds = big.NewInt(1000000000000000)
|
||||
|
||||
// first contract the sender transacts with
|
||||
aa = common.HexToAddress("0x7217d81b76bdd8707601e959454e3d776aee5f43")
|
||||
aaCode = []byte{byte(vm.PUSH1), 0x00, byte(vm.POP)}
|
||||
|
||||
// second contract the sender transacts with
|
||||
bb = common.HexToAddress("0x7217d81b76bdd8707601e959454e3d776aee5f44")
|
||||
bbCode = []byte{byte(vm.PUSH2), 0x00, 0x01, byte(vm.POP)}
|
||||
)
|
||||
|
||||
genesis := &core.Genesis{
|
||||
Config: params.TestChainConfig,
|
||||
Alloc: types.GenesisAlloc{
|
||||
address: {Balance: funds},
|
||||
aa: {
|
||||
Code: aaCode,
|
||||
Nonce: 1,
|
||||
Balance: big.NewInt(0),
|
||||
},
|
||||
bb: {
|
||||
Code: bbCode,
|
||||
Nonce: 1,
|
||||
Balance: big.NewInt(0),
|
||||
},
|
||||
},
|
||||
}
|
||||
txHashs := make([]common.Hash, 0, 2)
|
||||
backend := newTestBackend(t, 1, genesis, func(i int, b *core.BlockGen) {
|
||||
b.SetCoinbase(common.Address{1})
|
||||
// first tx to aa
|
||||
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{
|
||||
Nonce: 0,
|
||||
To: &aa,
|
||||
Value: big.NewInt(0),
|
||||
Gas: 50000,
|
||||
GasPrice: b.BaseFee(),
|
||||
Data: nil,
|
||||
}), types.HomesteadSigner{}, key)
|
||||
b.AddTx(tx)
|
||||
txHashs = append(txHashs, tx.Hash())
|
||||
// second tx to bb
|
||||
tx, _ = types.SignTx(types.NewTx(&types.LegacyTx{
|
||||
Nonce: 1,
|
||||
To: &bb,
|
||||
Value: big.NewInt(1),
|
||||
Gas: 100000,
|
||||
GasPrice: b.BaseFee(),
|
||||
Data: nil,
|
||||
}), types.HomesteadSigner{}, key)
|
||||
b.AddTx(tx)
|
||||
txHashs = append(txHashs, tx.Hash())
|
||||
})
|
||||
defer backend.chain.Stop()
|
||||
|
||||
var testSuite = []struct {
|
||||
blockNumber rpc.BlockNumber
|
||||
config *StdTraceConfig
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
// test that all traces in the block were outputted if no trace config is specified
|
||||
blockNumber: rpc.LatestBlockNumber,
|
||||
config: nil,
|
||||
want: []string{
|
||||
`{"pc":0,"op":96,"gas":"0x7148","gasCost":"0x3","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH1"}
|
||||
{"pc":2,"op":80,"gas":"0x7145","gasCost":"0x2","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"POP"}
|
||||
{"pc":3,"op":0,"gas":"0x7143","gasCost":"0x0","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"STOP"}
|
||||
{"output":"","gasUsed":"0x5"}
|
||||
`,
|
||||
`{"pc":0,"op":97,"gas":"0x13498","gasCost":"0x3","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH2"}
|
||||
{"pc":3,"op":80,"gas":"0x13495","gasCost":"0x2","memSize":0,"stack":["0x1"],"depth":1,"refund":0,"opName":"POP"}
|
||||
{"pc":4,"op":0,"gas":"0x13493","gasCost":"0x0","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"STOP"}
|
||||
{"output":"","gasUsed":"0x5"}
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
// test that only a specific tx is traced if specified
|
||||
blockNumber: rpc.LatestBlockNumber,
|
||||
config: &StdTraceConfig{TxHash: txHashs[1]},
|
||||
want: []string{
|
||||
`{"pc":0,"op":97,"gas":"0x13498","gasCost":"0x3","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH2"}
|
||||
{"pc":3,"op":80,"gas":"0x13495","gasCost":"0x2","memSize":0,"stack":["0x1"],"depth":1,"refund":0,"opName":"POP"}
|
||||
{"pc":4,"op":0,"gas":"0x13493","gasCost":"0x0","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"STOP"}
|
||||
{"output":"","gasUsed":"0x5"}
|
||||
`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
api := NewAPI(backend)
|
||||
for i, tc := range testSuite {
|
||||
block, _ := api.blockByNumber(context.Background(), tc.blockNumber)
|
||||
txTraces, err := api.StandardTraceBlockToFile(context.Background(), block.Hash(), tc.config)
|
||||
if err != nil {
|
||||
t.Fatalf("test index %d received error %v", i, err)
|
||||
}
|
||||
for j, traceFileName := range txTraces {
|
||||
traceReceived, err := os.ReadFile(traceFileName)
|
||||
if err != nil {
|
||||
t.Fatalf("could not read trace file: %v", err)
|
||||
}
|
||||
if tc.want[j] != string(traceReceived) {
|
||||
t.Fatalf("unexpected trace result. expected\n'%s'\n\nreceived\n'%s'\n", tc.want[j], string(traceReceived))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue