From 85efd891354a9831e5e31ac967d31bf54954b193 Mon Sep 17 00:00:00 2001 From: Kim Neunert Date: Thu, 2 Feb 2023 14:27:49 +0100 Subject: [PATCH 1/2] fixes psbt key error --- cypress/integration/spec_balances_amounts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/spec_balances_amounts.js b/cypress/integration/spec_balances_amounts.js index b4658188a8..ef6efbbf56 100644 --- a/cypress/integration/spec_balances_amounts.js +++ b/cypress/integration/spec_balances_amounts.js @@ -27,7 +27,7 @@ describe('Test the rendering of balances and amounts', () => { cy.get('#satoshis_hot_keys_hot_sign_btn').click() cy.get('#hot_enter_passphrase__submit').click() cy.get('#broadcast_local_btn').click() - cy.reload() + cy.visit("/") cy.selectWallet('Ghost wallet') cy.get('#unconfirmed_amount').then(($amount) => { expect(parseFloat($amount.text())).to.be.gt(0).and.to.be.lt(1); From 298eef213237ed5e859e90da4081895097ea2ee9 Mon Sep 17 00:00:00 2001 From: Kim Neunert Date: Thu, 2 Feb 2023 18:19:25 +0100 Subject: [PATCH 2/2] use lock to avoid concurrent access --- src/cryptoadvance/specter/txlist.py | 82 ++++++++++++++++------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/src/cryptoadvance/specter/txlist.py b/src/cryptoadvance/specter/txlist.py index c6458fa294..5c2478e941 100644 --- a/src/cryptoadvance/specter/txlist.py +++ b/src/cryptoadvance/specter/txlist.py @@ -25,6 +25,7 @@ SpecterTx, ) from .util.tx import decoderawtransaction +from threading import RLock logger = logging.getLogger(__name__) @@ -448,6 +449,8 @@ class TxList(dict, AbstractTxListContext): ItemCls = WalletAwareTxItem # for inheritance PSBTCls = SpecterPSBT + lock = RLock() + def __init__(self, path, parent, addresses): self.parent = parent self.path = path @@ -522,7 +525,11 @@ def get_transactions(self, current_blockheight=None) -> WalletAwareTxItem: # Make a copy of all txs if the tx.ismine (which should be all of them) # As TxItem is derived from Dict, the __Dict__ will return a TxItem - transactions: List(TxItem) = [tx.copy() for tx in self.values() if tx.ismine] + with self.lock: + tx_values = self.values() + transactions: List(TxItem) = [ + tx.copy() for tx in self.values() if tx.ismine + ] # 1. sorted transactions = sorted(transactions, key=lambda tx: tx["time"], reverse=True) @@ -606,42 +613,43 @@ def add(self, txs): } (format of listtransactions) """ - # here we store all addresses in transactions - # to set them used later - addresses = [] - # first we add all transactions to cache - for txid in txs: - tx = txs[txid] - # find minimal from 3 times: - maxtime = 10445238000 # TODO: change after 31 dec 2300 lol - time = min( - tx.get("blocktime", maxtime), - tx.get("timereceived", maxtime), - tx.get("time", maxtime), - ) - obj = { - "txid": txid, - "fee": tx.get("fee", None), - "blockheight": tx.get("blockheight", None), - "blockhash": tx.get("blockhash", None), - "time": time, - "blocktime": tx.get("blocktime", None), - "conflicts": tx.get("walletconflicts", []), - "bip125-replaceable": tx.get("bip125-replaceable", "no"), - "hex": tx.get("hex", None), - } - txitem = self.ItemCls(self, self._addresses, self.rawdir, **obj) - self[txid] = txitem - if txitem.tx: - for vout in txitem.tx.vout: - try: - addr = vout.script_pubkey.address(get_network(self.chain)) - if addr not in addresses: - addresses.append(addr) - except: - pass # maybe not an address, but a raw script? - self._addresses.set_used(addresses) - self._save() + with self.lock: + # here we store all addresses in transactions + # to set them used later + addresses = [] + # first we add all transactions to cache + for txid in txs: + tx = txs[txid] + # find minimal from 3 times: + maxtime = 10445238000 # TODO: change after 31 dec 2300 lol + time = min( + tx.get("blocktime", maxtime), + tx.get("timereceived", maxtime), + tx.get("time", maxtime), + ) + obj = { + "txid": txid, + "fee": tx.get("fee", None), + "blockheight": tx.get("blockheight", None), + "blockhash": tx.get("blockhash", None), + "time": time, + "blocktime": tx.get("blocktime", None), + "conflicts": tx.get("walletconflicts", []), + "bip125-replaceable": tx.get("bip125-replaceable", "no"), + "hex": tx.get("hex", None), + } + txitem = self.ItemCls(self, self._addresses, self.rawdir, **obj) + self[txid] = txitem + if txitem.tx: + for vout in txitem.tx.vout: + try: + addr = vout.script_pubkey.address(get_network(self.chain)) + if addr not in addresses: + addresses.append(addr) + except: + pass # maybe not an address, but a raw script? + self._addresses.set_used(addresses) + self._save() def load(self, arr): """