GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — staticaddr/loopin: map looped-in deposits to the swap that spent them by claravanstaden · Pull Request #1253 · lightninglabs/loop

Conversation

@claravanstaden

@claravanstaden claravanstaden commented Oct 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Based on #1251. Only the last three commits are new here.

A looped-in static address deposit can stay mapped in deposits.swap_hash to a swap that didn't spend it:

What happened Mapped to Should be
Swap A fails, then swap B selects the same deposits and succeeds A B

Problem: the deposit swap hash migration mapped a deposit that several swaps selected to the first of them (comment on #1248). Both swaps are final, so nothing on chain depends on it, but swap B lists no deposits and reports an unknown on-chain cost.

Fix: loopd runs MigrateRepairLoopedInDepositSwapHash once at startup, with its own migration id, using the repair from #1251. It maps each looped-in deposit to the paid swap that selected it. If no swap or more than one swap was paid, it leaves the deposit and logs a warning.

Tests

TestRepairLoopedInDepositSwapHash covers the retry case, plus ambiguous, unspent, htlc timeout and already correct deposits. It checks the on-chain cost before and after the repair, and that the repair runs only once and separately from the htlc timeout repair.

TestRepairLoopedInDepositSwapHashAfterMigration simulates an upgrade from before the deposit swap hash migration: it clears the deposits' swap hashes, runs that migration and then the repair, in startup order. The migration maps the deposits to the failed swaps, and the repair moves them to the paid swaps, including one in SucceededTransitioningFailed.

go test ./staticaddr/... ./loopd/... passes on every commit, and lint is clean.

Pull Request Checklist

  • Add an entry to docs/release-notes/release-notes-next.md, or apply the
    no-changelog label (required by CI)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@claravanstaden claravanstaden added the static-loop-in label Oct 19, 2026
@claravanstaden
claravanstaden force-pushed the static-repair-looped-in-swap-hash branch from d427b0d to 76065f0 Compare October 19, 2026 10:43
@claravanstaden claravanstaden mentioned this pull request Oct 19, 2026
staticaddr/loopin: map reclaimed deposits to the swap that spent them #1251
Open
1 task done
@claravanstaden
claravanstaden force-pushed the static-repair-looped-in-swap-hash branch 6 times, most recently from 5fcdc7a to bbfa9ec Compare October 22, 2026 07:16
@levmi levmi assigned claravanstaden Oct 22, 2026
@claravanstaden
claravanstaden force-pushed the static-repair-looped-in-swap-hash branch 2 times, most recently from cf6700a to 6988051 Compare November 6, 2026 06:47
@claravanstaden
claravanstaden marked this pull request as ready for review November 6, 2026 06:52
@claravanstaden
claravanstaden force-pushed the static-repair-looped-in-swap-hash branch from 6988051 to b1fa6a8 Compare November 6, 2026 07:23
@claravanstaden claravanstaden changed the title staticaddr: repair the swap hashes of looped-in deposits staticaddr/loopin: map looped-in deposits to the swap that spent them Nov 6, 2026
@claravanstaden
claravanstaden force-pushed the static-repair-looped-in-swap-hash branch 2 times, most recently from 7726e04 to 0b7ff28 Compare November 27, 2026 13:30
@claravanstaden
claravanstaden requested review from bhandras and hieblmi November 27, 2026 13:34
@claravanstaden
claravanstaden force-pushed the static-repair-looped-in-swap-hash branch from 0b7ff28 to cd8751b Compare November 27, 2026 15:30
claravanstaden added 7 commits November 27, 2026 21:10
@claravanstaden
staticaddr: map reclaimed loop-in deposits back to their swap
5861e4d
If a static loop-in's payment deadline passes before its htlc confirms,
it gives its deposits back, and another swap can select them, which
maps them to that swap. If the first swap's htlc confirms after all, it
sweeps them through its htlc timeout path, but they stay mapped to the
other swap.

Map the deposits to the swap once they are locked for its htlc timeout
sweep, and again if they already were, in case loopd stopped in
between. A deposit another swap completed with can't be locked and
stays with that swap. Any tx paying to the htlc script confirms it, so
only map them if the confirmed tx spends exactly the deposits the swap
signed its htlc tx for.

After a restart the swap only loads the deposits still mapped to it, so
replace them with all signed deposits, in signed order, which the htlc
timeout sweep needs. If any is no longer active, none are added.

A nil deposit now fails the transition. The loop-in store interface
gains the existing BatchMapDepositsToSwapHashes.
@claravanstaden
staticaddr: repair the swap hashes of reclaimed deposits
8f4f313
A swap whose payment deadline passed gave its deposits back before its
htlc confirmed after all, which left them mapped to the swap that
selected them next. The previous commit maps them back when that
happens from now on, but deposits that it already happened to stay
mapped to the other swap. The swap that spent them reports no on-chain
cost for them, and if the other swap took only some of its deposits, it
loads only the rest after a restart, so it can't sweep its htlc timeout
path.

Add a migration that maps each deposit on the htlc timeout path to the
swap whose htlc tx spent it: a swap on its own htlc timeout path whose
htlc tx is the confirmed wallet tx that spent the deposit. That tx must
spend exactly the deposits the swap signed its htlc tx for and pay to
the swap's htlc, since the swap's state alone isn't proof and two swaps
can select the same deposits. A deposit stays as it is if the wallet
doesn't know that tx or no swap qualifies. If lnd can't list the wallet
txs, the repair is skipped so that loopd still starts, and it runs
again at the next start.

A swap that still waits for its htlc timeout isn't covered: its htlc
timeout sweep loads only the deposits mapped to it, which is fixed
separately.

The repair has its own migration id, and the lookup of the swaps by the
outpoints they selected and the final write are separate helpers, so
that other repairs can reuse them. The swap state check is shared with
the on-chain cost of a swap.
@claravanstaden
loopd: repair the swap hashes of reclaimed deposits at startup
f033d2a
Run the reclaimed deposit swap hash repair once, after the deposit swap
hash migration. It looks up the txs that spent the deposits in the lnd
wallet.
@claravanstaden
docs: add release note for reclaimed loop-in deposits
04a05ed
@claravanstaden
staticaddr: repair the swap hashes of looped-in deposits
9de82d2
The deposit swap hash migration mapped a deposit that several static
loop-ins selected to the first of them. So if a swap failed and a later
swap looped in the same deposit, the deposit stayed mapped to the
failed swap. The swap that looped it in then listed no deposits and
reported an unknown on-chain cost.

Add a migration that maps each looped-in deposit to the paid swap that
selected it. A deposit stays as it is if no swap or more than one swap
that selected it was paid. Both swaps are final, so this only corrects
what loopd reports.
@claravanstaden
loopd: repair the swap hashes of looped-in deposits at startup
b822523
Run the looped-in deposit swap hash repair once, after the reclaimed
deposit swap hash repair.
@claravanstaden
docs: add release note for repaired looped-in deposits
60d20a4
@claravanstaden
claravanstaden force-pushed the static-repair-looped-in-swap-hash branch from cd8751b to 60d20a4 Compare November 27, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hieblmi hieblmi Awaiting requested review from hieblmi
@bhandras bhandras Awaiting requested review from bhandras

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@claravanstaden claravanstaden

Labels

static-loop-in

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@claravanstaden
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.