From d9c4ada99102c7a42fa8637859217ec857b5afa6 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 15 Jun 2023 08:19:49 +0200 Subject: [PATCH 1/4] 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. --- config.go | 1 + lncfg/wtclient.go | 40 +++++++++++++++++++++++++++++++++++++++- server.go | 36 +++++++++++------------------------- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/config.go b/config.go index 5018994a71..d3d28a2b34 100644 --- a/config.go +++ b/config.go @@ -713,6 +713,7 @@ func DefaultConfig() Config { ServerPingTimeout: defaultGrpcServerPingTimeout, ClientPingMinWait: defaultGrpcClientPingMinWait, }, + WtClient: lncfg.DefaultWtClientCfg(), } } diff --git a/lncfg/wtclient.go b/lncfg/wtclient.go index 7a6959adfc..aab71faead 100644 --- a/lncfg/wtclient.go +++ b/lncfg/wtclient.go @@ -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 } diff --git a/server.go b/server.go index 35e375452c..4719691e98 100644 --- a/server.go +++ b/server.go @@ -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() - } - - if cfg.WtClient.MaxUpdates != 0 { - policy.MaxUpdates = cfg.WtClient.MaxUpdates - } - - sessionCloseRange := uint32(wtclient.DefaultSessionCloseRange) - if cfg.WtClient.SessionCloseRange != 0 { - sessionCloseRange = cfg.WtClient.SessionCloseRange - } + // We expose the sweep fee rate in sat/vbyte, but the tower + // protocol operations on sat/kw. + sweepRateSatPerVByte := chainfee.SatPerKVByte( + 1000 * cfg.WtClient.SweepFeeRate, + ) - 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 From f3525e8b7c2ca1db20b06be500439e53d051ba7b Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 15 Jun 2023 08:37:42 +0200 Subject: [PATCH 2/4] multi: add default watchtower config to main LND config In this commit, a `DefaultWatchtowerCfg` function is added which is used to construct a default `lncfg.Watchtower` struct. This is then used to populate the default watchtower config in the main LND config struct. --- config.go | 4 +--- lncfg/watchtower.go | 11 +++++++++++ watchtower/conf.go | 8 ++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index d3d28a2b34..50a6fffa42 100644 --- a/config.go +++ b/config.go @@ -638,9 +638,7 @@ func DefaultConfig() Config { ChannelCacheSize: channeldb.DefaultChannelCacheSize, }, Prometheus: lncfg.DefaultPrometheus(), - Watchtower: &lncfg.Watchtower{ - TowerDir: defaultTowerDir, - }, + Watchtower: lncfg.DefaultWatchtowerCfg(defaultTowerDir), HealthChecks: &lncfg.HealthCheckConfig{ ChainCheck: &lncfg.CheckConfig{ Interval: defaultChainInterval, diff --git a/lncfg/watchtower.go b/lncfg/watchtower.go index 4ef2919a2d..851d24e928 100644 --- a/lncfg/watchtower.go +++ b/lncfg/watchtower.go @@ -13,3 +13,14 @@ type Watchtower struct { watchtower.Conf } + +// DefaultWatchtowerCfg creates a Watchtower with some default values filled +// out. +func DefaultWatchtowerCfg(defaultTowerDir string) *Watchtower { + conf := watchtower.DefaultConf() + + return &Watchtower{ + TowerDir: defaultTowerDir, + Conf: *conf, + } +} diff --git a/watchtower/conf.go b/watchtower/conf.go index 653ed1e852..9b81a14470 100644 --- a/watchtower/conf.go +++ b/watchtower/conf.go @@ -23,6 +23,14 @@ type Conf struct { WriteTimeout time.Duration `long:"writetimeout" description:"Duration the watchtower server will wait for messages to be written before hanging up on client connections"` } +// DefaultConf returns a Conf with some default values filled in. +func DefaultConf() *Conf { + return &Conf{ + ReadTimeout: DefaultReadTimeout, + WriteTimeout: DefaultWriteTimeout, + } +} + // Apply completes the passed Config struct by applying any parsed Conf options. // If the corresponding values parsed by Conf are already set in the Config, // those fields will be not be modified. From 255d8bb355e54d9baff2643e1878aedbf27f73ee Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 15 Jun 2023 08:39:44 +0200 Subject: [PATCH 3/4] lncfg: remove deprecated PrivateTowerURIs from Wtclient cfg This commit removes the `PrivateTowerURIs` member from the `WtClient` config struct. This field has been deprecated since v0.8.0-beta and currently, LND would fail to start if the field was specified. --- lncfg/wtclient.go | 13 ------------- sample-lnd.conf | 5 ----- 2 files changed, 18 deletions(-) diff --git a/lncfg/wtclient.go b/lncfg/wtclient.go index aab71faead..461a2c9d0e 100644 --- a/lncfg/wtclient.go +++ b/lncfg/wtclient.go @@ -15,10 +15,6 @@ type WtClient struct { // back up channel states with registered watchtowers. Active bool `long:"active" description:"Whether the daemon should use private watchtowers to back up revoked channel states."` - // PrivateTowerURIs specifies the lightning URIs of the towers the - // watchtower client should send new backups to. - PrivateTowerURIs []string `long:"private-tower-uris" description:"(Deprecated) Specifies the URIs of private watchtowers to use in backing up revoked states. URIs must be of the form @. Only 1 URI is supported at this time, if none are provided the tower will not be enabled."` - // SweepFeeRate specifies the fee rate in sat/byte to be used when // constructing justice transactions sent to the tower. SweepFeeRate uint64 `long:"sweep-fee-rate" description:"Specifies the fee rate in sat/byte to be used when constructing justice transactions sent to the watchtower."` @@ -58,15 +54,6 @@ func DefaultWtClientCfg() *WtClient { // // NOTE: Part of the Validator interface. func (c *WtClient) Validate() error { - // TODO(wilmer): remove in v0.9.0 release. - if len(c.PrivateTowerURIs) > 0 { - return fmt.Errorf("the `wtclient.private-tower-uris` option " + - "has been deprecated as of v0.8.0-beta and will be " + - "removed in v0.9.0-beta. To setup watchtowers for " + - "the client, set `wtclient.active` and run " + - "`lncli wtclient -h` for more information") - } - if c.SweepFeeRate == 0 { return fmt.Errorf("sweep-fee-rate must be non-zero") } diff --git a/sample-lnd.conf b/sample-lnd.conf index 8bb8879091..1711a6e0b2 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -992,11 +992,6 @@ litecoin.node=ltcd ; specified in sat/byte, the default is 10 sat/byte. ; wtclient.sweep-fee-rate=10 -; (Deprecated) Specifies the URIs of private watchtowers to use in backing up -; revoked states. URIs must be of the form @. Only 1 URI is -; supported at this time, if none are provided the tower will not be enabled. -; wtclient.private-tower-uris= - ; The range over which to choose a random number of blocks to wait after the ; last channel of a session is closed before sending the DeleteSession message ; to the tower server. The default is currently 288. Note that setting this to From 748491096897a48a989c82c3e9bf48e00c2751d0 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 15 Jun 2023 08:48:57 +0200 Subject: [PATCH 4/4] docs: add release note for 7771 --- docs/release-notes/release-notes-0.17.0.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/release-notes/release-notes-0.17.0.md b/docs/release-notes/release-notes-0.17.0.md index 981e331ad2..c417ef6662 100644 --- a/docs/release-notes/release-notes-0.17.0.md +++ b/docs/release-notes/release-notes-0.17.0.md @@ -12,9 +12,19 @@ wtdb.BackupIDs](https://github.com/lightningnetwork/lnd/pull/7623) instead of the entire retribution struct. This reduces the amount of data that needs to be held in memory. + * [Replace in-mem task pipeline with a disk-overflow queue](https://github.com/lightningnetwork/lnd/pull/7380) +* [Add defaults](https://github.com/lightningnetwork/lnd/pull/7771) to the + wtclient and watchtower config structs and use these to populate the defaults + of the main LND config struct so that the defaults appear in the `lnd --help` + command output. + +* The deprecated "wtclient.private-tower-uris" option has also been + [removed](https://github.com/lightningnetwork/lnd/pull/7771). This field was + deprecated in v0.8.0-beta. + ## Misc * [Ensure that both the byte and string form of a TXID is populated in the