From c8b2e4426b78e63c0e9565688192963331221984 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 4 Dec 2012 23:46:30 +0100 Subject: [PATCH 1/2] Update the block file counter in database when using -reindex This problem is like earth (mostly harmless). After/during a -reindex, it means the statistics about the last block file reported in debug.log are always of blk00000.dat instead of the last file. Apart from that, it means a few more database entries need to be read when finding a file to append to the first time. --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index ed03414173..0e0be2f01e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1897,6 +1897,7 @@ bool FindBlockPos(CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeigh nLastBlockFile = pos.nFile; infoLastBlockFile.SetNull(); pblocktree->ReadBlockFileInfo(nLastBlockFile, infoLastBlockFile); + fUpdatedLast = true; } } else { while (infoLastBlockFile.nSize + nAddSize >= MAX_BLOCKFILE_SIZE) { From 3fb9b99cca390e8ac5838c03363c46a99396e463 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 4 Dec 2012 23:53:26 +0100 Subject: [PATCH 2/2] Allow lengthy block reconnections to be interrupted When the coin database is out of date with the block database, the best block in it is automatically switched to. This reconnection process can take time, so allow it to be interrupted. This also stops block connection as soon as shutdown is requested, leading to a faster shutdown. --- src/init.cpp | 8 ++++---- src/main.cpp | 7 +++++-- src/util.cpp | 2 +- src/util.h | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index a224b336ce..b68ca1cf1a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -345,7 +345,7 @@ void ThreadImport(void *data) { if (fReindex) { CImportingNow imp; int nFile = 0; - while (!fShutdown) { + while (!fRequestShutdown) { CDiskBlockPos pos(nFile, 0); FILE *file = OpenBlockFile(pos, true); if (!file) @@ -354,7 +354,7 @@ void ThreadImport(void *data) { LoadExternalBlockFile(file, &pos); nFile++; } - if (!fShutdown) { + if (!fRequestShutdown) { pblocktree->WriteReindexing(false); fReindex = false; printf("Reindexing finished\n"); @@ -363,7 +363,7 @@ void ThreadImport(void *data) { // hardcoded $DATADIR/bootstrap.dat filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat"; - if (filesystem::exists(pathBootstrap) && !fShutdown) { + if (filesystem::exists(pathBootstrap) && !fRequestShutdown) { FILE *file = fopen(pathBootstrap.string().c_str(), "rb"); if (file) { CImportingNow imp; @@ -376,7 +376,7 @@ void ThreadImport(void *data) { // -loadblock= BOOST_FOREACH(boost::filesystem::path &path, import->vFiles) { - if (fShutdown) + if (fRequestShutdown) break; FILE *file = fopen(path.string().c_str(), "rb"); if (file) { diff --git a/src/main.cpp b/src/main.cpp index 0e0be2f01e..158c94783c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1240,9 +1240,12 @@ bool ConnectBestBlock() { if (pindexTest->pprev == NULL || pindexTest->pnext != NULL) { reverse(vAttach.begin(), vAttach.end()); - BOOST_FOREACH(CBlockIndex *pindexSwitch, vAttach) + BOOST_FOREACH(CBlockIndex *pindexSwitch, vAttach) { + if (fRequestShutdown) + break; if (!SetBestChain(pindexSwitch)) return false; + } return true; } pindexTest = pindexTest->pprev; @@ -2553,7 +2556,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) } } uint64 nRewind = blkdat.GetPos(); - while (blkdat.good() && !blkdat.eof() && !fShutdown) { + while (blkdat.good() && !blkdat.eof() && !fRequestShutdown) { blkdat.SetPos(nRewind); nRewind++; // start one byte further next time, in case of failure blkdat.SetLimit(); // remove former limit diff --git a/src/util.cpp b/src/util.cpp index bd8ad8acd0..3cbc6b196b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -64,7 +64,7 @@ bool fDebug = false; bool fDebugNet = false; bool fPrintToConsole = false; bool fPrintToDebugger = false; -bool fRequestShutdown = false; +volatile bool fRequestShutdown = false; bool fShutdown = false; bool fDaemon = false; bool fServer = false; diff --git a/src/util.h b/src/util.h index ada0dd3790..d8203b58ee 100644 --- a/src/util.h +++ b/src/util.h @@ -132,7 +132,7 @@ extern bool fDebug; extern bool fDebugNet; extern bool fPrintToConsole; extern bool fPrintToDebugger; -extern bool fRequestShutdown; +extern volatile bool fRequestShutdown; extern bool fShutdown; extern bool fDaemon; extern bool fServer;