mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 06:34:19 +01:00
Updates Watcher to use new Cleaner functions and reformats filter_valid_breaches to return a list of valid and invalid breaches.
This commit is contained in:
@@ -124,7 +124,7 @@ class Watcher:
|
|||||||
logger.info("Waking up")
|
logger.info("Waking up")
|
||||||
|
|
||||||
self.db_manager.store_watcher_appointment(uuid, appointment.to_json())
|
self.db_manager.store_watcher_appointment(uuid, appointment.to_json())
|
||||||
self.db_manager.store_update_locator_map(appointment.locator, uuid)
|
self.db_manager.create_append_locator_map(appointment.locator, uuid)
|
||||||
|
|
||||||
appointment_added = True
|
appointment_added = True
|
||||||
signature = Cryptographer.sign(appointment.serialize(), self.signing_key)
|
signature = Cryptographer.sign(appointment.serialize(), self.signing_key)
|
||||||
@@ -164,35 +164,36 @@ class Watcher:
|
|||||||
if block["height"] > appointment_data.get("end_time") + self.config.get("EXPIRY_DELTA")
|
if block["height"] > appointment_data.get("end_time") + self.config.get("EXPIRY_DELTA")
|
||||||
]
|
]
|
||||||
|
|
||||||
Cleaner.delete_expired_appointment(
|
Cleaner.delete_expired_appointments(
|
||||||
expired_appointments, self.appointments, self.locator_uuid_map, self.db_manager
|
expired_appointments, self.appointments, self.locator_uuid_map, self.db_manager
|
||||||
)
|
)
|
||||||
|
|
||||||
filtered_breaches = self.filter_valid_breaches(self.get_breaches(txids))
|
valid_breaches, invalid_breaches = self.filter_valid_breaches(self.get_breaches(txids))
|
||||||
|
|
||||||
for uuid, filtered_breach in filtered_breaches.items():
|
for uuid, breach in valid_breaches.items():
|
||||||
# Errors decrypting the Blob will result in a None penalty_txid
|
|
||||||
if filtered_breach["valid_breach"] is True:
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Notifying responder and deleting appointment",
|
"Notifying responder and deleting appointment",
|
||||||
penalty_txid=filtered_breach["penalty_txid"],
|
penalty_txid=breach["penalty_txid"],
|
||||||
locator=filtered_breach["locator"],
|
locator=breach["locator"],
|
||||||
uuid=uuid,
|
uuid=uuid,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.responder.handle_breach(
|
self.responder.handle_breach(
|
||||||
uuid,
|
uuid,
|
||||||
filtered_breach["locator"],
|
breach["locator"],
|
||||||
filtered_breach["dispute_txid"],
|
breach["dispute_txid"],
|
||||||
filtered_breach["penalty_txid"],
|
breach["penalty_txid"],
|
||||||
filtered_breach["penalty_rawtx"],
|
breach["penalty_rawtx"],
|
||||||
self.appointments[uuid].get("end_time"),
|
self.appointments[uuid].get("end_time"),
|
||||||
block_hash,
|
block_hash,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Delete the appointment and update db
|
Cleaner.flag_triggered_appointments(
|
||||||
Cleaner.delete_completed_appointment(
|
list(valid_breaches.keys()), self.appointments, self.locator_uuid_map, self.db_manager
|
||||||
uuid, self.appointments, self.locator_uuid_map, self.db_manager
|
)
|
||||||
|
|
||||||
|
Cleaner.delete_completed_appointments(
|
||||||
|
invalid_breaches, self.appointments, self.locator_uuid_map, self.db_manager
|
||||||
)
|
)
|
||||||
|
|
||||||
# Register the last processed block for the watcher
|
# Register the last processed block for the watcher
|
||||||
@@ -248,7 +249,8 @@ class Watcher:
|
|||||||
``{locator, dispute_txid, penalty_txid, penalty_rawtx, valid_breach}``
|
``{locator, dispute_txid, penalty_txid, penalty_rawtx, valid_breach}``
|
||||||
"""
|
"""
|
||||||
|
|
||||||
filtered_breaches = {}
|
valid_breaches = {}
|
||||||
|
invalid_breaches = []
|
||||||
|
|
||||||
for locator, dispute_txid in breaches.items():
|
for locator, dispute_txid in breaches.items():
|
||||||
for uuid in self.locator_uuid_map[locator]:
|
for uuid in self.locator_uuid_map[locator]:
|
||||||
@@ -263,21 +265,18 @@ class Watcher:
|
|||||||
penalty_tx = BlockProcessor.decode_raw_transaction(penalty_rawtx)
|
penalty_tx = BlockProcessor.decode_raw_transaction(penalty_rawtx)
|
||||||
|
|
||||||
if penalty_tx is not None:
|
if penalty_tx is not None:
|
||||||
penalty_txid = penalty_tx.get("txid")
|
valid_breaches[uuid] = {
|
||||||
valid_breach = True
|
|
||||||
|
|
||||||
logger.info("Breach found for locator", locator=locator, uuid=uuid, penalty_txid=penalty_txid)
|
|
||||||
|
|
||||||
else:
|
|
||||||
penalty_txid = None
|
|
||||||
valid_breach = False
|
|
||||||
|
|
||||||
filtered_breaches[uuid] = {
|
|
||||||
"locator": locator,
|
"locator": locator,
|
||||||
"dispute_txid": dispute_txid,
|
"dispute_txid": dispute_txid,
|
||||||
"penalty_txid": penalty_txid,
|
"penalty_txid": penalty_tx.get("txid"),
|
||||||
"penalty_rawtx": penalty_rawtx,
|
"penalty_rawtx": penalty_rawtx,
|
||||||
"valid_breach": valid_breach,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return filtered_breaches
|
logger.info(
|
||||||
|
"Breach found for locator", locator=locator, uuid=uuid, penalty_txid=penalty_tx.get("txid")
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
invalid_breaches.append(uuid)
|
||||||
|
|
||||||
|
return valid_breaches, invalid_breaches
|
||||||
|
|||||||
Reference in New Issue
Block a user