Skip to content

Commit

Permalink
Merge pull request #1464 from 0chain/hotfix/chain-size
Browse files Browse the repository at this point in the history
fix connection object size calculation
  • Loading branch information
dabasov authored Jul 29, 2024
2 parents 3cb6f8f + ee7d2b4 commit ad7ae10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
28 changes: 18 additions & 10 deletions code/go/0chain.net/blobbercore/handler/object_operation_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,6 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation")
}

if allocationObj.BlobberSizeUsed+connectionObj.Size > allocationObj.BlobberSize {
return nil, common.NewError("max_allocation_size",
"Max size reached for the allocation with this blobber")
}

writeMarkerString := r.FormValue("write_marker")
if writeMarkerString == "" {
return nil, common.NewError("invalid_parameters", "Invalid write marker passed")
Expand Down Expand Up @@ -689,11 +684,6 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
"Latest write marker is in failed state")
}

if latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size != writeMarker.ChainSize {
return nil, common.NewErrorf("invalid_chain_size",
"Invalid chain size. expected:%v got %v", latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size, writeMarker.ChainSize)
}

if latestWriteMarkerEntity.Status != writemarker.Committed {
writeMarker.ChainLength = latestWriteMarkerEntity.WM.ChainLength
}
Expand Down Expand Up @@ -758,6 +748,24 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
if !rootRef.IsPrecommit {
return nil, common.NewError("no_root_change", "No change in root ref")
}
connectionObj.Size = rootRef.Size - allocationObj.BlobberSizeUsed

if writemarkerEntity.WM.Size != connectionObj.Size {
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))
}

if allocationObj.BlobberSizeUsed+connectionObj.Size > allocationObj.BlobberSize {
return nil, common.NewError("max_allocation_size",
"Max size reached for the allocation with this blobber")
}

if latestWriteMarkerEntity != nil && latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size != writeMarker.ChainSize {
return nil, common.NewErrorf("invalid_chain_size",
"Invalid chain size. expected:%v got %v", latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size, writeMarker.ChainSize)
} else if latestWriteMarkerEntity == nil && connectionObj.Size != writeMarker.ChainSize {
return nil, common.NewErrorf("invalid_chain_size",
"Invalid chain size. expected:%v got %v", connectionObj.Size, writeMarker.ChainSize)
}

elapsedApplyChanges := time.Since(startTime) - elapsedAllocation - elapsedGetLock -
elapsedGetConnObj - elapsedVerifyWM - elapsedWritePreRedeem
Expand Down
4 changes: 0 additions & 4 deletions code/go/0chain.net/blobbercore/writemarker/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *al
return common.NewError("write_marker_validation_failed", "Write Marker is not for the same allocation transaction")
}

if wme.WM.Size != co.Size {
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))
}

clientPublicKey := ctx.Value(constants.ContextKeyClientKey).(string)
if clientPublicKey == "" {
return common.NewError("write_marker_validation_failed", "Could not get the public key of the client")
Expand Down

0 comments on commit ad7ae10

Please sign in to comment.