@@ -10,7 +10,6 @@ import (
1010 "context"
1111 "errors"
1212 "fmt"
13- "math/rand/v2"
1413 "strconv"
1514 "time"
1615
@@ -45,13 +44,10 @@ const (
4544)
4645
4746const (
48- defaultTTL = 30 * time .Second // request time to live
49- preemptiveInterval = 5 * time .Second // P90 request time to live
50- skiplistDur = 5 * time .Minute
51- overDraftRefresh = time .Millisecond * 600 // overdraft refresh duration and initial backoff delay
52- maxOverDraftRefresh = time .Second * 5 // maximum backoff delay
53- overDraftBackoffMultiplier = 1.2 // backoff multiplier
54- overDraftJitterPercent = 0.1 // 10% jitter
47+ defaultTTL = 30 * time .Second // request time to live
48+ preemptiveInterval = 5 * time .Second // P90 request time to live
49+ skiplistDur = 5 * time .Minute
50+ overDraftRefresh = time .Millisecond * 600
5551)
5652
5753const (
@@ -319,6 +315,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)
319315 default :
320316 ps .metrics .Forwarder .Inc ()
321317 return fmt .Errorf ("handler: push to closest chunk %s: %w" , chunkAddress , err )
318+
322319 }
323320}
324321
@@ -358,12 +355,10 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, origin bo
358355 ps .metrics .TotalRequests .Inc ()
359356
360357 var (
361- sentErrorsLeft = 1
362- preemptiveTicker <- chan time.Time
363- inflight int
364- parallelForwards = maxMultiplexForwards
365- overdraftBackoffDelay time.Duration
366- overdraftRetryCount int
358+ sentErrorsLeft = 1
359+ preemptiveTicker <- chan time.Time
360+ inflight int
361+ parallelForwards = maxMultiplexForwards
367362 )
368363
369364 if origin {
@@ -429,19 +424,10 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, origin bo
429424 continue // there is still an inflight request, wait for it's result
430425 }
431426
432- overdraftBackoffDelay = calculateOverdraftBackoff (overdraftBackoffDelay )
433- overdraftRetryCount ++
434-
435- // log first 3 attempts and then every 5th
436- if overdraftRetryCount % 5 == 1 || overdraftRetryCount <= 3 {
437- ps .logger .Debug ("sleeping to refresh overdraft balance" ,
438- "chunk_address" , ch .Address (),
439- "backoff_delay" , overdraftBackoffDelay ,
440- "retry_count" , overdraftRetryCount )
441- }
427+ ps .logger .Debug ("sleeping to refresh overdraft balance" , "chunk_address" , ch .Address ())
442428
443429 select {
444- case <- time .After (overdraftBackoffDelay ):
430+ case <- time .After (overDraftRefresh ):
445431 retry ()
446432 continue
447433 case <- ctx .Done ():
@@ -458,12 +444,6 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, origin bo
458444 continue
459445 }
460446
461- if overdraftRetryCount > 0 {
462- ps .logger .Debug ("overdraft resolved, resetting backoff" , "chunk_address" , ch .Address (), "total_retries" , overdraftRetryCount )
463- overdraftBackoffDelay = 0
464- overdraftRetryCount = 0
465- }
466-
467447 // since we can reach into the neighborhood of the chunk
468448 // act as the multiplexer and push the chunk in parallel to multiple peers
469449 if swarm .Proximity (peer .Bytes (), ch .Address ().Bytes ()) >= rad {
@@ -698,22 +678,6 @@ func (ps *PushSync) validStampWrapper(f postage.ValidStampFn) postage.ValidStamp
698678 }
699679}
700680
701- // calculateOverdraftBackoff calculates the next backoff delay using exponential backoff with jitter.
702- // It takes the current backoff delay and returns the next delay, capped at maxOverDraftRefresh.
703- func calculateOverdraftBackoff (currentDelay time.Duration ) time.Duration {
704- if currentDelay == 0 {
705- currentDelay = overDraftRefresh
706- }
707-
708- nextDelay := min (time .Duration (float64 (currentDelay )* overDraftBackoffMultiplier ), maxOverDraftRefresh )
709-
710- jitterRange := float64 (nextDelay ) * overDraftJitterPercent
711- jitter := (rand .Float64 () - 0.5 ) * 2 * jitterRange
712- finalDelay := max (time .Duration (float64 (nextDelay )+ jitter ), overDraftRefresh )
713-
714- return finalDelay
715- }
716-
717681func (s * PushSync ) Close () error {
718682 return s .errSkip .Close ()
719683}
0 commit comments