Skip to content

Commit 5db443b

Browse files
authored
Merge pull request #27 from guggero/grub
Grand unified binary
2 parents e88a9bf + 1d07f41 commit 5db443b

20 files changed

+1884
-293
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
app/build
2+
app/coverage
3+
app/node_modules
4+
shushtar-debug

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ https.cert
33
https.key
44

55
# local environment vars to ignore
6-
.env*.local
6+
.env*.local
7+
8+
shushtar-debug
9+
/shushtar-*
10+
11+
# go code generated by statik
12+
/statik/statik.go

Dockerfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
FROM golang:1.13-alpine as builder
2+
3+
# Copy in the local repository to build from.
4+
COPY . /go/src/github.com/lightninglabs/shushtar
5+
6+
# Force Go to use the cgo based DNS resolver. This is required to ensure DNS
7+
# queries required to connect to linked containers succeed.
8+
ENV GODEBUG netdns=cgo
9+
10+
# Explicitly turn on the use of modules (until this becomes the default).
11+
ENV GO111MODULE on
12+
13+
ENV NODE_VERSION=v12.17.0
14+
15+
# Install dependencies and install/build shushtar.
16+
RUN apk add --no-cache --update alpine-sdk \
17+
git \
18+
make \
19+
curl \
20+
bash \
21+
binutils \
22+
tar \
23+
&& touch ~/.bashrc \
24+
&& curl -sfSLO https://unofficial-builds.nodejs.org/download/release/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64-musl.tar.xz \
25+
&& tar -xf node-${NODE_VERSION}-linux-x64-musl.tar.xz -C /usr --strip 1 \
26+
&& rm node-${NODE_VERSION}-linux-x64-musl.tar.xz \
27+
&& curl -o- -L https://yarnpkg.com/install.sh | bash \
28+
&& /bin/bash \
29+
&& . ~/.bashrc \
30+
&& cd /go/src/github.com/lightninglabs/shushtar \
31+
&& make install \
32+
&& go install -v -trimpath github.com/lightningnetwork/lnd/cmd/lncli \
33+
&& go install -v -trimpath github.com/lightninglabs/faraday/cmd/frcli \
34+
&& go install -v -trimpath github.com/lightninglabs/loop/cmd/loop
35+
36+
# Start a new, final image to reduce size.
37+
FROM alpine as final
38+
39+
# Define a root volume for data persistence.
40+
VOLUME /root/.lnd
41+
42+
# Expose shushtar and lnd ports (server, rpc).
43+
EXPOSE 8443 10009 9735
44+
45+
# Copy the binaries and entrypoint from the builder image.
46+
COPY --from=builder /go/bin/shushtar /bin/
47+
COPY --from=builder /go/bin/lncli /bin/
48+
COPY --from=builder /go/bin/frcli /bin/
49+
COPY --from=builder /go/bin/loop /bin/
50+
51+
# Add bash.
52+
RUN apk add --no-cache \
53+
bash \
54+
jq \
55+
ca-certificates
56+
57+
# Specify the start command and entrypoint as the shushtar daemon.
58+
ENTRYPOINT ["shushtar"]

