Commit Graph
100 Commits
Author SHA1 Message Date
Johan T. Halseth afccca59c4 lnd_test: add testDataLossProtection
This commit adds the integration test testDataLossProtection, that
ensures that when a node loses state, the channel counterparty will
force close the channel, and they both can recover their funds.
2018-07-31 15:16:24 +02:00
Johan T. Halseth 00154bda24 contractcourt/chain_watcher: attempt dispatchRemoteClose using data loss commitPoint
This commit makes the chainwatcher attempt to dispatch a remote close
when it detects a remote state with a state number higher than our
known remote state. This can mean that we lost some state, and we check
the database for (hopefully) a data loss commit point retrieved during
channel sync with the remote peer. If this commit point is found in the
database we use it to try to recover our funds from the commitment.
2018-07-31 15:16:24 +02:00
Johan T. Halseth ebed786b2a htlcswitch/link: inspect sync errors, force close channel
This commit makes the link inspect the error encountered during channel
sync, force closing the channel if we detect a remote data loss.
2018-07-31 15:16:23 +02:00
Johan T. Halseth 410b730778 lnwallet/channel test: add TestChanSyncFailure 2018-07-31 15:16:23 +02:00
Johan T. Halseth 78a4a15bb4 lnwallet/channel: check validity of received commitPoint
This commit adds a check for the LocalUnrevokedCommitPoint sent to us by
the remote during channel reestablishment, ensuring it is the same point
as they have previously sent us.
2018-07-31 15:16:23 +02:00
Johan T. Halseth a2f2d28d0b lnwallet/channel: enumerate error cases from remote chain desync
This commit enumerates the various error cases we can encounter when we
compare our remote commit chain to the view the remote communicates to us
via msg.NextLocalCommitHeight.

We now compare this height to our remote tail and tip height, returning
relevant error in case of a unrecoverable desync, and re-send a
commitment signature (including log updates) in case we owe one.
2018-07-31 15:16:23 +02:00
Johan T. Halseth f1757d6da4 lnwallet/channel: enumerate error cases from local chain desync
This commit enumerates the various error cases we can encounter when we
compare our local commit chain to the view the remote communicates to us
via msg.RemoteCommitTailHeight.

We now compare this height to our local tail height (note that there's
never a local "tip" at this point), returning relevant error in case of
a unrecoverable desync, and re-send a revocation in case we owe one.
2018-07-31 15:16:23 +02:00
Johan T. Halseth 7fb3be84df lnwallet/channel test: rename ErrCommitSyncDataLoss->ErrCommitSyncLocalDataLoss 2018-07-31 15:16:23 +02:00
Johan T. Halseth 48f1458ae5 lnwallet/channel: define channel sync errors
This commit defines a few new errors that we can potentially encounter
during channel reestablishment:
* ErrInvalidLocalUnrevokedCommitPoint
* ErrCommitSyncLocalDataLoss
* ErrCommitSyncRemoteDataLoss

in addition to the already defined errors
* ErrInvalidLastCommitSecret
* ErrCannotSyncCommitChains
2018-07-31 15:16:23 +02:00
Johan T. Halseth 3825ca71dd lnwallet/channel: reduce scope of commitSecretCorrect 2018-07-31 15:16:22 +02:00
Johan T. Halseth 6cdf0e2d6e channeldb/channel: methods for marking borked+dataloss commitPoint in db 2018-07-31 15:16:22 +02:00
Johan T. Halseth ea6aca26a5 channeldb: make chanStatus unexported
Since the ChanStatus field can be changed from concurrent callers, we
make it unexported and add the method ChanStatus() for safe retrieval.
2018-07-31 15:07:30 +02:00
Johan T. Halseth b437d03174 fundingmanager test: add TestFundingManagerMaxPendingChannels 2018-07-31 14:53:22 +02:00
Johan T. Halseth 8b6e7b24aa fundingmanager: count channels pending open when checking MaxPending 2018-07-31 14:53:22 +02:00
Johan T. Halseth 3afa16b7a6 mock: make ListUnspentWitness return new outpoints each call 2018-07-31 14:53:21 +02:00
Johan T. Halseth 5b77ebddb2 lnwallet test: account for funding tx being published by fundingmanager 2018-07-31 14:53:21 +02:00
Johan T. Halseth b885e8d288 fundingmanager test: check reservation canceled after tx broadcast 2018-07-31 14:53:21 +02:00
Johan T. Halseth 2a77b57788 lnwallet + funding: move funding tx publish to fundingmgr
This commit moves the responsibility for publishing the funding tx to
the network from the wallet to the funding manager. This is done to
distinguish the failure of completing the reservation within the wallet
and failure of publishing the transaction.

