cosmos-sdk/x/simulation/simulate.go

394 lines
12 KiB
Go
Raw Normal View History

2018-07-16 18:25:15 -07:00
package simulation
import (
"fmt"
"io"
"math/rand"
2018-08-29 23:02:15 -07:00
"os"
"os/signal"
"syscall"
"testing"
"time"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
2018-07-16 18:15:50 -07:00
"github.com/cosmos/cosmos-sdk/baseapp"
Use any as validator pubkey (#7597) * protobuf pubkey type update * wip2 * wip3 * solving types.NewValidator issues * remove bech32 from validator type assignment * update Validator interface * Changelog update * wip4 * update genutil * fix simapp & x/ibc/testing tests * update staking * changelog update * fix import cycle in tests * fix amino panic on TestValidatorMarshalUnmarshalJSON * fix TestValidatorMarshalUnmarshalJSON consensus_pubkey check * Add UnpackInterfaces to HistoricalInfo * fix TestHistoricalInfo * update todos * fix: Expecting ed25519.PubKey to implement proto.Message * fix linter issues * Fix migrate test * Update CHANGELOG.md Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * review comments * cosmetic changes * add UnpackInterfaces got GenesisRandomized test * Validator.Equal reuses Validator.MinEqual * fix test * use Validator.Equal in tests * Fix staking simulation TestRandomizedGenState * Remove TODO * use HistoricalInfo.Equal * use proto.Equal * rename Validator.GetConsPubKey to TmConsPubKey * prefer require.Equal over reflect.DeepEqual * SetHistoricalInfo using a pointer * Fix TestQueryDelegation test * Fix TestQueryValidators test * Fix TestSimulateMsgUnjail test * experiement with LegacyAmino instances * Register codecs in all simapp tests * Fix cli_test compilation problems * fix typo sdk -> std * fix typo * fix TestPlanStringer * Rename to MakeEncodingConfig * Remove RegisterCodecsTests * Use gRPC in GetCmdQueryValidators * Empty status * fix info log check * linter fixes * rename simapparams to simappparams * Update simapp/test_helpers.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * comments updates * use valAddr1 instead of sdk.ValAddress(pk1.Address().Bytes()) Co-authored-by: Cory Levinson <cjlevinson@gmail.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
2020-10-23 05:07:52 -07:00
"github.com/cosmos/cosmos-sdk/codec"
2018-07-17 15:04:10 -07:00
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/simulation"
)
const AverageBlockTime = 6 * time.Second
2018-11-07 20:26:02 -08:00
// initialize the chain for the simulation
func initChain(
r *rand.Rand,
params Params,
accounts []simulation.Account,
app *baseapp.BaseApp,
appStateFn simulation.AppStateFn,
config simulation.Config,
cdc codec.JSONCodec,
) (mockValidators, time.Time, []simulation.Account, string) {
2018-11-07 20:26:02 -08:00
appState, accounts, chainID, genesisTimestamp := appStateFn(r, accounts, config)
Use any as validator pubkey (#7597) * protobuf pubkey type update * wip2 * wip3 * solving types.NewValidator issues * remove bech32 from validator type assignment * update Validator interface * Changelog update * wip4 * update genutil * fix simapp & x/ibc/testing tests * update staking * changelog update * fix import cycle in tests * fix amino panic on TestValidatorMarshalUnmarshalJSON * fix TestValidatorMarshalUnmarshalJSON consensus_pubkey check * Add UnpackInterfaces to HistoricalInfo * fix TestHistoricalInfo * update todos * fix: Expecting ed25519.PubKey to implement proto.Message * fix linter issues * Fix migrate test * Update CHANGELOG.md Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * review comments * cosmetic changes * add UnpackInterfaces got GenesisRandomized test * Validator.Equal reuses Validator.MinEqual * fix test * use Validator.Equal in tests * Fix staking simulation TestRandomizedGenState * Remove TODO * use HistoricalInfo.Equal * use proto.Equal * rename Validator.GetConsPubKey to TmConsPubKey * prefer require.Equal over reflect.DeepEqual * SetHistoricalInfo using a pointer * Fix TestQueryDelegation test * Fix TestQueryValidators test * Fix TestSimulateMsgUnjail test * experiement with LegacyAmino instances * Register codecs in all simapp tests * Fix cli_test compilation problems * fix typo sdk -> std * fix typo * fix TestPlanStringer * Rename to MakeEncodingConfig * Remove RegisterCodecsTests * Use gRPC in GetCmdQueryValidators * Empty status * fix info log check * linter fixes * rename simapparams to simappparams * Update simapp/test_helpers.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * comments updates * use valAddr1 instead of sdk.ValAddress(pk1.Address().Bytes()) Co-authored-by: Cory Levinson <cjlevinson@gmail.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
2020-10-23 05:07:52 -07:00
consensusParams := randomConsensusParams(r, appState, cdc)
2018-11-07 20:26:02 -08:00
req := abci.RequestInitChain{
AppStateBytes: appState,
ChainId: chainID,
ConsensusParams: consensusParams,
Time: genesisTimestamp,
2018-08-29 23:02:15 -07:00
}
2018-11-07 20:26:02 -08:00
res := app.InitChain(req)
2018-11-07 22:57:37 -08:00
validators := newMockValidators(r, res.Validators, params)
2018-08-29 23:02:15 -07:00
update simulation operations to use BaseApp (#4946) * update operations to use baseapp * updates and cleanup operations * update operations * restructure sim ops params * rename sim /operations/msg.go to /operations.go * move GenTx to a helper pkg to avoid circle deps * rm msg.ValidateBasic * changelog * random fees; delete auth's DeductFees sim operation * add chain-id for sig verification * Update x/simulation/account.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * fix bank, gov and distr errors * fix staking and slashing errors; increase prob for send enabled * increase gas x10 * make format * fix some distr and staking edge cases * fix all edge cases * golang ci * rename acc vars; default no fees to 0stake * cleanup; check for exchange rate and skip invalid ops * fixes * check for max entries * add pubkey to genaccounts * fix gov bug * update staking sim ops * fix small redelegation error * fix small self delegation on unjail * rm inf loop on random val/accs * copy array * add ok boolean to RandomValidator return values * format * Update x/bank/simulation/operations.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * Update simapp/helpers/test_helpers.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * address @colin-axner comments * add genaccount pubkey validation * fix test * update operations and move RandomFees to x/simulation * update gov ops * address @alexanderbez comments * avoid modifications to config * reorder params * changelog * Update x/distribution/simulation/genesis.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * remove named return values * ensure all operations are simulated * golangci * add nolint * disable whitespace and funlen linter * disable godox * add TODO on unjail * update ops weights * remove dup * update godoc * x/slashing/simulation/operations.go linting * x/staking/simulation/operations.go linting * update operations format * x/bank/simulation/operations.go linting * x/distribution/simulation/operations.go linting * x/staking/simulation/operations.go linting * start changes: make bank simulate send multiple coins, code cleanup * fix nondeterminism bug * fix txsiglimit err * fix multisend bug * simplify simulation, cleanup opt privkey args * make slashing test invalid unjail msgs * Update simapp/state.go * golangCI changes
2019-10-23 02:14:45 -07:00
return validators, genesisTimestamp, accounts, chainID
2018-08-29 23:02:15 -07:00
}
2018-07-17 11:33:53 -07:00
// SimulateFromSeed tests an application by running the provided
// operations, testing the provided invariants, but using the provided config.Seed.
// TODO: split this monster function up
func SimulateFromSeed(
tb testing.TB,
w io.Writer,
app *baseapp.BaseApp,
appStateFn simulation.AppStateFn,
randAccFn simulation.RandomAccountFn,
ops WeightedOperations,
blockedAddrs map[string]bool,
config simulation.Config,
cdc codec.JSONCodec,
) (stopEarly bool, exportedParams Params, err error) {
// in case we have to end early, don't os.Exit so that we can run cleanup code.
testingMode, _, b := getTestingMode(tb)
2018-11-07 21:12:51 -08:00
fmt.Fprintf(w, "Starting SimulateFromSeed with randomness created with seed %d\n", int(config.Seed))
r := rand.New(rand.NewSource(config.Seed))
params := RandomParams(r)
fmt.Fprintf(w, "Randomized simulation params: \n%s\n", mustMarshalJSONIndent(params))
2018-11-07 21:12:51 -08:00
timeDiff := maxTimePerBlock - minTimePerBlock
accs := randAccFn(r, params.NumKeys())
eventStats := NewEventStats()
2018-11-07 09:19:58 -08:00
// Second variable to keep pending validator set (delayed one block since
// TM 0.24) Initially this is the same as the initial validator set
Use any as validator pubkey (#7597) * protobuf pubkey type update * wip2 * wip3 * solving types.NewValidator issues * remove bech32 from validator type assignment * update Validator interface * Changelog update * wip4 * update genutil * fix simapp & x/ibc/testing tests * update staking * changelog update * fix import cycle in tests * fix amino panic on TestValidatorMarshalUnmarshalJSON * fix TestValidatorMarshalUnmarshalJSON consensus_pubkey check * Add UnpackInterfaces to HistoricalInfo * fix TestHistoricalInfo * update todos * fix: Expecting ed25519.PubKey to implement proto.Message * fix linter issues * Fix migrate test * Update CHANGELOG.md Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * review comments * cosmetic changes * add UnpackInterfaces got GenesisRandomized test * Validator.Equal reuses Validator.MinEqual * fix test * use Validator.Equal in tests * Fix staking simulation TestRandomizedGenState * Remove TODO * use HistoricalInfo.Equal * use proto.Equal * rename Validator.GetConsPubKey to TmConsPubKey * prefer require.Equal over reflect.DeepEqual * SetHistoricalInfo using a pointer * Fix TestQueryDelegation test * Fix TestQueryValidators test * Fix TestSimulateMsgUnjail test * experiement with LegacyAmino instances * Register codecs in all simapp tests * Fix cli_test compilation problems * fix typo sdk -> std * fix typo * fix TestPlanStringer * Rename to MakeEncodingConfig * Remove RegisterCodecsTests * Use gRPC in GetCmdQueryValidators * Empty status * fix info log check * linter fixes * rename simapparams to simappparams * Update simapp/test_helpers.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * comments updates * use valAddr1 instead of sdk.ValAddress(pk1.Address().Bytes()) Co-authored-by: Cory Levinson <cjlevinson@gmail.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
2020-10-23 05:07:52 -07:00
validators, genesisTimestamp, accs, chainID := initChain(r, params, accs, app, appStateFn, config, cdc)
if len(accs) == 0 {
return true, params, fmt.Errorf("must have greater than zero genesis accounts")
}
update simulation operations to use BaseApp (#4946) * update operations to use baseapp * updates and cleanup operations * update operations * restructure sim ops params * rename sim /operations/msg.go to /operations.go * move GenTx to a helper pkg to avoid circle deps * rm msg.ValidateBasic * changelog * random fees; delete auth's DeductFees sim operation * add chain-id for sig verification * Update x/simulation/account.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * fix bank, gov and distr errors * fix staking and slashing errors; increase prob for send enabled * increase gas x10 * make format * fix some distr and staking edge cases * fix all edge cases * golang ci * rename acc vars; default no fees to 0stake * cleanup; check for exchange rate and skip invalid ops * fixes * check for max entries * add pubkey to genaccounts * fix gov bug * update staking sim ops * fix small redelegation error * fix small self delegation on unjail * rm inf loop on random val/accs * copy array * add ok boolean to RandomValidator return values * format * Update x/bank/simulation/operations.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * Update simapp/helpers/test_helpers.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * address @colin-axner comments * add genaccount pubkey validation * fix test * update operations and move RandomFees to x/simulation * update gov ops * address @alexanderbez comments * avoid modifications to config * reorder params * changelog * Update x/distribution/simulation/genesis.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * remove named return values * ensure all operations are simulated * golangci * add nolint * disable whitespace and funlen linter * disable godox * add TODO on unjail * update ops weights * remove dup * update godoc * x/slashing/simulation/operations.go linting * x/staking/simulation/operations.go linting * update operations format * x/bank/simulation/operations.go linting * x/distribution/simulation/operations.go linting * x/staking/simulation/operations.go linting * start changes: make bank simulate send multiple coins, code cleanup * fix nondeterminism bug * fix txsiglimit err * fix multisend bug * simplify simulation, cleanup opt privkey args * make slashing test invalid unjail msgs * Update simapp/state.go * golangCI changes
2019-10-23 02:14:45 -07:00
config.ChainID = chainID
fmt.Printf(
"Starting the simulation from time %v (unixtime %v)\n",
genesisTimestamp.UTC().Format(time.UnixDate), genesisTimestamp.Unix(),
)
// remove module account address if they exist in accs
var tmpAccs []simulation.Account
for _, acc := range accs {
if !blockedAddrs[acc.Address.String()] {
tmpAccs = append(tmpAccs, acc)
}
}
accs = tmpAccs
2018-11-07 22:57:37 -08:00
nextValidators := validators
header := tmproto.Header{
update simulation operations to use BaseApp (#4946) * update operations to use baseapp * updates and cleanup operations * update operations * restructure sim ops params * rename sim /operations/msg.go to /operations.go * move GenTx to a helper pkg to avoid circle deps * rm msg.ValidateBasic * changelog * random fees; delete auth's DeductFees sim operation * add chain-id for sig verification * Update x/simulation/account.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * fix bank, gov and distr errors * fix staking and slashing errors; increase prob for send enabled * increase gas x10 * make format * fix some distr and staking edge cases * fix all edge cases * golang ci * rename acc vars; default no fees to 0stake * cleanup; check for exchange rate and skip invalid ops * fixes * check for max entries * add pubkey to genaccounts * fix gov bug * update staking sim ops * fix small redelegation error * fix small self delegation on unjail * rm inf loop on random val/accs * copy array * add ok boolean to RandomValidator return values * format * Update x/bank/simulation/operations.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * Update simapp/helpers/test_helpers.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * address @colin-axner comments * add genaccount pubkey validation * fix test * update operations and move RandomFees to x/simulation * update gov ops * address @alexanderbez comments * avoid modifications to config * reorder params * changelog * Update x/distribution/simulation/genesis.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * remove named return values * ensure all operations are simulated * golangci * add nolint * disable whitespace and funlen linter * disable godox * add TODO on unjail * update ops weights * remove dup * update godoc * x/slashing/simulation/operations.go linting * x/staking/simulation/operations.go linting * update operations format * x/bank/simulation/operations.go linting * x/distribution/simulation/operations.go linting * x/staking/simulation/operations.go linting * start changes: make bank simulate send multiple coins, code cleanup * fix nondeterminism bug * fix txsiglimit err * fix multisend bug * simplify simulation, cleanup opt privkey args * make slashing test invalid unjail msgs * Update simapp/state.go * golangCI changes
2019-10-23 02:14:45 -07:00
ChainID: config.ChainID,
2018-11-07 09:19:58 -08:00
Height: 1,
Time: genesisTimestamp,
2018-11-07 22:57:37 -08:00
ProposerAddress: validators.randomProposer(r),
2018-11-07 09:19:58 -08:00
}
opCount := 0
// Setup code to catch SIGTERM's
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
go func() {
receivedSignal := <-c
fmt.Fprintf(w, "\nExiting early due to %s, on block %d, operation %d\n", receivedSignal, header.Height, opCount)
2019-08-19 09:06:27 -07:00
err = fmt.Errorf("exited due to %s", receivedSignal)
stopEarly = true
}()
var (
pastTimes []time.Time
pastVoteInfos [][]abci.VoteInfo
)
2018-11-07 09:19:58 -08:00
request := RandomRequestBeginBlock(r, params,
validators, pastTimes, pastVoteInfos, eventStats.Tally, header)
2018-11-07 07:28:18 -08:00
// These are operations which have been queued by previous operations
operationQueue := NewOperationQueue()
var timeOperationQueue []simulation.FutureOperation
2019-03-14 11:13:15 -07:00
logWriter := NewLogWriter(testingMode)
2018-11-07 07:28:18 -08:00
blockSimulator := createBlockSimulator(
testingMode, tb, w, params, eventStats.Tally,
ops, operationQueue, timeOperationQueue, logWriter, config)
2018-11-07 07:28:18 -08:00
if !testingMode {
b.ResetTimer()
} else {
2019-08-07 09:54:13 -07:00
// recover logs in case of panic
defer func() {
if r := recover(); r != nil {
update simulation operations to use BaseApp (#4946) * update operations to use baseapp * updates and cleanup operations * update operations * restructure sim ops params * rename sim /operations/msg.go to /operations.go * move GenTx to a helper pkg to avoid circle deps * rm msg.ValidateBasic * changelog * random fees; delete auth's DeductFees sim operation * add chain-id for sig verification * Update x/simulation/account.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * fix bank, gov and distr errors * fix staking and slashing errors; increase prob for send enabled * increase gas x10 * make format * fix some distr and staking edge cases * fix all edge cases * golang ci * rename acc vars; default no fees to 0stake * cleanup; check for exchange rate and skip invalid ops * fixes * check for max entries * add pubkey to genaccounts * fix gov bug * update staking sim ops * fix small redelegation error * fix small self delegation on unjail * rm inf loop on random val/accs * copy array * add ok boolean to RandomValidator return values * format * Update x/bank/simulation/operations.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * Update simapp/helpers/test_helpers.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * address @colin-axner comments * add genaccount pubkey validation * fix test * update operations and move RandomFees to x/simulation * update gov ops * address @alexanderbez comments * avoid modifications to config * reorder params * changelog * Update x/distribution/simulation/genesis.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * remove named return values * ensure all operations are simulated * golangci * add nolint * disable whitespace and funlen linter * disable godox * add TODO on unjail * update ops weights * remove dup * update godoc * x/slashing/simulation/operations.go linting * x/staking/simulation/operations.go linting * update operations format * x/bank/simulation/operations.go linting * x/distribution/simulation/operations.go linting * x/staking/simulation/operations.go linting * start changes: make bank simulate send multiple coins, code cleanup * fix nondeterminism bug * fix txsiglimit err * fix multisend bug * simplify simulation, cleanup opt privkey args * make slashing test invalid unjail msgs * Update simapp/state.go * golangCI changes
2019-10-23 02:14:45 -07:00
_, _ = fmt.Fprintf(w, "simulation halted due to panic on block %d\n", header.Height)
2019-03-14 11:13:15 -07:00
logWriter.PrintLogs()
2019-08-07 09:54:13 -07:00
panic(r)
}
}()
}
2018-08-30 00:13:31 -07:00
// set exported params to the initial state
if config.ExportParamsPath != "" && config.ExportParamsHeight == 0 {
exportedParams = params
}
// TODO: split up the contents of this for loop into new functions
for height := config.InitialBlockHeight; height < config.NumBlocks+config.InitialBlockHeight && !stopEarly; height++ {
2018-09-01 12:32:24 -07:00
// Log the header time for future lookup
pastTimes = append(pastTimes, header.Time)
pastVoteInfos = append(pastVoteInfos, request.LastCommitInfo.Votes)
2018-09-01 12:32:24 -07:00
// Run the BeginBlock handler
2019-03-14 11:13:15 -07:00
logWriter.AddEntry(BeginBlockEntry(int64(height)))
app.BeginBlock(request)
ctx := app.NewContext(false, header)
2018-08-29 23:02:15 -07:00
// Run queued operations. Ignores blocksize if blocksize is too small
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
numQueuedOpsRan, futureOps := runQueuedOperations(
update simulation operations to use BaseApp (#4946) * update operations to use baseapp * updates and cleanup operations * update operations * restructure sim ops params * rename sim /operations/msg.go to /operations.go * move GenTx to a helper pkg to avoid circle deps * rm msg.ValidateBasic * changelog * random fees; delete auth's DeductFees sim operation * add chain-id for sig verification * Update x/simulation/account.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * fix bank, gov and distr errors * fix staking and slashing errors; increase prob for send enabled * increase gas x10 * make format * fix some distr and staking edge cases * fix all edge cases * golang ci * rename acc vars; default no fees to 0stake * cleanup; check for exchange rate and skip invalid ops * fixes * check for max entries * add pubkey to genaccounts * fix gov bug * update staking sim ops * fix small redelegation error * fix small self delegation on unjail * rm inf loop on random val/accs * copy array * add ok boolean to RandomValidator return values * format * Update x/bank/simulation/operations.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * Update simapp/helpers/test_helpers.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * address @colin-axner comments * add genaccount pubkey validation * fix test * update operations and move RandomFees to x/simulation * update gov ops * address @alexanderbez comments * avoid modifications to config * reorder params * changelog * Update x/distribution/simulation/genesis.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * remove named return values * ensure all operations are simulated * golangci * add nolint * disable whitespace and funlen linter * disable godox * add TODO on unjail * update ops weights * remove dup * update godoc * x/slashing/simulation/operations.go linting * x/staking/simulation/operations.go linting * update operations format * x/bank/simulation/operations.go linting * x/distribution/simulation/operations.go linting * x/staking/simulation/operations.go linting * start changes: make bank simulate send multiple coins, code cleanup * fix nondeterminism bug * fix txsiglimit err * fix multisend bug * simplify simulation, cleanup opt privkey args * make slashing test invalid unjail msgs * Update simapp/state.go * golangCI changes
2019-10-23 02:14:45 -07:00
operationQueue, int(header.Height), tb, r, app, ctx, accs, logWriter,
eventStats.Tally, config.Lean, config.ChainID,
)
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
numQueuedTimeOpsRan, timeFutureOps := runQueuedTimeOperations(
2019-03-14 11:13:15 -07:00
timeOperationQueue, int(header.Height), header.Time,
update simulation operations to use BaseApp (#4946) * update operations to use baseapp * updates and cleanup operations * update operations * restructure sim ops params * rename sim /operations/msg.go to /operations.go * move GenTx to a helper pkg to avoid circle deps * rm msg.ValidateBasic * changelog * random fees; delete auth's DeductFees sim operation * add chain-id for sig verification * Update x/simulation/account.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * fix bank, gov and distr errors * fix staking and slashing errors; increase prob for send enabled * increase gas x10 * make format * fix some distr and staking edge cases * fix all edge cases * golang ci * rename acc vars; default no fees to 0stake * cleanup; check for exchange rate and skip invalid ops * fixes * check for max entries * add pubkey to genaccounts * fix gov bug * update staking sim ops * fix small redelegation error * fix small self delegation on unjail * rm inf loop on random val/accs * copy array * add ok boolean to RandomValidator return values * format * Update x/bank/simulation/operations.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * Update simapp/helpers/test_helpers.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * address @colin-axner comments * add genaccount pubkey validation * fix test * update operations and move RandomFees to x/simulation * update gov ops * address @alexanderbez comments * avoid modifications to config * reorder params * changelog * Update x/distribution/simulation/genesis.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * remove named return values * ensure all operations are simulated * golangci * add nolint * disable whitespace and funlen linter * disable godox * add TODO on unjail * update ops weights * remove dup * update godoc * x/slashing/simulation/operations.go linting * x/staking/simulation/operations.go linting * update operations format * x/bank/simulation/operations.go linting * x/distribution/simulation/operations.go linting * x/staking/simulation/operations.go linting * start changes: make bank simulate send multiple coins, code cleanup * fix nondeterminism bug * fix txsiglimit err * fix multisend bug * simplify simulation, cleanup opt privkey args * make slashing test invalid unjail msgs * Update simapp/state.go * golangCI changes
2019-10-23 02:14:45 -07:00
tb, r, app, ctx, accs, logWriter, eventStats.Tally,
config.Lean, config.ChainID,
)
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
futureOps = append(futureOps, timeFutureOps...)
queueOperations(operationQueue, timeOperationQueue, futureOps)
2019-03-14 11:13:15 -07:00
// run standard operations
operations := blockSimulator(r, app, ctx, accs, header)
opCount += operations + numQueuedOpsRan + numQueuedTimeOpsRan
res := app.EndBlock(abci.RequestEndBlock{})
header.Height++
2018-11-07 07:28:18 -08:00
header.Time = header.Time.Add(
time.Duration(minTimePerBlock) * time.Second)
header.Time = header.Time.Add(
time.Duration(int64(r.Intn(int(timeDiff)))) * time.Second)
2018-11-07 22:57:37 -08:00
header.ProposerAddress = validators.randomProposer(r)
2019-03-14 11:13:15 -07:00
logWriter.AddEntry(EndBlockEntry(int64(height)))
if config.Commit {
app.Commit()
}
if header.ProposerAddress == nil {
fmt.Fprintf(w, "\nSimulation stopped early as all validators have been unbonded; nobody left to propose a block!\n")
stopEarly = true
break
}
// Generate a random RequestBeginBlock with the current validator set
// for the next block
request = RandomRequestBeginBlock(r, params, validators, pastTimes, pastVoteInfos, eventStats.Tally, header)
// Update the validator set, which will be reflected in the application
// on the next block
validators = nextValidators
nextValidators = updateValidators(tb, r, params, validators, res.ValidatorUpdates, eventStats.Tally)
// update the exported params
if config.ExportParamsPath != "" && config.ExportParamsHeight == height {
exportedParams = params
}
}
if stopEarly {
if config.ExportStatsPath != "" {
fmt.Println("Exporting simulation statistics...")
eventStats.ExportJSON(config.ExportStatsPath)
} else {
eventStats.Print(w)
}
return true, exportedParams, err
}
fmt.Fprintf(
w,
"\nSimulation complete; Final height (blocks): %d, final time (seconds): %v, operations ran: %d\n",
header.Height, header.Time, opCount,
)
if config.ExportStatsPath != "" {
fmt.Println("Exporting simulation statistics...")
eventStats.ExportJSON(config.ExportStatsPath)
} else {
eventStats.Print(w)
}
return false, exportedParams, nil
}
2018-11-07 07:28:18 -08:00
type blockSimFn func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
accounts []simulation.Account, header tmproto.Header) (opCount int)
2018-10-31 10:11:41 -07:00
2018-11-07 20:26:02 -08:00
// Returns a function to simulate blocks. Written like this to avoid constant
2018-11-07 21:12:51 -08:00
// parameters being passed everytime, to minimize memory overhead.
func createBlockSimulator(testingMode bool, tb testing.TB, w io.Writer, params Params,
event func(route, op, evResult string), ops WeightedOperations,
operationQueue OperationQueue, timeOperationQueue []simulation.FutureOperation,
logWriter LogWriter, config simulation.Config) blockSimFn {
2018-10-31 09:37:50 -07:00
2019-08-07 09:54:13 -07:00
lastBlockSizeState := 0 // state for [4 * uniform distribution]
2019-03-14 11:13:15 -07:00
blocksize := 0
2018-11-07 20:26:02 -08:00
selectOp := ops.getSelectOpFn()
2019-08-07 09:54:13 -07:00
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simulation.Account, header tmproto.Header,
2019-08-07 09:54:13 -07:00
) (opCount int) {
_, _ = fmt.Fprintf(
w, "\rSimulating... block %d/%d, operation %d/%d.",
header.Height, config.NumBlocks, opCount, blocksize,
2019-08-07 09:54:13 -07:00
)
lastBlockSizeState, blocksize = getBlockSize(r, params, lastBlockSizeState, config.BlockSize)
2018-11-07 07:28:18 -08:00
type opAndR struct {
op simulation.Operation
rand *rand.Rand
}
2019-08-07 09:54:13 -07:00
opAndRz := make([]opAndR, 0, blocksize)
2019-08-07 09:54:13 -07:00
// Predetermine the blocksize slice so that we can do things like block
// out certain operations without changing the ops that follow.
for i := 0; i < blocksize; i++ {
opAndRz = append(opAndRz, opAndR{
op: selectOp(r),
rand: simulation.DeriveRand(r),
})
}
for i := 0; i < blocksize; i++ {
// NOTE: the Rand 'r' should not be used here.
opAndR := opAndRz[i]
op, r2 := opAndR.op, opAndR.rand
update simulation operations to use BaseApp (#4946) * update operations to use baseapp * updates and cleanup operations * update operations * restructure sim ops params * rename sim /operations/msg.go to /operations.go * move GenTx to a helper pkg to avoid circle deps * rm msg.ValidateBasic * changelog * random fees; delete auth's DeductFees sim operation * add chain-id for sig verification * Update x/simulation/account.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * fix bank, gov and distr errors * fix staking and slashing errors; increase prob for send enabled * increase gas x10 * make format * fix some distr and staking edge cases * fix all edge cases * golang ci * rename acc vars; default no fees to 0stake * cleanup; check for exchange rate and skip invalid ops * fixes * check for max entries * add pubkey to genaccounts * fix gov bug * update staking sim ops * fix small redelegation error * fix small self delegation on unjail * rm inf loop on random val/accs * copy array * add ok boolean to RandomValidator return values * format * Update x/bank/simulation/operations.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * Update simapp/helpers/test_helpers.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * address @colin-axner comments * add genaccount pubkey validation * fix test * update operations and move RandomFees to x/simulation * update gov ops * address @alexanderbez comments * avoid modifications to config * reorder params * changelog * Update x/distribution/simulation/genesis.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * remove named return values * ensure all operations are simulated * golangci * add nolint * disable whitespace and funlen linter * disable godox * add TODO on unjail * update ops weights * remove dup * update godoc * x/slashing/simulation/operations.go linting * x/staking/simulation/operations.go linting * update operations format * x/bank/simulation/operations.go linting * x/distribution/simulation/operations.go linting * x/staking/simulation/operations.go linting * start changes: make bank simulate send multiple coins, code cleanup * fix nondeterminism bug * fix txsiglimit err * fix multisend bug * simplify simulation, cleanup opt privkey args * make slashing test invalid unjail msgs * Update simapp/state.go * golangCI changes
2019-10-23 02:14:45 -07:00
opMsg, futureOps, err := op(r2, app, ctx, accounts, config.ChainID)
2019-03-14 11:13:15 -07:00
opMsg.LogEvent(event)
if !config.Lean || opMsg.OK {
logWriter.AddEntry(MsgEntry(header.Height, int64(i), opMsg))
2019-03-14 11:13:15 -07:00
}
if err != nil {
2019-03-14 11:13:15 -07:00
logWriter.PrintLogs()
update simulation operations to use BaseApp (#4946) * update operations to use baseapp * updates and cleanup operations * update operations * restructure sim ops params * rename sim /operations/msg.go to /operations.go * move GenTx to a helper pkg to avoid circle deps * rm msg.ValidateBasic * changelog * random fees; delete auth's DeductFees sim operation * add chain-id for sig verification * Update x/simulation/account.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * fix bank, gov and distr errors * fix staking and slashing errors; increase prob for send enabled * increase gas x10 * make format * fix some distr and staking edge cases * fix all edge cases * golang ci * rename acc vars; default no fees to 0stake * cleanup; check for exchange rate and skip invalid ops * fixes * check for max entries * add pubkey to genaccounts * fix gov bug * update staking sim ops * fix small redelegation error * fix small self delegation on unjail * rm inf loop on random val/accs * copy array * add ok boolean to RandomValidator return values * format * Update x/bank/simulation/operations.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * Update simapp/helpers/test_helpers.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * address @colin-axner comments * add genaccount pubkey validation * fix test * update operations and move RandomFees to x/simulation * update gov ops * address @alexanderbez comments * avoid modifications to config * reorder params * changelog * Update x/distribution/simulation/genesis.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * remove named return values * ensure all operations are simulated * golangci * add nolint * disable whitespace and funlen linter * disable godox * add TODO on unjail * update ops weights * remove dup * update godoc * x/slashing/simulation/operations.go linting * x/staking/simulation/operations.go linting * update operations format * x/bank/simulation/operations.go linting * x/distribution/simulation/operations.go linting * x/staking/simulation/operations.go linting * start changes: make bank simulate send multiple coins, code cleanup * fix nondeterminism bug * fix txsiglimit err * fix multisend bug * simplify simulation, cleanup opt privkey args * make slashing test invalid unjail msgs * Update simapp/state.go * golangCI changes
2019-10-23 02:14:45 -07:00
tb.Fatalf(`error on block %d/%d, operation (%d/%d) from x/%s:
%v
Comment: %s`,
header.Height, config.NumBlocks, opCount, blocksize, opMsg.Route, err, opMsg.Comment)
}
queueOperations(operationQueue, timeOperationQueue, futureOps)
if testingMode && opCount%50 == 0 {
fmt.Fprintf(w, "\rSimulating... block %d/%d, operation %d/%d. ",
header.Height, config.NumBlocks, opCount, blocksize)
}
opCount++
}
return opCount
}
}
2018-09-03 09:47:24 -07:00
// nolint: errcheck
func runQueuedOperations(queueOps map[int][]simulation.Operation,
height int, tb testing.TB, r *rand.Rand, app *baseapp.BaseApp,
ctx sdk.Context, accounts []simulation.Account, logWriter LogWriter,
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
event func(route, op, evResult string), lean bool, chainID string) (numOpsRan int, allFutureOps []simulation.FutureOperation) {
2018-11-07 07:28:18 -08:00
2018-11-07 09:19:58 -08:00
queuedOp, ok := queueOps[height]
if !ok {
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
return 0, nil
2018-11-07 09:19:58 -08:00
}
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
// Keep all future operations
allFutureOps = make([]simulation.FutureOperation, 0)
numOpsRan = len(queuedOp)
for i := 0; i < numOpsRan; i++ {
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
opMsg, futureOps, err := queuedOp[i](r, app, ctx, accounts, chainID)
if futureOps != nil && len(futureOps) > 0 {
allFutureOps = append(allFutureOps, futureOps...)
}
opMsg.LogEvent(event)
2019-03-14 11:13:15 -07:00
if !lean || opMsg.OK {
logWriter.AddEntry((QueuedMsgEntry(int64(height), opMsg)))
}
2018-11-07 09:19:58 -08:00
if err != nil {
2019-03-14 11:13:15 -07:00
logWriter.PrintLogs()
2018-11-07 09:19:58 -08:00
tb.FailNow()
}
}
2018-11-07 09:19:58 -08:00
delete(queueOps, height)
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
return numOpsRan, allFutureOps
}
func runQueuedTimeOperations(queueOps []simulation.FutureOperation,
2019-03-14 11:13:15 -07:00
height int, currentTime time.Time, tb testing.TB, r *rand.Rand,
app *baseapp.BaseApp, ctx sdk.Context, accounts []simulation.Account,
update simulation operations to use BaseApp (#4946) * update operations to use baseapp * updates and cleanup operations * update operations * restructure sim ops params * rename sim /operations/msg.go to /operations.go * move GenTx to a helper pkg to avoid circle deps * rm msg.ValidateBasic * changelog * random fees; delete auth's DeductFees sim operation * add chain-id for sig verification * Update x/simulation/account.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * fix bank, gov and distr errors * fix staking and slashing errors; increase prob for send enabled * increase gas x10 * make format * fix some distr and staking edge cases * fix all edge cases * golang ci * rename acc vars; default no fees to 0stake * cleanup; check for exchange rate and skip invalid ops * fixes * check for max entries * add pubkey to genaccounts * fix gov bug * update staking sim ops * fix small redelegation error * fix small self delegation on unjail * rm inf loop on random val/accs * copy array * add ok boolean to RandomValidator return values * format * Update x/bank/simulation/operations.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * Update simapp/helpers/test_helpers.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * address @colin-axner comments * add genaccount pubkey validation * fix test * update operations and move RandomFees to x/simulation * update gov ops * address @alexanderbez comments * avoid modifications to config * reorder params * changelog * Update x/distribution/simulation/genesis.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * remove named return values * ensure all operations are simulated * golangci * add nolint * disable whitespace and funlen linter * disable godox * add TODO on unjail * update ops weights * remove dup * update godoc * x/slashing/simulation/operations.go linting * x/staking/simulation/operations.go linting * update operations format * x/bank/simulation/operations.go linting * x/distribution/simulation/operations.go linting * x/staking/simulation/operations.go linting * start changes: make bank simulate send multiple coins, code cleanup * fix nondeterminism bug * fix txsiglimit err * fix multisend bug * simplify simulation, cleanup opt privkey args * make slashing test invalid unjail msgs * Update simapp/state.go * golangCI changes
2019-10-23 02:14:45 -07:00
logWriter LogWriter, event func(route, op, evResult string),
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
lean bool, chainID string) (numOpsRan int, allFutureOps []simulation.FutureOperation) {
// Keep all future operations
allFutureOps = make([]simulation.FutureOperation, 0)
numOpsRan = 0
2018-11-07 09:00:13 -08:00
for len(queueOps) > 0 && currentTime.After(queueOps[0].BlockTime) {
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
opMsg, futureOps, err := queueOps[0].Op(r, app, ctx, accounts, chainID)
opMsg.LogEvent(event)
2019-03-14 11:13:15 -07:00
if !lean || opMsg.OK {
logWriter.AddEntry(QueuedMsgEntry(int64(height), opMsg))
}
if err != nil {
2019-03-14 11:13:15 -07:00
logWriter.PrintLogs()
tb.FailNow()
}
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
if futureOps != nil && len(futureOps) > 0 {
allFutureOps = append(allFutureOps, futureOps...)
}
2018-11-07 09:00:13 -08:00
queueOps = queueOps[1:]
numOpsRan++
}
feat: Allow futureOps to queue more Ops (#10469) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description I modified where we handle queued operations to get all of the future operations from each queued operation that is executed. We then add any new futureOps to the queued ops list. This enables simulations to run chains of Operations rather than only being able to go one layer deep. This is helpful in the case of building simulations around smart contracts that require multiple operations occurring in order. Closes: #10468 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-11-11 01:32:06 -08:00
return numOpsRan, allFutureOps
}