taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

delete-transaction-requeries-deleted-id.md (4814B)


      1 <!--
      2   This file is part of GNU Taler
      3   (C) 2026 Taler Systems S.A.
      4 
      5   GNU Taler is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13   You should have received a copy of the GNU General Public License along with
     14   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 -->
     16 
     17 # Deleting a transaction makes the app immediately ask wallet-core for it again
     18 
     19 Found by the `history_delete` scenario, which reproduces it on **every run** —
     20 five rounds so far, three stray requests each.
     21 
     22 **Severity: low.** Nothing visible goes wrong — the row disappears and the user
     23 is returned to the list — but every deletion leaves an error in the log, which
     24 is noise in exactly the place one looks when triaging a real problem.
     25 
     26 ## What happens
     27 
     28 Deleting a transaction from its detail screen deletes it, and then the screen
     29 asks for it once more:
     30 
     31 ```
     32 {"type":"error","operation":"getTransactionById","id":78,
     33  "error":{"code":7052,
     34           "hint":"transaction txn:payment:7W5B3DR0…X5Z0 not found",
     35           "transactionId":"txn:payment:7W5B3DR0…X5Z0"}}
     36 ```
     37 
     38 wallet-core also records it as a failed database query
     39 (`db-query-finish-error` at `handleTxRetries/runWalletDbTx`). Three such
     40 requests go out per deletion, consistently:
     41 
     42 ```console
     43 $ for d in /opt/taler-sim/run/out/*history_delete; do
     44     echo "$(basename $d): $(grep -c '"code":7052' $d/logcat.txt)"; done
     45 suite-w1-1792268945-history_delete: 3
     46 suite-w1-1792270256-history_delete: 3
     47 suite-w1-1792272286-history_delete: 3
     48 suite-w1-1792274698-history_delete: 3
     49 suite-w1-1792277245-history_delete: 3
     50 ```
     51 
     52 The error code makes it worse: 7052 (`WALLET_TRANSACTION_NOT_FOUND`) is not in
     53 the app's `TalerErrorCode.kt`, so even if the app wanted to recognise this case
     54 it could not — see `error-code-registry-behind-wallet-core.md`.
     55 
     56 ## Reproduce by hand
     57 
     58 1. Install a debug build, enable **Developer mode** in Settings.
     59 2. Get a transaction into the wallet: withdraw once, or pay for something
     60    (against the local stack from `simulator/README.md`, or any deployment).
     61 3. Start `adb logcat | grep -E 'getTransactionById|7052'` in a terminal.
     62 4. On the main screen, under **Recent transactions**, tap the transaction.
     63 5. On the detail screen tap **Delete**, then confirm **Delete** in the dialog.
     64 
     65 The list comes back without the row, and the log shows the
     66 `getTransactionById` request for the id that was just deleted, answered with
     67 "transaction … not found".
     68 
     69 ## Reproduce with the simulator
     70 
     71 ```bash
     72 ssh root@tripwire.taler.net
     73 cd /opt/taler-sim/driver
     74 python3 ../findings/repro_delete_requeries_transaction.py
     75 ```
     76 
     77 Prints the stray error lines and `reproduced: True`.
     78 
     79 ## Why
     80 
     81 Not the detail screen's observer, which is what this finding first said — the
     82 requests come from the notification handler, and clearing the selection would
     83 not stop one of them.
     84 
     85 Deleting a transaction makes wallet-core emit transaction-state-transition
     86 notifications for it, and the handler asks for the transaction *before* it can
     87 know what the transition was:
     88 
     89 ```kotlin
     90 // wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt:170
     91 fun onTransactionStateTransition(transactionId: String) = scope.launch {
     92     val transaction = getTransactionById(transactionId)      // 7052 after a delete
     93     …
     94     if (transaction == null) return@launch
     95 ```
     96 
     97 It needs the transaction for two things — refreshing the copy the detail screen
     98 is showing, and learning which scopes' lists to reload — and after a deletion
     99 neither applies, but the query has already gone out. A deletion emits several
    100 transitions, which is why exactly three requests appear rather than one.
    101 
    102 `getTransactionById` then logs every failure at error level
    103 (`Log.e(TAG, "Error getting transaction $it")`), so each one lands in the log
    104 as an error.
    105 
    106 ## Suggested fix
    107 
    108 Remember the ids this wallet has just deleted and let the handler skip them:
    109 the transaction is gone, so there is nothing to refresh and no scope to
    110 reload. A small bounded set is enough — an id cannot come back, and only the
    111 transitions that follow the deletion matter.
    112 
    113 Treating 7052 as an expected outcome instead would also work, but the app
    114 cannot currently recognise it: `WALLET_TRANSACTION_NOT_FOUND` is not in
    115 `TalerErrorCode.kt`, so the code does not survive deserialization (see
    116 `error-code-registry-behind-wallet-core.md`). That makes the id-based fix the
    117 one that can be written today.