Skip to content

Commit

Permalink
IRISHUB-524: improve the fix for this issue
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoyangLiu committed Oct 22, 2018
1 parent 3ae6b63 commit 5a4484e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 13 additions & 4 deletions store/multistoreproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
}

Expand All @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions store/rootmultistore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5a4484e

Please sign in to comment.