Skip to content

Commit 216914d

Browse files
morehouset-bast
authored andcommitted
Check for preimage before failing back missing HTLCs
When an outstanding HTLC is missing from a confirmed commitment, the current recommendation is to fail it back immediately (or after a reorg-safety delay). But if a preimage is available for the HTLC, failing it back is at best going to cause an error (if the HTLC has already been fulfilled upstream) and at worst going to cause loss of funds (if the HTLC has *not* already been fulfilled upstream). Instead, the spec should clearly indicate that upstream HTLCs should be fulfilled when possible and only failed back if a preimage is not available.
1 parent a09564a commit 216914d

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

05-onchain.md

+43-21
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,14 @@ A node:
254254
before spending that HTLC-timeout output.
255255
- for any committed HTLC that does NOT have an output in this commitment
256256
transaction:
257-
- once the commitment transaction has reached reasonable depth:
258-
- MUST fail the corresponding incoming HTLC (if any).
259-
- if no *valid* commitment transaction contains an output corresponding to
260-
the HTLC.
261-
- MAY fail the corresponding incoming HTLC sooner.
257+
- if the payment preimage is known:
258+
- MUST fulfill the corresponding incoming HTLC (if any).
259+
- otherwise:
260+
- once the commitment transaction has reached reasonable depth:
261+
- MUST fail the corresponding incoming HTLC (if any).
262+
- if no *valid* commitment transaction contains an output corresponding to
263+
the HTLC:
264+
- MAY fail the corresponding incoming HTLC sooner.
262265

263266
### Rationale
264267

@@ -281,12 +284,21 @@ detailed in
281284
If the incoming HTLC is also on-chain, a node must simply wait for it to
282285
timeout: there is no way to signal early failure.
283286

284-
If an HTLC is too small to appear in *any commitment transaction*, it can be
285-
safely failed immediately. Otherwise, if an HTLC isn't in the *local commitment
286-
transaction*, a node needs to make sure that a blockchain reorganization, or
287-
race, does not switch to a commitment transaction that does contain the HTLC
288-
before the node fails it (hence the wait). The requirement that the incoming
289-
HTLC be failed before its own timeout still applies as an upper bound.
287+
There are several reasons a committed HTLC may not have an output in the
288+
confirmed commitment transaction: the HTLC may be smaller than
289+
`dust_limit_satoshis`, the HTLC may not have been added to the commitment
290+
transaction yet, or the HTLC may have already been failed or fulfilled. In any
291+
case, if the payment preimage is known for the HTLC, the upstream HTLC needs to
292+
be fulfilled to avoid loss of funds.
293+
294+
If the payment preimage is not known for the missing HTLC, the correct action
295+
depends on the possibility of a blockchain reorganization that swaps out the
296+
confirmed commitment transaction for one with the HTLC present.
297+
If the HTLC is too small to appear in *any commitment transaction*, such a
298+
reorganization is not possible, and the HTLC can be safely failed immediately.
299+
Otherwise, a reorganization delay is required before failing the incoming HTLC.
300+
The requirement that the incoming HTLC be failed before its own timeout still
301+
applies as an upper bound.
290302

291303
## HTLC Output Handling: Local Commitment, Remote Offers
292304

@@ -406,12 +418,14 @@ A local node:
406418
- MUST *resolve* the output, by spending it to a convenient address.
407419
- for any committed HTLC that does NOT have an output in this commitment
408420
transaction:
409-
- once the commitment transaction has reached reasonable depth:
410-
- MUST fail the corresponding incoming HTLC (if any).
421+
- if the payment preimage is known:
422+
- MUST fulfill the corresponding incoming HTLC (if any).
411423
- otherwise:
424+
- once the commitment transaction has reached reasonable depth:
425+
- MUST fail the corresponding incoming HTLC (if any).
412426
- if no *valid* commitment transaction contains an output corresponding to
413427
the HTLC:
414-
- MAY fail it sooner.
428+
- MAY fail the corresponding incoming HTLC sooner.
415429

416430
### Rationale
417431

@@ -437,13 +451,21 @@ back-fail any corresponding incoming HTLC, using `update_fail_htlc`
437451
If the incoming HTLC is also on-chain, a node simply waits for it to
438452
timeout, as there's no way to signal early failure.
439453

440-
If an HTLC is too small to appear in *any commitment transaction*, it
441-
can be safely failed immediately. Otherwise,
442-
if an HTLC isn't in the *local commitment transaction* a node needs to make sure
443-
that a blockchain reorganization or race does not switch to a
444-
commitment transaction that does contain it before the node fails it: hence
445-
the wait. The requirement that the incoming HTLC be failed before its
446-
own timeout still applies as an upper bound.
454+
There are several reasons a committed HTLC may not have an output in the
455+
confirmed commitment transaction: the HTLC may be smaller than
456+
`dust_limit_satoshis`, the HTLC may not have been added to the commitment
457+
transaction yet, or the HTLC may have already been failed or fulfilled. In any
458+
case, if the payment preimage is known for the HTLC, the upstream HTLC needs to
459+
be fulfilled to avoid loss of funds.
460+
461+
If the payment preimage is not known for the missing HTLC, the correct action
462+
depends on the possibility of a blockchain reorganization that swaps out the
463+
confirmed commitment transaction for one with the HTLC present.
464+
If the HTLC is too small to appear in *any commitment transaction*, such a
465+
reorganization is not possible, and the HTLC can be safely failed immediately.
466+
Otherwise, a reorganization delay is required before failing the incoming HTLC.
467+
The requirement that the incoming HTLC be failed before its own timeout still
468+
applies as an upper bound.
447469

448470
## HTLC Output Handling: Remote Commitment, Remote Offers
449471

0 commit comments

Comments
 (0)