Skip to content

tapd: bump maxFeeRatio for funded psbts #1545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/release-notes/release-notes-0.7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@
balances of asset channels grouped by group key (if grouped assets were used
in a channel)](https://github.com/lightninglabs/taproot-assets/pull/1691).

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing final punctuation. And missing a space between "preferred." and "It".


## RPC Updates

## tapcli Updates
Expand Down
49 changes: 46 additions & 3 deletions lndservices/wallet_anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,59 @@ import (
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
)

// defaultPsbtMaxFeeRatio is the maximum ratio between fees paid and total
// output amount produced. Since taproot assets can be anchored to outpoints
// that may carry relatively small bitcoin amounts, we want to bump the allowed
// ratio between fees paid and total produced output amount. This can prove
// useful in high fee environments where we'd otherwise fail to fund the psbt.
const defaultPsbtMaxFeeRatio = 0.75

// LndRpcWalletAnchor is an implementation of the tapgarden.WalletAnchor
// interfaced backed by an active remote lnd node.
type LndRpcWalletAnchor struct {
lnd *lndclient.LndServices
cfg *WalletAnchorConfig
}

// WalletAnchorConfig is a configuration for the wallet anchor.
type WalletAnchorConfig struct {
psbtMaxFeeRatio float64
}

// defaultWalletAnchorConfig returns the default configuration for the wallet
// anchor.
func defaultWalletAnchorConfig() *WalletAnchorConfig {
return &WalletAnchorConfig{
psbtMaxFeeRatio: defaultPsbtMaxFeeRatio,
}
}

// WalletAnchorOption is an optional argument that modifies the wallet anchor
// configuration.
type WalletAnchorOption func(cfg *WalletAnchorConfig)

// WithPsbtMaxFeeRatio is an optional argument that provides a custom psbt
// max fee ratio.
func WithPsbtMaxFeeRatio(val float64) WalletAnchorOption {
return func(cfg *WalletAnchorConfig) {
cfg.psbtMaxFeeRatio = val
}
}

// NewLndRpcWalletAnchor returns a new wallet anchor instance using the passed
// lnd node.
func NewLndRpcWalletAnchor(lnd *lndclient.LndServices) *LndRpcWalletAnchor {
func NewLndRpcWalletAnchor(lnd *lndclient.LndServices,
opts ...WalletAnchorOption) *LndRpcWalletAnchor {

cfg := defaultWalletAnchorConfig()

for _, opt := range opts {
opt(cfg)
}

return &LndRpcWalletAnchor{
lnd: lnd,
cfg: cfg,
}
}

Expand Down Expand Up @@ -82,8 +124,9 @@ func (l *LndRpcWalletAnchor) FundPsbt(ctx context.Context, packet *psbt.Packet,
Fees: &walletrpc.FundPsbtRequest_SatPerKw{
SatPerKw: uint64(feeRate),
},
MinConfs: int32(minConfs),
ChangeType: defaultChangeType,
MinConfs: int32(minConfs),
ChangeType: defaultChangeType,
MaxFeeRatio: l.cfg.psbtMaxFeeRatio,
},
)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions sample-tapd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@
; the syncer cache. (default: 10240)
; universe.multiverse-caches.root-node-page-cache-size=10240

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

[address]

Expand Down
20 changes: 20 additions & 0 deletions tapcfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ const (
// defaultMailboxAuthTimeout is the default timeout we'll use for
// mailbox message retrieval client authentication.
defaultMailboxAuthTimeout = 10 * time.Second

// defaultPsbtMaxFeeRatio is the default maximum for fees to total
// output amount ratio to use when funding PSBTs.
defaultPsbtMaxFeeRatio = 0.75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we export the lndservices.defaultPsbtMaxFeeRation and use that here? Or the other way around, depending on what works without creating a circular package dependency.

)

var (
Expand Down Expand Up @@ -276,6 +280,17 @@ type LndConfig struct {
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}."`
}

// WalletConfig is the config that contains wallet related configurations.
type WalletConfig struct {
// PsbtMaxFeeRatio is the maximum fees to total output amount ratio to
// use when funding PSBTs for asset transfers. Since taproot assets can
// be anchored to outpoints that may carry relatively small bitcoin
// amounts it is useful to pick a high value for this argument as in
// high fee environments the total fees paid may outweight the anchor
// amount. The allowed values for this argument range from 0.00 to 1.00.
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"`
}

// UniverseConfig is the config that houses any Universe related config
// values.
type UniverseConfig struct {
Expand Down Expand Up @@ -355,6 +370,8 @@ type Config struct {

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

Wallet *WalletConfig `group:"wallet" namespace:"wallet"`

AddrBook *AddrBookConfig `group:"address" namespace:"address"`

Prometheus monitoring.PrometheusConfig `group:"prometheus" namespace:"prometheus"`
Expand Down Expand Up @@ -461,6 +478,9 @@ func DefaultConfig() Config {
),
MboxAuthTimeout: defaultMailboxAuthTimeout,
},
Wallet: &WalletConfig{
PsbtMaxFeeRatio: defaultPsbtMaxFeeRatio,
},
AddrBook: &AddrBookConfig{
DisableSyncer: false,
},
Expand Down
5 changes: 4 additions & 1 deletion tapcfg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
assetStore := tapdb.NewAssetStore(assetDB, metaDB, defaultClock, dbType)

keyRing := lndservices.NewLndRpcKeyRing(lndServices)
walletAnchor := lndservices.NewLndRpcWalletAnchor(lndServices)
walletAnchor := lndservices.NewLndRpcWalletAnchor(
lndServices,
lndservices.WithPsbtMaxFeeRatio(cfg.Wallet.PsbtMaxFeeRatio),
)
chainBridge := lndservices.NewLndRpcChainBridge(lndServices, assetStore)
msgTransportClient := lndservices.NewLndMsgTransportClient(lndServices)
lndRouterClient := lndservices.NewLndRouterClient(lndServices)
Expand Down
Loading