@@ -231,25 +231,6 @@ def rollback_cache_block(self, header_hash: bytes32) -> None:
231231 # block to the cache yet
232232 pass
233233
234- async def get_prev_hash (self , header_hash : bytes32 ) -> bytes32 :
235- """
236- Returns the header hash preceeding the input header hash.
237- Throws an exception if the block is not present
238- """
239- cached = self .block_cache .get (header_hash )
240- if cached is not None :
241- return cached .prev_header_hash
242-
243- async with self .db_wrapper .reader_no_transaction () as conn :
244- async with conn .execute (
245- "SELECT prev_hash FROM full_blocks WHERE header_hash=?" ,
246- (header_hash ,),
247- ) as cursor :
248- row = await cursor .fetchone ()
249- if row is None :
250- raise KeyError ("missing block in chain" )
251- return bytes32 (row [0 ])
252-
253234 async def get_full_block (self , header_hash : bytes32 ) -> Optional [FullBlock ]:
254235 cached : Optional [FullBlock ] = self .block_cache .get (header_hash )
255236 if cached is not None :
@@ -397,6 +378,25 @@ async def get_block_records_by_hash(self, header_hashes: list[bytes32]) -> list[
397378 ret .append (all_blocks [hh ])
398379 return ret
399380
381+ async def get_prev_hash (self , header_hash : bytes32 ) -> bytes32 :
382+ """
383+ Returns the header hash preceeding the input header hash.
384+ Throws an exception if the block is not present
385+ """
386+ cached = self .block_cache .get (header_hash )
387+ if cached is not None :
388+ return cached .prev_header_hash
389+
390+ async with self .db_wrapper .reader_no_transaction () as conn :
391+ async with conn .execute (
392+ "SELECT prev_hash FROM full_blocks WHERE header_hash=?" ,
393+ (header_hash ,),
394+ ) as cursor :
395+ row = await cursor .fetchone ()
396+ if row is None :
397+ raise KeyError ("missing block in chain" )
398+ return bytes32 (row [0 ])
399+
400400 async def get_block_bytes_by_hash (self , header_hashes : list [bytes32 ]) -> list [bytes ]:
401401 """
402402 Returns a list of Full Blocks block blobs, ordered by the same order in which header_hashes are passed in.
0 commit comments