mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-29 03:01:52 +01:00
lnwallet: modify CoopCloseBalance to not depend on chan commit
This commit is contained in:
parent
e536cfad0f
commit
8b97d4f833
@ -7781,7 +7781,10 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
|
|||||||
// during the channel closing process.
|
// during the channel closing process.
|
||||||
ourBalance, theirBalance, err := CoopCloseBalance(
|
ourBalance, theirBalance, err := CoopCloseBalance(
|
||||||
lc.channelState.ChanType, lc.channelState.IsInitiator,
|
lc.channelState.ChanType, lc.channelState.IsInitiator,
|
||||||
proposedFee, lc.channelState.LocalCommitment,
|
proposedFee,
|
||||||
|
lc.channelState.LocalCommitment.LocalBalance.ToSatoshis(),
|
||||||
|
lc.channelState.LocalCommitment.RemoteBalance.ToSatoshis(),
|
||||||
|
lc.channelState.LocalCommitment.CommitFee,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, 0, err
|
return nil, nil, 0, err
|
||||||
@ -7879,7 +7882,10 @@ func (lc *LightningChannel) CompleteCooperativeClose(
|
|||||||
// Get the final balances after subtracting the proposed fee.
|
// Get the final balances after subtracting the proposed fee.
|
||||||
ourBalance, theirBalance, err := CoopCloseBalance(
|
ourBalance, theirBalance, err := CoopCloseBalance(
|
||||||
lc.channelState.ChanType, lc.channelState.IsInitiator,
|
lc.channelState.ChanType, lc.channelState.IsInitiator,
|
||||||
proposedFee, lc.channelState.LocalCommitment,
|
proposedFee,
|
||||||
|
lc.channelState.LocalCommitment.LocalBalance.ToSatoshis(),
|
||||||
|
lc.channelState.LocalCommitment.RemoteBalance.ToSatoshis(),
|
||||||
|
lc.channelState.LocalCommitment.CommitFee,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
@ -1033,16 +1033,12 @@ func CreateCommitTx(chanType channeldb.ChannelType,
|
|||||||
// CoopCloseBalance returns the final balances that should be used to create
|
// CoopCloseBalance returns the final balances that should be used to create
|
||||||
// the cooperative close tx, given the channel type and transaction fee.
|
// the cooperative close tx, given the channel type and transaction fee.
|
||||||
func CoopCloseBalance(chanType channeldb.ChannelType, isInitiator bool,
|
func CoopCloseBalance(chanType channeldb.ChannelType, isInitiator bool,
|
||||||
coopCloseFee btcutil.Amount, localCommit channeldb.ChannelCommitment) (
|
coopCloseFee, ourBalance, theirBalance,
|
||||||
btcutil.Amount, btcutil.Amount, error) {
|
commitFee btcutil.Amount) (btcutil.Amount, btcutil.Amount, error) {
|
||||||
|
|
||||||
// Get both parties' balances from the latest commitment.
|
|
||||||
ourBalance := localCommit.LocalBalance.ToSatoshis()
|
|
||||||
theirBalance := localCommit.RemoteBalance.ToSatoshis()
|
|
||||||
|
|
||||||
// We'll make sure we account for the complete balance by adding the
|
// We'll make sure we account for the complete balance by adding the
|
||||||
// current dangling commitment fee to the balance of the initiator.
|
// current dangling commitment fee to the balance of the initiator.
|
||||||
initiatorDelta := localCommit.CommitFee
|
initiatorDelta := commitFee
|
||||||
|
|
||||||
// Since the initiator's balance also is stored after subtracting the
|
// Since the initiator's balance also is stored after subtracting the
|
||||||
// anchor values, add that back in case this was an anchor commitment.
|
// anchor values, add that back in case this was an anchor commitment.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user