Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 7 additions & 5 deletions code/go/0chain.net/blobbercore/handler/handler_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ func WithStatusConnectionForWM(handler common.StatusCodeResponderF) common.Statu

if blobberRes, ok := resp.(*blobberhttp.CommitResult); ok {
// Save the write marker data
writemarker.SaveMarkerData(allocationID, blobberRes.WriteMarker.WM.Timestamp, blobberRes.WriteMarker.WM.ChainLength)
trie := blobberRes.Trie
if trie != nil {
_ = trie.DeleteNodes()
blobberRes.Trie = nil
if blobberRes.WriteMarker != nil {
writemarker.SaveMarkerData(allocationID, blobberRes.WriteMarker.WM.Timestamp, blobberRes.WriteMarker.WM.ChainLength)
trie := blobberRes.Trie
if trie != nil {
_ = trie.DeleteNodes()
blobberRes.Trie = nil
}
}
} else {
Logger.Error("Invalid response type for commit handler")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,17 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
Logger.Error("Error checking pending markers", zap.Error(err))
return nil, common.NewError("pending_markers", "previous marker is still pending to be redeemed")
}

var result blobberhttp.CommitResult
connectionObj, err := allocation.GetAllocationChanges(ctx, connectionID, allocationID, clientID)
if err != nil {
// might be good to check if blobber already has stored writemarker
return nil, common.NewErrorf("invalid_parameters",
"Invalid connection id. Connection id was not found: %v", err)
}
if connectionObj.Status == allocation.CommittedConnection {
result.Success = true
return &result, nil
}
if len(connectionObj.Changes) == 0 {
if connectionObj.Status == allocation.NewConnection {
return nil, common.NewError("invalid_parameters",
Expand Down Expand Up @@ -680,7 +684,6 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
err)
}

var result blobberhttp.CommitResult
var latestWriteMarkerEntity *writemarker.WriteMarkerEntity
if allocationObj.AllocationRoot == "" {
latestWriteMarkerEntity = nil
Expand Down Expand Up @@ -867,7 +870,6 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b

//Delete connection object and its changes

db.Delete(connectionObj)
go allocation.DeleteConnectionObjEntry(connectionID)
go AddWriteMarkerCount(clientID, connectionObj.Size <= 0)

Expand Down Expand Up @@ -936,13 +938,17 @@ func (fsh *StorageHandler) CommitWriteV2(ctx context.Context, r *http.Request) (
Logger.Error("Error checking pending markers", zap.Error(err))
return nil, common.NewError("pending_markers", "previous marker is still pending to be redeemed")
}

var result blobberhttp.CommitResult
connectionObj, err := allocation.GetAllocationChanges(ctx, connectionID, allocationID, clientID)
if err != nil {
// might be good to check if blobber already has stored writemarker
return nil, common.NewErrorf("invalid_parameters",
"Invalid connection id. Connection id was not found: %v", err)
}
if connectionObj.Status == allocation.CommittedConnection {
result.Success = true
return &result, nil
}
if len(connectionObj.Changes) == 0 {
if connectionObj.Status == allocation.NewConnection {
return nil, common.NewError("invalid_parameters",
Expand Down Expand Up @@ -970,7 +976,6 @@ func (fsh *StorageHandler) CommitWriteV2(ctx context.Context, r *http.Request) (
err)
}

var result blobberhttp.CommitResult
var latestWriteMarkerEntity *writemarker.WriteMarkerEntity
if allocationObj.AllocationRoot == "" {
latestWriteMarkerEntity = nil
Expand Down Expand Up @@ -1193,8 +1198,6 @@ func (fsh *StorageHandler) CommitWriteV2(ctx context.Context, r *http.Request) (
commitSuccess = true

//Delete connection object and its changes

db.Delete(connectionObj)
go allocation.DeleteConnectionObjEntry(connectionID)
go AddWriteMarkerCount(clientID, connectionObj.Size <= 0)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.5

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.18.14
github.com/0chain/gosdk v1.18.15
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/didip/tollbooth/v6 v6.1.2
github.com/go-openapi/runtime v0.26.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI=
github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw=
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
github.com/0chain/gosdk v1.18.14 h1:N/PwLmUVQe1qM0eDuEDSQRB97a03Fp+I5W67cF0Zgsw=
github.com/0chain/gosdk v1.18.14/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
github.com/0chain/gosdk v1.18.15 h1:jujBBRAv2xendebjdoC6nMmoVl5w+uhDrKBqokIvxKI=
github.com/0chain/gosdk v1.18.15/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
Expand Down
Loading