Commit Graph

721 Commits

Author SHA1 Message Date
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
Johan T. Halseth
9712dd1a7f
routing/payment_lifecycle: extract attempt sending logic
Define shardHandler which is a struct holding what is needed to send
attempts along given routes. The reason we define the logic on this
struct instead of the paymentLifecycle is that we later will make
SendToRoute calls not go through the payment lifecycle, but only using
this struct.

The launch shard is responsible for registering the attempt with the
control tower, failing it if the launch fails. Note that it is NOT
responsible for marking the _payment_ failed in case a terminal error is
encountered. This is important since we will later reuse this method for
SendToRoute, where whether to fail the payment cannot be decided on the
shard level.
2020-04-02 10:24:34 +02:00
Johan T. Halseth
bcca1ab821
routing/payment_lifeycle: remove payment level attempt and circuit
We replace the cached attempt, and instead use the control tower
(database) to fetch any in-flight attempt. This is done as a
preparation for having multiple attempts in flight.

In addition we remove the cached circuit, as it won't be applicable when
multiple shards are in flight.

Instead of tracking the attemp we consult the database on every
iteration, and pick up any existing attempt. This also let us avoid
having to pass in the existing attempts from the payment loop, as we
just fetch them direclty.
2020-04-02 10:24:34 +02:00
Johan T. Halseth
e1f4d89ad9
routing: add FetchPayment method to ControlTower
This method is used to fetch a payment and all HTLC attempt that have
been made for that payment. It will both be used to resume inflight
attempts, and to fetch the final outcome of previous attempts.

We also update the the mock control tower to mimic the real control
tower, by letting it track multiple HTLC attempts for a given payment
hash, laying the groundwork for later enabling it for MPP.
2020-04-02 10:24:34 +02:00
Johan T. Halseth
6d9f9c31f4
routing/router_test: remove preimage overwrite
The test case's preimage was (mistakenly) overwritten after crafting the
lightning payment, causing the parts of the testcases use the same
preimage causing problems when we are using the payment hash and
preimage in the mock control tower to distinguish paymennts.
2020-04-02 10:24:34 +02:00
Johan T. Halseth
79227bab3a
routing/route: define route.ReceiverAmt() method 2020-04-02 10:24:34 +02:00
Johan T. Halseth
4485e8261f
routing/payment_lifecycle: move Fail call to payment loop
In our quest to move calls to the ControlTower into the main payment
lifecycle loop, we move the edge case of a too long route out of
createNewPaymentAttempt.
2020-04-02 10:24:33 +02:00
Johan T. Halseth
3620721391
routing/payment_lifecycle: move attempt DB checkpointing into payment
loop

To prepare for multiple in flight payment attempts, we move
checkpointing the payment attempt out of createNewPaymentAttempt and
into the main payment lifecycle loop.

We'll attempt to move all calls to the DB via the ControlTower into this
loop, so we can more easily handle them in sequence.
2020-04-02 10:24:33 +02:00
Johan T. Halseth
e61fcda6a9
routing/payment_lifecycle: move requesting route out of createNewPaymentAttempt
To prepare for having more than one payment attempt in flight at the
same time, we decouple fetching the next route from crafting the payment
attempt.
2020-04-02 10:24:33 +02:00
Johan T. Halseth
00903ef9f5
routing/payment_session: make RequestRoute take max amt, fee limit and
active shards

In preparation for doing pathfinding for routes sending a value less
than the total payment amount, we let the payment session take the max
amount to send and the fee limit as arguments to RequestRoute.
2020-04-02 10:24:33 +02:00
Johan T. Halseth
f9eeb6b41f
routing/router+lifecycle: remove LightningPayment from payment lifecycle
Now that the information needed is stored by the paymentSession, we no
longer need to pass the LightningPayment into the payment lifecycle.
2020-04-02 10:24:33 +02:00
Johan T. Halseth
c2301c14b2
routing/payment_session: make NewPaymentSession take payment directly
This commit moves supplying of the information in the LightningPayment
to the initialization of the paymentSession, away from every call to
RequestRoute.

