Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ object CheckBalance {
this.copy(closing = this.closing.copy(toLocal = this.closing.toLocal + localBalance))
case None => this
}
// If we have a fully signed mutual close transaction and a closing transaction is in our mempool or recently
// confirmed, the channel will most likely end up being mutual-closed (since the feerate is higher than any
// force-close transaction). We thus ignore this channel in our off-chain balance to avoid counting it twice.
case None if d.mutualClosePublished.nonEmpty && recentlySpentInputs.contains(d.commitments.latest.fundingInput) => this
// We don't know yet which type of closing will confirm on-chain, so we use our default off-chain balance.
case None => this.copy(closing = this.closing.addChannelBalance(d.commitments))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ class CheckBalanceSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
assert(CheckBalance.computeOffChainBalance(Seq(alice.stateData.asInstanceOf[DATA_NEGOTIATING_SIMPLE]), recentlySpentInputs = Set(closingTxInput)).negotiating == expected)
}

test("channel closing with published closing tx (without option_simple_close)") { f =>
import f._

mutualClose(alice, bob, alice2bob, bob2alice, alice2blockchain, bob2blockchain)
assert(alice.stateData.asInstanceOf[DATA_CLOSING].mutualClosePublished.nonEmpty)
val closingTxInput = alice.stateData.asInstanceOf[DATA_CLOSING].commitments.latest.fundingInput
val expected = MainAndHtlcBalance(toLocal = 0 sat, htlcs = 0 sat)
assert(CheckBalance.computeOffChainBalance(Seq(alice.stateData.asInstanceOf[DATA_CLOSING]), recentlySpentInputs = Set(closingTxInput)).closing == expected)
}

test("channel closed with remote commit tx", Tag(ChannelStateTestsTags.StaticRemoteKey), Tag(ChannelStateTestsTags.AnchorOutputsZeroFeeHtlcTxs)) { f =>
import f._

Expand Down