Skip to content

Commit

Permalink
[client] change tip attempt to local time and modify exp delay to con…
Browse files Browse the repository at this point in the history
…stant delay
  • Loading branch information
vctt94 committed Dec 20, 2024
1 parent 35d8905 commit 09041f2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions client/tip_attempts.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (tal *tipAttemptsList) determineTipAttemptAction(ta *clientdb.TipUserAttemp
// that older attempts have a lower (i.e. earlier) action time for
// sorting purposes.
actNow := func() time.Time {
return ta.Created.Add(-time.Minute)
return ta.Created.Add(-time.Minute).In(time.Local)
}

if ta.Attempts > ta.MaxAttempts {
Expand All @@ -157,7 +157,7 @@ func (tal *tipAttemptsList) determineTipAttemptAction(ta *clientdb.TipUserAttemp
}

// expireDeadline is when the entire tip attempt expires.
expireDeadline := ta.Created.Add(tal.maxLifetimeDuration)
expireDeadline := ta.Created.Add(tal.maxLifetimeDuration).In(time.Local)
if expireDeadline.Before(time.Now()) {
// Expired.
return actionExpire, expireDeadline
Expand All @@ -176,10 +176,10 @@ func (tal *tipAttemptsList) determineTipAttemptAction(ta *clientdb.TipUserAttemp
return actionAttemptPayment, actNow()
}

// Exponential delay for repeated retriable payment attempts.
expDelay := time.Duration(1 << ta.PaymentAttemptCount)
delay := expDelay * tal.payRetryDelayFactor
return actionAttemptPayment, (*ta.PaymentAttemptFailed).Add(delay)
// constant delay increase for repeated retriable payment attempts.
delay := time.Duration(ta.PaymentAttemptCount) * tal.payRetryDelayFactor
nextAttemptTime := (*ta.PaymentAttemptFailed).Add(delay).In(time.Local)
return actionAttemptPayment, nextAttemptTime
}

// Check payment attempt.
Expand All @@ -195,7 +195,7 @@ func (tal *tipAttemptsList) determineTipAttemptAction(ta *clientdb.TipUserAttemp
if ta.LastInvoiceError != nil {
// Had an error paying or requesting an invoice. Wait until
// it's time to try and request a new invoice.
return actionRequestInvoice, ta.InvoiceRequested.Add(tal.requestInvoiceDeadline)
return actionRequestInvoice, ta.InvoiceRequested.Add(tal.requestInvoiceDeadline).In(time.Local)
}

if ta.InvoiceRequested == nil {
Expand Down

0 comments on commit 09041f2

Please sign in to comment.