Instead the paymentSession will store this information internally, as it
doesn't change between payment attempts.

This is done to rid the RequestRoute call of the LightingPayment
argument, as for SendToRoute calls, it is not needed to supply the next
route.
2020-04-02 10:24:33 +02:00
Joost Jager
a2336005e6
Merge pull request #4113 from joostjager/mc-failure-overwrite
routing: minimum failure relaxation interval
2020-03-28 11:10:26 +01:00
Joost Jager
1a6b28553a
routing: stricter mission control state failure updates
This commit puts a mechanism in place to prevent a failure for a low
amount from being overwritten very soon after by a higher amount
failure.
2020-03-28 07:49:23 +01:00
Joost Jager
36e1b92e0c
routing: log reported success amount 2020-03-24 19:02:40 +01:00
Joost Jager
2d07756263
routing: log amount for probability 2020-03-24 19:02:38 +01:00
Joost Jager
6a36ed44f8
routing: extract mission control state
Preparation for unit testing just the state logic.
2020-03-24 16:48:35 +01:00
Olaoluwa Osuntokun
28bbaa2a94
routing: convert to use new kvdb abstraction 2020-03-18 19:34:58 -07:00
Joost Jager
f86e68a1a2
channeldb+routing: store full htlc failure reason
This commit extends the htlc fail info with the full failure reason that
was received over the wire. In a later commit, this info will also be
exposed on the rpc interface. Furthermore it serves as a building block
to make SendToRoute reliable across restarts.
2020-03-09 18:31:35 +01:00
Joost Jager
48c0e42c26
channeldb+routing: store all payment htlcs
This commit converts the database structure of a payment so that it can
not just store the last htlc attempt, but all attempts that have been
made. This is a preparation for mpp sending.

In addition to that, we now also persist the fail time of an htlc. In a
later commit, the full failure reason will be added as well.

A key change is made to the control tower interface. Previously the
control tower wasn't aware of individual htlc outcomes. The payment
remained in-flight with the latest attempt recorded, but an outcome was
only set when the payment finished. With this commit, the outcome of
every htlc is expected by the control tower and recorded in the
database.

Co-authored-by: Johan T. Halseth <johanth@gmail.com>
2020-03-09 18:31:33 +01:00
Joost Jager
8558534417
routing: add clock to router config 2020-03-09 11:43:44 +01:00
Johan T. Halseth
bee2380441
channeldb: rename PaymentAttemptInfo to HTLCAttemptInfo
To better distinguish payments from HTLCs, we rename the attempt info
struct to HTLCAttemptInfo. We also embed it into the HTLCAttempt struct,
to avoid having to duplicate this information.

The paymentID term is renamed to attemptID.
2020-03-09 11:43:26 +01:00
Joost Jager
967b4b2dc3
channeldb: remove redundant MPPaymentCreationInfo struct
MPPaymentCreationInfo and PaymentCreationInfo are identical except for
the naming of CreationTime/CreationDate.
2020-03-09 11:43:24 +01:00
elkanatovey
5ff017664c fix typo 2020-02-27 15:22:00 +02:00
Joost Jager
29476ec6a3
routing/test: test probability extrapolation
Adds an integrated routing test of probability extrapolation for untried
channels. The larger part of this commit is mock code to simulate the
Lightning Network.