Earlier we could fail to broadcast the transaction, which would cause us
to fail the funding flow. This is not something we can do directly,
since the CompeteReservation call will mark the channel IsPending in the
databas.e
2018-07-31 14:53:21 +02:00
Johan T. Halseth 8865bcf3d9 fundingmanager: delete active reservation after channel is in DB
This commit makes sure we delete a pending channel from the set of
activeReservations within the fundingmanager immediately after the
channel is moved to the openChannelBucket in the DB. Previously we
wouldn't do this before the funding tx was confirmed, making it possible
that failing the funding flow at a later point would try to cancel a
non-existent reservation context.
2018-07-31 14:53:21 +02:00
Johan T. Halseth eed052eba5 lnwallet/channel: extract local balance from spend instead of stored commit 2018-07-31 08:27:03 +02:00
Johan T. Halseth 2626bba105 contractcourt/chain_watcher: use commitPoint directly instead of isPendingCommit 2018-07-31 08:27:03 +02:00
Johan T. Halseth d9e9b6197c lnwallet/channel test: take commitPoint in NewUnilateralCloseSummary 2018-07-31 08:27:03 +02:00
Johan T. Halseth 06ceba429f lnwallet/channel: make NewUnilateralCloseSummary take commitPoint 2018-07-31 08:27:03 +02:00
Johan T. Halseth f8751350bc lnd_test: set --nolisten for node being cheated
In this commit we modify the integration tests slightly, by setting the
parties that gets breached during the breach tests to --nolisten. We do
this to ensure that once the data protection logic is in place, they
nodes won't automatically connect, detect the state desync and recover
before we are able to trigger the breach.
2018-07-31 08:27:03 +02:00
Johan T. Halseth 22e21da370 htlcswitch tests: add missing OnChannelFailure to test link configs 2018-07-31 08:27:03 +02:00
Johan T. Halseth c48ecb85f6 Merge pull request #1657 from cfromknecht/resend-ann-copy-key
discovery/gossiper: copy bolt key to prevent panic
2018-07-31 08:26:23 +02:00
Johan T. Halseth 92b0b10dc7 Merge pull request #1613 from halseth/rpctest-increase-timeout
make: if timeout not set, use 20m instead of default 10m
2018-07-26 21:52:13 +02:00
Johan T. Halseth 44982ea98d make: if timeout not set, use 20m instead of default 10m
go test's default timeout is 10m, which is no longer enough during
integration tests. This commit increases it to 20m.
2018-07-26 13:29:23 +02:00
Johan T. Halseth 45a1fa54d8 lnd_test: check close status also for force closes
This commit makes sure the channels that are force closed also are put
into the state "waiting close" before the commitment transaction is
confirmed, and exits this state when it confirms.

This was previously not checked, as this check was added before the
"waiting close" state was introduced.
2018-07-26 09:18:42 +02:00
Johan T. Halseth f73a2f362e lnd_test: correct that Bob can sweep immediately
This commit fixes a flake within the integration tests, where we would
mine a set of blocks before checking if Bob's sweep tx was in the
mempool. Usually this would pass since the blocks were generated before
the tx hit the miner's mempool, but sometimes it was mined and then we
would check the mempool.

