Commit Graph
100 Commits
Author SHA1 Message Date
Joost Jager 220c2becb1 lncli: unify payinvoice and sendpayment code
This commit prepares lncli for moving over to routerrpc payment calls.
2019-06-05 12:41:57 +02:00
Joost Jager 2644759924 channeldb: add todo for more detailed failure reasons 2019-06-05 12:41:55 +02:00
Joost Jager f03533c67a routerrpc: convert sendpayment to async
Modify the routerrpc SendPayment api to asynchronous. This allows
callers to pick up a payment after the rpc connection was lost or lnd
was restarted.
2019-06-05 12:41:53 +02:00
Joost Jager 07d289c14e routing: add SendPaymentAsync to router 2019-06-05 12:41:51 +02:00
Joost Jager eb2647e8fc channeldb: add subscription to control tower
Allows other sub-systems to subscribe to payment success and fail
events.
2019-06-05 12:41:49 +02:00
Joost Jager 87d3207baf channeldb+routing: move control tower interface to routing
This commit creates an empty shall for control tower in the routing
package. It is a preparation for adding event notification.
2019-06-05 12:41:47 +02:00
Joost Jager eb700d35e1 routerrpc: extend payment request parameters
Add missing parameters to routerrpc version of SendPayment.
2019-06-05 12:41:45 +02:00
Joost Jager 19d5f8f82c routing: move default cltv assignment out of router
This commit lifts default setting up to the rpc server level, in line
with other payment defaults.
2019-06-05 12:41:43 +02:00
Joost Jager afd86763ac lntypes: add ZeroHash 2019-06-05 12:41:41 +02:00
Joost Jager 054e42f680 routing+routerrpc: expose mission control parameters in lnd config
This commit exposes the three main parameters that influence mission
control and path finding to the user as command line or config file
flags. It allows for fine-tuning for optimal results.
2019-06-04 13:22:50 +02:00
Joost Jager 9b71d90a6e lncli: add querymc command
Adds querymc command to lncli to dump mission control state.
2019-06-04 10:00:29 +02:00
Joost Jager f7982f0f4c routing+routerrpc: expose mission control state over rpc
This commit exposes mission control state for rpc for development
purposes.
2019-06-04 10:00:27 +02:00
Joost Jager 7133f37bb8 routing: global probability based mission control
Previously every payment had its own local mission control state which
was in effect only for that payment. In this commit most of the local
state is removed and payments all tap into the global mission control
probability estimator.

Furthermore the decay time of pruned edges and nodes is extended, so
that observations about the network can better benefit future payment
processes.

Last, the probability function is transformed from a binary output to a
gradual curve, allowing for a better trade off between candidate routes.
2019-06-04 10:00:25 +02:00
Joost Jager 3349d517aa routing: add min probability to path finding
This commit adds a new restriction to pathfinding that allows returning
only routes with a minimum success probability.
2019-06-04 10:00:23 +02:00
Joost Jager 6b70791c2d routing: use probability source in path finding
This PR replaces the previously used edge and node ignore lists in path
finding by a probability based system. It modifies path finding so that
it not only compares routes on fee and time lock, but also takes route
success probability into account.

Allowing routes to be compared based on success probability is achieved
by introducing a 'virtual' cost of a payment attempt and using that to
translate probability into another cost factor.
2019-06-04 10:00:21 +02:00
Joost Jager b6102ad191 routing: remove querybandwidth self node check
This function is only ever called for channels connected to self.
2019-06-04 10:00:19 +02:00
Joost Jager 68f2a04f42 routerrpc: expose mission control reset rpc 2019-06-04 10:00:17 +02:00
Joost Jager 3db48dc53f routing: Route String() method 2019-06-04 10:00:15 +02:00
Joost Jager 35003bd87c routing/test: sort nodes for channel graph
This commit ensures that channel endpoints in EdgeInfo are ordered
node1 < node2 to not violate assumptions being made by dependent code.
2019-06-04 10:00:13 +02:00
Joost Jager 1b5655f7fa Merge pull request #3113 from joostjager/sendtoroute-error-fix
routing: return structured error for send to route
2019-05-30 23:20:14 +02:00
Joost Jager 1fc01370bf routerrpc: marshall missing channel update data 2019-05-29 14:07:03 +02:00
Joost Jager cc88bfb560 routerrpc: proto comments updated 2019-05-29 14:07:01 +02:00
Joost Jager cbfc7dd42d routing: check findPath error 2019-05-29 14:07:00 +02:00
Joost Jager 0e273a5731 routing: return structured error for send to route 2019-05-29 14:06:58 +02:00
Joost Jager dff0387363 lntest: move itest into package 2019-05-28 21:43:23 +02:00
Joost Jager 9a4c0d5699 lnrpc: upgrade to protobuf v1.3.1
This commit upgrades the protobuf version. Compared to the previous
v1.2.0 it generates smaller diffs in generated code. This change was
introduced in:

