Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testnet difficulty calculation changes, to take effect Feb 15 2012 #686

Merged
merged 1 commit into from Jan 31, 2012

Conversation

gavinandresen
Copy link
Contributor

Allow mining of min-difficulty blocks if 20 minutes have gone by without mining a regular-difficulty block.
Normal rules apply every 2016 blocks, though, so there may be a very-slow-to-confirm block at the difficulty-adjustment blocks (once per month, assuming testnet is in it's normal "difficulty too high for number of people mining it" state).

This will almost certainly cause a testnet blockchain split after Jan 15. I'll update the Testnet Faucet, I'll ask theymos if he can update the testnet block explorer bitcoind.

(date slipped from Jan 1 to Feb 15)


// Only change once per interval
if ((pindexLast->nHeight+1) % nInterval != 0)
{
// Special rules for testnet after 1 Jan 2012:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why inside the interval check? If we are on the cusp of an interval, why shouldn't we allow min-diff blocks?

@TheBlueMatt
Copy link
Contributor

Other than that one concern, ACK

@luke-jr
Copy link
Member

luke-jr commented Dec 7, 2011

At the same time, I propose adjusting the testnet base58 versions to match with the new proposed base58 version spec.

@gavinandresen
Copy link
Contributor Author

RE: why keep the regular-difficulty-every-2016-blocks:

Because if you don't, and hashing power drops, then it will never adjust downward properly because the common case for non-cusp blocks is "find the last block with something other than minimum work and return its difficulty."

Example: Imagine difficulty is at 1111 before block 201600, and that block ends up taking 60 minutes to find. Imagine the normal difficulty adjustment would drop difficulty to 600.

If we allow block 201600 to have difficulty 1, then block 201601 would also be looked for at difficulty 1111, because there's no previous block with the new difficulty.

I wrote the code that way so testnet is as close to mainnet as possible; I didn't want a completely different testnet non-cusp-block calculation (yes, I COULD figure out what the last difficulty adjustment interval was and factor out the difficulty computation into yet another method... benefit doesn't seem worth the extra code complexity).

RE: adjusting testnet base58 version: okey doke. What's the right number for testnet under your scheme? 192?

@TheBlueMatt
Copy link
Contributor

mmm, fair enough

@luke-jr
Copy link
Member

luke-jr commented Dec 8, 2011

Yes, 192 for testnet pubkey-addresses. 196 for testnet script-addresses (OP_EVAL).

return nProofOfWorkLimit;
else
{
// Return the last non-min-difficulty-block
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the correct difficulty for this interval is min difficulty? Wouldn't this code return something higher from a block that it finds in the previous inteval? It should probably stop at the interval change and use the difficulty there.

const CBlockIndex* pindex = pindexLast;
while (pindex->pprev && pindex->nHeight % nInterval != 0 && pindex->nBits == nProofOfWorkLimit)
pindex = pindex->pprev;
return pindex->nBits;

@luke-jr
Copy link
Member

luke-jr commented Dec 8, 2011

The new anti-orphan-flood code won't break this, will it?

@gavinandresen
Copy link
Contributor Author

coblee: Nice catch! You're right, this would prevent difficulty from ever dropping all the way down to min difficulty.

luke-jr: Nice catch! You're right, the orphan block DoS code needs to take into account this change.

I won't have time to fix this until I'm back next week.

@gavinandresen
Copy link
Contributor Author

Code updated/rebased to fix the issues pointed out by coblee and luke-jr.

@luke-jr
Copy link
Member

luke-jr commented Jan 11, 2012

Is this going to be merged before 15 Jan? ;)

// Testnet has min-difficulty blocks
// after nTargetSpacing*2 time between blocks:
if (fTestNet && nTime > nTargetSpacing*2)
return bnProofOfWorkLimit.GetCompact();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether this affects anything, but this does not check pblock->nTime > 1326585600 like the other one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is OK-- the code that calls ComputeMinWork call pblock->GetBlockTime() which just return pblock->nTime.

Allow mining of min-difficulty blocks if 20 minutes have gone by without mining a regular-difficulty block.
Normal rules apply every 2016 blocks, though, so there may be a very-slow-to-confirm block at the difficulty-adjustment blocks.
@gavinandresen gavinandresen merged commit c52296a into bitcoin:master Jan 31, 2012
jpentland pushed a commit to jpentland/bitcoin that referenced this pull request Feb 7, 2016
ptschip pushed a commit to ptschip/bitcoin that referenced this pull request Jul 11, 2017
[Backport to Release PR#685] Do not continue if header will not connect
rajarshimaitra pushed a commit to rajarshimaitra/bitcoin that referenced this pull request Aug 5, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants