Commit Graph

549 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
67aa519480
lnwallet: reverse order of signatures when spending the funding output
This commit is a follow up to the prior commit, as since we reversed
the order of the pubkeys in the multi-sig scripts, then we also need to
reverse the order of the signatures that we use when attempting to
spend the funding output directly.
2017-09-12 17:54:21 +02:00
Olaoluwa Osuntokun
eb2c8ba653
lnwallet: reverse the order of the pubkeys in the funding output
When creating the script for the funding output, we were reversing the
order of the public keys due to an incorrect assertion of the return
value of the bytes.Compare function. To fix this, we now flip the
order, allowing us to properly create channels as specified within the
specification.
2017-09-12 17:49:37 +02:00
Olaoluwa Osuntokun
5359476936
lnwallet: add new methods to ChannelReservation for dealing w/ chan constraints
This commit adds to methods to the ChannelReservation struct: one for
generating the channel constraints we require for the remote party, and
one for validating their desired constraints, and committing them to
our ChannelConfig.

With these two new methods, we can now begin to properly store and
adhere to the current set of channel flow control constraints.
2017-09-12 17:41:55 +02:00
Olaoluwa Osuntokun
5bb3efba4c
lnwallet: properly use the lsat 6-bytes of the sha hash for state hints
This commit fixes an existing w.r.t the way that we constructed all
commitment transactions. We were computing the hash that the obfsucator
was derived form correctly, but we were using the first 6-bytes, rather
than the last 6 bytes.
2017-09-12 17:38:31 +02:00
Olaoluwa Osuntokun
73421caecc
lnwallet: don't attach the rpcclient to the lnwallet logging instance
We no longer attach the RPC client to the lnwallet logging instance as
it can generate a ton of spam in trace mode as it’ll dump the entire
hex encoded blocks, transactions, etc.
2017-08-30 20:32:37 -07:00
Olaoluwa Osuntokun
a52d405998
lnwallet: ensure HTLC values are properly converted to SAT in commit tx
This commit fixes a bug within the HTLC construction and commitment
transaction construction that would result in HTLC _values_ within the
commitment transaction being off by a factor of 1000. This was due to
the fact that we failed to convert the amount of an HTLC, in mSAT, to
SAT before placing it as an output within the commitment transaction.
When attempt to locate the output index of a particular half, we use
the unconverted amount, meaning it was unnoticed.