This commit fixes this by correctly waiting immediately for Bob to sweep
his funds, as they are not time locked.
2018-07-26 09:18:42 +02:00
Johan T. Halseth 181014c363 chainntnfs/bitcoindnotify: remove all mempool spend clients 2018-07-22 23:09:09 +02:00
Johan T. Halseth 3808105dcd chainntnfs/btcdnotify: remove all mempool spend clients 2018-07-22 23:09:08 +02:00
Johan T. Halseth d7b2977e8c multi test: remove mempool bool from RegisterSpendNtfn 2018-07-22 23:09:08 +02:00
Johan T. Halseth 57e829f47e multi: remove mempool bool from RegisterSpendNtfn 2018-07-22 23:09:08 +02:00
Johan T. Halseth 02f7f29b97 chainntnfs/interface_test: remove mempool spend tests 2018-07-22 23:09:08 +02:00
Johan T. Halseth 44d7b84df0 chainntnfs: remove mempool option from RegisterSpendNtfn 2018-07-22 23:09:08 +02:00
Johan T. Halseth 77f0020697 lnd_test: account for justice tx broadcast failure 2018-07-22 23:09:08 +02:00
Johan T. Halseth 8cff5eae6c breacharbiter: make the second level check use confirmed spends 2018-07-22 23:09:08 +02:00
Johan T. Halseth a16bb662a4 contractcourt/chain_arbitrator: make watchForChannelClose use confirmed spend 2018-07-22 23:09:07 +02:00
Johan T. Halseth 5bfa2f5912 contractcourt/contract_resolvers: make commitSweepResolver use confirmed spend 2018-07-22 23:09:07 +02:00
Johan T. Halseth 9fffe23696 contractcourt/contract_resolvers: make htlcOutgoingContestResolver act on conf 2018-07-22 23:07:53 +02:00
Johan T. Halseth b3e17aa67b contractcourt/contract_resolvers: make second level htlcSuccessResolver wait for conf 2018-07-22 11:20:23 +02:00
Johan T. Halseth bf06dc24c1 contractcourt/contract_resolvers: make waitForOutputResolution use confirmed spend 2018-07-22 11:20:23 +02:00
Johan T. Halseth fdf3b407c9 lnd_test: correct node names in comments, format file 2018-07-22 11:20:23 +02:00
Johan T. Halseth ea2b706174 lntest/node: make sure finalizing file is over before stop 2018-07-22 11:20:23 +02:00
Johan T. Halseth 07618ca0c6 chainntnfs/interface_test: increase wait time for mempool spends
This commit increases the time we wait for a spend client to notify a
mempool spend from 50ms to 10s. This is done to catch the case where
bitcoind would use up to 7 seconds before notifying about a mempool
spend, which wasn't caught by the test.
2018-07-16 15:08:59 +02:00
Johan T. Halseth 4e47e4e7f1 chainntnfs/bitcoindnotify: filter out mempool spends from relevant txs
This commit fix a bug within the bitcoind notifier logic, which would
ignore the passed mempool argument, and notify spentness whether the
spending transaction was confirmed or not. The logic used to fix this is
similar to what is already done for the btcd backend.
2018-07-16 12:27:05 +02:00
Johan T. Halseth d787e74125 contractcourt/channel_arbitrator: stop block epoch on channel attendant exit 2018-06-21 11:13:46 +01:00
Johan T. Halseth 1c43a0cb36 contractcourt/chain_arbitrator: delete watcher from activeWatchers 2018-06-21 11:13:46 +01:00
Johan T. Halseth b56d922ce2 fundingmanager: properly stop channel on error 2018-06-19 12:48:38 +01:00
Johan T. Halseth 55c8741e42 peer: don't stop nil channel 2018-06-19 12:48:11 +01:00
Johan T. Halseth 327420d854 contractcourt/channel_arbitrator: Cancel block epoch in case of error in Start() 2018-06-19 12:20:30 +01:00
Johan T. Halseth 3bdc968f39 breacharbiter: wait on spend events instead of timeout
This commit handles a racy condition within the breacharbiter's justice
tx procedure. For backends that have no mempool we would check if an
HTLC output was spent and then try broadcasting the justice tx, but this
would fail since we wouldn't detect the spend before it was in a block.
The result was that we would continuously attempt to broadcast the
transaction, effectively ending up in an endless (until the second-level
tx actually comfirmed) loop.

