fix: Update get missing block

This commit is contained in:
Nathan Woodburn 2025-02-09 22:09:51 +11:00
parent 0a46dad1b7
commit 98cf4345e0
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

26
main.py
View File

@ -259,22 +259,22 @@ def getNodeHeight():
info = response.json()
return info["chain"]["height"]
def getFirstMissingBlock():
"""Finds missing block heights in the database."""
height = dbGet.execute("SELECT height FROM blocks ORDER BY height ASC")
heights = [row[0] for row in height]
def getFirstMissingBlock() -> int:
"""Finds the first missing block height in the database."""
# Fetch all existing block heights in ascending order
result = dbGet.query("SELECT height FROM blocks ORDER BY height ASC").result
heights = [row[0] for row in result]
if not heights:
return 0
return 0 # No blocks found, start from 0
block = 0
for i in heights:
if i == block:
block += 1
else:
return block
return block
# Find the first missing block height
for expected, actual in enumerate(heights):
if expected != actual:
return expected # First missing height found
return len(heights) # No missing block, return next expected height
async def main():