-
Notifications
You must be signed in to change notification settings - Fork 322
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
Make backend objects Send + Sync for compatibility with cln-plugin #1047
Comments
@chrisguida for reference also add a comment with the error message you got, the one that mentions the missing send+sync. |
Here is the error:
|
It looks like this is a problem with But it's weird that something would need a Future to be |
cc @cdecker Please see the above comment. Are you sure the I'm trying to determine whether this is a problem with |
Also FYI I got this error while building this time:
Seems unrelated to the Send + Sync issue I was hitting on previous versions of this code (and which @notmandatory hit on this version of the code. His is the Sync + Send error in the previous message above). Does this warrant a new issue, or am I just doing something dumb? |
Considering that a Future only uses I don't think Sync should ever be needed to bind a Future.
|
Can you try |
@junderw same error as before:
|
pinging @evanlinjin in case he an figure out how this
|
Ok, I managed to fix the above error by replacing
with
(i have the bdk master branch stored locally there) Now I'm back to the original
|
Btw the above is just a straight copy/paste of the |
Try adding |
Then try |
These are work arounds...... the main cause is the |
To explain:
|
These workarounds are kind of hacky... but tbh the dropping tx_builder thing would have been needed regardless of cln-plugin's Sync requirement. |
Right let tx = {
let mut tx_builder = wallet.build_tx();
// build the tx
tx_builder.finish()
}; |
(In case the question comes up)
The reason why is the function signature of block_on (which is used in |
…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.
I have made a PR upstream to fix this issue. However, please keep in mind about the tx_builder and not holding it over an await point. I think this can be closed as irrelevant to bdk. Thanks for helping me find and diagnose the issue @chrisguida! |
Actually I unconvinced myself that I understand what's going on here.
|
aaaaaahhhh! lol TxBuilder is invariant in the first generic type (Store<..>) which means that the tx_builder is seen as lasting as long as the wallet and db variables by the borrow checker..... And since it uses Rc internally, it does not impl Send... oof. TxBuilder is pretty tricky to use in async then... Using |
This change was on top of 0c00bc077fe8fd3da937bc1c5b79d77fe9f8bae4. @chrisguida This should fix the issue for now until the Sync fix is merged in cln-plugin. diff --git a/src/main.rs b/src/main.rs
index 912af84..b360ed9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -367,7 +367,7 @@ async fn watchdescriptor(
(k, k_spks)
})
.collect();
- let update = client
+ let update = tokio::runtime::Handle::try_current()?.block_on(client
.scan(
local_chain,
keychain_spks,
@@ -376,7 +376,7 @@ async fn watchdescriptor(
STOP_GAP,
PARALLEL_REQUESTS,
)
- .await?;
+ )?;
println!();
wallet.apply_update(update)?;
wallet.commit()?; |
This seems to compile RE: tx_builder. let mut psbt;
{
let mut tx_builder = wallet.build_tx();
tx_builder
.add_recipient(faucet_address.script_pubkey(), SEND_AMOUNT)
.enable_rbf();
(psbt, _) = tx_builder.finish()?;
}
let finalized = wallet.sign(&mut psbt, SignOptions::default())?;
assert!(finalized); I was able to get everything to compile locally after using the handle try_current block_on method. |
I was just able to get https://github.com/chrisguida/watchdescriptor/tree/wip/esplora_client to compile after fixing the verisons etc and removing sync requirement in the cln-plugin library. Thanks for your help @junderw. |
Thanks @junderw !! Excellent work, gentlemen!!! By the way, there seems to be a new error when building with latest master. When I apply @junderw's patch from above and checkout
Shall I report this as a new issue? Perhaps just the Also FWIW I did not have to update the Looks like this is the relevant upstream PR, thanks again for all your help @junderw @LLFourn @notmandatory ! |
Also one more thing, I tried to run the code above and I got this error:
Does this warrant a new issue? Thanks! |
Nope that's just my workaround not working. :P Just wait on the Sync removal from cln-plugin. I'll try to make another workaround later when I have time. |
Replace that whole block_on thing with this instead: (This ugly workaround can be removed once the Sync bound is removed) let handle = tokio::runtime::Handle::try_current()?;
let update = std::thread::scope(|scope| {
scope
.spawn(|| {
handle.block_on(client.scan(
local_chain,
keychain_spks,
[],
[],
STOP_GAP,
PARALLEL_REQUESTS,
))
})
.join()
// join() only returns an Err if scan panicked.
})
.expect("Propagating scan() panic")?; |
(Explanation: client contains references, and is thus non-static, so even |
Hmm, it builds, but I'm having trouble running it still. Now it's just hanging indefinitely. When you say "Just wait on the Sync removal from cln-plugin", does that mean that the code in the I'd like to get started working with the version of |
Can you verify exactly where it's hanging? My PR removing Sync should allow it to work just with client.scan(...).await |
…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.
Hmm no, I cannot determine where it's hanging. For some reason when I include the above workaround in the However, I did finally try @LLFourn's fix of tx_builder with the newly merged upstream PR, and that seems to work great! 🎉 |
@junderw are you in the BDK Discord btw? I'm available anytime to take a closer look if you're up for it, I'd super appreciate it :) |
…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.
Describe the enhancement
Not sure if this is a feature request or a bug. It sounds like BDK v1.0 wants to have good async support, so it seems this would be good to get working before then? But I'll just put it in as a feature request in case not :)
I'm trying to get this CLN plugin repo to build: https://github.com/chrisguida/watchdescriptor/tree/wip/esplora_client
Currently it seems the support for async in BDK is not quite where
cln-plugin
(the official Rust CLN plugin framework) is expecting it to be, as it requires everything to beSend + Sync
.I discussed this with @notmandatory and he says:
Use case
To be able to use BDK inside CLN plugins
I will take this on myself if someone wants to coach me.
The text was updated successfully, but these errors were encountered: