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-08-31 20:51:41 +00:00
|
|
|
// func PluginCreateConsensusEngine(pl *plugins.PluginLoader, stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
|
|
|
|
// fnList := pl.Lookup("CreateConsensusEngine", func(item interface{}) bool {
|
|
|
|
// _, ok := item.(func(*node.Node, *params.ChainConfig, *ethash.Config, []string, bool, ethdb.Database) consensus.Engine)
|
|
|
|
// return ok
|
|
|
|
// })
|
|
|
|
// for _, fni := range fnList {
|
|
|
|
// if fn, ok := fni.(func(*node.Node, *params.ChainConfig, *ethash.Config, []string, bool, ethdb.Database) consensus.Engine); ok {
|
|
|
|
// return fn(stack, chainConfig, config, notify, noverify, db)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return ethconfig.CreateConsensusEngine(stack, chainConfig, config, notify, noverify, db)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// func pluginCreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
|
|
|
|
// if plugins.DefaultPluginLoader == nil {
|
|
|
|
// log.Warn("Attempting CreateConsensusEngine, but default PluginLoader has not been initialized")
|
|
|
|
// return ethconfig.CreateConsensusEngine(stack, chainConfig, config, notify, noverify, db)
|
|
|
|
// }
|
|
|
|
// return PluginCreateConsensusEngine(plugins.DefaultPluginLoader, stack, chainConfig, config, notify, noverify, db)
|
|
|
|
// }
|
2021-06-26 04:02:25 +00:00
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
// TODO (philip): Translate to core.TracerResult instead of vm.Tracer, with appropriate type adjustments (let me know if this one is too hard)
|
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-09-08 21:38:17 +00:00
|
|
|
_, ok := item.(*vm.Tracer)
|
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-08 21:38:17 +00:00
|
|
|
cfg.Tracer = mt //I think this means we will need a vm.config wrapper although confugure doesnt sound very passive
|
2021-09-01 20:34:03 +00:00
|
|
|
} else {
|
|
|
|
log.Warn("Module is not tracer")
|
|
|
|
}
|
2021-06-28 17:11:38 +00:00
|
|
|
|
2021-09-01 20:34:03 +00:00
|
|
|
fnList := plugins.Lookup("UpdateBlockchainVMConfig", func(item interface{}) bool {
|
|
|
|
_, ok := item.(func(*vm.Config))
|
|
|
|
return ok
|
|
|
|
})
|
|
|
|
for _, fni := range fnList {
|
|
|
|
if fn, ok := fni.(func(*vm.Config)); ok {
|
|
|
|
fn(cfg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|