diff --git a/crates/subspace-core-primitives/src/lib.rs b/crates/subspace-core-primitives/src/lib.rs index fa84ccadc6..0b9d0eb7ea 100644 --- a/crates/subspace-core-primitives/src/lib.rs +++ b/crates/subspace-core-primitives/src/lib.rs @@ -59,22 +59,16 @@ pub const REWARD_SIGNING_CONTEXT: &[u8] = b"subspace_reward"; /// Type of randomness. #[derive( - Debug, - Default, - Copy, - Clone, - Eq, - PartialEq, - From, - Into, - Deref, - Encode, - Decode, - TypeInfo, - MaxEncodedLen, + Default, Copy, Clone, Eq, PartialEq, From, Into, Deref, Encode, Decode, TypeInfo, MaxEncodedLen, )] pub struct Randomness([u8; Randomness::SIZE]); +impl fmt::Debug for Randomness { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)] @@ -156,7 +150,6 @@ pub type BlockWeight = u128; /// A Ristretto Schnorr public key as bytes produced by `schnorrkel` crate. #[derive( - Debug, Default, Copy, Clone, @@ -174,6 +167,12 @@ pub type BlockWeight = u128; )] pub struct PublicKey([u8; PublicKey::SIZE]); +impl fmt::Debug for PublicKey { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)] @@ -239,7 +238,6 @@ impl PublicKey { /// Single BLS12-381 scalar with big-endian representation, not guaranteed to be valid #[derive( - Debug, Default, Copy, Clone, @@ -262,6 +260,12 @@ impl PublicKey { #[cfg_attr(feature = "serde", serde(transparent))] pub struct ScalarBytes([u8; ScalarBytes::FULL_BYTES]); +impl fmt::Debug for ScalarBytes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + impl ScalarBytes { /// How many full bytes can be stored in BLS12-381 scalar (for instance before encoding). It is /// actually 254 bits, but bits are mut harder to work with and likely not worth it. diff --git a/crates/subspace-core-primitives/src/pieces.rs b/crates/subspace-core-primitives/src/pieces.rs index 5f2f6eb91d..e22a9349d2 100644 --- a/crates/subspace-core-primitives/src/pieces.rs +++ b/crates/subspace-core-primitives/src/pieces.rs @@ -252,10 +252,16 @@ impl PieceOffset { /// Raw record contained within recorded history segment before archiving is applied. /// /// NOTE: This is a stack-allocated data structure and can cause stack overflow! -#[derive(Debug, Copy, Clone, Eq, PartialEq, Deref, DerefMut)] +#[derive(Copy, Clone, Eq, PartialEq, Deref, DerefMut)] #[repr(transparent)] pub struct RawRecord([[u8; ScalarBytes::SAFE_BYTES]; Self::NUM_CHUNKS]); +impl fmt::Debug for RawRecord { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0.as_flattened())) + } +} + impl Default for RawRecord { #[inline] fn default() -> Self { @@ -407,10 +413,16 @@ impl RawRecord { /// Record contained within a piece. /// /// NOTE: This is a stack-allocated data structure and can cause stack overflow! -#[derive(Debug, Copy, Clone, Eq, PartialEq, Deref, DerefMut)] +#[derive(Copy, Clone, Eq, PartialEq, Deref, DerefMut)] #[repr(transparent)] pub struct Record([[u8; ScalarBytes::FULL_BYTES]; Self::NUM_CHUNKS]); +impl fmt::Debug for Record { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0.as_flattened())) + } +} + impl Default for Record { #[inline] fn default() -> Self { @@ -601,7 +613,6 @@ impl Record { /// Record commitment contained within a piece. #[derive( - Debug, Copy, Clone, Eq, @@ -618,6 +629,12 @@ impl Record { )] pub struct RecordCommitment([u8; RecordCommitment::SIZE]); +impl fmt::Debug for RecordCommitment { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)] @@ -731,7 +748,6 @@ impl RecordCommitment { /// Record witness contained within a piece. #[derive( - Debug, Copy, Clone, Eq, @@ -748,6 +764,12 @@ impl RecordCommitment { )] pub struct RecordWitness([u8; RecordWitness::SIZE]); +impl fmt::Debug for RecordWitness { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)] @@ -859,12 +881,17 @@ impl RecordWitness { pub const SIZE: usize = 48; } -#[derive(Debug)] enum CowBytes { Shared(Bytes), Owned(BytesMut), } +impl fmt::Debug for CowBytes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.as_ref())) + } +} + impl PartialEq for CowBytes { fn eq(&self, other: &Self) -> bool { self.as_ref().eq(other.as_ref()) @@ -1162,12 +1189,16 @@ impl Piece { /// Internally piece contains a record and corresponding witness that together with segment /// commitment of the segment this piece belongs to can be used to verify that a piece belongs to /// the actual archival history of the blockchain. -#[derive( - Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deref, DerefMut, AsRef, AsMut, -)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deref, DerefMut, AsRef, AsMut)] #[repr(transparent)] pub struct PieceArray([u8; Piece::SIZE]); +impl fmt::Debug for PieceArray { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + impl Default for PieceArray { #[inline] fn default() -> Self { diff --git a/crates/subspace-core-primitives/src/pos.rs b/crates/subspace-core-primitives/src/pos.rs index 691003ede8..e7b9567ecb 100644 --- a/crates/subspace-core-primitives/src/pos.rs +++ b/crates/subspace-core-primitives/src/pos.rs @@ -1,6 +1,7 @@ //! Proof of space-related data structures. use crate::hashes::{blake3_hash, Blake3Hash}; +use core::fmt; use derive_more::{Deref, DerefMut, From, Into}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; @@ -12,9 +13,15 @@ use serde::{Deserializer, Serializer}; use serde_big_array::BigArray; /// Proof of space seed. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Deref, From, Into)] +#[derive(Copy, Clone, Eq, PartialEq, Deref, From, Into)] pub struct PosSeed([u8; PosSeed::SIZE]); +impl fmt::Debug for PosSeed { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + impl PosSeed { /// Size of proof of space seed in bytes. pub const SIZE: usize = 32; @@ -22,22 +29,16 @@ impl PosSeed { /// Proof of space proof bytes. #[derive( - Debug, - Copy, - Clone, - Eq, - PartialEq, - Deref, - DerefMut, - From, - Into, - Encode, - Decode, - TypeInfo, - MaxEncodedLen, + Copy, Clone, Eq, PartialEq, Deref, DerefMut, From, Into, Encode, Decode, TypeInfo, MaxEncodedLen, )] pub struct PosProof([u8; PosProof::SIZE]); +impl fmt::Debug for PosProof { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)] diff --git a/crates/subspace-core-primitives/src/pot.rs b/crates/subspace-core-primitives/src/pot.rs index cdbe703d4b..c6020d66b4 100644 --- a/crates/subspace-core-primitives/src/pot.rs +++ b/crates/subspace-core-primitives/src/pot.rs @@ -15,7 +15,6 @@ use serde::{Deserializer, Serializer}; /// Proof of time key(input to the encryption). #[derive( - Debug, Default, Copy, Clone, @@ -33,6 +32,12 @@ use serde::{Deserializer, Serializer}; )] pub struct PotKey([u8; Self::SIZE]); +impl fmt::Debug for PotKey { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)] @@ -98,7 +103,6 @@ impl PotKey { /// Proof of time seed #[derive( - Debug, Default, Copy, Clone, @@ -117,6 +121,12 @@ impl PotKey { )] pub struct PotSeed([u8; Self::SIZE]); +impl fmt::Debug for PotSeed { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)] @@ -187,7 +197,6 @@ impl PotSeed { /// Proof of time output, can be intermediate checkpoint or final slot output #[derive( - Debug, Default, Copy, Clone, @@ -206,6 +215,12 @@ impl PotSeed { )] pub struct PotOutput([u8; Self::SIZE]); +impl fmt::Debug for PotOutput { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)] diff --git a/crates/subspace-core-primitives/src/segments.rs b/crates/subspace-core-primitives/src/segments.rs index c259b59ad9..274a4d587c 100644 --- a/crates/subspace-core-primitives/src/segments.rs +++ b/crates/subspace-core-primitives/src/segments.rs @@ -9,6 +9,7 @@ use crate::BlockNumber; #[cfg(not(feature = "std"))] use alloc::boxed::Box; use core::array::TryFromSliceError; +use core::fmt; use core::iter::Step; use core::num::NonZeroU64; use derive_more::{ @@ -134,7 +135,6 @@ impl SegmentIndex { /// Segment commitment contained within segment header. #[derive( - Debug, Copy, Clone, Eq, @@ -152,6 +152,12 @@ impl SegmentIndex { #[repr(transparent)] pub struct SegmentCommitment([u8; SegmentCommitment::SIZE]); +impl fmt::Debug for SegmentCommitment { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)] @@ -422,10 +428,17 @@ impl SegmentHeader { /// Recorded history segment before archiving is applied. /// /// NOTE: This is a stack-allocated data structure and can cause stack overflow! -#[derive(Debug, Copy, Clone, Eq, PartialEq, Deref, DerefMut)] +#[derive(Copy, Clone, Eq, PartialEq, Deref, DerefMut)] #[repr(transparent)] pub struct RecordedHistorySegment([RawRecord; Self::NUM_RAW_RECORDS]); +impl fmt::Debug for RecordedHistorySegment { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RecordedHistorySegment") + .finish_non_exhaustive() + } +} + impl Default for RecordedHistorySegment { #[inline] fn default() -> Self { diff --git a/crates/subspace-core-primitives/src/solutions.rs b/crates/subspace-core-primitives/src/solutions.rs index 21d4a8465e..aac35f5a4d 100644 --- a/crates/subspace-core-primitives/src/solutions.rs +++ b/crates/subspace-core-primitives/src/solutions.rs @@ -6,6 +6,7 @@ use crate::sectors::SectorIndex; use crate::segments::{HistorySize, SegmentIndex}; use crate::{PublicKey, ScalarBytes}; use core::array::TryFromSliceError; +use core::fmt; use derive_more::{AsMut, AsRef, Deref, DerefMut, From, Into}; use num_traits::WrappingSub; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; @@ -64,23 +65,16 @@ const_assert!(solution_range_to_pieces(pieces_to_solution_range(5, (1, 6)), (1, /// A Ristretto Schnorr signature as bytes produced by `schnorrkel` crate. #[derive( - Debug, - Copy, - Clone, - PartialEq, - Eq, - Ord, - PartialOrd, - Hash, - Encode, - Decode, - TypeInfo, - Deref, - From, - Into, + Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Encode, Decode, TypeInfo, Deref, From, Into, )] pub struct RewardSignature([u8; RewardSignature::SIZE]); +impl fmt::Debug for RewardSignature { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)] @@ -135,7 +129,6 @@ impl RewardSignature { /// Witness for chunk contained within a record. #[derive( - Debug, Copy, Clone, Eq, @@ -153,6 +146,12 @@ impl RewardSignature { #[repr(transparent)] pub struct ChunkWitness([u8; ChunkWitness::SIZE]); +impl fmt::Debug for ChunkWitness { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + #[cfg(feature = "serde")] #[derive(Serialize, Deserialize)] #[serde(transparent)]