Skip to content

Commit

Permalink
Merge pull request #51 from binance-chain/upgrade281
Browse files Browse the repository at this point in the history
fixes for TM upgrade
  • Loading branch information
rickyyangz authored Jan 29, 2019
2 parents 0586f7b + 98ff294 commit a535834
Show file tree
Hide file tree
Showing 71 changed files with 514 additions and 444 deletions.
64 changes: 29 additions & 35 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@

[[override]]
name = "github.com/tendermint/go-amino"
version = "=v0.12.0"
version = "=v0.14.1"

[[override]]
name = "github.com/tendermint/iavl"
version = "=v0.11.0"
version = "=v0.12.0"

[[override]]
name = "github.com/tendermint/tendermint"
source = "github.com/BiJie/bnc-tendermint"
version = "=0.25.1-br5"
version = "=v0.29.1-br0"

## deps without releases:

Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc
}

// Encode with json
value := codec.Cdc.MustMarshalBinary(result)
value := codec.Cdc.MustMarshalBinaryLengthPrefixed(result)
return abci.ResponseQuery{
Code: uint32(sdk.ABCICodeOK),
Value: value,
Expand Down
16 changes: 8 additions & 8 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func testTxDecoder(cdc *codec.Codec) sdk.TxDecoder {
if len(txBytes) == 0 {
return nil, sdk.ErrTxDecode("txBytes are empty")
}
err := cdc.UnmarshalBinary(txBytes, &tx)
err := cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx)
if err != nil {
return nil, sdk.ErrTxDecode("").TraceSDK(err.Error())
}
Expand Down Expand Up @@ -500,7 +500,7 @@ func TestCheckTx(t *testing.T) {

for i := int64(0); i < nTxs; i++ {
tx := newTxCounter(i, 0)
txBytes, err := codec.MarshalBinary(tx)
txBytes, err := codec.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)
r := app.CheckTx(txBytes)
assert.True(t, r.IsOK(), fmt.Sprintf("%v", r))
Expand Down Expand Up @@ -548,7 +548,7 @@ func TestDeliverTx(t *testing.T) {
for i := 0; i < txPerHeight; i++ {
counter := int64(blockN*txPerHeight + i)
tx := newTxCounter(counter, counter)
txBytes, err := codec.MarshalBinary(tx)
txBytes, err := codec.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)
res := app.DeliverTx(txBytes)
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))
Expand Down Expand Up @@ -589,7 +589,7 @@ func TestMultiMsgDeliverTx(t *testing.T) {
{
app.BeginBlock(abci.RequestBeginBlock{})
tx := newTxCounter(0, 0, 1, 2)
txBytes, err := codec.MarshalBinary(tx)
txBytes, err := codec.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)
res := app.DeliverTx(txBytes)
require.True(t, res.IsErr(), fmt.Sprintf("%v", res))
Expand Down Expand Up @@ -626,7 +626,7 @@ func TestPreCheckTx(t *testing.T) {

for i := int64(0); i < nTxs; i++ {
tx := newTxCounter(i, 0)
txBytes, err := codec.MarshalBinary(tx)
txBytes, err := codec.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)
r := app.PreCheckTx(txBytes)
assert.False(t, r.IsOK(), fmt.Sprintf("%v", r))
Expand All @@ -644,7 +644,7 @@ func TestPreCheckTx(t *testing.T) {
})

tx := newTxCounter(0, 0)
txBytes, _ := codec.MarshalBinary(tx)
txBytes, _ := codec.MarshalBinaryLengthPrefixed(tx)
r := app.PreCheckTx(txBytes)
assert.True(t, r.IsOK(), fmt.Sprintf("%v", r))
assert.Equal(t, 1, app.txMsgCache.Len())
Expand Down Expand Up @@ -691,7 +691,7 @@ func TestSimulateTx(t *testing.T) {
require.True(t, result.IsOK(), result.Log)

// simulate by calling Query with encoded tx
txBytes, err := cdc.MarshalBinary(tx)
txBytes, err := cdc.MarshalBinaryLengthPrefixed(tx)
require.Nil(t, err)
query := abci.RequestQuery{
Path: "/app/simulate",
Expand All @@ -701,7 +701,7 @@ func TestSimulateTx(t *testing.T) {
require.True(t, queryResult.IsOK(), queryResult.Log)

var res sdk.Result
codec.Cdc.MustUnmarshalBinary(queryResult.Value, &res)
codec.Cdc.MustUnmarshalBinaryLengthPrefixed(queryResult.Value, &res)
require.Nil(t, err, "Result unmarshalling failed")
require.True(t, res.IsOK(), res.Log)
app.EndBlock(abci.RequestEndBlock{})
Expand Down
6 changes: 5 additions & 1 deletion client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ func createVerifier() tmlite.Verifier {
os.Exit(1)
}
node := rpcclient.NewHTTP(nodeURI, "/websocket")
verifier, err := tmliteProxy.NewVerifier(chainID, filepath.Join(home, ".gaialite"), node, log.NewNopLogger())
cacheSize := 10 // TODO: determine appropriate cache size
verifier, err := tmliteProxy.NewVerifier(
chainID, filepath.Join(home, ".gaialite"),
node, log.NewNopLogger(), cacheSize,
)

if err != nil {
fmt.Printf("Create verifier failed: %s\n", err.Error())
Expand Down
52 changes: 34 additions & 18 deletions client/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (

"github.com/pkg/errors"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
cmn "github.com/tendermint/tendermint/libs/common"
tmliteErr "github.com/tendermint/tendermint/lite/errors"
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"
rpcclient "github.com/tendermint/tendermint/rpc/client"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand Down Expand Up @@ -52,7 +52,7 @@ func (ctx CLIContext) QuerySubspace(subspace []byte, storeName string) (res []sd
return res, err
}

ctx.Codec.MustUnmarshalBinary(resRaw, &res)
ctx.Codec.MustUnmarshalBinaryLengthPrefixed(resRaw, &res)
return
}

Expand Down Expand Up @@ -155,8 +155,8 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, err erro
}

opts := rpcclient.ABCIQueryOptions{
Height: ctx.Height,
Trusted: ctx.TrustNode,
Height: ctx.Height,
Prove: !ctx.TrustNode,
}

result, err := node.ABCIQueryWithOptions(path, key, opts)
Expand Down Expand Up @@ -196,7 +196,7 @@ func (ctx CLIContext) Verify(height int64) (tmtypes.SignedHeader, error) {
}

// verifyProof perform response proof verification.
func (ctx CLIContext) verifyProof(_ string, resp abci.ResponseQuery) error {
func (ctx CLIContext) verifyProof(queryPath string, resp abci.ResponseQuery) error {
if ctx.Verifier == nil {
return fmt.Errorf("missing valid certifier to verify data from distrusted node")
}
Expand All @@ -207,25 +207,22 @@ func (ctx CLIContext) verifyProof(_ string, resp abci.ResponseQuery) error {
return err
}

var multiStoreProof store.MultiStoreProof
cdc := codec.New()
// TODO: Instead of reconstructing, stash on CLIContext field?
prt := store.DefaultProofRuntime()

err = cdc.UnmarshalBinary(resp.Proof, &multiStoreProof)
// TODO: Better convention for path?
storeName, err := parseQueryStorePath(queryPath)
if err != nil {
return errors.Wrap(err, "failed to unmarshalBinary rangeProof")
return err
}

// verify the substore commit hash against trusted appHash
substoreCommitHash, err := store.VerifyMultiStoreCommitInfo(
multiStoreProof.StoreName, multiStoreProof.StoreInfos, commit.Header.AppHash,
)
if err != nil {
return errors.Wrap(err, "failed in verifying the proof against appHash")
}
kp := merkle.KeyPath{}
kp = kp.AppendKey([]byte(storeName), merkle.KeyEncodingURL)
kp = kp.AppendKey(resp.Key, merkle.KeyEncodingURL)

err = store.VerifyRangeProof(resp.Key, resp.Value, substoreCommitHash, &multiStoreProof.RangeProof)
err = prt.VerifyValue(resp.Proof, commit.Header.AppHash, kp.String(), resp.Value)
if err != nil {
return errors.Wrap(err, "failed in the range proof verification")
return errors.Wrap(err, "failed to prove merkle proof")
}

return nil
Expand Down Expand Up @@ -256,3 +253,22 @@ func isQueryStoreWithProof(path string) bool {

return false
}

// parseQueryStorePath expects a format like /store/<storeName>/key.
func parseQueryStorePath(path string) (storeName string, err error) {
if !strings.HasPrefix(path, "/") {
return "", errors.New("expected path to start with /")
}

paths := strings.SplitN(path[1:], "/", 3)
switch {
case len(paths) != 3:
return "", errors.New("expected format like /store/<storeName>/key")
case paths[0] != "store":
return "", errors.New("expected format like /store/<storeName>/key")
case paths[2] != "key":
return "", errors.New("expected format like /store/<storeName>/key")
}

return paths[1], nil
}
4 changes: 2 additions & 2 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ func TestNodeStatus(t *testing.T) {
res, body := Request(t, port, "GET", "/node_info", nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var nodeInfo p2p.NodeInfo
var nodeInfo p2p.DefaultNodeInfo
err := cdc.UnmarshalJSON([]byte(body), &nodeInfo)
require.Nil(t, err, "Couldn't parse node info")

require.NotEqual(t, p2p.NodeInfo{}, nodeInfo, "res: %v", res)
require.NotEqual(t, p2p.DefaultNodeInfo{}, nodeInfo, "res: %v", res)

// syncing
res, body = Request(t, port, "GET", "/syncing", nil)
Expand Down
Loading

0 comments on commit a535834

Please sign in to comment.