-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
304 lines (240 loc) · 14 KB
/
Copy pathMakefile
File metadata and controls
304 lines (240 loc) · 14 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# KKKKKKKKK KKKKKKKLLLLLLLLLLL EEEEEEEEEEEEEEEEEEEEEEVVVVVVVV VVVVVVVVEEEEEEEEEEEEEEEEEEEEEERRRRRRRRRRRRRRRRR
# K:::::::K K:::::KL:::::::::L E::::::::::::::::::::EV::::::V V::::::VE::::::::::::::::::::ER::::::::::::::::R
# K:::::::K K:::::KL:::::::::L E::::::::::::::::::::EV::::::V V::::::VE::::::::::::::::::::ER::::::RRRRRR:::::R
# K:::::::K K::::::KLL:::::::LL EE::::::EEEEEEEEE::::EV::::::V V::::::VEE::::::EEEEEEEEE::::ERR:::::R R:::::R
# KK::::::K K:::::KKK L:::::L E:::::E EEEEEE V:::::V V:::::V E:::::E EEEEEE R::::R R:::::R
# K:::::K K:::::K L:::::L E:::::E V:::::V V:::::V E:::::E R::::R R:::::R
# K::::::K:::::K L:::::L E::::::EEEEEEEEEE V:::::V V:::::V E::::::EEEEEEEEEE R::::RRRRRR:::::R
# K:::::::::::K L:::::L E:::::::::::::::E V:::::V V:::::V E:::::::::::::::E R:::::::::::::RR
# K:::::::::::K L:::::L E:::::::::::::::E V:::::V V:::::V E:::::::::::::::E R::::RRRRRR:::::R
# K::::::K:::::K L:::::L E::::::EEEEEEEEEE V:::::V V:::::V E::::::EEEEEEEEEE R::::R R:::::R
# K:::::K K:::::K L:::::L E:::::E V:::::V:::::V E:::::E R::::R R:::::R
# KK::::::K K:::::KKK L:::::L LLLLLL E:::::E EEEEEE V:::::::::V E:::::E EEEEEE R::::R R:::::R
# K:::::::K K::::::KLL:::::::LLLLLLLLL:::::LEE::::::EEEEEEEE:::::E V:::::::V EE::::::EEEEEEEE:::::ERR:::::R R:::::R
# K:::::::K K:::::KL::::::::::::::::::::::LE::::::::::::::::::::E V:::::V E::::::::::::::::::::ER::::::R R:::::R
# K:::::::K K:::::KL::::::::::::::::::::::LE::::::::::::::::::::E V:::V E::::::::::::::::::::ER::::::R R:::::R
# KKKKKKKKK KKKKKKKLLLLLLLLLLLLLLLLLLLLLLLLEEEEEEEEEEEEEEEEEEEEEE VVV EEEEEEEEEEEEEEEEEEEEEERRRRRRRR RRRRRRR
###############################################################################
# Usage #
###############################################################################
#
# Common workflows
# make build Build all binaries into ./bin/
# make all Run validator node (default log level)
# make debug Run node in debug mode
# make tests-unit Run unit tests
# make profile Run node with pprof on 127.0.0.1:8080 (see pprof-* targets)
# make docker-build Build Debian Docker image (see docker/Makefile)
# make help List every available target
#
# Environment variables
# LOG=*:DEBUG Log level filter (default: *:INFO)
# VERBOSE=1 Add -v to go test invocations
# RELEASE=1 Strip DWARF + trim paths (CI / release builds)
# FOR_DEV=dev- Prefix docker image tags with "dev-"
# FOR_TESTNET=-testnet Suffix docker image tags with "-testnet"
# E2E_NODE_URL, E2E_PROXY_URL Used by tests-e2e
# NODE Used by connector (node URL)
# ARGS Forwarded to benchmark target
#
###############################################################################
# Safer recipe execution: if a recipe fails, delete its target so the next
# invocation doesn't treat a half-written file as up-to-date.
.DELETE_ON_ERROR:
###############################################################################
# Configuration #
###############################################################################
# LOAD builder info
ifndef VERSION
SHELL := /bin/bash
VERSION := $(shell git describe --always --long --dirty --tag)
endif
ldflags := -X 'main.appVersion=${VERSION}'
# Release builds strip DWARF, build IDs, and trim source paths for smaller,
# reproducible binaries. Set RELEASE=1 in CI / docker release builds.
# Local `make build` keeps DWARF + symbols so delve still works on developer
# machines. Panic stack traces and pprof remain readable on RELEASE=1 builds
# because Go's runtime symbol table (pclntab) is independent of DWARF.
GO_BUILD_FLAGS :=
ifeq ($(RELEASE),1)
ldflags += -s -w -buildid=
GO_BUILD_FLAGS := -trimpath -buildvcs=false
endif
ifdef FOR_TESTNET
FOR_TESTNET := -testnet
endif
ifdef FOR_DEV
FOR_DEV := dev-
endif
UNAME_S := $(shell uname -s)
ENV_FLAG :=
ifeq ($(UNAME_S),Darwin)
ENV_FLAG += env DYLD_LIBRARY_PATH=$(shell pwd)/kvm/wasmer2
else
ENV_FLAG += env LD_LIBRARY_PATH=$(shell pwd)/kvm/wasmer2
endif
ifdef VERBOSE
VERBOSE=-v
endif
ifndef LOG
LOG=*:INFO
endif
GOCMD=go
override GOOS_TARGET := $(shell $(GOCMD) env GOOS)
# Some vendored cgo static archives lack .note.GNU-stack markers, which makes
# GNU ld mark the binaries' stack executable. Force noexecstack on Linux;
# Darwin's ld64 has no GNU_STACK concept and doesn't accept the flag. rpath
# tokens are platform-specific too ($ORIGIN is GNU ld/ELF, @executable_path is
# ld64/Mach-O), so pick exactly one instead of passing both on every build.
# Gated on GOOS_TARGET (the Go target, not UNAME_S the build host) so a
# cross-compiled GOOS=linux build from a non-Linux host still gets it.
ifeq ($(GOOS_TARGET),darwin)
override EXTLDFLAGS := -Wl,-rpath,@executable_path
else
override EXTLDFLAGS := -Wl,-rpath,\$$ORIGIN
endif
ifeq ($(GOOS_TARGET),linux)
override EXTLDFLAGS += -Wl,-z,noexecstack
endif
GORUN=$(ENV_FLAG) $(GOCMD) run -ldflags="$(ldflags) -extldflags '$(EXTLDFLAGS)'"
GOBUILD=$(GOCMD) build $(GO_BUILD_FLAGS) -ldflags="$(ldflags) -extldflags '$(EXTLDFLAGS)'"
.DEFAULT_GOAL := help
###############################################################################
# Help #
###############################################################################
.PHONY: help version
help: ## Show this help message
@echo "Klever Blockchain - Available Make Targets"
@echo ""
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z0-9_-]+:[^#]*##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
version: ## Print the build version string (git describe)
@echo $(VERSION)
###############################################################################
# Run & Debug #
###############################################################################
.PHONY: all debug trace redundancy seednode import-from-localdb runsc-trace
.PHONY: profile pprof-goroutines pprof-heartbeat pprof-top
all: ## Run validator node with default log level
$(GORUN) ./cmd/node --log-level="${LOG}" --use-log-view
debug: ## Run node in debug mode
$(GORUN) ./cmd/node --log-level=*:DEBUG --use-log-view
trace: ## Run node in trace mode (verbose logging)
$(GORUN) ./cmd/node --log-level=*:TRACE,ntp:INFO,debug/p2p:INFO,state:DEBUG,trie:INFO,facade:INFO,sharding/networksharding:INFO,p2p/libp2p:INFO,basichost:INFO,dht:INFO,pubsub:INFO,heartbeat/process:INFO,statistics/machine:INFO,process/rating:INFO,consensus/chronology:INFO --use-log-view --log-save
redundancy: ## Run node with redundancy for testing
$(GORUN) ./cmd/node --log-level="${LOG}" --redundancy-level=1 --working-directory=./db/db1 --p2p-seed=node1 --rest-api-interface=127.0.0.1:8091 --use-log-view #--log-save
seednode: ## Run seednode for network bootstrap
$(GORUN) ./cmd/seednode --log-level=*:DEBUG --rest-api-interface=8081
import-from-localdb: ## Import blockchain data from local database
$(GORUN) ./cmd/node --log-level="${LOG}" --use-log-view --import-db=./db/local --import-db-no-sig-check
runsc-trace: ## Run node with smart-contract trace logging (wipes ./db first)
rm -rf db
$(GORUN) ./cmd/node --use-log-view --log-level=*:INFO,process/block:DEBUG,process/transaction:DEBUG,process/transaction.smartcontract:TRACE,process/smartcontract:DEBUG,vm/host:TRACE,vm/metering:DEBUG
# --- pprof -------------------------------------------------------------------
# Live runtime profiling. Start the node with `make profile`, then query the
# pprof endpoint from another terminal.
#
# Typical workflow
# make profile # terminal 1: start node with pprof on :8080
# make pprof-top # terminal 2 (after ~20s bootstrap)
# make pprof-heartbeat # focused heartbeat-monitor check
# go tool pprof http://127.0.0.1:8080/debug/pprof/heap # interactive heap
#
# Reference: https://pkg.go.dev/net/http/pprof
profile: ## Run node with pprof enabled on 127.0.0.1:8080/debug/pprof
$(GORUN) ./cmd/node --log-level="${LOG}" --use-log-view \
--profile-mode --rest-api-interface=127.0.0.1:8080
pprof-goroutines: ## Dump all live goroutines from a running --profile-mode node
@curl -s "http://127.0.0.1:8080/debug/pprof/goroutine?debug=2"
pprof-heartbeat: ## Show only the heartbeat monitor goroutine stack (with state header)
@curl -s "http://127.0.0.1:8080/debug/pprof/goroutine?debug=2" | \
grep -B 1 -A 4 "startValidatorProcessing.func1"
pprof-top: ## Top 30 functions by live goroutine count (spot fan-out / leaks)
@curl -s "http://127.0.0.1:8080/debug/pprof/goroutine?debug=2" | \
awk '/^goroutine /{getline; sub(/\(.*/,""); print}' | \
sort | uniq -c | sort -rn | head -30
###############################################################################
# Tools #
###############################################################################
.PHONY: newkey connector benchmark
newkey: ## Generate new validator keys
$(GORUN) ./cmd/keygenerator
connector: ## Run terminal UI connector against a node (NODE=<url>)
go run ./cmd/connector/main.go node --address="${NODE}" --log-level="${LOG}"
benchmark: ## Run full validator benchmark (ARGS=<args>)
$(GORUN) ./cmd/benchmark $(ARGS)
###############################################################################
# Build #
###############################################################################
.PHONY: build build-validator build-seednode build-operator build-keygenerator build-benchmark clean
build: build-validator build-seednode build-operator build-keygenerator build-benchmark ## Build all binaries
build-validator: ## Build validator node binary
$(GOBUILD) -o ./bin/validator ./cmd/node
build-seednode: ## Build seednode binary
$(GOBUILD) -o ./bin/seednode ./cmd/seednode
build-operator: ## Build operator tools binary
$(GOBUILD) -o ./bin/operator ./cmd/operator
build-keygenerator: ## Build key generator binary
$(GOBUILD) -o ./bin/keygenerator ./cmd/keygenerator
build-benchmark: ## Build validator benchmark tool
$(GOBUILD) -o ./bin/benchmark ./cmd/benchmark
clean: ## Remove build artifacts and caches
@echo "Cleaning build artifacts..."
@rm -rf ./bin/
@rm -rf ./vendor/
@go clean -testcache
@go clean -cache
@echo "Clean complete"
###############################################################################
# Docker #
###############################################################################
# Docker-related targets are isolated in docker/Makefile (they have their own
# registry / multi-arch builder model). Targets become available via include.
include docker/Makefile
###############################################################################
# Code Generation & Docs #
###############################################################################
.PHONY: vm-generate-rs gen-doc
vm-generate-rs: ## Generate VM hooks from Rust SDK
cd kvm/vmhost/vmhooks && go run generate/cmd/eiGenMain.go
gen-doc: ## Generate Swagger API documentation
swag init -d ./cmd/node,./network/api -o ./docs --parseInternal --parseDependency --instanceName="node"
###############################################################################
# Development Setup #
###############################################################################
.PHONY: prepare ensure-dependencies goimports
prepare: ## Install development dependencies
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install github.com/swaggo/swag/cmd/swag@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/goware/modvendor@latest
ensure-dependencies: ## Ensure Go dependencies are up to date
go mod tidy
goimports: ## Format Go code and organize imports
@goimports -w -d $(shell find . -type f -name '*.go' \
! -name '*.pb.go' \
! -name '*_setter.go' \
! -name 'opcodeCost.go' \
! -name 'wasmer2ImportsCgo.go' \
! -name 'wasmer2Names.go' \
! -name 'wrapperVMHooks_test.go' \
! -name 'executorMockFunc.go' \
! -name 'gasCostWASM.go' \
! -path "./vendor/*")
###############################################################################
# Tests #
###############################################################################
.PHONY: tests tests-unit tests-integration tests-kvm tests-e2e
tests: tests-unit tests-integration tests-kvm tests-e2e ## Run all tests
tests-unit: ## Run unit tests
go clean -testcache
go test ${VERBOSE} $(shell go list ./... | grep -v "integrationTest" | grep -v "kvm")
tests-integration: ## Run integration tests
go clean -testcache
go test ${VERBOSE} ./integrationTest/...
tests-kvm: ## Run KVM (smart contract) tests
go clean -testcache
go test ${VERBOSE} -timeout 1500s ./kvm/...
tests-e2e: ## Run end-to-end tests
if [ ! -d klever-go-e2e ]; then git clone git@github.com:klever-io/klever-go-e2e.git; fi
cd klever-go-e2e && go mod tidy && make build && cd ..
klever-go-e2e/bin/klever-go-e2e --node="${E2E_NODE_URL}" --proxy="${E2E_PROXY_URL}"