cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
7 years ago
|
|
|
// Copyright 2017 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package tracers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core"
|
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
7 years ago
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
"github.com/ethereum/go-ethereum/eth/tracers/logger"
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
7 years ago
|
|
|
"github.com/ethereum/go-ethereum/tests"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkTransactionTrace(b *testing.B) {
|
|
|
|
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
|
|
|
from := crypto.PubkeyToAddress(key.PublicKey)
|
|
|
|
gas := uint64(1000000) // 1M gas
|
|
|
|
to := common.HexToAddress("0x00000000000000000000000000000000deadbeef")
|
|
|
|
signer := types.LatestSignerForChainID(big.NewInt(1337))
|
|
|
|
tx, err := types.SignNewTx(key, signer,
|
|
|
|
&types.LegacyTx{
|
|
|
|
Nonce: 1,
|
|
|
|
GasPrice: big.NewInt(500),
|
|
|
|
Gas: gas,
|
|
|
|
To: &to,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
txContext := vm.TxContext{
|
|
|
|
Origin: from,
|
|
|
|
GasPrice: tx.GasPrice(),
|
|
|
|
}
|
|
|
|
context := vm.BlockContext{
|
|
|
|
CanTransfer: core.CanTransfer,
|
|
|
|
Transfer: core.Transfer,
|
|
|
|
Coinbase: common.Address{},
|
|
|
|
BlockNumber: new(big.Int).SetUint64(uint64(5)),
|
|
|
|
Time: 5,
|
|
|
|
Difficulty: big.NewInt(0xffffffff),
|
|
|
|
GasLimit: gas,
|
|
|
|
BaseFee: big.NewInt(8),
|
|
|
|
}
|
|
|
|
alloc := core.GenesisAlloc{}
|
|
|
|
// The code pushes 'deadbeef' into memory, then the other params, and calls CREATE2, then returns
|
|
|
|
// the address
|
|
|
|
loop := []byte{
|
|
|
|
byte(vm.JUMPDEST), // [ count ]
|
|
|
|
byte(vm.PUSH1), 0, // jumpdestination
|
|
|
|
byte(vm.JUMP),
|
|
|
|
}
|
|
|
|
alloc[common.HexToAddress("0x00000000000000000000000000000000deadbeef")] = core.GenesisAccount{
|
|
|
|
Nonce: 1,
|
|
|
|
Code: loop,
|
|
|
|
Balance: big.NewInt(1),
|
|
|
|
}
|
|
|
|
alloc[from] = core.GenesisAccount{
|
|
|
|
Nonce: 1,
|
|
|
|
Code: []byte{},
|
|
|
|
Balance: big.NewInt(500000000000000),
|
|
|
|
}
|
|
|
|
_, statedb := tests.MakePreState(rawdb.NewMemoryDatabase(), alloc, false)
|
|
|
|
// Create the tracer, the EVM environment and run it
|
|
|
|
tracer := logger.NewStructLogger(&logger.Config{
|
|
|
|
Debug: false,
|
|
|
|
//DisableStorage: true,
|
|
|
|
//EnableMemory: false,
|
|
|
|
//EnableReturnData: false,
|
|
|
|
})
|
|
|
|
evm := vm.NewEVM(context, txContext, statedb, params.AllEthashProtocolChanges, vm.Config{Debug: true, Tracer: tracer})
|
core, core/types: plain Message struct (#25977)
Here, the core.Message interface turns into a plain struct and
types.Message gets removed.
This is a breaking change to packages core and core/types. While we do
not promise API stability for package core, we do for core/types. An
exception can be made for types.Message, since it doesn't have any
purpose apart from invoking the state transition in package core.
types.Message was also marked deprecated by the same commit it
got added in, 4dca5d4db7 (November 2016).
The core.Message interface was added in December 2014, in commit
db494170dc, for the purpose of 'testing' state transitions. It's the
same change that made transaction struct fields private. Before that,
the state transition used *types.Transaction directly.
Over time, multiple implementations of the interface accrued across
different packages, since constructing a Message is required whenever
one wants to invoke the state transition. These implementations all
looked very similar, a struct with private fields exposing the fields
as accessor methods.
By changing Message into a struct with public fields we can remove all
these useless interface implementations. It will also hopefully
simplify future changes to the type with less updates to apply across
all of go-ethereum when a field is added to Message.
---------
Co-authored-by: Felix Lange <fjl@twurst.com>
2 years ago
|
|
|
msg, err := core.TransactionToMessage(tx, signer, nil)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatalf("failed to prepare transaction for tracing: %v", err)
|
|
|
|
}
|
|
|
|
b.ResetTimer()
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
snap := statedb.Snapshot()
|
|
|
|
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(tx.Gas()))
|
|
|
|
_, err = st.TransitionDb()
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
statedb.RevertToSnapshot(snap)
|
|
|
|
if have, want := len(tracer.StructLogs()), 244752; have != want {
|
|
|
|
b.Fatalf("trace wrong, want %d steps, have %d", want, have)
|
|
|
|
}
|
|
|
|
tracer.Reset()
|
|
|
|
}
|
|
|
|
}
|