-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakefile
More file actions
411 lines (356 loc) · 13.4 KB
/
makefile
File metadata and controls
411 lines (356 loc) · 13.4 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# Catalyst Node Makefile
# Provides convenient commands for building, testing, and running the Catalyst node
.PHONY: help build test run clean setup dev docker fmt clippy docs bench
# Default target
help:
@echo "Catalyst Node Development Commands"
@echo "================================="
@echo ""
@echo "Setup and Build:"
@echo " setup - Install dependencies and set up development environment"
@echo " build - Build the project in release mode"
@echo " dev - Build the project in development mode"
@echo " clean - Clean build artifacts"
@echo ""
@echo "Code Quality:"
@echo " fmt - Format code with rustfmt"
@echo " clippy - Run clippy lints"
@echo " test - Run all tests"
@echo " bench - Run benchmarks"
@echo ""
@echo "Documentation:"
@echo " docs - Generate and open documentation"
@echo ""
@echo "Running:"
@echo " run - Run the node with default configuration"
@echo " run-validator - Run as a validator node"
@echo " run-storage - Run with storage provision enabled"
@echo ""
@echo "Docker:"
@echo " docker-build - Build Docker image"
@echo " docker-run - Run Docker container"
@echo ""
@echo "Network:"
@echo " genesis - Create genesis configuration"
@echo " testnet - Start local testnet with 3 nodes"
# Variables
CARGO = cargo
DOCKER = docker
PROJECT_NAME = catalyst-node
RUST_LOG ?= info
# Cargo target directory
# When working from GVFS/SMB mounts, file locking can be unsupported which breaks
# Cargo's `.cargo-lock` in `target/` (os error 95). Use a local target dir by default.
PROJECT_ROOT := $(CURDIR)
DEFAULT_CARGO_TARGET_DIR := $(PROJECT_ROOT)/target
GVFS_CARGO_TARGET_DIR := $(HOME)/.cache/$(PROJECT_NAME)/cargo-target
GVFS_WORKDIR := $(HOME)/.cache/$(PROJECT_NAME)/gvfs-workdir
GVFS_MIRROR_DIR := $(GVFS_WORKDIR)/src
ifeq (,$(findstring gvfs,$(PROJECT_ROOT)))
CARGO_TARGET_DIR ?= $(DEFAULT_CARGO_TARGET_DIR)
CARGO_MANIFEST_PATH ?= $(PROJECT_ROOT)/Cargo.toml
else
CARGO_TARGET_DIR ?= $(GVFS_CARGO_TARGET_DIR)
# On GVFS/SMB mounts, Cargo may fail to lock/write Cargo.lock. Build from a local mirror.
CARGO_MANIFEST_PATH ?= $(GVFS_MIRROR_DIR)/Cargo.toml
endif
export CARGO_TARGET_DIR
# Keep a local mirror of the source tree when building from GVFS/SMB.
.PHONY: sync-gvfs-mirror
sync-gvfs-mirror:
ifeq (,$(findstring gvfs,$(PROJECT_ROOT)))
@true
else
@mkdir -p "$(GVFS_MIRROR_DIR)"
@rsync -a --delete \
--exclude 'target' \
--exclude '.git' \
"$(PROJECT_ROOT)/" "$(GVFS_MIRROR_DIR)/"
endif
# System dependency checks
.PHONY: check-system-deps
check-system-deps:
@command -v cc >/dev/null 2>&1 || { \
echo "Missing C toolchain (cc). On Ubuntu/Debian: sudo apt install build-essential"; \
exit 1; \
}
@printf '#include <stddef.h>\n' | cc -E - >/dev/null 2>&1 || { \
echo "C standard headers not found (missing stddef.h). On Ubuntu/Debian: sudo apt install build-essential"; \
exit 1; \
}
@command -v pkg-config >/dev/null 2>&1 || { \
echo "Missing pkg-config. On Ubuntu/Debian: sudo apt install pkg-config"; \
exit 1; \
}
@pkg-config --exists openssl >/dev/null 2>&1 || { \
echo "Missing OpenSSL development headers (.pc not found). On Ubuntu/Debian: sudo apt install libssl-dev"; \
exit 1; \
}
@command -v clang >/dev/null 2>&1 || { \
echo "Missing clang (needed by bindgen). On Ubuntu/Debian: sudo apt install clang libclang-dev"; \
exit 1; \
}
@command -v cmake >/dev/null 2>&1 || { \
echo "Missing cmake (often required by native deps like RocksDB). On Ubuntu/Debian: sudo apt install cmake"; \
exit 1; \
}
# Setup development environment
setup:
@echo "Setting up Catalyst development environment..."
@$(MAKE) check-system-deps
rustup update
rustup component add rustfmt clippy
$(CARGO) install cargo-audit cargo-outdated
@echo "Installing IPFS for DFS support..."
@if ! command -v ipfs &> /dev/null; then \
echo "Please install IPFS manually: https://ipfs.io/docs/install/"; \
fi
@echo "Setup complete!"
# Build commands
build:
@echo "Building Catalyst node (release)..."
@$(MAKE) check-system-deps
@$(MAKE) sync-gvfs-mirror
$(CARGO) build --release --workspace --manifest-path "$(CARGO_MANIFEST_PATH)"
dev:
@echo "Building Catalyst node (debug)..."
@$(MAKE) check-system-deps
@$(MAKE) sync-gvfs-mirror
$(CARGO) build --workspace --manifest-path "$(CARGO_MANIFEST_PATH)"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
$(CARGO) clean
rm -rf target/
rm -rf data/
rm -rf logs/
rm -rf dfs_cache/
# Code formatting and linting
fmt:
@echo "Formatting code..."
$(CARGO) fmt --all
clippy:
@echo "Running clippy..."
$(CARGO) clippy --workspace --all-targets --all-features -- -D warnings
# Testing
test:
@echo "Running tests..."
@$(MAKE) sync-gvfs-mirror
RUST_LOG=debug $(CARGO) test --workspace --manifest-path "$(CARGO_MANIFEST_PATH)"
test-all-features:
@echo "Running tests (all features)..."
@$(MAKE) sync-gvfs-mirror
RUST_LOG=debug $(CARGO) test --workspace --all-features --manifest-path "$(CARGO_MANIFEST_PATH)"
test-integration:
@echo "Running integration tests..."
@$(MAKE) sync-gvfs-mirror
RUST_LOG=debug $(CARGO) test --workspace --test integration_tests --manifest-path "$(CARGO_MANIFEST_PATH)"
bench:
@echo "Running benchmarks..."
@$(MAKE) sync-gvfs-mirror
$(CARGO) bench --workspace --manifest-path "$(CARGO_MANIFEST_PATH)"
# Documentation
docs:
@echo "Generating documentation..."
@$(MAKE) sync-gvfs-mirror
$(CARGO) doc --workspace --all-features --no-deps --open --manifest-path "$(CARGO_MANIFEST_PATH)"
# Run commands
run: build
@echo "Starting Catalyst node..."
RUST_LOG=$(RUST_LOG) $(CARGO_TARGET_DIR)/release/catalyst-cli start
run-dev: dev
@echo "Starting Catalyst node (debug)..."
RUST_LOG=$(RUST_LOG) $(CARGO) run --bin catalyst-cli -- start
run-validator: build
@echo "Starting Catalyst validator node..."
RUST_LOG=$(RUST_LOG) $(CARGO_TARGET_DIR)/release/catalyst-cli start --validator --rpc
run-storage: build
@echo "Starting Catalyst storage node..."
RUST_LOG=$(RUST_LOG) $(CARGO_TARGET_DIR)/release/catalyst-cli start --storage --storage-capacity 50
run-full: build
@echo "Starting full Catalyst node (validator + storage + RPC)..."
RUST_LOG=$(RUST_LOG) $(CARGO_TARGET_DIR)/release/catalyst-cli start --validator --storage --rpc
# Docker commands
docker-build:
@echo "Building Docker image..."
$(DOCKER) build -t $(PROJECT_NAME):latest .
docker-run:
@echo "Running Docker container..."
$(DOCKER) run -p 8545:8545 -p 8546:8546 -p 30333:30333 \
-v $(PWD)/data:/app/data \
$(PROJECT_NAME):latest
# Network setup
genesis:
@echo "Creating genesis configuration..."
mkdir -p configs
@$(MAKE) sync-gvfs-mirror
$(CARGO) run --bin catalyst-cli --manifest-path "$(CARGO_MANIFEST_PATH)" -- create-genesis --output configs/genesis.json
identity:
@echo "Generating node identity..."
@$(MAKE) sync-gvfs-mirror
$(CARGO) run --bin catalyst-cli --manifest-path "$(CARGO_MANIFEST_PATH)" -- generate-identity --output identity.json
# Development utilities
check:
@echo "Running cargo check..."
@$(MAKE) sync-gvfs-mirror
$(CARGO) check --workspace --all-targets --all-features --manifest-path "$(CARGO_MANIFEST_PATH)"
audit:
@echo "Running security audit..."
$(CARGO) audit
outdated:
@echo "Checking for outdated dependencies..."
$(CARGO) outdated
update:
@echo "Updating dependencies..."
$(CARGO) update
# Local testnet
testnet: build
@echo "Starting local testnet with 3 nodes..."
@bash -lc 'set -euo pipefail; \
# Write a deterministic, pre-funded faucet key for dev/testnet usage. \
# Matches FAUCET_PRIVATE_KEY_BYTES ([0xFA;32]) embedded in the node. \
python3 -c "print(\"fa\"*32)" > testnet/faucet.key; \
for n in 1 2 3; do \
mkdir -p "testnet/node$${n}/logs" "testnet/node$${n}/data" "testnet/node$${n}/dfs_cache"; \
done; \
# Pre-generate per-node identities so we can build a deterministic validator set before startup. \
for n in 1 2 3; do \
key="testnet/node$${n}/node.key"; \
if [ ! -f "$$key" ]; then \
python3 -c "import os,binascii; print(binascii.hexlify(os.urandom(32)).decode())" > "$$key"; \
fi; \
done; \
# Validator set (node1 + node2): used for protocol producer selection without NodeStatus gossip. \
PK1=$$("$(CARGO_TARGET_DIR)/release/catalyst-cli" --log-level error pubkey --key-file testnet/node1/node.key | tail -n 1); \
PK2=$$("$(CARGO_TARGET_DIR)/release/catalyst-cli" --log-level error pubkey --key-file testnet/node2/node.key | tail -n 1); \
printf "validator_worker_ids = [\"%s\", \"%s\"]\n" "$$PK1" "$$PK2" > testnet/validators.toml; \
echo "Starting node1 (bootstrap + validator)..." ; \
RUST_LOG=info stdbuf -oL -eL "$(CARGO_TARGET_DIR)/release/catalyst-cli" --config testnet/node1/config.toml start \
--validator --rpc --rpc-port 8545 --generate-txs --tx-interval-ms 1000 \
> testnet/node1/logs/stdout.log 2>&1 & \
echo $$! > testnet/node1/node.pid; \
sleep 2; \
echo "Starting node2 (validator + storage)..." ; \
RUST_LOG=info stdbuf -oL -eL "$(CARGO_TARGET_DIR)/release/catalyst-cli" --config testnet/node2/config.toml start \
--validator --storage --rpc-port 8546 \
--bootstrap-peers "/ip4/127.0.0.1/tcp/30333" \
> testnet/node2/logs/stdout.log 2>&1 & \
echo $$! > testnet/node2/node.pid; \
sleep 2; \
echo "Starting node3 (storage only)..." ; \
RUST_LOG=info stdbuf -oL -eL "$(CARGO_TARGET_DIR)/release/catalyst-cli" --config testnet/node3/config.toml start \
--storage --rpc-port 8547 \
--bootstrap-peers "/ip4/127.0.0.1/tcp/30333" \
> testnet/node3/logs/stdout.log 2>&1 & \
echo $$! > testnet/node3/node.pid; \
echo "Testnet started! Logs:"; \
echo " - testnet/node1/logs/stdout.log"; \
echo " - testnet/node2/logs/stdout.log"; \
echo " - testnet/node3/logs/stdout.log"; \
echo "Faucet key written to: testnet/faucet.key"; \
echo "Example send: cargo run -p catalyst-cli -- send <NODE_PUBKEY_HEX> 25 --key-file testnet/faucet.key --rpc-url http://127.0.0.1:8545"; \
echo "Stop with: make stop-testnet"; \
wait $$(cat testnet/node1/node.pid) $$(cat testnet/node2/node.pid) $$(cat testnet/node3/node.pid)'
stop-testnet:
@echo "Stopping testnet..."
@bash -lc 'set -euo pipefail; \
# Primary: stop via pidfiles (normal path) \
for n in 1 2 3; do \
pidfile="testnet/node$${n}/node.pid"; \
if [ -f "$$pidfile" ]; then \
pid=$$(cat "$$pidfile" || true); \
if [ -n "$$pid" ] && kill -0 "$$pid" 2>/dev/null; then \
echo "Stopping node$${n} (pid $$pid)"; \
kill "$$pid" 2>/dev/null || true; \
fi; \
fi; \
done; \
sleep 1; \
for n in 1 2 3; do \
pidfile="testnet/node$${n}/node.pid"; \
if [ -f "$$pidfile" ]; then \
pid=$$(cat "$$pidfile" || true); \
if [ -n "$$pid" ] && kill -0 "$$pid" 2>/dev/null; then \
echo "Force killing node$${n} (pid $$pid)"; \
kill -9 "$$pid" 2>/dev/null || true; \
fi; \
fi; \
done; \
# Fallback: if pidfiles were never created (older broken testnet runs), stop by exact cmdline match. \
for n in 1 2 3; do \
pids=$$(pgrep -f "$(CARGO_TARGET_DIR)/release/catalyst-cli --config testnet/node$${n}/config.toml start" || true); \
if [ -n "$$pids" ]; then \
echo "Stopping node$${n} by pgrep fallback (pids $$pids)"; \
kill $$pids 2>/dev/null || true; \
fi; \
done; \
true'
.PHONY: smoke-testnet
smoke-testnet: build
@echo "Running local testnet smoke test..."
@bash scripts/smoke_testnet.sh
.PHONY: testnet-up testnet-down testnet-status testnet-logs testnet-basic-test devnet-up devnet-down devnet-status
testnet-up: build
@bash scripts/netctl.sh testnet up
.PHONY: testnet-up-clean
testnet-up-clean: build
@bash scripts/netctl.sh testnet up --clean
testnet-down:
@bash scripts/netctl.sh testnet down
testnet-status:
@bash scripts/netctl.sh testnet status
testnet-logs:
@bash scripts/netctl.sh testnet logs $(or $(NODE),node1)
testnet-basic-test: build
@bash scripts/netctl.sh testnet test-basic
.PHONY: testnet-contract-test
testnet-contract-test: build
@bash scripts/netctl.sh testnet test-contract
# Public/stable devnet helpers (single node that exposes RPC externally).
# Example:
# make devnet-up HOST=203.0.113.10 P2P_PORT=30333 RPC_PORT=8545
devnet-up: build
@bash scripts/netctl.sh devnet up --host "$(HOST)" --p2p-port "$(or $(P2P_PORT),30333)" --rpc-port "$(or $(RPC_PORT),8545)"
devnet-down:
@bash scripts/netctl.sh devnet down
devnet-status:
@bash scripts/netctl.sh devnet status
# Development helpers
watch:
@echo "Watching for changes and rebuilding..."
$(CARGO) watch -x "build --workspace"
watch-test:
@echo "Watching for changes and running tests..."
$(CARGO) watch -x "test --workspace"
# Performance profiling
profile:
@echo "Building with profiling..."
@$(MAKE) sync-gvfs-mirror
$(CARGO) build --release --workspace --manifest-path "$(CARGO_MANIFEST_PATH)"
@echo "Run with: perf record $(CARGO_TARGET_DIR)/release/catalyst-cli start"
# Release preparation
pre-release: fmt clippy test audit
@echo "Pre-release checks complete!"
# Installation
install: build
@echo "Installing Catalyst CLI..."
$(CARGO) install --path crates/catalyst-cli --force
uninstall:
@echo "Uninstalling Catalyst CLI..."
$(CARGO) uninstall catalyst-cli
# Status check
status:
@echo "Checking node status..."
$(CARGO) run --bin catalyst-cli -- status
peers:
@echo "Checking connected peers..."
$(CARGO) run --bin catalyst-cli -- peers
# Backup and restore
backup:
@echo "Creating backup..."
@mkdir -p backups
tar -czf backups/catalyst-backup-$(shell date +%Y%m%d-%H%M%S).tar.gz data/ configs/ *.toml *.json
restore:
@echo "List available backups:"
@ls -la backups/
@echo "To restore: tar -xzf backups/[backup-file]"