1
0
Commit Graph

135 Commits

Author SHA1 Message Date
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
ThomasV
16ef287e86 swap server: try to batch funding transactions 2023-10-07 13:26:07 +02:00
ThomasV
622162a056 submarine swaps:
- use SPV'd funding_height.conf instead of txin.height
- remove local transactions if funding tx was double spent
2023-09-21 10:29:15 +02:00
Sander van Grieken
8dbddedd30 submarine swaps: register hold invoice early in wait_for_htlcs_and_broadcast, so a SwapManager.cancel_normal_swap() does not race.
cancel_normal_swap unregisters the hold invoice, which can occur before register_hold_invoice in wait_for_htlcs_and_broadcast
if the network call has not returned yet.
2023-09-18 16:58:04 +02:00
ThomasV
c27e6de975 Merge pull request #8616 from SomberNight/202309_dont_sign_tx_with_dummy_addr
add sanity checks we don't sign tx including dummy addr
2023-09-16 15:02:36 +02:00
ThomasV
ea79562b7a submarine swaps: remove expired swaps from the list, and log the reason for failing a swap. 2023-09-16 10:21:08 +02:00
SomberNight
4c63d8729b add sanity checks we don't sign tx including dummy addr
Somewhat a follow-up to 649ce979ab.

This adds some safety belts so we don't accidentally sign a tx that
contains a dummy address.
Specifically we check that tx does not contain output for dummy addr:
- in wallet.sign_transaction
- in network.broadcast_transaction

The second one is perhaps redundant, but I think it does not hurt.
2023-09-16 04:36:08 +00:00
ThomasV
3bc9ead67b submarine swaps: use password stored in memory. fixes #8612 2023-09-15 16:01:13 +02:00
ThomasV
9df8bb61a5 Give users an option to cancel a submarine swap while awaiting HTLCs.
Note that HTLCs must not be cancelled after the funding transaction
has been broadcast. If one want to cancel a swap once the funding
transaction is in mempool, one should double spend the transaction.
2023-09-13 16:28:31 +02:00
ThomasV
649ce979ab send tx change to lightning 2023-09-09 14:14:43 +02:00
ThomasV
136978e9d0 submarine swaps: fail received HTLCs of normal swap htlcs if
the swap is still unfunded and the refund delay has expired.
2023-09-08 16:38:08 +02:00
SomberNight
6a2806c2c5 simple_config: implement complex default values
Besides a literal value, the default can now also be a callable,
which gets called with the config and evaluated as needed, lazily.

This potentially allows e.g. the default value of one configvar to
depend on the current value of another configvar.
2023-09-07 15:30:46 +00:00
SomberNight
a560841f3f lnworker: fix some type hints re hold_invoices 2023-09-06 19:01:41 +00:00
SomberNight
6468813105 swaps: fix type of payment_hash in init 2023-09-06 18:01:04 +00:00
ThomasV
78f0f788d6 submarine swaps: use a short expiry with hold invoices, and display result to the user 2023-08-30 11:07:16 +02:00
ThomasV
f5ab4b0f18 swapserver: sanity check amount in new flow 2023-08-27 20:56:49 +02:00
ThomasV
e06df2cb69 swapserver: reduce refund delay to 70 blocks
if a refund occurs, it needs to be done before the cltv expiration
of the htlc, or the channel might be force closed.
2023-08-27 14:06:56 +02:00
ThomasV
68be768818 swapserver: use taskgroup (follow-up 0083560ee6) 2023-08-15 09:15:57 +02:00
ThomasV
0083560ee6 swapserver: throttle payments, handle exceptions in pay_pending_invoices 2023-08-14 09:53:04 +02:00
ThomasV
f85354903d swapserver: try many times, to increase trampoline fee 2023-08-10 19:55:10 +02:00
ThomasV
dfa0dd47b7 swapserver: remove config option LIGHTNING_SWAP_HTLC_FIRST; read it from get_pairs instead. 2023-08-10 17:06:31 +02:00
ThomasV
e0c1fbfe77 normal swaps: use different callbacks for server and client
- client creates tx immediately
- server defers tx creation, and does not use encrypted storage
2023-08-10 15:19:52 +02:00
ThomasV
fd10ae3a3b New flow for submarine swaps:
- client requests payment_hash from the server
 - client sends an invoice with that hash
 - client waits to receive HTLCs, then broadcasts funding tx

This means that we now use same script for normal and reverse swaps.
The new flow is enabled by setting option LIGHTNING_SWAP_HTLC_FIRST
in the client. The old protocol is still supported server-side.
2023-08-10 09:04:30 +02:00
ThomasV
11af4e47a8 follow-up ff547e3dcf 2023-08-10 09:02:42 +02:00
ThomasV
ff547e3dcf swapserver: use a single config variable for swapserver_url; testnet and regtest have their own config files 2023-08-10 08:11:37 +02:00
ThomasV
1ce50b9dee submarine swaps: register callbacks on startup 2023-08-09 14:15:49 +02:00
ThomasV
bf86cd6761 lnpeer and lnworker cleanup:
- rename trampoline_forwardings -> final_onion_forwardings,
   because this dict is used for both trampoline and hold invoices
 - remove timeout from hold_invoice_callbacks (redundant with invoice)
 - add test_failure boolean parameter to TestPeer._test_simple_payment,
   in order to test correct propagation of OnionRoutingFailures.
 - maybe_fulfill_htlc: raise an OnionRoutingFailure if we do not have
   the preimage for a payment that does not have a hold invoice callback.
   Without this, the above unit tests stall when we use test_failure=True
2023-08-09 13:23:26 +02:00
ThomasV
cb907c90f9 submarine swaps: set prepay_hash for normal swaps.
This fixes the group_id of fee prepayment transactions for the server
2023-08-06 11:37:31 +02:00
ThomasV
69a1242ea8 restructure submarine_swaps._claim_swap 2023-07-26 19:20:18 +02:00
ThomasV
1411b75584 swapserver: add test for refund path 2023-07-26 19:20:18 +02:00
ThomasV
351ff1e4b5 swapserver: support prepayment of fees 2023-07-26 19:20:18 +02:00
ThomasV
098c65d732 submarine swap server plugin:
- hold invoices
 - uses the same web API as the Boltz backend
2023-07-26 19:20:18 +02:00
ThomasV
39f8664402 make submarine swap server url configurable 2023-06-19 14:46:56 +02:00