Skip to content

Commit 4f9bcb9

Browse files
committed
Check difficulty transition against Target instead of Work
`rust-bitcoin v0.30.0` made some changes in this area that no longer allow us to work with the previously exposed `U256` type. While `Work` and `Target` (they're inverses of each other) essentially represent the same concept, it makes more sense from their API's perspective to only expose difficulty transitions and adjustments on `Target`s.
1 parent 72f5e0b commit 4f9bcb9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lightning-block-sync/src/poll.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ impl ValidatedBlockHeader {
136136

137137
if let Network::Bitcoin = network {
138138
if self.height % 2016 == 0 {
139-
let previous_work = previous_header.header.work();
140-
if work > (previous_work << 2) || work < (previous_work >> 2) {
139+
let target = self.header.target();
140+
let previous_target = previous_header.header.target();
141+
let min_target = previous_target >> 2;
142+
let max_target = previous_target << 2;
143+
if target > max_target || target < min_target {
141144
return Err(BlockSourceError::persistent("invalid difficulty transition"))
142145
}
143146
} else if self.header.bits != previous_header.header.bits {

0 commit comments

Comments
 (0)