Commit Graph

55 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
c7ca387a9d
Merge pull request #2744 from cfromknecht/disable-before-close
cnct+chancloser: disable channel before closing
2019-03-21 21:08:23 -07:00
Olaoluwa Osuntokun
aa1cd04dbf
Merge pull request #2022 from joostjager/holdinvoice
htlcswitch: hodl invoice
2019-03-15 13:26:53 -07:00
Joost Jager
449c3d533e
contractcourt: add access to full invoice registry from resolvers
Previously a function pointer was passed to chain arbitrator to avoid a
circular dependency. Now that the routetypes package exists, we can pass
the full invoice registry to chain arbitrator.

This is a preparation to be able to use other invoice registry methods
in contract resolvers.
2019-03-15 10:08:35 +01:00
Olaoluwa Osuntokun
48532dc9f6
contractcourt: abstract call to GetStateNumHint within the closeObserver
In this commit, we abstract the call to `GetStateNumHint` within the
`closeObserver` method to a function closure in the primary config. This
allows us to feed in an arbitrary broadcast state number within unit
tests.
2019-03-13 17:31:20 -07:00
Conner Fromknecht
325d77c431
chancloser+cnct: disable channel before closing 2019-03-12 17:34:28 -07:00
Olaoluwa Osuntokun
bc72691806
contractcourt: mark channel as borked before removing the link
In this commit, we ensure that we mark the channel as borked before we
remove the link during the force close process. This ensures that if the
peer reconnects right after we remove the link, then it won't be loaded
into memory in `loadActiveChannels`. We'll now:

  * mark the channel as borked
  * remove the link
  * read the channel state from disk
  * force close

