Browse Source

make lightd availbe (#3364)

1."abci_query": rpcserver.NewRPCFunc(c.ABCIQuery, "path,data,prove")
"validators": rpcserver.NewRPCFunc(c.Validators, "height"),
the parameters and function do not match, cause index out of range error.
2. the prove of query is forced to be true, while default option is false.
3. fix the wrong key of merkle
pull/3374/head
zjubfd 6 years ago
committed by Ethan Buchman
parent
commit
3421e4dcd7
4 changed files with 37 additions and 11 deletions
  1. +3
    -3
      cmd/tendermint/commands/lite.go
  2. +2
    -2
      lite/proxy/proxy.go
  3. +28
    -6
      lite/proxy/query.go
  4. +4
    -0
      lite/proxy/wrapper.go

+ 3
- 3
cmd/tendermint/commands/lite.go View File

@ -43,7 +43,7 @@ func init() {
LiteCmd.Flags().IntVar(&cacheSize, "cache-size", 10, "Specify the memory trust store cache size") LiteCmd.Flags().IntVar(&cacheSize, "cache-size", 10, "Specify the memory trust store cache size")
} }
func ensureAddrHasSchemeOrDefaultToTCP(addr string) (string, error) {
func EnsureAddrHasSchemeOrDefaultToTCP(addr string) (string, error) {
u, err := url.Parse(addr) u, err := url.Parse(addr)
if err != nil { if err != nil {
return "", err return "", err
@ -64,11 +64,11 @@ func runProxy(cmd *cobra.Command, args []string) error {
// TODO: close up shop // TODO: close up shop
}) })
nodeAddr, err := ensureAddrHasSchemeOrDefaultToTCP(nodeAddr)
nodeAddr, err := EnsureAddrHasSchemeOrDefaultToTCP(nodeAddr)
if err != nil { if err != nil {
return err return err
} }
listenAddr, err := ensureAddrHasSchemeOrDefaultToTCP(listenAddr)
listenAddr, err := EnsureAddrHasSchemeOrDefaultToTCP(listenAddr)
if err != nil { if err != nil {
return err return err
} }


+ 2
- 2
lite/proxy/proxy.go View File

@ -66,7 +66,7 @@ func RPCRoutes(c rpcclient.Client) map[string]*rpcserver.RPCFunc {
"block": rpcserver.NewRPCFunc(c.Block, "height"), "block": rpcserver.NewRPCFunc(c.Block, "height"),
"commit": rpcserver.NewRPCFunc(c.Commit, "height"), "commit": rpcserver.NewRPCFunc(c.Commit, "height"),
"tx": rpcserver.NewRPCFunc(c.Tx, "hash,prove"), "tx": rpcserver.NewRPCFunc(c.Tx, "hash,prove"),
"validators": rpcserver.NewRPCFunc(c.Validators, ""),
"validators": rpcserver.NewRPCFunc(c.Validators, "height"),
// broadcast API // broadcast API
"broadcast_tx_commit": rpcserver.NewRPCFunc(c.BroadcastTxCommit, "tx"), "broadcast_tx_commit": rpcserver.NewRPCFunc(c.BroadcastTxCommit, "tx"),
@ -74,7 +74,7 @@ func RPCRoutes(c rpcclient.Client) map[string]*rpcserver.RPCFunc {
"broadcast_tx_async": rpcserver.NewRPCFunc(c.BroadcastTxAsync, "tx"), "broadcast_tx_async": rpcserver.NewRPCFunc(c.BroadcastTxAsync, "tx"),
// abci API // abci API
"abci_query": rpcserver.NewRPCFunc(c.ABCIQuery, "path,data,prove"),
"abci_query": rpcserver.NewRPCFunc(c.ABCIQuery, "path,data"),
"abci_info": rpcserver.NewRPCFunc(c.ABCIInfo, ""), "abci_info": rpcserver.NewRPCFunc(c.ABCIInfo, ""),
} }
} }

+ 28
- 6
lite/proxy/query.go View File

