We are experimenting issues while mining using RPC API in version 0.10.0
Scenario: private testnet, not connected to the public testnet with a custom genesis block. We use it to run integration tests of our software. To reduce the testing time, we restore the blockchain to a known state every time the tests are run.
The whole system were working perfectly. After upgrading bitcoind
to version 0.10.0, we cannot mine anymore. bitcoind
responds with an error 500 with the error message Bitcoin is downloading blocks…, even when the daemon has fully reindexed the contents and using the flag -checkpoints=0
.
Reading the source code of Bitcoin, we realized there is a check that is causing the daemon to consider it is downloading blocks even when it is not. In src/rpcmining.cpp
we have this guard:
0 if (IsInitialBlockDownload())
1 throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Bitcoin is downloading blocks...");
So the result of IsInitialBlockDownload()
is the clue. We have the following implementation.
0bool IsInitialBlockDownload()
1{
2 LOCK(cs_main);
3 if (fImporting || fReindex || chainActive.Height() < Checkpoints::GetTotalBlocksEstimate())
4 return true;
5 static bool lockIBDState = false;
6 if (lockIBDState)
7 return false;
8 bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 ||
9 pindexBestHeader->GetBlockTime() < GetTime() - 24 * 60 * 60);
10 if (!state)
11 lockIBDState = true;
12 return state;
13}
After some debugging, we found out the problem is caused by the following expression.
0pindexBestHeader->GetBlockTime() < GetTime() - 24 * 60 * 60
If we understand it well, a best header mined before 24 hours ago means the initial block is being downloading. That could make sense for mainnet and public testnet, but breaks the possibility to have a private testnet with private miners that had interrupted the mining process at some instant for more than 24 hours.
We recompiled bitcoind
with the following expression for state
variable and the miner succeed to connect to the daemon and is mining without problems.
0 bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6);
We don’t understand perfectly what’s the purpose of this state calculation and what would be the effect to remove this guard. So we cannot provide a patch to fix it. Any idea on how to fix this issue?