diff --git a/autonomi/src/client/archive.rs b/autonomi/src/client/archive.rs index 8eb23bb686..b1d256280d 100644 --- a/autonomi/src/client/archive.rs +++ b/autonomi/src/client/archive.rs @@ -93,13 +93,18 @@ impl Archive { .as_secs(); meta.modified = now; self.map.insert(new_path.to_path_buf(), (data_addr, meta)); + debug!( + "Renamed file successfully in the archive, old path: {:?} new_path: {:?}", + old_path, new_path + ); Ok(()) } /// Add a file to a local archive /// Note that this does not upload the archive to the network pub fn add_file(&mut self, path: PathBuf, data_addr: DataAddr, meta: Metadata) { - self.map.insert(path, (data_addr, meta)); + self.map.insert(path.clone(), (data_addr, meta)); + debug!("Added a new file to the archive, path: {:?}", path); } /// List all files in the archive @@ -160,7 +165,12 @@ impl Client { let bytes = archive .into_bytes() .map_err(|e| PutError::Serialization(format!("Failed to serialize archive: {e:?}")))?; - self.data_put(bytes, wallet.into()).await + let result = self.data_put(bytes, wallet.into()).await; + debug!( + "Uploaded archive {:?} to the network and the address is {:?}", + archive, result + ); + result } /// Get the cost to upload an archive @@ -168,6 +178,11 @@ impl Client { let bytes = archive .into_bytes() .map_err(|e| CostError::Serialization(format!("Failed to serialize archive: {e:?}")))?; - self.data_cost(bytes).await + let result = self.data_cost(bytes).await; + debug!( + "Calculated the cost to upload archive {:?} is {:?}", + archive, result + ); + result } } diff --git a/autonomi/src/client/archive_private.rs b/autonomi/src/client/archive_private.rs index 84927c977c..c9a3a38608 100644 --- a/autonomi/src/client/archive_private.rs +++ b/autonomi/src/client/archive_private.rs @@ -56,13 +56,18 @@ impl PrivateArchive { .as_secs(); meta.modified = now; self.map.insert(new_path.to_path_buf(), (data_addr, meta)); + debug!( + "Renamed file successfully in the private archive, old path: {:?} new_path: {:?}", + old_path, new_path + ); Ok(()) } /// Add a file to a local archive /// Note that this does not upload the archive to the network pub fn add_file(&mut self, path: PathBuf, data_map: PrivateDataAccess, meta: Metadata) { - self.map.insert(path, (data_map, meta)); + self.map.insert(path.clone(), (data_map, meta)); + debug!("Added a new file to the archive, path: {:?}", path); } /// List all files in the archive @@ -129,6 +134,11 @@ impl Client { let bytes = archive .into_bytes() .map_err(|e| PutError::Serialization(format!("Failed to serialize archive: {e:?}")))?; - self.private_data_put(bytes, payment_option).await + let result = self.private_data_put(bytes, payment_option).await; + debug!( + "Uploaded private archive {:?} to the network and address is {:?}", + archive, result + ); + result } } diff --git a/autonomi/src/client/data.rs b/autonomi/src/client/data.rs index 113e0511a5..edbebcb095 100644 --- a/autonomi/src/client/data.rs +++ b/autonomi/src/client/data.rs @@ -134,6 +134,7 @@ impl Client { .fetch_from_data_map_chunk(data_map_chunk.value()) .await?; + debug!("Successfully fetched a blob of data from the network"); Ok(data) } @@ -214,7 +215,7 @@ impl Client { info!("Getting chunk: {addr:?}"); let key = NetworkAddress::from_chunk_address(ChunkAddress::new(addr)).to_record_key(); - + debug!("Fetching chunk from network at: {key:?}"); let get_cfg = GetRecordCfg { get_quorum: Quorum::One, retry_strategy: None, @@ -232,8 +233,13 @@ impl Client { if let RecordKind::Chunk = header.kind { let chunk: Chunk = try_deserialize_record(&record)?; + debug!("Chunk deserialized successfully: {:?}", chunk); Ok(chunk) } else { + error!( + "Record kind mismatch: expected Chunk, got {:?}", + header.kind + ); Err(NetworkError::RecordKindMismatch(RecordKind::Chunk).into()) } } @@ -267,6 +273,7 @@ impl Client { .map(|quote| quote.2.cost.as_atto()) .sum::(), ); + debug!("Total cost calculated: {:?}", total_cost); Ok(total_cost) } diff --git a/autonomi/src/client/data_private.rs b/autonomi/src/client/data_private.rs index 5f2dd1793c..d31a13f437 100644 --- a/autonomi/src/client/data_private.rs +++ b/autonomi/src/client/data_private.rs @@ -54,6 +54,7 @@ impl Client { ); let data = self.fetch_from_data_map_chunk(data_map.0.value()).await?; + debug!("Successfully fetched a blob of private data from the network"); Ok(data) } diff --git a/autonomi/src/client/external_signer.rs b/autonomi/src/client/external_signer.rs index 6a4e46d524..4db94d51c5 100644 --- a/autonomi/src/client/external_signer.rs +++ b/autonomi/src/client/external_signer.rs @@ -30,6 +30,10 @@ impl Client { let (quote_payments, free_chunks) = extract_quote_payments(&cost_map); let quotes = cost_map_to_quotes(cost_map); + debug!( + "Got the quotes , quote_payments and freechunks from the network {:?}", + (quotes, quote_payments, free_chunks) + ); Ok((quotes, quote_payments, free_chunks)) } } diff --git a/autonomi/src/client/fs.rs b/autonomi/src/client/fs.rs index 15e32d1bf5..44bb7017dd 100644 --- a/autonomi/src/client/fs.rs +++ b/autonomi/src/client/fs.rs @@ -89,8 +89,10 @@ impl Client { let data = self.data_get(data_addr).await?; if let Some(parent) = to_dest.parent() { tokio::fs::create_dir_all(parent).await?; + debug!("Created parent directories {parent:?} for {to_dest:?}"); } - tokio::fs::write(to_dest, data).await?; + tokio::fs::write(to_dest.clone(), data).await?; + debug!("Downloaded file to {to_dest:?} from the network address {data_addr:?}"); Ok(()) } @@ -101,9 +103,15 @@ impl Client { to_dest: PathBuf, ) -> Result<(), DownloadError> { let archive = self.archive_get(archive_addr).await?; + debug!("Downloaded archive for the directory from the network at {archive_addr:?}"); for (path, addr, _meta) in archive.iter() { self.file_download(*addr, to_dest.join(path)).await?; } + debug!( + "All files in the directory downloaded to {:?} from the network address {:?}", + to_dest.parent(), + archive_addr + ); Ok(()) } @@ -159,6 +167,7 @@ impl Client { info!("Complete archive upload completed in {:?}", start.elapsed()); #[cfg(feature = "loud")] println!("Upload completed in {:?}", start.elapsed()); + debug!("Directory uploaded to the network at {arch_addr:?}"); Ok(arch_addr) } @@ -173,9 +182,10 @@ impl Client { #[cfg(feature = "loud")] println!("Uploading file: {path:?}"); - let data = tokio::fs::read(path).await?; + let data = tokio::fs::read(path.clone()).await?; let data = Bytes::from(data); let addr = self.data_put(data, wallet.into()).await?; + debug!("File {path:?} uploaded to the network at {addr:?}"); Ok(addr) } @@ -217,6 +227,7 @@ impl Client { let archive_cost = self.data_cost(Bytes::from(root_serialized)).await?; total_cost += archive_cost.as_atto(); + debug!("Total cost for the directory: {total_cost:?}"); Ok(total_cost.into()) } } diff --git a/autonomi/src/client/fs_private.rs b/autonomi/src/client/fs_private.rs index 9a49cbd2c1..332981e17d 100644 --- a/autonomi/src/client/fs_private.rs +++ b/autonomi/src/client/fs_private.rs @@ -36,8 +36,10 @@ impl Client { let data = self.private_data_get(data_access).await?; if let Some(parent) = to_dest.parent() { tokio::fs::create_dir_all(parent).await?; + debug!("Created parent directories for {to_dest:?}"); } - tokio::fs::write(to_dest, data).await?; + tokio::fs::write(to_dest.clone(), data).await?; + debug!("Downloaded file to {to_dest:?}"); Ok(()) } @@ -52,6 +54,7 @@ impl Client { self.private_file_download(addr.clone(), to_dest.join(path)) .await?; } + debug!("Downloaded directory to {to_dest:?}"); Ok(()) } @@ -129,6 +132,10 @@ impl Client { let data = tokio::fs::read(path).await?; let data = Bytes::from(data); let addr = self.private_data_put(data, wallet.into()).await?; + debug!( + "Uploaded file successfully in the privateAchive: {:?}", + addr + ); Ok(addr) } } diff --git a/autonomi/src/client/mod.rs b/autonomi/src/client/mod.rs index f039d097a0..dc408e51c1 100644 --- a/autonomi/src/client/mod.rs +++ b/autonomi/src/client/mod.rs @@ -115,6 +115,7 @@ impl Client { ant_networking::target_arch::spawn(handle_event_receiver(event_receiver, sender)); receiver.await.expect("sender should not close")?; + debug!("Client is connected to the network"); Ok(Self { network, @@ -127,6 +128,8 @@ impl Client { let (client_event_sender, client_event_receiver) = tokio::sync::mpsc::channel(CLIENT_EVENT_CHANNEL_SIZE); self.client_event_sender = Arc::new(Some(client_event_sender)); + debug!("All events to the clients are enabled"); + client_event_receiver } } @@ -140,6 +143,7 @@ fn build_client_and_run_swarm(local: bool) -> (Network, mpsc::Receiver { let (receipt, _) = self.pay(content_addrs, &wallet).await?; + debug!( + "Paid for content addresses with wallet and the receipt is {:?}", + receipt + ); Ok(receipt) } PaymentOption::Receipt(receipt) => Ok(receipt), diff --git a/autonomi/src/client/registers.rs b/autonomi/src/client/registers.rs index c405fd6cf7..8a032399a5 100644 --- a/autonomi/src/client/registers.rs +++ b/autonomi/src/client/registers.rs @@ -96,7 +96,11 @@ impl Register { if let Some(value) = initial_value { register.write_atop(&value, &owner)?; } - + debug!( + "Created register {:?} with address: {:?}", + register, + register.address() + ); Ok(register) } @@ -166,10 +170,12 @@ impl Client { } } - Ok(Register { + let register = Register { signed_reg, crdt_reg, - }) + }; + debug!("Fetched register {register:?} from the address: {address} in the network"); + Ok(register) } /// Updates a Register on the network with a new value. This will overwrite existing value(s). @@ -217,7 +223,11 @@ impl Client { register.address() ) })?; - + debug!( + "Updated register {:?} with new value {:?}", + register.address(), + new_value + ); Ok(()) } @@ -244,7 +254,7 @@ impl Client { .map(|quote| quote.2.cost.as_atto()) .sum::(), ); - + debug!("Calculated the cost to create register with name: {name} is {total_cost}"); Ok(total_cost) } diff --git a/autonomi/src/client/utils.rs b/autonomi/src/client/utils.rs index 4962b400eb..06694beb59 100644 --- a/autonomi/src/client/utils.rs +++ b/autonomi/src/client/utils.rs @@ -22,6 +22,7 @@ use futures::stream::{FuturesUnordered, StreamExt}; use libp2p::kad::{Quorum, Record}; use rand::{thread_rng, Rng}; use self_encryption::{decrypt_full_set, DataMap, EncryptedChunk}; +use serde::de; use std::{collections::HashMap, future::Future, num::NonZero}; use xor_name::XorName; @@ -34,6 +35,10 @@ use crate::self_encryption::DataMapLevel; impl Client { /// Fetch and decrypt all chunks in the data map. pub(crate) async fn fetch_from_data_map(&self, data_map: &DataMap) -> Result { + debug!( + "Fetching encrypted data chunks from data map {:?}", + data_map + ); let mut download_tasks = vec![]; for info in data_map.infos() { download_tasks.push(async move { @@ -53,7 +58,7 @@ impl Client { } }); } - + debug!("Successfully fetched all the encrypted chunks"); let encrypted_chunks = process_tasks_with_max_concurrency(download_tasks, *CHUNK_DOWNLOAD_BATCH_SIZE) .await @@ -64,7 +69,7 @@ impl Client { error!("Error decrypting encrypted_chunks: {e:?}"); GetError::Decryption(crate::self_encryption::Error::SelfEncryption(e)) })?; - + debug!("Successfully decrypted all the chunks"); Ok(data) } @@ -153,7 +158,9 @@ impl Client { use_put_record_to: Some(vec![storing_node]), verification, }; - Ok(self.network.put_record(record, &put_cfg).await?) + let payment_upload = Ok(self.network.put_record(record, &put_cfg).await?); + debug!("Successfully stored chunk: {chunk:?} to {:?}", storing_node); + payment_upload } /// Pay for the chunks and get the proof of payment. diff --git a/autonomi/src/client/vault.rs b/autonomi/src/client/vault.rs index baa86ed120..83553e3e16 100644 --- a/autonomi/src/client/vault.rs +++ b/autonomi/src/client/vault.rs @@ -63,10 +63,11 @@ impl Client { &self, secret_key: &VaultSecretKey, ) -> Result<(Bytes, VaultContentType), VaultError> { - info!("Fetching and decrypting vault"); + info!("Fetching and decrypting vault..."); let pad = self.get_vault_from_network(secret_key).await?; let data = pad.decrypt_data(secret_key)?; + debug!("vault data is successfully fetched and decrypted"); Ok((data, pad.data_encoding())) }