Skip to content

Commit efe193f

Browse files
committed
Scan for better chains in ThreadImport
>>> based on bitcoin/bitcoin@316623f without switching to AcceptBlock in LoadExternalBlockFile, as we need to sequentially Accept and ActivateBestChain for PoS validation
1 parent 0aceea3 commit efe193f

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/consensus/zerocoin_verify.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "chainparams.h"
88
#include "consensus/consensus.h"
99
#include "guiinterface.h" // for ui_interface
10-
#include "init.h" // for ShutdownRequested()
1110
#include "invalid.h"
1211
#include "script/interpreter.h"
1312
#include "spork.h" // for sporkManager

src/init.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -689,11 +689,11 @@ struct CImportingNow {
689689
void ThreadImport(const std::vector<fs::path>& vImportFiles)
690690
{
691691
util::ThreadRename("pivx-loadblk");
692+
CImportingNow imp;
692693
ScheduleBatchPriority();
693694

694695
// -reindex
695696
if (fReindex) {
696-
CImportingNow imp;
697697
int nFile = 0;
698698
while (true) {
699699
FlatFilePos pos(nFile, 0);
@@ -720,7 +720,6 @@ void ThreadImport(const std::vector<fs::path>& vImportFiles)
720720
if (fs::exists(pathBootstrap)) {
721721
FILE* file = fsbridge::fopen(pathBootstrap, "rb");
722722
if (file) {
723-
CImportingNow imp;
724723
fs::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
725724
LogPrintf("Importing bootstrap.dat...\n");
726725
LoadExternalBlockFile(file);
@@ -734,7 +733,6 @@ void ThreadImport(const std::vector<fs::path>& vImportFiles)
734733
for (const fs::path& path : vImportFiles) {
735734
FILE* file = fsbridge::fopen(path, "rb");
736735
if (file) {
737-
CImportingNow imp;
738736
LogPrintf("Importing blocks file %s...\n", path.string());
739737
LoadExternalBlockFile(file);
740738
} else {
@@ -747,6 +745,13 @@ void ThreadImport(const std::vector<fs::path>& vImportFiles)
747745
StartShutdown();
748746
}
749747

748+
// scan for better chains in the block chain database, that are not yet connected in the active best chain
749+
CValidationState state;
750+
if (!ActivateBestChain(state)) {
751+
LogPrintf("Failed to connect best block");
752+
StartShutdown();
753+
}
754+
750755
// force UpdatedBlockTip to initialize nCachedBlockHeight for DS, MN payments and budgets
751756
// but don't call it directly to prevent triggering of other listeners like zmq etc.
752757
pEvoNotificationInterface->InitializeCurrentBlockTip();
@@ -1744,13 +1749,6 @@ bool AppInitMain()
17441749
if (gArgs.IsArgSet("-blocknotify"))
17451750
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
17461751

1747-
// scan for better chains in the block chain database, that are not yet connected in the active best chain
1748-
CValidationState state;
1749-
if (!ActivateBestChain(state)) {
1750-
strErrors << "Failed to connect best block";
1751-
StartShutdown();
1752-
return false;
1753-
}
17541752
// update g_best_block if needed
17551753
{
17561754
LOCK(g_best_block_mutex);

src/validation.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,7 +3122,8 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, CBlockInde
31223122
{
31233123
AssertLockHeld(cs_main);
31243124

3125-
CBlockIndex*& pindex = *ppindex;
3125+
CBlockIndex* pindexDummy = nullptr;
3126+
CBlockIndex*& pindex = ppindex ? *ppindex : pindexDummy;
31263127

31273128
const Consensus::Params& consensus = Params().GetConsensus();
31283129

@@ -3973,7 +3974,7 @@ bool LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp)
39733974
if (state.IsError())
39743975
break;
39753976
} else if (hash != Params().GetConsensus().hashGenesisBlock && mapBlockIndex[hash]->nHeight % 1000 == 0) {
3976-
LogPrintf("Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
3977+
LogPrint(BCLog::REINDEX, "Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
39773978
}
39783979

39793980
// Recursively process earlier encountered successors of this block
@@ -3986,7 +3987,7 @@ bool LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp)
39863987
while (range.first != range.second) {
39873988
std::multimap<uint256, FlatFilePos>::iterator it = range.first;
39883989
if (ReadBlockFromDisk(block, it->second)) {
3989-
LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
3990+
LogPrint(BCLog::REINDEX, "%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
39903991
head.ToString());
39913992
CValidationState dummy;
39923993
std::shared_ptr<const CBlock> block_ptr = std::make_shared<const CBlock>(block);

0 commit comments

Comments
 (0)