htlcswitch: align forwarding response and circuit lifetimes #11258
LGTM.
👍
🔴 PR Severity: CRITICAL
gh pr view | 17 files | 1389 lines changed
<details>
<summary>🔴 <strong>Critical</strong> (9 files)</summary>
channeldb/channel.go - channel state persistence logicchanneldb/db.go - core channel database wiringchanneldb/fwd_response_store.go - new persisted store for forwarding responsescontractcourt/channel_arbitrator.go - on-chain dispute/breach handling state machinehtlcswitch/circuit_map.go - HTLC circuit tracking used by the forwarding switchhtlcswitch/mock.go - htlcswitch test scaffolding touched alongside switch changeshtlcswitch/resolution_store.go - HTLC resolution persistencehtlcswitch/switch.go - core HTLC forwarding/routing state machineserver.go - core server coordination/wiring</details>
<details>
<summary>🟢 <strong>Low</strong> (8 files)</summary>
docs/release-notes/release-notes-0.20.5.md - release notesdocs/release-notes/release-notes-0.21.4.md - release noteschanneldb/fwd_response_store_test.go - test onlycontractcourt/channel_arbitrator_test.go - test onlyhtlcswitch/circuit_map_test.go - test onlyhtlcswitch/circuit_test.go - test onlyhtlcswitch/resolution_store_test.go - test onlyhtlcswitch/switch_fwd_response_test.go - test only</details>
Analysis
This PR adds a new forward-response store (channeldb/fwd_response_store.go) and wires it through htlcswitch/switch.go and htlcswitch/circuit_map.go, plus modifies contractcourt/channel_arbitrator.go and server.go. It touches multiple distinct CRITICAL packages (channeldb, contractcourt, htlcswitch) that make up the core HTLC forwarding and on-chain dispute resolution path, and non-test/non-generated changes exceed 500 lines. This is squarely core payment-routing and channel-state logic and warrants expert review.
---
<sub>To override, add a severity-override-{critical,high,medium,low} label.</sub>
<!-- pr-severity-bot -->
Can be wrapped up into a new interface to collocate the new responsibility.
When the pre-image is found, true is always returned, so might as well return fn.Option[lntypes.Preimage]. Then can go further to wrap then in fn.Result, then it's a bit clearer as you can collapse the redundant return type (non-blank preimage is never seen with false as a return value).
LGTM! 🎉
Great PR! Thanks!
If these are rolled into an interface, only need a single nil check there.
will be done in a followup, kept it as is for easier backporting
Accepted took the fn.Option approach
see comment above regarding the interface
LGTM
Created backport PR for v0.20.x-branch:
Please cherry-pick the changes locally and resolve any conflicts.
git fetch origin backport-11258-to-v0.20.x-branch
git worktree add --checkout .worktree/backport-11258-to-v0.20.x-branch backport-11258-to-v0.20.x-branch
cd .worktree/backport-11258-to-v0.20.x-branch
git reset --hard HEAD^
git cherry-pick -x 94c598a01ebc2ee21f7827b31eb1a9754d761768 b17f70d797e32ef4dc933156a330238b254747c1 dd0c09d8f58d01a946897007c0511044b035d8d8 413b02cd53f7cf7afd0febe43ef86f113471df25
git push --force-with-lease
Created backport PR for v0.21.x-branch:
Please cherry-pick the changes locally and resolve any conflicts.
git fetch origin backport-11258-to-v0.21.x-branch
git worktree add --checkout .worktree/backport-11258-to-v0.21.x-branch backport-11258-to-v0.21.x-branch
cd .worktree/backport-11258-to-v0.21.x-branch
git reset --hard HEAD^
git cherry-pick -x 94c598a01ebc2ee21f7827b31eb1a9754d761768 b17f70d797e32ef4dc933156a330238b254747c1 dd0c09d8f58d01a946897007c0511044b035d8d8 413b02cd53f7cf7afd0febe43ef86f113471df25
git push --force-with-lease
gijswijs
ziggie1984
Summary
Forwarding responses participate in switch recovery through per-channel
package state, while resolution messages and payment circuits have separately
managed lifecycles.
This PR adds circuit-indexed persistence for forwarding responses and
integrates it with the switch's existing startup and cleanup flows.
Changes
resolution path
Persistence
Response persistence and synchronous package cleanup share a transaction.
Startup propagates unreadable state and removes records that no longer refer to
an open circuit.
Testing