1
0
Commit Graph

123 Commits

Author SHA1 Message Date
SomberNight
6332a3a6a8 lnrouter: LiquidityHint: fix logic bug in calculation
Reported privately by Zuzana Kotásková <36777@mail.vsfs.cz>
2025-11-11 16:00:41 +00:00
f321x
8d79c58c5e Stop including all invoice r_tags in legacy trampoline onion
This change modifies create_trampoline_onion to only include as many
available r_tags as there is space left in the trampoline onion payload.

Previously we tried to include all passed invoice r_tags of legacy
trampoline payments into the payload which caused an user facing
exception and payment failure as the onion can only store a max of 400
bytes.
A single, single hop r_tag is around 52 bytes and the payload
without r_tags is already at ~280 bytes. So usually there is enough
space for 2 r_tags.
The implementation shuffles the r_tags on each call
so the payment will try different route hints on the attempts (fee level
increase or user retry).

I have logged the following byte sizes of the trampoline onion with a 2
trampoline onion hop and changing amounts of r_tags:

3 rtags:
payload size [0]: 113 (hop size: 81)
payload size [1]: 440 (hop size: 295) ( 52 bytes/rtag )
payload size [2]: 550 (hop size: 78)

2 rtags:
payload size [0]: 113 (hop size: 81)
payload size [1]: 386 (hop size: 241) ( 52 bytes/rtag )
payload size [2]: 496 (hop size: 78)

1 rtag:
payload size [0]: 113 (hop size: 81)
payload size [1]: 334 (hop size: 189) ( 52 bytes/rtag )
payload size [2]: 444 (hop size: 78)

0 rtags:
payload size [0]: 113 (hop size: 81)
payload size [1]: 282 (hop size: 137)
payload size [2]: 392 (hop size: 78)

As can be seen in the data, using 2 trampoline hops there is not enough
space for even a single r_tag which is why this option is being removed
too.
2025-04-14 19:20:11 +02:00
f321x
f1900e493d Fix assertion error in ln payments when using same seed in multiple wallets.
Make path calculation check if channel is not in our sending channels but still uses our nodeID as starting node of the path.

I noticed an assertion error when trying to pay an invoice from a seed i have opened channels with in different wallet instances (same seed, different wallet).
Because the channel seemed suitable for sending the payment path finding included the channel for sending in the first position of the route but then
in pay_to_route the channel for route[0] could not be found as it is not included in our channel list, causing the assert and payment to fail.
2025-04-11 14:04:51 +02:00
Sander van Grieken
7b4180202a add onion message support 2025-02-19 14:29:02 +01:00
SomberNight
90136f0de5 (trivial) fix some import orders
1. stdlib
2. 3rd-party
3. internal

(as in PEP-8)
2024-06-04 18:29:17 +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
SomberNight
6506abf583 lnworker: use PaymentFeeBudget
- introduce PaymentFeeBudget, which contains limits for fee budget and cltv budget
  - when splitting a payment,
    - the fee budget is linearly distributed between the parts
      - this resolves a FIXME in lnrouter ("FIXME in case of MPP")
    - the cltv budget is simply copied
  - we could also add other kinds of budgets later, e.g. for the num in-flight htlcs
- resolves TODO in lnworker ("todo: compare to the fee of the actual route we found")
2023-10-27 16:01:23 +00:00
SomberNight
53a8453e3b trampoline: fix off-by-one confusion of fees
The convention is that edges (start_node -> edge_node) store
the policy/fees for the *start_node*.
This is what the non-trampoline edges were already using (for a long time),
but the trampoline ones were off-by-one (policy was for end_node),
which was then worked around in multiple places, to correct for...

i.e. I think because of all the workarounds, there was no actual bug,
but it was just very confusing.

