fix: Update get missing block
This commit is contained in:
parent
0a46dad1b7
commit
98cf4345e0
26
main.py
26
main.py
@ -259,22 +259,22 @@ def getNodeHeight():
|
|||||||
info = response.json()
|
info = response.json()
|
||||||
return info["chain"]["height"]
|
return info["chain"]["height"]
|
||||||
|
|
||||||
|
def getFirstMissingBlock() -> int:
|
||||||
def getFirstMissingBlock():
|
"""Finds the first missing block height in the database."""
|
||||||
"""Finds missing block heights in the database."""
|
|
||||||
height = dbGet.execute("SELECT height FROM blocks ORDER BY height ASC")
|
# Fetch all existing block heights in ascending order
|
||||||
heights = [row[0] for row in height]
|
result = dbGet.query("SELECT height FROM blocks ORDER BY height ASC").result
|
||||||
|
heights = [row[0] for row in result]
|
||||||
|
|
||||||
if not heights:
|
if not heights:
|
||||||
return 0
|
return 0 # No blocks found, start from 0
|
||||||
|
|
||||||
block = 0
|
# Find the first missing block height
|
||||||
for i in heights:
|
for expected, actual in enumerate(heights):
|
||||||
if i == block:
|
if expected != actual:
|
||||||
block += 1
|
return expected # First missing height found
|
||||||
else:
|
|
||||||
return block
|
return len(heights) # No missing block, return next expected height
|
||||||
return block
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
Loading…
Reference in New Issue
Block a user