Commit Graph

246 Commits

Author SHA1 Message Date
SomberNight
08f041f3da swaps: add check for blockchain().is_tip_stale() 2025-08-23 02:41:53 +00:00
SomberNight
a7afd59dec swaps: more clean-up, add comments, more sanity checks 2025-08-23 02:41:43 +00:00
SomberNight
fc362826e8 swaps: clean-up onchain script construction 2025-08-23 02:41:40 +00:00
ThomasV
44a95bafbe Merge pull request #10164 from f321x/proper_cleanup_after_swap_failed
swaps: cleanup data after swap gets failed
2025-08-22 15:20:47 +02:00
f321x
97a0d27fa6 swaps: cleanup after successful swap
unregister hold invoice callback and delete payment bundle. they are not
used anymore.
2025-08-22 12:52:43 +02:00
f321x
c623cca654 swaps: cleanup data after swap gets failed
Removes the persisted payment info from lnworker once a swap got failed.
Stops persisting the OnionRoutingFailure as it is sufficient to delete
the payment info to fail potential incoming htlcs.
Deletes stored swap leftovers in lnworker and SwapManager
2025-08-21 19:56:42 +02:00
ThomasV
864932c79a reverse swaps: in the CLI, replace 'server_mining_fee' with
'prepayment', which corresponds to the trusted part of the
lightning payment.

We use 2*sm.mining_fee, where 'mining_fee' is the flat part of
the server fee. However, future protocol should probably allow
to set a value that does not depend on 'mining_fee'.
(note that LND uses a hardcoded amount).
2025-08-21 19:47:00 +02:00
f321x
aa661da9e2 swaps: stop sending whole req exception to client 2025-08-21 14:41:47 +02:00
f321x
9086f1af14 swaps: rate limit swapserver requests 2025-08-21 14:41:36 +02:00
ghost43
e85a3f2d3f Merge pull request #10157 from SomberNight/202508_swap_sanity_check_costs
swaps: add sanity-check for total swap costs
2025-08-20 18:05:13 +00:00
f321x
71c71a96f3 swaps: add sanity check to reverse swap mining fee 2025-08-20 17:57:36 +02:00
SomberNight
bb39ca5595 swaps: add sanity-check for total swap costs 2025-08-20 15:13:25 +00:00
ThomasV
5553d5aa86 Merge pull request #10152 from SomberNight/202508_swaps_dm_replies
swaps: nostr: add sanity checks for replies
2025-08-20 12:37:41 +02:00
f321x
04b0aca878 swaps: improve prepayment invoice handling 2025-08-20 12:04:44 +02:00
SomberNight
93e0e8a7b8 swaps: nostr: add sanity checks for replies 2025-08-19 16:38:27 +00:00
ThomasV
eae6ddd773 submarine_swaps: use dict instead of defaultdict for dm_replies 2025-08-19 17:54:25 +02:00
SomberNight
81be0554a3 swaps: more robust parsing 2025-08-19 13:42:21 +00:00
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