Skip to content

[v0.20.x-branch] Backport #11106: invoices: migrate legacy AMP invoice HTLCs - #11107

Merged
ziggie1984 merged 2 commits into
v0.20.x-branchfrom
backport-11106-to-v0.20.x-branch
Aug 20, 2026
Merged

[v0.20.x-branch] Backport #11106: invoices: migrate legacy AMP invoice HTLCs#11107
ziggie1984 merged 2 commits into
v0.20.x-branchfrom
backport-11106-to-v0.20.x-branch

Conversation

@github-actions

Copy link
Copy Markdown

Backport of #11106


Change Description

Legacy AMP invoices created before reusable AMP invoices store their HTLCs
inline and don't contain AMPState metadata.

The KV-to-SQL migration inserted the generic HTLC rows for these invoices, but
without AMPState it did not create AMP sub-invoices or associate the HTLCs
with them. SQL read-back therefore returned an empty HTLC map, and strict
migration verification aborted startup.

Reconstruct the modern AMP sub-invoice state from each inline HTLC's set ID
before insertion. This preserves the HTLC associations, AMP metadata, custom
records, amounts, and settlement metadata while keeping the compatibility
handling isolated to the migration.

The migration fails closed if the legacy data is structurally inconsistent.
Release notes are included for v0.21.3 and v0.20.4.

Steps to Test

make lint
go vet ./invoices
go test ./invoices -run '^TestMigrateLegacyAMPInvoice -count=20

The regression test migrates a settled legacy AMP invoice with a canceled
competing set, AMP metadata, a large child index, and custom records, then
verifies complete SQL read-back equality.

AMP invoices created before reusable invoices store their HTLCs inline
and have no AMPState metadata. Reconstruct the sub-invoice state from
each HTLC set ID before inserting it into SQL. This preserves the AMP
associations during read-back verification.

Add regression coverage for settled and canceled legacy sets, AMP
metadata, and custom records.

(cherry picked from commit 96a0a26)
@github-actions github-actions Bot added this to the v0.21.3 milestone Aug 20, 2026
@github-actions

Copy link
Copy Markdown
Author

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-11106-to-v0.20.x-branch
git worktree add --checkout .worktree/backport-11106-to-v0.20.x-branch backport-11106-to-v0.20.x-branch
cd .worktree/backport-11106-to-v0.20.x-branch
git reset --hard HEAD^
git cherry-pick -x cb9c86195251422dc217c35b915e54a55d8f8580 b7a2f153962c34b3920533da0ae70f05e01d7a4f
git push --force-with-lease

@ziggie1984
ziggie1984 force-pushed the backport-11106-to-v0.20.x-branch branch from da8c765 to 8fc74ae Compare August 20, 2026 20:11
@github-actions github-actions Bot added the severity-high Requires knowledgeable engineer review label Aug 20, 2026
@github-actions

Copy link
Copy Markdown
Author

🟠 PR Severity: HIGH

gh pr view | 3 files | 401 lines changed (117 non-test)

🟠 High (1 file)
  • invoices/sql_migration.go - modifies the KV-to-SQL invoice migration logic (reconstructs AMP sub-invoice state), under invoices/*
🟢 Low (2 files)
  • docs/release-notes/release-notes-0.20.4.md - release notes only
  • invoices/sql_migration_test.go - test-only change

Analysis

This is a backport of #‌11106 fixing a bug in the KV-to-SQL migration for legacy AMP invoices: without reconstructed AMPState, HTLCs weren't associated with AMP sub-invoices, causing empty HTLC maps and failed strict migration verification on startup. The core logic change is confined to invoices/sql_migration.go, which falls under invoices/* (HIGH severity). It does not touch channeldb/migration*, sqldb/*, or wtdb/*, so the always-CRITICAL database-migration rule doesn't apply. Non-test/non-doc changes total only ~117 lines across a single file, well under the thresholds for a severity bump. Given this touches invoice migration correctness (data integrity on startup), a knowledgeable engineer review is warranted.


To override, add a severity-override-{critical,high,medium,low} label.

@ziggie1984
ziggie1984 marked this pull request as ready for review August 20, 2026 22:06

@ziggie1984 ziggie1984 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ziggie1984
ziggie1984 merged commit 0a1c0e1 into v0.20.x-branch Aug 20, 2026
34 of 35 checks passed
@ziggie1984
ziggie1984 deleted the backport-11106-to-v0.20.x-branch branch August 20, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog severity-high Requires knowledgeable engineer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant