Skip to content

Commit

Permalink
must re-sort proofs cause no write after seal
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnguyen22 committed Oct 13, 2020
1 parent b1fe36c commit d6c0682
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion x/pocketcore/types/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func (cs *CacheStorage) Seal(key []byte, object CacheObject) (cacheObject CacheO
if len(bz) == 0 {
return nil, false
}
cs.Cache.Remove(hex.EncodeToString(key))
keyString := hex.EncodeToString(key)
cs.Cache.Remove(keyString)
res, err := object.Unmarshal(bz)
if err != nil {
return nil, false
Expand All @@ -89,6 +90,7 @@ func (cs *CacheStorage) Seal(key []byte, object CacheObject) (cacheObject CacheO
}
// not in cache, so search database
cs.DB.Set(key, sealedBz)
cs.Cache.Add(keyString, sealed)
return sealed, true
}

Expand Down
5 changes: 4 additions & 1 deletion x/pocketcore/types/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type evidence struct {
NumOfProofs int64 `json:"num_of_proofs"` // the total number of proofs in the evidence
Proofs []Proof `json:"proofs"` // a slice of Proof objects (Proof per relay or challenge)
EvidenceType EvidenceType `json:"evidence_type"`
Sealed bool `json:"sealed"`
}

var _ CacheObject = Evidence{} // satisfies the cache object interface
Expand All @@ -78,6 +79,7 @@ func (e Evidence) Marshal() ([]byte, error) {
NumOfProofs: e.NumOfProofs,
Proofs: e.Proofs,
EvidenceType: e.EvidenceType,
Sealed: e.Sealed,
}
return ModuleCdc.MarshalBinaryBare(ep)
}
Expand All @@ -98,7 +100,8 @@ func (e Evidence) Unmarshal(b []byte) (CacheObject, error) {
SessionHeader: ep.SessionHeader,
NumOfProofs: ep.NumOfProofs,
Proofs: ep.Proofs,
EvidenceType: ep.EvidenceType}
EvidenceType: ep.EvidenceType,
Sealed: ep.Sealed}
return evidence, nil
}

Expand Down
2 changes: 1 addition & 1 deletion x/pocketcore/types/merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func nextPowerOfTwo(v uint) uint {

// "GenerateProofs" - Generates the merkle Proof object from the leaf node data and the index
func GenerateProofs(p []Proof, index int) (mProof MerkleProof, leaf Proof) {
data, proofs := structureProofs(p) // proofs are already sorted
data, proofs := sortAndStructure(p) // proofs are already sorted
// make a copy of the data because the merkle proof function will manipulate the slice
dataCopy := make([]HashRange, len(data))
// Copy from the original map to the target map
Expand Down

0 comments on commit d6c0682

Please sign in to comment.