@ -2,6 +2,7 @@ package proxy
import ( import (
"fmt" "fmt"
"strings"
cmn "github.com/tendermint/tendermint/libs/common" cmn "github.com/tendermint/tendermint/libs/common"
@ -43,11 +44,7 @@ func GetWithProof(prt *merkle.ProofRuntime, key []byte, reqHeight int64, node rp
func GetWithProofOptions(prt *merkle.ProofRuntime, path string, key []byte, opts rpcclient.ABCIQueryOptions, func GetWithProofOptions(prt *merkle.ProofRuntime, path string, key []byte, opts rpcclient.ABCIQueryOptions,
node rpcclient.Client, cert lite.Verifier) ( node rpcclient.Client, cert lite.Verifier) (
*ctypes.ResultABCIQuery, error) { *ctypes.ResultABCIQuery, error) {
if !opts.Prove {
return nil, cmn.NewError("require ABCIQueryOptions.Prove to be true")
}
opts.Prove = true
res, err := node.ABCIQueryWithOptions(path, key, opts) res, err := node.ABCIQueryWithOptions(path, key, opts)
if err != nil { if err != nil {
return nil, err return nil, err
@ -77,7 +74,14 @@ func GetWithProofOptions(prt *merkle.ProofRuntime, path string, key []byte, opts
if resp.Value != nil { if resp.Value != nil {
// Value exists // Value exists
// XXX How do we encode the key into a string... // XXX How do we encode the key into a string...
err = prt.VerifyValue(resp.Proof, signedHeader.AppHash, string(resp.Key), resp.Value)
storeName, err := parseQueryStorePath(path)
if err != nil {
return nil, err
}
kp := merkle.KeyPath{}
kp = kp.AppendKey([]byte(storeName), merkle.KeyEncodingURL)
kp = kp.AppendKey(resp.Key, merkle.KeyEncodingURL)
err = prt.VerifyValue(resp.Proof, signedHeader.AppHash, kp.String(), resp.Value)
if err != nil { if err != nil {
return nil, cmn.ErrorWrap(err, "Couldn't verify value proof") return nil, cmn.ErrorWrap(err, "Couldn't verify value proof")
} }
@ -94,6 +98,24 @@ func GetWithProofOptions(prt *merkle.ProofRuntime, path string, key []byte, opts
} }
} }
func parseQueryStorePath(path string) (storeName string, err error) {
if !strings.HasPrefix(path, "/") {
return "", fmt.Errorf("expected path to start with /")
}
paths := strings.SplitN(path[1:], "/", 3)
switch {
case len(paths) != 3:
return "", fmt.Errorf("expected format like /store/<storeName>/key")
case paths[0] != "store":
return "", fmt.Errorf("expected format like /store/<storeName>/key")
case paths[2] != "key":
return "", fmt.Errorf("expected format like /store/<storeName>/key")
}
return paths[1], nil
}
// GetCertifiedCommit gets the signed header for a given height and certifies // GetCertifiedCommit gets the signed header for a given height and certifies
// it. Returns error if unable to get a proven header. // it. Returns error if unable to get a proven header.
func GetCertifiedCommit(h int64, client rpcclient.Client, cert lite.Verifier) (types.SignedHeader, error) { func GetCertifiedCommit(h int64, client rpcclient.Client, cert lite.Verifier) (types.SignedHeader, error) {


+ 4
- 0
lite/proxy/wrapper.go View File

@ -145,6 +145,10 @@ func (w Wrapper) Commit(height *int64) (*ctypes.ResultCommit, error) {
return res, err return res, err
} }
func (w Wrapper) RegisterOpDecoder(typ string, dec merkle.OpDecoder) {
w.prt.RegisterOpDecoder(typ, dec)
}
// // WrappedSwitch creates a websocket connection that auto-verifies any info // // WrappedSwitch creates a websocket connection that auto-verifies any info
// // coming through before passing it along. // // coming through before passing it along.
// // // //


Loading…
Cancel
Save