1

I am helping a community of an altcoin that needs to change it's retarget difficulty. So far I have written some code for the new wallet.

This is what I have done to the main.cpp file

I want to change the retarget the difficulty from 960 blocks (1 day) to 40 blocks (1 hours) of a coin. The block that I want the change to happen is 28000.

from:

static const int64 nTargetTimespan = 1 * 24 * 60 * 60; // UFO: 1 days
static const int64 nTargetSpacing = 90; // UFO: 1.5 minute blocks
static const int64 nInterval = nTargetTimespan / nTargetSpacing;
static const int64 nReTargetHistoryFact = 4; // look at 4 times the retarget interval into block history

to:

static int64 nTargetTimespan = 1 * 24 * 60 * 60; // 1 day
static int64 nTargetSpacing = 90; // 1.5 minute blocks
static int64 nInterval = nTargetTimespan / nTargetSpacing;
static int64 nReTargetHistoryFact = 4; // look at 4 times the retarget interval into block history

Then in the GetNextWorkRequired function this:

from:

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

// Only change once per interval
if ((pindexLast->nHeight+1) % nInterval != 0)

to:

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

// From block 28000 reassess the difficulty every 40 blocks
// Reduce Retarget factor to 2
if(pindexLast->nHeight >= 28000)
{
    nTargetTimespan = 60 * 60; // 1 hours
    nTargetSpacing = 1.5 * 60; // 1.5 minutes
    nInterval = nTargetTimespan / nTargetSpacing;
    nReTargetHistoryFact = 2;
}
else
{
    nTargetTimespan = 1 * 24 * 60 * 60; // 1 day
    nTargetSpacing = 1.5 * 60; // 1.5 minutes
    nInterval = nTargetTimespan / nTargetSpacing;
    nReTargetHistoryFact = 4;
}

// Only change once per interval
if ((pindexLast->nHeight+1) % nInterval != 0)

Is this code correct or is something else to be done?

Thanks I appreciate any help.

1
  • Hi.. Have got any solution to achieve it..?? May 27, 2019 at 7:17

1 Answer 1

-2

your code looks good. I was wondering the same, so i changed it as you did , but i got this error

  GetNextWorkRequired RETARGET
nTargetTimespan = 60    nActualTimespan = 79
Before: 1d0d7333  0000000d73330000000000000000000000000000000000000000000000000000
After:  1d11b58b  00000011b58baeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
ERROR: AcceptBlock() : incorrect proof of work
ERROR: ProcessBlock() : AcceptBlock FAILED

I don't know if it could work if i release the new wallet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.