input+lnwallet: use individual commit weight calculations for channel type
Based on the channel type, the commitment weight will be calculated.
This commit is contained in:
parent
1f28bd8086
commit
ea94dbbe34
@ -122,6 +122,12 @@ const (
|
|||||||
// - PkScript (P2WPKH)
|
// - PkScript (P2WPKH)
|
||||||
CommitmentKeyHashOutput = 8 + 1 + P2WPKHSize
|
CommitmentKeyHashOutput = 8 + 1 + P2WPKHSize
|
||||||
|
|
||||||
|
// CommitmentAnchorOutput 43 bytes
|
||||||
|
// - Value: 8 bytes
|
||||||
|
// - VarInt: 1 byte (PkScript length)
|
||||||
|
// - PkScript (P2WSH)
|
||||||
|
CommitmentAnchorOutput = 8 + 1 + P2WSHSize
|
||||||
|
|
||||||
// HTLCSize 43 bytes
|
// HTLCSize 43 bytes
|
||||||
// - Value: 8 bytes
|
// - Value: 8 bytes
|
||||||
// - VarInt: 1 byte (PkScript length)
|
// - VarInt: 1 byte (PkScript length)
|
||||||
@ -159,9 +165,32 @@ const (
|
|||||||
// WitnessCommitmentTxWeight 224 weight
|
// WitnessCommitmentTxWeight 224 weight
|
||||||
WitnessCommitmentTxWeight = WitnessHeaderSize + WitnessSize
|
WitnessCommitmentTxWeight = WitnessHeaderSize + WitnessSize
|
||||||
|
|
||||||
|
// BaseAnchorCommitmentTxSize 225 + 43 * num-htlc-outputs bytes
|
||||||
|
// - Version: 4 bytes
|
||||||
|
// - WitnessHeader <---- part of the witness data
|
||||||
|
// - CountTxIn: 1 byte
|
||||||
|
// - TxIn: 41 bytes
|
||||||
|
// FundingInput
|
||||||
|
// - CountTxOut: 3 byte
|
||||||
|
// - TxOut: 4*43 + 43 * num-htlc-outputs bytes
|
||||||
|
// OutputPayingToThem,
|
||||||
|
// OutputPayingToUs,
|
||||||
|
// AnchorPayingToThem,
|
||||||
|
// AnchorPayingToUs,
|
||||||
|
// ....HTLCOutputs...
|
||||||
|
// - LockTime: 4 bytes
|
||||||
|
BaseAnchorCommitmentTxSize = 4 + 1 + FundingInputSize + 3 +
|
||||||
|
2*CommitmentDelayOutput + 2*CommitmentAnchorOutput + 4
|
||||||
|
|
||||||
|
// BaseAnchorCommitmentTxWeight 900 weight
|
||||||
|
BaseAnchorCommitmentTxWeight = witnessScaleFactor * BaseAnchorCommitmentTxSize
|
||||||
|
|
||||||
// CommitWeight 724 weight
|
// CommitWeight 724 weight
|
||||||
CommitWeight = BaseCommitmentTxWeight + WitnessCommitmentTxWeight
|
CommitWeight = BaseCommitmentTxWeight + WitnessCommitmentTxWeight
|
||||||
|
|
||||||
|
// AnchorCommitWeight 1124 weight
|
||||||
|
AnchorCommitWeight = BaseAnchorCommitmentTxWeight + WitnessCommitmentTxWeight
|
||||||
|
|
||||||
// HTLCWeight 172 weight
|
// HTLCWeight 172 weight
|
||||||
HTLCWeight = witnessScaleFactor * HTLCSize
|
HTLCWeight = witnessScaleFactor * HTLCSize
|
||||||
|
|
||||||
|
@ -3772,7 +3772,8 @@ func (lc *LightningChannel) computeView(view *htlcView, remoteChain bool,
|
|||||||
totalHtlcWeight += input.HTLCWeight
|
totalHtlcWeight += input.HTLCWeight
|
||||||
}
|
}
|
||||||
|
|
||||||
totalCommitWeight := input.CommitWeight + totalHtlcWeight
|
totalCommitWeight := CommitWeight(lc.channelState.ChanType) +
|
||||||
|
totalHtlcWeight
|
||||||
return ourBalance, theirBalance, totalCommitWeight, filteredHTLCView, nil
|
return ourBalance, theirBalance, totalCommitWeight, filteredHTLCView, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6322,7 +6323,7 @@ func CreateCooperativeCloseTx(fundingTxIn wire.TxIn,
|
|||||||
// CalcFee returns the commitment fee to use for the given
|
// CalcFee returns the commitment fee to use for the given
|
||||||
// fee rate (fee-per-kw).
|
// fee rate (fee-per-kw).
|
||||||
func (lc *LightningChannel) CalcFee(feeRate chainfee.SatPerKWeight) btcutil.Amount {
|
func (lc *LightningChannel) CalcFee(feeRate chainfee.SatPerKWeight) btcutil.Amount {
|
||||||
return feeRate.FeeForWeight(input.CommitWeight)
|
return feeRate.FeeForWeight(CommitWeight(lc.channelState.ChanType))
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxFeeRate returns the maximum fee rate given an allocation of the channel
|
// MaxFeeRate returns the maximum fee rate given an allocation of the channel
|
||||||
|
@ -224,6 +224,16 @@ func CommitScriptToRemote(chanType channeldb.ChannelType,
|
|||||||
}, 0, nil
|
}, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommitWeight returns the base commitment weight before adding HTLCs.
|
||||||
|
func CommitWeight(chanType channeldb.ChannelType) int64 {
|
||||||
|
// If this commitment has anchors, it will be slightly heavier.
|
||||||
|
if chanType.HasAnchors() {
|
||||||
|
return input.AnchorCommitWeight
|
||||||
|
}
|
||||||
|
|
||||||
|
return input.CommitWeight
|
||||||
|
}
|
||||||
|
|
||||||
// CommitScriptAnchors return the scripts to use for the local and remote
|
// CommitScriptAnchors return the scripts to use for the local and remote
|
||||||
// anchor.
|
// anchor.
|
||||||
func CommitScriptAnchors(localChanCfg,
|
func CommitScriptAnchors(localChanCfg,
|
||||||
@ -364,7 +374,8 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance,
|
|||||||
// on its total weight. Once we have the total weight, we'll multiply
|
// on its total weight. Once we have the total weight, we'll multiply
|
||||||
// by the current fee-per-kw, then divide by 1000 to get the proper
|
// by the current fee-per-kw, then divide by 1000 to get the proper
|
||||||
// fee.
|
// fee.
|
||||||
totalCommitWeight := input.CommitWeight + (input.HTLCWeight * numHTLCs)
|
totalCommitWeight := CommitWeight(cb.chanState.ChanType) +
|
||||||
|
input.HTLCWeight*numHTLCs
|
||||||
|
|
||||||
// With the weight known, we can now calculate the commitment fee,
|
// With the weight known, we can now calculate the commitment fee,
|
||||||
// ensuring that we account for any dust outputs trimmed above.
|
// ensuring that we account for any dust outputs trimmed above.
|
||||||
|
Loading…
Reference in New Issue
Block a user