From 4ead850fe54ae0bdfb4b3724cbefb3425a16b74a Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 29 Oct 2014 17:01:01 -0700 Subject: [PATCH 1/3] Fix for crash during block download --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 008a0591032..0506a7f598c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1739,9 +1739,9 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C } // Update the on-disk chain state. -bool static WriteChainState(CValidationState &state) { +bool static WriteChainState(CValidationState &state, bool forceWrite=false) { static int64_t nLastWrite = 0; - if (pcoinsTip->GetCacheSize() > nCoinCacheSize || (!IsInitialBlockDownload() && GetTimeMicros() > nLastWrite + 600*1000000)) { + if (forceWrite || pcoinsTip->GetCacheSize() > nCoinCacheSize || (!IsInitialBlockDownload() && GetTimeMicros() > nLastWrite + 600*1000000)) { // Typical CCoins structures on disk are around 100 bytes in size. // Pushing a new one to the database can cause it to be written // twice (once in the log, and once in the tables). This is already @@ -2999,6 +2999,8 @@ bool InitBlockIndex() { return error("LoadBlockIndex() : genesis block not accepted"); if (!ActivateBestChain(state, &block)) return error("LoadBlockIndex() : genesis block cannot be activated"); + // Force a chainstate write so that when we VerifyDB in a moment, it doesnt check stale data + return WriteChainState(state, true); } catch(std::runtime_error &e) { return error("LoadBlockIndex() : failed to initialize block database: %s", e.what()); } From 8375e2215f24ff4b92c634d2dc56898e9cda437b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 29 Oct 2014 17:01:18 -0700 Subject: [PATCH 2/3] Fix -loadblock after shutdown during IBD --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 0506a7f598c..238b0400ea0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3136,7 +3136,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) } // process in case the block isn't known yet - if (mapBlockIndex.count(hash) == 0) { + if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) { CValidationState state; if (ProcessBlock(state, NULL, &block, dbp)) nLoaded++; From 50b43fda08afeeaf22e0ad991a9885ee078a7c78 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 29 Oct 2014 17:02:48 -0700 Subject: [PATCH 3/3] Be a bit more verbose during -loadblock if we already have blocks --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 238b0400ea0..5302f0bcb45 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3142,6 +3142,8 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) nLoaded++; if (state.IsError()) break; + } else if (hash != Params().HashGenesisBlock() && mapBlockIndex[hash]->nHeight % 1000 == 0) { + LogPrintf("Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight); } // Recursively process earlier encountered successors of this block