The difference between this test and the existing pathfinding tests, is that
this test focuses on the feedback loop from result interpretation via
mission control updates and probability estimation back to pathfinding.
Improvements like probability extrapolation were previously only
validated by reasoning, while this setup makes it possible to assert the
improvement in a test and guard it for the future.
2020-02-11 14:19:13 +01:00
Joost Jager
06bdeb56e2
routing: add graph interface 2020-02-11 13:35:38 +01:00
Joost Jager
a8ed1b342a
routing: remove pathfinding db tx
Pathfinding is never used with an externally supplied bbolt transaction.
2020-02-10 19:55:40 +01:00
Olaoluwa Osuntokun
07977a2bf0
Merge pull request #3957 from cfromknecht/amp-record
record+routing/route: add AMP record
2020-02-03 15:53:21 -08:00
Conner Fromknecht
9fc197d8b1
routing/route: fix TestMPPHop comment 2020-01-28 06:43:44 -08:00
Conner Fromknecht
0cb27151e5
routing/route: add AMP record to payload size calcs 2020-01-28 06:43:34 -08:00
Joost Jager
ef28d2aaed
routing: penalize node-level failures harder
Previously we only penalized the outgoing connections of a failing node.
This turned out not to be sufficient, because the next route sometimes
went into the same failing node again to try a different outgoing
connection that wasn't yet known to mission control and therefore not
penalized before.
2020-01-21 09:06:42 +01:00
Joost Jager
e9b7e80848
routing: remove path finding shortcut
This shortcut does not work when the destination is a private node. We
also don't have this shortcut for regular payments. This commit
aligns the behavior between SendPayment and QueryRoutes.
2020-01-15 20:32:45 +01:00
Carla Kirk-Cohen
7d356458e3
Merge pull request #3843 from carlaKC/htlcnotifier-0-switcherrors
[htlcnotifier 1/4]: Introduce Internal Errors
2020-01-15 08:46:38 +02:00
Joost Jager
5de308c4b5
routerrpc: update final cltv delta default
The default was increased for the main sendpayment RPC in commit
d3fa9767a9729756bab9b4a1121344b265410b1a. This commit sets the
same default for QueryRoutes, routerrpc.SendPayment and
router.EstimateRouteFee.
2020-01-14 21:03:24 +01:00
carla
ec099bf5dd
htlcswitch: remove extramsg string from ForwardingError
Remove the extramsg field in ForwardingError because
it has been replaced with detailed link errors.
2020-01-14 15:23:11 +02:00
carla
b5a2d75465
htlcswitch+routing: type check on ClearTextError
Update the type check used for checking local payment
failures to check on the ClearTextError interface rather
than on the ForwardingError type. This change prepares
for splitting payment errors up into Link and Forwarding
errors.
2020-01-14 15:07:42 +02:00
carla
102f9b003f
htlcswitch: add ClearTextError interface
This commit adds a ClearTextError interface
which is implemented by non-opaque errors that
we know the underlying wire failure message for.
This interface is implemented by ForwardingErrors,
because we can fully decrypt the onion blob to
obtain the underlying failure reason. This interface
will also be implemented by errors which originate
at our node in following commits, because we know
the failure reason when we fail the htlc.

The lnwire interface is un-embedded in the
ForwardingError struct in favour of implementing
this interface. This change is made to protect
against accidental passing of a ForwardingError
to the wire, where the embedded FailureMessage
interface will present as wire failure but
will not serialize properly.
2020-01-14 15:07:41 +02:00
carla
6f0a342f92
htlcswitch: add ForwardingError constructor
Add a constructor for the creation of forwarding errors.
A special constructor is added for the case where we have
an unknown wire failure, and must set a nil failure message.
2020-01-14 15:07:29 +02:00
Joost Jager
81bf6e15b3
routing+lnrpc: add missing query routes parameters 2020-01-14 11:21:31 +01:00
Joost Jager
9c577f3f57
routing: extract route hint conversion 2020-01-14 11:21:29 +01:00
Conner Fromknecht
32284ef1f1
routing/pathfind_test: use ctx in recent tests
Modifies TestMissingFeatureDep and TestDestPaymentAddr to use the test
ctx directly instead of generating a closure and using local state to
modify restrictions.
2020-01-09 13:53:45 -08:00
Conner Fromknecht
c7a241fc59
routing/pathfind: ignore unknown required features
This commit brings us inline with recent modifications to the spec, that
say we shouldn't pay nodes whose feature vectors signal unknown required
features, and also that we shouldn't route through nodes signaling
unknown required features.

