From 9d1e1db42ef96a85ae91696f3297043b9ac4634b Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 24 Jan 2019 14:28:25 +0100 Subject: [PATCH 1/3] lnd: move main method to cmd/lnd/main.go --- cmd/lnd/main.go | 21 +++++++++++++++++++++ lnd.go | 25 +++++++------------------ 2 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 cmd/lnd/main.go diff --git a/cmd/lnd/main.go b/cmd/lnd/main.go new file mode 100644 index 00000000..177fb67d --- /dev/null +++ b/cmd/lnd/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "os" + + flags "github.com/jessevdk/go-flags" + "github.com/lightningnetwork/lnd" +) + +func main() { + // Call the "real" main in a nested manner so the defers will properly + // be executed in the case of a graceful shutdown. + if err := lnd.Main(); err != nil { + if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp { + } else { + fmt.Fprintln(os.Stderr, err) + } + os.Exit(1) + } +} diff --git a/lnd.go b/lnd.go index c3b40179..318ac3ef 100644 --- a/lnd.go +++ b/lnd.go @@ -18,7 +18,6 @@ import ( "math/big" "net" "net/http" - _ "net/http/pprof" "os" "path/filepath" "runtime/pprof" @@ -26,6 +25,9 @@ import ( "sync" "time" + // Blank import to set up profiling HTTP handlers. + _ "net/http/pprof" + "gopkg.in/macaroon-bakery.v2/bakery" "golang.org/x/net/context" @@ -36,7 +38,6 @@ import ( "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcwallet/wallet" proxy "github.com/grpc-ecosystem/grpc-gateway/runtime" - flags "github.com/jessevdk/go-flags" "github.com/lightninglabs/neutrino" "github.com/lightningnetwork/lnd/autopilot" @@ -89,10 +90,10 @@ var ( } ) -// lndMain is the true entry point for lnd. This function is required since -// defers created in the top-level scope of a main method aren't executed if -// os.Exit() is called. -func lndMain() error { +// Main is the true entry point for lnd. This function is required since defers +// created in the top-level scope of a main method aren't executed if os.Exit() +// is called. +func Main() error { // Load the configuration, and parse any command line options. This // function will also set up logging properly. loadedConfig, err := loadConfig() @@ -468,18 +469,6 @@ func getTLSConfig(cfg *config) (*tls.Config, *credentials.TransportCredentials, return tlsCfg, &restCreds, restProxyDest, nil } -func main() { - // Call the "real" main in a nested manner so the defers will properly - // be executed in the case of a graceful shutdown. - if err := lndMain(); err != nil { - if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp { - } else { - fmt.Fprintln(os.Stderr, err) - } - os.Exit(1) - } -} - // fileExists reports whether the named file or directory exists. // This function is taken from https://github.com/btcsuite/btcd func fileExists(name string) bool { From b53899c43caa3697b553c6f11b361e1eff65aade Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 24 Jan 2019 14:28:25 +0100 Subject: [PATCH 2/3] lnd: rename package main->lnd --- breacharbiter.go | 2 +- breacharbiter_test.go | 2 +- chainparams.go | 2 +- chainregistry.go | 2 +- chancloser.go | 2 +- channel_notifier.go | 2 +- chanrestore.go | 2 +- config.go | 2 +- doc.go | 2 +- fundingmanager.go | 2 +- fundingmanager_test.go | 2 +- lnd.go | 2 +- lnd_test.go | 2 +- log.go | 2 +- mock.go | 2 +- nursery_store.go | 2 +- nursery_store_test.go | 2 +- peer.go | 2 +- peer_test.go | 2 +- pilot.go | 2 +- rpcserver.go | 2 +- server.go | 2 +- server_test.go | 2 +- subrpcserver_config.go | 2 +- test_utils.go | 2 +- utxonursery.go | 2 +- utxonursery_test.go | 2 +- witness_beacon.go | 2 +- 28 files changed, 28 insertions(+), 28 deletions(-) diff --git a/breacharbiter.go b/breacharbiter.go index be5e1b36..33dd0fd8 100644 --- a/breacharbiter.go +++ b/breacharbiter.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/breacharbiter_test.go b/breacharbiter_test.go index b3ae1693..8be6e992 100644 --- a/breacharbiter_test.go +++ b/breacharbiter_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import ( "bytes" diff --git a/chainparams.go b/chainparams.go index 2d65d68a..8313c6cf 100644 --- a/chainparams.go +++ b/chainparams.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "github.com/btcsuite/btcd/chaincfg" diff --git a/chainregistry.go b/chainregistry.go index 71137e6a..e50e9c69 100644 --- a/chainregistry.go +++ b/chainregistry.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "encoding/hex" diff --git a/chancloser.go b/chancloser.go index 86361569..be8395ce 100644 --- a/chancloser.go +++ b/chancloser.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/channel_notifier.go b/channel_notifier.go index c85f94e2..36a2224a 100644 --- a/channel_notifier.go +++ b/channel_notifier.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/chanrestore.go b/chanrestore.go index bb1ba680..cf3bdf5b 100644 --- a/chanrestore.go +++ b/chanrestore.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/config.go b/config.go index 0c079585..63f475b0 100644 --- a/config.go +++ b/config.go @@ -2,7 +2,7 @@ // Copyright (c) 2015-2016 The Decred developers // Copyright (C) 2015-2017 The Lightning Network Developers -package main +package lnd import ( "errors" diff --git a/doc.go b/doc.go index 06ab7d0f..4e2eb511 100644 --- a/doc.go +++ b/doc.go @@ -1 +1 @@ -package main +package lnd diff --git a/fundingmanager.go b/fundingmanager.go index 6a7e642c..bc272312 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/fundingmanager_test.go b/fundingmanager_test.go index 08e0b557..75ba4eaa 100644 --- a/fundingmanager_test.go +++ b/fundingmanager_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import ( "errors" diff --git a/lnd.go b/lnd.go index 318ac3ef..41d6a49e 100644 --- a/lnd.go +++ b/lnd.go @@ -2,7 +2,7 @@ // Copyright (c) 2015-2016 The Decred developers // Copyright (C) 2015-2017 The Lightning Network Developers -package main +package lnd import ( "bytes" diff --git a/lnd_test.go b/lnd_test.go index 0fe7a83d..a7eeebbd 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -1,6 +1,6 @@ // +build rpctest -package main +package lnd import ( "bytes" diff --git a/log.go b/log.go index 37afa0bc..8ddb7f6d 100644 --- a/log.go +++ b/log.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/mock.go b/mock.go index 6c1f3fb6..10e077c5 100644 --- a/mock.go +++ b/mock.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/nursery_store.go b/nursery_store.go index eec8e74a..d7f30d07 100644 --- a/nursery_store.go +++ b/nursery_store.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/nursery_store_test.go b/nursery_store_test.go index 0c205958..af5e0a06 100644 --- a/nursery_store_test.go +++ b/nursery_store_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import ( "io/ioutil" diff --git a/peer.go b/peer.go index e227d141..d7fcf2e1 100644 --- a/peer.go +++ b/peer.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/peer_test.go b/peer_test.go index 61251cd1..9db7e7f3 100644 --- a/peer_test.go +++ b/peer_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import ( "testing" diff --git a/pilot.go b/pilot.go index 8a5cdd5a..b8f3831a 100644 --- a/pilot.go +++ b/pilot.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "errors" diff --git a/rpcserver.go b/rpcserver.go index 1c8e2fb7..38280d3e 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/server.go b/server.go index 50b8fd9e..083ae07c 100644 --- a/server.go +++ b/server.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/server_test.go b/server_test.go index 93ad3b68..ad2c0413 100644 --- a/server_test.go +++ b/server_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import "testing" diff --git a/subrpcserver_config.go b/subrpcserver_config.go index c697b03e..4ba01552 100644 --- a/subrpcserver_config.go +++ b/subrpcserver_config.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "fmt" diff --git a/test_utils.go b/test_utils.go index 9b30c300..8d1fc3d1 100644 --- a/test_utils.go +++ b/test_utils.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/utxonursery.go b/utxonursery.go index 36b97815..a95adcb9 100644 --- a/utxonursery.go +++ b/utxonursery.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "bytes" diff --git a/utxonursery_test.go b/utxonursery_test.go index b300e4ad..05be1a0a 100644 --- a/utxonursery_test.go +++ b/utxonursery_test.go @@ -1,6 +1,6 @@ // +build !rpctest -package main +package lnd import ( "bytes" diff --git a/witness_beacon.go b/witness_beacon.go index 1d368c58..82835226 100644 --- a/witness_beacon.go +++ b/witness_beacon.go @@ -1,4 +1,4 @@ -package main +package lnd import ( "sync" From ccff4fc0a54c00fa17f9b77d164db6fa20ffce13 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 24 Jan 2019 14:28:26 +0100 Subject: [PATCH 3/3] make: point makefile to new main package --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0c0d3de9..79b7e04f 100644 --- a/Makefile +++ b/Makefile @@ -92,17 +92,17 @@ btcd: build: @$(call print, "Building debug lnd and lncli.") - $(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(LDFLAGS) $(PKG) + $(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(LDFLAGS) $(PKG)/cmd/lnd $(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(LDFLAGS) $(PKG)/cmd/lncli build-itest: @$(call print, "Building itest lnd and lncli.") - $(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(LDFLAGS) $(PKG) + $(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(LDFLAGS) $(PKG)/cmd/lnd $(GOBUILD) -tags="$(ITEST_TAGS)" -o lncli-itest $(LDFLAGS) $(PKG)/cmd/lncli install: @$(call print, "Installing lnd and lncli.") - $(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG) + $(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lnd $(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lncli scratch: build