Commit Graph

1086 Commits

Author SHA1 Message Date
bitromortac
0358b3a0fa
routing: use amount to send for time lock weight
The time lock weight for a hop is supposed to be proportional to the
amount that is sent/locked, but in a previous change we switched to the
net amount, where inbound fees aren't yet applied. This is corrected in
this commit.
2024-07-30 08:53:10 +02:00
bitromortac
b0f0715813
routing: fix fee limit condition
When iterating edges, pathfinding checks early whether using an edge
would violate the requested total fee limit for a route. This check is
done on the net amount (an amount the inbound fee is calculated with).
However, a possible next hop's fee discount leads to a reduction in fees
and as such using the net amount leads to assuming a higher cumulative
fee than the route really has, excluding the path erroneously. We
perform the fee limit check on the amount to send, which includes both
inbound and outbound fees. This should be possible as the first hop's
outbound fee is zero and therefore doesn't have to be checked in the
end.
2024-07-30 08:53:09 +02:00
bitromortac
9b3b309f2d
routing: remove unused param, log 2024-07-30 08:52:49 +02:00
Elle Mouton
c490279002
blindedpath: smarter dummy hop policy selection
This commit introduces more sophisticated code for selecting dummy hop
policy values for dummy hops in blinded paths.

For the case where the path does contain real hops, the dummy hop policy
values are derived by taking the average of those hop polices. For the
case where there are no real hops (in other words, we are the
introduction node), we use the default policy values used for normal
ChannelUpdates but then for the MaxHTLC value, we take the average of
all our open channel capacities.
2024-07-26 13:03:07 +02:00
Elle Mouton
60a856ab65
record/routing: set minimum padding size 2024-07-26 10:32:47 +02:00
Elle Mouton
398623bde5
blindedpath: move blinded path logic to own pkg 2024-07-26 09:54:59 +02:00
Elle Mouton
f0558babf3
multi: send MPP payment to blinded path
Make various sender side adjustments so that a sender is able to send an
MP payment to a single blinded path without actually including an MPP
record in the payment.
2024-07-26 09:54:38 +02:00
Elle Mouton
735d7d9738
multi: send to a blinded path in an invoice
Update the SendPayment flow so that it is able to send to an invoice
containing a blinded path.
2024-07-26 09:54:37 +02:00
Elle Mouton
e12a226272
routing: use mission control to select blinded paths
Add a `FindBlindedPaths` method to the `ChannelRouter` which will use
the new `findBlindedPaths` function to get a set of candidate blinded
path routes. It then uses mission control to select the best of these
paths.

Note that as of this commit, the MC data we get from these queries won't
mean much since we wont have data about a channel in the direction
towards us. But we do this now in preparation for a future PR which will
start writing mission control success pairs for successful receives from
blinded route paths.
2024-07-26 09:54:17 +02:00
Elle Mouton
1039aedd0c
routing: find blinded paths to a destination node
This commit adds a new function, `findBlindedPaths`, that does a depth
first search from the target node to find a set of blinded paths to the
target node given the set of restrictions. This function will select and
return any candidate path. A candidate path is a path to the target node
with a size determined by the given hop number constraints where all the
nodes on the path signal the route blinding feature _and_ the
introduction node for the path has more than one public channel. Any
filtering of paths based on payment value or success probabilities is
left to the caller.
2024-07-26 09:54:17 +02:00
yyforyongyu
d992cf94d6
multi: add SpewLogClosure to avoid code repetition 2024-07-25 22:18:49 +08:00
yyforyongyu
b6049ff94b
multi: add NewLogClosure in lnutils to avoid repetition
And replaces all usage of `logClosure` with `lnutils.LogClosure`.
2024-07-25 21:25:23 +08:00
yyforyongyu
2608c0893e
multi: make sure missionControlStore catches done signal
This commit makes sure `missionControlStore` catches the shutdown signal
when draining the ticker. A few debug logs are added to aid the process.
2024-07-23 21:30:08 +08:00
Elle Mouton
d1c54d74a8
routing: close graph session if getBandwidthHints fails
Ensure that the graph session used during pathfinding is properly closed
if the call to getBandwidthHints fails.
2024-07-15 15:56:33 +02:00
Elle Mouton
fe34d62eb1
graph+routing: address linter errors
This is done in a separate commit so as to keep the original code-move
commit mostly a pure code move.
2024-07-15 15:56:33 +02:00
Elle Mouton
7f1be39d45
refactor: move various duties from ChannelRouter to graph.Builder
This commit is a large refactor that moves over various responsibilities
from the ChannelRouter to the graph.Builder. These include all graph
related tasks such as:
- graph pruning
- validation of new network updates & persisting new updates
- notifying topology update clients of any changes.

This is a large commit but:
- many of the files are purely moved from `routing` to `graph`
- the business logic put in the graph Builder is copied exactly as is
  from the ChannelRouter with one exception:
