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: Broken-Invar Tx - aka. Crisis module #3656

Merged
merged 64 commits into from
Mar 28, 2019
Merged

Conversation

rigelrozanski
Copy link
Contributor

@rigelrozanski rigelrozanski commented Feb 14, 2019

This PR also introduces gaiad assert-invariants-blockly

closes #2935
offshoot-issue #3967

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote tests
  • Updated relevant documentation (docs/)
  • Added entries in PENDING.md with issue #
  • rereviewed Files changed in the github PR explorer

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)

@rigelrozanski rigelrozanski changed the title WIP: Broken-Invar Tx - aka. Crisis module SPEC-R4R: Broken-Invar Tx - aka. Crisis module Feb 19, 2019
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

Thanks for the spec, some notes. I think we should keep this as simple as possible initially.

docs/spec/crisis/README.md Outdated Show resolved Hide resolved
docs/spec/crisis/README.md Outdated Show resolved Hide resolved
docs/spec/crisis/README.md Outdated Show resolved Hide resolved
x/crisis/handler.go Show resolved Hide resolved
x/crisis/handler.go Show resolved Hide resolved
docs/spec/crisis/README.md Outdated Show resolved Hide resolved
@alexanderbez alexanderbez removed this from the v0.34.0 milestone Mar 11, 2019
@rigelrozanski rigelrozanski added this to the v0.34.0 milestone Mar 23, 2019
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

Thanks @rigelrozanski - structure is mostly solid I think; see comments.

cmd/gaia/app/app.go Show resolved Hide resolved
docs/spec/crisis/02_messages.md Outdated Show resolved Hide resolved
docs/spec/crisis/02_messages.md Outdated Show resolved Hide resolved
docs/spec/crisis/02_messages.md Outdated Show resolved Hide resolved
docs/spec/crisis/02_messages.md Outdated Show resolved Hide resolved
x/crisis/codec.go Outdated Show resolved Hide resolved
x/crisis/handler.go Outdated Show resolved Hide resolved
x/crisis/msg.go Outdated Show resolved Hide resolved
x/distribution/keeper/fee_pool.go Outdated Show resolved Hide resolved
x/distribution/keeper/fee_pool.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mossid mossid left a comment

Choose a reason for hiding this comment

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

Just a few comments on the code 👍

x/crisis/handler.go Show resolved Hide resolved
x/crisis/keeper.go Show resolved Hide resolved
x/distribution/keeper/invariants.go Outdated Show resolved Hide resolved
x/crisis/params.go Outdated Show resolved Hide resolved
x/crisis/params.go Outdated Show resolved Hide resolved
cwgoes and others added 3 commits March 25, 2019 12:58
Co-Authored-By: rigelrozanski <rigel.rozanski@gmail.com>
@rigelrozanski
Copy link
Contributor Author

rigelrozanski commented Mar 25, 2019

@cwgoes I've added in usage of all the invariants from the crisis module instead of the previously restrictive list:

invarRoutes := app.crisisKeeper.Routes()
for _, ir := range invarRoutes {
if err := ir.Invar(ctx); err != nil {
panic(fmt.Errorf("invariant broken: %s\n"+
"\tCRITICAL please submit the following transaction:\n"+
"\t\t gaiacli tx crisis invariant-broken %v %v", err, ir.ModuleName, ir.Route))
}
}

Now a bunch of import/export tests fail in distribution. Notably here is a fast/simple failing test:

go test ./cmd/gaia/app -run TestGaiaSimulationAfterImport -SimulationEnabled=true -SimulationNumBlocks=5 -SimulationVerbose=true -SimulationCommit=true -SimulationSeed=1 -v -timeout 24h
debug startingPeriod: 3
debug endingPeriod: 2
--- FAIL: TestGaiaSimulationAfterImport (7.93s)
panic: startingPeriod cannot be greater than endingPeriod [recovered]
	panic: startingPeriod cannot be greater than endingPeriod

goroutine 19 [running]:
testing.tRunner.func1(0xc0004e7400)
	/usr/local/Cellar/go/1.12.1/libexec/src/testing/testing.go:830 +0x392
panic(0x18e1c00, 0x1c9e9e0)
	/usr/local/Cellar/go/1.12.1/libexec/src/runtime/panic.go:522 +0x1b5
