Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: print hash as an hex string in logs #383

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node/src/tasks/bsp_delete_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions node/src/tasks/bsp_upload_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -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(());
Expand Down Expand Up @@ -636,7 +636,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
);
Expand Down
2 changes: 1 addition & 1 deletion node/src/tasks/mock_bsp_volunteer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
8 changes: 4 additions & 4 deletions node/src/tasks/msp_delete_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

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

Expand Down Expand Up @@ -253,15 +253,15 @@ 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
);

// Only proceed if proof of inclusion was provided, meaning the file was actually deleted from the forest
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(());
Expand Down
6 changes: 3 additions & 3 deletions node/src/tasks/msp_upload_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -938,7 +938,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
Expand Down
10 changes: 5 additions & 5 deletions node/src/tasks/user_sends_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ where
Ok(r) => {
debug!(
target: LOG_TARGET,
"Successfully uploaded batch for file {:?} to peer {:?}",
"Successfully uploaded batch for file fingerprint {:x} to peer {:?}",
file_metadata.fingerprint,
peer_id
);
Expand All @@ -299,7 +299,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,
file_metadata.fingerprint
);
Expand Down Expand Up @@ -388,15 +388,15 @@ 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 {:?}",
file_metadata.fingerprint,
peer_id
);

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,
file_metadata.fingerprint
);
Expand Down Expand Up @@ -433,7 +433,7 @@ where
}
}

info!(target: LOG_TARGET, "Successfully sent file {:?} to peer {:?}", file_metadata.fingerprint, peer_id);
info!(target: LOG_TARGET, "Successfully sent file fingerprint {:x} to peer {:?}", file_metadata.fingerprint, peer_id);
Ok(())
}
}
9 changes: 3 additions & 6 deletions primitives/file-metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -30,16 +31,12 @@ 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",
"shp-traits/std",
"sp-core/std",
"sp-std/std",
]
try-runtime = [
"shp-traits/try-runtime",
]
try-runtime = ["shp-traits/try-runtime"]
17 changes: 17 additions & 0 deletions primitives/file-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// A struct containing all the information about a file in StorageHub.
Expand Down Expand Up @@ -196,6 +197,14 @@ impl<const H_LENGTH: usize> AsRef<[u8; H_LENGTH]> for FileKey<H_LENGTH> {
}
}

impl<const H_LENGTH: usize> fmt::LowerHex for FileKey<H_LENGTH> {
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.
Expand Down Expand Up @@ -262,6 +271,14 @@ impl<const H_LENGTH: usize> AsRef<[u8]> for Fingerprint<H_LENGTH> {
}
}

impl<const H_LENGTH: usize> fmt::LowerHex for Fingerprint<H_LENGTH> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let val = self.0;

write!(f, "0x{}", hex::encode(val))
}
}

/// Typed u64 representing the index of a file [`Chunk`]. Indexed from 0.
#[derive(Debug, Clone, Copy, PartialEq, Eq, TypeInfo, Encode, Decode, Ord, PartialOrd, Hash)]
pub struct ChunkId(u64);
Expand Down
Loading