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: Remove Sync requirements on Futures returned in the Rust plugin library. #6490

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

junderw
Copy link
Contributor

@junderw junderw commented Aug 3, 2023

See: bitcoindevkit/bdk#1047 (comment)

In general, futures produced by most libraries in the ecosystem of Rust, and bounds placed on users of famous runtimes like tokio and its spawn method all lack Sync requirements.

Because of this, anyone who creates a callback using any sort of library that returns a non-Sync future (which most libraries fit this description) inside of it will get some cryptic error messages (async error messages still leave a lot to be desired).

Removing these Sync requirements will make the library more useful.

…library.

See: bitcoindevkit/bdk#1047 (comment)

In general, futures produced by most libraries in the ecosystem of Rust, and bounds placed
on users of famous runtimes like tokio and its spawn method all lack Sync requirements.

Because of this, anyone who creates a callback using any sort of library that returns a
non-Sync future (which most libraries fit this description) inside of it will get some
cryptic error messages (async error messages still leave a lot to be desired).

Removing these Sync requirements will make the library more useful.
@junderw junderw requested a review from cdecker as a code owner August 3, 2023 06:56
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

Mh, I need to think more hard about this, but at least this should not be a breaking change because we are relaxing the requirements, and also looks like our internal plugin is not doing something that required Sync, but I need to look more into it.

In addition, the current API will have still problems due the Send requirements, see rust-lang/rust#102211

@junderw
Copy link
Contributor Author

junderw commented Aug 3, 2023

internal plugin is not doing something that required Sync

  1. Plugin doesn't require Sync on its S (even before this PR)
  2. AsyncCallback and AsyncNotificationCallback only use S for the argument (Plugin) of the callback, which has nothing to do with the anonymous closure-struct contained in the HashMaps (since they only contain items that were captured)
  3. The AsyncCallback and AsyncNotificationCallback already have Send + Sync bounds on the closures themselves, and it doesn't interfere with the Future removing Sync.

So theoretically, there should be no possible way this causes a problem.

will have still problems due the Send requirements

This is more of a language problem. I have nothing but respect for the async-wg and their work on getting things to be more compatible across the ecosystem, but the problems caused by the superfluous Sync bound are much greater than the small edge case that exists for every async library.

@vincenzopalazzo
Copy link
Collaborator

Yeah, I see your point! To me, this change sounds good also because it is just relaxing the requirements, but I am not sure why this bound was specified, so better wait more expert people on this

@cdecker
Copy link
Member

cdecker commented Aug 4, 2023

Thanks @junderw, to be honest when I wrote the library I was (and probably still am) a Rust novice, so I resorted to fiddling with the constraints until they worked. If we can relax some of the constraints that's perfect.

I appreciate the correction very much 👍

ACK d163230

@junderw
Copy link
Contributor Author

junderw commented Aug 5, 2023

Would you like me to bump the Cargo.toml version to 0.1.5? That way you can just cargo publish after merging.

@cdecker
Copy link
Member

cdecker commented Aug 5, 2023

I have a couple more changes but will bump as soon as possible 👍

@rustyrussell
Copy link
Contributor

rustyrussell commented Aug 7, 2023

Seems like this should go into the current release, @cdecker ? If so, please merge! (Otherwise please fix milestone!)

@rustyrussell rustyrussell added this to the v23.08 milestone Aug 7, 2023
@rustyrussell rustyrussell merged commit 32b88a2 into ElementsProject:master Aug 8, 2023
39 checks passed
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.

4 participants