Skip to content

Commit a6a6887

Browse files
fix(testnet4): do not compute difficulty adjustment
Raised by: bitcoindevkit/bdk-cli#197 Users of `Testnet4` will run into problems when loading headers from the database, as the network allows for minimum difficulty blocks. Instead of adding logic for the header timestamps just for the sake of `Testnet4`, I am opting to simply ignore the difficutly adjustment. This boolean does not evaluate to `true` on `Bitcoin`, which is easily verified in `rust-bitcoin`. Notably `Signet` does not allow minimum difficulty blocks, so difficulty adjustment logic is still tested by a testnet as well as mainnet. This is only dropping `Testnet4`
1 parent 813a262 commit a6a6887

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/chain/graph.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ impl BlockTree {
324324
}
325325

326326
fn compute_next_work_required(&self, new_height: Height) -> Option<CompactTarget> {
327+
// Do not audit the diffulty for `Testnet`. Auditing the difficulty properly for a testnet
328+
// will result in convoluted logic. This is a critical code block for mainnet and should be
329+
// as readable as possible
330+
if self.network.params().allow_min_difficulty_blocks {
331+
return None;
332+
}
327333
let adjustment_period =
328334
Height::from_u64_checked(self.network.params().difficulty_adjustment_interval())?;
329335
let epoch_start = new_height.checked_sub(adjustment_period)?;

0 commit comments

Comments
 (0)