Skip to content

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

Closed
jnewbery wants to merge 1 commit intobitcoin:masterfrom
jnewbery:crashlogging
Closed

Add logging to GetAncestor if pindex->pprev == NULL#9630
jnewbery wants to merge 1 commit intobitcoin:masterfrom
jnewbery:crashlogging

Conversation

@jnewbery
Copy link
Copy Markdown
Contributor

84c13e7 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.

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.
Comment thread src/chain.cpp
} else if (pindexWalk->pprev == NULL) {
// pindexWalk should always have a parent (since pindexWalk is not the genesis block)
LogPrintf("%s: Block index is missing a block. Block %s, height %d has no parent.\n", __func__, pindexWalk->GetBlockHash().ToString(), heightWalk);
LogPrintf("%s: Run bitcoin with -reindex to rebuild the block index. This will redownload the entire blockchain if running a pruned node.\n", __func__);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@laanwj
Copy link
Copy Markdown
Member

laanwj commented Jan 26, 2017

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?

@jnewbery
Copy link
Copy Markdown
Contributor Author

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

@fanquake fanquake added the Docs label Jan 27, 2017
@jtimon
Copy link
Copy Markdown
Contributor

jtimon commented Mar 18, 2017

Concept ACK but agree with the feedback.

@jnewbery
Copy link
Copy Markdown
Contributor Author

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

@jnewbery jnewbery closed this Mar 30, 2017
@php-wizard
Copy link
Copy Markdown

php-wizard commented Jan 16, 2018

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
.......

@php-wizard
Copy link
Copy Markdown

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

@andrade
Copy link
Copy Markdown

andrade commented May 3, 2018

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

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

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants