Skip to content

Commit

Permalink
Merge pull request #2457 from maidsafe/revert-2397-feat-non-blocking-…
Browse files Browse the repository at this point in the history
…self-encrypt-client-api

Revert "feat(autonomi): run self encryption non-blocking"
  • Loading branch information
b-zee authored Nov 20, 2024
2 parents 41739f1 + 10603e6 commit 421c8e6
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 57 deletions.
53 changes: 14 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion autonomi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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"] }
Expand Down
2 changes: 0 additions & 2 deletions autonomi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ RUST_LOG=autonomi EVM_NETWORK=arbitrum-one EVM_PRIVATE_KEY=<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`
Expand Down
4 changes: 2 additions & 2 deletions autonomi/src/client/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Client {
payment_option: PaymentOption,
) -> Result<DataAddr, PutError> {
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:?}");
Expand Down Expand Up @@ -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<AttoTokens, CostError> {
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());

Expand Down
2 changes: 1 addition & 1 deletion autonomi/src/client/data_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Client {
payment_option: PaymentOption,
) -> Result<PrivateDataAccess, PutError> {
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
Expand Down
4 changes: 2 additions & 2 deletions autonomi/src/client/external_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Chunk>), PutError> {
pub fn encrypt_data(data: Bytes) -> Result<(Chunk, Vec<Chunk>), PutError> {
let now = sn_networking::target_arch::Instant::now();
let result = encrypt(data).await?;
let result = encrypt(data)?;

debug!("Encryption took: {:.2?}", now.elapsed());

Expand Down
2 changes: 1 addition & 1 deletion autonomi/src/client/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 2 additions & 8 deletions autonomi/src/self_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)]
Expand All @@ -36,8 +30,8 @@ pub(crate) enum DataMapLevel {
Additional(DataMap),
}

pub(crate) async fn encrypt(data: Bytes) -> Result<(Chunk, Vec<Chunk>), Error> {
let (data_map, chunks) = task::spawn_blocking(move || self_encryption::encrypt(data)).await??;
pub(crate) fn encrypt(data: Bytes) -> Result<(Chunk, Vec<Chunk>), Error> {
let (data_map, chunks) = self_encryption::encrypt(data)?;
let (data_map_chunk, additional_chunks) = pack_data_map(data_map)?;

// Transform `EncryptedChunk` into `Chunk`
Expand Down
2 changes: 1 addition & 1 deletion autonomi/tests/external_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Receipt> {
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];
Expand Down

0 comments on commit 421c8e6

Please sign in to comment.