[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: generate cleaner history for
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: generate cleaner history for recoup |
Date: |
Fri, 27 Mar 2020 19:07:07 +0100 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new 131d2b34 generate cleaner history for recoup
131d2b34 is described below
commit 131d2b34d9d1f84782d749c9943a7da5ab9dab8a
Author: Florian Dold <address@hidden>
AuthorDate: Fri Mar 27 23:37:02 2020 +0530
generate cleaner history for recoup
---
src/operations/history.ts | 1 +
src/operations/recoup.ts | 39 ++++++++++++++++++++++-----------------
src/types/dbTypes.ts | 11 +++++++++++
src/types/history.ts | 1 +
4 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/src/operations/history.ts b/src/operations/history.ts
index c09aa8d3..b19b9f19 100644
--- a/src/operations/history.ts
+++ b/src/operations/history.ts
@@ -492,6 +492,7 @@ export async function getHistory(
type: HistoryEventType.FundsRecouped,
timestamp: rg.timestampFinished,
eventId: makeEventId(HistoryEventType.FundsRecouped,
rg.recoupGroupId),
+ numCoinsRecouped: rg.coinPubs.length,
});
}
});
diff --git a/src/operations/recoup.ts b/src/operations/recoup.ts
index de2e6c9a..4c6eaf3b 100644
--- a/src/operations/recoup.ts
+++ b/src/operations/recoup.ts
@@ -72,10 +72,14 @@ async function incrementRecoupRetry(
}
async function putGroupAsFinished(
+ ws: InternalWalletState,
tx: TransactionHandle,
recoupGroup: RecoupGroupRecord,
coinIdx: number,
): Promise<void> {
+ if (recoupGroup.timestampFinished) {
+ return;
+ }
recoupGroup.recoupFinishedPerCoin[coinIdx] = true;
let allFinished = true;
for (const b of recoupGroup.recoupFinishedPerCoin) {
@@ -87,6 +91,16 @@ async function putGroupAsFinished(
recoupGroup.timestampFinished = getTimestampNow();
recoupGroup.retryInfo = initRetryInfo(false);
recoupGroup.lastError = undefined;
+ if (recoupGroup.scheduleRefreshCoins.length > 0) {
+ const refreshGroupId = await createRefreshGroup(
+ tx,
+ recoupGroup.scheduleRefreshCoins.map((x) => ({ coinPub: x })),
+ RefreshReason.Recoup,
+ );
+ processRefreshGroup(ws, refreshGroupId.refreshGroupId).then((e) => {
+ console.error("error while refreshing after recoup", e);
+ });
+ }
}
await tx.put(Stores.recoupGroups, recoupGroup);
}
@@ -108,7 +122,7 @@ async function recoupTipCoin(
if (recoupGroup.recoupFinishedPerCoin[coinIdx]) {
return;
}
- await putGroupAsFinished(tx, recoupGroup, coinIdx);
+ await putGroupAsFinished(ws, tx, recoupGroup, coinIdx);
});
}
@@ -179,7 +193,7 @@ async function recoupWithdrawCoin(
updatedReserve.reserveStatus = ReserveRecordStatus.QUERYING_STATUS;
await tx.put(Stores.coins, updatedCoin);
await tx.put(Stores.reserves, updatedReserve);
- await putGroupAsFinished(tx, recoupGroup, coinIdx);
+ await putGroupAsFinished(ws, tx, recoupGroup, coinIdx);
},
);
@@ -227,7 +241,7 @@ async function recoupRefreshCoin(
return;
}
- const refreshGroupId = await ws.db.runWithWriteTransaction(
+ await ws.db.runWithWriteTransaction(
[Stores.coins, Stores.reserves, Stores.recoupGroups, Stores.refreshGroups],
async (tx) => {
const recoupGroup = await tx.get(Stores.recoupGroups, recoupGroupId);
@@ -254,22 +268,12 @@ async function recoupRefreshCoin(
"recoup: setting old coin amount to",
Amounts.toString(oldCoin.currentAmount),
);
+ recoupGroup.scheduleRefreshCoins.push(oldCoin.coinPub);
await tx.put(Stores.coins, revokedCoin);
await tx.put(Stores.coins, oldCoin);
- await putGroupAsFinished(tx, recoupGroup, coinIdx);
- return await createRefreshGroup(
- tx,
- [{ coinPub: oldCoin.coinPub }],
- RefreshReason.Recoup,
- );
+ await putGroupAsFinished(ws, tx, recoupGroup, coinIdx);
},
);
-
- if (refreshGroupId) {
- processRefreshGroup(ws, refreshGroupId.refreshGroupId).then((e) => {
- console.error("error while refreshing after recoup", e);
- });
- }
}
async function resetRecoupGroupRetry(
@@ -340,17 +344,18 @@ export async function createRecoupGroup(
recoupFinishedPerCoin: coinPubs.map(() => false),
// Will be populated later
oldAmountPerCoin: [],
+ scheduleRefreshCoins: [],
};
for (let coinIdx = 0; coinIdx < coinPubs.length; coinIdx++) {
const coinPub = coinPubs[coinIdx];
const coin = await tx.get(Stores.coins, coinPub);
if (!coin) {
- await putGroupAsFinished(tx, recoupGroup, coinIdx);
+ await putGroupAsFinished(ws, tx, recoupGroup, coinIdx);
continue;
}
if (Amounts.isZero(coin.currentAmount)) {
- await putGroupAsFinished(tx, recoupGroup, coinIdx);
+ await putGroupAsFinished(ws, tx, recoupGroup, coinIdx);
continue;
}
recoupGroup.oldAmountPerCoin[coinIdx] = coin.currentAmount;
diff --git a/src/types/dbTypes.ts b/src/types/dbTypes.ts
index c8c4ed61..5a0a653e 100644
--- a/src/types/dbTypes.ts
+++ b/src/types/dbTypes.ts
@@ -1397,8 +1397,19 @@ export interface RecoupGroupRecord {
*/
recoupFinishedPerCoin: boolean[];
+ /**
+ * We store old amount (i.e. before recoup) of recouped coins here,
+ * as the balance of a recouped coin is set to zero when the
+ * recoup group is created.
+ */
oldAmountPerCoin: AmountJson[];
+ /**
+ * Public keys of coins that should be scheduled for refreshing
+ * after all individual recoups are done.
+ */
+ scheduleRefreshCoins: string[];
+
/**
* Retry info.
*/
diff --git a/src/types/history.ts b/src/types/history.ts
index f4a1d063..b1ac0ef9 100644
--- a/src/types/history.ts
+++ b/src/types/history.ts
@@ -349,6 +349,7 @@ export interface HistoryFundsDepositedToSelfEvent {
*/
export interface HistoryFundsRecoupedEvent {
type: HistoryEventType.FundsRecouped;
+ numCoinsRecouped: number;
}
/**
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: generate cleaner history for recoup,
gnunet <=