aboutsummaryrefslogtreecommitdiff
path: root/src/pow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pow.cpp')
-rw-r--r--src/pow.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/pow.cpp b/src/pow.cpp
index 1e8d53de8b..6c8e7e5d98 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -61,7 +61,19 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
// Retarget
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
arith_uint256 bnNew;
- bnNew.SetCompact(pindexLast->nBits);
+
+ // Special difficulty rule for Testnet4
+ if (params.enforce_BIP94) {
+ // Here we use the first block of the difficulty period. This way
+ // the real difficulty is always preserved in the first block as
+ // it is not allowed to use the min-difficulty exception.
+ int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
+ const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
+ bnNew.SetCompact(pindexFirst->nBits);
+ } else {
+ bnNew.SetCompact(pindexLast->nBits);
+ }
+
bnNew *= nActualTimespan;
bnNew /= params.nPowTargetTimespan;
@@ -122,8 +134,19 @@ bool PermittedDifficultyTransition(const Consensus::Params& params, int64_t heig
return true;
}
+// Bypasses the actual proof of work check during fuzz testing with a simplified validation checking whether
+// the most signficant bit of the last byte of the hash is set.
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ return (hash.data()[31] & 0x80) == 0;
+#else
+ return CheckProofOfWorkImpl(hash, nBits, params);
+#endif
+}
+
+bool CheckProofOfWorkImpl(uint256 hash, unsigned int nBits, const Consensus::Params& params)
+{
bool fNegative;
bool fOverflow;
arith_uint256 bnTarget;