cryptoadvance / specter-desktop

A desktop GUI for Bitcoin Core optimised to work with hardware wallets
MIT License
808 stars 242 forks source link

Wallet becomes unusable after trying to send funds from the wallet to itself. #2475

Open oren-z0 opened 2 weeks ago

oren-z0 commented 2 weeks ago

Describe the bug Wallet becomes unusable after sending funds from the wallet to itself.

To Reproduce

  1. Remove ~/.specter-dev and /tmp/specter_btc_regtest_plain_datadir if exist.
  2. Activate the virtualenv and start bitcoind on regtest with: python3 -m cryptoadvance.specter bitcoind.
  3. Activate the virtualenv in a new terminal and start specter-desktop with: python3 -m cryptoadvance.specter server --config DevelopmentConfig --debug.
  4. Setup the connection to bitcoin-core.
  5. Create a new "Bitcoin Core" hotwallet-device named "core1" and a new wallet "wallet1".
  6. Restart the bitcoind process so it will start mining to the first address of "wallet1".
  7. Create a second "Bitcoin Core" hotwallet-device named "core2" and a new wallet "wallet2".
  8. You will be able to send funds from wallet1 to wallet2 and vice versa.
  9. Trying send funds from a wallet1 to itself will result in a "list index out of range" error, and the wallet will become unusable.

Debug logs:

Exception in thread Thread-1142 (_update):
Traceback (most recent call last):
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/wallet/wallet.py", line 721, in check_utxo
    searched_vout = [
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.10/3.10.15/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/util/flask.py", line 32, in run
    super().run()
  File "/usr/local/Cellar/python@3.10/3.10.15/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/managers/wallet_manager.py", line 243, in _update
    self.wallets[wallet_name].update()
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/wallet/wallet.py", line 497, in update
    self.getdata()
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/wallet/wallet.py", line 745, in getdata
    self.check_utxo()
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/wallet/wallet.py", line 741, in check_utxo
    raise SpecterError(f"Failed to load utxos, {type(e).__name__}: {e}")
cryptoadvance.specter.specter_error.SpecterError: Failed to load utxos, IndexError: list index out of range

Expected behavior Wallet should be able to send funds to its own address.

Screenshots https://v.nostr.build/iNEmbAfNpV96Vcfu.mov

Desktop (please complete the following information):

oren-z0 commented 2 weeks ago

https://github.com/cryptoadvance/specter-desktop/pull/2467 doesn't solve the problem. I'm getting a different error message: "Failed to load utxos, KeyError: '51845...'":

Traceback (most recent call last):
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/wallet/wallet.py", line 699, in check_utxo
    tx: WalletAwareTxItem = txlist_dict[utxo_txid]
KeyError: '518457cbb7fa87fe90980b32890721fef2a6c850497369484423ae361dcb2ae8'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/wallet/wallet.py", line 705, in check_utxo
    tx: WalletAwareTxItem = txlist_dict[utxo_txid]
KeyError: '518457cbb7fa87fe90980b32890721fef2a6c850497369484423ae361dcb2ae8'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.10/3.10.15/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/util/flask.py", line 32, in run
    super().run()
  File "/usr/local/Cellar/python@3.10/3.10.15/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/managers/wallet_manager.py", line 243, in _update
    self.wallets[wallet_name].update()
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/wallet/wallet.py", line 497, in update
    self.getdata()
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/wallet/wallet.py", line 756, in getdata
    self.check_utxo()
  File "/Users/oren/private_workspace/specter-desktop/src/cryptoadvance/specter/wallet/wallet.py", line 752, in check_utxo
    raise SpecterError(f"Failed to load utxos, {type(e).__name__}: {e}")
cryptoadvance.specter.specter_error.SpecterError: Failed to load utxos, KeyError: '518457cbb7fa87fe90980b32890721fef2a6c850497369484423ae361dcb2ae8'