Commit Graph

280 Commits

Author SHA1 Message Date
Joost Jager
462d86d0bb
cnct/test: add unit test for commit sweep resolver 2019-11-14 13:38:06 +01:00
Joost Jager
08c9db9725
cnct: create sweeper interface 2019-11-14 13:38:04 +01:00
Joost Jager
919ab60540
utxonursery: remove unused commit sweep code
Now that the commit sweep resolver is no longer relying on the nursery,
all code associated with commit sweeping can be removed.
2019-11-14 13:38:03 +01:00
Joost Jager
9acb236665
cnct: remove nursery dependency in commit sweep resolver
The channel arbitrator no longer passes the direct commitment output to
the nursery for incubation. Instead the resolver itself will await the
csv lock if any.

The reason to change this now is to prevent having to deal with the
(legacy) nursery code for a planned anchor outputs related change to the
commit sweep resolver (also csv lock to_remote).

It is no problem if there are any lingering incubating outputs at the
time of upgrade. This just means that the output will be offered twice
to the sweeper and this doesn't hurt.
2019-11-14 13:38:01 +01:00
Joost Jager
1597a92160
cnct: add resolver report output type
This commit prepares for the commit sweep resolver to report on its
state.
2019-11-13 10:17:28 +01:00
Joost Jager
55a32c951a
cnct: prefix logger for commit sweep resolver
Unify resolver specific log statements. Leaves modification of
the other resolvers for a later moment when it can be combined with a
real change.
2019-11-13 10:17:24 +01:00
Joost Jager
9d79fea937
cnct: fix incoming resolver assertion 2019-11-13 10:17:22 +01:00
Joost Jager
0d7119a8ca
cnct: parse onion for resolvers
With the introduction of additional payload fields for mpp, it becomes
a necessity to have their values available in the on-chain resolution
flow. The incoming contest resolver notifies the invoice registry of the
arrival of a payment and needs to supply all parameters for the registry
to validate the htlc.
2019-11-12 15:01:39 +01:00
Joost Jager
ede7e5e7ee
cnct: log more info when checking chain actions 2019-11-12 15:01:37 +01:00
Joost Jager
50abb41e94
cnct: store full htlc struct inside resolver
This change prepares for accessing the onion blob from a resolver.
2019-11-12 15:01:36 +01:00
Joost Jager
a83be177c6
cnct: move supplement method into resolvers 2019-11-12 14:55:03 +01:00
Joost Jager
32249cb72e
cnct: add new methods for resolvers 2019-11-11 14:35:30 +01:00
Joost Jager
1e5eec990e
cnct: add new from reader resolver initializers 2019-11-11 14:35:28 +01:00
Joost Jager
ff63a680a1
cnct: instantiate quit channels inside resolvers
Removes a bug-prone construction that existed previously where the quit
channel was replaced just-in-time.
2019-11-07 13:10:35 +01:00
Joost Jager
75ecbfd321
cnct: unexport ResolverKit quit field 2019-11-07 13:10:33 +01:00
Joost Jager
ee14eaec5f
cnct: remove redundant AttachResolverKit call 2019-11-07 13:10:31 +01:00
Joost Jager
53d210d741
cnct: remove unused Decode interface method 2019-11-07 13:10:29 +01:00
Joost Jager
f930dd42a6
cnct/test: add outgoing contest resolver test 2019-11-06 16:07:06 +01:00
Joost Jager
1cb796b9b7
cnct: remove redundant current block fetch
The block notifier now always sends the current block immediately.
2019-11-06 15:53:32 +01:00
Conner Fromknecht
9e9b912d3a
multi: replace NotifyExitHopHtlc eob param with hop.Payload 2019-11-04 15:10:32 -08:00
Olaoluwa Osuntokun
777ed104a3
chainfee: create new chainfee package extracting fees from lnwallet
In this commit, we create a new chainfee package, that houses all fee
related functionality used within the codebase. The creation of this new
package furthers our long-term goal of extracting functionality from the
bloated `lnwallet` package into new distinct packages. Additionally,
this new packages resolves a class of import cycle that could arise if a
new package that was imported by something in `lnwallet` wanted to use
the existing fee related functions in the prior `lnwallet` package.
2019-10-31 16:41:57 -07:00
Olaoluwa Osuntokun
7a491776a1
contractcourt: use legacy chain actions of commitSet not found
In this commit, we fix a bug that would prevent users that had
unresolved contracts at the time of update from starting their nodes.
Before we added the conf commit set, the information needed to
supplement the resolvers was found in the chain action map. As a result,
if the conf commit set is nil, then we also need to check this legacy
data to ensure that we can supplement the resolvers to the best of our
ability based on the available data.

