Skip to content

Commit

Permalink
Merge PR cosmos#4748: Write-Through Inter-Block Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Sep 4, 2019
1 parent 0d27ad1 commit f421ff4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authsimops "github.com/cosmos/cosmos-sdk/x/auth/simulation/operations"
Expand Down Expand Up @@ -288,11 +289,18 @@ func invariants(app *SimApp) []sdk.Invariant {
return simulation.PeriodicInvariants(app.CrisisKeeper.Invariants(), flagPeriodValue, 0)
}

// Pass this in as an option to use a dbStoreAdapter instead of an IAVLStore for simulation speed.
// fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of
// an IAVLStore for faster simulation speed.
func fauxMerkleModeOpt(bapp *baseapp.BaseApp) {
bapp.SetFauxMerkleMode()
}

// interBlockCacheOpt returns a BaseApp option function that sets the persistent
// inter-block write-through cache.
func interBlockCacheOpt() func(*baseapp.BaseApp) {
return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager())
}

// Profile with:
// /usr/local/go/bin/go test -benchmem -run=^$ github.com/cosmos/cosmos-sdk/simapp -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out
func BenchmarkFullAppSimulation(b *testing.B) {
Expand All @@ -306,7 +314,8 @@ func BenchmarkFullAppSimulation(b *testing.B) {
db.Close()
os.RemoveAll(dir)
}()
app := NewSimApp(logger, db, nil, true, 0)

app := NewSimApp(logger, db, nil, true, 0, interBlockCacheOpt())

// Run randomized simulation
// TODO: parameterize numbers, save for a later PR
Expand Down Expand Up @@ -593,6 +602,7 @@ func TestAppSimulationAfterImport(t *testing.T) {

newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, 0, fauxMerkleModeOpt)
require.Equal(t, "SimApp", newApp.Name())

newApp.InitChain(abci.RequestInitChain{
AppStateBytes: appState,
})
Expand Down Expand Up @@ -630,7 +640,8 @@ func TestAppStateDeterminism(t *testing.T) {
for j := 0; j < numTimesToRunPerSeed; j++ {
logger := log.NewNopLogger()
db := dbm.NewMemDB()
app := NewSimApp(logger, db, nil, true, 0)

app := NewSimApp(logger, db, nil, true, 0, interBlockCacheOpt())

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down Expand Up @@ -671,7 +682,7 @@ func BenchmarkInvariants(b *testing.B) {
os.RemoveAll(dir)
}()

app := NewSimApp(logger, db, nil, true, 0)
app := NewSimApp(logger, db, nil, true, 0, interBlockCacheOpt())

// 2. Run parameterized simulation (w/o invariants)
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down

0 comments on commit f421ff4

Please sign in to comment.