Commit Graph

718 Commits

Author SHA1 Message Date
Conner Fromknecht
6622c4814e
multi: enforce routing.MinCLTVDelta=18 for invoices + chanupd
This commit clamps all user-chosen CLTVs in LND to be at least 18, which
is the new conservative value used in the sepc. This minimum is applied
uniformly to forwarding CLTV deltas (via channel updates) as well as
final CLTV deltas for new invoices.
2020-07-24 13:13:56 -07:00
Olaoluwa Osuntokun
bdc0d875bc
Merge pull request #4327 from joostjager/stuck-payment-loop
routing: don't treat bad features as an unexpected error
2020-05-28 15:43:09 -07:00
Joost Jager
3ef68baf4a
routing: don't treat bad features as an unexpected error
Previous behavior led to the payment loop being abandoned immediately,
resulting in a payment stuck in state in_flight.
2020-05-27 12:15:53 +02:00
Conner Fromknecht
d0d2ca403d
multi: rename ReadTx to RTx 2020-05-26 18:20:37 -07:00
Conner Fromknecht
2f84d1a819
Merge pull request #4280 from cfromknecht/read-for-each-node
channeldb: remove Tx arg from ForEachNode
2020-05-13 16:37:10 -07:00
Conner Fromknecht
90d3bf532d
channeldb+routing: remove tx arg for ForEachNode 2020-05-12 17:53:20 -07:00
Joost Jager
674c199047
routing: return full htlc attempt from router 2020-05-12 19:56:52 +02:00
Joost Jager
cc37485432
routing: return full htlc attempt from shard handler 2020-05-12 19:56:50 +02:00
Joost Jager
c33d94ff27
routing+routerrpc: add multiple outgoing channel restriction 2020-05-12 07:17:24 +02:00
Joost Jager
53e4876a1d
routing/test: add channel id constants 2020-05-12 07:17:22 +02:00
Andras Banki-Horvath
556e3525ea misc: fix error formatting in multiple files 2020-04-24 19:15:08 +02:00
Andras Banki-Horvath
ebf058a2a5 routing: static check fix, time.Since instead of Now().Sub() 2020-04-24 19:15:08 +02:00
Andras Banki-Horvath
4773ae17d9 routing: remove unused code 2020-04-24 19:15:08 +02:00
Joost Jager
f6b2410011
routing+routerrpc: rename max_shards to max_parts
Don't introduce a new term and align with the P in MPP.
2020-04-22 14:49:19 +02:00
Joost Jager
7fc1938f10
routing: payment splitting pre-check
This commit reverts cb4cd49dc8d3b0255afe9ff29af9c46c2dbb2c98 to bring
back the insufficient local balance failure.

Distinguishing betweeen this failure and a regular "no route" failure
prevents meaningless htlcs from being sent out.
2020-04-18 08:30:26 +02:00
Joost Jager
f44a9e1d4c
routing/test: make test channel capacities configurable 2020-04-17 15:56:19 +02:00
Joost Jager
805641adf5
routing: do not split payment if destination does not support mpp 2020-04-17 14:23:57 +02:00
Joost Jager
9bd7eb74b6
routing: add prefix logger for payment session 2020-04-17 14:23:55 +02:00
Joost Jager
6e8442b333
routing: move payment session constructor 2020-04-16 16:25:24 +02:00
Joost Jager
969eecc7d2
routing+routerrpc+lncli: rename MaxHtlcs to MaxShards 2020-04-14 10:31:59 +02:00
Joost Jager
110c99f676
routing: continue trying after mpp timeout
It can happen that the receiver times out some htlcs of the set if it
took to long to complete. But because the sender's mission control is
now updated, it is worth to keep trying to send those shards again.
2020-04-09 08:20:52 +02:00
Joost Jager
e9bd691e6a
routerrpc+routing: adapt payment session for multi shard send
Modifies the payment session to launch additional pathfinding attempts
for lower amounts. If a single shot payment isn't possible, the goal is
to try to complete the payment using multiple htlcs. In previous
commits, the payment lifecycle has been prepared to deal with
partial-amount routes returned from the payment session. It will query
for additional shards if needed.

