From 392f6b5d8a3624e76af32dcfe69114bdd4127c5e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 16 May 2017 18:50:50 -0700 Subject: [PATCH] lnwallet: convert all references to transaction/block cost to weight --- lnwallet/size.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lnwallet/size.go b/lnwallet/size.go index 7320e751..cadde8dd 100644 --- a/lnwallet/size.go +++ b/lnwallet/size.go @@ -5,12 +5,12 @@ import ( ) const ( - // The weight(cost), which is different from the !size! (see BIP-141), + // The weight(weight), which is different from the !size! (see BIP-141), // is calculated as: // Weight = 4 * BaseSize + WitnessSize (weight). // BaseSize - size of the transaction without witness data (bytes). // WitnessSize - witness size (bytes). - // Weight - the metric for determining the cost of the transaction. + // Weight - the metric for determining the weight of the transaction. // P2WSHSize 34 bytes // - OP_0: 1 byte @@ -53,7 +53,7 @@ const ( // - ScriptSig: 0 bytes // - Witness <---- we use "Witness" instead of "ScriptSig" for // transaction validation, but "Witness" is stored - // separately and cost for it size is smaller. So + // separately and weight for it size is smaller. So // we separate the calculation of ordinary data // from witness data. // - Sequence: 4 bytes @@ -97,14 +97,14 @@ const ( BaseCommitmentTxSize = 4 + 1 + FundingInputSize + 1 + CommitmentDelayOutput + CommitmentKeyHashOutput + 4 - // BaseCommitmentTxCost 500 weight - BaseCommitmentTxCost = blockchain.WitnessScaleFactor * BaseCommitmentTxSize + // BaseCommitmentTxWeight 500 weight + BaseCommitmentTxWeight = blockchain.WitnessScaleFactor * BaseCommitmentTxSize - // WitnessCommitmentTxCost 224 weight - WitnessCommitmentTxCost = WitnessHeaderSize + WitnessSize + // WitnessCommitmentTxWeight 224 weight + WitnessCommitmentTxWeight = WitnessHeaderSize + WitnessSize - // HTLCCost 172 weight - HTLCCost = blockchain.WitnessScaleFactor * HTLCSize + // HTLCWeight 172 weight + HTLCWeight = blockchain.WitnessScaleFactor * HTLCSize // MaxHTLCNumber shows as the maximum number HTLCs which can be // included in commitment transaction. This numbers was calculated by @@ -114,19 +114,19 @@ const ( MaxHTLCNumber = 1253 ) -// estimateCommitTxCost estimate commitment transaction cost depending on the -// precalculated cost of base transaction, witness data, which is needed for -// paying for funding tx, and htlc cost multiplied by their count. -func estimateCommitTxCost(count int, prediction bool) int64 { +// estimateCommitTxWeight estimate commitment transaction weight depending on +// the precalculated weight of base transaction, witness data, which is needed +// for paying for funding tx, and htlc weight multiplied by their count. +func estimateCommitTxWeight(count int, prediction bool) int64 { // Make prediction about the size of commitment transaction with // additional HTLC. if prediction { count++ } - htlcCost := int64(count * HTLCCost) - baseCost := int64(BaseCommitmentTxCost) - witnessCost := int64(WitnessCommitmentTxCost) + htlcWeight := int64(count * HTLCWeight) + baseWeight := int64(BaseCommitmentTxWeight) + witnessWeight := int64(WitnessCommitmentTxWeight) - return htlcCost + baseCost + witnessCost + return htlcWeight + baseWeight + witnessWeight }