Currently we assert that invoices don't have such features during
decoding, but now that users can specify feature vectors via the rpc
interface, it makes sense to perform this check deeper in call stack.
This will also allow us to remove the check from decoding entirely,
making decodepayreq more useful for debugging.
2020-01-08 12:25:00 -08:00
Olaoluwa Osuntokun
128be259a7
routing: use updated sphinx.NewOnionPacket method
In this commit, we update the routing package to use the new
`sphinx.NewOnionPacket` method. The new version of this method allows us
to specify _how_ the packet should be filled before it's used to create
a mix-header. This isn't a fundamental change (totally backwards
compatible), instead it plugs a privacy leak that may have revealed to
the destination how long the true route was.
2020-01-07 16:11:39 -08:00
Andras Banki-Horvath
4e0ada9ea3 routing: clean up locking on topology change 2020-01-02 18:03:48 +01:00
Wilmer Paulino
9216ef2cd7
Merge pull request #3855 from cfromknecht/sorted-policies
routing/pathfind_test: construct sorted edge policies
2019-12-20 10:27:28 -08:00
Joost Jager
6e0cfe579b
Merge pull request #3841 from joostjager/check-max-onion-size
routing: check max routing info size
2019-12-20 14:42:47 +01:00
Joost Jager
e3b9ed5cd8
Merge pull request #3863 from joostjager/fix-result-interpretation
routing: fix gap in result interpretation
2019-12-20 14:42:19 +01:00
carla
25a8773736
routing: interpret mpp timeout failues
This commit adds success mission control
results for all hops along the route in
a mpp timeout and takes no action for
the final hop along the route. This is a
temporary measure to prevent the default
logic from penalizing the final node while
we decide how to penalize mpp timeouts.
2019-12-20 13:02:30 +02:00
carla
e0c86f1e71
htlcswitch+invoices: fail mpp timeouts with FailMPPTimeout
This commit adds a getResolutionFailure function
which returns an appropriate wire failure based
on the outcome of a htlc resolution. It also updates
 the MissionControlStore test to ensure that lnd
can handle failures which occur due to mpp timeout.
2019-12-20 13:02:02 +02:00
Joost Jager
c84e57a522
routing: remove unnecessary newline 2019-12-20 11:00:07 +01:00
Joost Jager
b760b25229
routing: limit routing info size during pathfinding
Also the max hop count check can be removed, because the real bound is
the payload size. By moving the check inside the search loop, we now
also backtrack when we hit the limit.
2019-12-20 11:00:05 +01:00
Joost Jager
513341516e
routing: fix max route length test
Enable the test again and use a programmatically built network.
2019-12-20 11:00:03 +01:00
Joost Jager
e8fd05e8e3
tlv+record+routing: add payload size calculation 2019-12-20 11:00:01 +01:00
Joost Jager
72a6383975
routing: use absolute final expiry in pathfinding 2019-12-20 11:00:00 +01:00
Joost Jager
e546a2c42b
routing: more efficient feature validation
Also prepares for payload size tracking during pathfinding
2019-12-20 10:17:03 +01:00
Joost Jager
95ddab57fa
channeldb: add tx argument for FetchLightningNode
To allow execution within an existing tx.
2019-12-20 10:17:01 +01:00
Joost Jager
a3a1b488a6
routing: fix gap in result interpretation
Fixes an off by one error that skipped assigning a success pair. Added a
test that previously failed because of this bug.
2019-12-20 09:14:15 +01:00
Conner Fromknecht
ff443a389b
routing/pathfind_test: constructed sorted edge policies
This commit fixes a potential bug in our test harness, by ensuring that
the constructed node policies are configured _after_ sorting. Currently
the node pubkeys are sorted, but additional parameters (max htlc,
disabled, etc) are applied using the unsorted policies.

Most of the constructors used today use the symmetric channel
constructor, so this shouldn't cause an issue with the majority of our
tests. We recently introduced an asymmetric channel constructor for
which this could have been an issue, however, no known issues were
discovered.

