Changes in service of extending block context object into the tracer plugins

This commit is contained in:
philip-morlier 2022-02-02 20:46:25 -08:00
parent ec965607cd
commit 4a33bc66c5
5 changed files with 58 additions and 14 deletions

View File

@ -882,7 +882,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex
}
// Get the tracer from the plugin loader
if tr, ok := getPluginTracer(*config.Tracer); ok {
tracer = tr(statedb)
tracer = tr(statedb, vmctx)
} else {
// Constuct the JavaScript tracer to execute with
if t, err := New(*config.Tracer, txctx); err != nil {

View File

@ -4,6 +4,7 @@ import (
"reflect"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/plugins"
"github.com/ethereum/go-ethereum/plugins/interfaces"
@ -11,29 +12,44 @@ import (
"github.com/openrelayxyz/plugeth-utils/core"
)
func GetPluginTracer(pl *plugins.PluginLoader, name string) (func(*state.StateDB) interfaces.TracerResult, bool) {
func GetPluginTracer(pl *plugins.PluginLoader, name string) (func(*state.StateDB, vm.BlockContext) interfaces.TracerResult, bool) {
tracers := pl.Lookup("Tracers", func(item interface{}) bool {
_, ok := item.(*map[string]func(core.StateDB) core.TracerResult)
if !ok {
_, ok2 := item.(*map[string]func(core.StateDB, core.BlockContext) core.TracerResult)
if !(ok || ok2) {
log.Warn("Found tracer that did not match type", "tracer", reflect.TypeOf(item))
}
return ok
return ok || ok2
})
for _, tmap := range tracers {
if tracerMap, ok := tmap.(*map[string]func(core.StateDB) core.TracerResult); ok {
if tracer, ok := (*tracerMap)[name]; ok {
return func(sdb *state.StateDB) interfaces.TracerResult {
return func(sdb *state.StateDB, vmctx vm.BlockContext) interfaces.TracerResult {
return wrappers.NewWrappedTracer(tracer(wrappers.NewWrappedStateDB(sdb)))
}, true
}
}
if tracerMap, ok := tmap.(*map[string]func(core.StateDB, core.BlockContext) core.TracerResult); ok {
if tracer, ok := (*tracerMap)[name]; ok {
return func(sdb *state.StateDB, vmctx vm.BlockContext) interfaces.TracerResult {
return wrappers.NewWrappedTracer(tracer(wrappers.NewWrappedStateDB(sdb), core.BlockContext{
Coinbase: core.Address(vmctx.Coinbase),
GasLimit: vmctx.GasLimit,
BlockNumber: vmctx.BlockNumber,
Time: vmctx.Time,
Difficulty: vmctx.Difficulty,
BaseFee: vmctx.BaseFee,
}))
}, true
}
}
}
log.Info("Tracer not found", "name", name, "tracers", len(tracers))
return nil, false
}
func getPluginTracer(name string) (func(*state.StateDB) interfaces.TracerResult, bool) {
func getPluginTracer(name string) (func(*state.StateDB, vm.BlockContext) interfaces.TracerResult, bool) {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting GetPluginTracer, but default PluginLoader has not been initialized")
return nil, false

12
go.mod
View File

@ -17,7 +17,7 @@ require (
github.com/cloudflare/cloudflare-go v0.14.0
github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.8.0
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea
github.com/deepmap/oapi-codegen v1.8.2 // indirect
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf
github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48
@ -32,7 +32,7 @@ require (
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa
github.com/google/uuid v1.1.5
github.com/gorilla/websocket v1.4.2
github.com/graph-gophers/graphql-go v1.3.0
github.com/graph-gophers/graphql-go v0.0.0-20201113091052-beb923fada29
github.com/hashicorp/go-bexpr v0.1.10
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
github.com/holiman/bloomfilter/v2 v2.0.3
@ -41,17 +41,17 @@ require (
github.com/influxdata/influxdb v1.8.3
github.com/influxdata/influxdb-client-go/v2 v2.4.0
github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect
github.com/jackpal/go-nat-pmp v1.0.2
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e
github.com/julienschmidt/httprouter v1.2.0
github.com/karalabe/usb v0.0.2
github.com/karalabe/usb v0.0.0-20211005121534-4c5740d64559
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.8
github.com/mattn/go-isatty v0.0.12
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
github.com/olekukonko/tablewriter v0.0.5
github.com/openrelayxyz/plugeth-utils v0.0.11
github.com/openrelayxyz/plugeth-utils v0.0.13
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
github.com/prometheus/tsdb v0.7.1
github.com/rjeczalik/notify v0.9.1
@ -74,5 +74,3 @@ require (
gotest.tools v2.2.0+incompatible // indirect
)
replace github.com/openrelayxyz/plugeth-utils v0.0.14 => ../plugeth-utils

3
go.sum
View File

@ -339,10 +339,13 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
<<<<<<< HEAD
github.com/openrelayxyz/plugeth-utils v0.0.10 h1:Aw1wiQUepHH9yytOM8+RlSj9Z3OU+OsegoPym7SLdic=
github.com/openrelayxyz/plugeth-utils v0.0.10/go.mod h1:Lv47unyKJ3b/PVbVAt9Uk+RQmpdrzDOsjSCPhAMQAps=
github.com/openrelayxyz/plugeth-utils v0.0.11 h1:e+pRjMyz/GHB8lJr60iH2nuclBV5YMeF3QIQ4xPVEUA=
github.com/openrelayxyz/plugeth-utils v0.0.11/go.mod h1:Lv47unyKJ3b/PVbVAt9Uk+RQmpdrzDOsjSCPhAMQAps=
=======
>>>>>>> 94587c70d... Changes in service of extending block context object into the tracer plugins
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=

View File

@ -206,7 +206,34 @@ func (n *Node) WSEndpoint() string {
func (n *Node) ResolvePath(x string) string {
return n.n.ResolvePath(x)
}
func (n *Node) Attach() (core.Client, error) {
return n.n.Attach()
}
// type WrappedBlockContext struct {
// b vm.BlockContext
// }
//
// //type WrappedBlockContext vm.BlockContext
//
// func NewWrappedBlockContext(c vm.BlockContext) *WrappedBlockContext {
// return &WrappedBlockContext{c}
// }
// func (w *WrappedBlockContext) Coinbase() core.Address {
// return core.Address(w.b.Coinbase)
// }
// func (w *WrappedBlockContext) GasLimit() uint64 {
// return w.b.GasLimit
// }
// func (w *WrappedBlockContext) BlockNumber() *big.Int {
// return w.b.BlockNumber
// }
// func (w *WrappedBlockContext) Time() *big.Int {
// return w.b.Time
// }
// func (w *WrappedBlockContext) Difficulty() *big.Int {
// return w.b.Difficulty
// }
// func (w *WrappedBlockContext) BaseFee() *big.Int {
// return w.b.BaseFee
// }