Skip to content

Commit 088f3d2

Browse files
authored
Merge pull request #1545 from lightninglabs/bump-psbt-maxfeeratio
tapd: bump maxFeeRatio for funded psbts
2 parents a17a67a + cb76cd7 commit 088f3d2

File tree

5 files changed

+93
-4
lines changed

5 files changed

+93
-4
lines changed

docs/release-notes/release-notes-0.7.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@
189189
[PR](https://github.com/lightninglabs/taproot-assets/pull/1640) addresses the
190190
issue.
191191

192+
- A new configuration is now available which controls the max ratio of fees that
193+
each anchor transaction pays. This is important because given the nature of
194+
the small taproot-assets anchors we might want to allow for fees to be greater
195+
than the anchor amount itself, which is helpful in high fee environment where
196+
pulling in extra inputs might not be preferred. It is exposed via the flag
197+
`wallet.psbt-max-fee-ratio` and is introduced by
198+
[PR #1545](https://github.com/lightninglabs/taproot-assets/pull/1545).
199+
192200
## RPC Updates
193201

194202
## tapcli Updates

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 {

sample-tapd.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@
407407
; the syncer cache. (default: 10240)
408408
; universe.multiverse-caches.root-node-page-cache-size=10240
409409

410+
[wallet]
411+
; The maximum ratio of fees to total output amount for the wallet funded PSBTs.
412+
; Value must be a valid float ranging from 0.00 to 1.00.
413+
; wallet.psbt-max-fee-ratio=0.75
410414

411415
[address]
412416

tapcfg/config.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/lightninglabs/lndclient"
2323
tap "github.com/lightninglabs/taproot-assets"
2424
"github.com/lightninglabs/taproot-assets/fn"
25+
"github.com/lightninglabs/taproot-assets/lndservices"
2526
"github.com/lightninglabs/taproot-assets/monitoring"
2627
"github.com/lightninglabs/taproot-assets/proof"
2728
"github.com/lightninglabs/taproot-assets/rfq"
@@ -143,6 +144,10 @@ const (
143144
// defaultMailboxAuthTimeout is the default timeout we'll use for
144145
// mailbox message retrieval client authentication.
145146
defaultMailboxAuthTimeout = 10 * time.Second
147+
148+
// DefaultPsbtMaxFeeRatio is the default maximum for fees to total
149+
// output amount ratio to use when funding PSBTs.
150+
DefaultPsbtMaxFeeRatio = lndservices.DefaultPsbtMaxFeeRatio
146151
)
147152

148153
var (
@@ -280,6 +285,17 @@ type LndConfig struct {
280285
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}."`
281286
}
282287

288+
// WalletConfig is the config that contains wallet related configurations.
289+
type WalletConfig struct {
290+
// PsbtMaxFeeRatio is the maximum fees to total output amount ratio to
291+
// use when funding PSBTs for asset transfers. Since taproot assets can
292+
// be anchored to outpoints that may carry relatively small bitcoin
293+
// amounts it is useful to pick a high value for this argument as in
294+
// high fee environments the total fees paid may outweigh the anchor
295+
// amount. The allowed values for this argument range from 0.00 to 1.00.
296+
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"`
297+
}
298+
283299
// UniverseConfig is the config that houses any Universe related config
284300
// values.
285301
type UniverseConfig struct {
@@ -363,6 +379,8 @@ type Config struct {
363379

364380
Universe *UniverseConfig `group:"universe" namespace:"universe"`
365381

382+
Wallet *WalletConfig `group:"wallet" namespace:"wallet"`
383+
366384
AddrBook *AddrBookConfig `group:"address" namespace:"address"`
367385

368386
Channel *ChannelConfig `group:"channel" namespace:"channel"`
@@ -473,6 +491,9 @@ func DefaultConfig() Config {
473491
SupplyIgnoreCacheSize: tapdb.DefaultNegativeLookupCacheSize,
474492
DisableSupplyVerifierChainWatch: false,
475493
},
494+
Wallet: &WalletConfig{
495+
PsbtMaxFeeRatio: DefaultPsbtMaxFeeRatio,
496+
},
476497
AddrBook: &AddrBookConfig{
477498
DisableSyncer: false,
478499
},
@@ -932,6 +953,16 @@ func ValidateConfig(cfg Config, cfgLogger btclog.Logger) (*Config, error) {
932953
cfg.ReOrgSafeDepth = testnetDefaultReOrgSafeDepth
933954
}
934955

956+
// Let's validate that the wallet's psbt max fee ratio is within the
957+
// expected range.
958+
switch {
959+
case cfg.Wallet.PsbtMaxFeeRatio < 0.00:
960+
fallthrough
961+
case cfg.Wallet.PsbtMaxFeeRatio > 1.00:
962+
return nil, fmt.Errorf("psbt-max-fee-ratio must be set in " +
963+
"range of 0.00 to 1.00")
964+
}
965+
935966
// All good, return the sanitized result.
936967
return &cfg, nil
937968
}

tapcfg/server.go

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

110110
keyRing := lndservices.NewLndRpcKeyRing(lndServices)
111-
walletAnchor := lndservices.NewLndRpcWalletAnchor(lndServices)
111+
walletAnchor := lndservices.NewLndRpcWalletAnchor(
112+
lndServices,
113+
lndservices.WithPsbtMaxFeeRatio(cfg.Wallet.PsbtMaxFeeRatio),
114+
)
112115
chainBridge := lndservices.NewLndRpcChainBridge(lndServices, assetStore)
113116
msgTransportClient := lndservices.NewLndMsgTransportClient(lndServices)
114117
lndRouterClient := lndservices.NewLndRouterClient(lndServices)

0 commit comments

Comments
 (0)