Skip to content

Commit 697e8d6

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 f8c1607 commit 697e8d6

File tree

6 files changed

+53
-8
lines changed

6 files changed

+53
-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

loopd/log.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/lightninglabs/loop/liquidity"
1212
"github.com/lightninglabs/loop/loopdb"
1313
"github.com/lightninglabs/loop/notifications"
14+
"github.com/lightninglabs/loop/sweep"
1415
"github.com/lightninglabs/loop/sweepbatcher"
1516
"github.com/lightningnetwork/lnd"
1617
"github.com/lightningnetwork/lnd/build"
@@ -52,6 +53,9 @@ func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) {
5253
lnd.AddSubLogger(
5354
root, notifications.Subsystem, intercept, notifications.UseLogger,
5455
)
56+
lnd.AddSubLogger(
57+
root, sweep.Subsystem, intercept, sweep.UseLogger,
58+
)
5559
}
5660

5761
// genSubLogger creates a logger for a subsystem. We provide an instance of

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/log.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package sweep
2+
3+
import (
4+
"github.com/btcsuite/btclog"
5+
"github.com/lightningnetwork/lnd/build"
6+
)
7+
8+
// Subsystem defines the sub system name of this package.
9+
const Subsystem = "SWP"
10+
11+
// log is a logger that is initialized with no output filters. This means the
12+
// package will not perform any logging by default until the caller requests
13+
// it.
14+
var log btclog.Logger
15+
16+
// The default amount of logging is none.
17+
func init() {
18+
UseLogger(build.NewSubLogger(Subsystem, nil))
19+
}
20+
21+
// UseLogger uses a specified Logger to output package logging info. This
22+
// should be used in preference to SetLogWriter if the caller is also using
23+
// btclog.
24+
func UseLogger(logger btclog.Logger) {
25+
log = logger
26+
}

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)