mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-21 06:12:38 +02:00
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:
parent
453fbb3358
commit
d9c4ada991
@ -713,6 +713,7 @@ func DefaultConfig() Config {
|
|||||||
ServerPingTimeout: defaultGrpcServerPingTimeout,
|
ServerPingTimeout: defaultGrpcServerPingTimeout,
|
||||||
ClientPingMinWait: defaultGrpcClientPingMinWait,
|
ClientPingMinWait: defaultGrpcClientPingMinWait,
|
||||||
},
|
},
|
||||||
|
WtClient: lncfg.DefaultWtClientCfg(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package lncfg
|
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.
|
// 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."`
|
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.
|
// Validate ensures the user has provided a valid configuration.
|
||||||
//
|
//
|
||||||
// NOTE: Part of the Validator interface.
|
// NOTE: Part of the Validator interface.
|
||||||
@ -45,6 +67,22 @@ func (c *WtClient) Validate() error {
|
|||||||
"`lncli wtclient -h` for more information")
|
"`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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
server.go
36
server.go
@ -1497,29 +1497,15 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
|
|
||||||
if cfg.WtClient.Active {
|
if cfg.WtClient.Active {
|
||||||
policy := wtpolicy.DefaultPolicy()
|
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
|
||||||
// We expose the sweep fee rate in sat/vbyte, but the
|
// protocol operations on sat/kw.
|
||||||
// tower protocol operations on sat/kw.
|
sweepRateSatPerVByte := chainfee.SatPerKVByte(
|
||||||
sweepRateSatPerVByte := chainfee.SatPerKVByte(
|
1000 * cfg.WtClient.SweepFeeRate,
|
||||||
1000 * cfg.WtClient.SweepFeeRate,
|
)
|
||||||
)
|
|
||||||
policy.SweepFeeRate = sweepRateSatPerVByte.FeePerKWeight()
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.WtClient.MaxUpdates != 0 {
|
policy.SweepFeeRate = sweepRateSatPerVByte.FeePerKWeight()
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := policy.Validate(); err != nil {
|
if err := policy.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1565,7 +1551,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
s.towerClient, err = wtclient.New(&wtclient.Config{
|
s.towerClient, err = wtclient.New(&wtclient.Config{
|
||||||
FetchClosedChannel: fetchClosedChannel,
|
FetchClosedChannel: fetchClosedChannel,
|
||||||
BuildBreachRetribution: buildBreachRetribution,
|
BuildBreachRetribution: buildBreachRetribution,
|
||||||
SessionCloseRange: sessionCloseRange,
|
SessionCloseRange: cfg.WtClient.SessionCloseRange,
|
||||||
ChainNotifier: s.cc.ChainNotifier,
|
ChainNotifier: s.cc.ChainNotifier,
|
||||||
SubscribeChannelEvents: func() (subscribe.Subscription,
|
SubscribeChannelEvents: func() (subscribe.Subscription,
|
||||||
error) {
|
error) {
|
||||||
@ -1584,7 +1570,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
MinBackoff: 10 * time.Second,
|
MinBackoff: 10 * time.Second,
|
||||||
MaxBackoff: 5 * time.Minute,
|
MaxBackoff: 5 * time.Minute,
|
||||||
ForceQuitDelay: wtclient.DefaultForceQuitDelay,
|
ForceQuitDelay: wtclient.DefaultForceQuitDelay,
|
||||||
MaxTasksInMemQueue: maxTasksInMemQueue,
|
MaxTasksInMemQueue: cfg.WtClient.MaxTasksInMemQueue,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1599,7 +1585,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
s.anchorTowerClient, err = wtclient.New(&wtclient.Config{
|
s.anchorTowerClient, err = wtclient.New(&wtclient.Config{
|
||||||
FetchClosedChannel: fetchClosedChannel,
|
FetchClosedChannel: fetchClosedChannel,
|
||||||
BuildBreachRetribution: buildBreachRetribution,
|
BuildBreachRetribution: buildBreachRetribution,
|
||||||
SessionCloseRange: sessionCloseRange,
|
SessionCloseRange: cfg.WtClient.SessionCloseRange,
|
||||||
ChainNotifier: s.cc.ChainNotifier,
|
ChainNotifier: s.cc.ChainNotifier,
|
||||||
SubscribeChannelEvents: func() (subscribe.Subscription,
|
SubscribeChannelEvents: func() (subscribe.Subscription,
|
||||||
error) {
|
error) {
|
||||||
@ -1618,7 +1604,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
MinBackoff: 10 * time.Second,
|
MinBackoff: 10 * time.Second,
|
||||||
MaxBackoff: 5 * time.Minute,
|
MaxBackoff: 5 * time.Minute,
|
||||||
ForceQuitDelay: wtclient.DefaultForceQuitDelay,
|
ForceQuitDelay: wtclient.DefaultForceQuitDelay,
|
||||||
MaxTasksInMemQueue: maxTasksInMemQueue,
|
MaxTasksInMemQueue: cfg.WtClient.MaxTasksInMemQueue,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user