Browse Source

Support new Query message for proofs

pull/386/head
Jae Kwon 8 years ago
parent
commit
1af930441c
8 changed files with 60 additions and 57 deletions
  1. +4
    -3
      consensus/mempool_test.go
  2. +5
    -5
      glide.lock
  3. +19
    -11
      node/node.go
  4. +4
    -4
      proxy/app_conn.go
  5. +13
    -10
      rpc/core/abci.go
  6. +3
    -3
      rpc/core/routes.go
  7. +4
    -7
      rpc/core/types/responses.go
  8. +8
    -14
      rpc/test/client_test.go

+ 4
- 3
consensus/mempool_test.go View File

@ -5,9 +5,9 @@ import (
"testing" "testing"
"time" "time"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/tendermint/config/tendermint_test" "github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
abci "github.com/tendermint/abci/types"
. "github.com/tendermint/go-common" . "github.com/tendermint/go-common"
) )
@ -161,6 +161,7 @@ func (app *CounterApplication) Commit() abci.Result {
} }
} }
func (app *CounterApplication) Query(query []byte) abci.Result {
return abci.NewResultOK(nil, Fmt("Query is not supported"))
func (app *CounterApplication) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQuery) {
resQuery.Log = "Query is not supported"
return
} }

+ 5
- 5
glide.lock View File

@ -1,5 +1,5 @@
hash: e283934fbbd221161d53a918db9e49db8c5be2b8929592b05ffe6b72c2ef0ab1 hash: e283934fbbd221161d53a918db9e49db8c5be2b8929592b05ffe6b72c2ef0ab1
updated: 2017-01-14T20:59:48.253671736-08:00
updated: 2017-01-27T22:32:42.896956819-08:00
imports: imports:
- name: github.com/btcsuite/btcd - name: github.com/btcsuite/btcd
version: afec1bd1245a4a19e6dfe1306974b733e7cbb9b8 version: afec1bd1245a4a19e6dfe1306974b733e7cbb9b8
@ -32,7 +32,7 @@ imports:
- name: github.com/mattn/go-isatty - name: github.com/mattn/go-isatty
version: 66b8e73f3f5cda9f96b69efd03dd3d7fc4a5cdb8 version: 66b8e73f3f5cda9f96b69efd03dd3d7fc4a5cdb8
- name: github.com/spf13/pflag - name: github.com/spf13/pflag
version: 25f8b5b07aece3207895bf19f7ab517eb3b22a40
version: 5ccb023bc27df288a957c5e994cd44fd19619465
- name: github.com/syndtr/goleveldb - name: github.com/syndtr/goleveldb
version: 6ae1797c0b42b9323fc27ff7dcf568df88f2f33d version: 6ae1797c0b42b9323fc27ff7dcf568df88f2f33d
subpackages: subpackages:
@ -49,7 +49,7 @@ imports:
- leveldb/table - leveldb/table
- leveldb/util - leveldb/util
- name: github.com/tendermint/abci - name: github.com/tendermint/abci
version: 6526ab2137fadd0f4d2e25002bbfc1784b4f3c27
version: 8df0bc3a40ccad0d2be10e33c62c404e65c92502
subpackages: subpackages:
- client - client
- example/counter - example/counter
@ -67,7 +67,7 @@ imports:
- name: github.com/tendermint/go-clist - name: github.com/tendermint/go-clist
version: 3baa390bbaf7634251c42ad69a8682e7e3990552 version: 3baa390bbaf7634251c42ad69a8682e7e3990552
- name: github.com/tendermint/go-common - name: github.com/tendermint/go-common
version: 70e694ee76f09058ea38c9ba81b4aa621bd54df1
version: 339e135776142939d82bc8e699db0bf391fd938d
subpackages: subpackages:
- test - test
- name: github.com/tendermint/go-config - name: github.com/tendermint/go-config
@ -85,7 +85,7 @@ imports:
- name: github.com/tendermint/go-logger - name: github.com/tendermint/go-logger
version: cefb3a45c0bf3c493a04e9bcd9b1540528be59f2 version: cefb3a45c0bf3c493a04e9bcd9b1540528be59f2
- name: github.com/tendermint/go-merkle - name: github.com/tendermint/go-merkle
version: 2979c7eb8aa020fa1cf203654907dbb889703888
version: 653cb1f631528351ddbc359b994eb0c96f0341cd
- name: github.com/tendermint/go-p2p - name: github.com/tendermint/go-p2p
version: 67c9086b7458eb45b1970483decd01cd744c477a version: 67c9086b7458eb45b1970483decd01cd744c477a
subpackages: subpackages:


+ 19
- 11
node/node.go View File

