diff options
author | Florian Dold <florian@dold.me> | 2022-05-31 15:44:22 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-05-31 15:44:22 +0200 |
commit | 59bc54422f3e9aa7a487705489f6755e02ff5c0a (patch) | |
tree | c61337bbcd01ed03ea110d3e90d3bfec128fbddc | |
parent | 2e6f3b356971f3a56ff78db0ea6fa75ce0ab85b2 (diff) |
wallet-core: only schedule auto-refresh check if exchange update has no last error
-rw-r--r-- | packages/taler-wallet-core/src/operations/pending.ts | 18 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/refresh.ts | 49 |
2 files changed, 42 insertions, 25 deletions
diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts index b89c7c640..0a262d3bb 100644 --- a/packages/taler-wallet-core/src/operations/pending.ts +++ b/packages/taler-wallet-core/src/operations/pending.ts @@ -57,14 +57,16 @@ async function gatherExchangePending( lastError: e.lastError, }); - resp.pendingOperations.push({ - type: PendingTaskType.ExchangeCheckRefresh, - timestampDue: - e.retryInfo?.nextRetry ?? - AbsoluteTime.fromTimestamp(e.nextRefreshCheck), - givesLifeness: false, - exchangeBaseUrl: e.baseUrl, - }); + // We only schedule a check for auto-refresh if the exchange update + // was successful. + if (!e.lastError) { + resp.pendingOperations.push({ + type: PendingTaskType.ExchangeCheckRefresh, + timestampDue: AbsoluteTime.fromTimestamp(e.nextRefreshCheck), + givesLifeness: false, + exchangeBaseUrl: e.baseUrl, + }); + } }); } diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index 0dfcef427..fc90b6081 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -15,26 +15,41 @@ */ import { - AbsoluteTime, AgeCommitment, - AgeRestriction, AmountJson, Amounts, amountToPretty, codecForExchangeMeltResponse, + AbsoluteTime, + AgeCommitment, + AgeRestriction, + AmountJson, + Amounts, + amountToPretty, + codecForExchangeMeltResponse, codecForExchangeRevealResponse, - CoinPublicKey, CoinPublicKeyString, - DenomKeyType, Duration, + CoinPublicKey, + CoinPublicKeyString, + DenomKeyType, + Duration, durationFromSpec, - durationMul, encodeCrock, + durationMul, + encodeCrock, ExchangeMeltRequest, - ExchangeProtocolVersion, ExchangeRefreshRevealRequest, fnutil, getRandomBytes, + ExchangeProtocolVersion, + ExchangeRefreshRevealRequest, + fnutil, + getRandomBytes, HashCodeString, HttpStatusCode, - j2s, Logger, NotificationType, + j2s, + Logger, + NotificationType, RefreshGroupId, RefreshReason, - TalerErrorDetail, TalerProtocolTimestamp, URL + TalerErrorDetail, + TalerProtocolTimestamp, + URL, } from "@gnu-taler/taler-util"; import { TalerCryptoInterface } from "../crypto/cryptoImplementation.js"; import { DerivedRefreshSession, - RefreshNewDenomInfo + RefreshNewDenomInfo, } from "../crypto/cryptoTypes.js"; import { CryptoApiStoppedError } from "../crypto/workers/cryptoDispatcher.js"; import { @@ -45,28 +60,26 @@ import { OperationStatus, RefreshCoinStatus, RefreshGroupRecord, - WalletStoresV1 + WalletStoresV1, } from "../db.js"; import { TalerError } from "../errors.js"; import { DenomInfo, EXCHANGE_COINS_LOCK, - InternalWalletState + InternalWalletState, } from "../internal-wallet-state.js"; import { readSuccessResponseJsonOrThrow, - readUnexpectedResponseDetails + readUnexpectedResponseDetails, } from "../util/http.js"; import { checkDbInvariant } from "../util/invariants.js"; import { GetReadWriteAccess } from "../util/query.js"; -import { - RetryInfo -} from "../util/retries.js"; +import { RetryInfo } from "../util/retries.js"; import { guardOperationException } from "./common.js"; import { updateExchangeFromUrl } from "./exchanges.js"; import { isWithdrawableDenom, - selectWithdrawalDenominations + selectWithdrawalDenominations, } from "./withdraw.js"; const logger = new Logger("refresh.ts"); @@ -1023,10 +1036,12 @@ export async function autoRefresh( ): Promise<void> { logger.info(`doing auto-refresh check for '${exchangeBaseUrl}'`); - //updateExchangeFromUrl will also update retryInfo for this operation + // We must make sure that the exchange is up-to-date so that + // can refresh into new denominations. await updateExchangeFromUrl(ws, exchangeBaseUrl, { forceNow: true, }); + let minCheckThreshold = AbsoluteTime.addDuration( AbsoluteTime.now(), durationFromSpec({ days: 1 }), |