wallet-core: only schedule auto-refresh check if exchange update has no last error

This commit is contained in:
Florian Dold 2022-05-31 15:44:22 +02:00
parent 2e6f3b3569
commit 59bc54422f
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 42 additions and 25 deletions

View File

@ -57,14 +57,16 @@ async function gatherExchangePending(
lastError: e.lastError, lastError: e.lastError,
}); });
// We only schedule a check for auto-refresh if the exchange update
// was successful.
if (!e.lastError) {
resp.pendingOperations.push({ resp.pendingOperations.push({
type: PendingTaskType.ExchangeCheckRefresh, type: PendingTaskType.ExchangeCheckRefresh,
timestampDue: timestampDue: AbsoluteTime.fromTimestamp(e.nextRefreshCheck),
e.retryInfo?.nextRetry ??
AbsoluteTime.fromTimestamp(e.nextRefreshCheck),
givesLifeness: false, givesLifeness: false,
exchangeBaseUrl: e.baseUrl, exchangeBaseUrl: e.baseUrl,
}); });
}
}); });
} }

View File

@ -15,26 +15,41 @@
*/ */
import { import {
AbsoluteTime, AgeCommitment, AbsoluteTime,
AgeRestriction, AmountJson, Amounts, amountToPretty, codecForExchangeMeltResponse, AgeCommitment,
AgeRestriction,
AmountJson,
Amounts,
amountToPretty,
codecForExchangeMeltResponse,
codecForExchangeRevealResponse, codecForExchangeRevealResponse,
CoinPublicKey, CoinPublicKeyString, CoinPublicKey,
DenomKeyType, Duration, CoinPublicKeyString,
DenomKeyType,
Duration,
durationFromSpec, durationFromSpec,
durationMul, encodeCrock, durationMul,
encodeCrock,
ExchangeMeltRequest, ExchangeMeltRequest,
ExchangeProtocolVersion, ExchangeRefreshRevealRequest, fnutil, getRandomBytes, ExchangeProtocolVersion,
ExchangeRefreshRevealRequest,
fnutil,
getRandomBytes,
HashCodeString, HashCodeString,
HttpStatusCode, HttpStatusCode,
j2s, Logger, NotificationType, j2s,
Logger,
NotificationType,
RefreshGroupId, RefreshGroupId,
RefreshReason, RefreshReason,
TalerErrorDetail, TalerProtocolTimestamp, URL TalerErrorDetail,
TalerProtocolTimestamp,
URL,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { TalerCryptoInterface } from "../crypto/cryptoImplementation.js"; import { TalerCryptoInterface } from "../crypto/cryptoImplementation.js";
import { import {
DerivedRefreshSession, DerivedRefreshSession,
RefreshNewDenomInfo RefreshNewDenomInfo,
} from "../crypto/cryptoTypes.js"; } from "../crypto/cryptoTypes.js";
import { CryptoApiStoppedError } from "../crypto/workers/cryptoDispatcher.js"; import { CryptoApiStoppedError } from "../crypto/workers/cryptoDispatcher.js";
import { import {
@ -45,28 +60,26 @@ import {
OperationStatus, OperationStatus,
RefreshCoinStatus, RefreshCoinStatus,
RefreshGroupRecord, RefreshGroupRecord,
WalletStoresV1 WalletStoresV1,
} from "../db.js"; } from "../db.js";
import { TalerError } from "../errors.js"; import { TalerError } from "../errors.js";
import { import {
DenomInfo, DenomInfo,
EXCHANGE_COINS_LOCK, EXCHANGE_COINS_LOCK,
InternalWalletState InternalWalletState,
} from "../internal-wallet-state.js"; } from "../internal-wallet-state.js";
import { import {
readSuccessResponseJsonOrThrow, readSuccessResponseJsonOrThrow,
readUnexpectedResponseDetails readUnexpectedResponseDetails,
} from "../util/http.js"; } from "../util/http.js";
import { checkDbInvariant } from "../util/invariants.js"; import { checkDbInvariant } from "../util/invariants.js";
import { GetReadWriteAccess } from "../util/query.js"; import { GetReadWriteAccess } from "../util/query.js";
import { import { RetryInfo } from "../util/retries.js";
RetryInfo
} from "../util/retries.js";
import { guardOperationException } from "./common.js"; import { guardOperationException } from "./common.js";
import { updateExchangeFromUrl } from "./exchanges.js"; import { updateExchangeFromUrl } from "./exchanges.js";
import { import {
isWithdrawableDenom, isWithdrawableDenom,
selectWithdrawalDenominations selectWithdrawalDenominations,
} from "./withdraw.js"; } from "./withdraw.js";
const logger = new Logger("refresh.ts"); const logger = new Logger("refresh.ts");
@ -1023,10 +1036,12 @@ export async function autoRefresh(
): Promise<void> { ): Promise<void> {
logger.info(`doing auto-refresh check for '${exchangeBaseUrl}'`); 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, { await updateExchangeFromUrl(ws, exchangeBaseUrl, {
forceNow: true, forceNow: true,
}); });
let minCheckThreshold = AbsoluteTime.addDuration( let minCheckThreshold = AbsoluteTime.addDuration(
AbsoluteTime.now(), AbsoluteTime.now(),
durationFromSpec({ days: 1 }), durationFromSpec({ days: 1 }),