lnwallet+rpcserver: fix weight calculation for taproot channels

This commit is contained in:
yyforyongyu committed 2023-09-28 19:42:13 +08:00
1 parent 62d240bba1
commit 522518922f
2 files changed
+24 -4

No files matched your search

+16 -2
View File
@@ -3476,10 +3476,17 @@ func (r *rpcServer) fetchPendingOpenChannels() (pendingOpenChannels, error) {
// broadcast.
// TODO(roasbeef): query for funding tx from wallet, display
// that also?
var witnessWeight int64
if pendingChan.ChanType.IsTaproot() {
witnessWeight = input.TaprootKeyPathWitnessSize
} else {
witnessWeight = input.WitnessCommitmentTxWeight
}
localCommitment := pendingChan.LocalCommitment
utx := btcutil.NewTx(localCommitment.CommitTx)
commitBaseWeight := blockchain.GetTransactionWeight(utx)
commitWeight := commitBaseWeight + input.WitnessCommitmentTxWeight
commitWeight := commitBaseWeight + witnessWeight
// FundingExpiryBlocks is the distance from the current block
// height to the broadcast height + MaxWaitNumBlocksFundingConf.
@@ -4227,10 +4234,17 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
// estimated weight of the witness to calculate the weight of
// the transaction if it were to be immediately unilaterally
// broadcast.
var witnessWeight int64
if dbChannel.ChanType.IsTaproot() {
witnessWeight = input.TaprootKeyPathWitnessSize
} else {
witnessWeight = input.WitnessCommitmentTxWeight
}
localCommit := dbChannel.LocalCommitment
utx := btcutil.NewTx(localCommit.CommitTx)
commitBaseWeight := blockchain.GetTransactionWeight(utx)
commitWeight := commitBaseWeight + input.WitnessCommitmentTxWeight
commitWeight := commitBaseWeight + witnessWeight
localBalance := localCommit.LocalBalance
remoteBalance := localCommit.RemoteBalance