From 145cd0b2b6bcc0859de81080ab71769ce028c9eb Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 9 Nov 2017 22:15:21 -0800 Subject: [PATCH] lnwallet: export HtlcWeight and CommitWeight publicly --- lnwallet/channel.go | 2 +- lnwallet/reservation.go | 2 +- lnwallet/size.go | 9 +++++++++ lnwallet/wallet.go | 3 --- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 7a9c3f2e..2ec41127 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1972,7 +1972,7 @@ func (lc *LightningChannel) createCommitmentTx(c *commitment, // 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 := commitWeight + (htlcWeight * numHTLCs) + totalCommitWeight := CommitWeight + (HtlcWeight * numHTLCs) // With the weight known, we can now calculate the commitment fee, // ensuring that we account for any dust outputs trimmed above. diff --git a/lnwallet/reservation.go b/lnwallet/reservation.go index 9c307243..c376590e 100644 --- a/lnwallet/reservation.go +++ b/lnwallet/reservation.go @@ -144,7 +144,7 @@ func NewChannelReservation(capacity, fundingAmt, feePerKw btcutil.Amount, initiator bool ) - commitFee := btcutil.Amount((int64(feePerKw) * commitWeight) / 1000) + commitFee := btcutil.Amount((int64(feePerKw) * CommitWeight) / 1000) fundingMSat := lnwire.NewMSatFromSatoshis(fundingAmt) capacityMSat := lnwire.NewMSatFromSatoshis(capacity) diff --git a/lnwallet/size.go b/lnwallet/size.go index 6061a141..75b9e4cd 100644 --- a/lnwallet/size.go +++ b/lnwallet/size.go @@ -5,6 +5,15 @@ import ( "github.com/roasbeef/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 diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 73132dba..7538be5b 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -39,9 +39,6 @@ const ( // TODO(roasbeef): should instead be child to make room for future // rotations, etc. identityKeyIndex = hdkeychain.HardenedKeyStart + 2 - - commitWeight int64 = 724 - htlcWeight int64 = 172 ) var (