From 5a4484e0c7c8d822b462d62428ad90d33c521e9c Mon Sep 17 00:00:00 2001 From: HaoyangLiu Date: Mon, 22 Oct 2018 15:25:03 +0800 Subject: [PATCH] IRISHUB-524: improve the fix for this issue --- store/multistoreproof.go | 17 +++++++++++++---- store/rootmultistore.go | 7 ++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/store/multistoreproof.go b/store/multistoreproof.go index e25f1cc1f2e8..518ef23aa69c 100644 --- a/store/multistoreproof.go +++ b/store/multistoreproof.go @@ -11,13 +11,16 @@ import ( type MultiStoreProof struct { StoreInfos []storeInfo StoreName string - RangeProof iavl.RangeProof + RangeProof *iavl.RangeProof } // buildMultiStoreProof build MultiStoreProof based on iavl proof and storeInfos func buildMultiStoreProof(iavlProof []byte, storeName string, storeInfos []storeInfo) []byte { - var rangeProof iavl.RangeProof - cdc.MustUnmarshalBinary(iavlProof, &rangeProof) + var rangeProof *iavl.RangeProof + if iavlProof != nil { + rangeProof = &iavl.RangeProof{} + cdc.MustUnmarshalBinary(iavlProof, rangeProof) + } msp := MultiStoreProof{ StoreInfos: storeInfos, @@ -32,14 +35,16 @@ func buildMultiStoreProof(iavlProof []byte, storeName string, storeInfos []store // VerifyMultiStoreCommitInfo verify multiStoreCommitInfo against appHash func VerifyMultiStoreCommitInfo(storeName string, storeInfos []storeInfo, appHash []byte) ([]byte, error) { var substoreCommitHash []byte + found := false var height int64 for _, storeInfo := range storeInfos { if storeInfo.Name == storeName { + found = true substoreCommitHash = storeInfo.Core.CommitID.Hash height = storeInfo.Core.CommitID.Version } } - if len(substoreCommitHash) == 0 { + if !found { return nil, cmn.NewError("failed to get substore root commit hash by store name") } @@ -56,6 +61,10 @@ func VerifyMultiStoreCommitInfo(storeName string, storeInfos []storeInfo, appHas // VerifyRangeProof verify iavl RangeProof func VerifyRangeProof(key, value []byte, substoreCommitHash []byte, rangeProof *iavl.RangeProof) error { + // Both rangeProof and substoreCommitHash are nil + if substoreCommitHash == nil && rangeProof == nil { + return nil + } // verify the proof to ensure data integrity. err := rangeProof.Verify(substoreCommitHash) diff --git a/store/rootmultistore.go b/store/rootmultistore.go index 783a5da47bcc..744f800b7e42 100644 --- a/store/rootmultistore.go +++ b/store/rootmultistore.go @@ -301,12 +301,9 @@ func (rs *rootMultiStore) Query(req abci.RequestQuery) abci.ResponseQuery { return res } - if len(res.Proof) == 0 { - if len(res.Value) == 0 { - return res - } + if len(res.Proof) == 0 && len(res.Value) != 0 { msg := fmt.Sprintf("proof from store %s is nil", storeName) - return sdk.ErrUnknownRequest(msg).QueryResult() + return sdk.ErrInternal(msg).QueryResult() } commitInfo, errMsg := getCommitInfo(rs.db, res.Height)