-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathjustfile
More file actions
573 lines (460 loc) · 19.7 KB
/
justfile
File metadata and controls
573 lines (460 loc) · 19.7 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
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
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:123@0.0.0.0: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 binary="stratus" features="dev":
#!/bin/bash
cargo {{nightly_flag}} build {{release_flag}} --bin {{binary}} --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="" clippy-flags="-D warnings -A clippy::unwrap_used -A clippy::expect_used -A clippy::panic":
@just _lint "{{nightly-version}}" --check "{{ clippy-flags }}"
# 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: Check for unused dependencies
check-unused-deps nightly-version="":
#!/bin/bash
command -v cargo-udeps >/dev/null 2>&1 || { cargo +nightly{{nightly-version}} install cargo-udeps --version 0.1.59 --locked; }
cargo +nightly{{nightly-version}} udeps --all-targets
# 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}} run --bin stratus {{release_flag}} --features dev -- --leader {{args}}
# Bin: Stratus main service as leader
stratus-test *args="":
#!/bin/bash
source <(just coverage-env)
FEATURES="dev"
if [[ "{{args}}" =~ --use-rocksdb-replication ]]; then
FEATURES="dev,replication"
fi
echo "leader features: " $FEATURES
cargo build --features $FEATURES
cargo run --bin stratus --features $FEATURES -- --leader --rocks-cf-size-metrics-interval 30s {{args}} > stratus.log &
just _wait_for_stratus
# 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: Stratus main service as follower
stratus-follower-test *args="":
#!/bin/bash
source <(just coverage-env)
FEATURES="dev"
if [[ "{{args}}" =~ --use-rocksdb-replication ]]; then
FEATURES="dev,replication"
fi
echo "follower features: " $FEATURES
cargo build --features $FEATURES
LOCAL_ENV_PATH=config/stratus-follower.env.local cargo run --bin stratus --features $FEATURES -- --follower --rocks-cf-size-metrics-interval 30s {{args}} -a 0.0.0.0:3001 > stratus_follower.log &
just _wait_for_stratus 3001
# Bin: Download external RPC blocks and receipts to temporary storage
rpc-downloader *args="":
cargo {{nightly_flag}} run --bin rpc-downloader {{release_flag}} -- {{args}}
rpc-downloader-test *args="":
#!/bin/bash
source <(just coverage-env)
cargo build
cargo run --bin rpc-downloader -- {{args}} > rpc-downloader.log
# Bin: Import external RPC blocks from temporary storage to Stratus storage
importer-offline *args="":
cargo {{nightly_flag}} run --bin importer-offline {{release_flag}} --features dev -- {{args}}
importer-offline-test *args="":
#!/bin/bash
source <(just coverage-env)
cargo build
cargo run --bin importer-offline -- {{args}} --rocks-file-descriptors-limit=65536 > importer-offline.log
# ------------------------------------------------------------------------------
# Test tasks
# ------------------------------------------------------------------------------
# Test: run rust tests
test:
#!/bin/bash
mkdir -p target/llvm-cov/codecov
source <(just coverage-env)
cargo test
mkdir -p target/llvm-cov/codecov
cargo llvm-cov report --html --ignore-filename-regex data_migration.rs
cargo llvm-cov report --lcov --output-path target/llvm-cov/codecov/rust_tests.info --ignore-filename-regex data_migration.rs
# Test: Execute Rust doc tests
test-doc name="":
cargo test {{name}} --doc
# Runs tests with coverage and kills stratus after
run-test recipe="" *args="":
#!/bin/bash
echo "Running test {{recipe}}"
cargo llvm-cov clean --workspace
source <(just coverage-env)
just {{recipe}} {{args}}
result_code=$?
echo "Killing stratus"
killport 3000 -s sigterm
killport 3001 -s sigterm
echo "Sleeping for 10 seconds"
sleep 10
echo "Generating reports"
mkdir -p target/llvm-cov/codecov
cargo llvm-cov report --html --ignore-filename-regex data_migration.rs
cargo llvm-cov report --lcov --output-path target/llvm-cov/codecov/{{recipe}}.info --ignore-filename-regex data_migration.rs
exit $result_code
# ------------------------------------------------------------------------------
# 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
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi
done
# E2E: Execute admin password tests
e2e-admin-password:
#!/bin/bash
mkdir -p e2e_logs
cd e2e
npm install
for test in "enabled|test123" "disabled|"; do
IFS="|" read -r type pass <<< "$test"
just _log "Running admin password tests with password $type"
ADMIN_PASSWORD=$pass just stratus-test -a 0.0.0.0:3000
npx hardhat test test/admin/e2e-admin-password-$type.test.ts --network stratus
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi
killport 3000 -s sigterm
just _wait_for_stratus_finish
sleep 20
done
# E2E: Starts and execute Hardhat tests in Hardhat
e2e-hardhat block-mode="automine" test="":
#!/bin/bash
if [ -d e2e ]; then
cd e2e
fi
echo "-> Starting Hardhat"
BLOCK_MODE={{block-mode}} npx hardhat node &
echo "-> Waiting Hardhat to start"
wait-service --tcp localhost:8545 -- echo
echo "-> Running E2E tests"
if [ -z "{{test}}" ]; then
just e2e hardhat {{block-mode}} ""
elif [ -f "test/{{block-mode}}/{{test}}.test.ts" ]; then
BLOCK_MODE={{block-mode}} npx hardhat test test/{{block-mode}}/{{test}}.test.ts --network hardhat
else
just e2e hardhat {{block-mode}} "{{test}}"
fi
echo "-> Killing Hardhat"
killport 8545
# 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 stratus-test -a 0.0.0.0:3000 --block-mode {{block-mode}}
just _log "Running E2E tests"
if [[ {{block-mode}} =~ ^[0-9]+(ms|s)$ ]]; then
just e2e stratus interval "{{test}}"
else
just e2e stratus {{block-mode}} "{{test}}"
fi
# 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 stratus-test --block-mode 1s -a 0.0.0.0:3000
just _log "Validating block time"
./utils/block-time-check.sh
# 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-leader:
#!/bin/bash
echo "starting e2e-leader"
# Leader doesn't need block changes flag, only follower does
unset ENABLE_BLOCK_CHANGES_REPLICATION
RUST_BACKTRACE=1 RUST_LOG=info just stratus-test --block-mode 1s --rocks-path-prefix=temp_3000
e2e-follower test="brlc" use_block_changes_replication="false":
#!/bin/bash
if [ "{{use_block_changes_replication}}" = "true" ]; then
export ENABLE_BLOCK_CHANGES_REPLICATION=true
else
export ENABLE_BLOCK_CHANGES_REPLICATION=false
fi
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 just stratus-follower-test --rocks-path-prefix=temp_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
else
RUST_BACKTRACE=1 RUST_LOG=info just stratus-follower-test --rocks-path-prefix=temp_3001 -r http://0.0.0.0:3000/ -w ws://0.0.0.0:3000/
fi
_e2e-leader-follower-up-impl test="brlc" use_block_changes_replication="false":
#!/bin/bash
mkdir e2e_logs
# Start Stratus with leader flag
just e2e-leader
if [ "{{use_block_changes_replication}}" = "true" ]; then
export ENABLE_BLOCK_CHANGES_REPLICATION=true
else
export ENABLE_BLOCK_CHANGES_REPLICATION=false
fi
# Start Stratus with follower flag
just e2e-follower {{test}} {{use_block_changes_replication}}
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
# E2E: Leader & Follower Up
e2e-leader-follower-up test="brlc" use_block_changes_replication="false":
just _e2e-leader-follower-up-impl {{test}} {{use_block_changes_replication}}
just e2e-leader-follower-down
# 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
# E2E: RPC Downloader test
e2e-rpc-downloader:
#!/bin/bash
mkdir e2e_logs
just _log "Starting Stratus"
just stratus-test -a 0.0.0.0:3000
just _log "Starting PostgreSQL"
docker-compose up -d postgres
just _log "Running TestContractBalances tests"
just e2e stratus automine
just _log "Running RPC Downloader test"
just rpc-downloader-test --external-rpc http://localhost:3000/ --external-rpc-storage postgres://postgres:123@localhost:5432/stratus --metrics-exporter-address 0.0.0.0:9001
result_code_1=$?
just _log "Checking content of postgres"
pip install -r utils/check_rpc_downloader/requirements.txt
POSTGRES_DB=stratus POSTGRES_PASSWORD=123 ETH_RPC_URL=http://localhost:3000/ python utils/check_rpc_downloader/main.py --start 0
result_code_2=$?
just _log "Killing PostgreSQL"
docker-compose down postgres
just _log "Check result codes"
if [ $result_code_1 -ne 0 ] || [ $result_code_2 -ne 0 ]; then
exit 1
fi
# E2E Importer Offline
e2e-importer-offline:
#!/bin/bash
mkdir -p e2e_logs
rm -rf data/importer-offline-database-rocksdb
just _log "Starting Stratus"
just stratus-test -a 0.0.0.0:3000
just _log "Running TestContractBalances tests"
just e2e stratus automine
just _log "Starting PostgreSQL"
docker-compose up -d postgres
just _log "Running rpc downloader"
just rpc-downloader-test --external-rpc http://localhost:3000/ --external-rpc-storage postgres://postgres:123@localhost:5432/stratus --metrics-exporter-address 0.0.0.0:9001 --initial-accounts 0x70997970c51812dc3a010c7d01b50e0d17dc79c8,0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
just _log "Run importer-offline"
just importer-offline-test --external-rpc-storage postgres://postgres:123@localhost:5432/stratus --rocks-path-prefix=data/importer-offline-database --metrics-exporter-address 0.0.0.0:9002
just _log "Stratus for importer-offline"
just stratus-test -a 0.0.0.0:3001 --rocks-path-prefix=data/importer-offline-database --metrics-exporter-address 0.0.0.0:9002
just _wait_for_stratus 3001
just _log "Compare blocks of stratus and importer-offline"
cd utils/compare_block/
poetry install --no-root
poetry run python3 ./main.py http://localhost:3000 http://localhost:3001 1 --ignore timestamp
result_code=$?
just _log "Killing PostgreSQL"
docker-compose down postgres
exit $result_code
# ------------------------------------------------------------------------------
# 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:
cd e2e/cloudwalk-contracts && ./contracts-clone.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:
cd e2e/cloudwalk-contracts && ./contracts-remove.sh
# Contracts: Start Stratus and run contracts tests
contracts-test-stratus *args="":
#!/bin/bash
just _log "Starting Stratus"
just stratus-test -a 0.0.0.0:3000
just _log "Running E2E Contracts tests"
just e2e-contracts {{args}}
# E2E: Starts and execute Genesis tests in Stratus
e2e-genesis:
#!/bin/bash
mkdir -p e2e_logs
# Create config directory in e2e if it doesn't exist
mkdir -p e2e/config
just _log "Starting Stratus with genesis.local.json"
just stratus-test -a 0.0.0.0:3000 --genesis-path config/genesis.local.json --block-mode automine
just _log "Running Genesis tests"
cd e2e
npm install
npx hardhat test test/genesis/genesis.test.ts --network stratus
killport 3000 -s sigterm
coverage-env:
#!/usr/bin/env bash
COVERAGE_FLAGS=$(env -u RUSTFLAGS cargo llvm-cov show-env 2>/dev/null | grep "^RUSTFLAGS=" | cut -d"'" -f2)
CURRENT_RUSTFLAGS="${RUSTFLAGS:-}"
if ! echo "$CURRENT_RUSTFLAGS" | grep -F -- "$COVERAGE_FLAGS" > /dev/null; then \
cargo llvm-cov show-env --export-prefix 2>/dev/null | grep '^export '; \
fi