From 16437867ff89f1a08a999aa46bb94b8674911b26 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sat, 5 Mar 2016 20:57:36 -0800 Subject: [PATCH] Starting to use tmsp.BlockchainAware --- proxy/app_conn.go | 4 ++++ proxy/local_app_conn.go | 27 +++++++++++++++++++++++++++ state/execution.go | 22 ++++++++++++++++++++-- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/proxy/app_conn.go b/proxy/app_conn.go index 2e19394a7..af20b7472 100644 --- a/proxy/app_conn.go +++ b/proxy/app_conn.go @@ -2,6 +2,7 @@ package proxy import ( tmspcli "github.com/tendermint/tmsp/client" + tmsp "github.com/tendermint/tmsp/types" ) type AppConn interface { @@ -18,4 +19,7 @@ type AppConn interface { InfoSync() (info string, err error) FlushSync() error CommitSync() (hash []byte, log string, err error) + InitChainSync(validators []*tmsp.Validator) (err error) + BeginBlockSync(height uint64) (err error) + EndBlockSync() (changedValidators []*tmsp.Validator, err error) } diff --git a/proxy/local_app_conn.go b/proxy/local_app_conn.go index 22c94f252..83b79069d 100644 --- a/proxy/local_app_conn.go +++ b/proxy/local_app_conn.go @@ -100,6 +100,33 @@ func (app *localAppConn) CommitSync() (hash []byte, log string, err error) { return hash, log, nil } +func (app *localAppConn) InitChainSync(validators []*tmsp.Validator) (err error) { + app.mtx.Lock() + if bcApp, ok := app.Application.(tmsp.BlockchainAware); ok { + bcApp.InitChain(validators) + } + app.mtx.Unlock() + return nil +} + +func (app *localAppConn) BeginBlockSync(height uint64) (err error) { + app.mtx.Lock() + if bcApp, ok := app.Application.(tmsp.BlockchainAware); ok { + bcApp.BeginBlock(height) + } + app.mtx.Unlock() + return nil +} + +func (app *localAppConn) EndBlockSync() (changedValidators []*tmsp.Validator, err error) { + app.mtx.Lock() + if bcApp, ok := app.Application.(tmsp.BlockchainAware); ok { + changedValidators = bcApp.EndBlock() + } + app.mtx.Unlock() + return changedValidators, nil +} + //------------------------------------------------------- func (app *localAppConn) callback(req *tmsp.Request, res *tmsp.Response) *tmspcli.ReqRes { diff --git a/state/execution.go b/state/execution.go index 1a81e6e66..9cc8605bc 100644 --- a/state/execution.go +++ b/state/execution.go @@ -77,16 +77,34 @@ func (s *State) execBlockOnProxyApp(evsw *events.EventSwitch, proxyAppConn proxy } proxyAppConn.SetResponseCallback(proxyCb) - // Run next txs in the block and get new AppHash + // Begin block + err := proxyAppConn.BeginBlockSync(uint64(block.Height)) + if err != nil { + log.Warn("Error in proxyAppConn.BeginBlock", "error", err) + return err + } + + // Run txs of block for _, tx := range block.Txs { proxyAppConn.AppendTxAsync(tx) if err := proxyAppConn.Error(); err != nil { return err } } + + // End block + changedValidators, err := proxyAppConn.EndBlockSync() + if err != nil { + log.Warn("Error in proxyAppConn.EndBlock", "error", err) + return err + } + // TODO: Do something with changedValidators + log.Info("TODO: Do something with changedValidators", changedValidators) + + // Commit block, get hash back hash, logStr, err := proxyAppConn.CommitSync() if err != nil { - log.Warn("Error computing proxyAppConn hash", "error", err) + log.Warn("Error in proxyAppConn.CommitSync", "error", err) return err } if logStr != "" {