diff --git a/cmd/tendermint/flags.go b/cmd/tendermint/flags.go index cdc6c1b32..029e65ab7 100644 --- a/cmd/tendermint/flags.go +++ b/cmd/tendermint/flags.go @@ -30,7 +30,8 @@ func parseFlags(config cfg.Config, args []string) { flags.BoolVar(&skipUPNP, "skip_upnp", config.GetBool("skip_upnp"), "Skip UPNP configuration") flags.StringVar(&rpcLaddr, "rpc_laddr", config.GetString("rpc_laddr"), "RPC listen address. Port required") flags.StringVar(&logLevel, "log_level", config.GetString("log_level"), "Log level") - flags.StringVar(&proxyApp, "proxy_app", config.GetString("proxy_app"), "Proxy app address") + flags.StringVar(&proxyApp, "proxy_app", config.GetString("proxy_app"), + "Proxy app address, or 'nilapp' or 'dummy' for local testing.") flags.Parse(args) if printHelp { flags.PrintDefaults() diff --git a/consensus/common_test.go b/consensus/common_test.go index c5ae6b7b5..fad0969bf 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -13,9 +13,9 @@ import ( bc "github.com/tendermint/tendermint/blockchain" "github.com/tendermint/tendermint/config/tendermint_test" mempl "github.com/tendermint/tendermint/mempool" - "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" + tmspcli "github.com/tendermint/tmsp/client" "github.com/tendermint/tmsp/example/counter" ) @@ -313,8 +313,8 @@ func newConsensusState(state *sm.State, pv *types.PrivValidator) *ConsensusState // one for mempool, one for consensus mtx, app := new(sync.Mutex), counter.NewCounterApplication(false) - proxyAppConnMem := proxy.NewLocalAppConn(mtx, app) - proxyAppConnCon := proxy.NewLocalAppConn(mtx, app) + proxyAppConnMem := tmspcli.NewLocalClient(mtx, app) + proxyAppConnCon := tmspcli.NewLocalClient(mtx, app) // Make Mempool mempool := mempl.NewMempool(proxyAppConnMem) diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index 16dd656f2..750f987da 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/tendermint/tendermint/config/tendermint_test" - "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/types" + tmspcli "github.com/tendermint/tmsp/client" "github.com/tendermint/tmsp/example/counter" ) @@ -20,8 +20,8 @@ func TestSerialReap(t *testing.T) { app := counter.NewCounterApplication(true) app.SetOption("serial", "on") mtx := new(sync.Mutex) - appConnMem := proxy.NewLocalAppConn(mtx, app) - appConnCon := proxy.NewLocalAppConn(mtx, app) + appConnMem := tmspcli.NewLocalClient(mtx, app) + appConnCon := tmspcli.NewLocalClient(mtx, app) mempool := NewMempool(appConnMem) appendTxsRange := func(start, end int) { diff --git a/node/node.go b/node/node.go index c85cb8850..5369a68d6 100644 --- a/node/node.go +++ b/node/node.go @@ -25,6 +25,7 @@ import ( sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/version" + tmspcli "github.com/tendermint/tmsp/client" "github.com/tendermint/tmsp/example/dummy" "github.com/tendermint/tmsp/example/nil" ) @@ -244,11 +245,11 @@ func getProxyApp(addr string, hash []byte) (proxyAppConn proxy.AppConn) { case "nilapp": app := nilapp.NewNilApplication() mtx := new(sync.Mutex) - proxyAppConn = proxy.NewLocalAppConn(mtx, app) + proxyAppConn = tmspcli.NewLocalClient(mtx, app) case "dummy": app := dummy.NewDummyApplication() mtx := new(sync.Mutex) - proxyAppConn = proxy.NewLocalAppConn(mtx, app) + proxyAppConn = tmspcli.NewLocalClient(mtx, app) default: // Run forever in a loop remoteApp, err := proxy.NewRemoteAppConn(addr) diff --git a/proxy/app_conn.go b/proxy/app_conn.go index 7311a07b6..f959d7b8c 100644 --- a/proxy/app_conn.go +++ b/proxy/app_conn.go @@ -2,23 +2,8 @@ package proxy import ( tmspcli "github.com/tendermint/tmsp/client" - tmsp "github.com/tendermint/tmsp/types" ) type AppConn interface { - SetResponseCallback(tmspcli.Callback) - Error() error - - EchoAsync(msg string) *tmspcli.ReqRes - FlushAsync() *tmspcli.ReqRes - AppendTxAsync(tx []byte) *tmspcli.ReqRes - CheckTxAsync(tx []byte) *tmspcli.ReqRes - CommitAsync() *tmspcli.ReqRes - SetOptionAsync(key string, value string) *tmspcli.ReqRes - - InfoSync() (info string, err error) - FlushSync() error - CommitSync() (res tmsp.Result) - InitChainSync(validators []*tmsp.Validator) (err error) - EndBlockSync(height uint64) (changedValidators []*tmsp.Validator, err error) + tmspcli.Client } diff --git a/proxy/local_app_conn.go b/proxy/local_app_conn.go deleted file mode 100644 index c2cab0718..000000000 --- a/proxy/local_app_conn.go +++ /dev/null @@ -1,133 +0,0 @@ -package proxy - -import ( - tmspcli "github.com/tendermint/tmsp/client" - tmsp "github.com/tendermint/tmsp/types" - "sync" -) - -type localAppConn struct { - mtx *sync.Mutex - tmsp.Application - tmspcli.Callback -} - -func NewLocalAppConn(mtx *sync.Mutex, app tmsp.Application) *localAppConn { - return &localAppConn{ - mtx: mtx, - Application: app, - } -} - -func (app *localAppConn) SetResponseCallback(cb tmspcli.Callback) { - app.mtx.Lock() - defer app.mtx.Unlock() - app.Callback = cb -} - -// TODO: change tmsp.Application to include Error()? -func (app *localAppConn) Error() error { - return nil -} - -func (app *localAppConn) EchoAsync(msg string) *tmspcli.ReqRes { - return app.callback( - tmsp.RequestEcho(msg), - tmsp.ResponseEcho(msg), - ) -} - -func (app *localAppConn) FlushAsync() *tmspcli.ReqRes { - // Do nothing - return NewReqRes(tmsp.RequestFlush(), nil) -} - -func (app *localAppConn) SetOptionAsync(key string, value string) *tmspcli.ReqRes { - app.mtx.Lock() - log := app.Application.SetOption(key, value) - app.mtx.Unlock() - return app.callback( - tmsp.RequestSetOption(key, value), - tmsp.ResponseSetOption(log), - ) -} - -func (app *localAppConn) AppendTxAsync(tx []byte) *tmspcli.ReqRes { - app.mtx.Lock() - res := app.Application.AppendTx(tx) - app.mtx.Unlock() - return app.callback( - tmsp.RequestAppendTx(tx), - tmsp.ResponseAppendTx(res.Code, res.Data, res.Log), - ) -} - -func (app *localAppConn) CheckTxAsync(tx []byte) *tmspcli.ReqRes { - app.mtx.Lock() - res := app.Application.CheckTx(tx) - app.mtx.Unlock() - return app.callback( - tmsp.RequestCheckTx(tx), - tmsp.ResponseCheckTx(res.Code, res.Data, res.Log), - ) -} - -func (app *localAppConn) CommitAsync() *tmspcli.ReqRes { - app.mtx.Lock() - res := app.Application.Commit() - app.mtx.Unlock() - return app.callback( - tmsp.RequestCommit(), - tmsp.ResponseCommit(res.Code, res.Data, res.Log), - ) -} - -func (app *localAppConn) InfoSync() (info string, err error) { - app.mtx.Lock() - info = app.Application.Info() - app.mtx.Unlock() - return info, nil -} - -func (app *localAppConn) FlushSync() error { - return nil -} - -func (app *localAppConn) CommitSync() (res tmsp.Result) { - app.mtx.Lock() - res = app.Application.Commit() - app.mtx.Unlock() - return res -} - -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) EndBlockSync(height uint64) (changedValidators []*tmsp.Validator, err error) { - app.mtx.Lock() - if bcApp, ok := app.Application.(tmsp.BlockchainAware); ok { - changedValidators = bcApp.EndBlock(height) - } - app.mtx.Unlock() - return changedValidators, nil -} - -//------------------------------------------------------- - -func (app *localAppConn) callback(req *tmsp.Request, res *tmsp.Response) *tmspcli.ReqRes { - app.Callback(req, res) - return NewReqRes(req, res) -} - -func NewReqRes(req *tmsp.Request, res *tmsp.Response) *tmspcli.ReqRes { - reqRes := tmspcli.NewReqRes(req) - reqRes.Response = res - reqRes.SetDone() - return reqRes -} diff --git a/proxy/remote_app_conn.go b/proxy/remote_app_conn.go index 094ef36bc..a593c4a8e 100644 --- a/proxy/remote_app_conn.go +++ b/proxy/remote_app_conn.go @@ -8,7 +8,7 @@ import ( // the application in general is not meant to be interfaced // with concurrent callers. type remoteAppConn struct { - *tmspcli.Client + tmspcli.Client } func NewRemoteAppConn(addr string) (*remoteAppConn, error) { diff --git a/proxy/remote_app_conn_test.go b/proxy/remote_app_conn_test.go index dcb4fdc16..ab42b9943 100644 --- a/proxy/remote_app_conn_test.go +++ b/proxy/remote_app_conn_test.go @@ -76,12 +76,11 @@ func TestInfo(t *testing.T) { } else { t.Log("Connected") } - proxy.Start() - data, err := proxy.InfoSync() - if err != nil { + res := proxy.InfoSync() + if res.IsErr() { t.Errorf("Unexpected error: %v", err) } - if data != "size:0" { + if string(res.Data) != "size:0" { t.Error("Expected ResponseInfo with one element 'size:0' but got something else") } }