HomePhabricator

Backport current GetDifficulty logic (& tests) from Core

Description

Backport current GetDifficulty logic (& tests) from Core

Summary:
Current GetDifficulty has a divergent history from core, time to patch
it up.

We missed a couple backports:
PR9612 https://github.com/bitcoin/bitcoin/pull/9612/files
PR10095 https://github.com/bitcoin/bitcoin/pull/10095/files

Then in D619, we simplified the logic of GetDifficulty in a nice way.

Core would later do the same:
PR13288 https://github.com/bitcoin/bitcoin/pull/13288/files
PR14135 https://github.com/bitcoin/bitcoin/pull/14135/files
But they had also added some tests in the meantime:
PR11748 https://github.com/bitcoin/bitcoin/pull/11748/files

This diff brings back basically into sync with core:

  • get tests
  • remove GetDifficultyFromBits function that isn't used elsewhere
  • and most importantly -- have less code ownership

It can't be simply done with revert-backport-backport-backport-backport so
I'm doing a snapshot update.

Depends on D3021

Test Plan: make check

Reviewers: jasonbcox, schancel, #bitcoin_abc, deadalnix

Reviewed By: jasonbcox, schancel, #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D3012

Details