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: "block target difficulty is higher than max" #255

Closed
amanzag opened this issue Aug 2, 2022 · 4 comments · Fixed by #283
Closed

Regtest: "block target difficulty is higher than max" #255

amanzag opened this issue Aug 2, 2022 · 4 comments · Fixed by #283

Comments

@amanzag
Copy link

amanzag commented Aug 2, 2022

Whenever I try to use neutrino in regtest mode, I run into this error:

I/GoLog   (29209): 2022-08-02 14:49:05.236 [DBG] BTCN: Difficulty retarget at block height 4032
I/GoLog   (29209): 2022-08-02 14:49:05.236 [DBG] BTCN: Old target 207fffff (7fffff0000000000000000000000000000000000000000000000000000000000)
I/GoLog   (29209): 2022-08-02 14:49:05.236 [DBG] BTCN: New target 201fffff (1fffff0000000000000000000000000000000000000000000000000000000000)
I/GoLog   (29209): 2022-08-02 14:49:05.236 [DBG] BTCN: Actual timespan 33h35m0s, adjusted timespan 84h0m0s, target timespan 336h0m0s
I/GoLog   (29209): 2022-08-02 14:49:05.236 [WRN] BTCN: Header doesn't pass sanity check: block target difficulty of 7fffff0000000000000000000000000000000000000000000000000000000000 is higher than max of 1fffff0000000000000000000000000000000000000000000000000000000000 -- disconnecting peer

There must be some flaw in the difficulty calculation logic here: https://github.com/lightninglabs/neutrino/blob/master/blockmanager.go#L2795-L2834

Related issue (but I think it belongs here): btcsuite/btcd#1819

@Roasbeef
Copy link
Member

Roasbeef commented Aug 2, 2022

Are you able to reproduce the same thing w/ simnet? IIRC, I think btcd will do difficulty retargets for regtest, while bitcoind never does. This is what historically led to the creation of simnet (which does the retargets).

@amanzag
Copy link
Author

amanzag commented Aug 2, 2022

I think you're right. I can't reproduce with simnet and that's probably because I'm running neutrino against a bitcoind which, as you say, doesn't do retargets, as can be seen here:
https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L407

Shouldn't btcd/neutrino disable retargets for regtest as well?

@amanzag
Copy link
Author

amanzag commented Aug 3, 2022

I created a pull request #256 that fixes the issue.
It's probably not the right way of fixing it, but if you point me in the right direction I can change it.

@guggero
Copy link
Member

guggero commented Apr 11, 2023

bitcoind was refactored a bit, the fPowNoRetargeting field can now be found here: https://github.com/bitcoin/bitcoin/blob/e695d8536e534f1e59de4a62a0d87a93e7a73456/src/kernel/chainparams.cpp#L415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants