Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IRISHUB-538 and improve fix for IRISHUB-524 #114

Merged
merged 2 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion x/stake/keeper/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
RedelegationByValDstIndexKey = []byte{0x0F} // prefix for each key for an redelegation, by destination validator owner
)

const maxDigitsForAccount = 12 // ~220,000,000 atoms created at launch
const maxDigitsForAccount = 30 // ~220,000,000 atoms created at launch

// gets the key for the validator with address
// VALUE: stake/types.Validator
Expand Down