Commit Graph

1281 Commits

Author SHA1 Message Date
Christopher Jämthagen
78e102f08d lnwallet: fix settled/cancelled HTLCs remote pkScripts + cleanup
When an HTLC is either cancelled or settled we must properly set the
pkScript for the HTLC on the remote commitment, such that we can
generate a valid ChannelDelta.
2017-03-21 21:21:46 -07:00
Christopher Jämthagen
2222df21f3 lnwallet: fix dust limit checks and toChannelDelta() handling of dust 2017-03-21 21:21:46 -07:00
Christopher Jämthagen
05a90df67a lnwallet: return error from toChannelDelta() if htlc output is not found 2017-03-21 21:21:46 -07:00
Christopher Jämthagen
9083007ece lnwallet: fix bug that retrieves incorrect pkScript in toChannelDelta()
Description of bug:
When calling ReceiveNewCommitment() we will progress through methods
fetchCommitmentView and addHTLC which will add HTLC outputs to the
commitment transaction in the local commitment chain and save the
pkScript to the relevant PaymentDescriptor which resides in the
corresponding updateLog. Finally the local commitment will be added
to the local commitment chain.

When the same user next calls SignNextCommitment we will again
progress through fetchCommitmentView and addHTLC. In addHTLC we will
now overwrite the pkScripts in the PaymentDescriptors with the
pkScript from the context of the remote commitment. When we later
call RevokeCurrentCommitment and proceed into toChannelDelta, we
will not be able to find the correct pkScript in the PaymentDescriptor
to match it against the outputs in the commitment transaction.
This will lead to the nested function locateOutputIndex returning
incorrect values.

Fixing the bug:
We introduce three new fields in PaymentDescriptor:
* ourPkScript
* theirPkScript
* theirPrevPkScript

ourPkScript will include the pkScript for the HTLC from the context
of the local commitment.

theirPkScript will take the value of the latest pkScript for the HTLC
from the context of the remote commitment.

theirPrevPkScript will take the second-latest pkScript for the HTLC
from the context of the remote commitment. This is the value we use
in toChannelDelta when we save a revoked commitment from our peer.

The appropriate value of these fields are set in the addHTLC method.

Additionally we pass a boolean value to toChannelDelta so we know
whether we are operating on a local or remote commitment and grab
the correct pkScript in locateUpdateIndex.
2017-03-21 21:21:46 -07:00
Christopher Jämthagen
4d03f60e40 lnwallet: handle duplicate payment hashes in toChannelDelta() 2017-03-21 21:21:46 -07:00
Andrey Samokhvalov
fbf819062a gotest: remove slow linters 2017-03-21 14:56:23 -07:00
Olaoluwa Osuntokun
69b257154f
routing: fix build on go 1.7.5 by using sort.Interface instead of sort.Lice
This commit fixes the issue of broken builds in versions other than go
1.7.5 by sorting according to the sort.Interface interface rather than
the newly available sort.Slice function.
2017-03-21 12:21:00 -07:00
Olaoluwa Osuntokun
3da8cd7551
routing: add a caching layer in front of the KSP algorithm
This commit adds caching to our route finding. Caching is done on a
tuple-basis mapping a (dest, amt) pair to a previously calculated set
of shortest paths. The cache invalidated on two occasions: when a block
closes a set of transactions, or we received a new channel update or
channel announcement message.

With this change, payments are now snappier from the PoV of an
application developer as we no longer need to do a series of disk-seeks
before we dispatch each payment.
2017-03-21 12:20:55 -07:00
Olaoluwa Osuntokun
47c065b72c
rpc: re-implement QueryRoute as QueryRoutes 2017-03-21 12:20:52 -07:00
Olaoluwa Osuntokun
dabaf9da70
cmd/lncli: convert queryRoute to queryRoutes 2017-03-21 12:20:50 -07:00
Olaoluwa Osuntokun
04a6c2f7f6
lnrpc: convert QueryRoute to QueryRoutes
This commit converts the previous QueryRoute command to a new command:
QueryRoutes. This command is identical to QueryRoute other than the
fact that it’s able to return multiple routes rather than a single
route.
2017-03-21 12:20:47 -07:00
Olaoluwa Osuntokun
b126298b2b
routing: implement route failure fallback in SendPayment
This commit adds payment route failure fallback to SendPayment. By
this, we mean that we now take all the possible routes found during
path finding and try them in series. Either a route fails and we move
onto the next one, or the route is successful and we terminate early.

