Commit Graph

197 Commits

Author SHA1 Message Date
Joost Jager
86eb0a3383
cnct: log go to chain reason
This commit adds logging of the reason to go to chain for a channel.
This can help users to find out the reason why a channels forced closed.

To get all go to chain reasons, an optimization to break early is
removed. This optimization was not significant, because the normal flow
already examined all htlcs. In the exceptional case where we need to go
to chain, it does not weigh up against logging all go to chain reasons.
2019-04-08 10:34:41 +02:00
Joost Jager
ab4da0f53d
cnct: define separate broadcast delta for outgoing htlcs
This commits exposes the various parameters around going to chain and
accepting htlcs in a clear way.

In addition to this, it reverts those parameters to what they were
before the merge of commit d1076271456bdab1625ea6b52b93ca3e1bd9aed9.
2019-04-05 11:36:07 +02:00
Olaoluwa Osuntokun
893cff60c4
Merge pull request #2839 from joostjager/htlc-expiry-check
link: increase expiry grace delta for exit hop and forwarded htlcs
2019-04-01 18:15:56 -07:00
Olaoluwa Osuntokun
26f6fd7db2
contractcourt: ignore all other dispatch cases in closeObserver when recovered chan
In this commit, we modify the `closeObserver` to fast path the DLP
dispatch case if we detect that the channel has been restored. We do
this as otherwise, we may inadvertently enter one of the other cases
erroneously, causing us to now properly look up their dlp commitment
point.
2019-03-28 17:54:00 -07:00
Olaoluwa Osuntokun
c722f2c064
contractcourt: only look for local force close for non-recovered channel
In this commit, we modify the main `closeObserver` dispatch loop to only
look for the local force close if we didn't recover the channel. We do
this, as for a recovered channel, it isn't possible for us to force
close from a recovered channel.
2019-03-28 17:53:59 -07:00
Olaoluwa Osuntokun
b491488c6f
contractcourt: update to new ChanSyncMsg API, reflow comments where needed 2019-03-28 17:53:57 -07:00
Jim Posen
d107627145
contractcourt: remove broadcastRedeemMultiplier
The multiplier doesn't make sense because funds may be equally at risk
by failing to broadcast to chain regardless of whether the HTLC is a
redeem or a timeout.
2019-03-26 14:31:51 +01:00
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
db411c244e
contractcourt: add new set of tests in htlcTimeoutResolver to exercise refactorings 2019-03-19 16:50:28 -07:00
Olaoluwa Osuntokun
6b24b6dabd
contractcourt: simplify htlcTimeoutResolver, unify with HTLC contest logic
In this commit, we simplify the existing `htlcTImeoutResolver` with some
newly refactored out methods from the `htlcTimeoutContestResolver`. The
resulting logic is easier to follow as it's more linear, and only deals
with spend notifications rather than both spend _and_ confirmation
notifications.
2019-03-19 16:50:27 -07:00
Olaoluwa Osuntokun
e1a07b68e8
contractcourt: extract which timeout HTLC output to watch into new method 2019-03-19 16:50:09 -07:00
Olaoluwa Osuntokun
b078cea83f contractcourt: move claimCleanUp from contest resolver to timeout 2019-03-19 16:49:56 -07:00
Olaoluwa Osuntokun
aa1cd04dbf
Merge pull request #2022 from joostjager/holdinvoice
htlcswitch: hodl invoice
2019-03-15 13:26:53 -07:00
Olaoluwa Osuntokun
5ef95a51dc
Merge pull request #2766 from Roasbeef/chain-watcher-fix-off-by-one
contractcourt: fix off-by-one error in closeObserver
2019-03-15 13:26:08 -07:00
Joost Jager
32f2b047e8
htlcswitch: hodl invoice
This commit modifies the invoice registry to handle invoices for which
the preimage is not known yet (hodl invoices). In that case, the
resolution channel passed in from links and resolvers is stored until we
either learn the preimage or want to cancel the htlc.
2019-03-15 10:09:17 +01:00
Joost Jager
1f41a2abce
htlcswitch: abtract invoice from link
This commit detaches signaling the invoice registry that an htlc was
locked in from the actually settling of the htlc.

It is a preparation for hodl invoices.
2019-03-15 10:09:15 +01: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
Wilmer Paulino
7946d0a256
multi: remove ErrDoubleSpend check for PublishTransaction
In this commit, we address a lingering issue within some subsystems that
are responsible for broadcasting transactions. Previously,
ErrDoubleSpend indicated that a transaction was already included in the
mempool/chain. This error was then modified to actually be returned for
conflicting transactions, but its callers were not modified accordingly.
This would lead to conflicting transactions to be interpreted as valid,
when they shouldn't be.
2019-03-13 17:57:19 -07:00
Olaoluwa Osuntokun
6983a9e146
contractcourt: fix off-by-one error in closeObserver case
In this commit, we fix an off-by-one error when handling force closes
from the remote party. Before this commit, if the remote party
broadcasts state 2, and we were on state 1, then we wouldn't act at all.
This is due to an extraneous +1 in the comparison, causing us to only
detect this DLP case if the remote party's state is two beyond what we
know atm. Before this commit, the test added in the prior commit failed.
2019-03-13 17:31:23 -07:00
Olaoluwa Osuntokun
795c9f1550
contractcourt: add new TestChainWatcherDataLossProtect test case
In this commit, we add a new test case to exercise the way we handle the
DLP detection and dispatch within the chain watcher. Briefly, we use
the `testing/quick` package to ensure that the following invariant is
always held: "if we do N state updates, then state M is broadcast, iff M
> N, we'll execute the DLP protocol". We limit the number of iterations
to 10 for now, as the tests can take a bit of time to execute, since it
actually does proper state transitions.
2019-03-13 17:31:21 -07: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
Joost Jager
f23fdf95e7
cnct: fix error returning bug
The wrong error variable was returned, causing a resolution failure to
be interpreted by the channel arbitrator as a success.
2019-02-26 12:56:21 -03:00
Conner Fromknecht
29f07a58cb
cnct+lnwl+hswc: use lntypes.Preimage for witness beacon 2019-02-19 17:06:00 -08:00
Conner Fromknecht
30f61b7630
multi: make AddPreimage variadic, optimistically compute key
In this commit, we modify the WitnessCache's
AddPreimage method to accept a variadic number
of preimages. This enables callers to batch
preimage writes in performance critical areas
of the codebase, e.g. the htlcswitch.

