From ae5c6c1ea62b74bfde4abdc6683b1aab854ea3f2 Mon Sep 17 00:00:00 2001 From: Omer Yacine Date: Thu, 26 Dec 2024 12:29:54 +0200 Subject: [PATCH 1/6] chore(eth-websocket): remove some unnecessary wrappers (#2291) * remove unnecessary Arc< The inners are already `Arc<`ed * eth websocket: avoid locking control message sender and clone it instead * review(sami): move tx declaration close to where it's being used * review(sami): free rx end out of the Arc and arc the entire controller channel instead --- .../eth/web3_transport/websocket_transport.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mm2src/coins/eth/web3_transport/websocket_transport.rs b/mm2src/coins/eth/web3_transport/websocket_transport.rs index 6d19573781..36b13bdb78 100644 --- a/mm2src/coins/eth/web3_transport/websocket_transport.rs +++ b/mm2src/coins/eth/web3_transport/websocket_transport.rs @@ -52,8 +52,8 @@ pub struct WebsocketTransport { #[derive(Debug)] struct ControllerChannel { - tx: Arc>>, - rx: Arc>>, + tx: UnboundedSender, + rx: AsyncMutex>, } enum ControllerMessage { @@ -86,11 +86,10 @@ impl WebsocketTransport { node, event_handlers, request_id: Arc::new(AtomicUsize::new(1)), - controller_channel: ControllerChannel { - tx: Arc::new(AsyncMutex::new(req_tx)), - rx: Arc::new(AsyncMutex::new(req_rx)), - } - .into(), + controller_channel: Arc::new(ControllerChannel { + tx: req_tx, + rx: AsyncMutex::new(req_rx), + }), connection_guard: Arc::new(AsyncMutex::new(())), proxy_sign_keypair: None, last_request_failed: Arc::new(AtomicBool::new(false)), @@ -298,7 +297,7 @@ impl WebsocketTransport { } pub(crate) async fn stop_connection_loop(&self) { - let mut tx = self.controller_channel.tx.lock().await; + let mut tx = self.controller_channel.tx.clone(); tx.send(ControllerMessage::Close) .await .expect("receiver channel must be alive"); @@ -357,12 +356,11 @@ async fn send_request( serialized_request = serde_json::to_string(&wrapper)?; } - let mut tx = transport.controller_channel.tx.lock().await; - let (notification_sender, notification_receiver) = oneshot::channel::>(); event_handlers.on_outgoing_request(&request_bytes); + let mut tx = transport.controller_channel.tx.clone(); tx.send(ControllerMessage::Request(WsRequest { request_id, serialized_request, From 10711a2062efa3513afbfab76dacee233e105e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Thu, 26 Dec 2024 14:14:55 +0300 Subject: [PATCH 2/6] replace broken rpc link (#2305) Signed-off-by: onur-ozkan --- mm2src/coins/tendermint/rpc/tendermint_wasm_rpc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/coins/tendermint/rpc/tendermint_wasm_rpc.rs b/mm2src/coins/tendermint/rpc/tendermint_wasm_rpc.rs index 9224ea997f..4a5d13c05f 100644 --- a/mm2src/coins/tendermint/rpc/tendermint_wasm_rpc.rs +++ b/mm2src/coins/tendermint/rpc/tendermint_wasm_rpc.rs @@ -138,7 +138,7 @@ mod tests { #[wasm_bindgen_test] async fn test_get_abci_info() { - let client = HttpClient::new("https://rpc.sentry-02.theta-testnet.polypore.xyz", None).unwrap(); + let client = HttpClient::new("http://34.80.202.172:26657", None).unwrap(); client.abci_info().await.unwrap(); } } From d90170b1b71fb8a727e8d5c3e67d837ef2470b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Thu, 26 Dec 2024 14:22:30 +0300 Subject: [PATCH 3/6] add `wasm` feature on WASM for timed-map (#2306) Signed-off-by: onur-ozkan --- mm2src/mm2_p2p/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm2src/mm2_p2p/Cargo.toml b/mm2src/mm2_p2p/Cargo.toml index 41a82c3c16..3fc156b6ca 100644 --- a/mm2src/mm2_p2p/Cargo.toml +++ b/mm2src/mm2_p2p/Cargo.toml @@ -46,7 +46,7 @@ tokio = { version = "1.20", default-features = false } futures-rustls = "0.22" instant = { version = "0.1.12", features = ["wasm-bindgen"] } libp2p = { git = "https://github.com/KomodoPlatform/rust-libp2p.git", tag = "k-0.52.11", default-features = false, features = ["identify", "floodsub", "noise", "gossipsub", "ping", "request-response", "secp256k1", "wasm-ext", "wasm-ext-websocket", "macros", "yamux"] } -timed-map = { version = "1.1.1", features = ["rustc-hash"] } +timed-map = { version = "1.1.1", features = ["rustc-hash", "wasm"] } [dev-dependencies] async-std = "1.6.2" From 7464be19ce70abf5c45a0477907ab9bb75e401a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Thu, 26 Dec 2024 19:48:42 +0300 Subject: [PATCH 4/6] chore(CI): unlock wasm-pack version (#2307) * unlock wasm-pack version Signed-off-by: onur-ozkan * force yes on docker build Signed-off-by: onur-ozkan --------- Signed-off-by: onur-ozkan --- .docker/Dockerfile | 3 ++- .github/workflows/dev-build.yml | 3 ++- .github/workflows/release-build.yml | 3 ++- docs/WASM_BUILD.md | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 677d5f8152..467dc4ebc4 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -51,7 +51,8 @@ RUN apt-get install -y \ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile minimal --default-toolchain nightly-2023-06-01 -y ENV PATH="/root/.cargo/bin:$PATH" -RUN cargo install wasm-pack --version 0.10.3 +# TODO: Lock wasm-pack version +RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | bash -s -- -y RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v25.3/protoc-25.3-linux-x86_64.zip RUN unzip protoc-25.3-linux-x86_64.zip && mv ./include/google /usr/include/google diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index ccc959509d..8877bb518f 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -368,7 +368,8 @@ jobs: rustup target add wasm32-unknown-unknown - name: Install wasm-pack - run: CARGO_HOME=/root/.cargo cargo install wasm-pack --version 0.10.3 + # TODO: Lock wasm-pack version + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - name: Calculate commit hash for PR commit if: github.event_name == 'pull_request' diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 9cf66098bb..cae080b3d9 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -334,7 +334,8 @@ jobs: rustup target add wasm32-unknown-unknown - name: Install wasm-pack - run: CARGO_HOME=/root/.cargo cargo install wasm-pack --version 0.10.3 + # TODO: Lock wasm-pack version + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - name: Calculate commit hash for PR commit if: github.event_name == 'pull_request' diff --git a/docs/WASM_BUILD.md b/docs/WASM_BUILD.md index 718b8d5bd1..28355bbf80 100644 --- a/docs/WASM_BUILD.md +++ b/docs/WASM_BUILD.md @@ -21,7 +21,7 @@ To build WASM binary from source, the following prerequisites are required: 1. Install `wasm-pack` ``` - cargo install wasm-pack + curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh ``` 2. OSX specific: install `llvm` ``` From 49f46e075e22c61e370d82ee946ff45b65667510 Mon Sep 17 00:00:00 2001 From: laruh Date: Fri, 27 Dec 2024 10:29:51 +0700 Subject: [PATCH 5/6] review: move SpendTxSearchParams up --- mm2src/coins/eth/eth_swap_v2/mod.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm2src/coins/eth/eth_swap_v2/mod.rs b/mm2src/coins/eth/eth_swap_v2/mod.rs index cb739f5b02..dc199fa5f3 100644 --- a/mm2src/coins/eth/eth_swap_v2/mod.rs +++ b/mm2src/coins/eth/eth_swap_v2/mod.rs @@ -73,6 +73,16 @@ pub(crate) enum PrepareTxDataError { Internal(String), } +pub(crate) struct SpendTxSearchParams<'a> { + pub(crate) swap_contract_address: Address, + pub(crate) event_name: &'a str, + pub(crate) abi_contract: &'a Contract, + pub(crate) swap_id: &'a [u8; 32], + pub(crate) from_block: u64, + pub(crate) wait_until: u64, + pub(crate) check_every: f64, +} + impl EthCoin { /// Retrieves the payment status from a given smart contract address based on the swap ID and state type. pub(crate) async fn payment_status_v2( @@ -216,16 +226,6 @@ impl EthCoin { } } -pub(crate) struct SpendTxSearchParams<'a> { - pub(crate) swap_contract_address: Address, - pub(crate) event_name: &'a str, - pub(crate) abi_contract: &'a Contract, - pub(crate) swap_id: &'a [u8; 32], - pub(crate) from_block: u64, - pub(crate) wait_until: u64, - pub(crate) check_every: f64, -} - pub(crate) fn validate_payment_state( tx: &SignedEthTx, state: U256, From 075c55b61cbd606cdd6b160110eeda8c0fa67e58 Mon Sep 17 00:00:00 2001 From: Alina Sharon <52405288+laruh@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:05:25 +0700 Subject: [PATCH 6/6] update Cargo.lock (#2308) --- Cargo.lock | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 60016ffc57..1e0790f40f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6963,6 +6963,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b102d4d896895d697f1dff4141dff28307532dac57a376b2b5665a55b280dc6" dependencies = [ "rustc-hash", + "web-time", ] [[package]] @@ -7784,6 +7785,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 = "web3" version = "0.19.0"