Commit Graph

838 Commits

Author SHA1 Message Date
f321x
48c53053d6 don't inline logic and add comment 2025-01-15 10:44:01 +01:00
f321x
4c93c9a26c limit payment attempts if client uses trampoline
revert line break

limit payment attempts if client uses trampoline
2025-01-14 11:18:21 +01:00
SomberNight
8f5b395ddc lnworker.open_channel: move max funding_sat check deeper in call stack
open_channel_with_peer was missing this check
2025-01-13 14:53:16 +00:00
ThomasV
33d0e6dbec Attach labels to outpoints instead of txids.
Move labels logic from lnworker to wallet.

Due to batching, a single transaction may have several labels attached to it.
2025-01-03 10:54:11 +01:00
ThomasV
29a8c41025 move watchtower to a plugin.
remove watchtower dialog in qt
2024-12-20 15:34:26 +01:00
ThomasV
ee42e09387 anchor channels: unlock wallet on startup if the wallet has channels 2024-12-20 10:10:07 +01:00
ThomasV
67470b92b7 lnchannel: fix extract_preimage for MPP.
- enforce MPP in the corresponding regtest.
 - fix get_invoice_status returning inflight if it was settled onchain
2024-12-15 10:46:18 +01:00
bitromortac
ea584e13fc anchors: switch to zero-fee-htlcs
* sets the weight of htlc transactions to zero, thereby putting a zero
  fee for the htlc transactions
* add inputs to htlc-tx for fee bumping
* switches feature flags
* disable anchor test vectors, which are now partially invalid
2024-11-25 10:56:50 +01:00
ThomasV
ece1fb39d2 enable anchor outputs via config option 2024-11-23 10:10:16 +01:00
bitromortac
b6e224c864 lnwatcher: add field for onchain htlc settlement control 2024-11-21 10:58:41 +01:00
bitromortac
22f5ff0d0e add static payment key
* in order to be able to sweep to_remote in an onchain backup scenario
  we need to retain the private key for the payment_basepoint
* to facilitate the above, we open a channel derived from a static
  secret (tied to the wallet seed), the static_payment_key combined with
the funding pubkey (multisig_key), which we can restore from the channel
closing transaction
2024-11-20 10:08:26 +01:00
ThomasV
58fee0d1cc Merge pull request #9265 from SomberNight/202410_ln_address_reuse_2
lnworker: reserve wallet addresses also for chan backups
2024-11-13 10:59:03 +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
3ee2d6a01d follow-up previous commit (indentation error) 2024-10-31 10:21:05 +01:00
accumulator
1b9f1dbb7f Merge pull request #9250 from accumulator/network_tor_stream_isolation
network: use TOR stream isolation
2024-10-28 09:50:00 +01:00
ThomasV
3c61f2a64a Fix #9280:
- Wait until HTLCs are irrevocably removed before cleaning up their
   data structures (MPP and forwarding)
 - keep methods maybe_cleanup_mpp and maybe_cleanup_forwarding separate
 - perform cleanup in htlc_switch, so that process_unfulfilled_htlc
   has less side effects
 - In htlc_switch, we blank the onion_packet_hex field to signal that
   an HTLC has been processed. An item of chan.unfulfilled_htlcs may
   go through 4 stages:
   - 1. not forwarded yet: (None, onion_packet_hex)
   - 2. forwarded: (forwarding_key, onion_packet_hex)
   - 3. processed: (forwarding_key, None), not irrevocably removed yet
   - 4. done: (forwarding_key, None), irrevocably removed
 - in test_lnpeer, an extra iteration of htlc_switch has been added to
   trampoline forwarding tests
