Skip to content

Commit 2bef23f

Browse files
authored
Merge pull request #1410 from 0chain/feat/random-worker
random redeem worker
2 parents 34092da + 5a2120d commit 2bef23f

File tree

1 file changed

+11
-1
lines changed
  • code/go/0chain.net/blobbercore/writemarker

1 file changed

+11
-1
lines changed

code/go/0chain.net/blobbercore/writemarker/worker.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ func retryRedeem(errString string) bool {
256256
}
257257

258258
func startCollector(ctx context.Context) {
259-
ticker := time.NewTicker(config.Configuration.MarkerRedeemInterval)
259+
randTime := getRandTime()
260+
ticker := time.NewTicker(time.Duration(randTime) * time.Second)
260261
defer ticker.Stop()
261262
for {
262263
select {
@@ -272,6 +273,8 @@ func startCollector(ctx context.Context) {
272273
}
273274
}
274275
markerDataMut.Unlock()
276+
randTime = getRandTime()
277+
ticker.Reset(time.Duration(randTime) * time.Second)
275278
}
276279
}
277280
}
@@ -284,6 +287,13 @@ func (md *markerData) processMarker() bool {
284287
return !md.processing && !md.inCommit && (md.chainLength >= config.Configuration.MaxChainLength || common.Now()-md.firstMarkerTimestamp > common.Timestamp(config.Configuration.MaxTimestampGap) || common.Now()-md.lastMarkerTimestamp > common.Timestamp(randTime))
285288
}
286289

290+
func getRandTime() int64 {
291+
secondsInterval := int64(config.Configuration.MarkerRedeemInterval.Seconds())
292+
randTime := rand.Int63n(secondsInterval / 2)
293+
randTime += secondsInterval / 2 // interval of secondsInterval/2 to secondsInterval
294+
return randTime
295+
}
296+
287297
// TODO: don't delete prev WM
288298
// func startCleanupWorker(ctx context.Context) {
289299
// for {

0 commit comments

Comments
 (0)