lnwallet/chancloser: add aux chan closer, use in coop flow

This commit is contained in:
Olaoluwa Osuntokun authored and Oliver Gugger committed 2024-09-19 10:18:40 +02:00
1 parent 7ff251ca44
commit 8d651b9370
4 files changed
+269 -17

No files matched your search

+39 -4
View File
@@ -8814,7 +8814,7 @@ func CreateCooperativeCloseTx(fundingTxIn wire.TxIn,
// LocalBalanceDust returns true if when creating a co-op close transaction,
// the balance of the local party will be dust after accounting for any anchor
// outputs.
func (lc *LightningChannel) LocalBalanceDust() bool {
func (lc *LightningChannel) LocalBalanceDust() (bool, btcutil.Amount) {
lc.RLock()
defer lc.RUnlock()
@@ -8828,13 +8828,15 @@ func (lc *LightningChannel) LocalBalanceDust() bool {
localBalance += 2 * AnchorSize
}
return localBalance <= chanState.LocalChanCfg.DustLimit
localDust := chanState.LocalChanCfg.DustLimit
return localBalance <= localDust, localDust
}
// RemoteBalanceDust returns true if when creating a co-op close transaction,
// the balance of the remote party will be dust after accounting for any anchor
// outputs.
func (lc *LightningChannel) RemoteBalanceDust() bool {
func (lc *LightningChannel) RemoteBalanceDust() (bool, btcutil.Amount) {
lc.RLock()
defer lc.RUnlock()
@@ -8848,7 +8850,40 @@ func (lc *LightningChannel) RemoteBalanceDust() bool {
remoteBalance += 2 * AnchorSize
}
return remoteBalance <= chanState.RemoteChanCfg.DustLimit
remoteDust := chanState.RemoteChanCfg.DustLimit
return remoteBalance <= remoteDust, remoteDust
}
// CommitBalances returns the local and remote balances in the current
// commitment state.
func (lc *LightningChannel) CommitBalances() (btcutil.Amount, btcutil.Amount) {
lc.RLock()
defer lc.RUnlock()
chanState := lc.channelState
localCommit := lc.channelState.LocalCommitment
localBalance := localCommit.LocalBalance.ToSatoshis()
remoteBalance := localCommit.RemoteBalance.ToSatoshis()
if chanState.ChanType.HasAnchors() {
if chanState.IsInitiator {
localBalance += 2 * AnchorSize
} else {
remoteBalance += 2 * AnchorSize
}
}
return localBalance, remoteBalance
}
// CommitFee returns the commitment fee for the current commitment state.
func (lc *LightningChannel) CommitFee() btcutil.Amount {
lc.RLock()
defer lc.RUnlock()
return lc.channelState.LocalCommitment.CommitFee
}
// CalcFee returns the commitment fee to use for the given fee rate