diff --git a/app/app.go b/app/app.go index aa06cce8e..47fb34f31 100644 --- a/app/app.go +++ b/app/app.go @@ -33,9 +33,13 @@ type BaseApp struct { info *sm.ChainState *sm.State + // cached validator changes from DeliverTx pending []*abci.Validator - height uint64 - logger log.Logger + + // height is last committed block, DeliverTx is the next one + height uint64 + + logger log.Logger } // NewBaseApp creates a data store to handle queries @@ -45,8 +49,9 @@ func NewBaseApp(dbName string, cacheSize int, logger log.Logger) (*BaseApp, erro return nil, err } app := &BaseApp{ - info: sm.NewChainState(), State: state, + height: state.LatestHeight(), + info: sm.NewChainState(), logger: logger, } return app, nil @@ -163,14 +168,10 @@ func (app *BaseApp) Commit() (res abci.Result) { // InitChain - ABCI func (app *BaseApp) InitChain(req abci.RequestInitChain) { - // for _, plugin := range app.plugins.GetList() { - // plugin.InitChain(app.state, validators) - // } } // BeginBlock - ABCI func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) { - app.height++ } // EndBlock - ABCI @@ -182,6 +183,9 @@ func (app *BaseApp) EndBlock(height uint64) (res abci.ResponseEndBlock) { return } +// AddValChange is meant to be called by apps on DeliverTx +// results, this is added to the cache for the endblock +// changeset func (app *BaseApp) AddValChange(diffs []*abci.Validator) { for _, d := range diffs { idx := pubKeyIndex(d, app.pending) @@ -203,8 +207,6 @@ func pubKeyIndex(val *abci.Validator, list []*abci.Validator) int { return -1 } -//TODO move split key to tmlibs? - // Splits the string at the first '/'. // if there are none, assign default module ("base"). func splitKey(key string) (string, string) { diff --git a/app/bc.go b/app/bc.go index f681a7c52..183e48bf4 100644 --- a/app/bc.go +++ b/app/bc.go @@ -75,7 +75,7 @@ func (app *Basecoin) DeliverTx(txBytes []byte) abci.Result { ctx := stack.NewContext( app.GetChainID(), - app.height, + app.height+1, app.Logger().With("call", "delivertx"), ) res, err := app.handler.DeliverTx(ctx, app.Append(), tx) @@ -96,7 +96,7 @@ func (app *Basecoin) CheckTx(txBytes []byte) abci.Result { ctx := stack.NewContext( app.GetChainID(), - app.height, + app.height+1, app.Logger().With("call", "checktx"), ) res, err := app.handler.CheckTx(ctx, app.Check(), tx) diff --git a/benchmarks/app_test.go b/benchmarks/app_test.go index acbf182f7..a84912015 100644 --- a/benchmarks/app_test.go +++ b/benchmarks/app_test.go @@ -53,25 +53,22 @@ func NewBenchApp(h sdk.Handler, chainID string, n int, // logger := log.NewFilter(log.NewTMLogger(os.Stdout), log.AllowError()) // logger = log.NewTracingLogger(logger) - // TODO: disk writing - var store *app.Store - var err error - + dbDir, cache := "", 0 if persist { - tmpDir, _ := ioutil.TempDir("", "bc-app-benchmark") - store, err = app.NewStore(tmpDir, 500, logger) - } else { - store, err = app.NewStore("", 0, logger) + dbDir, _ = ioutil.TempDir("", "bc-app-benchmark") + cache = 500 } + + app, err := app.NewBasecoin( + h, + dbDir, + cache, + logger.With("module", "app"), + ) if err != nil { panic(err) } - app := app.NewBasecoin( - h, - store, - logger.With("module", "app"), - ) res := app.InitState("base/chain_id", chainID) if res != "Success" { panic("cannot set chain") diff --git a/client/query_test.go b/client/query_test.go index 5d6a5bf5c..fe8ee4180 100644 --- a/client/query_test.go +++ b/client/query_test.go @@ -26,11 +26,11 @@ var node *nm.Node func TestMain(m *testing.M) { logger := log.TestingLogger() - store, err := app.NewStore("", 0, logger) + app, err := app.NewBasecoin(eyes.NewHandler(), "", 0, logger) if err != nil { panic(err) } - app := app.NewBasecoin(eyes.NewHandler(), store, logger) + node = rpctest.StartTendermint(app) code := m.Run() diff --git a/examples/counter/plugins/counter/counter_test.go b/examples/counter/plugins/counter/counter_test.go index 50af3b3d9..b9630706e 100644 --- a/examples/counter/plugins/counter/counter_test.go +++ b/examples/counter/plugins/counter/counter_test.go @@ -27,15 +27,14 @@ func TestCounterPlugin(t *testing.T) { logger := log.TestingLogger() // logger := log.NewTracingLogger(log.NewTMLogger(os.Stdout)) - store, err := app.NewStore("", 0, logger.With("module", "store")) - require.Nil(err, "%+v", err) - h := NewHandler("gold") - bcApp := app.NewBasecoin( + bcApp, err := app.NewBasecoin( h, - store, + "", + 0, logger.With("module", "app"), ) + require.Nil(err, "%+v", err) bcApp.InitState("base/chain_id", chainID) // Account initialization diff --git a/server/commands/start.go b/server/commands/start.go index 494660300..825e9bfd3 100644 --- a/server/commands/start.go +++ b/server/commands/start.go @@ -74,38 +74,36 @@ func tickStartCmd(tick app.Ticker) func(cmd *cobra.Command, args []string) error return func(cmd *cobra.Command, args []string) error { rootDir := viper.GetString(cli.HomeFlag) - store, err := app.NewStore( + // Create Basecoin app + basecoinApp, err := app.NewBasecoinTick( + Handler, + tick, path.Join(rootDir, "data", "merkleeyes.db"), EyesCacheSize, - logger.With("module", "store"), - ) + logger.With("module", "app")) if err != nil { return err } - - // Create Basecoin app - basecoinApp := app.NewBasecoinTick(Handler, store, logger.With("module", "app"), tick) - return start(rootDir, store, basecoinApp) + return start(rootDir, basecoinApp) } } func startCmd(cmd *cobra.Command, args []string) error { rootDir := viper.GetString(cli.HomeFlag) - store, err := app.NewStore( + // Create Basecoin app + basecoinApp, err := app.NewBasecoin( + Handler, path.Join(rootDir, "data", "merkleeyes.db"), EyesCacheSize, - logger.With("module", "store"), - ) + logger.With("module", "app")) if err != nil { return err } - // Create Basecoin app - basecoinApp := app.NewBasecoin(Handler, store, logger.With("module", "app")) - return start(rootDir, store, basecoinApp) + return start(rootDir, basecoinApp) } -func start(rootDir string, store *app.Store, basecoinApp *app.Basecoin) error { +func start(rootDir string, basecoinApp *app.Basecoin) error { // if chain_id has not been set yet, load the genesis. // else, assume it's been loaded