mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
cmd/utils, eth/filters: changed flag name to LogQueryLimit
This commit is contained in:
parent
75dd37215b
commit
3cc4015d29
7 changed files with 44 additions and 44 deletions
|
|
@ -180,7 +180,7 @@ var (
|
||||||
utils.RPCGlobalGasCapFlag,
|
utils.RPCGlobalGasCapFlag,
|
||||||
utils.RPCGlobalEVMTimeoutFlag,
|
utils.RPCGlobalEVMTimeoutFlag,
|
||||||
utils.RPCGlobalTxFeeCapFlag,
|
utils.RPCGlobalTxFeeCapFlag,
|
||||||
utils.EthGetLogMaxAddressFlag,
|
utils.RPCGlobalLogQueryLimit,
|
||||||
utils.AllowUnprotectedTxs,
|
utils.AllowUnprotectedTxs,
|
||||||
utils.BatchRequestLimit,
|
utils.BatchRequestLimit,
|
||||||
utils.BatchResponseMaxSize,
|
utils.BatchResponseMaxSize,
|
||||||
|
|
|
||||||
|
|
@ -590,10 +590,10 @@ var (
|
||||||
Value: ethconfig.Defaults.RPCTxFeeCap,
|
Value: ethconfig.Defaults.RPCTxFeeCap,
|
||||||
Category: flags.APICategory,
|
Category: flags.APICategory,
|
||||||
}
|
}
|
||||||
EthGetLogMaxAddressFlag = &cli.IntFlag{
|
RPCGlobalLogQueryLimit = &cli.IntFlag{
|
||||||
Name: "rpc.getlogmaxaddrs",
|
Name: "rpc.logquerylimit",
|
||||||
Usage: "Maximum number of addresses allowed in eth_getLogs filter criteria",
|
Usage: "Maximum number of alternative addresses or topics allowed per search position in eth_getLogs filter criteria (0 = no cap)",
|
||||||
Value: ethconfig.Defaults.FilterMaxAddresses,
|
Value: ethconfig.Defaults.LogQueryLimit,
|
||||||
Category: flags.APICategory,
|
Category: flags.APICategory,
|
||||||
}
|
}
|
||||||
// Authenticated RPC HTTP settings
|
// Authenticated RPC HTTP settings
|
||||||
|
|
@ -1695,8 +1695,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
if ctx.IsSet(CacheLogSizeFlag.Name) {
|
if ctx.IsSet(CacheLogSizeFlag.Name) {
|
||||||
cfg.FilterLogCacheSize = ctx.Int(CacheLogSizeFlag.Name)
|
cfg.FilterLogCacheSize = ctx.Int(CacheLogSizeFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.IsSet(EthGetLogMaxAddressFlag.Name) {
|
if ctx.IsSet(RPCGlobalLogQueryLimit.Name) {
|
||||||
cfg.FilterMaxAddresses = ctx.Int(EthGetLogMaxAddressFlag.Name)
|
cfg.LogQueryLimit = ctx.Int(RPCGlobalLogQueryLimit.Name)
|
||||||
}
|
}
|
||||||
if !ctx.Bool(SnapshotFlag.Name) || cfg.SnapshotCache == 0 {
|
if !ctx.Bool(SnapshotFlag.Name) || cfg.SnapshotCache == 0 {
|
||||||
// If snap-sync is requested, this flag is also required
|
// If snap-sync is requested, this flag is also required
|
||||||
|
|
@ -2007,7 +2007,7 @@ func RegisterGraphQLService(stack *node.Node, backend ethapi.Backend, filterSyst
|
||||||
func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconfig.Config) *filters.FilterSystem {
|
func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconfig.Config) *filters.FilterSystem {
|
||||||
filterSystem := filters.NewFilterSystem(backend, filters.Config{
|
filterSystem := filters.NewFilterSystem(backend, filters.Config{
|
||||||
LogCacheSize: ethcfg.FilterLogCacheSize,
|
LogCacheSize: ethcfg.FilterLogCacheSize,
|
||||||
MaxAddresses: ethcfg.FilterMaxAddresses,
|
LogQueryLimit: ethcfg.LogQueryLimit,
|
||||||
})
|
})
|
||||||
stack.RegisterAPIs([]rpc.API{{
|
stack.RegisterAPIs([]rpc.API{{
|
||||||
Namespace: "eth",
|
Namespace: "eth",
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ var Defaults = Config{
|
||||||
TrieTimeout: 60 * time.Minute,
|
TrieTimeout: 60 * time.Minute,
|
||||||
SnapshotCache: 102,
|
SnapshotCache: 102,
|
||||||
FilterLogCacheSize: 32,
|
FilterLogCacheSize: 32,
|
||||||
FilterMaxAddresses: 1000,
|
LogQueryLimit: 1000,
|
||||||
Miner: miner.DefaultConfig,
|
Miner: miner.DefaultConfig,
|
||||||
TxPool: legacypool.DefaultConfig,
|
TxPool: legacypool.DefaultConfig,
|
||||||
BlobPool: blobpool.DefaultConfig,
|
BlobPool: blobpool.DefaultConfig,
|
||||||
|
|
@ -133,7 +133,7 @@ type Config struct {
|
||||||
FilterLogCacheSize int
|
FilterLogCacheSize int
|
||||||
|
|
||||||
// This is the maximum number of addresses allowed in filter criteria for eth_getLogs.
|
// This is the maximum number of addresses allowed in filter criteria for eth_getLogs.
|
||||||
FilterMaxAddresses int
|
LogQueryLimit int
|
||||||
|
|
||||||
// Mining options
|
// Mining options
|
||||||
Miner miner.Config
|
Miner miner.Config
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
SnapshotCache int
|
SnapshotCache int
|
||||||
Preimages bool
|
Preimages bool
|
||||||
FilterLogCacheSize int
|
FilterLogCacheSize int
|
||||||
FilterMaxAddresses int
|
LogQueryLimit int
|
||||||
Miner miner.Config
|
Miner miner.Config
|
||||||
TxPool legacypool.Config
|
TxPool legacypool.Config
|
||||||
BlobPool blobpool.Config
|
BlobPool blobpool.Config
|
||||||
|
|
@ -87,7 +87,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
enc.SnapshotCache = c.SnapshotCache
|
enc.SnapshotCache = c.SnapshotCache
|
||||||
enc.Preimages = c.Preimages
|
enc.Preimages = c.Preimages
|
||||||
enc.FilterLogCacheSize = c.FilterLogCacheSize
|
enc.FilterLogCacheSize = c.FilterLogCacheSize
|
||||||
enc.FilterMaxAddresses = c.FilterMaxAddresses
|
enc.LogQueryLimit = c.LogQueryLimit
|
||||||
enc.Miner = c.Miner
|
enc.Miner = c.Miner
|
||||||
enc.TxPool = c.TxPool
|
enc.TxPool = c.TxPool
|
||||||
enc.BlobPool = c.BlobPool
|
enc.BlobPool = c.BlobPool
|
||||||
|
|
@ -134,7 +134,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
SnapshotCache *int
|
SnapshotCache *int
|
||||||
Preimages *bool
|
Preimages *bool
|
||||||
FilterLogCacheSize *int
|
FilterLogCacheSize *int
|
||||||
FilterMaxAddresses *int
|
LogQueryLimit *int
|
||||||
Miner *miner.Config
|
Miner *miner.Config
|
||||||
TxPool *legacypool.Config
|
TxPool *legacypool.Config
|
||||||
BlobPool *blobpool.Config
|
BlobPool *blobpool.Config
|
||||||
|
|
@ -234,8 +234,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
if dec.FilterLogCacheSize != nil {
|
if dec.FilterLogCacheSize != nil {
|
||||||
c.FilterLogCacheSize = *dec.FilterLogCacheSize
|
c.FilterLogCacheSize = *dec.FilterLogCacheSize
|
||||||
}
|
}
|
||||||
if dec.FilterMaxAddresses != nil {
|
if dec.LogQueryLimit != nil {
|
||||||
c.FilterMaxAddresses = *dec.FilterMaxAddresses
|
c.LogQueryLimit = *dec.LogQueryLimit
|
||||||
}
|
}
|
||||||
if dec.Miner != nil {
|
if dec.Miner != nil {
|
||||||
c.Miner = *dec.Miner
|
c.Miner = *dec.Miner
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ var (
|
||||||
errBlockHashWithRange = errors.New("can't specify fromBlock/toBlock with blockHash")
|
errBlockHashWithRange = errors.New("can't specify fromBlock/toBlock with blockHash")
|
||||||
errPendingLogsUnsupported = errors.New("pending logs are not supported")
|
errPendingLogsUnsupported = errors.New("pending logs are not supported")
|
||||||
errExceedMaxTopics = errors.New("exceed max topics")
|
errExceedMaxTopics = errors.New("exceed max topics")
|
||||||
errExceedMaxAddresses = errors.New("exceed max addresses")
|
errExceedLogQueryLimit = errors.New("exceed max addresses or topics per search position")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -73,7 +73,7 @@ type FilterAPI struct {
|
||||||
filtersMu sync.Mutex
|
filtersMu sync.Mutex
|
||||||
filters map[rpc.ID]*filter
|
filters map[rpc.ID]*filter
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
maxAddresses int
|
logQueryLimit int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFilterAPI returns a new FilterAPI instance.
|
// NewFilterAPI returns a new FilterAPI instance.
|
||||||
|
|
@ -83,7 +83,7 @@ func NewFilterAPI(system *FilterSystem) *FilterAPI {
|
||||||
events: NewEventSystem(system),
|
events: NewEventSystem(system),
|
||||||
filters: make(map[rpc.ID]*filter),
|
filters: make(map[rpc.ID]*filter),
|
||||||
timeout: system.cfg.Timeout,
|
timeout: system.cfg.Timeout,
|
||||||
maxAddresses: system.cfg.MaxAddresses,
|
logQueryLimit: system.cfg.LogQueryLimit,
|
||||||
}
|
}
|
||||||
go api.timeoutLoop(system.cfg.Timeout)
|
go api.timeoutLoop(system.cfg.Timeout)
|
||||||
|
|
||||||
|
|
@ -347,8 +347,8 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type
|
||||||
if len(crit.Topics) > maxTopics {
|
if len(crit.Topics) > maxTopics {
|
||||||
return nil, errExceedMaxTopics
|
return nil, errExceedMaxTopics
|
||||||
}
|
}
|
||||||
if len(crit.Addresses) > api.maxAddresses {
|
if len(crit.Addresses) > api.logQueryLimit {
|
||||||
return nil, errExceedMaxAddresses
|
return nil, errExceedLogQueryLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
var filter *Filter
|
var filter *Filter
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ import (
|
||||||
type Config struct {
|
type Config struct {
|
||||||
LogCacheSize int // maximum number of cached blocks (default: 32)
|
LogCacheSize int // maximum number of cached blocks (default: 32)
|
||||||
Timeout time.Duration // how long filters stay active (default: 5min)
|
Timeout time.Duration // how long filters stay active (default: 5min)
|
||||||
MaxAddresses int // maximum number of addresses allowed in filter criteria (default: 1000)
|
LogQueryLimit int // maximum number of addresses allowed in filter criteria (default: 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg Config) withDefaults() Config {
|
func (cfg Config) withDefaults() Config {
|
||||||
|
|
@ -53,8 +53,8 @@ func (cfg Config) withDefaults() Config {
|
||||||
if cfg.LogCacheSize == 0 {
|
if cfg.LogCacheSize == 0 {
|
||||||
cfg.LogCacheSize = 32
|
cfg.LogCacheSize = 32
|
||||||
}
|
}
|
||||||
if cfg.MaxAddresses == 0 {
|
if cfg.LogQueryLimit == 0 {
|
||||||
cfg.MaxAddresses = 1000
|
cfg.LogQueryLimit = 1000
|
||||||
}
|
}
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
@ -295,8 +295,8 @@ func (es *EventSystem) SubscribeLogs(crit ethereum.FilterQuery, logs chan []*typ
|
||||||
if len(crit.Topics) > maxTopics {
|
if len(crit.Topics) > maxTopics {
|
||||||
return nil, errExceedMaxTopics
|
return nil, errExceedMaxTopics
|
||||||
}
|
}
|
||||||
if len(crit.Addresses) > es.sys.cfg.MaxAddresses {
|
if len(crit.Addresses) > es.sys.cfg.LogQueryLimit {
|
||||||
return nil, errExceedMaxAddresses
|
return nil, errExceedLogQueryLimit
|
||||||
}
|
}
|
||||||
var from, to rpc.BlockNumber
|
var from, to rpc.BlockNumber
|
||||||
if crit.FromBlock == nil {
|
if crit.FromBlock == nil {
|
||||||
|
|
|
||||||
|
|
@ -435,7 +435,7 @@ func TestInvalidLogFilterCreation(t *testing.T) {
|
||||||
1: {FromBlock: big.NewInt(rpc.PendingBlockNumber.Int64()), ToBlock: big.NewInt(100)},
|
1: {FromBlock: big.NewInt(rpc.PendingBlockNumber.Int64()), ToBlock: big.NewInt(100)},
|
||||||
2: {FromBlock: big.NewInt(rpc.LatestBlockNumber.Int64()), ToBlock: big.NewInt(100)},
|
2: {FromBlock: big.NewInt(rpc.LatestBlockNumber.Int64()), ToBlock: big.NewInt(100)},
|
||||||
3: {Topics: [][]common.Hash{{}, {}, {}, {}, {}}},
|
3: {Topics: [][]common.Hash{{}, {}, {}, {}, {}}},
|
||||||
4: {Addresses: make([]common.Address, api.maxAddresses+1)},
|
4: {Addresses: make([]common.Address, api.logQueryLimit+1)},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range testCases {
|
for i, test := range testCases {
|
||||||
|
|
@ -532,10 +532,10 @@ func TestInvalidGetRangeLogsRequest(t *testing.T) {
|
||||||
func TestInvalidAddressLengthRequest(t *testing.T) {
|
func TestInvalidAddressLengthRequest(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
// Test with custom config (MaxAddresses = 5 for easier testing)
|
// Test with custom config (LogQueryLimit = 5 for easier testing)
|
||||||
var (
|
var (
|
||||||
db = rawdb.NewMemoryDatabase()
|
db = rawdb.NewMemoryDatabase()
|
||||||
_, sys = newTestFilterSystem(db, Config{MaxAddresses: 5})
|
_, sys = newTestFilterSystem(db, Config{LogQueryLimit: 5})
|
||||||
api = NewFilterAPI(sys)
|
api = NewFilterAPI(sys)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -550,14 +550,14 @@ func TestInvalidAddressLengthRequest(t *testing.T) {
|
||||||
FromBlock: big.NewInt(0),
|
FromBlock: big.NewInt(0),
|
||||||
ToBlock: big.NewInt(100),
|
ToBlock: big.NewInt(100),
|
||||||
Addresses: invalidAddresses,
|
Addresses: invalidAddresses,
|
||||||
}); err != errExceedMaxAddresses {
|
}); err != errExceedLogQueryLimit {
|
||||||
t.Errorf("Expected GetLogs with 6 addresses to return errExceedMaxAddresses, but got: %v", err)
|
t.Errorf("Expected GetLogs with 6 addresses to return errExceedLogQueryLimit, but got: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test with default config should reject 1001 addresses
|
// Test with default config should reject 1001 addresses
|
||||||
var (
|
var (
|
||||||
db2 = rawdb.NewMemoryDatabase()
|
db2 = rawdb.NewMemoryDatabase()
|
||||||
_, sys2 = newTestFilterSystem(db2, Config{}) // Uses default MaxAddresses = 1000
|
_, sys2 = newTestFilterSystem(db2, Config{}) // Uses default LogQueryLimit = 1000
|
||||||
api2 = NewFilterAPI(sys2)
|
api2 = NewFilterAPI(sys2)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -571,8 +571,8 @@ func TestInvalidAddressLengthRequest(t *testing.T) {
|
||||||
FromBlock: big.NewInt(0),
|
FromBlock: big.NewInt(0),
|
||||||
ToBlock: big.NewInt(100),
|
ToBlock: big.NewInt(100),
|
||||||
Addresses: tooManyAddresses,
|
Addresses: tooManyAddresses,
|
||||||
}); err != errExceedMaxAddresses {
|
}); err != errExceedLogQueryLimit {
|
||||||
t.Errorf("Expected GetLogs with 1001 addresses to return errExceedMaxAddresses, but got: %v", err)
|
t.Errorf("Expected GetLogs with 1001 addresses to return errExceedLogQueryLimit, but got: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue