-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
refactor(rpc): simplify the inner definitions of topics & address filters #3876
refactor(rpc): simplify the inner definitions of topics & address filters #3876
Conversation
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.
this simplifies it a lot but
the only case that isn't taken into account is null within a filter set, eg: topics: [[null], [0x...]] ; but I don't see how this can be useful.
would be a deal breaker because the spec allows this
does this mean this pr can't handle array topics with [null]?
Which spec though? In https://ethereum.github.io/execution-apis/api-documentation/ the definition of So
Cf. the examples above. Not that it would be easy to add such cases, but I thought we'd rather want to stick to "some" spec. |
#[derive(Default, Debug, PartialEq, Eq, Clone, Deserialize)] | ||
/// FilterSet is a set of values that will be used to filter logs | ||
pub struct FilterSet<T: Eq + Hash>(HashSet<T>); |
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.
one problem here is that this type is not necessarily symmetric, so serde can lead to a different order.
I'm not sure how to correctly solve this besides making this a Vec<, which is probably fine since we don't expect this these to be more than a few items?
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.
Yep, only drawback is having a worst inclusion check. This could be balanced by having a custom serialization that orders the Vec
in ascending order? I'm quite sure how this would be an issue though?
OK so I took a look at geth's implementation of decoding events: https://github.com/ethereum/go-ethereum/blob/a196f3e8a22b6ad22ced5c2e3baf32bc3ebd4ec9/eth/filters/api.go#L540-L579 It seems that if there's a single |
this is so bad -.- |
Yeah it's bad aha! So my understanding is that, given that the
So the |
Perhaps the reasoning for this is, arrays or OR concatenations so if there's a null that this essentially matches anything and can be simplified to just [], which is [null] |
Yeah, sounds reasonable when said like this, but no sane human or framework would allow building such a query: |
yeah... sigh |
error: incorrect implementation of `clone` on a `Copy` type cf. paritytech/parity-common#767
5c40853
to
e068cdc
Compare
Use a new FilterSet<T> type for filters (each topic and address) that gets serialized/de-serialized from/to the expected type. This simplifies the matches logic. BloomFilters are also simplified, removing the need to use an `Option`.
e068cdc
to
1c1f3b4
Compare
I update my PR to take into account the Note that I had to add another temporary commit updating |
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.
this is great!
will take a look at the fixed hash thing separately.
rolled the fixed-hash dep back because we track this #3544
Codecov Report
... and 7 files with indirect coverage changes
Flags with carried forward coverage won't be shown. Click here to find out more.
|
As suggested here: #3856 (comment) ; we could use simpler definitions for the filters (topics and address) in
rpc
.A new type
struct FilterSet<T: Eq + Hash>(HashSet<T>)
has been setup, that is used by both Address and Topic filters. An address filter has typeaddress: FilterSet<Address>
, without any need forOption<...>
. If theFilterSet
is empty, it means that there is no address filter. It includes several utility functions:matches
to check if the givenvalue: &T
matches the current filterto_bloom_filter
to create a list of bloom filtersto_value_or_array
for serialization.Based on the definition of filters in
https://ethereum.github.io/execution-apis/api-documentation/
, the only case that isn't taken into account isnull
within a filter set, eg:topics: [[null], [0x...]]
; but I don't see how this can be useful.