From 642cdb47299e9ff9ca13c58afb929fca42fc2a7e Mon Sep 17 00:00:00 2001 From: Jouzo <15011228+Jouzo@users.noreply.github.com> Date: Thu, 10 Oct 2024 05:45:32 +0100 Subject: [PATCH] Check for tip (#3088) --- src/init.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 2d1b608c88..951c259948 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2049,22 +2049,24 @@ bool AppInitMain(InitInterfaces& interfaces) } } - // Prune based on checkpoints - auto &checkpoints = chainparams.Checkpoints().mapCheckpoints; - auto it = checkpoints.lower_bound(::ChainActive().Tip()->nHeight); - if (it != checkpoints.begin()) { - auto &[height, _] = *(--it); - std::vector compactBegin; - std::vector compactEnd; - PruneCheckpoint(*pcustomcsview, height, compactBegin, compactEnd); - if (!compactBegin.empty() && !compactEnd.empty()) { - pcustomcsview->Flush(); - pcustomcsDB->Flush(); - auto time = GetTimeMillis(); - pcustomcsDB->Compact(compactBegin, compactEnd); - compactBegin.clear(); - compactEnd.clear(); - LogPrint(BCLog::BENCH, " - DB compacting takes: %dms\n", GetTimeMillis() - time); + if (::ChainActive().Tip() != nullptr) { + // Prune based on checkpoints + auto &checkpoints = chainparams.Checkpoints().mapCheckpoints; + auto it = checkpoints.lower_bound(::ChainActive().Tip()->nHeight); + if (it != checkpoints.begin()) { + auto &[height, _] = *(--it); + std::vector compactBegin; + std::vector compactEnd; + PruneCheckpoint(*pcustomcsview, height, compactBegin, compactEnd); + if (!compactBegin.empty() && !compactEnd.empty()) { + pcustomcsview->Flush(); + pcustomcsDB->Flush(); + auto time = GetTimeMillis(); + pcustomcsDB->Compact(compactBegin, compactEnd); + compactBegin.clear(); + compactEnd.clear(); + LogPrint(BCLog::BENCH, " - DB compacting takes: %dms\n", GetTimeMillis() - time); + } } } } catch (const std::exception& e) {