Skip to content

Conversation

@t-bast
Copy link
Member

@t-bast t-bast commented Jun 2, 2025

We re-work the channel balance computation (CheckBalance.scala) used to continuously monitor the overall balance of the node. We previously assumed that all pending HTLCs would timeout on-chain, and monitored our mempool to deduplicate unconfirmed transactions and RBF attempts. But it is actually simpler to assume that all pending HTLCs will be fulfilled, and keep counting them in our off-chain balance until the spending transaction reaches min-depth.

We introduce a distinction between recently confirmed transactions and deeply confirmed transactions in our on-chain balance: there will be cases where we don't know yet whether we'll be able to gets funds back and the information of pending on-chain funds lets us verify that our overall balance is looking good. It always eventually converges to be in our on-chain balance.

Fixes #3085

@t-bast t-bast requested a review from pm47 June 2, 2025 08:57
We re-work the channel balance computation (`CheckBalance.scala`) used
to continuously monitor the overall balance of the node. We previously
assumed that all pending HTLCs would timeout on-chain, and monitored
our mempool to deduplicate unconfirmed transactions and RBF attempts.
But it is actually simpler to assume that all pending HTLCs will be
fulfilled, and keep counting them in our off-chain balance until the
spending transaction reaches `min-depth`.

We introduce a distinction between recently confirmed transactions and
deeply confirmed transactions in our on-chain balance: there will be
cases where we don't know yet whether we'll be able to gets funds back
and the information of pending on-chain funds lets us verify that our
overall balance is looking good. It always eventually converges to be
in our on-chain balance.

Fixes #3085
@t-bast t-bast force-pushed the rework-balance-checks branch from c248e4d to 2589ceb Compare June 3, 2025 09:32
@t-bast
Copy link
Member Author

t-bast commented Jun 3, 2025

Rebased to fix conflicts with #3092.

@t-bast t-bast merged commit 2c10538 into master Jun 3, 2025
1 check passed
@t-bast t-bast deleted the rework-balance-checks branch June 3, 2025 16:41
t-bast added a commit that referenced this pull request Jun 25, 2025
Our node balance computation was simplified in #3096, but it is now too
simplistic during closing, where some of the balance may be duplicated
between the off-chain part and unconfirmed or recently confirmed
transactions.

We deduplicate those by not counting in our off-chain balance of closing
channels outputs that are spent by an unconfirmed or recently confirmed
transaction that we've included in our on-chain balance.

Fixes #3098
t-bast added a commit that referenced this pull request Jul 16, 2025
…3119)

Our node balance computation was simplified in #3096, but it is now too
simplistic during closing, where some of the balance may be duplicated
between the off-chain part and unconfirmed or recently confirmed
transactions.

We deduplicate those by not counting in our off-chain balance of closing
channels outputs that are spent by an unconfirmed or recently confirmed
transaction that we've included in our on-chain balance.

Fixes #3098
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.

Balance check doesn't work for HTLC outputs during force-close

3 participants