Skip to content

Commit c4e3578

Browse files
fedekunzealexanderbez
authored andcommitted
Merge PR #4791: resume simulations at a given height
1 parent 861e479 commit c4e3578

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 4490 add `InitialBlockHeight` flag to resume a simulation from a given block

simapp/sim_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func init() {
4545
flag.StringVar(&exportStatePath, "ExportStatePath", "", "custom file path to save the exported app state JSON")
4646
flag.StringVar(&exportStatsPath, "ExportStatsPath", "", "custom file path to save the exported simulation statistics JSON")
4747
flag.Int64Var(&seed, "Seed", 42, "simulation random seed")
48-
flag.IntVar(&numBlocks, "NumBlocks", 500, "number of blocks")
48+
flag.IntVar(&initialBlockHeight, "InitialBlockHeight", 1, "initial block to start the simulation")
49+
flag.IntVar(&numBlocks, "NumBlocks", 500, "number of new blocks to simulate from the initial block height")
4950
flag.IntVar(&blockSize, "BlockSize", 200, "operations per block")
5051
flag.BoolVar(&enabled, "Enabled", false, "enable the simulation")
5152
flag.BoolVar(&verbose, "Verbose", false, "verbose log output")
@@ -58,16 +59,17 @@ func init() {
5859
}
5960

6061
// helper function for populating input for SimulateFromSeed
62+
// TODO: clean up this function along with the simulation refactor
6163
func getSimulateFromSeedInput(tb testing.TB, w io.Writer, app *SimApp) (
6264
testing.TB, io.Writer, *baseapp.BaseApp, simulation.AppStateFn, int64,
63-
simulation.WeightedOperations, sdk.Invariants, int, int, int, string,
65+
simulation.WeightedOperations, sdk.Invariants, int, int, int, int, string,
6466
bool, bool, bool, bool, bool, map[string]bool) {
6567

6668
exportParams := exportParamsPath != ""
6769

6870
return tb, w, app.BaseApp, appStateFn, seed,
6971
testAndRunTxs(app), invariants(app),
70-
numBlocks, exportParamsHeight, blockSize,
72+
initialBlockHeight, numBlocks, exportParamsHeight, blockSize,
7173
exportStatsPath, exportParams, commit, lean, onOperation, allInvariants, app.ModuleAccountAddrs()
7274
}
7375

@@ -715,7 +717,7 @@ func TestAppStateDeterminism(t *testing.T) {
715717
simulation.SimulateFromSeed(
716718
t, os.Stdout, app.BaseApp, appStateFn, seed,
717719
testAndRunTxs(app), []sdk.Invariant{},
718-
50, 100, 0, "",
720+
1, 50, 100, 0, "",
719721
false, true, false, false, false, app.ModuleAccountAddrs(),
720722
)
721723
appHash := app.LastCommitID().Hash
@@ -743,7 +745,7 @@ func BenchmarkInvariants(b *testing.B) {
743745
// 2. Run parameterized simulation (w/o invariants)
744746
_, params, simErr := simulation.SimulateFromSeed(
745747
b, ioutil.Discard, app.BaseApp, appStateFn, seed, testAndRunTxs(app),
746-
[]sdk.Invariant{}, numBlocks, exportParamsHeight, blockSize,
748+
[]sdk.Invariant{}, initialBlockHeight, numBlocks, exportParamsHeight, blockSize,
747749
exportStatsPath, exportParams, commit, lean, onOperation, false, app.ModuleAccountAddrs(),
748750
)
749751

simapp/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/cosmos/cosmos-sdk/x/supply"
3434
)
3535

36+
// List of available flags for the simulator
3637
var (
3738
genesisFile string
3839
paramsFile string
@@ -41,6 +42,7 @@ var (
4142
exportStatePath string
4243
exportStatsPath string
4344
seed int64
45+
initialBlockHeight int
4446
numBlocks int
4547
blockSize int
4648
enabled bool

x/simulation/simulate.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func SimulateFromSeed(
4747
tb testing.TB, w io.Writer, app *baseapp.BaseApp,
4848
appStateFn AppStateFn, seed int64,
4949
ops WeightedOperations, invariants sdk.Invariants,
50-
numBlocks, exportParamsHeight, blockSize int,
50+
initialHeight, numBlocks, exportParamsHeight, blockSize int,
5151
exportStatsPath string,
5252
exportParams, commit, lean, onOperation, allInvariants bool,
5353
blackListedAccs map[string]bool,
@@ -139,10 +139,12 @@ func SimulateFromSeed(
139139
}
140140

141141
// set exported params to the initial state
142-
exportedParams = params
142+
if exportParams && exportParamsHeight == 0 {
143+
exportedParams = params
144+
}
143145

144146
// TODO: split up the contents of this for loop into new functions
145-
for height := 1; height <= numBlocks && !stopEarly; height++ {
147+
for height := initialHeight; height < numBlocks+initialHeight && !stopEarly; height++ {
146148

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

0 commit comments

Comments
 (0)