Commit Graph
100 Commits
Author SHA1 Message Date
Johan T. Halseth d216416db8 contractcourt/channel_arbitrator: ignore ErrDoubleSpend on force close
This commit mitigates a problem within the ChannelArbitrator, where
after a restart we would start up in the state StateBroadcastCommit but
fail to broadcast out commitment because a conflicting transaction (most
likely our own commitment) was already broadcast. A more complete fix
for this case will be added later, but this commit let the
ChannelArbitrator continue, trying to close out the channel.
2018-03-29 11:15:41 +02:00
Johan T. Halseth 5bf5a823ff contractcourt/chain_watcher: don't print curve of DoubleTweak 2018-03-29 11:11:54 +02:00
Johan T. Halseth 13be19c9ec chainntnfs/bitcoind: move NotifySpent to after recording the outpoint
This commit moves the call to the bitcoind backend to start watching an
outpoint for spentness to after we have recorded the outpoint in our
list of clients. This is done to avoid a race that we saw using the btcd
backend, and it is probable that it can also happen using bitcoind.
2018-03-28 10:22:41 +02:00
Johan T. Halseth b08fc05390 chainntnfs/btcd: move NotifySpent to after recording the outpoint
This commit moves the call to the btcd backend to start watching an
outpoint for spentness to after we have recorded the outpoint in our
list of clients. This is done to avoid a race that could occur if btcd
quicly sent a spend notification before we had been able to record it in
our map, essentially losing it.
2018-03-28 10:21:08 +02:00
Johan T. Halseth 0f90c950da rpcserver: remove uneccessary signal to breacharbiter at force close
This signal is no longer needed, as the breacharbiter is given
the UnilateralClosure chain event.
2018-03-28 08:10:19 +02:00
Johan T. Halseth 2fa2b545fc breacharbiter: reuse spend events instead of re-registering
This commit fixes a broadcast loop within the breach arbiter, that would
occur when HTLC outputs had been taken to the second level. The breach
arbiter would register for a spend event, but would immediately go on to
create and publish the justice, without waiting for the response to be
received on the spend channel. This lead to a race, where the outpoint
could actually already have been spent, but the notification would
arrive after the breach arbiter checked the channel, and publishing the
justice TX would fail because it was a double spend. This would create a
"broadcast loop", as seen in the logs from the integration test
revoked_uncooperative_close_retribution_remote_hodl.

This is fixed by reusing an existing spend event for the outputs,
meaning we will actually receive on the first channel we initiated,
making the broadcast loop more likely to terminate.
2018-03-23 13:36:57 +01:00
Johan T. Halseth a6e7dce7b7 lnwallet/channel: reject received commitment with too many htlc sigs
This commit adds a check that will make LightningChannel reject a
received commitment if it is accompanied with too many HTLC signatures.
This enforces the requirement in BOLT-2, saying:

if num_htlcs is not equal to the number of HTLC outputs in the local commitment transaction:
    * MUST fail the channel.

A test exercising the behaviour is added.
2018-03-22 14:58:22 +01:00
Johan T. Halseth 70b86e596e lnwallet/channel: use remote dustlimit when generating HTLC sigs
This commit fixes an issue which would arise in some cases when the
local and remote dust limits would differ, resulting in lnd not
producing the expected number of HTLC signatures. This was a result of
checking dust against the local instead of the remote dust limit.

A test exercising the scenario is added.
2018-03-22 14:58:22 +01:00
Johan T. Halseth 263d6b9c1f lnwallet/channel: don't accept immediately on empty htlc sigs
This commit fixes an issue where we would blindly accept a commitment
which came without any accompanying HTLC signatures. A test exercising
the scenario is added.
2018-03-22 14:58:22 +01:00
Johan T. Halseth 241c79397f lnwallet/channel: fix crash on receiving too few HTLC sigs
This commit fixes an out of bounds error that would occur in the case
where we received a new commitment where the accompanying HTLC sigs were
too few. Now we'll just reject such an commitment.

