mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 11:09:23 +01:00
sweep: rename fee()
to feeWithParent()
for clarity
To make sure the caller has a better idea about what this method is doing.
This commit is contained in:
parent
370e4ce98d
commit
59fbcb18d5
5 changed files with 24 additions and 19 deletions
|
@ -222,7 +222,7 @@ func (t *txInputSet) enoughInput() bool {
|
|||
// We did not have enough input for a change output. Check if we have
|
||||
// enough input to pay the fees for a transaction with no change
|
||||
// output.
|
||||
fee := t.weightEstimate(false).fee()
|
||||
fee := t.weightEstimate(false).feeWithParent()
|
||||
if t.inputTotal < t.requiredOutput+fee {
|
||||
return false
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ func (t *txInputSet) addToState(inp input.Input,
|
|||
newSet.inputTotal += value
|
||||
|
||||
// Recalculate the tx fee.
|
||||
fee := newSet.weightEstimate(true).fee()
|
||||
fee := newSet.weightEstimate(true).feeWithParent()
|
||||
|
||||
// Calculate the new output value.
|
||||
if reqOut != nil {
|
||||
|
|
|
@ -35,7 +35,7 @@ func TestTxInputSet(t *testing.T) {
|
|||
t.Fatal("expected add of positively yielding input to succeed")
|
||||
}
|
||||
|
||||
fee := set.weightEstimate(true).fee()
|
||||
fee := set.weightEstimate(true).feeWithParent()
|
||||
require.Equal(t, btcutil.Amount(487), fee)
|
||||
|
||||
// The tx output should now be 700-487 = 213 sats. The dust limit isn't
|
||||
|
@ -164,13 +164,13 @@ func TestTxInputSetRequiredOutput(t *testing.T) {
|
|||
require.True(t, set.add(inp, constraintsRegular), "failed adding input")
|
||||
|
||||
// The fee needed to pay for this input and output should be 439 sats.
|
||||
fee := set.weightEstimate(false).fee()
|
||||
fee := set.weightEstimate(false).feeWithParent()
|
||||
require.Equal(t, btcutil.Amount(439), fee)
|
||||
|
||||
// Since the tx set currently pays no fees, we expect the current
|
||||
// change to actually be negative, since this is what it would cost us
|
||||
// in fees to add a change output.
|
||||
feeWithChange := set.weightEstimate(true).fee()
|
||||
feeWithChange := set.weightEstimate(true).feeWithParent()
|
||||
if set.changeOutput != -feeWithChange {
|
||||
t.Fatalf("expected negative change of %v, had %v",
|
||||
-feeWithChange, set.changeOutput)
|
||||
|
@ -188,9 +188,10 @@ func TestTxInputSetRequiredOutput(t *testing.T) {
|
|||
// Now we add a an input that is large enough to pay the fee for the
|
||||
// transaction without a change output, but not large enough to afford
|
||||
// adding a change output.
|
||||
extraInput1 := weight.fee() + 100
|
||||
require.True(t, set.add(createP2WKHInput(extraInput1), constraintsRegular),
|
||||
"expected add of positively yielding input to succeed")
|
||||
extraInput1 := weight.feeWithParent() + 100
|
||||
require.True(t, set.add(
|
||||
createP2WKHInput(extraInput1), constraintsRegular,
|
||||
), "expected add of positively yielding input to succeed")
|
||||
|
||||
// The change should be negative, since we would have to add a change
|
||||
// output, which we cannot yet afford.
|
||||
|
@ -208,10 +209,12 @@ func TestTxInputSetRequiredOutput(t *testing.T) {
|
|||
require.NoError(t, weight.add(dummyInput))
|
||||
|
||||
// We add what is left to reach this value.
|
||||
extraInput2 := weight.fee() - extraInput1 + 100
|
||||
extraInput2 := weight.feeWithParent() - extraInput1 + 100
|
||||
|
||||
// Add this input, which should result in the change now being 100 sats.
|
||||
require.True(t, set.add(createP2WKHInput(extraInput2), constraintsRegular))
|
||||
require.True(t, set.add(
|
||||
createP2WKHInput(extraInput2), constraintsRegular,
|
||||
))
|
||||
|
||||
// The change should be 100, since this is what is left after paying
|
||||
// fees in case of a change output.
|
||||
|
@ -232,7 +235,7 @@ func TestTxInputSetRequiredOutput(t *testing.T) {
|
|||
|
||||
// We expect the change to everything that is left after paying the tx
|
||||
// fee.
|
||||
extraInput3 := weight.fee() - extraInput1 - extraInput2 + 1000
|
||||
extraInput3 := weight.feeWithParent() - extraInput1 - extraInput2 + 1000
|
||||
require.True(t, set.add(createP2WKHInput(extraInput3), constraintsRegular))
|
||||
|
||||
change = set.changeOutput
|
||||
|
|
|
@ -44,7 +44,7 @@ func createSweepTx(inputs []input.Input, outputs []*wire.TxOut,
|
|||
return nil, 0, err
|
||||
}
|
||||
|
||||
txFee := estimator.fee()
|
||||
txFee := estimator.feeWithParent()
|
||||
|
||||
var (
|
||||
// Create the sweep transaction that we will be building. We
|
||||
|
|
|
@ -106,9 +106,9 @@ func (w *weightEstimator) weight() int {
|
|||
return w.estimator.Weight()
|
||||
}
|
||||
|
||||
// fee returns the tx fee to use for the aggregated inputs and outputs, taking
|
||||
// into account unconfirmed parent transactions (cpfp).
|
||||
func (w *weightEstimator) fee() btcutil.Amount {
|
||||
// feeWithParent returns the tx fee to use for the aggregated inputs and
|
||||
// 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())
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@ func TestWeightEstimator(t *testing.T) {
|
|||
// The expectations is that this input is added.
|
||||
const expectedWeight1 = 322
|
||||
require.Equal(t, expectedWeight1, w.weight())
|
||||
require.Equal(t, testFeeRate.FeeForWeight(expectedWeight1), w.fee())
|
||||
require.Equal(t, testFeeRate.FeeForWeight(expectedWeight1),
|
||||
w.feeWithParent())
|
||||
|
||||
// Define a parent transaction that pays a fee of 30000 sat/kw.
|
||||
parentTxHighFee := &input.TxInfo{
|
||||
|
@ -51,7 +52,8 @@ func TestWeightEstimator(t *testing.T) {
|
|||
// rate than the child. We expect no additional fee on the child.
|
||||
const expectedWeight2 = expectedWeight1 + 280
|
||||
require.Equal(t, expectedWeight2, w.weight())
|
||||
require.Equal(t, testFeeRate.FeeForWeight(expectedWeight2), w.fee())
|
||||
require.Equal(t, testFeeRate.FeeForWeight(expectedWeight2),
|
||||
w.feeWithParent())
|
||||
|
||||
// Define a parent transaction that pays a fee of 10000 sat/kw.
|
||||
parentTxLowFee := &input.TxInfo{
|
||||
|
@ -78,7 +80,7 @@ func TestWeightEstimator(t *testing.T) {
|
|||
expectedWeight3+parentTxLowFee.Weight,
|
||||
) - parentTxLowFee.Fee
|
||||
|
||||
require.Equal(t, expectedFee, w.fee())
|
||||
require.Equal(t, expectedFee, w.feeWithParent())
|
||||
}
|
||||
|
||||
// TestWeightEstimatorMaxFee tests that the weight estimator correctly caps the
|
||||
|
@ -118,7 +120,7 @@ func TestWeightEstimatorMaxFee(t *testing.T) {
|
|||
//
|
||||
// Thus we cap at the maxFee.
|
||||
expectedFee := maxFeeRate.FeeForWeight(childWeight)
|
||||
require.Equal(t, expectedFee, w.fee())
|
||||
require.Equal(t, expectedFee, w.feeWithParent())
|
||||
}
|
||||
|
||||
// TestWeightEstimatorAddOutput tests that adding the raw P2WKH output to the
|
||||
|
|
Loading…
Add table
Reference in a new issue