diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-09-04 03:10:36 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-09-04 03:10:36 +0530 |
commit | c7a2abedbabe9142ce9a15902f90a5d1f4b36f05 (patch) | |
tree | 71346990d8e11212a1153f740bfec9921c067dcc | |
parent | 9754109004f37a789f7a00fa6c1073d22e089484 (diff) |
don't unnecessarily repeat reserve processing after recoup
-rw-r--r-- | packages/taler-wallet-core/src/operations/recoup.ts | 33 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/reserves.ts | 12 |
2 files changed, 35 insertions, 10 deletions
diff --git a/packages/taler-wallet-core/src/operations/recoup.ts b/packages/taler-wallet-core/src/operations/recoup.ts index 91579f602..eb268f18b 100644 --- a/packages/taler-wallet-core/src/operations/recoup.ts +++ b/packages/taler-wallet-core/src/operations/recoup.ts @@ -40,7 +40,7 @@ import { import { codecForRecoupConfirmation } from "../types/talerTypes"; import { NotificationType } from "../types/notifications"; -import { forceQueryReserve, getReserveRequestTimeout } from "./reserves"; +import { forceQueryReserve, getReserveRequestTimeout, processReserve } from "./reserves"; import { Amounts } from "../util/amounts"; import { createRefreshGroup, processRefreshGroup } from "./refresh"; @@ -200,8 +200,13 @@ async function recoupWithdrawCoin( updatedCoin.status = CoinStatus.Dormant; const currency = updatedCoin.currentAmount.currency; updatedCoin.currentAmount = Amounts.getZero(currency); - updatedReserve.reserveStatus = ReserveRecordStatus.QUERYING_STATUS; - updatedReserve.retryInfo = initRetryInfo(); + if (updatedReserve.reserveStatus === ReserveRecordStatus.DORMANT) { + updatedReserve.reserveStatus = ReserveRecordStatus.QUERYING_STATUS; + updatedReserve.retryInfo = initRetryInfo(); + } else { + updatedReserve.requestedQuery = true; + updatedReserve.retryInfo = initRetryInfo(); + } await tx.put(Stores.coins, updatedCoin); await tx.put(Stores.reserves, updatedReserve); await putGroupAsFinished(ws, tx, recoupGroup, coinIdx); @@ -211,10 +216,6 @@ async function recoupWithdrawCoin( ws.notify({ type: NotificationType.RecoupFinished, }); - - forceQueryReserve(ws, reserve.reservePub).catch((e) => { - logger.error("re-querying reserve after recoup failed:", e); - }); } async function recoupRefreshCoin( @@ -341,6 +342,24 @@ async function processRecoupGroupImpl( processRecoup(ws, recoupGroupId, i), ); await Promise.all(ps); + + const reserveSet = new Set<string>(); + for (let i = 0; i < recoupGroup.coinPubs.length; i++) { + const coinPub = recoupGroup.coinPubs[i]; + const coin = await ws.db.get(Stores.coins, coinPub); + if (!coin) { + throw Error(`Coin ${coinPub} not found, can't request payback`); + } + if (coin.coinSource.type === CoinSourceType.Withdraw) { + reserveSet.add(coin.coinSource.reservePub); + } + } + + for (const r of reserveSet.values()) { + processReserve(ws, r).catch((e) => { + logger.error(`processing reserve ${r} after recoup failed`); + }); + } } export async function createRecoupGroup( diff --git a/packages/taler-wallet-core/src/operations/reserves.ts b/packages/taler-wallet-core/src/operations/reserves.ts index a28c2e0cf..69942fe94 100644 --- a/packages/taler-wallet-core/src/operations/reserves.ts +++ b/packages/taler-wallet-core/src/operations/reserves.ts @@ -291,7 +291,7 @@ export async function forceQueryReserve( break; default: reserve.requestedQuery = true; - return; + break; } reserve.retryInfo = initRetryInfo(); await tx.put(Stores.reserves, reserve); @@ -601,13 +601,17 @@ async function updateReserve( logger.trace("setting reserve status to 'withdrawing' after query"); r.reserveStatus = ReserveRecordStatus.WITHDRAWING; r.retryInfo = initRetryInfo(); + r.requestedQuery = false; } else { - logger.trace("setting reserve status to 'dormant' after query"); if (r.requestedQuery) { + logger.trace( + "setting reserve status to 'querying-status' (requested query) after query", + ); r.reserveStatus = ReserveRecordStatus.QUERYING_STATUS; r.requestedQuery = false; r.retryInfo = initRetryInfo(); } else { + logger.trace("setting reserve status to 'dormant' after query"); r.reserveStatus = ReserveRecordStatus.DORMANT; r.retryInfo = initRetryInfo(false); } @@ -622,7 +626,9 @@ async function updateReserve( ws.notify({ type: NotificationType.ReserveUpdated, updateSummary }); const reserve2 = await ws.db.get(Stores.reserves, reservePub); if (reserve2) { - logger.trace(`after db transaction, reserve status is ${reserve2.reserveStatus}`); + logger.trace( + `after db transaction, reserve status is ${reserve2.reserveStatus}`, + ); } return { ready: true }; } |