Commit Graph

167 Commits

Author SHA1 Message Date
Sander van Grieken 6fdb6c93f7 refactor lnworker.pay_invoice to accept Invoice object instead of bolt11 string
rename lnworker._check_invoice to lnworker._check_bolt11_invoice
2025-03-09 14:47:34 +01:00
ThomasV 840243e029 separate fee policy from config
- Wallet.make_unsigned_transaction takes a FeePolicy parameter
 - fee sliders act on a FeePolicy instead of config
 - different fee policies may be used for different purposes
 - do not detect dust outputs in lnsweep, delegate that to lnwatcher
2025-03-05 10:29:26 +01:00
ThomasV 0e40be5fb5 swaps: replace request_swap_for_tx with request_swap_for_amount,
as this uses less side effects

(change backported from batch_payment_manager)
2025-03-03 14:02:29 +01:00
f321x 6f97b7b5f9 simplify submarine swap onchain fee model to single base fee 2025-02-20 16:51:48 +01:00
ThomasV 392c219913 simplify history-related commands:
- reduce number of methods
 - use nametuples instead of dicts
 - only two types: OnchainHistoryItem and LightningHistoryItem
 - channel open/closes are groups
 - move capital gains into separate RPC
2025-02-19 11:40:21 +01:00
ThomasV 18baf003d4 submarine swaps: backport changes from batch_payment_manager
- add 'is_funded' method to SwapData
 - sign claim transactions using the 'make_witness' method
2025-02-15 10:29:19 +01:00
SomberNight 2d8c26f211 qt swaps: fix _spend_max_reverse_swap: round down msats
Clicking "max" btn for a reverse swap was setting the text field to a too high value.

```
>>> wallet.lnworker.num_sats_can_send()
Decimal('1242647.947')
>>> util.format_satoshis_plain(Decimal('1242647.947'))
'0.01242648'
```
2025-02-14 14:33:51 +00:00
SomberNight 6749468866 swaps: add base class for transports. move "get_recent_offers" logic
the "get_recent_offers" logic is now shared between the GUIs
2025-02-14 14:10:24 +00:00
Sander van Grieken 993a575b7f submarine_swaps: implement swaps-over-nostr for qml 2025-02-14 09:54:09 +01:00
f321x a47421490d increase nonce size to 32 byte and make it hex in event 2025-02-12 10:09:11 +01:00
f321x 947094c1b0 add pow, more default relays, new event type 2025-02-11 18:16:15 +01:00
ThomasV 0ef7235147 swaps: ignore exceptions in publish_offers
nostr may temporarily raise an exception; we don't want to kill the taskgroup
2025-01-16 09:51:26 +01:00
ThomasV 0efe7e9bc8 swaps: make the zeroconf option non-persisted
Since we allow swaps with random servers, we should not persist that setting.
2025-01-10 16:19:01 +01:00
ThomasV 692a777da8 coins tab: if we do not know whether we can swap a utxo, assume we can 2024-12-17 17:43:43 +01:00
ThomasV 1da937f103 swaps: set nsequence in create_claim_tx (follow-up previous commit) 2024-12-11 10:24:40 +01:00
ThomasV 0599254e1f lnsweep and submarine_swaps: set txin.nsequence, instead of
calling set_rbf. set_rbf must be avoided if we batch transactions,
because it blindly overwrites nsequence of all txins.
2024-12-11 09:56:42 +01:00
ThomasV 26ed696479 swaps: follow-up d838b6c9b9b4d669c81832f5be256aca148c89d7 2024-12-08 10:41:55 +01:00
ThomasV 9aa7222c5c swaps: let plugin override self.is_server (config variable may be ser and plugin not active) 2024-12-01 09:16:16 +01:00
ThomasV 60f13a977e Swaps over Nostr
- Separation between SwapManager and its transport:
   Legacy transpport uses http, Nostr uses websockets
 - The transport uses a context to open/close connections.
   This context is not async, because it needs to be called
   from the GUI
 - Swapserver fees values are initialized to None instead
   of 0, so that any attempt to use them before the swap
   manager is initialized will raise an exception.
 - Remove swapserver fees disk caching (swap_pairs file)
 - Regtests use http transport
 - Android uses http transport (until QML is ready)
2024-11-12 09:32:25 +01:00
ThomasV 69503bbeb4 submarine swaps: disable tx batching, because we need
to handle the case where base_tx gets mined instead of
the replacing tx.

