Skip to content

Commit

Permalink
Check for tip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Oct 9, 2024
1 parent 19e8fd9 commit 5438b53
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char> compactBegin;
std::vector<unsigned char> 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<unsigned char> compactBegin;
std::vector<unsigned char> 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) {
Expand Down

0 comments on commit 5438b53

Please sign in to comment.