Skip to content

Commit f960163

Browse files
committed
sweep: log tx label in GetSweepFee methods
Added argument 'label' to GetSweepFee and GetSweepFeeDetails. It is logged together with expected weight, fee and feerate.
1 parent 32f13ae commit f960163

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,11 @@ func (s *Client) getLoopOutSweepFee(ctx context.Context, confTarget int32) (
570570
htlc = swap.QuoteHtlcP2WSH
571571
}
572572

573+
label := "loopout-quote"
574+
573575
return s.sweeper.GetSweepFee(
574576
ctx, htlc.AddSuccessToEstimator, p2wshAddress, confTarget,
577+
label,
575578
)
576579
}
577580

loopin.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,12 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
10771077
}
10781078
}
10791079

1080+
label := fmt.Sprintf("loopin-timeout-%x", s.hash[:6])
1081+
10801082
// Calculate sweep tx fee.
10811083
fee, err := s.sweeper.GetSweepFee(
10821084
ctx, s.htlc.AddTimeoutToEstimator, s.timeoutAddr,
1083-
TimeoutTxConfTarget,
1085+
TimeoutTxConfTarget, label,
10841086
)
10851087
if err != nil {
10861088
return 0, err

loopin_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,13 @@ func handleHtlcExpiry(t *testing.T, ctx *loopInTestContext, inSwap *loopInSwap,
312312
// Expect timeout tx to be published.
313313
timeoutTx := <-ctx.lnd.TxPublishChannel
314314

315+
label := fmt.Sprintf("loopin-timeout-%x", inSwap.hash[:6])
316+
315317
// We can just get our sweep fee as we would in the swap code because
316318
// our estimate is static.
317319
fee, err := inSwap.sweeper.GetSweepFee(
318320
context.Background(), inSwap.htlc.AddTimeoutToEstimator,
319-
inSwap.timeoutAddr, TimeoutTxConfTarget,
321+
inSwap.timeoutAddr, TimeoutTxConfTarget, label,
320322
)
321323
require.NoError(t, err)
322324
cost.Onchain += fee

sweep/sweeper.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,27 @@ func (s *Sweeper) CreateSweepTx(
177177

178178
// GetSweepFee calculates the required tx fee to spend to P2WKH. It takes a
179179
// function that is expected to add the weight of the input to the weight
180-
// estimator.
180+
// estimator. It also takes a label used for logging.
181181
func (s *Sweeper) GetSweepFee(ctx context.Context,
182182
addInputEstimate func(*input.TxWeightEstimator) error,
183-
destAddr btcutil.Address, sweepConfTarget int32) (
183+
destAddr btcutil.Address, sweepConfTarget int32, label string) (
184184
btcutil.Amount, error) {
185185

186186
// Use GetSweepFeeDetails to get the fee and other unused data.
187187
fee, _, _, err := s.GetSweepFeeDetails(
188-
ctx, addInputEstimate, destAddr, sweepConfTarget,
188+
ctx, addInputEstimate, destAddr, sweepConfTarget, label,
189189
)
190190

191191
return fee, err
192192
}
193193

194194
// GetSweepFeeDetails calculates the required tx fee to spend to P2WKH. It takes
195195
// a function that is expected to add the weight of the input to the weight
196-
// estimator. It returns also the fee rate and transaction weight.
196+
// estimator. It also takes a label used for logging. It returns also the fee
197+
// rate and transaction weight.
197198
func (s *Sweeper) GetSweepFeeDetails(ctx context.Context,
198199
addInputEstimate func(*input.TxWeightEstimator) error,
199-
destAddr btcutil.Address, sweepConfTarget int32) (
200+
destAddr btcutil.Address, sweepConfTarget int32, label string) (
200201
btcutil.Amount, chainfee.SatPerKWeight, lntypes.WeightUnit, error) {
201202

202203
// Get fee estimate from lnd.
@@ -224,7 +225,14 @@ func (s *Sweeper) GetSweepFeeDetails(ctx context.Context,
224225
// Find weight.
225226
weight := weightEstimate.Weight()
226227

227-
return feeRate.FeeForWeight(weight), feeRate, weight, nil
228+
// Find fee.
229+
fee := feeRate.FeeForWeight(weight)
230+
231+
log.Debugf("Estimations for a tx (label=%s): weight=%v, fee=%v, "+
232+
"feerate=%v, sweepConfTarget=%d.", label, weight, fee, feeRate,
233+
sweepConfTarget)
234+
235+
return fee, feeRate, weight, nil
228236
}
229237

230238
// AddOutputEstimate adds output to weight estimator.

0 commit comments

Comments
 (0)