2021-06-26 03:38:04 +00:00
|
|
|
package eth
|
|
|
|
|
|
|
|
import (
|
2021-09-08 21:38:17 +00:00
|
|
|
"math/big"
|
|
|
|
"reflect"
|
|
|
|
"time"
|
|
|
|
|
2021-09-01 20:34:03 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/plugins"
|
2021-09-08 21:38:17 +00:00
|
|
|
"github.com/ethereum/go-ethereum/plugins/wrappers"
|
|
|
|
"github.com/openrelayxyz/plugeth-utils/core"
|
2021-06-26 03:38:04 +00:00
|
|
|
)
|
|
|
|
|
2021-09-01 20:34:03 +00:00
|
|
|
type metaTracer struct {
|
2021-09-08 21:38:17 +00:00
|
|
|
tracers []core.TracerResult
|
2021-06-28 17:11:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mt *metaTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
|
2021-09-01 20:34:03 +00:00
|
|
|
for _, tracer := range mt.tracers {
|
2021-09-08 21:38:17 +00:00
|
|
|
tracer.CaptureStart(core.Address(from), core.Address(to), create, input, gas, value)
|
2021-09-01 20:34:03 +00:00
|
|
|
}
|
2021-06-28 17:11:38 +00:00
|
|
|
}
|
|
|
|
func (mt *metaTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) {
|
2021-09-01 20:34:03 +00:00
|
|
|
for _, tracer := range mt.tracers {
|
2021-09-08 21:38:17 +00:00
|
|
|
tracer.CaptureState(pc, core.OpCode(op), gas, cost, wrappers.NewWrappedScopeContext(scope), rData, depth, err)
|
2021-09-01 20:34:03 +00:00
|
|
|
}
|
2021-06-28 17:11:38 +00:00
|
|
|
}
|
|
|
|
func (mt *metaTracer) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) {
|
2021-09-01 20:34:03 +00:00
|
|
|
for _, tracer := range mt.tracers {
|
2021-09-08 21:38:17 +00:00
|
|
|
tracer.CaptureFault(pc, core.OpCode(op), gas, cost, wrappers.NewWrappedScopeContext(scope), depth, err)
|
2021-09-01 20:34:03 +00:00
|
|
|
}
|
2021-06-28 17:11:38 +00:00
|
|
|
}
|
|
|
|
func (mt *metaTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) {
|
2021-09-01 20:34:03 +00:00
|
|
|
for _, tracer := range mt.tracers {
|
|
|
|
tracer.CaptureEnd(output, gasUsed, t, err)
|
|
|
|
}
|
2021-06-28 17:11:38 +00:00
|
|
|
}
|
|
|
|
|
2021-06-26 04:02:25 +00:00
|
|
|
func PluginUpdateBlockchainVMConfig(pl *plugins.PluginLoader, cfg *vm.Config) {
|
2021-09-01 20:34:03 +00:00
|
|
|
tracerList := plugins.Lookup("LiveTracer", func(item interface{}) bool {
|
2021-10-11 18:43:26 +00:00
|
|
|
_, ok := item.(core.TracerResult)
|
2021-09-01 20:34:03 +00:00
|
|
|
log.Info("Item is LiveTracer", "ok", ok, "type", reflect.TypeOf(item))
|
|
|
|
return ok
|
|
|
|
})
|
|
|
|
if len(tracerList) > 0 {
|
2021-09-08 21:38:17 +00:00
|
|
|
mt := &metaTracer{tracers: []core.TracerResult{}}
|
2021-09-01 20:34:03 +00:00
|
|
|
for _, tracer := range tracerList {
|
2021-09-08 21:38:17 +00:00
|
|
|
if v, ok := tracer.(core.TracerResult); ok {
|
2021-09-01 20:34:03 +00:00
|
|
|
log.Info("LiveTracer registered")
|
2021-09-08 21:38:17 +00:00
|
|
|
mt.tracers = append(mt.tracers, v)
|
2021-09-01 20:34:03 +00:00
|
|
|
} else {
|
|
|
|
log.Info("Item is not tracer")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cfg.Debug = true
|
2021-09-17 19:11:30 +00:00
|
|
|
cfg.Tracer = mt
|
2021-09-01 20:34:03 +00:00
|
|
|
} else {
|
|
|
|
log.Warn("Module is not tracer")
|
|
|
|
}
|
2021-06-28 17:11:38 +00:00
|
|
|
|
2021-06-26 03:38:04 +00:00
|
|
|
}
|
|
|
|
|
2021-06-26 04:02:25 +00:00
|
|
|
func pluginUpdateBlockchainVMConfig(cfg *vm.Config) {
|
2021-09-01 20:34:03 +00:00
|
|
|
if plugins.DefaultPluginLoader == nil {
|
2021-06-26 04:02:25 +00:00
|
|
|
log.Warn("Attempting CreateConsensusEngine, but default PluginLoader has not been initialized")
|
2021-09-01 20:34:03 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
PluginUpdateBlockchainVMConfig(plugins.DefaultPluginLoader, cfg)
|
2021-06-26 04:02:25 +00:00
|
|
|
}
|