aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-11-07 11:52:08 +0100
committerFlorian Dold <florian@dold.me>2023-11-07 11:52:08 +0100
commit96e8ba5c239c8bcb40cbe330ee599b132005e4de (patch)
treef499c0ac7b1a0c1f592d615fb4a9ff6d7b2f409d /packages/taler-wallet-core
parent7436d8d8612006b5f7917c63ee6bfe18b06281c9 (diff)
downloadwallet-core-96e8ba5c239c8bcb40cbe330ee599b132005e4de.tar.xz
wallet-core: throttle tasks
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r--packages/taler-wallet-core/src/operations/pending.ts6
-rw-r--r--packages/taler-wallet-core/src/pending-types.ts5
-rw-r--r--packages/taler-wallet-core/src/wallet.ts25
3 files changed, 31 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts
index 7590280bc..e30958226 100644
--- a/packages/taler-wallet-core/src/operations/pending.ts
+++ b/packages/taler-wallet-core/src/operations/pending.ts
@@ -538,6 +538,7 @@ async function gatherPeerPullInitiationPending(
givesLifeness: true,
retryInfo: retryRecord?.retryInfo,
pursePub: pi.pursePub,
+ internalOperationStatus: `0x${pi.status.toString(16)}`,
});
},
);
@@ -579,12 +580,17 @@ async function gatherPeerPullDebitPending(
const timestampDue =
timestampOptionalAbsoluteFromDb(retryRecord?.retryInfo.nextRetry) ??
AbsoluteTime.now();
+ // switch (pi.status) {
+ // case PeerPullDebitRecordStatus.DialogProposed:
+ // return;
+ // }
resp.pendingOperations.push({
type: PendingTaskType.PeerPullDebit,
...getPendingCommon(ws, opId, timestampDue),
givesLifeness: true,
retryInfo: retryRecord?.retryInfo,
peerPullDebitId: pi.peerPullDebitId,
+ internalOperationStatus: `0x${pi.status.toString(16)}`,
});
},
);
diff --git a/packages/taler-wallet-core/src/pending-types.ts b/packages/taler-wallet-core/src/pending-types.ts
index e7a40e81b..f8406033a 100644
--- a/packages/taler-wallet-core/src/pending-types.ts
+++ b/packages/taler-wallet-core/src/pending-types.ts
@@ -234,6 +234,11 @@ export interface PendingTaskInfoCommon {
* exceeds a number of retries.
*/
retryInfo?: DbRetryInfo;
+
+ /**
+ * Internal operation status for debugging.
+ */
+ internalOperationStatus?: string;
}
/**
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index e917e8059..978ce4c39 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -133,6 +133,8 @@ import {
ListExchangesForScopedCurrencyRequest,
ExchangesShortListResponse,
AmountString,
+ RequestThrottler,
+ TaskThrottler,
} from "@gnu-taler/taler-util";
import type { HttpRequestLibrary } from "@gnu-taler/taler-util/http";
import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http";
@@ -424,6 +426,7 @@ async function runTaskLoop(
"task loop already running, nesting the wallet-core task loop is deprecated and should be avoided",
);
}
+ const throttler = new TaskThrottler();
ws.isTaskLoopRunning = true;
let retriesExceeded = false;
for (let iteration = 0; !ws.stopped; iteration++) {
@@ -431,6 +434,7 @@ async function runTaskLoop(
logger.trace(`pending operations: ${j2s(pending)}`);
let numGivingLiveness = 0;
let numDue = 0;
+ let numThrottled = 0;
let minDue: AbsoluteTime = AbsoluteTime.never();
for (const p of pending.pendingOperations) {
@@ -449,12 +453,23 @@ async function runTaskLoop(
if (!p.isDue) {
continue;
}
- minDue = AbsoluteTime.min(minDue, p.timestampDue);
numDue++;
+
+ const isThrottled = throttler.applyThrottle(p.id);
+
+ if (isThrottled) {
+ logger.warn(
+ `task ${p.id} throttled, this is very likely a bug in wallet-core, please report`,
+ );
+ numDue--;
+ numThrottled++;
+ } else {
+ minDue = AbsoluteTime.min(minDue, p.timestampDue);
+ }
}
logger.trace(
- `running task loop, iter=${iteration}, #tasks=${pending.pendingOperations.length} #lifeness=${numGivingLiveness}, #due=${numDue}`,
+ `running task loop, iter=${iteration}, #tasks=${pending.pendingOperations.length} #lifeness=${numGivingLiveness}, #due=${numDue} #trottled=${numThrottled}`,
);
if (opts.stopWhenDone && numGivingLiveness === 0 && iteration !== 0) {
@@ -932,9 +947,9 @@ async function dumpCoins(ws: InternalWalletState): Promise<CoinDumpJson> {
ageCommitmentProof: c.ageCommitmentProof,
spend_allocation: c.spendAllocation
? {
- amount: c.spendAllocation.amount,
- id: c.spendAllocation.id,
- }
+ amount: c.spendAllocation.amount,
+ id: c.spendAllocation.id,
+ }
: undefined,
});
}