Commit Graph

974 Commits

Author SHA1 Message Date
Elle Mouton
6c76d31e89
multi: let FetchLightningNode take an optional tx
In preparation for the next commit which will remove the
`*LightningNode` from the `ChannelEdgePolicy` struct,
`FetchLightningNode` is modified to take in an optional transaction so
that it can be utilised in places where a transaction exists.
2023-11-08 14:50:34 +02:00
Elle Mouton
fa7c1e250b
multi: let ForEachChannel be a method on ChannelGraph
Having a `ForEachChannel` method on the `LightningNode` struct itself
results in a `kvdb.Backend` object needing to be stored within the
LightningNode struct. In this commit, this method is replaced with a
`ForEachNodeChannel` method on the `ChannelGraph` struct will perform
the same function without needing the db pointer to be stored within the
LightningNode. This change, the LightningNode struct more closely
represents the schema on disk.

The existing `ForEachNodeChannel` method on `ChannelGraph` is renamed to
`ForEachNodeDirectedChannel`. It performs a slightly different function
since it's call-back operates on Cached policies.
2023-11-08 10:51:50 +02:00
Jonathan Harvey-Buschel
6edd1e1220
multi: add GetBlockHeader to BlockChainIO 2023-10-27 11:05:27 -04:00
Carla Kirk-Cohen
0e179fae1e routing: remove 0-value warning log in pathfinding
Blinded routes can now have "hints" that have zero value edges, so we
remove this log to avoid spamming logs.
2023-10-06 16:38:33 -07:00
Carla Kirk-Cohen
014683ee66 routing: include route blinding fields in blinded portion of path
This commit updates route construction to backfill the fields
required for payment to blinded paths and set amount to forward
and expiry fields to zero for intermediate hops (as is instructed
in the route blinding specification).

