wallet.get_relevant_invoice_keys_for_tx: take lock in callee not caller

This commit is contained in:
SomberNight 2020-08-31 21:58:47 +02:00
parent 6b4edc650a
commit 55eb62bb90
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9

View file

@ -766,11 +766,12 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
def _get_relevant_invoice_keys_for_tx(self, tx: Transaction) -> Set[str]: def _get_relevant_invoice_keys_for_tx(self, tx: Transaction) -> Set[str]:
relevant_invoice_keys = set() relevant_invoice_keys = set()
for txout in tx.outputs(): with self.transaction_lock:
for invoice_key in self._invoices_from_scriptpubkey_map.get(txout.scriptpubkey, set()): for txout in tx.outputs():
# note: the invoice might have been deleted since, so check now: for invoice_key in self._invoices_from_scriptpubkey_map.get(txout.scriptpubkey, set()):
if invoice_key in self.invoices: # note: the invoice might have been deleted since, so check now:
relevant_invoice_keys.add(invoice_key) if invoice_key in self.invoices:
relevant_invoice_keys.add(invoice_key)
return relevant_invoice_keys return relevant_invoice_keys
def get_relevant_invoices_for_tx(self, tx: Transaction) -> Sequence[OnchainInvoice]: def get_relevant_invoices_for_tx(self, tx: Transaction) -> Sequence[OnchainInvoice]:
@ -816,12 +817,12 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
return self._is_onchain_invoice_paid(invoice)[0] return self._is_onchain_invoice_paid(invoice)[0]
def _maybe_set_tx_label_based_on_invoices(self, tx: Transaction) -> bool: def _maybe_set_tx_label_based_on_invoices(self, tx: Transaction) -> bool:
# note: this is not done in 'get_default_label' as that would require deserializing each tx
tx_hash = tx.txid() tx_hash = tx.txid()
with self.transaction_lock: labels = []
labels = [] for invoice in self.get_relevant_invoices_for_tx(tx):
for invoice in self.get_relevant_invoices_for_tx(tx): if invoice.message:
if invoice.message: labels.append(invoice.message)
labels.append(invoice.message)
if labels: if labels:
self.set_label(tx_hash, "; ".join(labels)) self.set_label(tx_hash, "; ".join(labels))
return bool(labels) return bool(labels)