Regtest difficulty calculation error #5712

issue sdaftuar opened this issue on January 26, 2015
  1. sdaftuar commented at 4:06 PM on January 26, 2015: member

    There are a few issues referencing regtest mining speed (eg #5405, #4793), but I thought this observation made more sense as a separate issue:

    GetNextWorkRequired has an overflow bug that affects the regtest difficulty calculation. The way the arithmetic works in that function is to first multiply the prior difficulty by nActualTimespan and then divide by TargetTimespan. (TargetTimespan is 14 * 24* 60 * 60 = 1,209,600; nActualTimespan is bounded to be within a factor of 4 of TargetTimespan.)

    Since the regtest initial difficulty is so large, on the first retarget we end up overflowing on the multiply, and so the difficulty increases dramatically after the division, regardless of the timestamps on the regtest blocks.

    I don't believe this can affect mainnet or testnet, because the initial difficulties are small enough that no overflow can occur.

  2. laanwj added the label Mining on May 18, 2015
  3. MarcoFalke commented at 6:22 PM on November 24, 2015: member

    Is this still relevant after #6853?

  4. laanwj commented at 8:34 AM on November 25, 2015: member

    This will remain an issue to watch out for and that should be well documented (certainly experiments with other parameters may stumble on it), but for the end-user, #6853 solves it.

  5. laanwj closed this on Feb 9, 2016

  6. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 12:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me