From 1bc25c1136c7c5a076f9078e5f0b29ab705af05f Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Mon, 18 Nov 2024 11:17:02 -0300 Subject: [PATCH 1/3] config: fix "lnd --debuglevel show" command Previously, "lnd --debuglevel show" complained that bitcoin backend is not configured: $ lnd --debuglevel show failed to load config: ValidateConfig: either --bitcoin.mainnet, or ... To make it working, the user had to specify --bitcoin.mainnet and configure one of the backends, e.g. "--bitcoin.node neutrino". With this fix, the command works without any additional flags. --- config.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index dc9a1453c..fa2575d28 100644 --- a/config.go +++ b/config.go @@ -860,6 +860,18 @@ func LoadConfig(interceptor signal.Interceptor) (*Config, error) { func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, flagParser *flags.Parser) (*Config, error) { + // Special show command to list supported subsystems and exit. + if cfg.DebugLevel == "show" { + subLogMgr := build.NewSubLoggerManager() + + // Initialize logging at the default logging level. + SetupLoggers(subLogMgr, interceptor) + + fmt.Println("Supported subsystems", + subLogMgr.SupportedSubsystems()) + os.Exit(0) + } + // If the provided lnd directory is not the default, we'll modify the // path to all of the files and directories that will live within it. lndDir := CleanAndExpandPath(cfg.LndDir) @@ -1408,13 +1420,6 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, // Initialize logging at the default logging level. SetupLoggers(cfg.SubLogMgr, interceptor) - // Special show command to list supported subsystems and exit. - if cfg.DebugLevel == "show" { - fmt.Println("Supported subsystems", - cfg.SubLogMgr.SupportedSubsystems()) - os.Exit(0) - } - if cfg.MaxLogFiles != 0 { if cfg.LogConfig.File.MaxLogFiles != build.DefaultMaxLogFiles { From 3360d285fbec15e558f0af65ab3c8439558be40a Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Mon, 18 Nov 2024 11:24:16 -0300 Subject: [PATCH 2/3] config: improve error message Previously, the error message had one missing space: "... either --bitcoin.mainnet, or bitcoin.testnet,bitcoin.simnet, ..." I added a space after "bitcoin.testnet,". --- config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.go b/config.go index fa2575d28..04a491765 100644 --- a/config.go +++ b/config.go @@ -1261,7 +1261,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser, // The target network must be provided, otherwise, we won't // know how to initialize the daemon. if numNets == 0 { - str := "either --bitcoin.mainnet, or bitcoin.testnet," + + str := "either --bitcoin.mainnet, or bitcoin.testnet, " + "bitcoin.simnet, bitcoin.regtest or bitcoin.signet " + "must be specified" From 64c660c19e806a019e19079f4367ecec87cb85b8 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Mon, 18 Nov 2024 12:15:00 -0300 Subject: [PATCH 3/3] itest: test "lnd --debuglevel=show" command Tests that "lnd --debuglevel=show" command works and prints the list of supported subsystems. --- itest/config.go | 28 ++++++++++++++++++++++++++++ itest/list_on_test.go | 4 ++++ 2 files changed, 32 insertions(+) create mode 100644 itest/config.go diff --git a/itest/config.go b/itest/config.go new file mode 100644 index 000000000..98e633652 --- /dev/null +++ b/itest/config.go @@ -0,0 +1,28 @@ +//go:build integration + +package itest + +import ( + "os/exec" + + "github.com/lightningnetwork/lnd/lntest" + "github.com/stretchr/testify/require" +) + +// testDebuglevelShow tests that "lnd --debuglevel=show" command works and +// prints the list of supported subsystems. +func testDebuglevelShow(ht *lntest.HarnessTest) { + // We can't use ht.NewNode, because it adds more arguments to the + // command line (e.g. flags configuring bitcoin backend), but we want to + // make sure that "lnd --debuglevel=show" works without any other flags. + lndBinary := getLndBinary(ht.T) + cmd := exec.Command(lndBinary, "--debuglevel=show") + stdoutStderrBytes, err := cmd.CombinedOutput() + require.NoError(ht, err, "failed to run 'lnd --debuglevel=show'") + + // Make sure that the output contains the list of supported subsystems + // and that the list is not empty. We search PEER subsystem. + stdoutStderr := string(stdoutStderrBytes) + require.Contains(ht, stdoutStderr, "Supported subsystems") + require.Contains(ht, stdoutStderr, "PEER") +} diff --git a/itest/list_on_test.go b/itest/list_on_test.go index c5fa7cebf..68c923c3b 100644 --- a/itest/list_on_test.go +++ b/itest/list_on_test.go @@ -702,4 +702,8 @@ var allTestCases = []*lntest.TestCase{ Name: "send to route failed htlc timeout", TestFunc: testSendToRouteFailHTLCTimeout, }, + { + Name: "debuglevel show", + TestFunc: testDebuglevelShow, + }, }