Instead we now register for spend notifications in case broadcasting the
transaction fails, and then wait for any of the notifications to be
sent before trying again.

This is a necessary step to be able to make lnd work well only with
confimed transactions, and was a better solution than introducing
timeouts within the broadcast loop (which complicates integration
tests).
2018-06-15 12:11:13 +02:00
Johan T. Halseth e0560741b4 breacharbiter test: add TestBreachSecondLevelTransfer 2018-06-15 12:11:13 +02:00
Johan T. Halseth 60d9ae02c7 mock: protect mockSpendNotifier map by mutex 2018-06-15 12:11:13 +02:00
Johan T. Halseth 9aa55b164e breacharbiter test: extract common init logic 2018-06-15 12:11:13 +02:00
Johan T. Halseth 0316523bb5 lntest/harness: add pollIntervall to WaitPredicate
This commit adds a poll 20 ms interval to WaitPredicate, similar to what
is done for WaitInvariant. This makes the predicate not being checked
super-rapidly, potentially filling the logs with useless info over the
wait predicate interval.
2018-06-11 15:58:30 +02:00
Johan T. Halseth 5d8aaa94f1 lnd_test: add missing node shutdowns 2018-06-10 10:07:01 +02:00
Johan T. Halseth abe590b752 lnd_test: shutdown nodes using defers
This commit adds the helper method shutdownAndAssert, and makes us shut
down nodes created temporarily during the test cases using defers
instead of at the end of the test. This makes it easier to remember to
shut them down, as it is done right after they are started.
2018-06-10 10:07:00 +02:00
Johan T. Halseth 226b38fed7 lntest/node: add method Name to get a node's name 2018-06-10 10:07:00 +02:00
Johan T. Halseth ac1ab6f516 server: hold mutex shorter during broadcast
We remove the internale broadcastMessage method, and instead handle the
mutex handling within BroadcastMessage. This lets us hold the mutex only
when neccessary.
2018-06-06 12:20:25 +02:00
Johan T. Halseth b8512c3568 server: don't hold mutex while sending to peer
This commit removes the sendToPeer method from the server, and instead
moves the necessary logic into SendToPeer. This let's us make the mutex
acquisition more fine-grained, only holding it while reading from the
peer map. Earlier it was required to be held during the whole call to
sendToPeer, as the method would access the map internally.
2018-06-06 12:20:06 +02:00
Johan T. Halseth 07629e5da1 lnwallet/channel: use FullySynced to check chanSync special case
We check if the channel is FullySynced instead of comparing the local
and remote commit chain heights, as the heights might not be in sync.
Instead we call FullySynced which recently was modified to use compare
the message indexes instead, which is _should_ really be in sync between
the chains.

