Skip to content

Commit

Permalink
trace filter count limit
Browse files Browse the repository at this point in the history
  • Loading branch information
freddie committed Nov 18, 2024
1 parent 0c0dd33 commit 242b48a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ var (
utils.LogDebugFlag,
utils.LogBacktraceAtFlag,
utils.TraceActionFlag,
utils.TraceFilterCount,
}, utils.NetworkFlags, utils.DatabaseFlags)

rpcFlags = []cli.Flag{
Expand Down
10 changes: 9 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,11 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Name: "traceaction",
Usage: "Trace internal tx call/create/suicide action, 0=no trace, 1=trace only native token > 0, 2=trace all",
}
TraceFilterCount = &cli.Uint64Flag{
Name: "tracefiltercount",
Value: ethconfig.Defaults.TraceFilterCount,
Usage: "trace filter count",
}
)

var (
Expand Down Expand Up @@ -1627,6 +1632,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(TraceActionFlag.Name) {
cfg.TraceAction = ctx.Int(TraceActionFlag.Name)
}
if ctx.IsSet(TraceFilterCount.Name) {
cfg.TraceFilterCount = ctx.Uint64(TraceFilterCount.Name)
}
setEtherbase(ctx, cfg)
setGPO(ctx, &cfg.GPO)
setTxPool(ctx, &cfg.TxPool)
Expand Down Expand Up @@ -1909,7 +1917,7 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend
Fatalf("Failed to register the Ethereum service: %v", err)
}
stack.RegisterAPIs(tracers.APIs(backend.APIBackend))
stack.RegisterAPIs(tracers.TraceAPIs(backend.APIBackend))
stack.RegisterAPIs(tracers.TraceAPIs(backend.APIBackend, cfg.TraceFilterCount))
return backend.APIBackend, backend
}

Expand Down
3 changes: 3 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var Defaults = Config{
RPCEVMTimeout: 5 * time.Second,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether
TraceFilterCount: 8192,
}

//go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go
Expand Down Expand Up @@ -166,6 +167,8 @@ type Config struct {

// Enable record action trace
TraceAction int `toml:",omitempty"`

TraceFilterCount uint64 `toml:",omitempty"`
}

// CreateConsensusEngine creates a consensus engine for the given chain config.
Expand Down
17 changes: 10 additions & 7 deletions eth/tracers/api_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
)

type TraceAPI struct {
backend Backend
backend Backend
traceFilterCount uint64
}

func NewTraceAPI(backend Backend) *TraceAPI {
return &TraceAPI{backend: backend}
func NewTraceAPI(backend Backend, traceFilterCount uint64) *TraceAPI {
log.Info("NewTraceAPI traceFilterCount", traceFilterCount)
return &TraceAPI{backend: backend, traceFilterCount: traceFilterCount}
}

func (api *TraceAPI) Filter(ctx context.Context, req *types.TraceFilterRequest) (types.ParityTraces, error) {
Expand Down Expand Up @@ -70,8 +73,8 @@ func (api *TraceAPI) Filter(ctx context.Context, req *types.TraceFilterRequest)

includeAll := len(fromAddresses) == 0 && len(toAddresses) == 0

// TODO max count ?
count := uint64(^uint(0)) // this just makes it easier to use below
// count := uint64(^uint(0)) // this just makes it easier to use below
count := api.traceFilterCount
if req.Count != nil {
count = *req.Count
}
Expand Down Expand Up @@ -196,12 +199,12 @@ func (api *TraceAPI) Filter(ctx context.Context, req *types.TraceFilterRequest)
}

// TraceAPIs return the collection of RPC services the tracer package offers.
func TraceAPIs(backend Backend) []rpc.API {
func TraceAPIs(backend Backend, traceFilterCount uint64) []rpc.API {
// Append all the local APIs and return
return []rpc.API{
{
Namespace: "trace",
Service: NewTraceAPI(backend),
Service: NewTraceAPI(backend, traceFilterCount),
},
}
}

0 comments on commit 242b48a

Please sign in to comment.