2024-10-27 07:23:38 +01:00
ThomasV
fabc3637a2 lnsweep: use lnworker.is_accepted_mpp to decide if we can
release the preimage. (see #9280)

lnworker.is_accepted_mpp includes an assert that will raise
if the MPP has been cleaned-up too early.
2024-10-25 12:21:19 +02:00
Sander van Grieken
f4520b9e0d network: use TOR stream isolation
also refactor, for proxy instantiation, use Network instance, not a proxy dict.
2024-10-25 01:10:58 +02:00
ThomasV
4420944b76 lnsweep: detect incomplete MPP using mpp status instead of get_payment_status
get_payment_status is not set in the case of a hold invvoice
2024-10-24 11:20:12 +02:00
ThomasV
5708f7b1c8 Persist MPP resolution status in wallet file.
If we accept a MPP and we forward the payment (trampoline or swap),
we need to persist the payment accepted status, or we might wrongly
release htlcs on the next restart.

lnworker.received_mpp_htlcs used to be cleaned up in maybe_cleanup_forwarding,
which only applies to forwarded payments. However, since we now
persist this dict, we need to clean it up also in the case of
payments received by us. This part of maybe_cleanup_forwarding has
been migrated to lnworker.maybe_cleanup_mpp
2024-10-24 11:19:53 +02:00
ThomasV
c58c4d7451 Make lntransport not require lnutil.
This will be useful if we decide to ship lntransport as a separate
package. It is also a conceptual cleanup.

Notes:
 - lntransport still requires crypto.py
 - parsing node id from a bolt11 invoice is not supported.
2024-10-22 09:26:36 +02:00
SomberNight
b9a81cd03e lnworker: reserve wallet addresses also for chan backups
We were already reserving wallet addresses for full channels.
Now we also do the same for imported channel backups.
(but not for onchain, as we don't have enough info for that)

Without this, if the same seed is used on multiple devices (with each
device having its own set of LN channels), the wallet instances will
reuse keys (specifically the payment_basepoint, which for
static_remotekey chans is used as the to_remote output).
Now with this change, at least if the wallet instances have imported
channel backups of each other, this reuse is avoided.
2024-10-20 13:58:10 +00:00
SomberNight
dd140df17d lnchannel: convert sweep_address property to get_sweep_address() method
no functional changes
2024-10-20 13:12:52 +00: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
ThomasV
982443eaa3 maybe_cleanup_forwarding: fix crash if payment_key not in self.received_mpp_htlcs 2024-06-05 16:49:33 +02:00
SomberNight
eb6e503556 lnworker: follow-up prev: add some nuance to peer-collision-handling
e.g. existing peer might not have a working socket
2024-06-03 17:09:01 +00:00
ThomasV
0c48fd495f lnworker: if two instances of the same wallet are trying to connect
simultaneously, give priority to the existing connection
2024-06-03 18:34:47 +02:00
jinjiadu
e86c05177f chore: fix comment
Signed-off-by: jinjiadu <jinjiadu@aliyun.com>
2024-06-01 15:01:08 +08:00
SomberNight
235e28ce20 crypto: add some notes re considerations 2024-05-22 13:39:27 +00:00
ThomasV
dfa247773f Merge pull request #9041 from SomberNight/202405_tramp1
trampoline: use exponential search for fees, capped by configurable budget
2024-05-09 09:57:37 +02:00
SomberNight
967ceb7740 lnworker: move around some logging re PaySession, also log budget 2024-05-08 15:53:27 +00:00
SomberNight
67d373357b lnworker: make PaymentFeeBudget defaults configurable
- make PaymentFeeBudget proportional fee and flat cutoff fee configurable
  - closes https://github.com/spesmilo/electrum/issues/7622
- increase flat cutoff fee default to 10 sat
  - closes https://github.com/spesmilo/electrum/issues/7669
- rm RouteEdge.is_sane_to_use() (per edge limit) and just rely on budgets (per route limit)
2024-05-08 15:53:22 +00:00
ThomasV
fd672fed9f submarine swaps: separate server logic from transport 2024-05-07 09:01:33 +02:00
SomberNight
79d2b19fc0 trampoline: rm hardcoded TRAMPOLINE_FEES. just use exponential search
Values for exponential search are based on available fee budget:
we try with budget/64, budget/32, ..., budget/1  (spread uniformly among the selected Trampoline Forwarders).
Hence, if we make the fee budget configurable, that will usefully affect the trampoline fees as well.

related https://github.com/spesmilo/electrum/issues/9033
2024-05-06 18:36:29 +00: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
SomberNight
7a820f7561 lnworker: add_peer: no DNS lookup if a proxy is set, to avoid a DNS-leak
closes https://github.com/spesmilo/electrum/issues/9002
2024-04-24 14:49:23 +00:00
Sander van Grieken
e0e00da004 lnworker: don't query DNS for .onion hosts (fixes #9002) 2024-04-16 13:57:00 +02:00
SomberNight
bd9d0ccc33 ecc: refactor/clean-up sign/verify APIs 2024-04-11 15:25:45 +00:00
SomberNight
58a1bdfec7 lnworker.check_mpp_status: add docstring
This explains why stopping_soon behaves sanely with hold-invoice-htlcs.
2024-03-12 15:28:31 +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
777c2ffb23 create a trampoline onion when directly paying a trampoline node 2024-02-24 16:01:31 +01:00
SomberNight
197979063a lnworker: log gossip_db status in pay_invoice 2024-02-22 12:11:23 +00:00
SomberNight
b6e5fe8dbe lnworker: history to include close tx for channel backups
- scenario:
  - reuse same seed between two devices, LN enabled on both
  - open channel using device1, import chan backup on device2
  - local-force-close channel using device1
  - tx1 (ctx) gets into mempool (or even mined), tx2 (sweep tx for to_local) is a local (future) tx
  - history tab on device1 shows tx1 and tx2
  - history tab on device2 was showing only tx2, and no info about tx1
    - device2 knows about tx1, it was just not showing it previously.
      With this commit, tx1 is now shown in the history.
    - note: tx1 might linger in the mempool for an indeterminate amount of time, or even become local.
      During that time, it is confusing on device2 not to show any feedback. Also,
      if tx1 becomes local, it is useful to be able to rebroadcast it.
2024-02-12 02:01:14 +00:00
SomberNight
e6a0455ced lnpeer: raise chan fees using update_fee more aggressively
The existing logic of only updating the fee if it is not within 2x of
the current 2-block-eta does not work well for the current mempool.

The current mempool looks a bit weird: you need ~20 sat/vbyte to even get into it,
but there is only around 5 MB of txs paying >25 sat/vbyte.
The estimates look like this:
```
>>> config.fee_estimates
{144: 25764, 25: 27075, 10: 34538, 5: 34538, 2: 34538}
```

This commit changes the logic so that we send update_fee if the old rate is
- below 75% of the current 2-block-eta (instead of 50%), or
- below the 25-block-eta
2024-01-31 08:47:29 +00: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
SomberNight
df58dd1f25 lnchannel.get_close_opts: allow REQUEST_REMOTE_FCLOSE if WE_ARE_TOXIC
related https://github.com/spesmilo/electrum/issues/8770
2024-01-15 20:13:38 +00:00
SomberNight
95c55c542e lnworker.suggest_splits: (fix) don't force splitting
lnworker.suggest_splits for non-trampoline case tries to split amts over 5000 sat
but mpp_split.suggest_splits does not return splits where any part is smaller than 10000 sat.
So in practice, without trampoline, invoices between 5k and ~20k sats could not be paid.
This suggests that the logic should not be scattered in multiple places but merged into mpp_split.py...
This commit just does a quick fix though, to try again without splitting if there was no solution.
2024-01-15 20:12:16 +00:00
SomberNight
129917c463 lnworker: fix current_feerate_per_kw for regtest
follow-up 45b248fdef

```
121.72 | I | P/lnpeer.Peer.[LNWallet, 034cd7a09f-e1e44142] | FEES HAVE FALLEN
121.72 | I | P/lnpeer.Peer.[LNWallet, 034cd7a09f-e1e44142] | (chan: 502x1x1) current pending feerate 45000. new feerate 250
121.72 | E | W/lnwatcher.LNWalletWatcher.[default_wallet-LNW] | Exception in update_channel_state: Exception('Cannot update_fee: feerate lower than min relay fee. 250 sat/kw. us: True')
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/util.py", line 1148, in wrapper
    return await func(*args, **kwargs)
  File "/home/user/wspace/electrum/electrum/lnwatcher.py", line 434, in update_channel_state
    await self.lnworker.handle_onchain_state(chan)
  File "/home/user/wspace/electrum/electrum/lnworker.py", line 1216, in handle_onchain_state
    peer.maybe_update_fee(chan)
  File "/home/user/wspace/electrum/electrum/lnpeer.py", line 2221, in maybe_update_fee
    chan.update_fee(feerate_per_kw, True)
  File "/home/user/wspace/electrum/electrum/lnchannel.py", line 1490, in update_fee
    raise Exception(f"Cannot update_fee: feerate lower than min relay fee. {feerate} sat/kw. us: {from_us}")
Exception: Cannot update_fee: feerate lower than min relay fee. 250 sat/kw. us: True
```
2024-01-15 19:28:55 +00:00
MrNaif2018
7369145a49 Fix graceful shutdown for lightning swaps 2024-01-10 17:17:48 +01:00