Add logging to GetAncestor if pindex->pprev == NULL #9630

pull jnewbery wants to merge 1 commits into bitcoin:master from jnewbery:crashlogging changing 1 files +6 −1
  1. jnewbery commented at 6:45 PM on January 25, 2017: member

    https://github.com/bitcoin/bitcoin/commit/84c13e759dbb0de282e2c8ce43d77f4d52fda6d9 added an assert if GetAncestor() fails to find the parent of the current block (ie if pprev is NULL). This PR adds helpful logging for debugging which block is missing a parent.

    This will be helpful for troubleshooting issues like #9001 and #9170.

  2. Add logging if pindex->pprev == NULL
    GetAncestor asserts if pindex->prev is NULL, but doesn't log any useful
    output. This PR adds helpful logging for debugging why the blockchain is
    corrupt.
    d180c15ef8
  3. in src/chain.cpp:None in d180c15ef8
      99 | @@ -99,8 +100,12 @@ CBlockIndex* CBlockIndex::GetAncestor(int height)
     100 |              // Only follow pskip if pprev->pskip isn't better than pskip->pprev.
     101 |              pindexWalk = pindexWalk->pskip;
     102 |              heightWalk = heightSkip;
     103 | +        } else if (pindexWalk->pprev == NULL) {
     104 | +            // pindexWalk should always have a parent (since pindexWalk is not the genesis block)
     105 | +            LogPrintf("%s: Block index is missing a block. Block %s, height %d has no parent.\n",  __func__, pindexWalk->GetBlockHash().ToString(), heightWalk);
     106 | +            LogPrintf("%s: Run bitcoin with -reindex to rebuild the block index. This will redownload the entire blockchain if running a pruned node.\n",  __func__);
    


    sipa commented at 7:06 PM on January 25, 2017:

    This sounds like logic that belongs in LoadBlockIndex, not in the basic data structure logic.

  4. laanwj commented at 6:47 PM on January 26, 2017: member

    Concept ACK, also did this a few times while debugging but never bothered to PR it.

    Agree with @sipa that logging doesn't belong here, but in the caller, to which the error condition would need to be signalled in some way.

    Also: should we use AbortNode instead of abort() to make sure GUI users get a popup to check the debug log?

  5. jnewbery commented at 10:24 PM on January 26, 2017: member

    @sipa @laanwj thanks for the feedback. I'll take a look at putting the logging into the caller.

  6. fanquake added the label Docs and Output on Jan 27, 2017
  7. jtimon commented at 7:51 PM on March 18, 2017: contributor

    Concept ACK but agree with the feedback.

  8. jnewbery commented at 6:34 PM on March 30, 2017: member

    Closing this for now. I'll reopen once I've changed this to incorporate the feedback.

  9. jnewbery closed this on Mar 30, 2017

  10. php-wizard commented at 10:19 PM on January 16, 2018: none

    Hello, i see this assertion error showing on a MessageBox ( i'm under Windows ):

    Assertion Failed!
    Program: C:\Program Files\Bitcoin\bitcoin-qt.exe
    File: chain.cpp Line 101
    Expression: pIndexWalk->prev
    

    The logs seem not to be helpful. db.log is empty, and this is from debug.log:

    2018-01-16 22:10:31 Bitcoin version v0.14.2
    2018-01-16 22:10:31 InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
    2018-01-16 22:10:31 Assuming ancestors of block 00000000000000000013176bf8d7dfeab4e1db31dc93bc311b436e82ab226b90 have valid signatures.
    2018-01-16 22:10:31 GUI: "registerShutdownBlockReason: Successfully registered: Bitcoin Core didn't yet exit safely..."
    2018-01-16 22:10:31 Default data directory C:\Users\Developer\AppData\Roaming\Bitcoin
    2018-01-16 22:10:31 Using data directory X:\btc-wallet
    2018-01-16 22:10:31 Using config file X:\btc-wallet\bitcoin.conf
    2018-01-16 22:10:31 Using at most 125 automatic connections (2048 file descriptors available)
    2018-01-16 22:10:31 Using 32 MiB out of 32 requested for signature cache, able to store 1048576 elements
    2018-01-16 22:10:31 Using 2 threads for script verification
    2018-01-16 22:10:31 scheduler thread start
    2018-01-16 22:10:31 libevent: getaddrinfo: nodename nor servname provided, or not known
    2018-01-16 22:10:31 Binding RPC on address ::1 port 8332 failed.
    2018-01-16 22:10:31 HTTP: creating work queue of depth 16
    2018-01-16 22:10:31 Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation.
    2018-01-16 22:10:31 HTTP: starting 4 worker threads
    2018-01-16 22:10:31 Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
    2018-01-16 22:10:31 Using wallet wallet.dat
    2018-01-16 22:10:31 init message: Verifying wallet...
    2018-01-16 22:10:31 CDBEnv::Open: LogDir=X:\btc-wallet\database ErrorFile=X:\btc-wallet\db.log
    2018-01-16 22:10:31 Bound to [::]:8333
    2018-01-16 22:10:31 Bound to 0.0.0.0:8333
    2018-01-16 22:10:31 Cache configuration:
    2018-01-16 22:10:31 * Using 2.0MiB for block index database
    2018-01-16 22:10:31 * Using 8.0MiB for chain state database
    2018-01-16 22:10:31 * Using 440.0MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space)
    2018-01-16 22:10:31 init message: Loading block index...
    2018-01-16 22:10:31 Opening LevelDB in X:\btc-wallet\blocks\index
    2018-01-16 22:10:31 Opened LevelDB successfully
    2018-01-16 22:10:31 Using obfuscation key for X:\btc-wallet\blocks\index: 0000000000000000
    2018-01-16 22:10:31 Opening LevelDB in X:\btc-wallet\chainstate
    2018-01-16 22:10:31 Opened LevelDB successfully
    2018-01-16 22:10:31 Using obfuscation key for X:\btc-wallet\chainstate: 63e0585ea48cf626
    2018-01-16 22:12:41 
    
    
    
    2018-01-16 22:12:41 Bitcoin version v0.14.2
    2018-01-16 22:12:41 InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
    2018-01-16 22:12:41 Assuming ancestors of block 00000000000000000013176bf8d7dfeab4e1db31dc93bc311b436e82ab226b90 have valid signatures.
    2018-01-16 22:12:41 GUI: "registerShutdownBlockReason: Successfully registered: Bitcoin Core didn't yet exit safely..."
    2018-01-16 22:12:42 Default data directory C:\Users\Developer\AppData\Roaming\Bitcoin
    2018-01-16 22:12:42 Using data directory X:\btc-wallet
    2018-01-16 22:12:42 Using config file X:\btc-wallet\bitcoin.conf
    2018-01-16 22:12:42 Using at most 125 automatic connections (2048 file descriptors available)
    2018-01-16 22:12:42 Using 32 MiB out of 32 requested for signature cache, able to store 1048576 elements
    2018-01-16 22:12:42 Using 2 threads for script verification
    2018-01-16 22:12:42 scheduler thread start
    2018-01-16 22:12:42 libevent: getaddrinfo: nodename nor servname provided, or not known
    2018-01-16 22:12:42 Binding RPC on address ::1 port 8332 failed.
    2018-01-16 22:12:42 HTTP: creating work queue of depth 16
    2018-01-16 22:12:42 Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation.
    2018-01-16 22:12:42 HTTP: starting 4 worker threads
    2018-01-16 22:12:42 Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
    2018-01-16 22:12:42 Using wallet wallet.dat
    2018-01-16 22:12:42 init message: Verifying wallet...
    2018-01-16 22:12:42 CDBEnv::Open: LogDir=X:\btc-wallet\database ErrorFile=X:\btc-wallet\db.log
    2018-01-16 22:12:42 Bound to [::]:8333
    2018-01-16 22:12:42 Bound to 0.0.0.0:8333
    2018-01-16 22:12:42 Cache configuration:
    2018-01-16 22:12:42 * Using 2.0MiB for block index database
    2018-01-16 22:12:42 * Using 8.0MiB for chain state database
    2018-01-16 22:12:42 * Using 440.0MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space)
    2018-01-16 22:12:42 init message: Loading block index...
    2018-01-16 22:12:42 Opening LevelDB in X:\btc-wallet\blocks\index
    2018-01-16 22:12:42 Opened LevelDB successfully
    2018-01-16 22:12:42 Using obfuscation key for X:\btc-wallet\blocks\index: 0000000000000000
    2018-01-16 22:12:42 Opening LevelDB in X:\btc-wallet\chainstate
    2018-01-16 22:12:42 Opened LevelDB successfully
    2018-01-16 22:12:42 Using obfuscation key for X:\btc-wallet\chainstate: 63e0585ea48cf626
    

    I have tried removing peers.dat , to no avail. Then i removed .lock and every .dat and .log file except wallet.dat and retried. Did not help.

    What else can i try ? I wish not to re-download the whole blockchain, it may take even a whole week Thanks

    ....... EDIT: i had an electricity blackout today and my PC crashed, so i might have disk errors. Will run a chkdisk and retry.

    But i have to say that last night my wallet was synchronized and i closed it, then i have backupped the whole blocks/ and chainstate/ folders to another drive.

    Today after the blackout/crash , before retrying to open Bitcoin Core, i removed those 2 folders and restored from the backups altogether, but apparently that was not enough.

    Maybe i was stupid not thinking to backup the whole wallet folder, and not just blocks/ and chainstate/ . Do you think it would be enough as a backup routine? Thanks .......

  11. php-wizard commented at 4:56 AM on January 17, 2018: none

    UPDATE: chkdsk did not help, but i got away with the -reindex wallet flag. It is taking a lot of time though

  12. andrade commented at 11:33 AM on May 3, 2018: none

    @sleepndevelop -reindex worked for me but took over an hour on the testnet.

    I wonder if -reindex-chainstate would've worked (should be faster).

  13. 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: 2026-04-21 21:15 UTC

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