lnd/htlcswitch
ziggie b32e432e0b
htlcswitch: track held HTLC source
Store held forwards as off-chain or on-chain entries instead of a raw
InterceptedForward map. Off-chain entries keep the existing resume, fail,
settle and auto-fail behavior. On-chain entries are settle-only and
expire by pruning local interceptor state.

When contractcourt re-offers a circuit that is already held off-chain,
replace the stored entry with the on-chain forward so a later SETTLE
reaches the witness beacon instead of the old link mailbox path.

Also set the on-chain interceptor deadline to the HTLC refund timeout.
This keeps the public interceptor deadline populated while ensuring only
off-chain held entries use that value to fail back.

Only off-chain held HTLCs can be released when an optional interceptor
disconnects, because they can resume into the link forwarding flow.

On-chain held HTLCs have no link flow to resume. Keep them in the held
set so a reconnecting interceptor can replay and settle them while
contractcourt waits for the preimage or on-chain expiry.

Use distinct internal deadline types for off-chain auto-fail heights and
on-chain settlement deadlines instead of overloading the intercepted packet
field.

Project both variants back into the existing router RPC auto_fail_height
field to preserve wire compatibility. Reject mismatched held HTLC deadline
types in tests.

On-chain intercepted HTLCs can only be settled. Resume and fail actions
already return concrete errors through the on-chain intercepted forward, so
let those errors propagate to the interceptor client instead of converting
them to success.

Keep the held entry tracked on these errors so the client can reconnect and
settle the HTLC later.

(cherry picked from commit eb1193f80b)
2026-06-26 14:29:23 -03:00
..
hodl multi: add golang 1.17 compatible build tags 2021-09-29 17:31:37 -07:00
hop htlcswitch: fix outgoing cltv spelling 2026-06-26 07:58:48 -03:00
testdata multi: update linter, fix new issues 2023-06-13 11:58:33 +02:00
circuit.go multi+refactor: move models package to graph/db 2024-11-28 13:34:33 +02:00
circuit_map.go multi: use the "errors" package everywhere 2025-06-30 09:46:55 +02:00
circuit_map_test.go multi: fix fmt.Errorf error wrapping 2024-02-27 11:13:40 +00:00
circuit_test.go multi: rename chan DB Open method to OpenForTesting 2024-11-28 13:51:15 +02:00
decayedlog.go htlcswitch: remove batchReplayBkt 2025-06-17 11:39:38 +08:00
decayedlog_test.go htlcswitch: use T.TempDir to create temporary test directory 2022-08-24 09:03:01 +08:00
failure.go htlcswitch: add linkError field to htlcpacket 2020-02-06 19:43:29 +02:00
failure_detail.go htlcswitch: add linkError field to htlcpacket 2020-02-06 19:43:29 +02:00
failure_test.go multi: update linter, fix new issues 2023-06-13 11:58:33 +02:00
held_htlc_set.go htlcswitch: track held HTLC source 2026-06-26 14:29:23 -03:00
held_htlc_set_test.go htlcswitch: track held HTLC source 2026-06-26 14:29:23 -03:00
htlcnotifier.go multi+refactor: move models package to graph/db 2024-11-28 13:34:33 +02:00
interceptable_switch.go htlcswitch: track held HTLC source 2026-06-26 14:29:23 -03:00
interfaces.go htlcswitch: track held HTLC source 2026-06-26 14:29:23 -03:00
link.go htlcswitch: fix outgoing cltv spelling 2026-06-26 07:58:48 -03:00
link_isolated_test.go htlcswitch+invoices: align final-hop CLTV handling 2026-06-26 10:15:18 +00:00
link_test.go htlcswitch: fix outgoing cltv spelling 2026-06-26 07:58:48 -03:00
linkfailure.go multi: use the "errors" package everywhere 2025-06-30 09:46:55 +02:00
log.go multi: start updating various loggers to use the new v2 type 2024-10-22 17:03:55 +02:00
mailbox.go htlcswitch: pass quit chans as unidirectional 2024-10-17 17:33:15 +02:00
mailbox_test.go htlcswitch: pass quit chans as unidirectional 2024-10-17 17:33:15 +02:00
mock.go htlcswitch: fix outgoing cltv spelling 2026-06-26 07:58:48 -03:00
packet.go htlcswitch: handle nil circuit properly when settling 2024-12-16 15:58:23 +08:00
payment_result.go htlcswitch: rename paymentID to attemptID for clarity 2024-08-07 22:17:58 +08:00
payment_result_test.go multi: rename chan DB Open method to OpenForTesting 2024-11-28 13:51:15 +02:00
quiescer.go multi: add new config QuiescenceTimeout 2025-07-04 04:19:59 +08:00
quiescer_test.go multi: update to fn v2 2024-12-04 13:19:00 -07:00
resolution_store.go multi: use the "errors" package everywhere 2025-06-30 09:46:55 +02:00
resolution_store_test.go multi: update walletdb package 2025-04-09 18:47:53 +02:00
sequencer.go multi: use the "errors" package everywhere 2025-06-30 09:46:55 +02:00
switch.go routing+htlcswitch+discovery+peer+netann: optimize debug logging with lazy evaluation 2025-09-05 18:20:51 -07:00
switch_test.go htlcswitch: track held HTLC source 2026-06-26 14:29:23 -03:00
test_utils.go multi: use the "errors" package everywhere 2025-06-30 09:46:55 +02:00