Commit Graph

380 Commits

Author SHA1 Message Date
Conner Fromknecht
455ddfebdb
multi: rename: ReadBucket to RBucket 2020-05-26 18:21:08 -07:00
Conner Fromknecht
d0d2ca403d
multi: rename ReadTx to RTx 2020-05-26 18:20:37 -07:00
carla
75370ce6b4
multi: update WalletController PublishTransaction to include label
Add label parameter to PublishTransaction in WalletController
interface. A labels package is added to store generic labels that are
used for the different types of transactions that are published by lnd.

To keep commit size down, the two endpoints that require a label
parameter be passed down have a todo added, which will be removed in
subsequent commits.
2020-05-19 13:30:00 +02:00
Olaoluwa Osuntokun
280bf8d26c
Merge pull request #4226 from breez/fix-chainrpc-crash
Fix crash when ChainNotifier is being accessed too early.
2020-05-15 16:17:40 -07:00
Matheus Degiovani
43b9318b2d contractcourt/commit_sweep_resolver: reduce log msg to warn 2020-05-12 07:46:14 -03:00
Matheus Degiovani
9ed14a50a4 contractcourt: switch to table based testCommitSweepResolverDelay
This improves readability since both instances of the test are very
similar.
2020-05-12 07:46:14 -03:00
Matheus Degiovani
2110bfa40b contractcourt: test sweep of locally breached commit tx
This adds a test to the commit sweeper resolver to ensure it behaves
properly if the local node breaches a channel.

In this situation the remote party is expected to sweep the breached
output to itself and therefore the local party won't be able to recover
any funds.
2020-05-12 07:46:14 -03:00
Matheus Degiovani
d71a4ee033 contractcourt+itest: fix lingering pending channel after breach
This fixes an issue where the contract court could leave a completely
swept commit tx unresolved if it was swept by the remote party.

This could happen if (our) commit tx just published was actually a
previously revoked state, in which case the remote party would claim the
funds via a justice transaction.

This manifested itself in the testRevokedCloseRetribution integration
test where at the end of the test Bob was left with a pending channel
that never resolved itself.
2020-05-12 07:46:14 -03:00
Roei Erez
ae2c37e043 Ensure chain notifier is started before accessed.
The use case comes from the RPC layer that is ready before the
chain notifier which is used in the sub server.
2020-04-30 12:54:33 +03:00
Andras Banki-Horvath
ccf6e2a393 contractcourt: remove redundant return 2020-04-24 19:15:08 +02:00
Conner Fromknecht
0f94b8dc62
multi: return input.Signature from SignOutputRaw 2020-04-10 14:27:35 -07:00
Conner Fromknecht
978ff82f1f
contractcourt/chain_watchter: fix broken log stmts 2020-04-03 15:29:18 -07:00
Olaoluwa Osuntokun
9b39692bb2
contractcourt: add additional logging of commitments at play
In this commit, we add some additional logging of the commitments at
play when we detect a channel closure on-chain. This should help to
debug things more in the future as we don't log the full commitments
anywhere.  We also now also print the type of commitment as well, as a
follow up from the recent anchor outputs work. In the near future, as we
implement a dynamic commitments update protocol, always logging the
commitment type as well will likely be useful for debugging purposes.
2020-04-02 16:46:33 -07:00
Joost Jager
8b7bde7200
cnct: log txid for force close 2020-03-27 07:42:01 +01:00
Olaoluwa Osuntokun
320101d054
contractcourt: convert to use new kvdb abstraction 2020-03-18 19:34:52 -07:00
Joost Jager
ab451f634e
cnct+lnrpc: report anchor resolution 2020-03-18 12:27:03 +01:00
Joost Jager
ea397c9d6e
cnct: resolve anchors post-confirmation
Sweeping anchors and being able to bump the fee was already added in a
previous commit. This commit extends anchor sweeping with an anchor
resolver object that becomes active after the commitment tx confirms.
At that point, the anchors do not serve the purpose of getting the
commitment tranaction confirmed anymore. It is however still possible to
reclaim some of their value if using a low fee rate.
2020-03-18 12:27:01 +01:00
Joost Jager
d84b596f55
cnct: do not ignore resolver reports after resolution
Preparation for anchor resolver. The recovered anchor amount should
still be included in the pending channel report even after it has been
resolved.

