multi: apply the new type lntypes.WeightUnit

This commit is contained in:
yyforyongyu committed 2024-05-25 13:37:13 +08:00
1 parent dc9a0b31c0
commit 8da68bb7db
36 files changed
+178 -133

No files matched your search

+1 -1
View File
@@ -309,7 +309,7 @@ func fundingFee(numInput int, change bool) btcutil.Amount {
weightEstimate.AddP2TROutput()
}
totalWeight := int64(weightEstimate.Weight())
totalWeight := weightEstimate.Weight()
return feeRate.FeeForWeight(totalWeight)
}
+1 -1
View File
@@ -379,7 +379,7 @@ func testRescanAddressDetection(ht *lntest.HarnessTest) {
estimator := input.TxWeightEstimator{}
estimator.AddP2WKHInput()
estimator.AddP2WKHOutput()
estimatedWeight := int64(estimator.Weight())
estimatedWeight := estimator.Weight()
requiredFee := feeRate.FeeForWeight(estimatedWeight)
tx := wire.NewMsgTx(2)
+7 -6
View File
@@ -271,7 +271,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
// We expect the fees to increase by i*delta.
expectedFee := startFeeAnchor + feeDelta.MulF64(float64(i))
expectedFeeRate := chainfee.NewSatPerKWeight(
expectedFee, uint64(txWeight),
expectedFee, txWeight,
)
// We should see Bob's anchor sweeping tx being fee bumped
@@ -608,7 +608,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
// We expect the fees to increase by i*delta.
expectedFee := startFeeAnchor + feeDelta.MulF64(float64(i))
expectedFeeRate := chainfee.NewSatPerKWeight(
expectedFee, uint64(txWeight),
expectedFee, txWeight,
)
// We should see Bob's anchor sweeping tx being fee bumped
@@ -929,7 +929,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
outgoingBudget := 2 * invoiceAmt
outgoingTxSize := ht.CalculateTxWeight(outgoingSweep)
outgoingEndFeeRate := chainfee.NewSatPerKWeight(
outgoingBudget, uint64(outgoingTxSize),
outgoingBudget, outgoingTxSize,
)
// Assert the initial sweeping tx is using the start fee rate.
@@ -950,7 +950,8 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
// assertSweepFeeRate is a helper closure that asserts the expected fee
// rate is used at the given position for a sweeping tx.
assertSweepFeeRate := func(sweepTx *wire.MsgTx,
startFeeRate, delta chainfee.SatPerKWeight, txSize int64,
startFeeRate, delta chainfee.SatPerKWeight,
txSize lntypes.WeightUnit,
deadline, position int32, desc string) {
// Bob's HTLC sweeping tx should be fee bumped.
@@ -1068,7 +1069,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
incomingBudget := invoiceAmt.MulF64(contractcourt.DefaultBudgetRatio)
incomingTxSize := ht.CalculateTxWeight(incomingSweep)
incomingEndFeeRate := chainfee.NewSatPerKWeight(
incomingBudget, uint64(incomingTxSize),
incomingBudget, incomingTxSize,
)
// Assert the initial sweeping tx is using the start fee rate.
@@ -1415,7 +1416,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
// Calculate the ending fee rate and fee rate delta used in his fee
// function.
bobTxWeight := uint64(ht.CalculateTxWeight(bobSweepTx))
bobTxWeight := ht.CalculateTxWeight(bobSweepTx)
bobEndingFeeRate := chainfee.NewSatPerKWeight(bobBudget, bobTxWeight)
bobFeeRateDelta := (bobEndingFeeRate - bobStartFeeRate) /
chainfee.SatPerKWeight(deadlineB-1)
+13 -11
View File
@@ -22,6 +22,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/node"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/stretchr/testify/require"
)
@@ -187,7 +188,7 @@ func testTaprootComputeInputScriptKeySpendBip86(ht *lntest.HarnessTest,
estimator := input.TxWeightEstimator{}
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
estimator.AddP2WKHOutput()
estimatedWeight := int64(estimator.Weight())
estimatedWeight := estimator.Weight()
requiredFee := feeRate.FeeForWeight(estimatedWeight)
tx := wire.NewMsgTx(2)
@@ -278,7 +279,7 @@ func testTaprootSignOutputRawScriptSpend(ht *lntest.HarnessTest,
)
estimator.AddP2WKHOutput()
estimatedWeight := int64(estimator.Weight())
estimatedWeight := estimator.Weight()
sigHash := txscript.SigHashDefault
if len(sigHashType) != 0 {
sigHash = sigHashType[0]
@@ -431,7 +432,7 @@ func testTaprootSignOutputRawKeySpendBip86(ht *lntest.HarnessTest,
estimator := input.TxWeightEstimator{}
estimator.AddTaprootKeySpendInput(sigHash)
estimator.AddP2WKHOutput()
estimatedWeight := int64(estimator.Weight())
estimatedWeight := estimator.Weight()
requiredFee := feeRate.FeeForWeight(estimatedWeight)
tx := wire.NewMsgTx(2)
@@ -525,7 +526,7 @@ func testTaprootSignOutputRawKeySpendRootHash(ht *lntest.HarnessTest,
estimator := input.TxWeightEstimator{}
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
estimator.AddP2WKHOutput()
estimatedWeight := int64(estimator.Weight())
estimatedWeight := estimator.Weight()
requiredFee := feeRate.FeeForWeight(estimatedWeight)
tx := wire.NewMsgTx(2)
@@ -610,7 +611,7 @@ func testTaprootMuSig2KeySpendBip86(ht *lntest.HarnessTest,
estimator := input.TxWeightEstimator{}
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
estimator.AddP2WKHOutput()
estimatedWeight := int64(estimator.Weight())
estimatedWeight := estimator.Weight()
requiredFee := feeRate.FeeForWeight(estimatedWeight)
tx := wire.NewMsgTx(2)
@@ -740,7 +741,7 @@ func testTaprootMuSig2KeySpendRootHash(ht *lntest.HarnessTest,
estimator := input.TxWeightEstimator{}
estimator.AddTaprootKeySpendInput(txscript.SigHashDefault)
estimator.AddP2WKHOutput()
estimatedWeight := int64(estimator.Weight())
estimatedWeight := estimator.Weight()
requiredFee := feeRate.FeeForWeight(estimatedWeight)
tx := wire.NewMsgTx(2)
@@ -874,10 +875,11 @@ func testTaprootMuSig2ScriptSpend(ht *lntest.HarnessTest,
feeRate := chainfee.SatPerKWeight(12500)
estimator := input.TxWeightEstimator{}
estimator.AddTapscriptInput(
len([]byte("foobar"))+len(leaf1.Script)+1, tapscript,
lntypes.WeightUnit(len([]byte("foobar"))+len(leaf1.Script)+1),
tapscript,
)
estimator.AddP2WKHOutput()
estimatedWeight := int64(estimator.Weight())
estimatedWeight := estimator.Weight()
requiredFee := feeRate.FeeForWeight(estimatedWeight)
tx := wire.NewMsgTx(2)
@@ -956,7 +958,7 @@ func testTaprootMuSig2CombinedLeafKeySpend(ht *lntest.HarnessTest,
input.TaprootSignatureWitnessSize, tapscript,
)
estimator.AddP2WKHOutput()
estimatedWeight := int64(estimator.Weight())
estimatedWeight := estimator.Weight()
requiredFee := feeRate.FeeForWeight(estimatedWeight)
tx := wire.NewMsgTx(2)
@@ -1525,7 +1527,7 @@ func sendToTaprootOutput(ht *lntest.HarnessTest, hn *node.HarnessNode,
// spend request, the given sweep address' balance is verified to be seen as
// funds belonging to the wallet.
func publishTxAndConfirmSweep(ht *lntest.HarnessTest, node *node.HarnessNode,
tx *wire.MsgTx, estimatedWeight int64,
tx *wire.MsgTx, estimatedWeight lntypes.WeightUnit,
spendRequest *chainrpc.SpendRequest, sweepAddr string) {
ht.Helper()
@@ -1564,7 +1566,7 @@ func publishTxAndConfirmSweep(ht *lntest.HarnessTest, node *node.HarnessNode,
// Since Schnorr signatures are fixed size, we must be able to estimate
// the size of this transaction exactly.
txWeight := blockchain.GetTransactionWeight(btcutil.NewTx(tx))
require.Equal(ht, estimatedWeight, txWeight)
require.EqualValues(ht, estimatedWeight, txWeight)
txReq := &walletrpc.Transaction{
TxHex: buf.Bytes(),