Makefile

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
PKG := github.com/lightninglabs/shushtar
2+
ESCPKG := github.com\/lightninglabs\/shushtar
3+
LND_PKG := github.com/lightningnetwork/lnd
4+
5+
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
6+
GOVERALLS_PKG := github.com/mattn/goveralls
7+
GOACC_PKG := github.com/ory/go-acc
8+
STATIK_PKG := github.com/rakyll/statik
9+
10+
GO_BIN := ${GOPATH}/bin
11+
GOVERALLS_BIN := $(GO_BIN)/goveralls
12+
LINT_BIN := $(GO_BIN)/golangci-lint
13+
GOACC_BIN := $(GO_BIN)/go-acc
14+
STATIK_BIN := $(GO_BIN)/statik
15+
16+
COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
17+
18+
LINT_COMMIT := v1.18.0
19+
GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5
20+
21+
DEPGET := cd /tmp && GO111MODULE=on go get -v
22+
GOBUILD := GO111MODULE=on go build -v
23+
GOINSTALL := GO111MODULE=on go install -v
24+
GOTEST := GO111MODULE=on go test -v
25+
GOMOD := GO111MODULE=on go mod
26+
27+
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
28+
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
29+
GOLISTCOVER := $(shell go list -deps -f '{{.ImportPath}}' ./... | grep '$(PKG)' | sed -e 's/^$(ESCPKG)/./')
30+
31+
RM := rm -f
32+
CP := cp
33+
MAKE := make
34+
XARGS := xargs -L 1
35+
36+
LINT = $(LINT_BIN) run -v
37+
38+
include make/release_flags.mk
39+
40+
# We only return the part inside the double quote here to avoid escape issues
41+
# when calling the external release script. The second parameter can be used to
42+
# add additional ldflags if needed (currently only used for the release).
43+
make_ldflags = $(2) -X $(LND_PKG)/build.Commit=$(COMMIT) \
44+
-X $(LND_PKG)/build.CommitHash=$(COMMIT_HASH) \
45+
-X $(LND_PKG)/build.GoVersion=$(GOVERSION) \
46+
-X $(LND_PKG)/build.RawTags=$(shell echo $(1) | sed -e 's/ /,/g')
47+
48+
LDFLAGS := $(call make_ldflags, $(LND_RELEASE_TAGS))
49+
50+
# For the release, we want to remove the symbol table and debug information (-s)
51+
# and omit the DWARF symbol table (-w). Also we clear the build ID.
52+
RELEASE_LDFLAGS := $(call make_ldflags, $(LND_RELEASE_TAGS), -s -w -buildid=)
53+
54+
GREEN := "\\033[0;32m"
55+
NC := "\\033[0m"
56+
define print
57+
echo $(GREEN)$1$(NC)
58+
endef
59+
60+
default: scratch
61+
62+
all: scratch check install
63+
64+
# ============
65+
# DEPENDENCIES
66+
# ============
67+
68+
$(GOVERALLS_BIN):
69+
@$(call print, "Fetching goveralls.")
70+
go get -u $(GOVERALLS_PKG)
71+
72+
$(LINT_BIN):
73+
@$(call print, "Fetching linter")
74+
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
75+
76+
$(GOACC_BIN):
77+
@$(call print, "Fetching go-acc")
78+
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
79+
80+
$(STATIK_BIN):
81+
@$(call print, "Fetching statik")
82+
$(DEPGET) $(STATIK_PKG)
83+
84+
yarn-install:
85+
@$(call print, "Installing app dependencies with yarn")
86+
cd app; yarn
87+
88+
# ============
89+
# INSTALLATION
90+
# ============
91+
statik-build: $(STATIK_BIN) app-build
92+
@$(call print, "Building statik package.")
93+
statik -src=app/build
94+
95+
build: statik-build go-build
96+
install: statik-build go-install
97+
98+
go-build:
99+
@$(call print, "Building shushtar.")
100+
$(GOBUILD) -tags="$(LND_RELEASE_TAGS)" -ldflags "$(LDFLAGS)" -o shushtar-debug $(PKG)/cmd/shushtar
101+
102+
go-install:
103+
@$(call print, "Installing shushtar.")
104+
$(GOINSTALL) -tags="$(LND_RELEASE_TAGS)" -ldflags "$(LDFLAGS)" $(PKG)/cmd/shushtar
105+
106+
app-build: yarn-install
107+
@$(call print, "Building production app.")
108+
cd app; yarn build
109+
110+
release: statik-build
111+
@$(call print, "Creating release of shushtar.")
112+
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(LND_RELEASE_TAGS)" "$(RELEASE_LDFLAGS)"
113+
114+
scratch: build
115+
116+
# =======
117+
# TESTING
118+
# =======
119+
120+
check: unit
121+
122+
unit:
123+
@$(call print, "Running unit tests.")
124+
$(UNIT)
125+
126+
unit-cover: $(GOACC_BIN)
127+
@$(call print, "Running unit coverage tests.")
128+
$(GOACC_BIN) $(COVER_PKG)
129+
130+
unit-race:
131+
@$(call print, "Running unit race tests.")
132+
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE)
133+
134+
goveralls: $(GOVERALLS_BIN)
135+
@$(call print, "Sending coverage report.")
136+
$(GOVERALLS_BIN) -coverprofile=coverage.txt -service=travis-ci
137+
138+
travis-race: lint unit-race
139+
140+
travis-cover: lint unit-cover goveralls
141+
142+
travis-itest: lint
143+
144+
145+
# =============
146+
# FLAKE HUNTING
147+
# =============
148+
flake-unit:
149+
@$(call print, "Flake hunting unit tests.")
150+
while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done
151+
152+
# =========
153+
# UTILITIES
154+
# =========
155+
fmt:
156+
@$(call print, "Formatting source.")
157+
gofmt -l -w -s $(GOFILES_NOVENDOR)
158+
159+
lint: $(LINT_BIN)
160+
@$(call print, "Linting source.")
161+
$(LINT)
162+
163+
mod:
164+
@$(call print, "Tidying modules.")
165+
$(GOMOD) tidy
166+
167+
mod-check:
168+
@$(call print, "Checking modules.")
169+
$(GOMOD) tidy
170+
if test -n "$$(git status | grep -e "go.mod\|go.sum")"; then echo "Running go mod tidy changes go.mod/go.sum"; git status; git diff; exit 1; fi
171+
172+
list:
173+
@$(call print, "Listing commands.")
174+
@$(MAKE) -qp | \
175+
awk -F':' '/^[a-zA-Z0-9][^$$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)print A[i]}' | \
176+
grep -v Makefile | \
177+
sort
178+
179+
clean:
180+
@$(call print, "Cleaning source.$(NC)")
181+
$(RM) ./shushtar-debug
182+
$(RM) coverage.txt
183+
$(RM) -r statik