This commit adds a new assertion within the TestSimpleAddSettleWorkflow
test to ensure that the HTLC is found within the commitment transaction
with the proper value in satoshi.
2017-08-30 15:34:18 -07:00
Conner Fromknecht
438c6b9621 lnwallet: move latest SignDescriptor + serialization 2017-08-25 17:56:50 -07:00
Philip Hayes
ce411f8e22 lint: fix linter complaints 2017-08-25 17:56:50 -07:00
Philip Hayes
d8c56433e3 lnwallet: extract SignDescriptor serialization and witness generator 2017-08-25 17:56:50 -07:00
Olaoluwa Osuntokun
7f575b688e
multi: txscript.WitnessScript -> txscript.WitnessSignature 2017-08-24 18:55:32 -07:00
Olaoluwa Osuntokun
9f0efddc20
multi: switch from btcrpcclient to rpcclient 2017-08-24 18:54:24 -07:00
Olaoluwa Osuntokun
ad00266451
lnwallet: update channel reservation flow to use milli-satoshis 2017-08-22 00:52:53 -07:00
Olaoluwa Osuntokun
6e54aba7ac
lnwallet: convert channel state machine accounting to milli-satoshi 2017-08-22 00:52:50 -07:00
Olaoluwa Osuntokun
063525c6e0
channeldb: update the OutgoingPayment struct to use lnwire.MilliSatoshi 2017-08-22 00:52:12 -07:00
Olaoluwa Osuntokun
6e17c34229
lnwallet: update commitScriptToSelf to match BOLT-0003
This commit updates the script we use to match the current
specification. The change is minor: we can say an extra byte by moving
the OP_CHECKSIG to the end of the script, and swapping the checks and
seqverify operations in the second clause. However, the witness remains
the same!
2017-08-22 00:52:09 -07:00
Olaoluwa Osuntokun
f458dc26ed
lnwallet: correct godoc comments on script util helper functions
The godoc comments for htlcSpendRevoke and htlcSpendSuccess were
incorrect.
2017-08-15 17:53:45 -07:00
Johan T. Halseth
b9516b7cdd
lnwallet: make CreateCloseProposal take absolute fee instead of fee rate 2017-08-11 12:09:39 +02:00
Olaoluwa Osuntokun
43b736225b
multi: add new method to generate fresh node announcments 2017-08-04 18:32:33 -07:00
Olaoluwa Osuntokun
812ebe6fe6
lnwallet: type htlcWeight and commitWeight as int64's 2017-07-31 21:02:30 -07:00
Olaoluwa Osuntokun
5240953de0
lnwallet: temporarily ensure TestStateUpdatePersistence doesn't make dust
Note that this commit is temporary, and should be reverted once #231 is
merged. The reason we need to do this for now, is that we don’t
properly track the exact state of the remote party’s commitment. In
this test case, the resulting HTLC’s added are dust to one party, but
non-dust to another. So upon restart, the states (balance wise) has
diverged.
2017-07-31 20:53:08 -07:00
Olaoluwa Osuntokun
8c6a83a67d
lnwallet: account for second-level HTLC fee in TestChannelBalanceDustLimit 2017-07-31 20:50:54 -07:00
Olaoluwa Osuntokun
4aacf2b51d
lnwallet: ensure TestHTLCDustLimit also asserts for bob's commit chain 2017-07-31 20:50:12 -07:00
Olaoluwa Osuntokun
350e6d5c9f
lnwallet: extend TestDustHTLCFees to ensure dust HTLC's go to miners 2017-07-31 20:49:13 -07:00
Olaoluwa Osuntokun
00ca97c789
lnwallet: in TestForceClose properly assign Bob's balance 2017-07-31 20:44:22 -07:00
Olaoluwa Osuntokun
1b61341410
lnwallet: when creating channels in tests, properly account for commitment fee 2017-07-31 20:43:38 -07:00
Olaoluwa Osuntokun
db793991ac
lnwallet: don't add trimmed HTLC value to initiator commitment fees
This commit fixes a lingering bug in the way the internal channel state
machine handled fee calculation. Previously, we would count the dust
HTLC’s that were trimmed towards the fee that the initiator paid. This
is invalid as otherwise, the initiator would always benefit from dust
HTLC’s. Instead, we now simply “donate” the dust HTLC’s to the miner in
the commitment transaction. This change puts us in compliance with
BOLT-0003.
2017-07-31 20:41:23 -07:00
Olaoluwa Osuntokun
5ece7fec2d
lnwallet: add a String() method to updateType 2017-07-31 20:37:51 -07:00
Olaoluwa Osuntokun
d4a5eaa6ad
lnwallet: modify CommitSpendNoDelay to directly craft witness
This commit modifies the CommitSpendNoDelay script witness generation
function. We must modify this function as all non-delayed outputs now
also require a key derivation. The current default
signer.ComputeInputScript implementation is unable to directly look up
the public key required as it attempt to target the pub key using the
pkScript.
2017-07-30 20:23:31 -07:00
Olaoluwa Osuntokun
747e0f57d1
multi: fix linter errors 2017-07-30 18:22:45 -07:00
Olaoluwa Osuntokun
07b0604458
lnwallet: add TweakPubKeyWithTweak helper function
This commit adds a new helper function which is identical to
TweakPubkey, but lets the caller specify their own hash tweak.
2017-07-30 17:52:22 -07:00
Olaoluwa Osuntokun
899fa1ea3e
lnwallet: properly populate the signDesc within UnilateralCloseSummary
This commit modifies the closeObserver code to populate the signDesc in
the case we have a non-trimmed balance. Additionally, we now also add a
*wire.OutPoint field to the struct in order to allow receivers of the
message to construct a witness that can spend the newly created output
to their wallet.
2017-07-30 17:52:18 -07:00
Olaoluwa Osuntokun
8a23de5303
lnwallet: consult current state instead of revocation log during unilateral closure 2017-07-30 17:52:14 -07:00
Olaoluwa Osuntokun
6ad9d218b0
lnwallet: update all channel unittests due to new commitment design 2017-07-30 17:51:09 -07:00
Olaoluwa Osuntokun
8121bc77ce
lnwallet: add delivery scripts as a param to CreateCloseProposal+ CompleteCooperativeClose
This commit modifies the methods that transition the state of the
channel into an active closing state. With the new commitment design,
the delivery scripts are no longer pre-committed to the initial funding
messages. Instead, the scripts are sent at the instant that either side
decides to shutdown within the Shutdown message.
2017-07-30 17:51:05 -07:00
Olaoluwa Osuntokun
40e9120c04
lnwallet: populate HTLC resolutions after observing a unilateral channel close 2017-07-30 17:51:02 -07:00
Olaoluwa Osuntokun
01aa4eb2ae
lnwallet: populate HTLC resolutions within the ForceCloseSummary 2017-07-30 17:50:59 -07:00
Olaoluwa Osuntokun
83e0116d7e
lnwallet: extend the UnilateralCloseSummary to include HTLC resolutions
This commit adds a new companion struct: OutgoingHtlcResolution to the
commitment state machine. The purpose of this struct is the provide the
caller with the information necessary to sweep all outgoing HTLC’s in
the case of a broadcast up-to-date commitment transaction.