Lastly, we remove the direction from the configuration altogether, and
derive it purely from the final sorting of the pubkeys.
2019-12-19 03:47:24 -08:00
Joost Jager
37d9ee302c
channeldb: take serialized key to fetch lightning node
This prevents inefficient key conversions in a follow up commit that
change the inner pathfinding loop.
2019-12-19 12:44:00 +01:00
Conner Fromknecht
f868bc128b
rpcserver+routerrpc: thread features + payment addr to SendPayment 2019-12-18 23:56:59 -08:00
Conner Fromknecht
0993256b77
routing/pathfind: set single-shot MPP if payment addr is known 2019-12-18 23:56:42 -08:00
Conner Fromknecht
7965cb08db
routing/pathfind: consolidate population of custom records 2019-12-18 23:56:23 -08:00
Conner Fromknecht
cddb71ee53
routing/pathfind: evaluate TLV support sooner
We move up the check for TLV support, since we will later use it to
determine if we can use dependent features, e.g. TLV records and payment
addresses.
2019-12-18 23:56:05 -08:00
Conner Fromknecht
e3a9603846
routing/pathfind: simplify cltv calculation 2019-12-18 23:55:47 -08:00
Conner Fromknecht
b97adf79a4
routing/pathfind: consolidate final vs non-final hop processing 2019-12-18 23:55:27 -08:00
Conner Fromknecht
495ae8ca42
routing: consolidate final hop params for newRoute
This commit creates a wrapper struct, grouping all parameters that
influence the final hop during route construction. This is a preliminary
step for passing in the receiver's invoice feature bits, which will be
used to select an appropriate payment or payload type.
2019-12-18 23:55:08 -08:00
Conner Fromknecht
71e05e05bf
routing/pathfind: set final hop features used in pathfinding
In this commit, we overwrite the final hop's features with either the
destination features or those loaded from the graph fallback. This
ensures that the same features used in pathfinding will be provided to
route construction.

In an earlier commit, we validated the final hop's transitive feature
dependencies, so we also add validation to non-final nodes.
2019-12-18 23:54:49 -08:00
Conner Fromknecht
990d55d08c
routing/pathfind: ensure final hop supports payment addrs
This commit adds an optional PaymentAddr field to the RestrictParams, so
that we can verify the final hop can support it before doing an
expensive round of pathfindig.
2019-12-18 23:54:31 -08:00
Conner Fromknecht
acb7b83ead
routing/pathfind: validate final hop feature dependencies 2019-12-18 23:54:11 -08:00
Conner Fromknecht
cfa3fe2921
routing/pathfind: fix TLV fallback for unadvertised hops
In this commit, we fix a bug that prevents us from sending custom
records to nodes that aren't in the graph. Previously we would simply
fail if we were unable to retrieve the node's features.

To remedy, we add the option of supplying the destination's feature bits
into path finding. If present, we will use them directly without
consulting the graph, resolving the original issue. Instead, we will
only consult the graph as a fallback, which will still fail if the node
doesn't exist since the TLV features won't be populated in the empty
feature vector.

Furthermore, this also permits us to provide "virtual features" into the
pathfinding logic, where we make assumptions about what the receiver
supports even if the feature vector isn't actually taken from an
invoice. This can useful in cases like keysend, where we don't have an
invoice, but we can still attempt the payment if we assume the receiver
supports TLV.
2019-12-18 23:53:51 -08:00
Conner Fromknecht
bd66c0d34e
routing/pathfind_test: allow custom node features
This commit allows custom node features to be populated in specific test
instances. For consistency, we auto-populate an empty feature vector for
nodes that have nil feature vectors before writing them to the database.
2019-12-18 23:53:32 -08:00
Conner Fromknecht
618810394c
routing/pathfind_test: add asymmetric chan consructor
Later this will be used to populate distinct feature vectors for either
end of the channel.
2019-12-18 23:53:18 -08:00
Joost Jager
d85f378aa2
routing: move zero hops check 2019-12-16 14:53:47 +01:00
Joost Jager
31b2c22cf5
routing: check for invalid routes 2019-12-16 14:53:45 +01:00
Joost Jager
b8abae6a7e
routing: rename route variable to prevent clash with package 2019-12-14 08:47:53 +01:00
Joost Jager
75aa4e7061
routing: require tlv capability for custom record payments
Previously if a payment was sent with custom records attached, path
finding wouldn't perform a check whether the final node was capable of
receiving custom records in a tlv payload.
2019-12-12 00:15:02 +01:00
Joost Jager
c37289cd94
routing: pass custom records into pathfinding 2019-12-12 00:15:00 +01:00
Joost Jager
d02de70d20
multi: do not use tlv.Record outside wire format handling
This commit prepares for more manipulation of custom records. A list of
tlv.Record types is more difficult to use than the more basic
map[uint64][]byte.

