embeddable native light-client Rust library
Closed this issue · 7 comments
It'd be useful to have some kind of Rust library in this repo which you can link in, pass a chain-spec and some operating parameters, and get an RPC object back.
Is this something we want in the smoldot repo? Should it live somewhere else?
What architecture would you recommend for this? The bin/wasm-node seems to be a good starting point.
What should its API be?
If you want to integrate a light client into a Rust application, the library you're looking for is smoldot-light-base
: https://github.com/paritytech/smoldot/tree/main/bin/light-base
The most difficult is to implement the Platform
trait found here:
smoldot/bin/light-base/src/lib.rs
Line 91 in 2f1c8e6
I believe that this is the least opinionated API possible. Anything higher level (for example, sockets handled automatically for you) and you might run into "stupid" API-related issues such as creating multiple tokio runtimes.
Not that I'm not sure how easy this trait is to implement on a desktop platform, as I've never tried. I imagine that the fact that it assumes an implicit environment could be problematic, but maybe not that much considering that tokio also assumes an implicit environment as well.
cc #2542
I've had a look at the light-base but it's hardly plug-and-play. I guess I'd be looking for something like a Platform
implementation for a desktop environment which could be combined with the light-base here. Global environment isn't usually my style but I agree it seems fine for the task.
I'd be happy to contribute an example to the repo of implementing the Platform
trait for the desktop environment - would Connection
be a tokio::TcpStream
in that scenario?
Stream
would be a TcpStream
, and Connection
can be anything (!
would be the most appropriate, but since it's not stable you can use ()
). The Future
that connect
returns should always return a PlatformConnection::SingleStream
, and thus no connection is ever instantiated.
I think the best approach is to make the trait as easy to implement as possible, and then have everyone either implement the trait themselves or copy-paste an existing example.
I'd prefer to not add a demo implementation as code in this repo, unless we go for maintaining a proper desktop light client.
Is the platform trait expected to change much in the future? It'd be nice to have more developer resources but we could put something in the substrate.dev site instead.
I'd prefer to not add a demo implementation as code in this repo, unless we go for maintaining a proper desktop light client.
As a potential user of a smoldot desktop light client I do think it's desirable to have something like that, unless you want to implement it in a separate repo (like substrate-connect), but I do think we need something that can be easily plugged into subxt like substrate-connect can be plugged into polkadot.js api