Commit Graph

886 Commits

Author SHA1 Message Date
f321x
e8171ca7c6 suggest_splits: don't exclude single part configs for too small multi
part configs

I noticed certain ln payments become very unreliable. These payments are ~21k sat, from gossip to gossip sender, with direct, unannounced channel.

Due to the recent fix https://github.com/spesmilo/electrum/pull/9723 `LNPathFinder.get_shortest_path_hops()` will not use channels for the last hop of a route anymore that aren't also passed to it in `my_sending_channels`:

```python
if edge_startnode == nodeA and my_sending_channels:  # payment outgoing, on our channel
    if edge_channel_id not in my_sending_channels:
        continue
```

Conceptually this makes sense as we only want to send through `my_sending_channels`, however if the only channel between us and the receiver is a direct channel that we got from the r_tag and it's not passed in `my_sending_channel` it's not able to construct a route now.

Previously this type of payment worked as `get_shortest_path_hops()` knew of the direct channel between us and `nodeB` from the invoices r_tag and then just used this channel as the route, even though it was (often) not contained in `my_sending_channels`.

`my_sending_channels`, passed in `LNWallet.create_routes_for_payment()` is either a single channel or all our channels, depending on `is_multichan_mpp`:

```python
for sc in split_configurations:
	  is_multichan_mpp = len(sc.config.items()) > 1
```

This causes the unreliable, random behavior as `LNWallet.suggest_splits()` is supposed to `exclude_single_part_payments` if the amount is > `MPP_SPLIT_PART_MINAMT_SAT` (5000 sat).
As `mpp_split.py suggest_splits()` is selecting channels randomly, and then removes single part configs, it sometimes doesn't return a single configuration, as it removes single part splits, and also removes multi part splits if a part is below 10 000 sat:

```python
if target_parts > 1 and config.is_any_amount_smaller_than_min_part_size():
    continue
```

This will result in a fallback to allow single part payments:

```python
split_configurations = get_splits()
if not split_configurations and exclude_single_part_payments:
    exclude_single_part_payments = False
    split_configurations = get_splits()
```

Then the payment works as all our channels are passed as `my_sending_channels` to  `LNWallet.create_routes_for_payment()`.

However sometimes this fallback doesn't happen, because a few mpp configurations found in the first iteration of `suggest_splits` have been kept, e.g. [10500, 10500], but at the same time most others have been removed as they crossed the limit, e.g. [11001, 9999], (which happens sometimes with payments ~20k sat), this makes `suggest_splits` return very few usable channels/configurations (sometimes just one or two, even with way more available channels).
This makes payments in this range unreliable as we do not retry to generate new split configurations if the following path finding fails with `NoPathFound()`, and there is no single part configuration that allows the path finding to access all channels. Also this does not only affect direct channel payments, but all gossip payments in this amount range.

