rust-bitcoin / rust-bitcoincore-rpc

Rust RPC client library for the Bitcoin Core JSON-RPC API.
334 stars 247 forks source link

Async version of bitcoincore-rpc #78

Open thomaseizinger opened 5 years ago

thomaseizinger commented 5 years ago

Is there an async version of the library in the planning?

I guess that is blocked by async support in jsonrpc?

stevenroose commented 5 years ago

Is there demand for an async version?

stevenroose commented 5 years ago

I think if we do this, I would like to do it in a way that also supports batching. Like every call returns an object that can have several getters, one for an async execution, a sync execution or being added to a batch.

thomaseizinger commented 5 years ago

Is there demand for an async version?

We would need it :grimacing: It is kind of painful to use a blocking library in a totally async system. The only thing I can think of to do it properly is to have a dedicated execution thread that you communicate with via channels.

Apart from that, most of the Rust ecosystem around networking is already async (tokio, async-std). In addition, async/await is landing on stable for the next release (1.39).

jsonrpc is based on hyper, so it should be fairly trivial to adapt to an async interface. There is also reqwest, a very popular http client library that supports Futures or surf.

thomaseizinger commented 5 years ago

I think if we do this, I would like to do it in a way that also supports batching.

Batching as in, sending the requests at once and wait for all their results? You can join together several futures and then spawn them all at the same time. However, it will still result in several HTTP calls but that is due to the way JsonRPC works and I think you can't get around that.

chris-belcher commented 4 years ago

Is there demand for an async version?

If you're still measuring demand then I need to signal that I would also like an async version.

The async paradigm is really good because it keeps the app responsive and resource-efficent, without damaging the code's readability as with what happens with a select() loop

sgeisler commented 4 years ago

At some point I'll need some form of async support too for a project I'm working on and might just build it then.

TheBlueMatt commented 4 years ago

There's definitely some demand. We have a RPC/REST client that can act as a trivial SPV client at https://github.com/rust-bitcoin/rust-lightning/pull/614/files#diff-386a00d0abcf87d8b4cff018609f2b56 that is all async.

JeremyRubin commented 3 years ago

FWIW I put together a set of crates based on the rust-bitcoin suite that use async:

https://crates.io/crates/bitcoincore-rpc-async https://crates.io/crates/bitcoincore-rpc-json-async https://crates.io/crates/jsonrpc-async

Not heavily tested, but the changes weren't too intense.

stevenroose commented 2 years ago

Please give some feedback on this idea I have, it might be relevant to this discussion: https://github.com/rust-bitcoin/rust-bitcoincore-rpc/pull/212

gd87429 commented 1 year ago

If you're still measuring demand then I need to signal that I would also like an async version.

Same here. Wish this had async support. It's been 3 years since this issue was opened, and I think async is a lot more popular/common in Rust now.