Commit Graph

71 Commits

Author SHA1 Message Date
Johan T. Halseth
79341fc63e
contractcourt/chain_watcher: move log message
This move the log message "channel marked pending-closed" to the point
where the channel actually has been marked pending closed, instead of
before the database transaction has been done.
2018-05-02 08:43:30 +02:00
Johan T. Halseth
7e397067f6
contractcourt/chainwatcher: remove close observer for loop
This commit removes the for loop in the closeObserver, as it wasn't
serving any purpose. After receiving a spend notification we would
return, breaking out of the loop. When getting a quit signal we would
also return, making the loop only do one iteration in any case.
2018-05-02 08:43:30 +02:00
Johan T. Halseth
4320421110
contractcourt/chain_watcher: don't delete syncDispatch clients on Cancel()
This commit makes clients subscribing to channel events that are marked
"sync dispatch" _not_ being deleted from the list of clients when they
call Cancel(). Instead a go routine will be launched that will send an
error on every read of the ProcessACK channel.

This fixes a race in handing off the breach info while lnd was shutting
down. The breach arbiter could end up being shut down (and calling
Cancel()) before while the ChainWatcher was in the process of
dispatching a breach. Since the breach arbiter no longer was among the
registered clients at this point, the ChainWatcher would assume the
breach was handed off successfully, and mark the channel as pending
closed. When lnd now was restarted, the breach arbiter would not know
about the breach, and the ChainWatcher wouldn't attempt to re-dispatch,
as it was already marked as pending closed.
2018-04-25 09:37:26 +02:00
Johan T. Halseth
854e73b8e0
contractcourt/chain_watcher: register for confirmed spend, mark closed when detected
This commit changes the ChainWatcher to only send a chain event in case
the various spends are _confirmed_ on-chain, not only seen on the
network.

A consequence of this is that we now give the ChainWatcher the
responsibility of marking the channel closed when the closing tx is
confirmed, instead of the ChannelArbitrator.
2018-04-25 09:37:24 +02:00
Johan T. Halseth
49f4a70e5a
contractcourt/chain_watcher: add dispatchLocalForceClose
This commit adds a new method dispatchLocalClose, which will be called
in case our commitment is detected to spend the funding transaction. In
this case LocalUnilateralCloseInfo will be sent on the
LocalUnilateralClosure channel to all subscribers.

The UnilateralClosure channel is renamed to RemoteUnilateralClosure for
consistency.
2018-04-25 09:37:22 +02:00
practicalswift
663c396235 multi: fix a-vs-an typos 2018-04-17 19:02:04 -07:00
Olaoluwa Osuntokun
09291d6aeb
contractcourt: ensure the closeObserver exits on quit 2018-04-16 17:28:48 -07:00
Olaoluwa Osuntokun
aaa8fa33b1
contractcourt: when creating resolveContract closure don't bind to loop variable
In this commit, we fix a long standing bug where at times a co-op
channel closure wouldn't be properly marked as fully closed in the
database. The culprit was a re-occurring code flaw we've seen many times
in the codebase: a closure variable that closes over a loop iterator
variable. Before this instance, I assumed that this could only pop up
when goroutines bind to the loop iterator within a  closure. However,
this instance is the exact same issue, but within a regular closure that
has _delayed_ execution. As the closure doesn't execute until long after
the loop has finished executing, it may still be holding onto the _last_
item the loop iterator variable was assigned to.

The fix for this issue is very simple: re-assign the channel point
before creating the closure. Without this fix, we would go to call
db.MarkChanFullyClosed on a channel that may not have yet actually be in
the pending close state, causing all executions to fail.

Fixes #1054.
Fixes #1056.
Fixes #1075.
2018-04-12 18:54:33 -07:00
Olaoluwa Osuntokun
7a13378671
channeldb+contractcourt: add additional logging around co-op channel closes 2018-04-12 17:13:37 -07:00
Conner Fromknecht
218293db4a
contractcourt/chain_watcher: release mutex on return 2018-04-11 14:50:05 -07:00
Olaoluwa Osuntokun
bc029b9cd4
contractcourt: properly log error if unable to update chan close state 2018-04-10 16:55:32 -07:00
Johan T. Halseth
8b02064c7b
multi: provide mempool=true to RegisterSpendNtfn 2018-04-03 11:24:07 +02:00
Johan T. Halseth
5bf5a823ff
contractcourt/chain_watcher: don't print curve of DoubleTweak 2018-03-29 11:11:54 +02:00
Olaoluwa Osuntokun
4b20e805fe
multi: update packages due to recent SignDescriptor and WalletController changes 2018-03-06 16:04:03 -05:00
practicalswift
a93736d21e multi: comprehensive typo fixes across all packages 2018-02-06 19:11:11 -08:00
Olaoluwa Osuntokun
73641d222f
contractcourt: properly use the broadcast state number during breach remedy 2018-01-22 19:19:58 -08:00
Olaoluwa Osuntokun
5df6704a9c
contractcourt: make synchronous chain watcher notifications optional
In this commit, we modify the way that notifications are dispatched
within the chainWatcher. Before we would *always* wait for an ack back
before we started to clean up he database state. This would at times
lead to deadlocks. To remedy this, we now allow callers to decide if
they want notifications to be sync or not. The only current caller that
requires this is the breach arbiter.
2018-01-22 19:19:58 -08:00
Olaoluwa Osuntokun
783f01e1c7
multi: fix linter warnings 2018-01-22 19:19:56 -08:00
Olaoluwa Osuntokun
3ec83cc82f
peer+contractcourt: delegate watching for co-op closes to the chainWatcher
In this commit, we modify the interaction between the chanCloser
sub-system and the chain notifier all together. This fixes a series of
bugs as before this commit, we wouldn’t be able to detect if the remote
party actually broadcasted *any* of the transactions that we signed off
upon. This would be rejected to the user by having a “zombie” channel
close that would never actually be resolved.

Rather than the chanCloser watching for on-chain closes, we’ll now open
up a co-op close context to the chainWatcher (via a layer of
indirection via the ChainArbitrator), and report to it all possible
closes that we’ve signed. The chainWatcher will then be able to launch
a goroutine to properly update the database state once any of the
possible closure transactions confirms.
2018-01-22 19:19:53 -08:00
Olaoluwa Osuntokun
62f951a969
contractcourt: extend the chainWatcher to be able to detect co-op closes
In this commit, we extend the chainWatcher to be able to automatically
detect co-op closes of the channel. With this change, it’s now fully
encompassed so able to detect all types of closes on-chain. We detect a
co-op close due to the sequence number being finalized, as well as
paying to us directly in a regular p2wkh-like output.
2018-01-22 19:19:52 -08:00
Olaoluwa Osuntokun
0e14ac2063
contractcourt: add new chainWatcher struct
In this commit, we add a new struct to the package, the chainWatcher.
The duty of this struct is to replace the functionality that was
previously implemented by the closeObserver of each channel. Rather
than the source of notification being tied to the lifetime of a
particular object, it’s now delegated to a persistent object that will
be around for the entire lifetime of the channel (until it’s closed).
This will serve to greatly simplify the code, and eliminate a large
class of bugs.
2018-01-22 19:19:48 -08:00