Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sims): [WIP]Minor optimizations to sim execution time #20178

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
107 changes: 23 additions & 84 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ name: Sims
# Sims workflow runs multiple types of simulations (nondeterminism, import-export, after-import, multi-seed-short)
# This workflow will run on all Pull Requests, if a .go, .mod or .sum file have been changed
on:
schedule:
- cron: "0 */2 * * *"
release:
types: [published]
pull_request: # TODO(Alex): DO NOT merge
branches:
- main
- release/**
paths:
- "**/*.go"
- "go.mod"
- "go.sum"
push:
branches:
- main
paths:
- "**/*.go"
- "go.mod"
- "go.sum"

concurrency:
group: ci-${{ github.ref }}-sims
Expand Down Expand Up @@ -34,7 +45,11 @@ jobs:
test-sim-import-export:
runs-on: ubuntu-latest
needs: [build]
timeout-minutes: 60
timeout-minutes: 20
strategy:
max-parallel: 4
matrix:
seed: [1, 2, 4, 7, 32, 123, 124, 582, 1893, 2989]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand All @@ -46,85 +61,9 @@ jobs:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
- name: test-sim-import-export
run: |
make test-sim-import-export

test-sim-after-import:
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
check-latest: true
- uses: actions/cache@v4
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
- name: test-sim-after-import
SIM_SEED: ${{ matrix.seed }}
run: |
make test-sim-after-import
make test-sim-import-export-matrix

test-sim-multi-seed-short:
runs-on: ubuntu-latest
needs: [build]
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
check-latest: true
- uses: actions/cache@v4
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
- name: test-sim-multi-seed-short
run: |
make test-sim-multi-seed-short

sims-notify-success:
needs:
[test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export]
runs-on: ubuntu-latest
if: ${{ success() }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Get previous workflow status
uses: ./.github/actions/last-workflow-status
id: last_status
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Notify Slack on success
if: ${{ steps.last_status.outputs.last_status == 'failure' }}
uses: rtCamp/action-slack-notify@v2.3.0
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: sdk-sims
SLACK_USERNAME: Sim Tests
SLACK_ICON_EMOJI: ":white_check_mark:"
SLACK_COLOR: good
SLACK_MESSAGE: Sims are passing
SLACK_FOOTER: ""

sims-notify-failure:
permissions:
contents: none
needs:
[test-sim-multi-seed-short, test-sim-after-import, test-sim-import-export]
runs-on: ubuntu-latest
if: ${{ failure() }}
steps:
- name: Notify Slack on failure
uses: rtCamp/action-slack-notify@v2.3.0
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: sdk-sims
SLACK_USERNAME: Sim Tests
SLACK_ICON_EMOJI: ":skull:"
SLACK_COLOR: danger
SLACK_MESSAGE: Sims are failing
SLACK_FOOTER: ""
# TODO (Alex): do not merge
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ MOCKS_DIR = $(CURDIR)/tests/mocks
HTTPS_GIT := https://github.com/cosmos/cosmos-sdk.git
DOCKER := $(shell which docker)
PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)
NUM_CPUS = $(shell if [[ "$$(uname)" == "Darwin" ]]; then sysctl -n hw.logicalcpu; else nproc; fi)
SIM_SEED ?= 1

# process build tags
build_tags = netgo
Expand Down Expand Up @@ -294,11 +296,16 @@ test-sim-custom-genesis-fast:

test-sim-import-export: runsim
@echo "Running application import/export simulation. This may take several minutes..."
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 50 5 TestAppImportExport
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=$(NUM_CPUS) -SimAppPkg=. -ExitOnFail 50 5 TestAppImportExport

test-sim-import-export-matrix:
@echo "Running application import/export simulation. This may take several minutes..."
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=50 -BlockSize=5 -Commit=true -Period=0 -Seed=$(SIM_SEED) -v -timeout 20m -EnableStreaming=true

test-sim-after-import: runsim
@echo "Running application simulation-after-import. This may take several minutes..."
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 50 5 TestAppSimulationAfterImport
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=$(NUM_CPUS) -SimAppPkg=. -ExitOnFail 50 5 TestAppSimulationAfterImport

test-sim-custom-genesis-multi-seed: runsim
@echo "Running multi-seed custom genesis simulation..."
Expand All @@ -307,11 +314,11 @@ test-sim-custom-genesis-multi-seed: runsim

test-sim-multi-seed-long: runsim
@echo "Running long multi-seed application simulation. This may take awhile!"
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 500 50 TestFullAppSimulation
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=$(NUM_CPUS) -SimAppPkg=. -ExitOnFail 500 50 TestFullAppSimulation

test-sim-multi-seed-short: runsim
@echo "Running short multi-seed application simulation. This may take awhile!"
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 50 10 TestFullAppSimulation
@cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=$(NUM_CPUS) -SimAppPkg=. -ExitOnFail 50 10 TestFullAppSimulation

test-sim-benchmark-invariants:
@echo "Running simulation invariant benchmarks..."
Expand Down
27 changes: 1 addition & 26 deletions types/simulation/rand_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,6 @@
}

// DeriveRand derives a new Rand deterministically from another random source.
// Unlike rand.New(rand.NewSource(seed)), the result is "more random"
// depending on the source and state of r.
//
// NOTE: not crypto safe.
func DeriveRand(r *rand.Rand) *rand.Rand {
const num = 8 // TODO what's a good number? Too large is too slow.
ms := multiSource(make([]rand.Source, num))

for i := 0; i < num; i++ {
ms[i] = rand.NewSource(r.Int63())
}

return rand.New(ms)
}

type multiSource []rand.Source

func (ms multiSource) Int63() (r int64) {
for _, source := range ms {
r ^= source.Int63()
}

return r
}

func (ms multiSource) Seed(_ int64) {
panic("multiSource Seed should not be called")
return rand.New(rand.NewSource(r.Int63()))

Check failure

Code scanning / Golang security checks by gosec

Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand) Error

Use of weak random number generator (math/rand instead of crypto/rand)
}