Commit Graph

82 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun b6f64932c2
htlcswitch: face race condition in unit tests by returning invoice
In this commit we modify the primary InvoiceRegistry interface within
the package to instead return a direct value for LookupInvoice rather
than a pointer. This fixes an existing race condition wherein a caller
could modify or read the value of the returned invoice.
2017-11-11 16:09:29 -08:00
Olaoluwa Osuntokun 1734f96544
lnwallet: add a set of unit tests to exercise the various ChanSync cases
In this commit, we’ve added a set of unit tests to cover all enumerated
channel sync scenarios, including the case where both nodes deem that
they’re unable to synchronize properly.
2017-11-10 19:51:01 -08:00
Olaoluwa Osuntokun 08c7fd9b4d
lnwallet: extend TestStateUpdatePersistence to assert proper htlc counters 2017-11-10 19:51:00 -08:00
Olaoluwa Osuntokun 32651e9311
lnwallet: revert commit 5240953de0
In this commit we revert a prior commit
(5240953de0) which was added as a stop
gap before we added the proper state needed to recover from cases where
the commitment transactions of both chains had diverged slightly due to
asymmetric dust limits.
2017-11-10 19:51:00 -08:00
Olaoluwa Osuntokun e9d0e40a17
lnwallet: update existing channel unit tests to adhere to new channels API's 2017-11-10 19:51:00 -08:00
Olaoluwa Osuntokun 097e1c0f5c
lnwallet: update createTestChannels to adhere to new channeldb API's 2017-11-10 19:50:59 -08:00
Andrey Samokhvalov e29193d550 htlcswitch+channel: remove cancel reasons from channel link 2017-11-09 16:38:58 -08:00
Jim Posen a13ad0a339 multi: Fix various typos. 2017-10-25 13:20:54 -07:00
Olaoluwa Osuntokun 3b94e5df4d
lnwallet: introduce distinct HTLC counter+index on top of updateLog
In this commit, we fix an existing derivation from the commitment state
machine as defined within the specification. Before this commit, we
only kept a single counter which both HTLC adds and fails/settles would
share. This was valid in the prior pre-spec iteration of the state
machine. However in the current draft of the spec, only a distinct
counter for HTLCs are used throughout.

This would cause an incompatibility, as if we mixed adds and settles
during an exchange, then our counter values would differ with other
implementations. To remedy this, we now introduce a distinct HTLC
counter and index within the updateLog.

Each Add will increment both the log counter, and the HTLC counter.
Each Settle/Fail will only increment the log counter. Inbound
Settle/Fails will index into the HTLC index as to target the proper
HTLC. The PaymentDescriptor type has been extended with an additional
field (HltcIndex) which itself tracks the index of an incoming/outgoing
HTLC.
2017-10-22 18:36:57 -07:00
nsa aa6395874d wallet: channel test fee fix for added HTLC
This commit fixes the TestChannelBalanceDustLimit unit test in
channel_test.go. The unit test does not account for the fees
required by adding an HTLC. As a result, Alice's balance according
to her local and remote commitment chains drops below 0 at certain
points. By using the correct fee, this is avoided.
2017-10-19 20:04:04 -07:00
Olaoluwa Osuntokun d79c0ff95b
lnwallet: expand TestForceClose to ensure outgoing HTLC's can be swept
This commit expands the existing TestForceClose test case to add an
HTLC (outgoing) to Alice’s commitment transaction before force closing.
We then ensure that both the pre-signed timeout transaction _and_ the
sign descriptor to sweep the second-level output are fully valid.
2017-09-29 14:38:42 -07:00
Olaoluwa Osuntokun 927fb2ea0a
lnwallet: split off new TestForceCloseDustOutput case from TestForceClose
This commit extracts the ending dust adherence test case from the
existing TestForceClose test case into a distinct test case. With this
modification, we now ensure that the two new tests are focused and test
a single scenario at at time.
2017-09-29 14:13:28 -07:00
Olaoluwa Osuntokun 21d151d2ce
lnwallet: ensure the goroutines of all channels are stopped after test execution 2017-09-24 20:20:15 -07:00
Olaoluwa Osuntokun 9164cc218a
lnwallet: modify ReceiveFailHTLC to return value of HTLC failed 2017-09-24 20:17:53 -07:00
Olaoluwa Osuntokun f576a74bf6
lnwallet: modify SettleHTLC to return value of HTLC settled
This commit adds an additional return value to SettleHTLC in order to
make way for an upcoming change to modify the way bandwidth status from
the link to the switch is reported.
2017-09-24 20:17:14 -07:00
Olaoluwa Osuntokun 2bf8d1b3fb
lnwallet: ensure all channel tests run in parallel 2017-09-24 20:14:30 -07:00
Olaoluwa Osuntokun c85fcf2885
lnwallet: add test case for ErrInsufficientBalance error in channel state machine 2017-09-24 20:13:46 -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
Olaoluwa Osuntokun 7f575b688e
multi: txscript.WitnessScript -> txscript.WitnessSignature 2017-08-24 18:55:32 -07:00
Olaoluwa Osuntokun 6e54aba7ac
lnwallet: convert channel state machine accounting to milli-satoshi 2017-08-22 00:52:50 -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 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 747e0f57d1
multi: fix linter errors 2017-07-30 18:22:45 -07:00
Olaoluwa Osuntokun 6ad9d218b0
lnwallet: update all channel unittests due to new commitment design 2017-07-30 17:51:09 -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
Olaoluwa Osuntokun 1be4d67ce4
multi: run all test instances in parallel 2017-06-17 01:00:07 +02: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
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 222385bf73
lnwallet: calcStaticFee now directly uses feePerKw 2017-05-16 18:56:46 -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 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 2486097554
discovery+lnwallet: fix tests by making mock notifiers compliant to new interface 2017-05-11 15:58:41 -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
Christopher Jämthagen e524b7ac81 test: change HTLC amount in persistent test to account for dust 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
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
Christopher Jämthagen 810d8c286e test: add TestForceClose for lnwallet package 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