lnwallet: convert all references to transaction/block cost to weight

This commit is contained in:
Olaoluwa Osuntokun 2017-05-16 18:50:50 -07:00
parent 49e27c77dd
commit 392f6b5d8a
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -5,12 +5,12 @@ import (
) )
const ( 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: // is calculated as:
// Weight = 4 * BaseSize + WitnessSize (weight). // Weight = 4 * BaseSize + WitnessSize (weight).
// BaseSize - size of the transaction without witness data (bytes). // BaseSize - size of the transaction without witness data (bytes).
// WitnessSize - witness size (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 // P2WSHSize 34 bytes
// - OP_0: 1 byte // - OP_0: 1 byte
@ -53,7 +53,7 @@ const (
// - ScriptSig: 0 bytes // - ScriptSig: 0 bytes
// - Witness <---- we use "Witness" instead of "ScriptSig" for // - Witness <---- we use "Witness" instead of "ScriptSig" for
// transaction validation, but "Witness" is stored // 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 // we separate the calculation of ordinary data
// from witness data. // from witness data.
// - Sequence: 4 bytes // - Sequence: 4 bytes
@ -97,14 +97,14 @@ const (
BaseCommitmentTxSize = 4 + 1 + FundingInputSize + 1 + BaseCommitmentTxSize = 4 + 1 + FundingInputSize + 1 +
CommitmentDelayOutput + CommitmentKeyHashOutput + 4 CommitmentDelayOutput + CommitmentKeyHashOutput + 4
// BaseCommitmentTxCost 500 weight // BaseCommitmentTxWeight 500 weight
BaseCommitmentTxCost = blockchain.WitnessScaleFactor * BaseCommitmentTxSize BaseCommitmentTxWeight = blockchain.WitnessScaleFactor * BaseCommitmentTxSize
// WitnessCommitmentTxCost 224 weight // WitnessCommitmentTxWeight 224 weight
WitnessCommitmentTxCost = WitnessHeaderSize + WitnessSize WitnessCommitmentTxWeight = WitnessHeaderSize + WitnessSize
// HTLCCost 172 weight // HTLCWeight 172 weight
HTLCCost = blockchain.WitnessScaleFactor * HTLCSize HTLCWeight = blockchain.WitnessScaleFactor * HTLCSize
// MaxHTLCNumber shows as the maximum number HTLCs which can be // MaxHTLCNumber shows as the maximum number HTLCs which can be
// included in commitment transaction. This numbers was calculated by // included in commitment transaction. This numbers was calculated by
@ -114,19 +114,19 @@ const (
MaxHTLCNumber = 1253 MaxHTLCNumber = 1253
) )
// estimateCommitTxCost estimate commitment transaction cost depending on the // estimateCommitTxWeight estimate commitment transaction weight depending on
// precalculated cost of base transaction, witness data, which is needed for // the precalculated weight of base transaction, witness data, which is needed
// paying for funding tx, and htlc cost multiplied by their count. // for paying for funding tx, and htlc weight multiplied by their count.
func estimateCommitTxCost(count int, prediction bool) int64 { func estimateCommitTxWeight(count int, prediction bool) int64 {
// Make prediction about the size of commitment transaction with // Make prediction about the size of commitment transaction with
// additional HTLC. // additional HTLC.
if prediction { if prediction {
count++ count++
} }
htlcCost := int64(count * HTLCCost) htlcWeight := int64(count * HTLCWeight)
baseCost := int64(BaseCommitmentTxCost) baseWeight := int64(BaseCommitmentTxWeight)
witnessCost := int64(WitnessCommitmentTxCost) witnessWeight := int64(WitnessCommitmentTxWeight)
return htlcCost + baseCost + witnessCost return htlcWeight + baseWeight + witnessWeight
} }