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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Slashing, validator set, and governance simulation #1783

Merged
merged 80 commits into from
Aug 16, 2018

Conversation

cwgoes
Copy link
Contributor

@cwgoes cwgoes commented Jul 20, 2018

Continuation of #1620.

This PR does the following:

  • Adds simulated messages for x/gov and x/slashing
  • Simulates validators signing/missing blocks (with a simple Markov chain written by @ValarDragon)
  • Simulates Tendermint validator set update logic
  • Simulates enough time for unbonding to happen
  • Simulates double-signatures (occaisionally)
  • Adds in several methods to make long-running simulations faster

Will include:

  • Simulated validator set & simulated validator signatures (or missed signatures!) on each block
  • Simulated random amount of time elapsed per block
  • Simulated slashing msgs
  • Simulated governance msgs

Want to complete before R4R/merge:

  • Clearer logs for slashing and governance tally events (ensure that we've actually tested these)
  • Simplify simulation parameter choices (or interactive CLI!)
  • Cleanup the app.Commit() logic (avoid the actual multistore commit)

To be completed in a followup PR:

edit: Wishlist moved to #1924.

Standard checklist:

  • Updated all relevant documentation (docs/)
  • Updated all relevant code comments
  • Wrote tests
  • Added entries in PENDING.md
  • Updated cmd/gaia and examples/

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Jul 20, 2018

Codecov Report

Merging #1783 into release/v0.24.0 will decrease coverage by 1.06%.
The diff coverage is 40.74%.

@@                 Coverage Diff                 @@
##           release/v0.24.0    #1783      +/-   ##
===================================================
- Coverage            64.86%   63.79%   -1.07%     
===================================================
  Files                  115      113       -2     
  Lines                 6862     6671     -191     
===================================================
- Hits                  4451     4256     -195     
- Misses                2127     2132       +5     
+ Partials               284      283       -1

@@ -125,7 +125,7 @@ func TestFullGaiaSimulation(t *testing.T) {
},
[]simulation.RandSetup{},
[]simulation.Invariant{
allInvariants,
simulation.PeriodicInvariant(allInvariants, 100, 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to break up these invariants more? i.e. bank invariant every 100, staking/slashing every time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly! Currently optimized for ease of changing periodicity...

Copy link
Contributor

@ValarDragon ValarDragon Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to what I previously suggested, maybe we should have a separate convenient debug full simulation function which takes in the seed and then run the invariants every time. (i.e. I'd prefer if we had a very easy way to see exactly what caused that randomized error once we've found an error)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can search by bisection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and also have a way to run the invariants every time, sure)

@cwgoes cwgoes changed the base branch from develop to release/v0.24.0 August 15, 2018 12:15
Makefile Outdated
@@ -136,7 +136,7 @@ test_sim_modules:

test_sim_gaia_fast:
@echo "Running full Gaia simulation. This may take several minutes..."
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=200 -timeout 2h
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=200 -timeout 24h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be fast. Perhaps make a test_sim_gaia_release, and have that run only on merges to master

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cwgoes! Left some feedback on UX and non-determinism.

@echo "Running individual module simulations..."
@go test $(PACKAGES_SIMTEST)

test_sim_gaia_fast:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not able to send a successful SIGINT to this command.

Copy link
Contributor

@ValarDragon ValarDragon Aug 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! We should resolve this, but I strongly think we should get this PR merged, and fix this once its merged. Reviewing / rebasing / etc. is becoming a pain, and it will be much easier to parallelize work once its on develop. Mentioned your point about SIGINT #1924

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just send SIGKILL!

@echo "Running full Gaia simulation. This may take several minutes..."
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=1000 -v -timeout 24h

test_sim_gaia_slow:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

) {
log := fmt.Sprintf("Starting SimulateFromSeed with randomness created with seed %d", int(seed))
keys, addrs := mock.GeneratePrivKeyAddressPairs(numKeys)
fmt.Printf("%s\n", log)
keys, accs := mock.GeneratePrivKeyAddressPairs(numKeys)
Copy link
Contributor

@alexanderbez alexanderbez Aug 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is non-deterministic regardless of seed which results in different state hashes in each iteration.

Reference:

func GenPrivKey() PrivKeyEd25519 {
	return genPrivKey(crypto.CReader())
}

/cc @ValarDragon

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #2059 , but lets get this PR merged in first.

@ValarDragon
Copy link
Contributor

ValarDragon commented Aug 16, 2018

Can we remove testing this from CLI, and get this merged in? We can open a new PR for bug fixes in the interrim. I think just getting the code here merged is valuable so that we can work on this in a way that is easier to review.

I'll write the fix for the non-determinism in a separate PR aimed at this one (with the intent of being rebased onto develop once this is merged in)

@ValarDragon
Copy link
Contributor

appState, validators, err := app.ExportAppStateAndValidators() fails on randomized testing gaia instances, but lets save debugging that for a separate PR.

@cwgoes
Copy link
Contributor Author

cwgoes commented Aug 16, 2018

appState, validators, err := app.ExportAppStateAndValidators() fails on randomized testing gaia instances, but lets save debugging that for a separate PR.

Did you call InitGenesis?

@cwgoes cwgoes merged commit 3d50567 into release/v0.24.0 Aug 16, 2018
@cwgoes cwgoes deleted the cwgoes/slashing-simulation branch August 16, 2018 15:36
chillyvee pushed a commit to chillyvee/cosmos-sdk that referenced this pull request Mar 1, 2024
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.0.2 to 3.1.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3.0.2...v3.1.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants