Skip to content

Commit 6335631

Browse files
authored
perf: Replace runsim with Go stdlib testing (#20490)
1 parent 4133dc2 commit 6335631

File tree

23 files changed

+802
-679
lines changed

23 files changed

+802
-679
lines changed

.github/workflows/sims.yml

+21-24
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
build:
1616
permissions:
1717
contents: read # for actions/checkout to fetch code
18-
runs-on: ubuntu-latest
18+
runs-on: large-sdk-runner
1919
if: "!contains(github.event.head_commit.message, 'skip-sims')"
2020
steps:
2121
- uses: actions/checkout@v4
@@ -24,15 +24,9 @@ jobs:
2424
go-version: "1.22"
2525
check-latest: true
2626
- run: make build
27-
- name: Install runsim
28-
run: go install github.com/cosmos/tools/cmd/[email protected]
29-
- uses: actions/cache@v4
30-
with:
31-
path: ~/go/bin
32-
key: ${{ runner.os }}-go-runsim-binary
3327

3428
test-sim-import-export:
35-
runs-on: ubuntu-latest
29+
runs-on: large-sdk-runner
3630
needs: [build]
3731
timeout-minutes: 60
3832
steps:
@@ -41,33 +35,26 @@ jobs:
4135
with:
4236
go-version: "1.22"
4337
check-latest: true
44-
- uses: actions/cache@v4
45-
with:
46-
path: ~/go/bin
47-
key: ${{ runner.os }}-go-runsim-binary
4838
- name: test-sim-import-export
4939
run: |
5040
make test-sim-import-export
5141
5242
test-sim-after-import:
53-
runs-on: ubuntu-latest
43+
runs-on: large-sdk-runner
5444
needs: [build]
45+
timeout-minutes: 60
5546
steps:
5647
- uses: actions/checkout@v4
5748
- uses: actions/setup-go@v5
5849
with:
5950
go-version: "1.22"
6051
check-latest: true
61-
- uses: actions/cache@v4
62-
with:
63-
path: ~/go/bin
64-
key: ${{ runner.os }}-go-runsim-binary
6552
- name: test-sim-after-import
6653
run: |
6754
make test-sim-after-import
6855
69-
test-sim-multi-seed-short:
70-
runs-on: ubuntu-latest
56+
test-sim-deterministic:
57+
runs-on: large-sdk-runner
7158
needs: [build]
7259
timeout-minutes: 60
7360
steps:
@@ -76,18 +63,28 @@ jobs:
7663
with:
7764
go-version: "1.22"
7865
check-latest: true
79-
- uses: actions/cache@v4
66+
- name: test-sim-nondeterminism-streaming
67+
run: |
68+
make test-sim-nondeterminism-streaming
69+
70+
test-sim-multi-seed-short:
71+
runs-on: large-sdk-runner
72+
needs: [build]
73+
timeout-minutes: 60
74+
steps:
75+
- uses: actions/checkout@v4
76+
- uses: actions/setup-go@v5
8077
with:
81-
path: ~/go/bin
82-
key: ${{ runner.os }}-go-runsim-binary
78+
go-version: "1.22"
79+
check-latest: true
8380
- name: test-sim-multi-seed-short
8481
run: |
8582
make test-sim-multi-seed-short
8683
8784
sims-notify-success:
8885
needs:
8986
[test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export]
90-
runs-on: ubuntu-latest
87+
runs-on: large-sdk-runner
9188
if: ${{ success() }}
9289
steps:
9390
- name: Check out repository
@@ -115,7 +112,7 @@ jobs:
115112
contents: none
116113
needs:
117114
[test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export]
118-
runs-on: ubuntu-latest
115+
runs-on: large-sdk-runner
119116
if: ${{ failure() }}
120117
steps:
121118
- name: Notify Slack on failure

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
196196

197197
### CLI Breaking Changes
198198

199+
* (perf)[#20490](https://github.com/cosmos/cosmos-sdk/pull/20490) Sims: Replace runsim command with Go stdlib testing. CLI: `Commit` default true, `Lean`, `SimulateEveryOperation`, `PrintAllInvariants`, `DBBackend` params removed
199200
* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `appd export` has moved with other genesis commands, use `appd genesis export` instead.
200201

201202
### Deprecated

Makefile

+31-22
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ endif
109109
#? all: Run tools build
110110
all: build
111111

112-
# The below include contains the tools and runsim targets.
113-
include contrib/devtools/Makefile
114-
115112
###############################################################################
116113
### Build ###
117114
###############################################################################
@@ -164,7 +161,7 @@ $(MOCKS_DIR):
164161
mkdir -p $(MOCKS_DIR)
165162

166163
#? distclean: Run `make clean` and `make tools-clean`
167-
distclean: clean tools-clean
164+
distclean: clean
168165

169166
#? clean: Clean some auto generated directory
170167
clean:
@@ -286,8 +283,8 @@ endif
286283
#? test-sim-nondeterminism: Run non-determinism test for simapp
287284
test-sim-nondeterminism:
288285
@echo "Running non-determinism test..."
289-
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -run TestAppStateDeterminism -Enabled=true \
290-
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h
286+
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout=30m -tags='sims' -run TestAppStateDeterminism \
287+
-NumBlocks=100 -BlockSize=200 -Period=0
291288

292289
# Requires an exported plugin. See store/streaming/README.md for documentation.
293290
#
@@ -300,39 +297,45 @@ test-sim-nondeterminism:
300297
# make test-sim-nondeterminism-streaming
301298
test-sim-nondeterminism-streaming:
302299
@echo "Running non-determinism-streaming test..."
303-
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -run TestAppStateDeterminism -Enabled=true \
304-
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h -EnableStreaming=true
300+
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout=30m -tags='sims' -run TestAppStateDeterminism \
301+
-NumBlocks=100 -BlockSize=200 -Period=0 -EnableStreaming=true
305302

306303
test-sim-custom-genesis-fast:
307304
@echo "Running custom genesis simulation..."
308305
@echo "By default, ${HOME}/.simapp/config/genesis.json will be used."
309-
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -run TestFullAppSimulation -Genesis=${HOME}/.simapp/config/genesis.json \
310-
-Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -SigverifyTx=false -v -timeout 24h
306+
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout=30m -tags='sims' -run TestFullAppSimulation -Genesis=${HOME}/.simapp/config/genesis.json \
307+
-NumBlocks=100 -BlockSize=200 -Seed=99 -Period=5 -SigverifyTx=false
311308

312-
test-sim-import-export: runsim
309+
test-sim-import-export:
313310
@echo "Running application import/export simulation. This may take several minutes..."
314-
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 50 5 TestAppImportExport
311+
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout 20m -tags='sims' -run TestAppImportExport \
312+
-NumBlocks=50 -Period=5
315313

316-
test-sim-after-import: runsim
314+
test-sim-after-import:
317315
@echo "Running application simulation-after-import. This may take several minutes..."
318-
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 50 5 TestAppSimulationAfterImport
316+
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout 30m -tags='sims' -run TestAppSimulationAfterImport \
317+
-NumBlocks=50 -Period=5
318+
319319

320-
test-sim-custom-genesis-multi-seed: runsim
320+
test-sim-custom-genesis-multi-seed:
321321
@echo "Running multi-seed custom genesis simulation..."
322322
@echo "By default, ${HOME}/.simapp/config/genesis.json will be used."
323-
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Genesis=${HOME}/.simapp/config/genesis.json -SigverifyTx=false -SimAppPkg=. -ExitOnFail 400 5 TestFullAppSimulation
323+
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout 30m -tags='sims' -run TestFullAppSimulation -Genesis=${HOME}/.simapp/config/genesis.json \
324+
-NumBlocks=400 -Period=5
324325

325-
test-sim-multi-seed-long: runsim
326+
test-sim-multi-seed-long:
326327
@echo "Running long multi-seed application simulation. This may take awhile!"
327-
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 500 50 TestFullAppSimulation
328+
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout=1h -tags='sims' -run TestFullAppSimulation \
329+
-NumBlocks=500 -Period=50
328330

329-
test-sim-multi-seed-short: runsim
331+
test-sim-multi-seed-short:
330332
@echo "Running short multi-seed application simulation. This may take awhile!"
331-
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 50 10 TestFullAppSimulation
333+
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout 30m -tags='sims' -run TestFullAppSimulation \
334+
-NumBlocks=50 -Period=10
332335

333336
test-sim-benchmark-invariants:
334337
@echo "Running simulation invariant benchmarks..."
335-
cd ${CURRENT_DIR}/simapp && @go test -mod=readonly -benchmem -bench=BenchmarkInvariants -run=^$ \
338+
cd ${CURRENT_DIR}/simapp && go test -mod=readonly -benchmem -bench=BenchmarkInvariants -tags='sims' -run=^$ \
336339
-Enabled=true -NumBlocks=1000 -BlockSize=200 \
337340
-Period=1 -Commit=true -Seed=57 -v -timeout 24h
338341

@@ -351,6 +354,12 @@ SIM_NUM_BLOCKS ?= 500
351354
SIM_BLOCK_SIZE ?= 200
352355
SIM_COMMIT ?= true
353356

357+
#? test-sim-fuzz: Run fuzz test for simapp
358+
test-sim-fuzz:
359+
@echo "Running application fuzz for numBlocks=2, blockSize=20. This may take awhile!"
360+
#ld flags are a quick fix to make it work on current osx
361+
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -json -tags='sims' -ldflags="-extldflags=-Wl,-ld_classic" -timeout=60m -fuzztime=60m -run=^$$ -fuzz=FuzzFullAppSimulation -GenesisTime=1714720615 -NumBlocks=2 -BlockSize=20
362+
354363
#? test-sim-benchmark: Run benchmark test for simapp
355364
test-sim-benchmark:
356365
@echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!"
@@ -390,7 +399,7 @@ test-sim-profile-streaming:
390399
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -benchmem -run=^$$ $(.) -bench ^BenchmarkFullAppSimulation$$ \
391400
-Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h -cpuprofile cpu.out -memprofile mem.out -EnableStreaming=true
392401

393-
.PHONY: test-sim-profile test-sim-benchmark
402+
.PHONY: test-sim-profile test-sim-benchmark test-sim-fuzz
394403

395404
#? benchmark: Run benchmark tests
396405
benchmark:

baseapp/baseapp.go

+5
Original file line numberDiff line numberDiff line change
@@ -1165,3 +1165,8 @@ func (app *BaseApp) Close() error {
11651165

11661166
return errors.Join(errs...)
11671167
}
1168+
1169+
// GetBaseApp returns the pointer to itself.
1170+
func (app *BaseApp) GetBaseApp() *BaseApp {
1171+
return app
1172+
}

contrib/devtools/Makefile

-69
This file was deleted.

docs/build/building-modules/14-simulator.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ As you can see, the weights are predefined in this case. Options exist to overri
6969
Here is how one can override the above package `simappparams`.
7070

7171
```go reference
72-
https://github.com/cosmos/cosmos-sdk/blob/release/v0.50.x/Makefile#L293-L299
72+
https://github.com/cosmos/cosmos-sdk/blob/release/v0.51.x/Makefile#L292-L334
7373
```
74+
The SDK simulations can be executed like normal tests in Go from the shell or within an IDE.
75+
Make sure that you pass the `-tags='sims` parameter to enable them and other params that make sense for your scenario.
7476

75-
For the last test a tool called [runsim](https://github.com/cosmos/tools/tree/master/cmd/runsim) is used, this is used to parallelize go test instances, provide info to Github and slack integrations to provide information to your team on how the simulations are running.
7677

7778
### Random proposal contents
7879

@@ -124,3 +125,12 @@ func NewCustomApp(...) {
124125
...
125126
}
126127
```
128+
129+
## Integration with the Go fuzzer framework
130+
131+
The simulations provide deterministic behaviour already. The integration with the [Go fuzzer](https://go.dev/doc/security/fuzz/)
132+
can be done at a high level with the deterministic pseudo random number generator where the fuzzer provides varying numbers.
133+
134+
```go reference
135+
https://github.com/cosmos/cosmos-sdk/blob/release/v0.51.x/Makefile#L352-L355
136+
```

0 commit comments

Comments
 (0)