A test exercising the behavior is also added.
2018-03-22 14:58:22 +01:00
Johan T. Halseth bbdad9d5d6 lncli: add remote_csv_delay to openchannel command 2018-03-22 14:54:00 +01:00
Johan T. Halseth a848a58749 funding: use remoteCsvDelay from openChanReq if specified 2018-03-22 14:54:00 +01:00
Johan T. Halseth 208d1199ef pilot: set remoteCsvDelay=0 (default) for OpenChannel 2018-03-22 14:54:00 +01:00
Johan T. Halseth 938aefb573 rpcserver: pass incoming RemoteCsvDelay to server.OpenChannel 2018-03-22 14:54:00 +01:00
Johan T. Halseth 6f98803967 server: add remoteCsvDelay to openChanReq 2018-03-22 14:53:59 +01:00
Johan T. Halseth 00ed95b414 lnrpc: add remote_csv_delay to OpenChannelRequest 2018-03-22 14:53:41 +01:00
Johan T. Halseth 9c0fc023af Merge pull request #834 from wilmerpaulino/list-channels
multi: specify retrieving active, inactive, public, and private channels from listchannels rpc
2018-03-20 09:37:58 +01:00
Johan T. Halseth 5818bdba96 Merge pull request #828 from cfromknecht/switch-itest-hardening
Switch ITest Hardening
2018-03-14 11:06:34 +01:00
Johan T. Halseth b2608dd292 htlcswitch/link_test: increase timeout for message sends
This commit increases the time we wait for a message to be sent for
several test cases, aiming to decrease the false negative rate on
Travis.
2018-03-13 12:20:58 +01:00
Johan T. Halseth a6c2550404 peer: track failed channels
This commit adds a set used to track channels we consider failed. This
is done to ensure we don't end up in a connect/disconnect loop when we
attempt to re-sync the channel state of a failed channel with a peer.
2018-03-13 11:11:17 +01:00
Johan T. Halseth 300fb1af4a lnwire: define ConnectionWideID 2018-03-11 17:21:23 +01:00
Johan T. Halseth 80ef16e853 peer: hand lnwire.Error to fndgMngr or link depending on chanID 2018-03-11 17:21:23 +01:00
Johan T. Halseth 33762e0f81 htlcswitch/link: fail channel on lnwire.Error 2018-03-11 17:21:23 +01:00
Johan T. Halseth f1f1a38663 funding: add method IsPendingChannel 2018-03-11 17:20:28 +01:00
Johan T. Halseth 7252dbd934 funding: add missing mutex around activeReservations 2018-03-11 17:20:28 +01:00
Johan T. Halseth 781c2a6eb4 lnwallet test: update test to new error message 2018-03-06 22:02:35 +01:00
Johan T. Halseth 6942e1479d funding: only send know errors across wire
This commit changes the failFundingFlow to accept an error, which will
only be sent to the remote the peer if it is among the
ReservationErrors or ErrorCode. This is done to ensure we don't send
errors that contain information we don't want to leak.
2018-03-06 22:02:35 +01:00
Johan T. Halseth b3441561cf lnwire: make ErrorCode satisfy error interface 2018-03-06 22:02:34 +01:00
Johan T. Halseth 0cbb759d0a lnwallet: send ReservationError for invalid/incompatible reservation 2018-03-06 22:02:34 +01:00
Johan T. Halseth bb63ad7da6 lnwallet: send ReservationError for unacceptable constraints 2018-03-06 22:02:34 +01:00
Johan T. Halseth 2cd7ec0833 lnwallet: add errors.go, errors sent to peer during funding 2018-03-06 22:02:34 +01:00
Johan T. Halseth 2db5e56754 lnwire: add todo for changing to SatPerKWeight for fee rates 2018-02-26 22:42:28 +01:00
Johan T. Halseth b9f09a666d lnd test: calculate channel reserve based on balance before fees 2018-02-26 22:42:27 +01:00
Johan T. Halseth 24d30e6495 peer test: remove var casting 2018-02-26 22:42:27 +01:00
Johan T. Halseth f42c16b612 lnd test: ensure static fee is not rounded down 2018-02-26 22:42:27 +01:00
Johan T. Halseth 004563b20b channeldb: add todo making feerate explicit type 2018-02-26 22:42:27 +01:00
Johan T. Halseth dd6872da31 lnwallet test: add TestFeeRateTypes and TestStaticFeeEstimator 2018-02-26 22:42:27 +01:00
Johan T. Halseth 7b30425111 multi test: update tests/mocks to use EstimateFeePerVSize 2018-02-26 22:42:27 +01:00
Johan T. Halseth ba3f3e1942 rpcserver: express fee rates using types 2018-02-26 22:42:27 +01:00
Johan T. Halseth b9d1eceda3 peer: use EstimateFeePerVSize 2018-02-26 22:42:26 +01:00
Johan T. Halseth d4cedc2917 breacharbiter: use EstimateFeePerVSize 2018-02-26 22:42:26 +01:00
Johan T. Halseth e48d51db92 pilot: express fee rates using types, use EstimateFeePerVSize 2018-02-26 22:42:26 +01:00
Johan T. Halseth 3dc9e3c7d4 server: express fee rates using fee rate types 2018-02-26 22:42:26 +01:00
Johan T. Halseth 5f267bcc5b utxonursery: use EstimateFeePerVSize 2018-02-26 22:42:26 +01:00
Johan T. Halseth 2a9aa092d8 fundingmanager: express fee rates using types, use EstimateFeePerVSize 2018-02-26 22:42:26 +01:00
Johan T. Halseth 3e12f823b2 chancloser: express fee rates in sat/vbyte 2018-02-26 22:42:26 +01:00
Johan T. Halseth 6d5c0679f4 chainregistry: express fee rates in sat/vbyte 2018-02-26 22:42:25 +01:00
Johan T. Halseth 166637bb55 contractcourt: use vsize fee estimate and new fee rate types 2018-02-26 22:42:25 +01:00
Johan T. Halseth 4d2a36dce8 htlcswitch tests: update tests to new FeeEstimator and fee rate types 2018-02-26 22:42:25 +01:00
Johan T. Halseth 80277c0517 htlcswitch: use fee rate types instead of btcutil.Amount for fee rates 2018-02-26 22:42:25 +01:00
Johan T. Halseth d7834ca4eb lnwallet tests: update tests to new FeeEstimator and fee rate types 2018-02-26 22:42:25 +01:00
Johan T. Halseth 1f839d2526 lnwallet/channel: denominate in fee rate types 2018-02-26 22:42:25 +01:00
Johan T. Halseth e1bb762cf7 lnwallet: denominate in fee rate types 2018-02-26 22:42:25 +01:00
Johan T. Halseth 088d9bc42f lnwallet: add VSize method for returning size from TxWeightEstimator 2018-02-26 22:42:24 +01:00
Johan T. Halseth f6ac5658e2 lnwallet: make SendOutputs take feerate in SatPerVByte 2018-02-26 22:42:24 +01:00
Johan T. Halseth 68557e43c1 lnwallet: add feerate types, make estimator return sat/vbyte 2018-02-26 22:42:24 +01:00
Johan T. Halseth b0d1be282c fundingmanager: cancel reservation if unable to send initial msg to peer 2018-02-23 15:41:32 +01:00
Johan T. Halseth ff1dc2bbd4 funding: ensure we fail funding flow if unable to query wallet 2018-02-23 15:41:32 +01:00
Johan T. Halseth 00ea46d9ae Merge pull request #767 from sangaman/master
zpay32: handle segwit prefixes > 2 chars
2018-02-21 14:42:47 +01:00
Johan T. Halseth 31ec79e7ae Merge branch 'master' into master 2018-02-21 13:54:26 +01:00
Johan T. Halseth cabc07ea7d breacharbiter: check ErrDoubleSpend from PublishTransaction 2018-02-14 12:34:42 +01:00
Johan T. Halseth 2ae1b7dbbe contractcourt: remove TODO for checking double spends from PublishTx 2018-02-14 12:34:41 +01:00
Johan T. Halseth 3fd7f28b39 lnwallet: don't ignore any returned error from PublishTransaction 2018-02-14 12:34:41 +01:00
Johan T. Halseth 7aaa15b8b5 utxonursery: don't ignore any returned error from PublishTransaction 2018-02-14 12:34:41 +01:00
Johan T. Halseth db0928fa6f chancloser: don't check error returned from broadcastTx
This commit removes the inspection of the return error
from broadcastTx. This is done since the new error
checking added to PublishTransaction will return a nil
error in case the transaction already exists in the
mempool.
2018-02-14 12:34:41 +01:00
Johan T. Halseth d96b5b62eb lnwallet test: add test for PublishTransaction return errors 2018-02-14 12:34:41 +01:00
Johan T. Halseth 1dcc89cca9 lnwallet/btcwallet: return concrete error type from PublishTransaction 2018-02-14 12:34:40 +01:00
Johan T. Halseth a1a9834a53 lnwallet: add PublishTransaction error types 2018-02-14 12:34:40 +01:00
Johan T. Halseth d092b57d9c Merge pull request #736 from nalinbhardwaj/zpay32-test
zpay32: Add tests for non-ASCII(UTF-8) descriptions
2018-02-09 22:09:28 -05:00
Johan T. Halseth f6d357e122 breacharbiter tests: set MinHtlc=0 during tests 2018-02-08 18:35:25 -05:00
Johan T. Halseth 82dc8e0794 lnwallet test: add channel constraints tests
This commit adds the tests TestMaxAcceptedHTLCs,
TestMaxPendingAmount, TestChanReserve and TestMinHTLC.
2018-02-08 18:35:25 -05:00
Johan T. Halseth f9701cde63 lnwallet tests: set channel reserve during channel tests 2018-02-08 18:35:25 -05:00
Johan T. Halsethandnsa 7b9f098fe6 lnwallet: fully validate all channel constraints in validateCommitmentSanity
This commit introduces changes to the validateCommitmentSanity
function to fully validate all channel constraints.
validateCommitmentSanity now validates that the
MaxPendingAmount, ChanReserve, MinHTLC, & MaxAcceptedHTLCs
limits are all adhered to during the lifetime of a channel.

