Skip to content

Commit

Permalink
add in_main_chain=1 to the SQL query, that just asks for heights
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Nov 26, 2024
1 parent 71893df commit 62b8643
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions chia/full_node/block_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ async def get_full_blocks_at(self, heights: list[uint32]) -> list[FullBlock]:
if len(heights) == 0:
return []

formatted_str = f'SELECT block from full_blocks WHERE height in ({"?," * (len(heights) - 1)}?)'
formatted_str = (
f'SELECT block from full_blocks WHERE in_main_chain=1 AND height in ({"?," * (len(heights) - 1)}?)'
)
async with self.db_wrapper.reader_no_transaction() as conn:
async with conn.execute(formatted_str, heights) as cursor:
ret: list[FullBlock] = []
Expand Down Expand Up @@ -445,7 +447,8 @@ async def get_block_records_in_range(
ret: dict[bytes32, BlockRecord] = {}
async with self.db_wrapper.reader_no_transaction() as conn:
async with conn.execute(
"SELECT header_hash,block_record FROM full_blocks WHERE height >= ? AND height <= ?",
"SELECT header_hash,block_record FROM full_blocks "
"WHERE height >= ? AND height <= ? AND in_main_chain=1",
(start, stop),
) as cursor:
for row in await cursor.fetchall():
Expand All @@ -468,7 +471,7 @@ async def get_block_bytes_in_range(
assert self.db_wrapper.db_version == 2
async with self.db_wrapper.reader_no_transaction() as conn:
async with conn.execute(
"SELECT block FROM full_blocks WHERE height >= ? AND height <= ? and in_main_chain=1",
"SELECT block FROM full_blocks WHERE height >= ? AND height <= ? AND in_main_chain=1",
(start, stop),
) as cursor:
rows: list[sqlite3.Row] = list(await cursor.fetchall())
Expand Down Expand Up @@ -504,7 +507,7 @@ async def get_block_records_close_to_peak(
ret: dict[bytes32, BlockRecord] = {}
async with self.db_wrapper.reader_no_transaction() as conn:
async with conn.execute(
"SELECT header_hash, block_record FROM full_blocks WHERE height >= ?",
"SELECT header_hash, block_record FROM full_blocks WHERE height >= ? AND in_main_chain=1",
(peak[1] - blocks_n,),
) as cursor:
for row in await cursor.fetchall():
Expand Down

0 comments on commit 62b8643

Please sign in to comment.