Skip to content

Commit 1e7ddea

Browse files
authored
Merge pull request #432 from lightninglabs/accounts-prepare
litd: maintenance, code cleanup, middleware fixes
2 parents f7c74ef + 98b68a6 commit 1e7ddea

31 files changed

+1822
-243
lines changed

.github/workflows/main.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,37 @@ jobs:
171171
working-directory: ./app
172172
run: yarn
173173

174-
- name: run check
175-
run: make protos-check
174+
- name: setup go ${{ env.GO_VERSION }}
175+
uses: actions/setup-go@v2
176+
with:
177+
go-version: '${{ env.GO_VERSION }}'
176178

177179
- name: compile rpc for golang
178180
run: make rpc
179181

182+
- name: run check
183+
run: make mod-check
184+
185+
lint:
186+
name: lint
187+
runs-on: ubuntu-latest
188+
steps:
189+
- name: git checkout
190+
uses: actions/checkout@v2
191+
with:
192+
fetch-depth: 0
193+
194+
- name: setup go ${{ env.GO_VERSION }}
195+
uses: actions/setup-go@v2
196+
with:
197+
go-version: '${{ env.GO_VERSION }}'
198+
199+
- name: prepare dummy static data
200+
run: mkdir -p app/build; touch app/build/index.html
201+
202+
- name: run check
203+
run: make lint mod-check
204+
180205
unit-race:
181206
name: unit-race
182207
runs-on: ubuntu-latest

.golangci.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
run:
2+
# timeout for analysis
3+
deadline: 4m
4+
5+
build-tags:
6+
- autopilotrpc
7+
- signrpc
8+
- walletrpc
9+
- chainrpc
10+
- invoicesrpc
11+
- watchtowerrpc
12+
- neutrinorpc
13+
- peersrpc
14+
15+
linters-settings:
16+
govet:
17+
# Don't report about shadowed variables
18+
check-shadowing: false
19+
gofmt:
20+
# simplify code: gofmt with `-s` option, true by default
21+
simplify: true
22+
tagliatelle:
23+
case:
24+
rules:
25+
json: snake
26+
whitespace:
27+
multi-func: true
28+
multi-if: true
29+
gosec:
30+
excludes:
31+
- G402 # Look for bad TLS connection settings.
32+
- G306 # Poor file permissions used when writing to a new file.
33+
staticcheck:
34+
go: "1.18"
35+
checks: ["-SA1019"]
36+
37+
linters:
38+
enable:
39+
- gofmt
40+
- tagliatelle
41+
- whitespace
42+
- gosec
43+
44+
issues:
45+
exclude-rules:
46+
# Exclude gosec from running for tests so that tests with weak randomness
47+
# (math/rand) will pass the linter.
48+
- path: _test\.go
49+
linters:
50+
- gosec
51+
- path: internal/test/.*
52+
linters:
53+
- gosec
54+
# Fix false positives because of build flags in itest directory.
55+
- path: itest/.*
56+
linters:
57+
- unused
58+
- deadcode
59+
- varcheck

Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ COPY --from=nodejsbuilder /go/src/github.com/lightninglabs/lightning-terminal /g
4545
# queries required to connect to linked containers succeed.
4646
ENV GODEBUG netdns=cgo
4747

48-
# Explicitly turn on the use of modules (until this becomes the default).
49-
ENV GO111MODULE on
50-
5148
# Install dependencies and install/build lightning-terminal.
5249
RUN apk add --no-cache --update alpine-sdk \
5350
make \

Makefile

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ LOOP_PKG := github.com/lightninglabs/loop
55
POOL_PKG := github.com/lightninglabs/pool
66
BTCD_PKG := github.com/btcsuite/btcd
77

8-
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
9-
GOVERALLS_PKG := github.com/mattn/goveralls
108
GOACC_PKG := github.com/ory/go-acc
9+
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
10+
TOOLS_DIR := tools
1111

1212
GO_BIN := ${GOPATH}/bin
13-
GOVERALLS_BIN := $(GO_BIN)/goveralls
14-
LINT_BIN := $(GO_BIN)/golangci-lint
1513
GOACC_BIN := $(GO_BIN)/go-acc
14+
GOIMPORTS_BIN := $(GO_BIN)/gosimports
1615

1716
COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
1817
COMMIT_HASH := $(shell git rev-parse HEAD)
@@ -30,16 +29,12 @@ POOL_COMMIT := $(shell cat go.mod | \
3029
awk -F " " '{ print $$2 }' | \
3130
awk -F "/" '{ print $$1 }')
3231

33-
LINT_COMMIT := v1.18.0
34-
GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5
32+
GOBUILD := go build -v
33+
GOINSTALL := go install -v
34+
GOTEST := go test -v
35+
GOMOD := go mod
3536

