mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
pass eth.Backend into live tracer
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
561c43d873
commit
9ae1444d48
6 changed files with 16 additions and 21 deletions
|
|
@ -2192,7 +2192,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
|
|||
if ctx.IsSet(VMTraceJsonConfigFlag.Name) {
|
||||
config = json.RawMessage(ctx.String(VMTraceJsonConfigFlag.Name))
|
||||
}
|
||||
t, err := tracers.LiveDirectory.New(name, config, stack)
|
||||
t, err := tracers.LiveDirectory.New(name, config, stack, nil)
|
||||
if err != nil {
|
||||
Fatalf("Failed to create tracer %q: %v", name, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/bloombits"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
"github.com/ethereum/go-ethereum/core/state/pruner"
|
||||
"github.com/ethereum/go-ethereum/core/tracing"
|
||||
"github.com/ethereum/go-ethereum/core/txpool"
|
||||
"github.com/ethereum/go-ethereum/core/txpool/blobpool"
|
||||
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
|
||||
|
|
@ -181,6 +180,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
rawdb.WriteDatabaseVersion(chainDb, core.BlockChainVersion)
|
||||
}
|
||||
}
|
||||
|
||||
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
|
||||
if eth.APIBackend.allowUnprotectedTxs {
|
||||
log.Info("Unprotected transactions allowed")
|
||||
}
|
||||
|
||||
var (
|
||||
vmConfig = vm.Config{
|
||||
EnablePreimageRecording: config.EnablePreimageRecording,
|
||||
|
|
@ -196,19 +201,17 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
StateHistory: config.StateHistory,
|
||||
StateScheme: scheme,
|
||||
}
|
||||
liveTracer *tracing.Hooks
|
||||
)
|
||||
if config.VMTrace != "" {
|
||||
var traceConfig json.RawMessage
|
||||
if config.VMTraceJsonConfig != "" {
|
||||
traceConfig = json.RawMessage(config.VMTraceJsonConfig)
|
||||
}
|
||||
var err error
|
||||
liveTracer, err = tracers.LiveDirectory.New(config.VMTrace, traceConfig, stack)
|
||||
t, err := tracers.LiveDirectory.New(config.VMTrace, traceConfig, stack, eth.APIBackend)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create tracer %s: %v", config.VMTrace, err)
|
||||
}
|
||||
vmConfig.Tracer = liveTracer
|
||||
vmConfig.Tracer = t
|
||||
}
|
||||
// Override the chain config with provided settings.
|
||||
var overrides core.ChainOverrides
|
||||
|
|
@ -257,10 +260,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
eth.miner = miner.New(eth, config.Miner, eth.engine)
|
||||
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
|
||||
|
||||
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
|
||||
if eth.APIBackend.allowUnprotectedTxs {
|
||||
log.Info("Unprotected transactions allowed")
|
||||
}
|
||||
// Start the gas price oracle after blockchain is fully loaded
|
||||
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, config.GPO, config.Miner.GasPrice)
|
||||
|
||||
// Start the RPC service
|
||||
|
|
@ -271,11 +271,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
stack.RegisterProtocols(eth.Protocols())
|
||||
stack.RegisterLifecycle(eth)
|
||||
|
||||
// Set live tracer's backend and register the live tracer APIs
|
||||
if liveTracer != nil {
|
||||
liveTracer.SetBackend(eth.APIBackend)
|
||||
}
|
||||
|
||||
// Successful startup; push a marker and check previous unclean shutdowns.
|
||||
eth.shutdownTracker.MarkStartup()
|
||||
|
||||
|
|
|
|||
|
|
@ -552,7 +552,7 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG
|
|||
traceOutputFilename := path.Join(traceOutputPath, "supply.jsonl")
|
||||
|
||||
// Load supply tracer
|
||||
tracer, err := tracers.LiveDirectory.New("supply", json.RawMessage(fmt.Sprintf(`{"path":"%s"}`, traceOutputPath)), nil)
|
||||
tracer, err := tracers.LiveDirectory.New("supply", json.RawMessage(fmt.Sprintf(`{"path":"%s"}`, traceOutputPath)), nil, nil)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to create call tracer: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ type LiveApiRegister interface {
|
|||
RegisterAPIs(apis []rpc.API)
|
||||
}
|
||||
|
||||
type ctorFunc func(config json.RawMessage, stack LiveApiRegister) (*tracing.Hooks, error)
|
||||
type ctorFunc func(config json.RawMessage, stack LiveApiRegister, backend tracing.Backend) (*tracing.Hooks, error)
|
||||
|
||||
// LiveDirectory is the collection of tracers which can be used
|
||||
// during normal block import operations.
|
||||
|
|
@ -29,9 +29,9 @@ func (d *liveDirectory) Register(name string, f ctorFunc) {
|
|||
}
|
||||
|
||||
// New instantiates a tracer by name.
|
||||
func (d *liveDirectory) New(name string, config json.RawMessage, stack LiveApiRegister) (*tracing.Hooks, error) {
|
||||
func (d *liveDirectory) New(name string, config json.RawMessage, stack LiveApiRegister, backend tracing.Backend) (*tracing.Hooks, error) {
|
||||
if f, ok := d.elems[name]; ok {
|
||||
return f(config, stack)
|
||||
return f(config, stack, backend)
|
||||
}
|
||||
return nil, errors.New("not found")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func init() {
|
|||
// as soon as we have a real live tracer.
|
||||
type noop struct{}
|
||||
|
||||
func newNoopTracer(_ json.RawMessage, _ tracers.LiveApiRegister) (*tracing.Hooks, error) {
|
||||
func newNoopTracer(_ json.RawMessage, _ tracers.LiveApiRegister, _ tracing.Backend) (*tracing.Hooks, error) {
|
||||
t := &noop{}
|
||||
return &tracing.Hooks{
|
||||
OnTxStart: t.OnTxStart,
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ type supplyTracerConfig struct {
|
|||
MaxSize int `json:"maxSize"` // MaxSize is the maximum size in megabytes of the tracer log file before it gets rotated. It defaults to 100 megabytes.
|
||||
}
|
||||
|
||||
func newSupply(cfg json.RawMessage, _ tracers.LiveApiRegister) (*tracing.Hooks, error) {
|
||||
func newSupply(cfg json.RawMessage, _ tracers.LiveApiRegister, _ tracing.Backend) (*tracing.Hooks, error) {
|
||||
var config supplyTracerConfig
|
||||
if cfg != nil {
|
||||
if err := json.Unmarshal(cfg, &config); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue