Commit Graph

33 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
a0fe4fb716
Merge pull request #968 from halseth/chanarb-doublespend
contractcourt/channel_arbitrator: ignore ErrDoubleSpend on force close
2018-03-29 16:11:38 -07:00
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
Olaoluwa Osuntokun
800eea931f
build+multi: switch from bolt to bbolt
In this commit, we switch from boltbd/bolt to coreos/bbolt as the
former is no longer being actively maintained.
2018-03-10 19:01:13 -08:00
Olaoluwa Osuntokun
dc2404f289
contractcourt: update test due to recent SignDescriptor API changes 2018-03-06 16:04:06 -05:00
Olaoluwa Osuntokun
4b20e805fe
multi: update packages due to recent SignDescriptor and WalletController changes 2018-03-06 16:04:03 -05: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
2ae1b7dbbe
contractcourt: remove TODO for checking double spends from PublishTx 2018-02-14 12:34:41 +01:00
Daniel McNally
8543497dcc multi: fixing it's/its typos in comments 2018-02-06 19:13:07 -08:00
practicalswift
a93736d21e multi: comprehensive typo fixes across all packages 2018-02-06 19:11:11 -08:00
Olaoluwa Osuntokun
2099d6fa77
contractcourt: ensure we always cancel block epoch notifications after use
In this commit, we fix an existing grouting leak within the contract
court package. If a goroutine dies, but it doesn’t actually cancel the
block epoch notification that it requested, then it’s possible to leak
thousands of gorutines. To remedy this situation, we ensure that we’ll
*always* cancel the epoch notification once the goroutine has exited.
2018-02-05 14:41:08 -08:00
Olaoluwa Osuntokun
2d104b7ec0
test: wait for 2 transactions to enter mempool at the end of testMultiHopHtlcRemoteChainClaim
In this commit, we fix an existing flake on Travis related to the new
set of on-chain HTLC tests. In this timing flake, Bob would broadcast
his sweeping transaction, but *mid block mining*. As a result, the
output would never be properly swept, needing an additional block to be
mined. We’ll now wait for both Bob’s sweeping transaction, and Carol’s
sweep transaction to be confirmed before we attempt our assertions.
2018-01-23 19:05:36 -08:00
Olaoluwa Osuntokun
5dc0d669a6
contractcourt: watch proper output within htlcOutgoingContestResolver
In this commit, we fix an existing bug in the implementation of the
resolution of the htlcOutgoingContestResolver. Before this commit, we
would _always_ watch the claim outpoint. However, if this is on the
remote party’s commitment transaction, then we would end up watching
the wrong output. We’ll now properly detect this by modifying which
output we watch, based on if we have a second level transaction or not.
2018-01-23 14:16:22 -08:00
Olaoluwa Osuntokun
f8adab1f1c
test: add comprehensive integration tests for on-chain HTLC handling
In this commit, we add 6 new integration tests to test the various
actions that may need to be performed when either side goes on-chain to
fully resolve HTLC’s. Many of the tests are mirrors of each other as
they test sweeping/resolving HTLC’s from both commitment transactions.
2018-01-22 19:20:02 -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
91d45b37ba
contractcourt: on startup, launch a goroutine to finalize co-op chan close if needed 2018-01-22 19:19:54 -08:00
Olaoluwa Osuntokun
db2b9fd9ff
contractcourt: remove the existing ManuallyResolveChannel methiod
We’re removing this method as it’s no longer needed, since the
chainWatcher will properly handle on-chain co-op closes.
2018-01-22 19:19:54 -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
bbca53507f
contractcourt: extend the ChainArbitratorConfig with IsOurAddress closure
In this commit, we add the IsOurAddress field into the config of the
chain arb. With this new function closure, the chain arb is able to
detect co-op on chain closes automatically.
2018-01-22 19:19:53 -08:00
Olaoluwa Osuntokun
bdbb33344a
contractcourt: extend resolveContract to also stop any active chainWatcher 2018-01-22 19:19:52 -08:00
Olaoluwa Osuntokun
723bfb0eac
contractcourt: channel arbitrators now exit on co-op close of the channel 2018-01-22 19:19:52 -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
b5ae0855d2
contractcourt: add new SubscribeChannelEvents method to ChainArbitrator
In this commit, we add a new method to allow external sub-systems to
gain an intent to receive notifications once an on-chain event happens.
This will be used in place of the old channel signals directly on the
channel state machine object in a series of follow up commits.
2018-01-22 19:19:49 -08:00
Olaoluwa Osuntokun
754d1c1c38
contractcourt: when handling a remote force close, use their view of the HTLC's 2018-01-22 19:19:49 -08:00
Olaoluwa Osuntokun
63f7bf4e65
contractcourt: integrate notifications of the chainWatcher with each channel arb
In this commit, we modify the construction of the channel arbitrator to
accept a pointer to an event stream from the chain watcher that’s been
assigned to that channel. As a result, we no longer need a fresh
unilateral close signal, as the one we get from the chain watcher will
*always* be up to date.

For each active channel, we’ll now create a chainWatcher instance that
will be around until the channel is fully closed on chain.
2018-01-22 19:19:48 -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
Olaoluwa Osuntokun
31aa7265b7
contractcourt: add new ChainArbitrator struct as central coordinator of package
In this commit, we add the ChainArbitrator struct. The ChainArbitrator
is a special sub-system that will oversee the on-chain resolution of
all active channels, and also channels that are in the pending close
state. The ChainArbitrator maintains a set of ChannelArbitrators, one
for each channel that hasn’t yet been fully resolved.

Outside sub-systems should send new channels to the arbitrator once
they’ve opened. Additionally, they can also trigger manual
interventions to close out a channel on chain forcibly, or just to
signal that a channel has been closed cooperatively.

Finally, (for now) the ChainArbitrator should be notified once a fresh
set of signals for a channel becomes available. The ChannelArbitrator
for the channel will use these set of signals to be notified when an
on-chain event happens.
2018-01-22 19:19:36 -08:00
Olaoluwa Osuntokun
09b6bee8d4
contractcourt: add complete ContractResolver implementations
In this commit, we introduce a new interface, the ContractResolver. The
duty of a ContractResolver is to watch a contract on-chain, for all
possible transitions, and exit finally when the contract has been fully
resolved. Resolvers themselves can be recursive: meaning producing
another resolver to hand off the duties require to fully resolve a
contract.

Each resolver also has a ResolverKit which contains all the function
closures and interfaces that the resolver need to properly do its job.

The 5 types of resolvers are:
  * outgoing HTLC timeout
  * outgoing HTLC contested
  * incoming HTLC know presage
  * incoming HTLC contested (don’t yet know)
  * commitment sweep

In the future, more advanced resolver types can be added as required.
2018-01-22 19:19:36 -08:00
Olaoluwa Osuntokun
701eb9d4f4
contractcourt: add new briefcase.go file to house persistent arbitrator state
In this commit, we add a new file: briefcase.go. The contents of this
file are the ArbitratorLog. This log will be used by the internal state
machine of each Channel Arbitrator to ensure that each state transition
is fully reflected on-disk, to ensure that the state machine is durable
and able to survive restarts.

This commit also adds a new implementation of the ArbitratorLog
interface backed by boltdb.
2018-01-22 19:19:35 -08:00
Olaoluwa Osuntokun
d64ffcb6c8
contractcourt: add new ChannelArbitrator struct
In this commit, we add the primary struct of the package with a full
implementation. The duty of the ChannelArbitrator is to watch the set
of active contracts on a comment transaction and act accordingly if any
of their redemption criteria have been met. Potential criteria include:
an HTLC about to time out, and HTLC about to time out that we know the
preiamge to, or the remote party going to chain (forcing us to resolve
all pending contracts on chain).

The primary goroutine of this struct implements a persistent state
machine in order to ensure that mid contract resolution, we’re able to
properly survive restarts without losing our place, or forgetting about
a pending contract.

A ChannelArbitrator will stay alive until all contracts have been fully
resolved. This means that outside sub-systems no longer need to worry
about remembering to mark a channel as fully resolved, as it’s the job
of the ChannelArbitrator to do this task.
2018-01-22 19:19:34 -08:00
Olaoluwa Osuntokun
71009438b6
contractcourt: create new package, add logger 2018-01-22 19:19:34 -08:00