From 3403794e81c487f12b35546264f20780930fb52c Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:21:32 -0700 Subject: [PATCH 01/20] chainntnfs: switch debug tag to dev This avoids collisions with the logging level tags --- .../bitcoindnotify/{bitcoind_debug.go => bitcoind_dev.go} | 2 +- chainntnfs/bitcoindnotify/bitcoind_test.go | 2 +- chainntnfs/btcdnotify/{btcd_debug.go => btcd_dev.go} | 2 +- chainntnfs/btcdnotify/btcd_test.go | 2 +- chainntnfs/{interface_debug.go => interface_dev.go} | 2 +- chainntnfs/interface_test.go | 2 +- .../neutrinonotify/{neutrino_debug.go => neutrino_dev.go} | 2 +- chainntnfs/test_utils.go | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) rename chainntnfs/bitcoindnotify/{bitcoind_debug.go => bitcoind_dev.go} (99%) rename chainntnfs/btcdnotify/{btcd_debug.go => btcd_dev.go} (99%) rename chainntnfs/{interface_debug.go => interface_dev.go} (96%) rename chainntnfs/neutrinonotify/{neutrino_debug.go => neutrino_dev.go} (99%) diff --git a/chainntnfs/bitcoindnotify/bitcoind_debug.go b/chainntnfs/bitcoindnotify/bitcoind_dev.go similarity index 99% rename from chainntnfs/bitcoindnotify/bitcoind_debug.go rename to chainntnfs/bitcoindnotify/bitcoind_dev.go index 04cd030c..f45cda09 100644 --- a/chainntnfs/bitcoindnotify/bitcoind_debug.go +++ b/chainntnfs/bitcoindnotify/bitcoind_dev.go @@ -1,4 +1,4 @@ -// +build debug +// +build dev package bitcoindnotify diff --git a/chainntnfs/bitcoindnotify/bitcoind_test.go b/chainntnfs/bitcoindnotify/bitcoind_test.go index e65945b0..8f731f38 100644 --- a/chainntnfs/bitcoindnotify/bitcoind_test.go +++ b/chainntnfs/bitcoindnotify/bitcoind_test.go @@ -1,4 +1,4 @@ -// +build debug +// +build dev package bitcoindnotify diff --git a/chainntnfs/btcdnotify/btcd_debug.go b/chainntnfs/btcdnotify/btcd_dev.go similarity index 99% rename from chainntnfs/btcdnotify/btcd_debug.go rename to chainntnfs/btcdnotify/btcd_dev.go index 1c91d3f6..af64dad8 100644 --- a/chainntnfs/btcdnotify/btcd_debug.go +++ b/chainntnfs/btcdnotify/btcd_dev.go @@ -1,4 +1,4 @@ -// +build debug +// +build dev package btcdnotify diff --git a/chainntnfs/btcdnotify/btcd_test.go b/chainntnfs/btcdnotify/btcd_test.go index 239e0d9d..6ef564d0 100644 --- a/chainntnfs/btcdnotify/btcd_test.go +++ b/chainntnfs/btcdnotify/btcd_test.go @@ -1,4 +1,4 @@ -// +build debug +// +build dev package btcdnotify diff --git a/chainntnfs/interface_debug.go b/chainntnfs/interface_dev.go similarity index 96% rename from chainntnfs/interface_debug.go rename to chainntnfs/interface_dev.go index aeb3461b..ac00fa8d 100644 --- a/chainntnfs/interface_debug.go +++ b/chainntnfs/interface_dev.go @@ -1,4 +1,4 @@ -// +build debug +// +build dev package chainntnfs diff --git a/chainntnfs/interface_test.go b/chainntnfs/interface_test.go index f51d912b..36006dcc 100644 --- a/chainntnfs/interface_test.go +++ b/chainntnfs/interface_test.go @@ -1,4 +1,4 @@ -// +build debug +// +build dev package chainntnfs_test diff --git a/chainntnfs/neutrinonotify/neutrino_debug.go b/chainntnfs/neutrinonotify/neutrino_dev.go similarity index 99% rename from chainntnfs/neutrinonotify/neutrino_debug.go rename to chainntnfs/neutrinonotify/neutrino_dev.go index 19085c38..635f0d95 100644 --- a/chainntnfs/neutrinonotify/neutrino_debug.go +++ b/chainntnfs/neutrinonotify/neutrino_dev.go @@ -1,4 +1,4 @@ -// +build debug +// +build dev package neutrinonotify diff --git a/chainntnfs/test_utils.go b/chainntnfs/test_utils.go index 44c844d0..bc3dae05 100644 --- a/chainntnfs/test_utils.go +++ b/chainntnfs/test_utils.go @@ -1,4 +1,4 @@ -// +build debug +// +build dev package chainntnfs From ece305123701ef48e4cb43d4d364029c873b9407 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:31:20 -0700 Subject: [PATCH 02/20] htlcswitch/hodl: switch from debug tag to dev --- htlcswitch/hodl/{config_debug.go => config_dev.go} | 4 ++-- htlcswitch/hodl/{config_production.go => config_prod.go} | 2 +- htlcswitch/hodl/{mask_debug.go => mask_dev.go} | 5 +---- htlcswitch/hodl/{mask_production.go => mask_prod.go} | 5 +---- htlcswitch/hodl/mask_test.go | 5 +++-- 5 files changed, 8 insertions(+), 13 deletions(-) rename htlcswitch/hodl/{config_debug.go => config_dev.go} (96%) rename htlcswitch/hodl/{config_production.go => config_prod.go} (92%) rename htlcswitch/hodl/{mask_debug.go => mask_dev.go} (89%) rename htlcswitch/hodl/{mask_production.go => mask_prod.go} (78%) diff --git a/htlcswitch/hodl/config_debug.go b/htlcswitch/hodl/config_dev.go similarity index 96% rename from htlcswitch/hodl/config_debug.go rename to htlcswitch/hodl/config_dev.go index 957eb50d..ef8389ad 100644 --- a/htlcswitch/hodl/config_debug.go +++ b/htlcswitch/hodl/config_dev.go @@ -1,4 +1,4 @@ -// +build debug +// +build dev package hodl @@ -61,7 +61,7 @@ func (c *Config) Mask() Mask { } // NOTE: The value returned here will only honor the configuration if - // the debug build flag is present. In production, this method always + // the dev build flag is present. In production, this method always // returns hodl.MaskNone and Active(*) always returns false. return MaskFromFlags(flags...) } diff --git a/htlcswitch/hodl/config_production.go b/htlcswitch/hodl/config_prod.go similarity index 92% rename from htlcswitch/hodl/config_production.go rename to htlcswitch/hodl/config_prod.go index 8daeefd8..c5e9e934 100644 --- a/htlcswitch/hodl/config_production.go +++ b/htlcswitch/hodl/config_prod.go @@ -1,4 +1,4 @@ -// +build !debug +// +build !dev package hodl diff --git a/htlcswitch/hodl/mask_debug.go b/htlcswitch/hodl/mask_dev.go similarity index 89% rename from htlcswitch/hodl/mask_debug.go rename to htlcswitch/hodl/mask_dev.go index 5d5fd065..a1d50ff0 100644 --- a/htlcswitch/hodl/mask_debug.go +++ b/htlcswitch/hodl/mask_dev.go @@ -1,4 +1,4 @@ -// +build debug +// +build dev package hodl @@ -7,9 +7,6 @@ import ( "strings" ) -// DebugBuild signals that this is a debug build. -const DebugBuild = true - // MaskFromFlags merges a variadic set of Flags into a single Mask. func MaskFromFlags(flags ...Flag) Mask { var mask Mask diff --git a/htlcswitch/hodl/mask_production.go b/htlcswitch/hodl/mask_prod.go similarity index 78% rename from htlcswitch/hodl/mask_production.go rename to htlcswitch/hodl/mask_prod.go index c2db04ef..1b8a4b70 100644 --- a/htlcswitch/hodl/mask_production.go +++ b/htlcswitch/hodl/mask_prod.go @@ -1,10 +1,7 @@ -// +build !debug +// +build !dev package hodl -// DebugBuild signals that this is a production build. -const DebugBuild = false - // MaskFromFlags in production always returns MaskNone. func MaskFromFlags(_ ...Flag) Mask { return MaskNone diff --git a/htlcswitch/hodl/mask_test.go b/htlcswitch/hodl/mask_test.go index cf29d19b..07ba6e33 100644 --- a/htlcswitch/hodl/mask_test.go +++ b/htlcswitch/hodl/mask_test.go @@ -3,6 +3,7 @@ package hodl_test import ( "testing" + "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/htlcswitch/hodl" ) @@ -87,8 +88,8 @@ var hodlMaskTests = []struct { // correctly reports active for flags in the tests' expected flags, and inactive // for all others. func TestMask(t *testing.T) { - if !hodl.DebugBuild { - t.Fatalf("htlcswitch tests must be run with '-tags debug'") + if !build.IsDevBuild() { + t.Fatalf("htlcswitch tests must be run with '-tags=dev'") } for i, test := range hodlMaskTests { From bab52421faff767afc18d8b94c359f5885dba8f9 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:27:57 -0700 Subject: [PATCH 03/20] make/testing_flags: make DEV_TAGS+PROD_TAGS, switch debug to dev --- make/testing_flags.mk | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/make/testing_flags.mk b/make/testing_flags.mk index 308f83f9..1b8114f8 100644 --- a/make/testing_flags.mk +++ b/make/testing_flags.mk @@ -1,4 +1,6 @@ -TEST_TAGS = debug +DEV_TAGS = dev +PROD_TAGS = prod +LOG_TAGS = TEST_FLAGS = # If specific package is being unit tested, construct the full name of the @@ -34,16 +36,16 @@ UNIT_TARGETED ?= no # If a specific package/test case was requested, run the unit test for the # targeted case. Otherwise, default to running all tests. ifeq ($(UNIT_TARGETED), yes) -UNIT := $(GOTEST) -tags="$(TEST_TAGS)" $(TEST_FLAGS) $(UNITPKG) -UNIT_RACE := $(GOTEST) -tags="$(TEST_TAGS)" $(TEST_FLAGS) -race $(UNITPKG) +UNIT := $(GOTEST) -tags="$(DEV_TAGS)" $(TEST_FLAGS) $(UNITPKG) +UNIT_RACE := $(GOTEST) -tags="$(DEV_TAGS)" $(TEST_FLAGS) -race $(UNITPKG) endif ifeq ($(UNIT_TARGETED), no) -UNIT := $(GOLIST) | $(XARGS) $(GOTEST) -tags="$(TEST_TAGS)" $(TEST_FLAGS) +UNIT := $(GOLIST) | $(XARGS) $(GOTEST) -tags="$(DEV_TAGS)" $(TEST_FLAGS) UNIT_RACE := $(UNIT) -race endif # Construct the integration test command with the added build flags. -ITEST_TAGS := $(TEST_TAGS) rpctest +ITEST_TAGS := $(DEV_TAGS) rpctest ITEST := rm output*.log; date; $(GOTEST) -tags="$(ITEST_TAGS)" $(TEST_FLAGS) -logoutput From 10b35a8f20e233fe2cc6055f6e26783603dac224 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:23:01 -0700 Subject: [PATCH 04/20] main: remove disable log in testing + clean up imports --- breacharbiter.go | 1 + breacharbiter_test.go | 5 ----- fundingmanager.go | 5 +++-- fundingmanager_test.go | 11 +---------- nursery_store_test.go | 7 ------- peer.go | 1 + peer_test.go | 12 ------------ utxonursery.go | 1 + 8 files changed, 7 insertions(+), 36 deletions(-) diff --git a/breacharbiter.go b/breacharbiter.go index 07fb5b25..df19bff1 100644 --- a/breacharbiter.go +++ b/breacharbiter.go @@ -15,6 +15,7 @@ import ( "github.com/btcsuite/btcutil" "github.com/coreos/bbolt" "github.com/davecgh/go-spew/spew" + "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/htlcswitch" diff --git a/breacharbiter_test.go b/breacharbiter_test.go index 8f6c90a3..31fc5a04 100644 --- a/breacharbiter_test.go +++ b/breacharbiter_test.go @@ -22,7 +22,6 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btclog" "github.com/btcsuite/btcutil" "github.com/go-errors/errors" "github.com/lightningnetwork/lnd/chainntnfs" @@ -268,10 +267,6 @@ var ( ) func init() { - channeldb.UseLogger(btclog.Disabled) - lnwallet.UseLogger(btclog.Disabled) - brarLog = btclog.Disabled - // Ensure that breached outputs are initialized before starting tests. if err := initBreachedOutputs(); err != nil { panic(err) diff --git a/fundingmanager.go b/fundingmanager.go index 55622e40..0acfadcf 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -15,6 +15,9 @@ import ( "github.com/coreos/bbolt" "github.com/davecgh/go-spew/spew" "github.com/go-errors/errors" + "golang.org/x/crypto/salsa20" + "google.golang.org/grpc" + "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/htlcswitch" @@ -24,8 +27,6 @@ import ( "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/routing" - "golang.org/x/crypto/salsa20" - "google.golang.org/grpc" ) const ( diff --git a/fundingmanager_test.go b/fundingmanager_test.go index c1421575..2cfd8097 100644 --- a/fundingmanager_test.go +++ b/fundingmanager_test.go @@ -18,12 +18,10 @@ import ( "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btclog" "github.com/btcsuite/btcutil" - _ "github.com/btcsuite/btcwallet/walletdb/bdb" + "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" - "github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lnpeer" @@ -201,13 +199,6 @@ func (n *testNode) AddNewChannel(channel *channeldb.OpenChannel, } } -func init() { - channeldb.UseLogger(btclog.Disabled) - lnwallet.UseLogger(btclog.Disabled) - contractcourt.UseLogger(btclog.Disabled) - fndgLog = btclog.Disabled -} - func createTestWallet(cdb *channeldb.DB, netParams *chaincfg.Params, notifier chainntnfs.ChainNotifier, wc lnwallet.WalletController, signer lnwallet.Signer, keyRing keychain.SecretKeyRing, diff --git a/nursery_store_test.go b/nursery_store_test.go index 16723abb..4617e5e0 100644 --- a/nursery_store_test.go +++ b/nursery_store_test.go @@ -9,16 +9,9 @@ import ( "testing" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btclog" "github.com/lightningnetwork/lnd/channeldb" ) -func init() { - // Disable logging to prevent panics bc. of global state - channeldb.UseLogger(btclog.Disabled) - utxnLog = btclog.Disabled -} - // makeTestDB creates a new instance of the ChannelDB for testing purposes. A // callback which cleans up the created temporary directories is also returned // and intended to be executed after the test completes. diff --git a/peer.go b/peer.go index 2f7f5488..e95f30ee 100644 --- a/peer.go +++ b/peer.go @@ -16,6 +16,7 @@ import ( "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/davecgh/go-spew/spew" + "github.com/lightningnetwork/lnd/brontide" "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" diff --git a/peer_test.go b/peer_test.go index ffeb5951..86ba3c16 100644 --- a/peer_test.go +++ b/peer_test.go @@ -7,26 +7,14 @@ import ( "time" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btclog" "github.com/btcsuite/btcutil" "github.com/lightningnetwork/lnd/chainntnfs" - "github.com/lightningnetwork/lnd/channeldb" - "github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" ) -func init() { - peerLog = btclog.Disabled - srvrLog = btclog.Disabled - lnwallet.UseLogger(btclog.Disabled) - htlcswitch.UseLogger(btclog.Disabled) - channeldb.UseLogger(btclog.Disabled) - contractcourt.UseLogger(btclog.Disabled) -} - // TestPeerChannelClosureAcceptFeeResponder tests the shutdown responder's // behavior if we can agree on the fee immediately. func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) { diff --git a/utxonursery.go b/utxonursery.go index 71511ab2..8eed7cb5 100644 --- a/utxonursery.go +++ b/utxonursery.go @@ -13,6 +13,7 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/davecgh/go-spew/spew" + "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/lnwallet" From 738ba45bcf0d3d9ec4f46f82f22e1d5d44231083 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:16:25 -0700 Subject: [PATCH 05/20] build/deployment: add prod+dev targets --- build/deployment.go | 36 ++++++++++++++++++++++++++++++++++++ build/deployment_dev.go | 6 ++++++ build/deployment_prod.go | 6 ++++++ 3 files changed, 48 insertions(+) create mode 100644 build/deployment.go create mode 100644 build/deployment_dev.go create mode 100644 build/deployment_prod.go diff --git a/build/deployment.go b/build/deployment.go new file mode 100644 index 00000000..410f7e96 --- /dev/null +++ b/build/deployment.go @@ -0,0 +1,36 @@ +package build + +// DeploymentType is an enum specifying the deployment to compile. +type DeploymentType byte + +const ( + // Development is a deployment that includes extra testing hooks and + // logging configurations. + Development DeploymentType = iota + + // Production is a deployment that strips out testing logic and uses + // Default logging. + Production +) + +// String returns a human readable name for a build type. +func (b DeploymentType) String() string { + switch b { + case Development: + return "development" + case Production: + return "production" + default: + return "unknown" + } +} + +// IsProdBuild returns true if this is a production build. +func IsProdBuild() bool { + return Deployment == Production +} + +// IsDevBuild returns true if this is a development build. +func IsDevBuild() bool { + return Deployment == Development +} diff --git a/build/deployment_dev.go b/build/deployment_dev.go new file mode 100644 index 00000000..fb2bb2b9 --- /dev/null +++ b/build/deployment_dev.go @@ -0,0 +1,6 @@ +// +build dev + +package build + +// Deployment specifies a development build. +const Deployment = Development diff --git a/build/deployment_prod.go b/build/deployment_prod.go new file mode 100644 index 00000000..247f25ae --- /dev/null +++ b/build/deployment_prod.go @@ -0,0 +1,6 @@ +// +build !dev + +package build + +// Deployment specifies a production build. +const Deployment = Production From 4ea1a40a887ac3083c85b3c3110e23322c7a7760 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:17:45 -0700 Subject: [PATCH 06/20] build/loglevel: add build flag hooks for log levels --- build/loglevel_critical.go | 6 ++++++ build/loglevel_debug.go | 6 ++++++ build/loglevel_default.go | 6 ++++++ build/loglevel_error.go | 6 ++++++ build/loglevel_info.go | 6 ++++++ build/loglevel_off.go | 6 ++++++ build/loglevel_trace.go | 6 ++++++ build/loglevel_warn.go | 6 ++++++ 8 files changed, 48 insertions(+) create mode 100644 build/loglevel_critical.go create mode 100644 build/loglevel_debug.go create mode 100644 build/loglevel_default.go create mode 100644 build/loglevel_error.go create mode 100644 build/loglevel_info.go create mode 100644 build/loglevel_off.go create mode 100644 build/loglevel_trace.go create mode 100644 build/loglevel_warn.go diff --git a/build/loglevel_critical.go b/build/loglevel_critical.go new file mode 100644 index 00000000..2e3a3734 --- /dev/null +++ b/build/loglevel_critical.go @@ -0,0 +1,6 @@ +// +build dev,critical + +package build + +// LogLevel specifies a critical log level. +var LogLevel = "critical" diff --git a/build/loglevel_debug.go b/build/loglevel_debug.go new file mode 100644 index 00000000..7d22c90a --- /dev/null +++ b/build/loglevel_debug.go @@ -0,0 +1,6 @@ +// +build dev,debug + +package build + +// LogLevel specifies a debug log level. +var LogLevel = "debug" diff --git a/build/loglevel_default.go b/build/loglevel_default.go new file mode 100644 index 00000000..5e12ffcc --- /dev/null +++ b/build/loglevel_default.go @@ -0,0 +1,6 @@ +// +build !info,!debug,!trace,!warn,!error,!critical,!off + +package build + +// LogLevel specifies a default log level of info. +var LogLevel = "info" diff --git a/build/loglevel_error.go b/build/loglevel_error.go new file mode 100644 index 00000000..81e3849e --- /dev/null +++ b/build/loglevel_error.go @@ -0,0 +1,6 @@ +// +build dev,error + +package build + +// LogLevel specifies an error log level. +var LogLevel = "error" diff --git a/build/loglevel_info.go b/build/loglevel_info.go new file mode 100644 index 00000000..f0d6dca0 --- /dev/null +++ b/build/loglevel_info.go @@ -0,0 +1,6 @@ +// +build dev,info + +package build + +// LogLevel specifies an info log level. +var LogLevel = "info" diff --git a/build/loglevel_off.go b/build/loglevel_off.go new file mode 100644 index 00000000..d6c65e77 --- /dev/null +++ b/build/loglevel_off.go @@ -0,0 +1,6 @@ +// +build dev,off + +package build + +// LogLevel specifies an off log level. +var LogLevel = "off" diff --git a/build/loglevel_trace.go b/build/loglevel_trace.go new file mode 100644 index 00000000..ec17e9dd --- /dev/null +++ b/build/loglevel_trace.go @@ -0,0 +1,6 @@ +// +build dev,trace + +package build + +// LogLevel specifies a trace log level. +var LogLevel = "trace" diff --git a/build/loglevel_warn.go b/build/loglevel_warn.go new file mode 100644 index 00000000..a8fdfc29 --- /dev/null +++ b/build/loglevel_warn.go @@ -0,0 +1,6 @@ +// +build dev,warn + +package build + +// LogLevel specifies a warning log level. +var LogLevel = "warn" From 9654a1c6198b4ae719fbe6498d8d3921bd4955f3 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:17:15 -0700 Subject: [PATCH 07/20] build/log: add log types + NewSubLogger --- build/log.go | 95 ++++++++++++++++++++++++++++++++++++++++++++ build/log_default.go | 18 +++++++++ build/log_nolog.go | 11 +++++ build/log_stdlog.go | 14 +++++++ 4 files changed, 138 insertions(+) create mode 100644 build/log.go create mode 100644 build/log_default.go create mode 100644 build/log_nolog.go create mode 100644 build/log_stdlog.go diff --git a/build/log.go b/build/log.go new file mode 100644 index 00000000..31be5d4d --- /dev/null +++ b/build/log.go @@ -0,0 +1,95 @@ +package build + +import ( + "io" + + "github.com/btcsuite/btclog" +) + +// LogType is an indicating the type of logging specified by the build flag. +type LogType byte + +const ( + // LogTypeNone indicates no logging. + LogTypeNone LogType = iota + + // LogTypeStdOut all logging is written directly to stdout. + LogTypeStdOut + + // LogTypeDefault logs to both stdout and a given io.PipeWriter. + LogTypeDefault +) + +// String returns a human readable identifier for the logging type. +func (t LogType) String() string { + switch t { + case LogTypeNone: + return "none" + case LogTypeStdOut: + return "stdout" + case LogTypeDefault: + return "default" + default: + return "unknown" + } +} + +// LogWriter is a stub type whose behavior can be changed using the build flags +// "stdlog" and "nolog". The default behavior is to write to both stdout and the +// RotatorPipe. Passing "stdlog" will cause it only to write to stdout, and +// "nolog" implements Write as a no-op. +type LogWriter struct { + // RotatorPipe is the write-end pipe for writing to the log rotator. It + // is written to by the Write method of the LogWriter type. This only + // needs to be set if neither the stdlog or nolog builds are set. + RotatorPipe *io.PipeWriter +} + +// NewSubLogger constructs a new subsystem log from the current LogWriter +// implementation. This is primarily intended for use with stdlog, as the actual +// writer is shared amongst all instantiations. +func NewSubLogger(subsystem string, + genSubLogger func(string) btclog.Logger) btclog.Logger { + + switch Deployment { + + // For production builds, generate a new subsystem logger from the + // primary log backend. If no function is provided, logging will be + // disabled. + case Production: + if genSubLogger != nil { + return genSubLogger(subsystem) + } + + // For development builds, we must handle two distinct types of logging: + // unit tests and running the live daemon, e.g. for integration testing. + case Development: + switch LoggingType { + + // Default logging is used when running the standalone daemon. + // We'll use the optional sublogger constructor to mimic the + // production behavior. + case LogTypeDefault: + if genSubLogger != nil { + return genSubLogger(subsystem) + } + + // Logging to stdout is used in unit tests. It is not important + // that they share the same backend, since all output is written + // to std out. + case LogTypeStdOut: + backend := btclog.NewBackend(&LogWriter{}) + logger := backend.Logger(subsystem) + + // Set the logging level of the stdout logger to use the + // configured logging level specified by build flags. + level, _ := btclog.LevelFromString(LogLevel) + logger.SetLevel(level) + + return logger + } + } + + // For any other configurations, we'll disable logging. + return btclog.Disabled +} diff --git a/build/log_default.go b/build/log_default.go new file mode 100644 index 00000000..399a00df --- /dev/null +++ b/build/log_default.go @@ -0,0 +1,18 @@ +// +build !stdlog,!nolog + +package build + +import "os" + +// LoggingType is a log type that writes to both stdout and the log rotator, if +// present. +const LoggingType = LogTypeDefault + +// Write writes the byte slice to both stdout and the log rotator, if present. +func (w *LogWriter) Write(b []byte) (int, error) { + os.Stdout.Write(b) + if w.RotatorPipe != nil { + w.RotatorPipe.Write(b) + } + return len(b), nil +} diff --git a/build/log_nolog.go b/build/log_nolog.go new file mode 100644 index 00000000..0aa15bc4 --- /dev/null +++ b/build/log_nolog.go @@ -0,0 +1,11 @@ +// +build nolog + +package build + +// LoggingType is a log type that writes no logs. +const LoggingType = LogTypeNone + +// Write is a noop. +func (w *LogWriter) Write(b []byte) (int, error) { + return len(b), nil +} diff --git a/build/log_stdlog.go b/build/log_stdlog.go new file mode 100644 index 00000000..a495eaec --- /dev/null +++ b/build/log_stdlog.go @@ -0,0 +1,14 @@ +// +build stdlog + +package build + +import "os" + +// LoggingType is a log type that only writes to stdout. +const LoggingType = LogTypeStdOut + +// Write writes the provided byte slice to stdout. +func (w *LogWriter) Write(b []byte) (int, error) { + os.Stdout.Write(b) + return len(b), nil +} From 59b459674dc14558254a6e78795be70a06494510 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:14:50 -0700 Subject: [PATCH 08/20] multi: init subsystem loggers via build pkg --- autopilot/log.go | 9 ++++++--- chainntnfs/log.go | 9 ++++++--- channeldb/log.go | 10 ++++++---- contractcourt/log.go | 9 ++++++--- discovery/log.go | 9 ++++++--- htlcswitch/log.go | 9 ++++++--- lnwallet/log.go | 6 ++++-- routing/chainview/log.go | 9 ++++++--- routing/log.go | 5 +++-- signal/log.go | 2 +- 10 files changed, 50 insertions(+), 27 deletions(-) diff --git a/autopilot/log.go b/autopilot/log.go index 70f49947..34e53c84 100644 --- a/autopilot/log.go +++ b/autopilot/log.go @@ -1,6 +1,9 @@ package autopilot -import "github.com/btcsuite/btclog" +import ( + "github.com/btcsuite/btclog" + "github.com/lightningnetwork/lnd/build" +) // log is a logger that is initialized with no output filters. This // means the package will not perform any logging by default until the caller @@ -9,13 +12,13 @@ var log btclog.Logger // The default amount of logging is none. func init() { - DisableLog() + UseLogger(build.NewSubLogger("ATPL", nil)) } // DisableLog disables all library log output. Logging output is disabled // by default until UseLogger is called. func DisableLog() { - log = btclog.Disabled + UseLogger(btclog.Disabled) } // UseLogger uses a specified Logger to output package logging info. diff --git a/chainntnfs/log.go b/chainntnfs/log.go index b6a3f148..f2124605 100644 --- a/chainntnfs/log.go +++ b/chainntnfs/log.go @@ -1,6 +1,9 @@ package chainntnfs -import "github.com/btcsuite/btclog" +import ( + "github.com/btcsuite/btclog" + "github.com/lightningnetwork/lnd/build" +) // Log is a logger that is initialized with no output filters. This // means the package will not perform any logging by default until the caller @@ -9,13 +12,13 @@ var Log btclog.Logger // The default amount of logging is none. func init() { - DisableLog() + UseLogger(build.NewSubLogger("NTFN", nil)) } // DisableLog disables all library log output. Logging output is disabled // by default until UseLogger is called. func DisableLog() { - Log = btclog.Disabled + UseLogger(btclog.Disabled) } // UseLogger uses a specified Logger to output package logging info. diff --git a/channeldb/log.go b/channeldb/log.go index d44192e7..e0158d45 100644 --- a/channeldb/log.go +++ b/channeldb/log.go @@ -1,21 +1,23 @@ package channeldb -import "github.com/btcsuite/btclog" +import ( + "github.com/btcsuite/btclog" + "github.com/lightningnetwork/lnd/build" +) // log is a logger that is initialized with no output filters. This // means the package will not perform any logging by default until the caller // requests it. var log btclog.Logger -// The default amount of logging is none. func init() { - DisableLog() + UseLogger(build.NewSubLogger("CHDB", nil)) } // DisableLog disables all library log output. Logging output is disabled // by default until UseLogger is called. func DisableLog() { - log = btclog.Disabled + UseLogger(btclog.Disabled) } // UseLogger uses a specified Logger to output package logging info. diff --git a/contractcourt/log.go b/contractcourt/log.go index 0168177c..e8b70719 100644 --- a/contractcourt/log.go +++ b/contractcourt/log.go @@ -1,6 +1,9 @@ package contractcourt -import "github.com/btcsuite/btclog" +import ( + "github.com/btcsuite/btclog" + "github.com/lightningnetwork/lnd/build" +) // log is a logger that is initialized with no output filters. This // means the package will not perform any logging by default until the caller @@ -9,13 +12,13 @@ var log btclog.Logger // The default amount of logging is none. func init() { - DisableLog() + UseLogger(build.NewSubLogger("CNCT", nil)) } // DisableLog disables all library log output. Logging output is disabled // by default until UseLogger is called. func DisableLog() { - log = btclog.Disabled + UseLogger(btclog.Disabled) } // UseLogger uses a specified Logger to output package logging info. diff --git a/discovery/log.go b/discovery/log.go index 7d38664c..bd2004d3 100644 --- a/discovery/log.go +++ b/discovery/log.go @@ -1,6 +1,9 @@ package discovery -import "github.com/btcsuite/btclog" +import ( + "github.com/btcsuite/btclog" + "github.com/lightningnetwork/lnd/build" +) // log is a logger that is initialized with no output filters. This // means the package will not perform any logging by default until the caller @@ -9,13 +12,13 @@ var log btclog.Logger // The default amount of logging is none. func init() { - DisableLog() + UseLogger(build.NewSubLogger("DISC", nil)) } // DisableLog disables all library log output. Logging output is disabled // by default until UseLogger is called. func DisableLog() { - log = btclog.Disabled + UseLogger(btclog.Disabled) } // UseLogger uses a specified Logger to output package logging info. diff --git a/htlcswitch/log.go b/htlcswitch/log.go index bd4593a3..63fe63a1 100644 --- a/htlcswitch/log.go +++ b/htlcswitch/log.go @@ -1,6 +1,9 @@ package htlcswitch -import "github.com/btcsuite/btclog" +import ( + "github.com/btcsuite/btclog" + "github.com/lightningnetwork/lnd/build" +) // log is a logger that is initialized with no output filters. This // means the package will not perform any logging by default until the caller @@ -9,13 +12,13 @@ var log btclog.Logger // The default amount of logging is none. func init() { - DisableLog() + UseLogger(build.NewSubLogger("HSWC", nil)) } // DisableLog disables all library log output. Logging output is disabled // by default until UseLogger is called. func DisableLog() { - log = btclog.Disabled + UseLogger(btclog.Disabled) } // UseLogger uses a specified Logger to output package logging info. diff --git a/lnwallet/log.go b/lnwallet/log.go index f36aa99f..97f1c21f 100644 --- a/lnwallet/log.go +++ b/lnwallet/log.go @@ -5,6 +5,8 @@ import ( "github.com/btcsuite/btcwallet/chain" btcwallet "github.com/btcsuite/btcwallet/wallet" "github.com/btcsuite/btcwallet/wtxmgr" + + "github.com/lightningnetwork/lnd/build" ) // walletLog is a logger that is initialized with no output filters. This @@ -14,13 +16,13 @@ var walletLog btclog.Logger // The default amount of logging is none. func init() { - DisableLog() + UseLogger(build.NewSubLogger("LNWL", nil)) } // DisableLog disables all library log output. Logging output is disabled // by default until UseLogger is called. func DisableLog() { - walletLog = btclog.Disabled + UseLogger(btclog.Disabled) } // UseLogger uses a specified Logger to output package logging info. diff --git a/routing/chainview/log.go b/routing/chainview/log.go index cb3b59a2..b411819d 100644 --- a/routing/chainview/log.go +++ b/routing/chainview/log.go @@ -1,6 +1,9 @@ package chainview -import "github.com/btcsuite/btclog" +import ( + "github.com/btcsuite/btclog" + "github.com/lightningnetwork/lnd/build" +) // log is a logger that is initialized with no output filters. This // means the package will not perform any logging by default until the caller @@ -9,13 +12,13 @@ var log btclog.Logger // The default amount of logging is none. func init() { - DisableLog() + UseLogger(build.NewSubLogger("CRTR", nil)) } // DisableLog disables all library log output. Logging output is disabled // by default until either UseLogger or SetLogWriter are called. func DisableLog() { - log = btclog.Disabled + UseLogger(btclog.Disabled) } // UseLogger uses a specified Logger to output package logging info. diff --git a/routing/log.go b/routing/log.go index b990aa74..ce550812 100644 --- a/routing/log.go +++ b/routing/log.go @@ -2,6 +2,7 @@ package routing import ( "github.com/btcsuite/btclog" + "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/routing/chainview" ) @@ -12,13 +13,13 @@ var log btclog.Logger // The default amount of logging is none. func init() { - DisableLog() + UseLogger(build.NewSubLogger("CRTR", nil)) } // DisableLog disables all library log output. Logging output is disabled by // by default until UseLogger is called. func DisableLog() { - log = btclog.Disabled + UseLogger(btclog.Disabled) } // UseLogger uses a specified Logger to output package logging info. This diff --git a/signal/log.go b/signal/log.go index e7034321..6bde284b 100644 --- a/signal/log.go +++ b/signal/log.go @@ -15,7 +15,7 @@ func init() { // DisableLog disables all library log output. Logging output is disabled // by default until UseLogger is called. func DisableLog() { - log = btclog.Disabled + UseLogger(btclog.Disabled) } // UseLogger uses a specified Logger to output package logging info. From bfcda6e205391214417fcd84ec9f62c7bac738e7 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:28:35 -0700 Subject: [PATCH 09/20] log: initialize subloggers w/ build.LogWriter and build.NewSubLogger --- log.go | 58 ++++++++++++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/log.go b/log.go index 01ba080f..1fe1b658 100644 --- a/log.go +++ b/log.go @@ -12,8 +12,10 @@ import ( "github.com/btcsuite/btclog" "github.com/jrick/logrotate/rotator" "github.com/lightninglabs/neutrino" + "github.com/lightningnetwork/lightning-onion" "github.com/lightningnetwork/lnd/autopilot" + "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/contractcourt" @@ -24,16 +26,6 @@ import ( "github.com/lightningnetwork/lnd/signal" ) -// logWriter implements an io.Writer that outputs to both standard output and -// the write-end pipe of an initialized log rotator. -type logWriter struct{} - -func (logWriter) Write(p []byte) (n int, err error) { - os.Stdout.Write(p) - logRotatorPipe.Write(p) - return len(p), nil -} - // Loggers per subsystem. A single backend logger is created and all subsystem // loggers created from it will write to the backend. When adding new // subsystems, add the subsystem logger variable here and to the @@ -43,38 +35,36 @@ func (logWriter) Write(p []byte) (n int, err error) { // log file. This must be performed early during application startup by // calling initLogRotator. var ( + logWriter = &build.LogWriter{} + // backendLog is the logging backend used to create all subsystem // loggers. The backend must not be used before the log rotator has // been initialized, or data races and/or nil pointer dereferences will // occur. - backendLog = btclog.NewBackend(logWriter{}) + backendLog = btclog.NewBackend(logWriter) // logRotator is one of the logging outputs. It should be closed on // application shutdown. logRotator *rotator.Rotator - // logRotatorPipe is the write-end pipe for writing to the log rotator. - // It is written to by the Write method of the logWriter type. - logRotatorPipe *io.PipeWriter - - ltndLog = backendLog.Logger("LTND") - lnwlLog = backendLog.Logger("LNWL") - peerLog = backendLog.Logger("PEER") - discLog = backendLog.Logger("DISC") - rpcsLog = backendLog.Logger("RPCS") - srvrLog = backendLog.Logger("SRVR") - ntfnLog = backendLog.Logger("NTFN") - chdbLog = backendLog.Logger("CHDB") - fndgLog = backendLog.Logger("FNDG") - hswcLog = backendLog.Logger("HSWC") - utxnLog = backendLog.Logger("UTXN") - brarLog = backendLog.Logger("BRAR") - cmgrLog = backendLog.Logger("CMGR") - crtrLog = backendLog.Logger("CRTR") - btcnLog = backendLog.Logger("BTCN") - atplLog = backendLog.Logger("ATPL") - cnctLog = backendLog.Logger("CNCT") - sphxLog = backendLog.Logger("SPHX") + ltndLog = build.NewSubLogger("LTND", backendLog.Logger) + lnwlLog = build.NewSubLogger("LNWL", backendLog.Logger) + peerLog = build.NewSubLogger("PEER", backendLog.Logger) + discLog = build.NewSubLogger("DISC", backendLog.Logger) + rpcsLog = build.NewSubLogger("RPCS", backendLog.Logger) + srvrLog = build.NewSubLogger("SRVR", backendLog.Logger) + ntfnLog = build.NewSubLogger("NTFN", backendLog.Logger) + chdbLog = build.NewSubLogger("CHDB", backendLog.Logger) + fndgLog = build.NewSubLogger("FNDG", backendLog.Logger) + hswcLog = build.NewSubLogger("HSWC", backendLog.Logger) + utxnLog = build.NewSubLogger("UTXN", backendLog.Logger) + brarLog = build.NewSubLogger("BRAR", backendLog.Logger) + cmgrLog = build.NewSubLogger("CMGR", backendLog.Logger) + crtrLog = build.NewSubLogger("CRTR", backendLog.Logger) + btcnLog = build.NewSubLogger("BTCN", backendLog.Logger) + atplLog = build.NewSubLogger("ATPL", backendLog.Logger) + cnctLog = build.NewSubLogger("CNCT", backendLog.Logger) + sphxLog = build.NewSubLogger("SPHX", backendLog.Logger) ) // Initialize package-global logger variables. @@ -134,8 +124,8 @@ func initLogRotator(logFile string, MaxLogFileSize int, MaxLogFiles int) { pr, pw := io.Pipe() go r.Run(pr) + logWriter.RotatorPipe = pw logRotator = r - logRotatorPipe = pw } // setLogLevel sets the logging level for provided subsystem. Invalid From bbceec8bea377dbc837f2f20fe19f60aedf73030 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:24:53 -0700 Subject: [PATCH 10/20] lnd: log shutdown before closing rotator --- lnd.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lnd.go b/lnd.go index e323e95d..f7dba152 100644 --- a/lnd.go +++ b/lnd.go @@ -93,12 +93,6 @@ var ( // defers created in the top-level scope of a main method aren't executed if // os.Exit() is called. func lndMain() error { - defer func() { - if logRotatorPipe != nil { - ltndLog.Info("Shutdown complete") - } - }() - // Load the configuration, and parse any command line options. This // function will also set up logging properly. loadedConfig, err := loadConfig() @@ -108,6 +102,7 @@ func lndMain() error { cfg = loadedConfig defer func() { if logRotator != nil { + ltndLog.Info("Shutdown complete") logRotator.Close() } }() From 1e64070a1d1a20af35b94899c847af7aa1bf081b Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:31:50 -0700 Subject: [PATCH 11/20] build/version: move version.go to build pkg --- version.go => build/version.go | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) rename version.go => build/version.go (72%) diff --git a/version.go b/build/version.go similarity index 72% rename from version.go rename to build/version.go index 69c6cc43..c535a649 100644 --- a/version.go +++ b/build/version.go @@ -3,7 +3,7 @@ // Heavily inspired by https://github.com/btcsuite/btcd/blob/master/version.go // Copyright (C) 2015-2017 The Lightning Network Developers -package main +package build import ( "bytes" @@ -11,6 +11,10 @@ import ( "strings" ) +// Commit stores the current commit hash of this build, this should be set using +// the -ldflags during compilation. +var Commit string + // semanticAlphabet const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-" @@ -26,14 +30,9 @@ const ( appPreRelease = "beta" ) -// appBuild is defined as a variable so it can be overridden during the build -// process with '-ldflags "-X main.appBuild foo' if needed. It MUST only -// contain characters from semanticAlphabet per the semantic versioning spec. -var appBuild string - -// version returns the application version as a properly formed string per the +// Version returns the application version as a properly formed string per the // semantic versioning 2.0.0 spec (http://semver.org/). -func version() string { +func Version() string { // Start with the major, minor, and patch versions. version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch) @@ -46,15 +45,6 @@ func version() string { version = fmt.Sprintf("%s-%s", version, preRelease) } - // Append build metadata if there is any. The plus called for - // by the semantic versioning spec is automatically appended and should - // not be contained in the build metadata string. The build metadata - // string is not appended if it contains invalid characters. - build := normalizeVerString(appBuild) - if build != "" { - version = fmt.Sprintf("%s+%s", version, build) - } - // Append commit hash of current build to version. version = fmt.Sprintf("%s commit=%s", version, Commit) From 97fd56cf47550f0bf64f0da57e48c82d88eb8e7a Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:26:38 -0700 Subject: [PATCH 12/20] cmd/lncli: display build.Version() for commit hash --- cmd/lncli/main.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 7a698f07..3588ba57 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -15,6 +15,7 @@ import ( macaroon "gopkg.in/macaroon.v2" "github.com/btcsuite/btcutil" + "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/macaroons" @@ -34,10 +35,6 @@ const ( ) var ( - // Commit stores the current commit hash of this build. This should be - // set using -ldflags during compilation. - Commit string - defaultLndDir = btcutil.AppDataDir("lnd", false) defaultTLSCertPath = filepath.Join(defaultLndDir, defaultTLSCertFilename) ) @@ -205,7 +202,7 @@ func extractPathArgs(ctx *cli.Context) (string, string, error) { func main() { app := cli.NewApp() app.Name = "lncli" - app.Version = fmt.Sprintf("%s commit=%s", "0.5", Commit) + app.Version = build.Version() app.Usage = "control plane for your Lightning Network Daemon (lnd)" app.Flags = []cli.Flag{ cli.StringFlag{ From 0903fe3183343f7807248310d9a87ce5e6fb5350 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:26:58 -0700 Subject: [PATCH 13/20] main+lnd: display build.Version() for commit hash --- config.go | 3 ++- lnd.go | 9 ++++----- rpcserver.go | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index f39099e1..26e4c522 100644 --- a/config.go +++ b/config.go @@ -21,6 +21,7 @@ import ( "github.com/btcsuite/btcutil" flags "github.com/jessevdk/go-flags" + "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/htlcswitch/hodl" "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnwire" @@ -323,7 +324,7 @@ func loadConfig() (*config, error) { appName = strings.TrimSuffix(appName, filepath.Ext(appName)) usageMessage := fmt.Sprintf("Use %s -h to show usage", appName) if preCfg.ShowVersion { - fmt.Println(appName, "version", version()) + fmt.Println(appName, "version", build.Version()) os.Exit(0) } diff --git a/lnd.go b/lnd.go index f7dba152..93b58ef1 100644 --- a/lnd.go +++ b/lnd.go @@ -37,6 +37,8 @@ import ( "github.com/btcsuite/btcwallet/wallet" proxy "github.com/grpc-ecosystem/grpc-gateway/runtime" flags "github.com/jessevdk/go-flags" + + "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lncfg" @@ -54,10 +56,6 @@ const ( ) var ( - // Commit stores the current commit hash of this build. This should be - // set using -ldflags during compilation. - Commit string - cfg *config registeredChains = newChainRegistry() @@ -108,7 +106,8 @@ func lndMain() error { }() // Show version at startup. - ltndLog.Infof("Version %s", version()) + ltndLog.Infof("Version: %s, build=%s, logging=%s", + build.Version(), build.Deployment, build.LoggingType) var network string switch { diff --git a/rpcserver.go b/rpcserver.go index 24984c4f..85043408 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -24,6 +24,7 @@ import ( "github.com/btcsuite/btcwallet/waddrmgr" "github.com/coreos/bbolt" "github.com/davecgh/go-spew/spew" + "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/lnrpc" @@ -1364,7 +1365,7 @@ func (r *rpcServer) GetInfo(ctx context.Context, Uris: uris, Alias: nodeAnn.Alias.String(), BestHeaderTimestamp: int64(bestHeaderTimestamp), - Version: version(), + Version: build.Version(), }, nil } From ecc5d267e31cb692b79e95136bb8ff1fc4824291 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 20 Sep 2018 03:24:07 -0700 Subject: [PATCH 14/20] Makefile: use git describe for better commit versions --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2c7b4aa2..8fbd18bb 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,8 @@ HAVE_LINTER := $(shell command -v $(LINT_BIN) 2> /dev/null) BTCD_DIR :=${GOPATH}/src/$(BTCD_PKG) -COMMIT := $(shell git rev-parse HEAD) -LDFLAGS := -ldflags "-X main.Commit=$(COMMIT)" +COMMIT := $(shell git describe --abbrev=40 --dirty --broken) +LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT)" GLIDE_COMMIT := 84607742b10f492430762d038e954236bbaf23f7 BTCD_COMMIT := $(shell cat Gopkg.toml | \ From a98cdfd8976e83cabbc86c829d83729bb624d60a Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 26 Sep 2018 02:43:05 -0700 Subject: [PATCH 15/20] config_debug: remove in favor of build.Deployment --- config_debug.go | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 config_debug.go diff --git a/config_debug.go b/config_debug.go deleted file mode 100644 index 6c9fd714..00000000 --- a/config_debug.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build debug - -package main - -// DebugBuild signals that this is a debug build. -const DebugBuild = true From 5706c12d6932dea674f04bdb599d3d7449d0478f Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 26 Sep 2018 02:43:28 -0700 Subject: [PATCH 16/20] config_production: remove in favor of build.Deployment --- config_production.go | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 config_production.go diff --git a/config_production.go b/config_production.go deleted file mode 100644 index 59b986bf..00000000 --- a/config_production.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build !debug - -package main - -// DebugBuild signals that this is a debug build. -const DebugBuild = false From 2e489fcf24c1b4ea8eff4aa0087c514c5fc19cb7 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 26 Sep 2018 02:43:46 -0700 Subject: [PATCH 17/20] rpcserver: replace DebugBuild cmp w/ IsDevBuild in AbandonChannel --- rpcserver.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 85043408..f3e3abfb 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1191,12 +1191,12 @@ out: func (r *rpcServer) AbandonChannel(ctx context.Context, in *lnrpc.AbandonChannelRequest) (*lnrpc.AbandonChannelResponse, error) { - // If this isn't the debug build, then we won't allow the RPC to be + // If this isn't the dev build, then we won't allow the RPC to be // executed, as it's an advanced feature and won't be activated in // regular production/release builds. - if !DebugBuild { + if !build.IsDevBuild() { return nil, fmt.Errorf("AbandonChannel RPC call only " + - "available in debug builds") + "available in dev builds") } // We'll parse out the arguments to we can obtain the chanPoint of the From 57ec03564e8e18ed9f66d613ccfce27656563539 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 26 Sep 2018 02:44:25 -0700 Subject: [PATCH 18/20] make/testing_flags: add LOG_TAGS, set using log envvar The default is nolog, which prevents the unit tests in the main pkg from being active, since otherwise they would print as if they were being run like a dev build of the daemon. Users can pass in custom tags when running the Makefile by passing arguments using the log variable, e.g. log="xxxxx xxx"". --- make/testing_flags.mk | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/make/testing_flags.mk b/make/testing_flags.mk index 1b8114f8..e232b39b 100644 --- a/make/testing_flags.mk +++ b/make/testing_flags.mk @@ -21,6 +21,14 @@ ifneq ($(icase),) TEST_FLAGS += -test.run=TestLightningNetworkDaemon/$(icase) endif +# Define the log tags that will be applied only when running unit tests. If none +# are provided, we default to "nolog" which will be silent. +ifneq ($(log),) +LOG_TAGS := ${log} +else +LOG_TAGS := nolog +endif + # If a timeout was requested, construct initialize the proper flag for the go # test command. If not, we set 20m (up from the default 10m). ifneq ($(timeout),) @@ -36,12 +44,12 @@ UNIT_TARGETED ?= no # If a specific package/test case was requested, run the unit test for the # targeted case. Otherwise, default to running all tests. ifeq ($(UNIT_TARGETED), yes) -UNIT := $(GOTEST) -tags="$(DEV_TAGS)" $(TEST_FLAGS) $(UNITPKG) -UNIT_RACE := $(GOTEST) -tags="$(DEV_TAGS)" $(TEST_FLAGS) -race $(UNITPKG) +UNIT := $(GOTEST) -tags="$(DEV_TAGS) $(LOG_TAGS)" $(TEST_FLAGS) $(UNITPKG) +UNIT_RACE := $(GOTEST) -tags="$(DEV_TAGS) $(LOG_TAGS)" $(TEST_FLAGS) -race $(UNITPKG) endif ifeq ($(UNIT_TARGETED), no) -UNIT := $(GOLIST) | $(XARGS) $(GOTEST) -tags="$(DEV_TAGS)" $(TEST_FLAGS) +UNIT := $(GOLIST) | $(XARGS) $(GOTEST) -tags="$(DEV_TAGS) $(LOG_TAGS)" $(TEST_FLAGS) UNIT_RACE := $(UNIT) -race endif From 1881ccdaf2f689d5db84168f58e466da25c17c22 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 26 Sep 2018 04:31:40 -0700 Subject: [PATCH 19/20] Makefile: merge build+install tags with DEV/PROD_TAGS, trim whitespace --- Makefile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 8fbd18bb..3efde731 100644 --- a/Makefile +++ b/Makefile @@ -47,8 +47,11 @@ XARGS := xargs -L 1 include make/testing_flags.mk +DEV_TAGS := $(if ${tags},$(DEV_TAGS) ${tags},$(DEV_TAGS)) +PROD_TAGS := $(if ${tags},$(PROD_TAGS) ${tags},$(PROD_TAGS)) + COVER = for dir in $(GOLISTCOVER); do \ - $(GOTEST) -tags="$(TEST_TAGS)" \ + $(GOTEST) -tags="$(DEV_TAGS) $(LOG_TAGS)" \ -covermode=count \ -coverprofile=$$dir/profile.tmp $$dir; \ \ @@ -130,13 +133,13 @@ btcd: $(GLIDE_BIN) $(BTCD_DIR) build: @$(call print, "Building debug lnd and lncli.") - $(GOBUILD) -tags="$(TEST_TAGS) ${tags}" -o lnd-debug $(LDFLAGS) $(PKG) - $(GOBUILD) -tags="$(TEST_TAGS) ${tags}" -o lncli-debug $(LDFLAGS) $(PKG)/cmd/lncli + $(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(LDFLAGS) $(PKG) + $(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(LDFLAGS) $(PKG)/cmd/lncli install: @$(call print, "Installing lnd and lncli.") - go install -v -tags="${tags}" $(LDFLAGS) $(PKG) - go install -v -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lncli + go install -v -tags="$(PROD_TAGS)" $(LDFLAGS) $(PKG) + go install -v -tags="$(PROD_TAGS)" $(LDFLAGS) $(PKG)/cmd/lncli scratch: dep build From c2d9cb11d3628e9ec22655771355839e81bfb8d3 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 27 Sep 2018 09:53:34 -0700 Subject: [PATCH 20/20] docs/MAKEFILE: add log params to unit test targets --- docs/MAKEFILE.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/MAKEFILE.md b/docs/MAKEFILE.md index b7111b93..c7c60ecc 100644 --- a/docs/MAKEFILE.md +++ b/docs/MAKEFILE.md @@ -160,6 +160,8 @@ Arguments: - `pkg=` - `case=` - `timeout=` +- `log="stdlog[ ]"` prints logs to stdout + - `` can be `info` (default), `debug`, `trace`, `warn`, `error`, `critical`, or `off` `unit-cover` ------------ @@ -170,6 +172,8 @@ Arguments: - `pkg=` - `case=` - `timeout=` +- `log="stdlog[ ]"` prints logs to stdout + - `` can be `info` (default), `debug`, `trace`, `warn`, `error`, `critical`, or `off` Related: [`unit`](#unit) @@ -181,6 +185,8 @@ Arguments: - `pkg=` - `case=` - `timeout=` +- `log="stdlog[ ]"` prints logs to stdout + - `` can be `info` (default), `debug`, `trace`, `warn`, `error`, `critical`, or `off` Related: [`unit`](#unit)