Switch reindexing to AcceptBlock in-loop and ActivateBestChain afterwards
This commit is contained in:
parent
d253ec4baa
commit
316623f2c1
2 changed files with 18 additions and 15 deletions
20
src/init.cpp
20
src/init.cpp
|
@ -404,7 +404,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||||
strUsage += HelpMessageOpt("-limitdescendantcount=<n>", strprintf("Do not accept transactions if any ancestor would have <n> or more in-mempool descendants (default: %u)", DEFAULT_DESCENDANT_LIMIT));
|
strUsage += HelpMessageOpt("-limitdescendantcount=<n>", strprintf("Do not accept transactions if any ancestor would have <n> or more in-mempool descendants (default: %u)", DEFAULT_DESCENDANT_LIMIT));
|
||||||
strUsage += HelpMessageOpt("-limitdescendantsize=<n>", strprintf("Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT));
|
strUsage += HelpMessageOpt("-limitdescendantsize=<n>", strprintf("Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT));
|
||||||
}
|
}
|
||||||
string debugCategories = "addrman, alert, bench, coindb, db, lock, rand, rpc, selectcoins, mempool, mempoolrej, net, proxy, prune, http, libevent, tor, zmq"; // Don't translate these and qt below
|
string debugCategories = "addrman, alert, bench, coindb, db, http, libevent, lock, mempool, mempoolrej, net, proxy, prune, rand, reindex, rpc, selectcoins, tor, zmq"; // Don't translate these and qt below
|
||||||
if (mode == HMM_BITCOIN_QT)
|
if (mode == HMM_BITCOIN_QT)
|
||||||
debugCategories += ", qt";
|
debugCategories += ", qt";
|
||||||
strUsage += HelpMessageOpt("-debug=<category>", strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + ". " +
|
strUsage += HelpMessageOpt("-debug=<category>", strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + ". " +
|
||||||
|
@ -554,9 +554,10 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
|
||||||
{
|
{
|
||||||
const CChainParams& chainparams = Params();
|
const CChainParams& chainparams = Params();
|
||||||
RenameThread("bitcoin-loadblk");
|
RenameThread("bitcoin-loadblk");
|
||||||
|
CImportingNow imp;
|
||||||
|
|
||||||
// -reindex
|
// -reindex
|
||||||
if (fReindex) {
|
if (fReindex) {
|
||||||
CImportingNow imp;
|
|
||||||
int nFile = 0;
|
int nFile = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
CDiskBlockPos pos(nFile, 0);
|
CDiskBlockPos pos(nFile, 0);
|
||||||
|
@ -581,7 +582,6 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
|
||||||
if (boost::filesystem::exists(pathBootstrap)) {
|
if (boost::filesystem::exists(pathBootstrap)) {
|
||||||
FILE *file = fopen(pathBootstrap.string().c_str(), "rb");
|
FILE *file = fopen(pathBootstrap.string().c_str(), "rb");
|
||||||
if (file) {
|
if (file) {
|
||||||
CImportingNow imp;
|
|
||||||
boost::filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
|
boost::filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
|
||||||
LogPrintf("Importing bootstrap.dat...\n");
|
LogPrintf("Importing bootstrap.dat...\n");
|
||||||
LoadExternalBlockFile(chainparams, file);
|
LoadExternalBlockFile(chainparams, file);
|
||||||
|
@ -595,7 +595,6 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
|
||||||
BOOST_FOREACH(const boost::filesystem::path& path, vImportFiles) {
|
BOOST_FOREACH(const boost::filesystem::path& path, vImportFiles) {
|
||||||
FILE *file = fopen(path.string().c_str(), "rb");
|
FILE *file = fopen(path.string().c_str(), "rb");
|
||||||
if (file) {
|
if (file) {
|
||||||
CImportingNow imp;
|
|
||||||
LogPrintf("Importing blocks file %s...\n", path.string());
|
LogPrintf("Importing blocks file %s...\n", path.string());
|
||||||
LoadExternalBlockFile(chainparams, file);
|
LoadExternalBlockFile(chainparams, file);
|
||||||
} else {
|
} else {
|
||||||
|
@ -603,6 +602,13 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// scan for better chains in the block chain database, that are not yet connected in the active best chain
|
||||||
|
CValidationState state;
|
||||||
|
if (!ActivateBestChain(state, chainparams)) {
|
||||||
|
LogPrintf("Failed to connect best block");
|
||||||
|
StartShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
if (GetBoolArg("-stopafterblockimport", DEFAULT_STOPAFTERBLOCKIMPORT)) {
|
if (GetBoolArg("-stopafterblockimport", DEFAULT_STOPAFTERBLOCKIMPORT)) {
|
||||||
LogPrintf("Stopping after block import\n");
|
LogPrintf("Stopping after block import\n");
|
||||||
StartShutdown();
|
StartShutdown();
|
||||||
|
@ -1358,12 +1364,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||||
if (mapArgs.count("-blocknotify"))
|
if (mapArgs.count("-blocknotify"))
|
||||||
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
|
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
|
||||||
|
|
||||||
uiInterface.InitMessage(_("Activating best chain..."));
|
|
||||||
// scan for better chains in the block chain database, that are not yet connected in the active best chain
|
|
||||||
CValidationState state;
|
|
||||||
if (!ActivateBestChain(state, chainparams))
|
|
||||||
strErrors << "Failed to connect best block";
|
|
||||||
|
|
||||||
std::vector<boost::filesystem::path> vImportFiles;
|
std::vector<boost::filesystem::path> vImportFiles;
|
||||||
if (mapArgs.count("-loadblock"))
|
if (mapArgs.count("-loadblock"))
|
||||||
{
|
{
|
||||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -3402,7 +3402,8 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
|
|
||||||
CBlockIndex *&pindex = *ppindex;
|
CBlockIndex *pindexDummy = NULL;
|
||||||
|
CBlockIndex *&pindex = ppindex ? *ppindex : pindexDummy;
|
||||||
|
|
||||||
if (!AcceptBlockHeader(block, state, chainparams, &pindex))
|
if (!AcceptBlockHeader(block, state, chainparams, &pindex))
|
||||||
return false;
|
return false;
|
||||||
|
@ -4037,13 +4038,14 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
|
||||||
|
|
||||||
// process in case the block isn't known yet
|
// process in case the block isn't known yet
|
||||||
if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) {
|
if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) {
|
||||||
|
LOCK(cs_main);
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
if (ProcessNewBlock(state, chainparams, NULL, &block, true, dbp))
|
if (AcceptBlock(block, state, chainparams, NULL, true, dbp))
|
||||||
nLoaded++;
|
nLoaded++;
|
||||||
if (state.IsError())
|
if (state.IsError())
|
||||||
break;
|
break;
|
||||||
} else if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex[hash]->nHeight % 1000 == 0) {
|
} else if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex[hash]->nHeight % 1000 == 0) {
|
||||||
LogPrintf("Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
|
LogPrint("reindex", "Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively process earlier encountered successors of this block
|
// Recursively process earlier encountered successors of this block
|
||||||
|
@ -4057,10 +4059,11 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
|
||||||
std::multimap<uint256, CDiskBlockPos>::iterator it = range.first;
|
std::multimap<uint256, CDiskBlockPos>::iterator it = range.first;
|
||||||
if (ReadBlockFromDisk(block, it->second, chainparams.GetConsensus()))
|
if (ReadBlockFromDisk(block, it->second, chainparams.GetConsensus()))
|
||||||
{
|
{
|
||||||
LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
|
LogPrint("reindex", "%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
|
||||||
head.ToString());
|
head.ToString());
|
||||||
|
LOCK(cs_main);
|
||||||
CValidationState dummy;
|
CValidationState dummy;
|
||||||
if (ProcessNewBlock(dummy, chainparams, NULL, &block, true, &it->second))
|
if (AcceptBlock(block, dummy, chainparams, NULL, true, &it->second))
|
||||||
{
|
{
|
||||||
nLoaded++;
|
nLoaded++;
|
||||||
queue.push_back(block.GetHash());
|
queue.push_back(block.GetHash());
|
||||||
|
|
Loading…
Reference in a new issue