https://github.com/golang/protobuf/commit/fffb0f78287ac709b1395be9708df0b579a385f7
2019-05-20 15:35:14 +02:00
Joost Jager 27ae22fa6c Merge pull request #2913 from joostjager/hodl-restart-fix
cnct+htlcswitch+invoices: move invoice parameter check to registry
2019-05-16 21:31:26 +02:00
Joost Jager 570f9ca57e htlcswitch/test: hodl invoice restart test
This commit adds a test that covers the hodl invoice behaviour after a
link restart.
2019-05-15 14:42:24 +02:00
Joost Jager e5ead599cc htlcswitch/test: use single channel restore function
This commit refactors test code around channel restoration in unit
tests to make it easier to use.
2019-05-15 14:42:21 +02:00
Joost Jager 3d17c2bcfe cnct/test: add incoming contest resolver test 2019-05-15 14:42:18 +02:00
Joost Jager 16ff4e3ffa cnct/test: extend mockWitnessBeacon 2019-05-15 14:42:15 +02:00
Joost Jager 064e8492de cnct+htlcswitch+invoices: move invoice parameter check out of link
This commit is the final step in making the link unaware of invoices. It
now purely offers the htlc to the invoice registry and follows
instructions from the invoice registry about how and when to respond to
the htlc.

The change also fixes a bug where upon restart, hodl htlcs were
subjected to the invoice minimum cltv delta requirement again. If the
block height has increased in the mean while, the htlc would be canceled
back.

Furthermore the invoice registry interaction is aligned between link and
contract resolvers.
2019-05-15 14:42:12 +02:00
Joost Jager e095819385 lnd_test: add hodl parameter to createThreeHopNetwork 2019-05-15 14:42:09 +02:00
Joost Jager bf0af12fae lnd_test: move chain claim tests to separate files
This commit splits out several integration tests that will be modified
in a follow up commit to separate files. The current lnd_test.go file is
10k+ loc which makes it harder to handle by tools and it isn't good for
overview either.
2019-05-15 14:42:06 +02:00
Joost Jager d8dac49112 cnct: add invoice registry interface
Create an interface type to be able to mock the registry in unit tests.
2019-05-15 14:42:01 +02:00
Joost Jager 1a80a1e540 witness_beacon: do not look up invoice preimages
This commit isolates preimages of forwarded htlcs from invoice
preimages. The reason to do this is to prevent the incoming contest
resolver from settling exit hop htlcs for which the invoice isn't marked
as settled.
2019-05-15 14:41:58 +02:00
Joost Jager 99e42ddde6 cnct: be stricter about matching preimages
The former tryApplyPreimage function silently ignored invalid preimages.
This could mask potential bugs. This commit makes the logic stricter and
generates an error in case an unexpected mismatch occurs.
2019-05-15 14:41:55 +02:00
Joost Jager ec6a35d6e8 cnct: do not depend on ChainIO in incoming contest resolver
New behaviour of the chain notifier to always send the current block
immediately after registration takes away the need to make a separate
GetBestBlock call on ChainIO.
2019-05-15 14:41:52 +02:00
Joost Jager d55a8b7b29 channel+cnct: remove preimage from channel and resolution
Now that the success resolver preimage field is always populated by the
incoming contest resolver, preimage lookups earlier in the
process (channel and channel arbitrator) can mostly be removed.
2019-05-15 14:41:49 +02:00
Joost Jager 6886a0117f cnct: always create incoming contest resolver
One of the first things the incoming contest resolver does is checking
if the preimage is available and if it is, convert itself into a success
resolver.

This behaviour makes it unnecessary to already determine earlier in the
process whether an incoming contest or a success resolver is needed.

By having all incoming htlcs go through the incoming contest resolver,
the number of execution paths is reduced and it becomes easier to
ascertain that the implemented logic is correct.

