1
0
Commit Graph

141 Commits

Author SHA1 Message Date
ThomasV
dbf055de9a EventListener class to handle callbacks
and QtEventListener for Qt
2022-06-22 02:07:46 +02:00
ThomasV
6bef6fab86 adb: do not notify GUI about already known transactions 2022-06-13 10:53:43 +02:00
ThomasV
7d5125c935 lnwatcher: fix tx replacement and notifications
- revert the logic of do_breach_remedy to what it was
   before 0ca3d66d15,
   but now calling self.maybe_redeem unconditionally.
 - replace mempool transactions only if the fee increases
 - do not notify the GUI if a local tx is replaced
 - delete labels when replacing
2022-06-12 14:28:11 +02:00
SomberNight
29d8d8de26 wallet: (fix) cannot just piggyback on adb.is_up_to_date()
The wallet needs its own up_to_date logic:
- the adb being up_to_date means all its addresses are synced
- but an HD wallet might decide to roll the gap limit and generate new addresses
  - the adb does not know about this...
  - the wallet should be considered *not* up_to_date
- relatedly, it is now the wallet that decides to reset the network request counters

- note that wallet.main() was never cleaned up previously.
  - now wallet gets its own taskgroup, which is cleaned up in wallet.stop.

Follow-up to adb refactor: 121d8732f1
2022-06-10 18:55:55 +02:00
ThomasV
6e7ffa29ae Move address_is_old to AddressSynchronizer.
Cache local_height at that level instead of wallet.synchronize
2022-06-10 13:07:53 +02:00
ThomasV
0ca3d66d15 persist_lnwatcher: split try_redeem into two methods:
- maybe_add_redeem_tx
 - maybe_broadcast

Before this commit, local tx that are now persisted
are bot broadcast
2022-06-10 13:07:53 +02:00
ThomasV
c47057b484 Move get_wallet_delta to wallet class, because it requires wallet.is_mine
Do not call it in AddressSynchronizer.get_tx_fee
2022-06-10 13:07:53 +02:00
ThomasV
121d8732f1 Persist LNWatcher transactions in wallet file:
- separate AddressSynchronizer from Wallet and LNWatcher
 - the AddressSynchronizer class is referred to as 'adb' (address database)
 - Use callbacks to replace overloaded methods
2022-06-10 13:07:53 +02:00
SomberNight
2841cbeade addr_sync: also trigger address_history_changed when a tx is removed 2022-06-09 19:24:55 +02:00
SomberNight
d499dde811 addr_sync: get_balance change cache_key to have delimiters
re https://github.com/spesmilo/electrum/pull/7807/files#r870482609
2022-05-11 17:54:33 +02:00
ThomasV
1d498eeefc Change the semantics of get_balance:
It does not make sense to count change outputs in our unconfirmed balance,
because our balance will not be negatively affected if the transaction does
not get confirmed.

It is also incorrect to add signed values of get_addr_balance in order to compute
the balance over a domain. For example, this leads to incoming and outgoing
transactions cancelling out in our total unconfirmed balance.

This commit looks at the coins that are spent by a transaction. If those
coins belong to us and are confirmed, we do not count the transaction outputs
in our unconfirmed balance.

