mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
Merge pull request #71 from joostjager/address-estimate
multi: base sweep fee estimate on actually used address type
This commit is contained in:
commit
6608337bb4
4 changed files with 30 additions and 6 deletions
13
client.go
13
client.go
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue