mirror of
https://github.com/logos-blockchain/logos-blockchain-block-explorer-template.git
synced 2026-05-18 07:19:27 +00:00
Merge pull request #13 from ygd58/fix/block-height-off-by-one
fix: count genesis block in height calculation
This commit is contained in:
commit
0d8be039a5
@ -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
|
||||
|
||||
@ -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",
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user