36-
DEPGET := cd /tmp && GO111MODULE=on go get -v
37-
GOBUILD := GO111MODULE=on go build -v
38-
GOINSTALL := GO111MODULE=on go install -v
39-
GOTEST := GO111MODULE=on go test -v
40-
GOMOD := GO111MODULE=on go mod
41-
42-
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
37+
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -name "*pb.go" -not -name "*pb.gw.go" -not -name "*.pb.json.go")
4338
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
4439
GOLISTCOVER := $(shell go list -deps -f '{{.ImportPath}}' ./... | grep '$(PKG)' | sed -e 's/^$(ESCPKG)/./')
4540

@@ -54,6 +49,7 @@ UNIT := $(GOLIST) | $(XARGS) env $(GOTEST)
5449
UNIT_RACE := $(UNIT) -race
5550

5651
include make/release_flags.mk
52+
include make/testing_flags.mk
5753

5854
# We only return the part inside the double quote here to avoid escape issues
5955
# when calling the external release script. The second parameter can be used to
@@ -73,6 +69,14 @@ LDFLAGS := $(call make_ldflags, $(LND_RELEASE_TAGS))
7369
# and omit the DWARF symbol table (-w). Also we clear the build ID.
7470
RELEASE_LDFLAGS := $(call make_ldflags, $(LND_RELEASE_TAGS), -s -w -buildid=)
7571

72+
# Linting uses a lot of memory, so keep it under control by limiting the number
73+
# of workers if requested.
74+
ifneq ($(workers),)
75+
LINT_WORKERS = --concurrency=$(workers)
76+
endif
77+
78+
DOCKER_TOOLS = docker run -v $$(pwd):/build litd-tools
79+
7680
ITEST_TAGS := rpctest itest $(LND_RELEASE_TAGS)
7781
ITEST_LDFLAGS := $(call make_ldflags, $(ITEST_TAGS))
7882

@@ -90,17 +94,13 @@ all: scratch check install
9094
# DEPENDENCIES
9195
# ============
9296

93-
$(GOVERALLS_BIN):
94-
@$(call print, "Fetching goveralls.")
95-
go get -u $(GOVERALLS_PKG)
96-
97-
$(LINT_BIN):
98-
@$(call print, "Fetching linter")
99-
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
100-
10197
$(GOACC_BIN):
102-
@$(call print, "Fetching go-acc")
103-
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
98+
@$(call print, "Installing go-acc.")
99+
cd $(TOOLS_DIR); go install -trimpath -tags=tools $(GOACC_PKG)
100+
101+
$(GOIMPORTS_BIN):
102+
@$(call print, "Installing goimports.")
103+
cd $(TOOLS_DIR); go install -trimpath $(GOIMPORTS_PKG)
104104

105105
yarn-install:
106106
@$(call print, "Installing app dependencies with yarn")
@@ -138,6 +138,10 @@ release: app-build
138138
@$(call print, "Creating release of lightning-terminal.")
139139
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(LND_RELEASE_TAGS)" "$(RELEASE_LDFLAGS)"
140140

141+
docker-tools:
142+
@$(call print, "Building tools docker image.")
143+
docker build -q -t litd-tools $(TOOLS_DIR)
144+
141145
scratch: build
142146

143147
# =======
@@ -160,16 +164,6 @@ unit-race:
160164
mkdir -p app/build && touch app/build/index.html
161165
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE) -tags="$(LND_RELEASE_TAGS)"
162166

163-
goveralls: $(GOVERALLS_BIN)
164-
@$(call print, "Sending coverage report.")
165-
$(GOVERALLS_BIN) -coverprofile=coverage.txt -service=travis-ci
166-
167-
travis-race: lint unit-race
168-
169-
travis-cover: lint unit-cover goveralls
170-
171-
travis-itest: lint
172-
173167
build-itest: app-build
174168
@$(call print, "Building itest btcd and litd.")
175169
CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" -o itest/btcd-itest -ldflags "$(ITEST_LDFLAGS)" $(BTCD_PKG)
@@ -196,13 +190,15 @@ flake-unit:
196190
# =========
197191
# UTILITIES
198192
# =========
199-
fmt:
193+
fmt: $(GOIMPORTS_BIN)
194+
@$(call print, "Fixing imports.")
195+
gosimports -w $(GOFILES_NOVENDOR)
200196
@$(call print, "Formatting source.")
201197
gofmt -l -w -s $(GOFILES_NOVENDOR)
202198

203-
lint: $(LINT_BIN)
199+
lint: docker-tools
204200
@$(call print, "Linting source.")
205-
$(LINT)
201+
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
206202

207203
mod:
208204
@$(call print, "Tidying modules.")
@@ -230,9 +226,10 @@ protos:
230226

231227
protos-check: protos
232228
@$(call print, "Verifying compiled protos.")
233-
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
229+
if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with correct version"; git status; git diff; exit 1; fi
234230

235231
clean:
236232
@$(call print, "Cleaning source.$(NC)")
237-
$(RM) ./lightning-terminal-debug
233+
$(RM) ./litcli-debug
234+
$(RM) ./litd-debug
238235
$(RM) coverage.txt

cmd/litcli/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99

1010
terminal "github.com/lightninglabs/lightning-terminal"
11-
"github.com/lightninglabs/lightning-terminal/litrpc"
1211
"github.com/lightninglabs/lndclient"
1312
"github.com/lightninglabs/protobuf-hex-display/jsonpb"
1413
"github.com/lightninglabs/protobuf-hex-display/proto"
@@ -97,7 +96,7 @@ func fatal(err error) {
9796
os.Exit(1)
9897
}
9998

100-
func getClient(ctx *cli.Context) (litrpc.SessionsClient, func(), error) {
99+
func connectClient(ctx *cli.Context) (grpc.ClientConnInterface, func(), error) {
101100
rpcServer := ctx.GlobalString("rpcserver")
102101
tlsCertPath, macPath, err := extractPathArgs(ctx)
103102
if err != nil {
@@ -109,8 +108,7 @@ func getClient(ctx *cli.Context) (litrpc.SessionsClient, func(), error) {
109108
}
110109
cleanup := func() { _ = conn.Close() }
111110

112-
sessionsClient := litrpc.NewSessionsClient(conn)
113-
return sessionsClient, cleanup, nil
111+
return conn, cleanup, nil
114112
}
115113

116114
func getClientConn(address, tlsCertPath, macaroonPath string) (*grpc.ClientConn,

cmd/litcli/sessions.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ var addSessionCommand = cli.Command{
6969
}
7070

7171
func addSession(ctx *cli.Context) error {
72-
client, cleanup, err := getClient(ctx)
72+
clientConn, cleanup, err := connectClient(ctx)
7373
if err != nil {
7474
return err
7575
}
7676
defer cleanup()
77+
client := litrpc.NewSessionsClient(clientConn)
7778

7879
label := ctx.String("label")
7980
if label == "" {
@@ -192,11 +193,12 @@ var sessionStateMap = map[litrpc.SessionState]sessionFilter{
192193

193194
func listSessions(filter sessionFilter) func(ctx *cli.Context) error {
194195
return func(ctx *cli.Context) error {
195-
client, cleanup, err := getClient(ctx)
196+
clientConn, cleanup, err := connectClient(ctx)
196197
if err != nil {
197198
return err
198199
}
199200
defer cleanup()
201+
client := litrpc.NewSessionsClient(clientConn)
200202

201203
ctxb := context.Background()
202204
resp, err := client.ListSessions(
@@ -240,11 +242,12 @@ var revokeSessionCommand = cli.Command{
240242
}
241243

242244
func revokeSession(ctx *cli.Context) error {
243-
client, cleanup, err := getClient(ctx)
245+
clientConn, cleanup, err := connectClient(ctx)
244246
if err != nil {
245247
return err
246248
}
247249
defer cleanup()
250+
client := litrpc.NewSessionsClient(clientConn)
248251

249252
pubkey, err := hex.DecodeString(ctx.String("localpubkey"))
250253
if err != nil {

cmd/litd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77

88
"github.com/jessevdk/go-flags"
9-
"github.com/lightninglabs/lightning-terminal"
9+
terminal "github.com/lightninglabs/lightning-terminal"
1010
)
1111

1212
// main starts the lightning-terminal application.

config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,12 @@ func buildTLSConfigForHttp2(config *Config) (*tls.Config, error) {
758758
log.Infof("Listening for Let's Encrypt challenges on "+
759759
"%v", config.LetsEncryptListen)
760760

761-
err := http.ListenAndServe(
762-
config.LetsEncryptListen,
763-
manager.HTTPHandler(nil),
764-
)
761+
srv := &http.Server{
762+
Addr: config.LetsEncryptListen,
763+
ReadHeaderTimeout: 3 * time.Second,
764+
Handler: manager.HTTPHandler(nil),
765+
}
766+
err := srv.ListenAndServe()
765767
if err != nil {
766768
log.Errorf("Error starting Let's Encrypt "+
767769
"HTTP listener on port 80: %v", err)

deps.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build deps
2+
// +build deps
3+
4+
package terminal
5+
6+
// This is a workaround to make sure go mod keeps around the dependencies in the
7+
// go.sum file that we only use during compilation of the CLI binaries that are
8+
// delivered together with LiT.
9+
import (
10+
_ "github.com/lightninglabs/faraday/cmd/frcli"
11+
_ "github.com/lightninglabs/loop/cmd/loop"
12+
_ "github.com/lightninglabs/pool/cmd/pool"
13+
_ "github.com/lightningnetwork/lnd/cmd/lncli"
14+
)

dev.Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ COPY --from=nodejsbuilder /go/src/github.com/lightninglabs/lightning-terminal /g
2323
# queries required to connect to linked containers succeed.
2424
ENV GODEBUG netdns=cgo
2525

26-
# Explicitly turn on the use of modules (until this becomes the default).
27-
ENV GO111MODULE on
28-
2926
# Install dependencies and install/build lightning-terminal.
3027
RUN apk add --no-cache --update alpine-sdk \
3128
make \

0 commit comments

Comments
 (0)