From eda888e57352037ab2e60f6ef90098b3ce23a157 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 6 Jul 2017 19:57:20 -0400 Subject: Fix some LoadChainTip-related init-order bugs. * Move the writing of fTxIndex to LoadBlockIndex - this fixes a bug introduced in d6af06d68aae985436cbc942f0d11078041d121b where InitBlockIndex was writing to fTxIndex which had not yet been checked (because LoadChainTip hadn't yet initialized the chainActive, which would otherwise have resulted in InitBlockIndex being a NOP), allowing you to modify -txindex without reindex, potentially corrupting your chainstate! * Rename InitBlockIndex to LoadGenesisBlock, which is now a more natural name for it. Also check mapBlockIndex instead of chainActive, fixing a bug where we'd write the genesis block out on every start. --- src/validation.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/validation.h') diff --git a/src/validation.h b/src/validation.h index a9f995abb8..3ce5023f0a 100644 --- a/src/validation.h +++ b/src/validation.h @@ -256,9 +256,10 @@ FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false); fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix); /** Import blocks from an external file */ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = NULL); -/** Initialize a new block tree database + block data on disk */ -bool InitBlockIndex(const CChainParams& chainparams); -/** Load the block tree and coins database from disk */ +/** Ensures we have a genesis block in the block tree, possibly writing one to disk. */ +bool LoadGenesisBlock(const CChainParams& chainparams); +/** Load the block tree and coins database from disk, + * initializing state if we're running with -reindex. */ bool LoadBlockIndex(const CChainParams& chainparams); /** Update the chain tip based on database information. */ void LoadChainTip(const CChainParams& chainparams); -- cgit v1.2.3 From b0f32497b873cd1eaf0be86f8e265355aa86174f Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 6 Jul 2017 20:00:11 -0400 Subject: More user-friendly error message if UTXO DB runs ahead of block DB This gives LoadChainTip a return value - allowing it to indicate that the UTXO DB ran ahead of the block DB. This just provides a nicer error message instead of the previous mysterious assert(!setBlockIndexCandidates.empty()) error. This also calls ActivateBestChain in case we just loaded the genesis block in LoadChainTip, avoiding relying on the ActivateBestChain in ThreadImport before continuing init process. --- src/validation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/validation.h') diff --git a/src/validation.h b/src/validation.h index 3ce5023f0a..b1d482cbfb 100644 --- a/src/validation.h +++ b/src/validation.h @@ -262,7 +262,7 @@ bool LoadGenesisBlock(const CChainParams& chainparams); * initializing state if we're running with -reindex. */ bool LoadBlockIndex(const CChainParams& chainparams); /** Update the chain tip based on database information. */ -void LoadChainTip(const CChainParams& chainparams); +bool LoadChainTip(const CChainParams& chainparams); /** Unload database information */ void UnloadBlockIndex(); /** Run an instance of the script checking thread */ -- cgit v1.2.3