Merge pull request #13 from ygd58/fix/block-height-off-by-one

fix: count genesis block in height calculation
This commit is contained in:
davidrusu 2026-04-24 20:05:24 +04:00 committed by GitHub
commit 0d8be039a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -120,15 +120,18 @@ class BlockRepository:
else:
# Parent not found anywhere
if block.slot == 0 or block.hash == chain_root_hash:
# Genesis block or chain root - no parent requirement
block.height = 0
# Genesis block or chain root - no parent requirement.
# Height starts at 1 to count the genesis block itself,
# so chain height = total number of blocks.
# See: https://github.com/logos-blockchain/logos-blockchain-block-explorer-template/issues/12
block.height = 1
parent_heights[block.hash] = block.height
resolved.add(block.hash)
made_progress = True
if block.hash == chain_root_hash:
logger.info(
f"Chain root block: hash={block.hash.hex()[:16]}..., "
f"slot={block.slot}, height=0"
f"slot={block.slot}, height=1"
)
else:
# Orphan block - parent doesn't exist

View File

@ -28,7 +28,7 @@ class FakeNodeApi(NodeApi):
lib="0" * 64,
tip="0" * 64,
slot=self.current_slot,
height=0,
height=1, # Genesis block counts as height 1
mode="Fake",
)