-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathbench-e2e.nu
More file actions
1839 lines (1716 loc) · 75.4 KB
/
Copy pathbench-e2e.nu
File metadata and controls
1839 lines (1716 loc) · 75.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
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
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env nu
# Single-runner e2e benchmark harness.
# Shared build/cache/report helpers are sourced from tempo.nu; the replacement
# e2e topology stays isolated here.
source tempo.nu
const E2E_A_STATE_PATH = "/var/lib/schelk/a.json"
const E2E_B_STATE_PATH = "/var/lib/schelk/b.json"
const E2E_A_MOUNT = "/reth-bench-a"
const E2E_B_MOUNT = "/reth-bench-b"
const BENCH_SCHELK_SCRIPT = "bench-schelk.nu"
const E2E_VALIDATORS = "127.0.0.2:8000,127.0.0.3:8100"
const E2E_SEED = 42
const E2E_A_CPUS = "0-7,16-23"
const E2E_B_CPUS = "8-15,24-31"
const E2E_A_MEMORY = "60G"
const E2E_B_MEMORY = "60G"
const E2E_GAS_LIMIT = "1000000000000"
const E2E_RUNNER_METRICS_URL = "http://127.0.0.1:9100/metrics"
const E2E_BLOAT_TMP_DIR = "/reth-bench-a/.bench-tmp/e2e-local-init"
const TRACY_SAMPLING_HZ = 18999
const E2E_BLOAT_FREE_MARGIN_MIB = 51200
const E2E_BLOAT_IMPORT_WORKING_SET_MULTIPLIER = 7
const E2E_DEFAULT_BLOAT = 100
const E2E_LOCAL_RETH_ARGS = [
"--ipcdisable"
"--disable-discovery"
"--trusted-only"
"--tempo.bootnodes-endpoint" "none"
"--consensus.no-legacy-archive"
"--engine.share-execution-cache-with-payload-builder"
"--builder.enable-prewarming"
"--rpc.max-connections" "10000"
"--txpool.pending-max-count" "200000"
"--txpool.basefee-max-count" "200000"
"--txpool.queued-max-count" "200000"
"--txpool.max-pending-txns" "200000"
"--txpool.max-new-txns" "200000"
"--txpool.max-batch-size" "200000"
]
def merge-e2e-features [...features: string] {
$features
| each { |f| $f | split row "," }
| flatten
| each { |f| $f | str trim }
| where { |f| $f != "" }
| uniq
| str join ","
}
def tempo-node-help [tempo_bin: string] {
let result = (run-external $tempo_bin "node" "--help" | complete)
if $result.exit_code != 0 {
print $"Error: failed to inspect supported tempo node args for ($tempo_bin)"
if $result.stdout != "" { print $result.stdout }
if $result.stderr != "" { print $result.stderr }
exit $result.exit_code
}
[$result.stdout $result.stderr] | str join "\n"
}
def supported-node-arg-filter [tempo_bin: string, args: list<string>] {
let help = (tempo-node-help $tempo_bin)
mut supported = []
mut removed = []
mut skip_next_value = false
for arg in $args {
if $skip_next_value {
if not ($arg starts-with "--") {
$removed = ($removed | append $arg)
$skip_next_value = false
continue
}
$skip_next_value = false
}
if not ($arg starts-with "--") {
$supported = ($supported | append $arg)
continue
}
let key = ($arg | split row "=" | first)
if ($help | str contains $key) {
$supported = ($supported | append $arg)
} else {
print $"Skipping unsupported tempo node arg for ($tempo_bin): ($key)"
$removed = ($removed | append $arg)
if not ($arg | str contains "=") {
$skip_next_value = true
}
}
}
{ supported: $supported, removed: $removed }
}
def format-removed-node-arg-config [label: string, removed: list<string>] {
if ($removed | is-empty) {
""
} else {
$", ($label)-removed-args: `($removed | str join ' ')`"
}
}
def removed-node-args-label [removed: list<string>] {
if ($removed | is-empty) {
""
} else {
$removed | str join " "
}
}
def run-bench-schelk [...args: string] {
let result = (nu $BENCH_SCHELK_SCRIPT ...$args | complete)
if $result.stdout != "" { print $result.stdout }
if $result.stderr != "" { print $result.stderr }
if $result.exit_code != 0 {
error make { msg: $"bench-schelk failed: ($args | str join ' ')" }
}
}
def schelk-state [state_path: string] {
sudo cat $state_path | from json
}
def mark-schelk-dirty-at [state_path: string] {
if (has-schelk) {
run-bench-schelk "mark-dirty" $state_path
}
}
def validate-schelk-state [a_state_path: string, b_state_path: string] {
if (has-schelk) {
for state_path in [$a_state_path $b_state_path] {
if not ($state_path | path exists) {
print $"Error: schelk state file does not exist: ($state_path)"
exit 1
}
}
let a_state = (schelk-state $a_state_path)
let b_state = (schelk-state $b_state_path)
let a_dm_era = ($a_state | get --optional dm_era_name)
let b_dm_era = ($b_state | get --optional dm_era_name)
if $a_dm_era == null or $b_dm_era == null {
print "Error: schelk state files must include dm_era_name for parallel a/b instances."
print "Reinitialize schelk a and b with unique --dm-era-name values."
exit 1
}
if $a_dm_era == $b_dm_era {
print $"Error: schelk a/b state files use the same dm_era_name: ($a_dm_era)"
print "Reinitialize one side with a unique --dm-era-name before running e2e."
exit 1
}
let a_mount = ($a_state | get --optional mount_point)
let b_mount = ($b_state | get --optional mount_point)
if $a_mount != $E2E_A_MOUNT {
print $"Error: schelk a state mount_point is ($a_mount), expected ($E2E_A_MOUNT)"
exit 1
}
if $b_mount != $E2E_B_MOUNT {
print $"Error: schelk b state mount_point is ($b_mount), expected ($E2E_B_MOUNT)"
exit 1
}
if $a_mount == $b_mount {
print $"Error: schelk a/b state files use the same mount_point: ($a_mount)"
exit 1
}
}
}
def bench-restore-at [state_path: string, mount_point: string, datadir: string] {
if (has-schelk) {
run-bench-schelk "restore" $state_path $mount_point
} else {
print $"Restoring snapshot from ($datadir).virgin..."
rm -rf $datadir
^cp -a $"($datadir).virgin" $datadir
}
}
# Promote a specific schelk scratch volume as the new virgin baseline.
def bench-promote-at [state_path: string, datadir: string] {
if (has-schelk) {
print $"Promoting schelk scratch to virgin ($state_path)..."
run-bench-schelk "promote" $state_path
} else {
print $"Saving snapshot to ($datadir).virgin..."
rm -rf $"($datadir).virgin"
^cp -a $datadir $"($datadir).virgin"
}
}
def df-available-mib [path: string] {
let row = (^df -Pm $path | lines | skip 1 | first | split row --regex '\s+')
$row | get 3 | into int
}
def e2e-db-size-bytes [datadir: string] {
let paths = [
$"($datadir)/db"
$"($datadir)/static_files"
] | where { |path| $path | path exists }
if ($paths | is-empty) {
return 0
}
let result = (^du -sb ...$paths | complete)
if $result.exit_code != 0 {
if $result.stderr != "" { print $result.stderr }
return 0
}
$result.stdout
| lines
| each { |line| $line | split row --regex '\s+' | first | into int }
| math sum
}
def ensure-bloat-space [bloat: int] {
if $bloat <= 0 {
return
}
let import_working_set_mib = $bloat * $E2E_BLOAT_IMPORT_WORKING_SET_MULTIPLIER
let a_required_mib = $bloat + $import_working_set_mib + $E2E_BLOAT_FREE_MARGIN_MIB
let b_required_mib = $import_working_set_mib + $E2E_BLOAT_FREE_MARGIN_MIB
let requirements = [
{
mount: $E2E_A_MOUNT
required_mib: $a_required_mib
components: $"dump=($bloat) MiB, import-working-set=($import_working_set_mib) MiB, margin=($E2E_BLOAT_FREE_MARGIN_MIB) MiB"
}
{
mount: $E2E_B_MOUNT
required_mib: $b_required_mib
components: $"import-working-set=($import_working_set_mib) MiB, margin=($E2E_BLOAT_FREE_MARGIN_MIB) MiB"
}
]
print "Checking e2e bloat rebuild free space..."
print $" Bloat dump: ($bloat) MiB on ($E2E_A_MOUNT)"
print $" Import working set: ($import_working_set_mib) MiB per side; multiplier=($E2E_BLOAT_IMPORT_WORKING_SET_MULTIPLIER)x bloat for DB, ETL, static file, and trie writes"
print $" Free-space margin: ($E2E_BLOAT_FREE_MARGIN_MIB) MiB per side"
mut failed = false
for requirement in $requirements {
let available_mib = (df-available-mib $requirement.mount)
print $" ($requirement.mount): available=($available_mib) MiB required=($requirement.required_mib) MiB \(($requirement.components)\)"
if $available_mib < $requirement.required_mib {
$failed = true
}
}
if $failed {
print "Error: insufficient free space for e2e bloat snapshot rebuild"
for requirement in $requirements {
let available_mib = (df-available-mib $requirement.mount)
if $available_mib < $requirement.required_mib {
print $" ($requirement.mount) needs at least ($requirement.required_mib) MiB, has ($available_mib) MiB"
}
}
exit 1
}
}
def e2e-bloat-gib-to-mib [bloat: int] {
if $bloat == 0 {
return 0
}
if $bloat in [1 10 100] {
return ($bloat * 1000)
}
print "Error: --bloat must be one of: 0, 1, 10, 100"
exit 1
}
def e2e-validate-token-count [token_count: int] {
let available_token_count = ($TIP20_TOKEN_IDS | length)
if $token_count <= 0 {
print "Error: --token-count must be a positive integer"
exit 1
}
if $token_count > $available_token_count {
print $"Error: --token-count ($token_count) exceeds ($available_token_count) TIP20 token\(s\) available in state bloat"
exit 1
}
}
def validator-dirs-in-localnet [localnet_dir: string] {
ls $localnet_dir
| where type == "dir"
| get name
| where { |d| ($d | path basename) =~ '^\d+\.\d+\.\d+\.\d+:\d+$' }
}
def trusted-peers-from-localnet [localnet_dir: string] {
validator-dirs-in-localnet $localnet_dir | each { |d|
let addr = ($d | path basename)
let ip = ($addr | split row ":" | get 0)
let port = ($addr | split row ":" | get 1 | into int)
let identity = (open $"($d)/enode.identity" | str trim)
$"enode://($identity)@($ip):($port + 1)"
} | str join ","
}
def init-e2e-db [tempo_bin: string, genesis: string, datadir: string, bloat: int, bloat_file: string] {
print $"Initializing database at ($datadir)..."
let init_result = (run-external $tempo_bin "init" "--chain" $genesis "--datadir" $datadir | complete)
if $init_result.stdout != "" { print $init_result.stdout }
if $init_result.stderr != "" { print $init_result.stderr }
if $init_result.exit_code != 0 {
print $"Error: tempo init failed for ($datadir) with exit code ($init_result.exit_code)"
exit $init_result.exit_code
}
if $bloat > 0 {
print $"Loading state bloat into ($datadir)..."
let bloat_result = (run-external $tempo_bin "init-from-binary-dump" "--chain" $genesis "--datadir" $datadir $bloat_file | complete)
if $bloat_result.stdout != "" { print $bloat_result.stdout }
if $bloat_result.stderr != "" { print $bloat_result.stderr }
if $bloat_result.exit_code != 0 {
print $"Error: state bloat load failed for ($datadir) with exit code ($bloat_result.exit_code)"
exit $bloat_result.exit_code
}
}
}
def bench-save-e2e-meta [datadir: string, meta_dir: string, marker: record, genesis_files: list] {
mkdir $meta_dir
for pair in $genesis_files {
cp ($pair | first) $"($meta_dir)/($pair | last)"
}
let marker_path = $"($meta_dir)/marker.json"
$marker | insert initialized_at (date now | format date "%Y-%m-%dT%H:%M:%SZ") | to json | save -f $marker_path
print $"Bench marker written to ($marker_path)"
}
def e2e-snapshot-required-files [datadir: string] {
let meta_dir = $"($datadir)/($BENCH_META_SUBDIR)"
[
$"($meta_dir)/genesis.json"
$"($meta_dir)/trusted-peers.txt"
$"($meta_dir)/marker.json"
$"($datadir)/signing.key"
$"($datadir)/signing.share"
$"($datadir)/enode.key"
$"($datadir)/enode.identity"
$"($datadir)/db"
$"($datadir)/static_files"
]
}
def e2e-snapshot-missing-files [datadir: string] {
e2e-snapshot-required-files $datadir | where { |path| not ($path | path exists) }
}
def e2e-snapshot-ready [datadir: string] {
(e2e-snapshot-missing-files $datadir | length) == 0
}
def e2e-snapshots-ready [a_db: string, b_db: string] {
(e2e-snapshot-ready $a_db) and (e2e-snapshot-ready $b_db)
}
def e2e-snapshot-state-hardfork [datadir: string] {
let marker = (read-bench-marker $datadir)
if $marker == null {
return ""
}
let state_hardfork = ($marker | get -o state_hardfork | default "")
if $state_hardfork == "" {
return ""
}
normalize-hardfork $state_hardfork
}
def normalize-gas-limit [gas_limit: string] {
if $gas_limit == "" {
return ""
}
$gas_limit | into int | into string
}
def gas-limit-quantity [gas_limit: string] {
let normalized = (normalize-gas-limit $gas_limit)
if $normalized == "" {
return ""
}
$normalized | into int | format number | get lowerhex
}
def e2e-snapshot-state-gas-limit [datadir: string] {
let marker = (read-bench-marker $datadir)
if $marker != null {
let marker_gas_limit = ($marker | get -o gas_limit | default "")
if $marker_gas_limit != "" {
return (normalize-gas-limit $marker_gas_limit)
}
}
let genesis_path = $"($datadir)/($BENCH_META_SUBDIR)/genesis.json"
if ($genesis_path | path exists) {
let genesis_gas_limit = (open $genesis_path | get -o gasLimit | default "")
if $genesis_gas_limit != "" {
return (normalize-gas-limit $genesis_gas_limit)
}
}
""
}
def e2e-snapshot-state-general-gas-limit [datadir: string] {
let marker = (read-bench-marker $datadir)
if $marker != null {
let marker_general_gas_limit = ($marker | get -o general_gas_limit | default "")
if $marker_general_gas_limit != "" {
return (normalize-gas-limit $marker_general_gas_limit)
}
}
let genesis_path = $"($datadir)/($BENCH_META_SUBDIR)/genesis.json"
if ($genesis_path | path exists) {
let genesis_general_gas_limit = (open $genesis_path | get -o config.generalGasLimit | default "")
if $genesis_general_gas_limit != "" {
return (normalize-gas-limit $genesis_general_gas_limit)
}
}
""
}
def e2e-update-snapshot-genesis-marker [
datadir: string,
hardfork: string,
gas_limit: string,
general_gas_limit: string,
] {
let marker_path = $"($datadir)/($BENCH_META_SUBDIR)/marker.json"
mut marker = (open $marker_path)
if $hardfork != "" {
let fork = (normalize-hardfork $hardfork)
$marker = ($marker | upsert state_hardfork $fork)
}
if $gas_limit != "" {
$marker = ($marker | upsert gas_limit (normalize-gas-limit $gas_limit))
}
if $general_gas_limit != "" {
$marker = ($marker | upsert general_gas_limit (normalize-gas-limit $general_gas_limit))
} else {
$marker = ($marker | reject -o general_gas_limit)
}
$marker | to json | save -f $marker_path
}
def e2e-synthesize-genesis [
source_genesis: string,
target_genesis: string,
hardfork: string,
gas_limit: string,
general_gas_limit: string,
] {
let source = (open $source_genesis)
mut config = ($source | get config)
mut patch_labels = []
if $hardfork != "" {
let fork = (normalize-hardfork $hardfork)
for field in (hardfork-genesis-config-fields $fork) {
$config = ($config | upsert $field.name $field.value)
}
$patch_labels = ($patch_labels | append $"hardfork=($fork)")
}
if $general_gas_limit != "" {
let normalized_general_gas_limit = (normalize-gas-limit $general_gas_limit)
$config = ($config | upsert generalGasLimit ($normalized_general_gas_limit | into int))
$patch_labels = ($patch_labels | append $"general_gas_limit=($normalized_general_gas_limit)")
} else {
$config = ($config | reject -o generalGasLimit)
}
mut genesis = ($source | upsert config $config)
if $gas_limit != "" {
let normalized_gas_limit = (normalize-gas-limit $gas_limit)
$genesis = ($genesis | upsert gasLimit (gas-limit-quantity $normalized_gas_limit))
$patch_labels = ($patch_labels | append $"gas_limit=($normalized_gas_limit)")
}
let target_dir = ($target_genesis | path dirname)
mkdir $target_dir
$genesis | to json | save -f $target_genesis
let patch_label = if ($patch_labels | length) > 0 {
$patch_labels | str join ", "
} else {
"unchanged"
}
print $"Synthesized genesis \(($patch_label)\) at ($target_genesis)"
}
def e2e-regenesis [
tempo_bin: string,
genesis: string,
datadir: string,
hardfork: string,
gas_limit: string,
general_gas_limit: string,
] {
let target_hardfork = if $hardfork != "" { normalize-hardfork $hardfork } else { latest-tempo-hardfork }
let target_gas_limit = if $gas_limit != "" { normalize-gas-limit $gas_limit } else { "" }
let target_general_gas_limit = if $general_gas_limit != "" { normalize-gas-limit $general_gas_limit } else { "" }
let current_hardfork = (e2e-snapshot-state-hardfork $datadir)
let current_gas_limit = (e2e-snapshot-state-gas-limit $datadir)
let current_general_gas_limit = (e2e-snapshot-state-general-gas-limit $datadir)
let hardfork_matches = $current_hardfork == $target_hardfork
let gas_limit_matches = $target_gas_limit == "" or $current_gas_limit == $target_gas_limit
let general_gas_limit_matches = $current_general_gas_limit == $target_general_gas_limit
if $hardfork_matches and $gas_limit_matches and $general_gas_limit_matches {
mut matches = []
if $target_hardfork != "" {
$matches = ($matches | append $"state_hardfork=($target_hardfork)")
}
if $target_gas_limit != "" {
$matches = ($matches | append $"gas_limit=($target_gas_limit)")
}
if $target_general_gas_limit != "" {
$matches = ($matches | append $"general_gas_limit=($target_general_gas_limit)")
}
print $"Skipping tempo regenesis for ($datadir); marker already matches (($matches | str join ', '))"
return
}
let target_genesis = $"($datadir)/($BENCH_META_SUBDIR)/regenesis-target.json"
e2e-synthesize-genesis $genesis $target_genesis $target_hardfork $target_gas_limit $target_general_gas_limit
mut changes = []
if not $hardfork_matches {
$changes = ($changes | append $"state_hardfork=($current_hardfork) -> ($target_hardfork)")
}
if not $gas_limit_matches {
$changes = ($changes | append $"gas_limit=($current_gas_limit) -> ($target_gas_limit)")
}
if not $general_gas_limit_matches {
$changes = ($changes | append $"general_gas_limit=($current_general_gas_limit) -> ($target_general_gas_limit)")
}
print $"Running tempo regenesis for ($datadir): ($changes | str join ', ') with ($target_genesis)..."
let result = (run-external $tempo_bin "regenesis" "--chain" $target_genesis "--datadir" $datadir | complete)
if $result.stdout != "" { print $result.stdout }
if $result.stderr != "" { print $result.stderr }
if $result.exit_code != 0 {
print $"Error: tempo regenesis failed for ($datadir) with exit code ($result.exit_code)"
exit $result.exit_code
}
e2e-synthesize-genesis $"($datadir)/($BENCH_META_SUBDIR)/genesis.json" $"($datadir)/($BENCH_META_SUBDIR)/genesis.json" $target_hardfork $target_gas_limit $target_general_gas_limit
e2e-update-snapshot-genesis-marker $datadir $target_hardfork $target_gas_limit $target_general_gas_limit
rm $target_genesis
}
def derive-tracing-otlp [tracing_otlp: string] {
if $tracing_otlp == "" and ($env.GRAFANA_TEMPO? | default "" | str length) > 0 {
let base = ($env.GRAFANA_TEMPO | str trim --right --char '/')
return $"($base)/v1/traces"
}
if $tracing_otlp == "" and ($env.TEMPO_TELEMETRY_URL? | default "" | str length) > 0 {
let base = ($env.TEMPO_TELEMETRY_URL | str trim --right --char '/')
return $"($base)/opentelemetry/v1/traces"
}
$tracing_otlp
}
def systemd-scope-command [unit: string, cpus: string, memory: string, script: string] {
let can_scope = (^uname | str trim) == "Linux" and ((which systemd-run | length) > 0) and ($cpus != "" or $memory != "")
if not $can_scope {
return ["bash" "-lc" $script]
}
let memory_args = if $memory != "" { ["-p" $"MemoryMax=($memory)"] } else { [] }
mut telemetry_env_names = []
if ($env.TEMPO_TELEMETRY_URL? | default "" | str length) > 0 {
$telemetry_env_names = ($telemetry_env_names | append "TEMPO_TELEMETRY_URL")
}
if ($env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT? | default "" | str length) > 0 {
$telemetry_env_names = ($telemetry_env_names | append "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT")
}
let preserve_env_args = if ($telemetry_env_names | length) > 0 {
[$"--preserve-env=($telemetry_env_names | str join ',')"]
} else { [] }
let telemetry_env = ($telemetry_env_names | each { |name| $"--setenv=($name)" })
[
"sudo"
...$preserve_env_args
"systemd-run"
"--scope"
"--quiet"
"--collect"
"--same-dir"
"--unit" $unit
...$telemetry_env
...$memory_args
"bash"
"-lc"
$script
]
}
def taskset-command [cmd: list<string>, cpus: string] {
if $cpus != "" {
["taskset" "-c" $cpus ...$cmd]
} else {
$cmd
}
}
def start-e2e-local-node [
role: string,
phase: string,
tempo_bin: string,
args: list<string>,
env_prefix: string,
otel_attrs: string,
tracy_env_prefix: string,
samply: bool,
samply_args: list<string>,
results_dir: string,
cpus: string,
memory: string,
] {
let profile_label = $"($phase)-($role)"
let full_samply_args = if $samply {
$samply_args | append ["--save-only" "--presymbolicate" "--output" $"($results_dir)/profile-($profile_label).json.gz"]
} else { [] }
let pinned_cmd = taskset-command [$tempo_bin ...$args] $cpus
let node_cmd = wrap-samply $pinned_cmd $samply $full_samply_args
let node_cmd_str = ($node_cmd | str join " ")
let script = $"($env_prefix)($otel_attrs)($tracy_env_prefix)($node_cmd_str) 2>&1"
let unit_phase = ($phase | str replace -a "_" "-" | str replace -a "." "-")
let runner = (systemd-scope-command $"tempo-e2e-($role)-($unit_phase)" $cpus $memory $script)
print $"Starting local e2e validator ($role) for ($phase): ($runner | str join ' ')"
job spawn {
run-external ($runner | first) ...($runner | skip 1)
| lines
| each { |line| print $"[e2e-($phase)-($role)] ($line)" }
}
}
def build-e2e-consensus-args [node_dir: string, trusted_peers: string, port: int, consensus_ip: string] {
let addr = ($node_dir | path basename)
let inferred_ip = if ($addr | str contains ":") {
$addr | split row ":" | get 0
} else {
"0.0.0.0"
}
let ip = if $consensus_ip != "" { $consensus_ip } else { $inferred_ip }
let signing_key = $"($node_dir)/signing.key"
let signing_share = $"($node_dir)/signing.share"
let enode_key = $"($node_dir)/enode.key"
let signing_key_contents = (open --raw $signing_key | into binary)
let signing_key_is_encrypted = ($signing_key_contents | bytes starts-with 0x[61 67 65 2d 65 6e 63 72 79 70 74 69 6f 6e 2e 6f 72 67 2f])
let signing_secret_args = if $signing_key_is_encrypted {
["--consensus.secret" "<(printf '%s\\n' 'tempo-localnet-signing-key-secret')"]
} else {
[]
}
let execution_p2p_port = $port + 1
let metrics_port = $port + 2
let authrpc_port = $port + 3
let discv5_port = $port + 4
[
"--consensus.signing-key" $signing_key
...$signing_secret_args
"--consensus.signing-share" $signing_share
"--consensus.listen-address" $"($ip):($port)"
"--consensus.metrics-address" $"($ip):($metrics_port)"
"--trusted-peers" $trusted_peers
"--port" $"($execution_p2p_port)"
"--discovery.port" $"($execution_p2p_port)"
"--discovery.v5.port" $"($discv5_port)"
"--p2p-secret-key" $enode_key
"--authrpc.port" $"($authrpc_port)"
"--consensus.use-local-defaults"
"--consensus.bypass-ip-check"
]
}
def stop-e2e-processes-gracefully [] {
let pids = (find-tempo-pids)
if ($pids | length) > 0 {
print $"Stopping tempo processes: ($pids | str join ', ')"
}
for pid in $pids {
sudo kill -s 2 $pid
}
for pid in $pids {
mut wait = 0
while $wait < 30 {
if (ps | where pid == $pid | length) == 0 { break }
sleep 1sec
$wait = $wait + 1
}
if $wait >= 30 {
print $" Warning: PID ($pid) did not exit, sending SIGKILL"
sudo kill -s 9 $pid
sleep 1sec
}
}
if ("/tmp/reth.ipc" | path exists) {
rm --force /tmp/reth.ipc
}
}
def stop-tracy-capture [] {
print " Stopping tracy-capture..."
let capture_pids = (ps | where name =~ "tracy-capture" | get pid)
for pid in $capture_pids {
sudo kill -s 2 $pid
}
mut wait_tracy = 0
while $wait_tracy < 30 {
if (ps | where name =~ "tracy-capture" | length) == 0 { break }
sleep 1sec
$wait_tracy = $wait_tracy + 1
}
if $wait_tracy >= 30 {
print " Warning: tracy-capture did not exit, sending SIGKILL"
for pid in (ps | where name =~ "tracy-capture" | get pid) {
sudo kill -s 9 $pid
}
}
}
def wait-for-tracy-capture-exit [job_id: int, phase: string] {
print " Waiting for tracy-capture to exit and close trace..."
let result = (try {
job recv --tag 18999 --timeout 45sec
} catch {
null
})
if $result == null {
print $" Warning: tracy-capture job did not report completion for ($phase); killing job ($job_id)"
try { job kill $job_id } catch {}
return
}
let exit_code = ($result | get --optional exit_code | default 0)
if $exit_code != 0 {
print $" Warning: tracy-capture exited with code ($exit_code) for ($phase)"
}
}
def wait-for-samply-profile [] {
print " Waiting for samply to finish saving profile..."
mut wait = 0
while $wait < 120 {
if (ps | where name =~ "samply" | length) == 0 { break }
sleep 500ms
$wait = $wait + 1
}
if $wait >= 120 {
print " Warning: samply did not exit in time"
}
}
def stop-local-e2e-systemd-scopes [] {
if (^uname | str trim) != "Linux" or ((which systemctl | length) == 0) {
return
}
let units = (
bash -lc "systemctl list-units 'tempo-e2e-*.scope' --all --plain --no-legend 2>/dev/null | awk '{print $1}'"
| lines
| where { |unit| $unit != "" }
)
for unit in $units {
print $"Stopping stale local e2e scope: ($unit)"
sudo systemctl kill --kill-whom=all $unit | ignore
sudo systemctl reset-failed $unit | ignore
}
}
def cleanup-local-e2e-processes [] {
stop-local-e2e-systemd-scopes
stop-e2e-processes-gracefully
stop-tracy-capture
}
def chown-to-current-user [path: string] {
if (^uname | str trim) != "Linux" or not ($path | path exists) {
return
}
let uid = (id -u | str trim)
let gid = (id -g | str trim)
sudo chown -R $"($uid):($gid)" $path | ignore
}
def rpc-block-number [url: string] {
let result = (do { curl -sf $url -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' } | complete)
if $result.exit_code != 0 {
return null
}
let parsed = (try { $result.stdout | from json } catch { null })
if $parsed == null {
return null
}
let hex = ($parsed | get -o result | default "")
if $hex == "" {
return null
}
try { $hex | str replace "0x" "" | into int --radix 16 } catch { null }
}
def rpc-peer-count [url: string] {
let result = (do { curl -sf $url -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":1}' } | complete)
if $result.exit_code != 0 {
return null
}
let parsed = (try { $result.stdout | from json } catch { null })
if $parsed == null {
return null
}
let hex = ($parsed | get -o result | default "")
if $hex == "" {
return null
}
try { $hex | str replace "0x" "" | into int --radix 16 } catch { null }
}
def e2e-wait-for-rpc-online [url: string, max_attempts: int] {
mut attempt = 0
loop {
$attempt = $attempt + 1
if $attempt > $max_attempts {
print $" Timeout waiting for ($url)"
return false
}
let block = (rpc-block-number $url)
if $block != null {
print $" ($url) online \(block ($block)\)"
return true
}
if ($attempt mod 10) == 0 {
print $" Still waiting for ($url)... \(($attempt)s\)"
}
sleep 1sec
}
}
def e2e-wait-for-peers [url: string, min_peers: int, max_attempts: int] {
mut attempt = 0
loop {
$attempt = $attempt + 1
if $attempt > $max_attempts {
print $" Timeout waiting for ($url) to reach ($min_peers) peer\(s\)"
return false
}
let peers = (rpc-peer-count $url)
if $peers != null and $peers >= $min_peers {
print $" ($url) has ($peers) peer\(s\)"
return true
}
if ($attempt mod 10) == 0 {
let current = if $peers == null { "unknown" } else { $"($peers)" }
print $" ($url) peers: ($current)/($min_peers)... \(($attempt)s\)"
}
sleep 1sec
}
}
def e2e-wait-for-chain-advance [url: string, max_attempts: int] {
mut attempt = 0
mut start_block: int = -1
loop {
$attempt = $attempt + 1
if $attempt > $max_attempts {
print $" Timeout waiting for ($url) chain to advance"
return false
}
let block = (rpc-block-number $url)
if $block != null {
if $start_block == -1 {
$start_block = $block
print $" ($url) connected \(block ($block)\), waiting for chain to advance..."
} else if $block > $start_block {
print $" ($url) ready \(block ($start_block) -> ($block)\)"
return true
} else if ($attempt mod 10) == 0 {
print $" ($url) still at block ($block)... \(($attempt)s\)"
}
} else if ($attempt mod 10) == 0 {
print $" ($url) unavailable while waiting for chain advance... \(($attempt)s\)"
}
sleep 1sec
}
}
def init-local-e2e-side [
role: string,
state_path: string,
mount_point: string,
datadir: string,
node_dir: string,
generated_node_dir: string,
generated_genesis: string,
trusted_peers: string,
bloat: int,
bloat_file: string,
tempo_bin: string,
marker: record,
] {
let meta_dir = $"($datadir)/($BENCH_META_SUBDIR)"
let generated_trusted_peers = $"($LOCALNET_DIR)/e2e-local-init/trusted-peers.txt"
bench-clean-datadir $datadir
mkdir $datadir
mkdir $node_dir
init-e2e-db $tempo_bin $generated_genesis $datadir $bloat $bloat_file
for file in ["signing.key" "signing.share" "enode.key" "enode.identity"] {
cp $"($generated_node_dir)/($file)" $"($node_dir)/($file)"
}
$trusted_peers | save -f $generated_trusted_peers
bench-save-e2e-meta $datadir $meta_dir ($marker | insert validator_role $role) [[$generated_genesis "genesis.json"] [$generated_trusted_peers "trusted-peers.txt"]]
}
# Update the PR comment with current benchmark phase status.
# Requires BENCH_GH_TOKEN, BENCH_COMMENT_ID, BENCH_ACTOR, BENCH_JOB_URL,
# BENCH_CONFIG, and GITHUB_REPOSITORY environment variables.
def bench-update-pr-status [status: string] {
let comment_id = ($env | get -o BENCH_COMMENT_ID | default "")
let token = ($env | get -o BENCH_GH_TOKEN | default "")
if $comment_id == "" or $token == "" { return }
let repo = $env.GITHUB_REPOSITORY
let actor = ($env | get -o BENCH_ACTOR | default "")
let job_url = ($env | get -o BENCH_JOB_URL | default "")
let config = ($env | get -o BENCH_CONFIG | default "")
let body = $"cc @($actor)\n\n🚀 Benchmark started! [View job]\(($job_url)\)\n\n⏳ **Status:** ($status)\n\n($config)"
let payload = { body: $body } | to json
try {
^curl -sS -X PATCH $"https://api.github.com/repos/($repo)/issues/comments/($comment_id)" -H $"Authorization: token ($token)" -H "Accept: application/vnd.github+json" -d $payload | ignore
} catch {
print $"Warning: failed to update PR comment status"
}
}
def build-valscope-static-reports [
results_dir: string,
benchmark_id: string,
valscope_dir: string,
] {
let manifest = $"($valscope_dir)/apps/api/Cargo.toml"
if not ($manifest | path exists) {
print $"Error: ValScope API Cargo manifest not found at ($manifest)"
exit 1
}
let vm_url = ($env | get -o VICTORIAMETRICS_URL | default "")
let vlogs_url = ($env | get -o VICTORIALOGS_URL | default "")
if $vm_url == "" {
print "Error: VICTORIAMETRICS_URL is required to generate ValScope static reports"
exit 1
}
if $vlogs_url == "" {
print "Error: VICTORIALOGS_URL is required to generate ValScope static reports"
exit 1
}
print "Generating ValScope static reports with configured VM/VLogs datasources"
let out_dir = $"($results_dir)/valscope-static"
let web_dir = $"($valscope_dir)/apps/web"
let web_dist = $"($web_dir)/dist"
let npm_ci = (run-external "npm" "--prefix" $web_dir "ci" | complete)
if $npm_ci.stdout != "" { print $npm_ci.stdout }
if $npm_ci.stderr != "" { print $npm_ci.stderr }
if $npm_ci.exit_code != 0 {
print $"Error: ValScope web dependency install failed with exit code ($npm_ci.exit_code)"
exit $npm_ci.exit_code
}
let web_build = (run-external "npm" "--prefix" $web_dir "run" "build:static-report-app" | complete)
if $web_build.stdout != "" { print $web_build.stdout }
if $web_build.stderr != "" { print $web_build.stderr }
if $web_build.exit_code != 0 {
print $"Error: ValScope static web build failed with exit code ($web_build.exit_code)"
exit $web_build.exit_code
}
let result = (with-env { VICTORIAMETRICS_URL: $vm_url, VICTORIALOGS_URL: $vlogs_url } {
run-external "cargo" "run" "--manifest-path" $manifest "--bin" "valscope-bench-report" "--" "--results-dir" $results_dir "--out-dir" $out_dir "--web-dist" $web_dist "--benchmark-id" $benchmark_id | complete
})
if $result.stdout != "" { print $result.stdout }
if $result.stderr != "" { print $result.stderr }
if $result.exit_code != 0 {
if ($out_dir | path exists) { rm -rf $out_dir }
print $"Error: ValScope static report generation failed with exit code ($result.exit_code)"
exit $result.exit_code
}
}
def run-local-e2e-phase [run: record, ctx: record] {
let phase = $run.phase
print $"=== Starting local e2e phase: ($phase) ==="
let run_type = if ($phase | str starts-with "baseline") { "baseline" } else { "feature" }