|
13 | 13 | from chia_rs.sized_ints import uint32 |
14 | 14 |
|
15 | 15 | from chia.full_node.full_block_utils import GeneratorBlockInfo, block_info_from_block, generator_from_block |
| 16 | +from chia.util.batches import to_batches |
16 | 17 | from chia.util.db_wrapper import DBWrapper2, execute_fetchone |
17 | 18 | from chia.util.errors import Err |
18 | 19 | from chia.util.lru_cache import LRUCache |
@@ -190,9 +191,6 @@ async def get_sub_epoch_challenge_segments( |
190 | 191 | return challenge_segments |
191 | 192 | return None |
192 | 193 |
|
193 | | - def get_host_parameter_limit(self) -> int: |
194 | | - return self.db_wrapper.host_parameter_limit |
195 | | - |
196 | 194 | def transaction(self) -> AbstractAsyncContextManager[Any]: |
197 | 195 | return self.db_wrapper.writer() |
198 | 196 |
|
@@ -332,20 +330,21 @@ async def get_block_records_by_hash(self, header_hashes: list[bytes32]) -> list[ |
332 | 330 | Returns a list of Block Records, ordered by the same order in which header_hashes are passed in. |
333 | 331 | Throws an exception if the blocks are not present |
334 | 332 | """ |
| 333 | + |
335 | 334 | if len(header_hashes) == 0: |
336 | 335 | return [] |
337 | 336 |
|
338 | 337 | all_blocks: dict[bytes32, BlockRecord] = {} |
339 | | - async with self.db_wrapper.reader_no_transaction() as conn: |
340 | | - async with conn.execute( |
341 | | - "SELECT header_hash,block_record " |
342 | | - "FROM full_blocks " |
343 | | - f"WHERE header_hash in ({'?,' * (len(header_hashes) - 1)}?)", |
344 | | - header_hashes, |
345 | | - ) as cursor: |
346 | | - for row in await cursor.fetchall(): |
347 | | - block_rec = BlockRecord.from_bytes(row[1]) |
348 | | - all_blocks[block_rec.header_hash] = block_rec |
| 338 | + for batch in to_batches(header_hashes, self.db_wrapper.host_parameter_limit): |
| 339 | + async with self.db_wrapper.reader_no_transaction() as conn: |
| 340 | + async with conn.execute( |
| 341 | + "SELECT header_hash,block_record FROM full_blocks " |
| 342 | + f"WHERE header_hash in ({'?,' * (len(batch.entries) - 1)}?)", |
| 343 | + batch.entries, |
| 344 | + ) as cursor: |
| 345 | + for row in await cursor.fetchall(): |
| 346 | + block_rec = BlockRecord.from_bytes(row[1]) |
| 347 | + all_blocks[block_rec.header_hash] = block_rec |
349 | 348 |
|
350 | 349 | ret: list[BlockRecord] = [] |
351 | 350 | for hh in header_hashes: |
|
0 commit comments