Skip to content
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

Fix subscribe_logs to pass topics correctly #118

Merged
merged 3 commits into from
May 5, 2018

Conversation

mjkoo
Copy link
Contributor

@mjkoo mjkoo commented May 1, 2018

@mjkoo
Copy link
Contributor Author

mjkoo commented May 2, 2018

Still seeing some strange behavior from geth in testing with this, am looking into it more. Any insight into how to correctly eth_subscribe to logs?

#[derive(Serialize)]
struct SubscribeLogParameters {
address: AddressVariants,
topics: Option<Vec<H256>>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This most likely should be Vec<Option<H256>> (the Vec can have 0-4 elements). Passing None tells the query to match all values on that particular position, omitting some positions should assume None (alternatively we can always require 4-element tuple of Option<H256>).

Copy link
Contributor Author

@mjkoo mjkoo May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing some tests on it now, will have an updated PR in a couple mins. Seems like there may be larger geth compatibility issues with log filters

self
}

/// Topics
pub fn topics(mut self, topic1: Option<Vec<H256>>, topic2: Option<Vec<H256>>, topic3: Option<Vec<H256>>, topic4: Option<Vec<H256>>) -> Self {
self.filter.topics = Some(vec![topic1, topic2, topic3, topic4]);
let mut topics = vec![topic1, topic2, topic3, topic4]
Copy link
Contributor Author

@mjkoo mjkoo May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat of a compromise to reduce breakage in the interface here, trims off the trailing None values from the topics as a shorter topic array will match regardless.

Think ideally this would be e.g. pub fn topics(mut self, topcs: Vec<Option<Vec<H256>>>) -> Self with perhaps build() returning Result<Filter, ...> checking that topics.len() <= 4, thoughts?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense as well. I hope that Rust will allow us to omit None soon in the future by introducing optional parameters, though :)

@mjkoo
Copy link
Contributor Author

mjkoo commented May 2, 2018

Did some experimentation with geth, added two new examples showing listening for event logs via EthFilter::create_logs_filter and EthSubscribe::subscribe_logs. These did not work with geth when linked with the released crate, but do with these changes.

Determined the following in serialized filters were causing issues with geth:

  • [TOPIC_HASH, null, null, null] won't match logs that are [TOPIC_HASH], that is null values at the end of the topics array prevent geth from matching
  • [[TOPIC_HASH], ...] won't match, geth wants single value topics to not be nested in arrays (also true for addresses)
  • Filter criteria that aren't present but serialized as null (e.g. fromBlock et. al.) will prevent matching

Restored subscribe_logs to take a filter, changed filter serialization to respect these rules. Used two examples added as tests against geth. Did not test against parity etc.

Question about change to FilterBuilder api added as comment in review.

self
}

/// Topics
pub fn topics(mut self, topic1: Option<Vec<H256>>, topic2: Option<Vec<H256>>, topic3: Option<Vec<H256>>, topic4: Option<Vec<H256>>) -> Self {
self.filter.topics = Some(vec![topic1, topic2, topic3, topic4]);
let mut topics = vec![topic1, topic2, topic3, topic4]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense as well. I hope that Rust will allow us to omit None soon in the future by introducing optional parameters, though :)

@tomusdrw
Copy link
Owner

tomusdrw commented May 5, 2018

[TOPIC_HASH, null, null, null] won't match logs that are [TOPIC_HASH], that is null values at the end of the topics array prevent geth from matching

IMHO sounds like something that could be fixed in geth. It's a bit inconsistent that nulls are accepted but not the trailing ones.

[[TOPIC_HASH], ...] won't match, geth wants single value topics to not be nested in arrays (also true for addresses)

Weird as well, makes client libraries way more complicated without any gains.

Ideally all these should be in the "spec" :(

@tomusdrw tomusdrw merged commit 0530858 into tomusdrw:master May 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants