Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PruneCheckpoint on genesis block #3088

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading