Commit Graph

320 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
a18d9b8449
lnwallet+routing: modify BlockChainIO.GetUtxo to be light client friendly
This commit modifies the GetUtxo method of the BlockChainIO interface
to be more light client friendly by introducing a height hint which
gives light clients that don’t have UTXO set commitments a way in which
they can restrict their search space. Light clients will now be able to
have a concrete cut off point in the chain as they scan backwards for
spentness of an output.
2017-05-11 15:20:29 -07:00
Olaoluwa Osuntokun
521c76d65a
lnwallet: add distinct channel to send close details over
This commit modifies the actions of the closeObserver goroutine to
utilize a _new_ channel to send channel close details over. The
original close signal channel is still used to notify observers that a
channel _has_ been closed, but this new channel will provide a single
observer with details w.r.t _how_ a channel was closed.
2017-05-04 17:39:24 -07:00
Olaoluwa Osuntokun
5e48cf1273
lnwallet: upon force close detection populate close summary 2017-05-04 17:39:22 -07:00
Olaoluwa Osuntokun
be583306ab
lnwallet: include the origin chanPoint in the ForceCloseSummary
This commit adds an additional field to the ForceCloseSummary that
allows observers of the channel that sends this struct to track _which_
channel the force close came from.
2017-05-04 17:39:20 -07:00
Olaoluwa Osuntokun
77ae9f560e
lnwallet: update DeleteState method to latest DB API change 2017-05-04 17:39:17 -07:00
bryanvu
0779ce59fe lnwallet: fix error propagation for funding messages
Previously, if an error was returned during handleSingleFunderSigs or
handleFundingCounterPartySigs, the wallet would hang waiting for
the completeChan channel to be populated. This commit adds nil returns for
the completeChan when errors are propagated.
2017-04-26 21:40:38 -07:00
Olaoluwa Osuntokun
c41d673c7b
lnwallet/btcwallet: update WalletController imp to latest btcwallet API 2017-04-23 19:19:22 -07:00
Olaoluwa Osuntokun
844cdba513
lnwallet/btcwallet: unlock wallet during startup, not creation
This commit modifies the way we go about unlocking the wallet. With the
latest changes to the API of btcwallet, we can on longer directly
access the waddrmgr struct. As a result, we’re now forced to go
_directly_ via the wallet to unlock the waddrmgr. The root
LightingWallet has been modified to not request the root key until we
finish starting the underlying wallet, so we can unlock the wallet in
the Start() method.
2017-04-23 19:17:59 -07:00
Olaoluwa Osuntokun
85b306bb48
lnwallet: fetch the root key during startup rather than on creation
This commit modifies the initialization logic of the LightningWallet to
fetch the root key during startup rather than during creation. We make
this change in order to give enough time for the underlying
WalletController to properly boot up before we ask it to do any work.
2017-04-23 19:15:30 -07:00
Olaoluwa Osuntokun
c4ea5e1e2c
lnwallet: save netParams within struct in constructor 2017-04-23 19:12:19 -07:00
Olaoluwa Osuntokun
c06894a2e6
lnwire: replace ChannelPoint with ChannelID, use new PendingChanID 2017-04-16 15:22:27 -07:00
Olaoluwa Osuntokun
4e988b228e
lnwallet/btcwallet: remove FundingSigner, implement MessageSigner
This commit removes the now deprecated FundingSigner struct as part of
the btcwallet package, and instead replaces it within an implementation
of the MessageSigner interface.
2017-04-14 11:08:24 -07:00
Olaoluwa Osuntokun
98c58ddb67
lnwallet: remove old deprecated MessageSigner struct 2017-04-14 11:00:06 -07:00
Olaoluwa Osuntokun
b226edf96e
lnwallet: introduce the MessageSigner interface
This commit introduces the MessageSigner interface which is an abstract
object capable of signing arbitrary messages with a target public key.
This interface will be used within the daemon for: signing channel
authentication proofs, signing node/channel announcements, and also to
possibly sign arbitrary messages in the future.
2017-04-14 10:59:19 -07:00
Olaoluwa Osuntokun
17d6835861
lnwallet: removed unused sync.RWMutex in PaymentDescriptor 2017-04-11 22:08:25 -07:00
Olaoluwa Osuntokun
31acace692
lnwallet: convert PendingUpdates to FullySynced
This commit improves the channel state machine by converting the
objective PendingUpdates method to a subjective FullySynced method
which is to be used in place of PendingUpdates. The new FullySynced
method is fully encompassing and replaces any upper state required by
the state machine which wraps this one.

The new FullySynced method is identical to PendingUpdates aside from
the fact that: it now also factors in the log message index of the
remote commitment chain, and also introduces a concept of an “owed
commitment”. A commitment chain owes a commitment if the height of the
local commitment chain is higher than that of the remote chain.
2017-04-11 22:02:33 -07:00
Olaoluwa Osuntokun
4cd277c8da
lnwallet: eliminate usage of LightningChannel.theirPrevPkScript
This commit removes the theirPrevPkScript field from the
LightningChannel struct all together. It’s no longer needed as the more
fundamental mutation bug has been fixed within the channel state
machine.
2017-04-11 22:02:30 -07:00
Olaoluwa Osuntokun
a3fd738491
lnwallet: fix HTLC mutation bug in commitment chain
This commit fixes a class of bug that can arise in the channel state
machine when a very high throughput workflow is attempted. Since the
PaymentDescriptor’s within a commitment pointed directly into the log,
any changes to a payment descriptor would also be reflected in all
other ones. Due to this mutation possibility, at times, the
locateOutputIndex method would fail since the HTLC’s pkScript was
modified, causing the channel to fail.

We fix this class of bug by simply ensure that once an HTLC has been
associated with a particular commitment, then it becomes immutable.
2017-04-11 22:02:26 -07:00
Olaoluwa Osuntokun
eca3a10064
lnwallet: reorder PaymentDescriptor attributes to reduce padding 2017-04-11 22:02:23 -07:00
Olaoluwa Osuntokun
0858d8a17d
lnwallet: fix constant overflow build issue on 32-bit systems
This commit fixes a build issue that appears when attempting to
cross-compile binaries to a 32-bit system from a 64-bit system. The
issue was that the defined max-state hint overflows a 32-bit integer. To
fix this issue, we now proeprly specify a type of a uint64 for the typed
constant.
2017-04-07 18:05:04 +02:00
Olaoluwa Osuntokun
a668aab478
lnwallet: couple websockets and wtxmgr logging into package logging
This commit bolsters the logging available within the lnwallet package
by include the logging from both web sockets connections, and the
wtxmgr as part of the exposed package level logging. With this, users
will gain additional avenues for obtaining debug logs from various
parts of the system.
2017-04-01 20:14:13 +02:00
Olaoluwa Osuntokun
ca053e5273
multi: minor coding style and comment clean ups post-discovery merge
This commit implements some minor coding style, commenting and naming
clean up after the recent major discovery service was merged into the
codebase.

Highlights of the naming changes:
* fundingManager.SendToDiscovery -> SendAnnouncement
* discovery.Discovery -> discovery.AuthenticatedGossiper

The rest of the changes consist primary of grammar fixes and proper
column wrapping.
2017-04-01 20:14:05 +02:00
Andrey Samokhvalov
a23715a9c7 lnwallet: add message signer
Added the signer which will be needed in the funding manager to sign
the lnwaire announcement message before sending them to discovery
package. Also in the future the message signer will be used to sign
the users data.
2017-03-29 19:49:05 -07:00
Olaoluwa Osuntokun
6b3a258e86
multi: fix formatting issues in packge README's 2017-03-27 16:25:25 -07:00
Olaoluwa Osuntokun
d6c863e2d1
lnwallet: initialize the height of both commitment chains independently
This commit fixes a slight oversight in the current state machine which
assumes that both commitment chains are always at the same height. In a
future where we move back to allowing nodes to pipeline commitment
updates, this will not always be the case.
2017-03-24 16:26:03 -07:00
Olaoluwa Osuntokun
a8671c485f
lnwallet: properly observe dust limits during cooperative chan closure
This commit fixes a lingering TODO within the wallet portion of the
codebase by properly adhering to the set dust limits when closing a
channel. With this new commit if a party’s current settled balance is
below their current dust-limit, then it will be omitted from the
commitment transaction.