Additionally, we lift the computation of the
witnesses' keys outside of the db transaction.
This saves us from having to do hashing inside
and blocking other callers, and limits extraneous
blocking at the call site.
2019-02-19 17:05:04 -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
8aecccf266
Merge pull request #2407 from joostjager/commit-resolver-sweeper
cnct: use sweeper in commit resolver
2019-02-01 17:34:51 -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
e486340106
cnct: use sweeper in commit resolver
Now that the sweeper is available, it isn't necessary anymore for the
commit resolver to craft its own sweep tx. Instead it can offer its
input to the sweeper and wait for the outcome.
2019-02-01 09:20:45 +01:00
Joost Jager
9abe06f3c8
cnct: finish channel arbitrator in StateFullyResolved
Previously the arbitrator wasn't advanced to the final stage after
the last contract resolved.

Also channel arbitrator now does not ignore a log error anymore
unresolved contracts cannot be retrieved.
2019-02-01 09:10:04 +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
Wilmer Paulino
974e0f2df5
cnct: make original htlc amt available for contract resolvers
Previously, contract resolvers that needed to publish a second level tx,
did not have access to the original htlc amount.

This commit reconstructs this amount from data that is already persisted
in arbitrator log.

Co-authored-by: Joost Jager <joost.jager@gmail.com>
2019-01-22 20:47:17 -08:00
Wilmer Paulino
93754f8d37
lnwallet: add HtlcPoint() resolution helper methods
Co-authored-by: Joost Jager <joost.jager@gmail.com>
2019-01-22 20:47:13 -08:00
Wilmer Paulino
865f7568d6
cnct: extract relaunching of resolvers to method
Co-authored-by: Joost Jager <joost.jager@gmail.com>
2019-01-22 20:46:14 -08:00
Joost Jager
4ec3fc3b1a
cnct: split resolvers in separate files 2019-01-16 20:03:59 +01:00
Olaoluwa Osuntokun
509bed614c
Merge pull request #2198 from Roasbeef/sendall-rpc
multi: add ability to sweep all coins in the the wallet to an addr to sendcoins
2019-01-15 14:49:17 -08:00
Olaoluwa Osuntokun
400a1d3282
Merge pull request #2431 from cfromknecht/keyring-remote-delay-retribution
lnwallet: Add keyring and remote CSV delay to BreachRetribution
2019-01-11 15:33:16 -08:00
Conner Fromknecht
eb2f5cecf6
multi: remove breach tx arg from NewBreachRetribution args
This commit removes the breach transaction from the
arguments passed to NewBreachRetribution. We already
keep all prior remote commitments on disk in the
commitment log, and load that transaction from disk
inside the method. In practice, the one loaded from
disk will be the same one that is passed in by the
caller, so there should be no change in behavior
as we've already derived the appropriate state number.

This changes makes integration with the watchtower
client simpler, since we no longer need to acquire
the breaching commitment transaction to be able to
construct the BreachRetribution. This simplifies
not only the logic surrounding transient backsups,
but also on startup (and later, retroactively
backing up historic updates).
2019-01-10 13:13:38 -08:00
Olaoluwa Osuntokun
73c9c2ee15
sweep+cnct+nursery+rpc: extract DetermineFeePerKw to func, add FeePreference
In this commit, we extract the existing determineFeePerKw method on the
RPC server into a new file in the sweep package. Along the way, we
consolidate code by introducing a new FeePreference struct, which allows
the caller to express their fee preference either in blocks to
confirmation, or a direct fee rate. This move takes a small step to
father decoupling calls in the main RPC server.
2019-01-09 15:55:17 -08:00
Conner Fromknecht
088fb33718
contractcourt: nil keyring curves on breach info 2019-01-07 17:15:45 -08:00
Joost Jager
687d4e7725
cnct: add todo comment for sweeper 2018-12-18 10:50:22 +01:00
Joost Jager
e43e89514f
sweep+utxonursery+cnct+breacharbiter: add height hint to input
This commit is a preparation for the implementation of remote spend
detection. Remote spends may happen before we broadcast our own sweep
tx. This calls for accurate height hints.
2018-12-18 10:50:11 +01:00
Olaoluwa Osuntokun
febe6cd47f
Merge pull request #2131 from wpaulino/force-close-same-channel
contractcourt/chain_arbitrator: prevent force closing same channel twice
2018-12-17 21:23:57 -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
Wilmer Paulino
60036aca1d
contractcourt/channel_arbitrator: prevent force closing same channel twice
In this commit, we prevent the ChainArbitrator from sending a force
close request for a channel if it has previously already sent one. We do
this to prevent blocking the caller of ForceCloseContract.
2018-12-10 20:37:58 -08:00