Skip to content

Commit 625d426

Browse files
Roasbeefguggero
authored andcommitted
lnwallet: modify CoopCloseBalance to not depend on chan commit
1 parent 8d651b9 commit 625d426

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lnwallet/channel.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7781,7 +7781,10 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
77817781
// during the channel closing process.
77827782
ourBalance, theirBalance, err := CoopCloseBalance(
77837783
lc.channelState.ChanType, lc.channelState.IsInitiator,
7784-
proposedFee, lc.channelState.LocalCommitment,
7784+
proposedFee,
7785+
lc.channelState.LocalCommitment.LocalBalance.ToSatoshis(),
7786+
lc.channelState.LocalCommitment.RemoteBalance.ToSatoshis(),
7787+
lc.channelState.LocalCommitment.CommitFee,
77857788
)
77867789
if err != nil {
77877790
return nil, nil, 0, err
@@ -7879,7 +7882,10 @@ func (lc *LightningChannel) CompleteCooperativeClose(
78797882
// Get the final balances after subtracting the proposed fee.
78807883
ourBalance, theirBalance, err := CoopCloseBalance(
78817884
lc.channelState.ChanType, lc.channelState.IsInitiator,
7882-
proposedFee, lc.channelState.LocalCommitment,
7885+
proposedFee,
7886+
lc.channelState.LocalCommitment.LocalBalance.ToSatoshis(),
7887+
lc.channelState.LocalCommitment.RemoteBalance.ToSatoshis(),
7888+
lc.channelState.LocalCommitment.CommitFee,
78837889
)
78847890
if err != nil {
78857891
return nil, 0, err

lnwallet/commitment.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,16 +1033,12 @@ func CreateCommitTx(chanType channeldb.ChannelType,
10331033
// CoopCloseBalance returns the final balances that should be used to create
10341034
// the cooperative close tx, given the channel type and transaction fee.
10351035
func CoopCloseBalance(chanType channeldb.ChannelType, isInitiator bool,
1036-
coopCloseFee btcutil.Amount, localCommit channeldb.ChannelCommitment) (
1037-
btcutil.Amount, btcutil.Amount, error) {
1038-
1039-
// Get both parties' balances from the latest commitment.
1040-
ourBalance := localCommit.LocalBalance.ToSatoshis()
1041-
theirBalance := localCommit.RemoteBalance.ToSatoshis()
1036+
coopCloseFee, ourBalance, theirBalance,
1037+
commitFee btcutil.Amount) (btcutil.Amount, btcutil.Amount, error) {
10421038

10431039
// We'll make sure we account for the complete balance by adding the
10441040
// current dangling commitment fee to the balance of the initiator.
1045-
initiatorDelta := localCommit.CommitFee
1041+
initiatorDelta := commitFee
10461042

10471043
// Since the initiator's balance also is stored after subtracting the
10481044
// anchor values, add that back in case this was an anchor commitment.

0 commit comments

Comments
 (0)