With this commit, sending payments using lnd is now much more robust as
if there exists an eligible route with sufficient capacity, it will be
utilized.
2017-03-21 12:20:45 -07:00
Olaoluwa Osuntokun
9818f662cf
routing: exit early in FindRoutes if unable to convert any paths to a route 2017-03-21 12:20:42 -07:00
Olaoluwa Osuntokun
1df5bece85
routing: FindRoute is now FindRoutes, uses our KSP algo, ranks by fee
This commit modifies the existing FindRoute method on the ChannelRouter
to now use the KSP implementation added in a prior commit.

This new method FindRoutes, is able to find all the possible paths
between a source and destination. The method takes all paths reported
by findPaths, and attempt to turn each of them into a route. A route
differs from a path in that is has complete time-lock and fee
information. Some paths may not be able to be turned into routes as
once fees are accounted for the have an insufficient flow. We then take
the routes, sort them by total fee (with time-lock being a
time-breaker), then return them in sorted order.
2017-03-21 12:20:40 -07:00
Olaoluwa Osuntokun
aaa04bb2e5
routing: add findPaths function whcih implements Yen's Algorithm
With this commit we make our routing more robust by looking for the
k-shortest paths rather than a single shortest path and using that
unconditionally. In a nut shell Yen’s algorithm does the following:
   * Find the shortest path from the source to the destination
   * From k=1…K, walk the kth shortest path and find possible
divergence from each node in the path

Our version of Yen’s implemented is slightly modified, rather than
actually increasing the edge weights or remove vertexes from the graph,
we instead use two black-lists: one for edges and the other for
vertexes. Our modified version of Djikstra’s algorithm is then made
aware of these black lists in order to more efficiently implement the
path iteration via spur and root node.
2017-03-21 12:20:37 -07:00
Olaoluwa Osuntokun
56d27f2d58
routing: rename findRoute to findPath, return path in forwards order
This commit modifies the findRoute method by first calling it findPath,
but also making the following modifications.

First, two new black-listing maps are now passed in. These two maps
contain vertexes but also edges to ignore while performing path
finding. These maps will be used in order to ensure that we don’t
duplicate paths or back-track when executing our KSP algorithm.

Next, we now ensure that the path returned from the findPath function
is ordered properly in the direction of source to target. Such a change
is required for our KSP algorithm to function properly.
2017-03-21 12:20:35 -07:00
Olaoluwa Osuntokun
fd18c2d036
routing: newRoute now expects the path in forwards order 2017-03-21 12:20:33 -07:00
Olaoluwa Osuntokun
9f96ceb1e0
routing: introduce new heap for storing candidate shortest paths
This commit adds a new heap structure to heap.go which will be used for
storing candidate paths during the iterations of the k-shortest paths
algorithm.
2017-03-21 12:20:30 -07:00
Olaoluwa Osuntokun
e0ef63e4e0
routing: findRoute now returns a slice of selected hops in reverse order
This commit modifies the findRoute function to decouple the
validation+creation of a route, from the path finding algorithm itself.
When we say “route”, we mean the full payment route complete with
time-lock and fee information. When we say “path” we simple mean an
ordered set of channel edges from one node to another target node.

With this commit we can now perform path finding independent of route
creation which will be needed in the up coming refactor to implement a
new modified k-shortest paths algorithm.
2017-03-21 12:20:28 -07:00
Olaoluwa Osuntokun
c6c56173a8
routing: modify findRoute to accept starting node as a paramter
This commit slightly modified findRoute to accept the node which should
be used as the starting point in our path finding algorithm. With this
change, as we move to a k-shortest paths algorithm this modification
will be needed as all of our path finding attempts won’t always
originate from a the same starting point.
2017-03-21 12:20:25 -07:00
Olaoluwa Osuntokun
b6199f27da
routing: replace linear vertex scan with distanceHeap usage
In this commit we now utilize the node distance heap that was added in
a prior commit into our core path finding logic. With this new data
structure, we no longer linearly scan the distance of all vertexes from
the source node when deciding which one to greedily explore.