- The ChannelRouter just needs to be able to call the Builder's
  `ApplyChannelUpdate` method. So this is now exported and provided to
the ChannelRouter as a config option.
- The trickiest part was just moving over the test code since quite a
  bit had to be duplicated.
2024-07-15 15:56:33 +02:00
Elle Mouton
30e6671a13
routing: use new graph.DB interface in ChannelRouter 2024-07-15 15:13:58 +02:00
Elle Mouton
c1d7a9d2e7
multi: move ChannelGraphSource interface
... to the new `graph` package in preparation for the implementation of
the interface being moved to this new package.
2024-07-15 15:13:58 +02:00
Elle Mouton
e9c89ae0ec
multi+refactor: create ForEachNodeChannel with no tx param
In prep for a clean Graph DB interface, we add a version of
ForEachNodeChannel that does not take in an existing db transaction.
2024-07-15 15:13:58 +02:00
Elle Mouton
c20d759d41
refactor: create FetchLightningNode with no tx param
In preparation for adding a clean Graph DB interface, we create a
version of FetchLightningNode that doesnt allow a caller to provide in a
transaction.
2024-07-15 15:13:57 +02:00
Elle Mouton
71e93526d6
multi+refactor: let FetchChanInfos not take tx
In preparation for having a clean graph DB interface, refactor
FetchChanInfos so that no transaction can be provided.
2024-07-15 15:13:57 +02:00
Elle Mouton
cf3de72503
routing: let SelfNode be passed via config
Instead of querying it from the graph since this will be removed in a
future commit.
2024-07-15 15:13:57 +02:00
Elle Mouton
8c0df98439
multi: add abstraction for Router and SessionSource graph access
In this commit, we completely remove the Router's dependence on a Graph
source that requires a `kvdb.RTx`. In so doing, we are more prepared for
a future where the Graph source is backed by different DB structure such
as pure SQL.

The two areas affected here are: the ChannelRouter's graph access that
it uses for pathfinding. And the SessionSource's graph access that it
uses for payments.

The ChannelRouter gets given a Graph and the SessionSource is given a
GraphSessionFactory which it can use to create a new session. Behind the
scenes, this will acquire a kvdb.RTx that will be used for calls to the
Graph's `ForEachNodeChannel` method.
2024-07-15 15:13:57 +02:00
Elle Mouton
90d6b863a8
routing+refactor: remove the need to give CachedGraph source node access
In preparation for the next commit.
2024-07-15 13:10:24 +02:00
Elle Mouton
3f121cbe81
routing: rename and export routingGraph
In preparation for structs outside of the `routing` package implementing
this interface, export `routingGraph` and rename it to `Graph` so as to
avoid stuttering.
2024-07-15 13:10:24 +02:00
Elle Mouton
5a903c270f
routing: remove sourceNode from routingGraph interface
In this commit, we further reduce the routingGraph interface and this
time we make it more node-agnostic so that it can be backed by any graph
and not one with a concept of "sourceNode".
2024-07-15 13:10:24 +02:00
Elle Mouton
5c18b5a042
routing: remove un-used method from routingGraph interface
We really want to narrow down the interface we provide the router, so
let's start here.
2024-07-15 13:10:23 +02:00
Elle Mouton
cd3da40fb9
routing: dont include final hop cltv in blinded path
Only include the final hop's cltv delta in the total timelock
calculation if the route does not include a blinded path. This is
because in a blinded path, the final hops final cltv delta will be
included in the blinded path's accumlated cltv delta value.

With this commit, we remove the responsibility of remembering not to set
the `finalHop.cltvDelta` from the caller of `newRoute`. The relevant
test is updated accordingly.
2024-07-10 17:51:56 +02:00
Elle Mouton
925b68c1ed
routing: add BlindedPayment to unifiedEdge
Later on in this series, we will need to know during path finding if an
edge we are traversing was derived from a blinded payment path. In
preparation for that, we add a BlindedPayment member to the
`unifiedEdge` struct.

The reason we will need this later on is because: In the case where we
receive multiple blinded paths from the receipient, we will first swap
out the final hop node of each path with a single unified target node so
that path finding can work as normal. Once we have selected a route
though, we will want to know which path an edge belongs to so that we
can swap the correct destination node back in.
2024-07-10 09:12:39 +02:00
Elle Mouton
1ec2a1be11
routing+refactor: add a constructor for unifiedEdge
Add a constructor for unified edge. In upcoming commits, we will add a
new member to unifiedEdge and a constructor forces us to not forget to
populate a required member.
2024-07-10 09:12:39 +02:00
Elle Mouton
28d1227c04
routing: add BlindedPayment() method to AdditionalEdges
Expand the AdditionalEdges interface with a BlindedPayment method. In
upcoming commits, we will want to know if an AdditionalEdge was derived
from a blinded payment or not and we will also need some information
from the blinded payment it was derived from. So we expand the interface
here to avoid needing to do type casts later on. The new method may
return nil if the edge was not derived from a blinded payment.
2024-07-10 09:12:39 +02:00
Elle Mouton
f7a9aa875e
routing+refactor: let BlindedEdge carry BlindedPayment
This commit is purely a refactor. In it, we let the `BlindedEdge` struct
carry a pointer to the `BlindedPayment` that it was derived from. This
is done now because later on in the PR series, we will need more
information about the `BlindedPayment` that an edge was derived from.

