Skip to content

Commit c884c64

Browse files
committed
multi: allow user defined psbt max fee ratio
This commit allows the user to set their own value for the maximum allowed fees to total output amount ratio that is used by the wallet when funding PSBTs.
1 parent 8785003 commit c884c64

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

lndservices/wallet_anchor.go

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,59 @@ import (
2121
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
2222
)
2323

24+
// defaultPsbtMaxFeeRatio is the maximum ratio between fees paid and total
25+
// output amount produced. Since taproot assets can be anchored to outpoints
26+
// that may carry relatively small bitcoin amounts, we want to bump the allowed
27+
// ratio between fees paid and total produced output amount. This can prove
28+
// useful in high fee environments where we'd otherwise fail to fund the psbt.
29+
const defaultPsbtMaxFeeRatio = 0.75
30+
2431
// LndRpcWalletAnchor is an implementation of the tapgarden.WalletAnchor
2532
// interfaced backed by an active remote lnd node.
2633
type LndRpcWalletAnchor struct {
2734
lnd *lndclient.LndServices
35+
cfg *WalletAnchorConfig
36+
}
37+
38+
// WalletAnchorConfig is a configuration for the wallet anchor.
39+
type WalletAnchorConfig struct {
40+
psbtMaxFeeRatio float64
41+
}
42+
43+
// defaultWalletAnchorConfig returns the default configuration for the wallet
44+
// anchor.
45+
func defaultWalletAnchorConfig() *WalletAnchorConfig {
46+
return &WalletAnchorConfig{
47+
psbtMaxFeeRatio: defaultPsbtMaxFeeRatio,
48+
}
49+
}
50+
51+
// WalletAnchorOption is an optional argument that modifies the wallet anchor
52+
// configuration.
53+
type WalletAnchorOption func(cfg *WalletAnchorConfig)
54+
55+
// WithPsbtMaxFeeRatio is an optional argument that provides a custom psbt
56+
// max fee ratio.
57+
func WithPsbtMaxFeeRatio(val float64) WalletAnchorOption {
58+
return func(cfg *WalletAnchorConfig) {
59+
cfg.psbtMaxFeeRatio = val
60+
}
2861
}
2962

3063
// NewLndRpcWalletAnchor returns a new wallet anchor instance using the passed
3164
// lnd node.
32-
func NewLndRpcWalletAnchor(lnd *lndclient.LndServices) *LndRpcWalletAnchor {
65+
func NewLndRpcWalletAnchor(lnd *lndclient.LndServices,
66+
opts ...WalletAnchorOption) *LndRpcWalletAnchor {
67+
68+
cfg := defaultWalletAnchorConfig()
69+
70+
for _, opt := range opts {
71+
opt(cfg)
72+
}
73+
3374
return &LndRpcWalletAnchor{
3475
lnd: lnd,
76+
cfg: cfg,
3577
}
3678
}
3779

@@ -82,8 +124,9 @@ func (l *LndRpcWalletAnchor) FundPsbt(ctx context.Context, packet *psbt.Packet,
82124
Fees: &walletrpc.FundPsbtRequest_SatPerKw{
83125
SatPerKw: uint64(feeRate),
84126
},
85-
MinConfs: int32(minConfs),
86-
ChangeType: defaultChangeType,
127+
MinConfs: int32(minConfs),
128+
ChangeType: defaultChangeType,
129+
MaxFeeRatio: l.cfg.psbtMaxFeeRatio,
87130
},
88131
)
89132
if err != nil {

tapcfg/config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ const (
143143
// defaultMailboxAuthTimeout is the default timeout we'll use for
144144
// mailbox message retrieval client authentication.
145145
defaultMailboxAuthTimeout = 10 * time.Second
146+
147+
// defaultPsbtMaxFeeRatio is the default maximum for fees to total
148+
// output amount ratio to use when funding PSBTs.
149+
defaultPsbtMaxFeeRatio = 0.75
146150
)
147151

148152
var (
@@ -276,6 +280,17 @@ type LndConfig struct {
276280
RPCTimeout time.Duration `long:"rpctimeout" description:"The timeout to use for RPC requests to lnd; a sufficiently long duration should be chosen to avoid issues with slow responses. Valid time units are {s, m, h}."`
277281
}
278282

283+
// WalletConfig is the config that contains wallet related configurations.
284+
type WalletConfig struct {
285+
// PsbtMaxFeeRatio is the maximum fees to total output amount ratio to
286+
// use when funding PSBTs for asset transfers. Since taproot assets can
287+
// be anchored to outpoints that may carry relatively small bitcoin
288+
// amounts it is useful to pick a high value for this argument as in
289+
// high fee environments the total fees paid may outweight the anchor
290+
// amount. The allowed values for this argument range from 0.00 to 1.00.
291+
PsbtMaxFeeRatio float64 `long:"psbt-max-fee-ratio" description:"The maximum fees to total output amount ratio to use when funding PSBTs for asset transfers. Value must be between 0.00 and 1.00"`
292+
}
293+
279294
// UniverseConfig is the config that houses any Universe related config
280295
// values.
281296
type UniverseConfig struct {
@@ -355,6 +370,8 @@ type Config struct {
355370

356371
Universe *UniverseConfig `group:"universe" namespace:"universe"`
357372

373+
Wallet *WalletConfig `group:"wallet" namespace:"wallet"`
374+
358375
AddrBook *AddrBookConfig `group:"address" namespace:"address"`
359376

360377
Prometheus monitoring.PrometheusConfig `group:"prometheus" namespace:"prometheus"`
@@ -461,6 +478,9 @@ func DefaultConfig() Config {
461478
),
462479
MboxAuthTimeout: defaultMailboxAuthTimeout,
463480
},
481+
Wallet: &WalletConfig{
482+
PsbtMaxFeeRatio: defaultPsbtMaxFeeRatio,
483+
},
464484
AddrBook: &AddrBookConfig{
465485
DisableSyncer: false,
466486
},

tapcfg/server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
106106
assetStore := tapdb.NewAssetStore(assetDB, metaDB, defaultClock, dbType)
107107

108108
keyRing := lndservices.NewLndRpcKeyRing(lndServices)
109-
walletAnchor := lndservices.NewLndRpcWalletAnchor(lndServices)
109+
walletAnchor := lndservices.NewLndRpcWalletAnchor(
110+
lndServices,
111+
lndservices.WithPsbtMaxFeeRatio(cfg.Wallet.PsbtMaxFeeRatio),
112+
)
110113
chainBridge := lndservices.NewLndRpcChainBridge(lndServices, assetStore)
111114
msgTransportClient := lndservices.NewLndMsgTransportClient(lndServices)
112115
lndRouterClient := lndservices.NewLndRouterClient(lndServices)

0 commit comments

Comments
 (0)