diff options
author | Suhas Daftuar <sdaftuar@gmail.com> | 2022-05-25 10:16:56 -0400 |
---|---|---|
committer | Suhas Daftuar <sdaftuar@gmail.com> | 2022-08-23 11:34:10 -0400 |
commit | 1d4cfa4272cf2c8b980cc8762c1ff2220d3e8d51 (patch) | |
tree | 4d1338b17702e4ed0998ece0f00f2d4b8b9ba062 /src/pow.h | |
parent | 2bd9aa5a44b88c866c4d98f8a7bf7154049cba31 (diff) |
Add function to validate difficulty changes
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.
Includes fuzz test by Martin Zumsande.
Diffstat (limited to 'src/pow.h')
-rw-r--r-- | src/pow.h | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -20,4 +20,18 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF /** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&); +/** + * Return false if the proof-of-work requirement specified by new_nbits at a + * given height is not possible, given the proof-of-work on the prior block as + * specified by old_nbits. + * + * This function only checks that the new value is within a factor of 4 of the + * old value for blocks at the difficulty adjustment interval, and otherwise + * requires the values to be the same. + * + * Always returns true on networks where min difficulty blocks are allowed, + * such as regtest/testnet. + */ +bool PermittedDifficultyTransition(const Consensus::Params& params, int64_t height, uint32_t old_nbits, uint32_t new_nbits); + #endif // BITCOIN_POW_H |