The HTLC resolutions allow a caller to sweep an outgoing HTLC into
their wallet after the absolute timeout of the HTLc has passed. This is
a two step process, with the first portion consisting of broadcasting
the HTLC timeout transaction itself, and the second portion consisting
of claiming the HTLC itself after a CSV delay.
2017-07-30 17:50:55 -07:00
Olaoluwa Osuntokun
a4c07d061e
lnwallet: the BreachRetribution struct is now aware of HTLC outputs
This commit adds awareness of active HTLC outputs to the
BreachRetribution struct. Previously, in the case of a breach, the
struct was only populated with enough information to sweep the two
commitment outputs. With this commit, the struct now has enough
information to sweep _all_ outputs within the commitment transaction.
2017-07-30 17:50:51 -07:00
Olaoluwa Osuntokun
5a78f80ffe
lnwallet: update restoreStateLogs to be aware of new commitment scheme 2017-07-30 17:50:47 -07:00
Olaoluwa Osuntokun
b9da43a2b8
lnwallet: update fetchCommitmentView due to new commitment design
This commit updates the central fetchCommitmentView method to manage
and derive the necessary easy required to create new commitments due to
the new state machine design within the specification. Each state now
requires us to derive a number of keys for each commitment state:
localDelay, remoteDelay, localKey, remoteKey, the commitment point, and
finally the revocation key itself.
2017-07-30 17:50:43 -07:00
Olaoluwa Osuntokun
3a052d2874
lnwallet: when creating new states, dispatch HTLC signing to sigPool 2017-07-30 17:50:40 -07:00
Olaoluwa Osuntokun
f569b80a80
lnwallet: when verifying new states, dispatch HTLC sig validation to sigPool 2017-07-30 17:50:37 -07:00
Olaoluwa Osuntokun
cd8672f824
lnwallet: update CreateCommitTx due to new key derivation 2017-07-30 17:50:34 -07:00
Olaoluwa Osuntokun
e314b83559
lnwallet: update HTLC script generation to account for new covenant HTLC's
This commit updates the set of functions tasked with generating HTLC’s
scripts for new commitments to now adhere to the new commitment
transaction design. With this change, the process of claiming an HTLC
now requires a second-level HTLC transaction, which solves a prior
issues due to the tight coupling of the timeout and delay clauses when
claiming an HTLC.
2017-07-30 17:50:31 -07:00
Olaoluwa Osuntokun
8b9a58cb15
lnwallet: add a sigPool instances to the state machine struct 2017-07-30 17:50:27 -07:00
Olaoluwa Osuntokun
4c9bd9dc54
lnwallet: when handling possible channel breach, only log if contract breach 2017-07-30 17:50:24 -07:00
Olaoluwa Osuntokun
e56258917e
lnwallet: introduce populateHtlcIndexes for tracking HTLC indexes in commitments
This commit adds a new method to the commitment struct:
populateHtlcIndexes.  populateHtlcIndexes modifies the set of HTLC's
locked-into the target view to have full indexing information
populated. This information is required as we need to keep track of the
indexes of each HTLC in order to properly write the current state to
disk, and also to locate the PaymentDescriptor corresponding to HTLC
outputs in the commitment transaction.

We also modify toChannelDelta to take not of these new changes, and
access the appropriate index directly.
2017-07-30 17:50:21 -07:00
Olaoluwa Osuntokun
549688d793
lnwallet: remove isDustLocal and isDustRemote, replace w/ htlcIsDust
This commit modifies the way we account for dust HTLC’s within the
commitment state machine when creating and validating new states.
Previously, an HTLC was dust if the amount of the HTLC was below the
dustLimit of the commitment chain. Now, with the HTLC covenant
transaction, the value of the HTLC also needs to cover the required fee
of the HTLC covenant transaction at the specified fee rate of the
commitment chain.

As a result, we now determine if an HTLC is dust or not, only at the
commitment site, using the new htlcIsDust function.
2017-07-30 17:50:16 -07:00
Olaoluwa Osuntokun
91165d98bb
lnwallet: eliminate the InitialRevocationWindow within the state machine
This commit modifies the current core channel state machine in order to
may a step towards BOLT-0002 and BOLT-0003 compliance. In this change,
we abandon the prior revocation window, in favor of a fixed revocation
window of size two. The revocation window will be filled at the start
of the lifetime of the channel, and never extended from there until the
channel has been fully closed.

