From fa4d3d4417f8d4e32be1b3b9c7f0b077aa5730f0 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 20 May 2024 08:56:44 +1000 Subject: [PATCH 1/2] Add whitespace The formatter lines up comments if they are on consecutive lines even if the second is supposed to be at the start of the collum and the first is after code. Putting a line of whitespace between the two lines stops this from happening. Add whitespace to stop the formatter doing silly changes. Whitespace only. --- bitcoin/src/pow.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index c4c09fb15..b82c6fe56 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -1795,6 +1795,7 @@ mod tests { use hashes::Hash; let params = Params::new(crate::Network::Signet); let epoch_start = genesis_block(¶ms).header; + // Block 2015, the only information used are `bits` and `time` let current = Header { version: Version::ONE, @@ -1815,6 +1816,7 @@ mod tests { use hashes::Hash; let params = Params::new(crate::Network::Signet); let starting_bits = CompactTarget::from_consensus(503394215); // Block 2016 compact target + // Block 2016, the only information used is `time` let epoch_start = Header { version: Version::ONE, @@ -1824,6 +1826,7 @@ mod tests { bits: starting_bits, nonce: 0 }; + // Block 4031, the only information used are `bits` and `time` let current = Header { version: Version::ONE, From f6129317bde3a1307c0b2eb5c192effad030398e Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 20 May 2024 08:58:48 +1000 Subject: [PATCH 2/2] Run the formatter Run `just fmt`, no other changes. --- bitcoin/src/pow.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index b82c6fe56..8f693c0b7 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -1791,8 +1791,11 @@ mod tests { #[test] fn compact_target_from_upwards_difficulty_adjustment_using_headers() { - use crate::{block::Version, constants::genesis_block, TxMerkleNode}; use hashes::Hash; + + use crate::block::Version; + use crate::constants::genesis_block; + use crate::TxMerkleNode; let params = Params::new(crate::Network::Signet); let epoch_start = genesis_block(¶ms).header; @@ -1803,17 +1806,20 @@ mod tests { merkle_root: TxMerkleNode::all_zeros(), time: 1599332177, bits: epoch_start.bits, - nonce: epoch_start.nonce + nonce: epoch_start.nonce, }; - let adjustment = CompactTarget::from_header_difficulty_adjustment(epoch_start, current, params); + let adjustment = + CompactTarget::from_header_difficulty_adjustment(epoch_start, current, params); let adjustment_bits = CompactTarget::from_consensus(503394215); // Block 2016 compact target assert_eq!(adjustment, adjustment_bits); } #[test] fn compact_target_from_downwards_difficulty_adjustment_using_headers() { - use crate::{block::Version, TxMerkleNode}; use hashes::Hash; + + use crate::block::Version; + use crate::TxMerkleNode; let params = Params::new(crate::Network::Signet); let starting_bits = CompactTarget::from_consensus(503394215); // Block 2016 compact target @@ -1824,7 +1830,7 @@ mod tests { merkle_root: TxMerkleNode::all_zeros(), time: 1599332844, bits: starting_bits, - nonce: 0 + nonce: 0, }; // Block 4031, the only information used are `bits` and `time` @@ -1834,9 +1840,10 @@ mod tests { merkle_root: TxMerkleNode::all_zeros(), time: 1600591200, bits: starting_bits, - nonce: 0 + nonce: 0, }; - let adjustment = CompactTarget::from_header_difficulty_adjustment(epoch_start, current, params); + let adjustment = + CompactTarget::from_header_difficulty_adjustment(epoch_start, current, params); let adjustment_bits = CompactTarget::from_consensus(503397348); // Block 4032 compact target assert_eq!(adjustment, adjustment_bits); } @@ -1847,9 +1854,8 @@ mod tests { let starting_bits = CompactTarget::from_consensus(503403001); let timespan = (0.2 * params.pow_target_timespan as f64) as u64; let got = CompactTarget::from_next_work_required(starting_bits, timespan, params); - let want = Target::from_compact(starting_bits) - .min_transition_threshold() - .to_compact_lossy(); + let want = + Target::from_compact(starting_bits).min_transition_threshold().to_compact_lossy(); assert_eq!(got, want); } @@ -1857,11 +1863,10 @@ mod tests { fn compact_target_from_minimum_downward_difficulty_adjustment() { let params = Params::new(crate::Network::Signet); let starting_bits = CompactTarget::from_consensus(403403001); // High difficulty for Signet - let timespan = 5 * params.pow_target_timespan; // Really slow. + let timespan = 5 * params.pow_target_timespan; // Really slow. let got = CompactTarget::from_next_work_required(starting_bits, timespan, ¶ms); - let want = Target::from_compact(starting_bits) - .max_transition_threshold(params) - .to_compact_lossy(); + let want = + Target::from_compact(starting_bits).max_transition_threshold(params).to_compact_lossy(); assert_eq!(got, want); } @@ -1869,7 +1874,7 @@ mod tests { fn compact_target_from_adjustment_is_max_target() { let params = Params::new(crate::Network::Signet); let starting_bits = CompactTarget::from_consensus(503543726); // Genesis compact target on Signet - let timespan = 5 * params.pow_target_timespan; // Really slow. + let timespan = 5 * params.pow_target_timespan; // Really slow. let got = CompactTarget::from_next_work_required(starting_bits, timespan, ¶ms); let want = params.max_attainable_target.to_compact_lossy(); assert_eq!(got, want);