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 (backport #16656) #16730

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
}
6 changes: 5 additions & 1 deletion x/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import (
"encoding/json"
"fmt"

Check failure on line 5 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / dependency-review

"fmt" imported but not used
"math/rand"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

Check failure on line 8 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / dependency-review

"github.com/cometbft/cometbft/proto/tendermint/types" imported but not used as tmproto
"github.com/cometbft/cometbft/types"

Check failure on line 9 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / dependency-review

"github.com/cometbft/cometbft/types" imported but not used

"github.com/cosmos/cosmos-sdk/codec"

Check failure on line 11 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / dependency-review

"github.com/cosmos/cosmos-sdk/codec" imported but not used
"github.com/cosmos/cosmos-sdk/types/simulation"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

Check failure on line 13 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / dependency-review

"github.com/cosmos/cosmos-sdk/x/staking/types" imported but not used as stakingtypes
)

const (
Expand Down Expand Up @@ -176,9 +176,13 @@
// Consensus Params

// randomConsensusParams returns random simulation consensus parameters, it extracts the Evidence from the Staking genesis state.
<<<<<<< HEAD

Check failure on line 179 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected declaration, found '<<'

Check failure on line 179 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected declaration, found '<<' (typecheck)

Check failure on line 179 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: non-declaration statement outside function body

Check failure on line 179 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: non-declaration statement outside function body

Check failure on line 179 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: non-declaration statement outside function body

Check failure on line 179 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: non-declaration statement outside function body

Check failure on line 179 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: non-declaration statement outside function body

Check failure on line 179 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: non-declaration statement outside function body

Check failure on line 179 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: non-declaration statement outside function body

Check failure on line 179 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: non-declaration statement outside function body
func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec) *tmproto.ConsensusParams {
=======

Check failure on line 181 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ==, expecting }

Check failure on line 181 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ==, expecting }

Check failure on line 181 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ==, expecting }

Check failure on line 181 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ==, expecting }

Check failure on line 181 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ==, expecting }

Check failure on line 181 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ==, expecting }

Check failure on line 181 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ==, expecting }

Check failure on line 181 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ==, expecting }
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))

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal character U+0023 '#' (typecheck)

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected >>, expecting }

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected >>, expecting }

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected >>, expecting }

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected >>, expecting }

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected >>, expecting }

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected >>, expecting }

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected >>, expecting }

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected >>, expecting }

Check failure on line 183 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'
facundomedica marked this conversation as resolved.
Show resolved Hide resolved
var genesisState map[string]json.RawMessage
err := json.Unmarshal(appState, &genesisState)

Check failure on line 185 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected declaration, found err

Check failure on line 185 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected declaration, found err (typecheck)

Check failure on line 185 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: non-declaration statement outside function body

Check failure on line 185 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: non-declaration statement outside function body

Check failure on line 185 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: non-declaration statement outside function body

Check failure on line 185 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: non-declaration statement outside function body

Check failure on line 185 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: non-declaration statement outside function body

Check failure on line 185 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: non-declaration statement outside function body

Check failure on line 185 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: non-declaration statement outside function body

Check failure on line 185 in x/simulation/params.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: non-declaration statement outside function body
if err != nil {
panic(err)
}
Expand All @@ -187,7 +191,7 @@
consensusParams := &tmproto.ConsensusParams{
Block: &tmproto.BlockParams{
MaxBytes: int64(simulation.RandIntBetween(r, 20000000, 30000000)),
MaxGas: -1,
MaxGas: maxGas,
},
Validator: &tmproto.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 @@
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)

Check failure on line 39 in x/simulation/simulate.go

View workflow job for this annotation

GitHub Actions / dependency-review

undeclared name: randomConsensusParams
req := abci.RequestInitChain{
AppStateBytes: appState,
ChainId: chainID,
Expand Down
Loading