Merge PR #4791: resume simulations at a given height
This commit is contained in:
parent
861e4798ad
commit
c4e3578087
|
@ -0,0 +1 @@
|
||||||
|
# 4490 add `InitialBlockHeight` flag to resume a simulation from a given block
|
|
@ -45,7 +45,8 @@ func init() {
|
||||||
flag.StringVar(&exportStatePath, "ExportStatePath", "", "custom file path to save the exported app state JSON")
|
flag.StringVar(&exportStatePath, "ExportStatePath", "", "custom file path to save the exported app state JSON")
|
||||||
flag.StringVar(&exportStatsPath, "ExportStatsPath", "", "custom file path to save the exported simulation statistics JSON")
|
flag.StringVar(&exportStatsPath, "ExportStatsPath", "", "custom file path to save the exported simulation statistics JSON")
|
||||||
flag.Int64Var(&seed, "Seed", 42, "simulation random seed")
|
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 new blocks to simulate from the initial block height")
|
||||||
flag.IntVar(&blockSize, "BlockSize", 200, "operations per block")
|
flag.IntVar(&blockSize, "BlockSize", 200, "operations per block")
|
||||||
flag.BoolVar(&enabled, "Enabled", false, "enable the simulation")
|
flag.BoolVar(&enabled, "Enabled", false, "enable the simulation")
|
||||||
flag.BoolVar(&verbose, "Verbose", false, "verbose log output")
|
flag.BoolVar(&verbose, "Verbose", false, "verbose log output")
|
||||||
|
@ -58,16 +59,17 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function for populating input for SimulateFromSeed
|
// 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) (
|
func getSimulateFromSeedInput(tb testing.TB, w io.Writer, app *SimApp) (
|
||||||
testing.TB, io.Writer, *baseapp.BaseApp, simulation.AppStateFn, int64,
|
testing.TB, io.Writer, *baseapp.BaseApp, simulation.AppStateFn, int64,
|
||||||
simulation.WeightedOperations, sdk.Invariants, int, int, int, string,
|
simulation.WeightedOperations, sdk.Invariants, int, int, int, int, string,
|
||||||
bool, bool, bool, bool, bool, map[string]bool) {
|
bool, bool, bool, bool, bool, map[string]bool) {
|
||||||
|
|
||||||
exportParams := exportParamsPath != ""
|
exportParams := exportParamsPath != ""
|
||||||
|
|
||||||
return tb, w, app.BaseApp, appStateFn, seed,
|
return tb, w, app.BaseApp, appStateFn, seed,
|
||||||
testAndRunTxs(app), invariants(app),
|
testAndRunTxs(app), invariants(app),
|
||||||
numBlocks, exportParamsHeight, blockSize,
|
initialBlockHeight, numBlocks, exportParamsHeight, blockSize,
|
||||||
exportStatsPath, exportParams, commit, lean, onOperation, allInvariants, app.ModuleAccountAddrs()
|
exportStatsPath, exportParams, commit, lean, onOperation, allInvariants, app.ModuleAccountAddrs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -715,7 +717,7 @@ func TestAppStateDeterminism(t *testing.T) {
|
||||||
simulation.SimulateFromSeed(
|
simulation.SimulateFromSeed(
|
||||||
t, os.Stdout, app.BaseApp, appStateFn, seed,
|
t, os.Stdout, app.BaseApp, appStateFn, seed,
|
||||||
testAndRunTxs(app), []sdk.Invariant{},
|
testAndRunTxs(app), []sdk.Invariant{},
|
||||||
50, 100, 0, "",
|
1, 50, 100, 0, "",
|
||||||
false, true, false, false, false, app.ModuleAccountAddrs(),
|
false, true, false, false, false, app.ModuleAccountAddrs(),
|
||||||
)
|
)
|
||||||
appHash := app.LastCommitID().Hash
|
appHash := app.LastCommitID().Hash
|
||||||
|
@ -743,7 +745,7 @@ func BenchmarkInvariants(b *testing.B) {
|
||||||
// 2. Run parameterized simulation (w/o invariants)
|
// 2. Run parameterized simulation (w/o invariants)
|
||||||
_, params, simErr := simulation.SimulateFromSeed(
|
_, params, simErr := simulation.SimulateFromSeed(
|
||||||
b, ioutil.Discard, app.BaseApp, appStateFn, seed, testAndRunTxs(app),
|
b, ioutil.Discard, app.BaseApp, appStateFn, seed, testAndRunTxs(app),
|
||||||
[]sdk.Invariant{}, numBlocks, exportParamsHeight, blockSize,
|
[]sdk.Invariant{}, initialBlockHeight, numBlocks, exportParamsHeight, blockSize,
|
||||||
exportStatsPath, exportParams, commit, lean, onOperation, false, app.ModuleAccountAddrs(),
|
exportStatsPath, exportParams, commit, lean, onOperation, false, app.ModuleAccountAddrs(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/supply"
|
"github.com/cosmos/cosmos-sdk/x/supply"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// List of available flags for the simulator
|
||||||
var (
|
var (
|
||||||
genesisFile string
|
genesisFile string
|
||||||
paramsFile string
|
paramsFile string
|
||||||
|
@ -41,6 +42,7 @@ var (
|
||||||
exportStatePath string
|
exportStatePath string
|
||||||
exportStatsPath string
|
exportStatsPath string
|
||||||
seed int64
|
seed int64
|
||||||
|
initialBlockHeight int
|
||||||
numBlocks int
|
numBlocks int
|
||||||
blockSize int
|
blockSize int
|
||||||
enabled bool
|
enabled bool
|
||||||
|
|
|
@ -47,7 +47,7 @@ func SimulateFromSeed(
|
||||||
tb testing.TB, w io.Writer, app *baseapp.BaseApp,
|
tb testing.TB, w io.Writer, app *baseapp.BaseApp,
|
||||||
appStateFn AppStateFn, seed int64,
|
appStateFn AppStateFn, seed int64,
|
||||||
ops WeightedOperations, invariants sdk.Invariants,
|
ops WeightedOperations, invariants sdk.Invariants,
|
||||||
numBlocks, exportParamsHeight, blockSize int,
|
initialHeight, numBlocks, exportParamsHeight, blockSize int,
|
||||||
exportStatsPath string,
|
exportStatsPath string,
|
||||||
exportParams, commit, lean, onOperation, allInvariants bool,
|
exportParams, commit, lean, onOperation, allInvariants bool,
|
||||||
blackListedAccs map[string]bool,
|
blackListedAccs map[string]bool,
|
||||||
|
@ -139,10 +139,12 @@ func SimulateFromSeed(
|
||||||
}
|
}
|
||||||
|
|
||||||
// set exported params to the initial state
|
// set exported params to the initial state
|
||||||
|
if exportParams && exportParamsHeight == 0 {
|
||||||
exportedParams = params
|
exportedParams = params
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: split up the contents of this for loop into new functions
|
// 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++ {
|
||||||
|
|
||||||
// Log the header time for future lookup
|
// Log the header time for future lookup
|
||||||
pastTimes = append(pastTimes, header.Time)
|
pastTimes = append(pastTimes, header.Time)
|
||||||
|
|
Loading…
Reference in New Issue