Skip to content

Commit 6e12623

Browse files
authored
Merge pull request #1520 from 0chain/fix/commited-connection
Add check for committed connection
2 parents 6c82da6 + a676dba commit 6e12623

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,13 @@ func WithStatusConnectionForWM(handler common.StatusCodeResponderF) common.Statu
189189

190190
if blobberRes, ok := resp.(*blobberhttp.CommitResult); ok {
191191
// Save the write marker data
192-
writemarker.SaveMarkerData(allocationID, blobberRes.WriteMarker.WM.Timestamp, blobberRes.WriteMarker.WM.ChainLength)
193-
trie := blobberRes.Trie
194-
if trie != nil {
195-
_ = trie.DeleteNodes()
196-
blobberRes.Trie = nil
192+
if blobberRes.WriteMarker != nil {
193+
writemarker.SaveMarkerData(allocationID, blobberRes.WriteMarker.WM.Timestamp, blobberRes.WriteMarker.WM.ChainLength)
194+
trie := blobberRes.Trie
195+
if trie != nil {
196+
_ = trie.DeleteNodes()
197+
blobberRes.Trie = nil
198+
}
197199
}
198200
} else {
199201
Logger.Error("Invalid response type for commit handler")

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,17 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
646646
Logger.Error("Error checking pending markers", zap.Error(err))
647647
return nil, common.NewError("pending_markers", "previous marker is still pending to be redeemed")
648648
}
649-
649+
var result blobberhttp.CommitResult
650650
connectionObj, err := allocation.GetAllocationChanges(ctx, connectionID, allocationID, clientID)
651651
if err != nil {
652652
// might be good to check if blobber already has stored writemarker
653653
return nil, common.NewErrorf("invalid_parameters",
654654
"Invalid connection id. Connection id was not found: %v", err)
655655
}
656+
if connectionObj.Status == allocation.CommittedConnection {
657+
result.Success = true
658+
return &result, nil
659+
}
656660
if len(connectionObj.Changes) == 0 {
657661
if connectionObj.Status == allocation.NewConnection {
658662
return nil, common.NewError("invalid_parameters",
@@ -680,7 +684,6 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
680684
err)
681685
}
682686

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

868871
//Delete connection object and its changes
869872

870-
db.Delete(connectionObj)
871873
go allocation.DeleteConnectionObjEntry(connectionID)
872874
go AddWriteMarkerCount(clientID, connectionObj.Size <= 0)
873875

@@ -936,13 +938,17 @@ func (fsh *StorageHandler) CommitWriteV2(ctx context.Context, r *http.Request) (
936938
Logger.Error("Error checking pending markers", zap.Error(err))
937939
return nil, common.NewError("pending_markers", "previous marker is still pending to be redeemed")
938940
}
939-
941+
var result blobberhttp.CommitResult
940942
connectionObj, err := allocation.GetAllocationChanges(ctx, connectionID, allocationID, clientID)
941943
if err != nil {
942944
// might be good to check if blobber already has stored writemarker
943945
return nil, common.NewErrorf("invalid_parameters",
944946
"Invalid connection id. Connection id was not found: %v", err)
945947
}
948+
if connectionObj.Status == allocation.CommittedConnection {
949+
result.Success = true
950+
return &result, nil
951+
}
946952
if len(connectionObj.Changes) == 0 {
947953
if connectionObj.Status == allocation.NewConnection {
948954
return nil, common.NewError("invalid_parameters",
@@ -970,7 +976,6 @@ func (fsh *StorageHandler) CommitWriteV2(ctx context.Context, r *http.Request) (
970976
err)
971977
}
972978

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

11951200
//Delete connection object and its changes
1196-
1197-
db.Delete(connectionObj)
11981201
go allocation.DeleteConnectionObjEntry(connectionID)
11991202
go AddWriteMarkerCount(clientID, connectionObj.Size <= 0)
12001203

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.22.5
66

77
require (
88
github.com/0chain/errors v1.0.3
9-
github.com/0chain/gosdk v1.18.14
9+
github.com/0chain/gosdk v1.18.15
1010
github.com/DATA-DOG/go-sqlmock v1.5.0
1111
github.com/didip/tollbooth/v6 v6.1.2
1212
github.com/go-openapi/runtime v0.26.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI=
4040
github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw=
4141
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
4242
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
43-
github.com/0chain/gosdk v1.18.14 h1:N/PwLmUVQe1qM0eDuEDSQRB97a03Fp+I5W67cF0Zgsw=
44-
github.com/0chain/gosdk v1.18.14/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
43+
github.com/0chain/gosdk v1.18.15 h1:jujBBRAv2xendebjdoC6nMmoVl5w+uhDrKBqokIvxKI=
44+
github.com/0chain/gosdk v1.18.15/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
4545
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4646
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
4747
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=

0 commit comments

Comments
 (0)