Furthermore fields and variables are renamed to make them more
consistent.
2019-12-12 00:14:58 +01:00
Joost Jager
b6eb3a69ba
routing+lnrpc+lncli: allow setting min htlc policy 2019-12-11 00:17:08 +01:00
Joost Jager
74c2df658e
localchans: log policy update error 2019-12-11 00:17:06 +01:00
Joost Jager
f289dbd826
routing: define subsystem constant 2019-12-11 00:17:04 +01:00
Joost Jager
ddb98fcc41
multi: distinguish between htlc in and out constraints 2019-12-11 00:16:57 +01:00
Joost Jager
883f9e5f9a
Merge pull request #3749 from joostjager/extended-routing-failures
routing: local balance check before path finding
2019-12-04 12:17:17 +01:00
Joost Jager
9ae014edf6
routing: use self instead of source node for creating unified policy
A unified policy differs between local channels and other channels on
the network. There is more information available for local channels and
this is used in the unified policy.

Previously we used the pathfinding source pubkey to determine whether to
apply the local channel logic or not. If queryroutes is executed with a
source node that isn't the self node, this wouldn't work.
2019-12-04 09:45:09 +01:00
Joost Jager
97344af8f3
routing: local balance check 2019-12-04 09:45:07 +01:00
Joost Jager
3aaf32dc2e
routing: improve equal cost route comparison
When the (virtual) payment attempt cost is set to zero, probabilities
are no longer a factor in determining the best route. In case of routes
with equal costs, we'd just go with the first one found. This commit
refines this behavior by picking the route with the highest probability.
So even though probability doesn't affect the route cost, it is still
used as a tie breaker.
2019-12-02 14:23:57 +01:00
Joost Jager
c15b0316a2
routing: use FailureReasonError for internal path finding errors 2019-11-27 15:21:12 +01:00
Joost Jager
b5f1bde604
routing: add error var for pre-built route tried 2019-11-27 15:21:10 +01:00
Joost Jager
ac2df9bbf4
routing: use simple errors for path finding 2019-11-27 15:21:08 +01:00
Joost Jager
6774b5a007
routing: remove unused error codes 2019-11-27 15:21:06 +01:00
Joost Jager
7e4f9dd70a
routing/test: simplify context instantiation 2019-11-26 21:40:30 +01:00
Joost Jager
f8e9efbf99
routing: allow route to self 2019-11-26 10:15:44 +01:00
Joost Jager
81b7798c03
routing: pop heap at the end of the loop
This prepares for routing to self.
2019-11-26 10:15:42 +01:00
Joost Jager
683282fa24
routing: check loop conditions at end
This prepares for routing to self. When checking the condition at the
start, the loop would terminate immediately because the source is equal
to the target.
2019-11-26 10:15:40 +01:00
Joost Jager
2b332893b7
routing/test: add test focusing on not having a cycle 2019-11-26 10:15:38 +01:00
Joost Jager
cdf1aa5bc1
routing: track amt ranges in mc 2019-11-22 11:17:28 +01:00
Joost Jager
62f8cca75b
routing+routerrpc: also expose amt for success results in mc 2019-11-22 11:17:26 +01:00
Olaoluwa Osuntokun
6f9fcfaccc
Merge pull request #3499 from cfromknecht/mpp-payments-rpc
channeldb+rpcserver: expose legacy payments as multi-path payments
2019-11-21 18:38:53 -08:00