From f360ec71bfb5ed983c00913fd2639fb2f7e2182b Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 15 Jul 2020 15:05:32 +0200 Subject: [PATCH 1/7] mobile: restore config parsing for mobile bindings A recent commit moved the config parsing out of lnd's Main method. This commit makes the mobile bindings compile with this change. --- mobile/bindings.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/mobile/bindings.go b/mobile/bindings.go index 8d669ca0e..d64540b98 100644 --- a/mobile/bindings.go +++ b/mobile/bindings.go @@ -9,6 +9,7 @@ import ( flags "github.com/jessevdk/go-flags" "github.com/lightningnetwork/lnd" + "github.com/lightningnetwork/lnd/signal" ) // Start starts lnd in a new goroutine. @@ -40,10 +41,21 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) { splitArgs = append(splitArgs, "--"+a) } - // Add the extra arguments to os.Args, as that will be parsed during - // startup. + // Add the extra arguments to os.Args, as that will be parsed in + // LoadConfig below. os.Args = append(os.Args, splitArgs...) + // Load the configuration, and parse the extra arguments as command + // line options. This function will also set up logging properly. + loadedConfig, err := lnd.LoadConfig() + if err != nil { + _, _ = fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + // Hook interceptor for os signals. + signal.Intercept() + // Set up channels that will be notified when the RPC servers are ready // to accept calls. var ( @@ -67,7 +79,9 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) { // Call the "real" main in a nested manner so the defers will properly // be executed in the case of a graceful shutdown. go func() { - if err := lnd.Main(cfg); err != nil { + if err := lnd.Main( + loadedConfig, cfg, signal.ShutdownChannel(), + ); err != nil { if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp { } else { @@ -84,7 +98,7 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) { // We must set the TLS certificates in order to properly // authenticate with the wallet unlocker service. - auth, err := lnd.WalletUnlockerAuthOptions() + auth, err := lnd.WalletUnlockerAuthOptions(loadedConfig) if err != nil { unlockerReady.OnError(err) return @@ -102,7 +116,7 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) { // Now that the RPC server is ready, we can get the needed // authentication options, and add them to the global dial // options. - auth, err := lnd.AdminAuthOptions() + auth, err := lnd.AdminAuthOptions(loadedConfig) if err != nil { rpcReady.OnError(err) return From 7a30332619b484f381d0635431d885e553a278d2 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 15 Jul 2020 15:19:25 +0200 Subject: [PATCH 2/7] mobile: use single "mobile" build tag instead of "ios" and "android" Since the "android" build tag conflicts with a go compiler build tag, we instead use a single "mobile" tag for both platforms. --- Makefile | 4 ++-- mobile/bindings.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 24d15ecb1..8080d76da 100644 --- a/Makefile +++ b/Makefile @@ -224,12 +224,12 @@ vendor: ios: vendor mobile-rpc @$(call print, "Building iOS framework ($(IOS_BUILD)).") mkdir -p $(IOS_BUILD_DIR) - $(GOMOBILE_BIN) bind -target=ios -tags="ios $(DEV_TAGS) autopilotrpc experimental" $(LDFLAGS) -v -o $(IOS_BUILD) $(MOBILE_PKG) + $(GOMOBILE_BIN) bind -target=ios -tags="mobile $(DEV_TAGS) autopilotrpc experimental" $(LDFLAGS) -v -o $(IOS_BUILD) $(MOBILE_PKG) android: vendor mobile-rpc @$(call print, "Building Android library ($(ANDROID_BUILD)).") mkdir -p $(ANDROID_BUILD_DIR) - $(GOMOBILE_BIN) bind -target=android -tags="android $(DEV_TAGS) autopilotrpc experimental" $(LDFLAGS) -v -o $(ANDROID_BUILD) $(MOBILE_PKG) + $(GOMOBILE_BIN) bind -target=android -tags="mobile $(DEV_TAGS) autopilotrpc experimental" $(LDFLAGS) -v -o $(ANDROID_BUILD) $(MOBILE_PKG) mobile: ios android diff --git a/mobile/bindings.go b/mobile/bindings.go index d64540b98..fcf8c11df 100644 --- a/mobile/bindings.go +++ b/mobile/bindings.go @@ -1,4 +1,4 @@ -// +build ios android +// +build mobile package lndmobile From fd8e6c98b9cc73056f6b819d63a88520f3c565b9 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 15 Jul 2020 15:36:20 +0200 Subject: [PATCH 3/7] make: fetch falafel dependency for mobile-rpc --- Makefile | 9 ++++++++- mobile/gen_bindings.sh | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8080d76da..40f9b2326 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ BTCD_PKG := github.com/btcsuite/btcd GOVERALLS_PKG := github.com/mattn/goveralls LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint GOACC_PKG := github.com/ory/go-acc +FALAFEL_PKG := github.com/lightninglabs/falafel GO_BIN := ${GOPATH}/bin BTCD_BIN := $(GO_BIN)/btcd @@ -32,6 +33,7 @@ BTCD_COMMIT := $(shell cat go.mod | \ LINT_COMMIT := v1.18.0 GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5 +FALAFEL_COMMIT := v0.7.1 DEPGET := cd /tmp && GO111MODULE=on go get -v GOBUILD := GO111MODULE=on go build -v @@ -107,6 +109,10 @@ btcd: @$(call print, "Installing btcd.") $(DEPGET) $(BTCD_PKG)@$(BTCD_COMMIT) +falafel: + @$(call print, "Installing falafel.") + $(DEPGET) $(FALAFEL_PKG)@$(FALAFEL_COMMIT) + # ============ # INSTALLATION # ============ @@ -213,7 +219,7 @@ rpc-check: rpc for rpc in $$(find lnrpc/ -name "*.proto" | $(XARGS) awk '/ rpc /{print $$2}'); do if ! grep -q $$rpc lnrpc/rest-annotations.yaml; then echo "RPC $$rpc not added to lnrpc/rest-annotations.yaml"; exit 1; fi; done if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with v3.4.0"; git status; git diff; exit 1; fi -mobile-rpc: +mobile-rpc: falafel @$(call print, "Creating mobile RPC from protos.") cd ./mobile; ./gen_bindings.sh @@ -252,6 +258,7 @@ clean: unit \ unit-cover \ unit-race \ + falafel \ goveralls \ travis-race \ travis-cover \ diff --git a/mobile/gen_bindings.sh b/mobile/gen_bindings.sh index 8ed84460a..705646b26 100755 --- a/mobile/gen_bindings.sh +++ b/mobile/gen_bindings.sh @@ -3,7 +3,7 @@ mkdir -p build # Check falafel version. -falafelVersion="0.7" +falafelVersion="0.7.1" falafel=$(which falafel) if [ $falafel ] then From b55b7025b03fdd0652f2eee58fd4e0fa5e6a68e9 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 15 Jul 2020 15:37:02 +0200 Subject: [PATCH 4/7] travis: sanity check mobile build compilation --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index e3e8c814e..a3a1c0bcb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,8 @@ jobs: - make lint workers=1 - make btcd - make release sys=windows-amd64 + - make mobile-rpc + - go build --tags="mobile" ./mobile - stage: Test script: make travis-cover name: Unit Cover From d41ca81aad202df35af7b59793a56b543ea323cd Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 15 Jul 2020 16:36:59 +0200 Subject: [PATCH 5/7] make: add goimports dep Required by mobile bindings generate script. --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 40f9b2326..224ac28a9 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ GOVERALLS_PKG := github.com/mattn/goveralls LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint GOACC_PKG := github.com/ory/go-acc FALAFEL_PKG := github.com/lightninglabs/falafel +GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports GO_BIN := ${GOPATH}/bin BTCD_BIN := $(GO_BIN)/btcd @@ -113,6 +114,10 @@ falafel: @$(call print, "Installing falafel.") $(DEPGET) $(FALAFEL_PKG)@$(FALAFEL_COMMIT) +goimports: + @$(call print, "Installing goimports.") + $(DEPGET) $(GOIMPORTS_PKG) + # ============ # INSTALLATION # ============ @@ -219,7 +224,7 @@ rpc-check: rpc for rpc in $$(find lnrpc/ -name "*.proto" | $(XARGS) awk '/ rpc /{print $$2}'); do if ! grep -q $$rpc lnrpc/rest-annotations.yaml; then echo "RPC $$rpc not added to lnrpc/rest-annotations.yaml"; exit 1; fi; done if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with v3.4.0"; git status; git diff; exit 1; fi -mobile-rpc: falafel +mobile-rpc: falafel goimports @$(call print, "Creating mobile RPC from protos.") cd ./mobile; ./gen_bindings.sh From 39241dcdc7da3d8e700f1cb3ff822d9da5f24841 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 16 Jul 2020 12:59:07 +0200 Subject: [PATCH 6/7] mobile: use single brackets for bash if check Double brackets are sh specific. --- mobile/gen_bindings.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/gen_bindings.sh b/mobile/gen_bindings.sh index 705646b26..14cb76651 100755 --- a/mobile/gen_bindings.sh +++ b/mobile/gen_bindings.sh @@ -45,7 +45,7 @@ protoc -I/usr/local/include -I. \ # If prefix=1 is specified, prefix the generated methods with subserver name. # This must be enabled to support subservers with name conflicts. use_prefix="0" -if [[ $prefix = "1" ]] +if [ "$prefix" = "1" ] then echo "Prefixing methods with subserver name" use_prefix="1" From 935fa7f12d7a23c34122587671cc0793169e2d11 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 16 Jul 2020 13:18:57 +0200 Subject: [PATCH 7/7] make+mobile: pass expected falafel version to build script --- Makefile | 2 +- mobile/gen_bindings.sh | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 224ac28a9..e474fbe5a 100644 --- a/Makefile +++ b/Makefile @@ -226,7 +226,7 @@ rpc-check: rpc mobile-rpc: falafel goimports @$(call print, "Creating mobile RPC from protos.") - cd ./mobile; ./gen_bindings.sh + cd ./mobile; ./gen_bindings.sh $(FALAFEL_COMMIT) vendor: @$(call print, "Re-creating vendor directory.") diff --git a/mobile/gen_bindings.sh b/mobile/gen_bindings.sh index 14cb76651..2e54beaac 100755 --- a/mobile/gen_bindings.sh +++ b/mobile/gen_bindings.sh @@ -3,11 +3,17 @@ mkdir -p build # Check falafel version. -falafelVersion="0.7.1" +falafelVersion=$1 +if [ -z $falafelVersion ] +then + echo "falafel version not set" + exit 1 +fi + falafel=$(which falafel) if [ $falafel ] then - version=$($falafel -v) + version="v$($falafel -v)" if [ $version != $falafelVersion ] then echo "falafel version $falafelVersion required"