Skip to content

Commit a404870

Browse files
authored
Merge branch 'staging' into hotfix/get-marker
2 parents 7aa18d7 + 3bcb469 commit a404870

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

code/go/0chain.net/blobbercore/filestore/storage.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (fs *FileStore) WriteFile(allocID, conID string, fileData *FileInputData, i
106106
_ = os.Remove(tempFilePath)
107107
return nil, common.NewError("file_size_mismatch", "File size is greater than expected")
108108
}
109-
logging.Logger.Info("temp_file_write: ", zap.String("filePath", fileData.Path), zap.Int64("currentSize", currentSize), zap.Int64("initialSize", initialSize), zap.Int64("writtenSize", writtenSize), zap.Int64("offset", fileData.UploadOffset), zap.Bool("ChunkUploaded", fileRef.ChunkUploaded))
109+
logging.Logger.Info("temp_file_write: ", zap.String("filePath", fileData.Path), zap.Int64("currentSize", currentSize), zap.Int64("initialSize", initialSize), zap.Int64("writtenSize", writtenSize), zap.Int64("offset", fileData.UploadOffset), zap.String("tempFilePath", tempFilePath))
110110
fileRef.Size = writtenSize
111111
fileRef.Name = fileData.Name
112112
fileRef.Path = fileData.Path
@@ -182,12 +182,6 @@ func (fs *FileStore) DeletePreCommitDir(allocID string) error {
182182
if err != nil {
183183
return common.NewError("pre_commit_dir_deletion_error", err.Error())
184184
}
185-
tempDir := fs.getAllocTempDir(allocID)
186-
err = os.RemoveAll(tempDir)
187-
if err != nil {
188-
return common.NewError("temp_dir_deletion_error", err.Error())
189-
}
190-
191185
return nil
192186
}
193187

@@ -398,7 +392,7 @@ func (fs *FileStore) DeleteTempFile(allocID, conID string, fd *FileInputData) er
398392
return common.NewError("invalid_allocation_id", "Allocation id cannot be empty")
399393
}
400394
fileObjectPath := fs.getTempPathForFile(allocID, fd.Name, encryption.Hash(fd.Path), conID)
401-
395+
logging.Logger.Info("deleting_temp_file", zap.String("fileObjectPath", fileObjectPath), zap.String("allocation_id", allocID), zap.String("connection_id", conID))
402396
finfo, err := os.Stat(fileObjectPath)
403397
if err != nil {
404398
if errors.Is(err, os.ErrNotExist) {

code/go/0chain.net/blobbercore/filestore/tree_validation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ func (c *CommitHasher) Start(ctx context.Context, connID, allocID, fileName, fil
427427
tempFilePath := GetFileStore().GetTempFilePath(allocID, connID, fileName, filePathHash)
428428
f, err := os.Open(tempFilePath)
429429
if err != nil {
430+
logging.Logger.Error("hasher_open", zap.Error(err), zap.String("tempFilePath", tempFilePath))
430431
c.hashErr = err
431432
return
432433
}

code/go/0chain.net/blobbercore/handler/object_operation_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
618618
return nil, common.NewError("chain_length_exceeded", "Chain length exceeded")
619619
}
620620

621-
err = writemarkerEntity.VerifyMarker(ctx, allocationObj, connectionObj)
621+
err = writemarkerEntity.VerifyMarker(ctx, allocationObj, connectionObj, latestWriteMarkerEntity)
622622
if err != nil {
623623
result.AllocationRoot = allocationObj.AllocationRoot
624624
result.ErrorMessage = "Verification of write marker failed: " + err.Error()

code/go/0chain.net/blobbercore/writemarker/protocol.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ type CommitConnection struct {
2525
ChainData []byte `json:"chain_data"`
2626
}
2727

28+
const timeGap = 180
29+
2830
// VerifyMarker verify WriteMarker's hash and check allocation_root if it is unique
29-
func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *allocation.Allocation, co *allocation.AllocationChangeCollector) error {
31+
func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *allocation.Allocation, co *allocation.AllocationChangeCollector, latestWM *WriteMarkerEntity) error {
3032
if wme == nil {
3133
return common.NewError("invalid_write_marker", "No Write Marker was found")
3234
}
@@ -92,9 +94,11 @@ func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *al
9294
}
9395

9496
currTime := common.Now()
95-
// blobber clock is allowed to be 60 seconds behind the current time
96-
if wme.WM.Timestamp > currTime+60 {
97-
return common.NewError("write_marker_validation_failed", "Write Marker timestamp is in the future")
97+
// blobber clock is allowed to be 180 seconds behind the current time
98+
if wme.WM.Timestamp > currTime+timeGap {
99+
if latestWM == nil || wme.WM.Timestamp > latestWM.WM.Timestamp+timeGap {
100+
return common.NewError("write_marker_validation_failed", "Write Marker timestamp is in the future")
101+
}
98102
}
99103

100104
hashData := wme.WM.GetHashData()

0 commit comments

Comments
 (0)