@ -2,10 +2,12 @@ package node
import ( import (
"bytes" "bytes"
"errors"
"net" "net"
"net/http" "net/http"
"strings" "strings"
abci "github.com/tendermint/abci/types"
cmn "github.com/tendermint/go-common" cmn "github.com/tendermint/go-common"
cfg "github.com/tendermint/go-config" cfg "github.com/tendermint/go-config"
"github.com/tendermint/go-crypto" "github.com/tendermint/go-crypto"
@ -23,9 +25,9 @@ import (
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/version" "github.com/tendermint/tendermint/version"
)
import _ "net/http/pprof"
_ "net/http/pprof"
)
type Node struct { type Node struct {
cmn.BaseService cmn.BaseService
@ -120,24 +122,30 @@ func NewNode(config cfg.Config, privValidator *types.PrivValidator, clientCreato
sw.AddReactor("PEX", pexReactor) sw.AddReactor("PEX", pexReactor)
} }
// filter peers by addr or pubkey with a abci query.
// if the query return code is OK, add peer
// XXX: query format subject to change
// Filter peers by addr or pubkey with an ABCI query.
// If the query return code is OK, add peer.
// XXX: Query format subject to change
if config.GetBool("filter_peers") { if config.GetBool("filter_peers") {
// NOTE: addr is ip:port // NOTE: addr is ip:port
sw.SetAddrFilter(func(addr net.Addr) error { sw.SetAddrFilter(func(addr net.Addr) error {
res := proxyApp.Query().QuerySync([]byte(cmn.Fmt("p2p/filter/addr/%s", addr.String())))
if res.IsOK() {
resQuery, err := proxyApp.Query().QuerySync(abci.RequestQuery{Path: cmn.Fmt("/p2p/filter/addr/%s", addr.String())})
if err != nil {
return err
}
if resQuery.Code.IsOK() {
return nil return nil
} }
return res
return errors.New(resQuery.Code.String())
}) })
sw.SetPubKeyFilter(func(pubkey crypto.PubKeyEd25519) error { sw.SetPubKeyFilter(func(pubkey crypto.PubKeyEd25519) error {
res := proxyApp.Query().QuerySync([]byte(cmn.Fmt("p2p/filter/pubkey/%X", pubkey.Bytes())))
if res.IsOK() {
resQuery, err := proxyApp.Query().QuerySync(abci.RequestQuery{Path: cmn.Fmt("/p2p/filter/pubkey/%X", pubkey.Bytes())})
if err != nil {
return err
}
if resQuery.Code.IsOK() {
return nil return nil
} }
return res
return errors.New(resQuery.Code.String())
}) })
} }


+ 4
- 4
proxy/app_conn.go View File

@ -34,8 +34,8 @@ type AppConnQuery interface {
Error() error Error() error
EchoSync(string) (res types.Result) EchoSync(string) (res types.Result)
InfoSync() (types.ResponseInfo, error)
QuerySync(tx []byte) (res types.Result)
InfoSync() (resInfo types.ResponseInfo, err error)
QuerySync(reqQuery types.RequestQuery) (resQuery types.ResponseQuery, err error)
// SetOptionSync(key string, value string) (res types.Result) // SetOptionSync(key string, value string) (res types.Result)
} }
@ -139,6 +139,6 @@ func (app *appConnQuery) InfoSync() (types.ResponseInfo, error) {
return app.appConn.InfoSync() return app.appConn.InfoSync()
} }
func (app *appConnQuery) QuerySync(tx []byte) (res types.Result) {
return app.appConn.QuerySync(tx)
func (app *appConnQuery) QuerySync(reqQuery types.RequestQuery) (types.ResponseQuery, error) {
return app.appConn.QuerySync(reqQuery)
} }

+ 13
- 10
rpc/core/abci.go View File

@ -1,25 +1,28 @@
package core package core
import ( import (
abci "github.com/tendermint/abci/types"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
) )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func ABCIQuery(query []byte) (*ctypes.ResultABCIQuery, error) {
res := proxyAppQuery.QuerySync(query)
return &ctypes.ResultABCIQuery{res}, nil
func ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) {
resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
Path: path,
Data: data,
Prove: prove,
})
if err != nil {
return nil, err
}
return &ctypes.ResultABCIQuery{resQuery}, nil
} }
func ABCIInfo() (*ctypes.ResultABCIInfo, error) { func ABCIInfo() (*ctypes.ResultABCIInfo, error) {
res, err := proxyAppQuery.InfoSync()
resInfo, err := proxyAppQuery.InfoSync()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &ctypes.ResultABCIInfo{
Data: res.Data,
Version: res.Version,
LastBlockHeight: res.LastBlockHeight,
LastBlockAppHash: res.LastBlockAppHash,
}, nil
return &ctypes.ResultABCIInfo{resInfo}, nil
} }

+ 3
- 3
rpc/core/routes.go View File

