Skip to content

Commit

Permalink
Document what happens to unusual difficulty values
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Dec 9, 2022
1 parent 851b5b1 commit 36ed685
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions zebra-chain/src/work/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ impl CompactDifficulty {
///
/// Zebra displays difficulties in big-endian byte-order,
/// following the u256 convention set by Bitcoin and zcashd.
///
/// Returns an error if the difficulty value is invalid.
pub fn from_bytes_in_display_order(
bytes_in_display_order: &[u8; 4],
) -> Result<CompactDifficulty, BoxError> {
Expand Down Expand Up @@ -451,6 +453,10 @@ impl ExpandedDifficulty {
///
/// Zebra displays difficulties in big-endian byte-order,
/// following the u256 convention set by Bitcoin and zcashd.
///
/// Preserves the exact difficulty value represented by the bytes,
/// even if it can't be generated from a [`CompactDifficulty`].
/// This means a round-trip conversion to [`CompactDifficulty`] can be lossy.
pub fn from_bytes_in_display_order(bytes_in_display_order: &[u8; 32]) -> ExpandedDifficulty {
let internal_byte_order = U256::from_big_endian(bytes_in_display_order);

Expand Down

0 comments on commit 36ed685

Please sign in to comment.