Skip to content

Commit ad7ae10

Browse files
authored
Merge pull request #1464 from 0chain/hotfix/chain-size
fix connection object size calculation
2 parents 3cb6f8f + ee7d2b4 commit ad7ae10

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,6 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
656656
return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation")
657657
}
658658

659-
if allocationObj.BlobberSizeUsed+connectionObj.Size > allocationObj.BlobberSize {
660-
return nil, common.NewError("max_allocation_size",
661-
"Max size reached for the allocation with this blobber")
662-
}
663-
664659
writeMarkerString := r.FormValue("write_marker")
665660
if writeMarkerString == "" {
666661
return nil, common.NewError("invalid_parameters", "Invalid write marker passed")
@@ -689,11 +684,6 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
689684
"Latest write marker is in failed state")
690685
}
691686

692-
if latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size != writeMarker.ChainSize {
693-
return nil, common.NewErrorf("invalid_chain_size",
694-
"Invalid chain size. expected:%v got %v", latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size, writeMarker.ChainSize)
695-
}
696-
697687
if latestWriteMarkerEntity.Status != writemarker.Committed {
698688
writeMarker.ChainLength = latestWriteMarkerEntity.WM.ChainLength
699689
}
@@ -758,6 +748,24 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
758748
if !rootRef.IsPrecommit {
759749
return nil, common.NewError("no_root_change", "No change in root ref")
760750
}
751+
connectionObj.Size = rootRef.Size - allocationObj.BlobberSizeUsed
752+
753+
if writemarkerEntity.WM.Size != connectionObj.Size {
754+
return nil, common.NewError("write_marker_validation_failed", fmt.Sprintf("Write Marker size %v does not match the connection size %v", writemarkerEntity.WM.Size, connectionObj.Size))
755+
}
756+
757+
if allocationObj.BlobberSizeUsed+connectionObj.Size > allocationObj.BlobberSize {
758+
return nil, common.NewError("max_allocation_size",
759+
"Max size reached for the allocation with this blobber")
760+
}
761+
762+
if latestWriteMarkerEntity != nil && latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size != writeMarker.ChainSize {
763+
return nil, common.NewErrorf("invalid_chain_size",
764+
"Invalid chain size. expected:%v got %v", latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size, writeMarker.ChainSize)
765+
} else if latestWriteMarkerEntity == nil && connectionObj.Size != writeMarker.ChainSize {
766+
return nil, common.NewErrorf("invalid_chain_size",
767+
"Invalid chain size. expected:%v got %v", connectionObj.Size, writeMarker.ChainSize)
768+
}
761769

762770
elapsedApplyChanges := time.Since(startTime) - elapsedAllocation - elapsedGetLock -
763771
elapsedGetConnObj - elapsedVerifyWM - elapsedWritePreRedeem

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *al
7676
return common.NewError("write_marker_validation_failed", "Write Marker is not for the same allocation transaction")
7777
}
7878

79-
if wme.WM.Size != co.Size {
80-
return common.NewError("write_marker_validation_failed", fmt.Sprintf("Write Marker size %v does not match the connection size %v", wme.WM.Size, co.Size))
81-
}
82-
8379
clientPublicKey := ctx.Value(constants.ContextKeyClientKey).(string)
8480
if clientPublicKey == "" {
8581
return common.NewError("write_marker_validation_failed", "Could not get the public key of the client")

0 commit comments

Comments
 (0)