Additionally a new rpc payment parameter is added that controls the
maximum number of shards that will be used for the payment.
2020-04-09 08:20:49 +02:00
Joost Jager
46f5fc7400
routing: distinguish between receiver amount and total amount in newRoute 2020-04-09 08:20:47 +02:00
Joost Jager
e5c7e9a38c
routing/test: return pathfinding error 2020-04-09 08:20:45 +02:00
Joost Jager
0f8eb80965
routing/test: use fixed identifiers in test graph 2020-04-09 08:20:43 +02:00
Joost Jager
3c6e4612ff
routing/test: expose full list of htlc attempts 2020-04-09 08:20:41 +02:00
Joost Jager
b13616a593
routing/test: use payment session in integrated routing test
Cover the payment session in the integrated routing test as a
preparation for executing the upcoming mpp split logic as part of the
test.
2020-04-09 08:20:39 +02:00
Joost Jager
47f9c1c3fd
routing: use routingGraph interface in payment session
Preparation for more test coverage of payment session.

The function findPath now has the call signature of the former
findPathInternal function.
2020-04-09 08:20:37 +02:00
Joost Jager
cb4cd49dc8
routing: map insufficient local bandwidth error to no path
With mpp it isn't possible anymore for findPath to determine that there
isn't enough local bandwidth. The full payment amount isn't known at
that point.

In a follow-up, this payment outcome can be reintroduced on a higher
level (payment lifecycle).
2020-04-09 08:20:35 +02:00
Joost Jager
af4abe7d58
routing+routerrpc: notify full payment structures
This commit fixes the inconsistency between the payment state as
reported by routerrpc.SendPayment/routerrpc.TrackPayment and the main
rpc ListPayments call.

In addition to that, payment state changes are now sent out for every
state change. This opens the door to user interfaces giving more
feedback to the user about the payment process. This is especially
interesting for multi-part payments.
2020-04-08 09:26:33 +02:00
Joost Jager
278915e598
channeldb: return updated payment on attempt update
Similar to what is done for SettleAttempt.

Co-authored-by: Johan T. Halseth <johanth@gmail.com>
2020-04-08 08:54:01 +02:00
Joost Jager
5d0a117162
routing: fix log 2020-04-08 08:14:10 +02:00
Johan T. Halseth
5e72a4b77c
routing: exit on unexpected RequestRoute error
We whitelist a set of "expected" errors that can be returned from
RequestRoute, by converting them into a new type noRouteError. For any
other error returned by RequestRoute, we'll now exit immediately.
2020-04-02 19:31:24 +02:00
Johan T. Halseth
95c5a123c8
routing/router_test: add TestSendToRouteMultiShardSend 2020-04-02 19:31:23 +02:00
Johan T. Halseth
864e64e725
channeldb: validate MPP options when registering attempts
We add validation making sure we are not trying to register MPP shards
for non-MPP payments, and vice versa. We also add validtion of total
sent amount against payment value, and matching MPP options.

We also add methods for copying Route/Hop, since it is useful to use
for modifying the route amount in the test.
2020-04-02 19:31:23 +02:00
Johan T. Halseth
36a80b4d51
routing/router: enable MPP sends for SendToRoute
This commit enables MPP sends for SendToRoute, by allowing launching
another payment attempt if the hash is already registered with the
ControlTower.

We also set the total payment amount of of the payment from mpp record,
to indicate that the shard value might be different from the total
payment value.

We only mark non-MPP payments as failed in the database after
encountering a failure, since we might want to try more shards for MPP.
For now this means that MPP sendToRoute payments will be failed
only after a restart has happened.
2020-04-02 19:29:15 +02:00
Johan T. Halseth
431372c0cf
routing/payment_lifecycle_test: add MPP test cases 2020-04-02 19:29:15 +02:00
Johan T. Halseth
7b318a4be7
routing/payment_lifecycle+channeldb: enable multi shard send
This commit finally enables MP payments within the payment lifecycle
(used for SendPayment). This is done by letting the loop launch shards
as long as there is value remaining to send, inspecting the outcomes for
the sent shards when the full payment amount has been filled.

