diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index dc796ba3..9efe89dc 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -1973,7 +1973,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) { t.Fatalf("unable to query fee estimator: %v", err) } htlcFee := lnwire.NewMSatFromSatoshis( - feePerKw.FeeForWeight(input.HtlcWeight), + feePerKw.FeeForWeight(input.HTLCWeight), ) // The starting bandwidth of the channel should be exactly the amount @@ -2462,7 +2462,7 @@ func TestChannelLinkBandwidthConsistencyOverflow(t *testing.T) { // TODO(roasbeef): increase sleep time.Sleep(time.Second * 1) - commitWeight := input.CommitWeight + input.HtlcWeight*numHTLCs + commitWeight := int64(input.CommitWeight + input.HTLCWeight*numHTLCs) htlcFee := lnwire.NewMSatFromSatoshis( feePerKw.FeeForWeight(commitWeight), ) @@ -2646,7 +2646,7 @@ func TestChannelLinkTrimCircuitsPending(t *testing.T) { defaultCommitFee := alice.channel.StateSnapshot().CommitFee htlcFee := lnwire.NewMSatFromSatoshis( - feePerKw.FeeForWeight(input.HtlcWeight), + feePerKw.FeeForWeight(input.HTLCWeight), ) // The starting bandwidth of the channel should be exactly the amount @@ -2925,7 +2925,7 @@ func TestChannelLinkTrimCircuitsNoCommit(t *testing.T) { defaultCommitFee := alice.channel.StateSnapshot().CommitFee htlcFee := lnwire.NewMSatFromSatoshis( - feePerKw.FeeForWeight(input.HtlcWeight), + feePerKw.FeeForWeight(input.HTLCWeight), ) // The starting bandwidth of the channel should be exactly the amount @@ -3181,7 +3181,7 @@ func TestChannelLinkBandwidthChanReserve(t *testing.T) { t.Fatalf("unable to query fee estimator: %v", err) } htlcFee := lnwire.NewMSatFromSatoshis( - feePerKw.FeeForWeight(input.HtlcWeight), + feePerKw.FeeForWeight(input.HTLCWeight), ) // The starting bandwidth of the channel should be exactly the amount diff --git a/input/size.go b/input/size.go index 07055dc8..68fa85e4 100644 --- a/input/size.go +++ b/input/size.go @@ -5,15 +5,6 @@ import ( "github.com/btcsuite/btcd/wire" ) -const ( - // CommitWeight is the weight of the base commitment transaction which - // includes: one p2wsh input, out p2wkh output, and one p2wsh output. - CommitWeight int64 = 724 - - // HtlcWeight is the weight of an HTLC output. - HtlcWeight int64 = 172 -) - const ( // witnessScaleFactor determines the level of "discount" witness data // receives compared to "base" data. A scale factor of 4, denotes that @@ -168,6 +159,9 @@ const ( // WitnessCommitmentTxWeight 224 weight WitnessCommitmentTxWeight = WitnessHeaderSize + WitnessSize + // CommitWeight 724 weight + CommitWeight = BaseCommitmentTxWeight + WitnessCommitmentTxWeight + // HTLCWeight 172 weight HTLCWeight = witnessScaleFactor * HTLCSize diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 210328e4..ff2228b4 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -3450,7 +3450,7 @@ func (lc *LightningChannel) computeView(view *htlcView, remoteChain bool, continue } - totalHtlcWeight += input.HtlcWeight + totalHtlcWeight += input.HTLCWeight } for _, htlc := range filteredHTLCView.theirUpdates { if htlcIsDust(!remoteChain, !remoteChain, feePerKw, @@ -3458,7 +3458,7 @@ func (lc *LightningChannel) computeView(view *htlcView, remoteChain bool, continue } - totalHtlcWeight += input.HtlcWeight + totalHtlcWeight += input.HTLCWeight } totalCommitWeight := input.CommitWeight + totalHtlcWeight diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index c0467af9..21461311 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -600,7 +600,7 @@ func TestForceClose(t *testing.T) { // Factoring in the fee rate, Alice's amount should properly reflect // that we've added two additional HTLC to the commitment transaction. - totalCommitWeight := input.CommitWeight + (input.HtlcWeight * 2) + totalCommitWeight := int64(input.CommitWeight + (input.HTLCWeight * 2)) feePerKw := chainfee.SatPerKWeight( aliceChannel.channelState.LocalCommitment.FeePerKw, ) diff --git a/lnwallet/commitment.go b/lnwallet/commitment.go index b00e6043..67b5cbc1 100644 --- a/lnwallet/commitment.go +++ b/lnwallet/commitment.go @@ -287,7 +287,7 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance, // 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 // fee. - totalCommitWeight := input.CommitWeight + (input.HtlcWeight * numHTLCs) + totalCommitWeight := input.CommitWeight + (input.HTLCWeight * numHTLCs) // With the weight known, we can now calculate the commitment fee, // ensuring that we account for any dust outputs trimmed above.