As a result, get_balance always returns positive values for unconfirmed balance.
2022-05-11 08:50:09 +02:00
ThomasV
dd43ccfda9 get_history: minor simplification 2022-05-07 18:46:28 +02:00
SomberNight
de724a214d asyncio: addr_sync: maybe fix "no current event loop in thread"
see https://github.com/spesmilo/electrum/issues/5376
crash report for electrum 4.2.1:
```
Traceback (most recent call last):
  File "/home/user/wspace/electrum/.buildozer/android/platform/build-arm64-v8a/build/python-installs/Electrum/kivy/base.py", line 347, in mainloop
  File "/home/user/wspace/electrum/.buildozer/android/platform/build-arm64-v8a/build/python-installs/Electrum/kivy/base.py", line 391, in idle
  File "/home/user/wspace/electrum/.buildozer/android/platform/build-arm64-v8a/build/python-installs/Electrum/kivy/base.py", line 342, in dispatch_input
  File "/home/user/wspace/electrum/.buildozer/android/platform/build-arm64-v8a/build/python-installs/Electrum/kivy/base.py", line 308, in post_dispatch_input
  File "kivy/_event.pyx", line 724, in kivy._event.EventDispatcher.dispatch
  File "/home/user/wspace/electrum/.buildozer/android/platform/build-arm64-v8a/build/python-installs/Electrum/kivy/uix/behaviors/button.py", line 179, in on_touch_up
  File "kivy/_event.pyx", line 720, in kivy._event.EventDispatcher.dispatch
  File "kivy/_event.pyx", line 1263, in kivy._event.EventObservers.dispatch
  File "kivy/_event.pyx", line 1147, in kivy._event.EventObservers._dispatch
  File "/home/user/wspace/electrum/.buildozer/android/platform/build-arm64-v8a/build/python-installs/Electrum/kivy/lang/builder.py", line 57, in custom_callback
  File "<string>", line 42, in <module>
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/gui/kivy/uix/dialogs/wallets.py", line 70, in cb
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/gui/kivy/main_window.py", line 710, in load_wallet_by_name
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/gui/kivy/main_window.py", line 728, in on_open_wallet
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/gui/kivy/main_window.py", line 691, in on_wizard_success
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/wallet.py", line 3267, in __new__
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/wallet.py", line 3111, in __init__
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/wallet.py", line 2904, in __init__
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/wallet.py", line 288, in __init__
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/address_synchronizer.py", line 97, in __init__
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/wallet.py", line 402, in load_and_cleanup
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/address_synchronizer.py", line 106, in load_and_cleanup
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/util.py", line 439, in <lambda>
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/util.py", line 435, in do_profile
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/address_synchronizer.py", line 432, in load_local_history
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/address_synchronizer.py", line 533, in _add_tx_to_local_history
  File "/home/user/wspace/electrum/.buildozer/android/app/electrum/address_synchronizer.py", line 548, in _mark_address_history_changed
  File "/home/user/wspace/electrum/.buildozer/android/platform/build-arm64-v8a/build/other_builds/python3/arm64-v8a__ndk_target_21/python3/Lib/asyncio/locks.py", line 260, in __init__
  File "/home/user/wspace/electrum/.buildozer/android/platform/build-arm64-v8a/build/other_builds/python3/arm64-v8a__ndk_target_21/python3/Lib/asyncio/events.py", line 639, in get_event_loop
RuntimeError: There is no current event loop in thread 'GUI'.
```
2022-04-26 20:24:15 +02:00
ThomasV
877a9f553b Merge pull request #7748 from spesmilo/confirm_reverse_swaps
Confirm reverse swaps
2022-04-09 10:41:02 +02:00
SomberNight
428dff90f8 address_sync: include verifier in sync_state progress indicator 2022-04-08 20:36:45 +02:00
SomberNight
30650c524c address_sync: "up_to_date" now waits for SPV 2022-04-08 20:35:23 +02:00
SomberNight
a05ef140d6 address_sync: split off unconfirmed_tx from unverified_tx 2022-04-08 20:34:45 +02:00
SomberNight
837fc1606c address_sync: change up_to_date to be private; no lock needed to read
After some consideration I am fairly certain there is no need to take
wallet.lock in `is_up_to_date()`. Any caller that might want some kind
of guarantees re the value returned by is_up_to_date() would need to
enforce them itself by e.g. taking wallet.lock around its critical code
block. That is, even if is_up_to_date() itself takes the lock, between
the call returning and the caller reading the value there could still
have been a race.
Also, the GUI was directly accessing the field already.
2022-04-08 20:33:13 +02:00
ThomasV
f01197b6b5 Reverse swaps: Wait until funding tx is confirmed
- override with allow_instant_swaps option (Qt)
2022-04-01 14:05:01 +02:00
ThomasV
1364e7538a bump fee of swap claim transactions
Note: This adds a new field, spent_txid, to PartialTxOutput
2022-03-30 13:44:10 +02:00
SomberNight
c9c094cfab requirements: bump min aiorpcx to 0.22.0
aiorpcx 0.20 changed the behaviour/API of TaskGroups.
When used as a context manager, TaskGroups no longer propagate
exceptions raised by their tasks. Instead, the calling code has
to explicitly check the results of tasks and decide whether to re-raise
any exceptions.
This is a significant change, and so this commit introduces "OldTaskGroup",
which should behave as the TaskGroup class of old aiorpcx. All existing
usages of TaskGroup are replaced with OldTaskGroup.

closes https://github.com/spesmilo/electrum/issues/7446
2022-02-15 18:22:44 +01:00
SomberNight
d94d443082 wallet: fire "request_status" event also when conf number changes 2021-07-11 16:57:01 +02:00
SomberNight
53d6eeb3f3 wallet: rm get_txout_address method 2021-06-08 16:45:30 +02:00
bitromortac
63308f94a0 reorganize with_lock decorator 2021-04-02 09:38:39 +02:00
ThomasV
3fc85725aa Merge pull request #7135 from SomberNight/202103_get_utxos_at_height
wallet: implement get_utxos at specific block height
2021-03-29 11:03:11 +02:00
ThomasV
e93becf33a wallet.add_transaction: prevent channel backup from being added twice 2021-03-27 14:29:10 +01:00
SomberNight
c2c3ece455 wallet: implement get_utxos at specific block height
This allows looking up what UTXOs the wallet had at a specific time in the past.
2021-03-24 19:37:37 +01:00
ThomasV
aa1fcc784e wallet: store wanted_height in future_tx, instead of remaining blocks 2021-03-22 11:00:42 +01:00
SomberNight
3c019c2f9c daemon/wallet/network: make stop() methods async 2021-03-09 17:52:36 +01:00
SomberNight
859f8ccf8e fix wallet.clear_history()
it would result in "wallet.get_history() failed balance sanity-check"

