diff --git a/CHANGELOG.md b/CHANGELOG.md index 73235a201b9a..6565b5cdd74d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -130,6 +130,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#9699](https://github.com/cosmos/cosmos-sdk/pull/9699) Add `:`, `.`, `-`, and `_` as allowed characters in the default denom regular expression. * (genesis) [\#9697](https://github.com/cosmos/cosmos-sdk/pull/9697) Ensure `InitGenesis` returns with non-empty validator set. * [\#10341](https://github.com/cosmos/cosmos-sdk/pull/10341) Move from `io/ioutil` to `io` and `os` packages. +* [\#10468](https://github.com/cosmos/cosmos-sdk/pull/10468) Allow futureOps to queue additional operations in simulations ### Bug Fixes diff --git a/x/simulation/simulate.go b/x/simulation/simulate.go index e1ff8f1826b6..9b8c433be10a 100644 --- a/x/simulation/simulate.go +++ b/x/simulation/simulate.go @@ -168,17 +168,20 @@ func SimulateFromSeed( ctx := app.NewContext(false, header) // Run queued operations. Ignores blocksize if blocksize is too small - numQueuedOpsRan := runQueuedOperations( + numQueuedOpsRan, futureOps := runQueuedOperations( operationQueue, int(header.Height), tb, r, app, ctx, accs, logWriter, eventStats.Tally, config.Lean, config.ChainID, ) - numQueuedTimeOpsRan := runQueuedTimeOperations( + numQueuedTimeOpsRan, timeFutureOps := runQueuedTimeOperations( timeOperationQueue, int(header.Height), header.Time, tb, r, app, ctx, accs, logWriter, eventStats.Tally, config.Lean, config.ChainID, ) + futureOps = append(futureOps, timeFutureOps...) + queueOperations(operationQueue, timeOperationQueue, futureOps) + // run standard operations operations := blockSimulator(r, app, ctx, accs, header) opCount += operations + numQueuedOpsRan + numQueuedTimeOpsRan @@ -321,20 +324,23 @@ Comment: %s`, 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, - event func(route, op, evResult string), lean bool, chainID string) (numOpsRan int) { + event func(route, op, evResult string), lean bool, chainID string) (numOpsRan int, allFutureOps []simulation.FutureOperation) { queuedOp, ok := queueOps[height] if !ok { - return 0 + return 0, nil } + // Keep all future operations + allFutureOps = make([]simulation.FutureOperation, 0) + numOpsRan = len(queuedOp) for i := 0; i < numOpsRan; i++ { + opMsg, futureOps, err := queuedOp[i](r, app, ctx, accounts, chainID) + if futureOps != nil && len(futureOps) > 0 { + allFutureOps = append(allFutureOps, futureOps...) + } - // For now, queued operations cannot queue more operations. - // If a need arises for us to support queued messages to queue more messages, this can - // be changed. - opMsg, _, err := queuedOp[i](r, app, ctx, accounts, chainID) opMsg.LogEvent(event) if !lean || opMsg.OK { @@ -348,22 +354,22 @@ func runQueuedOperations(queueOps map[int][]simulation.Operation, } delete(queueOps, height) - return numOpsRan + return numOpsRan, allFutureOps } func runQueuedTimeOperations(queueOps []simulation.FutureOperation, height int, currentTime time.Time, tb testing.TB, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simulation.Account, logWriter LogWriter, event func(route, op, evResult string), - lean bool, chainID string) (numOpsRan int) { + lean bool, chainID string) (numOpsRan int, allFutureOps []simulation.FutureOperation) { + + // Keep all future operations + allFutureOps = make([]simulation.FutureOperation, 0) numOpsRan = 0 for len(queueOps) > 0 && currentTime.After(queueOps[0].BlockTime) { + opMsg, futureOps, err := queueOps[0].Op(r, app, ctx, accounts, chainID) - // For now, queued operations cannot queue more operations. - // If a need arises for us to support queued messages to queue more messages, this can - // be changed. - opMsg, _, err := queueOps[0].Op(r, app, ctx, accounts, chainID) opMsg.LogEvent(event) if !lean || opMsg.OK { @@ -375,9 +381,13 @@ func runQueuedTimeOperations(queueOps []simulation.FutureOperation, tb.FailNow() } + if futureOps != nil && len(futureOps) > 0 { + allFutureOps = append(allFutureOps, futureOps...) + } + queueOps = queueOps[1:] numOpsRan++ } - return numOpsRan + return numOpsRan, allFutureOps }