Add logging to GetAncestor if pindex->pprev == NULL#9630
Add logging to GetAncestor if pindex->pprev == NULL#9630jnewbery wants to merge 1 commit intobitcoin:masterfrom
Conversation
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.
| } 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__); |
There was a problem hiding this comment.
This sounds like logic that belongs in LoadBlockIndex, not in the basic data structure logic.
|
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? |
|
Concept ACK but agree with the feedback. |
|
Closing this for now. I'll reopen once I've changed this to incorporate the feedback. |
|
Hello, i see this assertion error showing on a MessageBox ( i'm under Windows ): The logs seem not to be helpful. I have tried removing peers.dat , to no avail. What else can i try ? ....... 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/ . |
|
UPDATE: chkdsk did not help, but i got away with the -reindex wallet flag. |
|
@sleepndevelop I wonder if |
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.