Browse Source

Merge pull request #71 from joostjager/address-estimate

multi: base sweep fee estimate on actually used address type
pull/72/head
Alex Bosworth 1 year ago
committed by GitHub
parent
commit
6608337bb4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 6 deletions
  1. +12
    -1
      client.go
  2. +2
    -1
      loopin.go
  3. +2
    -2
      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

+ 2
- 2
loopout.go View File

@ -31,7 +31,7 @@ var (
// confirmation target.
//
// TODO(wilmer): tune?
DefaultSweepConfTargetDelta int32 = DefaultSweepConfTarget * 2
DefaultSweepConfTargetDelta = DefaultSweepConfTarget * 2
)
// loopOutSwap contains all the in-memory state related to a pending loop out
@ -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