The only functional change in this commit is that a forwarded htlc for
which is the preimage is known, is no longer settled when the htlc is
already expired. Previously a success resolver would be instantiated
directly, skipping the expiry height check.

This created a risk that the success resolver would never finish,
because an expired htlc could already have been swept by the remote
party and there is no detection of this remote spend in the success
resolver currently.

With the new change, the general direction that an expired htlc
shouldn't be settled and instead given up on is implemented more
consistently.

This commit prepares for fixing edges cases related to hodl
invoice on-chain resolution.
2019-05-15 14:41:47 +02:00
Joost Jager 863bf2f91b Merge pull request #1662 from joostjager/raw
lnrpc: better payment failure reporting
2019-05-15 14:38:52 +02:00
Joost Jager c97592692c routerrpc: add SendToRoute with structured failure message 2019-05-15 11:54:46 +02:00
Joost Jager b2eb2619bf routerrpc: connect UnmarshallRoute to existing config fields 2019-05-15 11:54:46 +02:00
Joost Jager ba3fa94268 lnrpc+routing: Only accept a single route for SendToRoute 2019-05-15 11:54:46 +02:00
Joost Jager 0b66d56aab routerrpc: move UnmarshallRoute to sub server 2019-05-13 12:55:56 +02:00
Joost Jager 7a5bd29a69 lnrpc+routing: remove k shortest path finding 2019-05-07 19:54:06 +02:00
Joost Jager f5f6a52ed8 htlcswitch: check channel policy for local htlcs 2019-05-03 12:22:36 +02:00
Joost Jager e571532d9a htlcswitch: reorder policy checks
This commit reorders the policies check as a preparation for splitting
the checks in separate sets for the incoming and outgoing htlc.
2019-05-03 12:22:33 +02:00
Joost Jager 5d2de91241 config: update broadcast delta to reduce risk of channel force close 2019-05-03 12:22:30 +02:00
Joost Jager 3b94627c12 routing: remove route cache
This commit removes the QueryRoutes route cache. It is causing wrong
routes to be returned because not all of the request parameters are
stored.

The cache allowed high frequency QueryRoutes calls to the same
destination and with the same amount to be returned fast. This behaviour
can also be achieved by caching the request on the client side. In case
a route is invalidated because of for example a channel update,
the subsequent SendToRoute call will fail. This is a trigger to call
QueryRoutes again for a fresh route.
2019-04-13 08:10:32 +02:00
Joost Jager 2b43da4220 Merge pull request #2944 from joostjager/increase-test-timeout
htlcswitch/test: increase test timeout for hodl invoice tests
2019-04-12 11:50:20 +02:00
Joost Jager 40cea6b487 htlcswitch/test: increase test timeout for hodl invoice tests 2019-04-12 09:01:05 +02:00
Joost Jager 72c86fbf5d htlcswitch/test: test revocation window exhaustion 2019-04-10 21:30:31 +02:00
Joost Jager 6d2dfed03d htlcswitch: increase batch counter for exit hop settle and fail
The idea of the batch counter is to increase it for commit tx updates,
so that if the commit tx cannot be updated immediately (revocation
window exhausted), the batch ticker makes sure it happens later.

The batch counter was increased for forwarded htlcs, but not for exit hop
resolutions.

This lead to the situation where the commitment tx would not be updated,
even though the htlc was settled locally. When no other changes happen
on the channel, the htlc eventually reaches its expiry and the channel
is force closed.
2019-04-10 21:04:51 +02:00
Joost Jager a2aeb646e7 Merge pull request #2908 from joostjager/chan-arb-logging
cnct+invoices: improve logging
2019-04-09 22:34:12 +02:00
Joost Jager 038ce342b3 htlcswitch: do not check final cltv for accepted invoices 2019-04-08 18:16:21 +02:00
Joost Jager 33a1904dc9 invoices: unify invoice log statements 2019-04-08 13:10:51 +02:00
Joost Jager 86eb0a3383 cnct: log go to chain reason
This commit adds logging of the reason to go to chain for a channel.
This can help users to find out the reason why a channels forced closed.

