diff --git a/autonomi/src/client/archive.rs b/autonomi/src/client/archive.rs index 24a8fae99e..59d33c619c 100644 --- a/autonomi/src/client/archive.rs +++ b/autonomi/src/client/archive.rs @@ -93,6 +93,7 @@ impl Archive { .as_secs(); meta.modified = now; self.map.insert(new_path.to_path_buf(), (data_addr, meta)); + debug!("File renamed successfully in the archive"); Ok(()) } @@ -100,6 +101,7 @@ impl 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)); + debug!("Added file successfully to the archive"); } /// List all files in the archive @@ -148,6 +150,7 @@ impl Client { /// Fetch an archive from the network pub async fn archive_get(&self, addr: ArchiveAddr) -> Result { let data = self.data_get(addr).await?; + debug!("Fetched archive from network"); Ok(Archive::from_bytes(data)?) } @@ -160,7 +163,9 @@ 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_archive = self.data_put(bytes, wallet.into()).await; + debug!("Uploaded archive to network"); + result_archive } /// Get the cost to upload an archive @@ -168,6 +173,8 @@ 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_cost = self.data_cost(bytes).await; + debug!("Got cost to upload archive"); + result_cost } } diff --git a/autonomi/src/client/archive_private.rs b/autonomi/src/client/archive_private.rs index 4bcf4c5ca9..a4e43a6d4c 100644 --- a/autonomi/src/client/archive_private.rs +++ b/autonomi/src/client/archive_private.rs @@ -56,6 +56,7 @@ impl PrivateArchive { .as_secs(); meta.modified = now; self.map.insert(new_path.to_path_buf(), (data_addr, meta)); + debug!("File renamed successfully in the archive"); Ok(()) } @@ -63,6 +64,7 @@ impl PrivateArchive { /// 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)); + debug!("Added file successfully to the archive"); } /// List all files in the archive @@ -117,6 +119,7 @@ impl Client { addr: PrivateArchiveAccess, ) -> Result { let data = self.private_data_get(addr).await?; + debug!("Private archive successfully fetched from the network"); Ok(PrivateArchive::from_bytes(data)?) } @@ -129,6 +132,8 @@ 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 private_archive_access_result = self.private_data_put(bytes, payment_option).await; + debug!("Private archive successfully uploaded to the network"); + private_archive_access_result } -} +} \ No newline at end of file diff --git a/autonomi/src/client/data.rs b/autonomi/src/client/data.rs index ec7ebf6d70..79f3a045a0 100644 --- a/autonomi/src/client/data.rs +++ b/autonomi/src/client/data.rs @@ -130,7 +130,7 @@ impl Client { let data = self .fetch_from_data_map_chunk(data_map_chunk.value()) .await?; - + debug!("Successfully fetched a blob of data from the network"); Ok(data) } @@ -176,6 +176,7 @@ impl Client { .await .inspect_err(|err| error!("Error uploading chunk {address:?} :{err:?}")) }); + debug!("Finished preparing upload tasks"); } else { debug!("Chunk at {address:?} was already paid for so skipping"); } @@ -205,6 +206,7 @@ impl Client { record_count, tokens_spent, }; + debug!("Sending upload summary: {:?}", summary); if let Err(err) = channel.send(ClientEvent::UploadComplete(summary)).await { error!("Failed to send client event: {err:?}"); } @@ -218,7 +220,8 @@ impl Client { info!("Getting chunk: {addr:?}"); let key = NetworkAddress::from_chunk_address(ChunkAddress::new(addr)).to_record_key(); - + debug!("Converted chunk address to network record key: {:?}", key); + let get_cfg = GetRecordCfg { get_quorum: Quorum::One, retry_strategy: None, @@ -226,18 +229,22 @@ impl Client { expected_holders: HashSet::new(), is_register: false, }; + debug!("GetRecordCfg created: {:?}", get_cfg); let record = self .network .get_record_from_network(key, &get_cfg) .await .inspect_err(|err| error!("Error fetching chunk: {err:?}"))?; + debug!("Record fetched from network: {:?}", record); let header = RecordHeader::from_record(&record)?; - + debug!("Record header created: {:?}", header); 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()) } } @@ -271,6 +278,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 29925b915b..b237f71009 100644 --- a/autonomi/src/client/data_private.rs +++ b/autonomi/src/client/data_private.rs @@ -55,7 +55,7 @@ impl Client { data_map.0.address() ); let data = self.fetch_from_data_map_chunk(data_map.0.value()).await?; - + debug!("Successfully fetched private data"); Ok(data) } diff --git a/autonomi/src/client/external_signer.rs b/autonomi/src/client/external_signer.rs index 401b6d3151..2e3f265357 100644 --- a/autonomi/src/client/external_signer.rs +++ b/autonomi/src/client/external_signer.rs @@ -29,7 +29,7 @@ impl Client { let cost_map = self.get_store_quotes(content_addrs).await?; let (quote_payments, free_chunks) = extract_quote_payments(&cost_map); let quotes = cost_map_to_quotes(cost_map); - + debug!("Got the quotes for data chunks from the network"); Ok((quotes, quote_payments, free_chunks)) } } diff --git a/autonomi/src/client/fs.rs b/autonomi/src/client/fs.rs index b91efbb865..88ea068eea 100644 --- a/autonomi/src/client/fs.rs +++ b/autonomi/src/client/fs.rs @@ -13,6 +13,7 @@ use crate::client::Client; use bytes::Bytes; use sn_evm::EvmWallet; use sn_networking::target_arch::{Duration, SystemTime}; +// use tracing_subscriber::field::debug; use std::path::PathBuf; use std::sync::LazyLock; @@ -89,8 +90,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 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(()) } @@ -104,6 +107,7 @@ impl Client { for (path, addr, _meta) in archive.iter() { self.file_download(*addr, to_dest.join(path)).await?; } + debug!("Downloaded directory to {to_dest:?}"); Ok(()) } @@ -176,6 +180,7 @@ impl Client { let data = tokio::fs::read(path).await?; let data = Bytes::from(data); let addr = self.data_put(data, wallet.into()).await?; + debug!("Uploaded file successfully"); Ok(addr) } @@ -217,6 +222,7 @@ impl Client { let archive_cost = self.data_cost(Bytes::from(root_serialized)).await?; total_cost += archive_cost.as_atto(); + debug!("Total cost has been computed successfully {:?}", total_cost); Ok(total_cost.into()) } } @@ -240,6 +246,8 @@ pub(crate) fn metadata_from_entry(entry: &walkdir::DirEntry) -> Metadata { } }; + debug!("Processing the metadata for the entry"); + let unix_time = |property: &'static str, time: std::io::Result| { time.inspect_err(|err| { tracing::warn!( @@ -260,7 +268,7 @@ pub(crate) fn metadata_from_entry(entry: &walkdir::DirEntry) -> Metadata { }; let created = unix_time("created", fs_metadata.created()); let modified = unix_time("modified", fs_metadata.modified()); - + debug!("successfully computed the metadata for the entry"); Metadata { uploaded: SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) diff --git a/autonomi/src/client/fs_private.rs b/autonomi/src/client/fs_private.rs index d158916373..5c1c28f599 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 private file to {to_dest:?}"); Ok(()) } @@ -52,6 +54,7 @@ impl Client { self.private_file_download(addr.clone(), to_dest.join(path)) .await?; } + debug!("Downloaded private directory to {to_dest:?}"); Ok(()) } @@ -129,6 +132,7 @@ 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!("Private file uploaded to the network successfully"); Ok(addr) } } diff --git a/autonomi/src/client/mod.rs b/autonomi/src/client/mod.rs index c4a2919347..ca21f0ebca 100644 --- a/autonomi/src/client/mod.rs +++ b/autonomi/src/client/mod.rs @@ -98,7 +98,7 @@ impl Client { let local = !peers.iter().any(multiaddr_is_global); let (network, event_receiver) = build_client_and_run_swarm(local); - + debug!("Client is built and swarm driver initiated"); // Spawn task to dial to the given peers let network_clone = network.clone(); let peers = peers.to_vec(); @@ -115,7 +115,7 @@ impl Client { sn_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, client_event_sender: Arc::new(None), @@ -127,6 +127,7 @@ 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,7 +141,7 @@ fn build_client_and_run_swarm(local: bool) -> (Network, mpsc::Receiver(), ); - + debug!("Register cost is successfully computed"); Ok(total_cost) } @@ -273,8 +273,10 @@ impl Client { let pk = owner.public_key(); let permissions = Permissions::new_with([pk]); - self.register_create_with_permissions(value, name, owner, permissions, wallet) - .await + let register_created = + self.register_create_with_permissions(value, name, owner, permissions, wallet).await; + debug!("Register created successfully"); + register_created } /// Creates a new Register with a name and an initial value and uploads it to the network. diff --git a/autonomi/src/client/utils.rs b/autonomi/src/client/utils.rs index e8e8556820..869ec8987f 100644 --- a/autonomi/src/client/utils.rs +++ b/autonomi/src/client/utils.rs @@ -34,6 +34,7 @@ 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 from data map"); let mut download_tasks = vec![]; for info in data_map.infos() { download_tasks.push(async move { @@ -53,7 +54,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,6 +65,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) } @@ -73,11 +75,12 @@ impl Client { &self, data_map_bytes: &Bytes, ) -> Result { + debug!("Fetching from data map chunk"); let mut data_map_level: DataMapLevel = rmp_serde::from_slice(data_map_bytes) .map_err(GetError::InvalidDataMap) .inspect_err(|err| error!("Error deserializing data map: {err:?}"))?; - loop { + let fetched_data = loop { let data_map = match &data_map_level { DataMapLevel::First(map) => map, DataMapLevel::Additional(map) => map, @@ -95,7 +98,9 @@ impl Client { continue; } }; - } + }; + debug!("Successfully fetched all the data from the data map chunk"); + fetched_data } pub(crate) async fn chunk_upload_with_payment( @@ -153,7 +158,10 @@ impl Client { use_put_record_to: Some(vec![storing_node]), verification, }; - Ok(self.network.put_record(record, &put_cfg).await?) + + let payment_upload = self.network.put_record(record, &put_cfg).await?; + debug!("Chunk successfully uploaded with payment"); + Ok(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 20eb1e1b93..475cd141d1 100644 --- a/autonomi/src/client/vault.rs +++ b/autonomi/src/client/vault.rs @@ -67,6 +67,7 @@ impl Client { let pad = self.get_vault_from_network(secret_key).await?; let data = pad.decrypt_data(secret_key)?; + debug!("Data is successfully fetched and decrypted"); Ok((data, pad.data_encoding())) } @@ -138,6 +139,7 @@ impl Client { return Err(e)?; } }; + debug!("Fetched vault scratchpad successfully"); Ok(pad) } @@ -158,7 +160,7 @@ impl Client { .map(|quote| quote.2.cost.as_atto()) .sum::(), ); - + debug!("Cost for the new vault is successfully computed"); Ok(total_cost) } diff --git a/autonomi/src/client/vault/key.rs b/autonomi/src/client/vault/key.rs index 2cd3f696cd..e0653a6b3a 100644 --- a/autonomi/src/client/vault/key.rs +++ b/autonomi/src/client/vault/key.rs @@ -31,26 +31,32 @@ const VAULT_SECRET_KEY_SEED: &[u8] = b"Massive Array of Internet Disks Secure Ac /// The EVM secret key is used to sign a message and the signature is hashed to derive the vault secret key /// Being able to derive the vault secret key from the EVM secret key allows users to only keep track of one key: the EVM secret key pub fn derive_vault_key(evm_sk_hex: &str) -> Result { + debug!("Attempting to fetch Secret key for the vault"); let signature = sn_evm::cryptography::sign_message(evm_sk_hex, VAULT_SECRET_KEY_SEED) .map_err(VaultKeyError::FailedToSignMessage)?; let blst_key = derive_secret_key_from_seed(&signature)?; let vault_sk = blst_to_blsttc(&blst_key)?; + debug!("Secret key is fetched for the vault"); Ok(vault_sk) } /// Convert a blst secret key to a blsttc secret key and pray that endianness is the same pub(crate) fn blst_to_blsttc(sk: &BlstSecretKey) -> Result { + debug!("Attempting to convert blst secret key to blsttc sk"); let sk_bytes = sk.to_bytes(); let sk = bls::SecretKey::from_bytes(sk_bytes).map_err(VaultKeyError::BlsConversionError)?; + debug!("Conversion to blsttc sk is successful"); Ok(sk) } pub(crate) fn derive_secret_key_from_seed(seed: &[u8]) -> Result { + debug!("Attempting to derive secret key from the seed"); let mut hasher = Sha256::new(); hasher.update(seed); let hashed_seed = hasher.finalize(); let sk = BlstSecretKey::key_gen(&hashed_seed, &[]).map_err(|_| VaultKeyError::KeyGenerationError)?; + debug!("Secret Key is successfully derived from the seed"); Ok(sk) } diff --git a/autonomi/src/client/vault/user_data.rs b/autonomi/src/client/vault/user_data.rs index a0f217bda8..8d4a6940f5 100644 --- a/autonomi/src/client/vault/user_data.rs +++ b/autonomi/src/client/vault/user_data.rs @@ -132,6 +132,8 @@ impl Client { )) })?; + debug!("Got the user data from the vault"); + Ok(vault) } @@ -154,6 +156,7 @@ impl Client { *USER_DATA_VAULT_CONTENT_IDENTIFIER, ) .await?; + debug!("the user data is updated to the vault"); Ok(total_cost) } }