gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-typescript-core] branch master updated: wallet-core: only transit


From: gnunet
Subject: [taler-typescript-core] branch master updated: wallet-core: only transition exchange entry if update is really required
Date: Tue, 14 Jan 2025 21:05:15 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository taler-typescript-core.

The following commit(s) were added to refs/heads/master by this push:
     new b57f85019 wallet-core: only transition exchange entry if update is 
really required
b57f85019 is described below

commit b57f850195d951db1de88c97e15a669e5d2e805b
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue Jan 14 21:05:11 2025 +0100

    wallet-core: only transition exchange entry if update is really required
---
 packages/taler-wallet-core/src/exchanges.ts | 150 ++++++++++++++--------------
 1 file changed, 75 insertions(+), 75 deletions(-)

diff --git a/packages/taler-wallet-core/src/exchanges.ts 
b/packages/taler-wallet-core/src/exchanges.ts
index bcb83d885..45b136c5e 100644
--- a/packages/taler-wallet-core/src/exchanges.ts
+++ b/packages/taler-wallet-core/src/exchanges.ts
@@ -1155,95 +1155,95 @@ async function startUpdateExchangeEntry(
       return provideExchangeRecordInTx(wex.ws, tx, exchangeBaseUrl);
     },
   );
-
-  logger.trace("created exchange record");
-
   if (notification) {
     wex.ws.notify(notification);
   }
 