README.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ Requirements: [Go](https://golang.org/doc/install), [protoc](https://github.com/
66

77
## One-time Setup
88

9-
Create certificate for browser to backend proxy communication
10-
11-
```
12-
openssl genrsa -out https.key 2048
13-
openssl req -new -x509 -key https.key -out https.cert -days 365
14-
```
15-
169
Install client app dependencies
1710

1811
```sh
@@ -23,16 +16,7 @@ yarn
2316

2417
## Development
2518

26-
- Spin up a local regtest env with nautilus and loopd (See [docker-regtest](https://github.com/lightninglabs/dev-resources/tree/master/docker-regtest))
27-
- Create a `.env.local` file in the `app/` directory with the following content. Replace `<macaroon>` with the HEX encoded admin.macaroon of the LND node to connect to
28-
```
29-
REACT_APP_DEV_MACAROON=<macaroon>
30-
REACT_APP_DEV_HOST=http://localhost:3000
31-
```
32-
- Start backend server, updating the ports for the LND and Loop nodes if necessary
33-
```sh
34-
go run . --lndhost=localhost:10011 --loophost=localhost:11010
35-
```
19+
- Compile and start the GrUB (see [Run the GrUB](#run-the-grub))
3620
- Run the client app in a separate terminal
3721
```sh
3822
cd app
@@ -79,3 +63,33 @@ The value for `debug` is a namespace filter which determines which portions of t
7963
Example filters: `main,action` will only log main and action messages. `*,-action` will log everything except action messages.
8064

8165
The value for `debug-level` determines the verbosity of the logs. The value can be one of `debug`, `info`, `warn`, or `error`.
66+
67+
# Run the GrUB
68+
69+
- Compile the GrUB binary:
70+
```sh
71+
make build
72+
```
73+
- Start the GrUB binary. The following is an example for testnet that starts an
74+
lnd node called `zane` on port `10020` (REST: `8100`), change this to your
75+
needs:
76+
```sh
77+
./shushtar-debug \
78+
--httpslisten=8443 \
79+
--lnd.lnddir=/home/$USER/.lnd-dev-zane \
80+
--lnd.alias=zane \
81+
--lnd.noseedbackup \
82+
--lnd.rpclisten=localhost:10020 \
83+
--lnd.listen=0.0.0.0:9750 \
84+
--lnd.restlisten=localhost:8100 \
85+
--lnd.bitcoin.active \
86+
--lnd.bitcoin.testnet \
87+
--lnd.bitcoin.node=bitcoind \
88+
--lnd.bitcoind.rpchost=localhost \
89+
--lnd.bitcoind.rpcuser=lightning \
90+
--lnd.bitcoind.rpcpass=lightning \
91+
--lnd.bitcoind.zmqpubrawblock=localhost:28332 \
92+
--lnd.bitcoind.zmqpubrawtx=localhost:28333 \
93+
--lnd.debuglevel=debug
94+
```
95+
- You can now access the web interface on https://localhost:8443

app/src/api/lnd.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import * as LND from 'types/generated/lnd_pb';
22
import { Lightning } from 'types/generated/lnd_pb_service';
3-
import { DEV_MACAROON } from 'config';
43
import GrpcClient from './grpc';
54

65
/**
76
* An API wrapper to communicate with the LND node via GRPC
87
*/
98
class LndApi {
10-
_meta = {
11-
'X-Grpc-Backend': 'lnd',
12-
macaroon: DEV_MACAROON,
13-
};
149

1510
private _grpc: GrpcClient;
1611

@@ -23,7 +18,7 @@ class LndApi {
2318
*/
2419
async getInfo(): Promise<LND.GetInfoResponse.AsObject> {
2520
const req = new LND.GetInfoRequest();
26-
const res = await this._grpc.request(Lightning.GetInfo, req, this._meta);
21+
const res = await this._grpc.request(Lightning.GetInfo, req);
2722
return res.toObject();
2823
}
2924

@@ -32,7 +27,7 @@ class LndApi {
3227
*/
3328
async channelBalance(): Promise<LND.ChannelBalanceResponse.AsObject> {
3429
const req = new LND.ChannelBalanceRequest();
35-
const res = await this._grpc.request(Lightning.ChannelBalance, req, this._meta);
30+
const res = await this._grpc.request(Lightning.ChannelBalance, req);
3631
return res.toObject();
3732
}
3833

@@ -41,7 +36,7 @@ class LndApi {
4136
*/
4237
async walletBalance(): Promise<LND.WalletBalanceResponse.AsObject> {
4338
const req = new LND.WalletBalanceRequest();
44-
const res = await this._grpc.request(Lightning.WalletBalance, req, this._meta);
39+
const res = await this._grpc.request(Lightning.WalletBalance, req);
4540
return res.toObject();
4641
}
4742

@@ -50,7 +45,7 @@ class LndApi {
5045
*/
5146
async listChannels(): Promise<LND.ListChannelsResponse.AsObject> {
5247
const req = new LND.ListChannelsRequest();
53-
const res = await this._grpc.request(Lightning.ListChannels, req, this._meta);
48+
const res = await this._grpc.request(Lightning.ListChannels, req);
5449
return res.toObject();
5550
}
5651
}

0 commit comments

Comments
 (0)