The test TestChanSyncOweRevocationAndCommitForceTransition is altered to
ensure the two chains at different heights before the test is started, to
trigger the case that would previously fail to resend the commitment
signature.
2018-06-04 15:09:51 +02:00
Johan T. Halseth cdaafc4a23 fundingmanager: hold mutex during ctx cancellation
This commit changes cancelReservationCtx to gold the resMtx from start
to finish. Earlier it would lock at different times only when accessing
the maps, meaning that other goroutines (I'm looking at you
PeerTerminationWatcher) could come in and grab the context in between
locks, possibly leading to a race.
2018-06-01 09:19:01 +02:00
Johan T. Halseth 3d964628f0 fundingmanager test: check that error is sent on timeout 2018-06-01 08:55:07 +02:00
Johan T. Halseth d20cb8e2f6 fundingmanager: send on resCtx.err in failFundingFlow
This commit moves the responsibility of sending a funding error on the
reservation error channel inside failFundingFlow, reducing the places we
need to keep track of sending it.
2018-06-01 08:55:07 +02:00
Johan T. Halseth 9090344329 fundingmanager: simplify handleErrorMsg 2018-06-01 08:55:07 +02:00
Johan T. Halseth 7d38e35cdc fundingmanager: send error directly in CancelPeerReservations
The error channel should never be nil, and it should always be buffered.
Because of this we can send directly on the channel.
2018-06-01 08:55:07 +02:00
Johan T. Halseth b63ee1a410 fundingmanager: fail funding flow on confirmation timeout 2018-06-01 08:55:07 +02:00
Johan T. Halseth ccf9cd47ef fundingmanager: delete empty peer in deleteReservationCtx 2018-06-01 08:55:06 +02:00
Johan T. Halseth 6ee58ec1b0 fundingmanager: don't block on pendingChannels chan send 2018-06-01 08:55:06 +02:00
Johan T. Halseth 08d9edd059 server: increase updateChan buffer to 2 2018-06-01 08:55:06 +02:00
Johan T. Halseth 5ddb154a45 fundingmanager: use non-zero channel ID 2018-06-01 08:55:06 +02:00
Johan T. Halseth d4700640e0 lnwallet/channel test: add TestChannelRestoreCommitHeight
This commit adds a test which will restore a channel from an OpenChannel
struct at various stages of the state transation cycle, ensuring the
HTLC local and remote add heights are restored properly.
2018-05-29 08:35:01 +02:00
Johan T. Halseth cb52151123 lnwallet/channel: set add heights based on the locked in commits
This commit fixes a bug which would cause the add heights of the HTLCs
in the update log to be set wrongly. At times, an add height could be
incorrecly set, leading to the HTLCs not being accounted for correctly
during evaluating the HTLC views. This was caused by the assumption that
if the HTLC was not on the pending remote commit, then it was locked in
on both the local and the remote commit, which is not always true.

Instead of making this assumption, we instead now inspect the three
commits: the local, remote and pending remote; and set the add heights
accordingly. This should ensure that HTLCs are subtracted from the
balances only when they are first added.
2018-05-29 08:35:01 +02:00
Johan T. Halseth 4dfb4547a0 htlcswitch: remove unused Disconnect from Peer interface 2018-05-25 06:58:24 +02:00
Johan T. Halseth f95ae1cdd6 htlcswitch/link: add failed variable to ensure exit 2018-05-25 06:58:24 +02:00
Johan T. Halseth d0b0734e5b lnd_test: add testFailingLink
This commit adds an integration test that checks that in case a channel
counterparty tries to settle an HTLC with the wrong preimage, the
channel is failed and force closed.
2018-05-25 06:58:24 +02:00
Johan T. Halseth 49fd3f34d4 htlcswitch/link: settle with fake preimage if BogusSettle active 2018-05-25 06:58:24 +02:00
Johan T. Halseth 71a1aae417 htlcswitch/hodl: add flag BogusSettle
This commit adds a new hodl flag "BogusSettle" which will be used to
emulate a node trying to settle back an incoming HTLC with a fake
preimage.
2018-05-25 06:58:23 +02:00
Johan T. Halseth 88670175c7 htlcswitch/link_test: add TestChannelLinkFail 2018-05-25 06:58:23 +02:00
Johan T. Halseth 9a47494517 htlcswitch/link_test: extract adding link to switch 2018-05-25 06:58:23 +02:00
Johan T. Halseth 3b2fd32523 peer: populate OnChannelFailure in link config
This commit makes the peer aware of the LinkFailureErrors that can
happen during link operation, and making it start a goroutine to
properly remove the link and force close the channel.
2018-05-25 06:58:23 +02:00
Johan T. Halseth fbec83699c htlcswitch/link: make fail() call OnChannelFailure with LinkFailureError
Adds a new closure OnChannelFailure to the link config, which is called
when the link fails. This function closure should use the given
LinkFailureError to properly force close the channel, send an error to
the peer, and disconnect the peer.
2018-05-25 06:58:23 +02:00
Johan T. Halseth 92afcbe3f4 htlcswitch/linkfailure: define LinkFailureError
This commit introduces a new error type LinkFailureError which is used
to distinguish the different kinds of errors that we can encounter
during link operation. It encapsulates the information necessary to
decide how we should handle the error.
2018-05-25 06:58:18 +02:00
Johan T. Halseth 4836a25c98 peer: move link creation into new method 2018-05-25 06:54:05 +02:00
Johan T. Halseth 1f746c3fda contractcourt/chan_arb: specify that ForceCloseChan removes link from
switch
2018-05-25 06:54:05 +02:00
Johan T. Halseth 5cef2bacde rpcserver: add TODO for removing coop closes from "pending close" channels 2018-05-24 10:29:20 +02:00
Johan T. Halseth 8afc7bf66e contractcourt/chain_arbitrator: add TODO for removing watchForChannelClose 2018-05-24 10:24:31 +02:00
Johan T. Halseth 69a76a808f breacharbiter: add todo for removing IsPending check 2018-05-23 12:11:19 +02:00
Johan T. Halseth 72d9726e7f channeldb/channel: update IsPending godoc
The pending state definitin in ChannelCloseSummary was slightly changed
in such a way that channels that has had their commitment broadcasted
now is no longer considered "pending close". They now instead stay in
the open chan bucket with the ChanStatus "CommitmentBroadcasted" until
their commitment is confirmed. This commit updates the IsPending godoc
to reflect this.
2018-05-23 12:07:35 +02:00
Johan T. Halseth 74205a64fd lnd_test: check for coop closed channel among WaitingClose instead of PendingClosed 2018-05-22 14:30:30 +02:00
Johan T. Halseth 921f02fe22 contractcourt/chain_arbitrator: markChanClosed->notifyChanClosed
We no longer have to mark the channel as fully closed in the database,
as it is done directly in the chainWatcher. Instead, we stop the watcher
and delete it from the set of active watchers.
2018-05-22 14:30:19 +02:00
Johan T. Halseth 0f077fcb54 contractcourt/chain_watcher: mark fully closed in dispatchCoopClose
This commit makes the dispatchCooperativeClose method mark the channel
fully closed directly, without registering for confirmation
notifications first. We can do this as recent changes to the
contractcourt changed the definition of a closed channel in the database
to have had its closing tx confirmed, and we only dispatch the
cooperative close once the transaction has 1 confirmation.

We also rename the markChanClosed method to notifyChanClosed, to more
clearly indicate that the ChainArbitrator no longer has to mark the
channel fully closed in the database.
2018-05-22 14:26:02 +02:00
Johan T. Halseth af14a2fc57 contractcourt/chain_watcher: remove CooperativeCloseCtx
Removes CooperativeCloseCtx and methods.
2018-05-22 14:21:43 +02:00
Johan T. Halseth 21d1cc3fe8 contractcourt/chain_arbitrator: remove BeginCoopChanClose 2018-05-22 12:06:33 +02:00
Johan T. Halseth bb611e065d peer: don't pass closeCtx to chanCloser 2018-05-22 12:06:33 +02:00
Johan T. Halseth 0809880426 chancloser: don't log potential closes to the chainwatcher
This commit stops the chan closer from sending the potential coop close
transactions to the chainwatcher, as this is no longer needed. The
chainwatcher recently was modified to watch for any potential close, and
will because of this handle the close regardless of which one appears in
chain.

When the chancloser broadcast the final close transaction, we mark it as
CommitmentBroadcasted in the database.
2018-05-22 12:05:47 +02:00
Johan T. Halseth 9ddd484524 lnwallet/channel: export method MarkCommitmentBroadcasted 2018-05-22 12:03:35 +02:00
Johan T. Halseth 7cd783d7bb lnwallet/channel: remove unused method DeleteState 2018-05-22 11:51:30 +02:00