multi: add wtclient config defaults to lnd config

In this commit, a `DefaultWtClientCfg` function is added which
populates some default values for the `WtClient` struct. This is then
used to populate the wtclient defaults in the main LND config struct.
This commit is contained in:
Elle Mouton 2023-06-15 08:19:49 +02:00
parent 453fbb3358
commit d9c4ada991
No known key found for this signature in database
GPG key ID: D7D916376026F177
3 changed files with 51 additions and 26 deletions

View file

@ -713,6 +713,7 @@ func DefaultConfig() Config {
ServerPingTimeout: defaultGrpcServerPingTimeout,
ClientPingMinWait: defaultGrpcClientPingMinWait,
},
WtClient: lncfg.DefaultWtClientCfg(),
}
}

View file

@ -1,6 +1,11 @@
package lncfg
import "fmt"
import (
"fmt"
"github.com/lightningnetwork/lnd/watchtower/wtclient"
"github.com/lightningnetwork/lnd/watchtower/wtpolicy"
)
// WtClient holds the configuration options for the daemon's watchtower client.
//
@ -32,6 +37,23 @@ type WtClient struct {
MaxUpdates uint16 `long:"max-updates" description:"The maximum number of updates to be backed up in a single session."`
}
// DefaultWtClientCfg returns the WtClient config struct with some default
// values populated.
func DefaultWtClientCfg() *WtClient {
// The sweep fee rate used internally by the tower client is in sats/kw
// but the config exposed to the user is in sats/byte, so we convert the
// default here before exposing it to the user.
sweepSatsPerKvB := wtpolicy.DefaultSweepFeeRate.FeePerKVByte()
sweepFeeRate := uint64(sweepSatsPerKvB / 1000)
return &WtClient{
SweepFeeRate: sweepFeeRate,
SessionCloseRange: wtclient.DefaultSessionCloseRange,
MaxTasksInMemQueue: wtclient.DefaultMaxTasksInMemQueue,
MaxUpdates: wtpolicy.DefaultMaxUpdates,
}
}
// Validate ensures the user has provided a valid configuration.
//
// NOTE: Part of the Validator interface.
@ -45,6 +67,22 @@ func (c *WtClient) Validate() error {
"`lncli wtclient -h` for more information")
}
if c.SweepFeeRate == 0 {
return fmt.Errorf("sweep-fee-rate must be non-zero")
}
if c.MaxUpdates == 0 {
return fmt.Errorf("max-updates must be non-zero")
}
if c.MaxTasksInMemQueue == 0 {
return fmt.Errorf("max-tasks-in-mem-queue must be non-zero")
}
if c.SessionCloseRange == 0 {
return fmt.Errorf("session-close-range must be non-zero")
}
return nil
}

View file

@ -1497,29 +1497,15 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
if cfg.WtClient.Active {
policy := wtpolicy.DefaultPolicy()
policy.MaxUpdates = cfg.WtClient.MaxUpdates
if cfg.WtClient.SweepFeeRate != 0 {
// We expose the sweep fee rate in sat/vbyte, but the
// tower protocol operations on sat/kw.
sweepRateSatPerVByte := chainfee.SatPerKVByte(
1000 * cfg.WtClient.SweepFeeRate,
)
policy.SweepFeeRate = sweepRateSatPerVByte.FeePerKWeight()
}
// We expose the sweep fee rate in sat/vbyte, but the tower
// protocol operations on sat/kw.
sweepRateSatPerVByte := chainfee.SatPerKVByte(
1000 * cfg.WtClient.SweepFeeRate,
)
if cfg.WtClient.MaxUpdates != 0 {
policy.MaxUpdates = cfg.WtClient.MaxUpdates
}
sessionCloseRange := uint32(wtclient.DefaultSessionCloseRange)
if cfg.WtClient.SessionCloseRange != 0 {
sessionCloseRange = cfg.WtClient.SessionCloseRange
}
maxTasksInMemQueue := uint64(wtclient.DefaultMaxTasksInMemQueue)
if cfg.WtClient.MaxTasksInMemQueue != 0 {
maxTasksInMemQueue = cfg.WtClient.MaxTasksInMemQueue
}
policy.SweepFeeRate = sweepRateSatPerVByte.FeePerKWeight()
if err := policy.Validate(); err != nil {
return nil, err
@ -1565,7 +1551,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
s.towerClient, err = wtclient.New(&wtclient.Config{
FetchClosedChannel: fetchClosedChannel,
BuildBreachRetribution: buildBreachRetribution,
SessionCloseRange: sessionCloseRange,
SessionCloseRange: cfg.WtClient.SessionCloseRange,
ChainNotifier: s.cc.ChainNotifier,
SubscribeChannelEvents: func() (subscribe.Subscription,
error) {
@ -1584,7 +1570,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
MinBackoff: 10 * time.Second,
MaxBackoff: 5 * time.Minute,
ForceQuitDelay: wtclient.DefaultForceQuitDelay,
MaxTasksInMemQueue: maxTasksInMemQueue,
MaxTasksInMemQueue: cfg.WtClient.MaxTasksInMemQueue,
})
if err != nil {
return nil, err
@ -1599,7 +1585,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
s.anchorTowerClient, err = wtclient.New(&wtclient.Config{
FetchClosedChannel: fetchClosedChannel,
BuildBreachRetribution: buildBreachRetribution,
SessionCloseRange: sessionCloseRange,
SessionCloseRange: cfg.WtClient.SessionCloseRange,
ChainNotifier: s.cc.ChainNotifier,
SubscribeChannelEvents: func() (subscribe.Subscription,
error) {
@ -1618,7 +1604,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
MinBackoff: 10 * time.Second,
MaxBackoff: 5 * time.Minute,
ForceQuitDelay: wtclient.DefaultForceQuitDelay,
MaxTasksInMemQueue: maxTasksInMemQueue,
MaxTasksInMemQueue: cfg.WtClient.MaxTasksInMemQueue,
})
if err != nil {
return nil, err