Skip to content

Commit 8cebc6b

Browse files
committed
add check with last marker
1 parent 34b6fc4 commit 8cebc6b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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: 7 additions & 3 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
}
@@ -93,8 +95,10 @@ func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *al
9395

9496
currTime := common.Now()
9597
// blobber clock is allowed to be 180 seconds behind the current time
96-
if wme.WM.Timestamp > currTime+180 {
97-
return common.NewError("write_marker_validation_failed", "Write Marker timestamp is in the future")
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)