mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
multi: log warnings if deprecated config options are used
This commit adds warning logs if the user uses deprecated config options, paving the way for future removal.
This commit is contained in:
parent
7d74165296
commit
157c84cc4d
41
config.go
41
config.go
@ -813,6 +813,9 @@ func LoadConfig(interceptor signal.Interceptor) (*Config, error) {
|
||||
ltndLog.Warnf("%v", configFileError)
|
||||
}
|
||||
|
||||
// Finally, log warnings for deprecated config options if they are set.
|
||||
logWarningsForDeprecation(*cleanCfg)
|
||||
|
||||
return cleanCfg, nil
|
||||
}
|
||||
|
||||
@ -2112,12 +2115,20 @@ func checkEstimateMode(estimateMode string) error {
|
||||
bitcoindEstimateModes[:])
|
||||
}
|
||||
|
||||
// configToFlatMap converts the given config struct into a flat map of key/value
|
||||
// pairs using the dot notation we are used to from the config file or command
|
||||
// line flags.
|
||||
func configToFlatMap(cfg Config) (map[string]string, error) {
|
||||
// configToFlatMap converts the given config struct into a flat map of
|
||||
// key/value pairs using the dot notation we are used to from the config file
|
||||
// or command line flags. It also returns a map containing deprecated config
|
||||
// options.
|
||||
func configToFlatMap(cfg Config) (map[string]string,
|
||||
map[string]struct{}, error) {
|
||||
|
||||
result := make(map[string]string)
|
||||
|
||||
// deprecated stores a map of deprecated options found in the config
|
||||
// that are set by the users. A config option is considered as
|
||||
// deprecated if it has a `hidden` flag.
|
||||
deprecated := make(map[string]struct{})
|
||||
|
||||
// redact is the helper function that redacts sensitive values like
|
||||
// passwords.
|
||||
redact := func(key, value string) string {
|
||||
@ -2159,6 +2170,8 @@ func configToFlatMap(cfg Config) (map[string]string, error) {
|
||||
longName := fieldType.Tag.Get("long")
|
||||
namespace := fieldType.Tag.Get("namespace")
|
||||
group := fieldType.Tag.Get("group")
|
||||
hidden := fieldType.Tag.Get("hidden")
|
||||
|
||||
switch {
|
||||
// We have a long name defined, this is a config value.
|
||||
case longName != "":
|
||||
@ -2172,6 +2185,11 @@ func configToFlatMap(cfg Config) (map[string]string, error) {
|
||||
"%v", field.Interface(),
|
||||
))
|
||||
|
||||
// If there's a hidden flag, it's deprecated.
|
||||
if hidden == "true" && !field.IsZero() {
|
||||
deprecated[key] = struct{}{}
|
||||
}
|
||||
|
||||
// We have no long name but a namespace, this is a
|
||||
// nested struct.
|
||||
case longName == "" && namespace != "":
|
||||
@ -2202,5 +2220,18 @@ func configToFlatMap(cfg Config) (map[string]string, error) {
|
||||
// Turn the whole config struct into a flat map.
|
||||
printConfig(reflect.ValueOf(cfg), "")
|
||||
|
||||
return result, nil
|
||||
return result, deprecated, nil
|
||||
}
|
||||
|
||||
// logWarningsForDeprecation logs a warning if a deprecated config option is
|
||||
// set.
|
||||
func logWarningsForDeprecation(cfg Config) {
|
||||
_, deprecated, err := configToFlatMap(cfg)
|
||||
if err != nil {
|
||||
ltndLog.Errorf("Convert configs to map: %v", err)
|
||||
}
|
||||
|
||||
for k := range deprecated {
|
||||
ltndLog.Warnf("Config '%s' is deprecated, please remove it", k)
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,15 @@ func TestConfigToFlatMap(t *testing.T) {
|
||||
cfg.DB.Etcd.Pass = testPassword
|
||||
cfg.DB.Postgres.Dsn = testPassword
|
||||
|
||||
result, err := configToFlatMap(cfg)
|
||||
// Set a deprecated field.
|
||||
cfg.Bitcoin.Active = true
|
||||
|
||||
result, deprecated, err := configToFlatMap(cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check that the deprecated option has been parsed out.
|
||||
require.Contains(t, deprecated, "bitcoin.active")
|
||||
|
||||
// Pick a couple of random values to check.
|
||||
require.Equal(t, DefaultLndDir, result["lnddir"])
|
||||
require.Equal(
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
//
|
||||
//nolint:lll
|
||||
type Chain struct {
|
||||
Active bool `long:"active" description:"DEPRECATED: If the chain should be active or not. This field is now ignored since only the Bitcoin chain is supported"`
|
||||
Active bool `long:"active" description:"DEPRECATED: If the chain should be active or not. This field is now ignored since only the Bitcoin chain is supported" hidden:"true"`
|
||||
ChainDir string `long:"chaindir" description:"The directory to store the chain's data within."`
|
||||
|
||||
Node string `long:"node" description:"The blockchain interface to use." choice:"btcd" choice:"bitcoind" choice:"neutrino" choice:"nochainbackend"`
|
||||
|
@ -3054,7 +3054,7 @@ func (r *rpcServer) GetInfo(_ context.Context,
|
||||
func (r *rpcServer) GetDebugInfo(_ context.Context,
|
||||
_ *lnrpc.GetDebugInfoRequest) (*lnrpc.GetDebugInfoResponse, error) {
|
||||
|
||||
flatConfig, err := configToFlatMap(*r.cfg)
|
||||
flatConfig, _, err := configToFlatMap(*r.cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting config to flat map: "+
|
||||
"%w", err)
|
||||
|
Loading…
Reference in New Issue
Block a user