eth/filters: add address limit to filters #31876
Open
+27
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The address filter was never checked against a maximum limit, which can be somewhat abusive for API nodes. This PR adds a limit similar to topics
Description (AI generated)
This pull request introduces a new validation to enforce a maximum limit on the number of addresses allowed in filter criteria for Ethereum logs. It includes updates to the
FilterAPI
andEventSystem
logic, as well as corresponding test cases to ensure the new constraint is properly enforced.Core functionality changes:
maxAddresses
, set to 100, to define the maximum allowable addresses in a filter.errExceedMaxAddresses
, to handle cases where the number of addresses exceeds the limit.GetLogs
method inFilterAPI
to validate the number of addresses againstmaxAddresses
.UnmarshalJSON
method to return an error if the number of addresses in the input JSON exceedsmaxAddresses
.SubscribeLogs
method inEventSystem
.Test updates:
TestUnmarshalJSONNewFilterArgs
to verify that exceeding the maximum number of addresses triggers theerrExceedMaxAddresses
error.TestInvalidLogFilterCreation
to include a test case for an invalid filter with more thanmaxAddresses
addresses.TestInvalidGetLogsRequest
to test for invalid log requests with excessive addresses.These changes ensure that the system enforces a reasonable limit on the number of addresses in filter criteria, improving robustness and preventing potential performance issues.