-  const { oldExchangeState, newExchangeState, taskId } =
-    await wex.db.runReadWriteTx(
-      { storeNames: ["exchanges", "operationRetries", "denominations"] },
-      async (tx) => {
-        const r = await tx.exchanges.get(exchangeBaseUrl);
-        if (!r) {
-          throw Error("exchange not found");
-        }
-
-        // FIXME: Do not transition at all if the exchange info is recent 
enough
-        // and the request is not forced.
+  const res = await wex.db.runReadWriteTx(
+    { storeNames: ["exchanges", "operationRetries", "denominations"] },
+    async (tx) => {
+      const r = await tx.exchanges.get(exchangeBaseUrl);
+      if (!r) {
+        throw Error("exchange not found");
+      }
 
-        const oldExchangeState = getExchangeState(r);
-        switch (r.updateStatus) {
-          case ExchangeEntryDbUpdateStatus.UnavailableUpdate:
-            r.cachebreakNextUpdate = options.forceUpdate;
-            break;
-          case ExchangeEntryDbUpdateStatus.Suspended:
-            r.cachebreakNextUpdate = options.forceUpdate;
-            break;
-          case ExchangeEntryDbUpdateStatus.ReadyUpdate: {
-            const outdated = await checkExchangeEntryOutdated(
-              wex,
-              tx,
-              exchangeBaseUrl,
-            );
-            if (outdated) {
-              r.updateStatus = ExchangeEntryDbUpdateStatus.OutdatedUpdate;
-            } else {
-              r.updateStatus = ExchangeEntryDbUpdateStatus.ReadyUpdate;
-            }
-            r.cachebreakNextUpdate = options.forceUpdate;
-            break;
+      const oldExchangeState = getExchangeState(r);
+      switch (r.updateStatus) {
+        case ExchangeEntryDbUpdateStatus.UnavailableUpdate:
+          r.cachebreakNextUpdate = options.forceUpdate;
+          break;
+        case ExchangeEntryDbUpdateStatus.Suspended:
+          r.cachebreakNextUpdate = options.forceUpdate;
+          break;
+        case ExchangeEntryDbUpdateStatus.ReadyUpdate: {
+          const outdated = await checkExchangeEntryOutdated(
+            wex,
+            tx,
+            exchangeBaseUrl,
+          );
+          if (outdated) {
+            r.updateStatus = ExchangeEntryDbUpdateStatus.OutdatedUpdate;
+          } else {
+            r.updateStatus = ExchangeEntryDbUpdateStatus.ReadyUpdate;
           }
-          case ExchangeEntryDbUpdateStatus.OutdatedUpdate:
-            r.cachebreakNextUpdate = options.forceUpdate;
-            break;
-          case ExchangeEntryDbUpdateStatus.Ready: {
-            const nextUpdateTimestamp = AbsoluteTime.fromPreciseTimestamp(
-              timestampPreciseFromDb(r.nextUpdateStamp),
-            );
-            // Only update if entry is outdated or update is forced.
-            if (
-              options.forceUpdate ||
-              AbsoluteTime.isExpired(nextUpdateTimestamp)
-            ) {
-              const outdated = await checkExchangeEntryOutdated(
-                wex,
-                tx,
-                exchangeBaseUrl,
-              );
-              if (outdated) {
-                r.updateStatus = ExchangeEntryDbUpdateStatus.OutdatedUpdate;
-              } else {
-                r.updateStatus = ExchangeEntryDbUpdateStatus.ReadyUpdate;
-              }
-              r.cachebreakNextUpdate = options.forceUpdate;
-            }
-            break;
+          r.cachebreakNextUpdate = options.forceUpdate;
+          break;
+        }
+        case ExchangeEntryDbUpdateStatus.OutdatedUpdate:
+          r.cachebreakNextUpdate = options.forceUpdate;
+          break;
+        case ExchangeEntryDbUpdateStatus.Ready: {
+          const nextUpdateTimestamp = AbsoluteTime.fromPreciseTimestamp(
+            timestampPreciseFromDb(r.nextUpdateStamp),
+          );
+          // Only update if entry is outdated or update is forced.
+          if (
+            !(
+              options.forceUpdate || 
AbsoluteTime.isExpired(nextUpdateTimestamp)
+            )
+          ) {
+            return undefined;
           }
-          case ExchangeEntryDbUpdateStatus.Initial:
-            r.cachebreakNextUpdate = options.forceUpdate;
-            r.updateStatus = ExchangeEntryDbUpdateStatus.InitialUpdate;
-            break;
-          case ExchangeEntryDbUpdateStatus.InitialUpdate:
-            r.cachebreakNextUpdate = options.forceUpdate;
-            break;
+          const outdated = await checkExchangeEntryOutdated(
+            wex,
+            tx,
+            exchangeBaseUrl,
+          );
+          if (outdated) {
+            r.updateStatus = ExchangeEntryDbUpdateStatus.OutdatedUpdate;
+          } else {
+            r.updateStatus = ExchangeEntryDbUpdateStatus.ReadyUpdate;
+          }
+          r.cachebreakNextUpdate = options.forceUpdate;
+          break;
         }
-        wex.ws.exchangeCache.clear();
-        await tx.exchanges.put(r);
-        const newExchangeState = getExchangeState(r);
-        const taskId = TaskIdentifiers.forExchangeUpdate(r);
-        return { oldExchangeState, newExchangeState, taskId };
-      },
-    );
+        case ExchangeEntryDbUpdateStatus.Initial:
+          r.cachebreakNextUpdate = options.forceUpdate;
+          r.updateStatus = ExchangeEntryDbUpdateStatus.InitialUpdate;
+          break;
+        case ExchangeEntryDbUpdateStatus.InitialUpdate:
+          r.cachebreakNextUpdate = options.forceUpdate;
+          break;
+      }
+      wex.ws.exchangeCache.clear();
+      await tx.exchanges.put(r);
+      const newExchangeState = getExchangeState(r);
+      const taskId = TaskIdentifiers.forExchangeUpdate(r);
+      return { oldExchangeState, newExchangeState, taskId };
+    },
+  );
+  if (!res) {
+    // Exchange entry is already good.
+    return;
+  }
+  const { oldExchangeState, newExchangeState, taskId } = res;
   wex.ws.notify({
     type: NotificationType.ExchangeStateTransition,
     exchangeBaseUrl,
     newExchangeState: newExchangeState,
     oldExchangeState: oldExchangeState,
   });
-  logger.info(`start update ${exchangeBaseUrl} task ${taskId}`);
+  logger.info(`updating exchange in task ${taskId}`);
 
   await wex.taskScheduler.resetTaskRetries(taskId);
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]