When applying a set of updates, the channel constraints are
validated from the point-of-view of either the local or the
remote node, to make sure the updates will be accepted.

Co-authored-by: nsa <elzeigel@gmail.com>
2018-02-08 18:35:25 -05:00
Johan T. Halseth 1873fe1381 lnwallet/channel: move common calculation of balance into computeView
This commit moves common logic used to calculate the state
of a commitment after applying a set of HTLC updates, into
the new method computeView. This method can be used when
calculating the available balance, validating the sanity
of a commitment after applying a set of updates, and also
when creating a new commitment, reducing the duplication
of this logic.
2018-02-08 18:35:25 -05:00
Johan T. Halseth 98d28611e4 lnwallet/channel: let evaluateHTLCView take mutate boolean
This commit adds a new boolean parameter mutateState to
evalueteHTLCView, that let us call it without neccessarily
mutating the addHeight/removeHeight of the HTLCs, which is
useful when evaluating the commitment validity without
mutating the state.
2018-02-08 18:35:25 -05:00
Johan T. Halseth 78514acd49 integration tests: accoount for channel reserve when sending payments. 2018-02-08 18:35:24 -05:00
Johan T. Halseth a3a0efbeb0 lnd: populate channel constraints closures in fundingConfig. 2018-02-08 18:35:24 -05:00
Johan T. Halseth 997b1ea8ee fundingmanager: channel constraints closures
This commit makes more channel constraints available
via closures part of the fundingConfig, moving them
from the reservation.RemoteChanConstraints method.
2018-02-08 18:35:24 -05:00
Johan T. Halseth 509adce2ad htlcswitch test: add TestChannelLinkBandwidthChanReserve 2018-02-08 18:35:24 -05:00
Johan T. Halseth e6f7a46d90 htlcswitch: don't return negative value from Bandwidth()
This commits prevents the Bandwith() method from returning
a negative value if the channel reserve is larger than
the actual available balance.
2018-02-08 18:35:24 -05:00
Johan T. Halseth 50f495fae1 lnwallet: cleanup of reservation.CommitConstraints, and move RemoteChanConstraints.
This commit adds some more comments and checks to
reservation.CommitConstraints, including making
MinHTLC value one of the passed constraints.

