Skip to content

fix: handle counterparty channel closes#806

Open
jvsena42 wants to merge 8 commits intofix/reimport-channel-monitorfrom
fix/channel-close-ui
Open

fix: handle counterparty channel closes#806
jvsena42 wants to merge 8 commits intofix/reimport-channel-monitorfrom
fix/channel-close-ui

Conversation

@jvsena42
Copy link
Member

@jvsena42 jvsena42 commented Feb 25, 2026

Closes #802 (comment)

This PR:

  1. Adds counterparty channel close detection and user notification via a "Connection Closed" sheet
  2. Creates transfer records for counterparty-initiated channel closes (force and cooperative)
  3. Improves syncTransferStates to handle batched force-close sweeps correctly

Description

  • Classifies ClosureReason variants to detect counterparty-initiated closes (force close vs cooperative)
  • Creates a transfer when a counterparty closes a channel, looking up the channel balance from lightning balances or closed channel records
  • Shows a "Connection Closed" bottom sheet to inform the user
  • Adds PendingSweepBalance extension functions for extracting channel IDs and spending txids
  • Improves force close settlement logic in syncTransferStates: checks on-chain activity for the channel, falls back to pending sweep status, and handles batched sweeps where LDK links a single transaction to multiple channels
  • Adds helper methods in CoreService.ActivityService for querying on-chain activity by channel or txid
  • Adds unit tests for the new force close sync scenarios

Preview

identify-force-close.webm
settle-force-close-transfer.webm
coop-close.webm

QA Notes

The easier way of triggering a force-close on Blocktank side is simulating #802 bug

  1. Counterparty force close detection

    • In regtest, open a channel with the LSP
    • Force close the channel from the LSP side
    • Verify the "Connection Closed" sheet appears
    • Verify a transfer banner appears on the savings screen tracking the sweep
  2. Cooperative close detection

    • Trigger a cooperative close from the counterparty
    • Verify the sheet and transfer are created
  3. Batched sweep handling

    • Open multiple channels, force close all from counterparty
    • Verify all transfers settle correctly even when LDK batches sweeps

@jvsena42 jvsena42 self-assigned this Feb 25, 2026
@jvsena42 jvsena42 changed the base branch from master to fix/reimport-channel-monitor February 25, 2026 18:29
@jvsena42 jvsena42 marked this pull request as ready for review February 26, 2026 11:32
@jvsena42 jvsena42 requested a review from ovitrif February 26, 2026 11:42
@pwltr pwltr self-requested a review February 26, 2026 14:06
@pwltr
Copy link
Contributor

pwltr commented Feb 26, 2026

The easier way of triggering a force-close on Blocktank side is simulating #802 bug

Can also use the staging bot /regtest-ln-close-channel <fundingTx:vout> [force]

@pwltr
Copy link
Contributor

pwltr commented Feb 26, 2026

Coop close:

  • shows 'Connection closed' sheet ✅
  • shows 'Transfer in progress' banner and 'incoming transfer' onchain balance ❌

Funds are immediately spendable, no need to show transfer in progress, need to ignore the reorg protection from ldk-node (6 blocks)

) {
Column(
modifier = modifier
.sheetHeight()
Copy link
Contributor

Choose a reason for hiding this comment

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

should be size .medium

@pwltr
Copy link
Contributor

pwltr commented Feb 26, 2026

Force close:

  • shows 'Connection closed' sheet after 1 block ✅
  • shows 'Transfer in progress' banner and 'incoming transfer' onchain balance ❌
    • should show 'Transfer ready in 60M' (6 blocks)
  • shows 'Received Bitcoin' sheet ❌
    • don't show received sheet

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.

2 participants