SideChain: use full 128 bits in get_difficulty

This commit is contained in:
SChernykh
2022-11-15 16:39:39 +01:00
parent e9a2e4b076
commit b3bce1651b
4 changed files with 166 additions and 33 deletions
+3 -14
View File
@@ -1209,20 +1209,9 @@ bool SideChain::get_difficulty(const PoolBlock* tip, std::vector<DifficultyData>
}
}
// This is correct as long as the difference between two 128-bit difficulties is less than 2^64, even if it wraps
const uint64_t delta_diff = diff2.lo - diff1.lo;
uint64_t product[2];
product[0] = umul128(delta_diff, m_targetBlockTime, &product[1]);
if (product[1] >= delta_t) {
LOGERR(1, "calculated difficulty is too high for block at height = " << tip->m_sidechainHeight << ", id = " << tip->m_sidechainId << ", mainchain height = " << tip->m_txinGenHeight);
return false;
}
uint64_t rem;
curDifficulty.lo = udiv128(product[1], product[0], delta_t, &rem);
curDifficulty.hi = 0;
curDifficulty = diff2 - diff1;
curDifficulty *= m_targetBlockTime;
curDifficulty /= delta_t;
if (curDifficulty < m_minDifficulty) {
curDifficulty = m_minDifficulty;