diff --git a/main.py b/main.py index 7611333..f44a109 100644 --- a/main.py +++ b/main.py @@ -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():