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

sdk: add FilterOptions #124

Merged
merged 1 commit into from
Jul 4, 2023
Merged

sdk: add FilterOptions #124

merged 1 commit into from
Jul 4, 2023

Conversation

yukibtc
Copy link
Member

@yukibtc yukibtc commented Jun 30, 2023

Closes #119

@yukibtc yukibtc added this to the Release 0.23 milestone Jun 30, 2023
@yukibtc yukibtc self-assigned this Jun 30, 2023
Copy link
Contributor

@ok300 ok300 left a comment

Choose a reason for hiding this comment

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

LGTM. I tested both of the new variants and they work.

I found one weird edge-case, where using FilterOptions::WaitForEventsAfterEOSE(x) actually waits until timeout, even if x events were received after EOSE. This happens when one of the relays is unresponsive and runs into timeout. In a sense, it behaves as expected, so I'd just ignore this for now.

crates/nostr-sdk/src/relay/mod.rs Outdated Show resolved Hide resolved
crates/nostr-sdk/src/relay/mod.rs Outdated Show resolved Hide resolved
crates/nostr-sdk/src/relay/mod.rs Outdated Show resolved Hide resolved
crates/nostr-sdk/src/relay/options.rs Outdated Show resolved Hide resolved
crates/nostr-sdk/src/relay/options.rs Outdated Show resolved Hide resolved
crates/nostr-sdk/src/relay/options.rs Outdated Show resolved Hide resolved
@ok300
Copy link
Contributor

ok300 commented Jul 1, 2023

I experimented with a different approach: #129 . I tested all 3 branches and they work.

I mainly tried to make the inner logic more readable and easier to reason about.

What do you think?

@ok300
Copy link
Contributor

ok300 commented Jul 1, 2023

On second thought, your new version is actually simpler. I closed my PR.

@ok300
Copy link
Contributor

ok300 commented Jul 1, 2023

I found a bug in your version:

timeout doesn't just mean "timeout to EOSE", it means "timeout until function returns".

So calling it with

  • timeout of Duration::from_secs(1) and
  • FilterOptions::WaitDurationAfterEOSE(Duration::from_secs(5))

will return after 1 second with a timeout (even though EOSE came on time).

@yukibtc
Copy link
Member Author

yukibtc commented Jul 2, 2023

Yes, the timeout should be intended as "timeout until function returns".
The WaitDurationAfterEOSE should be executed outside the timeout?

@ok300
Copy link
Contributor

ok300 commented Jul 2, 2023

IMO the simpler approach is better:

  • timeout refers to "timeout until EOSE" (could be renamed to better indicate that)
  • WaitDurationAfterEOSE is completely separate and up to the caller

I see two big reasons for this:

  1. It's backward compatible, so people who used timeout in the "timeout to EOSE" sense so far, will not be confused or surprised by a change in the meaning.
  2. After EOSE, there's no way to tell when a query "times out" (resulting in Err), or when the WaitDurationAfterEOSE was waited as per the filter option (success case, resulting in Ok).

Add `get_events_of_with_opts` and `req_events_of_with_opts` methods
@yukibtc yukibtc merged commit 44e754c into master Jul 4, 2023
27 checks passed
@yukibtc yukibtc deleted the filter-options branch July 4, 2023 07:33
@ok300
Copy link
Contributor

ok300 commented Jul 4, 2023

Tested all 3 versions, with different timeout combinations, all work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add get_events_of variant for post-EOSE events
2 participants