@ -29,7 +29,7 @@ var Routes = map[string]*rpc.RPCFunc{
"broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"), "broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
// abci API // abci API
"abci_query": rpc.NewRPCFunc(ABCIQueryResult, "query"),
"abci_query": rpc.NewRPCFunc(ABCIQueryResult, "path,data,prove"),
"abci_info": rpc.NewRPCFunc(ABCIInfoResult, ""), "abci_info": rpc.NewRPCFunc(ABCIInfoResult, ""),
// control API // control API
@ -163,8 +163,8 @@ func BroadcastTxAsyncResult(tx []byte) (ctypes.TMResult, error) {
} }
} }
func ABCIQueryResult(query []byte) (ctypes.TMResult, error) {
if r, err := ABCIQuery(query); err != nil {
func ABCIQueryResult(path string, data []byte, prove bool) (ctypes.TMResult, error) {
if r, err := ABCIQuery(path, data, prove); err != nil {
return nil, err return nil, err
} else { } else {
return r, nil return r, nil


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

@ -1,12 +1,12 @@
package core_types package core_types
import ( import (
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-crypto" "github.com/tendermint/go-crypto"
"github.com/tendermint/go-p2p" "github.com/tendermint/go-p2p"
"github.com/tendermint/go-rpc/types" "github.com/tendermint/go-rpc/types"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
abci "github.com/tendermint/abci/types"
) )
type ResultBlockchainInfo struct { type ResultBlockchainInfo struct {
@ -64,7 +64,7 @@ type ResultBroadcastTx struct {
} }
type ResultBroadcastTxCommit struct { type ResultBroadcastTxCommit struct {
CheckTx *abci.ResponseCheckTx `json:"check_tx"`
CheckTx *abci.ResponseCheckTx `json:"check_tx"`
DeliverTx *abci.ResponseDeliverTx `json:"deliver_tx"` DeliverTx *abci.ResponseDeliverTx `json:"deliver_tx"`
} }
@ -74,14 +74,11 @@ type ResultUnconfirmedTxs struct {
} }
type ResultABCIInfo struct { type ResultABCIInfo struct {
Data string `json:"data"`
Version string `json:"version"`
LastBlockHeight uint64 `json:"last_block_height"`
LastBlockAppHash []byte `json:"last_block_app_hash"`
Response abci.ResponseInfo `json:"response"`
} }
type ResultABCIQuery struct { type ResultABCIQuery struct {
Result abci.Result `json:"result"`
Response abci.ResponseQuery `json:"response"`
} }
type ResultUnsafeFlushMempool struct{} type ResultUnsafeFlushMempool struct{}


+ 8
- 14
rpc/test/client_test.go View File

@ -8,12 +8,10 @@ import (
"testing" "testing"
"time" "time"
abci "github.com/tendermint/abci/types"
. "github.com/tendermint/go-common" . "github.com/tendermint/go-common"
"github.com/tendermint/go-wire"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/abci/example/dummy"
abci "github.com/tendermint/abci/types"
) )
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
@ -134,7 +132,7 @@ func TestURIABCIQuery(t *testing.T) {
k, v := sendTx() k, v := sendTx()
time.Sleep(time.Second) time.Sleep(time.Second)
tmResult := new(ctypes.TMResult) tmResult := new(ctypes.TMResult)
_, err := clientURI.Call("abci_query", map[string]interface{}{"query": k}, tmResult)
_, err := clientURI.Call("abci_query", map[string]interface{}{"path": "", "data": k, "prove": false}, tmResult)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -144,7 +142,7 @@ func TestURIABCIQuery(t *testing.T) {
func TestJSONABCIQuery(t *testing.T) { func TestJSONABCIQuery(t *testing.T) {
k, v := sendTx() k, v := sendTx()
tmResult := new(ctypes.TMResult) tmResult := new(ctypes.TMResult)
_, err := clientJSON.Call("abci_query", []interface{}{k}, tmResult)
_, err := clientJSON.Call("abci_query", []interface{}{"", k, false}, tmResult)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -153,18 +151,14 @@ func TestJSONABCIQuery(t *testing.T) {
func testABCIQuery(t *testing.T, statusI interface{}, value []byte) { func testABCIQuery(t *testing.T, statusI interface{}, value []byte) {
tmRes := statusI.(*ctypes.TMResult) tmRes := statusI.(*ctypes.TMResult)
query := (*tmRes).(*ctypes.ResultABCIQuery)
if query.Result.IsErr() {
panic(Fmt("Query returned an err: %v", query))
resQuery := (*tmRes).(*ctypes.ResultABCIQuery)
if !resQuery.Response.Code.IsOK() {
panic(Fmt("Query returned an err: %v", resQuery))
} }
qResult := new(dummy.QueryResult)
if err := wire.ReadJSONBytes(query.Result.Data, qResult); err != nil {
t.Fatal(err)
}
// XXX: specific to value returned by the dummy // XXX: specific to value returned by the dummy
if qResult.Exists != true {
panic(Fmt("Query error. Expected to find 'exists=true'. Got: %v", qResult))
if len(resQuery.Response.Value) == 0 {
panic(Fmt("Query error. Found no value"))
} }
} }


Loading…
Cancel
Save