Add function to validate difficulty changes
Summary:
The rule against difficulty adjustments changing by more than a factor of 4 can
be helpful for anti-DoS measures in contexts where we lack a full headers
chain, so expose this functionality separately and in the narrow case where we
only know the height, new value, and old value.
The function was adjusted to account for the changes in difficulty algorithms after the 2017 BCH fork. The EDA algorithm no longer limits the difficulty change interval to 2016 blocks but still keeps the rule that the difficulty cannot change by more than a factor 4. The DAA (CW-144) and ASERTI3D algorithms no longer have hard rules for difficulty transitions, so the function always returns true after the november 15 2017 hard fork block height.
This is a backport of core#25717
https://github.com/bitcoin/bitcoin/pull/25717/commits/1d4cfa4272cf2c8b980cc8762c1ff2220d3e8d51
Test Plan: ninja && ninja check
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Subscribers: Fabien
Differential Revision: https://reviews.bitcoinabc.org/D15123