Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
1005 lines (882 loc) · 42.2 KB
/
Copy pathMakefile
File metadata and controls
1005 lines (882 loc) · 42.2 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
SHELL=/bin/bash
# Temp disabled for now until all tests are green
.SHELLFLAGS=-o pipefail -c
DEBUG_FLAGS=
TXMETA_TAG=
SETTINGS_CONTEXT_DEFAULT := docker.ci
LOCAL_TEST_START_FROM_STATE ?=
# Test retry configuration
TEST_RETRY_COUNT ?= 3
TEST_RETRY_DELAY ?= 2
# Get version from git using the shared script
# Use environment variables if set, otherwise use the script
ifndef GIT_VERSION
# Get git version variables directly from the script
GIT_VERSION := $(shell ./scripts/determine-git-version.sh --makefile | grep "^GIT_VERSION=" | cut -d'=' -f2)
GIT_COMMIT := $(shell ./scripts/determine-git-version.sh --makefile | grep "^GIT_COMMIT=" | cut -d'=' -f2)
GIT_SHA := $(shell ./scripts/determine-git-version.sh --makefile | grep "^GIT_SHA=" | cut -d'=' -f2)
GIT_TAG := $(shell ./scripts/determine-git-version.sh --makefile | grep "^GIT_TAG=" | cut -d'=' -f2)
GIT_TIMESTAMP := $(shell ./scripts/determine-git-version.sh --makefile | grep "^GIT_TIMESTAMP=" | cut -d'=' -f2)
endif
# Cross-compilation environment variables
# These can be overridden when calling make, e.g.: make build GOOS=linux GOARCH=amd64
CGO_ENABLED ?= 1
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
.PHONY: set_debug_flags
set_debug_flags:
ifeq ($(DEBUG),true)
$(eval DEBUG_FLAGS = -N -l)
endif
.PHONY: set_txmetacache_flag
set_txmetacache_flag:
ifeq ($(TXMETA_SMALL_TAG),true)
$(eval TXMETA_TAG = "smalltxmetacache")
else ifeq ($(TXMETA_TEST_TAG),true)
$(eval TXMETA_TAG = "testtxmetacache")
else
$(eval TXMETA_TAG = "largetxmetacache")
endif
.PHONY: all
all: deps install lint build test
.PHONY: deps
deps:
go mod download
.PHONY: dev
dev:
$(MAKE) dev-dashboard & $(MAKE) dev-teranode
.PHONY: dev-teranode
dev-teranode:
# Run go project
trap 'kill %1 %2' SIGINT; \
go run .
.PHONY: dev-dashboard
dev-dashboard:
# Run node project
trap 'kill %1 %2' SIGINT; \
npm install --prefix ./ui/dashboard && npm run dev --prefix ./ui/dashboard
.PHONY: build
# build-propagation-blaster build-aerospiketest build-blockassembly-blaster build-utxostore-blaster build-s3-blaster build-chainintegrity
build: update_config build-teranode-with-dashboard build-teranode-cli clean_backup
.PHONY: update_config
update_config:
ifeq ($(LOCAL_TEST_START_FROM_STATE),)
@echo "No LOCAL_TEST_START_FROM_STATE provided; using existing settings_local.conf"
else
@echo "Updating settings_local.conf with local_test_start_from_state=$(LOCAL_TEST_START_FROM_STATE)"
# Remove existing local_test_start_from_state line if it exists
# For macOS (BSD sed):
@sed -i '' '/^[[:space:]]*local_test_start_from_state[[:space:]]*=.*$$/d' settings_local.conf
# For Linux (GNU sed), comment out the above line and uncomment the following line:
# @sed -i '/^[[:space:]]*local_test_start_from_state[[:space:]]*=.*$$/d' settings_local.conf
# Append an empty line
@echo "" >> settings_local.conf
# Append the new local_test_start_from_state value
@echo "local_test_start_from_state = $(LOCAL_TEST_START_FROM_STATE)" >> settings_local.conf
endif
.PHONY: clean_backup
clean_backup:
@rm -f settings_local.conf.bak
.PHONY: build-teranode-with-dashboard
build-teranode-with-dashboard: set_debug_flags set_txmetacache_flag build-dashboard
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -mod=readonly -tags aerospike,${TXMETA_TAG} --trimpath -ldflags="-X main.commit=${GIT_COMMIT} -X main.version=${GIT_VERSION} -X main.StartFromState=${START_FROM_STATE}" -gcflags "all=${DEBUG_FLAGS}" -o teranode.run .
.PHONY: build-teranode
build-teranode: set_debug_flags set_txmetacache_flag
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -mod=readonly -tags aerospike,${TXMETA_TAG} --trimpath -ldflags="-X main.commit=${GIT_COMMIT} -X main.version=${GIT_VERSION}" -gcflags "all=${DEBUG_FLAGS}" -o teranode.run .
.PHONY: build-teranode-no-debug
build-teranode-no-debug: set_txmetacache_flag
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -mod=readonly -a -tags aerospike,${TXMETA_TAG} --trimpath -ldflags="-X main.commit=${GIT_COMMIT} -X main.version=${GIT_VERSION} -s -w" -gcflags "-l -B" -o teranode_no_debug.run .
.PHONY: build-teranode-ci
build-teranode-ci: set_debug_flags set_txmetacache_flag
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -mod=readonly -race -tags aerospike,${TXMETA_TAG} --trimpath -ldflags="-X main.commit=${GIT_COMMIT} -X main.version=${GIT_VERSION}" -gcflags "all=${DEBUG_FLAGS}" -o teranode.run .
.PHONY: build-chainintegrity
build-chainintegrity: set_debug_flags
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o chainintegrity.run ./compose/cmd/chainintegrity/
.PHONY: build-teranode-cli
build-teranode-cli:
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -mod=readonly -o teranode-cli ./cmd/teranodecli
.PHONY: build-teranode-dev
build-teranode-dev:
CGO_ENABLED=0 go build -o teranode-dev ./cmd/teranodedev
# .PHONY: build-propagation-blaster
# build-propagation-blaster: set_debug_flags
# go build --trimpath -ldflags="-X main.commit=${GITHUB_SHA} -X main.version=MANUAL" -gcflags "all=${DEBUG_FLAGS}" -o propagationblaster.run ./cmd/propagation_blaster/
# .PHONY: build-utxostore-blaster
# build-utxostore-blaster: set_debug_flags
# go build --trimpath -ldflags="-X main.commit=${GITHUB_SHA} -X main.version=MANUAL" -gcflags "all=${DEBUG_FLAGS}" -o utxostoreblaster.run ./cmd/utxostore_blaster/
# .PHONY: build-s3-blaster
# build-s3-blaster: set_debug_flags
# go build --trimpath -ldflags="-X main.commit=${GITHUB_SHA} -X main.version=MANUAL" -gcflags "all=${DEBUG_FLAGS}" -o s3blaster.run ./cmd/s3_blaster/
# .PHONY: build-blockassembly-blaster
# build-blockassembly-blaster: set_debug_flags
# go build --trimpath -ldflags="-X main.commit=${GITHUB_SHA} -X main.version=MANUAL" -gcflags "all=${DEBUG_FLAGS}" -o blockassemblyblaster.run ./cmd/blockassembly_blaster/main.go
# .PHONY: build-aerospiketest
# build-aerospiketest:
# go build -o aerospiketest.run ./cmd/aerospiketest/
.PHONY: build-dashboard
build-dashboard:
npm install --prefix ./ui/dashboard && npm run build --prefix ./ui/dashboard
# Generate a docker-compose stack for a multinode teranode network (3 <= N <= 10).
# Output is written to compose/generated/. Bring it up with:
# docker compose -f compose/generated/docker-compose-multinode.yml up -d
# Example: make gen-multinode N=5
.PHONY: gen-multinode
gen-multinode:
@test -n "$(N)" || { echo "usage: make gen-multinode N=<3..10>"; exit 2; }
go run ./compose/cmd/gennodes -n $(N) -o compose/generated
.PHONY: open-dashboards
open-dashboards:
@test -f compose/generated/open-dashboards.sh || { echo "run 'make gen-multinode N=<3..10>' first"; exit 2; }
@compose/generated/open-dashboards.sh
# Generate blocks on specific nodes. Usage: make generate-blocks ARGS="1,10 3,5"
.PHONY: generate-blocks
generate-blocks:
@test -f compose/generated/generate-blocks.sh || { echo "run 'make gen-multinode N=<3..10>' first"; exit 2; }
@compose/generated/generate-blocks.sh $(ARGS)
.PHONY: install-tools
install-tools:
go install github.com/ctrf-io/go-ctrf-json-reporter/cmd/go-ctrf-json-reporter@latest
go install gotest.tools/gotestsum@latest
.PHONY: test
test:
@command -v gotestsum >/dev/null 2>&1 || { echo "gotestsum not found. Installing..."; $(MAKE) install-tools; }
SETTINGS_CONTEXT=test $$(go env GOPATH)/bin/gotestsum --format pkgname -- -race -tags "testtxmetacache" -count=1 -timeout=10m -coverprofile=coverage.out -coverpkg=./... $$(go list ./... | grep -v github.com/bsv-blockchain/teranode/test/ | sort)
# run the tests too slow for `make test` under -race and coverage (TERANODE_HEAVY_TESTS), without -race.
# The PR test job runs it after `make test`.
.PHONY: test-heavy
test-heavy:
SETTINGS_CONTEXT=test TERANODE_HEAVY_TESTS=1 go test -tags "testtxmetacache" -count=1 -timeout=10m -run '^(TestSortedHashSet_|Test_queueLarge$$|TestDiskTxMap_(ExistenceLayerThroughput|ThroughputTarget|MultiDiskThroughput)$$|TestSubtreeProcessorSizePerformance$$|TestDirectSubtreeCreationPerformance$$|TestOverheadBreakdownDetailed$$)' ./services/blockassembly/subtreeprocessor
# run tagged service regressions and tests in the test/longtest directory
.PHONY: longtest
longtest:
@command -v gotestsum >/dev/null 2>&1 || { echo "gotestsum not found. Installing..."; $(MAKE) install-tools; }
SETTINGS_CONTEXT=test gotestsum --format pkgname -- -race -tags "testtxmetacache longtest" -count=1 -timeout=10m -run '^TestLegacyHistoricalTestnetSync$$' ./services/legacy/netsync
$(MAKE) test-heavy
SETTINGS_CONTEXT=test gotestsum --format pkgname -- -race -tags "testtxmetacache" -count=1 -timeout=10m -coverprofile=coverage.out ./test/longtest/... 2>&1 | grep -v "ld: warning:"
# run the soak test: the in-process daemon under steady tx load for SOAK_DURATION, failing if heap or goroutine
# counts trend upward. No -race: the detector skews memory and throughput, which is what this test measures.
# SOAK_TIMEOUT must exceed SOAK_DURATION by at least 10m. Other knobs (SOAK_WARMUP, SOAK_SAMPLE_INTERVAL,
# SOAK_TXS_PER_CYCLE, SOAK_UTXO_STORE, SOAK_OUTPUT_DIR, SOAK_INJECT_LEAK) are read from the environment.
# Example: make soaktest SOAK_DURATION=2h SOAK_TIMEOUT=150m
SOAK_DURATION ?= 30m
SOAK_TIMEOUT ?= 60m
.PHONY: soaktest
soaktest:
SETTINGS_CONTEXT=test SOAK_DURATION=$(SOAK_DURATION) go test -v -count=1 -tags "soak testtxmetacache" -timeout=$(SOAK_TIMEOUT) -run '^TestSoakSteadyLoad$$' ./test/soak/...
# run tests in the test/sequentialtest directory in order, one by one
# Environment variables:
# TEST_RETRY_COUNT - Number of retry attempts for failed tests (default: 3)
# TEST_RETRY_DELAY - Delay between retries in seconds (default: 2)
# Example: make sequentialtest TEST_RETRY_COUNT=5 TEST_RETRY_DELAY=3
.PHONY: sequentialtest
sequentialtest:
@mkdir -p /tmp/teranode-test-results
TEST_RETRY_COUNT=$(TEST_RETRY_COUNT) TEST_RETRY_DELAY=$(TEST_RETRY_DELAY) logLevel=INFO test/scripts/run_tests_sequentially.sh 2>&1 | tee /tmp/teranode-test-results/sequentialtest-results.txt
# run sequential tests for specific database backends
.PHONY: sequentialtest-sqlite
sequentialtest-sqlite:
@mkdir -p /tmp/teranode-test-results
TEST_RETRY_COUNT=$(TEST_RETRY_COUNT) TEST_RETRY_DELAY=$(TEST_RETRY_DELAY) logLevel=INFO test/scripts/run_tests_sequentially.sh --db sqlite 2>&1 | tee /tmp/teranode-test-results/sequentialtest-sqlite-results.txt
.PHONY: sequentialtest-postgres
sequentialtest-postgres:
@mkdir -p /tmp/teranode-test-results
TEST_RETRY_COUNT=$(TEST_RETRY_COUNT) TEST_RETRY_DELAY=$(TEST_RETRY_DELAY) logLevel=INFO test/scripts/run_tests_sequentially.sh --db postgres 2>&1 | tee /tmp/teranode-test-results/sequentialtest-postgres-results.txt
.PHONY: sequentialtest-aerospike
sequentialtest-aerospike:
@mkdir -p /tmp/teranode-test-results
TEST_RETRY_COUNT=$(TEST_RETRY_COUNT) TEST_RETRY_DELAY=$(TEST_RETRY_DELAY) logLevel=INFO test/scripts/run_tests_sequentially.sh --db aerospike 2>&1 | tee /tmp/teranode-test-results/sequentialtest-aerospike-results.txt
.PHONY: sequentialtest-shard
sequentialtest-shard:
@mkdir -p /tmp/teranode-test-results
TEST_RETRY_COUNT=$(TEST_RETRY_COUNT) TEST_RETRY_DELAY=$(TEST_RETRY_DELAY) logLevel=INFO \
test/scripts/run_tests_sequentially.sh --shard $(SHARD) --total $(TOTAL) 2>&1 \
| tee /tmp/teranode-test-results/sequentialtest-shard-$(SHARD)-results.txt
.PHONY: testall
testall: test longtest sequentialtest
# Fuzz targets as "package:FuzzTarget" pairs. Keep in sync with the matrix in
# .github/workflows/fuzz.yaml, which fuzzes the same list nightly with a larger
# budget.
#
# A Go fuzz target only mutates inputs when invoked with -fuzz. Under `make
# test` these same functions merely replay their committed seed corpus as
# ordinary table tests, so they can never find a new crashing input - running
# them here is the only way to actually fuzz them locally.
FUZZ_TARGETS = \
model:FuzzNewBlockFromBytes \
model:FuzzReadBlockFromReader \
model:FuzzDiskParentSpendsMap_Parity \
model:FuzzDecodeSubtreeMetaBody \
pkg/fileformat:FuzzHeaderParsersAgree \
pkg/fileformat:FuzzReadHeaderFromBytes \
services/utxopersister:FuzzUTXOWrapperFromBytes \
services/legacy/peer:FuzzReadWireMessage \
services/legacy/peer:FuzzStreamingBlockFraming \
services/rpc/bsvjson:FuzzParseRPCRequest \
services/rpc/bsvjson:FuzzUnmarshalCmd
# Per-target budget. The nightly workflow uses 5m; the default here is kept
# short so `make fuzz` is usable as a pre-push check.
FUZZTIME ?= 30s
# Minimization is unbounded by default, which can outlast the budget and hide
# the crasher. Cap it so a hit is always written out.
FUZZMINIMIZETIME ?= 60s
# Fuzz every target in FUZZ_TARGETS, stopping at the first crasher.
# A discovered input is written to <package>/testdata/fuzz/<Target>/<hash>
# along with a `go test -run=<Target>/<hash>` reproducer.
# Example: make fuzz FUZZTIME=5m
.PHONY: fuzz
fuzz:
@for t in $(FUZZ_TARGETS); do \
pkg=$${t%%:*}; target=$${t##*:}; \
echo "==> $$target ($$pkg), $(FUZZTIME)"; \
go test -run='^$$' -fuzz="^$$target$$" -fuzztime=$(FUZZTIME) \
-fuzzminimizetime=$(FUZZMINIMIZETIME) ./$$pkg/ || exit 1; \
done
# run tests in the test/e2e/daemon directory
# Tests run in parallel by default - each test gets unique ports and data directories
# Environment variables:
# TEST_RETRY_COUNT - Number of retry attempts for failed tests (default: 3, set to 1 to disable retries)
# TEST_RETRY_DELAY - Delay between retries in seconds (default: 2)
# Example: make smoketest TEST_RETRY_COUNT=5
# Note: With retries enabled, timeout is increased to 20m to accommodate retry attempts
.PHONY: smoketest
smoketest:
@command -v gotestsum >/dev/null 2>&1 || { echo "gotestsum not found. Installing..."; $(MAKE) install-tools; }
@mkdir -p /tmp/teranode-test-results
@RUN_ARG='.'; \
if [ -n "$(TOTAL)" ]; then \
RUN_ARG="$$(test/scripts/list_test_shard.sh test/e2e/daemon/ready $(SHARD) $(TOTAL) 'TestLegacySync|TestSVNodeSync|TestBidirectionalSync|TestSVNodeValidates|TestMultistreamLegacySync|TestMultistreamSVNodeSyncFromTeranode|TestMultistreamBackwardCompatibility|TestMultistreamDisabledRejectsConnection|TestMultistreamMixedPeers|TestMultistreamOnlyStandardPeer|TestMultistreamOnlyMultistreamPeer|TestMultistreamLongestChainSelection|TestBlobDeletion|TestPruner|TestShouldAllowSubmitMiningSolutionUsingMiningCandidateFromRPC|TestShouldRejectOversizedTx|TestLegacyTxBroadcast942_TeranodeRPCToSVMempool')"; \
fi; \
if [ "$(TEST_RETRY_COUNT)" != "1" ]; then \
echo "Running smoketest with retry support (TEST_RETRY_COUNT=$(TEST_RETRY_COUNT))"; \
cd test/e2e/daemon/ready && TEST_RETRY_COUNT=$(TEST_RETRY_COUNT) TEST_RETRY_DELAY=$(TEST_RETRY_DELAY) ../../../../test/scripts/gotestsum_with_retry.sh --format pkgname -- -v -count=1 -race -timeout=20m -parallel 1 -skip 'TestLegacySync|TestSVNodeSync|TestBidirectionalSync|TestSVNodeValidates|TestMultistreamLegacySync|TestMultistreamSVNodeSyncFromTeranode|TestMultistreamBackwardCompatibility|TestMultistreamDisabledRejectsConnection|TestMultistreamMixedPeers|TestMultistreamOnlyStandardPeer|TestMultistreamOnlyMultistreamPeer|TestMultistreamLongestChainSelection|TestBlobDeletion|TestPruner|TestShouldAllowSubmitMiningSolutionUsingMiningCandidateFromRPC|TestShouldRejectOversizedTx|TestLegacyTxBroadcast942_TeranodeRPCToSVMempool' -run "$$RUN_ARG" 2>&1 | tee /tmp/teranode-test-results/smoketest-results.txt; \
else \
echo "Running smoketest without retry (TEST_RETRY_COUNT=1)"; \
cd test/e2e/daemon/ready && gotestsum --format pkgname -- -v -count=1 -race -timeout=10m -parallel 1 -skip 'TestLegacySync|TestSVNodeSync|TestBidirectionalSync|TestSVNodeValidates|TestMultistreamLegacySync|TestMultistreamSVNodeSyncFromTeranode|TestMultistreamBackwardCompatibility|TestMultistreamDisabledRejectsConnection|TestMultistreamMixedPeers|TestMultistreamOnlyStandardPeer|TestMultistreamOnlyMultistreamPeer|TestMultistreamLongestChainSelection|TestBlobDeletion|TestPruner|TestShouldAllowSubmitMiningSolutionUsingMiningCandidateFromRPC|TestShouldRejectOversizedTx|TestLegacyTxBroadcast942_TeranodeRPCToSVMempool' -run "$$RUN_ARG" 2>&1 | tee /tmp/teranode-test-results/smoketest-results.txt; \
fi
# run pruner e2e tests - heavyweight tests that mine blocks and verify pruning behavior
.PHONY: prunertest
prunertest:
@command -v gotestsum >/dev/null 2>&1 || { echo "gotestsum not found. Installing..."; $(MAKE) install-tools; }
@mkdir -p /tmp/teranode-test-results
cd test/e2e/daemon/ready && gotestsum --format pkgname -- -v -count=1 -race -timeout=15m -parallel 1 -run 'TestBlobDeletion|TestPruner' 2>&1 | tee /tmp/teranode-test-results/prunertest-results.txt
# run legacy sync tests - tests teranode syncing with legacy svnode
# Note: TestMultistreamLongestChainSelection skipped due to race condition in Kafka producer
.PHONY: legacy-sync
legacy-sync:
@command -v gotestsum >/dev/null 2>&1 || { echo "gotestsum not found. Installing..."; $(MAKE) install-tools; }
@mkdir -p /tmp/teranode-test-results
cd test/e2e/daemon/ready && gotestsum --format pkgname -- -v -count=1 -race -timeout=15m -run 'TestLegacySync|TestSVNodeSync|TestBidirectionalSync|TestSVNodeValidates|TestMultistreamLegacySync|TestMultistreamSVNodeSyncFromTeranode|TestMultistreamBackwardCompatibility|TestMultistreamDisabledRejectsConnection|TestMultistreamMixedPeers|TestMultistreamOnlyStandardPeer|TestMultistreamOnlyMultistreamPeer|TestBIP68|TestLegacyTxBroadcast942_TeranodeRPCToSVMempool' 2>&1 | tee /tmp/teranode-test-results/legacy-sync-results.txt
# run chain integrity tests - multi-node tests with deep chain verification
# This test mines blocks across multiple nodes and verifies chain consistency
.PHONY: chainintegrity
chainintegrity:
@command -v gotestsum >/dev/null 2>&1 || { echo "gotestsum not found. Installing..."; $(MAKE) install-tools; }
@mkdir -p /tmp/teranode-test-results
cd test/e2e/chainintegrity && gotestsum --format pkgname -- -v -count=1 -race -timeout=35m -run . 2>&1 | tee /tmp/teranode-test-results/chainintegrity-results.txt
.PHONY: network-chaos-test
network-chaos-test:
@command -v gotestsum >/dev/null 2>&1 || { echo "gotestsum not found. Installing..."; $(MAKE) install-tools; }
@docker image inspect teranode:latest >/dev/null 2>&1 || { echo "teranode:latest image not found. Run 'make build' (or 'compose/multinode.sh up N --build') first."; exit 1; }
@mkdir -p /tmp/teranode-test-results
cd test/multinode && gotestsum --format pkgname -- -v -count=1 -tags network_chaos -timeout=30m -parallel=1 -run . 2>&1 | tee /tmp/teranode-test-results/network-chaos-results.txt
# Split-per-service variant of the network-chaos suite. Brings up its own
# -allinone=0 stack (~32 containers) so per-service chaos verbs are available.
# Kept separate from network-chaos-test because the two stacks cannot coexist
# and the split topology takes materially longer to start.
.PHONY: network-chaos-test-split
network-chaos-test-split:
@command -v gotestsum >/dev/null 2>&1 || { echo "gotestsum not found. Installing..."; $(MAKE) install-tools; }
@docker image inspect teranode:latest >/dev/null 2>&1 || { echo "teranode:latest image not found. Run 'make build' (or 'compose/multinode.sh up N --build') first."; exit 1; }
@mkdir -p /tmp/teranode-test-results
cd test/multinode_split && gotestsum --format pkgname -- -v -count=1 -tags network_chaos -timeout=40m -parallel=1 -run . 2>&1 | tee /tmp/teranode-test-results/network-chaos-split-results.txt
.PHONY: nightly-tests
nightly-tests:
docker compose -f docker-compose.ci.build.yml build
$(MAKE) install-tools
cd $(test_dir) && SETTINGS_CONTEXT=$(or $(settings_context),$(SETTINGS_CONTEXT_DEFAULT)) go test -v -tags $(test_tags) -json | go-ctrf-json-reporter -output ../../$(report_name) --verbose
# cd $(TEST_DIR) && SETTINGS_CONTEXT=docker.ci go test -json | go-ctrf-json-reporter -output ../../$(REPORT_NAME) --verbose
BENCH_PACKAGES = \
./errors \
./model \
./services/blockassembly \
./services/blockassembly/mining \
./services/blockassembly/subtreeprocessor \
./services/blockchain/work \
./services/blockpersister \
./services/blockvalidation \
./services/legacy/bsvec \
./services/legacy/bsvutil/hdkeychain \
./services/legacy/netsync \
./services/legacy/peer \
./services/subtreevalidation \
./services/validator \
./stores/blob/null \
./stores/blockchain/options \
./stores/blockchain/sql \
./stores/txmetacache \
./stores/utxo \
./stores/utxo/meta \
./test/consensus \
./ulogger \
./util \
./util/health \
./util/servicemanager \
./util/usql
BENCH_FLAGS = -bench=. -benchmem -benchtime=1s -short -timeout=30m -count=2 -run='^$$' -tags "testtxmetacache"
.PHONY: bench-test
bench-test:
go test $(BENCH_FLAGS) $(BENCH_PACKAGES)
.PHONY: bench-local-compare
bench-local-compare:
@command -v benchstat >/dev/null 2>&1 || { echo "Installing benchstat..."; go install golang.org/x/perf/cmd/benchstat@latest; }
go build -o /tmp/bench-compare ./cmd/compare-benchmarks
@echo "=== Run 1 (baseline) ==="
go test $(BENCH_FLAGS) $(BENCH_PACKAGES) | tee /tmp/bench-run1.txt
@echo "=== Run 2 (current) ==="
go test $(BENCH_FLAGS) $(BENCH_PACKAGES) | tee /tmp/bench-run2.txt
@echo "=== Comparing (benchstat with p-value) ==="
/tmp/bench-compare -baseline /tmp/bench-run1.txt -current /tmp/bench-run2.txt -output /tmp/bench-local-report.md -threshold 10.0 -alpha 0.05
@cat /tmp/bench-local-report.md
reset-data:
unzip data.zip
chmod -R u+w data
.PHONY: gen
gen:
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
model/model.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
errors/error.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
stores/utxo/status.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/validator/validator_api/validator_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/propagation/propagation_api/propagation_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/blockassembly/blockassembly_api/blockassembly_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/blockvalidation/blockvalidation_api/blockvalidation_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/subtreevalidation/subtreevalidation_api/subtreevalidation_api.proto
# protoc \
# --proto_path=. \
# --go_out=. \
# --go_opt=paths=source_relative \
# --go-grpc_out=. \
# --go-grpc_opt=paths=source_relative \
# services/txmeta/txmeta_api/txmeta_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/blockchain/blockchain_api/blockchain_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/asset/asset_api/asset_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/alert/alert_api/alert_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/legacy/peer_api/peer_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/p2p/p2p_api/p2p_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
services/pruner/pruner_api/pruner_api.proto
protoc \
--proto_path=. \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
util/kafka/kafka_message/kafka_messages.proto
.PHONY: clean_gen
clean_gen:
rm -f ./services/blockassembly/blockassembly_api/*.pb.go
rm -f ./services/blockvalidation/blockvalidation_api/*.pb.go
rm -f ./services/subtreevalidation/subtreevalidation_api/*.pb.go
rm -f ./services/validator/validator_api/*.pb.go
rm -f ./services/propagation/propagation_api/*.pb.go
# rm -f ./services/txmeta/txmeta_api/*.pb.go
rm -f ./services/blockchain/blockchain_api/*.pb.go
rm -f ./services/asset/asset_api/*.pb.go
rm -f ./services/coinbase/coinbase_api/*.pb.go
rm -f ./services/legacy/peer_api/*.pb.go
rm -f ./services/p2p/p2p_api/*.pb.go
rm -f ./services/pruner/pruner_api/*.pb.go
rm -f ./model/*.pb.go
rm -f ./errors/*.pb.go
rm -f ./stores/utxo/*.pb.go
.PHONY: clean
clean:
rm -f ./teranode_*.tar.gz
rm -rf build/
rm -f coverage.out
.PHONY: install-lint
install-lint:
brew install golangci-lint
brew install staticcheck
# lint will check the changed files in the current branch compared to main, including commits and unstaged/untracked changes
# It will show new linting errors/warnings, by updating local copy of origin/main with the latest state of the remote main branch.
.PHONY: lint
lint: lint-tracing-info
git fetch origin main
golangci-lint run ./... --new-from-rev origin/main --disable gosec --disable prealloc # TODO: re-enable gosec once gosec >v2.23.0 is released (fixes float constant panic)
# tracing.WithLogMessage logs at INFO on span start AND again on span end, so each
# call site costs two INFO lines per operation. Sites on per-transaction,
# per-subtree or per-request paths belong on tracing.WithDebugLogMessage instead.
# This gate pins that count exactly, so it ratchets both ways: adding a site
# fails, and so does removing one without lowering the number here. Otherwise a
# demotion would free a slot that a later INFO site could take unnoticed.
# Change TRACING_INFO_SITES in the same commit as the site, and say why.
# Only production code counts: test files are excluded so that deleting a test
# cannot silently free a slot for a new production INFO site.
TRACING_INFO_SITES := 59
.PHONY: lint-tracing-info
lint-tracing-info:
@count=$$(git grep -oh "tracing\.WithLogMessage(" -- '*.go' ':!*_test.go' ':!test/**' | wc -l | tr -d ' '); \
if [ "$$count" -lt 1 ]; then \
echo "lint-tracing-info: counted $$count sites, which cannot be right."; \
echo "Either the count command failed (not a git checkout, or git grep"; \
echo "unavailable) or tracing.WithLogMessage was renamed and this gate needs"; \
echo "updating. Failing rather than passing silently."; \
exit 1; \
fi; \
if [ "$$count" -gt "$(TRACING_INFO_SITES)" ]; then \
echo "tracing.WithLogMessage sites: $$count (expected $(TRACING_INFO_SITES))"; \
echo "Each is two INFO lines per operation. Use tracing.WithDebugLogMessage on"; \
echo "per-tx/per-subtree/per-request paths, or raise TRACING_INFO_SITES deliberately."; \
exit 1; \
elif [ "$$count" -lt "$(TRACING_INFO_SITES)" ]; then \
echo "tracing.WithLogMessage sites: $$count (expected $(TRACING_INFO_SITES))"; \
echo "A site was removed or demoted. Lower TRACING_INFO_SITES to $$count in the"; \
echo "same change, so the freed slot cannot be reused by a new INFO site."; \
exit 1; \
else \
echo "tracing.WithLogMessage sites: $$count (expected $(TRACING_INFO_SITES)) OK"; \
fi
# lint-new will only check only your unstaged/untracked changes (not committed changes), or fallback to check last commit if no changes in checkout
# It is useful for quickly checking that your current, uncommitted work doesn't introduce new lint errors.
.PHONY: lint-new
lint-new:
golangci-lint run ./... --new --disable gosec --disable prealloc # TODO: re-enable gosec once gosec >v2.23.0 is released (fixes float constant panic)
# lint-full will check all files in the project
# It will show all lint errors and warnings.
.PHONY: lint-full
lint-full:
golangci-lint run ./... --disable gosec --disable prealloc # TODO: re-enable gosec once gosec >v2.23.0 is released (fixes float constant panic)
# lint-full-changed-dirs will check the files that have been added/modified in the current branch compared to base main, including unstaged/untracked changes
# It will show all lint errors and warnings.
.PHONY: lint-full-changed-dirs
lint-full-changed-dirs:
@base_commit=$$(git merge-base main HEAD); \
echo "Using base commit $$base_commit for diffing"; \
changed_dirs=$$(git diff --name-only $$base_commit HEAD | grep '\.go$$' | xargs -I{} dirname {} | sort -u); \
if [ -z "$$changed_dirs" ]; then \
echo "No changed Go files found."; \
else \
echo "Linting packages in the following directories:"; \
echo "$$changed_dirs"; \
golangci-lint run --disable gosec --disable prealloc $$changed_dirs; \
fi
# The install target installs all dependencies needed for development.
# Dependencies are categorized as:
# - Core: Required for all development tasks (protobuf tools)
# - Build: Required for specific build operations (libtool, autoconf, automake)
# - Quality: Tools for code quality (linting)
# - Workflow: Required for team collaboration (git hooks)
.PHONY: install
install:
# Quality tools (optional but recommended)
$(MAKE) install-lint
# Core dependencies (required for gRPC service development)
brew install protobuf
brew install protoc-gen-go
brew install protoc-gen-go-grpc
# Build dependencies (required for certain native code components)
brew install libtool
brew install autoconf
brew install automake
# Workflow tools (required for team collaboration)
brew install pre-commit
pre-commit install
.PHONY: generate_fsm_diagram
generate_fsm_diagram:
go run ./services/blockchain/fsm_visualizer/main.go
echo "State Machine diagram generated in docs/state-machine.diagram.md"
# Chain Integrity Test - Local version of the GitHub workflow
.PHONY: chain-integrity-test
chain-integrity-test:
@echo "Starting Chain Integrity Test..."
@echo "This test replicates the GitHub workflow locally"
@echo "================================================"
@echo "Timestamp: $$(date)"
@echo ""
# Step 1: Build chainintegrity binary
@echo "Step 1: Building chainintegrity binary..."
@echo " - Compiling chainintegrity tool..."
$(MAKE) build-chainintegrity
@echo " ✓ Chainintegrity binary built successfully"
@echo ""
# Step 2: Clean up old data
@echo "Step 2: Cleaning up old data..."
@echo " - Removing existing data directory..."
@rm -rf data
@echo " ✓ Data directory cleaned up"
@echo ""
# Step 3: Build teranode image locally
@echo "Step 3: Building teranode image locally..."
@echo " - Building Docker image (this may take several minutes)..."
@docker build -t teranode:latest .
@echo " ✓ Teranode Docker image built successfully"
@echo ""
# Step 4: Start Teranode nodes with 3 block generators
@echo "Step 4: Starting Teranode nodes with 3 block generators..."
@echo " - Starting Docker Compose services..."
@docker compose -f compose/docker-compose-3blasters.yml up -d
@echo " ✓ Docker Compose services started"
@echo " - Waiting for services to initialize..."
@sleep 10
@echo " ✓ Services initialized"
@echo ""
# Step 5: Wait for mining to complete (all nodes at height 120+ and in sync)
@echo "Step 5: Waiting for mining to complete (all nodes at height 120+ and in sync)..."
@echo " - Target height: 120 blocks"
@echo " - Maximum wait time: 10 minutes (120 attempts × 5 seconds)"
@echo " - Check interval: 5 seconds"
@echo " - This may take several minutes..."
@echo ""
@set -e; \
REQUIRED_HEIGHT=120; \
MAX_ATTEMPTS=120; \
SLEEP=5; \
\
# Function to check for errors in all teranode container logs at once \
check_errors() { \
# Get current time for this check \
local current_time; \
current_time=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
\
# Check for errors - if last_check_time is empty, it will check all logs \
local since_param=""; \
if [ ! -z "$$last_check_time" ]; then \
since_param="--since=$$last_check_time"; \
fi; \
\
# Single command pattern that works for both initial and subsequent checks \
local errors; \
errors=$$(docker compose -f compose/docker-compose-3blasters.yml logs --no-color $$since_param teranode1 teranode2 teranode3 | grep -i "| ERROR |" || true); \
\
# Update timestamp for next check \
last_check_time=$$current_time; \
\
if [[ ! -z "$$errors" ]]; then \
echo "ERROR: Found error logs in teranode containers:"; \
echo "$$errors"; \
return 1; \
fi; \
return 0; \
}; \
\
# Initialize empty for first check to get all logs \
last_check_time=""; \
\
for ((i=1; i<=MAX_ATTEMPTS; i++)); do \
h1=$$(curl -s http://localhost:18090/api/v1/bestblockheader/json | jq -r .height); \
h2=$$(curl -s http://localhost:28090/api/v1/bestblockheader/json | jq -r .height); \
h3=$$(curl -s http://localhost:38090/api/v1/bestblockheader/json | jq -r .height); \
echo "Attempt $$i: heights: $$h1 $$h2 $$h3"; \
\
# Check for errors in all teranode containers \
if ! check_errors; then \
echo "Errors found in container logs. Exiting."; \
exit 1; \
fi; \
\
if [[ -z "$$h1" || -z "$$h2" || -z "$$h3" ]]; then \
if [[ $$i -gt 10 ]]; then \
echo "Error: One or more nodes are not responding after 10 attempts. Exiting."; \
exit 1; \
else \
echo "Warning: One or more nodes are not responding. Continuing..."; \
fi; \
fi; \
if [[ "$$h1" =~ ^[0-9]+$$ && "$$h2" =~ ^[0-9]+$$ && "$$h3" =~ ^[0-9]+$$ ]]; then \
if [[ $$h1 -ge $$REQUIRED_HEIGHT && $$h2 -ge $$REQUIRED_HEIGHT && $$h3 -ge $$REQUIRED_HEIGHT ]]; then \
echo "All nodes have reached height $$REQUIRED_HEIGHT or greater."; \
break; \
fi; \
fi; \
sleep $$SLEEP; \
done; \
if [[ $$i -gt MAX_ATTEMPTS ]]; then \
echo "Timeout waiting for all nodes to reach height $$REQUIRED_HEIGHT."; \
exit 1; \
fi
# Step 6: Stop Teranode nodes (docker compose down for teranode-1/2/3)
@echo "Step 6: Stopping Teranode nodes..."
@docker compose -f compose/docker-compose-3blasters.yml down teranode1 teranode2 teranode3
# Step 7: Run chainintegrity test
@echo "Step 7: Running chainintegrity test..."
@./chainintegrity.run --logfile=chainintegrity --debug | tee chainintegrity_output.log
# Step 8: Check for hash mismatch and fail if found
@echo "Step 8: Checking for hash mismatch..."
@if grep -q "All filtered log file hashes differ! No majority consensus among nodes." chainintegrity_output.log; then \
echo "Chain integrity test failed: all log file hashes differ, no majority consensus."; \
exit 1; \
fi
# Step 9: Cleanup
@echo "Step 9: Cleaning up..."
@docker compose -f compose/docker-compose-3blasters.yml down
@echo "================================================"
@echo "✓ Chain Integrity Test completed successfully!"
@echo "✓ All nodes reached the required block height"
@echo "✓ Chain integrity verification passed"
@echo "✓ Consensus achieved among all nodes"
@echo ""
@echo "Generated log files:"
@echo " - chainintegrity_output.log (main output)"
@echo " - chainintegrity*.log (individual node logs)"
@echo " - chainintegrity*.filtered.log (filtered logs)"
@echo ""
@echo "Test completed at: $$(date)"
@echo "================================================"
# Chain Integrity Test with custom parameters
.PHONY: chain-integrity-test-custom
chain-integrity-test-custom:
@echo "Starting Chain Integrity Test with custom parameters..."
@echo "Usage: make chain-integrity-test-custom REQUIRED_HEIGHT=<height> MAX_ATTEMPTS=<attempts> SLEEP=<seconds>"
@echo "Default values: REQUIRED_HEIGHT=120, MAX_ATTEMPTS=120, SLEEP=5"
@echo "================================================"
@echo "Timestamp: $$(date)"
@echo ""
# Set default values if not provided
$(eval REQUIRED_HEIGHT ?= 120)
$(eval MAX_ATTEMPTS ?= 120)
$(eval SLEEP ?= 5)
@echo "Using parameters: REQUIRED_HEIGHT=$(REQUIRED_HEIGHT), MAX_ATTEMPTS=$(MAX_ATTEMPTS), SLEEP=$(SLEEP)"
# Step 1: Build chainintegrity binary
@echo "Step 1: Building chainintegrity binary..."
$(MAKE) build-chainintegrity
# Step 2: Clean up old data
@echo "Step 2: Cleaning up old data..."
@rm -rf data
# Step 3: Build teranode image locally
@echo "Step 3: Building teranode image locally..."
@docker build -t teranode:latest .
# Step 4: Start Teranode nodes with 3 block generators
@echo "Step 4: Starting Teranode nodes with 3 block generators..."
@docker compose -f compose/docker-compose-3blasters.yml up -d
# Step 5: Wait for mining to complete with custom parameters
@echo "Step 5: Waiting for mining to complete (all nodes at height $(REQUIRED_HEIGHT)+ and in sync)..."
@echo "This may take several minutes..."
@set -e; \
REQUIRED_HEIGHT=$(REQUIRED_HEIGHT); \
MAX_ATTEMPTS=$(MAX_ATTEMPTS); \
SLEEP=$(SLEEP); \
\
# Function to check for errors in all teranode container logs at once \
check_errors() { \
# Get current time for this check \
local current_time; \
current_time=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
\
# Check for errors - if last_check_time is empty, it will check all logs \
local since_param=""; \
if [ ! -z "$$last_check_time" ]; then \
since_param="--since=$$last_check_time"; \
fi; \
\
# Single command pattern that works for both initial and subsequent checks \
local errors; \
errors=$$(docker compose -f compose/docker-compose-3blasters.yml logs --no-color $$since_param teranode1 teranode2 teranode3 | grep -i "| ERROR |" || true); \
\
# Update timestamp for next check \
last_check_time=$$current_time; \
\
if [[ ! -z "$$errors" ]]; then \
echo "ERROR: Found error logs in teranode containers:"; \
echo "$$errors"; \
return 1; \
fi; \
return 0; \
}; \
\
# Initialize empty for first check to get all logs \
last_check_time=""; \
\
for ((i=1; i<=MAX_ATTEMPTS; i++)); do \
h1=$$(curl -s http://localhost:18090/api/v1/bestblockheader/json | jq -r .height); \
h2=$$(curl -s http://localhost:28090/api/v1/bestblockheader/json | jq -r .height); \
h3=$$(curl -s http://localhost:38090/api/v1/bestblockheader/json | jq -r .height); \
echo "Attempt $$i: heights: $$h1 $$h2 $$h3"; \
\
# Check for errors in all teranode containers \
if ! check_errors; then \
echo "Errors found in container logs. Exiting."; \
exit 1; \
fi; \
\
if [[ -z "$$h1" || -z "$$h2" || -z "$$h3" ]]; then \
if [[ $$i -gt 10 ]]; then \
echo "Error: One or more nodes are not responding after 10 attempts. Exiting."; \
exit 1; \
else \
echo "Warning: One or more nodes are not responding. Continuing..."; \
fi; \
fi; \
if [[ "$$h1" =~ ^[0-9]+$$ && "$$h2" =~ ^[0-9]+$$ && "$$h3" =~ ^[0-9]+$$ ]]; then \
if [[ $$h1 -ge $$REQUIRED_HEIGHT && $$h2 -ge $$REQUIRED_HEIGHT && $$h3 -ge $$REQUIRED_HEIGHT ]]; then \
echo "All nodes have reached height $$REQUIRED_HEIGHT or greater."; \
break; \
fi; \
fi; \
sleep $$SLEEP; \
done; \
if [[ $$i -gt MAX_ATTEMPTS ]]; then \
echo "Timeout waiting for all nodes to reach height $$REQUIRED_HEIGHT."; \
exit 1; \
fi
# Step 6: Stop Teranode nodes (docker compose down for teranode-1/2/3)
@echo "Step 6: Stopping Teranode nodes..."
@docker compose -f compose/docker-compose-3blasters.yml down teranode1 teranode2 teranode3
# Step 7: Run chainintegrity test
@echo "Step 7: Running chainintegrity test..."
@./chainintegrity.run --logfile=chainintegrity --debug | tee chainintegrity_output.log
# Step 8: Check for hash mismatch and fail if found
@echo "Step 8: Checking for hash mismatch..."
@if grep -q "All filtered log file hashes differ! No majority consensus among nodes." chainintegrity_output.log; then \
echo "Chain integrity test failed: all log file hashes differ, no majority consensus."; \
exit 1; \
fi
# Step 9: Cleanup
@echo "Step 9: Cleaning up..."
@docker compose -f compose/docker-compose-3blasters.yml down
@echo "================================================"
@echo "Chain Integrity Test completed successfully!"
@echo "Log files generated:"
@echo " - chainintegrity_output.log (main output)"
@echo " - chainintegrity*.log (individual node logs)"
@echo " - chainintegrity*.filtered.log (filtered logs)"
# Clean up chain integrity test artifacts
.PHONY: clean-chain-integrity
clean-chain-integrity:
@echo "Cleaning up chain integrity test artifacts..."
@echo " - Removing log files..."
@rm -f chainintegrity*.log
@rm -f chainintegrity*.filtered.log
@rm -f chainintegrity_output.log
@echo " - Removing chainintegrity binary..."
@rm -f chainintegrity.run
@echo " - Stopping Docker Compose services..."
@docker compose -f compose/docker-compose-3blasters.yml down 2>/dev/null || true
@echo " ✓ Chain integrity test artifacts cleaned up."
@echo " ✓ All containers stopped"
@echo " ✓ All log files removed"
# Display hash analysis results from chainintegrity test
.PHONY: show-hashes
show-hashes:
@echo "📊 Hash Analysis Results:"
@echo "=========================="
@if [ -f chainintegrity_output.log ]; then \
if grep -q "chainintegrity.*\.filtered\.log:" chainintegrity_output.log; then \
echo " - Extracting hash information..."; \
echo ""; \
grep "chainintegrity.*\.filtered\.log:" chainintegrity_output.log | while read line; do \
echo " $$line"; \
done; \
echo ""; \
if grep -q "At least two nodes are consistent" chainintegrity_output.log; then \
echo " ✓ Consensus achieved: At least two nodes have matching hashes"; \
elif grep -q "All filtered log file hashes differ" chainintegrity_output.log; then \
echo " ✗ No consensus: All nodes have different hashes"; \
else \
echo " ⚠ Hash analysis result unclear - check chainintegrity_output.log"; \
fi; \
else \
echo " ⚠ No hash information found in chainintegrity_output.log"; \
echo " - Run 'make chain-integrity-test' first to generate the log file"; \
fi; \
else \
echo " ⚠ chainintegrity_output.log not found"; \
echo " - Run 'make chain-integrity-test' first to generate the log file"; \
fi
@echo ""
# Generate Swagger spec for Asset service from go-swagger annotations
.PHONY: swagger-asset
swagger-asset:
@echo "Generating Swagger spec for Asset service..."
swagger generate spec -m -o services/asset/httpimpl/swagger.json -w services/asset/httpimpl/
@echo "Swagger spec generated at services/asset/httpimpl/swagger.json"
# Validate generated Swagger spec
.PHONY: swagger-validate
swagger-validate: swagger-asset
swagger validate services/asset/httpimpl/swagger.json
# Quick chain integrity test (shorter wait times for faster testing)
.PHONY: chain-integrity-test-quick
chain-integrity-test-quick:
@echo "Starting Quick Chain Integrity Test (shorter wait times)..."
@echo " - Target height: 50 blocks"