Updates builder with new minimal in-memory data from #83

- The builder was never modified when the in-memory data was reduced, so it was still trying to build data based on the past approach.
- Renames create_block_queue to poplate_block_queue and repurposes the method

When creating a block queue, a new Queue was created and populated. That was breaking the link between the Watcher/Responder and the ChainMonitor since the Queue is defined beforehand.
This commit is contained in:
Sergi Delgado Segura
2020-01-24 13:21:36 +01:00
parent 26d61ca784
commit ba5aa9f651

View File

@@ -32,14 +32,13 @@ class Builder:
locator_uuid_map = {} locator_uuid_map = {}
for uuid, data in appointments_data.items(): for uuid, data in appointments_data.items():
appointment = Appointment.from_dict(data) appointments[uuid] = {"locator": data.get("locator"), "end_time": data.get("end_time")}
appointments[uuid] = appointment
if appointment.locator in locator_uuid_map: if data.get("locator") in locator_uuid_map:
locator_uuid_map[appointment.locator].append(uuid) locator_uuid_map[data.get("locator")].append(uuid)
else: else:
locator_uuid_map[appointment.locator] = [uuid] locator_uuid_map[data.get("locator")] = [uuid]
return appointments, locator_uuid_map return appointments, locator_uuid_map
@@ -67,33 +66,33 @@ class Builder:
tx_tracker_map = {} tx_tracker_map = {}
for uuid, data in tracker_data.items(): for uuid, data in tracker_data.items():
tracker = TransactionTracker.from_dict(data) trackers[uuid] = {
trackers[uuid] = tracker "penalty_txid": data.get("penalty_txid"),
"locator": data.get("locator"),
"appointment_end": data.get("appointment_end"),
}
if tracker.penalty_txid in tx_tracker_map: if data.get("penalty_txid") in tx_tracker_map:
tx_tracker_map[tracker.penalty_txid].append(uuid) tx_tracker_map[data.get("penalty_txid")].append(uuid)
else: else:
tx_tracker_map[tracker.penalty_txid] = [uuid] tx_tracker_map[data.get("penalty_txid")] = [uuid]
return trackers, tx_tracker_map return trackers, tx_tracker_map
@staticmethod @staticmethod
def build_block_queue(missed_blocks): def populate_block_queue(block_queue, missed_blocks):
""" """
Builds a ``Queue`` of block hashes to initialize the :mod:`Watcher <pisa.watcher.Watcher>` or the Populates a ``Queue`` of block hashes to initialize the :mod:`Watcher <pisa.watcher.Watcher>` or the
:mod:`Responder <pisa.responder.Responder>` using backed up data. :mod:`Responder <pisa.responder.Responder>` using backed up data.
Args: Args:
block_queue (:obj:`Queue`): a ``Queue``
missed_blocks (:obj:`list`): list of block hashes missed by the Watchtower (do to a crash or shutdown). missed_blocks (:obj:`list`): list of block hashes missed by the Watchtower (do to a crash or shutdown).
Returns: Returns:
:obj:`Queue`: A ``Queue`` containing all the missed blocks hashes. :obj:`Queue`: A ``Queue`` containing all the missed blocks hashes.
""" """
block_queue = Queue()
for block in missed_blocks: for block in missed_blocks:
block_queue.put(block) block_queue.put(block)
return block_queue