2

the standard values

    if (nActualTimespan < params.nPowTargetTimespan/4)
        nActualTimespan = params.nPowTargetTimespan/4;
    if (nActualTimespan > params.nPowTargetTimespan*4)
        nActualTimespan = params.nPowTargetTimespan*4;

but if i use

        if (nActualTimespan < params.nPowTargetTimespan/4)
            nActualTimespan = params.nPowTargetTimespan/4;
        if (nActualTimespan > params.nPowTargetTimespan*2)
            nActualTimespan = params.nPowTargetTimespan*2;

It's be valid or it's can broke diff system ?

What values can i add for diff is not grow very quickly, but drop faster than grow for it be more stable for fast block time.

setting of block time is

consensus.nPowTargetTimespan = 10 * 60; // 10 min
consensus.nPowTargetSpacing = 5 * 60; //5 min

And another question

I try use the exist function low diff block what created for testnet for only block with Height 2001 . Previous exist block is 2000 and latest now in blockchain.

if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
{
    if(pindexLast->nHeight+1 == 2001)
    {
        // Special difficulty rule for testnet:
        // If the new block's timestamp is more than 2* 10 minutes
        // then allow mining of a min-difficulty block.
        if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
            return nProofOfWorkLimit;
        else
        {
            // Return the last non-special-min-difficulty-rules-block
            const CBlockIndex* pindex = pindexLast;
            while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == nProofOfWorkLimit)
                pindex = pindex->pprev;
            return pindex->nBits;
        }
    }
    return pindexLast->nBits;           
}
else
{           
    if (params.fPowAllowMinDifficultyBlocks)
    {
        // Special difficulty rule for testnet:
        // If the new block's timestamp is more than 2* 10 minutes
        // then allow mining of a min-difficulty block.
        if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
            return nProofOfWorkLimit;
        else
        {
            // Return the last non-special-min-difficulty-rules-block
            const CBlockIndex* pindex = pindexLast;
            while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == nProofOfWorkLimit)
                pindex = pindex->pprev;
            return pindex->nBits;
        }
    }
    return pindexLast->nBits;
}

And use new rule retarget for new block's after 2001 and accept old block with old retarget rule.

   if(pindexLast->nHeight+1 > 2001)
    {
        if (nActualTimespan < params.nPowTargetTimespan/4)
            nActualTimespan = params.nPowTargetTimespan/4;
        if (nActualTimespan > params.nPowTargetTimespan*2)
            nActualTimespan = params.nPowTargetTimespan*2;
    }
    else
    {
        if (nActualTimespan < params.nPowTargetTimespan/4)
            nActualTimespan = params.nPowTargetTimespan/4;
        if (nActualTimespan > params.nPowTargetTimespan*4)
            nActualTimespan = params.nPowTargetTimespan*4;
    }

About what i asking , is this solution is right and it will work, or this solution is wrong end exist another way to do this ?

mraksoll
  • 37
  • 6

1 Answers1

0
    if (nActualTimespan < params.nPowTargetTimespan/4)
        nActualTimespan = params.nPowTargetTimespan/4;
    if (nActualTimespan > params.nPowTargetTimespan*2)
        nActualTimespan = params.nPowTargetTimespan*2;

This does the opposite of what you want. It increases the difficulty quickly, but decreases the difficulty slowly.

Here's what you meant to do:

    if (nActualTimespan < params.nPowTargetTimespan/2)
        nActualTimespan = params.nPowTargetTimespan/2;
    if (nActualTimespan > params.nPowTargetTimespan*4)
        nActualTimespan = params.nPowTargetTimespan*4;
Nick ODell
  • 29,184
  • 11
  • 69
  • 129
  • what parameters need to use for decrees it quickly , but increase slowly . End exit any alternative method to add on blockchain - mine block with low diff for reset diff for new block's ? – mraksoll Aug 08 '17 at 01:33
  • I do not understand if it's only for increase , where the decrease setting's ??? I think it's rule with /4 it's for decrease end rule with* for increase :/ – mraksoll Aug 08 '17 at 02:00
  • The code you posted caps the measured timespan at one fourth target, or twice the target. This limits the difficulty change in one retarget period to increasing by a factor of 4, or decreasing by a factor of 2. – Nick ODell Aug 08 '17 at 02:02
  • I need use /2 /2 *4 *4 or it's again wrong ? You can make little example with any setting how it be correct :/ Or for decrease x4 end increase only x2 – mraksoll Aug 08 '17 at 02:06
  • See edit I added. – Nick ODell Aug 08 '17 at 02:08
  • End about block , it's possible to add low diff block after huge to blockchain ? For new rules start work after this block, i try with low diff block with parameter only for they height , but it's stop accept old block's and how i understand it's wrong to. But cannot find any information about this. – mraksoll Aug 08 '17 at 02:16
  • Bitcoin's rules require a miner to set a difficulty before trying to mine a block, and the difficulty must exactly match what the validating node expects. That is why it won't accept old blocks. – Nick ODell Aug 08 '17 at 02:44
  • I understand this , but with retarget system it's work , why not work with min diff block's , for example the latest block is 2000 , i try == 2001, and >2000. Maybe exist other way to do this and I simple not find it. – mraksoll Aug 08 '17 at 03:05
  • I'm not sure I understand the question. Can you rephrase? – Nick ODell Aug 08 '17 at 03:05
  • Example on fist post , latest code if(pindexLast->nHeight+1 > 2001) code else code i try this trick to min diff block to , but it now work , but for retarget work perfect – mraksoll Aug 08 '17 at 03:07
  • Ok. What's the problem with that code? – Nick ODell Aug 08 '17 at 03:08
  • code before retarget with this trick, i try do the same with min diff block's ... For mine new block after block with huge diff and after this block disable low diff block's for normal mining with normal diff. – mraksoll Aug 08 '17 at 03:12
  • I need low diff only for one block after 2000 for drop diff. But rule with block height not work for this function, but perfect work for retarget. – mraksoll Aug 08 '17 at 03:16
  • So you want a one-time difficulty drop at block 2000? – Nick ODell Aug 08 '17 at 03:20
  • Yes this why i try use function low diff block with rule only for block after 2000. for fully reset diff, then new block's start work with new retarget rules for more stable diff increase. – mraksoll Aug 08 '17 at 03:25
  • I try find solution to do this , but not find any solution and try this. – mraksoll Aug 08 '17 at 03:37
  • exist any solution for this ? :/ – mraksoll Aug 08 '17 at 03:59
  • what i try to do , create new block with low diff and start calculate new diff from them. – mraksoll Aug 08 '17 at 04:34