cosmos / cosmos-sdk

:chains: A Framework for Building High Value Public Blockchains :sparkles:
https://cosmos.network/
Apache License 2.0
6.24k stars 3.6k forks source link

[Bug]: x/staking simulation operations assumes all delegators are EOA accounts #15879

Closed javiersuweijie closed 1 year ago

javiersuweijie commented 1 year ago

Summary of Bug

When running x/staking simulations, it is assumed that all delegators are EOA accounts with a private key. Staking module allows cosmwasm contracts and other modules as delegators so running the simulation when another module is the delegator will fail with

delegation addr: cosmos1srd5yxrg346qd7mne893gy3g43elh2sw7lz0s3 does not exist in simulation accounts

Current implementation https://github.com/cosmos/cosmos-sdk/blob/58f3a4a2375f0b617ee0ac3399085c1f996195ba/x/staking/simulation/operations.go#L551-L553

Suggestion to prevent the simulation from panic-ing here.

if simAccount.PrivKey == nil {
    return simtypes.NoOpMsg(types.ModuleName, msgType, "account private key is nil"), nil, nil
}

I can create a PR if core contributors think this should be updated. Thanks!

Version

Steps to Reproduce

We're running a custom module that stakes with a module account. Easiest way to reproduce would be to

  1. clone: https://github.com/yan-wl/feather-core/tree/refactor-app
  2. run go test -v -run=TestFullAppSimulation ./app -NumBlocks 200 -BlockSize 50 -Commit -Enabled -Seed 40
alexanderbez commented 1 year ago

Want to open a PR @javiersuweijie?

javiersuweijie commented 1 year ago

@alexanderbez Created the PR here: https://github.com/cosmos/cosmos-sdk/pull/16068