Skip to content

Commit

Permalink
feat: add more logs to autonomi
Browse files Browse the repository at this point in the history
  • Loading branch information
ermineJose committed Nov 19, 2024
1 parent d0e6faf commit a4214aa
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 24 deletions.
9 changes: 7 additions & 2 deletions autonomi/src/client/archive_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ 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(())
}

/// 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));
debug!("Added file successfully to the archive");
}

/// List all files in the archive
Expand Down Expand Up @@ -117,6 +119,7 @@ impl Client {
addr: PrivateArchiveAccess,
) -> Result<PrivateArchive, GetError> {
let data = self.private_data_get(addr).await?;
debug!("Private archive successfully fetched from the network");
Ok(PrivateArchive::from_bytes(data)?)
}

Expand All @@ -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
}
}
}
14 changes: 11 additions & 3 deletions autonomi/src/client/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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:?}");
}
Expand All @@ -218,26 +220,31 @@ 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,
target_record: None,
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())
}
}
Expand Down Expand Up @@ -271,6 +278,7 @@ impl Client {
.map(|quote| quote.2.cost.as_atto())
.sum::<Amount>(),
);
debug!("Total cost calculated: {:?}", total_cost);
Ok(total_cost)
}
}
2 changes: 1 addition & 1 deletion autonomi/src/client/data_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

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

Expand Down Expand Up @@ -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(())
}

Expand All @@ -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(())
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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())
}
}
Expand All @@ -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<SystemTime>| {
time.inspect_err(|err| {
tracing::warn!(
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion autonomi/src/client/fs_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand All @@ -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(())
}

Expand Down Expand Up @@ -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)
}
}
7 changes: 4 additions & 3 deletions autonomi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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),
Expand All @@ -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
}
}
Expand All @@ -140,7 +141,7 @@ fn build_client_and_run_swarm(local: bool) -> (Network, mpsc::Receiver<NetworkEv
network_builder.build_client().expect("mdns to succeed");

let _swarm_driver = sn_networking::target_arch::spawn(swarm_driver.run());

debug!("Network, event_reciever and swarm driver are built and initiated");
(network, event_receiver)
}

Expand Down
15 changes: 9 additions & 6 deletions autonomi/src/client/registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Register {
if let Some(value) = initial_value {
register.write_atop(&value, &owner)?;
}

debug!("Instantiated a new register");
Ok(register)
}

Expand Down Expand Up @@ -170,7 +170,7 @@ impl Client {
return Err(RegisterError::Write(err));
}
}

debug!("Fetched register from network");
Ok(Register {
signed_reg,
crdt_reg,
Expand Down Expand Up @@ -222,7 +222,7 @@ impl Client {
register.address()
)
})?;

debug!("Register value is updated on the network");
Ok(())
}

Expand All @@ -249,7 +249,7 @@ impl Client {
.map(|quote| quote.2.cost.as_atto())
.sum::<Amount>(),
);

debug!("Register cost is successfully computed");
Ok(total_cost)
}

Expand All @@ -273,8 +273,11 @@ 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.
Expand Down
16 changes: 12 additions & 4 deletions autonomi/src/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bytes, GetError> {
debug!("Fetching from data map");
let mut download_tasks = vec![];
for info in data_map.infos() {
download_tasks.push(async move {
Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -73,11 +75,12 @@ impl Client {
&self,
data_map_bytes: &Bytes,
) -> Result<Bytes, GetError> {
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,
Expand All @@ -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(
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion autonomi/src/client/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}

Expand Down Expand Up @@ -138,6 +139,7 @@ impl Client {
return Err(e)?;
}
};
debug!("Fetched vault scratchpad successfully");

Ok(pad)
}
Expand All @@ -158,7 +160,7 @@ impl Client {
.map(|quote| quote.2.cost.as_atto())
.sum::<Amount>(),
);

debug!("Cost for the new vault is successfully computed");
Ok(total_cost)
}

Expand Down
Loading

0 comments on commit a4214aa

Please sign in to comment.