From 4f9bcb9958d0981dbc69fcbee70fcc847f786392 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 28 Apr 2023 02:06:23 -0700 Subject: [PATCH] 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. --- lightning-block-sync/src/poll.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lightning-block-sync/src/poll.rs b/lightning-block-sync/src/poll.rs index 9f7e8bec..e7171cf3 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 { -- 2.30.2