diff --git a/Cargo.lock b/Cargo.lock index e35c267dd..458148773 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13994,6 +13994,7 @@ dependencies = [ name = "shp-file-metadata" version = "0.1.0" dependencies = [ + "hex", "num-bigint", "parity-scale-codec", "scale-info", diff --git a/node/src/tasks/bsp_delete_file.rs b/node/src/tasks/bsp_delete_file.rs index 8254f7ee1..83b821e95 100644 --- a/node/src/tasks/bsp_delete_file.rs +++ b/node/src/tasks/bsp_delete_file.rs @@ -74,7 +74,7 @@ where ) -> anyhow::Result<()> { info!( target: LOG_TARGET, - "Deleting file {:?} for BSP {:?}", + "Deleting file {:x} for BSP {:?}", event.file_key, event.bsp_id ); @@ -94,7 +94,7 @@ where { warn!( target: LOG_TARGET, - "FinalisedBspConfirmStoppedStoring applied and finalised for file key {:?}, but file key is still in Forest. This can only happen if the same file key was added again after deleted by this BSP.", + "FinalisedBspConfirmStoppedStoring applied and finalised for file key {:x}, but file key is still in Forest. This can only happen if the same file key was added again after deleted by this BSP.", event.file_key, ); } else { diff --git a/node/src/tasks/bsp_upload_file.rs b/node/src/tasks/bsp_upload_file.rs index a8ea4b4c8..d263bb5d2 100644 --- a/node/src/tasks/bsp_upload_file.rs +++ b/node/src/tasks/bsp_upload_file.rs @@ -113,9 +113,9 @@ where async fn handle_event(&mut self, event: NewStorageRequest) -> anyhow::Result<()> { info!( target: LOG_TARGET, - "Initiating BSP volunteer for file_key {:?}, location {:?}, fingerprint {:?}", + "Initiating BSP volunteer for file_key {:x}, location 0x{}, fingerprint {:x}", event.file_key, - event.location, + hex::encode(event.location.as_slice()), event.fingerprint ); @@ -419,7 +419,7 @@ where if fs.read().await.contains_file_key(&event.file_key.into())? { info!( target: LOG_TARGET, - "Skipping file key {:?} NewStorageRequest because we are already storing it.", + "Skipping file key {:x} NewStorageRequest because we are already storing it.", event.file_key ); return Ok(()); @@ -637,7 +637,7 @@ where info!( target: LOG_TARGET, - "Waiting for tick {:?} to volunteer for file {:?}", + "Waiting for tick {:?} to volunteer for file {:x}", earliest_volunteer_tick, file_key ); diff --git a/node/src/tasks/mock_bsp_volunteer.rs b/node/src/tasks/mock_bsp_volunteer.rs index e581bd84c..813d53d91 100644 --- a/node/src/tasks/mock_bsp_volunteer.rs +++ b/node/src/tasks/mock_bsp_volunteer.rs @@ -55,7 +55,7 @@ where async fn handle_event(&mut self, event: NewStorageRequest) -> anyhow::Result<()> { info!( target: LOG_TARGET, - "Initiating BSP volunteer mock for file key: {:?}", + "Initiating BSP volunteer mock for file key: {:x}", event.file_key ); diff --git a/node/src/tasks/msp_delete_file.rs b/node/src/tasks/msp_delete_file.rs index ab1403b6d..2a9211d88 100644 --- a/node/src/tasks/msp_delete_file.rs +++ b/node/src/tasks/msp_delete_file.rs @@ -78,7 +78,7 @@ where async fn handle_event(&mut self, event: FileDeletionRequest) -> anyhow::Result<()> { info!( target: LOG_TARGET, - "Queueing file deletion request for file_key {:?}", + "Queueing file deletion request for file_key {:x}", event.file_key ); @@ -225,7 +225,7 @@ where info!( target: LOG_TARGET, - "Successfully processed file deletion request for file_key {:?}", + "Successfully processed file deletion request for file_key {:x}", delete_file_request.file_key ); @@ -253,7 +253,7 @@ where ) -> anyhow::Result<()> { info!( target: LOG_TARGET, - "Processing finalized file deletion request for file_key {:?}", + "Processing finalized file deletion request for file_key {:x}", event.file_key ); @@ -261,7 +261,7 @@ where if !event.proof_of_inclusion { info!( target: LOG_TARGET, - "Skipping file deletion as no proof of inclusion was provided for file_key {:?}", + "Skipping file deletion as no proof of inclusion was provided for file_key {:x}", event.file_key ); return Ok(()); diff --git a/node/src/tasks/msp_upload_file.rs b/node/src/tasks/msp_upload_file.rs index 68b973e50..c8b7726bd 100644 --- a/node/src/tasks/msp_upload_file.rs +++ b/node/src/tasks/msp_upload_file.rs @@ -108,9 +108,9 @@ where async fn handle_event(&mut self, event: NewStorageRequest) -> anyhow::Result<()> { info!( target: LOG_TARGET, - "Registering user peer for file_key {:?}, location {:?}, fingerprint {:?}", + "Registering user peer for file_key {:x}, location 0x{}, fingerprint {:x}", event.file_key, - event.location, + hex::encode(event.location.as_slice()), event.fingerprint ); @@ -939,7 +939,7 @@ where } async fn on_file_complete(&self, file_key: &H256) -> anyhow::Result<()> { - info!(target: LOG_TARGET, "File upload complete ({:?})", file_key); + info!(target: LOG_TARGET, "File upload complete (file_key {:x})", file_key); // Unregister the file from the file transfer service. self.storage_hub_handler diff --git a/node/src/tasks/user_sends_file.rs b/node/src/tasks/user_sends_file.rs index bd0cc6f1a..892f1dd62 100644 --- a/node/src/tasks/user_sends_file.rs +++ b/node/src/tasks/user_sends_file.rs @@ -294,7 +294,7 @@ where Ok(r) => { debug!( target: LOG_TARGET, - "Successfully uploaded batch for file {:?} to peer {:?}", + "Successfully uploaded batch for file fingerprint {:x} to peer {:?}", fingerprint, peer_id ); @@ -303,7 +303,7 @@ where if r.file_complete { info!( target: LOG_TARGET, - "Stopping file upload process. Peer {:?} has the entire file {:?}", + "Stopping file upload process. Peer {:?} has the entire file fingerprint {:x}", peer_id, fingerprint ); @@ -392,7 +392,7 @@ where Ok(r) => { debug!( target: LOG_TARGET, - "Successfully uploaded final batch for file {:?} to peer {:?}", + "Successfully uploaded final batch for file fingerprint {:x} to peer {:?}", fingerprint, peer_id ); @@ -400,7 +400,7 @@ where if r.file_complete { info!( target: LOG_TARGET, - "File upload complete. Peer {:?} has the entire file {:?}", + "File upload complete. Peer {:?} has the entire file fingerprint {:x}", peer_id, fingerprint ); @@ -437,7 +437,7 @@ where } } - info!(target: LOG_TARGET, "Successfully sent file {:?} to peer {:?}", fingerprint, peer_id); + info!(target: LOG_TARGET, "Successfully sent file fingerprint {:x} to peer {:?}", fingerprint, peer_id); Ok(()) } } diff --git a/primitives/file-metadata/Cargo.toml b/primitives/file-metadata/Cargo.toml index 536c757c9..2df0be6f0 100644 --- a/primitives/file-metadata/Cargo.toml +++ b/primitives/file-metadata/Cargo.toml @@ -16,6 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { workspace = true } +hex = { workspace = true } num-bigint = { workspace = true } scale-info = { workspace = true } serde = { workspace = true } @@ -30,9 +31,7 @@ sp-arithmetic = { workspace = true } [features] default = ["std"] -runtime-benchmarks = [ - "shp-traits/runtime-benchmarks", -] +runtime-benchmarks = ["shp-traits/runtime-benchmarks"] std = [ "codec/std", "scale-info/std", @@ -40,6 +39,4 @@ std = [ "sp-core/std", "sp-std/std", ] -try-runtime = [ - "shp-traits/try-runtime", -] +try-runtime = ["shp-traits/try-runtime"] diff --git a/primitives/file-metadata/src/lib.rs b/primitives/file-metadata/src/lib.rs index f23d7543e..f62c10271 100644 --- a/primitives/file-metadata/src/lib.rs +++ b/primitives/file-metadata/src/lib.rs @@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize}; use shp_traits::{AsCompact, FileMetadataInterface}; use sp_arithmetic::traits::SaturatedConversion; use sp_core::{crypto::AccountId32, H256}; +use sp_std::fmt; use sp_std::vec::Vec; /// Maximum number of chunks a Storage Provider would need to prove for a file. @@ -247,6 +248,14 @@ impl AsRef<[u8; H_LENGTH]> for FileKey { } } +impl fmt::LowerHex for FileKey { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let val = self.0; + + write!(f, "0x{}", hex::encode(val)) + } +} + /// A fingerprint is something that uniquely identifies the content of a file. /// In the context of this crate, a fingerprint is the root hash of a Merkle Patricia Trie /// of the merklised file. @@ -313,6 +322,14 @@ impl AsRef<[u8]> for Fingerprint { } } +impl fmt::LowerHex for Fingerprint { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let val = self.0; + + write!(f, "0x{}", hex::encode(val)) + } +} + impl PartialEq<[u8]> for Fingerprint { fn eq(&self, other: &[u8]) -> bool { self.0 == other