This ensures that the link (if it's active) is able to commit any
pending changes to disk before we read out the channel to force close.
2019-03-08 19:15:08 -08:00
Valentine Wallace
10090a978d contractcourt/chain_arbitrator: notify the ChannelNotifier on newly closed channels. 2019-02-05 18:17:54 -08:00
Olaoluwa Osuntokun
4af857f0c6
Merge pull request #2356 from joostjager/invoices-subserver
invoices: add subscribesingleinvoice
2019-02-01 17:19:58 -08:00
Joost Jager
bacd92418a
invoices: use lntypes.Hash and lntypes.Preimage
Previously chainhash.Hash was used, which converts to/from string in
reversed format. Payment hashes and preimages are supposed to be
non-reversed.
2019-02-01 09:42:29 +01:00
Joost Jager
55aee9c703
cnct: expose non-incubating htlcs after channel force close
In this commit we fix a reporting gap that previously existed for htlcs
that were still contested.
2019-02-01 09:36:47 +01:00
Joost Jager
9e012ecc93
multi: move Input interface and related code
This commit is a step to split the lnwallet package. It puts the Input
interface and implementations in a separate package along with all their
dependencies from lnwallet.
2019-01-31 13:25:33 +01:00
Olaoluwa Osuntokun
4fd1f832d7
contractcourt+rpc: use new FetchChannel method instead of scanning
In this commit, we modify areas where we need to force close a channel
to use the new FetchChannel method instead of manually scanning. This
dramatically reduces the CPU usage when doing things like closing a
large number of channels within lnd.
2019-01-28 20:24:45 -08:00
Wilmer Paulino
41f638c7cf
contractcourt+server: settle invoice for on-chain HTLC sweep
In this commit, we extend the htlcSuccessResolver to settle the invoice,
if any, of the corresponding on-chain HTLC sweep. This ensures that the
invoice state is consistent as when claiming the HTLC "off-chain".
2019-01-22 20:46:14 -08:00
Olaoluwa Osuntokun
fa160f559c
multi: replace per channel sigPool with global daemon level sigPool
In this commit, we remove the per channel `sigPool` within the
`lnwallet.LightningChannel` struct. With this change, we ensure that as
the number of channels grows, the number of gouroutines idling in the
sigPool stays constant. It's the case that currently on the daemon, most
channels are likely inactive, with only a hand full actually
consistently carrying out channel updates. As a result, this change
should reduce the amount of idle CPU usage, as we have less active
goroutines in select loops.

In order to make this change, the `SigPool` itself has been publicly
exported such that outside callers can make a `SigPool` and pass it into
newly created channels. Since the sig pool now lives outside the
channel, we were also able to do away with the Stop() method on the
channel all together.

Finally, the server is the sub-system that is currently responsible for
managing the `SigPool` within lnd.
2018-12-16 15:40:14 -08:00
Joost Jager
c1d845aa0d
cnct: reuse sweep tx logic for commit resolver
Removes duplicate sweep tx code from commit resolver
and delegates generation to UtxoSweeper in the sweep
package.
2018-10-17 12:44:34 +02:00
Johan T. Halseth
3a67fe2552
contractcourt+server: make IncubateOutputs take broadcastHeight 2018-09-20 12:54:48 +02:00
Conner Fromknecht
0c74575c44
contractcourt/chain_arbitrator: parallel chain watcher start
This commit restructures the initialization procedure
for chain watchers such that they can proceed in parallel.
This is primarily to help nodes running with the neutrino
backend, which otherwise forces a serial rescan for each
active channel to check for spentness.

Doing so allows the rescans to take advantage of batch
scheduling in registering for the spend notifications,
ensuring that only one or two passes are made, as opposed
to one for each channel.

Lastly, this commit ensures that the chain arb is properly
shutdown if any of it's chain watchers or channel arbs
fails to start, so as to cancel their goroutines before
exiting.
2018-09-11 16:10:29 -07:00
Johan T. Halseth
1758ad829f
contractcourt/[chain|channel]_arbitrator: define IsPendingClose 2018-08-23 00:03:22 +02:00
Johan T. Halseth
3549f2bc17
contractcourt/[channel|chain]_arbitrator: define MarkChannelClosed 2018-08-22 23:51:04 +02:00
Valentine Wallace
1ffc3bb82e
multi: update to latest RegisterBlockEpochNtfn interface 2018-08-10 01:08:57 -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
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
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
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
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
1c43a0cb36
contractcourt/chain_arbitrator: delete watcher from activeWatchers 2018-06-21 11:13:46 +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
8afc7bf66e
contractcourt/chain_arbitrator: add TODO for removing watchForChannelClose 2018-05-24 10:24:31 +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
21d1cc3fe8
contractcourt/chain_arbitrator: remove BeginCoopChanClose 2018-05-22 12:06:33 +02:00
Olaoluwa Osuntokun
9dcd98ad9c
contractcourt: prevent scoping bug by re-binding channel pointer
In this commit, we attempt to fix a bug that's possible within the
Start() method of the ChainArbiter. We pass the channel pointer directly
into the newActiveChannelArbitrator function causing it to close over
the loop variable. We later use the channel point directly to send
messages to other sub-systems. It's possible that we actually have the
shadowed loop variable and will send an incorrect message. Defensively,
we now re-bind the loop variable in order to ensure we point to the
proper channel.
2018-05-18 16:21:06 -07:00
Conner Fromknecht
f963f91a3c
multi: use mutex-guarded ShortChanID() on OpenChannel 2018-05-09 16:06:49 -07:00
Johan T. Halseth
f06797ab00
contractcourt/chain_arbitrator: make breachArbiter handoff a function closure
This commit adds the new function closure option ContractBreach to the
ChainArbitrator config, a closure that is again used by the ChainWatcher
to reliably handoff a breach event to the breachArbiter.
2018-05-02 08:43:31 +02:00
Johan T. Halseth
a6f0dd72ac
contractcourt/chain_arbitrator: use chainWatcherConfig 2018-05-02 08:43:31 +02:00
Johan T. Halseth
84f06959f3
contractcourt/chain_arbitrator: remove CloseChannel method from ChannelArbitrator config 2018-04-25 09:37:25 +02:00
Johan T. Halseth
1265c9cc99
contractcourt/chain_arbitrator: add MarkCommitmentBroadcasted to ChanArb cfg 2018-04-25 09:37:24 +02:00
practicalswift
663c396235 multi: fix a-vs-an typos 2018-04-17 19:02:04 -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
Johan T. Halseth
8e77e1e6eb
lnwallet/channel: add NewLocalForceCloseSummary
This commit renames ForceCloseSummary to LocalForceCloseSummary, and
adds a new method NewLocalForceCloseSummary that can be used to derive a
LocalForceCloseSummary if our commitment transaction gets confirmed
in-chain. It is meant to accompany the NewUnilateralCloseSummary method,
which is used for the same purpose in the event of a remote commitment
being seen in-chain.
2018-04-06 09:46:30 +02:00
Johan T. Halseth
8b02064c7b
multi: provide mempool=true to RegisterSpendNtfn 2018-04-03 11:24:07 +02: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
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
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