diff --git a/code/go/0chain.net/blobbercore/challenge/worker.go b/code/go/0chain.net/blobbercore/challenge/worker.go index b721f2030..e6fbe14e2 100644 --- a/code/go/0chain.net/blobbercore/challenge/worker.go +++ b/code/go/0chain.net/blobbercore/challenge/worker.go @@ -71,6 +71,7 @@ func startPullWorker(ctx context.Context) { } func startWorkers(ctx context.Context) { + setRound() go getRoundWorker(ctx) // start challenge listeners @@ -85,21 +86,26 @@ func getRoundWorker(ctx context.Context) { for { select { case <-ctx.Done(): + ticker.Stop() return case <-ticker.C: - currentRound, _ := zcncore.GetRoundFromSharders() - - if roundInfo.LastRoundDiff == 0 { - roundInfo.LastRoundDiff = 1000 - } else { - roundInfo.LastRoundDiff = currentRound - roundInfo.CurrentRound - } - roundInfo.CurrentRound = currentRound - roundInfo.CurrentRoundCaptureTime = time.Now() + setRound() } } } +func setRound() { + currentRound, _ := zcncore.GetRoundFromSharders() + + if roundInfo.LastRoundDiff == 0 { + roundInfo.LastRoundDiff = 1000 + } else { + roundInfo.LastRoundDiff = currentRound - roundInfo.CurrentRound + } + roundInfo.CurrentRound = currentRound + roundInfo.CurrentRoundCaptureTime = time.Now() +} + func challengeProcessor(ctx context.Context) { defer func() { if r := recover(); r != nil { diff --git a/code/go/0chain.net/blobbercore/filestore/storage.go b/code/go/0chain.net/blobbercore/filestore/storage.go index e12f2a44a..0377e8a5c 100644 --- a/code/go/0chain.net/blobbercore/filestore/storage.go +++ b/code/go/0chain.net/blobbercore/filestore/storage.go @@ -117,7 +117,7 @@ func (fs *FileStore) WriteFile(allocID, conID string, fileData *FileInputData, i fileRef.ChunkUploaded = true fs.updateAllocTempFileSize(allocID, currentSize-initialSize) } - fmt.Println("writtenSize", writtenSize, offset) + fileRef.Size = writtenSize fileRef.Name = fileData.Name fileRef.Path = fileData.Path diff --git a/code/go/0chain.net/blobbercore/handler/client_quota.go b/code/go/0chain.net/blobbercore/handler/client_quota.go index b4d314dd5..99d6a8f2d 100644 --- a/code/go/0chain.net/blobbercore/handler/client_quota.go +++ b/code/go/0chain.net/blobbercore/handler/client_quota.go @@ -8,6 +8,7 @@ import ( "github.com/0chain/blobber/code/go/0chain.net/blobbercore/config" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore" "github.com/0chain/blobber/code/go/0chain.net/core/common" + "gorm.io/gorm" ) var ( @@ -33,7 +34,7 @@ func (ClientStats) TableName() string { return "client_stats" } -func (cs *ClientStats) BeforeCreate() error { +func (cs *ClientStats) BeforeCreate(tx *gorm.DB) error { cs.CreatedAt = common.Now() return nil } diff --git a/code/go/0chain.net/blobbercore/handler/handler_common.go b/code/go/0chain.net/blobbercore/handler/handler_common.go index f716a7eae..51eecd6e5 100644 --- a/code/go/0chain.net/blobbercore/handler/handler_common.go +++ b/code/go/0chain.net/blobbercore/handler/handler_common.go @@ -119,15 +119,18 @@ func WithStatusConnectionForWM(handler common.StatusCodeResponderF) common.Statu return func(ctx context.Context, r *http.Request) (resp interface{}, statusCode int, err error) { ctx = GetMetaDataStore().CreateTransaction(ctx) var vars = mux.Vars(r) - allocationID := vars["allocation_id"] - if allocationID != "" { - // Lock will compete with other CommitWrites and Challenge validation - var allocationObj *allocation.Allocation - mutex := lock.GetMutex(allocationObj.TableName(), allocationID) - Logger.Info("Locking allocation", zap.String("allocation_id", allocationID)) - mutex.Lock() - defer mutex.Unlock() + allocationID := vars["allocation"] + if allocationID == "" { + return nil, http.StatusBadRequest, common.NewError("invalid_allocation_id", "Allocation ID is required") } + + // Lock will compete with other CommitWrites and Challenge validation + var allocationObj *allocation.Allocation + mutex := lock.GetMutex(allocationObj.TableName(), allocationID) + Logger.Info("Locking allocation", zap.String("allocation_id", allocationID)) + mutex.Lock() + defer mutex.Unlock() + tx := GetMetaDataStore().GetTransaction(ctx) resp, statusCode, err = handler(ctx, r)