lnwallet: add anchor size back to balance on coop close

To be spec compliant, we require the initiator to not pay the anchor
values into fees on coop close. We extract the balance calculation into
commitment.go, and add back the value of the anchors to the initiator's
balance.
This commit is contained in:
Johan T. Halseth committed 2020-09-11 11:10:58 +02:00
1 parent 07a57ae778
commit 09a126b29f
2 files changed
+67 -7

No files matched your search

+14 -3
View File
@@ -675,11 +675,22 @@ func CoopCloseBalance(chanType channeldb.ChannelType, isInitiator bool,
// We'll make sure we account for the complete balance by adding the
// current dangling commitment fee to the balance of the initiator.
commitFee := localCommit.CommitFee
initiatorDelta := localCommit.CommitFee
// Since the initiator's balance also is stored after subtracting the
// anchor values, add that back in case this was an anchor commitment.
if chanType.HasAnchors() {
initiatorDelta += 2 * anchorSize
}
// The initiator will pay the full coop close fee, subtract that value
// from their balance.
initiatorDelta -= coopCloseFee
if isInitiator {
ourBalance = ourBalance - coopCloseFee + commitFee
ourBalance += initiatorDelta
} else {
theirBalance = theirBalance - coopCloseFee + commitFee
theirBalance += initiatorDelta
}
return ourBalance, theirBalance