The method channeldb.MPPayment.SentAmt() is added to easily look up how
much value we have sent for the payment.
2020-04-02 19:29:15 +02:00
Johan T. Halseth
0fd71cd596
routing/payment_lifecycle_test: add step for terminal failure
And modify the MissionControl mock to return a non-nil failure reason in
this case.
2020-04-02 19:29:15 +02:00
Johan T. Halseth
2e63b518b7
routing/payment_lifecycle_test+mock: set up listener for FailAttempt
Also rename Success to SettleAttempt in the tests.
2020-04-02 19:29:15 +02:00
Johan T. Halseth
aa9c971dc0
routing/payment_lifecycle_test: extract route creation into method
This also fixes a test bug that the manually created route didn't match
the actual payment amount in the test cases, and adds some fees to the
route.
2020-04-02 19:29:14 +02:00
Johan T. Halseth
4d343bbb46
routing tests: move TestRouterPaymentStateMachine to own file
(almost) PURE CODE MOVE
The only code change is to change a few select cases from

case _ <- channel:
to
case <- channel:

to please the linter.

The test is testing the payment lifecycle, so move it to
payment_lifecycle_test.go
2020-04-02 19:29:14 +02:00
Johan T. Halseth
70202be580
channeldb: make database logic MPP compatible
This commit redefines how the control tower handles shard and payment
level settles and failures. We now consider the payment in flight as
long it has active shards, or it has no active shards but has not
reached a terminal condition (settle of one of the shards, or a payment
level failure has been encountered).

We also make it possible to settle/fail shards regardless of the payment
level status (since we must allow late shards recording their status
even though we have already settled/failed the payment).

Finally, we make it possible to Fail the payment when it is already
failed. This is to allow multiple concurrent shards that reach terminal
errors to mark the payment failed, without havinng to synchronize.
2020-04-02 19:29:14 +02:00
Johan T. Halseth
5adfc968df
routing/payment_lifecycle: return recorded errors
In preparation for MPP we return the terminal errors recorded with the
control tower. The reason is that we cannot return immediately when a
shard fails for MPP, since there might be more shards in flight that we
must wait for. For that reason we instead mark the payment failed in the
control tower, then return this error when we inspect the payment,
seeing it has been failed and there are no shards in flight.
2020-04-02 10:24:35 +02:00
Johan T. Halseth
7b5c10814b
routing/payment_lifecycle+channeldb: collect existing outcome first
To move towards how we will handle existing attempt in case of MPP
(collecting their outcome will be done in separate goroutines separate
from the payment loop), we move to collect their outcome first.

To easily fetch HTLCs that are still not resolved, we add the utility
method InFlightHTLCs to channeldb.MPPayment.
2020-04-02 10:24:35 +02:00
Johan T. Halseth
49efbefb43
routing/payment_session: remove prebuilt payment session
Since we no longer use payment sessions for send to route, we remove the
prebuilt one.
2020-04-02 10:24:35 +02:00
Johan T. Halseth
4509c4f3a9
routing: move ErrMaxRouteHopsExceeded check
Now that SendToRoute is no longer using the payment lifecycle, we move
the max hop check out of the payment shard's launch() method, and return
the error directly, such that it can be handled in SendToRoute.
2020-04-02 10:24:35 +02:00
Johan T. Halseth
a979b91b27
routing: remove errNoRoute and lastError
Now that SendToRoute is no longer using the payment lifecycle, we
remove the error structs and vars used to cache the last encountered
error. For SendToRoute this will now be returned directly after a shard
has failed.

For SendPayment this means that the last error encountered durinng
pathfinding no longer will be returned. All errors encounterd can
instead be inspected from the HTLC list.
2020-04-02 10:24:35 +02:00
Johan T. Halseth
6cc162e0b0
router: make sendToRoute omit payment lifecycle
Instead of having SendToRoute pull routes from the payment session in
the payment lifecycle, we utilize the new methods on the paymentShard to
launch and collect the result for this single route.

This also let us remove the check for noRouteError, as we will always
have the result from the tried attempt returned. A result of this is
that we can finally remove lastError from the payment lifecycle (see
next commits).
2020-04-02 10:24:35 +02:00
Johan T. Halseth
2c01e79eb5
routing/payment_lifecycle: extract result collection into collectResult
Fetching the final shard result will also be done for calls to
SendToRoute, so we extract this code into a new method.

We move the call to the ControlTower to set the payment level failure
out into the payment loop, as this must be handled differently when
multiple shards are in flight, and for SendToRoute.
2020-04-02 10:24:34 +02:00