diff --git a/code/go/0chain.net/blobbercore/handler/handler_common.go b/code/go/0chain.net/blobbercore/handler/handler_common.go index e523cee42..e37e9d41d 100644 --- a/code/go/0chain.net/blobbercore/handler/handler_common.go +++ b/code/go/0chain.net/blobbercore/handler/handler_common.go @@ -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") diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go index 888e7d963..29afc3bc5 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go @@ -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", @@ -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 @@ -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) @@ -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", @@ -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 @@ -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) diff --git a/go.mod b/go.mod index e57c325af..1910ed238 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index fa62e5af4..b6f2abfff 100644 --- a/go.sum +++ b/go.sum @@ -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=