| 20 | #include <iostream> |
| 21 | |
| 22 | unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, |
| 23 | const Consensus::Params& params) |
| 24 | { |
| 25 | assert(pindexLast != nullptr); |
| 26 | int nHeight = pindexLast->nHeight + 1; |
| 27 | bool postfork = nHeight >= params.BTGHeight; |
| 28 | |
| 29 | if (postfork == false) { |
| 30 | // Original Bitcoin PoW. |
| 31 | return BitcoinGetNextWorkRequired(pindexLast, pblock, params); |
| 32 | } |
| 33 | else if (nHeight < params.BTGHeight + params.BTGPremineWindow) { |
| 34 | // PoW limit for premine period. |
| 35 | unsigned int nProofOfWorkLimit = UintToArith256(params.PowLimit(true)).GetCompact(); |
| 36 | return nProofOfWorkLimit; |
| 37 | } |
| 38 | else if (nHeight < params.BTGHeight + params.BTGPremineWindow + params.nDigishieldAveragingWindow) { |
| 39 | // Pow limit start for warm-up period. |
| 40 | return UintToArith256(params.powLimitStart).GetCompact(); |
| 41 | } |
| 42 | else if (nHeight < params.BTGZawyLWMAHeight) { |
| 43 | // Regular Digishield v3. |
| 44 | return DigishieldGetNextWorkRequired(pindexLast, pblock, params); |
| 45 | } else if (nHeight < params.BTGEquihashForkHeight) { |
| 46 | // Zawy's LWMA (testnet launch). |
| 47 | return LwmaGetNextWorkRequired(pindexLast, pblock, params); |
| 48 | } else if (nHeight < params.BTGEquihashForkHeight + params.nZawyLwmaAveragingWindow) { |
| 49 | // Reduce the difficulty of the first forked block by 100x and keep it for N blocks. |
| 50 | if (nHeight == params.BTGEquihashForkHeight) { |
| 51 | return ReduceDifficultyBy(pindexLast, 100, params); |
| 52 | } else { |
| 53 | return pindexLast->nBits; |
| 54 | } |
| 55 | } else { |
| 56 | // Zawy's LWMA. |
| 57 | return LwmaGetNextWorkRequired(pindexLast, pblock, params); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | unsigned int LwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) |
| 62 | { |
no test coverage detected