forked from cloudwalk/stratus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
528 lines (413 loc) · 17.4 KB
/
justfile
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
import "justfile_helpers"
# Environment variables automatically passed to executed commands.
export CARGO_PROFILE_RELEASE_DEBUG := env("CARGO_PROFILE_RELEASE_DEBUG", "1")
export RUST_BACKTRACE := env("RUST_BACKTRACE", "0")
export CARGO_COMMAND := env("CARGO_COMMAND", "")
# Global arguments that can be passed to receipts.
nightly_flag := if env("NIGHTLY", "") =~ "(true|1)" { "+nightly" } else { "" }
release_flag := if env("RELEASE", "") =~ "(true|1)" { "--release" } else { "" }
database_url := env("DATABASE_URL", "postgres://postgres:[email protected]:5432/stratus")
# Project: Show available tasks
default:
just --list --unsorted
# Project: Run project setup
setup:
@just _log "Installing Cargo killport"
cargo install killport
@just _log "Installing Cargo wait-service"
cargo install wait-service
@just _log "Installing Cargo flamegraph"
cargo install flamegraph
@just _log "Cloning Solidity repositories"
just contracts-clone
# ------------------------------------------------------------------------------
# Stratus tasks
# ------------------------------------------------------------------------------
alias run := stratus
alias run-leader := stratus
alias run-follower := stratus-follower
alias run-importer := stratus-follower
# Stratus: Compile with debug options
build features="":
cargo {{nightly_flag}} build {{release_flag}} --features "{{features}}"
# Stratus: Check, or compile without generating code
check:
cargo {{nightly_flag}} check
# Stratus: Check all features individually using cargo hack
check-features *args="":
command -v cargo-hack >/dev/null 2>&1 || { cargo install cargo-hack; }
cargo hack check --each-feature --keep-going {{args}}
# Stratus: Clean build artifacts
clean:
cargo clean
# Stratus: Build documentation
doc nightly-version="":
@just _doc "{{nightly-version}}"
# Stratus: Lint and format code
lint:
@just _lint
# Stratus: Lint and check code formatting
lint-check nightly-version="":
@just _lint "{{nightly-version}}" --check "-D warnings"
# Stratus: Check for dependencies major updates
outdated:
#!/bin/bash
command -v cargo-outdated >/dev/null 2>&1 || { cargo install cargo-outdated; }
cargo outdated --root-deps-only --ignore-external-rel
# Stratus: Update only the project dependencies
update:
cargo update stratus
# ------------------------------------------------------------------------------
# Database tasks
# ------------------------------------------------------------------------------
# Database: Compile SQLx queries
db-compile:
SQLX_OFFLINE=true cargo sqlx prepare --database-url {{database_url}} -- --all-targets
alias sqlx := db-compile
# ------------------------------------------------------------------------------
# Additional binaries
# ------------------------------------------------------------------------------
# Bin: Stratus main service as leader
stratus *args="":
cargo {{nightly_flag}} ${CARGO_COMMAND} run --bin stratus {{release_flag}} --features dev -- --leader {{args}}
# Bin: Stratus main service as leader while performing memory-profiling, producing a heap dump every 2^32 allocated bytes (~4gb)
# To produce a flamegraph of the memory usage use jeprof:
# * Diferential flamegraph: jeprof <binary> --base=./jeprof.<...>.i0.heap ./jeprof.<...>.i<n>.heap --collapsed | flamegraph.pl > mem_prof.svg
# * Point in time flamegraph: jeprof <binary> ./jeprof.<...>.i<n>.heap --collapsed | flamegraph.pl > mem_prof.svg
stratus-memory-profiling *args="":
_RJEM_MALLOC_CONF=prof:true,prof_final:true,prof_leak:true,prof_gdump:true,lg_prof_interval:32 cargo {{nightly_flag}} run --bin stratus {{release_flag}} --features dev,jeprof -- --leader {{args}}
# Bin: Stratus main service as follower
stratus-follower *args="":
LOCAL_ENV_PATH=config/stratus-follower.env.local cargo {{nightly_flag}} run --bin stratus {{release_flag}} --features dev -- --follower {{args}}
# Bin: Download external RPC blocks and receipts to temporary storage
rpc-downloader *args="":
cargo {{nightly_flag}} run --bin rpc-downloader {{release_flag}} -- {{args}}
# Bin: Import external RPC blocks from temporary storage to Stratus storage
importer-offline *args="":
cargo {{nightly_flag}} run --bin importer-offline {{release_flag}} -- {{args}}
# ------------------------------------------------------------------------------
# Test tasks
# ------------------------------------------------------------------------------
# Test: Execute all Rust tests
test name="":
@just test-doc {{name}}
@just test-unit {{name}}
@just test-int {{name}}
# Test: Execute Rust doc tests
test-doc name="":
cargo test {{name}} --doc
# Test: Execute Rust unit tests
test-unit name="":
cargo test --lib {{name}} -- --nocapture --test-threads=1
# Test: Execute Rust integration tests
test-int name="'*'":
cargo test --test {{name}} {{release_flag}} -- --nocapture
# ------------------------------------------------------------------------------
# E2E tasks
# ------------------------------------------------------------------------------
# E2E: Execute Hardhat tests in the specified network
e2e network="stratus" block_modes="automine" test="":
#!/bin/bash
if [ -d e2e ]; then
cd e2e
fi
if [ ! -d node_modules ]; then
npm install
fi
block_modes_split=$(echo {{block_modes}} | sed "s/,/ /g")
for block_mode in $block_modes_split
do
just _log "Executing: $block_mode"
if [ -z "{{test}}" ]; then
BLOCK_MODE=$block_mode npx hardhat test test/$block_mode/*.test.ts --network {{network}}
else
BLOCK_MODE=$block_mode npx hardhat test test/$block_mode/*.test.ts --network {{network}} --grep "{{test}}"
fi
done
# E2E: Starts and execute Hardhat tests in Stratus
e2e-stratus block-mode="automine" test="":
#!/bin/bash
if [ -d e2e ]; then
cd e2e
fi
just _log "Starting Stratus"
just run -a 0.0.0.0:3000 --block-mode {{block-mode}} > stratus.log &
just _wait_for_stratus
just _log "Running E2E tests"
just e2e stratus {{block-mode}} "{{test}}"
result_code=$?
just _log "Killing Stratus"
killport 3000 -s sigterm
exit $result_code
# E2E: Starts and execute Hardhat tests in Stratus
e2e-stratus-rocks block-mode="automine" test="":
#!/bin/bash
if [ -d e2e ]; then
cd e2e
fi
just _log "Starting Stratus"
just run -a 0.0.0.0:3000 --block-mode {{block-mode}} --perm-storage=rocks > stratus.log &
just _wait_for_stratus
just _log "Running E2E tests"
just e2e stratus {{block-mode}} "{{test}}"
result_code=$?
just _log "Killing Stratus"
killport 3000 -s sigterm
exit $result_code
# E2E Clock: Builds and runs Stratus with block-time flag, then validates average block generation time
e2e-clock-stratus:
#!/bin/bash
just _log "Starting Stratus"
just run --block-mode 1s -a 0.0.0.0:3000 > stratus.log &
just _wait_for_stratus
just _log "Validating block time"
./utils/block-time-check.sh
result_code=$?
just _log "Killing Stratus"
killport 3000 -s sigterm
exit $result_code
# E2E Clock: Builds and runs Stratus Rocks with block-time flag, then validates average block generation time
e2e-clock-stratus-rocks:
#!/bin/bash
just _log "Starting Stratus"
just run --block-mode 1s --perm-storage=rocks -a 0.0.0.0:3000 > stratus.log &
just _wait_for_stratus
just _log "Validating block time"
./utils/block-time-check.sh
result_code=$?
just _log "Killing Stratus"
killport 3000 -s sigterm
exit $result_code
# E2E: Lint and format code
e2e-lint mode="--write":
#!/bin/bash
if [ -d e2e ]; then
cd e2e
fi
node_modules/.bin/prettier . {{ mode }} --ignore-unknown
# E2E: Lint and format shell scripts for cloudwalk contracts
shell-lint mode="--write":
@command -v shfmt > /dev/null 2>&1 && command -v shellcheck > /dev/null 2>&1 || echo "Please, install shfmt and shellcheck" && exit 0
@shfmt {{ mode }} --indent 4 e2e/cloudwalk-contracts/*.sh
@shellcheck e2e/cloudwalk-contracts/*.sh --severity=warning --shell=bash
# E2E: profiles RPC sync and generates a flamegraph
e2e-flamegraph:
#!/bin/bash
# Start RPC mock server
just _log "Starting RPC mock server"
killport 3003 -s sigterm
cd e2e/rpc-mock-server
if [ ! -d node_modules ]; then
npm install
fi
cd ../..
node ./e2e/rpc-mock-server/index.js &
sleep 1
# Wait for RPC mock server
just _log "Waiting for RPC mock server to start for 60 seconds"
wait-service --tcp 0.0.0.0:3003 -t 60 -- echo "RPC mock server started"
# Run cargo flamegraph with necessary environment variables
just _log "Running cargo flamegraph"
cargo flamegraph --bin importer-online --deterministic --features dev -- --external-rpc=http://localhost:3003/rpc --chain-id=2009
# E2E: Leader & Follower Up
e2e-leader-follower-up test="brlc" release_flag="--release":
#!/bin/bash
mkdir e2e_logs
# Start Stratus with leader flag
RUST_BACKTRACE=1 RUST_LOG=info cargo ${CARGO_COMMAND} run {{release_flag}} --bin stratus --features dev -- --leader --block-mode 1s --perm-storage=rocks --rocks-path-prefix=temp_3000 --tokio-console-address=0.0.0.0:6668 --metrics-exporter-address=0.0.0.0:9000 -a 0.0.0.0:3000 > e2e_logs/stratus.log &
# Wait for Stratus with leader flag to start
just _wait_for_stratus 3000
# Start Stratus with follower flag
if [ "{{test}}" = "kafka" ]; then
# Start Kafka using Docker Compose
just _log "Starting Kafka"
docker-compose up kafka >> e2e_logs/kafka.log &
just _log "Waiting Kafka start"
wait-service --tcp 0.0.0.0:29092 -- echo
docker exec kafka kafka-topics --create --topic stratus-events --bootstrap-server localhost:29092 --partitions 1 --replication-factor 1
RUST_BACKTRACE=1 RUST_LOG=info cargo ${CARGO_COMMAND} run {{release_flag}} --bin stratus --features dev -- --follower --perm-storage=rocks --rocks-path-prefix=temp_3001 --tokio-console-address=0.0.0.0:6669 --metrics-exporter-address=0.0.0.0:9001 -a 0.0.0.0:3001 -r http://0.0.0.0:3000/ -w ws://0.0.0.0:3000/ --kafka-bootstrap-servers localhost:29092 --kafka-topic stratus-events --kafka-client-id stratus-producer --kafka-security-protocol none > e2e_logs/importer.log &
else
RUST_BACKTRACE=1 RUST_LOG=info cargo ${CARGO_COMMAND} run {{release_flag}} --bin stratus --features dev -- --follower --perm-storage=rocks --rocks-path-prefix=temp_3001 --tokio-console-address=0.0.0.0:6669 --metrics-exporter-address=0.0.0.0:9001 -a 0.0.0.0:3001 -r http://0.0.0.0:3000/ -w ws://0.0.0.0:3000/ > e2e_logs/importer.log &
fi
# Wait for Stratus with follower flag to start
just _wait_for_stratus 3001
if [ "{{test}}" = "deploy" ]; then
just _log "Running deploy script"
cd utils/deploy
poetry install --no-root
for i in {1..5}; do
poetry run python3 ./deploy.py --current-leader 0.0.0.0:3000 --current-follower 0.0.0.0:3001 --auto-approve --log-file deploy_01.log
if [ $? -ne 0 ]; then
just _log "Deploy script failed"
exit 1
fi
just _log "Switching back roles..."
sleep 5
poetry run python3 ./deploy.py --current-leader 0.0.0.0:3001 --current-follower 0.0.0.0:3000 --auto-approve --log-file deploy_02.log
if [ $? -ne 0 ]; then
just _log "Deploy script failed"
exit 1
fi
sleep 5
done
just _log "Deploy script ran successfully"
exit 0
elif [ -d e2e/cloudwalk-contracts ]; then
(
cd e2e/cloudwalk-contracts/integration
npm install
npx hardhat test test/leader-follower-{{test}}.test.ts --bail --network stratus --show-stack-traces
if [ $? -ne 0 ]; then
just _log "Tests failed"
exit 1
else
just _log "Tests passed successfully"
exit 0
fi
)
fi
killport 3000 -s sigterm
killport 3001 -s sigterm
# E2E: Leader & Follower Down
e2e-leader-follower-down:
#!/bin/bash
# Kill Stratus
killport 3001 -s sigterm
killport 3000 -s sigterm
stratus_pid=$(pgrep -f 'stratus')
kill $stratus_pid
# Kill Kafka
docker-compose down
# Delete data contents
rm -rf ./temp_*
# Delete zeppelin directory
rm -rf ./e2e/cloudwalk-contracts/integration/.openzeppelin
# ------------------------------------------------------------------------------
# Hive tests
# ------------------------------------------------------------------------------
# Hive: Build Stratus image for hive task
hive-build-client:
docker build -f hive/clients/stratus/Dockerfile_base -t stratus_base .
# Hive: Execute test pipeline
hive:
if ! docker images | grep -q stratus_base; then \
just _log "Building Docker image..."; \
docker build -f hive/clients/stratus/Dockerfile_base -t stratus_base .; \
else \
just _log "Docker image already built."; \
fi
cd hive && go build .
cd hive && ./hive --client stratus --sim stratus/rpc --sim.parallelism 10
# cd hive && sudo ./hive --client stratus --sim stratus/rpc --sim.parallelism 10 --loglevel 5 --docker.output
# Hive: View test pipeline results in Hiveview
hiveview:
cd hive && go build ./cmd/hiveview
./hive/hiveview --serve --addr 0.0.0.0:8080 --logdir ./hive/workspace/logs/
# ------------------------------------------------------------------------------
# Contracts tasks
# ------------------------------------------------------------------------------
# Contracts: Clone Solidity repositories
contracts-clone *args="":
cd e2e/cloudwalk-contracts && ./contracts-clone.sh {{args}}
# Contracts: Compile selected Solidity contracts
contracts-compile:
cd e2e/cloudwalk-contracts && ./contracts-compile.sh
# Contracts: Flatten solidity contracts for integration test
contracts-flatten *args="":
cd e2e/cloudwalk-contracts && ./contracts-flatten.sh {{args}}
# Contracts: Test selected Solidity contracts on Stratus
contracts-test *args="":
cd e2e/cloudwalk-contracts && ./contracts-test.sh {{args}}
alias e2e-contracts := contracts-test
# Contracts: Remove all the cloned repositories
contracts-remove *args="":
cd e2e/cloudwalk-contracts && ./contracts-remove.sh {{args}}
# Contracts: Start Stratus and run contracts tests with InMemory storage
contracts-test-stratus *args="":
#!/bin/bash
just _log "Starting Stratus"
just run -a 0.0.0.0:3000 &
just _wait_for_stratus
just _log "Running E2E Contracts tests"
just e2e-contracts {{args}}
result_code=$?
just _log "Killing Stratus"
killport 3000 -s sigterm
exit $result_code
# Contracts: Start Stratus and run contracts tests with RocksDB storage
contracts-test-stratus-rocks *args="":
#!/bin/bash
just _log "Starting Stratus"
just run -a 0.0.0.0:3000 --perm-storage=rocks > stratus.log &
just _wait_for_stratus
just _log "Running E2E tests"
just e2e-contracts {{args}}
result_code=$?
just _log "Killing Stratus"
killport 3000 -s sigterm
exit $result_code
# Contracts: Run tests and generate coverage info. Use --html to open in browser.
contracts-coverage *args="":
cd e2e/cloudwalk-contracts && ./contracts-coverage.sh {{args}}
# Contracts: Erase coverage info
contracts-coverage-erase:
#!/bin/bash
cd e2e/cloudwalk-contracts/repos || exit 1
just _log "Erasing coverage info..."
rm -rf ./*/coverage && echo "Coverage info erased."
stratus-test-coverage output="":
just contracts-clone
cargo llvm-cov clean --workspace
# inmemory
CARGO_COMMAND="llvm-cov --no-report" just e2e-stratus automine
sleep 10
CARGO_COMMAND="llvm-cov --no-report" just e2e-stratus external
sleep 10
CARGO_COMMAND="llvm-cov --no-report" just e2e-clock-stratus
sleep 10
CARGO_COMMAND="llvm-cov --no-report" just contracts-test-stratus
sleep 10
# rocksdb
-rm -r data/rocksdb
CARGO_COMMAND="llvm-cov --no-report" just e2e-stratus-rocks automine
sleep 10
-rm -r data/rocksdb
CARGO_COMMAND="llvm-cov --no-report" just e2e-stratus-rocks external
sleep 10
-rm -r data/rocksdb
CARGO_COMMAND="llvm-cov --no-report" just e2e-clock-stratus-rocks
sleep 10
-rm -r data/rocksdb
CARGO_COMMAND="llvm-cov --no-report" just contracts-test-stratus-rocks
sleep 10
# other
CARGO_COMMAND="llvm-cov --no-report" cargo llvm-cov --no-report
sleep 10
-just contracts-clone --token
-just contracts-flatten --token
-rm -r temp_3000-rocksdb
-rm -r temp_3001-rocksdb
-docker compose down -v
CARGO_COMMAND="llvm-cov --no-report" just e2e-leader-follower-up kafka " "
sleep 10
-rm -r temp_3000-rocksdb
-rm -r temp_3001-rocksdb
CARGO_COMMAND="llvm-cov --no-report" just e2e-leader-follower-up deploy " "
sleep 10
-rm -r temp_3000-rocksdb
-rm -r temp_3001-rocksdb
CARGO_COMMAND="llvm-cov --no-report" just e2e-leader-follower-up brlc " "
sleep 10
-rm -r temp_3000-rocksdb
-rm -r temp_3001-rocksdb
CARGO_COMMAND="llvm-cov --no-report" just e2e-leader-follower-up change " "
sleep 10
-rm -r temp_3000-rocksdb
-rm -r temp_3001-rocksdb
CARGO_COMMAND="llvm-cov --no-report" just e2e-leader-follower-up miner " "
sleep 10
-rm -r temp_3000-rocksdb
-rm -r temp_3001-rocksdb
CARGO_COMMAND="llvm-cov --no-report" just e2e-leader-follower-up importer " "
sleep 10
cargo llvm-cov report {{output}}