Add light client platform WASM compatible (#1026)

* Cargo update in prep for wasm build

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Add light client test

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Implement low level socket

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Add native platform primitives

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Add wasm platform primitives

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Implement smoldot platform

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust code to use custom platform

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust feature flags

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Adjust wasm endpoint to accept ws for p2p

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust wasm socket

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Book mention of wasm

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* ci: Propagate env variable properly

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Revert to native feature flags

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Use tokio rt-multi-thread feature

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Add tokio feature flags for native platform

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* wasm: Use polkadot live for wasm testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* wasm: Add support for DNS p2p addresses

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* wasm: Disable logs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* wasm: Run wasm test for firefox driver

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* wasm: Reenable chrome driver

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Move lightclient RPC to dedicated crate for better feature flags and modularity

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Use subxt-lightclient low level RPC crate

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Apply cargo fmt

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Enable default:native feature for cargo check

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* ci: Extra step for subxt-lightclient similar to signer crate

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Remove native platform code and use smoldot instead

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Enable tokio/multi-threads

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Refactor modules

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust testing crates

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* ci: Run light-client WASM tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* wasm-rpc: Remove light-client imports

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Update wasm cargo.lock files

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* ci: Spawn substrate node with deterministic p2p address for WASM tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* wasm_socket: Use rc and refcell

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* wasm_socket: Switch back to Arc<Mutex<>>

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Add comments

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2023-07-18 14:27:16 +03:00
committed by GitHub
parent ab2f2a8cdf
commit 4bda673847
28 changed files with 5280 additions and 305 deletions
+7 -15
View File
@@ -23,7 +23,8 @@ default = ["jsonrpsee", "native", "substrate-compat"]
# Exactly 1 of "web" and "native" is expected.
native = [
"jsonrpsee?/async-client",
"jsonrpsee?/client-ws-transport"
"jsonrpsee?/client-ws-transport",
"subxt-lightclient?/native"
]
# Enable this for web/wasm builds.
@@ -31,7 +32,8 @@ native = [
web = [
"jsonrpsee?/async-wasm-client",
"jsonrpsee?/client-web-transport",
"getrandom/js"
"getrandom/js",
"subxt-lightclient?/web"
]
# Enable this to use jsonrpsee (allowing for example `OnlineClient::from_url`).
@@ -56,11 +58,8 @@ unstable-metadata = []
# Activate this to expose the Light Client functionality.
# Note that this feature is experimental and things may break or not work as expected.
unstable-light-client = [
"smoldot-light/std",
"tokio-stream",
"tokio/sync",
"tokio/rt",
"futures-util",
"subxt-lightclient",
"tokio-stream"
]
[dependencies]
@@ -99,12 +98,10 @@ sp-runtime = { workspace = true, optional = true }
# Other subxt crates we depend on.
subxt-macro = { workspace = true }
subxt-metadata = { workspace = true }
subxt-lightclient = { workspace = true, optional = true, default-features = false }
# Light client support:
smoldot-light = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
tokio-stream = { workspace = true, optional = true }
futures-util = { workspace = true, optional = true }
# Included if "web" feature is enabled, to enable its js feature.
getrandom = { workspace = true, optional = true }
@@ -130,8 +127,3 @@ tracing-subscriber = { workspace = true }
name = "unstable_light_client_tx_basic"
path = "examples/unstable_light_client_tx_basic.rs"
required-features = ["unstable-light-client", "jsonrpsee"]
[profile.dev.package.smoldot-light]
opt-level = 2
[profile.test.package.smoldot-light]
opt-level = 2