The prior test that asserted negative outputs are rejected has been
removed as they’ll now be avoided by ensuring we omit dust outputs from
the commitment transaction.
2017-03-24 16:20:12 -07:00
Olaoluwa Osuntokun
2dd1c0de3d
lnwallet: adhere to project code-style in restoreStateLogs
This commit does some minor shuffling around and also adds some
additional comments to the restoreStateLogs method within the channel
state machine. After the latest merge in this area, the code has
diverged slightly from what’s considered typical within the rest of the
codebase.
2017-03-24 16:15:19 -07:00
Olaoluwa Osuntokun
c241892104
lnwallet: use full struct initialization for outputs in CreateCommitmentTx 2017-03-24 16:13:36 -07:00
Christopher Jämthagen
d958ea005f lnwallet: check for correct value in HTLC outputs in commitment transaction
It is possible that that there are multiple HTLCs with different values,
but the same public key script. As such, a check against the value should
be performed when looking for HTLC outputs in a commitment transaction.
2017-03-21 21:21:46 -07:00
Christopher Jämthagen
17d29ba62e lnwallet: properly restore public key scripts for HTLCs
Create a new helper method called genHtlcScript which will
generate the public key scripts for a supplied HTLC. This functionality
from addHTLC is removed, and addHTLC will instead call this new
method.

In restoreStateLogs we will regenerate the public key scripts for the
HTLCs with genHtlcScript and restore the proper values.
2017-03-21 21:21:46 -07:00
Christopher Jämthagen
e524b7ac81 test: change HTLC amount in persistent test to account for dust 2017-03-21 21:21:46 -07:00
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
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
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
ee2379775c lnd: fix golint warning which requires to add additional comments 2017-03-13 16:30:23 -07:00
Andrey Samokhvalov
7fcccff22a lnwallet: add TODO which asks to justifying strange import 2017-03-13 16:30:23 -07:00
Andrey Samokhvalov
fd97a4bd19 lnd: partially fix golint warnings 2017-03-13 16:30:23 -07:00
Andrey Samokhvalov
f2843dd4c9 lnd: fix gofmt warnings 2017-03-13 16:30:23 -07:00
Andrey Samokhvalov
8fb54782e2 lnd: fix gosimple warnings 2017-03-13 16:30:23 -07:00
Christopher Jämthagen
242c656fd6 lnwallet: use DefaultDustLimit() instead of hard-coded values 2017-03-09 15:32:31 -08:00
Christopher Jämthagen
810d8c286e test: add TestForceClose for lnwallet package 2017-03-09 15:32:31 -08:00
Christopher Jämthagen
a6a503bf28 lnwallet: ForceCloseSummary should check if to-local output exists
If the value of the to-local output is below the dust limit, the
ForceCloseSummary should not include a sign descriptor for this output.

We also find the proper to-self output by looking for the expected public
key script and not assume that no HTLC outputs exist.
2017-03-09 15:32:31 -08:00
Christopher Jämthagen
52b56b8cf2 lnwallet+test: no dust outputs in commitment transaction + tests
Currently non-HTLC outputs will be accepted in the commitment
transaction as long as it is non-zero. We change this by not allowing
outputs with a value lower than the dust limit. The value of such
an output will go towards transaction fees.
2017-03-09 15:32:31 -08:00
Olaoluwa Osuntokun
fc54c5d8d8
lnwallet: perform sanity check on cooperative closure transacitons
This commit fixes a class of bug that currently exists within the
cooperative closure methods for the channel state machine. As an
example, due to the current hard coded fees, if one of the outputs
generated within the generated closure transaction has a negative
output, then the initiating node would gladly forward this to the
remote node. The remote node would then reject the closure as the
transaction is invalid. However, the act of completing the closure
would cause the remote node’s state machine to shift into a “closed”
state. As a result, any further closure attempts by the first node
(force or regular) would go unnoticed by the remote node.

We fix this issue by ensuring the transaction is “sane” before
initiating of completing a cooperative channel closure.

At test case has been added exercising the particular erroneous case
reported by “moli” on IRC.
2017-02-27 21:00:25 -06:00
Olaoluwa Osuntokun
8283ff2da6
lnwallet: during cooperative closure don't shift status until end
This commit avoids a class of bug wherein the state of the channel
would be marked as closing enough though an error occurred somewhere in
the function. The bug was due to the fact that the channel `status` was
shifted before any actual logic within the function(s) were executed.

We fix this bug by _only_ shifting the channel status once the function
has completed without any error.
2017-02-27 20:52:30 -06:00