From e4e17a2c956cfaebbe9e9d1565a94ff20a23003f Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 10 Apr 2017 21:16:41 +0200 Subject: [PATCH 01/11] Play well with go-{rpc,crypto,data}:develop --- benchmarks/simu/counter.go | 4 +- glide.lock | 16 +++---- glide.yaml | 2 + rpc/client/httpclient.go | 32 +++++++------ rpc/test/client_test.go | 95 ++++++++++++++++---------------------- rpc/test/helpers.go | 8 ++-- 6 files changed, 76 insertions(+), 81 deletions(-) diff --git a/benchmarks/simu/counter.go b/benchmarks/simu/counter.go index ca155bbd8..36d1e35df 100644 --- a/benchmarks/simu/counter.go +++ b/benchmarks/simu/counter.go @@ -37,7 +37,9 @@ func main() { for i := 0; ; i++ { binary.BigEndian.PutUint64(buf, uint64(i)) //txBytes := hex.EncodeToString(buf[:n]) - request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx", Arr(buf[:8])) + request := rpctypes.NewRPCRequest("fakeid", + "broadcast_tx", + map[string]interface{}{"tx": buf[:8]}) reqBytes := wire.JSONBytes(request) //fmt.Println("!!", string(reqBytes)) fmt.Print(".") diff --git a/glide.lock b/glide.lock index e79888029..b018ab6e9 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 81cd41d28f9a747a71e6a47e8bc7d855846df29f359ffdcc8d1645c451112b31 -updated: 2017-03-06T17:34:23.99160606-05:00 +hash: 3fd28c04658701e65d8f27e245d15c61056199201fd5af6d18385491fc579a70 +updated: 2017-04-10T20:38:02.65047007+02:00 imports: - name: github.com/btcsuite/btcd version: 583684b21bfbde9b5fc4403916fd7c807feb0289 @@ -16,7 +16,7 @@ imports: - name: github.com/go-stack/stack version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/gogo/protobuf - version: 909568be09de550ed094403c2bf8a261b5bb730a + version: 100ba4e885062801d56799d78530b73b178a78f3 subpackages: - proto - name: github.com/golang/protobuf @@ -66,7 +66,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: 1236e8fb6eee3a63909f4014a8e84385ead7933d + version: af792eac777de757cd496349a5f6b5313738fcbc subpackages: - client - example/counter @@ -83,15 +83,15 @@ imports: - name: github.com/tendermint/go-clist version: 3baa390bbaf7634251c42ad69a8682e7e3990552 - name: github.com/tendermint/go-common - version: dcb015dff6c7af21e65c8e2f3b450df19d38c777 + version: 6af2364fa91ef2f3afc8ba0db33b66d9d3ae006c subpackages: - test - name: github.com/tendermint/go-config version: 620dcbbd7d587cf3599dedbf329b64311b0c307a - name: github.com/tendermint/go-crypto - version: 3f47cfac5fcd9e0f1727c7db980b3559913b3e3a + version: 750b25c47a5782f5f2b773ed9e706cb82b3ccef4 - name: github.com/tendermint/go-data - version: 32271140e8fd5abdbb22e268d7a02421fa382f0b + version: e7fcc6d081ec8518912fcdc103188275f83a3ee5 - name: github.com/tendermint/go-db version: eac3f2bc147023957c8bf69432a4e6c4dc5c3f72 - name: github.com/tendermint/go-events @@ -109,7 +109,7 @@ imports: subpackages: - upnp - name: github.com/tendermint/go-rpc - version: fcea0cda21f64889be00a0f4b6d13266b1a76ee7 + version: a416c37ebd389dcc320d8f41bdcdc575bdc0a826 subpackages: - client - server diff --git a/glide.yaml b/glide.yaml index 53d308233..cdb083e69 100644 --- a/glide.yaml +++ b/glide.yaml @@ -10,6 +10,8 @@ import: version: develop - package: github.com/tendermint/go-crypto version: develop +- package: github.com/tendermint/go-data + version: develop - package: github.com/tendermint/go-db version: develop - package: github.com/tendermint/go-events diff --git a/rpc/client/httpclient.go b/rpc/client/httpclient.go index bb4e6d3a8..07059bca0 100644 --- a/rpc/client/httpclient.go +++ b/rpc/client/httpclient.go @@ -22,7 +22,7 @@ out the server for test code (mock). */ type HTTP struct { remote string - rpc *rpcclient.ClientJSONRPC + rpc *rpcclient.JSONRPCClient *WSEvents } @@ -30,7 +30,7 @@ type HTTP struct { // and the websocket path (which always seems to be "/websocket") func NewHTTP(remote, wsEndpoint string) *HTTP { return &HTTP{ - rpc: rpcclient.NewClientJSONRPC(remote), + rpc: rpcclient.NewJSONRPCClient(remote), remote: remote, WSEvents: newWSEvents(remote, wsEndpoint), } @@ -50,7 +50,7 @@ func (c *HTTP) _assertIsEventSwitch() types.EventSwitch { func (c *HTTP) Status() (*ctypes.ResultStatus, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("status", []interface{}{}, tmResult) + _, err := c.rpc.Call("status", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "Status") } @@ -60,7 +60,7 @@ func (c *HTTP) Status() (*ctypes.ResultStatus, error) { func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("abci_info", []interface{}{}, tmResult) + _, err := c.rpc.Call("abci_info", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "ABCIInfo") } @@ -69,7 +69,9 @@ func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) { func (c *HTTP) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("abci_query", []interface{}{path, data, prove}, tmResult) + _, err := c.rpc.Call("abci_query", + map[string]interface{}{"path": path, "data": data, "prove": prove}, + tmResult) if err != nil { return nil, errors.Wrap(err, "ABCIQuery") } @@ -78,7 +80,7 @@ func (c *HTTP) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultAB func (c *HTTP) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("broadcast_tx_commit", []interface{}{tx}, tmResult) + _, err := c.rpc.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) if err != nil { return nil, errors.Wrap(err, "broadcast_tx_commit") } @@ -95,7 +97,7 @@ func (c *HTTP) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { func (c *HTTP) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call(route, []interface{}{tx}, tmResult) + _, err := c.rpc.Call(route, map[string]interface{}{"tx": tx}, tmResult) if err != nil { return nil, errors.Wrap(err, route) } @@ -104,7 +106,7 @@ func (c *HTTP) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTx func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("net_info", nil, tmResult) + _, err := c.rpc.Call("net_info", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "NetInfo") } @@ -113,7 +115,7 @@ func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) { func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("dump_consensus_state", nil, tmResult) + _, err := c.rpc.Call("dump_consensus_state", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "DumpConsensusState") } @@ -122,7 +124,9 @@ func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) { func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("blockchain", []interface{}{minHeight, maxHeight}, tmResult) + _, err := c.rpc.Call("blockchain", + map[string]interface{}{"minHeight": minHeight, "maxHeight": maxHeight}, + tmResult) if err != nil { return nil, errors.Wrap(err, "BlockchainInfo") } @@ -131,7 +135,7 @@ func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchai func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("genesis", nil, tmResult) + _, err := c.rpc.Call("genesis", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "Genesis") } @@ -140,7 +144,7 @@ func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error) { func (c *HTTP) Block(height int) (*ctypes.ResultBlock, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("block", []interface{}{height}, tmResult) + _, err := c.rpc.Call("block", map[string]interface{}{"height": height}, tmResult) if err != nil { return nil, errors.Wrap(err, "Block") } @@ -149,7 +153,7 @@ func (c *HTTP) Block(height int) (*ctypes.ResultBlock, error) { func (c *HTTP) Commit(height int) (*ctypes.ResultCommit, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("commit", []interface{}{height}, tmResult) + _, err := c.rpc.Call("commit", map[string]interface{}{"height": height}, tmResult) if err != nil { return nil, errors.Wrap(err, "Commit") } @@ -158,7 +162,7 @@ func (c *HTTP) Commit(height int) (*ctypes.ResultCommit, error) { func (c *HTTP) Validators() (*ctypes.ResultValidators, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("validators", nil, tmResult) + _, err := c.rpc.Call("validators", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "Validators") } diff --git a/rpc/test/client_test.go b/rpc/test/client_test.go index 1141de4ee..43409c723 100644 --- a/rpc/test/client_test.go +++ b/rpc/test/client_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/abci/types" . "github.com/tendermint/go-common" + rpc "github.com/tendermint/go-rpc/client" ctypes "github.com/tendermint/tendermint/rpc/core/types" "github.com/tendermint/tendermint/types" ) @@ -25,24 +26,20 @@ import ( // status func TestURIStatus(t *testing.T) { - tmResult := new(ctypes.TMResult) - _, err := GetURIClient().Call("status", map[string]interface{}{}, tmResult) - require.Nil(t, err) - testStatus(t, tmResult) + testStatus(t, GetURIClient()) } func TestJSONStatus(t *testing.T) { - tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("status", []interface{}{}, tmResult) - require.Nil(t, err) - testStatus(t, tmResult) + testStatus(t, GetJSONClient()) } -func testStatus(t *testing.T, statusI interface{}) { +func testStatus(t *testing.T, client rpc.HTTPClient) { chainID := GetConfig().GetString("chain_id") + tmResult := new(ctypes.TMResult) + _, err := client.Call("status", map[string]interface{}{}, tmResult) + require.Nil(t, err) - tmRes := statusI.(*ctypes.TMResult) - status := (*tmRes).(*ctypes.ResultStatus) + status := (*tmResult).(*ctypes.ResultStatus) assert.Equal(t, chainID, status.NodeInfo.Network) } @@ -59,28 +56,22 @@ func randBytes(t *testing.T) []byte { } func TestURIBroadcastTxSync(t *testing.T) { - config.Set("block_size", 0) - defer config.Set("block_size", -1) - tmResult := new(ctypes.TMResult) - tx := randBytes(t) - _, err := GetURIClient().Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult) - require.Nil(t, err) - testBroadcastTxSync(t, tmResult, tx) + testBroadcastTxSync(t, GetURIClient()) } func TestJSONBroadcastTxSync(t *testing.T) { + testBroadcastTxSync(t, GetJSONClient()) +} + +func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) { config.Set("block_size", 0) defer config.Set("block_size", -1) tmResult := new(ctypes.TMResult) tx := randBytes(t) - _, err := GetJSONClient().Call("broadcast_tx_sync", []interface{}{tx}, tmResult) + _, err := client.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult) require.Nil(t, err) - testBroadcastTxSync(t, tmResult, tx) -} -func testBroadcastTxSync(t *testing.T, resI interface{}, tx []byte) { - tmRes := resI.(*ctypes.TMResult) - res := (*tmRes).(*ctypes.ResultBroadcastTx) + res := (*tmResult).(*ctypes.ResultBroadcastTx) require.Equal(t, abci.CodeType_OK, res.Code) mem := node.MempoolReactor().Mempool require.Equal(t, 1, mem.Size()) @@ -98,34 +89,31 @@ func testTxKV(t *testing.T) ([]byte, []byte, []byte) { return k, v, []byte(Fmt("%s=%s", k, v)) } -func sendTx(t *testing.T) ([]byte, []byte) { +func sendTx(t *testing.T, client rpc.HTTPClient) ([]byte, []byte) { tmResult := new(ctypes.TMResult) k, v, tx := testTxKV(t) - _, err := GetJSONClient().Call("broadcast_tx_commit", []interface{}{tx}, tmResult) + _, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) require.Nil(t, err) return k, v } func TestURIABCIQuery(t *testing.T) { - k, v := sendTx(t) - time.Sleep(time.Second) - tmResult := new(ctypes.TMResult) - _, err := GetURIClient().Call("abci_query", map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult) - require.Nil(t, err) - testABCIQuery(t, tmResult, v) + testABCIQuery(t, GetURIClient()) } func TestJSONABCIQuery(t *testing.T) { - k, v := sendTx(t) + testABCIQuery(t, GetURIClient()) +} + +func testABCIQuery(t *testing.T, client rpc.HTTPClient) { + k, _ := sendTx(t, client) + time.Sleep(time.Millisecond * 100) tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("abci_query", []interface{}{"", k, false}, tmResult) + _, err := client.Call("abci_query", + map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult) require.Nil(t, err) - testABCIQuery(t, tmResult, v) -} -func testABCIQuery(t *testing.T, statusI interface{}, value []byte) { - tmRes := statusI.(*ctypes.TMResult) - resQuery := (*tmRes).(*ctypes.ResultABCIQuery) + resQuery := (*tmResult).(*ctypes.ResultABCIQuery) require.EqualValues(t, 0, resQuery.Response.Code) // XXX: specific to value returned by the dummy @@ -136,25 +124,22 @@ func testABCIQuery(t *testing.T, statusI interface{}, value []byte) { // broadcast tx commit func TestURIBroadcastTxCommit(t *testing.T) { - tmResult := new(ctypes.TMResult) - tx := randBytes(t) - _, err := GetURIClient().Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) - require.Nil(t, err) - testBroadcastTxCommit(t, tmResult, tx) + testBroadcastTxCommit(t, GetURIClient()) } func TestJSONBroadcastTxCommit(t *testing.T) { - tmResult := new(ctypes.TMResult) - tx := randBytes(t) - _, err := GetJSONClient().Call("broadcast_tx_commit", []interface{}{tx}, tmResult) - require.Nil(t, err) - testBroadcastTxCommit(t, tmResult, tx) + testBroadcastTxCommit(t, GetJSONClient()) } -func testBroadcastTxCommit(t *testing.T, resI interface{}, tx []byte) { +func testBroadcastTxCommit(t *testing.T, client rpc.HTTPClient) { require := require.New(t) - tmRes := resI.(*ctypes.TMResult) - res := (*tmRes).(*ctypes.ResultBroadcastTxCommit) + + tmResult := new(ctypes.TMResult) + tx := randBytes(t) + _, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) + require.Nil(err) + + res := (*tmResult).(*ctypes.ResultBroadcastTxCommit) checkTx := res.CheckTx require.Equal(abci.CodeType_OK, checkTx.Code) deliverTx := res.DeliverTx @@ -240,7 +225,7 @@ func TestWSTxEvent(t *testing.T) { // send an tx tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("broadcast_tx_sync", []interface{}{tx}, tmResult) + _, err := GetJSONClient().Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult) require.Nil(err) waitForEvent(t, wsc, eid, true, func() {}, func(eid string, b interface{}) error { @@ -310,7 +295,9 @@ func TestURIUnsafeSetConfig(t *testing.T) { func TestJSONUnsafeSetConfig(t *testing.T) { for _, testCase := range testCasesUnsafeSetConfig { tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("unsafe_set_config", []interface{}{testCase[0], testCase[1], testCase[2]}, tmResult) + _, err := GetJSONClient().Call("unsafe_set_config", + map[string]interface{}{"type": testCase[0], "key": testCase[1], "value": testCase[2]}, + tmResult) require.Nil(t, err) } testUnsafeSetConfig(t) diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index cf64ac155..349980e9c 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -72,15 +72,15 @@ func GetConfig() cfg.Config { } // GetURIClient gets a uri client pointing to the test tendermint rpc -func GetURIClient() *client.ClientURI { +func GetURIClient() *client.URIClient { rpcAddr := GetConfig().GetString("rpc_laddr") - return client.NewClientURI(rpcAddr) + return client.NewURIClient(rpcAddr) } // GetJSONClient gets a http/json client pointing to the test tendermint rpc -func GetJSONClient() *client.ClientJSONRPC { +func GetJSONClient() *client.JSONRPCClient { rpcAddr := GetConfig().GetString("rpc_laddr") - return client.NewClientJSONRPC(rpcAddr) + return client.NewJSONRPCClient(rpcAddr) } func GetGRPCClient() core_grpc.BroadcastAPIClient { From d3069b0f5b24e0a62d9ab7f1c88acdeb6b5ac94b Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 10 Apr 2017 22:46:03 +0200 Subject: [PATCH 02/11] Update abci develop --- glide.lock | 44 ++++++++++++++++++++++++------------ scripts/install_abci_apps.sh | 2 +- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/glide.lock b/glide.lock index b018ab6e9..f3065569d 100644 --- a/glide.lock +++ b/glide.lock @@ -1,12 +1,12 @@ hash: 3fd28c04658701e65d8f27e245d15c61056199201fd5af6d18385491fc579a70 -updated: 2017-04-10T20:38:02.65047007+02:00 +updated: 2017-04-10T22:34:33.346948802+02:00 imports: - name: github.com/btcsuite/btcd - version: 583684b21bfbde9b5fc4403916fd7c807feb0289 + version: 4b348c1d33373d672edd83fc576892d0e46686d2 subpackages: - btcec - name: github.com/BurntSushi/toml - version: 99064174e013895bbd9b025c31100bd1d9b590ca + version: b26d9c308763d68093482582cea63d69be07a0f0 - name: github.com/davecgh/go-spew version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: @@ -20,9 +20,10 @@ imports: subpackages: - proto - name: github.com/golang/protobuf - version: 69b215d01a5606c843240eab4937eab3acee6530 + version: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef subpackages: - proto + - ptypes/any - name: github.com/golang/snappy version: 553a641470496b2327abcac10b36396bd98e45c9 - name: github.com/gorilla/websocket @@ -32,9 +33,9 @@ imports: - name: github.com/jmhodges/levigo version: c42d9e0ca023e2198120196f842701bb4c55d7b9 - name: github.com/mattn/go-colorable - version: acb9493f2794fd0f820de7a27a217dafbb1b65ea + version: ded68f7a9561c023e790de24279db7ebf473ea80 - name: github.com/mattn/go-isatty - version: 9622e0cc9d8f9be434ca605520ff9a16808fee47 + version: fc9e8d8ef48496124e79ae0df75490096eccf6fe - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/pmezard/go-difflib @@ -42,16 +43,16 @@ imports: subpackages: - difflib - name: github.com/spf13/cobra - version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c + version: 5deb57bbca49eb370538fc295ba4b2988f9f5e09 - name: github.com/spf13/pflag - version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7 + version: 9a906f17374922ed0f74e1b2f593d3723f2ffb00 - name: github.com/stretchr/testify version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: - assert - require - name: github.com/syndtr/goleveldb - version: 3c5717caf1475fd25964109a0fc640bd150fce43 + version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 subpackages: - leveldb - leveldb/cache @@ -66,7 +67,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: af792eac777de757cd496349a5f6b5313738fcbc + version: 31eafe8f8eba6b8817edd74df399f508540da528 subpackages: - client - example/counter @@ -105,7 +106,7 @@ imports: - name: github.com/tendermint/go-merkle version: 714d4d04557fd068a7c2a1748241ce8428015a96 - name: github.com/tendermint/go-p2p - version: 97a5ed2d1a17eaee8717b8a32cfaf7a9a82a273d + version: ebd3929c0db9e42268cd677a7782451be7d23327 subpackages: - upnp - name: github.com/tendermint/go-rpc @@ -127,7 +128,7 @@ imports: - client - testutil - name: golang.org/x/crypto - version: 40541ccb1c6e64c947ed6f606b8a6cb4b67d7436 + version: 9ef620b9ca2f82b55030ffd4f41327fa9e77a92c subpackages: - curve25519 - nacl/box @@ -138,7 +139,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: d379faa25cbdc04d653984913a2ceb43b0bc46d7 + version: d1e1b351919c6738fdeb9893d5c998b161464f0c subpackages: - context - http2 @@ -148,20 +149,33 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: e48874b42435b4347fc52bdee0424a52abc974d7 + version: f3918c30c5c2cb527c0b071a27c35120a6c0719a subpackages: - unix +- name: golang.org/x/text + version: f4b4367115ec2de254587813edaa901bc1c723a8 + subpackages: + - secure/bidirule + - transform + - unicode/bidi + - unicode/norm +- name: google.golang.org/genproto + version: 411e09b969b1170a9f0c467558eb4c4c110d9c77 + subpackages: + - googleapis/rpc/status - name: google.golang.org/grpc - version: 7b399ed358736bc5522021cdc7d79a8ee9ac6f98 + version: b47cbd158b4721c318abbb389929ef005c322118 subpackages: - codes - credentials - grpclog - internal + - keepalive - metadata - naming - peer - stats + - status - tap - transport testImports: [] diff --git a/scripts/install_abci_apps.sh b/scripts/install_abci_apps.sh index 6da2e2ed2..b2c0b085b 100644 --- a/scripts/install_abci_apps.sh +++ b/scripts/install_abci_apps.sh @@ -1,6 +1,6 @@ #! /bin/bash -go get github.com/tendermint/abci/... +go get -d github.com/tendermint/abci # get the abci commit used by tendermint COMMIT=`bash scripts/glide/parse.sh abci` From d1fc37ff9e8b8034aa3c029fc59f56768f373d73 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 11 Apr 2017 12:57:06 +0200 Subject: [PATCH 03/11] Undo last two commits --- benchmarks/simu/counter.go | 4 +- glide.lock | 56 ++++++++------------- glide.yaml | 2 - rpc/client/httpclient.go | 32 ++++++------ rpc/test/client_test.go | 95 ++++++++++++++++++++---------------- rpc/test/helpers.go | 8 +-- scripts/install_abci_apps.sh | 2 +- 7 files changed, 95 insertions(+), 104 deletions(-) diff --git a/benchmarks/simu/counter.go b/benchmarks/simu/counter.go index 36d1e35df..ca155bbd8 100644 --- a/benchmarks/simu/counter.go +++ b/benchmarks/simu/counter.go @@ -37,9 +37,7 @@ func main() { for i := 0; ; i++ { binary.BigEndian.PutUint64(buf, uint64(i)) //txBytes := hex.EncodeToString(buf[:n]) - request := rpctypes.NewRPCRequest("fakeid", - "broadcast_tx", - map[string]interface{}{"tx": buf[:8]}) + request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx", Arr(buf[:8])) reqBytes := wire.JSONBytes(request) //fmt.Println("!!", string(reqBytes)) fmt.Print(".") diff --git a/glide.lock b/glide.lock index f3065569d..e79888029 100644 --- a/glide.lock +++ b/glide.lock @@ -1,12 +1,12 @@ -hash: 3fd28c04658701e65d8f27e245d15c61056199201fd5af6d18385491fc579a70 -updated: 2017-04-10T22:34:33.346948802+02:00 +hash: 81cd41d28f9a747a71e6a47e8bc7d855846df29f359ffdcc8d1645c451112b31 +updated: 2017-03-06T17:34:23.99160606-05:00 imports: - name: github.com/btcsuite/btcd - version: 4b348c1d33373d672edd83fc576892d0e46686d2 + version: 583684b21bfbde9b5fc4403916fd7c807feb0289 subpackages: - btcec - name: github.com/BurntSushi/toml - version: b26d9c308763d68093482582cea63d69be07a0f0 + version: 99064174e013895bbd9b025c31100bd1d9b590ca - name: github.com/davecgh/go-spew version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: @@ -16,14 +16,13 @@ imports: - name: github.com/go-stack/stack version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/gogo/protobuf - version: 100ba4e885062801d56799d78530b73b178a78f3 + version: 909568be09de550ed094403c2bf8a261b5bb730a subpackages: - proto - name: github.com/golang/protobuf - version: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef + version: 69b215d01a5606c843240eab4937eab3acee6530 subpackages: - proto - - ptypes/any - name: github.com/golang/snappy version: 553a641470496b2327abcac10b36396bd98e45c9 - name: github.com/gorilla/websocket @@ -33,9 +32,9 @@ imports: - name: github.com/jmhodges/levigo version: c42d9e0ca023e2198120196f842701bb4c55d7b9 - name: github.com/mattn/go-colorable - version: ded68f7a9561c023e790de24279db7ebf473ea80 + version: acb9493f2794fd0f820de7a27a217dafbb1b65ea - name: github.com/mattn/go-isatty - version: fc9e8d8ef48496124e79ae0df75490096eccf6fe + version: 9622e0cc9d8f9be434ca605520ff9a16808fee47 - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/pmezard/go-difflib @@ -43,16 +42,16 @@ imports: subpackages: - difflib - name: github.com/spf13/cobra - version: 5deb57bbca49eb370538fc295ba4b2988f9f5e09 + version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c - name: github.com/spf13/pflag - version: 9a906f17374922ed0f74e1b2f593d3723f2ffb00 + version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7 - name: github.com/stretchr/testify version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: - assert - require - name: github.com/syndtr/goleveldb - version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 + version: 3c5717caf1475fd25964109a0fc640bd150fce43 subpackages: - leveldb - leveldb/cache @@ -67,7 +66,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: 31eafe8f8eba6b8817edd74df399f508540da528 + version: 1236e8fb6eee3a63909f4014a8e84385ead7933d subpackages: - client - example/counter @@ -84,15 +83,15 @@ imports: - name: github.com/tendermint/go-clist version: 3baa390bbaf7634251c42ad69a8682e7e3990552 - name: github.com/tendermint/go-common - version: 6af2364fa91ef2f3afc8ba0db33b66d9d3ae006c + version: dcb015dff6c7af21e65c8e2f3b450df19d38c777 subpackages: - test - name: github.com/tendermint/go-config version: 620dcbbd7d587cf3599dedbf329b64311b0c307a - name: github.com/tendermint/go-crypto - version: 750b25c47a5782f5f2b773ed9e706cb82b3ccef4 + version: 3f47cfac5fcd9e0f1727c7db980b3559913b3e3a - name: github.com/tendermint/go-data - version: e7fcc6d081ec8518912fcdc103188275f83a3ee5 + version: 32271140e8fd5abdbb22e268d7a02421fa382f0b - name: github.com/tendermint/go-db version: eac3f2bc147023957c8bf69432a4e6c4dc5c3f72 - name: github.com/tendermint/go-events @@ -106,11 +105,11 @@ imports: - name: github.com/tendermint/go-merkle version: 714d4d04557fd068a7c2a1748241ce8428015a96 - name: github.com/tendermint/go-p2p - version: ebd3929c0db9e42268cd677a7782451be7d23327 + version: 97a5ed2d1a17eaee8717b8a32cfaf7a9a82a273d subpackages: - upnp - name: github.com/tendermint/go-rpc - version: a416c37ebd389dcc320d8f41bdcdc575bdc0a826 + version: fcea0cda21f64889be00a0f4b6d13266b1a76ee7 subpackages: - client - server @@ -128,7 +127,7 @@ imports: - client - testutil - name: golang.org/x/crypto - version: 9ef620b9ca2f82b55030ffd4f41327fa9e77a92c + version: 40541ccb1c6e64c947ed6f606b8a6cb4b67d7436 subpackages: - curve25519 - nacl/box @@ -139,7 +138,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: d1e1b351919c6738fdeb9893d5c998b161464f0c + version: d379faa25cbdc04d653984913a2ceb43b0bc46d7 subpackages: - context - http2 @@ -149,33 +148,20 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: f3918c30c5c2cb527c0b071a27c35120a6c0719a + version: e48874b42435b4347fc52bdee0424a52abc974d7 subpackages: - unix -- name: golang.org/x/text - version: f4b4367115ec2de254587813edaa901bc1c723a8 - subpackages: - - secure/bidirule - - transform - - unicode/bidi - - unicode/norm -- name: google.golang.org/genproto - version: 411e09b969b1170a9f0c467558eb4c4c110d9c77 - subpackages: - - googleapis/rpc/status - name: google.golang.org/grpc - version: b47cbd158b4721c318abbb389929ef005c322118 + version: 7b399ed358736bc5522021cdc7d79a8ee9ac6f98 subpackages: - codes - credentials - grpclog - internal - - keepalive - metadata - naming - peer - stats - - status - tap - transport testImports: [] diff --git a/glide.yaml b/glide.yaml index cdb083e69..53d308233 100644 --- a/glide.yaml +++ b/glide.yaml @@ -10,8 +10,6 @@ import: version: develop - package: github.com/tendermint/go-crypto version: develop -- package: github.com/tendermint/go-data - version: develop - package: github.com/tendermint/go-db version: develop - package: github.com/tendermint/go-events diff --git a/rpc/client/httpclient.go b/rpc/client/httpclient.go index 07059bca0..bb4e6d3a8 100644 --- a/rpc/client/httpclient.go +++ b/rpc/client/httpclient.go @@ -22,7 +22,7 @@ out the server for test code (mock). */ type HTTP struct { remote string - rpc *rpcclient.JSONRPCClient + rpc *rpcclient.ClientJSONRPC *WSEvents } @@ -30,7 +30,7 @@ type HTTP struct { // and the websocket path (which always seems to be "/websocket") func NewHTTP(remote, wsEndpoint string) *HTTP { return &HTTP{ - rpc: rpcclient.NewJSONRPCClient(remote), + rpc: rpcclient.NewClientJSONRPC(remote), remote: remote, WSEvents: newWSEvents(remote, wsEndpoint), } @@ -50,7 +50,7 @@ func (c *HTTP) _assertIsEventSwitch() types.EventSwitch { func (c *HTTP) Status() (*ctypes.ResultStatus, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("status", map[string]interface{}{}, tmResult) + _, err := c.rpc.Call("status", []interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "Status") } @@ -60,7 +60,7 @@ func (c *HTTP) Status() (*ctypes.ResultStatus, error) { func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("abci_info", map[string]interface{}{}, tmResult) + _, err := c.rpc.Call("abci_info", []interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "ABCIInfo") } @@ -69,9 +69,7 @@ func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) { func (c *HTTP) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("abci_query", - map[string]interface{}{"path": path, "data": data, "prove": prove}, - tmResult) + _, err := c.rpc.Call("abci_query", []interface{}{path, data, prove}, tmResult) if err != nil { return nil, errors.Wrap(err, "ABCIQuery") } @@ -80,7 +78,7 @@ func (c *HTTP) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultAB func (c *HTTP) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) + _, err := c.rpc.Call("broadcast_tx_commit", []interface{}{tx}, tmResult) if err != nil { return nil, errors.Wrap(err, "broadcast_tx_commit") } @@ -97,7 +95,7 @@ func (c *HTTP) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { func (c *HTTP) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call(route, map[string]interface{}{"tx": tx}, tmResult) + _, err := c.rpc.Call(route, []interface{}{tx}, tmResult) if err != nil { return nil, errors.Wrap(err, route) } @@ -106,7 +104,7 @@ func (c *HTTP) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTx func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("net_info", map[string]interface{}{}, tmResult) + _, err := c.rpc.Call("net_info", nil, tmResult) if err != nil { return nil, errors.Wrap(err, "NetInfo") } @@ -115,7 +113,7 @@ func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) { func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("dump_consensus_state", map[string]interface{}{}, tmResult) + _, err := c.rpc.Call("dump_consensus_state", nil, tmResult) if err != nil { return nil, errors.Wrap(err, "DumpConsensusState") } @@ -124,9 +122,7 @@ func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) { func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("blockchain", - map[string]interface{}{"minHeight": minHeight, "maxHeight": maxHeight}, - tmResult) + _, err := c.rpc.Call("blockchain", []interface{}{minHeight, maxHeight}, tmResult) if err != nil { return nil, errors.Wrap(err, "BlockchainInfo") } @@ -135,7 +131,7 @@ func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchai func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("genesis", map[string]interface{}{}, tmResult) + _, err := c.rpc.Call("genesis", nil, tmResult) if err != nil { return nil, errors.Wrap(err, "Genesis") } @@ -144,7 +140,7 @@ func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error) { func (c *HTTP) Block(height int) (*ctypes.ResultBlock, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("block", map[string]interface{}{"height": height}, tmResult) + _, err := c.rpc.Call("block", []interface{}{height}, tmResult) if err != nil { return nil, errors.Wrap(err, "Block") } @@ -153,7 +149,7 @@ func (c *HTTP) Block(height int) (*ctypes.ResultBlock, error) { func (c *HTTP) Commit(height int) (*ctypes.ResultCommit, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("commit", map[string]interface{}{"height": height}, tmResult) + _, err := c.rpc.Call("commit", []interface{}{height}, tmResult) if err != nil { return nil, errors.Wrap(err, "Commit") } @@ -162,7 +158,7 @@ func (c *HTTP) Commit(height int) (*ctypes.ResultCommit, error) { func (c *HTTP) Validators() (*ctypes.ResultValidators, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("validators", map[string]interface{}{}, tmResult) + _, err := c.rpc.Call("validators", nil, tmResult) if err != nil { return nil, errors.Wrap(err, "Validators") } diff --git a/rpc/test/client_test.go b/rpc/test/client_test.go index 43409c723..1141de4ee 100644 --- a/rpc/test/client_test.go +++ b/rpc/test/client_test.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/abci/types" . "github.com/tendermint/go-common" - rpc "github.com/tendermint/go-rpc/client" ctypes "github.com/tendermint/tendermint/rpc/core/types" "github.com/tendermint/tendermint/types" ) @@ -26,20 +25,24 @@ import ( // status func TestURIStatus(t *testing.T) { - testStatus(t, GetURIClient()) + tmResult := new(ctypes.TMResult) + _, err := GetURIClient().Call("status", map[string]interface{}{}, tmResult) + require.Nil(t, err) + testStatus(t, tmResult) } func TestJSONStatus(t *testing.T) { - testStatus(t, GetJSONClient()) + tmResult := new(ctypes.TMResult) + _, err := GetJSONClient().Call("status", []interface{}{}, tmResult) + require.Nil(t, err) + testStatus(t, tmResult) } -func testStatus(t *testing.T, client rpc.HTTPClient) { +func testStatus(t *testing.T, statusI interface{}) { chainID := GetConfig().GetString("chain_id") - tmResult := new(ctypes.TMResult) - _, err := client.Call("status", map[string]interface{}{}, tmResult) - require.Nil(t, err) - status := (*tmResult).(*ctypes.ResultStatus) + tmRes := statusI.(*ctypes.TMResult) + status := (*tmRes).(*ctypes.ResultStatus) assert.Equal(t, chainID, status.NodeInfo.Network) } @@ -56,22 +59,28 @@ func randBytes(t *testing.T) []byte { } func TestURIBroadcastTxSync(t *testing.T) { - testBroadcastTxSync(t, GetURIClient()) + config.Set("block_size", 0) + defer config.Set("block_size", -1) + tmResult := new(ctypes.TMResult) + tx := randBytes(t) + _, err := GetURIClient().Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult) + require.Nil(t, err) + testBroadcastTxSync(t, tmResult, tx) } func TestJSONBroadcastTxSync(t *testing.T) { - testBroadcastTxSync(t, GetJSONClient()) -} - -func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) { config.Set("block_size", 0) defer config.Set("block_size", -1) tmResult := new(ctypes.TMResult) tx := randBytes(t) - _, err := client.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult) + _, err := GetJSONClient().Call("broadcast_tx_sync", []interface{}{tx}, tmResult) require.Nil(t, err) + testBroadcastTxSync(t, tmResult, tx) +} - res := (*tmResult).(*ctypes.ResultBroadcastTx) +func testBroadcastTxSync(t *testing.T, resI interface{}, tx []byte) { + tmRes := resI.(*ctypes.TMResult) + res := (*tmRes).(*ctypes.ResultBroadcastTx) require.Equal(t, abci.CodeType_OK, res.Code) mem := node.MempoolReactor().Mempool require.Equal(t, 1, mem.Size()) @@ -89,31 +98,34 @@ func testTxKV(t *testing.T) ([]byte, []byte, []byte) { return k, v, []byte(Fmt("%s=%s", k, v)) } -func sendTx(t *testing.T, client rpc.HTTPClient) ([]byte, []byte) { +func sendTx(t *testing.T) ([]byte, []byte) { tmResult := new(ctypes.TMResult) k, v, tx := testTxKV(t) - _, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) + _, err := GetJSONClient().Call("broadcast_tx_commit", []interface{}{tx}, tmResult) require.Nil(t, err) return k, v } func TestURIABCIQuery(t *testing.T) { - testABCIQuery(t, GetURIClient()) + k, v := sendTx(t) + time.Sleep(time.Second) + tmResult := new(ctypes.TMResult) + _, err := GetURIClient().Call("abci_query", map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult) + require.Nil(t, err) + testABCIQuery(t, tmResult, v) } func TestJSONABCIQuery(t *testing.T) { - testABCIQuery(t, GetURIClient()) -} - -func testABCIQuery(t *testing.T, client rpc.HTTPClient) { - k, _ := sendTx(t, client) - time.Sleep(time.Millisecond * 100) + k, v := sendTx(t) tmResult := new(ctypes.TMResult) - _, err := client.Call("abci_query", - map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult) + _, err := GetJSONClient().Call("abci_query", []interface{}{"", k, false}, tmResult) require.Nil(t, err) + testABCIQuery(t, tmResult, v) +} - resQuery := (*tmResult).(*ctypes.ResultABCIQuery) +func testABCIQuery(t *testing.T, statusI interface{}, value []byte) { + tmRes := statusI.(*ctypes.TMResult) + resQuery := (*tmRes).(*ctypes.ResultABCIQuery) require.EqualValues(t, 0, resQuery.Response.Code) // XXX: specific to value returned by the dummy @@ -124,22 +136,25 @@ func testABCIQuery(t *testing.T, client rpc.HTTPClient) { // broadcast tx commit func TestURIBroadcastTxCommit(t *testing.T) { - testBroadcastTxCommit(t, GetURIClient()) + tmResult := new(ctypes.TMResult) + tx := randBytes(t) + _, err := GetURIClient().Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) + require.Nil(t, err) + testBroadcastTxCommit(t, tmResult, tx) } func TestJSONBroadcastTxCommit(t *testing.T) { - testBroadcastTxCommit(t, GetJSONClient()) -} - -func testBroadcastTxCommit(t *testing.T, client rpc.HTTPClient) { - require := require.New(t) - tmResult := new(ctypes.TMResult) tx := randBytes(t) - _, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) - require.Nil(err) + _, err := GetJSONClient().Call("broadcast_tx_commit", []interface{}{tx}, tmResult) + require.Nil(t, err) + testBroadcastTxCommit(t, tmResult, tx) +} - res := (*tmResult).(*ctypes.ResultBroadcastTxCommit) +func testBroadcastTxCommit(t *testing.T, resI interface{}, tx []byte) { + require := require.New(t) + tmRes := resI.(*ctypes.TMResult) + res := (*tmRes).(*ctypes.ResultBroadcastTxCommit) checkTx := res.CheckTx require.Equal(abci.CodeType_OK, checkTx.Code) deliverTx := res.DeliverTx @@ -225,7 +240,7 @@ func TestWSTxEvent(t *testing.T) { // send an tx tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult) + _, err := GetJSONClient().Call("broadcast_tx_sync", []interface{}{tx}, tmResult) require.Nil(err) waitForEvent(t, wsc, eid, true, func() {}, func(eid string, b interface{}) error { @@ -295,9 +310,7 @@ func TestURIUnsafeSetConfig(t *testing.T) { func TestJSONUnsafeSetConfig(t *testing.T) { for _, testCase := range testCasesUnsafeSetConfig { tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("unsafe_set_config", - map[string]interface{}{"type": testCase[0], "key": testCase[1], "value": testCase[2]}, - tmResult) + _, err := GetJSONClient().Call("unsafe_set_config", []interface{}{testCase[0], testCase[1], testCase[2]}, tmResult) require.Nil(t, err) } testUnsafeSetConfig(t) diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index 349980e9c..cf64ac155 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -72,15 +72,15 @@ func GetConfig() cfg.Config { } // GetURIClient gets a uri client pointing to the test tendermint rpc -func GetURIClient() *client.URIClient { +func GetURIClient() *client.ClientURI { rpcAddr := GetConfig().GetString("rpc_laddr") - return client.NewURIClient(rpcAddr) + return client.NewClientURI(rpcAddr) } // GetJSONClient gets a http/json client pointing to the test tendermint rpc -func GetJSONClient() *client.JSONRPCClient { +func GetJSONClient() *client.ClientJSONRPC { rpcAddr := GetConfig().GetString("rpc_laddr") - return client.NewJSONRPCClient(rpcAddr) + return client.NewClientJSONRPC(rpcAddr) } func GetGRPCClient() core_grpc.BroadcastAPIClient { diff --git a/scripts/install_abci_apps.sh b/scripts/install_abci_apps.sh index b2c0b085b..6da2e2ed2 100644 --- a/scripts/install_abci_apps.sh +++ b/scripts/install_abci_apps.sh @@ -1,6 +1,6 @@ #! /bin/bash -go get -d github.com/tendermint/abci +go get github.com/tendermint/abci/... # get the abci commit used by tendermint COMMIT=`bash scripts/glide/parse.sh abci` From ac86e664c76fde358441ecb6c34b833e5607a5bb Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 11 Apr 2017 15:44:36 -0400 Subject: [PATCH 04/11] Revert "Undo last two commits" This reverts commit d1fc37ff9e8b8034aa3c029fc59f56768f373d73. --- benchmarks/simu/counter.go | 4 +- glide.lock | 56 +++++++++++++-------- glide.yaml | 2 + rpc/client/httpclient.go | 32 ++++++------ rpc/test/client_test.go | 95 ++++++++++++++++-------------------- rpc/test/helpers.go | 8 +-- scripts/install_abci_apps.sh | 2 +- 7 files changed, 104 insertions(+), 95 deletions(-) diff --git a/benchmarks/simu/counter.go b/benchmarks/simu/counter.go index ca155bbd8..36d1e35df 100644 --- a/benchmarks/simu/counter.go +++ b/benchmarks/simu/counter.go @@ -37,7 +37,9 @@ func main() { for i := 0; ; i++ { binary.BigEndian.PutUint64(buf, uint64(i)) //txBytes := hex.EncodeToString(buf[:n]) - request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx", Arr(buf[:8])) + request := rpctypes.NewRPCRequest("fakeid", + "broadcast_tx", + map[string]interface{}{"tx": buf[:8]}) reqBytes := wire.JSONBytes(request) //fmt.Println("!!", string(reqBytes)) fmt.Print(".") diff --git a/glide.lock b/glide.lock index e79888029..f3065569d 100644 --- a/glide.lock +++ b/glide.lock @@ -1,12 +1,12 @@ -hash: 81cd41d28f9a747a71e6a47e8bc7d855846df29f359ffdcc8d1645c451112b31 -updated: 2017-03-06T17:34:23.99160606-05:00 +hash: 3fd28c04658701e65d8f27e245d15c61056199201fd5af6d18385491fc579a70 +updated: 2017-04-10T22:34:33.346948802+02:00 imports: - name: github.com/btcsuite/btcd - version: 583684b21bfbde9b5fc4403916fd7c807feb0289 + version: 4b348c1d33373d672edd83fc576892d0e46686d2 subpackages: - btcec - name: github.com/BurntSushi/toml - version: 99064174e013895bbd9b025c31100bd1d9b590ca + version: b26d9c308763d68093482582cea63d69be07a0f0 - name: github.com/davecgh/go-spew version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: @@ -16,13 +16,14 @@ imports: - name: github.com/go-stack/stack version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/gogo/protobuf - version: 909568be09de550ed094403c2bf8a261b5bb730a + version: 100ba4e885062801d56799d78530b73b178a78f3 subpackages: - proto - name: github.com/golang/protobuf - version: 69b215d01a5606c843240eab4937eab3acee6530 + version: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef subpackages: - proto + - ptypes/any - name: github.com/golang/snappy version: 553a641470496b2327abcac10b36396bd98e45c9 - name: github.com/gorilla/websocket @@ -32,9 +33,9 @@ imports: - name: github.com/jmhodges/levigo version: c42d9e0ca023e2198120196f842701bb4c55d7b9 - name: github.com/mattn/go-colorable - version: acb9493f2794fd0f820de7a27a217dafbb1b65ea + version: ded68f7a9561c023e790de24279db7ebf473ea80 - name: github.com/mattn/go-isatty - version: 9622e0cc9d8f9be434ca605520ff9a16808fee47 + version: fc9e8d8ef48496124e79ae0df75490096eccf6fe - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/pmezard/go-difflib @@ -42,16 +43,16 @@ imports: subpackages: - difflib - name: github.com/spf13/cobra - version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c + version: 5deb57bbca49eb370538fc295ba4b2988f9f5e09 - name: github.com/spf13/pflag - version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7 + version: 9a906f17374922ed0f74e1b2f593d3723f2ffb00 - name: github.com/stretchr/testify version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: - assert - require - name: github.com/syndtr/goleveldb - version: 3c5717caf1475fd25964109a0fc640bd150fce43 + version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 subpackages: - leveldb - leveldb/cache @@ -66,7 +67,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: 1236e8fb6eee3a63909f4014a8e84385ead7933d + version: 31eafe8f8eba6b8817edd74df399f508540da528 subpackages: - client - example/counter @@ -83,15 +84,15 @@ imports: - name: github.com/tendermint/go-clist version: 3baa390bbaf7634251c42ad69a8682e7e3990552 - name: github.com/tendermint/go-common - version: dcb015dff6c7af21e65c8e2f3b450df19d38c777 + version: 6af2364fa91ef2f3afc8ba0db33b66d9d3ae006c subpackages: - test - name: github.com/tendermint/go-config version: 620dcbbd7d587cf3599dedbf329b64311b0c307a - name: github.com/tendermint/go-crypto - version: 3f47cfac5fcd9e0f1727c7db980b3559913b3e3a + version: 750b25c47a5782f5f2b773ed9e706cb82b3ccef4 - name: github.com/tendermint/go-data - version: 32271140e8fd5abdbb22e268d7a02421fa382f0b + version: e7fcc6d081ec8518912fcdc103188275f83a3ee5 - name: github.com/tendermint/go-db version: eac3f2bc147023957c8bf69432a4e6c4dc5c3f72 - name: github.com/tendermint/go-events @@ -105,11 +106,11 @@ imports: - name: github.com/tendermint/go-merkle version: 714d4d04557fd068a7c2a1748241ce8428015a96 - name: github.com/tendermint/go-p2p - version: 97a5ed2d1a17eaee8717b8a32cfaf7a9a82a273d + version: ebd3929c0db9e42268cd677a7782451be7d23327 subpackages: - upnp - name: github.com/tendermint/go-rpc - version: fcea0cda21f64889be00a0f4b6d13266b1a76ee7 + version: a416c37ebd389dcc320d8f41bdcdc575bdc0a826 subpackages: - client - server @@ -127,7 +128,7 @@ imports: - client - testutil - name: golang.org/x/crypto - version: 40541ccb1c6e64c947ed6f606b8a6cb4b67d7436 + version: 9ef620b9ca2f82b55030ffd4f41327fa9e77a92c subpackages: - curve25519 - nacl/box @@ -138,7 +139,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: d379faa25cbdc04d653984913a2ceb43b0bc46d7 + version: d1e1b351919c6738fdeb9893d5c998b161464f0c subpackages: - context - http2 @@ -148,20 +149,33 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: e48874b42435b4347fc52bdee0424a52abc974d7 + version: f3918c30c5c2cb527c0b071a27c35120a6c0719a subpackages: - unix +- name: golang.org/x/text + version: f4b4367115ec2de254587813edaa901bc1c723a8 + subpackages: + - secure/bidirule + - transform + - unicode/bidi + - unicode/norm +- name: google.golang.org/genproto + version: 411e09b969b1170a9f0c467558eb4c4c110d9c77 + subpackages: + - googleapis/rpc/status - name: google.golang.org/grpc - version: 7b399ed358736bc5522021cdc7d79a8ee9ac6f98 + version: b47cbd158b4721c318abbb389929ef005c322118 subpackages: - codes - credentials - grpclog - internal + - keepalive - metadata - naming - peer - stats + - status - tap - transport testImports: [] diff --git a/glide.yaml b/glide.yaml index 53d308233..cdb083e69 100644 --- a/glide.yaml +++ b/glide.yaml @@ -10,6 +10,8 @@ import: version: develop - package: github.com/tendermint/go-crypto version: develop +- package: github.com/tendermint/go-data + version: develop - package: github.com/tendermint/go-db version: develop - package: github.com/tendermint/go-events diff --git a/rpc/client/httpclient.go b/rpc/client/httpclient.go index bb4e6d3a8..07059bca0 100644 --- a/rpc/client/httpclient.go +++ b/rpc/client/httpclient.go @@ -22,7 +22,7 @@ out the server for test code (mock). */ type HTTP struct { remote string - rpc *rpcclient.ClientJSONRPC + rpc *rpcclient.JSONRPCClient *WSEvents } @@ -30,7 +30,7 @@ type HTTP struct { // and the websocket path (which always seems to be "/websocket") func NewHTTP(remote, wsEndpoint string) *HTTP { return &HTTP{ - rpc: rpcclient.NewClientJSONRPC(remote), + rpc: rpcclient.NewJSONRPCClient(remote), remote: remote, WSEvents: newWSEvents(remote, wsEndpoint), } @@ -50,7 +50,7 @@ func (c *HTTP) _assertIsEventSwitch() types.EventSwitch { func (c *HTTP) Status() (*ctypes.ResultStatus, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("status", []interface{}{}, tmResult) + _, err := c.rpc.Call("status", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "Status") } @@ -60,7 +60,7 @@ func (c *HTTP) Status() (*ctypes.ResultStatus, error) { func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("abci_info", []interface{}{}, tmResult) + _, err := c.rpc.Call("abci_info", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "ABCIInfo") } @@ -69,7 +69,9 @@ func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) { func (c *HTTP) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("abci_query", []interface{}{path, data, prove}, tmResult) + _, err := c.rpc.Call("abci_query", + map[string]interface{}{"path": path, "data": data, "prove": prove}, + tmResult) if err != nil { return nil, errors.Wrap(err, "ABCIQuery") } @@ -78,7 +80,7 @@ func (c *HTTP) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultAB func (c *HTTP) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("broadcast_tx_commit", []interface{}{tx}, tmResult) + _, err := c.rpc.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) if err != nil { return nil, errors.Wrap(err, "broadcast_tx_commit") } @@ -95,7 +97,7 @@ func (c *HTTP) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { func (c *HTTP) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call(route, []interface{}{tx}, tmResult) + _, err := c.rpc.Call(route, map[string]interface{}{"tx": tx}, tmResult) if err != nil { return nil, errors.Wrap(err, route) } @@ -104,7 +106,7 @@ func (c *HTTP) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTx func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("net_info", nil, tmResult) + _, err := c.rpc.Call("net_info", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "NetInfo") } @@ -113,7 +115,7 @@ func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) { func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("dump_consensus_state", nil, tmResult) + _, err := c.rpc.Call("dump_consensus_state", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "DumpConsensusState") } @@ -122,7 +124,9 @@ func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) { func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("blockchain", []interface{}{minHeight, maxHeight}, tmResult) + _, err := c.rpc.Call("blockchain", + map[string]interface{}{"minHeight": minHeight, "maxHeight": maxHeight}, + tmResult) if err != nil { return nil, errors.Wrap(err, "BlockchainInfo") } @@ -131,7 +135,7 @@ func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchai func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("genesis", nil, tmResult) + _, err := c.rpc.Call("genesis", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "Genesis") } @@ -140,7 +144,7 @@ func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error) { func (c *HTTP) Block(height int) (*ctypes.ResultBlock, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("block", []interface{}{height}, tmResult) + _, err := c.rpc.Call("block", map[string]interface{}{"height": height}, tmResult) if err != nil { return nil, errors.Wrap(err, "Block") } @@ -149,7 +153,7 @@ func (c *HTTP) Block(height int) (*ctypes.ResultBlock, error) { func (c *HTTP) Commit(height int) (*ctypes.ResultCommit, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("commit", []interface{}{height}, tmResult) + _, err := c.rpc.Call("commit", map[string]interface{}{"height": height}, tmResult) if err != nil { return nil, errors.Wrap(err, "Commit") } @@ -158,7 +162,7 @@ func (c *HTTP) Commit(height int) (*ctypes.ResultCommit, error) { func (c *HTTP) Validators() (*ctypes.ResultValidators, error) { tmResult := new(ctypes.TMResult) - _, err := c.rpc.Call("validators", nil, tmResult) + _, err := c.rpc.Call("validators", map[string]interface{}{}, tmResult) if err != nil { return nil, errors.Wrap(err, "Validators") } diff --git a/rpc/test/client_test.go b/rpc/test/client_test.go index 1141de4ee..43409c723 100644 --- a/rpc/test/client_test.go +++ b/rpc/test/client_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/abci/types" . "github.com/tendermint/go-common" + rpc "github.com/tendermint/go-rpc/client" ctypes "github.com/tendermint/tendermint/rpc/core/types" "github.com/tendermint/tendermint/types" ) @@ -25,24 +26,20 @@ import ( // status func TestURIStatus(t *testing.T) { - tmResult := new(ctypes.TMResult) - _, err := GetURIClient().Call("status", map[string]interface{}{}, tmResult) - require.Nil(t, err) - testStatus(t, tmResult) + testStatus(t, GetURIClient()) } func TestJSONStatus(t *testing.T) { - tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("status", []interface{}{}, tmResult) - require.Nil(t, err) - testStatus(t, tmResult) + testStatus(t, GetJSONClient()) } -func testStatus(t *testing.T, statusI interface{}) { +func testStatus(t *testing.T, client rpc.HTTPClient) { chainID := GetConfig().GetString("chain_id") + tmResult := new(ctypes.TMResult) + _, err := client.Call("status", map[string]interface{}{}, tmResult) + require.Nil(t, err) - tmRes := statusI.(*ctypes.TMResult) - status := (*tmRes).(*ctypes.ResultStatus) + status := (*tmResult).(*ctypes.ResultStatus) assert.Equal(t, chainID, status.NodeInfo.Network) } @@ -59,28 +56,22 @@ func randBytes(t *testing.T) []byte { } func TestURIBroadcastTxSync(t *testing.T) { - config.Set("block_size", 0) - defer config.Set("block_size", -1) - tmResult := new(ctypes.TMResult) - tx := randBytes(t) - _, err := GetURIClient().Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult) - require.Nil(t, err) - testBroadcastTxSync(t, tmResult, tx) + testBroadcastTxSync(t, GetURIClient()) } func TestJSONBroadcastTxSync(t *testing.T) { + testBroadcastTxSync(t, GetJSONClient()) +} + +func testBroadcastTxSync(t *testing.T, client rpc.HTTPClient) { config.Set("block_size", 0) defer config.Set("block_size", -1) tmResult := new(ctypes.TMResult) tx := randBytes(t) - _, err := GetJSONClient().Call("broadcast_tx_sync", []interface{}{tx}, tmResult) + _, err := client.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult) require.Nil(t, err) - testBroadcastTxSync(t, tmResult, tx) -} -func testBroadcastTxSync(t *testing.T, resI interface{}, tx []byte) { - tmRes := resI.(*ctypes.TMResult) - res := (*tmRes).(*ctypes.ResultBroadcastTx) + res := (*tmResult).(*ctypes.ResultBroadcastTx) require.Equal(t, abci.CodeType_OK, res.Code) mem := node.MempoolReactor().Mempool require.Equal(t, 1, mem.Size()) @@ -98,34 +89,31 @@ func testTxKV(t *testing.T) ([]byte, []byte, []byte) { return k, v, []byte(Fmt("%s=%s", k, v)) } -func sendTx(t *testing.T) ([]byte, []byte) { +func sendTx(t *testing.T, client rpc.HTTPClient) ([]byte, []byte) { tmResult := new(ctypes.TMResult) k, v, tx := testTxKV(t) - _, err := GetJSONClient().Call("broadcast_tx_commit", []interface{}{tx}, tmResult) + _, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) require.Nil(t, err) return k, v } func TestURIABCIQuery(t *testing.T) { - k, v := sendTx(t) - time.Sleep(time.Second) - tmResult := new(ctypes.TMResult) - _, err := GetURIClient().Call("abci_query", map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult) - require.Nil(t, err) - testABCIQuery(t, tmResult, v) + testABCIQuery(t, GetURIClient()) } func TestJSONABCIQuery(t *testing.T) { - k, v := sendTx(t) + testABCIQuery(t, GetURIClient()) +} + +func testABCIQuery(t *testing.T, client rpc.HTTPClient) { + k, _ := sendTx(t, client) + time.Sleep(time.Millisecond * 100) tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("abci_query", []interface{}{"", k, false}, tmResult) + _, err := client.Call("abci_query", + map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult) require.Nil(t, err) - testABCIQuery(t, tmResult, v) -} -func testABCIQuery(t *testing.T, statusI interface{}, value []byte) { - tmRes := statusI.(*ctypes.TMResult) - resQuery := (*tmRes).(*ctypes.ResultABCIQuery) + resQuery := (*tmResult).(*ctypes.ResultABCIQuery) require.EqualValues(t, 0, resQuery.Response.Code) // XXX: specific to value returned by the dummy @@ -136,25 +124,22 @@ func testABCIQuery(t *testing.T, statusI interface{}, value []byte) { // broadcast tx commit func TestURIBroadcastTxCommit(t *testing.T) { - tmResult := new(ctypes.TMResult) - tx := randBytes(t) - _, err := GetURIClient().Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) - require.Nil(t, err) - testBroadcastTxCommit(t, tmResult, tx) + testBroadcastTxCommit(t, GetURIClient()) } func TestJSONBroadcastTxCommit(t *testing.T) { - tmResult := new(ctypes.TMResult) - tx := randBytes(t) - _, err := GetJSONClient().Call("broadcast_tx_commit", []interface{}{tx}, tmResult) - require.Nil(t, err) - testBroadcastTxCommit(t, tmResult, tx) + testBroadcastTxCommit(t, GetJSONClient()) } -func testBroadcastTxCommit(t *testing.T, resI interface{}, tx []byte) { +func testBroadcastTxCommit(t *testing.T, client rpc.HTTPClient) { require := require.New(t) - tmRes := resI.(*ctypes.TMResult) - res := (*tmRes).(*ctypes.ResultBroadcastTxCommit) + + tmResult := new(ctypes.TMResult) + tx := randBytes(t) + _, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) + require.Nil(err) + + res := (*tmResult).(*ctypes.ResultBroadcastTxCommit) checkTx := res.CheckTx require.Equal(abci.CodeType_OK, checkTx.Code) deliverTx := res.DeliverTx @@ -240,7 +225,7 @@ func TestWSTxEvent(t *testing.T) { // send an tx tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("broadcast_tx_sync", []interface{}{tx}, tmResult) + _, err := GetJSONClient().Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult) require.Nil(err) waitForEvent(t, wsc, eid, true, func() {}, func(eid string, b interface{}) error { @@ -310,7 +295,9 @@ func TestURIUnsafeSetConfig(t *testing.T) { func TestJSONUnsafeSetConfig(t *testing.T) { for _, testCase := range testCasesUnsafeSetConfig { tmResult := new(ctypes.TMResult) - _, err := GetJSONClient().Call("unsafe_set_config", []interface{}{testCase[0], testCase[1], testCase[2]}, tmResult) + _, err := GetJSONClient().Call("unsafe_set_config", + map[string]interface{}{"type": testCase[0], "key": testCase[1], "value": testCase[2]}, + tmResult) require.Nil(t, err) } testUnsafeSetConfig(t) diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index cf64ac155..349980e9c 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -72,15 +72,15 @@ func GetConfig() cfg.Config { } // GetURIClient gets a uri client pointing to the test tendermint rpc -func GetURIClient() *client.ClientURI { +func GetURIClient() *client.URIClient { rpcAddr := GetConfig().GetString("rpc_laddr") - return client.NewClientURI(rpcAddr) + return client.NewURIClient(rpcAddr) } // GetJSONClient gets a http/json client pointing to the test tendermint rpc -func GetJSONClient() *client.ClientJSONRPC { +func GetJSONClient() *client.JSONRPCClient { rpcAddr := GetConfig().GetString("rpc_laddr") - return client.NewClientJSONRPC(rpcAddr) + return client.NewJSONRPCClient(rpcAddr) } func GetGRPCClient() core_grpc.BroadcastAPIClient { diff --git a/scripts/install_abci_apps.sh b/scripts/install_abci_apps.sh index 6da2e2ed2..b2c0b085b 100644 --- a/scripts/install_abci_apps.sh +++ b/scripts/install_abci_apps.sh @@ -1,6 +1,6 @@ #! /bin/bash -go get github.com/tendermint/abci/... +go get -d github.com/tendermint/abci # get the abci commit used by tendermint COMMIT=`bash scripts/glide/parse.sh abci` From c0f026a9b3b9932f0a0e7133f17a7f1ef24baf50 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 11 Apr 2017 13:42:45 +0200 Subject: [PATCH 05/11] update go-rpc to fix race condition --- glide.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glide.lock b/glide.lock index f3065569d..321122e6f 100644 --- a/glide.lock +++ b/glide.lock @@ -110,7 +110,7 @@ imports: subpackages: - upnp - name: github.com/tendermint/go-rpc - version: a416c37ebd389dcc320d8f41bdcdc575bdc0a826 + version: 9d18cbe74e66f875afa36d2fa3be280e4a2dc9e6 subpackages: - client - server From 9775ecde996c0e7468b485d895a4f22ac373cfa1 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 11 Apr 2017 15:25:28 -0400 Subject: [PATCH 06/11] update glide --- glide.lock | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/glide.lock b/glide.lock index 321122e6f..9b11967a2 100644 --- a/glide.lock +++ b/glide.lock @@ -1,12 +1,14 @@ -hash: 3fd28c04658701e65d8f27e245d15c61056199201fd5af6d18385491fc579a70 -updated: 2017-04-10T22:34:33.346948802+02:00 +hash: d9724aa287c40d1b3856b6565f09235d809c8b2f7c6537c04f597137c0d6cd26 +updated: 2017-04-11T15:24:16.619608243-04:00 imports: - name: github.com/btcsuite/btcd - version: 4b348c1d33373d672edd83fc576892d0e46686d2 + version: b8df516b4b267acf2de46be593a9d948d1d2c420 subpackages: - btcec +- name: github.com/btcsuite/fastsha256 + version: 637e656429416087660c84436a2a035d69d54e2e - name: github.com/BurntSushi/toml - version: b26d9c308763d68093482582cea63d69be07a0f0 + version: 99064174e013895bbd9b025c31100bd1d9b590ca - name: github.com/davecgh/go-spew version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: @@ -20,10 +22,9 @@ imports: subpackages: - proto - name: github.com/golang/protobuf - version: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef + version: 69b215d01a5606c843240eab4937eab3acee6530 subpackages: - proto - - ptypes/any - name: github.com/golang/snappy version: 553a641470496b2327abcac10b36396bd98e45c9 - name: github.com/gorilla/websocket @@ -33,9 +34,9 @@ imports: - name: github.com/jmhodges/levigo version: c42d9e0ca023e2198120196f842701bb4c55d7b9 - name: github.com/mattn/go-colorable - version: ded68f7a9561c023e790de24279db7ebf473ea80 + version: 9fdad7c47650b7d2e1da50644c1f4ba7f172f252 - name: github.com/mattn/go-isatty - version: fc9e8d8ef48496124e79ae0df75490096eccf6fe + version: 56b76bdf51f7708750eac80fa38b952bb9f32639 - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d - name: github.com/pmezard/go-difflib @@ -43,16 +44,16 @@ imports: subpackages: - difflib - name: github.com/spf13/cobra - version: 5deb57bbca49eb370538fc295ba4b2988f9f5e09 + version: fcd0c5a1df88f5d6784cb4feead962c3f3d0b66c - name: github.com/spf13/pflag - version: 9a906f17374922ed0f74e1b2f593d3723f2ffb00 + version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7 - name: github.com/stretchr/testify version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: - assert - require - name: github.com/syndtr/goleveldb - version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 + version: 3c5717caf1475fd25964109a0fc640bd150fce43 subpackages: - leveldb - leveldb/cache @@ -106,7 +107,7 @@ imports: - name: github.com/tendermint/go-merkle version: 714d4d04557fd068a7c2a1748241ce8428015a96 - name: github.com/tendermint/go-p2p - version: ebd3929c0db9e42268cd677a7782451be7d23327 + version: c39e001a957caf768f06c85c840debb8282c3aaa subpackages: - upnp - name: github.com/tendermint/go-rpc @@ -116,7 +117,7 @@ imports: - server - types - name: github.com/tendermint/go-wire - version: f530b7af7a8b06e612c2063bff6ace49060a085e + version: ad797c70affa2c81fccc5edaed63ac25144397c6 - name: github.com/tendermint/log15 version: ae0f3d6450da9eac7074b439c8e1c3cabf0d5ce6 subpackages: @@ -128,7 +129,7 @@ imports: - client - testutil - name: golang.org/x/crypto - version: 9ef620b9ca2f82b55030ffd4f41327fa9e77a92c + version: 1f22c0103821b9390939b6776727195525381532 subpackages: - curve25519 - nacl/box @@ -139,7 +140,7 @@ imports: - ripemd160 - salsa20/salsa - name: golang.org/x/net - version: d1e1b351919c6738fdeb9893d5c998b161464f0c + version: d379faa25cbdc04d653984913a2ceb43b0bc46d7 subpackages: - context - http2 @@ -149,33 +150,20 @@ imports: - lex/httplex - trace - name: golang.org/x/sys - version: f3918c30c5c2cb527c0b071a27c35120a6c0719a + version: 50c6bc5e4292a1d4e65c6e9be5f53be28bcbe28e subpackages: - unix -- name: golang.org/x/text - version: f4b4367115ec2de254587813edaa901bc1c723a8 - subpackages: - - secure/bidirule - - transform - - unicode/bidi - - unicode/norm -- name: google.golang.org/genproto - version: 411e09b969b1170a9f0c467558eb4c4c110d9c77 - subpackages: - - googleapis/rpc/status - name: google.golang.org/grpc - version: b47cbd158b4721c318abbb389929ef005c322118 + version: 7b399ed358736bc5522021cdc7d79a8ee9ac6f98 subpackages: - codes - credentials - grpclog - internal - - keepalive - metadata - naming - peer - stats - - status - tap - transport testImports: [] From 28307fd4c96b50519059c27b48fcf264ebbd9b15 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 3 Apr 2017 15:45:09 +0200 Subject: [PATCH 07/11] Add proof generation for one tx --- types/tx.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/types/tx.go b/types/tx.go index a67206d4e..e7c454f09 100644 --- a/types/tx.go +++ b/types/tx.go @@ -1,6 +1,9 @@ package types import ( + "bytes" + "errors" + "github.com/tendermint/go-merkle" ) @@ -30,3 +33,55 @@ func (txs Txs) Hash() []byte { return merkle.SimpleHashFromTwoHashes(left, right) } } + +// Index returns the index of this transaction in the list, or -1 if not found +func (txs Txs) Index(tx Tx) int { + return -1 +} + +// Proof returns a simple merkle proof for this node. +// +// Panics if i < 0 or i >= len(txs) +// +// TODO: optimize this! +func (txs Txs) Proof(i int) TxProof { + l := len(txs) + hashables := make([]merkle.Hashable, l) + for i := 0; i < l; i++ { + hashables[i] = txs[i] + } + root, proofs := merkle.SimpleProofsFromHashables(hashables) + + return TxProof{ + Index: i, + Total: l, + RootHash: root, + Data: txs[i], + Proof: *proofs[i], + } +} + +type TxProof struct { + Index, Total int + RootHash []byte + Data Tx + Proof merkle.SimpleProof +} + +func (tp TxProof) LeafHash() []byte { + return tp.Data.Hash() +} + +// Validate returns nil if it matches the dataHash, and is internally consistent +// otherwise, returns a sensible error +func (tp TxProof) Validate(dataHash []byte) error { + if !bytes.Equal(dataHash, tp.RootHash) { + return errors.New("Proof matches different data hash") + } + + valid := tp.Proof.Verify(tp.Index, tp.Total, tp.LeafHash(), tp.RootHash) + if !valid { + return errors.New("Proof is not internally consistent") + } + return nil +} From fd68bc7cfda1592114f574e2bd2101ae62acd255 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 3 Apr 2017 16:18:03 +0200 Subject: [PATCH 08/11] Test Tx proofs secure --- types/tx_test.go | 105 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 types/tx_test.go diff --git a/types/tx_test.go b/types/tx_test.go new file mode 100644 index 000000000..2d4abc5b0 --- /dev/null +++ b/types/tx_test.go @@ -0,0 +1,105 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/assert" + cmn "github.com/tendermint/go-common" + ctest "github.com/tendermint/go-common/test" + wire "github.com/tendermint/go-wire" +) + +func makeTxs(cnt, size int) Txs { + txs := make(Txs, cnt) + for i := 0; i < cnt; i++ { + txs[i] = cmn.RandBytes(size) + } + return txs +} + +func randInt(low, high int) int { + off := cmn.RandInt() % (high - low) + return low + off +} + +func TestValidTxProof(t *testing.T) { + assert := assert.New(t) + cases := []struct { + txs Txs + }{ + {Txs{{1, 4, 34, 87, 163, 1}}}, + {Txs{{5, 56, 165, 2}, {4, 77}}}, + {Txs{Tx("foo"), Tx("bar"), Tx("baz")}}, + {makeTxs(20, 5)}, + {makeTxs(7, 81)}, + {makeTxs(61, 15)}, + } + + for h, tc := range cases { + txs := tc.txs + root := txs.Hash() + // make sure valid proof for every tx + for i := range txs { + leaf := txs[i] + leafHash := leaf.Hash() + proof := txs.Proof(i) + assert.Equal(i, proof.Index, "%d: %d", h, i) + assert.Equal(len(txs), proof.Total, "%d: %d", h, i) + assert.Equal(root, proof.RootHash, "%d: %d", h, i) + assert.Equal(leaf, proof.Data, "%d: %d", h, i) + assert.Equal(leafHash, proof.LeafHash(), "%d: %d", h, i) + assert.Nil(proof.Validate(root), "%d: %d", h, i) + assert.NotNil(proof.Validate([]byte("foobar")), "%d: %d", h, i) + + // read-write must also work + var p2 TxProof + bin := wire.BinaryBytes(proof) + err := wire.ReadBinaryBytes(bin, &p2) + if assert.Nil(err, "%d: %d: %+v", h, i, err) { + assert.Nil(p2.Validate(root), "%d: %d", h, i) + } + } + } +} + +func TestTxProofUnchangable(t *testing.T) { + // run the other test a bunch... + for i := 0; i < 4; i++ { + testTxProofUnchangable(t) + } +} + +func testTxProofUnchangable(t *testing.T) { + assert := assert.New(t) + + // make some proof + txs := makeTxs(randInt(2, 100), randInt(16, 128)) + root := txs.Hash() + i := randInt(0, len(txs)-1) + proof := txs.Proof(i) + + // make sure it is valid to start with + assert.Nil(proof.Validate(root)) + bin := wire.BinaryBytes(proof) + + // try mutating the data and make sure nothing breaks + for j := 0; j < 50; j++ { + bad := ctest.MutateByteSlice(bin) + assertBadProof(t, root, bad) + } +} + +// this make sure the proof doesn't deserialize into something valid +func assertBadProof(t *testing.T, root []byte, bad []byte) { + // we kind of expect this to panic sometimes... (bad, go-wire, bad) + defer func() { + recover() + }() + + var proof TxProof + err := wire.ReadBinaryBytes(bad, &proof) + if err == nil { + err = proof.Validate(root) + assert.NotNil(t, err, "%+v", err) + } +} From 285a2a70618d62e1dfed62f458a46723140c3440 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 3 Apr 2017 16:57:34 +0200 Subject: [PATCH 09/11] More thorough testing of mutated bytes, use fixed go-wire --- glide.lock | 2 +- types/tx_test.go | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/glide.lock b/glide.lock index 9b11967a2..674b8b86d 100644 --- a/glide.lock +++ b/glide.lock @@ -117,7 +117,7 @@ imports: - server - types - name: github.com/tendermint/go-wire - version: ad797c70affa2c81fccc5edaed63ac25144397c6 + version: 09dae074245a8042aa689d084af774e6ad6a90bb - name: github.com/tendermint/log15 version: ae0f3d6450da9eac7074b439c8e1c3cabf0d5ce6 subpackages: diff --git a/types/tx_test.go b/types/tx_test.go index 2d4abc5b0..3be669638 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -1,6 +1,7 @@ package types import ( + "bytes" "testing" "github.com/stretchr/testify/assert" @@ -64,7 +65,7 @@ func TestValidTxProof(t *testing.T) { func TestTxProofUnchangable(t *testing.T) { // run the other test a bunch... - for i := 0; i < 4; i++ { + for i := 0; i < 40; i++ { testTxProofUnchangable(t) } } @@ -83,14 +84,16 @@ func testTxProofUnchangable(t *testing.T) { bin := wire.BinaryBytes(proof) // try mutating the data and make sure nothing breaks - for j := 0; j < 50; j++ { + for j := 0; j < 500; j++ { bad := ctest.MutateByteSlice(bin) - assertBadProof(t, root, bad) + if !bytes.Equal(bad, bin) { + assertBadProof(t, root, bad, proof) + } } } // this make sure the proof doesn't deserialize into something valid -func assertBadProof(t *testing.T, root []byte, bad []byte) { +func assertBadProof(t *testing.T, root []byte, bad []byte, good TxProof) { // we kind of expect this to panic sometimes... (bad, go-wire, bad) defer func() { recover() @@ -100,6 +103,11 @@ func assertBadProof(t *testing.T, root []byte, bad []byte) { err := wire.ReadBinaryBytes(bad, &proof) if err == nil { err = proof.Validate(root) - assert.NotNil(t, err, "%+v", err) + if err == nil { + // okay, this can happen if we have a slightly different total + // (where the path ends up the same), if it is something else, we have + // a real problem + assert.NotEqual(t, proof.Total, good.Total, "bad: %#v\ngood: %#v", proof, good) + } } } From 705e7bd577f18b89d846595f26c681956f31fd42 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 3 Apr 2017 17:21:30 +0200 Subject: [PATCH 10/11] Implemented and tested Txs.Index, hopefully better coverage --- types/tx.go | 5 +++++ types/tx_test.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/types/tx.go b/types/tx.go index e7c454f09..bcff2633f 100644 --- a/types/tx.go +++ b/types/tx.go @@ -36,6 +36,11 @@ func (txs Txs) Hash() []byte { // Index returns the index of this transaction in the list, or -1 if not found func (txs Txs) Index(tx Tx) int { + for i := range txs { + if bytes.Equal(txs[i], tx) { + return i + } + } return -1 } diff --git a/types/tx_test.go b/types/tx_test.go index 3be669638..aa20f7443 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -23,6 +23,20 @@ func randInt(low, high int) int { return low + off } +func TestTxIndex(t *testing.T) { + assert := assert.New(t) + for i := 0; i < 20; i++ { + txs := makeTxs(15, 60) + for j := 0; j < len(txs); j++ { + tx := txs[j] + idx := txs.Index(tx) + assert.Equal(j, idx) + } + assert.Equal(-1, txs.Index(nil)) + assert.Equal(-1, txs.Index(Tx("foodnwkf"))) + } +} + func TestValidTxProof(t *testing.T) { assert := assert.New(t) cases := []struct { From a1387c7c179c15944030323b1e80112c9a46f034 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 12 Apr 2017 18:45:37 -0400 Subject: [PATCH 11/11] remove expected panic in test --- types/tx_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/types/tx_test.go b/types/tx_test.go index aa20f7443..7688a9bf1 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -108,11 +108,6 @@ func testTxProofUnchangable(t *testing.T) { // this make sure the proof doesn't deserialize into something valid func assertBadProof(t *testing.T, root []byte, bad []byte, good TxProof) { - // we kind of expect this to panic sometimes... (bad, go-wire, bad) - defer func() { - recover() - }() - var proof TxProof err := wire.ReadBinaryBytes(bad, &proof) if err == nil {