From 4c44932deec65a7f82c6fff26606fc366ef06892 Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Sun, 31 Jan 2021 13:32:24 +0000 Subject: [PATCH] gettransaction called once per txid in monitor See #772. This is likely a partial fix but that issue may be more complex. More generally, while we may have to process multiple entries in the return of `listtransactions`, with the same txid, because they may have different wallet labels, we do not want to call `gettransaction` repeatedly on the same txid in the same monitor loop call. Note however, that we *do* need to call `gettransaction` again in the next monitor loop, since the state (confirmations) updates, so we cannot permanently cache those results. Additionally removed redundant old_txs entries with set(). --- jmclient/jmclient/wallet_service.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/jmclient/jmclient/wallet_service.py b/jmclient/jmclient/wallet_service.py index 260752f..7dd2800 100644 --- a/jmclient/jmclient/wallet_service.py +++ b/jmclient/jmclient/wallet_service.py @@ -309,11 +309,19 @@ class WalletService(Service): if x['txid'] in self.active_txids or x['txid'] not in self.old_txs: new_txs.append(x) # reset for next polling event: - self.old_txs = [x['txid'] for x in txlist if "txid" in x] - + self.old_txs = set(x['txid'] for x in txlist if "txid" in x) + # for this invocation of transaction_monitor, we *don't* want + # to call `gettransaction` more than once per txid, even if the + # `listtransactions` result has multiple instances for different + # wallet labels; so we use a temporary variable to cache. + gettx_results = {} for tx in new_txs: txid = tx["txid"] - res = self.bci.get_transaction(hextobin(txid)) + if txid not in gettx_results: + res = self.bci.get_transaction(hextobin(txid)) + gettx_results[txid] = res + else: + res = gettx_results[txid] if not res: continue confs = res["confirmations"]