diff --git a/sweep/tx_input_set.go b/sweep/tx_input_set.go index 996911b94..48b5115a3 100644 --- a/sweep/tx_input_set.go +++ b/sweep/tx_input_set.go @@ -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 { diff --git a/sweep/tx_input_set_test.go b/sweep/tx_input_set_test.go index be75a3147..ba6a8900f 100644 --- a/sweep/tx_input_set_test.go +++ b/sweep/tx_input_set_test.go @@ -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 diff --git a/sweep/txgenerator.go b/sweep/txgenerator.go index 57e0cce17..a06078b44 100644 --- a/sweep/txgenerator.go +++ b/sweep/txgenerator.go @@ -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 diff --git a/sweep/weight_estimator.go b/sweep/weight_estimator.go index 7dae25d80..2a923d5a0 100644 --- a/sweep/weight_estimator.go +++ b/sweep/weight_estimator.go @@ -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()) diff --git a/sweep/weight_estimator_test.go b/sweep/weight_estimator_test.go index 350da9af3..d5beb5174 100644 --- a/sweep/weight_estimator_test.go +++ b/sweep/weight_estimator_test.go @@ -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