Commit Graph

229 Commits

Author SHA1 Message Date
f321x 37614e9092 swaps: handle timeouts in send_direct_message
Adds logic to retry sending a direct message in
`NostrTransport.send_direct_message()` on `TimeoutError`.
Handles `TimeoutError` exception more gracefully by catching it and
returning `None`.
2025-08-19 15:29:58 +02:00
f321x a68bfab596 swaps: improve preimage extraction logic 2025-08-18 10:03:24 +02:00
ThomasV 971e3f1945 submarine_swaps: fix swapserver dying taskgroup (follow-up 21e3fd91dd and 4490bd3a76) 2025-08-08 16:17:01 +02:00
f321x dd41e87295 fix: NostrTransport.update_relays() KeyError
`NostrTransport.update_relays()` raises a `KeyError` when the offer of
the configured swapserver (`config.SWAPSERVER_NPUB`) is not in
`self._offers` even though `sm.pairs_updated` gets triggered. This
happens because `NostrTransport.get_pairs()` called `sm.update_pairs()`
before adding the received offer to `self._offers`.
2025-07-18 10:17:12 +02:00
SomberNight f2f1dddcc8 swaps: factor out pubkey_to_rgb_color into core lib 2025-07-14 21:09:18 +00:00
SomberNight f337b4782d lnwatcher: keep watching sweep TXOs that are dust due to high fees
- if fee estimates are high atm, some outputs are not worth to sweep
- however, fee estimates might be only-temporarily very high
  - previously in such a case lnwatcher would just discard outputs as dust,
    and mark the channel REDEEMED (and hence never watch it or try again)
  - now, instead, if the outputs would not be dust if fee estimates were lower,
    lnwatcher will keep watching the channel
    - and if estimates go down, lnwatcher will sweep them then
- relatedly, previously txbatcher.is_dust() used allow_fallback_to_static_rates=True,
    and it erroneously almost always fell back to the static rates (150 s/b) during
	startup (race: lnwatcher was faster than the network managed to get estimates)
	- now, instead, txbatcher.is_dust() does not fallback to static rates,
	  and the callers are supposed to handle NoDynamicFeeEstimates.
	  - I think this makes much more sense. The previous meaning of "is_dust"
	    with the fallback was weird. Now it means: "is dust at current feerates".

fixes https://github.com/spesmilo/electrum/issues/9980
2025-07-08 14:02:52 +00:00
f321x 73249404d4 qt: SwapDialog: update on changes, don't translate fstr
and differenciate between a single 'provider' and multiple or 0
'providers'. Also update SwapDialog and SwapServerDialog
when new offers are incoming. Stops translating f-string.
2025-06-27 11:18:38 +02:00
Sander van Grieken 1687b17e00 submarine_swaps: wait for unlock if wallet is password protected before starting nostr swap service 2025-06-16 09:39:50 +02:00
ThomasV 213d182f30 Merge pull request #9933 from f321x/prevent_fail_swap_exception
fix: prevent KeyError if _fail_swap gets called multiple times
2025-06-11 13:09:52 +02:00
f321x 8b15d64dc9 fix: prevent KeyError if _fail_swap gets called multiple times
If `_fail_swap()` gets called multiple times (e.g. from callbacks) this
would race a `KeyError` as the swap got already popped from
`self._swaps`.
In theory `_fail_swap` unregisters itself from the lnwatcher callback
but the callback may is scheduled multiple times before it has the
chance to unregister itself.
2025-06-11 11:37:24 +02:00
SomberNight 47e76b25b1 swaps: add some type hints, and force kwargs 2025-06-10 16:20:43 +00:00
SomberNight 2fb4debc7c commands: fix normal_swap cmd 2025-06-10 16:20:39 +00:00
ThomasV 86f3eec8e6 fix user-facing exception refreshing history after swap is refunded
(txbatcher first adds the tx unsigned)
2025-06-10 10:44:10 +02:00
f321x 37181cd3a8 disable qt swap fee slider on reverse swaps, change eta
disables the fee slider in the swap dialog for reverse swaps as the tx
fee for claiming is not configurable by the user. Also replaces calls to
`sm.get_swap_tx_fee()` with `sm.get_fee_for_txbatcher()` as this is the
correct fee estimate for claim transactions, instead of the config fee
eta used by `get_swap_tx_fee()`.
2025-06-09 17:36:38 +02:00
f321x 3a39abc415 fix: use single long lived transport in qeswaphelper
changes qeswaphelper to shate a single, long lived transport instance
instead of opening new transports to do swaps and fetch offers.
This allows to continuosly fetch offers, so events which get returned
later by slow relays don't get missed and the fee values stay updated.
Also fixes a race causing the list to miss some swapservers, as the
current implementation fetches only until
`swap_manager.is_initialized()` is set, which will get set as soon as an
event of the configured swapserver is received. So if the event of the
configured swapserver is received as first, all server events coming in
after it would get ignored.
2025-06-06 14:38:11 +02:00
ThomasV 9afd2fa098 Merge pull request #9911 from f321x/fix_swap_exception_send_change_to_lightning
fix: exceptions when sending change to lightning
2025-06-05 09:15:21 +02:00
Sander van Grieken 044ea1f4f6 submarine_swaps: imports, whitespace 2025-06-04 19:47:30 +02:00
f321x 5ad1b4b5dd fix: exceptions with send change to lightning 2025-06-04 17:40:04 +02:00
SomberNight 468f496f34 submarine_swaps: make swaps dict thread-safe
In general many methods of the SwapManager are called both from the asyncio thread
and from the GUI, and hence must be thread-safe.

