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

Add consensus params into Simulation #6002

Merged
merged 25 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
752859c
temporal commit
jgimeno Apr 16, 2020
4b61cd1
add random consensus params
jgimeno Apr 17, 2020
351069a
Merge branch 'master' into jonathan/5988-sim-params-consensus
jgimeno Apr 17, 2020
bfbd275
make format
jgimeno Apr 17, 2020
ef06bbc
Merge branch 'master' into jonathan/5988-sim-params-consensus
jgimeno Apr 20, 2020
e734a7f
make random pass
jgimeno Apr 20, 2020
ede19d9
remove comment
jgimeno Apr 20, 2020
c275138
revert change
jgimeno Apr 20, 2020
b1a3403
update ub key types
jgimeno Apr 20, 2020
42b4c70
extract Evidence params from state
jgimeno Apr 20, 2020
d2382c9
extract the random parameters from state
jgimeno Apr 20, 2020
2f36081
clean the code
jgimeno Apr 20, 2020
cdcb9e9
Merge branch 'master' into jonathan/5988-sim-params-consensus
jgimeno Apr 20, 2020
af3c2fc
update imports!
jgimeno Apr 20, 2020
2b98aff
mispelled back
jgimeno Apr 20, 2020
d1d3355
mispelled back
jgimeno Apr 20, 2020
0e9ec1b
add misspelled command
jgimeno Apr 20, 2020
4125431
update changelog
jgimeno Apr 21, 2020
84341c8
Merge branch 'master' into jonathan/5988-sim-params-consensus
jgimeno Apr 21, 2020
d09de06
remove useless linter to avoid misspell
jgimeno Apr 21, 2020
2b3a6f3
Merge branch 'master' into jonathan/5988-sim-params-consensus
alexanderbez Apr 21, 2020
6c0e4ff
remove function
jgimeno Apr 21, 2020
2e52fcf
use tendermint constants
jgimeno Apr 21, 2020
fc895f0
Merge branch 'master' into jonathan/5988-sim-params-consensus
jgimeno Apr 21, 2020
6cf3eb0
Merge branch 'master' into jonathan/5988-sim-params-consensus
jgimeno Apr 21, 2020
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
2 changes: 1 addition & 1 deletion client/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestValidateCmd(t *testing.T) {
{"help flag", []string{"commission", "--help"}, false}, // nolint: misspell
{"shorthand help flag", []string{"commission", "-h"}, false}, // nolint: misspell
{"flag only, no command provided", []string{"--gas", "1000atom"}, false},
{"flag and misspelled command", []string{"--gas", "1000atom", "comission"}, true}, // nolint: misspell
{"flag and misspelled command", []string{"--gas", "1000atom", "commission"}, true}, // nolint: misspell
jgimeno marked this conversation as resolved.
Show resolved Hide resolved
}

for _, tt := range tests {
Expand Down
3 changes: 2 additions & 1 deletion x/ibc/09-localhost/types/localhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (

"github.com/stretchr/testify/suite"

dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/cachekv"
"github.com/cosmos/cosmos-sdk/store/dbadapter"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
dbm "github.com/tendermint/tm-db"
)

const (
Expand Down
23 changes: 23 additions & 0 deletions x/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package simulation
import (
"fmt"
"math/rand"
"time"

abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/types/simulation"
)
Expand Down Expand Up @@ -142,3 +145,23 @@ func (w WeightedProposalContent) DefaultWeight() int {
func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn {
return w.contentSimulatorFn
}

//-----------------------------------------------------------------------------
// Param change proposals

// RandomParams returns random simulation consensus parameters
func RandomConsensusParams(r *rand.Rand) *abci.ConsensusParams {
return &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: int64(simulation.RandIntBetween(r, 20000000, 30000000)),
MaxGas: -1,
},
Evidence: &abci.EvidenceParams{
MaxAgeNumBlocks: int64(simulation.RandIntBetween(r, 100000, 500000)),
jgimeno marked this conversation as resolved.
Show resolved Hide resolved
MaxAgeDuration: time.Duration(simulation.RandIntBetween(r, 10000, 50000)),
},
Validator: &abci.ValidatorParams{
PubKeyTypes: []string{"secp256k1"},
jgimeno marked this conversation as resolved.
Show resolved Hide resolved
},
}
}
13 changes: 8 additions & 5 deletions x/simulation/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ import (

// initialize the chain for the simulation
func initChain(
r *rand.Rand, params Params, accounts []simulation.Account, app *baseapp.BaseApp,
r *rand.Rand, params Params, consensusParams *abci.ConsensusParams, accounts []simulation.Account, app *baseapp.BaseApp,
appStateFn simulation.AppStateFn, config simulation.Config,
) (mockValidators, time.Time, []simulation.Account, string) {

appState, accounts, chainID, genesisTimestamp := appStateFn(r, accounts, config)

req := abci.RequestInitChain{
AppStateBytes: appState,
ChainId: chainID,
AppStateBytes: appState,
ChainId: chainID,
ConsensusParams: consensusParams,
}
res := app.InitChain(req)
validators := newMockValidators(r, res.Validators, params)
Expand All @@ -52,13 +53,15 @@ func SimulateFromSeed(
params := RandomParams(r)
fmt.Fprintf(w, "Randomized simulation params: \n%s\n", mustMarshalJSONIndent(params))

consParams := RandomConsensusParams(r)

timeDiff := maxTimePerBlock - minTimePerBlock
accs := simulation.RandomAccounts(r, params.NumKeys())
eventStats := NewEventStats()

// Second variable to keep pending validator set (delayed one block since
// TM 0.24) Initially this is the same as the initial validator set
validators, genesisTimestamp, accs, chainID := initChain(r, params, accs, app, appStateFn, config)
validators, genesisTimestamp, accs, chainID := initChain(r, params, consParams, accs, app, appStateFn, config)
if len(accs) == 0 {
return true, params, fmt.Errorf("must have greater than zero genesis accounts")
}
Expand Down Expand Up @@ -108,7 +111,7 @@ func SimulateFromSeed(

// These are operations which have been queued by previous operations
operationQueue := NewOperationQueue()
timeOperationQueue := []simulation.FutureOperation{}
var timeOperationQueue []simulation.FutureOperation

logWriter := NewLogWriter(testingMode)

Expand Down