diff --git a/Cargo.lock b/Cargo.lock index 823f4518b3..d41129d8b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -212,20 +212,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" -[[package]] -name = "async-executor" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" -dependencies = [ - "async-lock", - "async-task", - "concurrent-queue", - "fastrand", - "futures-lite", - "slab", -] - [[package]] name = "async-lock" version = "2.7.0" @@ -235,12 +221,6 @@ dependencies = [ "event-listener", ] -[[package]] -name = "async-task" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" - [[package]] name = "async-trait" version = "0.1.68" @@ -682,15 +662,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" -[[package]] -name = "concurrent-queue" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -1226,15 +1197,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - [[package]] name = "fiat-crypto" version = "0.1.20" @@ -1335,21 +1297,6 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" -[[package]] -name = "futures-lite" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "futures-macro" version = "0.3.28" @@ -1829,6 +1776,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] @@ -2437,12 +2387,6 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1ad0aff30c1da14b1254fcb2af73e1fa9a28670e584a626f53a369d0e157304" -[[package]] -name = "parking" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" - [[package]] name = "parking_lot" version = "0.12.1" @@ -3420,26 +3364,6 @@ dependencies = [ "smoldot", ] -[[package]] -name = "smoldot-light-wasm" -version = "1.0.6" -dependencies = [ - "async-executor", - "async-task", - "event-listener", - "fnv", - "futures-util", - "hashbrown 0.13.2", - "lazy_static", - "log", - "nom", - "pin-project", - "rand 0.8.5", - "slab", - "smoldot", - "smoldot-light", -] - [[package]] name = "snow" version = "0.9.2" @@ -3977,6 +3901,7 @@ dependencies = [ "gloo-net", "hex", "impl-serde", + "instant", "jsonrpsee", "parity-scale-codec", "primitive-types", @@ -3989,7 +3914,6 @@ dependencies = [ "serde_json", "smoldot", "smoldot-light", - "smoldot-light-wasm", "sp-core", "sp-core-hashing", "sp-keyring", @@ -4619,12 +4543,6 @@ dependencies = [ "glob 0.2.11", ] -[[package]] -name = "waker-fn" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" - [[package]] name = "walkdir" version = "2.3.3" diff --git a/Cargo.toml b/Cargo.toml index 4599669ebd..49840b13b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,6 +82,9 @@ futures-timer = { version = "3" } gloo-net = { version = "0.2.6", default-features = false, features = ["json", "websocket"] } futures-executor = { version = "0.3.28", default-features = false } + +instant = { version = "0.1.12", default-features = false } + tokio-stream = "0.1.14" futures-util = "0.3.28" diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 902f0417f3..bcba3af818 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -49,7 +49,7 @@ unstable-light-client = [ # "smoldot-light/std", "smoldot-light", # "futures-executor", - "smoldot-light-wasm", + # "smoldot-light-wasm", "tokio-stream", "tokio/sync", "tokio/rt", @@ -57,7 +57,8 @@ unstable-light-client = [ "wasm-bindgen-futures", "futures-timer/wasm-bindgen", "gloo-net", - "subxt-light-client", + "instant/wasm-bindgen", + # "subxt-light-client", ] [dependencies] @@ -100,7 +101,7 @@ subxt-metadata = { workspace = true } # Light client support: smoldot = { workspace = true, optional = true } smoldot-light = { workspace = true, optional = true } -smoldot-light-wasm = { workspace = true, optional = true } +# smoldot-light-wasm = { workspace = true, optional = true } wasm-bindgen-futures = { workspace = true, optional = true } futures-timer = { workspace = true, optional = true } gloo-net = { workspace = true, optional = true } @@ -111,6 +112,9 @@ tokio = { workspace = true, optional = true } tokio-stream = { workspace = true, optional = true } futures-util = { workspace = true, optional = true } +instant = { workspace = true, optional = true } + + [target.wasm32-unknown-unknown.dependencies] getrandom = { workspace = true, features = ["js"] } diff --git a/subxt/src/lib.rs b/subxt/src/lib.rs index ee7e257c6f..9b20708189 100644 --- a/subxt/src/lib.rs +++ b/subxt/src/lib.rs @@ -27,7 +27,7 @@ while_true, trivial_casts, trivial_numeric_casts, - unused_crate_dependencies, + // unused_crate_dependencies, unused_extern_crates, clippy::all )] diff --git a/subxt/src/rpc/lightclient/client.rs b/subxt/src/rpc/lightclient/client.rs index e098da93e0..782e2535c7 100644 --- a/subxt/src/rpc/lightclient/client.rs +++ b/subxt/src/rpc/lightclient/client.rs @@ -12,7 +12,7 @@ use crate::{ use core::time::Duration; use futures::{lock::Mutex as AsyncMutex, stream::StreamExt, Stream}; -use subxt_light_client as _; +// use subxt_light_client as _; #[cfg(feature = "jsonrpsee-ws")] use jsonrpsee::{ @@ -37,9 +37,8 @@ use std::{ use tokio::sync::{mpsc, oneshot}; use tokio_stream::wrappers::ReceiverStream; -use smoldot_light_wasm::platform::Platform as WasmPlatform; - -// use super::platform::Platform as MyPlatform; +// use smoldot_light_wasm::platform::Platform as WasmPlatform; +use super::platform::Platform as WasmPlatform; const LOG_TARGET: &str = "light-client"; diff --git a/subxt/src/rpc/lightclient/platform.rs b/subxt/src/rpc/lightclient/platform.rs index cd37b48125..d46fe7ae81 100644 --- a/subxt/src/rpc/lightclient/platform.rs +++ b/subxt/src/rpc/lightclient/platform.rs @@ -18,6 +18,14 @@ use std::{ net::{IpAddr, SocketAddr}, }; +use core::{mem, pin, str, task, time::Duration}; +use std::{ + borrow::Cow, + collections::{BTreeMap, VecDeque}, + sync::atomic::{AtomicU64, Ordering}, + time::{Instant, SystemTime, UNIX_EPOCH}, +}; + use tokio::sync::{mpsc, oneshot}; #[derive(Clone)] @@ -35,7 +43,7 @@ impl smoldot_light::platform::PlatformRef for Platform { // No-op yielding. type Yield = future::Ready<()>; - type Instant = std::time::Instant; + type Instant = instant::Instant; type Connection = std::convert::Infallible; @@ -51,22 +59,43 @@ impl smoldot_light::platform::PlatformRef for Platform { type NextSubstreamFuture<'a> = future::Pending>; - fn now_from_unix_epoch(&self) -> std::time::Duration { - std::time::UNIX_EPOCH - .elapsed() - .expect("Invalid systime cannot be configured earlier than `UNIX_EPOCH`") + fn now_from_unix_epoch(&self) -> instant::Duration { + tracing::trace!("[call] now_from_unix_epoch"); + + // The documentation of `now_from_unix_epoch()` mentions that it's ok to panic if we're + // before the UNIX epoch. + + let res = instant::SystemTime::now() + .duration_since(instant::SystemTime::UNIX_EPOCH) + .unwrap_or_else(|_| panic!()); + + // let res = std::time::UNIX_EPOCH + // .elapsed() + // .expect("Invalid systime cannot be configured earlier than `UNIX_EPOCH`"); + tracing::trace!("[response] now_from_unix_epoch={:?}", res); + + res } fn now(&self) -> Self::Instant { - std::time::Instant::now() + // tracing::trace!("[call] now"); + let now = instant::Instant::now(); + // tracing::trace!("[res] now ={:?}", now); + now } - fn sleep(&self, duration: std::time::Duration) -> Self::Delay { - futures_timer::Delay::new(duration).boxed() + fn sleep(&self, duration: Duration) -> Self::Delay { + tracing::trace!("[call] sleep"); + let future = futures_timer::Delay::new(duration).boxed(); + tracing::trace!("[res] sleep"); + future } fn sleep_until(&self, when: Self::Instant) -> Self::Delay { - self.sleep(when.saturating_duration_since(self.now())) + tracing::trace!("[call] sleep_until"); + let res = self.sleep(when.saturating_duration_since(self.now())); + tracing::trace!("[res] sleep_until"); + res } fn spawn_task( @@ -74,7 +103,8 @@ impl smoldot_light::platform::PlatformRef for Platform { task_name: std::borrow::Cow, task: futures_util::future::BoxFuture<'static, ()>, ) { - println!("Spawning {task_name}"); + tracing::trace!("[call] spawn_task task_name={:?}", task_name); + wasm_bindgen_futures::spawn_local(task) } @@ -91,6 +121,8 @@ impl smoldot_light::platform::PlatformRef for Platform { } fn connect(&self, url: &str) -> Self::ConnectFuture { + tracing::trace!("[call] connect url={:?}", url); + let url = url.to_string(); Box::pin(async move { @@ -204,6 +236,8 @@ impl smoldot_light::platform::PlatformRef for Platform { } fn update_stream<'a>(&self, stream: &'a mut Self::Stream) -> Self::StreamUpdateFuture<'a> { + tracing::trace!("[call] update_stream"); + Box::pin(async move {}) } @@ -211,6 +245,8 @@ impl smoldot_light::platform::PlatformRef for Platform { &self, stream: &'a mut Self::Stream, ) -> smoldot_light::platform::ReadBuffer<'a> { + tracing::trace!("[call] read_buffer"); + let mut locked = stream .inner .lock() @@ -239,13 +275,18 @@ impl smoldot_light::platform::PlatformRef for Platform { } } - fn advance_read_cursor(&self, stream: &mut Self::Stream, bytes: usize) {} + fn advance_read_cursor(&self, stream: &mut Self::Stream, bytes: usize) { + tracing::trace!("[call] advance_read_cursor"); + } fn writable_bytes(&self, stream: &mut Self::Stream) -> usize { + tracing::trace!("[call] writable_bytes"); 1024 } fn send(&self, stream: &mut Self::Stream, data: &[u8]) { + tracing::trace!("[call] send"); + let mut locked = stream .inner .lock() @@ -256,7 +297,9 @@ impl smoldot_light::platform::PlatformRef for Platform { } } - fn close_send(&self, stream: &mut Self::Stream) {} + fn close_send(&self, stream: &mut Self::Stream) { + tracing::trace!("[call] close_send"); + } } pub struct ConnectionInner { diff --git a/testing/wasm-tests/Cargo.lock b/testing/wasm-tests/Cargo.lock index 4e389976d7..610564e31a 100644 --- a/testing/wasm-tests/Cargo.lock +++ b/testing/wasm-tests/Cargo.lock @@ -75,20 +75,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -[[package]] -name = "async-executor" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" -dependencies = [ - "async-lock", - "async-task", - "concurrent-queue", - "fastrand", - "futures-lite", - "slab", -] - [[package]] name = "async-lock" version = "2.7.0" @@ -98,12 +84,6 @@ dependencies = [ "event-listener", ] -[[package]] -name = "async-task" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" - [[package]] name = "async-trait" version = "0.1.68" @@ -311,15 +291,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "concurrent-queue" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -613,15 +584,6 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - [[package]] name = "fiat-crypto" version = "0.1.20" @@ -712,21 +674,6 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" -[[package]] -name = "futures-lite" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "futures-macro" version = "0.3.28" @@ -1067,6 +1014,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] @@ -1437,12 +1387,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "parking" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" - [[package]] name = "paste" version = "1.0.12" @@ -2083,26 +2027,6 @@ dependencies = [ "smoldot", ] -[[package]] -name = "smoldot-light-wasm" -version = "1.0.6" -dependencies = [ - "async-executor", - "async-task", - "event-listener", - "fnv", - "futures-util", - "hashbrown 0.13.2", - "lazy_static", - "log", - "nom", - "pin-project", - "rand", - "slab", - "smoldot", - "smoldot-light", -] - [[package]] name = "snow" version = "0.9.2" @@ -2217,6 +2141,7 @@ dependencies = [ "gloo-net", "hex", "impl-serde", + "instant", "jsonrpsee", "parity-scale-codec", "primitive-types", @@ -2229,9 +2154,7 @@ dependencies = [ "serde_json", "smoldot", "smoldot-light", - "smoldot-light-wasm", "sp-core-hashing", - "subxt-light-client", "subxt-macro", "subxt-metadata", "thiserror", @@ -2259,18 +2182,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "subxt-light-client" -version = "0.28.0" -dependencies = [ - "console_error_panic_hook", - "gloo-timers", - "lazy_static", - "tracing", - "tracing-wasm", - "wasm-bindgen", -] - [[package]] name = "subxt-macro" version = "0.28.0" @@ -2564,12 +2475,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "waker-fn" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" - [[package]] name = "want" version = "0.3.0"