Fixes #3549.
2019-10-04 12:30:55 -07:00
Joost Jager
b58dbb2d70
multi: fix canceled spelling 2019-10-03 17:27:36 +02:00
Olaoluwa Osuntokun
6d97bcbacd
lnwallet+contractcourt: publicly export DeriveCommitmentKeys use in chain watcher
In this commit, we consolidate the number of areas where we derive our
commitment keys. Before this commit, the `isOurCommitment` function in
the chain watcher used a custom routine to derive the expected
scripts/keys for our commitment at that height. With the recent changes,
we now have additional logic in `DeriveCommitmentKeys` that wasn't
copied over to this area. As a result, the prior logic would erroneously
detect if it was our commitment that had hit the chain or not.

In this commit, we remove the old custom code, and use
`DeriveCommitmentKeys` wihtin the chain watcher as well. This ensures
that we only need to maintain the key derivation code in a single place,
preventing future bugs of this nature.
2019-09-25 18:26:13 -07:00
Olaoluwa Osuntokun
d22f2a1936
contractcourt: don't wait for DLP point if commit is tweakless on remote close
In this commit, we update the logic in the `chainWatcher` to no longer
wait until the DLP point has been populated in the database before we
dispatch the force close summary to any registered clients. Instead, we
can sweep immediately, as we have all the information we need to sweep
the funds (just our key).
2019-09-25 18:25:52 -07:00
Olaoluwa Osuntokun
fdec603279
contractcourt: update the commitSweepResolver to be aware of tweakless commits
In this commit, we update the `commitSweepResolver` to be aware of
tweakless commitments. We'll now use the new behavior of the uni close
summary (leaving out the single tweak) to detect if we're dealing with a
new, or modern commitment. Depending on the commitment type, we'll then
set the witness type accordingly so we can generate the proper signature
within the sweeper.
2019-09-25 18:25:49 -07:00
Olaoluwa Osuntokun
0b62126067
multi: update funding workflow to be aware of new tweakless commits
In this commit, we update the funding workflow to be aware of the new
channel type that doesn't tweak the remote party's output within the
non-delay script on their commitment transaction. To do this, we now
allow the caller of `InnitChannelReservation` to signal if they want the
old or new (tweakless) commitment style.

The funding tests are also updated to test both funding variants, as
we'll still need to understand the legacy format for older nodes.
2019-09-25 18:25:46 -07:00
Olaoluwa Osuntokun
c57bb9d86b
Merge pull request #3480 from Roasbeef/proper-resolution-supplements
contractcourt: supplement resolvers with confirmed commit set HTLCs
2019-09-25 17:08:35 -07:00
Olaoluwa Osuntokun
d0df5a4ddd
contractcourt: supplement resolvers with confirmed commit set HTLCs
In this commit, we fix an existing bug in the package, causing
resolutions to be restarted without their required supplementary
information. This can happen if a distinct HTLC set gets confirmed
compared to the HTLCs that we may have had our commitment at time of
close. Due to this bug, on restart certain HTLCS would be rejected as
they would present their state to the invoice registry, but be rejected
due to checks such as amount value.

To fix this, we'll now pass in the set of confirmed HTLCs into the
resolvers when we re-launch them, giving us access to all the
information we need to supplement the HTLCS.

We also add a new test that ensures that the proper fields of a resolver
are set after a restart.
2019-09-25 16:05:25 -07:00
Olaoluwa Osuntokun
c3bf8d2054
contractcourt: create new channel arb test context struct
In this commit, we create a new channel arb test context struct as the
current `createTestChannelArbitrator` has several return parameters, and
upcoming changes will likely at first glance need to add one or more
additional parameters. Rather than extend the existing set of return
parameters, we opt to instead create this struct that wraps the existing
state.

Along the way we add several new utility methods to this context, and
use them in the existing tests where applicable:
  * `AssertStateTransitions`
  * `AssertState`
  * `Restart`
  * `CleanUp`
2019-09-25 16:05:21 -07:00
Johan T. Halseth
2a6ad6e634
channeldb+lnwallet: don't pass isRestoredChan to ChanSyncMsg
Since we have access to the internal state of the channel, we can
instead get it directly instead of passing it in as a parameter.
2019-09-25 14:04:44 +02:00
Johan T. Halseth
2cb80c4449
contractcourt/chain_arbitrator: mark commitment broadcasted before publish
Before publishing the close tx to the network and commit to the
StateCommitmentBroadcasted state, we mark the commitment as broadcasted
and store it to the db. This ensures it will get re-published on startup
if we go down.
2019-09-25 14:04:44 +02:00
Johan T. Halseth
d75feeb953
contractcourt/chain_arbitrator_test: add TestChainArbitratorRepublishCommitment
TestChainArbitratorRepulishCommitment testst that the chain arbitrator
will republish closing transactions for channels marked
CommitementBroadcast in the database at startup.
2019-09-25 14:04:43 +02:00
Johan T. Halseth
425afd28ea
contractcourt/chain_arbitrator: republish closeTx for open channels 2019-09-25 14:04:43 +02:00
Johan T. Halseth
02b2787e44
multi: make MarkCommitmentBroadcasted take closeTx 2019-09-25 14:04:43 +02:00
Johan T. Halseth
eb1b84c0b4
channeldb+lnwallet: make ChanSyncMsg method on OpenChannel 2019-09-25 14:04:42 +02:00
Johan T. Halseth
ce9f7faff2
contractcourt/channel_arbitrator: handle breach channel at startup
Earlier the channel arbitrator would fail to recognize channels pending
close that were in the breached state. This lead to the state machine
not progressing correctly, and in some cases crashing since we would
attempt to force close an already closed channel.

