1
0
Commit Graph

149 Commits

Author SHA1 Message Date
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
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