We now maintain two variables, the current un-revoked commitment point,
and the next commitment point to use when creating a new state. The
next commitment point must initially be inserted into the channel state
with the InitNextRevocation method.

A major difference between the prior revocation key handling is that
the remote party now instead sends us the _commitment point_ in
isolation, which we then use locally (with our revocation base point)
to create the next full revocation key for _their_ commitment
transaction.
2017-07-30 17:50:13 -07:00
Olaoluwa Osuntokun
c7df82ab68
lnwallet: update the LightningChannel API usage for recent channels changes
This commit updates much of the state interaction within the
LightningChannel structure to account for the recent changes within the
chanenldb involving the OpenChannel struct, namely the introduction of
ChannelConfig and ChannelConstraints.
2017-07-30 17:50:10 -07:00
Olaoluwa Osuntokun
b5044e9217
lnwallet: introduce the sigPool struct to optimize state creation+verification
This commit introduce a new struct which acts as a companion struct to
the channel state machine struct. With the new commitment state
machine, we require a signature to be signed and validated for each
outstanding non-trimmed HTLC within the commitment state. As it’s
possible to have hundreds of HTLC’s on a given commitment transaction,
rather than perform all ECDSA operations in serial, we instead aim to
parallelize the computation with a worker pool of sign+verify workers.

The two primary methods of the sigPool are SubmitVerifyBatch and
SubmitSignBatch which allow a caller to trigger an asynchronous job
execution when creating or validating a new commitment state.
2017-07-30 17:50:06 -07:00
Olaoluwa Osuntokun
30b1cbc1fd
lnwallet: update interface-level wallet tests for new funding flow
This commit updates the prior set of interface-level wallet tests to
exercise the new funding workflow, and also to switch to utilizing two
wallet instances throughout the tests. This allows us to abandon the
dependency on the bobNode struct.
2017-07-30 17:50:03 -07:00
Olaoluwa Osuntokun
5dc0b407f3
lnwallet: update the btcwallet Signer interface due to new key derivation 2017-07-30 17:50:00 -07:00
Olaoluwa Osuntokun
c872d94606
lnwallet: convert interface-level tests to spin up two wallet instances
This commit modifies the interface-level wallet integration tests to
spin up two distinct wallet instances, wiping them after each
successful test. This change paves the way for an upcoming change which
uses two live wallet instances, rather than mocking out most of the
other interaction.
2017-07-30 17:49:57 -07:00
Olaoluwa Osuntokun
4f02a2af80
lnwallet: remove bobNode as sadly he's no longer needed
This commit removes bobNode from the wallet’s funding interaction
tests. bobNode was originally created at a very early point in lnd’s
life time before any sort of back end chain access was hooked in. At
that time the integration tests were unable to run, but bobNode allowed
us to test a portion of the funding workflow given idealized inputs.

The tests will be modified in a later commit to eschew bobNode in favor
of just having two LightningWallet instances communicate with one
another.
2017-07-30 17:49:54 -07:00
Olaoluwa Osuntokun
eca8dd1076
lnwallet: update testSignOutputUsingTweaks to exercise new key derivation 2017-07-30 17:49:50 -07:00
Olaoluwa Osuntokun
9edc335049
lnwallet: update internal funding workflow to account for BOLT-0002
This commit updates the engine that drives the reservation workflow to
utilize the new ChannelConfig and ChannelConstraint structs added in
prior commits.  With this change, the internal reservation engine has
been modified to retain the prior dual funder workflow, but also be
able to properly manage and execute the new single funder workflow
defined in BOLT-0002.
2017-07-30 17:49:47 -07:00
Olaoluwa Osuntokun
441e5b2d7c
lnwallet: add new helper function to generate both comitment pairs 2017-07-30 17:49:44 -07:00
Olaoluwa Osuntokun
62110b33e7
lnwallet: flesh out the Config struct, wallet constructor now takes 2017-07-30 17:49:41 -07:00
Olaoluwa Osuntokun
c63c7cd22f
lnwallet: update Channel[Reservation+Contribution] for new funding flow
This commit updates the channel reservation workflow in order to
properly implement the new funding workflow defined in BOLT-0002.

The workflow itself hasn’t changed significantly, but the contents of
the contributions of both sides have. The bulk of the fields within the
contribution of both sides has been boiled down into a pointer to the
ChannelConfig which houses all the data required to handle all states
of the channel, and commitment state machine.

