From: Wilmer Paulino Date: Fri, 28 Apr 2023 09:06:23 +0000 (-0700) Subject: Check difficulty transition against `Target` instead of `Work` X-Git-Tag: v0.0.116-alpha1~37^2~2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=4f9bcb9958d0981dbc69fcbee70fcc847f786392;p=rust-lightning 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. --- diff --git a/lightning-block-sync/src/poll.rs b/lightning-block-sync/src/poll.rs index 9f7e8becf..e7171cf36 100644 --- a/lightning-block-sync/src/poll.rs +++ b/lightning-block-sync/src/poll.rs @@ -136,8 +136,11 @@ impl ValidatedBlockHeader { if let Network::Bitcoin = network { if self.height % 2016 == 0 { - let previous_work = previous_header.header.work(); - if work > (previous_work << 2) || work < (previous_work >> 2) { + let target = self.header.target(); + let previous_target = previous_header.header.target(); + let min_target = previous_target >> 2; + let max_target = previous_target << 2; + if target > max_target || target < min_target { return Err(BlockSourceError::persistent("invalid difficulty transition")) } } else if self.header.bits != previous_header.header.bits {