Skip to content

Fix incorrect block progress calculation in header download log#204

Merged
philippem merged 1 commit intoBlockstream:new-indexfrom
EddieHouston:fix/block-progress-calculation
Apr 7, 2026
Merged

Fix incorrect block progress calculation in header download log#204
philippem merged 1 commit intoBlockstream:new-indexfrom
EddieHouston:fix/block-progress-calculation

Conversation

@EddieHouston
Copy link
Copy Markdown
Collaborator

Summary

The downloaded X/Y block headers (Z%) log in get_all_headers uses tip_height as the denominator, but tip_height is 0-indexed while result.len() counts total headers. This causes:

  • Progress >100%: A chain with genesis (height 0) + one mined block (height 1) has 2 headers but tip_height=1, logging 2/1 (200%)
  • Division by zero: When only the genesis block exists, tip_height=0

The fix uses tip_height + 1 as the denominator, which matches the actual header count (0..=tip_height).

Fixes #197

  tip_height is 0-indexed, so the total header count is tip_height + 1.
  Using tip_height as the denominator caused >100% progress (e.g. 200%
  with 2 blocks) and division by zero when tip_height is 0.

  Fixes Blockstream#197
@philippem philippem merged commit 5852c0c into Blockstream:new-index Apr 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logs: Incorrect block progress calculation

3 participants