Repository navigation
staticaddr: map reclaimed loop-in deposits back to their swap - #1251
Draft
claravanstaden wants to merge 2 commits into
Draft
claravanstaden wants to merge 2 commits into
claravanstaden wants to merge 2 commits into
Conversation
claravanstaden
force-pushed
the
static-reclaim-swap-hash
branch
from
October 15, 2026 05:44
9e46c7a to
98b99ac
Compare
1 task done
If a static loop-in's payment deadline passes before its htlc confirms, the swap cancels its invoice, gives its deposits back and keeps watching the htlc. Another swap can then select the deposits, which maps them to that swap in deposits.swap_hash. If the first swap's htlc confirms after all, the first swap takes the deposits back to sweep the htlc timeout path, but they stay mapped to the other swap, which never spends them. Map the deposits to the swap that sweeps them once they are locked for its htlc timeout sweep, also when they already were, in case loopd stopped before mapping them. Deposits that can't be locked, for example because the other swap completed with them, stay mapped to that swap. A nil deposit now fails the transition instead of being passed on. The loop-in store interface gains the existing BatchMapDepositsToSwapHashes for this.
claravanstaden
force-pushed
the
static-reclaim-swap-hash
branch
from
October 16, 2026 11:39
98b99ac to
225407c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A static loop-in's deposits can end up mapped in
deposits.swap_hashto a swap that never spends them:In step 2 the htlc hasn't confirmed yet, so swap A cancels its invoice but keeps watching the htlc. In step 4 it takes the deposits back to sweep the htlc timeout path.
This maps the deposits back to swap A in step 4, in
transitionDepositsToHtlcTimeout, once they are locked inSweepHtlcTimeout, and again if they already were, in case loopd stopped before mapping them. Deposits that can't be locked, for example because swap B completed with them, stay mapped to swap B. The loop-in store interface gains the existingBatchMapDepositsToSwapHashesfor this.What changes is everything that goes through the mapping: which deposits a swap recovers after a restart, and so which htlc it rebuilds for its htlc timeout sweep, and which swap the deposits' on-chain cost is reported for in #1248. A restart while swap B holds only some of the deposits isn't covered here and will be fixed separately.
Tests
TestMonitorInvoiceAndHtlcTxRemapsReclaimedDepositsruns the monitor with the real loop-in store through the steps above, with swap B taking one of swap A's two deposits, and checks that each swap loads its own deposits from the store. It fails on master.TestMonitorInvoiceAndHtlcTxMapsOnlyLockedDepositschecks that a deposit swap B completed with stays mapped to it, and that an already locked deposit is mapped again.TestMonitorInvoiceAndHtlcTxRetriesFailedMappingchecks that the monitor retries if the mapping fails, andTestMonitorInvoiceAndHtlcTxNilDepositthat a nil deposit fails the transition before any deposit is moved.Pull Request Checklist
docs/release-notes/release-notes-next.md, or apply theno-changeloglabel (required by CI)