To get all go to chain reasons, an optimization to break early is
removed. This optimization was not significant, because the normal flow
already examined all htlcs. In the exceptional case where we need to go
to chain, it does not weigh up against logging all go to chain reasons.
2019-04-08 10:34:41 +02:00
Joost Jager 206d93d856 htlcswitch/test: test zero value for outbound cltv reject delta 2019-04-05 11:36:18 +02:00
Joost Jager 1b2816006f htlcswitch/test: align test invoice cltv expiry 2019-04-05 11:36:16 +02:00
Joost Jager af7d0e5ff5 htlcswitch/test: convert TestChannelLinkSingleHopPayment to two hop network 2019-04-05 11:36:13 +02:00
Joost Jager 037913fd28 link: rewrite height comparisons without subtraction
Prevent the case where a uint32 wrap around could happen.
2019-04-05 11:36:10 +02:00
Joost Jager ab4da0f53d cnct: define separate broadcast delta for outgoing htlcs
This commits exposes the various parameters around going to chain and
accepting htlcs in a clear way.

In addition to this, it reverts those parameters to what they were
before the merge of commit d107627145.
2019-04-05 11:36:07 +02:00
Joost Jager cf42719c45 lnd+rpcserver: refactor TLS configuration
This commit restructures the creation of various tls related object. It
also fixes a bug where wildcard IP addresses where only instantiated for
the main RPC server and not the WalletUnlocker service.
2019-04-04 14:18:18 -07:00
Joost Jager 6b6dd30aa7 routerrpc: register router sub server logger 2019-03-27 11:44:49 +01:00
Joost JagerandJim Posen cd535b9401 link: increase expiry grace delta
This commit increase the expiry grace delta to a value above the
broadcast delta. This prevents htlcs from being accepted that would
immediately trigger a channel force close.

A correct delta is generated in server.go where there is access to
the broadcast delta and passed via the peer to the links.

Co-authored-by: Jim Posen <jim.posen@gmail.com>
2019-03-26 18:42:00 +01:00
Joost JagerandJim Posen e6fbbaa1dc link: also check expiry grace delta for forwarded htlcs
Previously there was no minimum remaining blocks requirement on
forwarded htlcs, which may cause channel arbitrator to force
close the channel directly after forwarding the htlc.

Co-authored-by: Jim Posen <jim.posen@gmail.com>
2019-03-26 18:41:41 +01:00
Joost Jager 73efc31177 build: add routerrpc tag in itest 2019-03-21 10:25:58 +01:00
Joost Jager 087de7cc4d routerrpc: adapt to changed interfaces of routing subsystem 2019-03-21 10:25:55 +01:00
Joost Jager ec0d241905 lncli: add cltv limit 2019-03-19 10:38:09 +01:00
Joost Jager 06cd64cbbc routing: add cltv limit to payment session 2019-03-19 10:36:51 +01:00
Joost Jager e3bb3d46a2 routing: abstract path finding interface 2019-03-19 10:36:48 +01:00
Joost Jager 6006549ed5 routing: enforce cltv limit in path finding 2019-03-19 10:36:45 +01:00
Joost Jager c5961d4904 routing: only warn for zero cltv delta edges
This condition may be caused by a bug somewhere else in the system.
Expose it here as a warn log line.
2019-03-19 10:36:43 +01:00
Joost Jager f6d67945dc lncli: add settle invoice command 2019-03-15 10:09:26 +01:00
Joost Jager f450929b65 invoicesrpc: add SettleInvoice 2019-03-15 10:09:23 +01:00
Joost Jager 0823c79e4e htlcswitch/test: hodl invoice test 2019-03-15 10:09:20 +01:00
Joost Jager 32f2b047e8 htlcswitch: hodl invoice
This commit modifies the invoice registry to handle invoices for which
the preimage is not known yet (hodl invoices). In that case, the
resolution channel passed in from links and resolvers is stored until we
either learn the preimage or want to cancel the htlc.
2019-03-15 10:09:17 +01:00
Joost Jager 1f41a2abce htlcswitch: abtract invoice from link
This commit detaches signaling the invoice registry that an htlc was
locked in from the actually settling of the htlc.

