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

resume simulations at a given height #4791

Merged
merged 5 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
1 change: 1 addition & 0 deletions .pending/improvements/simulation/_4490-add-init-heigh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 4490 add `InitialBlockHeight` flag to resume a simulation from a given block
12 changes: 7 additions & 5 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func init() {
flag.IntVar(&exportParamsHeight, "ExportParamsHeight", 0, "height to which export the randomly generated params")
flag.StringVar(&exportStatePath, "ExportStatePath", "", "custom file path to save the exported app state JSON")
flag.Int64Var(&seed, "Seed", 42, "simulation random seed")
flag.IntVar(&numBlocks, "NumBlocks", 500, "number of blocks")
flag.IntVar(&initialBlockHeight, "InitialBlockHeight", 1, "initial block to start the simulation")
flag.IntVar(&numBlocks, "NumBlocks", 500, "number of blocks to run the current simulation, after which the simulation halts")
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
flag.IntVar(&blockSize, "BlockSize", 200, "operations per block")
flag.BoolVar(&enabled, "Enabled", false, "enable the simulation")
flag.BoolVar(&verbose, "Verbose", false, "verbose log output")
Expand All @@ -50,16 +51,17 @@ func init() {
}

// helper function for populating input for SimulateFromSeed
// TODO: clean up this function along with the simulation refactor
func getSimulateFromSeedInput(tb testing.TB, w io.Writer, app *SimApp) (
testing.TB, io.Writer, *baseapp.BaseApp, simulation.AppStateFn, int64,
simulation.WeightedOperations, sdk.Invariants, int, int, int,
simulation.WeightedOperations, sdk.Invariants, int, int, int, int,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry @alexanderbez. I promise I'll refactor this later lol

bool, bool, bool, bool, bool, map[string]bool) {

exportParams := exportParamsPath != ""

return tb, w, app.BaseApp, appStateFn, seed,
testAndRunTxs(app), invariants(app),
numBlocks, exportParamsHeight, blockSize,
initialBlockHeight, numBlocks, exportParamsHeight, blockSize,
exportParams, commit, lean, onOperation, allInvariants, app.ModuleAccountAddrs()
}

Expand Down Expand Up @@ -705,7 +707,7 @@ func TestAppStateDeterminism(t *testing.T) {
simulation.SimulateFromSeed(
t, os.Stdout, app.BaseApp, appStateFn, seed,
testAndRunTxs(app), []sdk.Invariant{},
50, 100, 0,
1, 50, 100, 0,
false, true, false, false, false, app.ModuleAccountAddrs(),
)
appHash := app.LastCommitID().Hash
Expand Down Expand Up @@ -733,7 +735,7 @@ func BenchmarkInvariants(b *testing.B) {
// 2. Run parameterized simulation (w/o invariants)
_, params, simErr := simulation.SimulateFromSeed(
b, ioutil.Discard, app.BaseApp, appStateFn, seed, testAndRunTxs(app),
[]sdk.Invariant{}, numBlocks, exportParamsHeight, blockSize,
[]sdk.Invariant{}, initialBlockHeight, numBlocks, exportParamsHeight, blockSize,
exportParams, commit, lean, onOperation, false, app.ModuleAccountAddrs(),
)

Expand Down
2 changes: 2 additions & 0 deletions simapp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ import (
"github.com/cosmos/cosmos-sdk/x/supply"
)

// List of available flags for the simulator
var (
genesisFile string
paramsFile string
exportParamsPath string
exportParamsHeight int
exportStatePath string
seed int64
initialBlockHeight int
numBlocks int
blockSize int
enabled bool
Expand Down
8 changes: 5 additions & 3 deletions x/simulation/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func SimulateFromSeed(
tb testing.TB, w io.Writer, app *baseapp.BaseApp,
appStateFn AppStateFn, seed int64, ops WeightedOperations,
invariants sdk.Invariants,
numBlocks, exportParamsHeight, blockSize int,
initialHeight, numBlocks, exportParamsHeight, blockSize int,
exportParams, commit, lean, onOperation, allInvariants bool,
blackListedAccs map[string]bool,
) (stopEarly bool, exportedParams Params, err error) {
Expand Down Expand Up @@ -138,10 +138,12 @@ func SimulateFromSeed(
}

// set exported params to the initial state
exportedParams = params
if exportParams && exportParamsHeight == 0 {
exportedParams = params
}

// TODO: split up the contents of this for loop into new functions
for height := 1; height <= numBlocks && !stopEarly; height++ {
for height := initialHeight; height < numBlocks+initialHeight && !stopEarly; height++ {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved

// Log the header time for future lookup
pastTimes = append(pastTimes, header.Time)
Expand Down