Private testnet mining is broken in version 0.10.0 #5984

issue apoloval openend this issue on April 8, 2015
  1. apoloval commented at 3:03 pm on April 8, 2015: none

    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?

  2. luke-jr commented at 7:16 pm on April 8, 2015: member
    It should be safe to remove the check for testing. I have an incomplete fix for this locally, but it adds the tip expiry time as a chain param.
  3. laanwj added the label Bug on May 15, 2015
  4. laanwj commented at 11:47 am on May 18, 2015: member
    See #5987
  5. apoloval commented at 12:19 pm on May 18, 2015: none
    Perfect! #5987 should fix the issue!
  6. laanwj closed this on Feb 9, 2016

  7. laanwj commented at 4:03 pm on February 9, 2016: member
    Note that in 0.12, this no longer comes automatically with -testnet, but you need to set the tip age manually to a large number, say -maxtipage=99999999.
  8. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me