multi: base sweep fee estimate on actually used address type

pull/71/head
Joost Jager 5 years ago
parent b3b20fc66f
commit ecd36b921c
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -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

@ -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

@ -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

@ -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