|
3 | 3 | import dataclasses |
4 | 4 | import logging |
5 | 5 | import sqlite3 |
| 6 | +from contextlib import AbstractAsyncContextManager |
6 | 7 | from typing import Optional |
7 | 8 |
|
8 | 9 | import typing_extensions |
@@ -396,25 +397,6 @@ async def get_block_records_by_hash(self, header_hashes: list[bytes32]) -> list[ |
396 | 397 | ret.append(all_blocks[hh]) |
397 | 398 | return ret |
398 | 399 |
|
399 | | - async def get_prev_hash(self, header_hash: bytes32) -> bytes32: |
400 | | - """ |
401 | | - Returns the header hash preceeding the input header hash. |
402 | | - Throws an exception if the block is not present |
403 | | - """ |
404 | | - cached = self.block_cache.get(header_hash) |
405 | | - if cached is not None: |
406 | | - return cached.prev_header_hash |
407 | | - |
408 | | - async with self.db_wrapper.reader_no_transaction() as conn: |
409 | | - async with conn.execute( |
410 | | - "SELECT prev_hash FROM full_blocks WHERE header_hash=?", |
411 | | - (header_hash,), |
412 | | - ) as cursor: |
413 | | - row = await cursor.fetchone() |
414 | | - if row is None: |
415 | | - raise KeyError("missing block in chain") |
416 | | - return bytes32(row[0]) |
417 | | - |
418 | 400 | async def get_block_bytes_by_hash(self, header_hashes: list[bytes32]) -> list[bytes]: |
419 | 401 | """ |
420 | 402 | Returns a list of Full Blocks block blobs, ordered by the same order in which header_hashes are passed in. |
@@ -545,30 +527,6 @@ async def get_peak(self) -> Optional[tuple[bytes32, uint32]]: |
545 | 527 | return None |
546 | 528 | return bytes32(peak_row[0]), uint32(peak_height[0]) |
547 | 529 |
|
548 | | - async def get_block_records_close_to_peak( |
549 | | - self, blocks_n: int |
550 | | - ) -> tuple[dict[bytes32, BlockRecord], Optional[bytes32]]: |
551 | | - """ |
552 | | - Returns a dictionary with all blocks that have height >= peak height - blocks_n, as well as the |
553 | | - peak header hash. Only blocks that are part of the main chain/current peak are included. |
554 | | - """ |
555 | | - |
556 | | - peak = await self.get_peak() |
557 | | - if peak is None: |
558 | | - return {}, None |
559 | | - |
560 | | - ret: dict[bytes32, BlockRecord] = {} |
561 | | - async with self.db_wrapper.reader_no_transaction() as conn: |
562 | | - async with conn.execute( |
563 | | - "SELECT header_hash, block_record FROM full_blocks WHERE height >= ? AND in_main_chain=1", |
564 | | - (peak[1] - blocks_n,), |
565 | | - ) as cursor: |
566 | | - for row in await cursor.fetchall(): |
567 | | - header_hash = bytes32(row[0]) |
568 | | - ret[header_hash] = BlockRecord.from_bytes(row[1]) |
569 | | - |
570 | | - return ret, peak[0] |
571 | | - |
572 | 530 | async def set_peak(self, header_hash: bytes32) -> None: |
573 | 531 | # We need to be in a sqlite transaction here. |
574 | 532 | # Note: we do not commit this to the database yet, as we need to also change the coin store |
|
0 commit comments