Skip to content

Conversation

TheBlueMatt
Copy link
Contributor

This is an alternative to #5078...instead of throwing when chainActive.Tip() is missing (breaking what has otherwise traditionally been a global assumption) we just wait until at least genesis has been imported (its always first).

@sipa
Copy link
Member

sipa commented Nov 8, 2014

I wonder what would happen if you start with -reindex but don't actually already have a blockchain locally. Or what if the genesis block entry on disk is broken.

Maybe it makes sense to wait for either the genesis block present, or the importing process to be finished.

@TheBlueMatt
Copy link
Contributor Author

If the import process finishes without genesis, then we have skipped the genesis-build and we should actually wipe chainstate or so.

@laanwj
Copy link
Member

laanwj commented Nov 12, 2014

Agreed on concept, but this looks fragile. Polling every 10 milliseconds is also suboptimal - if this really needs to happen in a thread I would prefer to use a condition variable.

Though as said in #5078 I'd prefer to split off the part of the import that looks for the Genesis block into a LocateGenesisBlock function. This would look in the first block file, look at the first block, and if it is not the Genesis block it would terminate. Waiting for the whole import to finish to detect that the genesis block is corrupt/missing would be suboptimal.

@sipa
Copy link
Member

sipa commented Nov 14, 2014

@TheBlueMatt Agree, I don't think this makes things worse.

@sipa
Copy link
Member

sipa commented Nov 18, 2014

@TheBlueMatt Actually, it does. -reindex without any datadir currently works as expected. I believe that the code here will end up in an infinite sleep loop.

@sipa
Copy link
Member

sipa commented Nov 18, 2014

Tested ACK.

I was wrong. Importing ends with a call to InitBlockIndex(), which fixes the no-genesis case in case nothing was imported.

@laanwj laanwj added the Bug label Dec 5, 2014
@@ -1238,6 +1238,8 @@ bool AppInit2(boost::thread_group& threadGroup)
vImportFiles.push_back(strFile);
}
threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles));
while (chainActive.Tip() == NULL) // Wait until ThreadImport has imported genesis
Copy link
Member

Choose a reason for hiding this comment

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

This should check for fRequestShutdown, otherwise the initialization is not interruptible while waiting here (which make take a long time if the genesis block is corrupted).

@TheBlueMatt
Copy link
Contributor Author

@laanwj I agree, but overcomplicating this stuff for the incredibly rare/strange case of having a corrupt genesis block (especially if it works in that case, even if not well)...probably not worth it. Anyway, I added a log print and a check to fRequestShutdown.

@laanwj laanwj merged commit ff09e31 into bitcoin:master Jan 26, 2015
laanwj added a commit that referenced this pull request Jan 26, 2015
ff09e31 sleep-wait on genesis block during init with -reindex (Matt Corallo)
@laanwj
Copy link
Member

laanwj commented Jan 26, 2015

Backported to 0.10 branch as c5044bc

laanwj pushed a commit that referenced this pull request Jan 26, 2015
@laanwj laanwj mentioned this pull request Feb 10, 2016
reddink pushed a commit to reddcoin-project/reddcoin-3.10 that referenced this pull request May 27, 2020
Rebased-From: ff09e31
Github-Pull: bitcoin#5243
(cherry picked from commit c5044bc)
@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.

3 participants