Merge pull request #8774 from yyforyongyu/fix-size-calc
lnwallet+sweep: fix wrong unit used in fee calculation
This commit is contained in:
38 files changed
+301
-156
No files matched your search
+4
-3
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lntest/node"
|
||||
"github.com/lightningnetwork/lnd/lntest/rpc"
|
||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -2041,9 +2042,9 @@ func (h *HarnessTest) CalculateTxFee(tx *wire.MsgTx) btcutil.Amount {
|
||||
// CalculateTxWeight calculates the weight for a given tx.
|
||||
//
|
||||
// TODO(yy): use weight estimator to get more accurate result.
|
||||
func (h *HarnessTest) CalculateTxWeight(tx *wire.MsgTx) int64 {
|
||||
func (h *HarnessTest) CalculateTxWeight(tx *wire.MsgTx) lntypes.WeightUnit {
|
||||
utx := btcutil.NewTx(tx)
|
||||
return blockchain.GetTransactionWeight(utx)
|
||||
return lntypes.WeightUnit(blockchain.GetTransactionWeight(utx))
|
||||
}
|
||||
|
||||
// CalculateTxFeeRate calculates the fee rate for a given tx.
|
||||
@@ -2053,7 +2054,7 @@ func (h *HarnessTest) CalculateTxFeeRate(
|
||||
w := h.CalculateTxWeight(tx)
|
||||
fee := h.CalculateTxFee(tx)
|
||||
|
||||
return chainfee.NewSatPerKWeight(fee, uint64(w))
|
||||
return chainfee.NewSatPerKWeight(fee, w)
|
||||
}
|
||||
|
||||
// CalculateTxesFeeRate takes a list of transactions and estimates the fee rate
|
||||
|
||||
+7
-3
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@@ -212,8 +213,9 @@ func CalcStaticFee(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
||||
anchors = anchorSize
|
||||
}
|
||||
|
||||
return feePerKw.FeeForWeight(int64(commitWeight+htlcWeight*numHTLCs)) +
|
||||
anchors
|
||||
totalWeight := commitWeight + htlcWeight*numHTLCs
|
||||
|
||||
return feePerKw.FeeForWeight(lntypes.WeightUnit(totalWeight)) + anchors
|
||||
}
|
||||
|
||||
// CalculateMaxHtlc re-implements the RequiredRemoteChannelReserve of the
|
||||
@@ -266,8 +268,10 @@ func CalcStaticFeeBuffer(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
||||
|
||||
// Account for the HTLC which will be required when sending an htlc.
|
||||
numHTLCs++
|
||||
|
||||
totalWeight := commitWeight + numHTLCs*htlcWeight
|
||||
feeBuffer := lnwallet.CalcFeeBuffer(
|
||||
feePerKw, int64(commitWeight+numHTLCs*htlcWeight),
|
||||
feePerKw, lntypes.WeightUnit(totalWeight),
|
||||
)
|
||||
|
||||
return feeBuffer.ToSatoshis()
|
||||
|
||||
Reference in new issue
Block a user