This also fixes an existing bug that in some cases caused the recovered
amount from an htlc resolver not to be included in the total.
2020-03-18 12:26:59 +01:00
Joost Jager
07a39b1ebf
cnct: do not persist stateless resolvers
Preparation for the anchor resolver which does not have persistent
state.
2020-03-18 12:26:57 +01:00
Joost Jager
d2b6472843
cnct: pre-confirmation anchor sweep
Start anchor sweep attempts immediately after the commitment transaction
has been published. This makes the anchor known to the sweeper and
allows the user to bump the fee on it to get their commitment
transaction confirmed in case the fee committed too is insufficient for
timely confirmation.
2020-03-18 12:26:55 +01:00
Joost Jager
e8e99c6533
cnct: simplify channel arbitrator state logging 2020-03-17 16:25:39 +01:00
Joost Jager
3b517390d8
cnct+sweeper: give contract court access to relay fee
Relay fee is needed later to sweep anchors at the minimum fee rate.
2020-03-17 16:25:37 +01:00
Joost Jager
dd77d9263e
cnct: persist anchor resolutions 2020-03-17 16:25:33 +01:00
Joost Jager
7f3d4e7d49
cnct: create channel interface for arbitrator
Allows unit testing of the channel arbitrator with fewer dependencies.
This is a preparation for the addition of anchor sweeping.
2020-03-17 16:25:31 +01:00
Joost Jager
c0b1b3be14
cnct: always set trigger height to close height
Prior to this change, the trigger height for closed channels was set to
the current best block height. As this height is in some cases used as a
height hint, the spend may have been missed.
2020-03-17 16:25:29 +01:00
Joost Jager
30fc03d84d
lnwallet/test: pass in test channel type 2020-03-17 14:19:33 +01:00
Johan T. Halseth
92af2342da
lnwallet+nursery+input: set sequence=1 for direct HTLC spends 2020-03-09 12:59:33 +01:00
Johan T. Halseth
bddd3e128c
lnwallet: make second level sigs using sighash single|anyonecanpay 2020-03-09 12:59:33 +01:00
Johan T. Halseth
1f28bd8086
contractcourt/commit_sweep_resolver: set sweep witness type based on witness script
We use the fact that we can tell whether the commit is local or remote
by inspecting the witness script. We cannot use the maturity delay
anymore, as we can have delayed to_remote outputs also now.

Co-authored-by: Joost Jager <joost.jager@gmail.com>
2020-03-09 12:10:59 +01:00
Johan T. Halseth
af68ff1640
lnwallet: add anchor commitmenttype
With this commitment type, we'll add extra anchor outputs to the
commitment transaction if the anchor channel type is active.
2020-03-09 12:10:59 +01:00
carla
4eb3036f67
contractcourt: record force and breach close initiator 2020-02-21 13:53:43 +02:00
carla
c9915e027e
contractcourt/test: replace timeouts with constants 2020-02-21 13:34:26 +02:00
carla
d3cb6ad869
channeldb: store close initiator status
This commit adds two new channel statuses which indicate the party that
initatited closing the channel. These statuses are set in conjunction
with the existing commit broadcast status so that we do not need to
migrate existing logic to handle multiple types of closes. This status
is set for locally initiated force closes in this commit because they
follow a similar pattern to cooparative closes, marking the commitment
broadcast then proceeding with tx broadcast. Remote force closes are
added in the following commit, as they are handled differently.
2020-02-21 13:33:49 +02:00
Olaoluwa Osuntokun
fce472e820
Merge pull request #3876 from breez/allow-timeouted-initiated-htlc
contractcourt: keep channels with timed-out initiated htlcs.
2020-02-17 14:08:44 -08:00
Roei Erez
0407b37fce contractcourt+switch: keep channels with timed-out initiated htlcs.
This commit enables the user to specify he is not interested in
automatically close channels with pending payments that their
corresponding htlcs have timed-out.
By requiring a configurable grace period uptime of our node
before closing such channels, we give a chance to the other node to
properly cancel the htlc and avoid unnecessary on-chain transaction.
In mobile it is very important for the user experience as otherwise
channels will be force closed more frequently.
2020-02-16 09:08:03 +02:00
Johan T. Halseth
99ebe50f4c
contractcourt/chainwatcher: add missing chanpoint log 2020-02-11 13:23:34 +01:00
carla
2569b4d08a
multi: replace htlcResolution with an interface
This commit repalces the htlcResolution struct with an interface.
This interface is implemeted by failure, settle and accept resolution
structs. Only settles and fails are exported because the existing
code that handles htlc resolutions uses a nil resolution to indicate
that a htlc was accepted. The accept resolution is used internally
to report on the resolution result of the accepted htlc, but a nil
resolution is surfaced. Further refactoring of all the functions
that call NotifyExitHopHtlc to handle a htlc accept case (rather than
having a nil check) is required.
2020-02-06 19:41:36 +02:00
Roei Erez
f8da26ee30 contractcourt: change shouldGoOnChain signature.
This commit changes the shouldGoOnChain signature to get the htlc
as parameter. I will allow the function to take decisions based on
whether the htlc is Incoming or Outgoing.
2020-02-03 12:46:21 +02:00
Johan T. Halseth
a56ed72bd7
lnwallet: use channel type to derive remote script
Based on the current channel type, we derive the script used for the
to_remote output. Currently only the unencumbered p2wkh type is used,
but that will change with upcoming channel types.
2020-01-06 12:08:19 +01:00
Johan T. Halseth
5e3718a1b5
lnwallet: use channel type to derive keys
We abstract away how keys are generated for the different channel types
types (currently tweak(less)).