RemoteChanConstraints is also moved out of
reservation.
2018-02-08 18:35:24 -05:00
Johan T. Halseth 65723387fa channeldb: update ChannelConstraints godoc
This commit changes the definition of the
constraints in the ChannelConstraints struct
to specify that these are all constraints the
*owner* of the set of constraints must *never
violate*.

This is done to make it easier to check that
a particular node is not violating any
constraint for a gien update, as before it
could violate constraints found both in its
local and the remote contraints.
2018-02-08 18:35:24 -05:00
Johan T. Halseth 9f2ec87ed6 lnwallet/sigpool: exit SubmitSignBatch on quit 2018-02-02 21:16:38 -05:00
Johan T. Halseth 12d3327833 htlcswitch/link_test: update Bandwidth tests
This commit updates the tests for checking a links Bandwidth()
calculation, after the change that made us use the remoteACKedIndex
instead of the logIndex when calculating it. The main result of this
change is that we never consider incoming updates before they are
acked, when calculating the bandwidth. This is because this was
inconsistent with the state we actually end up signing later on.
2018-02-02 21:16:37 -05:00
Johan T. Halseth ab75cd3a4d htlcswitch/test_utils: set BatchTicker mock and BatchSize
This commit adds the mockTicker and BatchSize to the link
config. It also exits the goroutines draining the HtlcUpdates
gracefully.
2018-02-02 21:16:37 -05:00
Johan T. Halseth f83f47541d channel test: add TestDesyncHTLCs
This commit adds a test that trigger a case where the balance
could end up being negative when we used the logIndex when
calculating the channel's available balance. This could
happen when the logs got out of sync, and we would use
the balance from a settled HTLC even though we wouldn't
include it when signing the next state.
2018-02-02 21:16:37 -05:00
Johan T. Halseth 83b368d20e lnwallet/channel: use remoteACKedIndex instead of logIndex in
availableBalance
2018-02-02 21:16:37 -05:00
Johan T. Halseth 26a80f86b8 peer: set BatchTicker and BatchSize in channellink config 2018-02-02 21:16:37 -05:00
Johan T. Halseth cc050f183f htlcswitch tests: add mockTicker struct 2018-02-02 21:16:37 -05:00
Johan T. Halseth 9b7b3fa3b6 channellink: make BatchTicker and BatchSize configurable
This commit introduces a new Ticker interface, that can be used
to control when the batch timer should tick. This is done to be
able to more easily control the ticker during tests. The batch
timer is wrapped in the new BatchTicker struct, and made part
of the config together with BatchSize.
2018-02-02 21:16:36 -05:00
Johan T. Halseth 08ae9fe510 lnrpc: change REST post path of PolicyUpdate from /fees to /chanpolicy 2018-01-27 14:48:28 -08:00
Johan T. Halseth 764323eb69 integration tests: use wait predicate to get Bob balance 2018-01-24 11:12:52 +01:00
Johan T. Halseth a55c74f80c discovery/gossiper: restrict database access per channel ID
This commit uses the multimutex.Mutex to esure database
state stays consistent when handling an announcement, by
restricting access to one goroutine per channel ID.

