Commit Graph

11311 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
5330513c7b
lnwire: morph HTLCSettleRequest into UpdateFufillHTLC
This commit modifies the prior HTLCSettleRequest to more closely match
the UpdateFufillHTLC defined within the specification. The only
semantic change is the move from a slice of pre-images (for “multi-sig”
LN) to a single payment preimage.
2017-02-21 01:42:32 -08:00
Olaoluwa Osuntokun
f1357e96b3
lnwire: morph CancelHTLC into UpdateFailHTLC, remove HTLCAddReject
This commit morphs the prior CancelHTLC into the new UpdateFailHTLC
message and also gets rid of the obsolete HLTCAddReject message while
we’re at it.

The primary change from the CancelHTLC message to the UpdateFailHTLC
message is that the CancelReason is now simply called Reason and that
it’s now an opaque encrypted set of bytes. With this update the failure
messages are now more flexible (they can even carry new
ChannelUpdate’s) and also don’t reveal the exact cause of failure to
intermediate nodes.
2017-02-21 01:42:29 -08:00
Olaoluwa Osuntokun
ec02060c9f
lnwire: rename HTLCAddRequest to UpdateAddHTLC 2017-02-21 01:42:26 -08:00
Olaoluwa Osuntokun
8a63c83283
lnwire: morph CommitSignature into CommitSig
This commit renames and modifies the CommitSignature message to more
closely match the CommitSig message defined within the current set of
draft specifications.

The major change within the new message is that we now longer
explicitly specify the update log index of the remote node that this
signature covers. This is due to the fact the revocation message now
also double as acknowledgements of the remote parties recevied
commitment update messages.
2017-02-21 01:42:23 -08:00
Olaoluwa Osuntokun
9a61bb3ae1
lnwire: rename CommitRevocation to RevokeAndAck
This commit renames the prior CommitRevocation message to RevokeAndAck
in order to better align the set of wire messages implemented by the
`lnwire` message with those currently defined within the specification.
2017-02-21 01:42:09 -08:00
Olaoluwa Osuntokun
0bbb072ceb
server: ensure we don't auto-connect to peers we're unable to create/start
This commit prevent unnecessary connection flapping by ensure we don’t
attempt to auto-connect to a peer that we’re unable to create or start
the goroutines of. With this commit, we won’t attempt to auto-connect
to a peer that has incompatible feature sets to that of ours.
2017-02-21 01:35:26 -08:00
Andrey Samokhvalov
ae15a193e2 lnwire+features: transition to the user friendly list of features 2017-02-21 01:25:05 -08:00
Olaoluwa Osuntokun
4d7ca825d4
build: update travis to build against Go 1.8 and 1.7.5
Sticking with our tradition of tracking the two latest go releases,
we'll now build against Go 1.8 (which was recently released and Go
1.7.5).

The release of Go 1.8 is very attractive to the project as it includes
performance and GC improvements as well as the addition of more
profiling and race condition detection capabilities within the runtime.
2017-02-17 13:37:09 +08:00
Andrey Samokhvalov
6ce9ea29da server+peer: add 'init' message support
In this commit the support for global and local feature vectors were
added in 'server' and 'peer' structures respectively. Also with commit
additional logic was added and now node waits to receive 'init'
lnwire.Message before sending/responding on any other messages.
2017-02-17 13:27:29 +08:00
Andrey Samokhvalov
bff55cb705 features: add global/local feature maps
In this commit the feature maps were added which which binds the name
of the global feature with it index in feature vector. The index is
just an order of the feature and the final binary representation of
feature vector is determined by decode function. This maps helps to
operate with feature by their names rather than their indexes.
2017-02-17 13:27:29 +08:00
Andrey Samokhvalov
3dd619fb35 lnwire: Add BOLT#1 'init' message
'init' message is the first message reveals the features supported or required
by this node. Nodes wait for receipt of the other's features to simplify error
diagnosis where features are incompatible. This message will help negotioate the
the features which are supported by both sides.
2017-02-17 13:27:29 +08:00
Olaoluwa Osuntokun
5560f032f6
rpc+routing: fix panic when channel edge but no edge info in db 2017-02-16 19:35:32 +08:00
Olaoluwa Osuntokun
384fe61e73
multi: fix go vet warnings throughout code base 2017-02-16 19:33:19 +08:00
Alex Akselrod
55e693aa09 zpay32: fix decoding when payment request is too short
This commit fixes a panic that can result when a zpay32 payment request
that is too short (and possibly invalid) is attempted to be decoded.