maybe related: https://github.com/spesmilo/electrum/issues/6792
2021-03-04 14:25:41 +01:00
SomberNight
c4e9afa019 wallet.remove_transaction: also rm dependent/child txs
Main motivation is that I often use wallet.remove_transaction
from the Qt console, and would find this behaviour more intuitive.
Note that previously if one were to call this on a tx with children,
the crash reporter would appear with "wallet.get_history() failed balance sanity-check".

related: https://github.com/spesmilo/electrum/issues/6960#issuecomment-764716533
2021-01-21 18:05:48 +01:00
SomberNight
8ac6d3b17d wallet.get_history: take locks.
Re the check at the end: "history not synchronized" - it's not that it's not synchronized,
rather that the history is changing while being computed.
2020-10-18 22:21:06 +02:00
SomberNight
777095fda8 wallet: simplify get_history
some years ago wallet.get_tx_delta returned Optional[int] but it returns int now
2020-10-18 22:14:52 +02:00
SomberNight
f125a06453 wallet: simplify get_wallet_delta 2020-10-18 20:37:29 +02:00
SomberNight
da6080421e wallet_db: WalletDB.get_txo_addr now returns dict instead of list 2020-10-18 20:37:25 +02:00
SomberNight
e71fa4924f wallet: rm wallet.txin_value 2020-10-18 20:37:21 +02:00
SomberNight
8b2eb83238 wallet: use get_txin_value in get_wallet_delta 2020-10-18 20:37:18 +02:00
SomberNight
55b5335ebb qt tx dialog: always show input amounts if we know them
Previously we would only show input amounts for partial txs.
Now also show them for complete txs as well, if we know them:
we check in the wallet db for the prevtx and read the value for the output.
This is safe as the input commits to the prevout via txid (which commits to the output value).

Also show "from addresses" in more cases in a similar fashion.
2020-10-18 20:37:14 +02:00
SomberNight
772199a766 wallet: fix clear_history 2020-10-09 16:22:59 +02:00
SomberNight
ea3e3ddbb8 lnpeer: handle cooperative close edge-case
fix #6317
2020-09-13 16:55:37 +02:00
SomberNight
a1baf860b6 wallet.set_up_to_date: (trivial) reduce log spam 2020-07-15 23:50:26 +02:00
ThomasV
04fb329c2e swaps: stop watching address once utxo is spent and mined 2020-06-18 14:28:40 +02:00
SomberNight
2b1a150c52 multi-wallet: properly stop lnworker/lnwatcher 2020-05-01 04:50:08 +02:00
ThomasV
9224404108 Move callback manager out of Network class 2020-04-14 18:29:51 +02:00
ThomasV
99f933401a add more logging shortcuts 2020-04-12 12:30:59 +02:00
SomberNight
900a7631cf commands: add new cmd "getprivatekeyforpath" to export a WIF for a path
related: #6061
2020-03-31 05:50:18 +02:00
SomberNight
7a574c3cbc wallet/GUI: don't allow "removing" a LN force-close-tx from history 2020-03-02 05:11:08 +01:00
SomberNight
d8180c678b Qt addresses list: show derivation path in tooltip (also addr dialog)
related: #5641
2020-03-01 05:45:15 +01:00
SomberNight
4a8ee1818a follow-up prev
E/W | lnwatcher.LNWalletWatcher | Exception in on_network_update: AssertionError('None')
Traceback (most recent call last):
  File "...\electrum\electrum\util.py", line 1035, in wrapper
    return await func(*args, **kwargs)
  File "...\electrum\electrum\lnwatcher.py", line 174, in on_network_update
    await self.check_onchain_situation(address, outpoint)
  File "...\electrum\electrum\lnwatcher.py", line 184, in check_onchain_situation
    closing_height = self.get_tx_height(closing_txid)
  File "...\electrum\electrum\address_synchronizer.py", line 597, in get_tx_height
    verified_tx_mined_info = self.db.get_verified_tx(tx_hash)
  File "...\electrum\electrum\json_db.py", line 44, in wrapper
    return func(self, *args, **kwargs)
  File "...\electrum\electrum\wallet_db.py", line 859, in get_verified_tx
    assert isinstance(txid, str), f"{repr(txid)}"
AssertionError: None
2020-02-24 18:52:33 +01:00
ThomasV
9616333b39 add_future_tx should return success 2020-02-22 17:20:05 +01:00