mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
eth/tracers: follow-up fixes
This commit is contained in:
parent
220c250db8
commit
8ebb222227
2 changed files with 14 additions and 16 deletions
|
|
@ -535,7 +535,7 @@ func TestTraceTransaction(t *testing.T) {
|
||||||
Gas: params.TxGas,
|
Gas: params.TxGas,
|
||||||
Failed: false,
|
Failed: false,
|
||||||
ReturnValue: "",
|
ReturnValue: "",
|
||||||
StructLogs: []logger.StructLogRes{},
|
StructLogs: []json.RawMessage{},
|
||||||
}) {
|
}) {
|
||||||
t.Error("Transaction tracing result is different")
|
t.Error("Transaction tracing result is different")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,15 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
|
"github.com/ethereum/go-ethereum/core/tracing"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth/tracers/logger"
|
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/tests"
|
"github.com/ethereum/go-ethereum/tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkTransactionTrace(b *testing.B) {
|
func BenchmarkTransactionTraceV2(b *testing.B) {
|
||||||
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
from := crypto.PubkeyToAddress(key.PublicKey)
|
from := crypto.PubkeyToAddress(key.PublicKey)
|
||||||
gas := uint64(1000000) // 1M gas
|
gas := uint64(1000000) // 1M gas
|
||||||
|
|
@ -78,14 +78,14 @@ func BenchmarkTransactionTrace(b *testing.B) {
|
||||||
state := tests.MakePreState(rawdb.NewMemoryDatabase(), alloc, false, rawdb.HashScheme)
|
state := tests.MakePreState(rawdb.NewMemoryDatabase(), alloc, false, rawdb.HashScheme)
|
||||||
defer state.Close()
|
defer state.Close()
|
||||||
|
|
||||||
// Create the tracer, the EVM environment and run it
|
// Create a tracer which records the number of steps
|
||||||
tracer := logger.NewStructLogger(&logger.Config{
|
var steps = 0
|
||||||
Debug: false,
|
tracer := &tracing.Hooks{
|
||||||
//DisableStorage: true,
|
OnOpcode: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
||||||
//EnableMemory: false,
|
steps++
|
||||||
//EnableReturnData: false,
|
},
|
||||||
})
|
}
|
||||||
evm := vm.NewEVM(context, state.StateDB, params.AllEthashProtocolChanges, vm.Config{Tracer: tracer.Hooks()})
|
evm := vm.NewEVM(context, state.StateDB, params.AllEthashProtocolChanges, vm.Config{Tracer: tracer})
|
||||||
msg, err := core.TransactionToMessage(tx, signer, context.BaseFee)
|
msg, err := core.TransactionToMessage(tx, signer, context.BaseFee)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("failed to prepare transaction for tracing: %v", err)
|
b.Fatalf("failed to prepare transaction for tracing: %v", err)
|
||||||
|
|
@ -95,16 +95,14 @@ func BenchmarkTransactionTrace(b *testing.B) {
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
snap := state.StateDB.Snapshot()
|
snap := state.StateDB.Snapshot()
|
||||||
tracer.OnTxStart(evm.GetVMContext(), tx, msg.From)
|
_, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.Gas()))
|
||||||
res, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.Gas()))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
tracer.OnTxEnd(&types.Receipt{GasUsed: res.UsedGas}, nil)
|
|
||||||
state.StateDB.RevertToSnapshot(snap)
|
state.StateDB.RevertToSnapshot(snap)
|
||||||
if have, want := len(tracer.StructLogs()), 244752; have != want {
|
if have, want := steps, 244752; have != want {
|
||||||
b.Fatalf("trace wrong, want %d steps, have %d", want, have)
|
b.Fatalf("trace wrong, want %d steps, have %d", want, have)
|
||||||
}
|
}
|
||||||
tracer.Reset()
|
steps = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue