Commit Graph

126 Commits

Author SHA1 Message Date
Johan T. Halseth
8344b05c38
contractcourt/chanarb test: expand TestChannelArbitratorCommitFailure to coop and local force close 2018-08-23 10:04:43 +02:00
Johan T. Halseth
4933120d38
contractcourt/channel arbitrator: add coopCloseTrigger on startup for pendingClose channel 2018-08-23 10:04:43 +02:00
Johan T. Halseth
bb71856204
contractcourt/channel_arbitrator test: add TestChannelArbitratorEmptyResolutions 2018-08-23 00:03:22 +02:00
Johan T. Halseth
ed5db96e05
contractcourt/channel_arbittrator: ignore noResolutions error on startup 2018-08-23 00:03:22 +02:00
Johan T. Halseth
b031d87daf
contractcourt/briefcase: test FetchContractResolutions error when no resolutions logged 2018-08-23 00:03:22 +02:00
Johan T. Halseth
53286b8cee
contractcourt test: add TestChannelArbitratorCommitFailure 2018-08-23 00:03:22 +02:00
Johan T. Halseth
f2a033e965
contractcourt/channel_arbitrator: override trigger on startup if IsClosing
At ChannelArbitrator startup we now check the database close status of
the channel. If we detect that the channel is closed, but our state
machine hasn't advanced to reflect that (possibly because of a shutdown
before the state transition was finished), we manually trigger the state
transition to recover.
2018-08-23 00:03:22 +02:00
Johan T. Halseth
1758ad829f
contractcourt/[chain|channel]_arbitrator: define IsPendingClose 2018-08-23 00:03:22 +02:00
Johan T. Halseth
6b24ca0387
contractcourt test: add TestChannelArbitratorPeristence 2018-08-23 00:03:21 +02:00
Johan T. Halseth
75df58c68b
contractcourt: move responsibility for closing force closes to chanArb
This commit moves the responsibility for closing local and remote force
closes in the database from the chain watcher to the channel arbitrator.

We do this because we previously would close the channel in the
database, before sending the event to the channel arbitrator. This could
lead to a situation where the channel was marked closed, but the channel
arbitrator didn't receive the event before shutdown. As we don't listen
for chain events for channels that are closed, those channels would be
stuck in the pending close state forever, as the channel arbitrator
state machine wouldn't progress.

We fix this by letting the ChannelArbitrator close the channel in the
database. After the contract resolutions are logged (in the state
callback before transitioning to StateContractClosed) we mark the
channel closed in the database. This way we make sure that it is marked
closed only if the resolutions have been successfully persisted.
2018-08-23 00:03:21 +02:00
Johan T. Halseth
c11e0940c2
contractcourt/channel_arbitrator test: test new coop close actions 2018-08-23 00:03:21 +02:00
Johan T. Halseth
ad1d78884a
contractcourt: move responsibility for closing coop close channel to chanArb 2018-08-23 00:03:21 +02:00
Johan T. Halseth
3549f2bc17
contractcourt/[channel|chain]_arbitrator: define MarkChannelClosed 2018-08-22 23:51:04 +02:00
Johan T. Halseth
740db4716f
contractcourt/channel_arbitrator test: test state transitions 2018-08-22 23:51:04 +02:00
Johan T. Halseth
862c7ae223
contractcourt/channel_arbitrator test: check both respChan and errChan
// Both are sent on, so in some cases we would read from errChan first,
making the test fail.
2018-08-22 23:51:04 +02:00
Johan T. Halseth
06c683d48d
contractcourt/channel_arbitrator: move next state commit out of stateStep 2018-08-22 23:51:04 +02:00
Johan T. Halseth
6df302d7f5
contractcourt/channel_arbitrator: remove state callback
This commit removes the state callback, and instead logs the contract
resolutions directly after receiving the unilateral close event. The
resolutions won't change so there's not really necessary to wait to log
them, and this greatly simplifies the code.
2018-08-22 23:51:04 +02:00
Johan T. Halseth
245dae0071
contractcourt/channel_arbitrator: properly commit to next state 2018-08-22 23:51:04 +02:00
Olaoluwa Osuntokun
86e2e3fe2e
Merge pull request #1608 from halseth/htlc-expiry-off-by-one
contractcourt/contract_resolvers: correct off-by-one HTLC expiry
2018-08-17 16:41:42 -07:00
Olaoluwa Osuntokun
e97e4c1f5d
contractcourt: set auxiliary chan recovery info for all created chan close summaries 2018-08-14 19:11:40 -07:00
Johan T. Halseth
5476f6d310
contractcourt/contract_resolvers: correct off-by-one HTLC expiry
This commit attempts to fix an inconsistency in when we consider an HTLC
to expire. When we first launched the resolver we would compare the
current block height against the expiry, while for new incoming blocks
we would compare against expiry-1.

This lead to a flake during integration tests, during a call to
RestartNode after _exactly_ enough blocks for the HTLC to expire. In
some cases the resolver would see the new blocks and consider the HTLC
to be expired (because of the -1), while in some cases resolver would
shut down before seeing the new blocks, and upon restart wouldn't act on
the new height because we did not compare against -1.

This commit fixes this by doing the same comparison in both cases.
2018-08-14 09:15:48 +02:00
Valentine Wallace
1ffc3bb82e
multi: update to latest RegisterBlockEpochNtfn interface 2018-08-10 01:08:57 -07:00
Wilmer Paulino
a63677a381
multi: switch to transaction weight to calculate transaction fees
Due to a recent change within the codebase to return estimated fee rates
in sat/kw, this commit ensures that we use this fee rate properly by
calculing a transaction's fees using its weight. This includes all of
the different transactions that are created within lnd (funding, sweeps,
etc.). On-chain transactions still rely on a sat/vbyte fee rate since it's
required by btcwallet.
2018-08-09 17:29:50 -07:00
Conner Fromknecht
8758671552
contractcourt/chain_arbitrator: fix potential shutdown race
This commit fixes a potential race condition during
shutdown, that could allow the chain arb's
activeWatchers or activeChannels map to be modified
while ranging over their contents. We fix this by
copying the contents into new maps with the mutex
held, before releasing the mutex and shutting down
each watcher or channel arbitrator.
2018-08-03 16:46:41 -07:00
Conner Fromknecht
1ded697e8d
multi: sort import paths with gofmt 2018-08-02 18:20:49 -07:00
Olaoluwa Osuntokun
d9969f5dc2
contractcourt: update contract resolvers to use pkScripts for spend ntfns 2018-07-31 21:29:01 -07:00
Olaoluwa Osuntokun
c6950fcc2f
contractcourt: update channel arbitrator unit tests due to recent API changes 2018-07-31 21:29:01 -07:00
Olaoluwa Osuntokun
08e11d197d
contractcourt: update chain watcher to make funding pkScript for spend ntfn 2018-07-31 21:29:00 -07:00
Olaoluwa Osuntokun
ac9f9bd061
contractcourt: remove now obsolete code from the chain arbitrator
We no longer need this code fragment as the chain watcher is now able to
handle confirmed cooperative channel closures itself.
2018-07-31 21:29:00 -07:00
Olaoluwa Osuntokun
c707577e99
contractcourt: update conf ntfn registartions to use pkScript not txid 2018-07-31 21:28:49 -07: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
2626bba105
contractcourt/chain_watcher: use commitPoint directly instead of isPendingCommit 2018-07-31 08:27:03 +02:00
Conner Fromknecht
aa6e5bdd2a
contractcourt/contract_resolvers: fix subscribe preimage race
This commit fixes a potential race condition within the
IncomingContestResolver, that could cause us to miss a
preimage that was delivered in time.

Currently we query the db for the preimage, and then
subscribe for notifications. This permits the following
ordering of events:
 - query for preimage, returns nothing
 - preimage is added and delivered to subscribers
 - subscribe to preimages
 - preimage never comes through!!

We fix this by reordering to subscribe for preimages and
then query just in case it already exists. The effect is
that the query will always return a valid read of the
preimages that are currently queued for delivery.
2018-07-25 03:15:51 -07:00
Olaoluwa Osuntokun
e0baa49690
Merge pull request #1387 from wpaulino/send-disable-chan-update
multi: send a channel update with disabled flag set on channel close
2018-07-23 17:46:37 -07: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
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
Wilmer Paulino
d26050f711
contractcourt: use MarkChannelResolved for coop channel closures
In this commit, we alter cooperative channel closures to also use
MarkChannelResolved in order to unify the logic for the different types
of channel closures.
2018-07-17 17:35:28 -07:00
Olaoluwa Osuntokun
6f60f139f4 multi: switch over import paths from roasbeef/* to btcsuite/* 2018-07-13 17:05:39 -07:00
Wilmer Paulino
873cccc7a6
multi: send channel update with disabled active on force and coop chan closes 2018-07-11 17:07:03 -07: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
327420d854
contractcourt/channel_arbitrator: Cancel block epoch in case of error in Start() 2018-06-19 12:20:30 +01:00
maurycy
3be08e69cf multi: 64bit aligment of atomic vars on arm/x86-32 2018-06-04 20:02:34 -07: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
8afc7bf66e
contractcourt/chain_arbitrator: add TODO for removing watchForChannelClose 2018-05-24 10:24:31 +02:00