Skip to content

Commit

Permalink
enhanced proof entropy and flush to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnguyen22 committed Jul 24, 2020
1 parent 98b4233 commit d1b8944
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
13 changes: 8 additions & 5 deletions x/pocketcore/keeper/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (k Keeper) SendClaimTx(ctx sdk.Ctx, n client.Client, claimTx func(pk crypto
return
}
// retrieve the iterator to go through each piece of evidence in storage
iter := pc.EvidenceIterator()
iter := pc.EvidenceIterator() // TODO need to delete evidence in the case that unable to send proof or claim
defer iter.Close()
// loop through each evidence
for ; iter.Valid(); iter.Next() {
Expand All @@ -43,7 +43,11 @@ func (k Keeper) SendClaimTx(ctx sdk.Ctx, n client.Client, claimTx func(pk crypto
// get the session context
sessionCtx, er := ctx.PrevCtx(evidence.SessionHeader.SessionBlockHeight)
if er != nil {
ctx.Logger().Error("could not get sessionCtx")
ctx.Logger().Error("could not get sessionCtx in auto send claim tx: " + er.Error())
continue
}
if ctx.BlockHeight() <= evidence.SessionBlockHeight+k.BlocksPerSession(sessionCtx)-1 { // ensure session is over
ctx.Logger().Info("the session is ongoing, so will not send the claimtx yet")
continue
}
// if the blockchain in the evidence is not supported then delete it because nodes don't get paid/challenged for unsupported blockchains
Expand All @@ -60,7 +64,6 @@ func (k Keeper) SendClaimTx(ctx sdk.Ctx, n client.Client, claimTx func(pk crypto
}
// if the claim is mature, delete it because we cannot submit a mature claim
if k.ClaimIsMature(ctx, evidence.SessionBlockHeight) {
fmt.Println("claim is mature @ ", ctx.BlockHeight(), evidence)
if err := pc.DeleteEvidence(evidence.SessionHeader, evidenceType); err != nil {
ctx.Logger().Debug(err.Error())
}
Expand Down Expand Up @@ -93,11 +96,11 @@ func (k Keeper) ValidateClaim(ctx sdk.Ctx, claim pc.MsgClaim) (err sdk.Error) {
return sdk.ErrInternal(er.Error())
}
// ensure that session ended
sessionEndHeight := sessionContext.BlockHeight() + k.BlocksPerSession(sessionContext) - 1
sessionEndHeight := claim.SessionBlockHeight + k.BlocksPerSession(sessionContext) - 1
if ctx.BlockHeight() <= sessionEndHeight {
return pc.NewInvalidBlockHeightError(pc.ModuleName)
}
if claim.TotalProofs <= k.MinimumNumberOfProofs(sessionContext) {
if claim.TotalProofs < k.MinimumNumberOfProofs(sessionContext) {
return pc.NewInvalidProofsError(pc.ModuleName)
}
// if is not a pocket supported blockchain then return not supported error
Expand Down
2 changes: 1 addition & 1 deletion x/pocketcore/keeper/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (k Keeper) ValidateProof(ctx sdk.Ctx, proof pc.MsgProof) (servicerAddr sdk.
return nil, pc.MsgClaim{}, pc.NewInvalidProofsError(pc.ModuleName)
}
// validate number of proofs
if minProofs := k.MinimumNumberOfProofs(sessionCtx); claim.TotalProofs <= minProofs {
if minProofs := k.MinimumNumberOfProofs(sessionCtx); claim.TotalProofs < minProofs {
return nil, pc.MsgClaim{}, pc.NewInvalidMerkleVerifyError(pc.ModuleName)
}
// validate the merkle proofs
Expand Down
1 change: 1 addition & 0 deletions x/pocketcore/types/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (cs *CacheStorage) Clear() {

// "Iterator" - Returns an iterator for all of the items in the stores
func (cs *CacheStorage) Iterator() db.Iterator {
_ = cs.FlushToDB()
return cs.DB.Iterator(nil, 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 @@ -112,7 +112,7 @@ func (mp MerkleProof) Validate(root HashRange, leaf Proof, totalRelays int64) (i
func sumFromHash(hash []byte) uint64 {
hashCopy := make([]byte, len(hash))
copy(hashCopy, hash)
return binary.LittleEndian.Uint64(append(hashCopy[:3], make([]byte, 5)...))
return binary.LittleEndian.Uint64(hash[:8])
}

// "newLevelIsValid" - Ensure that the number of levels in the relayProof is valid
Expand Down

0 comments on commit d1b8944

Please sign in to comment.