diff --git a/server/block_processor.py b/server/block_processor.py index 23dffcd..12caf29 100644 --- a/server/block_processor.py +++ b/server/block_processor.py @@ -16,7 +16,7 @@ from bisect import bisect_left from collections import defaultdict from functools import partial -from server.cache import FSCache, UTXOCache, NO_CACHE_ENTRY +from server.cache import UTXOCache, NO_CACHE_ENTRY from server.daemon import Daemon, DaemonError from lib.hash import hash_to_str from lib.tx import Deserializer @@ -315,6 +315,9 @@ class BlockProcessor(server.db.DB): self.last_flush = time.time() self.last_flush_tx_count = self.tx_count + # UTXO cache + self.utxo_cache = UTXOCache(self.get_tx_hash, self.db, self.coin) + # Log state self.logger.info('{}/{} height: {:,d} tx count: {:,d} ' 'flush count: {:,d} utxo flush count: {:,d} ' diff --git a/server/db.py b/server/db.py index 9215dbd..1415514 100644 --- a/server/db.py +++ b/server/db.py @@ -14,13 +14,12 @@ import os import struct from collections import namedtuple -from server.cache import FSCache, UTXOCache, NO_CACHE_ENTRY +from server.cache import FSCache, NO_CACHE_ENTRY from lib.util import LoggedClass from server.storage import open_db UTXO = namedtuple("UTXO", "tx_num tx_pos tx_hash height value") - class DB(LoggedClass): '''Simple wrapper of the backend database for querying. @@ -28,6 +27,9 @@ class DB(LoggedClass): it was shutdown uncleanly. ''' + class DBError(Exception): + pass + def __init__(self, env): super().__init__() self.env = env @@ -57,9 +59,6 @@ class DB(LoggedClass): self.get_tx_hash = self.fs_cache.get_tx_hash self.read_headers = self.fs_cache.read_headers - # UTXO cache - self.utxo_cache = UTXOCache(self.get_tx_hash, self.db, self.coin) - def init_state_from_db(self): if self.db.is_new: self.db_height = -1 @@ -73,9 +72,9 @@ class DB(LoggedClass): state = self.db.get(b'state') state = ast.literal_eval(state.decode()) if state['genesis'] != self.coin.GENESIS_HASH: - raise ChainError('DB genesis hash {} does not match coin {}' - .format(state['genesis_hash'], - self.coin.GENESIS_HASH)) + raise self.DBError('DB genesis hash {} does not match coin {}' + .format(state['genesis_hash'], + self.coin.GENESIS_HASH)) self.db_height = state['height'] self.db_tx_count = state['tx_count'] self.db_tip = state['tip'] @@ -143,7 +142,30 @@ class DB(LoggedClass): hash168 = None if 0 <= index <= 65535: idx_packed = struct.pack('