diff --git a/teos/responder.py b/teos/responder.py index a5d6843..862733f 100644 --- a/teos/responder.py +++ b/teos/responder.py @@ -259,6 +259,7 @@ class Responder: # Distinguish fresh bootstraps from bootstraps from db if self.last_known_block is None: self.last_known_block = self.block_processor.get_best_block_hash() + self.db_manager.store_last_block_hash_responder(self.last_known_block) while True: block_hash = self.block_queue.get() diff --git a/teos/watcher.py b/teos/watcher.py index bb02ff7..f5e7cf8 100644 --- a/teos/watcher.py +++ b/teos/watcher.py @@ -54,6 +54,7 @@ class Watcher: signing_key (:mod:`PrivateKey`): a private key used to sign accepted appointments. max_appointments (:obj:`int`): the maximum amount of appointments accepted by the ``Watcher`` at the same time. expiry_delta (:obj:`int`): the additional time the ``Watcher`` will keep an expired appointment around. + last_known_block (:obj:`str`): the last block known by the ``Watcher``. Raises: ValueError: if `teos_sk_file` is not found. @@ -70,6 +71,7 @@ class Watcher: self.max_appointments = max_appointments self.expiry_delta = expiry_delta self.signing_key = Cryptographer.load_private_key_der(sk_der) + self.last_known_block = db_manager.load_last_block_hash_watcher() def awake(self): """Starts a new thread to monitor the blockchain for channel breaches""" @@ -166,6 +168,11 @@ class Watcher: :obj:`Responder ` upon detecting a breach. """ + # Distinguish fresh bootstraps from bootstraps from db + if self.last_known_block is None: + self.last_known_block = self.block_processor.get_best_block_hash() + self.db_manager.store_last_block_hash_watcher(self.last_known_block) + while True: block_hash = self.block_queue.get() block = self.block_processor.get_block(block_hash) @@ -228,6 +235,7 @@ class Watcher: # Register the last processed block for the watcher self.db_manager.store_last_block_hash_watcher(block_hash) + self.last_known_block = block.get("hash") self.block_queue.task_done() def get_breaches(self, txids):