From 10603e63b0dc48d9600a255fc8391d1f8549866f Mon Sep 17 00:00:00 2001 From: Mick van Dijke Date: Wed, 20 Nov 2024 13:30:43 +0100 Subject: [PATCH] Revert "feat(autonomi): run self encryption non-blocking" --- Cargo.lock | 53 +++++++------------------- autonomi/Cargo.toml | 1 - autonomi/README.md | 2 - autonomi/src/client/data.rs | 4 +- autonomi/src/client/data_private.rs | 2 +- autonomi/src/client/external_signer.rs | 4 +- autonomi/src/client/fs.rs | 2 +- autonomi/src/self_encryption.rs | 10 +---- autonomi/tests/external_signer.rs | 2 +- 9 files changed, 23 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff1de17dc5..0ff28dc1c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1130,7 +1130,6 @@ dependencies = [ "thiserror", "tiny_http", "tokio", - "tokio_with_wasm", "tracing", "tracing-subscriber", "tracing-web", @@ -4714,9 +4713,9 @@ checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" [[package]] name = "js-sys" -version = "0.3.72" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -9525,30 +9524,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio_with_wasm" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "660450fdbb1f84b197fafe53d64566f2b8b10a972f70b53bd1ba2bafdea6928c" -dependencies = [ - "js-sys", - "tokio", - "tokio_with_wasm_proc", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - -[[package]] -name = "tokio_with_wasm_proc" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a7822b53d3581eebb1c8ad9e8a2647f1ea1bfe0bd5c92983e46e1c0a9a87e" -dependencies = [ - "quote", - "syn 2.0.77", -] - [[package]] name = "toml" version = "0.8.19" @@ -10223,9 +10198,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.95" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", "once_cell", @@ -10234,9 +10209,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.95" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -10249,9 +10224,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.45" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" dependencies = [ "cfg-if", "js-sys", @@ -10261,9 +10236,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.95" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -10271,9 +10246,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.95" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -10284,9 +10259,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.95" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wasm-bindgen-test" diff --git a/autonomi/Cargo.toml b/autonomi/Cargo.toml index b7ab999d9c..27b1439bda 100644 --- a/autonomi/Cargo.toml +++ b/autonomi/Cargo.toml @@ -78,7 +78,6 @@ evmlib = { path = "../evmlib", version = "0.1.4", features = ["wasm-bindgen"] } # See https://github.com/sebcrozet/instant/blob/7bd13f51f5c930239fddc0476a837870fb239ed7/README.md#using-instant-for-a-wasm-platform-where-performancenow-is-not-available instant = { version = "0.1", features = ["wasm-bindgen", "inaccurate"] } js-sys = "0.3.70" -tokio_with_wasm = { version = "0.7.2", features = ["rt"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-web = "0.1.3" xor_name = { version = "5.0.0", features = ["serialize-hex"] } diff --git a/autonomi/README.md b/autonomi/README.md index 0890f8a33f..5a638b136e 100644 --- a/autonomi/README.md +++ b/autonomi/README.md @@ -62,8 +62,6 @@ RUST_LOG=autonomi EVM_NETWORK=arbitrum-one EVM_PRIVATE_KEY= cargo t ### WebAssembly -> Note: compilation requires a nightly Rust compiler which is passed `RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals'` and `-Z build-std=std,panic_abort`. - To run a WASM test - Install `wasm-pack` diff --git a/autonomi/src/client/data.rs b/autonomi/src/client/data.rs index 6c41eff6dd..ec7ebf6d70 100644 --- a/autonomi/src/client/data.rs +++ b/autonomi/src/client/data.rs @@ -143,7 +143,7 @@ impl Client { payment_option: PaymentOption, ) -> Result { let now = sn_networking::target_arch::Instant::now(); - let (data_map_chunk, chunks) = encrypt(data).await?; + let (data_map_chunk, chunks) = encrypt(data)?; let data_map_addr = data_map_chunk.address(); debug!("Encryption took: {:.2?}", now.elapsed()); info!("Uploading datamap chunk to the network at: {data_map_addr:?}"); @@ -245,7 +245,7 @@ impl Client { /// Get the estimated cost of storing a piece of data. pub async fn data_cost(&self, data: Bytes) -> Result { let now = sn_networking::target_arch::Instant::now(); - let (data_map_chunk, chunks) = encrypt(data).await?; + let (data_map_chunk, chunks) = encrypt(data)?; debug!("Encryption took: {:.2?}", now.elapsed()); diff --git a/autonomi/src/client/data_private.rs b/autonomi/src/client/data_private.rs index 353cfa670c..29925b915b 100644 --- a/autonomi/src/client/data_private.rs +++ b/autonomi/src/client/data_private.rs @@ -68,7 +68,7 @@ impl Client { payment_option: PaymentOption, ) -> Result { let now = sn_networking::target_arch::Instant::now(); - let (data_map_chunk, chunks) = encrypt(data).await?; + let (data_map_chunk, chunks) = encrypt(data)?; debug!("Encryption took: {:.2?}", now.elapsed()); // Pay for all chunks diff --git a/autonomi/src/client/external_signer.rs b/autonomi/src/client/external_signer.rs index 7d95ee35b6..401b6d3151 100644 --- a/autonomi/src/client/external_signer.rs +++ b/autonomi/src/client/external_signer.rs @@ -37,9 +37,9 @@ impl Client { /// Encrypts data as chunks. /// /// Returns the data map chunk and file chunks. -pub async fn encrypt_data(data: Bytes) -> Result<(Chunk, Vec), PutError> { +pub fn encrypt_data(data: Bytes) -> Result<(Chunk, Vec), PutError> { let now = sn_networking::target_arch::Instant::now(); - let result = encrypt(data).await?; + let result = encrypt(data)?; debug!("Encryption took: {:.2?}", now.elapsed()); diff --git a/autonomi/src/client/fs.rs b/autonomi/src/client/fs.rs index 0e15d38cd3..b91efbb865 100644 --- a/autonomi/src/client/fs.rs +++ b/autonomi/src/client/fs.rs @@ -204,7 +204,7 @@ impl Client { // re-do encryption to get the correct map xorname here // this code needs refactor let now = sn_networking::target_arch::Instant::now(); - let (data_map_chunk, _) = crate::self_encryption::encrypt(file_bytes).await?; + let (data_map_chunk, _) = crate::self_encryption::encrypt(file_bytes)?; tracing::debug!("Encryption took: {:.2?}", now.elapsed()); let map_xor_name = *data_map_chunk.address().xorname(); diff --git a/autonomi/src/self_encryption.rs b/autonomi/src/self_encryption.rs index db2b3910d2..097dcb69ce 100644 --- a/autonomi/src/self_encryption.rs +++ b/autonomi/src/self_encryption.rs @@ -10,10 +10,6 @@ use bytes::{BufMut, Bytes, BytesMut}; use self_encryption::{DataMap, MAX_CHUNK_SIZE}; use serde::{Deserialize, Serialize}; use sn_protocol::storage::Chunk; -#[cfg(not(target_arch = "wasm32"))] -use tokio::task; -#[cfg(target_arch = "wasm32")] -use tokio_with_wasm::task; use tracing::debug; #[derive(Debug, thiserror::Error)] @@ -22,8 +18,6 @@ pub enum Error { Encoding(#[from] rmp_serde::encode::Error), #[error(transparent)] SelfEncryption(#[from] self_encryption::Error), - #[error(transparent)] - Tokio(#[from] task::JoinError), } #[derive(Serialize, Deserialize)] @@ -36,8 +30,8 @@ pub(crate) enum DataMapLevel { Additional(DataMap), } -pub(crate) async fn encrypt(data: Bytes) -> Result<(Chunk, Vec), Error> { - let (data_map, chunks) = task::spawn_blocking(move || self_encryption::encrypt(data)).await??; +pub(crate) fn encrypt(data: Bytes) -> Result<(Chunk, Vec), Error> { + let (data_map, chunks) = self_encryption::encrypt(data)?; let (data_map_chunk, additional_chunks) = pack_data_map(data_map)?; // Transform `EncryptedChunk` into `Chunk` diff --git a/autonomi/tests/external_signer.rs b/autonomi/tests/external_signer.rs index 2a23102663..89c9cd4d48 100644 --- a/autonomi/tests/external_signer.rs +++ b/autonomi/tests/external_signer.rs @@ -20,7 +20,7 @@ use tokio::time::sleep; use xor_name::XorName; async fn pay_for_data(client: &Client, wallet: &Wallet, data: Bytes) -> eyre::Result { - let (data_map_chunk, chunks) = encrypt_data(data).await?; + let (data_map_chunk, chunks) = encrypt_data(data)?; let map_xor_name = *data_map_chunk.address().xorname(); let mut xor_names = vec![map_xor_name];