From 30f74312519880354682d34330d6b091572dc03b Mon Sep 17 00:00:00 2001 From: Ermine Jose Date: Sat, 16 Nov 2024 00:08:16 +0530 Subject: [PATCH] feat: add more logs to autonomi --- autonomi/src/client/archive_private.rs | 9 +++++++-- autonomi/src/client/data.rs | 14 +++++++++++--- autonomi/src/client/data_private.rs | 2 +- autonomi/src/client/external_signer.rs | 2 +- autonomi/src/client/fs.rs | 12 ++++++++++-- autonomi/src/client/fs_private.rs | 6 +++++- autonomi/src/client/mod.rs | 5 +++-- autonomi/src/client/vault/key.rs | 6 ++++++ autonomi/src/client/vault/user_data.rs | 3 +++ 9 files changed, 47 insertions(+), 12 deletions(-) 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..e535b619b2 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 } } 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) } }