To fix this bug, we now simply ensure that that after we decode the
zbase32 encoding, the resulting set of bytes is _exactly_ the length we
expect. A new error has been introduced to handle this case, and a
simple test has been added which ensures proper handling of short
payment requests.

Fixes #127.
2017-02-16 19:30:28 +08:00
Christopher Jämthagen
a2403d9c07 lnwallet: optimize PaymentDescriptor lookup on HTLC state transitions
rHashMap is used to store the PaymentDescriptor belonging to a received
HTLC's revocation hash. This improves the efficiency of looking up
PaymentDescriptors from their RHash whenever we want to settle or cancel
that HTLC.
2017-02-08 18:22:01 -08:00
Olaoluwa Osuntokun
59615b3cb2
channedb: add db migration for databases before delivery script bug fix 2017-02-08 13:05:45 -08:00
Olaoluwa Osuntokun
a34df2f7d8
test: modify force close integration test to assert bob gets his balance
This commit adds a new assertion in the channel force closure test in
order to exercise the fix for a bug related to channel force closure
implemented in a prior commit. With this new assertion, we ensure that
bob is aware of his on-chain balance after a force channel closure
initiated by alice.
2017-02-07 20:54:11 -08:00
Olaoluwa Osuntokun
1da054625b
lnwallet/btcwallet: fix bug in non-recognition of self-funds in chan force close
This commit fixes a bug which would cause the node on the _receiving_
side of a channel force close to be blind of their immediately funds
on-chain. The root of the issue was that within the btcwallet
implementation of the WalletController method ‘NewRawKey’, the wallet
wouldn’t request notifications for the new address, as the direct
function from the waddrmgr was used which skips registration of the new
address.

To fix, this, we now ensure that btcwallet will receive notifications
for keys used within the raw p2wkh commitment output. This ensures that
the wallet is aware of funds that are made available as a result of a
channel force closure by the channel counter party.
2017-02-07 20:01:19 -08:00
Olaoluwa Osuntokun
a9078562ac
lnwallet/btcwallet: fix bug in ordering of change vs regular addresses 2017-02-07 19:55:54 -08:00
Olaoluwa Osuntokun
e8e53a4b91
channeldb: fix channel corruption bug upon channel closure
This commit fixes a bug which would previously lead to corruption of
the channel state when a node had one or more channels open and one of
them was closed either forcibly or cooperatively. The source of the bug
itself as a typo: rather than using the construed `deliveryKey`
variable to fetch/put/delete the delivery scripts, `deliveryScriptsKey`
(the key prefix itself) as used. This bug would cause the database to
be unable to read _any_ channel from the database after one was
deleted, as each channel would actually be reading/writing-to the
_exact same_ delivery script.

The fix for the bug itself is simple: eliminate the typo.
2017-02-07 19:54:51 -08:00
Olaoluwa Osuntokun
926f5c84d0
cmd/lncli: always consume first message for openchannel/closechannel
This commit modifies the behavior for the commands which open and close
channels on the command line. Previsouly a user needed to use the
`—block` flag in order to get information about any possible errors or
the full progress of a request. This commit alters the behavior
slightly to block until the _first_ message or error is returned from
the gRPC stream.

With this change, the command line usage has a better UX as users
instantly get more information without having to peer into the logs.
2017-02-07 19:36:24 -08:00
Olaoluwa Osuntokun
a094681dae
routing: only log pre-mature announcements if we have any 2017-02-07 18:38:48 -08:00
Olaoluwa Osuntokun
7f98e8e5f1
channeldb: fix warnings found by go vet 2017-02-07 16:52:04 -08:00
Olaoluwa Osuntokun
906c0451c8
peer: check for existence of channel when handling a remote close
This commit patches a bug in the code for handling a remote cooperative
channel closer. Previous if the region node didn’t know of the channel
which was being requested to close, then a panic would occur as the
entry read from the map would be nil.

To fix this bug, we now ensure that the channel exists before we
perform any actions on it. In a later commit which overhauls the
channel opening and closing to match that of the specification, this
logic will be modified to properly send an error message in response to
the failed channel closure.
2017-02-07 16:49:04 -08:00
Olaoluwa Osuntokun
5889331422
channeldb: improve error messages when unable to read channel 2017-02-07 16:41:20 -08:00
Olaoluwa Osuntokun
d87e795e2a
channeldb: ensure all state is deleted for a channel by CloseChannel
This commit addresses some lingering TODO’s which ensure that related
state to a channel is properly deleted by the CloseChannel method.
Previously the values for the respective dust-limits of either side,
the on-disk HTLC’s, and any entries the revocation log for the channel
weren’t being properly deleted.

