Skip to content

Commit

Permalink
Debug format GlobalObject.hash as hex
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Sep 11, 2024
1 parent 4ae72b9 commit 7ecd768
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ where
let objects = archived_segment_notification
.archived_segment
.global_object_mappings()
.filter(|object| hashes.remove(&object.hash))
.filter(|object| hashes.remove(&*object.hash))
.collect::<Vec<_>>();

stream::iter(objects)
Expand Down
7 changes: 7 additions & 0 deletions crates/subspace-core-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use alloc::boxed::Box;
use alloc::vec;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::fmt;
use core::num::{NonZeroU64, NonZeroU8};
use core::simd::Simd;
Expand Down Expand Up @@ -112,6 +113,12 @@ impl fmt::Debug for Blake3HashHex {
}
}

impl Borrow<Blake3Hash> for Blake3HashHex {
fn borrow(&self) -> &Blake3Hash {
&self.0
}
}

/// Type of randomness.
#[derive(
Debug,
Expand Down
10 changes: 5 additions & 5 deletions crates/subspace-core-primitives/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub struct PieceObjectMapping {
pub struct GlobalObject {
/// Object hash.
/// We order by hash, so object hash lookups can be performed efficiently.
pub hash: Blake3Hash,
pub hash: Blake3HashHex,
/// Piece index where object is contained (at least its beginning, might not fit fully)
pub piece_index: PieceIndex,
/// Raw record offset of the object in that piece, for use with `Record::to_raw_record_bytes`
Expand All @@ -147,24 +147,24 @@ pub struct GlobalObject {
impl From<CompactGlobalObject> for GlobalObject {
fn from(object: CompactGlobalObject) -> Self {
Self {
hash: *object.0,
hash: object.0,
piece_index: object.1,
offset: object.2,
}
}
}

impl From<GlobalObject> for CompactGlobalObject {
fn from(object: GlobalObject) -> CompactGlobalObject {
Self(object.hash.into(), object.piece_index, object.offset)
fn from(object: GlobalObject) -> Self {
Self(object.hash, object.piece_index, object.offset)
}
}

impl GlobalObject {
/// Returns a newly created GlobalObject from a piece index and object.
pub fn new(piece_index: PieceIndex, piece_object: &PieceObject) -> Self {
Self {
hash: piece_object.hash(),
hash: piece_object.hash().into(),
piece_index,
offset: piece_object.offset(),
}
Expand Down

0 comments on commit 7ecd768

Please sign in to comment.