Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: BlackHatCoiner on October 19, 2020, 11:23:48 AM



Title: Regtest: Can't mine blocks (anymore)
Post by: BlackHatCoiner on October 19, 2020, 11:23:48 AM
https://i.imgur.com/EjI5iW5.png

I've successfully mined 2018 blocks on my regtest mode, but it doesn't allow me mine anymore. Here's what I get when I try to:

https://i.imgur.com/c1NnBQA.png

Any ideas how can I continue mining?

Edit: It seems that it works fine if I generate 1 block per minute. It's not mining when I submit more than 1. Also I can't generatetoaddress 1 [address] too many times at once.

https://i.imgur.com/ih5rb3Q.png


Title: Re: Regtest: Can't mine blocks (anymore)
Post by: NotATether on October 20, 2020, 06:42:17 AM
Maybe the difficulty became so high that generatetoaddress exceeded the maximum iterations? It takes a third argument maxtries that's the maximum number of times to try to find a block. It's 1000000 (1 million) by default. You can try increasing this value, but I wasn't able to reproduce your issue; I mined more than 2018 blocks on regtest, but it crashed before I reached 4000.

A few possibilities on what's causing this:
- Maybe it's not accepting the proof of work for any of the blocks your making and generateBlocks() (https://github.com/bitcoin/bitcoin/blob/0.20/src/rpc/mining.cpp#L104-L143) returns an empty list.
- Or perhaps you exceeded the nonce, so that all block hashes are invalid so no blocks get added to generatetoaddress.

Can you reliably reproduce this problem?

Edit: It seems that it works fine if I generate 1 block per minute. It's not mining when I submit more than 1. Also I can't generatetoaddress 1 [address] too many times at once.

Looks like you didn't give the RPC call enough time to finish.


Title: Re: Regtest: Can't mine blocks (anymore)
Post by: BlackHatCoiner on October 20, 2020, 10:35:38 AM
Maybe the difficulty became so high that generatetoaddress exceeded the maximum iterations?
Oh I see, if I generate 2016 blocks at once it makes difficulty too high, because of this:
Code:
difficulty = expected time / actual time

Since expected time is 20160 minutes then the equation would be that:
Code:
difficulty = 20160 / actual time

I generated 2016 blocks within 5-10 seconds so that makes difficulty ~= 2000, which is too big for just one computer.

On what script is that maxtries located?

A few possibilities on what's causing this:
- Maybe it's not accepting the proof of work for any of the blocks your making and generateBlocks() (https://github.com/bitcoin/bitcoin/blob/0.20/src/rpc/mining.cpp#L104-L143) returns an empty list.
- Or perhaps you exceeded the nonce, so that all block hashes are invalid so no blocks get added to generatetoaddress.
Why it may not accept the proof of work? Even if difficulty was too high, I would not get an empty list. The computer would just try to find a tiny target, which would fail. But it would lag the whole computer, it wouldn't return me an empty list.

Isn't the nonce just an integer? I don't get why is this relevant with my issue.


Title: Re: Regtest: Can't mine blocks (anymore)
Post by: NotATether on October 20, 2020, 12:13:56 PM
Maybe the difficulty became so high that generatetoaddress exceeded the maximum iterations?
Oh I see, if I generate 2016 blocks at once it makes difficulty too high, because of this:
Code:
difficulty = expected time / actual time

Since expected time is 20160 minutes then the equation would be that:
Code:
difficulty = 20160 / actual time

I generated 2016 blocks within 5-10 seconds so that makes difficulty ~= 2000, which is too big for just one computer.

On what script is that maxtries located?

It's the third argument to the generatrtoaddress command: generatetoaddress <nblocks> <address> <maxtries>. It is an optional parameter and it's 1000000 by default.


A few possibilities on what's causing this:
- Maybe it's not accepting the proof of work for any of the blocks your making and generateBlocks() (https://github.com/bitcoin/bitcoin/blob/0.20/src/rpc/mining.cpp#L104-L143) returns an empty list.
- Or perhaps you exceeded the nonce, so that all block hashes are invalid so no blocks get added to generatetoaddress.
Why it may not accept the proof of work? Even if difficulty was too high, I would not get an empty list. The computer would just try to find a tiny target, which would fail. But it would lag the whole computer, it wouldn't return me an empty list.

Isn't the nonce just an integer? I don't get why is this relevant with my issue.

I don't think these points apply to this problem either now that you figured out the root cause is from the difficulty becoming too large.


Title: Re: Regtest: Can't mine blocks (anymore)
Post by: nc50lc on October 20, 2020, 12:19:47 PM
It may be another issue, since Regtest doesn't retarget.
Line 386: https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L365-L386 (https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L365-L386)

Wait, is that for Bitcoin Core or the fork that you've mentioned before?


Title: Re: Regtest: Can't mine blocks (anymore)
Post by: BlackHatCoiner on October 20, 2020, 12:32:33 PM
It may be another issue, since Regtest doesn't retarget.
Line 386: https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L365-L386 (https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L365-L386)

Wait, is that for Bitcoin Core or the fork that you've mentioned before?

It does retarget if you change consensus.fPowNoRetargeting = true; to consensus.fPowNoRetargeting = false;

This is for bitcoin core, I didn't mentioned any forks before.

It's the third argument to the generatrtoaddress command: generatetoaddress <nblocks> <address> <maxtries>. It is an optional parameter and it's 1000000 by default.

https://i.imgur.com/WLU859s.png

I now get it. It stops mining after max tries. I set it to 100 million and it hasn't returned me any empty lists. I'm just waiting for my blocks to get mined.


Title: Re: Regtest: Can't mine blocks (anymore)
Post by: nc50lc on October 20, 2020, 02:45:45 PM
It may be another issue, since Regtest doesn't retarget.
Line 386: https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L365-L386 (https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L365-L386)

Wait, is that for Bitcoin Core or the fork that you've mentioned before?
It does retarget if you change consensus.fPowNoRetargeting = true; to consensus.fPowNoRetargeting = false;
Ah, so you did compiled a modified version of Bitcoin core in this thread: Compiling error (chainparams.cpp: Permission denied) (https://bitcointalk.org/index.php?topic=5282855.msg55405268#msg55405268)

Next time, please include any relevant info in the OP so people wouldn't think that you're using the default.