We could attempt to do this in the first pass, but that loop
relies on fields like amount to forward and expiry to calculate
each hop backwards, so we keep it simple (stupid) and post
processes the blinded portion, since it's computationally cheap
and more readable.
2023-10-06 16:38:33 -07:00
Carla Kirk-Cohen
c9609b8214 multi: add blinded route to route requests expressed as hints
Add the option to include a blinded route in a route request (exclusive
to including hop hints, because it's incongruous to include both), and
express the route as a chain of hop hints.

Using a chain of hints over a single hint to represent the whole path
allows us to re-use our route construction to fill in a lot of the
path on our behalf.
2023-10-06 16:38:33 -07:00
Carla Kirk-Cohen
48e36d93d4 multi/refactor: add RouteRequest to hold FindRoute parameters
This commit introduces a single struct to hold all of the parameters
that are passed to FindRoute. This cleans up an already overloaded
function signature and prepares us for handling requests with blinded
routes where we need to perform some additional processing on our
para (such as extracting the target node from the blinded path).
2023-10-06 16:38:33 -07:00
Carla Kirk-Cohen
11a007dc16 routing: account for blinded routes in fee calculation
When we introduce blinded routes, some of our hops are expected
to have zero amounts to forward in their hop payload. This commit
updates our hop fee logic to attribute the full blinded route's
fees to the introduction node. We can't actually know where/how
these fees are distributed, so we collect them all at the
introduction node.
2023-10-06 16:38:33 -07:00
Carla Kirk-Cohen
940b491051 routing: only pack amount and cltv if populated
With the addition of blinded routes, we now need to account for the
possibility that intermediate nodes payloads will not have an amount
and expiry set because that information is provided by the recipient
encrypted data blob. This commit updates our payload packing to only
optionally include those fields.
2023-10-06 16:38:33 -07:00
Carla Kirk-Cohen
fee0e05708 multi: add blinded path TLVs to onion payload / hops
This commit adds the encrypted_data, blinding_point and total_amt_msat
tlvs to the known set of even tlvs for the onion payload. These TLVs
are added in two places (the onion payload and hop struct) because
lnd uses the same set of TLV types for both structs (and they
inherently represent the same thing).

Note: in some places, unit tests intentionally mimic the style
of older tests, so as to be more consistently readable.
2023-10-06 16:38:33 -07:00
Carla Kirk-Cohen
539a275faa routing: add representation of blinded payments
This commit adds a representation of blinded payments, which include a
blinded path and aggregate routing parameters to be used in payment to
the path.
2023-10-06 16:38:33 -07:00
yyforyongyu
20e7e801c0 routing+channeldb: use HTLCAttempt instead of HTLCAttemptInfo
This commit refactors the params used in lifecycle to prefer
`HTLCAttempt` over `HTLCAttemptInfo`. This change is needed as
`HTLCAttempt` also wraps settled and failure info, which is useful in
the following commits.
2023-10-06 16:38:33 -07:00
yyforyongyu
a6be939bfa routing: add newPaymentLifecycle to properly init lifecycle
This commit adds a new method to properly init a payment lifecycle so we
can easily see the default values used here.
2023-10-06 16:38:33 -07:00
yyforyongyu
34d0e5d4c5 routing+channeldb: make MPPayment into an interface
This commit turns `MPPayment` into an interface inside `routing`. Having
this interface gives us the benefit to write more granular unit tests
inside payment lifecycle. As seen from the modified unit tests, several
hacky ways of testing the `SendPayment` method is now replaced by a mock
over `MPPayment`.
2023-10-06 16:38:33 -07:00
yyforyongyu
c412ab5ccb routing: add exitWithErr to handle error logging 2023-10-06 16:38:33 -07:00
yyforyongyu
e5840f6216 channeldb+routing: add NeedWaitAttempts to decide waiting for attempts
This commit adds a new method, `NeedWaitAttempts`, to properly decide
whether we need to wait for the outcome of htlc attempts based on the
payment's current state.
2023-10-06 16:38:33 -07:00
yyforyongyu
52c00e8cc4 multi: move payment state handling into MPPayment
This commit moves the struct `paymentState` used in `routing` into
`channeldb` and replaces it with `MPPaymentState`. In the following
commit we'd see the benefit, that we don't need to pass variables back
and forth between the two packages. More importantly, this state is put
closer to its origin, and is strictly updated whenever a payment is read
from disk. This approach is less error-prone comparing to the previous
one, which both the `payment` and `paymentState` need to be updated at
the same time to make sure the data stay consistant in a parallel
environment.
2023-10-06 16:38:31 -07:00
yyforyongyu
bf99e42f8e routing: rename handleSendError to handleSwitchErr
This commit renames the `handleSendError` to be `handleSwitchErr` to
explicitly express that it's handling the error from htlcswitch.
2023-10-06 16:34:47 -07:00
yyforyongyu
42f1c0f1cc routing: refactor createNewPaymentAttempt and sendPaymentAttempt
This commit moves the creations of hop and htlcAdd message from
`createNewPaymentAttempt` to `sendPaymentAttempt` to clean up the code
and further pave the way to decomposite the lifecycle.
2023-10-06 16:34:47 -07:00
yyforyongyu
3c8784dca3 routing: change variable name numShardsInFlight -> numAttemptsInFlight 2023-10-06 16:34:47 -07:00
yyforyongyu
942697ae73 routing: shorten variable name currentState -> ps 2023-10-06 16:34:47 -07:00
yyforyongyu
3259557a46 routing: fix format and add more docs 2023-10-06 16:34:47 -07:00
yyforyongyu
66b8700c0b multi: add debug logs to catch slow shutdown 2023-10-06 16:34:47 -07:00
Elle Mouton
be90bcbe46 multi: remove litecoin references and comments 2023-10-06 16:34:47 -07:00
yyforyongyu
c175386c4d channeldb+routing: apply method Terminated to decide a payment's terminal state
This commit applies the new method `Terminated`. A side effect from
using this method is, we can now save one query `fetchPayment` inside
`FetchInFlightPayments`.
2023-10-06 16:34:47 -07:00
yyforyongyu
30fd29371c channeldb: add new payment status StatusInitiated
This commit adds a new payment status, `StatusInitiated`, to properly
represent the state where a payment is newly created without attempting
any HTLCs. Since the `PaymentStatus` is a memory representation of a
given payment's status, the enum used for the statuses are directly
updated.
2023-10-06 16:34:47 -07:00
Michael Rooke
78d9996620
trivial: Fix spelling errors
- Fixes some spelling in code comments and a couple of function names
2023-09-21 22:35:33 -04:00
Elle Mouton
dfec4a65cb
multi: update lightning-onion version
Update the lighting-onion dependency to include the lates changes which
support route blinding.
2023-08-23 12:09:53 +02:00
Olaoluwa Osuntokun
384b1b1c12
feature: use +100 staging bit for taproot channels
In this commit, we carry out a new notion introduced during a recent
spec meeting to use a feature bit plus 100 before the feature has been
finalized in the spec.

We split into the Final and Staging bits.
2023-08-22 16:34:28 -07:00
Olaoluwa Osuntokun
7d7513aa3c
routing+funding: add new makeFundingScript to support reg and taproot channels
In this commit, we start to set _internally_ a new feature bit in the
channel announcements we generate. As these taproot channels can only be
unadvertised, this will never actually leak to the public network. The
funding manager will then set this field to allow the router to properly
validate these channels.
2023-08-22 16:32:10 -07:00
Olaoluwa Osuntokun
b368e476c5
lnwire: update Sig to support both ECDSA and schnorr sigs
In this commit, we update the Sig type to support ECDSA and schnorr
signatures. We need to do this as the HTLC signatures will become
schnorr sigs for taproot channels. The current spec draft opts to
overload this field since both the sigs are actually 64 bytes in length.
The only consideration with this move is that callers need to "coerce" a
sig to the proper type if they need schnorr signatures.
2023-08-22 16:29:19 -07:00
Oliver Gugger
d5c504c8de
multi: use fwding policy from models pkg 2023-08-22 06:22:33 +08:00
positiveblue
83ccf61df9
routing: fix index out of range panic
Make sure that we do not crash the node trying to access an invalid
position for an array (-1) in `BuildRoute`.
2023-07-25 10:13:26 -07:00
positiveblue
aadf385f67
routing: split BuildRoute
Create a couple of subroutines that we can unit test separately.
2023-07-25 10:12:55 -07:00
Olaoluwa Osuntokun
a7d6826f60
multimutex: remove HashMutex, make Mutex type a type param
In this commit, we eliminate some code duplication by removing the old
`HashMutex` struct as it just duplicates all the code with a different
type (uint64 and hash). We then make the main Mutex struct take a type
param, so the key can be parametrized when the struct is instantiated.
2023-06-01 17:39:49 -07:00
yyforyongyu
de01e412d6
routing+lnrpc: subscribe payment stream before sending it
This commit moves the subscription of a given payment before it's been
sent so we won't miss any events.
2023-05-23 21:26:09 +08:00
Oliver Gugger
8df4edef1b
Merge pull request #7624 from ellemouton/marshalBytesAndStringTxid
multi: populate both string and byte TXID in lnrpc.Outpoint
2023-05-08 17:32:54 +02:00
George Tsagkarelis
dd93fc2539
routing: log node pubkey as hex 2023-04-25 21:27:24 +03:00
Elle Mouton
7b186716a1
multi: populate both string and byte TXID in lnrpc.Outpoint
This commit adds a a new `MarshalOutPoint` helper in the `lnrpc` package
that can be used to convert a `wire.Outpoint` to an `lnrpc.Outpoint`.
By using this helper, we are less likely to forget to populate both the
string and byte form of the TXID.
2023-04-24 16:19:26 +02:00
Olaoluwa Osuntokun
2596a33529
Merge pull request #7575 from lightningnetwork/0-16-1-staging
lnd: merge the 0.16.1 staging branch into master
2023-04-05 16:48:25 -07:00
Eval EXEC
cbcbddfe29
rpcserver: add time_lock_delta overflow check 2023-03-23 21:34:12 +08:00
bitromortac
170677be2b
routing: stronger use of direct bimodal probability
The process how we calculate a total probability from the direct and
node probability is modified to give more importance to the direct
probability.

This is important if we know about a recent failure. We should not try
to send over this channel again if we know we can't. Otherwise this can
lead to infinite retrials over the channel, when the probability is
pinned at high probabilities by the other node results.
2023-03-23 11:12:10 +01:00
bitromortac
4aa90cf474
routing: add error case for zero capacity
Since no edge should have a zero capacity associated with it, passing a
zero capacity to the bimodal probability calculation results now in an
error.
2023-03-23 11:12:10 +01:00
bitromortac
7df1482cfc
routing: add capacity to special edges
Having a capacity available is important for liquidity estimation.

* We add a dummy capacity to hop hints. Hop hints specify neither the
  capacity nor a maxHTLC size, which is why we assume the channel to
  have a high capacity relative to the amount we send.

* We add a capacity to local edges. These channels should always have a
  capacity associated with them, even in the neutrino case (a fallback
  to maxHTLC is not necessary). This is just for completeness, as the
  probability calculation for local channels is done separately.
2023-03-23 11:12:10 +01:00
bitromortac
b6d65752f7
routing: add and fix log statements 2023-03-21 08:54:10 +01:00
bitromortac
26d1f427df
routing: trace capacity in probability log 2023-02-24 15:28:55 +01:00
bitromortac
75a9dc9103
routing: limit capacity factor and tune parameters
* The maximal reduction in the probability is limited to 0.5 (previously
  ~0.05), such that we don't get too low apriori probabilities.
  Otherwise, this may lead to a too strong selection of large (and maybe
  expensive) channels. A two-hop path would get total probability
  penalties of:

  - 1000PPM/(0.6*0.6) = 2778 PPM in the unsaturated case
  - 1000PPM/(0.6*(0.6*0.5)) = 5556 PPM in the saturated case, where the
    second hop is saturated

  The difference in PPM of 2778 PPM should be enough to bias towards the
  first path.

* The smearing factor is reduced. Previously we had to keep a higher
  smearing factor in order to make the capacity factor not go to zero
  for high amounts, to still give a fully saturated channel a chance.
  This is not needed anymore due to the capping to 0.5. A lower value of
  the smearing factor lets us more precisely choose a capacity fraction
  and the capacity factor is more neutral when it comes to intermediate
  amounts.

We set a conservative default value for the capacity fraction, which
still has the effect of discarding exhausted channels, giving a
noticeable effect when about 90% of the capacity is being used.
2023-02-24 15:28:55 +01:00
bitromortac
a73581610e
routing+lnrpc: make capacity factor configurable
We make the capacity factor configurable via an lnd.conf routerrpc
apriori parameter. The capacity factor trades off increased success
probability with a reduced set of channel candidates, which may lead to
increased fees. To let users choose whether the factor is active or not,
we add a config setting where a capacity fraction of 1.0 disables the
factor. We limit the capacity fraction to values between 0.75 and 1.0.
Lower values may discard too many channels.
2023-02-24 15:28:55 +01:00
yyforyongyu
6618ab493a
multi: enhance loggings and fix logging format
Also adds TODO for a possible bug.
2023-02-23 21:56:08 +08:00
bitromortac
6aac2762b3
routing: stricter maxHTLC checks
We require channel updates to have the max HTLC message flag set.

Several flows need to pass that check before channel updates are
forwarded to peers:
* after channel funding: `addToRouterGraph`
* after receiving channel updates from a peer:
  `ProcessRemoteAnnouncement`
* after we update channel policies: `PropagateChanPolicyUpdate`
2023-02-21 14:03:51 +01:00