From 712a14446764d75624e71ec7fcf2739c950d5f89 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 29 Dec 2021 18:40:44 +0000 Subject: [PATCH] Fix race conditions in cleanup --- handler/agora.py | 13 ++++++++----- handler/transactions.py | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/handler/agora.py b/handler/agora.py index a89d153..c82ec9e 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -77,9 +77,8 @@ class Agora(object): current_trades = [] for contact_id, contact in dash.items(): reference = self.tx.tx_to_ref(contact_id) - if not reference: - reference = "not_set" - current_trades.append(reference) + if reference: + current_trades.append(reference) buyer = contact["data"]["buyer"]["username"] amount = contact["data"]["amount"] amount_xmr = contact["data"]["amount_xmr"] @@ -87,9 +86,11 @@ class Agora(object): if not contact["data"]["is_selling"]: continue if reference not in self.last_dash: - self.tx.new_trade(contact_id, buyer, currency, amount, amount_xmr) + reference = self.tx.new_trade(contact_id, buyer, currency, amount, amount_xmr) + if reference: + if reference not in current_trades: + current_trades.append(reference) if send_irc: - self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {buyer} {amount}{currency} {amount_xmr}XMR") dash_tmp.append(f"{reference}: {buyer} {amount}{currency} {amount_xmr}XMR") @@ -99,6 +100,8 @@ class Agora(object): for ref in list(self.last_dash): # We're removing from the list on the fly if ref not in current_trades: self.last_dash.remove(ref) + if reference and reference not in current_trades: + current_trades.append(reference) self.tx.cleanup(current_trades) return dash_tmp diff --git a/handler/transactions.py b/handler/transactions.py index f6e378a..55f2391 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -144,6 +144,10 @@ class Transactions(object): self.irc.client.msg(self.irc.client.channel, f"Generated reference for {trade_id}: {reference}") if settings.Agora.Send == "1": self.agora.agora.contact_message_post(trade_id, f"Hi! When sending the payment please use reference code: {reference}") + if existing_ref: + return convert(existing_ref) + else: + return reference def find_tx(self, reference, amount): """