cosmos-sdk: Panic when exporting state with --for-zero-height

Summary of Bug

When I export the state of a chain with --for-zero-height, it got panic.

Here is the stack trace

panic: calculated final stake for delegator desmos18qu3zck8866dsdd87w03la3w4anej2e2pnerj0 greater than current stake
	final stake:	2887250.859106529200909651
	current stake:	2810000.000000000000000000

goroutine 1 [running]:
github.com/cosmos/cosmos-sdk/x/distribution/keeper.Keeper.calculateDelegationRewards(0x164fea0, 0xc0001a3360, 0xc0001581c0, 0xc0001581c0, 0x164fea0, 0xc0001a33b0, 0x164fee0, 0xc0001a3400, 0xc0000e5740, 0xc, ...)
	/home/ubuntu/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.38.3/x/distribution/keeper/delegation.go:127 +0x873
github.com/cosmos/cosmos-sdk/x/distribution/keeper.Keeper.withdrawDelegationRewards(0x164fea0, 0xc0001a3360, 0xc0001581c0, 0xc0001581c0, 0x164fea0, 0xc0001a33b0, 0x164fee0, 0xc0001a3400, 0xc0000e5740, 0xc, ...)
	/home/ubuntu/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.38.3/x/distribution/keeper/delegation.go:147 +0x29f
github.com/cosmos/cosmos-sdk/x/distribution/keeper.Keeper.WithdrawDelegationRewards(0x164fea0, 0xc0001a3360, 0xc0001581c0, 0xc0001581c0, 0x164fea0, 0xc0001a33b0, 0x164fee0, 0xc0001a3400, 0xc0000e5740, 0xc, ...)
	/home/ubuntu/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.38.3/x/distribution/keeper/keeper.go:95 +0x1fc
github.com/desmos-labs/desmos/app.(*DesmosApp).prepForZeroHeightGenesis(0xc000016380, 0x16600e0, 0xc00003c080, 0x16731c0, 0xc000afb4c0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/ubuntu/desmos/app/export.go:77 +0x496
github.com/desmos-labs/desmos/app.(*DesmosApp).ExportAppStateAndValidators(0xc000016380, 0xc000e8de01, 0x2190288, 0x0, 0x0, 0x0, 0xc00018d901, 0xc0001f24e0, 0x0, 0x0, ...)
	/home/ubuntu/desmos/app/export.go:27 +0x31d
main.exportAppStateAndTMValidators(0x1660ae0, 0xc000e8de20, 0x16758c0, 0xc000010188, 0x0, 0x0, 0xffffffffffffffff, 0xc000e8de01, 0x2190288, 0x0, ...)
	/home/ubuntu/desmos/cmd/desmosd/main.go:120 +0x2d0
github.com/cosmos/cosmos-sdk/server.ExportCmd.func1(0xc000ddf600, 0xc000dceb00, 0x0, 0x1, 0x0, 0x0)
	/home/ubuntu/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.38.3/server/export.go:65 +0x53d
github.com/spf13/cobra.(*Command).execute(0xc000ddf600, 0xc000dceae0, 0x1, 0x1, 0xc000ddf600, 0xc000dceae0)
	/home/ubuntu/go/pkg/mod/github.com/spf13/cobra@v0.0.6/command.go:840 +0x453
github.com/spf13/cobra.(*Command).ExecuteC(0xc000129340, 0x12e5265, 0xc00019beb8, 0x58a2e2)
	/home/ubuntu/go/pkg/mod/github.com/spf13/cobra@v0.0.6/command.go:945 +0x317
github.com/spf13/cobra.(*Command).Execute(...)
	/home/ubuntu/go/pkg/mod/github.com/spf13/cobra@v0.0.6/command.go:885
github.com/tendermint/tendermint/libs/cli.Executor.Execute(0xc000129340, 0x144cdb0, 0x12c7eaa, 0x10)
	/home/ubuntu/go/pkg/mod/github.com/tendermint/tendermint@v0.33.3/libs/cli/setup.go:89 +0x3c
main.main()
	/home/ubuntu/desmos/cmd/desmosd/main.go:78 +0x6ff

The address in the panic is the self delegation address of a validator. This validator only have one delegation from it’s own address.

Here is the detail of that delegation

- delegation:
    delegator_address: desmos18qu3zck8866dsdd87w03la3w4anej2e2pnerj0
    validator_address: desmosvaloper18qu3zck8866dsdd87w03la3w4anej2e2l73hca
    shares: "3140921.409214092140921407"
  balance:
    denom: udaric
    amount: "2810000"

There is no problem if I don’t export with --for-zero-height.

We don’t have minting module enabled and the possible rewards will be tx fee which is nearly 0 in our current testnet.

Version

v0.38.3

Steps to Reproduce

desmosd export --for-zero-height

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 27 (21 by maintainers)

Most upvoted comments

@kwunyeung @bragaz do you have a script to reproduce this issue (is a list of actions). Are you trying to reproduce the issue with a fresh setup or trying the software on existing database? For Akash, all new setup worked fine after fixing x/auth order and x/evidence (for double signing)