Commit Graph

26 Commits

Author SHA1 Message Date
Johan T. Halseth
9b08ef6d4e
contractcourt/[incoming|outgoing]_contest_resolver: make inner resolver pointer
To make the linter happy, make a pointer to the inner resolver.
Otherwise the linter would complain with

copylocks: literal copies lock value

since we'll add a mutex to the resolver in following commits.
2020-12-10 14:24:19 +01:00
carla
cf739f3f87
contractcourt: persist timed out incoming htlc resolver reports
Incoming htlcs that are timed out or failed (invalid htlc or invoice
condition not met), save a single on chain resolution because we don't
need to take any actions on them ourselves (we don't need to worry
about 2 stage claims since this is the success path for our peer).
2020-07-07 19:49:54 +02:00
Matheus Degiovani
a2a2a301ca contractcourt/incoming_resolver: Improve comments
Small nits on a few comments.
2020-06-05 16:52:48 -03: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
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
ebfbc48973
link+contractcourt: rename processHodlEvent to processHtlcResolution 2019-12-20 12:59:56 +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
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
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
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
ecd3c59f7a
cnct: do not log resolver shutting down as error 2019-09-11 15:54:41 +02:00
Joost Jager
05e6b62cb2
cnct+htlcswitch+invoices: report circuit key to invoice registry
Currently the invoice registry cannot tell apart the htlcs that pay to
an invoice. Because htlcs may also be replayed on startup, it isn't
possible to determine the total amount paid to an invoice.

This commit is a first step towards fixing that. It reports the circuit
keys of htlcs to the invoice registry, which forms the basis for
accurate invoice accounting.
2019-09-04 19:20:13 +02:00
Olaoluwa Osuntokun
23cc8389f2
multi: add TLV awareness to htlcswitch, pass extra EOB to the invoice registry
In this commit, we update the `HopIterator` to gain awareness of the new
TLV hop payload. The default `HopIterator` will now hide the details of
the TLV from the caller, and return the same `ForwardingInfo` struct in
a uniform manner. We also add a new method: `ExtraOnionBlob` to allow
the caller to obtain the raw EOB (the serialized TLV stream) to pass
around.

Within the link, we'll now pass the EOB information into the invoice
registry. This allows the registry to parse out any additional
information from the EOB that it needs to settle the payment, such as a
preimage shard in the AMP case.
2019-08-22 18:53:05 -07:00
Joost Jager
064e8492de
cnct+htlcswitch+invoices: move invoice parameter check out of link
This commit is the final step in making the link unaware of invoices. It
now purely offers the htlc to the invoice registry and follows
instructions from the invoice registry about how and when to respond to
the htlc.

The change also fixes a bug where upon restart, hodl htlcs were
subjected to the invoice minimum cltv delta requirement again. If the
block height has increased in the mean while, the htlc would be canceled
back.

Furthermore the invoice registry interaction is aligned between link and
contract resolvers.
2019-05-15 14:42:12 +02:00
Joost Jager
99e42ddde6
cnct: be stricter about matching preimages
The former tryApplyPreimage function silently ignored invalid preimages.
This could mask potential bugs. This commit makes the logic stricter and
generates an error in case an unexpected mismatch occurs.
2019-05-15 14:41:55 +02:00
Joost Jager
ec6a35d6e8
cnct: do not depend on ChainIO in incoming contest resolver
New behaviour of the chain notifier to always send the current block
immediately after registration takes away the need to make a separate
GetBestBlock call on ChainIO.
2019-05-15 14:41:52 +02:00
Joost Jager
6886a0117f
cnct: always create incoming contest resolver
One of the first things the incoming contest resolver does is checking
if the preimage is available and if it is, convert itself into a success
resolver.

This behaviour makes it unnecessary to already determine earlier in the
process whether an incoming contest or a success resolver is needed.

By having all incoming htlcs go through the incoming contest resolver,
the number of execution paths is reduced and it becomes easier to
ascertain that the implemented logic is correct.

The only functional change in this commit is that a forwarded htlc for
which is the preimage is known, is no longer settled when the htlc is
already expired. Previously a success resolver would be instantiated
directly, skipping the expiry height check.

This created a risk that the success resolver would never finish,
because an expired htlc could already have been swept by the remote
party and there is no detection of this remote spend in the success
resolver currently.

With the new change, the general direction that an expired htlc
shouldn't be settled and instead given up on is implemented more
consistently.

This commit prepares for fixing edges cases related to hodl
invoice on-chain resolution.
2019-05-15 14:41:47 +02: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
Conner Fromknecht
29f07a58cb
cnct+lnwl+hswc: use lntypes.Preimage for witness beacon 2019-02-19 17:06:00 -08: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
4ec3fc3b1a
cnct: split resolvers in separate files 2019-01-16 20:03:59 +01:00