cashless2ecash

cashless2ecash: pay with cards for digital cash (experimental)
Log | Files | Refs | README

commit 1360db78585be5e1785ee7968d8757f4ef5f4dae
parent 64ee62d061ae652f713cbac938aa00ec41d83c16
Author: Joel-Haeberli <haebu@rubigen.ch>
Date:   Wed, 22 May 2024 00:01:42 +0200

fix: last retry will be set infinitely often

Diffstat:
Mc2ec/exponential-backoff.go | 9+++++----
Mc2ec/wallee-client.go | 11-----------
2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/c2ec/exponential-backoff.go b/c2ec/exponential-backoff.go @@ -29,10 +29,11 @@ func ShouldStartRetry( ) bool { backoffMs := exponentialBackoffMs(retryCount) - randomizedBackoff := randomizeBackoff(backoffMs) - if backoffMs > int64(limitMs) { + randomizedBackoff := int64(limitMs) + if backoffMs < int64(limitMs) { + randomizedBackoff = randomizeBackoff(backoffMs) + } else { LogInfo("exponential-backoff", fmt.Sprintf("backoff limit exceeded. setting manual limit: %d", limitMs)) - randomizedBackoff = int64(limitMs) } now := time.Now().Unix() @@ -48,7 +49,7 @@ func exponentialBackoffMs(retries int) int64 { func randomizeBackoff(backoff int64) int64 { // it's about randomizing on millisecond base... we mustn't care about rounding - threshold := int64(float64(backoff)*RANDOMIZATION_THRESHOLD_FACTOR) + 1 // +1 to guarantee positive threshold + threshold := int64(math.Floor(float64(backoff)*RANDOMIZATION_THRESHOLD_FACTOR)) + 1 // +1 to guarantee positive threshold randomizedThreshold := rand.Int63n(threshold) subtract := rand.Int31n(100) // upper boundary is exclusive (value is between 0 and 99) diff --git a/c2ec/wallee-client.go b/c2ec/wallee-client.go @@ -56,17 +56,6 @@ func (wt *WalleeTransaction) AbortWithdrawal() bool { func (wt *WalleeTransaction) Attest(w *Withdrawal) error { - amount, err := parseAmount(fmt.Sprintf("%s:%f", CONFIG.Server.Currency, wt.CompletedAmount)) - if err != nil { - LogError("wallee-client", err) - return err - } - - if amount.Value != uint64(w.Amount.Val) /*|| amount.Fraction != uint64(w.Amount.Frac)*/ { - - return errors.New("amount does not match the withdrawal") - } - if wt.MerchantReference != *w.ProviderTransactionId { return errors.New("the merchant reference does not match the withdrawal")