Skip to content

bugfix: truncate header sync percentage#935

Open
arejula27 wants to merge 1 commit into
bitcoin-core:masterfrom
arejula27:gui-ibd-fix-header-sync-percentage
Open

bugfix: truncate header sync percentage#935
arejula27 wants to merge 1 commit into
bitcoin-core:masterfrom
arejula27:gui-ibd-fix-header-sync-percentage

Conversation

@arejula27
Copy link
Copy Markdown

During IBD, if LoadingBlocks() is true (e.g. during a chainstate rebuild after a crash), the node rejects incoming headers from peers. The GUI has headers loaded from the block index on disk, but bestHeaderDate becomes stale over time.

After ~4 hours (HEADER_HEIGHT_DELTA_SYNC * nPowTargetSpacing), the time-based heuristic in modaloverlay.cpp considers headers as "not synced" and falls into the else branch, displaying "Unknown" for both blocks remaining and estimated time. Meanwhile, UpdateHeaderSyncLabel() computes a percentage that rounds up to 100.0%, creating a contradictory display: "Unknown. Syncing Headers (942188, 100.0%)". Please read issue #65 for more context.

This patch truncates the percentage to one decimal place instead of rounding, so it only shows 100.0% when headers are truly up to date. The same fix is applied to
UpdateHeaderPresyncLabel() for consistency.

Fixes #65 .

@DrahtBot
Copy link
Copy Markdown
Contributor

DrahtBot commented Mar 28, 2026

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Comment thread src/qt/modaloverlay.cpp Outdated
Comment on lines +168 to +171
double pct = 100.0 * bestHeaderHeight / (bestHeaderHeight + est_headers_left);
// Truncate to one decimal place to avoid displaying 100.0% when headers are still missing
pct = std::floor(pct * 10.0) / 10.0;
ui->numberOfBlocksLeft->setText(tr("Unknown. Syncing Headers (%1, %2%)…").arg(bestHeaderHeight).arg(QString::number(pct, 'f', 1)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
double pct = 100.0 * bestHeaderHeight / (bestHeaderHeight + est_headers_left);
// Truncate to one decimal place to avoid displaying 100.0% when headers are still missing
pct = std::floor(pct * 10.0) / 10.0;
ui->numberOfBlocksLeft->setText(tr("Unknown. Syncing Headers (%1, %2%)…").arg(bestHeaderHeight).arg(QString::number(pct, 'f', 1)));
const int pct = bestHeaderHeight ? static_cast<int>(1000LL * bestHeaderHeight / (bestHeaderHeight + est_headers_left)) : 0;
ui->numberOfBlocksLeft->setText(tr("Unknown. Syncing Headers (%1, %2%)…").arg(bestHeaderHeight).arg(QStringLiteral("%1.%2").arg(pct / 10).arg(pct % 10)));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, i guess it is more efficient as we do not work with floats, right?

luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Apr 13, 2026
…e stale

Github-Pull: bitcoin-core/gui#935
Rewritten-From: 13b1c9dc4cf5d3e297ee5487dba5f587af8583d3 (plus logged percentages)
@Sjors
Copy link
Copy Markdown
Member

Sjors commented May 8, 2026

@hebasto can you add a bug label to this PR and other bug fixes? That makes it easier to track them (e.g. with RSS feed).

@sedited sedited added the Bug Something isn't working label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GUI misses some header updates when in IBD

5 participants