Intention is that more of the logic that is unique for each commitment
type lives in commitment.go, making the channel state machine oblivious
to the keys and outputs being created on the commitment tx for a given
channel state.
2020-01-06 12:08:05 +01:00
Johan T. Halseth
4fde31229c
lnwallet: rename DelayKey->ToLocalKey, NoDelayKey->ToRemoteKey
Since both parties are going to have their ouputs delayed, we move way
from the DelayKey naming, and instead use ToLocalKey and ToRemoteKey.
2020-01-06 12:08:01 +01:00
carla
d2e395d5f2
multi: replace errInvoiceNotFound with resolution result
This commit moves handling of invoice not found
errors into NotifyExitHopHtlc and exposes a
resolution result to the calling functions. The
intention of this change is to make calling
functions as naive of the invoice registry's
mechanics as possible.

When NotifyExitHopHtlc is called and an invoice
is not found, calling functions can take action
based on the HtlcResolution's InvoiceNotFound
outcome rather than having to add a special error
check on every call to handle the error.
2019-12-20 13:01:15 +02:00
carla
7b5dda0417
invoices: add resolution result to htlcResolution
This commit adds the resolution result obtained
while updating an invoice in the registry to
htlcResolution. The field can be used by calling
functions to determine the outcome of the
update and act appropriately.
2019-12-20 13:00:53 +02:00
carla
273cd84355
invoices+contractcourt: add HtlcResolution constructor
This commit adds a constructor for HtlcResolution creation
to enforce provision of all relevant values when an
event is created. A custom construstor which also takes
a preimage is added for settle events.
2019-12-20 13:00:24 +02:00
carla
ebfbc48973
link+contractcourt: rename processHodlEvent to processHtlcResolution 2019-12-20 12:59:56 +02:00
carla
2c44afa3a7
contractcourt: rename mock notifyEvent to notifyResolution 2019-12-20 12:59:14 +02:00
carla
2c1eb17192
mutli: rename HodlEvent to HtlcResolution
This commit renames HodlEvent to HtlcResolution
to better reflect the fact that the struct is
only used for htlc settles and cancels, and that
it is not specifically used for hodl invoices.
2019-12-20 12:58:07 +02:00
Joost Jager
38adfd7ecc
sweep: create sweep parameters struct
Prepares for adding more input-specific sweep parameters.
2019-12-13 12:02:42 +01:00
Conner Fromknecht
b3c28c9cba
contractcourt: generalize rebroadcast for force and coop 2019-12-04 14:25:28 -08:00
Olaoluwa Osuntokun
faa5f340fd
contractcourt: export ResolveContract, update to stop channel arb
In this commit, we export the `ResolveContract` method as it's useful as
a way to manually remove active contracts from the chain and channel
arbitrator. Along the way, we also update the method to also attempt to
stop the channel arb if it exists. This allows an external party to
remove all state with a single call. Before this commit, it was assumed
that this method was only called by the channel arb itself, when it was
already on the way to exiting after all contracts were fully resolved.

We also add a set of unit tests to exercise the intended behavior as
this method is now public.
2019-11-20 17:42:52 -08:00
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