7

As is well known, testnet has a "20-minute rule": if no block is found within 20 minutes, the mining difficulty drops to 1 until a block is found.

From some experimentation, it appears that bitcoind's getdifficulty function reports the difficulty of the most recent block. Thus, if the most recent block was mined under the 20-minute rule, getdifficulty returns 1.

In this case, how can I find the "real" difficulty level? That is, the difficulty that would be required of a block submitted less than 20 minutes after the previous one?

The best approach I have found so far is to follow the blockchain back until I find a block with a difficulty other than 1 (or less than 20 minutes after the block preceding it). But this will be prone to error if a difficulty adjustment has recently taken place.

bitcoind must know the real difficulty at all times; can I query it?

3
  • Why would bitcoind always have to know it? If the 20-minute-rule is hard, bitcoind will just accept any new block it receives after 20 minutes. But I never heard of this rule, can you point out where you found out about it? Commented Dec 11, 2013 at 23:39
  • @StevenRoose: en.bitcoin.it/wiki/Testnet: "In addition, if no block has been found in 20 minutes, the difficulty automatically resets back to the minimum for a single block, after which it returns to its previous value." Commented Dec 11, 2013 at 23:42
  • @StevenRoose: If bitcoind receives a block that's less than 20 minutes newer than the previous one, it needs to use the "real" difficulty in deciding whether to accept it. Commented Dec 11, 2013 at 23:43

1 Answer 1

4

You can use the getblocktemplate RPC command and look at the target field.

Your Answer

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

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