Skip to content

Commit

Permalink
Jae/simulator improvements (cosmos#2900)
Browse files Browse the repository at this point in the history
* Make simulator operations predetermined
* Use new dbm.ReverseIterator API
* Simulation speed improvements
* Pin exact revisions, not branches
* Rename 'MountStoresIAVL' to 'MountStores'
* Zero Power Block fees to community pool
  • Loading branch information
jaekwon authored Nov 27, 2018
1 parent 2e0dfc3 commit d1e7622
Show file tree
Hide file tree
Showing 33 changed files with 265 additions and 118 deletions.
69 changes: 40 additions & 29 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

[[override]]
name = "github.com/tendermint/iavl"
version = "=v0.11.1"
revision = "d8d0eef715649bcc21682990ac635566119f070c"

[[override]]
name = "github.com/tendermint/tendermint"
version = "v0.26.1"
revision = "70a7cae58c8f880aede3b19101e54fb9a7b08c0b"

## deps without releases:

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ test_sim_gaia_nondeterminism:

test_sim_gaia_fast:
@echo "Running quick Gaia simulation. This may take several minutes..."
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=500 -SimulationBlockSize=200 -SimulationCommit=true -SimulationSeed=10 -v -timeout 24h
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=500 -SimulationBlockSize=200 -SimulationCommit=true -SimulationSeed=99 -v -timeout 24h

test_sim_gaia_import_export:
@echo "Running Gaia import/export simulation. This may take several minutes..."
Expand Down
28 changes: 18 additions & 10 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type BaseApp struct {
endBlocker sdk.EndBlocker // logic to run after all txs, and to determine valset changes
addrPeerFilter sdk.PeerFilter // filter peers by address and port
pubkeyPeerFilter sdk.PeerFilter // filter peers by public key
fauxMerkleMode bool // if true, IAVL MountStores uses MountStoresDB for simulation speed.

//--------------------
// Volatile
Expand Down Expand Up @@ -86,13 +87,14 @@ var _ abci.Application = (*BaseApp)(nil)
// Accepts variable number of option functions, which act on the BaseApp to set configuration choices
func NewBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp)) *BaseApp {
app := &BaseApp{
Logger: logger,
name: name,
db: db,
cms: store.NewCommitMultiStore(db),
router: NewRouter(),
queryRouter: NewQueryRouter(),
txDecoder: txDecoder,
Logger: logger,
name: name,
db: db,
cms: store.NewCommitMultiStore(db),
router: NewRouter(),
queryRouter: NewQueryRouter(),
txDecoder: txDecoder,
fauxMerkleMode: false,
}
for _, option := range options {
option(app)
Expand All @@ -111,10 +113,16 @@ func (app *BaseApp) SetCommitMultiStoreTracer(w io.Writer) {
app.cms.WithTracer(w)
}

// Mount IAVL stores to the provided keys in the BaseApp multistore
func (app *BaseApp) MountStoresIAVL(keys ...*sdk.KVStoreKey) {
// Mount IAVL or DB stores to the provided keys in the BaseApp multistore
func (app *BaseApp) MountStores(keys ...*sdk.KVStoreKey) {
for _, key := range keys {
app.MountStore(key, sdk.StoreTypeIAVL)
if !app.fauxMerkleMode {
app.MountStore(key, sdk.StoreTypeIAVL)
} else {
// StoreTypeDB doesn't do anything upon commit, and it doesn't
// retain history, but it's useful for faster simulation.
app.MountStore(key, sdk.StoreTypeDB)
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func setupBaseApp(t *testing.T, options ...func(*BaseApp)) *BaseApp {
app.LoadLatestVersion(capKey1)
})

app.MountStoresIAVL(capKey1, capKey2)
app.MountStores(capKey1, capKey2)

// stores are mounted
err := app.LoadLatestVersion(capKey1)
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestLoadVersion(t *testing.T) {

// make a cap key and mount the store
capKey := sdk.NewKVStoreKey("main")
app.MountStoresIAVL(capKey)
app.MountStores(capKey)
err := app.LoadLatestVersion(capKey) // needed to make stores non-nil
require.Nil(t, err)

Expand All @@ -117,15 +117,15 @@ func TestLoadVersion(t *testing.T) {

// reload with LoadLatestVersion
app = NewBaseApp(name, logger, db, nil)
app.MountStoresIAVL(capKey)
app.MountStores(capKey)
err = app.LoadLatestVersion(capKey)
require.Nil(t, err)
testLoadVersionHelper(t, app, int64(2), commitID2)

// reload with LoadVersion, see if you can commit the same block and get
// the same result
app = NewBaseApp(name, logger, db, nil)
app.MountStoresIAVL(capKey)
app.MountStores(capKey)
err = app.LoadVersion(1, capKey)
require.Nil(t, err)
testLoadVersionHelper(t, app, int64(1), commitID1)
Expand Down Expand Up @@ -161,7 +161,7 @@ func testChangeNameHelper(name string) func(*BaseApp) {
// make a cap key and mount the store
capKey := sdk.NewKVStoreKey("main")
app.MountStoresIAVL(capKey)
app.MountStores(capKey)
err := app.LoadLatestVersion(capKey) // needed to make stores non-nil
require.Nil(t, err)
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestInitChainer(t *testing.T) {
app := NewBaseApp(name, logger, db, nil)
capKey := sdk.NewKVStoreKey("main")
capKey2 := sdk.NewKVStoreKey("key2")
app.MountStoresIAVL(capKey, capKey2)
app.MountStores(capKey, capKey2)

// set a value in the store on init chain
key, value := []byte("hello"), []byte("goodbye")
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestInitChainer(t *testing.T) {
// reload app
app = NewBaseApp(name, logger, db, nil)
app.SetInitChainer(initChainer)
app.MountStoresIAVL(capKey, capKey2)
app.MountStores(capKey, capKey2)
err = app.LoadLatestVersion(capKey) // needed to make stores non-nil
require.Nil(t, err)

Expand Down
10 changes: 10 additions & 0 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ func (app *BaseApp) SetPubKeyPeerFilter(pf sdk.PeerFilter) {
app.pubkeyPeerFilter = pf
}

func (app *BaseApp) SetFauxMerkleMode() {
if app.sealed {
panic("SetFauxMerkleMode() on sealed BaseApp")
}
app.fauxMerkleMode = true
}

//----------------------------------------
// TODO: move these out of this file?

func (app *BaseApp) Router() Router {
if app.sealed {
panic("Router() on sealed BaseApp")
Expand Down
Loading

0 comments on commit d1e7622

Please sign in to comment.