github.com/cosmos/cosmos-sdk/x/distribution/keeper.Keeper.calculateDelegationRewardsBetween(0x1cbcb00, 0xc000966d10, 0xc00019f8f0, 0xc00019f8f0, 0x1cbcb00, 0xc000966d60, 0x1cbcb40, 0xc000966d70, 0xc0012caf80, 0x5, ...)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/x/distribution/keeper/delegation.go:37 +0x70c
github.com/cosmos/cosmos-sdk/x/distribution/keeper.Keeper.calculateDelegationRewards(0x1cbcb00, 0xc000966d10, 0xc00019f8f0, 0xc00019f8f0, 0x1cbcb00, 0xc000966d60, 0x1cbcb40, 0xc000966d70, 0xc0012caf80, 0x5, ...)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/x/distribution/keeper/delegation.go:103 +0x3fc
github.com/cosmos/cosmos-sdk/x/distribution/keeper.Keeper.withdrawDelegationRewards(0x1cbcb00, 0xc000966d10, 0xc00019f8f0, 0xc00019f8f0, 0x1cbcb00, 0xc000966d60, 0x1cbcb40, 0xc000966d70, 0xc0012caf80, 0x5, ...)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/x/distribution/keeper/delegation.go:117 +0x301
github.com/cosmos/cosmos-sdk/x/distribution/keeper.Keeper.WithdrawDelegationRewards(0x1cbcb00, 0xc000966d10, 0xc00019f8f0, 0xc00019f8f0, 0x1cbcb00, 0xc000966d60, 0x1cbcb40, 0xc000966d70, 0xc0012caf80, 0x5, ...)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/x/distribution/keeper/keeper.go:62 +0x20c
github.com/cosmos/cosmos-sdk/x/distribution/keeper.CanWithdrawInvariant.func1.1(0x0, 0x1cd7760, 0xc0038c4700, 0xc0038c4700)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/x/distribution/keeper/invariants.go:84 +0x62b
github.com/cosmos/cosmos-sdk/x/staking/keeper.Keeper.IterateValidators(0x1cbcb00, 0xc000966ce0, 0x1cbcb40, 0xc000966cf0, 0xc00019f8f0, 0x331a188, 0xc00000c5a0, 0x1cd4860, 0xc0000d9c20, 0xc00019f8f0, ...)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/x/staking/keeper/alias_functions.go:21 +0x1fa
github.com/cosmos/cosmos-sdk/x/distribution/keeper.CanWithdrawInvariant.func1(0x1cc89c0, 0xc0018cc930, 0xc0046b9b40, 0xc, 0x0, 0x0)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/x/distribution/keeper/invariants.go:78 +0x372
github.com/cosmos/cosmos-sdk/cmd/gaia/app.(*GaiaApp).assertRuntimeInvariantsOnContext(0xc0003c8000, 0x1cc89c0, 0xc0018cc930, 0xc0046b9b40, 0xc)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/cmd/gaia/app/invariants.go:21 +0x373
github.com/cosmos/cosmos-sdk/cmd/gaia/app.(*GaiaApp).assertRuntimeInvariants(0xc0003c8000)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/cmd/gaia/app/invariants.go:14 +0x100
github.com/cosmos/cosmos-sdk/cmd/gaia/app.(*GaiaApp).initChainer(0xc0003c8000, 0x1cc89c0, 0xc000f3a210, 0xc0009ac540, 0xd, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/cmd/gaia/app/app.go:343 +0x37c
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).InitChain(0xc0003c6200, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/baseapp/baseapp.go:354 +0x2c1
github.com/cosmos/cosmos-sdk/cmd/gaia/app.TestGaiaSimulationAfterImport(0xc0004e7400)
	/Users/rigelrozanski/go/src/github.com/cosmos/cosmos-sdk/cmd/gaia/app/sim_test.go:519 +0x728
testing.tRunner(0xc0004e7400, 0x1b89100)
	/usr/local/Cellar/go/1.12.1/libexec/src/testing/testing.go:865 +0xc0
created by testing.(*T).Run
	/usr/local/Cellar/go/1.12.1/libexec/src/testing/testing.go:916 +0x35a
FAIL	github.com/cosmos/cosmos-sdk/cmd/gaia/app	8.012s

client/utils/utils.go Show resolved Hide resolved
cmd/gaia/cmd/gaiacli/main.go Outdated Show resolved Hide resolved
cmd/gaia/cmd/gaiacli/main.go Outdated Show resolved Hide resolved
cmd/gaia/cmd/gaiad/main.go Outdated Show resolved Hide resolved
cmd/gaia/cmd/gaiad/main.go Outdated Show resolved Hide resolved
docs/spec/crisis/02_messages.md Outdated Show resolved Hide resolved
docs/spec/crisis/03_tags.md Show resolved Hide resolved
x/auth/stdtx.go Outdated Show resolved Hide resolved
x/crisis/handler.go Show resolved Hide resolved
ReferenceCountInvariant = keeper.ReferenceCountInvariant
CreateTestInputDefault = keeper.CreateTestInputDefault
CreateTestInputAdvanced = keeper.CreateTestInputAdvanced
TestAddrs = keeper.TestAddrs
Copy link
Contributor

Choose a reason for hiding this comment

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

What is TestAddrs? Anything pertaining to tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, they are predefined addresses to test with.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case I don't think they should be defined or set here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you be more specific? How better should this be organized?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just don't think they should be set or defined in "core" code. i.e. keep them in tests files or test utilities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so this is defined in a "test" file (aka keeper/test_common.go) I'm kinda peeved at all the code dup between the this test_common.go file across all the modules... but maybe it's worth refactoring into a new testing utilities package like x/testing_utilities - what you think of that?

Co-Authored-By: rigelrozanski <rigel.rozanski@gmail.com>
cmd/gaia/app/export.go Outdated Show resolved Hide resolved
cmd/gaia/app/export.go Outdated Show resolved Hide resolved
cmd/gaia/app/export.go Outdated Show resolved Hide resolved
x/crisis/keeper.go Show resolved Hide resolved
ReferenceCountInvariant = keeper.ReferenceCountInvariant
CreateTestInputDefault = keeper.CreateTestInputDefault
CreateTestInputAdvanced = keeper.CreateTestInputAdvanced
TestAddrs = keeper.TestAddrs
Copy link
Contributor

Choose a reason for hiding this comment

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

I just don't think they should be set or defined in "core" code. i.e. keep them in tests files or test utilities.

@cwgoes
Copy link
Contributor

cwgoes commented Mar 28, 2019

@rigelrozanski rigelrozanski mentioned this pull request Mar 28, 2019
5 tasks
@rigelrozanski rigelrozanski merged commit df43941 into develop Mar 28, 2019
@rigelrozanski rigelrozanski deleted the rigel/crisis-module branch March 28, 2019 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken-Invariant-Evidence Tx
6 participants