There seem to be multiple ways to fix this, i think one simple approach is to just disable `exclude_single_part_payments` if the splitting loop already begins to sort out configs on the second iteration (the first split), as this indicates that the amount may be too small to split within the given limits, and prevents the issue of having only few valid splits returned and not going into the fallback. However this also results in increased usage of single part payments.
2025-05-15 10:26:33 +02:00
ThomasV
5be646dfd2 call lnwatcher callbacks in asyncio thread
This partially reverts fbebe7de1a
lnwatcher.trigger_callbacks is called manually in commands.py
2025-05-06 12:37:00 +02:00
f321x
396800be61 fix: exception in suggest_swap_to_send due to missing method
can_pay_onchain has been removed in commit 840243e but
suggest_swap_to_send was still calling it causing an exception.
2025-05-05 12:41:41 +02:00
f321x
e72de47ef0 Remove LIGHTNING_LEGACY_ADD_TRAMPOLINE config option to prevent too large onion payload
The option to add a 2nd trampoline hop to legacy trampoline payments requires too much space in the trampoline onion.
Because the trampoline onion has only limited space of 400b and the payload with 2nd t hop and no r_tags already requires 392b it is essentially unusable for payments that require routing hints to be included in the onion
(because the receiver has no direct channel to the 2nd trampoline node)
as there is no space left to include them (1r_tag == ~52b).
2025-04-14 09:35:41 +02:00
ThomasV
875cb24665 Merge pull request #9707 from f321x/fix_receive_unknown_htlc_failed
lightning: trigger payment_failed only once in LNWallet.htlc_failed().
2025-04-11 12:39:25 +02:00
f321x
253ab6849a implement NIP47 plugin 2025-04-10 10:22:29 +02:00
Sander van Grieken
f751a77a65 lnworker: use MIN_FUNDING_SAT as lower bound for channel open 2025-04-07 13:09:09 +02:00
f321x
cb4837f1b3 trigger payment_failed only once on htlc timeout tx failing 2025-04-07 13:00:29 +02:00
f321x
6e8bdb346a move onchain balance calculation to wallet.py 2025-04-04 15:08:51 +02:00
ThomasV
b339b1e7e3 ln_utxo_reserve
When we send max, decrease sent amount in order to keep some
reserve utxo, in order to be able to sweep lightning channels.
2025-04-03 14:39:05 +02:00
ThomasV
651e081b2f Merge pull request #9671 from accumulator/fix_lightning_can_receive_offline_peer
lnworker: take peer_state into account in get_channels_for_receiving
2025-04-02 14:33:45 +02:00
f321x
964ffbd2c4 don't use route hint channels if they are frozen 2025-04-02 13:48:46 +02:00
Sander van Grieken
08e2970889 lnworker: add parameter include_disconnected for get_channels_for_receiving(),
allowing less strict filtering when building route hints (i.e. likely usable soon-ish)
2025-04-02 11:35:47 +02:00
f321x
0b19b660c5 don't use fallback feerates in lightning by default 2025-04-01 14:12:02 +02:00
ThomasV
e9335f5cc7 fix typo 2025-03-20 10:54:29 +01:00
ThomasV
525e261520 lnworker: replace sometimes failing assert with print statement
this assert typically fails when a channel is force-closed and
the tx is unconfirmed
2025-03-20 10:09:04 +01:00
ThomasV
60338eba5d lnworker.handle_onchain_state early return if no network (follow-up fbebe7de1a) 2025-03-20 10:00:59 +01:00
SomberNight
d36e877eb8 lnworker: comment re hist: if paying MPP, amt and fee might be shifted
a bit confusing behaviour
2025-03-18 19:25:18 +00:00
ThomasV
26910ef81d Merge pull request #9620 from accumulator/lightning_pass_invoice_not_bolt11
refactor lnworker.pay_invoice to accept Invoice object instead of bolt11 string
2025-03-18 20:09:01 +01:00
ThomasV
8e6be0a36a Remove inheritance between LNWatcher and Watchtower
As LNWatcher is no longer async, there is not enough overlap
between these classes to deserve inheritance
2025-03-14 11:59:56 +01:00
ThomasV
fbebe7de1a Make lnwatcher not async
This fixes offline history not having the proper labels
2025-03-14 11:09:11 +01:00
f321x
af8d1fb401 handle jit invoices in qml
make min funding amount symbol, change Signal name, change Exception type

change minChannelFunding to QEAmount and make message text variable

qml: improve translatibility of strings

init minchannelfunding value in init method

rebase on master
2025-03-13 12:02:46 +01:00
ThomasV
798df671ea If we have proposed htlcs in a channel that was force-closed,
call lnworker.htlc_failed once the htlc_tx is deeply mined.