Also note that the prior usage of trampoline edges would not work if
we (sender) were not directly connected to a TF (trampoline-forwarder)
but had extra edges in the route to even get to the first TF.
Having the policy corresponding to the start_node of the edge would work
even in that case.
2023-10-27 14:24:19 +00:00
SomberNight
22a8348303 renames: use consistent naming of cltv delta vs cltv abs
to avoid confusing relative vs absolute cltvs
(see b0401a6386)
2023-10-19 16:40:05 +00:00
SomberNight
98ccad68c1 channel_db: add TTLs to channel_updates_for_private_channels
eclair sends CHANNEL_DISABLED if its peer is offline. E.g. we might be
trying to pay a mobile phone with the app closed. In that case we
should not cache the CHANNEL_DISABLED for too long.
2023-08-15 16:34:51 +00:00
SomberNight
1dd0608718 lnrouter: rework blacklist a bit
separate from LiquidityHintMgr
2023-08-15 16:34:48 +00:00
SomberNight
35c9ac8f31 lnworker: MPP send: more aggressively split large htlcs
related: https://github.com/spesmilo/electrum/issues/7987#issuecomment-1670002482
2023-08-11 22:01:08 +00:00
SomberNight
cc030c60e9 lnutil: make LnFeatures.supports() faster
LnFeatures.supports() is became part of the hot path of
LNPathFinder.find_path_for_payment()
in 6b43eac6fd,
which made find_path_for_payment considerably slower than before.
It used to take around 0.8 sec originally, then after linked commit went to ~9 sec,
and now this takes it down to ~1.1 sec (on my laptop).
2023-08-10 18:05:02 +00:00
SomberNight
6b43eac6fd lnonion: rm support for legacy (pre-TLV) onions
see https://github.com/lightning/bolts/pull/962
2023-06-29 14:34:06 +00:00
SomberNight
373db76ac9 util: kill bh2u
no longer useful, and the name is so confusing...
2023-02-17 11:43:11 +00:00
ThomasV
8867387847 lnworker: fix stuck payment loop (fixes #7995)
If the short_channel_id of a channel update received
with update_fail_htlc does not match the channel in
our route, blacklist the channel in our route.
2022-10-04 10:51:18 +02:00
bitromortac
4ee5fa75f6 lnrouter+lnworker: rename my_channels 2021-07-29 16:26:23 +02:00
bitromortac
e6ccbcf7b7 lnrouter: fix self-payments 2021-07-28 08:12:44 +02:00
SomberNight
7ee4a2e299 follow-up prev 2021-06-10 18:52:12 +02:00
bitromortac
2749ea4d49 lnrouter: add inflight htlcs to liquidity hints 2021-05-11 09:17:11 +02:00
bitromortac
5e03d751eb lnrouter: add hint timestamp 2021-04-09 11:11:22 +02:00
bitromortac
bc20f57a78 lnrouter: remove blacklist boolean 2021-04-09 11:11:21 +02:00
bitromortac
2a45fdf09b lnrouter: penalty code simplification
Co-authored-by: ghost43 <somber.night@protonmail.com>
2021-04-06 20:13:42 +02:00
bitromortac
4df67a4f78 lnrouter+lnworker: use liquidity hints
Adds liquidity hints for the sending capabilities of routing channels in the
graph. The channel blacklist is incorporated into liquidity hints.
Liquidity hints are updated when a payment fails with a temporary
channel failure or when it succeeds. Liquidity hints are used to give a
penalty in the _edge_cost heuristics used by the pathfinding algorithm.
The base penalty in (_edge_cost) is removed because it is now part of the
liquidity penalty. We don't return early from get_distances, as we want
to explore all channels.
2021-04-06 20:13:42 +02:00
SomberNight
95b7c976e0 lnrouter.get_distances: fix exception due to rare race
if the graph is being updated while the pathfinding is running,
channel_info might be None here
2021-03-03 14:10:57 +01:00
SomberNight
750d8cfab5 lnworker: run create_route_for_payment end-to-end, incl private edges
We pass the private edges to lnrouter, and let it find routes end-to-end.
Previously the edge_cost heuristics didn't apply to the private edges
and we were just randomly picking one of the route hints and use that.
So e.g. cheaper private edges were not preferred, but they are now.

PathEdge now stores both start_node and end_node; not just end_node.
2021-03-02 18:00:31 +01:00
SomberNight
ab9bf07a79 (trivial) lnrouter: fix type of TrampolineEdge.short_channel_id
also, use keyword arguments inside attr.ib() as PyCharm was complaining
2021-02-24 16:46:59 +01:00
SomberNight
4aab843f17 lnutil.LnFeatures: impl and use "supports" method for feature-bit-tests
Note that for a required feature, BOLT-09 allows setting either:
- only the REQ bit
- both the REQ bit and the OPT bit

Hence, when checking if a feature is supported by e.g. an invoice, both
bits should be checked.

Note that in lnpeer.py, in self.features specifically, REQ implies OPT,
as it is set by ln_compare_features.
2021-02-22 19:53:01 +01:00
ThomasV
ded449233e Trampoline routing.
- trampoline is enabled by default in config, to prevent download of `gossip_db`.
   (if disabled, `gossip_db` will be downloaded, regardless of the existence of channels)
 - if trampoline is enabled:
    - the wallet can only open channels with trampoline nodes
    - already-existing channels with non-trampoline nodes are frozen for sending.
 - there are two types of trampoline payments: legacy and end-to-end (e2e).
 - we decide to perform legacy or e2e based on the invoice:
    - we use trampoline_routing_opt in features to detect Eclair and Phoenix invoices
    - we use trampoline_routing_hints to detect Electrum invoices
 - when trying a legacy payment, we add a second trampoline to the path to preserve privacy.
   (we fall back to a single trampoline if the payment fails for all trampolines)
 - the trampoline list is hardcoded, it will remain so until `trampoline_routing_opt` feature flag is in INIT.
 - there are currently only two nodes in the hardcoded list, it would be nice to have more.
 - similar to Phoenix, we find the fee/cltv by trial-and-error.
    - if there is a second trampoline in the path, we use the same fee for both.
    - the final spec should add fee info in error messages, so we will be able to fine-tune fees
2021-02-17 17:28:13 +01:00
ThomasV
ad91257729 pass blacklist to lnrouter.find_route, so that lnrouter is stateless (see #6778) 2021-01-11 15:19:50 +01:00
ThomasV
d5c360a958 simplify lnrouter API 2021-01-11 12:49:35 +01:00
SomberNight
01fe443928 lnrouter: nicer repr for PathEdge and RouteEdge 2020-11-24 23:44:09 +01:00
ThomasV
526c75ad53 lnrouter: blacklist channels for a limited time (see #6124) 2020-05-10 12:37:27 +02:00
SomberNight
7153e753d1 lnworker._pay: allow specifying path as argument
not exposed to CLI/etc yet but will be used in tests soon
2020-05-06 11:06:40 +02:00
SomberNight
63b18dc30f lnrouter: add PathEdge/LNPaymentPath for (node_id, scid) 2020-05-06 11:06:37 +02:00
ThomasV
1a4d33086b refactoring: remove inspect_edge 2020-04-20 11:48:38 +02:00
ThomasV
ec5330fc21 separate method that runs Dijkstra and return distances 2020-04-20 11:47:29 +02:00
SomberNight
30bf32b34b use option varonion: actually use TLV payloads, and signal support 2020-04-01 21:47:42 +02:00
SomberNight
90f3b667aa small clean-up re max CLTV delta for LN 2020-03-30 02:46:14 +02:00
SomberNight
3ed6afce64 lnchannel: implement freezing channels (for receiving)
A bit weird, I know... :)
It allows for rebalancing our own channels! :P
2020-03-26 09:05:15 +01:00
ThomasV
df15042cee Quantitative easing of lightning fees 2020-03-16 14:47:40 +01:00
ThomasV
b6cb983733 lnworker.pay: run path finding in sep. thread (don't block evt loop) 2020-03-10 17:56:11 +01:00
SomberNight
c95c0dcb80 lnrouter: add comments about path-finding blocking the asyncio loop 2020-03-09 20:39:13 +01:00
SomberNight
cdb72509a7 lnrouter: change edge cost estimate (distance metric)
Old estimate was heavily biased towards simply minimising CLTV sum.
(fees had a too low weight; typically they were ~noise)
Now also take payment_amount into account.
2020-03-03 02:12:42 +01:00
SomberNight
c81335fb44 lnrouter: simplify max fee sanity checks 2020-03-02 19:55:11 +01:00
SomberNight
46d8080c76 ln gossip: don't put own channels into db; always pass them to fn calls
Previously we would put fake chan announcement and fake outgoing chan upd
for own channels into db (to make path finding work). See Peer.add_own_channel().
Now, instead of above, we pass a "my_channels" param to the relevant ChannelDB methods.
2020-02-17 20:38:41 +01:00
SomberNight
b99add59c3 lnworker: introduce PaymentAttemptLog NamedTuple 2019-12-10 03:17:57 +01:00
SomberNight
d4da4aa56c lnrouter: fix off-by-one in NUM_MAX_EDGES_IN_PAYMENT_PATH 2019-09-06 18:36:21 +02:00
SomberNight
509df9ddaf create class for ShortChannelID and use it 2019-09-06 18:09:05 +02:00
ThomasV
246cda2928 fix Flake8 tests 2019-08-20 09:03:12 +02:00