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

Add/proof gen time #978

Merged
merged 7 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
24 changes: 24 additions & 0 deletions code/go/0chain.net/blobbercore/challenge/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ func (cr *ChallengeEntity) LoadValidationTickets(ctx context.Context) error {
}
postData["write_markers"] = markersArray

var proofGenTime int64 = -1

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

r := rand.New(rand.NewSource(cr.RandomNumber))
blockoffset := r.Intn(maxNumBlocks)
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 = time.Since(t1).Milliseconds()

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

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.Size,
)
if err != nil {
allocMu.Unlock()
logging.Logger.Error(err.Error())
return err
}

allocMu.Unlock()

postDataBytes, err := json.Marshal(postData)
Expand Down
22 changes: 22 additions & 0 deletions code/go/0chain.net/blobbercore/challenge/timing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore"
"github.com/0chain/blobber/code/go/0chain.net/core/common"
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
Expand All @@ -17,6 +18,10 @@ type ChallengeTiming struct {
CreatedAtChain common.Timestamp `gorm:"created_at_chain" json:"created_at_chain"`
// CreatedAtBlobber is when synchronized and created at blobber.
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 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 @@ -95,6 +100,23 @@ func UpdateChallengeTimingCompleteValidation(challengeID string, completeValidat
return err
}

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

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

c := &ChallengeTiming{
ChallengeID: challengeID,
ProofGenTime: proofGenTime,
FileSize: size,
}

db := datastore.GetStore().GetDB()
return db.Save(c).Error
}

func UpdateChallengeTimingTxnSubmission(challengeID string, txnSubmission common.Timestamp) error {
c := &ChallengeTiming{
ChallengeID: challengeID,
Expand Down