Since we now pass in the whole BlindedPayment, we swap out the
`cipherText` member for a `hopIndex` member so that we dont carry around
two sources of truth in the same struct.
2024-07-10 09:12:39 +02:00
Oliver Gugger
b300da8446
routing: assume TLV payloads everywhere
This commit removes another check for TLV payload support of the
destination node. We assume TLV payloads as the default everywhere else,
so we just remove two checks that were previously forgotten.
2024-06-26 14:28:51 -07:00
Elle Mouton
99b3c57b7f
routing: assume TLV onion during route construction 2024-06-24 10:01:23 -07:00
Elle Mouton
738253f5e1
routing: assume TLV onion during path finding 2024-06-24 10:01:21 -07:00
Matheus Degiovani
0c7a173354
missioncontrolstore: remove duplication of in-memory data
This removes duplication of in-memory data during the periodic flushing
stage of the mission control store.

The existing code entirely duplicates the in-memory cache of the store,
which is very wasteful when only a few additional results are being
rotated into the store.

This has a significant performance penalty specially for wallets that
remain online for a long time with a low volume of payments. The worst
case scenario are wallets that see at most 1 new payment a second, where
the entire in-memory cache is recreated every second.

This commit improves the situation by determining what will be the
actual changes that need to be committed before initiating the db
transaction and only keeping track of these to update the in-memory
cache if the db tx is successful.
2024-06-19 07:34:35 -03:00
Matheus Degiovani
9059a655db
missioncontrolstore: avoid ticker when there is no work to be done.
This modifies the mission control store to avoid running the one second
ticker for flushing data when there is no work to be done.

This improves performance of a quiscent LN node by avoiding a one second
interval busy loop that does nothing when there are no payments flowing
through the node.
2024-06-19 07:34:35 -03:00
Matheus Degiovani
637ac85d1d
missioncontrolstore: skip work when there are no new entries
This modifies the mission control store to avoid doing any work when no
new payment result entries are in the queue to be processed.

The mission control store maintains keeps the latest N (in production:
1000) entries in its DB, evicting older entries when new ones are added.
Currently, its implementation is somewhat less performant than it could
be.

This commit adds an early return to the storeResults function to avoid
doing any DB or memory operations when its outstanding queue is empty,
improving the performance during quiescent periods of the LN node's
execution.
2024-06-19 07:34:34 -03:00
Matheus Degiovani
6a27bc29ba
missioncontrolstore: add additional tests and benchmarks
These will be useful in the next commits.
2024-06-19 07:33:14 -03:00
Slyghtning
bba01cf634
routing+routerrpc: cancelable context in SendPaymentV2
In this commit we set up the payment loop context
according to user-provided parameters. The
`cancelable` parameter indicates whether the user
is able to interrupt the payment loop by cancelling
the server stream context. We'll additionally wrap
the context in a deadline if the user provided a
payment timeout.
We remove the timeout channel of the payment_lifecycle.go
and in favor of the deadline context.
2024-06-17 09:32:26 +02:00
Slyghtning
06bff6f81a
routing: fix typos and wrap errors 2024-06-17 09:32:25 +02:00
feelancer21
f62c00fe34
multi: Inbound fees are retained when not provided
Fixes the problem that inbound base fee and fee rate are overwritten
with 0 if they are not specified in PolicyUpdateRequest. This ensures
backward compatibility with older rpc clients that do not yet support
the inbound feature.
2024-05-22 20:48:42 +02:00
Slyghtning
c9713e0ddb
routing: log edge when skipping it 2024-05-16 13:54:54 +02:00
Bufo
af9858c3ed
feat: add inbound fees to channel notifications 2024-05-07 18:58:25 +02:00
erik
ab83343c87 multi: repleace ioutil.ReadFile 2024-04-25 11:22:43 +02:00
Oliver Gugger
648fb22f63
multi: wrap all errors 2024-04-11 15:04:03 +02:00
Joost Jager
0bae781785 routing: add inbound fee support to pathfinding
Add sender-side support for inbound fees in pathfinding
and route building.
2024-03-31 18:12:28 +02:00
Joost Jager
9d4251c18d routing/test: test local unified edge 2024-03-31 18:12:28 +02:00
Joost Jager
e0a080454a routing: track unifiedPolicyEdge
Preparation so that we can have the inbound fee available
in addition to the outgoing policy.
2024-03-31 18:12:28 +02:00
Joost Jager
763787e08c routing+lnrpc: add inbound fee policy update 2024-03-31 16:49:19 +02:00