-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
245 lines (207 loc) · 9.33 KB
/
Makefile
File metadata and controls
245 lines (207 loc) · 9.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
###################################################
### Supernode Makefile
###################################################
.PHONY: release
# tools/paths
GO ?= go
RELEASE_DIR ?= release
# Build variables
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u '+%Y-%m-%d_%H:%M:%S')
# Linker flags for version information
# Optional minimum peer version for DHT gating can be provided via MIN_VER env/make var
LDFLAGS = -X github.com/LumeraProtocol/supernode/v2/supernode/cmd.Version=$(VERSION) \
-X github.com/LumeraProtocol/supernode/v2/supernode/cmd.GitCommit=$(GIT_COMMIT) \
-X github.com/LumeraProtocol/supernode/v2/supernode/cmd.BuildTime=$(BUILD_TIME) \
-X github.com/LumeraProtocol/supernode/v2/supernode/cmd.MinVer=$(MIN_VER) \
-X github.com/LumeraProtocol/supernode/v2/pkg/logtrace.DDAPIKey=$(DD_API_KEY) \
-X github.com/LumeraProtocol/supernode/v2/pkg/logtrace.DDSite=$(DD_SITE) \
-X github.com/LumeraProtocol/supernode/v2/supernode/transport/gateway.RecoveryAdminToken=$(RECOVERY_ADMIN_TOKEN)
# Linker flags for sn-manager
SN_MANAGER_LDFLAGS = -X main.Version=$(VERSION) \
-X main.GitCommit=$(GIT_COMMIT) \
-X main.BuildTime=$(BUILD_TIME)
###################################################
### Build / Release ###
###################################################
.PHONY: build build-sncli build-sn-manager release
SN_SRC := $(shell find p2p -name "*.go") \
$(shell find pkg -name "*.go") \
$(shell find sdk -name "*.go") \
$(shell find supernode -name "*.go") \
$(shell find tools -name "*.go")
go.sum: go.mod
@echo "Verifying and tidying go modules..." \
${GO} mod tidy
${GO} mod verify
build: $(SN_SRC) go.sum Makefile
@echo "Building supernode..."
@mkdir -p $(RELEASE_DIR)
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 ${GO} build \
-trimpath \
-ldflags="-s -w $(LDFLAGS)" \
-o $(RELEASE_DIR)/supernode-linux-amd64 \
./supernode
@chmod +x $(RELEASE_DIR)/supernode-linux-amd64
@echo "supernode built successfully in $(RELEASE_DIR)/supernode-linux-amd64"
build-sncli: release/sncli
SNCLI_SRC := $(wildcard cmd/sncli/*.go) \
$(wildcard cmd/sncli/**/*.go)
cmd/sncli/go.sum: cmd/sncli/go.mod
cd cmd/sncli && ${GO} mod tidy
cd cmd/sncli && ${GO} mod verify
release/sncli: $(SNCLI_SRC) cmd/sncli/go.sum
@echo "Building sncli..."
@mkdir -p $(RELEASE_DIR)
@cd cmd/sncli && \
CGO_ENABLED=1 \
GOOS=linux \
GOARCH=amd64 \
${GO} build \
-trimpath \
-ldflags="-s -w $(LDFLAGS)" \
-o ../../$(RELEASE_DIR)/sncli && \
chmod +x ../../$(RELEASE_DIR)/sncli && \
echo "sncli built successfully at $(RELEASE_DIR)/sncli"
build-sn-manager:
@echo "Building sn-manager..."
@mkdir -p $(RELEASE_DIR)
@cd sn-manager && \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
${GO} build \
-trimpath \
-ldflags="-s -w $(SN_MANAGER_LDFLAGS)" \
-o ../$(RELEASE_DIR)/sn-manager \
.
@chmod +x $(RELEASE_DIR)/sn-manager
@echo "sn-manager built successfully at $(RELEASE_DIR)/sn-manager"
# Release command: push branch, tag, and push tag with auto-increment - this is for testing only (including releases) setup a new remote upstream or rename the script
release:
@echo "Getting current branch..."
$(eval CURRENT_BRANCH := $(shell git branch --show-current))
@echo "Current branch: $(CURRENT_BRANCH)"
@echo "Getting latest tag..."
$(eval LATEST_TAG := $(shell git tag -l "v*" | sort -V | tail -n1))
$(eval NEXT_TAG := $(shell \
if [ -z "$(LATEST_TAG)" ]; then \
echo "v2.5.0"; \
else \
echo "$(LATEST_TAG)" | sed 's/^v//' | awk -F. '{print "v" $$1 "." $$2 "." $$3+1}'; \
fi))
@echo "Next tag: $(NEXT_TAG)"
@echo "Pushing branch to upstream..."
git push upstream $(CURRENT_BRANCH) -f
@echo "Creating and pushing tag $(NEXT_TAG)..."
git tag $(NEXT_TAG)
git push upstream $(NEXT_TAG)
@echo "Release complete: $(NEXT_TAG) pushed to upstream"
###################################################
### Tests and Simulation ###
###################################################
.PHONY: test-e2e test-unit test-integration test-system test-cascade test-lep6 test-sn-manager
.PHONY: install-lumera setup-supernodes setup-lep6-supernodes system-test-setup install-deps
.PHONY: gen-cascade gen-supernode audit-mod-clean lep6-reset-dedup lep6-validate-config
test-unit:
${GO} test -v ./...
test-integration:
${GO} test -v -p 1 -count=1 -tags=integration ./...
test-system:
cd tests/system && ${GO} test -tags=system_test -v .
gen-cascade:
protoc \
--proto_path=proto \
--go_out=gen \
--go_opt=paths=source_relative \
--go-grpc_out=gen \
--go-grpc_opt=paths=source_relative \
proto/supernode/action/cascade/service.proto
gen-supernode:
protoc \
--proto_path=proto \
--proto_path=$$(${GO} list -m -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway)/third_party/googleapis \
--go_out=gen \
--go_opt=paths=source_relative \
--go-grpc_out=gen \
--go-grpc_opt=paths=source_relative \
--grpc-gateway_out=gen \
--grpc-gateway_opt=paths=source_relative \
--openapiv2_out=gen \
proto/supernode/service.proto proto/supernode/status.proto proto/supernode/storage_challenge.proto proto/supernode/self_healing.proto
# Define the paths
SUPERNODE_SRC=supernode/main.go
DATA_DIR=tests/system/supernode-data1
DATA_DIR2=tests/system/supernode-data2
DATA_DIR3=tests/system/supernode-data3
LEP6_DATA_DIR=tests/system/supernode-lep6-data1
LEP6_DATA_DIR2=tests/system/supernode-lep6-data2
LEP6_DATA_DIR3=tests/system/supernode-lep6-data3
CONFIG_FILE=tests/system/config.test-1.yml
CONFIG_FILE2=tests/system/config.test-2.yml
CONFIG_FILE3=tests/system/config.test-3.yml
LEP6_CONFIG_FILE=tests/system/config.lep6-1.yml
LEP6_CONFIG_FILE2=tests/system/config.lep6-2.yml
LEP6_CONFIG_FILE3=tests/system/config.lep6-3.yml
# Setup script
SETUP_SCRIPT=tests/scripts/setup-supernodes.sh
# Install Lumera
# Optional: specify lumera binary path to skip download
LUMERAD_BINARY ?=
# Derive default Lumera version from go.mod
LUMERA_DEFAULT_VERSION := $(shell awk '/github.com\/LumeraProtocol\/lumera[[:space:]]+v/ {print $$2; exit}' go.mod)
# Optional: specify installation mode (latest-release, latest-tag, or vX.Y.Z[...])
INSTALL_MODE ?= $(if $(LUMERA_DEFAULT_VERSION),$(LUMERA_DEFAULT_VERSION),latest-release)
install-lumera:
@echo "Installing Lumera..."
@chmod +x tests/scripts/install-lumera.sh
@LUMERAD_BINARY="$(LUMERAD_BINARY)" tests/scripts/install-lumera.sh $(INSTALL_MODE)
@echo "PtTDUHythfRfXHh63yzyiGDid4TZj2P76Zd,18749999981413" > ~/claims.csv
# Setup supernode environments
setup-supernodes:
@echo "Setting up all supernode environments..."
@chmod +x $(SETUP_SCRIPT)
@bash $(SETUP_SCRIPT) all $(SUPERNODE_SRC) $(DATA_DIR) $(CONFIG_FILE) $(DATA_DIR2) $(CONFIG_FILE2) $(DATA_DIR3) $(CONFIG_FILE3)
setup-lep6-supernodes:
@echo "Setting up isolated LEP-6 supernode environments..."
@rm -rf tests/system/heal-staging
@chmod +x $(SETUP_SCRIPT)
@bash $(SETUP_SCRIPT) all $(SUPERNODE_SRC) $(LEP6_DATA_DIR) $(LEP6_CONFIG_FILE) $(LEP6_DATA_DIR2) $(LEP6_CONFIG_FILE2) $(LEP6_DATA_DIR3) $(LEP6_CONFIG_FILE3)
# Complete system test setup (Lumera + Supernodes)
system-test-setup: install-lumera setup-supernodes
@echo "System test environment setup complete."
@if [ -f claims.csv ]; then cp claims.csv ~/; echo "Copied claims.csv to home directory."; fi
# Run system tests with complete setup
test-e2e:
@echo "Running system tests..."
@cd tests/system && ${GO} test -tags=system_test -v .
# Run cascade e2e tests only
test-cascade:
@echo "Running cascade e2e tests..."
@cd tests/system && ${GO} mod tidy && ${GO} test -tags=system_test -v -run TestCascadeE2E .
# Run LEP-6 e2e tests only against the real lumerad/local-chain system harness.
# The runtime test uses isolated supernode-lep6-data* directories so per-node
# SQLite history/dedup state is not shared with Cascade fixtures or other nodes.
test-lep6: setup-lep6-supernodes
@echo "Running LEP-6 e2e tests..."
@cd tests/system && ${GO} mod tidy && ${GO} test -tags=system_test -timeout=1500s -v -run '^TestLEP6' .
# Validate LEP-6 local config/default/fixture coverage without starting a network.
lep6-validate-config:
@echo "Validating LEP-6 supernode config fixtures..."
@${GO} test ./supernode/config -run 'TestLoadConfig_LEP6|TestCreateDefaultConfig_IncludesExplicitLEP6Blocks|TestSystemConfigFixturesIncludeLEP6' -count=1
# Recover from stale Lumera module checksum/cache issues during local PR-6 work.
audit-mod-clean:
@echo "Cleaning Go module cache and re-resolving modules..."
@${GO} clean -modcache
@${GO} mod download
# Reset local LEP-6 dedup/reconciliation tables. Requires DB=/absolute/path/to/local.db.
lep6-reset-dedup:
@if [ -z "$(DB)" ]; then echo "DB=/absolute/path/to/local.db is required"; exit 2; fi
@test -f "$(DB)" || (echo "DB does not exist: $(DB)"; exit 2)
@echo "Resetting LEP-6 local dedup tables in $(DB): heal_claims_submitted, heal_verifications_submitted, storage_recheck_submissions, recheck_attempt_failures"
@sqlite3 "$(DB)" "DELETE FROM heal_claims_submitted; DELETE FROM heal_verifications_submitted; DELETE FROM storage_recheck_submissions; DELETE FROM recheck_attempt_failures;"
# Run sn-manager e2e tests only
test-sn-manager:
@echo "Running sn-manager e2e tests..."
@cd tests/system && ${GO} test -tags=system_test -v -run '^TestSNManager' .