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

[light-client] Wasm compatible light-client #964

Closed
lexnv opened this issue May 18, 2023 · 1 comment · Fixed by #1026
Closed

[light-client] Wasm compatible light-client #964

lexnv opened this issue May 18, 2023 · 1 comment · Fixed by #1026

Comments

@lexnv
Copy link
Collaborator

lexnv commented May 18, 2023

Expose a light client that is wasm compatible to be utilized with subxt.

Smoldot provides an example that interacts with javascript world.
The example relies on the javascript to expose a few core functions (see here).

There are a few ways that this could be approached:

  • smoldot: implement required functions within rust wasm compatible (probably using gloo)
  • smoldot: wasm-compatible bindgens to import js part of the project in rust
  • investigate if using substrate-connect would be a viable / faster option
@tomaka
Copy link

tomaka commented May 25, 2023

smoldot: implement required functions within rust wasm compatible (probably using gloo)

I'm not sure exactly what you mean, but there are two approaches:

Reimplement the Platform trait yourself. You can find the implementation of the Platform trait that the smoldot NPM package uses here, and as you can see it's pretty complicated: https://github.com/smol-dot/smoldot/blob/8f6e978f72714edbd7454ac53f56c1e2cb12572d/wasm-node/rust/src/platform.rs#L51

Reimplement just the JS-side code using the bindings that you linked. You can find the code that the smoldot NPM package uses here: https://github.com/smol-dot/smoldot/blob/8f6e978f72714edbd7454ac53f56c1e2cb12572d/wasm-node/javascript/src/internals/local-instance.ts#L19
Unfortunately, everything related to connections is also pretty complicated because the code is different depending on the platform (NodeJS, Deno, browsers). The browser-specific code, for example, is more than 500 lines of code.

Both the Platform trait and the JS bindings are "stable-ish". They don't change too often, but they might occasionally do.

As a side note, I'm pretty convinced that wasm-bindgen is a bad library. We were initially using wasm-bindgen in an earlier prototype of smoldot, and we ditched it because it caused too many issues w.r.t. bundlers and transcripters and all. Keep in mind that the JavaScript world is a huge shitshow, and sooner or later someone will report a weird issue, and if this issue is caused by the internals of wasm-bindgen (which has a high chance of happening), then you will be stuck.


It seems to me that the best solution is for smoldot to re-export some of the code in its Wasm node, and you import it from subtx. However it's not clear to me what exactly and how to do it.

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 a pull request may close this issue.

3 participants