Browse Source

multi: base sweep fee estimate on actually used address type

pull/71/head
Joost Jager 1 year ago
parent
commit
ecd36b921c
No known key found for this signature in database GPG Key ID: A61B9D4C393C59C7
4 changed files with 29 additions and 5 deletions
  1. +12
    -1
      client.go
  2. +2
    -1
      loopin.go
  3. +1
    -1
      loopout.go
  4. +14
    -2
      sweep/sweeper.go

+ 12
- 1
client.go View File

@ -359,9 +359,20 @@ func (s *Client) LoopOutQuote(ctx context.Context,
request.Amount, terms.SwapFeeBase, terms.SwapFeeRate,
)
// Generate dummy p2wsh address for fee estimation. The p2wsh address
// type is chosen because it adds the most weight of all output types
// and we want the quote to return a worst case value.
wsh := [32]byte{}
p2wshAddress, err := btcutil.NewAddressWitnessScriptHash(
wsh[:], s.lndServices.ChainParams,
)
if err != nil {
return nil, err
}
minerFee, err := s.sweeper.GetSweepFee(
ctx, swap.QuoteHtlc.AddSuccessToEstimator,
request.SweepConfTarget,
p2wshAddress, request.SweepConfTarget,
)
if err != nil {
return nil, err

+ 2
- 1
loopin.go View File

@ -584,7 +584,8 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
// Calculate sweep tx fee
fee, err := s.sweeper.GetSweepFee(
ctx, s.htlc.AddTimeoutToEstimator, TimeoutTxConfTarget,
ctx, s.htlc.AddTimeoutToEstimator, s.timeoutAddr,
TimeoutTxConfTarget,
)
if err != nil {
return err

+ 1
- 1
loopout.go View File

@ -602,7 +602,7 @@ func (s *loopOutSwap) sweep(ctx context.Context,
confTarget = DefaultSweepConfTarget
}
fee, err := s.sweeper.GetSweepFee(
ctx, s.htlc.AddSuccessToEstimator, confTarget,
ctx, s.htlc.AddSuccessToEstimator, s.DestAddr, confTarget,
)
if err != nil {
return err

+ 14
- 2
sweep/sweeper.go View File

@ -91,7 +91,7 @@ func (s *Sweeper) CreateSweepTx(
// estimator.
func (s *Sweeper) GetSweepFee(ctx context.Context,
addInputEstimate func(*input.TxWeightEstimator),
sweepConfTarget int32) (
destAddr btcutil.Address, sweepConfTarget int32) (
btcutil.Amount, error) {
// Get fee estimate from lnd.
@ -102,7 +102,19 @@ func (s *Sweeper) GetSweepFee(ctx context.Context,
// Calculate weight for this tx.
var weightEstimate input.TxWeightEstimator
weightEstimate.AddP2WKHOutput()
switch destAddr.(type) {
case *btcutil.AddressWitnessScriptHash:
weightEstimate.AddP2WSHOutput()
case *btcutil.AddressWitnessPubKeyHash:
weightEstimate.AddP2WKHOutput()
case *btcutil.AddressScriptHash:
weightEstimate.AddP2SHOutput()
case *btcutil.AddressPubKeyHash:
weightEstimate.AddP2PKHOutput()
default:
return 0, fmt.Errorf("unknown adress type %T", destAddr)
}
addInputEstimate(&weightEstimate)
weight := weightEstimate.Weight()

Loading…
Cancel
Save