From 33a6f19d0cf356a2cb3b7007700556618963f3ec Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 18 Oct 2024 14:16:34 +0200 Subject: [PATCH 1/4] chore(deps): replace `instant` with `web-time` Close https://github.com/paritytech/subxt/issues/1597 --- Cargo.lock | 26 ++++++++++++-------------- Cargo.toml | 2 +- lightclient/Cargo.toml | 4 ++-- subxt/Cargo.toml | 3 +-- subxt/src/backend/chain_head/mod.rs | 2 +- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b6987d36c..f5506d5907 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3927,18 +3927,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "integer-sqrt" version = "0.1.5" @@ -10562,7 +10550,6 @@ dependencies = [ "http-body", "hyper", "impl-serde", - "instant", "jsonrpsee", "parity-scale-codec", "polkadot-sdk", @@ -10587,6 +10574,7 @@ dependencies = [ "tracing-subscriber", "url", "wasm-bindgen-futures", + "web-time", ] [[package]] @@ -10677,7 +10665,6 @@ dependencies = [ "futures-timer", "futures-util", "getrandom", - "instant", "js-sys", "pin-project", "send_wrapper 0.6.0", @@ -10692,6 +10679,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "web-time", ] [[package]] @@ -11877,6 +11865,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webpki-roots" version = "0.26.3" diff --git a/Cargo.toml b/Cargo.toml index 2b0f28e765..e4fda4b20f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -133,7 +133,7 @@ send_wrapper = "0.6.0" js-sys = "0.3.70" wasm-bindgen-futures = "0.4.43" futures-timer = "3" -instant = { version = "0.1.13", default-features = false } +web-time = { version = "1.1", default-features = false } tokio-util = "0.7.12" # Substrate crates: diff --git a/lightclient/Cargo.toml b/lightclient/Cargo.toml index 4290b27b1b..7c94b5b2b8 100644 --- a/lightclient/Cargo.toml +++ b/lightclient/Cargo.toml @@ -36,7 +36,7 @@ web = [ # For the light-client platform. "wasm-bindgen-futures", "futures-timer/wasm-bindgen", - "instant/wasm-bindgen", + "web-time", "pin-project", # For websocket. @@ -66,7 +66,7 @@ wasm-bindgen-futures = { workspace = true, optional = true } smoldot = { workspace = true, optional = true } pin-project = { workspace = true, optional = true } futures-timer = { workspace = true, optional = true } -instant = { workspace = true, optional = true } +web-time = { workspace = true, optional = true } getrandom = { workspace = true, optional = true } [package.metadata.docs.rs] diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 61e501b652..949cbb813f 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -42,7 +42,6 @@ web = [ "getrandom/js", "subxt-lightclient?/web", "subxt-macro/web", - "instant/wasm-bindgen", "tokio?/sync", "finito?/wasm-bindgen", ] @@ -99,7 +98,7 @@ thiserror = { workspace = true } tracing = { workspace = true } frame-metadata = { workspace = true } either = { workspace = true } -instant = { workspace = true } +web-time = { workspace = true } # Provides some deserialization, types like U256/H256 and hashing impls like twox/blake256: impl-serde = { workspace = true } diff --git a/subxt/src/backend/chain_head/mod.rs b/subxt/src/backend/chain_head/mod.rs index aacdb452f6..5b6145227a 100644 --- a/subxt/src/backend/chain_head/mod.rs +++ b/subxt/src/backend/chain_head/mod.rs @@ -560,7 +560,7 @@ impl Backend for ChainHeadBackend { let mut finalized_hash: Option = None; // Record the start time so that we can time out if things appear to take too long. - let start_instant = instant::Instant::now(); + let start_instant = web_time::Instant::now(); // A quick helper to return a generic error. let err_other = |s: &str| Some(Err(Error::Other(s.into()))); From 54d2718b396806ef30f853a72e0777ac20f59f48 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 18 Oct 2024 15:51:57 +0200 Subject: [PATCH 2/4] fix build --- lightclient/src/platform/wasm_helpers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightclient/src/platform/wasm_helpers.rs b/lightclient/src/platform/wasm_helpers.rs index a2914c5f72..b4e5608dba 100644 --- a/lightclient/src/platform/wasm_helpers.rs +++ b/lightclient/src/platform/wasm_helpers.rs @@ -21,7 +21,7 @@ pub fn now_from_unix_epoch() -> Duration { pub type Instant = instant::Instant; pub fn now() -> Instant { - instant::Instant::now() + web_time::Instant::now() } pub type Delay = future::BoxFuture<'static, ()>; From 8da6b21feab15c326e0e56aa93c7157ea34411f3 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 18 Oct 2024 16:18:17 +0200 Subject: [PATCH 3/4] fix build v2 --- lightclient/src/platform/wasm_helpers.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lightclient/src/platform/wasm_helpers.rs b/lightclient/src/platform/wasm_helpers.rs index b4e5608dba..a86725459d 100644 --- a/lightclient/src/platform/wasm_helpers.rs +++ b/lightclient/src/platform/wasm_helpers.rs @@ -11,14 +11,14 @@ use core::time::Duration; use futures_util::{future, FutureExt}; pub fn now_from_unix_epoch() -> Duration { - instant::SystemTime::now() - .duration_since(instant::SystemTime::UNIX_EPOCH) + web_time::SystemTime::now() + .duration_since(web_time::SystemTime::UNIX_EPOCH) .unwrap_or_else(|_| { panic!("Invalid systime cannot be configured earlier than `UNIX_EPOCH`") }) } -pub type Instant = instant::Instant; +pub type Instant = web_time::Instant; pub fn now() -> Instant { web_time::Instant::now() @@ -34,7 +34,7 @@ pub fn sleep(duration: Duration) -> Delay { #[pin_project::pin_project] pub struct Stream( #[pin] - pub smoldot::libp2p::with_buffers::WithBuffers< + pub smoldot::libp2p::with_buffers::WithBuffers< future::BoxFuture<'static, Result>, WasmSocket, Instant, From f1fa46c8e74b7cf359c398508e5b77f1c913dc27 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 18 Oct 2024 16:22:53 +0200 Subject: [PATCH 4/4] cargo fmt --- lightclient/src/platform/wasm_helpers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightclient/src/platform/wasm_helpers.rs b/lightclient/src/platform/wasm_helpers.rs index a86725459d..82359a5cff 100644 --- a/lightclient/src/platform/wasm_helpers.rs +++ b/lightclient/src/platform/wasm_helpers.rs @@ -34,7 +34,7 @@ pub fn sleep(duration: Duration) -> Delay { #[pin_project::pin_project] pub struct Stream( #[pin] - pub smoldot::libp2p::with_buffers::WithBuffers< + pub smoldot::libp2p::with_buffers::WithBuffers< future::BoxFuture<'static, Result>, WasmSocket, Instant,