don't unnecessarily repeat reserve processing after recoup

This commit is contained in:
Florian Dold 2020-09-04 03:10:36 +05:30
parent 9754109004
commit c7a2abedba
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 35 additions and 10 deletions

View File

@ -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(

View File

@ -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 };
}