mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Move triggered flag clearing to the Watcher when a triggered appointment cannot make it to the mempool
When an appointment was triggered a flag was set in the Watcher, and removed later on in the Responder if the transaction ended up being rejected. That's pretty annoying. Since we have information about whether a transaction has made it to the mempool or not via the Carrier's receipt, this can be all done in the Watcher, which makes more sense and reduces the interaction with the db (1 write if succeeds, 0 otherwise instead of 1 write if succeeds, 2 otherwise).
This commit is contained in:
@@ -214,10 +214,6 @@ class Responder:
|
||||
"Tracker cannot be created", reason=receipt.reason, uuid=uuid, on_sync=self.on_sync(block_hash)
|
||||
)
|
||||
|
||||
# FIXME: This is only necessary because of the triggered appointment approach. Remove if it changes.
|
||||
Cleaner.delete_appointment_from_db(uuid, self.db_manager)
|
||||
Cleaner.update_delete_db_locator_map(uuid, locator, self.db_manager)
|
||||
|
||||
return receipt
|
||||
|
||||
def add_tracker(self, uuid, locator, dispute_txid, penalty_txid, penalty_rawtx, appointment_end, confirmations=0):
|
||||
|
||||
@@ -178,7 +178,7 @@ class Watcher:
|
||||
uuid=uuid,
|
||||
)
|
||||
|
||||
self.responder.handle_breach(
|
||||
receipt = self.responder.handle_breach(
|
||||
uuid,
|
||||
breach["locator"],
|
||||
breach["dispute_txid"],
|
||||
@@ -188,9 +188,16 @@ class Watcher:
|
||||
block_hash,
|
||||
)
|
||||
|
||||
Cleaner.flag_triggered_appointments(
|
||||
list(valid_breaches.keys()), self.appointments, self.locator_uuid_map, self.db_manager
|
||||
)
|
||||
Cleaner.delete_appointment_from_memory(uuid, self.appointments, self.locator_uuid_map)
|
||||
|
||||
# Appointments are only flagged as triggered if they are delivered, otherwise they are just deleted.
|
||||
# FIXME: This is only necessary because of the triggered appointment approach. Fix if it changes.
|
||||
if receipt.delivered:
|
||||
self.db_manager.create_triggered_appointment_flag(uuid)
|
||||
|
||||
else:
|
||||
self.db_manager.delete_watcher_appointment(uuid)
|
||||
Cleaner.update_delete_db_locator_map(uuid, breach["locator"], self.db_manager)
|
||||
|
||||
Cleaner.delete_completed_appointments(
|
||||
invalid_breaches, self.appointments, self.locator_uuid_map, self.db_manager
|
||||
|
||||
Reference in New Issue
Block a user