From 98cf4345e043dc7a56aaa74e551a384f4fcaf8eb Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sun, 9 Feb 2025 22:09:51 +1100 Subject: [PATCH] fix: Update get missing block --- main.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) 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():