mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-02 03:54:26 +02:00
multi: apply the new type lntypes.WeightUnit
This commit is contained in:
@@ -211,7 +211,7 @@ func (b *BudgetAggregator) filterInputs(inputs InputsMap) InputsMap {
|
||||
}
|
||||
|
||||
// Skip inputs that has too little budget.
|
||||
minFee := minFeeRate.FeeForWeight(int64(size))
|
||||
minFee := minFeeRate.FeeForWeight(size)
|
||||
if pi.params.Budget < minFee {
|
||||
log.Warnf("Skipped input=%v: has budget=%v, but the "+
|
||||
"min fee requires %v", op, pi.params.Budget,
|
||||
@@ -224,7 +224,7 @@ func (b *BudgetAggregator) filterInputs(inputs InputsMap) InputsMap {
|
||||
startingFeeRate := pi.params.StartingFeeRate.UnwrapOr(
|
||||
chainfee.SatPerKWeight(0),
|
||||
)
|
||||
startingFee := startingFeeRate.FeeForWeight(int64(size))
|
||||
startingFee := startingFeeRate.FeeForWeight(size)
|
||||
if pi.params.Budget < startingFee {
|
||||
log.Errorf("Skipped input=%v: has budget=%v, but the "+
|
||||
"starting fee requires %v", op,
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -34,14 +35,15 @@ func TestBudgetAggregatorFilterInputs(t *testing.T) {
|
||||
|
||||
// Mock the `SizeUpperBound` method to return an error exactly once.
|
||||
dummyErr := errors.New("dummy error")
|
||||
wtErr.On("SizeUpperBound").Return(0, false, dummyErr).Once()
|
||||
wtErr.On("SizeUpperBound").Return(
|
||||
lntypes.WeightUnit(0), false, dummyErr).Once()
|
||||
|
||||
// Create a mock WitnessType that gives the size.
|
||||
wt := &input.MockWitnessType{}
|
||||
defer wt.AssertExpectations(t)
|
||||
|
||||
// Mock the `SizeUpperBound` method to return the size four times.
|
||||
const wtSize = 100
|
||||
const wtSize lntypes.WeightUnit = 100
|
||||
wt.On("SizeUpperBound").Return(wtSize, true, nil).Times(4)
|
||||
|
||||
// Create a mock input that will be filtered out due to error.
|
||||
@@ -396,7 +398,7 @@ func TestBudgetInputSetClusterInputs(t *testing.T) {
|
||||
|
||||
// Mock the `SizeUpperBound` method to return the size 10 times since
|
||||
// we are using ten inputs.
|
||||
const wtSize = 100
|
||||
const wtSize lntypes.WeightUnit = 100
|
||||
wt.On("SizeUpperBound").Return(wtSize, true, nil).Times(10)
|
||||
wt.On("String").Return("mock witness type")
|
||||
|
||||
|
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/labels"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
@@ -155,7 +156,7 @@ func (r *BumpRequest) MaxFeeRateAllowed() (chainfee.SatPerKWeight, error) {
|
||||
// calcSweepTxWeight calculates the weight of the sweep tx. It assumes a
|
||||
// sweeping tx always has a single output(change).
|
||||
func calcSweepTxWeight(inputs []input.Input,
|
||||
outputPkScript []byte) (uint64, error) {
|
||||
outputPkScript []byte) (lntypes.WeightUnit, error) {
|
||||
|
||||
// Use a const fee rate as we only use the weight estimator to
|
||||
// calculate the size.
|
||||
@@ -175,7 +176,7 @@ func calcSweepTxWeight(inputs []input.Input,
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return uint64(estimator.weight()), nil
|
||||
return estimator.weight(), nil
|
||||
}
|
||||
|
||||
// BumpResult is used by the Bumper to send updates about the tx being
|
||||
|
@@ -314,7 +314,8 @@ func (b *BudgetInputSet) AddWalletInputs(wallet Wallet) error {
|
||||
}
|
||||
b.addInput(pi)
|
||||
|
||||
log.Debugf("Added wallet input %v to input set", pi)
|
||||
log.Debugf("Added wallet input to input set: op=%v, amt=%v",
|
||||
pi.OutPoint(), utxo.Value)
|
||||
|
||||
// Return if we've reached the minimum output amount.
|
||||
if !b.NeedWalletInput() {
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
)
|
||||
|
||||
@@ -15,7 +16,7 @@ type weightEstimator struct {
|
||||
feeRate chainfee.SatPerKWeight
|
||||
parents map[chainhash.Hash]struct{}
|
||||
parentsFee btcutil.Amount
|
||||
parentsWeight int64
|
||||
parentsWeight lntypes.WeightUnit
|
||||
|
||||
// maxFeeRate is the max allowed fee rate configured by the user.
|
||||
maxFeeRate chainfee.SatPerKWeight
|
||||
@@ -102,7 +103,7 @@ func (w *weightEstimator) addOutput(txOut *wire.TxOut) {
|
||||
}
|
||||
|
||||
// weight gets the estimated weight of the transaction.
|
||||
func (w *weightEstimator) weight() int {
|
||||
func (w *weightEstimator) weight() lntypes.WeightUnit {
|
||||
return w.estimator.Weight()
|
||||
}
|
||||
|
||||
@@ -111,7 +112,7 @@ func (w *weightEstimator) weight() int {
|
||||
// parent transactions.
|
||||
func (w *weightEstimator) fee() btcutil.Amount {
|
||||
// Calculate the weight of the transaction.
|
||||
weight := int64(w.estimator.Weight())
|
||||
weight := w.estimator.Weight()
|
||||
|
||||
// Calculate the fee.
|
||||
fee := w.feeRate.FeeForWeight(weight)
|
||||
@@ -123,7 +124,7 @@ func (w *weightEstimator) fee() btcutil.Amount {
|
||||
// outputs, taking into account unconfirmed parent transactions (cpfp).
|
||||
func (w *weightEstimator) feeWithParent() btcutil.Amount {
|
||||
// Calculate fee and weight for just this tx.
|
||||
childWeight := int64(w.estimator.Weight())
|
||||
childWeight := w.estimator.Weight()
|
||||
|
||||
// Add combined weight of unconfirmed parent txes.
|
||||
totalWeight := childWeight + w.parentsWeight
|
||||
|
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -28,7 +29,7 @@ func TestWeightEstimator(t *testing.T) {
|
||||
require.NoError(t, w.add(&input1))
|
||||
|
||||
// The expectations is that this input is added.
|
||||
const expectedWeight1 = 322
|
||||
const expectedWeight1 lntypes.WeightUnit = 322
|
||||
require.Equal(t, expectedWeight1, w.weight())
|
||||
require.Equal(t, testFeeRate.FeeForWeight(expectedWeight1),
|
||||
w.feeWithParent())
|
||||
@@ -50,7 +51,7 @@ func TestWeightEstimator(t *testing.T) {
|
||||
|
||||
// Pay for parent isn't possible because the parent pays a higher fee
|
||||
// rate than the child. We expect no additional fee on the child.
|
||||
const expectedWeight2 = expectedWeight1 + 280
|
||||
const expectedWeight2 lntypes.WeightUnit = expectedWeight1 + 280
|
||||
require.Equal(t, expectedWeight2, w.weight())
|
||||
require.Equal(t, testFeeRate.FeeForWeight(expectedWeight2),
|
||||
w.feeWithParent())
|
||||
@@ -70,7 +71,7 @@ func TestWeightEstimator(t *testing.T) {
|
||||
require.NoError(t, w.add(&input3))
|
||||
|
||||
// Expect the weight to increase because of the third input.
|
||||
const expectedWeight3 = expectedWeight2 + 280
|
||||
const expectedWeight3 lntypes.WeightUnit = expectedWeight2 + 280
|
||||
require.Equal(t, expectedWeight3, w.weight())
|
||||
|
||||
// Expect the fee to cover the child and the parent transaction at 20
|
||||
@@ -107,7 +108,7 @@ func TestWeightEstimatorMaxFee(t *testing.T) {
|
||||
require.NoError(t, w.add(&childInput))
|
||||
|
||||
// The child weight should be 322 weight uints.
|
||||
const childWeight = 322
|
||||
const childWeight lntypes.WeightUnit = 322
|
||||
require.Equal(t, childWeight, w.weight())
|
||||
|
||||
// Check the fee is capped at the maximum allowed fee. The
|
||||
|
Reference in New Issue
Block a user