From 1a171471aa5df8bab7fb44e73271828436a72886 Mon Sep 17 00:00:00 2001 From: Mateusz Jasiuk Date: Tue, 4 Jul 2023 15:09:27 +0200 Subject: [PATCH 1/2] fix: namada to compile to wasm32-unknown-unknown --- Cargo.lock | 1 + ethereum_bridge/Cargo.toml | 2 +- shared/Cargo.toml | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index db8c34d0bc..cb5eb37492 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4158,6 +4158,7 @@ dependencies = [ "toml", "tracing 0.1.37", "tracing-subscriber 0.3.16", + "wasm-timer", "wasmer", "wasmer-cache", "wasmer-compiler-singlepass", diff --git a/ethereum_bridge/Cargo.toml b/ethereum_bridge/Cargo.toml index 15463a3265..bf966ccdcc 100644 --- a/ethereum_bridge/Cargo.toml +++ b/ethereum_bridge/Cargo.toml @@ -36,7 +36,7 @@ rand.workspace = true rust_decimal.workspace = true rust_decimal_macros.workspace = true tendermint = {git = "https://github.com/heliaxdev/tendermint-rs.git", rev = "b7d1e5afc6f2ccb3fd1545c2174bab1cc48d7fa7", optional = true} -tendermint-rpc = {git = "https://github.com/heliaxdev/tendermint-rs.git", rev = "b7d1e5afc6f2ccb3fd1545c2174bab1cc48d7fa7", features = ["http-client"], optional = true} +tendermint-rpc = {git = "https://github.com/heliaxdev/tendermint-rs.git", rev = "b7d1e5afc6f2ccb3fd1545c2174bab1cc48d7fa7", default-features = false, features = ["trait-client"], optional = true} tendermint-proto = {git = "https://github.com/heliaxdev/tendermint-rs.git", rev = "b7d1e5afc6f2ccb3fd1545c2174bab1cc48d7fa7", optional = true} tracing = "0.1.30" diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 62b62f9e9c..bb5d37ad6d 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -84,6 +84,7 @@ namada-sdk = [ "masp-tx-gen", "ferveo-tpke", "masp_primitives/transparent-inputs", + "wasm-timer" ] multicore = ["masp_proofs/multicore"] @@ -136,6 +137,7 @@ tiny-hderive.workspace = true tokio.workspace = true toml.workspace = true tracing.workspace = true +wasm-timer = {version = "0.2.5", optional = true} wasmer = {version = "=2.2.0", optional = true} wasmer-cache = {version = "=2.2.0", optional = true} wasmer-compiler-singlepass = {version = "=2.2.0", optional = true} From 4da03ddbaf9d4b5950357efce1fbfe823b5f32fe Mon Sep 17 00:00:00 2001 From: Mateusz Jasiuk Date: Wed, 5 Jul 2023 12:11:33 +0200 Subject: [PATCH 2/2] refactor: replace wasm-timer with wasmtimer to support web worker context --- Cargo.lock | 16 ++++++++- shared/Cargo.toml | 4 +-- shared/src/types/control_flow/time.rs | 12 +++---- wasm/Cargo.lock | 51 ++++++++++++++++++++++++--- 4 files changed, 67 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb5eb37492..d1c56a5b1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4158,7 +4158,6 @@ dependencies = [ "toml", "tracing 0.1.37", "tracing-subscriber 0.3.16", - "wasm-timer", "wasmer", "wasmer-cache", "wasmer-compiler-singlepass", @@ -4166,6 +4165,7 @@ dependencies = [ "wasmer-engine-universal", "wasmer-vm", "wasmparser 0.83.0", + "wasmtimer", "zeroize", ] @@ -8242,6 +8242,20 @@ version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" +[[package]] +name = "wasmtimer" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f656cd8858a5164932d8a90f936700860976ec21eb00e0fe2aa8cab13f6b4cf" +dependencies = [ + "futures", + "js-sys", + "parking_lot 0.12.1", + "pin-utils", + "slab", + "wasm-bindgen", +] + [[package]] name = "wast" version = "49.0.0" diff --git a/shared/Cargo.toml b/shared/Cargo.toml index bb5d37ad6d..8965192870 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -84,7 +84,7 @@ namada-sdk = [ "masp-tx-gen", "ferveo-tpke", "masp_primitives/transparent-inputs", - "wasm-timer" + "wasmtimer" ] multicore = ["masp_proofs/multicore"] @@ -137,7 +137,7 @@ tiny-hderive.workspace = true tokio.workspace = true toml.workspace = true tracing.workspace = true -wasm-timer = {version = "0.2.5", optional = true} +wasmtimer = {version = "0.2.0", optional = true} wasmer = {version = "=2.2.0", optional = true} wasmer-cache = {version = "=2.2.0", optional = true} wasmer-compiler-singlepass = {version = "=2.2.0", optional = true} diff --git a/shared/src/types/control_flow/time.rs b/shared/src/types/control_flow/time.rs index 82c935f48a..95250fa137 100644 --- a/shared/src/types/control_flow/time.rs +++ b/shared/src/types/control_flow/time.rs @@ -334,24 +334,20 @@ mod internal { use std::future::Future; pub use std::time::Duration; - pub use wasm_timer::Instant; - use wasm_timer::{Delay, TryFutureExt}; + pub use wasmtimer::std::Instant; + use wasmtimer::tokio::{sleep, timeout_at}; #[inline] pub(super) async fn internal_timeout_at( deadline: Instant, future: F, ) -> Result { - let run_future = async move { - let value = future.await; - Result::<_, std::io::Error>::Ok(value) - }; - run_future.timeout_at(deadline).await.map_err(|_| ()) + timeout_at(deadline, future).await.map_err(|_| ()) } #[inline] pub(super) async fn internal_sleep(dur: Duration) { - _ = Delay::new(dur).await; + _ = sleep(dur).await; } } diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 8a2fef69e9..cb763d6221 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -2827,7 +2827,7 @@ dependencies = [ "ibc-proto", "ics23", "num-traits", - "parking_lot", + "parking_lot 0.12.1", "primitive-types", "prost", "safe-regex", @@ -3544,7 +3544,7 @@ dependencies = [ "crossbeam-utils 0.8.15", "num_cpus", "once_cell", - "parking_lot", + "parking_lot 0.12.1", "quanta", "rustc_version 0.4.0", "scheduled-thread-pool", @@ -3619,6 +3619,7 @@ dependencies = [ "tokio", "toml 0.5.11", "tracing", + "wasm-timer", "wasmer", "wasmer-cache", "wasmer-compiler-singlepass", @@ -4139,6 +4140,17 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1ad0aff30c1da14b1254fcb2af73e1fa9a28670e584a626f53a369d0e157304" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core 0.8.6", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -4146,7 +4158,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.9.7", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "winapi", ] [[package]] @@ -5217,7 +5243,7 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cbc66816425a074528352f5789333ecff06ca41b36b0b0efdfbb29edc391a19" dependencies = [ - "parking_lot", + "parking_lot 0.12.1", ] [[package]] @@ -6078,7 +6104,7 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot", + "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", "socket2", @@ -6640,6 +6666,21 @@ dependencies = [ "leb128", ] +[[package]] +name = "wasm-timer" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" +dependencies = [ + "futures", + "js-sys", + "parking_lot 0.11.2", + "pin-utils", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "wasmer" version = "2.2.0"