Abrupt increase in difficulty of proof-of-work

1

I am simulating a private bitcoin network that I started with the initial difficulty set to (1/2)^16, however after about 20 blocks of mining on the network it increased to 1 and has been constant since then. As far as I understand from the source code, it is supposed to increase after every 2016 blocks, so how did it increase after only 20 blocks.Notice the difficulty=1

Change of powLimit in my bitcoind instances.

strNetworkID = "regtest";
        consensus.nSubsidyHalvingInterval = 210000;
        consensus.nMajorityEnforceBlockUpgrade = 51;
        consensus.nMajorityRejectBlockOutdated = 75;
        consensus.nMajorityWindow = 100;
        consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
        consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
        consensus.nPowTargetSpacing = 10 * 60;
        consensus.fPowAllowMinDifficultyBlocks = true;
        consensus.fPowNoRetargeting = false;

bawejakunal

Posted 2015-11-02T11:05:20.907

Reputation: 467

Are you sure it didn't say difficulty 1 all along? On Bitcoin mainnet, difficulty is equal to the maximum (least difficult) target divided by the current target; if you set your minimum target to x and it's still at x, then that would also be a relative difficulty of 1.David A. Harding 2015-11-02T17:13:57.407

@DavidA.Harding yeah I figured that out later from the bitcoin documentation. Thanks.bawejakunal 2015-11-03T03:04:54.797

Cool. Turned it into an answer.David A. Harding 2015-11-03T04:01:34.423

Answers

1

The network difficulty is equal to the maximum allowed (least difficult) target divided by the current target; if you set your minimum target to x and it's still at x, then that would also be a relative difficulty of 1.

An easy way to confirm this is to look at the calculated difficulty for your genesis block (or block 1 if you got your genesis block from somewhere else).

bitcoin-cli getblockhash 0
bitcoin-cli getblock <hash_from_above>

If it also says difficulty is one, then you know difficulty hasn't changed since you started mining.

As an interesting side note, as of (I think) Bitcoin Core 0.11.0, Bitcoin's regtest supports "instant" block generation even though its official maximum target is much lower (more difficult). This means that it has difficulties far below 1:

$ bitcoin-cli -regtest getmininginfo
{
  "blocks": 0,
  "currentblocksize": 0,
  "currentblocktx": 0,
  "difficulty": 4.656542373906925e-10,
  "errors": "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications",
  "genproclimit": -1,
  "networkhashps": 0,
  "pooledtx": 0,
  "testnet": false,
  "chain": "regtest",
  "generate": false
}

David A. Harding

Posted 2015-11-02T11:05:20.907

Reputation: 10 154