Ejemplo n.º 1
0
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{
    unsigned int retarget = DIFF_DGW;

    // mainnet/regtest share a configuration
    if (Params().NetworkIDString() == CBaseChainParams::MAIN || Params().NetworkIDString() == CBaseChainParams::REGTEST) 
	{
        retarget = DIFF_DGW;
    }
	else 
	{
        retarget = DIFF_DGW;
    }

    // Bitcoin style retargeting
    if (retarget == DIFF_BTC)
    {
        return GetNextWorkRequiredBTC(pindexLast, pblock, params);
    }

    // Retarget using Kimoto Gravity Wave
    else if (retarget == DIFF_KGW)
    {
        return KimotoGravityWell(pindexLast, params);
    }

    // Retarget using Dark Gravity Wave 3 by default
    return DarkGravityWave(pindexLast, params);
}
Ejemplo n.º 2
0
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{
    // Most recent algo first
    if (pindexLast->nHeight + 1 >= params.nPowDGWHeight) {
        return DarkGravityWave(pindexLast, pblock, params);
    }
    else if (pindexLast->nHeight + 1 >= params.nPowKGWHeight) {
        return KimotoGravityWell(pindexLast, params);
    }
    else {
        return GetNextWorkRequiredBTC(pindexLast, pblock, params);
    }
}
Ejemplo n.º 3
0
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{
    if (pindexLast->nHeight <= 101631) {
	return GetNextWorkRequiredV1(pindexLast, pblock, params);
    } else if (pindexLast->nHeight > 101631 && pindexLast->nHeight != 137161 && pindexLast->nHeight <= 181200) {
        return GetNextWorkRequiredEMA(pindexLast, pblock, params);
    } else if (pindexLast->nHeight == 137161) {
	return (0x1b034c51);
    } else if (pindexLast->nHeight > 181200 && pindexLast->nHeight < 806000) {
        return GetNextWorkRequiredV2(pindexLast, pblock, params);
    } else {
        return DarkGravityWave(pindexLast, params);
    }

    return GetNextWorkRequiredV2(pindexLast, pblock, params);

}
Ejemplo n.º 4
0
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock)
{
    unsigned int retarget = DIFF_DGW;

    if (Params().NetworkID() != CBaseChainParams::TESTNET) {
        if (pindexLast->nHeight + 1 >= 34140) retarget = DIFF_DGW;
        else if (pindexLast->nHeight + 1 >= 15200) retarget = DIFF_KGW;
        else retarget = DIFF_BTC;
    } else {
        if (pindexLast->nHeight + 1 >= 2000) retarget = DIFF_DGW;
        else retarget = DIFF_BTC;
    }

    // Default Bitcoin style retargeting
    if (retarget == DIFF_BTC)
    {
        unsigned int nProofOfWorkLimit = Params().ProofOfWorkLimit().GetCompact();

        // Genesis block
        if (pindexLast == NULL)
            return nProofOfWorkLimit;

        // Only change once per interval
        if ((pindexLast->nHeight+1) % Params().Interval() != 0)
        {
            if (Params().AllowMinDifficultyBlocks())
            {
                // Special difficulty rule for testnet:
                // If the new block's timestamp is more than 2* 2.5 minutes
                // then allow mining of a min-difficulty block.
                if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + Params().TargetSpacing()*2)
                    return nProofOfWorkLimit;
                else
                {
                    // Return the last non-special-min-difficulty-rules-block
                    const CBlockIndex* pindex = pindexLast;
                    while (pindex->pprev && pindex->nHeight % Params().Interval() != 0 && pindex->nBits == nProofOfWorkLimit)
                        pindex = pindex->pprev;
                    return pindex->nBits;
                }
            }
            return pindexLast->nBits;
        }

        // Dash legacy for testnet
        int64_t blockstogoback = Params().Interval()-1;
        if ((pindexLast->nHeight+1) != Params().Interval())
            blockstogoback = Params().Interval();

        // Go back by what we want to be 1 day worth of blocks
        const CBlockIndex* pindexFirst = pindexLast;
        for (int i = 0; pindexFirst && i < blockstogoback; i++)
            pindexFirst = pindexFirst->pprev;
        assert(pindexFirst);

        // Limit adjustment step
        int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
        LogPrintf("  nActualTimespan = %d  before bounds\n", nActualTimespan);
        if (nActualTimespan < Params().TargetTimespan()/4)
            nActualTimespan = Params().TargetTimespan()/4;
        if (nActualTimespan > Params().TargetTimespan()*4)
            nActualTimespan = Params().TargetTimespan()*4;

        // Retarget
        uint256 bnNew;
        uint256 bnOld;
        bnNew.SetCompact(pindexLast->nBits);
        bnOld = bnNew;
        bnNew *= nActualTimespan;
        bnNew /= Params().TargetTimespan();

        if (bnNew > Params().ProofOfWorkLimit())
            bnNew = Params().ProofOfWorkLimit();

        /// debug print
        LogPrintf("GetNextWorkRequired RETARGET at %d\n", pindexLast->nHeight + 1);
        LogPrintf("Params().TargetTimespan() = %d    nActualTimespan = %d\n", Params().TargetTimespan(), nActualTimespan);
        LogPrintf("Before: %08x  %s\n", pindexLast->nBits, bnOld.ToString());
        LogPrintf("After:  %08x  %s\n", bnNew.GetCompact(), bnNew.ToString());

        return bnNew.GetCompact();

    }

    // Retarget using Kimoto Gravity Wave
    else if (retarget == DIFF_KGW)
    {
        return KimotoGravityWell(pindexLast);
    }

    // Retarget using Dark Gravity Wave 3
    else if (retarget == DIFF_DGW)
    {
        return DarkGravityWave(pindexLast);
    }

    return DarkGravityWave(pindexLast);
}
Ejemplo n.º 5
0
	Target GetNextTargetRequired(const Block& blockLast, const Block& block) override {
		return DarkGravityWave(blockLast, block, blockLast.Height >= 99999);
	}