neutrino
neutrino copied to clipboard
Regtest: "block target difficulty is higher than max"
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): https://github.com/btcsuite/btcd/issues/1819
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).
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?
I created a pull request https://github.com/lightninglabs/neutrino/pull/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.
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