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
24 changes: 15 additions & 9 deletions code/go/0chain.net/blobbercore/challenge/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func startPullWorker(ctx context.Context) {
}

func startWorkers(ctx context.Context) {
setRound()
go getRoundWorker(ctx)

// start challenge listeners
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobbercore/filestore/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion code/go/0chain.net/blobbercore/handler/client_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
}
Expand Down
19 changes: 11 additions & 8 deletions code/go/0chain.net/blobbercore/handler/handler_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down