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

feat: add custom max gas for block for sim config #16656

Merged
merged 10 commits into from
Jun 27, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (cli) [#16209](https://github.com/cosmos/cosmos-sdk/pull/16209) Make `StartCmd` more customizable.
* (types) [#16257](https://github.com/cosmos/cosmos-sdk/pull/16257) Allow setting the base denom in the denom registry.
* (genutil) [#16046](https://github.com/cosmos/cosmos-sdk/pull/16046) Add "module-name" flag to genutil add-genesis-account to enable intializing module accounts at genesis.
* (sims) [#16656](https://github.com/cosmos/cosmos-sdk/pull/16656) Add custom max gas for block for sim config with unlimited as default.
Copy link
Member

Choose a reason for hiding this comment

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

nit, can you place the changelog under unreleased?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated, is it possible that we backport to v0.46.x as well


### Improvements

Expand Down
3 changes: 2 additions & 1 deletion types/simulation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ type Config struct {
OnOperation bool // run slow invariants every operation
AllInvariants bool // print all failed invariants if a broken invariant is found

DBBackend string // custom db backend type
DBBackend string // custom db backend type
BlockMaxGas int64 // custom max gas for block
}
4 changes: 2 additions & 2 deletions x/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulato
// Consensus Params

// randomConsensusParams returns random simulation consensus parameters, it extracts the Evidence from the Staking genesis state.
func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec) *cmtproto.ConsensusParams {
func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec, maxGas int64) *cmtproto.ConsensusParams {
var genesisState map[string]json.RawMessage
err := json.Unmarshal(appState, &genesisState)
if err != nil {
Expand All @@ -187,7 +187,7 @@ func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSO
consensusParams := &cmtproto.ConsensusParams{
Block: &cmtproto.BlockParams{
MaxBytes: int64(simulation.RandIntBetween(r, 20000000, 30000000)),
MaxGas: -1,
MaxGas: maxGas,
},
Validator: &cmtproto.ValidatorParams{
PubKeyTypes: []string{types.ABCIPubKeyTypeEd25519},
Expand Down
6 changes: 5 additions & 1 deletion x/simulation/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ func initChain(
config simulation.Config,
cdc codec.JSONCodec,
) (mockValidators, time.Time, []simulation.Account, string) {
blockMaxGas := int64(-1)
if config.BlockMaxGas > 0 {
blockMaxGas = config.BlockMaxGas
}
appState, accounts, chainID, genesisTimestamp := appStateFn(r, accounts, config)
consensusParams := randomConsensusParams(r, appState, cdc)
consensusParams := randomConsensusParams(r, appState, cdc, blockMaxGas)
req := abci.RequestInitChain{
AppStateBytes: appState,
ChainId: chainID,
Expand Down