IRISHUB-238: change wait 3 second to wait tendermint new block. use MustUnmarshalBinary instead of UnmarshalBinary

This commit is contained in:
HaoyangLiu 2018-08-31 23:20:06 +08:00
parent cb3e729582
commit 67857d704b
5 changed files with 46 additions and 45 deletions

View File

@ -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.

View File

@ -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
@ -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)

View File

@ -15,12 +15,9 @@ 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,
@ -28,12 +25,8 @@ func buildMultiStoreProof(iavlProof []byte, storeName string, storeInfos []store
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
@ -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")

View File

@ -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
}

View File

@ -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
@ -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() {