IRISHUB-238: change wait 3 second to wait tendermint new block. use MustUnmarshalBinary instead of UnmarshalBinary
This commit is contained in:
parent
cb3e729582
commit
67857d704b
|
@ -68,7 +68,9 @@ func NewCLIContext() CLIContext {
|
||||||
|
|
||||||
func createCertifier() tmlite.Certifier {
|
func createCertifier() tmlite.Certifier {
|
||||||
trustNode := viper.GetBool(client.FlagTrustNode)
|
trustNode := viper.GetBool(client.FlagTrustNode)
|
||||||
if !trustNode {
|
if trustNode {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
chainID := viper.GetString(client.FlagChainID)
|
chainID := viper.GetString(client.FlagChainID)
|
||||||
home := viper.GetString(cli.HomeFlag)
|
home := viper.GetString(cli.HomeFlag)
|
||||||
nodeURI := viper.GetString(client.FlagNode)
|
nodeURI := viper.GetString(client.FlagNode)
|
||||||
|
@ -93,8 +95,6 @@ func createCertifier() tmlite.Certifier {
|
||||||
}
|
}
|
||||||
return certifier
|
return certifier
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithCodec returns a copy of the context with an updated codec.
|
// WithCodec returns a copy of the context with an updated codec.
|
||||||
func (ctx CLIContext) WithCodec(cdc *wire.Codec) CLIContext {
|
func (ctx CLIContext) WithCodec(cdc *wire.Codec) CLIContext {
|
||||||
|
|
|
@ -37,7 +37,6 @@ import (
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
tmrpc "github.com/tendermint/tendermint/rpc/lib/server"
|
tmrpc "github.com/tendermint/tendermint/rpc/lib/server"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// makePathname creates a unique pathname for each test. It will panic if it
|
// 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)
|
node, err := startTM(config, logger, genDoc, privVal, app)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
time.Sleep(3 * time.Second)
|
tests.WaitForNextHeightTM(tests.ExtractPortFromAddress(config.RPC.ListenAddress))
|
||||||
lcd, err := startLCD(logger, listenAddr, cdc)
|
lcd, err := startLCD(logger, listenAddr, cdc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,9 @@ type MultiStoreProof struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildMultiStoreProof build MultiStoreProof based on iavl proof and storeInfos
|
// 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
|
var rangeProof iavl.RangeProof
|
||||||
err := cdc.UnmarshalBinary(iavlProof, &rangeProof)
|
cdc.MustUnmarshalBinary(iavlProof, &rangeProof)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
msp := MultiStoreProof{
|
msp := MultiStoreProof{
|
||||||
StoreInfos: storeInfos,
|
StoreInfos: storeInfos,
|
||||||
|
@ -28,12 +25,8 @@ func buildMultiStoreProof(iavlProof []byte, storeName string, storeInfos []store
|
||||||
RangeProof: rangeProof,
|
RangeProof: rangeProof,
|
||||||
}
|
}
|
||||||
|
|
||||||
proof, err := cdc.MarshalBinary(msp)
|
proof := cdc.MustMarshalBinary(msp)
|
||||||
if err != nil {
|
return proof
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return proof, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifyMultiStoreCommitInfo verify multiStoreCommitInfo against appHash
|
// VerifyMultiStoreCommitInfo verify multiStoreCommitInfo against appHash
|
||||||
|
@ -64,20 +57,20 @@ func VerifyMultiStoreCommitInfo(storeName string, storeInfos []storeInfo, appHas
|
||||||
// VerifyRangeProof verify iavl RangeProof
|
// VerifyRangeProof verify iavl RangeProof
|
||||||
func VerifyRangeProof(key, value []byte, substoreCommitHash []byte, rangeProof *iavl.RangeProof) error {
|
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)
|
err := rangeProof.Verify(substoreCommitHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "proof root hash doesn't equal to substore commit root hash")
|
return errors.Wrap(err, "proof root hash doesn't equal to substore commit root hash")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(value) != 0 {
|
if len(value) != 0 {
|
||||||
// Verify existence proof
|
// verify existence proof
|
||||||
err = rangeProof.VerifyItem(key, value)
|
err = rangeProof.VerifyItem(key, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed in existence verification")
|
return errors.Wrap(err, "failed in existence verification")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Verify absence proof
|
// verify absence proof
|
||||||
err = rangeProof.VerifyAbsence(key)
|
err = rangeProof.VerifyAbsence(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed in absence verification")
|
return errors.Wrap(err, "failed in absence verification")
|
||||||
|
|
|
@ -301,10 +301,7 @@ func (rs *rootMultiStore) Query(req abci.RequestQuery) abci.ResponseQuery {
|
||||||
return sdk.ErrInternal(errMsg.Error()).QueryResult()
|
return sdk.ErrInternal(errMsg.Error()).QueryResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Proof, errMsg = buildMultiStoreProof(res.Proof, storeName, commitInfo.StoreInfos)
|
res.Proof = buildMultiStoreProof(res.Proof, storeName, commitInfo.StoreInfos)
|
||||||
if errMsg != nil {
|
|
||||||
return sdk.ErrInternal(errMsg.Error()).QueryResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
tmclient "github.com/tendermint/tendermint/rpc/client"
|
tmclient "github.com/tendermint/tendermint/rpc/client"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
|
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Wait for the next tendermint block from the Tendermint RPC
|
// 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()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
Loading…
Reference in New Issue