Instead, we now start with the source added to our distance heap, then
new vertexes are progressively added to our heap as their edges are
explored. With this change, we move the computational complexity of our
path finding algorithm closer to the theoretical limit.
2017-03-21 12:20:23 -07:00
Olaoluwa Osuntokun
20aba8060f
routing: add sufficient link capacity to our relaxation condition
This commit modifies our modified version of Dijkstra's to include
sufficient link capacity within the algorithm’s relaxation condition.
With this change, we’ll now avoid exploring the graph in the direction
of a link that has insufficient capacity, allowing us to terminate path
finding more quickly.
2017-03-21 12:20:21 -07:00
Olaoluwa Osuntokun
606b23df43
routing: introduce a heap to keep track of closest nodes during pathfinding
This commit introduces a new heap struct that will be used to keep
track of the next closest node to the source during path finding within
our modified Dijkstra's algorithm.
2017-03-21 12:20:18 -07:00
Andrey Samokhvalov
5d434839a4 gotest: use stable version of metalinter 2017-03-17 12:53:15 -07:00
Andrey Samokhvalov
9dfaca1632 linter: fix new warnings 2017-03-17 12:53:15 -07:00
Andrey Samokhvalov
a423dc3e6c tests: add timeout in 'revoked uncooperative close retribution' test 2017-03-17 12:53:15 -07:00
Olaoluwa Osuntokun
aa0fbcaefd
lnrpc: correct wrong json_name field in Payment proto 2017-03-16 19:45:56 -07:00
Olaoluwa Osuntokun
ac83b8ae06
peer: fix bug in handshake wherein RevokeAndAck would be sent first
This commit fixes a bug in the opening handshake between to peers. The
bug would arise when on or many channels were active between a node
establishing a new connection. The htlcManager goroutines will
immediately attempt to extend the revocation window once they’re
active. However, at this time, the init message may not yet have been
sent as the two executions are in distinct goroutines.

