Fix tracer loading
This commit is contained in:
parent
b821bd9948
commit
4dd3527541
@ -1,99 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/bloombits"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/plugins"
|
||||
"github.com/ethereum/go-ethereum/plugins/interfaces"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
)
|
||||
|
||||
// Backend interface provides the common API services (that are provided by
|
||||
// both full and light clients) with access to necessary functions.
|
||||
type Backend interface {
|
||||
// General Ethereum API
|
||||
Downloader() *downloader.Downloader
|
||||
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
|
||||
ChainDb() ethdb.Database
|
||||
AccountManager() *accounts.Manager
|
||||
ExtRPCEnabled() bool
|
||||
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
|
||||
RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
|
||||
UnprotectedAllowed() bool // allows only for EIP155 transactions.
|
||||
type APILoader func(*node.Node, interfaces.Backend) []rpc.API
|
||||
|
||||
// Blockchain API
|
||||
SetHead(number uint64)
|
||||
HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
|
||||
HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
|
||||
HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error)
|
||||
CurrentHeader() *types.Header
|
||||
CurrentBlock() *types.Block
|
||||
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
|
||||
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
|
||||
BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
|
||||
StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
|
||||
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
|
||||
GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
|
||||
GetTd(ctx context.Context, hash common.Hash) *big.Int
|
||||
GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, cfg *vm.Config) (*vm.EVM, func() error, error)
|
||||
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
|
||||
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
|
||||
SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
|
||||
|
||||
// Transaction pool API
|
||||
SendTx(ctx context.Context, signedTx *types.Transaction) error
|
||||
GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
|
||||
GetPoolTransactions() (types.Transactions, error)
|
||||
GetPoolTransaction(txHash common.Hash) *types.Transaction
|
||||
GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
|
||||
Stats() (pending int, queued int)
|
||||
TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
|
||||
SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
|
||||
|
||||
// Filter API
|
||||
BloomStatus() (uint64, uint64)
|
||||
GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error)
|
||||
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
|
||||
SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
|
||||
SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription
|
||||
SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
|
||||
|
||||
ChainConfig() *params.ChainConfig
|
||||
Engine() consensus.Engine
|
||||
}
|
||||
|
||||
|
||||
type APILoader func(*node.Node, Backend) []rpc.API
|
||||
|
||||
func GetAPIsFromLoader(pl *plugins.PluginLoader, stack *node.Node, backend Backend) []rpc.API {
|
||||
func GetAPIsFromLoader(pl *plugins.PluginLoader, stack *node.Node, backend interfaces.Backend) []rpc.API {
|
||||
result := []rpc.API{}
|
||||
fnList := pl.Lookup("GetAPIs", func(item interface{}) bool {
|
||||
_, ok := item.(func(*node.Node, Backend) []rpc.API)
|
||||
_, ok := item.(func(*node.Node, interfaces.Backend) []rpc.API)
|
||||
return ok
|
||||
})
|
||||
for _, fni := range fnList {
|
||||
if fn, ok := fni.(func(*node.Node, Backend) []rpc.API); ok {
|
||||
if fn, ok := fni.(func(*node.Node, interfaces.Backend) []rpc.API); ok {
|
||||
result = append(result, fn(stack, backend)...)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func pluginGetAPIs(stack *node.Node, backend Backend) []rpc.API {
|
||||
func pluginGetAPIs(stack *node.Node, backend interfaces.Backend) []rpc.API {
|
||||
if plugins.DefaultPluginLoader == nil {
|
||||
log.Warn("Attempting GetAPIs, but default PluginLoader has not been initialized")
|
||||
return []rpc.API{}
|
||||
|
@ -40,6 +40,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/plugins/interfaces"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
@ -850,7 +851,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *txTrac
|
||||
StructLogs: ethapi.FormatLogs(tracer.StructLogs()),
|
||||
}, nil
|
||||
|
||||
case TracerResult:
|
||||
case interfaces.TracerResult:
|
||||
return tracer.GetResult()
|
||||
|
||||
case *Tracer:
|
||||
|
@ -2,33 +2,30 @@ package tracers
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/plugins"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/plugins/interfaces"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
|
||||
type TracerResult interface {
|
||||
vm.Tracer
|
||||
GetResult() (interface{}, error)
|
||||
}
|
||||
|
||||
func GetPluginTracer(pl *plugins.PluginLoader, name string) (func(*state.StateDB)TracerResult, bool) {
|
||||
func GetPluginTracer(pl *plugins.PluginLoader, name string) (func(*state.StateDB)interfaces.TracerResult, bool) {
|
||||
tracers := pl.Lookup("Tracers", func(item interface{}) bool {
|
||||
_, ok := item.(map[string]func(*state.StateDB)TracerResult)
|
||||
_, ok := item.(*map[string]func(*state.StateDB)interfaces.TracerResult)
|
||||
if !ok { log.Warn("Found tracer that did not match type", "tracer", reflect.TypeOf(item) ) }
|
||||
return ok
|
||||
})
|
||||
for _, tmap := range tracers {
|
||||
if tracerMap, ok := tmap.(map[string]func(*state.StateDB)TracerResult); ok {
|
||||
if tracer, ok := tracerMap[name]; ok {
|
||||
if tracerMap, ok := tmap.(*map[string]func(*state.StateDB)interfaces.TracerResult); ok {
|
||||
if tracer, ok := (*tracerMap)[name]; ok {
|
||||
return tracer, true
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Info("Tracer not found", "name", name, "tracers", len(tracers))
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func getPluginTracer(name string) (func(*state.StateDB)TracerResult, bool) {
|
||||
func getPluginTracer(name string) (func(*state.StateDB)interfaces.TracerResult, bool) {
|
||||
if plugins.DefaultPluginLoader == nil {
|
||||
log.Warn("Attempting GetPluginTracer, but default PluginLoader has not been initialized")
|
||||
return nil, false
|
||||
|
@ -1,4 +1,4 @@
|
||||
package plugins
|
||||
package interfaces
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -72,3 +72,9 @@ type Backend interface {
|
||||
ChainConfig() *params.ChainConfig
|
||||
Engine() consensus.Engine
|
||||
}
|
||||
|
||||
|
||||
type TracerResult interface {
|
||||
vm.Tracer
|
||||
GetResult() (interface{}, error)
|
||||
}
|
@ -3,7 +3,6 @@ package plugins
|
||||
import (
|
||||
"plugin"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"gopkg.in/urfave/cli.v1"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
@ -15,10 +14,6 @@ import (
|
||||
|
||||
|
||||
type Subcommand func(*cli.Context, []string) error
|
||||
type TracerResult interface {
|
||||
vm.Tracer
|
||||
GetResult() (interface{}, error)
|
||||
}
|
||||
|
||||
|
||||
type PluginLoader struct{
|
||||
|
@ -1,47 +0,0 @@
|
||||
package rpcloader
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/plugins"
|
||||
)
|
||||
|
||||
type APILoader func(*node.Node, Backend) []rpc.API
|
||||
|
||||
func GetRPCPluginsFromLoader(pl *plugins.PluginLoader) []APILoader {
|
||||
result := []APILoader{}
|
||||
for _, plug := range pl.Plugins {
|
||||
fn, err := plug.Lookup("GetAPIs")
|
||||
if err == nil {
|
||||
apiLoader, ok := fn.(func(*node.Node, Backend) []rpc.API)
|
||||
if !ok {
|
||||
log.Warn("Could not cast plugin.GetAPIs to APILoader", "file", fpath)
|
||||
} else {
|
||||
result = append(result, APILoader(apiLoader))
|
||||
}
|
||||
} else { log.Debug("Error retrieving GetAPIs for plugin", "file", fpath, "error", err.Error()) }
|
||||
}
|
||||
}
|
||||
|
||||
func GetRPCPlugins() []APILoader {
|
||||
if plugins.DefaultPluginLoader == nil {
|
||||
log.Warn("Attempting GetRPCPlugins, but default PluginLoader has not been initialized")
|
||||
return []APILoader{}
|
||||
}
|
||||
return GetRPCPluginsFromLoader(plugins.DefaultPluginLoader)
|
||||
|
||||
}
|
||||
func GetAPIsFromLoader(pl *plugins.PluginLoader, stack *node.Node, backend Backend) []rpc.API {
|
||||
apis := []rpc.API{}
|
||||
for _, apiLoader := range pl.RPCPlugins {
|
||||
apis = append(apis, apiLoader(stack, backend)...)
|
||||
}
|
||||
return apis
|
||||
}
|
||||
|
||||
func GetAPIs(stack *node.Node, backend Backend) []rpc.API {
|
||||
if plugins.DefaultPluginLoader == nil {
|
||||
log.Warn("Attempting GetAPIs, but default PluginLoader has not been initialized")
|
||||
return []rpc.API{}
|
||||
}
|
||||
return GetAPIsFromLoader(plugins.DefaultPluginLoader, stack, backend)
|
||||
}
|
Loading…
Reference in New Issue
Block a user