Skip to content

Commit

Permalink
IRISHUB-238: change wait 3 second to wait tendermint new block. use M…
Browse files Browse the repository at this point in the history
…ustUnmarshalBinary instead of UnmarshalBinary
  • Loading branch information
HaoyangLiu committed Aug 31, 2018
1 parent cb3e729 commit 67857d7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 45 deletions.
50 changes: 25 additions & 25 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,32 @@ func NewCLIContext() CLIContext {

func createCertifier() tmlite.Certifier {
trustNode := viper.GetBool(client.FlagTrustNode)
if !trustNode {
chainID := viper.GetString(client.FlagChainID)
home := viper.GetString(cli.HomeFlag)
nodeURI := viper.GetString(client.FlagNode)

var errMsg bytes.Buffer
if chainID == "" {
errMsg.WriteString("chain-id ")
}
if home == "" {
errMsg.WriteString("home ")
}
if nodeURI == "" {
errMsg.WriteString("node ")
}
// errMsg is not empty
if errMsg.Len() != 0 {
panic(fmt.Errorf("can't create certifier for distrust mode, empty values from these options: %s", errMsg.String()))
}
certifier, err := tmliteProxy.GetCertifier(chainID, home, nodeURI)
if err != nil {
panic(err)
}
return certifier
if trustNode {
return nil
}
return nil
chainID := viper.GetString(client.FlagChainID)
home := viper.GetString(cli.HomeFlag)
nodeURI := viper.GetString(client.FlagNode)

var errMsg bytes.Buffer
if chainID == "" {
errMsg.WriteString("chain-id ")
}
if home == "" {
errMsg.WriteString("home ")
}
if nodeURI == "" {
errMsg.WriteString("node ")
}
// errMsg is not empty
if errMsg.Len() != 0 {
panic(fmt.Errorf("can't create certifier for distrust mode, empty values from these options: %s", errMsg.String()))
}
certifier, err := tmliteProxy.GetCertifier(chainID, home, nodeURI)
if err != nil {
panic(err)
}
return certifier
}

// WithCodec returns a copy of the context with an updated codec.
Expand Down
3 changes: 1 addition & 2 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/tendermint/tendermint/proxy"
tmrpc "github.com/tendermint/tendermint/rpc/lib/server"
tmtypes "github.com/tendermint/tendermint/types"
"time"
)

// makePathname creates a unique pathname for each test. It will panic if it
Expand Down Expand Up @@ -191,7 +190,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress
node, err := startTM(config, logger, genDoc, privVal, app)
require.NoError(t, err)

time.Sleep(3 * time.Second)
tests.WaitForNextHeightTM(tests.ExtractPortFromAddress(config.RPC.ListenAddress))
lcd, err := startLCD(logger, listenAddr, cdc)
require.NoError(t, err)

Expand Down
21 changes: 7 additions & 14 deletions store/multistoreproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,18 @@ type MultiStoreProof struct {
}

// buildMultiStoreProof build MultiStoreProof based on iavl proof and storeInfos
func buildMultiStoreProof(iavlProof []byte, storeName string, storeInfos []storeInfo) ([]byte, error) {
func buildMultiStoreProof(iavlProof []byte, storeName string, storeInfos []storeInfo) []byte {
var rangeProof iavl.RangeProof
err := cdc.UnmarshalBinary(iavlProof, &rangeProof)
if err != nil {
return nil, err
}
cdc.MustUnmarshalBinary(iavlProof, &rangeProof)

msp := MultiStoreProof{
StoreInfos: storeInfos,
StoreName: storeName,
RangeProof: rangeProof,
}

proof, err := cdc.MarshalBinary(msp)
if err != nil {
return nil, err
}

return proof, nil
proof := cdc.MustMarshalBinary(msp)
return proof
}

// VerifyMultiStoreCommitInfo verify multiStoreCommitInfo against appHash
Expand Down Expand Up @@ -64,20 +57,20 @@ func VerifyMultiStoreCommitInfo(storeName string, storeInfos []storeInfo, appHas
// VerifyRangeProof verify iavl RangeProof
func VerifyRangeProof(key, value []byte, substoreCommitHash []byte, rangeProof *iavl.RangeProof) error {

// Verify the proof to ensure data integrity.
// verify the proof to ensure data integrity.
err := rangeProof.Verify(substoreCommitHash)
if err != nil {
return errors.Wrap(err, "proof root hash doesn't equal to substore commit root hash")
}

if len(value) != 0 {
// Verify existence proof
// verify existence proof
err = rangeProof.VerifyItem(key, value)
if err != nil {
return errors.Wrap(err, "failed in existence verification")
}
} else {
// Verify absence proof
// verify absence proof
err = rangeProof.VerifyAbsence(key)
if err != nil {
return errors.Wrap(err, "failed in absence verification")
Expand Down
5 changes: 1 addition & 4 deletions store/rootmultistore.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@ func (rs *rootMultiStore) Query(req abci.RequestQuery) abci.ResponseQuery {
return sdk.ErrInternal(errMsg.Error()).QueryResult()
}

res.Proof, errMsg = buildMultiStoreProof(res.Proof, storeName, commitInfo.StoreInfos)
if errMsg != nil {
return sdk.ErrInternal(errMsg.Error()).QueryResult()
}
res.Proof = buildMultiStoreProof(res.Proof, storeName, commitInfo.StoreInfos)

return res
}
Expand Down
12 changes: 12 additions & 0 deletions tests/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
tmclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
"strings"
)

// Wait for the next tendermint block from the Tendermint RPC
Expand Down Expand Up @@ -185,6 +186,17 @@ func WaitForRPC(laddr string) {
}
}

// ExtractPortFromAddress extract port from listenAddress
// The listenAddress must be some strings like tcp://0.0.0.0:12345
func ExtractPortFromAddress(listenAddress string) string {
stringList := strings.Split(listenAddress, ":")
length := len(stringList)
if length != 3 {
panic(fmt.Errorf("expected listen address: tcp://0.0.0.0:12345, got %s", listenAddress))
}
return stringList[2]
}

var cdc = amino.NewCodec()

func init() {
Expand Down

0 comments on commit 67857d7

Please sign in to comment.