mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
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:
parent
f8c1607154
commit
697e8d6255
6 changed files with 53 additions and 8 deletions
|
|
@ -570,8 +570,11 @@ func (s *Client) getLoopOutSweepFee(ctx context.Context, confTarget int32) (
|
|||
htlc = swap.QuoteHtlcP2WSH
|
||||
}
|
||||
|
||||
label := "loopout-quote"
|
||||
|
||||
return s.sweeper.GetSweepFee(
|
||||
ctx, htlc.AddSuccessToEstimator, p2wshAddress, confTarget,
|
||||
label,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/lightninglabs/loop/liquidity"
|
||||
"github.com/lightninglabs/loop/loopdb"
|
||||
"github.com/lightninglabs/loop/notifications"
|
||||
"github.com/lightninglabs/loop/sweep"
|
||||
"github.com/lightninglabs/loop/sweepbatcher"
|
||||
"github.com/lightningnetwork/lnd"
|
||||
"github.com/lightningnetwork/lnd/build"
|
||||
|
|
@ -52,6 +53,9 @@ func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) {
|
|||
lnd.AddSubLogger(
|
||||
root, notifications.Subsystem, intercept, notifications.UseLogger,
|
||||
)
|
||||
lnd.AddSubLogger(
|
||||
root, sweep.Subsystem, intercept, sweep.UseLogger,
|
||||
)
|
||||
}
|
||||
|
||||
// genSubLogger creates a logger for a subsystem. We provide an instance of
|
||||
|
|
|
|||
|
|
@ -1077,10 +1077,12 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
|
|||
}
|
||||
}
|
||||
|
||||
label := fmt.Sprintf("loopin-timeout-%x", s.hash[:6])
|
||||
|
||||
// Calculate sweep tx fee.
|
||||
fee, err := s.sweeper.GetSweepFee(
|
||||
ctx, s.htlc.AddTimeoutToEstimator, s.timeoutAddr,
|
||||
TimeoutTxConfTarget,
|
||||
TimeoutTxConfTarget, label,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
|||
|
|
@ -312,11 +312,13 @@ func handleHtlcExpiry(t *testing.T, ctx *loopInTestContext, inSwap *loopInSwap,
|
|||
// Expect timeout tx to be published.
|
||||
timeoutTx := <-ctx.lnd.TxPublishChannel
|
||||
|
||||
label := fmt.Sprintf("loopin-timeout-%x", inSwap.hash[:6])
|
||||
|
||||
// We can just get our sweep fee as we would in the swap code because
|
||||
// our estimate is static.
|
||||
fee, err := inSwap.sweeper.GetSweepFee(
|
||||
context.Background(), inSwap.htlc.AddTimeoutToEstimator,
|
||||
inSwap.timeoutAddr, TimeoutTxConfTarget,
|
||||
inSwap.timeoutAddr, TimeoutTxConfTarget, label,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
cost.Onchain += fee
|
||||
|
|
|
|||
26
sweep/log.go
Normal file
26
sweep/log.go
Normal 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
|
||||
}
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue