Repository: Chia-Network/chia-blockchain
File: chia/full_node/block_store.py (Python)

Code before:
        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 <= ? AND in_main_chain=1",
                (start, stop),
            ) as cursor:
                for row in await cursor.fetchall():
                    header_hash = bytes32(row[0])
                    block_record = BlockRecord.from_bytes(row[1])
                    ret[header_hash] = block_record

        return ret

    async def get_block_bytes_in_range(
        self,
        start: int,
        stop: int,
    ) -> list[bytes]:
        """
        Returns a list with all full blocks in range between start and stop
        if present. Only includes blocks in the main chain, in the current peak.
        No orphan blocks.
        """

        if self.db_wrapper.db_version != 2:
            raise RuntimeError("get_block_bytes_in_range requires 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",
                (start, stop),
            ) as cursor:
                rows: list[sqlite3.Row] = list(await cursor.fetchall())
                if len(rows) != (stop - start) + 1:
                    raise ValueError(f"Some blocks in range {start}-{stop} were not found.")
                return [decompress_blob(row[0]) for row in rows]

    async def get_peak(self) -> Optional[tuple[bytes32, uint32]]:
        async with self.db_wrapper.reader_no_transaction() as conn:
            async with conn.execute("SELECT hash FROM current_peak WHERE key = 0") as cursor:
                peak_row = await cursor.fetchone()
        if peak_row is None:
            return None
        async with self.db_wrapper.reader_no_transaction() as conn:
            async with conn.execute("SELECT height FROM full_blocks WHERE header_hash=?", (peak_row[0],)) as cursor:
                peak_height = await cursor.fetchone()
        if peak_height is None:
            return None
        return bytes32(peak_row[0]), uint32(peak_height[0])

    async def get_block_records_close_to_peak(
        self, blocks_n: int

Review comment (suggestion):
```suggestion
        assert self.db_wrapper.db_version == 2
```

Code after:
        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 <= ? AND in_main_chain=1",
                (start, stop),
            ) as cursor:
                for row in await cursor.fetchall():
                    header_hash = bytes32(row[0])
                    block_record = BlockRecord.from_bytes(row[1])
                    ret[header_hash] = block_record

        return ret

    async def get_block_bytes_in_range(
        self,
        start: int,
        stop: int,
    ) -> list[bytes]:
        """
        Returns a list with all full blocks in range between start and stop
        if present. Only includes blocks in the main chain, in the current peak.
        No orphan blocks.
        """

        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",
                (start, stop),
            ) as cursor:
                rows: list[sqlite3.Row] = list(await cursor.fetchall())
                if len(rows) != (stop - start) + 1:
                    raise ValueError(f"Some blocks in range {start}-{stop} were not found.")
                return [decompress_blob(row[0]) for row in rows]

    async def get_peak(self) -> Optional[tuple[bytes32, uint32]]:
        async with self.db_wrapper.reader_no_transaction() as conn:
            async with conn.execute("SELECT hash FROM current_peak WHERE key = 0") as cursor:
                peak_row = await cursor.fetchone()
        if peak_row is None:
            return None
        async with self.db_wrapper.reader_no_transaction() as conn:
            async with conn.execute("SELECT height FROM full_blocks WHERE header_hash=?", (peak_row[0],)) as cursor:
                peak_height = await cursor.fetchone()
        if peak_height is None:
            return None
        return bytes32(peak_row[0]), uint32(peak_height[0])

    async def get_block_records_close_to_peak(
        self, blocks_n: int
    ) -> tuple[dict[bytes32, BlockRecord], Optional[bytes32]]: