-
Notifications
You must be signed in to change notification settings - Fork 72
rpc: add a rpc.rangelimit flag #33163 #1957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ package filters | |||||||||||||
| import ( | ||||||||||||||
| "context" | ||||||||||||||
| "errors" | ||||||||||||||
| "fmt" | ||||||||||||||
| "math/big" | ||||||||||||||
|
|
||||||||||||||
| "github.com/XinFinOrg/XDPoSChain/common" | ||||||||||||||
|
|
@@ -38,11 +39,13 @@ type Filter struct { | |||||||||||||
| begin, end int64 // Range interval if filtering multiple blocks | ||||||||||||||
|
|
||||||||||||||
| matcher *bloombits.Matcher | ||||||||||||||
|
|
||||||||||||||
| rangeLimit uint64 | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // NewRangeFilter creates a new filter which uses a bloom filter on blocks to | ||||||||||||||
| // figure out whether a particular block is interesting or not. | ||||||||||||||
| func (sys *FilterSystem) NewRangeFilter(begin, end int64, addresses []common.Address, topics [][]common.Hash) *Filter { | ||||||||||||||
| func (sys *FilterSystem) NewRangeFilter(begin, end int64, addresses []common.Address, topics [][]common.Hash, rangeLimit uint64) *Filter { | ||||||||||||||
| // Flatten the address and topic filter clauses into a single bloombits filter | ||||||||||||||
| // system. Since the bloombits are not positional, nil topics are permitted, | ||||||||||||||
| // which get flattened into a nil byte slice. | ||||||||||||||
|
|
@@ -69,6 +72,7 @@ func (sys *FilterSystem) NewRangeFilter(begin, end int64, addresses []common.Add | |||||||||||||
| filter.matcher = bloombits.NewMatcher(size, filters) | ||||||||||||||
| filter.begin = begin | ||||||||||||||
| filter.end = end | ||||||||||||||
| filter.rangeLimit = rangeLimit | ||||||||||||||
|
|
||||||||||||||
| return filter | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -150,6 +154,9 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) { | |||||||||||||
| if f.end, err = resolveSpecial(f.end); err != nil { | ||||||||||||||
| return nil, err | ||||||||||||||
| } | ||||||||||||||
| if f.rangeLimit != 0 && (uint64(f.end)-uint64(f.begin)) > f.rangeLimit { | ||||||||||||||
|
||||||||||||||
| if f.rangeLimit != 0 && (uint64(f.end)-uint64(f.begin)) > f.rangeLimit { | |
| // Validate that the resolved range is non-negative and ordered correctly | |
| if f.begin < 0 || f.end < 0 || f.end < f.begin { | |
| return nil, errors.New("invalid block range") | |
| } | |
| if f.rangeLimit != 0 && uint64(f.end-f.begin) > f.rangeLimit { |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new range-limit error returned here is a plain fmt.Errorf from the filters package, so when called via JSON-RPC it will be surfaced as a generic internal error rather than an invalidParamsError like other input-validation failures (e.g. errInvalidBlockRange or errExceedLogQueryLimit). For better API consistency, consider mapping range-limit violations to an invalidParamsError in the RPC layer (or defining a dedicated errExceedRangeLimit using invalidParamsErr) so clients see the standard -32602 error code instead of a generic server error.
| return nil, fmt.Errorf("exceed maximum block range: %d", f.rangeLimit) | |
| return nil, rpc.NewInvalidParamsError("exceed maximum block range: %d", f.rangeLimit) |
Uh oh!
There was an error while loading. Please reload this page.