Skip to content

Commit

Permalink
Store proof gen time as milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
lpoli committed Mar 6, 2023
1 parent a4266b1 commit 896d612
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 19 additions & 5 deletions code/go/0chain.net/blobbercore/challenge/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (cr *ChallengeEntity) LoadValidationTickets(ctx context.Context) error {
}
postData["write_markers"] = markersArray

var proofGenTime common.Timestamp = -1
var proofGenTime int64 = -1

if blockNum > 0 {
if objectPath.Meta["type"] != reference.FILE {
Expand Down Expand Up @@ -219,26 +219,40 @@ func (cr *ChallengeEntity) LoadValidationTickets(ctx context.Context) error {

r := rand.New(rand.NewSource(cr.RandomNumber))
blockoffset := r.Intn(maxNumBlocks)
t1 := common.Now()
t1 := time.Now()
blockData, mt, err := filestore.GetFileStore().GetBlocksMerkleTreeForChallenge(cr.AllocationID, inputData, blockoffset)

if err != nil {
allocMu.Unlock()
cr.CancelChallenge(ctx, err)
return common.NewError("blockdata_not_found", err.Error())
}
proofGenTime = common.Now() - t1

proofGenTime = time.Since(t1).Milliseconds()

postData["data"] = []byte(blockData)
postData["merkle_path"] = mt.GetPathByIndex(blockoffset)
postData["chunk_size"] = objectPath.ChunkSize
}

UpdateChallengeTimingProofGenerationAndFileSize(
logging.Logger.Info("Proof gen logs: ",
zap.Int64("block num", blockNum),
zap.Int64("file size", objectPath.Meta["size"].(int64)),
zap.String("file path", objectPath.Meta["name"].(string)),
zap.Int64("proof gen time", proofGenTime),
)

err = UpdateChallengeTimingProofGenerationAndFileSize(
cr.ChallengeID,
proofGenTime,
objectPath.Meta["size"].(int64),
objectPath.Size,
)
if err != nil {
allocMu.Unlock()
logging.Logger.Error(err.Error())
return err
}

allocMu.Unlock()

postDataBytes, err := json.Marshal(postData)
Expand Down
6 changes: 3 additions & 3 deletions code/go/0chain.net/blobbercore/challenge/timing.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type ChallengeTiming struct {
CreatedAtBlobber common.Timestamp `gorm:"created_at_blobber" json:"created_at_blobber"`
// FileSize is size of file that was randomly selected for challenge
FileSize int64 `gorm:"file_size" json:"file_size"`
// ProofGenTime is the time taken to generate challenge proof for the file
ProofGenTime common.Timestamp `gorm:"proof_gen_time" json:"proof_gen_time"`
// ProofGenTime is the time taken in millisecond to generate challenge proof for the file
ProofGenTime int64 `gorm:"proof_gen_time" json:"proof_gen_time"`
// CompleteValidation is when all validation tickets are all received.
CompleteValidation common.Timestamp `gorm:"complete_validation" json:"complete_validation"`
// TxnSubmission is when challenge response is first sent to blockchain.
Expand Down Expand Up @@ -101,7 +101,7 @@ func UpdateChallengeTimingCompleteValidation(challengeID string, completeValidat
}

func UpdateChallengeTimingProofGenerationAndFileSize(
challengeID string, proofGenTime common.Timestamp, size int64) error {
challengeID string, proofGenTime, size int64) error {

if proofGenTime == 0 || size == 0 {
logging.Logger.Error(fmt.Sprintf("Proof gen time: %d, size: %d", proofGenTime, size))
Expand Down

0 comments on commit 896d612

Please sign in to comment.