sweep: log tx label in GetSweepFee methods

Added argument 'label' to GetSweepFee and GetSweepFeeDetails. It is logged
together with expected weight, fee and feerate.
This commit is contained in:
Boris Nagaev 2024-10-21 15:35:32 -03:00
parent f8c1607154
commit 697e8d6255
No known key found for this signature in database
6 changed files with 53 additions and 8 deletions

26
sweep/log.go Normal file
View file

@ -0,0 +1,26 @@
package sweep
import (
"github.com/btcsuite/btclog"
"github.com/lightningnetwork/lnd/build"
)
// Subsystem defines the sub system name of this package.
const Subsystem = "SWP"
// log is a logger that is initialized with no output filters. This means the
// package will not perform any logging by default until the caller requests
// it.
var log btclog.Logger
// The default amount of logging is none.
func init() {
UseLogger(build.NewSubLogger(Subsystem, nil))
}
// UseLogger uses a specified Logger to output package logging info. This
// should be used in preference to SetLogWriter if the caller is also using
// btclog.
func UseLogger(logger btclog.Logger) {
log = logger
}

View file

@ -177,15 +177,15 @@ func (s *Sweeper) CreateSweepTx(
// GetSweepFee calculates the required tx fee to spend to P2WKH. It takes a
// function that is expected to add the weight of the input to the weight
// estimator.
// estimator. It also takes a label used for logging.
func (s *Sweeper) GetSweepFee(ctx context.Context,
addInputEstimate func(*input.TxWeightEstimator) error,
destAddr btcutil.Address, sweepConfTarget int32) (
destAddr btcutil.Address, sweepConfTarget int32, label string) (
btcutil.Amount, error) {
// Use GetSweepFeeDetails to get the fee and other unused data.
fee, _, _, err := s.GetSweepFeeDetails(
ctx, addInputEstimate, destAddr, sweepConfTarget,
ctx, addInputEstimate, destAddr, sweepConfTarget, label,
)
return fee, err
@ -193,10 +193,11 @@ func (s *Sweeper) GetSweepFee(ctx context.Context,
// GetSweepFeeDetails calculates the required tx fee to spend to P2WKH. It takes
// a function that is expected to add the weight of the input to the weight
// estimator. It returns also the fee rate and transaction weight.
// estimator. It also takes a label used for logging. It returns also the fee
// rate and transaction weight.
func (s *Sweeper) GetSweepFeeDetails(ctx context.Context,
addInputEstimate func(*input.TxWeightEstimator) error,
destAddr btcutil.Address, sweepConfTarget int32) (
destAddr btcutil.Address, sweepConfTarget int32, label string) (
btcutil.Amount, chainfee.SatPerKWeight, lntypes.WeightUnit, error) {
// Get fee estimate from lnd.
@ -224,7 +225,14 @@ func (s *Sweeper) GetSweepFeeDetails(ctx context.Context,
// Find weight.
weight := weightEstimate.Weight()
return feeRate.FeeForWeight(weight), feeRate, weight, nil
// Find fee.
fee := feeRate.FeeForWeight(weight)
log.Debugf("Estimations for a tx (label=%s): weight=%v, fee=%v, "+
"feerate=%v, sweepConfTarget=%d.", label, weight, fee, feeRate,
sweepConfTarget)
return fee, feeRate, weight, nil
}
// AddOutputEstimate adds output to weight estimator.