Skip to content

Commit

Permalink
Merge pull request #7771 from ellemouton/towerConfigDefaults
Browse files Browse the repository at this point in the history
multi: add tower config defaults
  • Loading branch information
guggero authored Jun 16, 2023
2 parents 453fbb3 + 7484910 commit 2e1b659
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 45 deletions.
5 changes: 2 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -713,6 +711,7 @@ func DefaultConfig() Config {
ServerPingTimeout: defaultGrpcServerPingTimeout,
ClientPingMinWait: defaultGrpcClientPingMinWait,
},
WtClient: lncfg.DefaultWtClientCfg(),
}
}

Expand Down
10 changes: 10 additions & 0 deletions docs/release-notes/release-notes-0.17.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lncfg/watchtower.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
49 changes: 37 additions & 12 deletions lncfg/wtclient.go
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -10,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 <pubkey>@<addr>. 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."`
Expand All @@ -32,17 +33,41 @@ 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.
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")
}

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
Expand Down
5 changes: 0 additions & 5 deletions sample-lnd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pubkey>@<addr>. 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
Expand Down
36 changes: 11 additions & 25 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions watchtower/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2e1b659

Please sign in to comment.