We fix this bug by manually writing the init message directly to the
socket, rather than traveling through the queueHandler goroutine. With
this, we ensure that the init message is _always_ sent first.
2017-03-16 19:45:16 -07:00
Olaoluwa Osuntokun
ec52c49b6c
lnd+lnwallet+glide: replace last lingering instances of fastsha256 2017-03-16 19:40:29 -07:00
Thomas Preindl
a1bb36730a lnd: fix typos in comments 2017-03-16 12:39:40 -07:00
Thomas Preindl
862722d6fe lnrpc: switch Transaction.Amount from double (BTC) to int64 (sat) 2017-03-16 12:39:40 -07:00
Thomas Preindl
b880d2dd03 rcpserver: add missing BlockHeight value to GetTransactions response 2017-03-16 12:39:40 -07:00
andrew.shvv
35813ad939 server: fix panic when error occures on peer intialization (#163)
If an error occurs during, peer initialization then 'p' is nil. This 
may cause a panic while accessing the peer's member 
variables.

To avoid such panics, we now omit the call to `p.Disconnect` 
and also directly access the `connmgr.ConReq` variable if it's 
non-nil.
2017-03-16 12:37:36 -07:00
Olaoluwa Osuntokun
d0509955a7
routing: only log topology client sends if clients are active 2017-03-16 12:16:32 -07:00
Olaoluwa Osuntokun
57a7d58ef9
test: don't panic within lightningNetworkWatcher if lnd is shutting down
This commit fixes an issue in the newly added integration tests level
topology notifications that caused tests to erronosely panic when the
daemon was detected to be shutting down. This issue was notified by
AndrewSamokhvalov.

We fix this issue by checking if the error is a shutdown error, and
exiting early if so. Additionally we add a fail-fast case if the quit
channel for the node has already been closed.
2017-03-16 12:15:42 -07:00
Olaoluwa Osuntokun
0db384fd6b
lnwire: properly fold at 80-columns within features.go 2017-03-16 12:12:00 -07:00
Olaoluwa Osuntokun
c21cbc5021
cmd/lncli: append a new-line when using encoding/json to print resp
It was noticed by 21E14 on Github that when we fall back to using
golang’s encoding/json lib in special cases when printing the proto
responses in JSON form, the value printed lacked a new-line at the end.
This would cause the output to flow into bash prompts.

This issue has been fixed by simply appending a newline character to
the end of the formatted JSON output.

Fixes #160.
2017-03-16 12:06:17 -07:00
Olaoluwa Osuntokun
f0b14af0f3
glide: update glide to remove fastsha256, add x/crypto/chacha20poly1305 2017-03-15 19:08:39 -07:00
Olaoluwa Osuntokun
9234956a34
brontide: replace aead/chacha20 with x/crypto/chacha20poly1305
This commit replaces aead’s chacha20 library with the official golang
implementation. We should see a bit of a performance increase on amd64
as the assembly for the library uses the SIMD AVX2 instructions in the
inner loop. In the future assembly will be written for other platforms,
so we’ll see a performance increase across the board.

Fixes #146.
2017-03-15 19:03:24 -07:00
Olaoluwa Osuntokun
f217093c00
multi: replace usage of fastsha256 with crypto/sha256
This commit removes all instances of the fastsha256 library and
replaces it with the sha256 library in the standard library. This
change should see a number of performance improvements as the standard
library has highly optimized assembly instructions with use vectorized
instructions as the platform supports.
2017-03-15 18:56:41 -07:00
Andrey Samokhvalov
d723aada30 goclean: add vendor check; add '-i' flag
Add check that vendor directory is installed and if not we should run
glide install, also if additional flag '-i' is specified than we will
reinstall dependencies.
2017-03-14 21:22:44 -07:00
Olaoluwa Osuntokun
e4e63eb3a3
test: remove many sleeps from integration test by using new topology ntfns
This commit removes a number of sleeps from the set of current
integration tests by replacing them with a synchronous (w/ a timeout)
block until one or many channels are detected as being open within the
network.

As a result, the tests are now more robust, many flakes have been
eliminated, and finally this shaves a few second off of the integration
testing runs.
2017-03-14 20:08:02 -07:00
Olaoluwa Osuntokun
8ed79ae497
routing: fix bug when sending topology ntfns to multiple clients
This commit fixes a bug which was originally introduced when the
topology notifications were added to the channel router. The issue was
that a pointer to the loop-scope range variable was being passed into
the goroutine which dispatches the notification rather than the value
itself. It seems that the memory location is re-used between range
iterations causing the same client to receive _all_ the notifications.

This bug is fixed by passing a copy of the client struct rather than a
pointer to the range variable.

In the process, we also add some additional debug logging messages, and
remove the Curve parameter from any public keys involved in a
notification so the pretty print properly.
2017-03-14 20:07:55 -07:00
Olaoluwa Osuntokun
a179a3adbb
test: modify new network announcement hook to be in node level
This commit modifies the two newly added network announcement hook stop
be at the lightningNode level rather than on the level of the entire
test framework. With this, callers are now able to better utilize the
newly added RPC’s since they can target particular peers and wait for
network messages to be processed rather then depending on a single node
(Alice) for information about the announcements propagated within the
network.
2017-03-14 20:07:52 -07:00
Olaoluwa Osuntokun
5623df6d7e
test: add integration tests for graph topology notifications 2017-03-14 20:07:49 -07:00
Olaoluwa Osuntokun
19f33d4faf
test: add ability to register for LN channel notification to framework
This commit adds the ability for test authors using the integration
testing framework to hook into real-time notifications for
network-level announcements concerning channel openings, closings, and
updates. With this commit we should be able to eliminate a number of
the sleeps within the test framework with synchronous calls (time outs)
to the new methods added in this PR.
2017-03-14 20:07:46 -07:00
Olaoluwa Osuntokun
24a69c1164
rpc: implement new streaming SubscribeChannelGraph RPC call
This commit implements the new server-side streaming RPC call within
the current default implementation of the RPC server. With this, the
new functionality can now be used within the integration tests to
achieve a greater degree of synchronization in the tests. As a result,
we should be able to eliminate many of the sleeps lingering within the
tests.
2017-03-14 20:07:43 -07:00
Olaoluwa Osuntokun
94fa55cca3
lnrpc: add new SubscribeChannelGraph RPC call
This commit adds a new streaming RPC call the exposes the newly added
routing layer TopologyChange notifications within the gRPC service.
2017-03-14 20:07:39 -07:00
Olaoluwa Osuntokun
f6ab1390ed
routing: include the channel point of chan within edge update ntfn
This commit modifies the `ChannelEdgeUpdate` struct to include the
channel point itself within the notifications. Such a change improves
the notificaiton experience for callers as it allows them to filter out
update notifications based on a familiar object within the codebase: a
channel point.
2017-03-14 20:07:33 -07:00
Andrey Samokhvalov
61991a1c89 lnd: fix latest goclean.sh lint warning 2017-03-13 16:30:23 -07:00