Browse Source

Merge pull request #364 from tendermint/collapse_info

tmsp: ResponseInfo and ResponseEndBlock
pull/328/merge
Ethan Buchman 8 years ago
committed by GitHub
parent
commit
3a55339114
8 changed files with 45 additions and 50 deletions
  1. +2
    -2
      consensus/mempool_test.go
  2. +3
    -3
      glide.lock
  3. +4
    -4
      proxy/app_conn.go
  4. +5
    -5
      proxy/app_conn_test.go
  5. +10
    -2
      rpc/core/tmsp.go
  6. +4
    -4
      rpc/core/types/responses.go
  7. +12
    -25
      state/execution.go
  8. +5
    -5
      state/execution_test.go

+ 2
- 2
consensus/mempool_test.go View File

@ -122,8 +122,8 @@ func NewCounterApplication() *CounterApplication {
return &CounterApplication{}
}
func (app *CounterApplication) Info() (string, *tmsp.TMSPInfo, *tmsp.LastBlockInfo, *tmsp.ConfigInfo) {
return Fmt("txs:%v", app.txCount), nil, nil, nil
func (app *CounterApplication) Info() tmsp.ResponseInfo {
return tmsp.ResponseInfo{Data: Fmt("txs:%v", app.txCount)}
}
func (app *CounterApplication) SetOption(key string, value string) (log string) {


+ 3
- 3
glide.lock View File

@ -1,5 +1,5 @@
hash: 2c623322ed0ff7136db54be910e62e679af6e989b18804bb2e6c457fa79533ff
updated: 2017-01-12T14:33:09.663440725-05:00
hash: 8e2e970c04c55b02740daa62647bb637964504a65c45cf274ffed5b0b1930ae4
updated: 2017-01-12T14:56:02.152843341-05:00
imports:
- name: github.com/btcsuite/btcd
version: afec1bd1245a4a19e6dfe1306974b733e7cbb9b8
@ -94,7 +94,7 @@ imports:
subpackages:
- term
- name: github.com/tendermint/tmsp
version: a7b7fe83d6efdccef901ecc83c9dd7c326cfb7fb
version: f8167872d8ddd3a2362452ef1414991b5afa8862
subpackages:
- client
- example/counter


+ 4
- 4
proxy/app_conn.go View File

@ -16,7 +16,7 @@ type AppConnConsensus interface {
BeginBlockSync(hash []byte, header *types.Header) (err error)
AppendTxAsync(tx []byte) *tmspcli.ReqRes
EndBlockSync(height uint64) (changedValidators []*types.Validator, err error)
EndBlockSync(height uint64) (types.ResponseEndBlock, error)
CommitSync() (res types.Result)
}
@ -34,7 +34,7 @@ type AppConnQuery interface {
Error() error
EchoSync(string) (res types.Result)
InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo)
InfoSync() (types.ResponseInfo, error)
QuerySync(tx []byte) (res types.Result)
// SetOptionSync(key string, value string) (res types.Result)
@ -73,7 +73,7 @@ func (app *appConnConsensus) AppendTxAsync(tx []byte) *tmspcli.ReqRes {
return app.appConn.AppendTxAsync(tx)
}
func (app *appConnConsensus) EndBlockSync(height uint64) (changedValidators []*types.Validator, err error) {
func (app *appConnConsensus) EndBlockSync(height uint64) (types.ResponseEndBlock, error) {
return app.appConn.EndBlockSync(height)
}
@ -135,7 +135,7 @@ func (app *appConnQuery) EchoSync(msg string) (res types.Result) {
return app.appConn.EchoSync(msg)
}
func (app *appConnQuery) InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo) {
func (app *appConnQuery) InfoSync() (types.ResponseInfo, error) {
return app.appConn.InfoSync()
}


+ 5
- 5
proxy/app_conn_test.go View File

@ -16,7 +16,7 @@ import (
type AppConnTest interface {
EchoAsync(string) *tmspcli.ReqRes
FlushSync() error
InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo)
InfoSync() (types.ResponseInfo, error)
}
type appConnTest struct {
@ -35,7 +35,7 @@ func (app *appConnTest) FlushSync() error {
return app.appConn.FlushSync()
}
func (app *appConnTest) InfoSync() (types.Result, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo) {
func (app *appConnTest) InfoSync() (types.ResponseInfo, error) {
return app.appConn.InfoSync()
}
@ -114,11 +114,11 @@ func TestInfo(t *testing.T) {
proxy := NewAppConnTest(cli)
t.Log("Connected")
res, _, _, _ := proxy.InfoSync()
if res.IsErr() {
resInfo, err := proxy.InfoSync()
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if string(res.Data) != "{\"size\":0}" {
if string(resInfo.Data) != "{\"size\":0}" {
t.Error("Expected ResponseInfo with one element '{\"size\":0}' but got something else")
}
}

+ 10
- 2
rpc/core/tmsp.go View File

@ -12,6 +12,14 @@ func TMSPQuery(query []byte) (*ctypes.ResultTMSPQuery, error) {
}
func TMSPInfo() (*ctypes.ResultTMSPInfo, error) {
res, tmspInfo, lastBlockInfo, configInfo := proxyAppQuery.InfoSync()
return &ctypes.ResultTMSPInfo{res, tmspInfo, lastBlockInfo, configInfo}, nil
res, err := proxyAppQuery.InfoSync()
if err != nil {
return nil, err
}
return &ctypes.ResultTMSPInfo{
Data: res.Data,
Version: res.Version,
LastBlockHeight: res.LastBlockHeight,
LastBlockAppHash: res.LastBlockAppHash,
}, nil
}

+ 4
- 4
rpc/core/types/responses.go View File

@ -74,10 +74,10 @@ type ResultUnconfirmedTxs struct {
}
type ResultTMSPInfo struct {
Result tmsp.Result `json:"result"`
TMSPInfo *tmsp.TMSPInfo `json:"tmsp_info"`
LastBlockInfo *tmsp.LastBlockInfo `json:"last_block_info"`
ConfigInfo *tmsp.ConfigInfo `json:"config_info"`
Data string `json:"data"`
Version string `json:"version"`
LastBlockHeight uint64 `json:"last_block_height"`
LastBlockAppHash []byte `json:"last_block_app_hash"`
}
type ResultTMSPQuery struct {


+ 12
- 25
state/execution.go View File

@ -122,7 +122,7 @@ func execBlockOnProxyApp(eventCache types.Fireable, proxyAppConn proxy.AppConnCo
fail.Fail() // XXX
// End block
changedValidators, err := proxyAppConn.EndBlockSync(uint64(block.Height))
respEndBlock, err := proxyAppConn.EndBlockSync(uint64(block.Height))
if err != nil {
log.Warn("Error in proxyAppConn.EndBlock", "error", err)
return nil, err
@ -131,10 +131,10 @@ func execBlockOnProxyApp(eventCache types.Fireable, proxyAppConn proxy.AppConnCo
fail.Fail() // XXX
log.Info("Executed block", "height", block.Height, "valid txs", validTxs, "invalid txs", invalidTxs)
if len(changedValidators) > 0 {
log.Info("Update to validator set", "updates", tmsp.ValidatorsString(changedValidators))
if len(respEndBlock.Diffs) > 0 {
log.Info("Update to validator set", "updates", tmsp.ValidatorsString(respEndBlock.Diffs))
}
return changedValidators, nil
return respEndBlock.Diffs, nil
}
func updateValidators(validators *types.ValidatorSet, changedValidators []*tmsp.Validator) error {
@ -313,33 +313,20 @@ func NewHandshaker(config cfg.Config, state *State, store BlockStore) *Handshake
// TODO: retry the handshake/replay if it fails ?
func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
// handshake is done via info request on the query conn
res, tmspInfo, blockInfo, configInfo := proxyApp.Query().InfoSync()
if res.IsErr() {
return errors.New(Fmt("Error calling Info. Code: %v; Data: %X; Log: %s", res.Code, res.Data, res.Log))
}
if blockInfo == nil {
log.Warn("blockInfo is nil, aborting handshake")
return nil
res, err := proxyApp.Query().InfoSync()
if err != nil {
return errors.New(Fmt("Error calling Info: %v", err))
}
log.Notice("TMSP Handshake", "appHeight", blockInfo.BlockHeight, "appHash", blockInfo.AppHash)
blockHeight := int(blockInfo.BlockHeight) // XXX: beware overflow
appHash := blockInfo.AppHash
blockHeight := int(res.LastBlockHeight) // XXX: beware overflow
appHash := res.LastBlockAppHash
if tmspInfo != nil {
// TODO: check tmsp version (or do this in the tmspcli?)
_ = tmspInfo
}
log.Notice("TMSP Handshake", "appHeight", blockHeight, "appHash", appHash)
if configInfo != nil {
// TODO: set config info
_ = configInfo
}
// TODO: check version
// replay blocks up to the latest in the blockstore
err := h.ReplayBlocks(appHash, blockHeight, proxyApp.Consensus())
err = h.ReplayBlocks(appHash, blockHeight, proxyApp.Consensus())
if err != nil {
return errors.New(Fmt("Error on replay: %v", err))
}


+ 5
- 5
state/execution_test.go View File

@ -95,14 +95,14 @@ func testHandshakeReplay(t *testing.T, n int) {
}
// get the latest app hash from the app
r, _, blockInfo, _ := proxyApp.Query().InfoSync()
if r.IsErr() {
t.Fatal(r)
res, err := proxyApp.Query().InfoSync()
if err != nil {
t.Fatal(err)
}
// the app hash should be synced up
if !bytes.Equal(latestAppHash, blockInfo.AppHash) {
t.Fatalf("Expected app hashes to match after handshake/replay. got %X, expected %X", blockInfo.AppHash, latestAppHash)
if !bytes.Equal(latestAppHash, res.LastBlockAppHash) {
t.Fatalf("Expected app hashes to match after handshake/replay. got %X, expected %X", res.LastBlockAppHash, latestAppHash)
}
if handshaker.nBlocks != nBlocks-n {


Loading…
Cancel
Save