Browse Source

Merge branch 'blockchain_aware'

pull/206/merge
Jae Kwon 9 years ago
parent
commit
3adb579cf1
3 changed files with 51 additions and 2 deletions
  1. +4
    -0
      proxy/app_conn.go
  2. +27
    -0
      proxy/local_app_conn.go
  3. +20
    -2
      state/execution.go

+ 4
- 0
proxy/app_conn.go View File

@ -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)
}

+ 27
- 0
proxy/local_app_conn.go View File

@ -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 {


+ 20
- 2
state/execution.go View File

@ -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 != "" {


Loading…
Cancel
Save