Skip to content

fix: exclude orphan coop close balances#1043

Open
ovitrif wants to merge 3 commits into
masterfrom
ovi/fix-1041-orphan-coop-close
Open

fix: exclude orphan coop close balances#1043
ovitrif wants to merge 3 commits into
masterfrom
ovi/fix-1041-orphan-coop-close

Conversation

@ovitrif

@ovitrif ovitrif commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1041
Refs #599
Refs #808

This PR fixes the transient Spending balance overstatement after a cooperative channel close by excluding orphaned cooperative-close claimables from the displayed Lightning total.

Description

  • Subtracts orphaned COOP_CLOSE ClaimableAwaitingConfirmations balances when the channel no longer exists locally and no active transfer owns that channel.
  • Keeps the existing active close-transfer behavior intact, so active cooperative closes are still hidden from Spending without showing a duplicate in-transfer amount, and force-close claimables keep using the existing transfer-to-savings flow.
  • Stops settling transfer-to-savings rows when balances are unavailable, so a failed balance fetch no longer looks like "LDK balance swept."
  • Adds a changelog fragment for the wallet-total correction.

Preview

QA Notes

Manual Tests

  • 1. master baseline → same wallet/app data with an orphan cooperative-close claimable and a new Spending channel → Home: Spending incorrectly includes both the orphan close amount and the new channel amount; record before.mp4.
  • 2. PR branch verification → install ovi/fix-1041-orphan-coop-close over the same app data, without uninstalling or clearing storage → Home: Spending shows only the new channel amount, while Savings/on-chain still reflects the closing funds; record after.mp4.
  • 3. regression: Active cooperative close transfer → Home balances: transfer-to-savings amount stays hidden from Spending without showing a duplicate in-transfer amount.
  • 4. regression: Active force-close transfer with pending sweep → Home balances: transfer-to-savings progress remains visible until sweep detection settles it.

Automated Checks

  • Unit tests added/updated: DeriveBalanceStateUseCaseTest.kt covers orphan COOP_CLOSE subtraction and non-coop-close claimables staying in Lightning.
  • Unit tests added/updated: TransferRepoTest.kt covers not settling transfer-to-savings and cooperative-close transfers when balances are unavailable.
  • Local verification: just compile, just test, just lint, and git diff --check; just lint still reports the existing HwWalletRepoTest.kt LargeClass finding.

@ovitrif ovitrif self-assigned this Jun 24, 2026
@ovitrif ovitrif marked this pull request as ready for review June 24, 2026 18:55
@ovitrif ovitrif added this to the 2.4.0 milestone Jun 24, 2026
@ovitrif ovitrif force-pushed the ovi/fix-1041-orphan-coop-close branch from 6f22641 to 2a140df Compare June 24, 2026 19:00
@greptile-apps

This comment has been minimized.

@ovitrif

ovitrif commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Redundant channel resolution for non-close transfers. transferChannelIds is built from ALL active transfers, but its only purpose is to guard against treating a channel with an active close-related transfer as orphaned.

Scoped the orphan guard’s transfer lookup to isToSavings() transfers, so it only resolves close/to-savings entries before comparing orphan cooperative-close claimables.

Resolved in 76f5132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Spending balance briefly doubles after coop close + second channel open

1 participant