From 163e9d4d3246e4326e14b8b83f59da8dce5e6922 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 28 Jun 2023 06:59:54 +0800 Subject: [PATCH 1/2] feat: add custom max gas for block for sim config (#16656) (cherry picked from commit 9b2fd7bad9eac5015d10ed76c798826bfd63d44d) # Conflicts: # x/simulation/params.go --- CHANGELOG.md | 4 ++++ types/simulation/config.go | 3 ++- x/simulation/params.go | 6 +++++- x/simulation/simulate.go | 6 +++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e37750943bd..65e98c2e3d03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Features + +* (sims) [#16656](https://github.com/cosmos/cosmos-sdk/pull/16656) Add custom max gas for block for sim config with unlimited as default. + ### Improvements * (testutil) [#16704](https://github.com/cosmos/cosmos-sdk/pull/16704) Make app config configurator for testing for configurable. diff --git a/types/simulation/config.go b/types/simulation/config.go index 7f520004d478..4ed9530a92bc 100644 --- a/types/simulation/config.go +++ b/types/simulation/config.go @@ -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 } diff --git a/x/simulation/params.go b/x/simulation/params.go index d98373eb92b8..333e6071232a 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -176,7 +176,11 @@ func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulato // Consensus Params // randomConsensusParams returns random simulation consensus parameters, it extracts the Evidence from the Staking genesis state. +<<<<<<< HEAD func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec) *tmproto.ConsensusParams { +======= +func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec, maxGas int64) *cmtproto.ConsensusParams { +>>>>>>> 9b2fd7bad (feat: add custom max gas for block for sim config (#16656)) var genesisState map[string]json.RawMessage err := json.Unmarshal(appState, &genesisState) if err != nil { @@ -187,7 +191,7 @@ func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSO consensusParams := &tmproto.ConsensusParams{ Block: &tmproto.BlockParams{ MaxBytes: int64(simulation.RandIntBetween(r, 20000000, 30000000)), - MaxGas: -1, + MaxGas: maxGas, }, Validator: &tmproto.ValidatorParams{ PubKeyTypes: []string{types.ABCIPubKeyTypeEd25519}, diff --git a/x/simulation/simulate.go b/x/simulation/simulate.go index aca40c94f4b8..6affec9249ac 100644 --- a/x/simulation/simulate.go +++ b/x/simulation/simulate.go @@ -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, From f4a673a147828f8f64c6073dccfad0b385d8cb43 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 28 Jun 2023 11:00:09 +0200 Subject: [PATCH 2/2] fix conflicts --- x/simulation/params.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/x/simulation/params.go b/x/simulation/params.go index 333e6071232a..10c5cd7e4ca0 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -176,11 +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. -<<<<<<< HEAD -func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec) *tmproto.ConsensusParams { -======= -func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec, maxGas int64) *cmtproto.ConsensusParams { ->>>>>>> 9b2fd7bad (feat: add custom max gas for block for sim config (#16656)) +func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec, maxGas int64) *tmproto.ConsensusParams { var genesisState map[string]json.RawMessage err := json.Unmarshal(appState, &genesisState) if err != nil {