Additionally, we now modify the checks within the unit tests to ensure
that we can still read the channel from disk w/o running into an error
(thought the slice will be blank), and also the the revocation log is
properly garbage collected.
2017-02-07 16:40:46 -08:00
Olaoluwa Osuntokun
8c059631df
peer+server: ensure the remote TCP connection is always closed 2017-02-06 15:05:07 -08:00
Olaoluwa Osuntokun
38d8d37395
server: asynchronously synchronize graph state with peers on connect
This commit modifies the existing syncing logic to launch a new
goroutine on connect to synchronize graph state with the new peer
rather than the prior blocking version. This change should make the
initial sync a little snappier and also possible eliminate a circular
dependency between the ChannelRouter and the server.
2017-02-06 14:58:45 -08:00
Olaoluwa Osuntokun
bf78122dc7
routing: ensure advertised transaction index is within bounds
This commit fixes bug that could result in the panicking or crashing of
nodes in the case of an at-funding-time reorganization within the
network. In order to avoid such a case, we now ensure that the
advertised transaction index is within the bounds of the block before
attempting to access it.

Note that this is a temporary patch commit until full advertisement
validation which is implemented in the discovery PR lands in master.
Additionally, better reorg handling during the funding process is being
specified within the spec and will properly be implemented within lnd
at a later date.
2017-02-06 14:54:57 -08:00
Olaoluwa Osuntokun
71bb430836
rpc: don't return an error if no payments exist for ListPayments 2017-02-04 16:54:27 -08:00
Olaoluwa Osuntokun
a393362eb8
lnwallet: ensure CSV delay witness spend uses a minimal OP_IF
This commit fixes a slight scripting related issue as a result of
default policy in Bitcoin Core 0.13.1. With this version of Bitcoin
Core, nodes will now enforce a policy that ensures the first argument
of OP_IF is either an empty vector or a 0x01 value. Our current sent of
functions to generate the witness for the delay clause of the
commitment transaction instead uses a 0x00 value rather than an empty
byte vector.

With this commit we fix the issue by ensuring that we use an empty
vector rather an 0x00 for forcing the commitment delay script pathway.
2017-02-03 15:28:19 -08:00
Olaoluwa Osuntokun
9cef2f8657
routing: add support for detection+processing of premature announcements
This commit fixes a prior block propagation race-condition by detecting
and properly processing “premature” announcements. A premature
announcement is one that’s received with an anchored block height which
is beyond our chain tip. Once received, we now store these
announcements in a special map that’s caches them in memory. Once a new
block arrives, we check the map for the existence of any entries,
processing them as normal if so.
2017-02-02 17:44:25 -08:00
Olaoluwa Osuntokun
2c0d5e0f0d
breacharbiter: stop the stale contract when a live contract appears
This commit modifies the logic of the contract hand-off within the
breachArbiter to ensure that only a single internal closeObserver
goroutine is ever active for a given contract.

This modification cleans up the logs in the case of multiple
reconnections and may possible eliminate some non-deterministic bugs
related to channel force closures.
2017-02-02 17:28:15 -08:00
Olaoluwa Osuntokun
62bcd59db4
lnwallet: add ability to cancel the channel's closeObserver
This commit adds the ability to cancel a channel’s internal
closeObserver goroutine by adding a new public facing Stop method.

Additionally, we now make passing a ChainNotifier interface completely
optional. If the ChainNotifier isn’t passed in as a constructor, then
the closeObserver goroutine will never be launched. This new feature
lets the caller ensure that only a single closeObsever for any given
channels exists.
2017-02-02 17:11:03 -08:00
Olaoluwa Osuntokun
f4b403679b
lnwallet: remove BlockChainIO as a dependency to LightningChannel
This commit removes the BlockChainIO interface as a dependency to the
LightningChannel struct as the interface is no longer used within the
operation of the LightningChannel.
2017-02-02 17:05:40 -08:00
Olaoluwa Osuntokun
aeb7cce7c3
channeldb: move serialization of outpoint into db txn in CloseChannel 2017-02-02 16:59:22 -08:00
Olaoluwa Osuntokun
c1c1cabc4e
server: immediately return to caller when processing sendToPeer
This commit alters the logic of processing sendToPeer requests within
the server to immediately return to the caller after locating the
target peer.
2017-02-02 16:57:25 -08:00
Olaoluwa Osuntokun
3f6afa51b9
rpcserver: fix potential panic when opening channel to peer_id
This commit fixes a potential panic that could arise when one was
attempting to open a channel with the target peer identified by it’s
peerID and an error occurred. In this case, the nodepubKey pointer
would be nil, resulting in a panic when attempting to propagate the
error.

This commit fixes this bug by using a nil byte slice for the node’s
serialized pubkey in the case that the node was identified according to
ti’s peer ID.
2017-02-02 16:50:29 -08:00
Christopher Jämthagen
24a569b047 routing: add proper test for excessive number of hops 2017-02-02 00:24:16 -08:00
Christopher Jämthagen
4200d8a7e0 routing: check route length after edges for route is collected
This fixes the bug reproduced in #114. The prevHop map in newRoute may
include many more edges than what is used to produce the final route, and
thus the check prior to building the route could result with incorrect
errors being reported. We move this check to after the number of edges
to be used for the route is deduced.
2017-02-02 00:24:16 -08:00
Olaoluwa Osuntokun
08f0d0fbea
routing+rpcserver: move route querying+sending to SendPayment
This commit moves much of the logic for querying for a potential route,
constructing the HTLC including the Sphinx packet, and sending the
ultimate payment from the rpcServer to the ChannelRouter.

This movement paves the way for muilt-path path finding as well as
adding automatic retry logic to the ChannelRouter. Additionally, by
having the ChannelRouter construct the Sphinx packet, we’ll be able to
also include the proper time-lock and general per-hop-payload
information properly in the future.
2017-02-01 18:29:55 -08:00
Olaoluwa Osuntokun
4eebc7c994
peer: refactor the queueHandler to aggressively drain queue
This commit refactors the queueHandler slightly to be more aggressive
when attempting to drain the pending message queue.

With this new logic the queueHandler will now attempt to _completely_
drain the pendingMsgs queue by sending it all to the writeHandler
_before_ attempting to accept new messages from the outside
sub-systems. The previous queueHandler was a bit more passive and would
result in messages sitting the the pendingMessage queue longer than
required.
2017-02-01 17:02:03 -08:00
Olaoluwa Osuntokun
8731fadb46
utxonursery: log txid when sending sweep transaction 2017-02-01 16:53:14 -08:00
Olaoluwa Osuntokun
6333dfea8f
peer: fix memory alignment for integers used atomically on 32-bit archs
This commit fixes a panic that can occur on 32-bit systems to the
misalignment of a int64/uint64 that’s used atomically using the atomic
package. To fix this issue, we now move all int64/unit64 variables that
are used atomically to the top of the struct in order to ensure
alignment.

Cleaning up some dead-code, satoshisSent/satoshisReceived have been
removed as they aren’t currently used. Instead those values are
accessed directly from the channel themselves.
2017-01-30 00:53:17 -08:00
Andreas M. Antonopoulos
1bc011ae5a contrib: add basic bash completion for lncli 2017-01-29 18:12:53 -08:00
Cris Perez
b0d1247531 Add chmod +x to start scripts in dockerfiles 2017-01-29 18:02:26 -08:00
juscamarena
68c40b05ff cmd/lncli: Update command usage info to match current commands 2017-01-29 18:00:42 -08:00
Olaoluwa Osuntokun
28aa092ac2
test: eliminate sleep by tightly polling for existence of node
This commit elminates a sleep in the testHtlcErrorPropagation test by
instead polling for the existence of our target in a tight loop. This
is a small patch over until we get a “topology client” within the
ChannelRouter. This method is robust and can be applied in future tests
until we get the notification client into the ChannelRouter.
2017-01-29 17:16:58 -08:00
Olaoluwa Osuntokun
51e38d7544
server: fix goroutine closure bug when broadcasting messages to peers
This commit fixes a goroutine closure bug introduced by a prior commit.
A prior commit launched a goroutine for each peer to broadcast the
messages in parallel. However, as written this caused the messages to
only be broadcast to a single peer. When launching goroutines in a
for-loop, the “range” variable is actually re-used and re-assigned
within each iteration of the for-loop. As a result, all goroutines
launched will bind onto the _same_ instance of the variable.

We fix this bug in this commit by properly binding the target peer to a
new variable within the closure that launches the goroutine.

Relevant sources:
  *
https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loo
p-iterator-variables
  * https://golang.org/doc/faq#closures_and_goroutines
2017-01-29 17:15:25 -08:00
Olaoluwa Osuntokun
f18a21fc54
test: correct error message for htlc error propagation test 2017-01-29 17:08:02 -08:00