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

Regtest difficulty calculation error #5712

Closed
sdaftuar opened this issue Jan 26, 2015 · 2 comments
Closed

Regtest difficulty calculation error #5712

sdaftuar opened this issue Jan 26, 2015 · 2 comments
Labels

Comments

@sdaftuar
Copy link
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.

@maflcko
Copy link
Member

maflcko commented Nov 24, 2015

Is this still relevant after #6853?

@laanwj
Copy link
Member

laanwj commented Nov 25, 2015

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.

@laanwj laanwj closed this as completed Feb 9, 2016
@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
Projects
None yet
Development

No branches or pull requests

3 participants