Also, call adb.add_transaction before broadcasting, to
prevent races.
2024-11-07 11:25:36 +01:00
ThomasV 3ee2d6a01d follow-up previous commit (indentation error) 2024-10-31 10:21:05 +01:00
ThomasV f41a8105a1 normal swaps: do not try to get a refund if we have the preimage.
The other party's claim transaction might still be unconfirmed
at that point.
2024-10-31 10:13:34 +01:00
ThomasV 3f85c7132a swapserver: add config variable SWAPSERVER_FEE_MILLIONTHS 2024-10-14 10:23:03 +02:00
ThomasV 5928dbbc47 qt normal swap dialog: do not use run_from_another_thread, as it is blocking 2024-10-13 09:53:14 +02:00
ThomasV 3721f04ac8 replace electrum/ecc with electrum_ecc package 2024-10-10 15:46:00 +00:00
ThomasV e2afe2059b move tx grouping code from lnworker to submarine_swaps
This better encapsulates the swaps logic. If we turn
submarine_swaps into a plugin, these methods can be
replaced by hooks.
2024-10-03 14:49:00 +02:00
SomberNight 7a0bffc3e3 swaps: broadcast_transaction error-handling 2024-06-05 19:00:51 +00:00
ThomasV 6b02364457 follow-up 444b3f3e17: if we bump the fee of a claim tx, we must broadcast because add_transaction will fail 2024-06-05 19:39:14 +02:00
ThomasV 444b3f3e17 swapserver: bump fee of refund tx if needed 2024-06-05 13:49:31 +02:00
ThomasV fd672fed9f submarine swaps: separate server logic from transport 2024-05-07 09:01:33 +02:00
ThomasV 01ca1b0382 submarine_swaps: move http calls to method 2024-05-06 14:20:41 +02:00
SomberNight 2f1095510c bitcoin.py/transaction.py: API changes: rm most hex usage
Instead of some functions operating with hex strings,
and others using bytes, this consolidates most things to use bytes.

This mainly focuses on bitcoin.py and transaction.py,
and then adapts the API usages in other files.

Notably,
- scripts,
- pubkeys,
- signatures
should be bytes in almost all places now.
2024-04-29 17:10:26 +00:00
ghost43 745f9184e4 Merge pull request #8942 from SomberNight/202403_get_swap_by_funding_tx
swaps: fix get_swap_by_funding_tx, and types/type-hints
2024-03-13 13:55:18 +00:00
SomberNight 4a71032318 swaps: expand docstring for reverse_swap 2024-03-13 12:27:10 +00:00
SomberNight 05599eeda5 swaps: fix get_swap_by_funding_tx, and types/type-hints
- funding txs having only one output is not true...
- batch_rbf can combine funding txs
2024-03-13 11:37:01 +00:00
SomberNight af6a1f3d01 swaps: use longer final_cltv_delta for client-normal-swap
This gives more time for the client to come back online.

see https://github.com/spesmilo/electrum/issues/8940

- re note on submarine_swaps.py#L53:
  lnpeer.Peer.maybe_fulfill_htlc only checks against MIN_FINAL_CLTV_DELTA_ACCEPTED(=144),
  so this increased cltv_delta is not enforced when receiving the htlc on ln.
  It is put in the invoice, so the sender is supposed to honour it ofc.
  It would be nice to enforce it (make the check in maybe_fulfill_htlc dependent on
  what was in the invoice).
2024-03-12 14:20:52 +00:00
ThomasV 7ff3a0feff submarine swaps: fail htlc with INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS
If the sender uses trampoline, UNKNOWN_NEXT_PEER causes them to
retry, while INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS breaks the loop.
2024-02-22 10:11:34 +01:00
ThomasV b563c9dd0e submarine swaps: do not set attempts parameter in pay_invoice
there is no reason to handle that differently.
2024-01-18 12:38:10 +01:00
MrNaif2018 7369145a49 Fix graceful shutdown for lightning swaps 2024-01-10 17:17:48 +01:00
ThomasV 178a03129f submarine_swaps: define main_loop, with async with taskgroup
rm unneeded @ignore_exception wrapper in lnworker and network
2024-01-10 17:15:29 +01:00
SomberNight 8db68cadcd swaps: forward swap: make cltv requirements explicit
related: fb4eb86e7c
2023-11-22 18:00:32 +00:00
SomberNight 9f1b8613d0 swaps: code style clean-up, add type hints, force kwargs
no intended functional changes
2023-11-22 17:50:29 +00:00
SomberNight 9d5d582752 swaps: forward swap: (fix) propagate channels parameter 2023-11-22 16:59:24 +00:00
ThomasV 9b1c40e396 Refactor payment forwarding:
- all forwarding types use the same flow
 - forwarding callback returns a htlc_key or None
 - forwarding info is persisted in lnworker:
   - ongoing_forwardings
   - downstream to upstream htlc_key
   - htlc_key -> error_bytes
2023-11-18 16:03:18 +01:00
SomberNight c4068ab6cc swaps: add small comment 2023-11-17 11:16:45 +00:00
ThomasV fb4eb86e7c submarine swaps: remove support for 'old' normal swaps,
where the user has the preimage.

The CLTV requirements between old and new flow are imcompatible.
With the current locktime value, the server was vulnerable to an
attack where the client does not settle the lightning payment
and claims a refund. In order to support both old and new flows,
one would need to use different locktimes.
2023-11-10 10:35:34 +01:00
ThomasV 300c3bbd30 submarine_swaps: rename variable for clarity 2023-11-10 10:05:04 +01:00
ThomasV fce83c708c fail_swap: do not remove swap if it has been funded 2023-10-24 17:25:53 +02:00
SomberNight 65394c37d5 wallet.make_unsigned_transaction: add batch_rbf/send_change params
Don't side-effect config just to modify the next call of make_unsigned_transaction >.<
Cleaner to pass parameters.
2023-10-10 17:13:18 +00:00
ThomasV 535f7cdcb7 follow-up previous commit 2023-10-07 17:03:13 +02:00