eth-cache

Ethereum chain data caching tools
Info | Log | Files | Refs | LICENSE

commit 167def47b6b1136085fd3901a345fa9ff564dcb1
parent 0bbe05347f46550d994d3b3b41b19b53031691f6
Author: lash <dev@holbrook.no>
Date:   Sat,  6 Jul 2024 15:56:51 +0100

Handle missing results from lmdb backend

Diffstat:
Meth_cache/store/lmdb.py | 20+++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/eth_cache/store/lmdb.py b/eth_cache/store/lmdb.py @@ -55,17 +55,25 @@ class LmdbStore(FsStore): def get_tx(self, tx_hash): + tx = None k = bytes.fromhex(tx_hash) k = to_path_key(StoreAction.TX.value, k) with self.db.begin() as dbtx: - return dbtx.get(k) + tx = dbtx.get(k) + if tx == None: + raise FileNotFoundError(tx_hash) + return tx def get_rcpt(self, tx_hash): + rcpt = None k = bytes.fromhex(tx_hash) k = to_path_key(StoreAction.RCPT.value, k) with self.db.begin() as dbtx: - return dbtx.get(k) + rcpt = dbtx.get(k) + if rcpt == None: + raise FileNotFoundError(tx_hash) + return rcpt def get_block(self, block_hash): @@ -76,12 +84,18 @@ class LmdbStore(FsStore): def get_block_number(self, block_number): + block =None r = None k = block_number.to_bytes(8, byteorder='big') k = to_path_key(StoreAction.BLOCK_NUM.value, k) with self.db.begin() as dbtx: r = dbtx.get(k) - return self.get_block(r.hex()) + try: + block = self.get_block(r.hex()) + except AttributeError: + raise FileNotFoundError(str(block_number)) + + return block def get_address_tx(self, address):