In the case of a forwarding, this will fail incoming htlcs.
(fixes #8547)
2025-03-12 20:11:11 +01:00
ThomasV
c42201ccac remove lnworker.enable_htlc_settle_onchain: not used
I think this has only been used for manual testing
2025-03-11 12:12:43 +01:00
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
8011ae00ab Merge pull request #9586 from f321x/jit-block-preimage
Add mechanism to block htlcs from settling back
2025-03-07 12:04:39 +01:00
f321x
109ad2b3da add mechanism to block htlcs from settling back 2025-03-07 12:03:59 +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
6234cbf97b Merge pull request #9603 from spesmilo/gossip_info
gossip: less log lines, use command line instead
2025-03-05 08:23:19 +01:00
ThomasV
1201b87ad7 Merge pull request #9587 from f321x/jit-invoice-creation
Disable mpp flags in invoice creation if jit channel is required and consider available liquidity
2025-03-04 16:07:54 +01:00
f321x
d62eb7ab13 disable mpp flags in invoice creation if jit channel is required, check against available liquidity if we need a jit channel 2025-03-04 15:24:03 +01:00
ThomasV
96d0dad41c gossip: less log lines, use command line instead 2025-03-04 14:33:54 +01:00
f321x
d348da811a introduce gossip query handling and forwarding 2025-03-04 13:10:37 +01:00
ThomasV
4917f7e3ce fix balance sanity check in get_lightning_history 2025-02-28 09:42:24 +01:00
ThomasV
d714ef130a Merge pull request #9039 from accumulator/onion_messages
onion messages
2025-02-20 18:12:40 +01:00
ThomasV
f9c427124d qml: fix follow-up 392c219913 2025-02-20 09:38:47 +01:00
Sander van Grieken
7b4180202a add onion message support 2025-02-19 14:29:02 +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
Sander van Grieken
c740057bc7 lnworker: imports, whitespace 2025-02-17 14:41:32 +01:00
f321x
5eb9aa074e change to separate exception class for too low fees
store exception in variable instead of using a bool flag

add default str to routing exceptions

Add separate exception class to handle fee related payment errors
2025-01-28 16:15:03 +01:00
f321x
41e32145a8 Add maybe_fee_related bool to NoPathFound and set it on instanciation in according places 2025-01-28 15:58:03 +01:00
SomberNight
0779d9d7ae fallback ln nodes: simplify a bit
note: BitcoinRegtest subclasses BitcoinTestnet, so the FALLBACK_LN_NODES field should be overwritten

trivial follow-up of https://github.com/spesmilo/electrum/pull/9457
2025-01-27 13:19:29 +00:00
ThomasV
373d875f08 Merge pull request #9457 from f321x/move_constants
Move fallback ln nodes in separate json files
2025-01-22 14:58:56 +01:00
ThomasV
a084ccc74c lnworker: fix how lightning balance is affected when a channel is
force-closed. Assert final balance in lnworker.get_history().

If we offered some HTLCs, we do not know yet whether they will be
redeemed by us or by the remote.
2025-01-21 17:14:17 +01:00
f321x
eb600a3a14 move fallback ln nodes in separate json files and import them in constants 2025-01-20 11:13:23 +01:00
ThomasV
64e07732f8 Merge pull request #9430 from SomberNight/202501_funding_pubkey_deriv
lightning: change derivation of funding_pubkey
2025-01-17 10:49:16 +01:00
f321x
b1e1a39997 add fallback list of signet nodes 2025-01-15 16:40:30 +01:00
f321x
48c53053d6 don't inline logic and add comment 2025-01-15 10:44:01 +01:00
SomberNight
cba073dfd1 lightning: change derivation of funding_pubkey
Ideally, given an on-chain backup, after the remote force-closes, we should be able to spend our anchor output,
to CPFP the remote commitment tx (assuming the channel used OPTION_ANCHORS).
To spend the anchor output, we need to be able to sign with the local funding_privkey.

Previously we derived the funding_key from the channel_seed (which comes from os.urandom).
Prior to anchors, there was no use case for signing with the funding_key given a channel backup.
Now with anchors, we should make its derivation deterministic somehow, in a way so that it can
be derived given just an on-chain backup.
- one way would be to put some more data into the existing OP_RETURN
  - uses block space
  - the OP_RETURNs can be disabled via "use_recoverable_channels"
  - only the initiator can use OP_RETURNs (so what if channel is in incoming dir?)
- instead, new scheme for our funding_key:
  - we derive the funding_privkey from the lnworker root secret (derived from our bip32 seed)
  - for outgoing channels:
    - lnworker_root_secret + remote_node_id + funding_tx_nlocktime
  - for incoming channels:
    - lnworker_root_secret + remote_node_id + remote_funding_pubkey
  - a check is added to avoid reusing the same key between channels:
      not letting to user open more than one channel with the same peer in a single block
  - only the first 16 bytes of the remote_node_id are used, as the onchain backup OP_RETURNs only contain that
- as the funding_privkey cannot be derived from the channel_seed anymore, it is included in the
imported channel backups, which in turn need a new version defined
  - a wallet db upgrade is used to update already stored imported cbs
  - alternatively we could keep the imported cbs as-is, so no new version, no new funding_privkey field, as it is clearly somewhat redundant given on-chain backups can reconstruct it
    - however adding the field seems easier
      - otherwise the existing code would try to derive the funding_privkey from the channel_seed
      - also note: atm there is no field in the imported backups to distinguish anchor channels vs static-remotekey channels
2025-01-14 17:56:48 +00: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