For the two portions which are dictated by the other party, we now add
builder-like modifiers to allow specifying the constraints after the
initial portion of the workflow.
2017-07-30 17:49:37 -07:00
Olaoluwa Osuntokun
e930af4b43
lnwallet: convert interface-level tests to be run as sub-tests 2017-07-30 17:49:34 -07:00
Olaoluwa Osuntokun
9c0261206d
lnwallet: modify the Signer interface to reflect new key derivation scheme
This commit modifies the Signer interface to reflect the new key
derivation defined within BOLT-0003. This entails removing the prior
PrivateTweak field all together in favor of two new fields: SingleTweak
and DoubleTweak.

These two fields are mutually exclusive. The SingleTweak field is now
required in order to sign all regular non-delay, and also must be used
to generate signatures for the localKey, or delayKey. The DoubleTweak
field is used to generate the private key that corresponds to the
revoked revocation key.
2017-07-30 17:49:31 -07:00
Olaoluwa Osuntokun
7b002175f4
lnwallet: update state hint derivation to match BOLT-0003 2017-07-30 17:49:28 -07:00
Olaoluwa Osuntokun
ca45ae7524
lnwallet: update TestCommitmentSpendValidation due to new commitment scripts 2017-07-30 17:49:25 -07:00
Olaoluwa Osuntokun
016f56e8e3
lnwallet: update TestRevocationKeyDerivation to use new derivation 2017-07-30 17:49:22 -07:00
Olaoluwa Osuntokun
44ffcf2156
lnwallet: add new test case to exercise singly tweaked key derivation 2017-07-30 17:49:19 -07:00
Olaoluwa Osuntokun
5b6cc5e92d
lnwallet: TestHTLCSenderSpendValidation for new HTLC scripts 2017-07-30 17:49:16 -07:00
Olaoluwa Osuntokun
7c035a4729
lnwallet: update TestHTLCSenderSpendValidation for new scripts 2017-07-30 17:49:13 -07:00
Olaoluwa Osuntokun
c4866723d1
lnwallet: add redemption+spend tests for the second-level HTLC txns 2017-07-30 17:49:09 -07:00
Olaoluwa Osuntokun
1a9ada4897
lnwallet: move stateHintTests global var into TestCommitTxStateHint 2017-07-30 17:49:06 -07:00
Olaoluwa Osuntokun
4e4375513d
lnwallet: update MaxHTLCNumber to precisely match the spec 2017-07-30 17:49:03 -07:00
Olaoluwa Osuntokun
71e47283cf
lnwallet: update size.go to add the weight of the success+timeout txns
This commit updates the constants in size.go to include the weight of
the HTLC success and timeout transactions. These values are required in
order to properly compute the fee required for a particular HTLC
transaction. The fee will change depending on if the HTLC is incoming
or outgoing.
2017-07-30 17:49:00 -07:00
Olaoluwa Osuntokun
360876944e
lnwallet: add new functions to generate + claim second-level HTLC txns
This commit adds a series of new functions that can be used to generate
the second level HTLC transactions, and also to claim the output
created by the transaction after a delay. The details of the scripts
and transaction format can be found in BOLT #3.
2017-07-30 17:48:56 -07:00
Olaoluwa Osuntokun
f70697bf71
lnwallet: update all witness gen funcs for receiver's HTLC scripts 2017-07-30 17:48:53 -07:00
Olaoluwa Osuntokun
4b1a7091e6
lnwallet: update public key scripts for the HTLC receiver's outputs
This commit updates all the pkScripts used within the commitment
transaction of the party that is on the reign side of an HTLC.

The major difference in these scripts as the prior generation’s is that
the claim action is now spared into a distinct transition. This clause
is guarded by a 2-of-2 multi-sig op code, which effecting creates an
off-chain covenant forcing the party claiming the transaction to incur
a delay before the funds can be swept.
2017-07-30 17:48:50 -07:00
Olaoluwa Osuntokun
d697c6ca9a
lnwallet: update the witness generation funcs for sender's HTLC output
This commit updates all the spendHtlcSpend* functions which are used to
spend each of the possible clauses within the HTLC contract placed on
the sender’s commitment transaction.
2017-07-30 17:48:47 -07:00
Olaoluwa Osuntokun
8f5129e08f
lnwallet: update public key scripts for the HTLC sender's commitment tx 2017-07-30 17:48:44 -07:00
Olaoluwa Osuntokun
0b9c117bbd
lnwallet: update key derivation for the commitment txn scheme
This commit updates the key derivation to match the derivation required
in order to construct and validate the commitment scheme that is used
within the draft specification of the Lightning Network. The new scheme
is very similar to the prior scheme aside from the following major
differences:
  * Each key (not just the revocation key) now changes with each state.
  * A commitment point (a component of the revocation key) is used to