A test TestChannelArbitratorForceCloseBreachedChannel is added to
exercise one of these scenarios.
2019-09-18 13:05:35 +02:00
Johan T. Halseth
26b7ec1b94
contractcourt/channel_arbitrator: define and react to breachClose
Earlier we would not react to breaches, as these are handled by other
subsystems. Now we advances our state machine in case of breach, such
that we'll gracefully exit, and won't have leftover state in case of a
restart.

A simple test TestChannelArbitratorBreachClose to exercise this behavior
is added.
2019-09-18 13:05:35 +02:00
Conner Fromknecht
551693e1b8
Merge pull request #3496 from joostjager/fix-incoming-dust
cnct: do not create an action for incoming dust htlcs
2019-09-16 12:31:37 -07:00
Joost Jager
4e140213f9
htlcswitch+invoices: circuit key based hodl notifications
This commit modifies hodl htlc notification from invoice registry from a
single notification per hash to distinct notifications per htlc. This
prepares for htlc-specific information (accept height) to be added to the
notification.
2019-09-16 10:10:14 +02:00
Conner Fromknecht
72c5d11a1c
Merge pull request #3502 from joostjager/err-returns
multi: fix dropped errors
2019-09-13 11:24:04 -07:00
Joost Jager
be7fc9dd3e
cnct: do not create an action for incoming dust htlcs
This commit fixes the 'unable to find incoming resolution' error that
occured when trying to resolve incoming htlcs below the dust limit that
are not actually present on the commitment tx.
2019-09-13 12:31:26 +02:00
Joost Jager
3131bc4d64
cnct/test: test outgoing dust htlc resolution 2019-09-13 12:31:24 +02:00
Joost Jager
d553c304b2
cnct: log resolver type on error 2019-09-13 12:31:22 +02:00
Joost Jager
1e0ed1e52f
multi: fix dropped errors 2019-09-13 09:50:38 +02:00
Lars Lehtonen
3b29ecb921 routing: Fix dropped errors in tests.
lnd: Fix dropped errors in tests.

contractcourt: Fix dropped errors in tests.

htlcswitch: Fix dropped errors in tests.

invoices: Fix dropped error in tests.

lnwallet: Fix dropped errors in tests.

macaroons: Fix dropped error in tests.
2019-09-13 06:28:05 +00:00
Joost Jager
ecd3c59f7a
cnct: do not log resolver shutting down as error 2019-09-11 15:54:41 +02:00
Joost Jager
3186c0f3a2
cnct: use resolverType type 2019-09-10 17:22:01 +02:00
Joost Jager
3d7de2ad39
multi: remove dead code 2019-09-10 17:21:59 +02:00
Joost Jager
d6d9ec6aa5
invoices: replay awareness
Previously the invoice registry wasn't aware of replayed htlcs. This was
dealt with by keeping the invoice accept/settle logic idempotent, so
that a replay wouldn't have an effect.

This mechanism has two limitations:

1. No accurate tracking of the total amount paid to an invoice. The total
amount couldn't just be increased with every htlc received, because it
could be a replay which would lead to counting the htlc amount multiple
times. Therefore the total amount was set to the amount of the first
htlc that was received, even though there may have been multiple htlcs
paying to the invoice.

2. Impossible to check htlc expiry consistently for hodl invoices. When
an htlc is new, its expiry needs to be checked against the invoice cltv
delta. But for a replay, that check must be skipped. The htlc was
accepted in time, the invoice was moved to the accepted state and a
replay some blocks later shouldn't lead to that htlc being cancelled.
Because the invoice registry couldn't recognize replays, it stopped
checking htlc expiry heights when the invoice reached the accepted
state. This prevents hold htlcs from being cancelled after a restart.
But unfortunately this also caused additional htlcs to be accepted on an
already accepted invoice without their expiry being checked.

In this commit, the invoice registry starts to persistently track htlcs
so that replays can be recognized. For replays, an htlc resolution
action is returned early. This fixes both limitations mentioned above.
2019-09-04 19:20:31 +02:00