Replies: 5 comments 18 replies
-
I think async traits are entirely unnecessary in the The only one which may need this is |
Beta Was this translation helpful? Give feedback.
-
But the wallet using the bitcoin crate might. What if someone has a wallet that needs to send the data over a socket to some HSM? They need to wait for the HSM response in that case. This is IO. In BitcoinJS we handle this use case by accepting a Something like that would be useful in Rust as well. An abstraction over signing, which PrivateKey and Xpriv would implement. Then, alternatively, an async version that people could choose to implement for their IO based signing setup... Not sure if these kinds of abstractions should be higher up in something like bdk, but since a lot of HSMs are pretty low level and only concern themselves with signing hashes/preimages, it seems like the abstraction should be pretty low. |
Beta Was this translation helpful? Give feedback.
-
Async is an unfinished Rust flavor that is a PITA to use and I'd advise everyone to avoid it as much as they can. If you're interested about what I think about it: you can take a look. There is no way in Rust to be generic over async, so you'll inevitability having to deal with worst of both worlds if you want to support both, which means you'll just support async like most of the ecosystem does already: https://www.reddit.com/r/rust/comments/197811x/the_bane_of_my_existence_supporting_both_async/ IMO rust-bitcoin should avoid it as much as possible by being IO-agnostic. If software needs to read and deserialize in an async context, it should just read into memory first, then deserialize later, or figure out something else (push based encoding). Maybe there's a room for separate crate that does consensus encoding on async io traits (are these even stable thing yet?). |
Beta Was this translation helpful? Give feedback.
-
Whatever async IO is using under the hood, can be done in blocking IO code to enforce a deadline on a timer / select on a flag. It would have been slightly more "manual", but Rust is very good at building abstractions. And even if slightly cumbersome, it would only needed to be used where actually needed, instead of turning the language inside out, breaking composability of the ecosystem and infecting even code that doesn't care about it with all the async complexity. And ... if someone really needs it, they should only do that in async code, in a limited scope. I don't dislike async as much as I dislike how prevalent it became. For decades software of all kinds was built without async and suddenly it's "async, async, async" everywhere. |
Beta Was this translation helpful? Give feedback.
-
idk if we can achieve something without implementing a PoC of this, it is possible to implement the async trait and expose them with a feature flag anyway. The async in rust will be out iirc on 2027 for real usage, there are too many feature that are missing like async drop and |
Beta Was this translation helpful? Give feedback.
-
Starting a discussion on async traits.
Two topics of discussion I'd like to start with:
async_trait
crate acceptable or should we wait until we bump MSRV to >= 1.75?I think for 1 that waiting a few years for MSRV to get high enough is probably desirable.
For 2, I think signing related APIs tend to have use cases for async/await since hardware wallets etc. wait on user input and wallet wait on the hardware wallets.
Beta Was this translation helpful? Give feedback.
All reactions