mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Initializes block_queue on init
Building from backed up data may require initializing the block queues of both the watcher and responder with the blocks they've missed.
This commit is contained in:
@@ -59,8 +59,8 @@ class Responder:
|
||||
self.tx_job_map = dict()
|
||||
self.unconfirmed_txs = []
|
||||
self.missed_confirmations = dict()
|
||||
self.block_queue = None
|
||||
self.asleep = True
|
||||
self.block_queue = Queue()
|
||||
self.zmq_subscriber = None
|
||||
self.db_manager = db_manager
|
||||
|
||||
@@ -118,7 +118,6 @@ class Responder:
|
||||
|
||||
if self.asleep:
|
||||
self.asleep = False
|
||||
self.block_queue = Queue()
|
||||
zmq_thread = Thread(target=self.do_subscribe)
|
||||
responder = Thread(target=self.do_watch)
|
||||
zmq_thread.start()
|
||||
@@ -172,6 +171,7 @@ class Responder:
|
||||
# Go back to sleep if there are no more jobs
|
||||
self.asleep = True
|
||||
self.zmq_subscriber.terminate = True
|
||||
self.block_queue = Queue()
|
||||
|
||||
logger.info("No more pending jobs, going back to sleep")
|
||||
|
||||
|
||||
@@ -21,16 +21,15 @@ class Watcher:
|
||||
def __init__(self, db_manager, responder=None, max_appointments=MAX_APPOINTMENTS):
|
||||
self.appointments = dict()
|
||||
self.locator_uuid_map = dict()
|
||||
self.block_queue = None
|
||||
self.asleep = True
|
||||
self.block_queue = Queue()
|
||||
self.max_appointments = max_appointments
|
||||
self.zmq_subscriber = None
|
||||
self.db_manager = db_manager
|
||||
|
||||
if not isinstance(responder, Responder):
|
||||
self.responder = Responder(db_manager)
|
||||
|
||||
self.db_manager = db_manager
|
||||
|
||||
if PISA_SECRET_KEY is None:
|
||||
raise ValueError("No signing key provided. Please fix your pisa.conf")
|
||||
else:
|
||||
@@ -67,7 +66,6 @@ class Watcher:
|
||||
|
||||
if self.asleep:
|
||||
self.asleep = False
|
||||
self.block_queue = Queue()
|
||||
zmq_thread = Thread(target=self.do_subscribe)
|
||||
watcher = Thread(target=self.do_watch)
|
||||
zmq_thread.start()
|
||||
@@ -146,5 +144,6 @@ class Watcher:
|
||||
# Go back to sleep if there are no more appointments
|
||||
self.asleep = True
|
||||
self.zmq_subscriber.terminate = True
|
||||
self.block_queue = Queue()
|
||||
|
||||
logger.info("No more pending appointments, going back to sleep")
|
||||
|
||||
@@ -84,7 +84,7 @@ def test_init_responder(responder):
|
||||
assert type(responder.tx_job_map) is dict and len(responder.tx_job_map) == 0
|
||||
assert type(responder.unconfirmed_txs) is list and len(responder.unconfirmed_txs) == 0
|
||||
assert type(responder.missed_confirmations) is dict and len(responder.missed_confirmations) == 0
|
||||
assert responder.block_queue is None
|
||||
assert responder.block_queue.empty()
|
||||
assert responder.asleep is True
|
||||
assert responder.zmq_subscriber is None
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ def is_signature_valid(appointment, signature, pk):
|
||||
def test_init(watcher):
|
||||
assert type(watcher.appointments) is dict and len(watcher.appointments) == 0
|
||||
assert type(watcher.locator_uuid_map) is dict and len(watcher.locator_uuid_map) == 0
|
||||
assert watcher.block_queue is None
|
||||
assert watcher.block_queue.empty()
|
||||
assert watcher.asleep is True
|
||||
assert watcher.max_appointments == MAX_APPOINTMENTS
|
||||
assert watcher.zmq_subscriber is None
|
||||
|
||||
Reference in New Issue
Block a user