Skip to content

Commit c753b29

Browse files
Only initialize chainstate once during startup
Fixes issue with reindexing corrupted block database
1 parent c462611 commit c753b29

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/init.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
15871587
LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)\n", nCoinCacheUsage * (1.0 / 1024 / 1024), nMempoolSizeMax * (1.0 / 1024 / 1024));
15881588

15891589
bool fLoaded = false;
1590+
bool fInitializedChainstate = false;
15901591
while (!fLoaded && !ShutdownRequested()) {
15911592
bool fReset = fReindex;
15921593
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
@@ -1600,7 +1601,10 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
16001601
const int64_t load_block_index_start_time = GetTimeMillis();
16011602
try {
16021603
LOCK(cs_main);
1603-
chainman.InitializeChainstate(*Assert(node.mempool));
1604+
if (!fInitializedChainstate) {
1605+
chainman.InitializeChainstate(*Assert(node.mempool));
1606+
fInitializedChainstate = true;
1607+
}
16041608
chainman.m_total_coinstip_cache = nCoinCacheUsage;
16051609
chainman.m_total_coinsdb_cache = nCoinDBCache;
16061610

0 commit comments

Comments
 (0)