064f37d6f6
Here we add a Go API for running tracing plugins within the main block import process. As an advanced user of geth, you can now create a Go file in eth/tracers/live/, and within that file register your custom tracer implementation. Then recompile geth and select your tracer on the command line. Hooks defined in the tracer will run whenever a block is processed. The hook system is defined in package core/tracing. It uses a struct with callbacks, instead of requiring an interface, for several reasons: - We plan to keep this API stable long-term. The core/tracing hook API does not depend on on deep geth internals. - There are a lot of hooks, and tracers will only need some of them. Using a struct allows you to implement only the hooks you want to actually use. All existing tracers in eth/tracers/native have been rewritten to use the new hook system. This change breaks compatibility with the vm.EVMLogger interface that we used to have. If you are a user of vm.EVMLogger, please migrate to core/tracing, and sorry for breaking your stuff. But we just couldn't have both the old and new tracing APIs coexist in the EVM. --------- Co-authored-by: Matthieu Vachon <matthieu.o.vachon@gmail.com> Co-authored-by: Delweng <delweng@gmail.com> Co-authored-by: Martin HS <martin@swende.se>
97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package live
|
|
|
|
import (
|
|
"encoding/json"
|
|
"math/big"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core/tracing"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/ethereum/go-ethereum/eth/tracers"
|
|
"github.com/ethereum/go-ethereum/params"
|
|
)
|
|
|
|
func init() {
|
|
tracers.LiveDirectory.Register("noop", newNoopTracer)
|
|
}
|
|
|
|
// noop is a no-op live tracer. It's there to
|
|
// catch changes in the tracing interface, as well as
|
|
// for testing live tracing performance. Can be removed
|
|
// as soon as we have a real live tracer.
|
|
type noop struct{}
|
|
|
|
func newNoopTracer(_ json.RawMessage) (*tracing.Hooks, error) {
|
|
t := &noop{}
|
|
return &tracing.Hooks{
|
|
OnTxStart: t.OnTxStart,
|
|
OnTxEnd: t.OnTxEnd,
|
|
OnEnter: t.OnEnter,
|
|
OnExit: t.OnExit,
|
|
OnOpcode: t.OnOpcode,
|
|
OnFault: t.OnFault,
|
|
OnGasChange: t.OnGasChange,
|
|
OnBlockchainInit: t.OnBlockchainInit,
|
|
OnBlockStart: t.OnBlockStart,
|
|
OnBlockEnd: t.OnBlockEnd,
|
|
OnSkippedBlock: t.OnSkippedBlock,
|
|
OnGenesisBlock: t.OnGenesisBlock,
|
|
OnBalanceChange: t.OnBalanceChange,
|
|
OnNonceChange: t.OnNonceChange,
|
|
OnCodeChange: t.OnCodeChange,
|
|
OnStorageChange: t.OnStorageChange,
|
|
OnLog: t.OnLog,
|
|
}, nil
|
|
}
|
|
|
|
func (t *noop) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
|
}
|
|
|
|
func (t *noop) OnFault(pc uint64, op byte, gas, cost uint64, _ tracing.OpContext, depth int, err error) {
|
|
}
|
|
|
|
func (t *noop) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
|
|
}
|
|
|
|
func (t *noop) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
|
|
}
|
|
|
|
func (t *noop) OnTxStart(vm *tracing.VMContext, tx *types.Transaction, from common.Address) {
|
|
}
|
|
|
|
func (t *noop) OnTxEnd(receipt *types.Receipt, err error) {
|
|
}
|
|
|
|
func (t *noop) OnBlockStart(ev tracing.BlockEvent) {
|
|
}
|
|
|
|
func (t *noop) OnBlockEnd(err error) {
|
|
}
|
|
|
|
func (t *noop) OnSkippedBlock(ev tracing.BlockEvent) {}
|
|
|
|
func (t *noop) OnBlockchainInit(chainConfig *params.ChainConfig) {
|
|
}
|
|
|
|
func (t *noop) OnGenesisBlock(b *types.Block, alloc types.GenesisAlloc) {
|
|
}
|
|
|
|
func (t *noop) OnBalanceChange(a common.Address, prev, new *big.Int, reason tracing.BalanceChangeReason) {
|
|
}
|
|
|
|
func (t *noop) OnNonceChange(a common.Address, prev, new uint64) {
|
|
}
|
|
|
|
func (t *noop) OnCodeChange(a common.Address, prevCodeHash common.Hash, prev []byte, codeHash common.Hash, code []byte) {
|
|
}
|
|
|
|
func (t *noop) OnStorageChange(a common.Address, k, prev, new common.Hash) {
|
|
}
|
|
|
|
func (t *noop) OnLog(l *types.Log) {
|
|
|
|
}
|
|
|
|
func (t *noop) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {
|
|
}
|