-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
230 lines (180 loc) · 9.07 KB
/
Copy pathMakefile
File metadata and controls
230 lines (180 loc) · 9.07 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
ROOT_DIR := $(shell pwd)
BUILD_OUTPUT_DIR := $(ROOT_DIR)/src/Nethermind/src/Nethermind/artifacts/bin/Nethermind.Runner/debug
# JWT secret file - shared between Nethermind and Nitro
JWT_FILE ?= $(HOME)/.arbitrum/jwt.hex
# System test defaults
ARBOS_VERSION ?= 51
ACCOUNTS_FILE ?= src/Nethermind.Arbitrum/Properties/accounts/defaults.json
MAX_CODE_SIZE ?= 0x6000
CONFIG_NAME := arbitrum-system-test
# Snapshot cache configuration (shared with Nitro at ~/.cache/blockchain-snapshots/)
SNAPSHOT_CACHE_DIR := $(HOME)/.cache/blockchain-snapshots/nethermind
MAINNET_GENESIS_SNAPSHOT := snapshot.zip
MAINNET_GENESIS_SNAPSHOT_URL := https://arb-snapshot.nethermind.dev/arbitrum-snapshot/$(MAINNET_GENESIS_SNAPSHOT)
# =============================================================================
# Macros
# =============================================================================
# Run Nethermind: $(call run-nethermind,config-name)
define run-nethermind
cd $(BUILD_OUTPUT_DIR) && dotnet nethermind.dll -c $(1) \
--data-dir $(ROOT_DIR)/.data \
--JsonRpc.JwtSecretFile=$(JWT_FILE) $(NETHERMIND_ARGS)
endef
# Restore snapshot: $(call restore-snapshot,config-name,snapshot-subdir)
define restore-snapshot
@if [ -d "$(ROOT_DIR)/.data/nethermind_db/$(1)" ]; then \
exit 0; \
elif [ -f "$(SNAPSHOT_CACHE_DIR)/$(MAINNET_GENESIS_SNAPSHOT)" ]; then \
echo "Restoring snapshot from cache..."; \
mkdir -p "$(ROOT_DIR)/.data/snapshot/$(2)"; \
cp "$(SNAPSHOT_CACHE_DIR)/$(MAINNET_GENESIS_SNAPSHOT)" "$(ROOT_DIR)/.data/snapshot/$(2)/"; \
echo "Downloaded" > "$(ROOT_DIR)/.data/snapshot/$(2)/checkpoint_$(MAINNET_GENESIS_SNAPSHOT)"; \
else \
echo "No cached snapshot. Run 'make download-snapshot' to cache it."; \
fi
endef
# Clean config data: $(call clean-config,config-name,snapshot-subdir)
define clean-config
@echo "Cleaning $(1) data..."
@rm -rf "$(ROOT_DIR)/.data/nethermind_db/$(1)"
@rm -rf "$(ROOT_DIR)/.data/snapshot/$(2)"
endef
# =============================================================================
# Mainnet targets
# =============================================================================
run-mainnet: ## Run Mainnet (non-archive)
$(call restore-snapshot,arbitrum-mainnet,mainnet)
@echo "Starting Nethermind (Mainnet)..."
$(call run-nethermind,arbitrum-mainnet)
run-mainnet-archive: ## Run Mainnet Archive
$(call restore-snapshot,arbitrum-mainnet-archive,mainnet-archive)
@echo "Starting Nethermind (Mainnet Archive)..."
$(call run-nethermind,arbitrum-mainnet-archive)
clean-mainnet: ## Clean Mainnet data
$(call clean-config,arbitrum-mainnet,mainnet)
clean-mainnet-archive: ## Clean Mainnet Archive data
$(call clean-config,arbitrum-mainnet-archive,mainnet-archive)
clean-run-mainnet: clean-mainnet run-mainnet ## Clean and run Mainnet
clean-run-mainnet-archive: clean-mainnet-archive run-mainnet-archive ## Clean and run Mainnet Archive
# =============================================================================
# Sepolia targets
# =============================================================================
run-sepolia: ## Run Sepolia (non-archive)
@echo "Starting Nethermind (Sepolia)..."
$(call run-nethermind,arbitrum-sepolia)
run-sepolia-archive: ## Run Sepolia Archive
@echo "Starting Nethermind (Sepolia Archive)..."
$(call run-nethermind,arbitrum-sepolia-archive)
clean-sepolia: ## Clean Sepolia data
$(call clean-config,arbitrum-sepolia,sepolia)
clean-sepolia-archive: ## Clean Sepolia Archive data
$(call clean-config,arbitrum-sepolia-archive,sepolia-archive)
clean-run-sepolia: clean-sepolia run-sepolia ## Clean and run Sepolia
clean-run-sepolia-archive: clean-sepolia-archive run-sepolia-archive ## Clean and run Sepolia Archive
run-sepolia-verify: ## Run Sepolia Archive with block hash verification
@$(MAKE) run-sepolia-archive NETHERMIND_ARGS="--VerifyBlockHash.Enabled=true"
clean-run-sepolia-verify: clean-sepolia-archive run-sepolia-verify ## Clean and run Sepolia with verification
# =============================================================================
# Snapshot cache management
# =============================================================================
download-snapshot: ## Download mainnet snapshot to cache
@echo "Downloading mainnet snapshot to cache..."
@mkdir -p "$(SNAPSHOT_CACHE_DIR)"
@if command -v aria2c > /dev/null 2>&1; then \
echo "Using aria2c (16 connections)..."; \
aria2c -x 16 -s 16 -k 1M -c \
-d "$(SNAPSHOT_CACHE_DIR)" -o "$(MAINNET_GENESIS_SNAPSHOT)" "$(MAINNET_GENESIS_SNAPSHOT_URL)"; \
else \
echo "Using curl (install aria2 for faster downloads: brew install aria2)..."; \
curl -L -C - --http1.1 --retry 5 --retry-delay 5 --progress-bar \
-o "$(SNAPSHOT_CACHE_DIR)/$(MAINNET_GENESIS_SNAPSHOT)" "$(MAINNET_GENESIS_SNAPSHOT_URL)"; \
fi
@if unzip -t "$(SNAPSHOT_CACHE_DIR)/$(MAINNET_GENESIS_SNAPSHOT)" > /dev/null 2>&1; then \
echo "Snapshot downloaded and cached successfully."; \
else \
echo "ERROR: Download corrupted. Try again."; \
rm -f "$(SNAPSHOT_CACHE_DIR)/$(MAINNET_GENESIS_SNAPSHOT)"; \
exit 1; \
fi
cache-status: ## Show snapshot cache status
@echo "=== Nethermind Snapshot Cache Status ==="
@echo "Cache directory: $(SNAPSHOT_CACHE_DIR)"
@echo ""
@if [ -f "$(SNAPSHOT_CACHE_DIR)/$(MAINNET_GENESIS_SNAPSHOT)" ]; then \
echo "Mainnet: CACHED"; \
ls -lh "$(SNAPSHOT_CACHE_DIR)/$(MAINNET_GENESIS_SNAPSHOT)"; \
else \
echo "Mainnet: NOT CACHED (run 'make download-snapshot')"; \
fi
clean-cache: ## Remove snapshot cache
@rm -rf $(SNAPSHOT_CACHE_DIR)
@echo "Snapshot cache cleared."
# =============================================================================
# Local / System test targets
# =============================================================================
run-local: ## Run local dev node (no JWT)
cd $(BUILD_OUTPUT_DIR) && dotnet nethermind.dll -c arbitrum-local \
--data-dir $(ROOT_DIR)/.data --JsonRpc.UnsecureDevNoRpcAuthentication=true
clean-local: ## Clean local data
$(call clean-config,arbitrum-local,local)
clean-run-local: clean-local run-local ## Clean and run local
generate-system-test-config:
@./src/Nethermind.Arbitrum/Properties/scripts/generate-system-test-config.sh \
$(ARBOS_VERSION) $(ACCOUNTS_FILE) $(CONFIG_NAME) $(MAX_CODE_SIZE)
run-system-test: generate-system-test-config ## Run system test config
@echo "Starting Nethermind with system-test config..."
cd $(BUILD_OUTPUT_DIR) && dotnet nethermind.dll -c $(CONFIG_NAME) \
--data-dir $(ROOT_DIR)/.data --JsonRpc.UnsecureDevNoRpcAuthentication=true --log debug
clean-system-test: ## Clean system test data
$(call clean-config,$(CONFIG_NAME),)
clean-run-system-test: clean-system-test run-system-test ## Clean and run system test
nethermind-help: ## Show Nethermind help
cd $(BUILD_OUTPUT_DIR) && dotnet nethermind.dll -h
# =============================================================================
# General cleanup
# =============================================================================
clean: ## Remove all .data
@rm -rf $(ROOT_DIR)/.data
@rm -f $(ROOT_DIR)/.generated-chainspec.json
@echo "All data cleaned."
clean-all: clean clean-cache ## Remove all data and cache
stop: ## Stop Nethermind
@pkill -f "dotnet.*nethermind.dll" 2>/dev/null || true
@echo "Nethermind stopped."
# =============================================================================
# Build / Test / Format
# =============================================================================
build: ## Build Nethermind Arbitrum
dotnet build src/Nethermind.Arbitrum/Nethermind.Arbitrum.csproj -c Release
test: ## Run tests
dotnet test src/Nethermind.Arbitrum.Test/Nethermind.Arbitrum.Test.csproj
coverage: ## Generate test coverage
dotnet test src/Nethermind.Arbitrum.Test/Nethermind.Arbitrum.Test.csproj \
--collect:"XPlat Code Coverage" --results-directory $(ROOT_DIR)/test-coverage
coverage-report: coverage ## Generate HTML coverage report
@if command -v reportgenerator >/dev/null 2>&1; then \
reportgenerator \
-reports:$(ROOT_DIR)/test-coverage/*/coverage.cobertura.xml \
-targetdir:$(ROOT_DIR)/test-coverage/html \
-reporttypes:Html \
-sourcedirs:$(ROOT_DIR)/src; \
open $(ROOT_DIR)/test-coverage/html/index.html 2>/dev/null || true; \
else \
echo "Install reportgenerator: dotnet tool install -g dotnet-reportgenerator-globaltool"; \
fi
format: ## Format code
dotnet format src/Nethermind.Arbitrum/Nethermind.Arbitrum.csproj
dotnet format src/Nethermind.Arbitrum.Test/Nethermind.Arbitrum.Test.csproj
# =============================================================================
# Help
# =============================================================================
help: ## Show this help
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-25s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
list-system-test-accounts: ## List account configurations
@ls -1 src/Nethermind.Arbitrum/Properties/accounts/*.json 2>/dev/null
list-system-test-configs: ## Show system test examples
@echo "Examples:"
@echo " make run-system-test ARBOS_VERSION=51"
@echo " make run-system-test ACCOUNTS_FILE=src/Nethermind.Arbitrum/Properties/accounts/contract-tx.json"
@echo " make clean-run-system-test ARBOS_VERSION=30"