From 2dd703057993618dd37c16164ea97b48aba1bd0d Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 12 Jan 2017 15:13:47 -0500 Subject: [PATCH] tmsp: ResponseInfo and ResponseEndBlock --- consensus/mempool_test.go | 4 ++-- glide.lock | 6 +++--- proxy/app_conn.go | 8 ++++---- proxy/app_conn_test.go | 10 +++++----- rpc/core/tmsp.go | 12 ++++++++++-- rpc/core/types/responses.go | 8 ++++---- state/execution.go | 37 ++++++++++++------------------------- state/execution_test.go | 10 +++++----- 8 files changed, 45 insertions(+), 50 deletions(-) diff --git a/consensus/mempool_test.go b/consensus/mempool_test.go index 5d36a7118..58f46c7de 100644 --- a/consensus/mempool_test.go +++ b/consensus/mempool_test.go @@ -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) { diff --git a/glide.lock b/glide.lock index c9ebbfee6..2a272378a 100644 --- a/glide.lock +++ b/glide.lock @@ -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 diff --git a/proxy/app_conn.go b/proxy/app_conn.go index c2f383d3a..754a71e64 100644 --- a/proxy/app_conn.go +++ b/proxy/app_conn.go @@ -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() } diff --git a/proxy/app_conn_test.go b/proxy/app_conn_test.go index ed4e9fcef..e1e2d3040 100644 --- a/proxy/app_conn_test.go +++ b/proxy/app_conn_test.go @@ -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") } } diff --git a/rpc/core/tmsp.go b/rpc/core/tmsp.go index cecd71dbb..000e0f84c 100644 --- a/rpc/core/tmsp.go +++ b/rpc/core/tmsp.go @@ -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 } diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 0befac673..8d0c220b1 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -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 { diff --git a/state/execution.go b/state/execution.go index f8e2c1d82..1a618b9ca 100644 --- a/state/execution.go +++ b/state/execution.go @@ -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)) } diff --git a/state/execution_test.go b/state/execution_test.go index 16a9a080e..df9fc9a23 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -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 {