closes https://github.com/spesmilo/electrum/issues/9887
2025-06-02 17:06:08 +00:00
SomberNight 4539269960 submarine_swaps.py: trivial clean-up, add some type hints 2025-06-02 16:29:29 +00:00
ThomasV 43ca469774 Merge pull request #9555 from tianzedavid/master
chore: fix some typos
2025-05-30 14:36:12 +02:00
ThomasV f842ce0737 submarine_swaps: consider is_redeemed as sufficient for swap not
to be pending
2025-05-27 10:15:27 +02:00
ThomasV 58480a69db TxBatcher: store fee policy names instead of fee descriptors
This allows to change the fee policy of batches dynamically.
Config.fee_policy is a mapping between policy names and descriptors.
2025-05-26 13:30:25 +02:00
f321x 3693c38e37 swaps: replace offers dict with class, fix incorrect naming
introduces a class SwapOffer which is used instead of passing around
offers in dicts.

Also fixes incorrect variable naming of swapserver npubs / public keys
by assigning the npub instead of the hex pubkey to
config.SWAPSERVER_NPUB
2025-05-19 14:22:23 +02:00
f321x 07a40b1c53 Improve accuracy of swapserver liquidity announcement.
Adds event handler and more calls to the liquidity update trigger to
ensure that changes in liquidity will get published more reliably.
2025-05-19 09:52:53 +02:00
SomberNight 44f3444795 lnworker: make "preimages" dict private
I want to hook into lnworker.save_preimage (not done yet).
Other modules should not put preimages into the dict directly.
2025-05-14 13:23:02 +00:00
ThomasV 6e3f173a71 SweepInfo: define csv_delay as property 2025-05-13 08:50:33 +02:00
ThomasV db271d9b7d Fix get_pending_swaps: use both funding and spending tx heights
Also, do not show closing warnings if we are offline.
2025-05-08 14:58:13 +02:00
f321x 913f5ec6d8 add option to show warnings on wallet close, add warning for ongoing submarine swap 2025-05-07 17:11:08 +02:00
ThomasV 1c3268c2ff submarine_swaps: make callback async (follow-up previous commit) 2025-05-06 13:03:38 +02:00
accumulator 80e7dce539 Merge pull request #9736 from f321x/swapserver_show_amounts
swaps: show swap limits in SwapDialog
2025-04-28 21:59:33 +02:00
accumulator a7ce107f01 Merge pull request #9737 from f321x/fix_swap_pay_invoice
swaps: don't limit attempts when paying swap invoice
2025-04-28 21:50:23 +02:00
SomberNight 5f83fffd2e swaps.py: (trivial) fix stale type-hint 2025-04-17 17:13:21 +00:00
f321x 6bdedb3ecd don't limit attempts when paying swap invoice 2025-04-15 15:53:31 +02:00
f321x 48bf7ee2b5 Show swap limits in SwapDialog 2025-04-15 13:06:57 +02:00
ThomasV 4ecf6acc1c Merge pull request #9691 from f321x/send_change_to_lightning
swaps: improve send change to lightning and swapserver error handling
2025-04-09 13:18:54 +02:00
f321x c27035219a Set log level of logger passed to the aionostr.Manager to INFO because the debug log output of Manager is very verbose (showing single websocket messages etc.). This still provides enough useful information for debugging purposes. 2025-04-09 12:26:28 +02:00
ThomasV fe11fa3f4f Merge pull request #9716 from f321x/fix_swap_exception
swaps: make swap transport use shared timeout value
2025-04-09 12:06:52 +02:00
SomberNight 4b9d874d13 util: add fn run_sync_function_on_asyncio_thread
note: the return value is not propagated out.
It would be trivial to do that for the block=True case - but what about block=False?
2025-04-08 19:53:49 +00:00
f321x 216bfe3b50 fix race condition causing initialize_swap_manager assert to fail by waiting for trigger_pairs_updated_threadsafe to set the is_initialized event before returning if it is not running on the aio loop 2025-04-08 19:00:05 +02:00
f321x aace9aab91 make swap transport use shared timeout value 2025-04-08 17:44:17 +02:00
ThomasV 282c4561ff swapsserver fix for legacy clients. (follow-up 6e92a00) 2025-04-05 18:17:06 +02:00
f321x 6e8bdb346a move onchain balance calculation to wallet.py 2025-04-04 15:08:51 +02:00
f321x 17a9a91e1f announce actual available liquidity as swap provider 2025-04-04 15:06:50 +02:00
ThomasV cb75f21f3b Merge pull request #9640 from f321x/swap_dm_relays
swaps: Update submarine swap nostr relays dynamically and remove redundant query
2025-04-03 13:34:54 +02:00
f321x 4490bd3a76 improve send change to lightning and swapserver error handling 2025-04-02 12:58:27 +02:00
ThomasV 6e92a00ec4 Remove zeroconf option for submarine swaps
Since we now accept random swap providers, it is unreasonable
to keep that option.
2025-03-21 18:18:27 +01:00
f321x 21e3fd91dd dynamically update relays and remove redundant nostr query, store last
swapserver relays in file
2025-03-21 09:31:50 +01:00
f321x 9c7773c8db use ephemeral event type for nostr swap request events 2025-03-20 09:43:48 +01:00
ThomasV 1e4728bdf1 Merge pull request #9560 from f321x/nostr_proxy
Pass proxy settings to aionostr manager for submarine swaps
2025-03-19 14:26:27 +01:00