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
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
- get function comment
- 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.
Note that `if (blockindex == nullptr)` clause remains for now, since we
have not yet backported PR12151.