It is a preparation for hodl invoices.
2019-03-15 10:09:15 +01:00
Joost Jager aeb35d9898 htlcswitch/test: use real invoice registry with temp db as mock
In further commits the behaviour of invoice registry becomes more
intrinsically connected to the link. This commit prepares for that by
allowing link and registry to be tested as a single unit.
2019-03-15 10:09:12 +01:00
Joost Jager e464ed18c7 htlcswitch/test: make unknown hash test independent of mock
In the TestChannelLinkMultiHopUnknownPaymentHash test, a preimage was
modified to trigger an unknown payment hash failure. The way the mock is
implemented, it would take the hash of that modified preimage and store
it. It basically stores a completely different invoice. For this test,
it is just as good to store no invoice at all.
2019-03-15 10:09:09 +01:00
Joost Jager 3b5c2f44c6 invoices: extract invoice decoding from registry
Previously it was difficult to use the invoice registry in unit tests,
because it used zpay32 to decode the invoice. For that to succeed, a
valid signature is required on the payment request.

This commit injects the decode dependency on a different level so that
it is easier to mock.
2019-03-15 10:09:06 +01:00
Joost Jager c23bb5b3f1 htlcswitch: extract settle invoice into method 2019-03-15 10:09:03 +01:00
Joost Jager 22b68e5dc7 lncli: add hold invoice 2019-03-15 10:09:00 +01:00
Joost Jager fcdc8f0e83 lnrpc/invoices: add hold invoice rpc 2019-03-15 10:08:58 +01:00
Joost Jager 19f79613df channeldb: store hold invoice 2019-03-15 10:08:55 +01:00
Joost Jager 8392f6d28f lnrpc/invoicesrpc: remove lnrpc type from add invoice 2019-03-15 10:08:52 +01:00
Joost Jager b9cc165341 lnrpc: move add invoice logic to subserver 2019-03-15 10:08:49 +01:00
Joost Jager 4141773e90 htlcswitch: resolve invoice cancelation race condition
Previously it could happen that an invoice was open at the time of the
LookupInvoice call, the htlc was settled because of that, but when the
SettleInvoice call was made eventually, it would fail because the
invoice was canceled in the mean time. The htlc would then be settled,
but the invoice not marked as such.
2019-03-15 10:08:46 +01:00
Joost Jager eb598ec7a4 htlcswitch: extract exit hop processing to method 2019-03-15 10:08:43 +01:00
Joost Jager 9643b45dbc htlcswitch/test: move preimage cache to server level
In this commit the preimage cache is instantiated on the mock server
level where it belongs. Previously it was a cache shared across all mock
servers.
2019-03-15 10:08:40 +01:00
Joost Jager c4263e7061 lntypes: return a value from constructors
Returning pointers proved inconvenient in almost all cases. This commmit
converts the constructors to returning values.
2019-03-15 10:08:38 +01:00
Joost Jager 449c3d533e contractcourt: add access to full invoice registry from resolvers
Previously a function pointer was passed to chain arbitrator to avoid a
circular dependency. Now that the routetypes package exists, we can pass
the full invoice registry to chain arbitrator.

This is a preparation to be able to use other invoice registry methods
in contract resolvers.
2019-03-15 10:08:35 +01:00
Joost Jager 2be1051fb6 zpay32: move HopHint and DefaultFinalCLTVDelta 2019-03-15 10:08:32 +01:00
Joost Jager 652ebb1652 lnwire: add constructor for FinalExpiryTooSoon failure message 2019-03-15 10:08:29 +01:00
Joost Jager 10a655b6b1 lntypes: add preimage Matches method 2019-03-15 10:08:26 +01:00
Joost Jager 293971cd03 routerrpc: move query routes into sub server
This commit moves the query routes backend logic from the main
rpc server into the sub server. It is another step towards splitting up
the main rpc server code.

In addition to this, a unit test is added to verify rpc parameter
parsing.
2019-03-11 09:56:16 +01:00
Joost Jager 5b6fdbeb6f lncli: fix command line argument parsing for sendpayment
This commit fixes a bug that caused the payment hash to be (re)parsed as
an int representing the final cltv delta.
2019-03-08 10:42:18 +01:00
Joost Jager 6cc82b4a34 routing: add todo describing route cache bug 2019-03-06 15:31:09 +01:00
Joost Jager 6e10c05a82 lnrpc: deprecate QueryRoutes with more than one route
Now that QueryRoutes gained the ability to route from any source node
and takes in edge and node black lists, all pieces are in place to have
users implemented their own k-shortests path algorithm. Or any other algorithm
they might wish to use and currently can't.

This commit marks the num_routes field as deprecated as a preparation
for removing k-shortest for lnd.
2019-03-06 15:31:06 +01:00