This fixes a bug where the goroutine would read the
database, make some decisions based on what was read,
then write its data to the database, but the read data
would be outdated at this point. For instance, an
AuthProof could have been added between reading the
database and when the decision whether to announce
the channel is made, making it not announce it.
Similarly, when receiving the AuthProof, the edge
policy could be added between reading the edge state
and adding the proof to the database, also resulting
in the edge not being announced.
2018-01-24 10:26:40 +01:00
Johan T. Halseth b07f242dc2 routing: use multimutex.Mutex instead of package internal mutex 2018-01-24 10:26:40 +01:00
Johan T. Halseth 0df3ff4994 multimutex: add new multimutex package 2018-01-24 10:26:39 +01:00
Johan T. Halseth 3e01529de4 discovery/gossiper: don't reset batch after broadcast
This commit fixes a bug that could cause annoucements
to get lost, and resultet in flaky integration tests.
After a set of announcements was broadcastet, we would
reset (clear) the announcement batch, making any
annoucement that was added between the call to Emit()
and Reset() to be deleted, without ever being broadcast.

We can just remove the Reset() call, as the batch will
actually be reset within the call to Emit(), making
the previous call only delete those messages we hadn't
sent yet.
2018-01-24 10:26:39 +01:00
Johan T. Halseth 786ca6cc50 integration test: improve logging in case of channel announcement failure 2018-01-24 10:26:29 +01:00
Johan T. Halseth 8cce2ad630 Merge pull request #573 from wilmerpaulino/parse-data-fields
invoice: refactor parsing data tagged fields and add unit tests
2018-01-19 18:40:48 +01:00
Johan T. Halseth cb7699068b Merge pull request #591 from AdamISZ/master
Fix trivial comment errors in noise.go
2018-01-19 14:47:22 +01:00
Johan T. Halseth 88f5c9ca9c Merge branch 'master' into master 2018-01-19 14:04:52 +01:00