randomize each key, and also generate new tweaked versions of the key.
   * Base points are used along with the commitment point to generate
the keys for the commitment transaction.
   * Before the remote party would send over the fully valid revocation
key. Now the remote party sends us a commitment point, which we then
use our local revocation base point to generate their revocation key.
2017-07-30 17:48:41 -07:00
Olaoluwa Osuntokun
13404243cf
lnwallet: revocation root generation is now based on a block hash + node key
This commit modifies the prior revocation root generation to a newer
version which is intended to allow for easy recovery of revocation
state. Rather than using the node’s keys (which we can’t count on NOT
to change), we instead now use the block hash as a salt. With this,
given the block hash prior to the one that funded the channel, and the
node’s identity key, we can reconstruct our revocation state.
2017-07-30 17:48:38 -07:00
Olaoluwa Osuntokun
14832d8c09
lnwallet+lnwire: minor grammatical fixes after UpdateFee merge 2017-07-14 17:10:42 -07:00
Johan T. Halseth
ebe05f6568 lnwallet: add update_fee message support.
This commit adds the possibility for the initiator of a
channel to send the update_fee message, as specified
in BOLT#2. After the message is sent and both parties
have committed to the updated fee, all new commitment
messages in the channel will use the specified fee.
2017-07-14 16:39:15 -07:00
bryanvu
7fbb1e5a37 lnwallet: refactor dust limit tests
Split up and simplified dust limit tests.
2017-07-06 18:05:43 -07:00
bryanvu
73767f8c78 lnwallet: factor createHTLC out of unit tests 2017-07-06 18:05:43 -07:00
bryanvu
5068541044 lnwallet: apply dust HTLC amounts to fees
If an HTLC’s value is below a node’s dust limit, the amount for that
HTLC should be applied to to the fee used for the channel’s commitment
transaction.
2017-07-06 18:05:43 -07:00
Andrey Samokhvalov
8fa2b95c12 lnd: remove seelog logger
The btclog package has been changed to defining its own logging
interface (rather than seelog's) and provides a default implementation
for callers to use.

There are two primary advantages to the new logger implementation.

First, all log messages are created before the call returns.  Compared
to seelog, this prevents data races when mutable variables are logged.

Second, the new logger does not implement any kind of artifical rate
limiting (what seelog refers to as "adaptive logging").  Log messages
are outputted as soon as possible and the application will appear to
perform much better when watching standard output.

Because log rotation is not a feature of the btclog logging
implementation, it is handled by the main package by importing a file
rotation package that provides an io.Reader interface for creating
output to a rotating file output.  The rotator has been configured
with the same defaults that btcd previously used in the seelog config
(10MB file limits with maximum of 3 rolls) but now compresses newly
created roll files.  Due to the high compressibility of log text, the
compressed files typically reduce to around 15-30% of the original
10MB file.
2017-06-25 14:19:56 +01:00
Olaoluwa Osuntokun
5dd7b157a0
lnwallet: fix race condition when forwarding by creating new pubkey
This commit fixes a race condition that would at times occur in the
htlcswitch.TestChannelLinkBidirectionalOneHopPayments test case. A race
condition would occur in the goroutine running ReceiveNewCommitment
compared with the grouting that would obtain the snapshot in order to
make a forwarding decision.

We fix this by creating a new public key for each new commitment
transaction such that we complete avoid the read/write race condition.
2017-06-19 17:43:57 +02:00
Olaoluwa Osuntokun
1be4d67ce4
multi: run all test instances in parallel 2017-06-17 01:00:07 +02:00
Olaoluwa Osuntokun
6937a42f2d
lnwallet: add new ShortChanID method to LightningChannel 2017-06-16 23:25:13 +02:00
Olaoluwa Osuntokun
2e05051176
lnwallet: clarify comment within commitment state sanity function 2017-06-08 22:25:06 -07:00
Olaoluwa Osuntokun
9676d476c9
lnwallet: fix race condition in channel state machine, use single mutex
This commit fixes a race condition that was discovered as a result of
the new htlcswitch package. The StateSnapshot method and all of the
other methods which mutate the state of the channel state machine were
using distinct mutexes. The fix is trivial: all methods accessing the
internal channel state variable now use the same mutex.
2017-06-08 22:24:20 -07:00
Olaoluwa Osuntokun
5e2381a64c
lnwallet: properly set FeeEstimator within integration tests 2017-06-07 17:22:46 -07:00
Olaoluwa Osuntokun
dc40662770
lnwallet/btcwallet: properly pass in FeeEstimator to btcwallet
This commit fixes a bug wherein the wallet would use the default relay
fee to craft transactions. On testnet, this might be insufficient or be
rejected all together in a mainnet setting. Therefore, we now pass in
the FeeEstimator interface and ensure that it’s consulted in order to
set the relay fee the wallet will use to craft transactions.

Note that this is a hold over until we have true dynamic fee
calculation within lnd which can then be extended to the internal
wallets.
2017-06-07 17:01:27 -07:00
Olaoluwa Osuntokun
9fd70958f4
multi: fix linter errors 2017-06-05 19:45:01 -07:00
Olaoluwa Osuntokun
91d4e6a377
lnwallet/btcwallet: fix duplicate imports 2017-06-05 19:41:12 -07:00
Olaoluwa Osuntokun
cbf7cd48f5
multi: update to latest neutrino API changes 2017-06-05 19:41:07 -07:00
Olaoluwa Osuntokun
467ccfde41
lnwallet: update interface test initiation for latest API change 2017-06-05 19:21:44 -07:00
Olaoluwa Osuntokun
3c5d856248
lnwallet: use current height as FundingBrodcastHeight during funding flow 2017-06-05 19:18:34 -07:00
Olaoluwa Osuntokun
54f849a62e
lnwallet: use the FundingBroadcastHeight as height hint for spend ntfns 2017-06-05 19:17:13 -07:00
Olaoluwa Osuntokun
7d62293d4a
lnwallet: remove GetTransaction method from BlockChainIO 2017-06-05 19:12:42 -07:00
Olaoluwa Osuntokun
0e8af209bd
lnwallet/btcwallet: update BlockChainIO implementation to be backend aware 2017-06-05 19:12:00 -07:00
Olaoluwa Osuntokun
aca729abfe
lnwallet/btcwallet: update btcwallet config to be aware of new chain interface 2017-06-05 19:10:08 -07:00
Alex
5746e764cb lnwallet: replace empty byte arrays with nils 2017-06-05 18:54:00 -07:00
Alex
b65f92abe2 lnwallet: ensure minimal OP_IF used everywhere. 2017-06-05 18:41:56 -07:00
Andrey Samokhvalov
79feebea80 channeldb: remove redudant test
After addition of the bidirectional payment test in htlcswitch packet,
which is more abstract, we may remove redudant test.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
dbcce82d52 lnwallet: make DeriveRevocationRoot public
In order to be able to use the DeriveRevocationRoot in the createChannel
function inside the htlcswicth package we need to make it public.

NOTE: The original lnwallet.CreateChannel function haven't been
sufficient as far it not takes the private keys as input.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
f774e3d9bf lnwallet: add missed addition of RHash
add rhash to the payment descriptor when receiving the settle htlc in
order to be able to pass it during settle htlc packet generation and
later find the user pending payment by rhash without additional hashing.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
0e51b1d22d channeldb: add available balance function
In this commit we made state machine to be responsible for returning
proper available balance - amount of satoshi which we able to use at
current moment. This will help us in constrction channel link
abstraction.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
fde27716d1 channeldb: add restriction to to use only half of the capacity locally
In this commit severe bug have been fixed which allows the state of the
nodes to be desychnorinesed in the moments of high htlc flow. We limit
the number of the htlc which we can add to commitment transaction
to half of the available capcity. This change fixes the bug when
commimtment transaction on the verge of being full, in this case race
condition might occures and remote htlc will be rejected, but at the
same time they will be added on remote side, the same situiation will
happen with htlc we have added, which cause the commitment transactions
to be different.
2017-05-31 11:06:08 -07:00
bryanvu
408be356fb lnwallet: update channel close to use fee estimation interface
This commit switches the channel close workflow to use the lnwallet fee
estimation interface rather than the hardcoded proposedFee.
2017-05-23 14:31:20 -07:00
bryanvu
514760f529 peer: handling for channel shutdown messages
This commit changes the cooperative channel close workflow to comply
with the latest spec. This adds steps to handle and send shutdown
messages as well as moving responsibility for sending the channel close
message from the initiator to the responder.
2017-05-23 14:31:20 -07:00
Olaoluwa Osuntokun
e689ef61dd
lnwallet: when calc'ing fee for commitment tx, use current fee-per-kw
This commit modifies the fee calculation logic when creating or
accepting a new commitment transaction to use the set FeePerKw within
the channel rather then re-query the estimator each time. The prior
behavior was benign as we currently use a static fee estimator, but the
dynamic setting this could’ve caused a state divergence.
2017-05-16 19:05:18 -07:00
Olaoluwa Osuntokun
82f591dbab
lnwallet: add TODO to properly roll dust outputs into initiator's paid fee 2017-05-16 19:02:52 -07:00
Olaoluwa Osuntokun
4ba01bb558
lnwallet: correct scaling for fee-per-byte to fee-per-weight, divide by 4
This commit corrects an error in the scaling as currently implemented
in the default static fee estimator. The spec draft has an error and
erroneously recommends multiplying by 4 to arrive at the fee-per-weight
from the fee-per-byte. This is incorrect as with the segwit block-size
increase, the ratio is 1/4 rather than 4.
2017-05-16 19:02:02 -07:00
Olaoluwa Osuntokun
c324b11b95
lnwallet: use distinct fee rate for funding transaction coin selection
This commit modifies the coin selection logic around selecting inputs
for a funding transaction to query the fee estimator directly (and use
fee-per-byte), rather than use the fee estimate which was passed into
the context.

We also use the value passed into the InitChannelReservation method
directly rather than make a call to the fee estimator. With this
change, the responder to a funding workflow will now properly adopt the
fee-per-kw suggested by the funder of the channel.
2017-05-16 19:00:27 -07:00
Olaoluwa Osuntokun
222385bf73
lnwallet: calcStaticFee now directly uses feePerKw 2017-05-16 18:56:46 -07:00
Olaoluwa Osuntokun
52942e4f13
lnwallet: NewChannelReservation now accepts target feePerKw for commitment 2017-05-16 18:55:33 -07:00
Olaoluwa Osuntokun
48850d31d6
lnwallet: simplify remote balance computation for single funder
The remote balance in the case of a single funder workflow is simply
what ever the pushSat amount is. The capacity - fundingAmt in this
scenario would always be zero, so we simply just set it directly to
pushSat.
2017-05-16 18:52:39 -07:00
Olaoluwa Osuntokun
392f6b5d8a
lnwallet: convert all references to transaction/block cost to weight 2017-05-16 18:50:55 -07:00
bryanvu
4ac7cc719f lnwallet: replace hard-coded fees and adjust tests accordingly
This commit replaces the hard-coded 5000 satoshi fees with calls to the
FeeEstimator interface. This should provide a way to cleanly plug in
additional fee calculation algorithms in the future. This change
affected quite a few tests. When possible, the tests were changed to
assert amounts sent rather than balances so that fees wouldn't need to
be taken into account. There were several tests for which this wasn't
possible, so calls to the static fee calculator were made.
2017-05-15 20:26:11 -07:00
bryanvu
abe2e502d5 lnwallet: add FeeEstimator interface, StaticFeeEstimator implementation
This commit adds the FeeEstimator interface, which can be used for
future fee calculation implementations. Currently, there is only the
StaticFeeEstimator implementation, which returns the same fee rate for
any transaction.
2017-05-15 20:26:11 -07:00
bryanvu
320bed7e6b lnwallet: add CommitFee field to OpenChannel
In order to cleanly handle shutdowns and restarts during state machine operation, the fee for the current
commitment transaction must be persisted. This allows the fee to be
reapplied when the current state is reloaded.
2017-05-15 20:26:11 -07:00
bryanvu
18f453a3e6 lnwallet: add dust limit to contribution
In order to make the node's dust limit available to the wallet during
the initial stages of the funding process, add and set a
DustLimit field in the Contribution.
2017-05-15 20:26:11 -07:00
bryanvu
74854963bf lnwallet: remove OP_CHECKSEQUENCEVERIFY variable
Primarily to avoid linting errors, the lnwallet.OP_CHECKSEQUENCEVERIFY
variable was removed and references to it replaced with
txscript.OP_CHECKSEQUENCEVERIFY.
2017-05-15 20:26:11 -07:00
bryanvu
c1769f959b lnwallet: fix failure messages, spacing in tests
This commit changes t.Fatal to t.Fatalf in TestCheckDustLimit so as to
provide more information. This commit also makes some column width
adjustments and minor spelling/formatting changes.
2017-05-15 20:26:11 -07:00
Olaoluwa Osuntokun
80598dff11
lnwallet: in closeObserver if commitment is is ours, exit early 2017-05-15 18:21:02 -07:00
Olaoluwa Osuntokun
d2585ae6e5
lnwallet: add new struct UnilateralCloseSummary to provide complete channel close details 2017-05-15 18:20:59 -07:00
Olaoluwa Osuntokun
34959e4648
peer+lnwallet: update API usage to recent channeldb changes 2017-05-14 19:23:57 -07:00
Olaoluwa Osuntokun
2486097554
discovery+lnwallet: fix tests by making mock notifiers compliant to new interface 2017-05-11 15:58:41 -07:00
Olaoluwa Osuntokun
1b4862d815
lnwallet: use new ChainNotifier API, typo fixes 2017-05-11 15:21:05 -07:00
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