lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for the co-op close transaction. Before thsi commit, channel.CalcFee was used, which'll compute the fee based on the commitment transaction itself, rathern than the co-op close transaction. As the co-op close transaction is potentailly bigger (two P2TR outputs) than the commitment transaction, this can cause us to under estimate the fee, which can result in the fee rate being too low to propagate. To remedy this, we now compute a fee estimate from scratch, based on the delivery fees of the two parties. We also add a bug fix in the chancloser unit tests that wasn't caught due to loop variable shadowing. The wallet import itest has been updated as well, since we'll now pay 600 extra saothis to close the channel, since we're accounting for the added weight of the P2TR outputs. Fixes #6953
This commit is contained in:
6 files changed
+217
-45
No files matched your search
+42
-2
@@ -7214,8 +7214,48 @@ func CreateCooperativeCloseTx(fundingTxIn wire.TxIn,
|
||||
return closeTx
|
||||
}
|
||||
|
||||
// CalcFee returns the commitment fee to use for the given
|
||||
// fee rate (fee-per-kw).
|
||||
// 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 {
|
||||
lc.RLock()
|
||||
defer lc.RUnlock()
|
||||
|
||||
chanState := lc.channelState
|
||||
localBalance := chanState.LocalCommitment.LocalBalance.ToSatoshis()
|
||||
|
||||
// If this is an anchor channel, and we're the initiator, then we'll
|
||||
// regain the stats allocated to the anchor outputs with the co-op
|
||||
// close transaction.
|
||||
if chanState.ChanType.HasAnchors() && chanState.IsInitiator {
|
||||
localBalance += 2 * anchorSize
|
||||
}
|
||||
|
||||
return localBalance <= chanState.LocalChanCfg.DustLimit
|
||||
}
|
||||
|
||||
// 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 {
|
||||
lc.RLock()
|
||||
defer lc.RUnlock()
|
||||
|
||||
chanState := lc.channelState
|
||||
remoteBalance := chanState.RemoteCommitment.RemoteBalance.ToSatoshis()
|
||||
|
||||
// If this is an anchor channel, and they're the initiator, then we'll
|
||||
// regain the stats allocated to the anchor outputs with the co-op
|
||||
// close transaction.
|
||||
if chanState.ChanType.HasAnchors() && !chanState.IsInitiator {
|
||||
remoteBalance += 2 * anchorSize
|
||||
}
|
||||
|
||||
return remoteBalance <= chanState.RemoteChanCfg.DustLimit
|
||||
}
|
||||
|
||||
// CalcFee returns the commitment fee to use for the given fee rate
|
||||
// (fee-per-kw).
|
||||
func (lc *LightningChannel) CalcFee(feeRate chainfee.SatPerKWeight) btcutil.Amount {
|
||||
return feeRate.FeeForWeight(CommitWeight(lc.channelState.ChanType))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user