diff --git a/CLI-AUTOMATION-NOTES.md b/CLI-AUTOMATION-NOTES.md index 22f75e5..937fed0 100644 --- a/CLI-AUTOMATION-NOTES.md +++ b/CLI-AUTOMATION-NOTES.md @@ -9,7 +9,7 @@ Companions: - Android GUI → [`android-test/GUI-AUTOMATION-NOTES.md`](./android-test/GUI-AUTOMATION-NOTES.md) - Git / suite tree → [`VERSIONS.md`](./VERSIONS.md) -Scripts: `check_e2e.sh`, `check_amount_ladder.sh`, `taler-monitoring.sh`. +Scripts: `check_e2e.sh`, `check_goa_ladder.sh`, `taler-monitoring.sh`. Legend: @@ -47,82 +47,15 @@ Legend: --- -## 3. `reserve_pub` / force-select is fragile (5114 + empty scrape) +## 3. `reserve_pub` / force-select is fragile (5114) | | | |--|--| -| **Seen** | ladder force-select, e2e confirm path, Android spinner issues; **repro 2026-07-19 magikoopa** GOA ladder: `force-select skipped · no reserve_pub for this withdraw (WID=…); wallet may not have selected yet` | -| **Area** | **cli** / **core** / **bank** / **ops** | -| **Problem** | (a) Cumulative wallets re-emit old reserves; binding the wrong `reserve_pub` yields **HTTP 409 / code 5114** (“already bound”). (b) Automation scrapes accept/tx dumps for candidates — when the dump has **no** pub at all, ladder WARNs and skips force-select (soft), then often **SKIP_CONFIRM**. (c) Empty scrape is **not** the same as “bank out of money”; do not treat as balance failure. (d) **Mon bug (fixed v1.20.2):** extract used `json.loads(file_from_first_brace)` on wallet dumps that append log lines after JSON → **zero** objects parsed; regex only scanned accept (which has no `reservePub`) while the pub lives under `transactions[].withdrawalDetails.reservePub`. | -| **Workaround** | **Mon ≥1.20.2:** `JSONDecoder.raw_decode` + regex on accept **and** transactions; score by WID in `bankConfirmationUrl` / amount. Still: score pubs by WID/amount; try several; treat 5114 as “stale reserve” not “out of money”. Refresh `transactions` before each force-select try. Soft-skip confirm if still pending after polls. Fix wallet DB / helper first if accept/tx only print FATAL (see §15–16). | -| **Wanted** | CLI returns **the** `reserve_pub` for the just-accepted withdraw in structured JSON; `force-select` / bank-side select API documented with idempotency. Optional: bank integration already exposes `selected_reserve_pub` when wallet selected — prefer that over scraping wallet logs. | - -### 3a. Ladder pin amounts hide mid-range behaviour - -| | | -|--|--| -| **Seen** | `LADDER_STEPS=3` plan collapses to pins only: `GOA:0`, `max-1`, `max` (no random mid rungs) | -| **Area** | **ops** / **bank** / **cli** | -| **Problem** | **Zero** withdraw often never produces a usable `reserve_pub` / coins (wallet 7006 or no denoms). **Absolute max** and sometimes **max-1** hit **mint HTTP 500 / code 5110** SQL `P0001` (ceiling probe). Reproducing “real” force-select needs a **mid** amount (e.g. `GOA:1` … exchange min denom scale), not only pins. | -| **Workaround** | Use `LADDER_STEPS≥5` (or higher) so random mids exist; treat zero / absolute-max / max-1-5110 as probes (soft `CEILING_REJECT` in mon ≥1.20.2). | -| **Wanted** | Ladder plan docs: pin vs mid semantics; CLI structured error for amount-too-large / zero. | - -### 3b. We do **not** manage to withdraw **in time** (GOA) — bank path unreliable, not load - -| | | -|--|--| -| **Bottom line** | On live **hacktivism GOA**, automation **does not get spendable coins in time** for the pay phase (default wait **90 s**). Max-search may report a “best” amount and bank may even show `transfer_done`; pay still sees **`available=GOA:0`** with large **`pendingIncoming`**. Coins might arrive **later** (wirewatch / wallet) — **at least not within mon’s budget**. Recurring (several runs, 2026-07-19). | -| **Area** | **bank** + wire/wallet settle — **not** mon overload, **not** “laptop too slow” | -| **Not the cause: ecosystem load** | Outside-in check **2026-07-19 ~14:56 CEST**: bank/exchange/merchant all **HTTP 200**, config ~**50–150 ms**, exchange `/keys` ~**0.5 s**. Container **loadavg ~1.5–1.7**, RSS bank **~737 MiB** / exchange **~670 MiB**, bank probes **47 ms**, **`wirewatch_running: true`**. Stack is **healthy under moderate load** — failures are **application/SQL/protocol**, not “host on fire.” | -| **Call site (mint)** | `POST ${BANK}/accounts/explorer/withdrawals` → often HTTP **500** `{ code: 5110, hint: "Unexpected sql error with state P0001" }` (**`BANK_UNMANAGED_EXCEPTION`**; Postgres **`P0001`** = `RAISE EXCEPTION`). Should often be clean **409** (insufficient funds); instead opaque **500**. | -| **Config** | `/config` still allows ~**2⁵²** wire max; live mint fails **far below** that. Explorer **balance_explorer** on landing still **~4.5 Peta-GOA**. | - -#### Analysis — where withdraw dies - -| Stage | What we see | Manage to withdraw? | -|-------|-------------|---------------------| -| **Mint (high amounts)** | 5110/P0001 while hi falls Tera→Giga→Mega→Kilo with **lo=0** | **No** — withdrawal never created | -| **Mint (some mid amounts)** | occasional **HTTP 200** + URI | Mint only — not done | -| **Confirm** | force-select 200 then stuck **`selected`**, confirm **HTTP 500** → mon **`SKIP_CONFIRM`** (bounds unchanged) | **No** — bank never wires; **not** out-of-money (§3 / 5114 class) | -| **Bank settle** | rare full path: confirm 204 + `transfer_done` | Bank side “OK_BANK” | -| **Wallet coins** | almost always **`available=0`** within wait, large **`pendingIncoming`**, board **`done=0`** | **Not in time** for pay → **SKIP_BALANCE** / skip max-pay | - -**Pay-wait board (same cumulative wallet), example:** - -```text -summary: tsv_ok=2 · wallet_wd=14 (pendingIncoming=14 done=0) -timer 0s left — available still GOA:0 -pendingIncoming=GOA:335776 -``` - -Reading: only **2** TSV rows are full OK/OK_BANK, but the wallet holds **14** withdrawal txs still **pendingIncoming** and **none done** after the wait. Max-search also leaves many **mint-OK / confirm-failed** withdraws that **inflate pendingIncoming** and may never complete. After **90 s** + short `run-pending`: **still no spendable balance** → **we do not manage to withdraw in time** for pay (whether coins would appear later is unknown to the job). - -#### What *did* work (sparse) — for contrast - -| When / run | What worked | Amounts | -|------------|-------------|---------| -| Landing **2026-07-19 14:19–14:29 CEST** | Explorer singles **recorded** on bank intro stats | **~1.5–2 Giga-GOA**, **~145–202 Mega-GOA**, **~1.8–3.4 Mega-GOA** | -| Max-search run A (same day) | Full bank path (mint→confirm→`transfer_done`) for **two** amounts only; mon best | **`GOA:424114`**, **`GOA:822256`** (~822 Kilo best) | -| Max-search run B (later) | Even fewer full successes; many mint OK + **SKIP_CONFIRM**; mon best collapsed | e.g. full success around **`GOA:12276`** / **`GOA:17257`** (~**17 Kilo** best) | -| Pay after either | Spendable **available** within **90 s** | **`GOA:0`** (not in time) | - -So: **landing/history prove large withdraws were possible earlier the same day**; **automation does not manage a usable withdraw in time** (best amount drops run-to-run; coins not available inside mon’s wait). - -#### Mon behaviour (workaround only) - -- 5110 → soft **`CEILING_REJECT`** / max-search **`hi:=`** -- Full OK only raises **`lo`**; **SKIP_CONFIRM** does not -- Pay waits up to **`LADDER_PAY_WAIT_AVAILABLE_S`** (default 90) with withdraw board; then **SKIP_BALANCE** if still 0 -- **Does not fix** bank SQL mapping, stuck confirm, or wirewatch→coins lag - -#### Wanted (bank / exchange ops) - -1. Map mint **P0001** to structured errors (not **5110**). -2. Confirm after force-select must not stick **selected** + HTTP 500. -3. After `transfer_done`, coins must become wallet **available** (or document delay + API to wait). -4. File bugs with: max-search “what worked” table + landing `recent_withdraws`/`balance_explorer` + load note (healthy) + pay board `tsv_ok` vs `wallet_wd`/`pendingIncoming`/`done`. - -Sources: `https://bank.hacktivism.ch/intro/stats.json`, exchange/merchant intro stats, mon max-ladder logs 2026-07-19. +| **Seen** | ladder force-select, e2e confirm path, Android spinner issues | +| **Area** | **cli** / **core** / **bank** | +| **Problem** | Cumulative wallets re-emit old reserves; binding the wrong `reserve_pub` yields **HTTP 409 / code 5114** (“already bound”). Automation scrapes accept/tx dumps for candidates. | +| **Workaround** | Score pubs by WID/amount; try several; treat 5114 as “stale reserve” not “out of money”. | +| **Wanted** | CLI returns **the** `reserve_pub` for the just-accepted withdraw in structured JSON; `force-select` / bank-side select API documented with idempotency. | --- @@ -133,7 +66,7 @@ Sources: `https://bank.hacktivism.ch/intro/stats.json`, exchange/merchant intro | **Seen** | Android endless spinner; GOA `bank.hacktivism.ch` withdraw; fixed in app branch `fix/bank-withdraw-auto-exchange` | | **Area** | **core** / **cli** | | **Problem** | Withdraw URI names an exchange the wallet has never added → stuck loading / empty exchange list. CLI requires explicit `exchanges add` + `update` + `accept-tos` every fresh DB. | -| **Workaround** | e2e always adds exchange before bank withdraw ladder; Android needs ensureExchange-style fix. | +| **Workaround** | e2e always adds exchange before ATM ladder; Android needs ensureExchange-style fix. | | **Wanted** | CLI/core: on `accept-uri` withdraw, **auto-add** exchange from URI/bank details (`allowCompletion`), then surface ToS if needed in one command. | --- @@ -145,8 +78,8 @@ Sources: `https://bank.hacktivism.ch/intro/stats.json`, exchange/merchant intro | **Seen** | ladder/e2e strip ports; QR checks; mint URIs with `:443` | | **Area** | **cli** / **bank** / **doc** | | **Problem** | Some bank/wallet outputs include `taler://…host:443/…`. QR validators and some clients reject or double-normalize inconsistently. | -| **Workaround** | mon ≥1.23.4: `normalize_taler_uri` (lib.sh) on ladder/e2e/pay; bank landing `demo-withdraw-api.py` normalizes mint JSON; **urls** phase fails GOA/local if public landings still emit `:443`/`:80` in `taler://` (`www.taler-uri-ports-*`, unit `tests/test_normalize_taler_uri.sh`). | -| **Wanted** | libeufin never emits default ports (source fix). | +| **Workaround** | `sed 's/:443\//\//g'` everywhere in automation. | +| **Wanted** | Canonical form without default ports in **all** wallet-cli and bank integration outputs; document as invariant. | --- @@ -154,7 +87,7 @@ Sources: `https://bank.hacktivism.ch/intro/stats.json`, exchange/merchant intro | | | |--|--| -| **Seen** | e2e uses bank admin + bank withdraw create; ladder/gui-chain reimplement explorer mint in Python | +| **Seen** | e2e uses bank admin + ATM create; ladder/gui-chain reimplement explorer mint in Python | | **Area** | **cli** / **ops** | | **Problem** | Automation always hand-rolls Basic auth → token → `POST …/withdrawals` → `taler_withdraw_uri`. Easy to get wrong (auth header, amount currency). | | **Workaround** | Shared Python in `goa-chain` / ladder / e2e; secrets files. | @@ -258,59 +191,6 @@ Sources: `https://bank.hacktivism.ch/intro/stats.json`, exchange/merchant intro --- -## 15. `--wallet-db=*.json` is rejected (“memory backend not supported”) - -| | | -|--|--| -| **Seen** | **2026-07-19 magikoopa** wallet-cli **1.6.8** / **1.6.11** bundle: any command with `--wallet-db=/tmp/foo.json` fails immediately with `Error: memory backend not supported` | -| **Area** | **cli** / **ops** | -| **Problem** | Current node host treats storage paths ending in **`.json` as unsupported memory backend** and throws before opening sqlite. Old notes / local tests that used `WALLET_DB=….json` break. Accept/transactions then never emit `reserve_pub` → ladder §3 empty-scrape WARNs. | -| **Workaround** | Use a **non-`.json` path**, e.g. `--wallet-db=$SCRATCH/wallet.sqlite3` (ladder already prefers `wallet.sqlite3`). Never pass `….json` as wallet-db. | -| **Wanted** | Clearer error: `wallet-db path must not end in .json; use a directory or .sqlite3 path`. Document legal path forms in `--help`. | - ---- - -## 16. `taler-helper-sqlite3` requires Python ≥ 3.11 on PATH - -| | | -|--|--| -| **Seen** | magikoopa: helper is a **Python** script (`#!/usr/bin/env python3`); with Apple `/usr/bin/python3` **3.9.6** → `FATAL: python version >=3.11 required but running on 3.9.6` in accept/tx logs; wallet may still exit 0 on some paths while stdout is FATAL-only | -| **Area** | **ops** / **cli** | -| **Problem** | Wallet spawns `taler-helper-sqlite3` from **PATH**. Wrong `python3` ⇒ sqlite backend fails ⇒ no real wallet state ⇒ no `reserve_pub` for force-select. | -| **Workaround** | Put **Python ≥3.11** (or 3.12+) first on PATH for mon jobs; ensure `command -v taler-helper-sqlite3` works; smoke: `taler-helper-sqlite3` starts without FATAL. Prefer Homebrew / user `python3.11+` over macOS system 3.9 for agent PATH. | -| **Wanted** | Helper shebang or wrapper that finds a suitable python; wallet preflight error if helper HELLO fails (not silent empty logs). | - ---- - -## 17. Portable wall-clock for scripts (no GNU `timeout` assumed) - -| | | -|--|--| -| **Seen** | macOS agent shells: `timeout: command not found`; e2e already tries `timeout` then `gtimeout` then `perl -e alarm` | -| **Area** | **ops** / **doc** | -| **Problem** | GNU coreutils `timeout` is not on stock macOS. Hard-wiring it breaks portable repro and CI on Darwin. | -| **Workaround** | Prefer **python3** `subprocess.Popen(…).wait(timeout=…)` for outer budgets; for wallet-cli inner calls keep e2e order: `timeout` → `gtimeout` → perl alarm. Document both. | -| **Wanted** | One suite helper `run_with_budget SECS cmd…` in `lib.sh` used by ladder/e2e/smoke. | - ---- - -## 18. How to withdraw (operator checklist, GOA laptop) - -Portable path that works when §§15–16 are fixed: - -1. **PATH:** `taler-helper-sqlite3` + **python3 ≥ 3.11** ahead of system 3.9. -2. **Wallet DB:** `WDB=$TMP/wallet.sqlite3` — **not** `*.json`. -3. **Exchange:** `exchanges add` → `update -f` → `accept-tos` for `https://exchange.hacktivism.ch/`. -4. **Bank mint (explorer):** token with explorer password from `SECRETS_ROOT` / `EXP_PW`; `POST …/accounts/explorer/withdrawals` with e.g. `{"amount":"GOA:1"}` (avoid pure **0** and absolute **max** pins for happy-path tests). -5. **Strip** `:443` from `taler_withdraw_uri`. -6. **`withdraw accept-uri --exchange URL URI`**. -7. **Bank:** poll `…/taler-integration/withdrawal-operation/{WID}` → when `selected`, confirm; if stuck `pending`, force-select with scraped `reserve_pub` (§3). -8. **Settle:** poll wallet balance / bank `transfer_done` — **no** `run-until-done` (§1). - -If step 6’s stdout is only `FATAL: python version…` or `memory backend not supported`, **stop** and fix §15–16 before debugging force-select. - ---- - ## Priority shortlist for `taler-wallet-cli` / core If only a few changes land, these unlock the most automation: @@ -320,7 +200,6 @@ If only a few changes land, these unlock the most automation: 3. **Auto-add exchange + ToS on accept-uri** (§4, §8) 4. **Canonical URIs without :443** (§5) 5. **Emit reserve_pub for last withdraw** (§3) -6. **Clear wallet-db path rules + helper preflight** (§15, §16) --- @@ -333,12 +212,7 @@ If only a few changes land, these unlock the most automation: | exchange | Explicit add/update/accept-tos | | ladder explorer | `read_secret` / EXP_PW_FILE | | stage maxima | bank `max_wire` + keys min denom | -| force-select | multi-rpub try; soft-skip confirm; empty scrape → WARN not balance fail | -| higher amounts / withdraw fail | **§3b: we do not manage to withdraw in time** on GOA (healthy load); mint 5110/P0001 + SKIP_CONFIRM + pendingIncoming; pay still available=0 after 90s; landing had Giga/Mega earlier same day | -| pay vs balance | never order more than wallet **available** (soft `SKIP_BALANCE`); pendingIncoming does not count as spendable | -| pay wait UX | board: OK/OK_BANK start order + live pendingIncoming/`done`; often `tsv_ok≪wallet_wd` and **done=0** after 90s → skip pay | -| wallet-db path | Prefer `*.sqlite3` (never `*.json` as db path) | -| helper / python | mon PATH must include helper + python≥3.11 | +| force-select | multi-rpub try; soft-skip confirm | --- diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index 8e07f59..8823098 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -41,13 +41,9 @@ command -v qrencode zbarimg | `jq` | nice-to-have; suite uses python3 for JSON | | `dig` / `bind-utils` | debug DNS; not required for default phases | | `ssh` | only for access mode **ssh** (laptop → `KOOPA_SSH` / stage `INSIDE_SSH`); not needed for **host-podman** | -| `node` + `taler-wallet-cli` (.mjs) | **e2e** / ladder only (+ secrets) | -| **`taler-helper-sqlite3` on PATH** | **required for e2e** — wallet-core spawns it for withdraw accept-uri / pay; missing → ENOENT mid-ladder. Put next to wallet bindir (`~/.local/bin` on stagepaysan) | -| `timeout` (coreutils) | preferred hard wall for `wcli` (suite falls back to perl only if missing) | +| `node` / `pnpm` + wallet-cli | **e2e** / ladder only (+ secrets) | | `secrets.env` / admin passwords | e2e only — never system packages | -**Preflight (agents / ops):** before trusting e2e on a host, smoke on the **same PATH** mon uses (`run-host-report` / systemd user): `command -v node taler-helper-sqlite3`, `node "$WALLET_CLI" --version`, short temp-DB `balance`. Do not wait for a full mon run to discover ENOENT. - ### systemd user (no extra packages) - `systemd` user session + **`loginctl enable-linger hernani`** (already **Linger=yes** on koopa) @@ -70,17 +66,6 @@ command -v qrencode zbarimg --- -## Franc Paysan stage host (stagepaysan) +## Franc Paysan hosts (francpaysan / stagepaysan) -FP stage (`stagepaysan` via SSH alias `francpaysan-stage-user`): curl, python3, podman if inside, qrencode/zbar for full urls; suite at `~/src/taler-monitoring`. - -**e2e on stagepaysan** also needs user-local: - -| Path | Role | -|------|------| -| `~/.local/bin/node` | Node for wallet-cli | -| `~/.local/bin/taler-wallet-cli.mjs` (or `WALLET_CLI=`) | wallet CLI | -| `~/.local/bin/taler-helper-sqlite3` | **required** — accept-uri / coins | -| `~/francpaysan-secrets/stage/*` | bank admin + merchant token (layout like laptop `francpaysan-secrets`) | - -Host-agent PATH already puts `$HOME/.local/bin` first; still smoke-test under that PATH. +FP hosts (`francpaysan` / `stagepaysan`): same idea — curl, python3, podman if inside, qrencode/zbar for full urls; suite at `~/src/taler-monitoring`. diff --git a/README.md b/README.md index 2c08f4e..dace6d6 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Related: Host packages (koopa / runners): **[DEPENDENCIES.md](./DEPENDENCIES.md)**. Host-agents (GOA + FP; shared report pipeline): **[host-agent/README.md](./host-agent/README.md)**. Public HTML site-gen (same timeout/log/HTML defaults): **[site-gen/README.md](./site-gen/README.md)**. -FP stage host-agent: `host-agent/run-fp-stage-monitoring.sh` + `host-agent/env/stagepaysan.env.example` (see `host-agent/README.md`). +FP host-agent: `host-agent/run-fp-prod-monitoring.sh` / `run-fp-stage-monitoring.sh` + `host-agent/env/*.env.example` (see `host-agent/README.md`). Report for the **GOA** stack with boxed severity badges and **grouped test IDs** `area.group-NN` (e.g. `www.exchange-01`, `e2e.pay-03`): @@ -203,9 +203,8 @@ Each monitored stack must say **what is bank, exchange, and merchant-backend**. Edit **[domains.conf](./domains.conf)** (or set `TALER_DOMAINS_CONF=`): ```text -# name bank exchange merchant currency local landing lang locale [canonical] -taler-ops.ch bank.… exchange.… my.… CHF 0 0 en de-CH -stage.lefrancpaysan.ch stage.bank.… stage.exchange.… stage.monnaie.… TESTPAYSAN 0 1 fr fr-CH +# name bank exchange merchant-backend currency local [canonical] +taler-ops.ch bank.taler-ops.ch exchange.taler-ops.ch my.taler-ops.ch CHF 0 ``` | Field | Meaning | @@ -217,12 +216,8 @@ stage.lefrancpaysan.ch stage.bank.… stage.exchange.… stage.monnaie.… T | **currency** | `GOA` / `KUDOS` / `CHF` / … | | **local** | `1` = koopa SSH stack; `0` = public only | | **landing** | `1` = check `/intro` landings + assets; `0` = skip (TOPS / mytops) | -| **lang** | UI language **`en`** / **`fr`** / **`de`** when `TALER_MON_LANG_SET≠1`. Stock profiles use **en** or **fr** only — **`de` is never a default** (opt-in via `--lang de` or an explicit profile edit). | -| **locale** | Regional l10n (BCP 47): **`fr-CH`** for FrancPaysan (Suisse romande); **`de-CH`** for other Swiss stacks. Aliases `ch-FR` / `ch-DE` accepted. Not the same as UI `lang`. | | **canonical** | optional label after alias (e.g. `my.taler-ops.ch` → `taler-ops.ch`) | -Workstation `TALER_MON_LANG=en` does **not** override a profile with `lang=fr`. Force English on FP only with `--lang en` / `TALER_MON_LANG_SET=1`. - Then: ```bash @@ -267,21 +262,19 @@ Other domains: never SSH. Optional **e2e** aborts cleanly on login/KYC. | | Local (koopa) | Remote | |--|---------------|--------| -| **Bank withdraw** | 20 · 50 · 100 · 200 · **4200** (paivana) | 10 · 20 · 50 | +| **ATM withdraw** | 20 · 50 · 100 · 200 · **4200** (paivana) | 10 · 20 · 50 | | **Pay ladder** | 0.01 … 10 | 0.01 … 1 | | **Paivana** | HTTP paywall + template pay **GOA:4200** (`goa-shop` / `paivana`) | skipped | ```bash ./taler-monitoring.sh e2e ./taler-monitoring.sh -d taler.net urls e2e -# Amount ladder (any currency): classic 0 → … → max, then optional pay -./taler-monitoring.sh ladder # classic (current domain) +# Amount ladder (withdraw 0 → … → max, then pay): same script for GOA + stage +./taler-monitoring.sh ladder # GOA / current domain ./taler-monitoring.sh -d stage.lefrancpaysan.ch ladder # TESTPAYSAN maxima -# Max-search: highest withdrawable + highest payable (≤ available; GOA free template goa-free) -./taler-monitoring.sh max-ladder # Stage auto-reads bank max_wire_transfer_amount (e.g. 2000) and min denom (0.01). # Explorer password: francpaysan-stage-user …/bank-explorer-password.txt (or EXP_PW=). -# Override: LADDER_MODE=max LADDER_MAX_PROBES=16 LADDER_MAX_AMOUNT=100 LADDER_STEPS=7 LADDER_PAY=0 … +# Override: LADDER_MAX_AMOUNT=100 LADDER_STEPS=7 LADDER_PAY=0 … # customize e2e: E2E_WITHDRAW_VALUES="20 50 100" E2E_PAY_VALUES="0.05 1 5" ./taler-monitoring.sh e2e E2E_VARIABLE=0 WITHDRAW_AMT=GOA:50 PAY_AMT=GOA:1 ./taler-monitoring.sh e2e # single fixed @@ -306,7 +299,7 @@ E2E_VARIABLE=0 WITHDRAW_AMT=GOA:50 PAY_AMT=GOA:1 ./taler-monitoring.sh e2e # s | **versions** | `deb.taler.net` reachable (InRelease/Packages/pool `.deb`); containers can reach it + have apt source; installed Taler packages vs **trixie** | | **sanity** | bank · exchange · merchant sections (public + server) | | **e2e** | account → credit → withdraw → wallet → confirm → order → pay | -| **ladder** | amount ladder modules: classic 23-rung wd+pay, or max-search wd+pay (`max-ladder`) | +| **ladder** | GOA withdraw: fixed **0** + low bands + **random high ranges** + fixed **max** | ```bash # package suite (default trixie on deb.taler.net) @@ -345,8 +338,8 @@ Amounts use exchange **`alt_unit_names`** (Kilo-GOA, Mega-GOA, …) with the bas **GOA value in parentheses**: ```text -[INFO] coins after-bank-wd — amount_circ=2 Kilo-GOA (GOA:2000) -[INFO] coins after-bank-wd — denoms_in_circ 1 Kilo-GOA (GOA:1000)×2 (=2 Kilo-GOA (GOA:2000)) +[INFO] coins after-ATM — amount_circ=2 Kilo-GOA (GOA:2000) +[INFO] coins after-ATM — denoms_in_circ 1 Kilo-GOA (GOA:1000)×2 (=2 Kilo-GOA (GOA:2000)) == ladder · rung 12 GOA:1000000 · 1 Mega-GOA (GOA:1000000) == ``` @@ -377,7 +370,7 @@ snapshotted via SSH whenever the stack is under load: | Phase | When | |-------|------| | **inside** | end of container status | -| **e2e** | before work · after bank withdraws · after payments · after shop · e2e-end (+ delta) | +| **e2e** | before work · after ATM withdraws · after payments · after shop · e2e-end (+ delta) | | **ladder** | before first rung · after last rung (+ delta + timing overall) | ```bash @@ -396,14 +389,8 @@ LADDER_LOAD=0 ./taler-monitoring.sh ladder | `METRICS_LOAD` | `1` | `0` = skip all host/container load probes | | `LADDER_LOAD` | `1` | `0` = skip load in ladder only | | `LADDER_PAY` | `1` | `0` = skip payment ladder after withdraws | -| `LADDER_MODE` | `classic` | default **classic** 23-rung wd+pay; `max` = max-search wd+pay (`max-ladder`) | -| `LADDER_MAX_PROBES` | `32` | max-search probe budget; `0` = until converge / timeout | -| `LADDER_HIGH_RUNGS` | `6` | max-search: first N probes random-high, then bisect | -| `LADDER_MAX_TOL_REL` | `0.001` | max-search relative lo/hi gap to stop | -| `LADDER_FREE_TEMPLATE` | `goa-free` | public free-amount pay template (hacktivism) | -| `LADDER_USE_FREE_TEMPLATE` | `1` | create pays via template POST `{"amount":…}` | -| `LADDER_WITHDRAW_SCALE` | `1.5` | classic: withdraw mids / pay mids ratio (funding headroom) | -| `LADDER_STEPS` | `23` | classic: rungs for withdraw and pay (0 + mids + max−1 + max) | +| `LADDER_WITHDRAW_SCALE` | `1.5` | withdraw mids / pay mids ratio (funding headroom) | +| `LADDER_STEPS` | `23` | rungs for both withdraw and pay (0 + mids + max−1 + max) | | `METRICS_LOAD_SSH_TIMEOUT` | `90` | seconds for remote load python | ## Needs @@ -446,10 +433,7 @@ Taler Operations **rusty** host (`taler-devtesting` forced command): ``` Needs SSH to `devtesting@rusty.taler-ops.ch` (Host `taler-rusty-devtesting`). -Probes: CLI help, `geniban` (CH IBAN / synthetic debit funding), baseline `fake-incoming`, -optional **amount ladder** (`DEVTESTING_LADDER=1`, default **23** rungs up to **CHF:50000**). -Each rung reuses geniban debit payto so volume covers the max rung without a real bank withdraw. -`fake-incoming` CHF to exchange credit +Probes: CLI help, `geniban` (CH IBAN), `fake-incoming` CHF to exchange credit IBAN. A nexus bounce *missing reserve public key* is **OK** for the plumbing probe (no real wallet reserve required). diff --git a/TESTS.md b/TESTS.md index 7364968..9826fd7 100644 --- a/TESTS.md +++ b/TESTS.md @@ -24,11 +24,11 @@ Every check line has a **global** run number and a **grouped** id: | **surface** | `check_surface.sh` | ecosystem inventory + **nmap** OS fingerprint; mail/mattermost content reported via surface page | | **sanity** | `check_sanity.sh` | `bank` `exchange` `merchant` | | **server** | `check_server.sh` | (flat `server-NN` or host groups) | -| **e2e** | `check_e2e.sh` | `prereq` `load` `bank` `wallet` `bankwd` `settle` `pay` `shop` `paivana` `dig` `report` | -| **ladder** | `check_amount_ladder.sh` + `ladder/lib_pay.sh` | `plan` `load` `withdraw` `pay` `report` — classic / max-search; phases `ladder` · `max-ladder` · `goa-ladder` (alias) | +| **e2e** | `check_e2e.sh` | `prereq` `load` `bank` `wallet` `atm` `settle` `pay` `shop` `paivana` `dig` `report` | +| **ladder** | `check_goa_ladder.sh` | `plan` `load` `withdraw` `pay` `report` | **Why groups:** flat `www-001`…`www-080` was hard to talk about. -`www.bank-04` / `e2e.bankwd-02` pin the failure to a logical block. +`www.bank-04` / `e2e.atm-02` pin the failure to a logical block. Usage in scripts: @@ -59,13 +59,10 @@ Numbering follows **executed** checks (early skip may shift later NN inside the | **www.webui-** | SPA fingerprints: **`/webui/version.txt`**, **`/webui/version-overlay.txt`**, `index.html` / `index.js`; optional pin via `EXPECT_WEBUI_VERSION` / `EXPECT_WEBUI_OVERLAY` / `WEBUI_OVERLAY_DENY` | | **www.paivana-** | local GOA paywall front (redirect to template) | | **www.landing-** | own-stack intro links; static assets (`qrcode.min.js` hard; `og-goa-shop.png` hard only GOA/local); **demo-withdraw.json** GOA-only; shop-pay soft; stage merchant shop: `shop-ui.js` + `shops.css` + `qrcode.min.js`; cross-links local | -| **www.taler-uri-ports-** | **no default `:443`/`:80`** in public `taler://` URIs — bank/exchange/merchant `/intro/` HTML, `demo-withdraw.json`, `auto-account.json`, bank `stats.json` (ERROR on GOA/local). Unit: `tests/test_normalize_taler_uri.sh` | | **www.qr-** | QR payloads: harvest `taler://` / `payto://` / app `data-qr-url` from landings + mint JSON; **form** check; **qrencode → zbarimg** exact roundtrip; optional static QR images. Needs `qrencode` + `zbar-tools`. Skip: `QR_CHECK=0` | **QR rule:** `taler://withdraw/HOST/taler-integration/UUID` (no default `:443`/`:80`); `taler://pay/` / `pay-template/`; `payto://…` shape OK; decoded PNG must equal payload. Form errors on withdraw/pay/payto are **ERROR** on local/GOA. -**Default port rule:** public and automation URIs must never keep libeufin-style `host:443` / `host:80`. Consumers use `normalize_taler_uri` (lib.sh); bank landing API normalizes in `demo-withdraw-api.py`. - **Legal docs rule:** HTTP 200, non-empty body, not plain `not configured`, not merchant API JSON `code:21`. Local stack may require content needle (terms/privacy/FADP/GOA…). **Performance rule:** Measured from the **monitoring runner** (public via Caddy), not container loopback. Latency (ms) on every perf line + **perf summary** (n / min / p50 / avg / max). @@ -100,10 +97,10 @@ SSH: `KOOPA_SSH` (default `koopa`), then `KOOPA_SSH_FALLBACKS` when LAN is unrea | Group | Checks | |-------|--------| | **e2e.prereq-** | wallet-cli, currency, budgets, secrets, public reachability | -| **e2e.load-** | host/container load snapshots (before / after bank withdraw / after pay) | +| **e2e.load-** | host/container load snapshots (before / after ATM / after pay) | | **e2e.bank-** | account, credit, withdraw ops | | **e2e.wallet-** | exchange + ToS, wallet setup | -| **e2e.bankwd-** | Bank withdraw ladder rungs | +| **e2e.atm-** | ATM withdraw ladder rungs | | **e2e.settle-** | wallet settlement wait / spendable balance | | **e2e.pay-** | variable payments | | **e2e.shop-** | GOA shop product catalog pays | @@ -112,7 +109,7 @@ SSH: `KOOPA_SSH` (default `koopa`), then `KOOPA_SSH_FALLBACKS` when LAN is unrea | **e2e.report-** | final tallies | When filing an issue, quote the full id + label, e.g. -`e2e.bankwd-03 Bank withdraw 5 GOA · bank confirmed, wallet empty`. +`e2e.atm-03 ATM withdraw 5 GOA · bank confirmed, wallet empty`. --- @@ -144,7 +141,7 @@ Standalone: `host-agent/run-aptdeploy.sh` (on koopa local; else ssh `$DEPLOY_SSH - OSV CVE query when package+version known → **ERROR** on hits - Never SSH / never podman on the *targets* | **sanity.bank-** / **.exchange-** / **.merchant-** | public + optional server-side per component | -| **ladder.plan-** / **.load-** / **.withdraw-** / **.pay-** / **.report-** | amount ladder classic or max-search (any currency; stage uses `max_wire`) | +| **ladder.plan-** / **.load-** / **.withdraw-** / **.pay-** / **.report-** | amount ladder (GOA ceiling or stage TESTPAYSAN `max_wire`) | | **server-** | SSH host ports / processes (flat unless grouped later) | | **auth401.*** | merchant 401 / case matrix (WebUI APIs): **signup** `POST /instances` MIX id, **login** Basic user low vs MIX/UPPER, full **case** matrix, **password** bad/empty, **pwchange** `POST private/auth` + re-login, **admin-create** `POST /management/instances` (if admin token), **bearer**, **durable mon401**, **webui** SPA `toLowerCase` probe (`check_auth401.sh`) | @@ -205,5 +202,4 @@ Always use `printf --` friendly plain headers when colour is off (leading `---` | **devtesting.cli-** | SSH to rusty · `taler-devtesting` CLI | | **devtesting.geniban-** | synthetic CH IBAN | | **devtesting.credit-payto-** | exchange credit IBAN for nexus | -| **devtesting.fake-incoming-** / **baseline-** | CHF IN via nexus; bounce missing reserve pub = plumbing OK | -| **devtesting.ladder-** | CHF fake-incoming amount ladder (default 23 rungs → CHF:50000; synthetic geniban debit each rung) | +| **devtesting.fake-incoming-** | CHF IN via nexus; bounce missing reserve pub = plumbing OK | diff --git a/VERSION b/VERSION index 27ddcc1..f3352b3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.23.4 +1.13.10 diff --git a/VERSIONS.md b/VERSIONS.md index 1da8044..75b337c 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -17,43 +17,6 @@ Git tags: `vMAJOR.FEATURE.FIX` (e.g. `v1.8.0`). File `VERSION` omits the `v` pre | Tag | Date (UTC) | Notes | |-----|------------|--------| -| **v1.23.4** | 2026-07-19 | **Bugfix / mon:** shared **normalize_taler_uri** (strip taler:// host :443/:80); ladder/e2e/pay use it. **urls** scans bank+exchange+merchant intros + demo-withdraw/auto-account/stats for default ports (**ERROR** on GOA). Unit test tests/test_normalize_taler_uri.sh. | -| **v1.23.3** | 2026-07-19 | **Bugfix:** payments stale because max-ladder never got coins — root cause on koopa was **taler-wallet-cli missing** (all mint-OK → SKIP_ACCEPT). Hard-fail ladder prereq if CLI/helper missing; settle keeps polling after transfer_done + short run-pending; pay wait default 180s; max-ladder wrapper sets PATH/WALLET_CLI. | -| **v1.23.2** | 2026-07-19 | **Bugfix:** max-ladder host-agent forces **RUN_TIMEOUT=10800** (koopa env had 600 → run aborted mid-ladder); install starts oneshots with **--no-block**. | -| **v1.23.1** | 2026-07-19 | **Fix / scope:** only **`/monitoring-max-ladder/`** for GOA (drop classic `/monitoring-ladder`). Daily timer + install first-run. monpages catalog/Caddy bare redirs for max-ladder only. | -| **v1.23.0** | 2026-07-19 | **Feature:** GOA daily mon page **`/monitoring-max-ladder/`** (max-search) on bank/exchange/taler.hacktivism.ch *(1.23.0 briefly also had classic ladder; removed in 1.23.1)*. | -| **v1.22.1** | 2026-07-19 | **Bugfix (UX):** pay wait after withdraw no longer looks hung — shows **withdraw board in start order** (OK/OK_BANK from TSV) with live wallet status (`pendingIncoming` → `done`) + timer + aggregate available/pendingIncoming on the **same** wallet DB. Short `run-pending` nudge only (no run-until-done). Default wait 90s (`LADDER_PAY_WAIT_AVAILABLE_S`). | -| **v1.22.0** | 2026-07-19 | **Feature:** modular amount ladder — `ladder/lib_pay.sh` (pay) + withdraw in `check_amount_ladder.sh`; `ladder/extract_rpubs.py`. **max-ladder** hunts highest **withdrawable** and highest **payable** (≤ wallet available). GOA pays use public free-amount template **`goa-free`** (`LADDER_FREE_TEMPLATE`). Classic still default 23-rung wd+pay. Phase alias `goa-ladder` → amount ladder (shim removed). | -| **v1.21.0** | 2026-07-19 | **Feature:** generic **amount ladder** (`check_amount_ladder.sh`; compat shim `check_goa_ladder.sh`). Default **classic** 23-rung withdraw (+ pay when enabled); **max-search** (`max-ladder` / `LADDER_MODE=max`) hunts highest mintable amount (probes default 32, `0`=until timeout). **Pay:** never overspend — soft `SKIP_BALANCE` if amount > wallet available. **Alt units:** report/logs show human names (e.g. `8.15 Tera-GOA (GOA:…)`) + raw. **Fixes bundled:** external extract (no stdin SyntaxError); force-select multi-rpub; soft `CEILING_REJECT` on mint 5110/P0001; crash-proof report. CLI-AUTOMATION-NOTES §3/3a/3b/§15–18. | -| **v1.20.1** | 2026-07-19 | **Docs:** CLI-AUTOMATION-NOTES — force-select empty scrape + ladder pins (§3/3a); wallet-db must not be `*.json` (§15); `taler-helper-sqlite3` needs Python ≥3.11 (§16); portable wall-clock (§17); GOA withdraw checklist (§18). No code change. *(Superseded notes folded into **v1.21.0** feature release.)* | -| **v1.20.0** | 2026-07-19 | **Feature:** domains.conf **`locale`** (l10n) — FP **`fr-CH`**, others **`de-CH`** (aliases ch-FR/ch-DE); UI **`lang=de`** supported (sticky + console tags) but **never** a stock profile default; env `TALER_MON_LOCALE` / `TALER_DOMAIN_LOCALE`. | -| **v1.19.1** | 2026-07-19 | **Bugfix / docs:** DEPENDENCIES — e2e requires `taler-helper-sqlite3` on mon PATH + preflight; README domains.conf documents **`lang`** column. | -| **v1.19.0** | 2026-07-19 | **Feature:** domains.conf **`lang`** column (en\|fr) is the global UI language default per stack; i18n + HTML read `TALER_DOMAIN_LANG` / conf (FP profiles `lang=fr`). | -| **v1.18.9** | 2026-07-19 | **Bugfix:** UI lang — *lefrancpaysan*/*francpaysan* always default **fr** unless `TALER_MON_LANG_SET=1` / `--lang`; workstation `TALER_MON_LANG=en` no longer locks English (host-agent + console_to_html). | -| **v1.18.8** | 2026-07-19 | **Bugfix:** e2e wallet — require `taler-helper-sqlite3` on PATH; use absolute `node` + `timeout` instead of fragile `perl -e alarm` for wcli; clearer accept-uri errors (no raw alarm-shift noise). | -| **v1.18.7** | 2026-07-19 | **Bugfix:** mail/surface catalogs — TSA/Anastasis MX is **mail.anastasis.lu** (→ pixel), not non-resolving `anastasis.taler-systems.com`; add `anastasis.lu` + pixel host probes (fixes surface_err mail.*). **Also:** FP stage host-agent defaults include **e2e** + 1800s timeout; stagepaysan.env.example wires francpaysan-secrets + wallet-cli. | -| **v1.18.6** | 2026-07-19 | **Bugfix:** TESTS.md table cell for `e2e.bankwd-` markdown typo from rename. | -| **v1.18.5** | 2026-07-19 | **Bugfix:** TESTS.md e2e group list `atm` → `bankwd` (missed in 1.18.4). | -| **v1.18.4** | 2026-07-19 | **Bugfix:** e2e group id **atm → bankwd** (`e2e.bankwd-*`); finish ATM wording cleanup so mon logs match **Bank withdraw** (no leftover “atm” phase label). Env `E2E_ATM_MAX` still accepted as alias. | -| **v1.18.3** | 2026-07-19 | **Bugfix / wording:** e2e user-facing **ATM withdraw** → **Bank withdraw** (amounts still CHF-style cash-note ladder 20/50/100/200/… — “ATM” was only a metaphor for those note sizes, not a physical ATM). Env: `E2E_BANK_WITHDRAW_MAX` (legacy alias `E2E_ATM_MAX`). Internal group id `e2e.atm-*` kept for check-id stability. | -| **v1.18.2** | 2026-07-19 | **Bugfix:** never publish / accept **stale mon HTML assets** — refuse pre-1.15.8 box-drawing sticky JS in site-gen + generated pages; monpages ERROR on public pages still carrying that JS or teed `SyntaxWarning: invalid escape sequence`; purge `site-gen/__pycache__` after suite reset; convert with `PYTHONWARNINGS=error::SyntaxWarning`. | -| **v1.18.1** | 2026-07-19 | **Bugfix:** (1) mon HTML sticky/err counts honor French badges **ERREUR** / **AVERT** (were plain → 0 errors on FP pages); (2) `stage-lfp` + `INSIDE_PODMAN=1` uses **host-podman** (no empty `INSIDE_SSH` fail); (3) reaffirm filter JS has no box-glyph/`\\-` regex (charCodeAt only — kills SyntaxWarning “geheimsprache” noise). | -| **v1.18.0** | 2026-07-19 | **Feature:** mattermost — client compatibility matrix: **mobile**, **desktop**, **vendor support** floors (default ≥10.11.0, ERROR) + **web** WARN on EOL; env `MATTERMOST_DESKTOP/SUPPORT_MIN_SERVER`, `MATTERMOST_CLIENT_CHECK`. | -| **v1.17.0** | 2026-07-19 | **Feature:** mattermost phase — check **server version** (`X-Version-Id`) against **mobile store min** (default **≥10.11.0**); ERROR when too old (newest Android/iOS apps break); env `MATTERMOST_MOBILE_MIN_SERVER` / `MATTERMOST_MOBILE_CHECK=0`. | -| **v1.16.0** | 2026-07-19 | **Feature:** mon sticky — blue **info** + green **ok** filter badges; suite **version tag under status pill** (not blue badge); filters `#filter-info` / `#filter-ok`. | -| **v1.15.8** | 2026-07-19 | **Bugfix:** mon HTML filter JS — drop literal box-drawing / `\-` regex that caused Python SyntaxWarning (and weird glyphs in suite logs); use Unicode code-point loop instead. | -| **v1.15.7** | 2026-07-19 | **Bugfix:** mon HTML — do not paint «perf/ladder summary» as SUMMARY header (restore 2 INFO lines); drop converter SyntaxWarning/noise from public log; «wrote» on stderr; host-agent PYTHONWARNINGS for convert. | -| **v1.15.6** | 2026-07-19 | **Bugfix:** aptdeploy ERROR jump list is self-contained — systemd httpd failures include before/after state, Result/SubState, failed units, and journal snippets (no more vague «see systemd lines»); ldd/--version errors embed concrete missing libs / exit output. | -| **v1.15.5** | 2026-07-19 | **Bugfix:** devtesting CHF ladder — `ssh` was draining ladder stdin (only rung 1/23 ran → progress 45/98 then snap 52/52); use `ssh -n` + `mapfile`; incomplete ladder is WARN not false complete. | -| **v1.15.4** | 2026-07-19 | **Bugfix:** French sticky titles — page label *surveillance*, stack summary *public + interne*, SUMMARY verdict/totals via i18n (`tout est clair`, `totaux :`). | -| **v1.15.3** | 2026-07-19 | **Bugfix:** console language auto-**fr** for `*lefrancpaysan*` domains again — env `TALER_MON_LANG=en` no longer locks English; only `--lang` / `TALER_MON_LANG_SET=1` is explicit. | -| **v1.15.2** | 2026-07-19 | **Bugfix:** warn/error filter — drop blank log lines from HTML; compact console (no black voids above/mid/below); context skips SUMMARY chrome & pure box frames; tighter filter-gap. | -| **v1.15.1** | 2026-07-19 | **Bugfix:** mon HTML — phase `section()` boxes no longer painted as SUMMARY (were blue/green `sum-header`); only real SUMMARY rows get solid severity backgrounds (OK/WARN/ERROR/INFO). | -| **v1.15.0** | 2026-07-19 | **Feature:** CHF **fake-incoming amount ladder** in `devtesting` (`DEVTESTING_LADDER=1`, default **23** log-spaced rungs **CHF:0.01 → CHF:50000**); synthetic geniban debit funds each rung; baseline plumbing probe kept. | -| **v1.14.0** | 2026-07-19 | **Feature:** SUMMARY box rows are **colour-distinct** (per-severity badge + tinted background + bold counts; verdict-coloured header); HTML mon pages style `sum-ok` / `sum-warn` / `sum-err` / … panels the same way. | -| **v1.13.13** | 2026-07-19 | **Bugfix:** progress estimate for **devtesting** / fake-franken is 8 (happy-path numbered checks), not 10 — avoids mid-run 42/48 then end snap 46/46. | -| **v1.13.12** | 2026-07-19 | **Bugfix:** SUMMARY chrome (`[ WARN ] 2`, `warnings only`, OK/ERROR counts without `#NNN`) is **meta**, not warn/error — sticky counts + warn filter no longer double SUMMARY rows; filter context skips blank lines. | -| **v1.13.11** | 2026-07-19 | **Bugfix:** sticky error/warn filter keeps **±3 dimmed context lines** around each match (gray/grayscale) so phase/group context stays readable; dashed gap between distant clusters. | | **v1.13.10** | 2026-07-19 | **Bugfix:** multi-phase runs print **one global SUMMARY** at parent end (aggregated OK/ERROR/WARN/INFO/BLOCK via `TALER_MON_STATE`); no phase SUMMARY at all (not even last phase); mid-phase still lists ERRORS/BLOCKERS; solo `check_*.sh` unchanged. | | **v1.13.9** | 2026-07-19 | **Bugfix:** no mid-run SUMMARY / progress standings between phases (no more 34/52 + SUMMARY after urls while monpages still runs); full stand only on last phase or solo check script; `progress_finish` remains. | | **v1.13.8** | 2026-07-19 | **Bugfix:** monpages **TOP** meta/marker failures (missing generated/version-link/taler-mon-page, empty race body) are **WARN only** — no longer self-red the run; optional `MONPAGES_TOP_STRICT=1` restores ERROR. | diff --git a/check_amount_ladder.sh b/check_amount_ladder.sh deleted file mode 100755 index 2f5da98..0000000 --- a/check_amount_ladder.sh +++ /dev/null @@ -1,1577 +0,0 @@ -#!/usr/bin/env bash -# check_amount_ladder.sh — generic withdraw/pay amount ladder (any Taler currency) -# -# Orchestrator for the modular amount ladder: -# Phase A withdraw — this file (classic plan or max-search) -# Phase B pay — ladder/lib_pay.sh (classic list or max payable) -# Force-select — ladder/extract_rpubs.py -# See ladder/README.md. -# -# Flow (bank landings): -# 1) GET /intro/auto-account.json → personal *account-* (balance 0) -# 2) Mint pool withdrawals as explorer + confirm when selected -# 3) wallet-cli accept-uri only (no run-until-done) -# 4) bank confirm when selected; settle = balance + transfer_done -# 5) pay via free-amount template (GOA: goa-free) or private orders -# -# Modes (LADDER_MODE): -# classic — default 23-rung withdraw + matching pay plan (pins 0, max-1, max) -# max — max-search: highest withdrawable AND highest payable -# (pay never exceeds wallet available; GOA uses public free-amount -# template goa-free by default) -# -# Usage: -# ./taler-monitoring.sh ladder # classic -# ./taler-monitoring.sh max-ladder # LADDER_MODE=max -# ./taler-monitoring.sh goa-ladder # alias of ladder (phase name only) -# ./taler-monitoring.sh -d stage.lefrancpaysan.ch ladder -# LADDER_MODE=max LADDER_MAX_PROBES=32 ./taler-monitoring.sh ladder -# -# Env: LADDER_MODE, LADDER_STEPS, LADDER_MAX_AMOUNT, LADDER_MIN_AMOUNT, -# LADDER_MAX_PROBES, LADDER_MAX_TOL_REL, LADDER_HIGH_RUNGS, LADDER_STACK_AUTO, -# LADDER_PAY, LADDER_FREE_TEMPLATE, LADDER_FREE_TEMPLATE_INSTANCE, -# EXP_PW / EXP_PW_FILE, CLI_JS, MERCHANT_INSTANCE, … -set -euo pipefail -ROOT=$(cd "$(dirname "$0")" && pwd) -# shellcheck source=lib.sh -source "$ROOT/lib.sh" -# When invoked standalone (not via taler-monitoring.sh), still load secrets.env -load_monitoring_secrets_env 2>/dev/null || true - -# Area ladder.* — withdraw/pay amount ladder (any EXPECT_CURRENCY / stack) -# Groups: ladder.plan / ladder.load / ladder.withdraw / ladder.pay / ladder.report -set_area ladder -set_group plan -SECTION_T0=$(date +%s) -now_ms() { python3 -c 'import time; print(int(time.time()*1000))'; } -elapsed_ms() { - # elapsed_ms START_MS - python3 -c 'import sys; print(int(sys.argv[1]) - int(sys.argv[2]))' "$(now_ms)" "$1" -} - -: "${LADDER_TIMEOUT_S:=3600}" -: "${LADDER_SETTLE_ROUNDS:=18}" -: "${LADDER_SETTLE_SLEEP:=2}" -: "${EXP_USER:=explorer}" -# EXP_PW_FILE / EXP_PW optional overrides; otherwise read_secret + SECRETS_ROOT / stage SSH -: "${EXP_PW_FILE:=}" -: "${EXP_PW:=}" -: "${CLI_JS:=}" -# GOA libeufin amount ceiling (hacktivism). Stage auto-replaces via bank /config. -: "${LADDER_MAX_AMOUNT:=4503599627370496}" -: "${LADDER_STEPS:=23}" -: "${LADDER_LOAD:=1}" -: "${LADDER_PAY:=1}" -: "${LADDER_STACK_AUTO:=1}" -# Withdraw mids = pay mids × scale (so wallet can afford the pay ladder) -: "${LADDER_WITHDRAW_SCALE:=1.5}" -# Floor for random mids (must be ≥ smallest exchange coin; GOA min denom ≈ 0.000001) -: "${LADDER_MIN_AMOUNT:=0.000001}" -: "${LADDER_CONFIRM_POLLS:=40}" -: "${LADDER_PAY_SETTLE_ROUNDS:=6}" -: "${MERCHANT_INSTANCE:=goa-demo-cp4zqk}" -# Public variable template for stage pays (optional; fixed templates used when amount maps) -: "${LADDER_PAY_TEMPLATE:=}" -: "${LADDER_PAY_TEMPLATE_INSTANCE:=fermes-des-collines}" -# Free-amount public template (hacktivism: goa-free on goa-demo-cp4zqk — any GOA amount) -: "${LADDER_FREE_TEMPLATE:=goa-free}" -: "${LADDER_FREE_TEMPLATE_INSTANCE:=}" -# 1 = create pays via public free template POST (amount in body); 0 = private orders only -: "${LADDER_USE_FREE_TEMPLATE:=1}" -# classic | max (max = highest withdrawable + highest payable; phase alias max-ladder) -: "${LADDER_MODE:=classic}" -# max-search: probe budget (0 = run until convergence / LADDER_TIMEOUT_S only) -: "${LADDER_MAX_PROBES:=32}" -: "${LADDER_MAX_TOL_REL:=0.001}" -# first N probes = random high (log-uniform); then log-bisect between lo/hi -: "${LADDER_HIGH_RUNGS:=6}" -# optional seed for reproducible max-search (empty = time-based) -: "${LADDER_MAX_SEED:=}" -# After withdraw, wait for spendable available>0 before pay (secs total; shows countdown) -: "${LADDER_PAY_WAIT_AVAILABLE_S:=180}" - -# Historic libeufin-ish absolute ceiling used as default LADDER_MAX_AMOUNT on GOA -LADDER_ABS_CEILING="4503599627370496" -GOA_LADDER_CEILING="${LADDER_ABS_CEILING}" # back-compat alias - -# Resolve wallet-cli .mjs (no hardcoded laptop path) -if [ -z "${CLI_JS}" ] || [ ! -f "${CLI_JS}" ]; then - CLI_JS=$(find_wallet_cli 2>/dev/null || true) -fi -if [ -z "${CLI_JS}" ] || [ ! -f "${CLI_JS}" ]; then - # PATH wrapper last resort - if command -v taler-wallet-cli >/dev/null 2>&1; then - CLI_JS="" - else - err prereq "taler-wallet-cli not found" \ - "problem: no CLI_JS / WALLET_CLI .mjs and taler-wallet-cli not on PATH — accept-uri/pay cannot run (payments stay stale). Install wallet-cli (e.g. ~/.local/bin/taler-wallet-cli.mjs) + taler-helper-sqlite3; set WALLET_CLI= in ~/.config/taler-monitoring/env" - exit 1 - fi -fi -# helper is required for real wallet DB (otherwise accept "works" empty / no coins) -if ! command -v taler-helper-sqlite3 >/dev/null 2>&1; then - err prereq "taler-helper-sqlite3 not on PATH" \ - "problem: wallet-cli needs taler-helper-sqlite3 for sqlite backend — put it on PATH next to wallet-cli" - exit 1 -fi - -CUR="${EXPECT_CURRENCY:-GOA}" -BANK="${BANK_PUBLIC%/}" -EX="${EXCHANGE_PUBLIC%/}/" -MER="${MERCHANT_PUBLIC%/}" -INST="${MERCHANT_INSTANCE}" - -# --- Stack-specific ladder maxima (TESTPAYSAN stage) --- -# Uses bank max_wire_transfer_amount and exchange min denom when still on GOA defaults. -apply_ladder_stack_defaults() { - [ "${LADDER_STACK_AUTO}" = "1" ] || return 0 - if [ "${CUR}" != "TESTPAYSAN" ]; then - case "${TALER_DOMAIN:-}" in - stage.lefrancpaysan.ch|stage.bank.lefrancpaysan.ch|stage.exchange.lefrancpaysan.ch|stage.monnaie.lefrancpaysan.ch) - CUR="TESTPAYSAN" - ;; - *) return 0 ;; - esac - fi - - local bank_cfg max_wire min_denom - bank_cfg=$(curl -sS -m 12 "${BANK}/config" 2>/dev/null || true) - max_wire=$(printf '%s' "$bank_cfg" | python3 -c ' -import json,sys -try: - d=json.load(sys.stdin) -except Exception: - print("") - raise SystemExit(0) -a=d.get("max_wire_transfer_amount") or "" -print(a.split(":",1)[-1] if a else "") -' 2>/dev/null || true) - - min_denom=$(curl -sS -m 25 -H 'Accept: application/json' "${EX%/}/keys" 2>/dev/null | python3 -c ' -import json,sys -try: - d=json.load(sys.stdin) -except Exception: - print("") - raise SystemExit(0) -den=d.get("denoms") or d.get("denominations") or [] -vals=[] -for x in den if isinstance(den,list) else []: - v=x.get("value") or x.get("amount") or "" - if not v: continue - try: vals.append(float(str(v).split(":")[-1])) - except Exception: pass -print(min(vals) if vals else "") -' 2>/dev/null || true) - - # Fallback maxima if public config unreachable - [ -n "$max_wire" ] || max_wire="2000" - [ -n "$min_denom" ] || min_denom="0.01" - - # Only rewrite when caller left GOA defaults (explicit LADDER_MAX_AMOUNT=… kept) - if [ -n "$max_wire" ] && { [ "${LADDER_MAX_AMOUNT}" = "${GOA_LADDER_CEILING}" ] || [ "${LADDER_MAX_AMOUNT}" = "${LADDER_ABS_CEILING}" ] || [ "${LADDER_MAX_AMOUNT}" = "4503599627370496" ]; }; then - LADDER_MAX_AMOUNT="$max_wire" - fi - if [ -n "$min_denom" ] && { [ "${LADDER_MIN_AMOUNT}" = "0.000001" ] || [ "${LADDER_MIN_AMOUNT}" = "0.00000001" ]; }; then - LADDER_MIN_AMOUNT="$min_denom" - fi - # Slightly fewer rungs on stage (full GOA 23 still ok if user set LADDER_STEPS) - if [ "${LADDER_STEPS}" = "23" ]; then - LADDER_STEPS=15 - fi - # Stage farmer shops: private goa-demo instance does not exist - if [ "${MERCHANT_INSTANCE}" = "goa-demo-cp4zqk" ]; then - MERCHANT_INSTANCE="${LADDER_PAY_TEMPLATE_INSTANCE:-fermes-des-collines}" - INST="$MERCHANT_INSTANCE" - fi - # Prefer public templates for pays when no merchant token (set later) - : "${E2E_USE_TEMPLATES:=1}" - export E2E_USE_TEMPLATES - export LADDER_MAX_AMOUNT LADDER_MIN_AMOUNT LADDER_STEPS MERCHANT_INSTANCE - info "ladder stack" "TESTPAYSAN · max=${CUR}:${LADDER_MAX_AMOUNT} min=${CUR}:${LADDER_MIN_AMOUNT} steps=${LADDER_STEPS} (from bank max_wire / keys denoms)" -} -apply_ladder_stack_defaults - -# Normalize mode (max-ladder phase / aliases) -case "${LADDER_MODE}" in - max|MAX|max-search|maxsearch|find-max|findmax) LADDER_MODE=max ;; - classic|CLASSIC|default|plan|"" ) LADDER_MODE=classic ;; - *) - warn ladder "unknown LADDER_MODE=${LADDER_MODE} — using classic" - LADDER_MODE=classic - ;; -esac -# max mode: withdraw + pay hunts (LADDER_PAY=0 still disables pay entirely) -: "${LADDER_FREE_TEMPLATE_INSTANCE:=${MERCHANT_INSTANCE}}" -export LADDER_MODE LADDER_MAX_PROBES LADDER_MAX_TOL_REL LADDER_HIGH_RUNGS LADDER_MAX_SEED LADDER_PAY -export LADDER_FREE_TEMPLATE LADDER_FREE_TEMPLATE_INSTANCE LADDER_USE_FREE_TEMPLATE LADDER_PAY_WAIT_AVAILABLE_S - -SCRATCH=$(mktemp -d) -WDB="$SCRATCH/wallet.sqlite3" -REPORT_DIR="${LADDER_REPORT_DIR:-$SCRATCH}" -mkdir -p "$REPORT_DIR" -TSV="$REPORT_DIR/ladder-results.tsv" -PAY_TSV="$REPORT_DIR/ladder-pay-results.tsv" -JSON="$REPORT_DIR/ladder-report.json" -LOAD_BEFORE="$REPORT_DIR/load-before.json" -LOAD_AFTER="$REPORT_DIR/load-after.json" -echo -e "rung\trange\tamount\tstatus\tms_mint\tms_accept\tms_confirm\tms_settle\tms_total\twid\tnote" >"$TSV" -echo -e "rung\trange\tamount\tstatus\tms_order\tms_handle\tms_settle\tms_total\toid\tnote" >"$PAY_TSV" - -ladder_over() { - local now - now=$(date +%s) - [ $((now - SECTION_T0)) -ge "$LADDER_TIMEOUT_S" ] -} - -wcli() { - # taler-helper-sqlite3 is Python ≥3.11; prefer Homebrew/local python on macOS - # so Apple /usr/bin/python3 3.9 does not FATAL the sqlite backend (no reservePub). - local _path="${PATH:-}" - case ":${_path}:" in - *:/opt/homebrew/bin:*) ;; - *) _path="/opt/homebrew/bin:/usr/local/bin:${_path}" ;; - esac - if [ -n "${CLI_JS:-}" ] && [ -f "$CLI_JS" ]; then - PATH="$_path" node "$CLI_JS" --wallet-db="$WDB" --no-throttle "$@" - else - PATH="$_path" taler-wallet-cli --wallet-db="$WDB" --no-throttle "$@" - fi -} - -# Explorer pool password: env → file override → stack secrets → SSH -resolve_explorer_pw() { - local pw="" f="" host="" - if [ -n "${EXP_PW:-}" ]; then - printf '%s' "$EXP_PW" - return 0 - fi - if [ -n "${EXP_PW_FILE:-}" ] && [ -f "$EXP_PW_FILE" ]; then - tr -d '\n\r' <"$EXP_PW_FILE" - return 0 - fi - - # Stage TESTPAYSAN — never use GOA koopa-admin-secrets explorer pw first - if [ "${CUR}" = "TESTPAYSAN" ] \ - || [[ "${TALER_DOMAIN:-}" == stage.*lefrancpaysan* ]] \ - || [[ "${TALER_DOMAIN:-}" == *stage.lefrancpaysan* ]]; then - for f in \ - ${FRANCPAYSAN_SECRETS:+"${FRANCPAYSAN_SECRETS}/stage/bank-explorer-password.txt"} \ - "${HOME}/.config/taler-landing/stage-bank-explorer-password.txt" - do - [ -n "$f" ] && [ -f "$f" ] || continue - tr -d '\n\r' <"$f" - return 0 - done - _remote_exp="${FRANCPAYSAN_REMOTE_BANK_EXPLORER_SECRET:-}" - [ -z "$_remote_exp" ] && [ -n "${FRANCPAYSAN_REMOTE_SECRETS_ROOT:-}" ] && \ - _remote_exp="${FRANCPAYSAN_REMOTE_SECRETS_ROOT}/bank/secrets/bank-explorer-password.txt" - for host in ${INSIDE_SSH:+"$INSIDE_SSH"} ${FRANCPAYSAN_SSH:+"$FRANCPAYSAN_SSH"}; do - [ -n "$host" ] && [ -n "$_remote_exp" ] || continue - pw=$(ssh -o BatchMode=yes -o ConnectTimeout=12 "$host" \ - "tr -d '\\n\\r' <${_remote_exp} 2>/dev/null || sudo tr -d '\\n\\r' <${_remote_exp} 2>/dev/null" \ - 2>/dev/null || true) - if [ -n "$pw" ]; then - printf '%s' "$pw" - return 0 - fi - done - return 1 - fi - - # GOA / default: SECRETS_ROOT / ~/.config / koopa SSH - if pw=$(read_secret "taler-bank/bank-explorer-password.txt" 2>/dev/null) && [ -n "$pw" ]; then - printf '%s' "$pw" - return 0 - fi - for f in \ - "${SECRETS_ROOT:+${SECRETS_ROOT}/taler-bank/bank-explorer-password.txt}" \ - "${HOME}/.config/taler-landing/bank-explorer-password.txt" - do - [ -n "$f" ] && [ -f "$f" ] || continue - tr -d '\n\r' <"$f" - return 0 - done - return 1 -} - -wallet_avail() { - wcli balance 2>/dev/null | python3 -c ' -import json,sys -t=sys.stdin.read() -dec=json.JSONDecoder() -i=t.find("{") -if i<0: - print("0"); raise SystemExit -try: - d,_=dec.raw_decode(t,i) -except Exception: - # last-resort: brace slice (may fail on trailing logs) - try: - d=json.loads(t[i:t.rfind("}")+1]) - except Exception: - print("0"); raise SystemExit -cur=sys.argv[1] -for b in d.get("balances") or []: - a=b.get("available") or "" - if a.startswith(cur+":"): - print(a.split(":",1)[1]); raise SystemExit -print("0") -' "$CUR" 2>/dev/null || echo "0" -} - -# pendingIncoming for same currency (same wallet DB as withdraw) — "0" if missing -wallet_pending_in() { - wcli balance 2>/dev/null | python3 -c ' -import json,sys -t=sys.stdin.read() -dec=json.JSONDecoder() -i=t.find("{") -if i<0: - print("0"); raise SystemExit -try: - d,_=dec.raw_decode(t,i) -except Exception: - try: - d=json.loads(t[i:t.rfind("}")+1]) - except Exception: - print("0"); raise SystemExit -cur=sys.argv[1] -for b in d.get("balances") or []: - a=b.get("pendingIncoming") or b.get("pending_incoming") or "" - if a.startswith(cur+":"): - print(a.split(":",1)[1]); raise SystemExit -print("0") -' "$CUR" 2>/dev/null || echo "0" -} - -# Build paired pay + withdraw ladders (same step count, shared random shape). -# Pay: [0] + log-uniform mids + [max-1] + [max] -# Wd: [0] + max(mid, mid×scale) mids + [max-1] + [max] (mids higher → enough to spend) -# Writes: $1 = withdraw list file, $2 = pay list file (space-separated CUR:amt lines as one line each) -build_ladder_pair() { - local wd_out="$1" pay_out="$2" - python3 - <<'PY' "$CUR" "${LADDER_MAX_AMOUNT}" "${LADDER_STEPS}" "${LADDER_MIN_AMOUNT}" "${LADDER_WITHDRAW_SCALE}" "$wd_out" "$pay_out" -import math, random, sys -from decimal import Decimal, ROUND_HALF_UP, ROUND_UP -from pathlib import Path - -cur = sys.argv[1] -max_amt = Decimal(sys.argv[2]) -steps = max(1, int(sys.argv[3])) -min_amt = Decimal(sys.argv[4]) -scale = Decimal(sys.argv[5]) -wd_path, pay_path = Path(sys.argv[6]), Path(sys.argv[7]) -if min_amt <= 0: - min_amt = Decimal("0.000001") -if min_amt >= max_amt: - min_amt = max_amt / Decimal(1000) -if scale < 1: - scale = Decimal(1) -max_m1 = max_amt - Decimal(1) if max_amt > 1 else max_amt - -def fmt(v: Decimal) -> str: - q = v.quantize(Decimal("0.00000001"), rounding=ROUND_HALF_UP) - if q == q.to_integral(): - return format(int(q), "d") - return format(q, "f").rstrip("0").rstrip(".") - -def quant(v: Decimal) -> Decimal: - if v >= 1: - return v.quantize(Decimal(1), rounding=ROUND_HALF_UP) - if v < min_amt: - return min_amt - return v.quantize(Decimal("0.00000001"), rounding=ROUND_UP) - -def amt(v: Decimal) -> str: - return "%s:%s" % (cur, fmt(v)) - -def make_mids(n_mid: int, hi_cap: Decimal): - if n_mid <= 0 or hi_cap <= min_amt: - return [] - lo, hi = float(min_amt), float(hi_cap) * 0.999999 - if hi <= lo: - hi = lo * 10 - cuts = sorted(math.exp(random.uniform(math.log(lo), math.log(hi))) for _ in range(n_mid)) - out, prev = [], Decimal(0) - for c in cuts: - v = quant(Decimal(str(c))) - if v <= prev: - step = min_amt if prev < 1 else max(prev * Decimal("1e-6"), Decimal(1)) - v = quant(prev + step) - if v >= hi_cap: - v = quant(hi_cap - (Decimal(1) if hi_cap > 1 else min_amt)) - if v <= prev or v >= hi_cap: - continue - out.append(v) - prev = v - return out - -# Build withdraw ladder first (full range), then pay mids = withdraw/scale -# so each pay mid is always cheaper than the matching withdraw mid. -if steps == 1: - wd_vals = [max_amt] -elif steps == 2: - wd_vals = [Decimal(0), max_amt] -else: - n_mid = max(0, steps - 3) - wd_vals = [Decimal(0)] + make_mids(n_mid, max_m1) + [max_m1, max_amt] - while len(wd_vals) > steps and len(wd_vals) > 3: - wd_vals.pop(len(wd_vals) // 2) - while len(wd_vals) < steps and len(wd_vals) >= 2: - i = max(1, len(wd_vals) - 2) - a, b = wd_vals[i - 1], wd_vals[i] - if a <= 0: - m = max(min_amt, b / 2 if b > 0 else min_amt) - else: - m = (a * b).sqrt() if a * b > 0 else (a + b) / 2 - m = quant(m) - if m <= a or m >= b: - break - wd_vals.insert(i, m) - wd_vals = wd_vals[:steps] - -pay_vals = [] -prev_p = Decimal(-1) -for i, w in enumerate(wd_vals): - is_first = i == 0 - is_last = i == len(wd_vals) - 1 - is_m1 = (not is_last) and w == max_m1 and i == len(wd_vals) - 2 - if is_first and w == 0: - pay_vals.append(Decimal(0)) - prev_p = Decimal(0) - continue - if is_last: - pay_vals.append(max_amt) - continue - if is_m1 or w == max_m1: - pay_vals.append(max_m1) - prev_p = max_m1 - continue - # pay mid = withdraw / scale (strictly less funding needed per step) - p = quant(w / scale) if scale > 0 else w - if p < min_amt and w >= min_amt: - p = min_amt - if p <= prev_p: - p = quant(prev_p + (min_amt if prev_p < 1 else Decimal(1))) - if p >= w: - # keep pay strictly below this withdraw rung when possible - p = quant(w - (Decimal(1) if w > 1 else min_amt)) if w > prev_p else prev_p - if p <= prev_p: - p = prev_p # flat ok only if stuck; still ≤ w - pay_vals.append(p) - prev_p = p - -assert len(pay_vals) == len(wd_vals) -# sanity: every non-pin pay mid ≤ matching withdraw mid -for i, (p, w) in enumerate(zip(pay_vals, wd_vals)): - if i == 0 or i >= len(wd_vals) - 2: - continue - if p > w: - pay_vals[i] = w - -wd_path.write_text(" ".join(amt(v) for v in wd_vals) + "\n") -pay_path.write_text(" ".join(amt(v) for v in pay_vals) + "\n") -print(" ".join(amt(v) for v in wd_vals)) -PY -} - -# shellcheck source=metrics.sh -source "$ROOT/metrics.sh" -# Payment module (classic + max-search payable) -# shellcheck source=ladder/lib_pay.sh -source "$ROOT/ladder/lib_pay.sh" -METRICS_DIR="$REPORT_DIR" -ALT_UNITS_FILE="${REPORT_DIR}/alt_unit_names.json" -export METRICS_DIR CUR WDB CLI_JS ALT_UNITS_FILE -# Ladder can disable host load without killing coin metrics -if [ "${LADDER_LOAD:-1}" = "0" ]; then - METRICS_LOAD=0 - export METRICS_LOAD -fi - -if [ "${LADDER_MODE}" = "max" ]; then - section "ladder · ${CUR} max-search (find highest withdrawable)" -else - section "ladder · ${CUR} classic (0 → random → max · ${LADDER_STEPS} steps)" -fi -info "bank" "$BANK" -info "exchange" "$EX" -info "currency" "$CUR" -info "ladder mode" "${LADDER_MODE}" -# alt_unit_names for human amounts (Kilo-GOA / Mega-GOA / … + base in parentheses) -if metrics_load_alt_units "${EX%/}/config"; then - info "alt_unit_names" "from ${EX%/}/config → $ALT_UNITS_FILE" -else - warn "alt_unit_names" "using built-in SI fallback ($ALT_UNITS_FILE)" -fi -info "budget" "${LADDER_TIMEOUT_S}s" -_max_m1=$(python3 -c 'import sys; from decimal import Decimal; m=Decimal(sys.argv[1]); print(m-1 if m>1 else m)' "${LADDER_MAX_AMOUNT}" 2>/dev/null || echo "${LADDER_MAX_AMOUNT}-1") -if [ "${LADDER_MODE}" = "max" ]; then - info "max-search" "probes≤${LADDER_MAX_PROBES} high_rand=${LADDER_HIGH_RUNGS} tol=${LADDER_MAX_TOL_REL} ceiling=${CUR}:${LADDER_MAX_AMOUNT}" -else - info "steps" "${LADDER_STEPS} (0 + random≥${LADDER_MIN_AMOUNT} + max-1=${CUR}:${_max_m1} + max=${CUR}:${LADDER_MAX_AMOUNT})" - info "withdraw_scale" "${LADDER_WITHDRAW_SCALE}× pay mids (fund pay ladder)" -fi -info "pay_phase" "$([ "${LADDER_PAY}" = "1" ] && echo enabled || echo disabled)" -info "currency/domain" "${CUR} · ${TALER_DOMAIN:-?} · bank=${BANK}" - -set_group load -section "ladder · load snapshot (before withdraws)" -metrics_report_load "$LOAD_BEFORE" "ladder-start" || true -# Fresh wallet per rung — baseline empty (or last-rung DB if re-used later) -metrics_report_coins "ladder-start" || true - -if ! EXP_PW=$(resolve_explorer_pw); then - err bank "explorer password missing" \ - "set EXP_PW / EXP_PW_FILE or SECRETS_ROOT=…/koopa/host-root (taler-bank/bank-explorer-password.txt)${SECRETS_ROOT:+ · SECRETS_ROOT=${SECRETS_ROOT}}" - secrets_hint 2>/dev/null || true - exit 1 -fi -if [ -n "${SECRETS_ROOT:-}" ]; then - info "explorer secret" "resolved (SECRETS_ROOT=${SECRETS_ROOT} · stage uses stagepaysan secret first when CUR=TESTPAYSAN)" -else - info "explorer secret" "resolved via EXP_PW / EXP_PW_FILE / stage SSH / koopa" -fi -if [ -n "${CLI_JS:-}" ] && [ -f "${CLI_JS}" ]; then - ok "wallet-cli" "$CLI_JS" -else - ok "wallet-cli" "PATH $(command -v taler-wallet-cli)" -fi -ok "wallet-helper" "$(command -v taler-helper-sqlite3)" -# prove wcli can start (avoids minting 32 probes then SKIP_ACCEPT command-not-found) -if ! wcli balance >"$SCRATCH/wcli-smoke.out" 2>&1; then - err prereq "wallet-cli smoke failed" \ - "problem: wcli balance failed — fix CLI_JS/PATH/helper. detail: $(tr '\n' ' ' <"$SCRATCH/wcli-smoke.out" | head -c 240)" - exit 1 -fi - -# --- auto-account --- -t0=$(now_ms) -if ! curl -sS -m 30 -o "$SCRATCH/auto-account.json" "${BANK}/intro/auto-account.json"; then - err bank "auto-account.json unreachable" - exit 1 -fi -ms_auto=$(elapsed_ms "$t0") -if ! python3 -c 'import json; d=json.load(open("'"$SCRATCH"'/auto-account.json")); assert d.get("ok") or d.get("username")' 2>/dev/null; then - err bank "auto-account create failed" "$(head -c 120 "$SCRATCH/auto-account.json" | tr '\n' ' ')" - exit 1 -fi -ACCT_USER=$(python3 -c 'import json; print(json.load(open("'"$SCRATCH"'/auto-account.json"))["username"])') -ok "auto-account ${ACCT_USER} (${ms_auto}ms) — personal ${CUR}:0; pool=explorer" -info "auto-account password" "(see $SCRATCH/auto-account.json — not logged)" - -# --- explorer token --- -t0=$(now_ms) -TOK=$(curl -sS -m 20 -u "${EXP_USER}:${EXP_PW}" \ - -H 'Content-Type: application/json' \ - -d '{"scope":"readwrite","duration":{"d_us":3600000000}}' \ - "${BANK}/accounts/${EXP_USER}/token" \ - | python3 -c 'import json,sys; print(json.load(sys.stdin)["access_token"])') -ms_tok=$(elapsed_ms "$t0") -[ -n "$TOK" ] || { err bank "explorer token failed"; exit 1; } -ok "explorer token (${ms_tok}ms)" - -# ONE cumulative wallet for all withdraws + pays (need balance to spend). -# force-select uses *last* reserve_pub from the current accept output. -wallet_prepare() { - local label="${1:-wallet}" - WDB="$SCRATCH/wallet-${label}.sqlite3" - export WDB - if [ ! -f "$WDB" ]; then - wcli exchanges add "$EX" >"$SCRATCH/ex-add-$label.out" 2>&1 || true - wcli exchanges update "$EX" >"$SCRATCH/ex-upd-$label.out" 2>&1 || true - wcli exchanges accept-tos "$EX" >"$SCRATCH/ex-tos-$label.out" 2>&1 || true - fi -} - -t0=$(now_ms) -rm -f "$SCRATCH/wallet-main.sqlite3" -wallet_prepare "main" -ms_tos=$(elapsed_ms "$t0") -ok "wallet exchange + ToS (${ms_tos}ms) — cumulative DB for withdraw+pay (no run-until-done)" - -: "${LADDER_MAX_RUNGS:=99}" -if [ "${LADDER_MODE}" = "max" ]; then - info "ladder mode" "max-search (highest withdrawable + highest payable ${CUR})" - info "max-search params" "probes≤${LADDER_MAX_PROBES} high_rand=${LADDER_HIGH_RUNGS} tol_rel=${LADDER_MAX_TOL_REL} ceiling=${CUR}:${LADDER_MAX_AMOUNT}" - info "max-search pay" "LADDER_PAY=${LADDER_PAY} free_template=${LADDER_FREE_TEMPLATE}@${LADDER_FREE_TEMPLATE_INSTANCE:-$INST}" - LADDER_LIST="" - PAY_LIST="" - LADDER_N=0 - set -- - printf '%s\n' "# max-search (amounts chosen adaptively)" >"$SCRATCH/ladder-plan.txt" - : >"$SCRATCH/ladder-wd-plan.txt" - : >"$SCRATCH/ladder-pay-plan.txt" -else - info "ladder mode" "classic (0 → random mids → max-1 → max)" - build_ladder_pair "$SCRATCH/ladder-wd-plan.txt" "$SCRATCH/ladder-pay-plan.txt" - LADDER_LIST=$(tr -d '\n' <"$SCRATCH/ladder-wd-plan.txt") - PAY_LIST=$(tr -d '\n' <"$SCRATCH/ladder-pay-plan.txt") - # shellcheck disable=SC2086 - set -- $LADDER_LIST - if [ "$#" -gt "$LADDER_MAX_RUNGS" ]; then - # shellcheck disable=SC2046 - set -- $(printf '%s\n' "$@" | head -n "$LADDER_MAX_RUNGS") - fi - LADDER_N=$# - info "withdraw plan" "$*" - info "withdraw plan (alt)" "$(format_amount_list_alt "$@")" - info "pay plan" "$PAY_LIST" - # shellcheck disable=SC2086 - info "pay plan (alt)" "$(format_amount_list_alt $PAY_LIST)" - printf '%s\n' "$@" >"$SCRATCH/ladder-plan.txt" - # shellcheck disable=SC2086 - printf '%s\n' $PAY_LIST >"$SCRATCH/ladder-pay-plan-lines.txt" 2>/dev/null || true -fi - -OK_N=0 -FAIL_N_L=0 -PAY_OK_N=0 -PAY_FAIL_N=0 -STOP_REASON="" -STOP_AMOUNT="" -MAX_BEST_AMT="" -MAX_LO="0" -MAX_HI="${LADDER_MAX_AMOUNT}" -declare -a RUNG_JSON=() - -# --------------------------------------------------------------------------- -# One withdraw rung. Caller sets: AMT, range_note, rung. -# Returns 0 = soft continue (ok/skip/ceiling); 1 = hard stop. -# Sets: status, AMT_NUM, WID, note, ms_*. -# --------------------------------------------------------------------------- -ladder_withdraw_rung() { - if ladder_over; then - STOP_REASON="timeout budget ${LADDER_TIMEOUT_S}s" - warn ladder "time budget exhausted" \ - "problem: LADDER_TIMEOUT_S=${LADDER_TIMEOUT_S}s reached after ${OK_N} ok rungs; remaining amounts not tried" - return 1 - fi - - # section header is printed by classic/max controller (avoids double banners) - tag=$(printf '%s' "$AMT" | tr '.:' '__') - # range_note set by caller (classic pins / max-search labels) - t_rung=$(now_ms) - ms_mint=0 ms_accept=0 ms_confirm=0 ms_settle=0 - note="" - status="FAIL" - WID="-" - FORCE_SEL_409_LOGGED=0 - - # keep cumulative main wallet - wallet_prepare "main" - - # mint from explorer pool - t0=$(now_ms) - code=$(curl -sS -m 30 -o "$SCRATCH/wd-$tag.json" -w '%{http_code}' \ - -H "Authorization: Bearer ${TOK}" \ - -H 'Content-Type: application/json' \ - -d "{\"amount\":\"${AMT}\"}" \ - "${BANK}/accounts/${EXP_USER}/withdrawals") - ms_mint=$(elapsed_ms "$t0") - WID=$(python3 -c 'import json;d=json.load(open("'"$SCRATCH"'/wd-'"$tag"'.json"));print(d.get("withdrawal_id") or "")' 2>/dev/null || true) - # libeufin often emits taler://withdraw/host:443/… — strip default ports (lib.sh) - URI=$(python3 -c 'import json;print(json.load(open("'"$SCRATCH"'/wd-'"$tag"'.json")).get("taler_withdraw_uri") or "")' 2>/dev/null || true) - URI=$(normalize_taler_uri "$URI") - if taler_uri_has_default_port "$URI"; then - warn bank "withdraw URI still has default port" "problem: $URI" - fi - # numeric amount (for zero / settle / ceiling special-cases) - AMT_NUM=$(python3 -c 'import sys; print(sys.argv[1].split(":",1)[-1])' "$AMT") - IS_ZERO=0 - python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])==0 else 1)' "$AMT_NUM" 2>/dev/null && IS_ZERO=1 - IS_MAX_PIN=0 - IS_MAX_M1_PIN=0 - if [ "$AMT_NUM" = "${LADDER_MAX_AMOUNT}" ]; then - IS_MAX_PIN=1 - range_note="pin:max" - elif [ "$AMT_NUM" = "$((LADDER_MAX_AMOUNT - 1))" ] 2>/dev/null || \ - [ "$AMT_NUM" = "$(python3 -c 'print(int("'"$LADDER_MAX_AMOUNT"'")-1)')" ]; then - IS_MAX_M1_PIN=1 - range_note="pin:max-1" - fi - - if [ "$code" != "200" ] && [ "$code" != "201" ] || [ -z "$WID" ] || [ -z "$URI" ]; then - # strip quotes so STOP_REASON never breaks later shell/python argv - note="mint HTTP $code $(head -c 100 "$SCRATCH/wd-$tag.json" 2>/dev/null | tr '\n\"' ' ')" - ms_total=$(elapsed_ms "$t_rung") - if [ "$IS_ZERO" = "1" ]; then - # Probe only: bank may reject GOA:0 — record and continue ladder - status="ZERO_REJECT" - note="zero-withdraw rejected (expected possible): $note" - warn bank "mint $AMT rejected" \ - "problem: bank will not create a GOA:0 withdrawal (zero amount probe). Ladder continues. detail: $note" - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - OK_N=$((OK_N + 1)) - return 0 - fi - # Absolute max is a ceiling probe — bank often returns SQL P0001/5110; do not abort. - if [ "$IS_MAX_PIN" = "1" ]; then - status="CEILING_REJECT" - note="absolute max rejected (ceiling probe; max-1 is the hard pin): $note" - warn bank "mint $AMT rejected (ceiling)" \ - "problem: bank rejects absolute LADDER_MAX_AMOUNT (often SQL P0001/5110). max-1 rung is the last expected success. Ladder continues to report. detail: $note" - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - return 0 - fi - # max-1 can also hit the same libeufin SQL ceiling (5110/P0001) on live GOA — - # treat as soft ceiling when mid rungs already passed; do not block the report. - if [ "$IS_MAX_M1_PIN" = "1" ] && echo "$note" | grep -qE '5110|P0001'; then - status="CEILING_REJECT" - note="max-1 rejected (same ceiling as absolute max): $note" - warn bank "mint $AMT rejected (max-1 ceiling)" \ - "problem: bank rejects max-1 with SQL P0001/5110 (pool ceiling). Mid-rung OK_BANK/OK still count. Ladder continues. detail: $note" - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - return 0 - fi - # max-search: any mint reject is "too high" / ceiling — never hard-stop the hunt - if [ "${LADDER_MODE}" = "max" ]; then - status="CEILING_REJECT" - note="max-search too-high mint: $note" - warn bank "mint $AMT rejected (max-search)" \ - "problem: mint failed while hunting max withdrawable — treat as upper bound. detail: $note" - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - return 0 - fi - # Classic mid/high random rungs: same 5110/P0001 pool ceiling as pins — soft, not FAIL_MINT. - if echo "$note" | grep -qE '5110|P0001'; then - status="CEILING_REJECT" - note="amount above live mint ceiling (5110/P0001): $note" - warn bank "mint $AMT rejected (ceiling)" \ - "problem: bank mint HTTP 500/5110 SQL P0001 on high amount (not only pin:max). Ladder continues; use max-ladder to bound hi. detail: $note" - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - return 0 - fi - err bank "mint $AMT failed" "$note" - status="FAIL_MINT" - STOP_REASON="$note" - STOP_AMOUNT="$AMT" - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - FAIL_N_L=$((FAIL_N_L + 1)) - return 1 - fi - ok "mint $AMT ($WID) ${ms_mint}ms" - - before=$(wallet_avail) - - # accept - t0=$(now_ms) - if wcli withdraw accept-uri --exchange "$EX" "$URI" >"$SCRATCH/accept-$tag.out" 2>&1; then - ms_accept=$(elapsed_ms "$t0") - ok "accept-uri $AMT ${ms_accept}ms" - else - ms_accept=$(elapsed_ms "$t0") - note="accept-uri failed: $(tail -c 200 "$SCRATCH/accept-$tag.out" | tr '\n' ' ')" - ms_total=$(elapsed_ms "$t_rung") - # Wallet 7006: no denominations for this amount (0, sub-denom dust, etc.) — warn & continue - if [ "$IS_ZERO" = "1" ] || grep -qE 'code: 7006|"code"[[:space:]]*:[[:space:]]*7006|No denominations could be selected' \ - "$SCRATCH/accept-$tag.out" 2>/dev/null; then - if [ "$IS_ZERO" = "1" ]; then - status="ZERO_SKIP" - note="zero-withdraw skip (7006 / no denoms): $note" - warn wallet "accept $AMT skipped" \ - "problem: wallet code 7006 — no coin denominations for GOA:0 (zero amount cannot be withdrawn as coins). Ladder continues. detail: $note" - else - status="SKIP_DENOM" - note="skip amount (wallet 7006 no denoms): $note" - warn wallet "accept $AMT skipped" \ - "problem: wallet code 7006 — no denominations match this amount (below smallest coin or not combinable). Ladder continues with next rung. detail: $note" - fi - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - return 0 - fi - if [ "${LADDER_MODE}" = "max" ]; then - status="SKIP_ACCEPT" - warn wallet "accept $AMT skipped (max-search)" "$note" - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - return 0 - fi - err wallet "accept $AMT" "$note" - status="FAIL_ACCEPT" - STOP_REASON="$note" - STOP_AMOUNT="$AMT" - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - FAIL_N_L=$((FAIL_N_L + 1)) - return 1 - fi - - # Confirm ASAP when bank status is selected. No run-until-done (hangs on macOS/wallet). - # Server-side auto-confirm only watches landing withdraw-watch.ids — ladder must confirm itself. - bank_st() { - curl -sS -m 8 "${BANK}/taler-integration/withdrawal-operation/${WID}" 2>/dev/null \ - | python3 -c 'import json,sys; print((json.load(sys.stdin).get("status") or "").strip())' 2>/dev/null || true - } - do_confirm() { - curl -sS -m 15 -o "$SCRATCH/conf-$tag.json" -w '%{http_code}' -X POST \ - -H "Authorization: Bearer ${TOK}" -H 'Content-Type: application/json' -d '{}' \ - "${BANK}/accounts/${EXP_USER}/withdrawals/${WID}/confirm" - } - # Collect reserve_pub candidates for *this* withdrawal (WID + amount). - # Cumulative wallets re-print old reserves in accept/tx dumps — never trust a single "last" blindly. - # Prints unique pubs one per line, preferred order first. - # - # Critical: wallet-cli dumps mix log lines + JSON. Never json.loads(rest_of_file) — - # trailing "Shutdown requested" lines make that always fail. Use JSONDecoder.raw_decode - # and regex on *both* accept and transactions output (reservePub lives in tx, not accept). - extract_rpubs_for_wid() { - # External module — never feed extract via bash heredoc (refactor tools - # lives in ladder/extract_rpubs.py). - local _ext="$ROOT/ladder/extract_rpubs.py" - if [ ! -f "$_ext" ]; then - warn bank "force-select extract missing" "problem: $_ext not found" - return 0 - fi - python3 "$_ext" "$WID" "$AMT" \ - "$SCRATCH/accept-$tag.out" "$SCRATCH/tx-$tag.json" "$SCRATCH/used-rpubs.txt" - } - - mark_rpub_used() { - local p="$1" - [ -n "$p" ] || return 0 - mkdir -p "$SCRATCH" 2>/dev/null || true - grep -qxF "$p" "$SCRATCH/used-rpubs.txt" 2>/dev/null || echo "$p" >>"$SCRATCH/used-rpubs.txt" - } - - force_select_if_needed() { - local st_now="$1" - [ "$st_now" = "pending" ] || [ -z "$st_now" ] || return 0 - local rpub epayto code_fs any=0 - # refresh tx dump each try (wallet may attach reserve late) - wcli transactions >"$SCRATCH/tx-$tag.json" 2>&1 || true - epayto=$(curl -sS -m 10 "${EX%/}/keys" 2>/dev/null | python3 -c ' -import json,sys -d=json.load(sys.stdin) -acc=d.get("accounts") or [] -for a in acc: - p=a.get("payto_uri") or a.get("payto_address") or "" - if "x-taler-bank" in p or "exchange" in p: - print(p); break -else: - if acc: print(acc[0].get("payto_uri") or "") -' 2>/dev/null || true) - if [ -z "$epayto" ]; then - warn bank "force-select skipped" "problem: exchange payto empty from /keys" - return 0 - fi - # Try candidates until bank leaves pending (200/204) or we exhaust - while IFS= read -r rpub; do - [ -n "$rpub" ] || continue - any=1 - code_fs=$(curl -sS -m 12 -o "$SCRATCH/force-sel-$tag.json" -w '%{http_code}' -X POST \ - -H 'Content-Type: application/json' \ - -d "{\"reserve_pub\":\"${rpub}\",\"selected_exchange\":\"${epayto}\"}" \ - "${BANK}/taler-integration/withdrawal-operation/${WID}" 2>/dev/null || echo "000") - if [ "$code_fs" = "200" ] || [ "$code_fs" = "204" ]; then - info "force-select" "HTTP ${code_fs} rpub=${rpub:0:12}… (ok for WID ${WID:0:8})" - mark_rpub_used "$rpub" - return 0 - fi - if [ "$code_fs" = "409" ]; then - # 5114 = this reserve already bound to another op — not "out of money" - info "force-select" "HTTP 409 rpub=${rpub:0:12}… (stale/used reserve — not balance; trying next)" - mark_rpub_used "$rpub" - continue - fi - info "force-select" "HTTP ${code_fs} rpub=${rpub:0:12}… body=$(tr '\n' ' ' <"$SCRATCH/force-sel-$tag.json" 2>/dev/null | head -c 120)" - # other errors: still try next candidate - done < <(extract_rpubs_for_wid) - if [ "$any" != "1" ]; then - warn bank "force-select skipped" \ - "problem: no reserve_pub for this withdraw (WID=${WID:0:8}…); wallet may not have selected yet" - fi - } - - # No run-until-done (hangs / banned). Read transactions only for reserve_pub candidates. - wcli transactions >"$SCRATCH/tx-$tag.json" 2>&1 || true - - t0=$(now_ms) - conf_ok=0 - st="" - # Poll bank status; force-select while pending; confirm as soon as selected - for i in $(seq 1 "${LADDER_CONFIRM_POLLS}"); do - ladder_over && break - st=$(bank_st) - case "$st" in - selected) - ccode=$(do_confirm) - if [ "$ccode" = "204" ] || [ "$ccode" = "200" ]; then - conf_ok=1 - info "confirm" "HTTP $ccode after selected (poll $i)" - else - note="confirm HTTP $ccode" - fi - break - ;; - confirmed) - conf_ok=1 - break - ;; - aborted) - note="withdrawal aborted by bank" - break - ;; - esac - # force-select while pending — try alternate rpubs on 5114 (not out-of-money) - if [ "$st" = "pending" ] || [ -z "$st" ]; then - if [ "$i" -eq 1 ] || [ "$i" -eq 2 ] || [ $((i % 3)) -eq 0 ]; then - force_select_if_needed "$st" - fi - fi - sleep 0.35 - done - ms_confirm=$(elapsed_ms "$t0") - st=$(printf '%s' "${st:-}" | tr -d '\r\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - if [ "$conf_ok" != "1" ]; then - note="${note:-confirm timeout last=${st:-empty}}" - # Soft: not confirmed — usually stale reserve_pub (5114), NOT empty pool balance - status="SKIP_CONFIRM" - warn bank "confirm $AMT skipped" \ - "problem: bank status='${st:-empty}' after ${LADDER_CONFIRM_POLLS} polls (want selected/confirmed). Usually reserve_pub mismatch (5114), not out-of-money — mint/accept already OK. detail: $note" - ms_total=$(elapsed_ms "$t_rung") - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - return 0 - fi - ok "confirm $AMT ${ms_confirm}ms (client, on selected)" - - # settle: poll wallet balance + bank transfer_done — never run-until-done. - # Prefer real coin delta (status OK). If bank transfer_done first, keep polling - # briefly for available coins (OK) before accepting OK_BANK (pay needs available). - t0=$(now_ms) - settled=0 - xfer="?" - bank_done=0 - if [ "$IS_ZERO" = "1" ]; then - settled=1 - note="zero-amount: no coin delta expected" - else - for r in $(seq 1 "$LADDER_SETTLE_ROUNDS"); do - ladder_over && break - after=$(wallet_avail) - if python3 -c " -from decimal import Decimal -import sys -sys.exit(0 if Decimal(sys.argv[1]) > Decimal(sys.argv[2]) else 1) -" "$after" "$before" 2>/dev/null; then - settled=1 - break - fi - xfer=$(curl -sS -m 10 "${BANK}/taler-integration/withdrawal-operation/${WID}" \ - | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d.get("transfer_done"), d.get("status"))' 2>/dev/null || echo "?") - if echo "$xfer" | grep -qi True; then - bank_done=1 - # nudge wallet to pick up wire (bounded; not run-until-done) - wcli transactions >"$SCRATCH/tx-settle-$tag.out" 2>&1 || true - if command -v timeout >/dev/null 2>&1 || command -v gtimeout >/dev/null 2>&1; then - _to=$(command -v gtimeout 2>/dev/null || command -v timeout) - "$_to" 8 wcli advanced run-pending >"$SCRATCH/run-pending-settle.out" 2>&1 || true - fi - # after bank done, still prefer coins; allow remaining rounds for available - note="bank transfer_done waiting coins avail=${after} $xfer" - fi - sleep "$LADDER_SETTLE_SLEEP" - done - # If bank done but still no coin delta after all rounds, OK_BANK (pay-wait may finish) - if [ "$settled" != "1" ] && [ "$bank_done" = "1" ]; then - note="bank transfer_done avail=$(wallet_avail) $xfer (no run-until-done)" - fi - fi - ms_settle=$(elapsed_ms "$t0") - after=$(wallet_avail) - ms_total=$(elapsed_ms "$t_rung") - if [ -z "${xfer:-}" ] || [ "$xfer" = "?" ]; then - xfer=$(curl -sS -m 10 "${BANK}/taler-integration/withdrawal-operation/${WID}" \ - | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d.get("transfer_done"), d.get("status"))' 2>/dev/null || echo "?") - fi - - if [ "$settled" = "1" ]; then - status="OK" - note="${note:-avail=${CUR}:${after}}" - ok "settle $AMT → ${CUR}:${after} (settle ${ms_settle}ms, rung ${ms_total}ms)" - OK_N=$((OK_N + 1)) - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - metrics_report_coins "ladder-r${rung}-after-${tag}" || true - metrics_record_flow withdrawn "$AMT" || true - elif echo "$xfer" | grep -qi True; then - status="OK_BANK" - note="bank transfer_done avail=${after} $xfer (no run-until-done)" - ok "settle $AMT bank transfer_done (wallet avail=${CUR}:${after}, ${ms_settle}ms)" - OK_N=$((OK_N + 1)) - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - metrics_report_coins "ladder-r${rung}-after-${tag}" || true - metrics_record_flow withdrawn "$AMT" || true - else - note="no coins / no transfer_done avail=${after} $xfer" - if [ "${LADDER_MODE}" = "max" ]; then - status="SKIP_SETTLE" - warn wallet "settle $AMT skipped (max-search)" \ - "problem: bank confirm ok but settle inconclusive — do not move max bounds. detail: $note" - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - return 0 - fi - err wallet "settle $AMT" "$note" - status="FAIL_SETTLE" - STOP_REASON="$note" - STOP_AMOUNT="$AMT" - FAIL_N_L=$((FAIL_N_L + 1)) - echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" - metrics_report_coins "ladder-r${rung}-fail-${tag}" || true - return 1 - fi - return 0 -} - -set_group withdraw - -# --- next amount for max-search (prints: AMT_NUM|range_note|action) --- -# action: probe | done -max_search_next() { - python3 - "$CUR" "$MAX_LO" "$MAX_HI" "$LADDER_MIN_AMOUNT" \ - "$LADDER_MAX_TOL_REL" "$rung" "$LADDER_HIGH_RUNGS" "$LADDER_MAX_SEED" \ - "${MAX_BEST_OK:-}" <<'PY' -import math, random, sys -from decimal import Decimal, ROUND_HALF_UP, ROUND_UP - -cur = sys.argv[1] -lo = Decimal(sys.argv[2] or "0") -hi = Decimal(sys.argv[3]) -min_amt = Decimal(sys.argv[4]) -tol = Decimal(sys.argv[5] or "0.001") -probe_i = int(sys.argv[6]) -high_n = max(1, int(sys.argv[7] or "4")) -seed = sys.argv[8].strip() -best = sys.argv[9].strip() - -if seed: - random.seed(int(seed) + probe_i) -else: - random.seed() - -if min_amt <= 0: - min_amt = Decimal("0.000001") -if hi <= min_amt: - print("0|max:done|done") - raise SystemExit(0) - -if lo > 0 and hi > lo: - gap = (hi - lo) / hi - abs_step = Decimal(1) if hi >= 1 else min_amt - if gap <= tol or (hi - lo) <= abs_step: - print("%s|max:done|done" % (best or str(lo))) - raise SystemExit(0) - -def fmt(v: Decimal) -> str: - if v >= 1: - q = v.quantize(Decimal(1), rounding=ROUND_HALF_UP) - return format(int(q), "d") - q = v.quantize(Decimal("0.00000001"), rounding=ROUND_UP) - s = format(q, "f").rstrip("0").rstrip(".") - return s or "0" - -def clamp(v: Decimal): - if v <= lo and lo > 0: - v = lo + (Decimal(1) if lo >= 1 else min_amt) - if v >= hi: - v = hi - (Decimal(1) if hi > 1 else min_amt) - if v < min_amt: - v = min_amt - if v <= 0: - v = min_amt - if v >= hi: - return None - return v - -if probe_i < high_n: - band_lo = max(lo if lo > 0 else min_amt, hi * Decimal("0.15")) - band_hi = hi * Decimal("0.999") - if band_hi <= band_lo: - band_lo = max(min_amt, hi * Decimal("0.5")) - band_hi = hi * Decimal("0.99") - flo, fhi = float(band_lo), float(band_hi) - if flo <= 0: - flo = float(min_amt) - if fhi <= flo: - fhi = flo * 2 - v = Decimal(str(math.exp(random.uniform(math.log(flo), math.log(fhi))))) - v = clamp(v) - if v is None: - print("%s|max:done|done" % (best or str(lo))) - raise SystemExit(0) - print("%s|max:high-rand|probe" % fmt(v)) - raise SystemExit(0) - -if lo <= 0: - flo = float(max(min_amt, hi * Decimal("0.05"))) - fhi = float(hi * Decimal("0.85")) - if fhi <= flo: - fhi = flo * 1.5 - v = Decimal(str(math.exp(random.uniform(math.log(flo), math.log(fhi))))) - label = "max:descent" -else: - v = (lo * hi).sqrt() - label = "max:bisect" -v = clamp(v) -if v is None: - print("%s|max:done|done" % (best or str(lo))) - raise SystemExit(0) -print("%s|%s|probe" % (fmt(v), label)) -PY -} - -if [ "${LADDER_MODE}" = "max" ]; then - section "ladder · phase A · max-search (find highest withdrawable ${CUR})" - info "max-search" "ceiling=${CUR}:${LADDER_MAX_AMOUNT} min=${CUR}:${LADDER_MIN_AMOUNT} probes≤${LADDER_MAX_PROBES} high_rand=${LADDER_HIGH_RUNGS} tol_rel=${LADDER_MAX_TOL_REL}" - info "max-search" "pay phase $([ "${LADDER_PAY}" = "1" ] && echo enabled || echo disabled)" - MAX_LO="0" - MAX_HI="${LADDER_MAX_AMOUNT}" - MAX_BEST_OK="" - MAX_BEST_AMT="" - rung=0 - # LADDER_MAX_PROBES=0 → no probe cap (stop on converge / timeout only) - while [ "${LADDER_MAX_PROBES}" = "0" ] || [ "$rung" -lt "${LADDER_MAX_PROBES}" ]; do - if ladder_over; then - STOP_REASON="timeout budget ${LADDER_TIMEOUT_S}s" - warn ladder "time budget exhausted" \ - "problem: LADDER_TIMEOUT_S=${LADDER_TIMEOUT_S}s during max-search after ${OK_N} ok; best=${MAX_BEST_AMT:-none} · $(format_amount_alt "${MAX_BEST_AMT:-${CUR}:0}")" - break - fi - _next=$(max_search_next) - _anum=$(printf '%s' "$_next" | cut -d'|' -f1) - range_note=$(printf '%s' "$_next" | cut -d'|' -f2) - _act=$(printf '%s' "$_next" | cut -d'|' -f3) - if [ "$_act" = "done" ]; then - info "max-search" "converged best=$(format_amount_alt "${MAX_BEST_AMT:-${CUR}:0}") · lo=$(format_amount_alt "${CUR}:${MAX_LO}") · hi=$(format_amount_alt "${CUR}:${MAX_HI}") · probes=${rung}" - break - fi - AMT="${CUR}:${_anum}" - if [ -n "${_LAST_MAX_AMT:-}" ] && [ "$AMT" = "$_LAST_MAX_AMT" ]; then - info "max-search" "repeat amount $(format_amount_alt "$AMT") — tightening hi" - MAX_HI=$(python3 -c 'from decimal import Decimal; a=Decimal("'"${_anum}"'"); print(a-(1 if a>=1 else Decimal("'"${LADDER_MIN_AMOUNT}"'")))') - continue - fi - _LAST_MAX_AMT="$AMT" - rung=$((rung + 1)) - section "ladder · max probe $rung $AMT · $(format_amount_alt "$AMT") [lo=$(format_amount_alt "${CUR}:${MAX_LO}") · hi=$(format_amount_alt "${CUR}:${MAX_HI}")]" - status="FAIL" - if ! ladder_withdraw_rung; then - break - fi - AMT_NUM=$(python3 -c 'import sys; print(sys.argv[1].split(":",1)[-1])' "$AMT") - case "$status" in - OK|OK_BANK) - MAX_LO="$AMT_NUM" - MAX_BEST_OK="$AMT_NUM" - MAX_BEST_AMT="$AMT" - info "max-search" "success bound lo=$(format_amount_alt "${CUR}:${MAX_LO}") (best so far)" - ;; - CEILING_REJECT|FAIL_MINT) - MAX_HI=$(python3 -c ' -from decimal import Decimal -a=Decimal("'"$AMT_NUM"'"); h=Decimal("'"$MAX_HI"'") -print(min(a,h)) -') - info "max-search" "too-high hi:=$(format_amount_alt "${CUR}:${MAX_HI}")" - ;; - SKIP_DENOM|ZERO_SKIP|ZERO_REJECT) - info "max-search" "denom-skip $(format_amount_alt "$AMT") (bounds unchanged)" - ;; - SKIP_CONFIRM|SKIP_SETTLE|SKIP_ACCEPT) - info "max-search" "inconclusive $status $(format_amount_alt "$AMT") (bounds unchanged)" - ;; - *) - info "max-search" "status=$status $(format_amount_alt "$AMT") (bounds unchanged)" - ;; - esac - if python3 -c 'from decimal import Decimal; import sys; sys.exit(0 if Decimal(sys.argv[1])>0 and Decimal(sys.argv[2])<=Decimal(sys.argv[1]) else 1)' "$MAX_LO" "$MAX_HI" 2>/dev/null; then - info "max-search" "bounds crossed lo=$(format_amount_alt "${CUR}:${MAX_LO}") · hi=$(format_amount_alt "${CUR}:${MAX_HI}") — stop" - break - fi - done - if [ -n "${MAX_BEST_AMT:-}" ]; then - ok "max-search best withdrawable $(format_amount_alt "$MAX_BEST_AMT") · lo=$(format_amount_alt "${CUR}:${MAX_LO}") · hi=$(format_amount_alt "${CUR}:${MAX_HI}") · probes=${rung}" - else - warn ladder "max-search no successful withdraw" \ - "problem: no OK/OK_BANK within ${rung} probes; hi=$(format_amount_alt "${CUR}:${MAX_HI}")" - fi - { - echo "# max-search mode (withdraw)" - echo "best_wd=${MAX_BEST_AMT:-}" - echo "best_wd_alt=$(format_amount_alt "${MAX_BEST_AMT:-${CUR}:0}")" - echo "lo=${MAX_LO}" - echo "lo_alt=$(format_amount_alt "${CUR}:${MAX_LO}")" - echo "hi=${MAX_HI}" - echo "hi_alt=$(format_amount_alt "${CUR}:${MAX_HI}")" - echo "probes=${rung}" - } >"$SCRATCH/ladder-plan.txt" - printf '%s\n' "${MAX_BEST_AMT:-${CUR}:0}" >"$SCRATCH/ladder-wd-plan.txt" - : >"$SCRATCH/ladder-pay-plan.txt" - # pay phase uses max-search (not classic PAY_LIST) - PAY_LIST="" -else - section "ladder · phase A · withdraw (${LADDER_N} rungs)" - rung=0 - for AMT in "$@"; do - rung=$((rung + 1)) - if ladder_over; then - STOP_REASON="timeout budget ${LADDER_TIMEOUT_S}s" - warn ladder "time budget exhausted" \ - "problem: LADDER_TIMEOUT_S=${LADDER_TIMEOUT_S}s reached after ${OK_N} ok rungs; remaining amounts not tried" - break - fi - if [ "$rung" -eq 1 ]; then - range_note="pin:0" - elif [ "$rung" -eq "$LADDER_N" ]; then - range_note="pin:max" - elif [ "$rung" -eq $((LADDER_N - 1)) ] && [ "$LADDER_N" -ge 3 ]; then - range_note="pin:max-1" - else - range_note="random" - fi - section "ladder · rung $rung $AMT · $(format_amount_alt "$AMT")" - if ! ladder_withdraw_rung; then - break - fi - done -fi - - -# --------------------------------------------------------------------------- -# Phase B — payment (ladder/lib_pay.sh) -# classic: planned pay list · max: highest payable ≤ available (goa-free) -# --------------------------------------------------------------------------- -PAY_OK_N=0 -PAY_FAIL_N=0 -MAX_PAY_BEST_AMT="" -MAX_PAY_LO="0" -MAX_PAY_HI="0" -ladder_run_pay_phase - -ms_phase=$(python3 -c 'import sys,time; print(int((time.time()-float(sys.argv[1]))*1000))' "$SECTION_T0") - -# --- report --- -set_group report -section "ladder · report" -info "auto-account" "$ACCT_USER" -info "ok_rungs" "$OK_N" -info "fail_rungs" "$FAIL_N_L" -info "pay_ok" "$PAY_OK_N" -info "pay_fail" "$PAY_FAIL_N" -info "phase_ms" "$ms_phase" -info "tsv" "$TSV" -info "pay_tsv" "$PAY_TSV" - -# speed summary via python — free-text stop reason via env (JSON " in bank errors -# used to break shell argv quoting → "syntax error near unexpected token '('") -export LADDER_REPORT_STOP_AMOUNT="${STOP_AMOUNT:-}" -export LADDER_REPORT_STOP_REASON="${STOP_REASON:-}" -export LADDER_REPORT_MODE="${LADDER_MODE:-classic}" -export LADDER_REPORT_MAX_BEST="${MAX_BEST_AMT:-}" -export LADDER_REPORT_MAX_PAY_BEST="${MAX_PAY_BEST_AMT:-}" -export LADDER_REPORT_MAX_PAY_LO="${MAX_PAY_LO:-}" -export LADDER_REPORT_MAX_PAY_HI="${MAX_PAY_HI:-}" -export LADDER_REPORT_MAX_PAY_BEST_ALT="$(format_amount_alt "${MAX_PAY_BEST_AMT:-${CUR}:0}" 2>/dev/null || true)" -export LADDER_REPORT_MAX_LO="${MAX_LO:-}" -export LADDER_REPORT_MAX_HI="${MAX_HI:-}" -# Human alt_unit_names (e.g. 8.15 Tera-GOA (GOA:…)) for report + final lines -export LADDER_REPORT_MAX_BEST_ALT="$(format_amount_alt "${MAX_BEST_AMT:-${CUR}:0}" 2>/dev/null || true)" -export LADDER_REPORT_MAX_LO_ALT="$(format_amount_alt "${CUR}:${MAX_LO:-0}" 2>/dev/null || true)" -export LADDER_REPORT_MAX_HI_ALT="$(format_amount_alt "${CUR}:${MAX_HI:-0}" 2>/dev/null || true)" -export LADDER_REPORT_ALT_UNITS="${ALT_UNITS_FILE:-}" -# Report must never abort the ladder (set -e): soft-fail print/JSON only. -python3 - "$TSV" "$PAY_TSV" "$JSON" "$OK_N" "$FAIL_N_L" "$PAY_OK_N" "$PAY_FAIL_N" "$ms_phase" "$ACCT_USER" "$CUR" <<'PY' || true -import csv, json, os, sys, statistics, traceback -from decimal import Decimal, InvalidOperation, ROUND_HALF_UP - -try: - tsv, pay_tsv, jpath = sys.argv[1:4] - ok_n, fail_n, pay_ok, pay_fail, phase_ms, acct, cur = sys.argv[4:11] - stop_amt = os.environ.get("LADDER_REPORT_STOP_AMOUNT") or None - stop_reason = os.environ.get("LADDER_REPORT_STOP_REASON") or None - mode = os.environ.get("LADDER_REPORT_MODE") or "classic" - max_best = os.environ.get("LADDER_REPORT_MAX_BEST") or None - max_lo = os.environ.get("LADDER_REPORT_MAX_LO") or None - max_hi = os.environ.get("LADDER_REPORT_MAX_HI") or None - max_best_alt = os.environ.get("LADDER_REPORT_MAX_BEST_ALT") or None - max_lo_alt = os.environ.get("LADDER_REPORT_MAX_LO_ALT") or None - max_hi_alt = os.environ.get("LADDER_REPORT_MAX_HI_ALT") or None - max_pay_best = os.environ.get("LADDER_REPORT_MAX_PAY_BEST") or None - max_pay_lo = os.environ.get("LADDER_REPORT_MAX_PAY_LO") or None - max_pay_hi = os.environ.get("LADDER_REPORT_MAX_PAY_HI") or None - max_pay_best_alt = os.environ.get("LADDER_REPORT_MAX_PAY_BEST_ALT") or None - alt_path = os.environ.get("LADDER_REPORT_ALT_UNITS") or "" - alt = {} - if alt_path: - try: - _loaded = json.load(open(alt_path)) - if isinstance(_loaded, dict): - alt = {str(k): str(v) for k, v in _loaded.items()} - except Exception: - alt = {} - if not isinstance(alt, dict) or not alt: - alt = {"0": cur or "GOA"} - elif "0" not in alt: - alt = dict(alt) - alt["0"] = cur or "GOA" - - def fmt_num(v): - try: - if v == v.to_integral(): - return format(int(v), "d") - s = format(v.quantize(Decimal("0.00000001"), rounding=ROUND_HALF_UP), "f") - return s.rstrip("0").rstrip(".") - except Exception: - return str(v) - - def format_alt(amt): - """Human alt_unit_names; never raises.""" - try: - if not amt: - return "-" - s = str(amt).strip() - try: - if ":" in s: - c, v = s.split(":", 1) - val = Decimal(v) - else: - c, val = cur, Decimal(s) - except (InvalidOperation, ValueError, TypeError): - return s - au = alt if isinstance(alt, dict) else {"0": cur or "GOA"} - base_name = au.get("0") or c or cur or "GOA" - base_s = "%s:%s" % (c, fmt_num(val)) - if val == 0: - return "0 %s (%s)" % (base_name, base_s) - scales = [] - for k, name in au.items(): - try: - scales.append((int(k), str(name))) - except Exception: - continue - scales.sort(key=lambda x: -x[0]) - absval = abs(val) - chosen = None - for sc, name in scales: - try: - unit = Decimal(10) ** sc - if unit <= 0: - continue - coeff = absval / unit - if coeff >= 1: - chosen = (sc, name, coeff if val >= 0 else -coeff) - break - except Exception: - continue - if chosen is None: - return "%s %s (%s)" % (fmt_num(val), base_name, base_s) - sc, name, coeff = chosen - if sc == 0: - return "%s %s" % (fmt_num(val), name) - return "%s %s (%s)" % (fmt_num(coeff), name, base_s) - except Exception: - return str(amt) if amt else "-" - - def as_amt(s): - try: - if s is None or s == "": - return None - s = str(s).strip() - if ":" in s: - return s - return "%s:%s" % (cur, s) - except Exception: - return None - - def load_rows(path): - rows = [] - try: - with open(path, newline="") as f: - for row in csv.DictReader(f, delimiter="\t"): - rows.append(row) - except Exception: - pass - return rows - - rows = load_rows(tsv) - prows = load_rows(pay_tsv) - - def nums(rs, key): - out = [] - for row in rs: - try: - out.append(int(row[key])) - except Exception: - pass - return out - - def stats(xs): - if not xs: - return {"n": 0} - return { - "n": len(xs), - "min_ms": min(xs), - "max_ms": max(xs), - "avg_ms": int(sum(xs) / len(xs)), - "p50_ms": int(statistics.median(xs)), - } - - _max_block = None - if mode == "max": - _best = as_amt(max_best) if max_best else None - _lo = as_amt(max_lo) if max_lo is not None and str(max_lo) != "" else None - _hi = as_amt(max_hi) if max_hi is not None and str(max_hi) != "" else None - _pb = as_amt(max_pay_best) if max_pay_best else None - _max_block = { - "best": _best, - "best_alt": max_best_alt or (format_alt(_best) if _best else None), - "lo": max_lo, - "lo_alt": max_lo_alt or (format_alt(_lo) if _lo else None), - "hi": max_hi, - "hi_alt": max_hi_alt or (format_alt(_hi) if _hi else None), - "best_pay": _pb, - "best_pay_alt": max_pay_best_alt or (format_alt(_pb) if _pb else None), - "pay_lo": max_pay_lo, - "pay_hi": max_pay_hi, - } - - report = { - "currency": cur, - "mode": mode, - "auto_account": acct, - "ok_rungs": int(ok_n), - "fail_rungs": int(fail_n), - "pay_ok": int(pay_ok), - "pay_fail": int(pay_fail), - "max_search": _max_block, - "stopped_at_amount": stop_amt or None, - "stop_reason": stop_reason or None, - "phase_ms": int(phase_ms), - "timing": { - "mint": stats(nums(rows, "ms_mint")), - "accept": stats(nums(rows, "ms_accept")), - "confirm": stats(nums(rows, "ms_confirm")), - "settle": stats(nums(rows, "ms_settle")), - "rung_total": stats(nums(rows, "ms_total")), - "pay_order": stats(nums(prows, "ms_order")), - "pay_handle": stats(nums(prows, "ms_handle")), - "pay_settle": stats(nums(prows, "ms_settle")), - "pay_total": stats(nums(prows, "ms_total")), - }, - "rungs": rows, - "pays": prows, - } - try: - json.dump(report, open(jpath, "w"), indent=2) - print("JSON", jpath) - except Exception as e: - print("JSON write error:", e) - - print("--- withdraw speed (ms) ---") - for k in ("mint", "accept", "confirm", "settle", "rung_total"): - v = report["timing"][k] - if v.get("n"): - print(" %s n=%s min=%s p50=%s avg=%s max=%s" % ( - k.ljust(12), v["n"], v["min_ms"], v["p50_ms"], v["avg_ms"], v["max_ms"])) - print("--- pay speed (ms) ---") - for k in ("pay_order", "pay_handle", "pay_settle", "pay_total"): - v = report["timing"][k] - if v.get("n"): - print(" %s n=%s min=%s p50=%s avg=%s max=%s" % ( - k.ljust(12), v["n"], v["min_ms"], v["p50_ms"], v["avg_ms"], v["max_ms"])) - print("--- withdraw rungs ---") - for row in rows: - try: - amt = row.get("amount") or "" - aalt = format_alt(amt) if amt else "" - print(" %2s %-18s %-14s total=%sms %s" % ( - row.get("rung"), amt, row.get("status"), row.get("ms_total"), aalt)) - except Exception as e: - print(" ? row-print-error %s" % (e,)) - print("--- pay rungs ---") - for row in prows: - try: - amt = row.get("amount") or "" - aalt = format_alt(amt) if amt else "" - print(" %2s %-18s %-14s total=%sms oid=%s %s" % ( - row.get("rung"), amt, row.get("status"), row.get("ms_total"), - row.get("oid"), aalt)) - except Exception as e: - print(" ? pay-row-print-error %s" % (e,)) - if mode == "max": - print("--- max-search ---") - try: - ba = (max_best_alt or format_alt(as_amt(max_best) or "")) if max_best else "-" - la = (max_lo_alt or format_alt(as_amt(max_lo) or "")) if max_lo is not None and str(max_lo) != "" else "-" - ha = (max_hi_alt or format_alt(as_amt(max_hi) or "")) if max_hi is not None and str(max_hi) != "" else "-" - print(" best=%s" % (max_best or "-")) - print(" best_alt=%s" % ba) - print(" lo=%s" % (max_lo if max_lo is not None else "-")) - print(" lo_alt=%s" % la) - print(" hi=%s" % (max_hi if max_hi is not None else "-")) - print(" hi_alt=%s" % ha) - print(" best_pay=%s" % (max_pay_best or "-")) - print(" best_pay_alt=%s" % (max_pay_best_alt or (format_alt(as_amt(max_pay_best) or "") if max_pay_best else "-"))) - except Exception as e: - print(" max-search print error: %s" % (e,)) - if stop_amt: - try: - print("STOPPED at %s · %s: %s" % (stop_amt, format_alt(stop_amt), stop_reason)) - except Exception: - print("STOPPED at %s: %s" % (stop_amt, stop_reason)) - else: - print("Completed without hard failure (or budget stop without fail).") -except Exception: - traceback.print_exc() -sys.exit(0) -PY - -wcli balance 2>&1 | tee "$REPORT_DIR/balance-final.out" | tail -20 || true - -set_group load -section "ladder · load snapshot (after withdraws)" -metrics_report_load "$LOAD_AFTER" "ladder-end" || true -if [ -f "$LOAD_BEFORE" ] && [ -f "$LOAD_AFTER" ]; then - section "metrics · ladder load delta" - metrics_print_load_delta "$LOAD_BEFORE" "$LOAD_AFTER" || true -fi -# Speed timings → metrics overall (min/p50/avg/max per phase) -if [ -f "$JSON" ]; then - python3 - "$JSON" "${METRICS_DIR}/perf-summary.json" <<'PY' 2>/dev/null || true -import json, sys -rep = json.load(open(sys.argv[1])) -out = {} -for k, v in (rep.get("timing") or {}).items(): - if isinstance(v, dict) and v.get("n"): - out[k] = v -json.dump(out, open(sys.argv[2], "w"), indent=2) -PY -fi -export METRICS_WITHDRAW_TSV="$TSV" -export METRICS_PAY_TSV="$PAY_TSV" -metrics_report_coins "ladder-end" || true -metrics_print_overall "ladder final" || true - -# Keep scratch if LADDER_REPORT_DIR set; else copy key files to /tmp -if [ -z "${LADDER_REPORT_DIR:-}" ]; then - KEEP="/tmp/amount-ladder-report-$(date +%Y%m%d-%H%M%S)" - mkdir -p "$KEEP" - cp -a "$TSV" "$PAY_TSV" "$JSON" "$SCRATCH/auto-account.json" "$SCRATCH/ladder-plan.txt" \ - "$SCRATCH/ladder-wd-plan.txt" "$SCRATCH/ladder-pay-plan.txt" \ - "$REPORT_DIR/balance-final.out" "$LOAD_BEFORE" "$LOAD_AFTER" "$KEEP/" 2>/dev/null || true - info "report_dir" "$KEEP" - echo "$KEEP" >"$SCRATCH/KEEP_PATH" -fi - -if [ "$FAIL_N_L" -gt 0 ]; then - blocker "ladder" "stopped at ${STOP_AMOUNT:-?} — ${STOP_REASON:-error}" - exit 1 -fi -if [ "$OK_N" -eq 0 ]; then - blocker "ladder" "no successful withdraw rungs" - exit 1 -fi -if [ "${LADDER_MODE}" = "max" ] && [ -n "${MAX_BEST_AMT:-}" ]; then - ok "ladder finished mode=max wd_best=$(format_amount_alt "$MAX_BEST_AMT") · pay_best=$(format_amount_alt "${MAX_PAY_BEST_AMT:-${CUR}:0}") · withdraw_ok=$OK_N pay_ok=$PAY_OK_N phase=${ms_phase}ms" -else - ok "ladder finished mode=${LADDER_MODE} withdraw_ok=$OK_N pay_ok=$PAY_OK_N phase=${ms_phase}ms" -fi -exit 0 diff --git a/check_apt_deploy.sh b/check_apt_deploy.sh index e7bc488..54d5704 100755 --- a/check_apt_deploy.sh +++ b/check_apt_deploy.sh @@ -127,7 +127,7 @@ _merchant_ver() { check_ldd_deep() { local name=$1 - local out missing + local out out=$("$PODMAN_BIN" exec "$name" bash -lc ' set +e bin=$(command -v taler-merchant-httpd) @@ -147,48 +147,15 @@ check_ldd_deep() { info "ldd" "$line" done <<<"$out" if echo "$out" | grep -q 'not found'; then - missing=$(echo "$out" | grep 'not found' | tr '\n' ' ' | head -c 280) - err "ldd" "shared library missing in $name" "${missing:-not found (see ldd INFO above)}" + err "ldd" "shared library missing in $name" "see ldd lines above" return 1 fi return 0 } -# Build a single-line diagnosis for err() so jump lists are self-contained -# (operators should not need to hunt nearby INFO lines). -_apt_systemd_diagnose() { - local out="$1" - local before after failed journal status_line result - before=$(echo "$out" | sed -n 's/^httpd_active: //p' | tail -1) - after=$(echo "$out" | sed -n 's/^after_start_httpd: //p' | tail -1) - failed=$(echo "$out" | sed -n 's/^failed_taler: //p' | grep -v '^none$' | tr '\n' ';' | sed 's/;$//') - [ -z "$failed" ] && failed=$(echo "$out" | grep -E '^\s*●\s+taler-' | head -3 | tr '\n' ';' | sed 's/;$//') - result=$(echo "$out" | sed -n 's/^httpd_Result: //p' | tail -1) - [ -z "$result" ] && result=$(echo "$out" | sed -n 's/^ *Result: //p' | head -1) - status_line=$(echo "$out" | sed -n 's/^httpd_status_line: //p' | tail -1) - journal=$(echo "$out" | sed -n 's/^httpd_journal: //p' | tr '\n' ' ' | head -c 220) - # fallback: first non-meta journal-ish line - if [ -z "$journal" ]; then - journal=$(echo "$out" | grep -E 'taler-merchant-httpd\[[0-9]+\]|Failed|error|Error|NRestarts|Main PID' | head -3 | tr '\n' ' ' | head -c 220) - fi - local parts=() - [ -n "$before" ] && parts+=("before=${before}") - [ -n "$after" ] && parts+=("after_start=${after}") - [ -n "$result" ] && parts+=("Result=${result}") - [ -n "$status_line" ] && parts+=("status=${status_line}") - [ -n "$failed" ] && [ "$failed" != "none" ] && parts+=("failed_units=${failed}") - [ -n "$journal" ] && parts+=("journal=${journal}") - if [ "${#parts[@]}" -eq 0 ]; then - printf '%s' "no status/journal captured (podman exec empty?)" - return - fi - local IFS=' · ' - printf '%s' "${parts[*]}" -} - check_systemd() { local name=$1 - local out active_httpd before_httpd detail + local out active_httpd out=$("$PODMAN_BIN" exec "$name" bash -lc ' set +e echo "system: $(systemctl is-system-running 2>&1)" @@ -196,50 +163,17 @@ check_systemd() { echo "target_active: $(systemctl is-active taler-merchant.target 2>&1)" echo "httpd_active: $(systemctl is-active taler-merchant-httpd.service 2>&1)" echo "httpd_enabled: $(systemctl is-enabled taler-merchant-httpd.service 2>&1)" - # unit properties help when is-active is only "activating"/"failed" - echo "httpd_Result: $(systemctl show -p Result --value taler-merchant-httpd.service 2>&1)" - echo "httpd_SubState: $(systemctl show -p SubState --value taler-merchant-httpd.service 2>&1)" - echo "httpd_NRestarts: $(systemctl show -p NRestarts --value taler-merchant-httpd.service 2>&1)" - echo "httpd_ExecMainStatus: $(systemctl show -p ExecMainStatus --value taler-merchant-httpd.service 2>&1)" - echo "httpd_ExecMainCode: $(systemctl show -p ExecMainCode --value taler-merchant-httpd.service 2>&1)" - # one-line status (Active: failed / activating (start) …) - systemctl status taler-merchant-httpd.service --no-pager -l 2>&1 | head -12 | while IFS= read -r sl; do - echo "httpd_status: $sl" - done - # compact single-line for err detail - st1=$(systemctl status taler-merchant-httpd.service --no-pager -l 2>&1 | sed -n "s/^ *Active: //p" | head -1) - echo "httpd_status_line: ${st1:-?}" - systemctl start taler-merchant.target 2>&1 | tail -8 | while IFS= read -r sl; do - echo "start_target: $sl" - done - # wait longer: "activating" often clears only after dbinit - sleep 5 + systemctl start taler-merchant.target 2>&1 | tail -5 + sleep 2 echo "after_start_target: $(systemctl is-active taler-merchant.target 2>&1)" echo "after_start_httpd: $(systemctl is-active taler-merchant-httpd.service 2>&1)" - echo "after_httpd_Result: $(systemctl show -p Result --value taler-merchant-httpd.service 2>&1)" - echo "after_httpd_SubState: $(systemctl show -p SubState --value taler-merchant-httpd.service 2>&1)" - # journal: last failure reasons (self-contained for ERROR jump list) - journalctl -u taler-merchant-httpd.service -n 12 --no-pager -o cat 2>/dev/null \ - | sed "/^$/d" | tail -8 | while IFS= read -r jl; do - echo "httpd_journal: $jl" - done - journalctl -u taler-merchant-dbinit.service -n 6 --no-pager -o cat 2>/dev/null \ - | sed "/^$/d" | tail -4 | while IFS= read -r jl; do - echo "dbinit_journal: $jl" - done - ft=$(systemctl --failed --no-legend 2>/dev/null | grep -i taler || true) - if [ -n "$ft" ]; then - echo "$ft" | while IFS= read -r fl; do echo "failed_taler: $fl"; done - else - echo "failed_taler: none" - fi + systemctl --failed --no-legend 2>/dev/null | grep -i taler || echo "failed_taler: none" ' 2>/dev/null || echo "systemd probe failed") while IFS= read -r line; do [ -n "$line" ] || continue info "systemd" "$line" done <<<"$out" - before_httpd=$(echo "$out" | sed -n 's/^httpd_active: //p' | tail -1) active_httpd=$(echo "$out" | sed -n 's/^after_start_httpd: //p' | tail -1) # export for caller board APT_LAST_HTTPD="${active_httpd:-?}" @@ -247,17 +181,7 @@ check_systemd() { ok "systemd httpd" "taler-merchant-httpd active after start taler-merchant.target" return 0 fi - detail=$(_apt_systemd_diagnose "$out") - # Prefer after_* Result if present - local after_result after_sub - after_result=$(echo "$out" | sed -n 's/^after_httpd_Result: //p' | tail -1) - after_sub=$(echo "$out" | sed -n 's/^after_httpd_SubState: //p' | tail -1) - [ -n "$after_result" ] && [ "$after_result" != "success" ] && detail="${detail} · after_Result=${after_result}" - [ -n "$after_sub" ] && detail="${detail} · after_SubState=${after_sub}" - # Human one-liner for jump list (no "see …" without content) - err "systemd httpd" \ - "taler-merchant-httpd not active (container=${name})" \ - "${detail}" + err "systemd httpd" "taler-merchant-httpd not active" "after_start_httpd=${active_httpd:-?} · see systemd lines" return 1 } @@ -297,21 +221,18 @@ check_merchant_basics() { done <<<"$out" if echo "$out" | grep -qi 'error while loading shared libraries'; then - local lib_err - lib_err=$(echo "$out" | grep -i 'error while loading shared libraries' | head -1 | tr '\n' ' ' | head -c 240) - err "httpd" "shared library error on --version" "${lib_err:-see basics INFO lines}" + err "httpd" "shared library error on --version" "see basics/ldd" return 1 fi set +e - local ver_out ec - ver_out=$("$PODMAN_BIN" exec "$name" taler-merchant-httpd --version 2>&1) - ec=$? + "$PODMAN_BIN" exec "$name" taler-merchant-httpd --version >/dev/null 2>&1 + local ec=$? set -e if [ "$ec" -eq 0 ]; then ok "httpd --version" "exit 0" else - err "httpd --version" "exit $ec" "$(printf '%s' "$ver_out" | tr '\n' ' ' | head -c 240)" + err "httpd --version" "exit $ec" return 1 fi @@ -387,10 +308,9 @@ check_one() { if ! check_systemd "$name"; then c_fail=1 httpd="${APT_LAST_HTTPD:-FAIL}" - note="${note:+$note; }httpd=${httpd}" # deeper ldd if httpd failed if [ "$ldd" != "FAIL" ]; then - check_ldd_deep "$name" || { ldd="FAIL"; c_fail=1; note="${note:+$note; }ldd"; } + check_ldd_deep "$name" || { ldd="FAIL"; c_fail=1; } fi else httpd="active" diff --git a/check_devtesting.sh b/check_devtesting.sh index 899d51a..088ddd7 100755 --- a/check_devtesting.sh +++ b/check_devtesting.sh @@ -6,21 +6,18 @@ # # Probes: # 1) CLI reachable (fake-incoming --help) -# 2) geniban → Swiss IBAN (debit side — “enough money” is synthetic per rung) -# 3) baseline fake-incoming CHF:1.00 (plumbing) -# 4) optional amount ladder: DEVTESTING_LADDER=1 (default) — 23 rungs up to 50k CHF +# 2) geniban → Swiss IBAN +# 3) fake-incoming CHF amount to exchange credit IBAN (nexus IN) +# Bounce "missing reserve public key" = plumbing OK (no real wallet reserve) +# Full credit needs a real reserve pub as --subject (optional later) # # Env: -# DEVTESTING_SSH default taler-rusty-devtesting (or user@host) -# DEVTESTING_AMOUNT baseline amount (default CHF:1.00) -# DEVTESTING_CREDIT_PAYTO exchange IBAN payto -# DEVTESTING_EXCHANGE_IBAN fallback CH6808573105529100001 (TOPS CHF exchange) -# DEVTESTING_LADDER 1 (default) run amount ladder; 0 = baseline only -# DEVTESTING_LADDER_STEPS default 23 -# DEVTESTING_LADDER_MAX default 50000 (CHF major units) -# DEVTESTING_LADDER_MIN default 0.01 -# DEVTESTING_LADDER_STOP_ON_FAIL 1 (default) stop ladder on hard fail; 0 = continue -# DEVTESTING_SKIP=1 skip phase +# DEVTESTING_SSH default taler-rusty-devtesting (or user@host) +# DEVTESTING_AMOUNT default CHF:1.00 +# DEVTESTING_CREDIT_PAYTO exchange IBAN payto (auto from EXCHANGE_PUBLIC/keys if empty) +# DEVTESTING_EXCHANGE_IBAN fallback CH6808573105529100001 (TOPS CHF exchange) +# DEVTESTING_SKIP=1 skip phase +# SKIP_SSH=1 skip (same as other SSH phases) # set -euo pipefail ROOT=$(cd "$(dirname "$0")" && pwd) @@ -40,29 +37,23 @@ fi : "${DEVTESTING_SSH:=}" : "${DEVTESTING_AMOUNT:=CHF:1.00}" : "${DEVTESTING_EXCHANGE_IBAN:=CH6808573105529100001}" -: "${DEVTESTING_LADDER:=1}" -: "${DEVTESTING_LADDER_STEPS:=23}" -: "${DEVTESTING_LADDER_MAX:=50000}" -: "${DEVTESTING_LADDER_MIN:=0.01}" -: "${DEVTESTING_LADDER_STOP_ON_FAIL:=1}" : "${SSH_CONNECT_TIMEOUT:=8}" -: "${SSH_CMD_TIMEOUT:=60}" +: "${SSH_CMD_TIMEOUT:=45}" ssh_dt() { - # Prefer Host alias; fall back to explicit user@host if config missing. - # Always -n: do not read local stdin (ladder while-read must not be drained by ssh). + # Prefer Host alias; fall back to explicit user@host if config missing local target="$DEVTESTING_SSH" if ! ssh -G "$target" >/dev/null 2>&1; then target="devtesting@rusty.taler-ops.ch" fi if command -v timeout >/dev/null 2>&1; then - timeout "${SSH_CMD_TIMEOUT}" ssh -n \ + timeout "${SSH_CMD_TIMEOUT}" ssh \ -o BatchMode=yes \ -o ConnectTimeout="${SSH_CONNECT_TIMEOUT}" \ -o StrictHostKeyChecking=accept-new \ "$target" "$@" else - ssh -n \ + ssh \ -o BatchMode=yes \ -o ConnectTimeout="${SSH_CONNECT_TIMEOUT}" \ -o StrictHostKeyChecking=accept-new \ @@ -70,57 +61,8 @@ ssh_dt() { fi } -# Run one fake-incoming. Sets globals: FI_RC FI_FLAT FI_STATUS -# FI_STATUS: ok_bounce | ok_in | ok_cli | fail_ssh | fail_creditor | fail_nexus | fail_other -run_fake_incoming() { - local amount="$1" subject="$2" credit="$3" debit="$4" - local fi_out - FI_RC=0 - FI_FLAT="" - FI_STATUS="fail_other" - fi_out=$(ssh_dt fake-incoming \ - --amount "${amount}" \ - --subject "${subject}" \ - --credit-payto "${credit}" \ - --debit-payto "${debit}" 2>&1) || FI_RC=$? - FI_FLAT=$(printf '%s' "$fi_out" | tr '\n' ' ') - - if printf '%s' "$FI_FLAT" | grep -qiE 'Permission denied|Connection refused|Could not resolve|No such command'; then - FI_STATUS=fail_ssh - return 1 - fi - if printf '%s' "$FI_FLAT" | grep -qiE 'Creditor must be the exchange'; then - FI_STATUS=fail_creditor - return 1 - fi - if printf '%s' "$FI_FLAT" | grep -qiE 'Missing amount|unable to read secrets|CalledProcessError'; then - if ! printf '%s' "$FI_FLAT" | grep -qE 'libeufin-nexus - IN .* CHF'; then - FI_STATUS=fail_nexus - return 1 - fi - fi - if printf '%s' "$FI_FLAT" | grep -qE 'libeufin-nexus - IN .* CHF:[0-9]'; then - if printf '%s' "$FI_FLAT" | grep -qiE 'bounced.*missing reserve public key'; then - FI_STATUS=ok_bounce - return 0 - fi - if printf '%s' "$FI_FLAT" | grep -qiE 'bounced'; then - FI_STATUS=ok_bounce - return 0 - fi - FI_STATUS=ok_in - return 0 - fi - if [ "$FI_RC" -eq 0 ] && printf '%s' "$FI_FLAT" | grep -qi 'Faking incoming CHF'; then - FI_STATUS=ok_cli - return 0 - fi - FI_STATUS=fail_other - return 1 -} - set_group cli -info "ssh" "DEVTESTING_SSH=${DEVTESTING_SSH} baseline=${DEVTESTING_AMOUNT} ladder=${DEVTESTING_LADDER} steps=${DEVTESTING_LADDER_STEPS} max=CHF:${DEVTESTING_LADDER_MAX}" +info "ssh" "DEVTESTING_SSH=${DEVTESTING_SSH} amount=${DEVTESTING_AMOUNT}" help_out=$(ssh_dt fake-incoming --help 2>&1) || true if printf '%s' "$help_out" | grep -q 'fake-incoming'; then @@ -135,7 +77,7 @@ set_group geniban iban_out=$(ssh_dt geniban 2>&1) || true iban=$(printf '%s\n' "$iban_out" | grep -E '^CH[0-9A-Z]+$' | tail -1 || true) if [ -n "$iban" ]; then - ok "geniban" "synthetic IBAN $iban (debit / “withdraw” side for each rung)" + ok "geniban" "synthetic IBAN $iban" else fail "geniban" "expected CH… IBAN" "$(printf '%s' "$iban_out" | tr '\n' ' ' | head -c 160)" exit 1 @@ -150,187 +92,55 @@ if [ -z "$credit_payto" ]; then fi ok "credit-payto" "$credit_payto" +# Subject: not a real reserve — nexus should bounce missing reserve public key +# (proves CHF fake-incoming path). Real reserve pub would credit wirewatch. +subject="mon-fake-franken-$(date -u +%Y%m%d%H%M%S)-$$" debit_payto="payto://iban/${iban}?receiver-name=MonDevTest" -ts_base=$(date -u +%Y%m%d%H%M%S) -# --- baseline plumbing probe --- -set_group baseline -subject="mon-fake-franken-${ts_base}-base-$$" +set_group fake-incoming info "fake-incoming" "amount=${DEVTESTING_AMOUNT} subject=${subject}" -if run_fake_incoming "$DEVTESTING_AMOUNT" "$subject" "$credit_payto" "$debit_payto"; then - case "$FI_STATUS" in - ok_bounce) - ok "fake-incoming" "CHF IN accepted by nexus · bounce/missing reserve pub — plumbing OK" - info "note" "use real reserve pub as --subject for wirewatch credit (not required for mon probe)" - ;; - ok_in) ok "fake-incoming" "CHF IN recorded by nexus (no bounce line)" ;; - ok_cli) ok "fake-incoming" "CLI completed CHF fake-incoming" ;; - *) ok "fake-incoming" "status=${FI_STATUS}" ;; - esac -else - case "$FI_STATUS" in - fail_ssh) - fail "fake-incoming" "SSH/CLI failure" "$(printf '%s' "$FI_FLAT" | head -c 200)" - exit 1 - ;; - fail_creditor) - fail "fake-incoming" "wrong credit IBAN (not exchange)" "$(printf '%s' "$FI_FLAT" | head -c 220)" - exit 1 - ;; - fail_nexus) - fail "fake-incoming" "nexus rejected request" "$(printf '%s' "$FI_FLAT" | head -c 220)" - exit 1 - ;; - *) - fail "fake-incoming" "no CHF IN line from nexus" "rc=${FI_RC} $(printf '%s' "$FI_FLAT" | head -c 200)" - exit 1 - ;; - esac +fi_rc=0 +fi_out=$(ssh_dt fake-incoming \ + --amount "${DEVTESTING_AMOUNT}" \ + --subject "${subject}" \ + --credit-payto "${credit_payto}" \ + --debit-payto "${debit_payto}" 2>&1) || fi_rc=$? + +# Normalize multi-line for matching +fi_flat=$(printf '%s' "$fi_out" | tr '\n' ' ') + +if printf '%s' "$fi_flat" | grep -qiE 'Permission denied|Connection refused|Could not resolve|No such command'; then + fail "fake-incoming" "SSH/CLI failure" "$(printf '%s' "$fi_flat" | head -c 200)" + exit 1 fi -# --- CHF amount ladder (fake-incoming rungs) --- -if [ "${DEVTESTING_LADDER}" = "1" ]; then - set_group ladder - section "devtesting · CHF fake-incoming ladder (→ ${DEVTESTING_LADDER_MAX})" +if printf '%s' "$fi_flat" | grep -qiE 'Creditor must be the exchange'; then + fail "fake-incoming" "wrong credit IBAN (not exchange)" "$(printf '%s' "$fi_flat" | head -c 220)" + exit 1 +fi - LADDER_FILE=$(mktemp "${TMPDIR:-/tmp}/devtesting-ladder.XXXXXX") - python3 - <<'PY' "${DEVTESTING_LADDER_MAX}" "${DEVTESTING_LADDER_STEPS}" "${DEVTESTING_LADDER_MIN}" "$LADDER_FILE" -import math, sys -from decimal import Decimal, ROUND_HALF_UP -from pathlib import Path - -max_amt = Decimal(sys.argv[1]) -steps = max(1, int(sys.argv[2])) -min_amt = Decimal(sys.argv[3]) -out = Path(sys.argv[4]) -if min_amt <= 0: - min_amt = Decimal("0.01") -if min_amt >= max_amt: - min_amt = max_amt / Decimal(1000) -# CHF: 2 decimal places -q2 = Decimal("0.01") - -def quant(v: Decimal) -> Decimal: - if v < min_amt: - v = min_amt - return v.quantize(q2, rounding=ROUND_HALF_UP) - -def fmt(v: Decimal) -> str: - q = quant(v) - if q == q.to_integral(): - return str(int(q)) - return format(q, "f") - -if steps == 1: - amts = [quant(max_amt)] -elif steps == 2: - amts = [quant(min_amt), quant(max_amt)] -else: - # Exactly `steps` log-spaced rungs from min → max (includes both ends). - # Guarantees max rung = DEVTESTING_LADDER_MAX (“enough” volume at the top). - amts = [] - lo, hi = float(min_amt), float(max_amt) - if hi <= lo: - hi = lo * 10 - for i in range(steps): - if steps == 1: - v = max_amt - else: - t = i / (steps - 1) - v = Decimal(str(math.exp(math.log(lo) + t * (math.log(hi) - math.log(lo))))) - amts.append(quant(v)) - amts[0] = quant(min_amt) - amts[-1] = quant(max_amt) - # enforce strictly increasing - for i in range(1, len(amts)): - if amts[i] <= amts[i - 1]: - amts[i] = quant(amts[i - 1] + min_amt) - amts[-1] = quant(max_amt) - if amts[-1] <= amts[-2]: - # last-but-one squeezed; leave max exact and drop collision by nudging previous - amts[-2] = quant(max(amts[-3] + min_amt if len(amts) > 2 else min_amt, max_amt - Decimal(1))) - if amts[-2] >= amts[-1]: - amts[-2] = quant(amts[-1] - min_amt) - -lines = ["CHF:%s" % fmt(a) for a in amts] -out.write_text("\n".join(lines) + "\n") -PY - n_rungs_plan=$(grep -cE '^CHF:' "$LADDER_FILE" || echo 0) - ladder_sum=$(python3 -c ' -from decimal import Decimal -s=Decimal(0) -for ln in open("'"$LADDER_FILE"'"): - ln=ln.strip() - if not ln: continue - s += Decimal(ln.split(":",1)[-1]) -print(s) -' 2>/dev/null || echo "?") - - info "ladder plan" "steps=${n_rungs_plan} max=CHF:${DEVTESTING_LADDER_MAX} min=CHF:${DEVTESTING_LADDER_MIN} sum≈CHF:${ladder_sum} (synthetic debit geniban each rung)" - info "ladder funding" "each rung uses geniban debit payto — no real bank withdraw; volume covers max rung CHF:${DEVTESTING_LADDER_MAX}" - - LADDER_OK=0 - LADDER_FAIL=0 - LADDER_WARN=0 - rung=0 - # Load amounts into an array first — never `while read … done "$out"; return 1; } - if [ -n "${WSERVE_PID:-}" ] && [ -S "${WSOCK:-}" ]; then - if command -v timeout >/dev/null 2>&1; then - timeout -k 2 10 "$_node" "$WALLET_CLI" --wallet-connection="$WSOCK" --no-throttle balance \ + if command -v perl >/dev/null 2>&1; then + if [ -n "${WSERVE_PID:-}" ] && [ -S "${WSOCK:-}" ]; then + perl -e 'alarm shift; exec @ARGV' 10 \ + node "$WALLET_CLI" --wallet-connection="$WSOCK" --no-throttle balance \ >"$out" 2>"$err" || true else - "$_node" "$WALLET_CLI" --wallet-connection="$WSOCK" --no-throttle balance \ + perl -e 'alarm shift; exec @ARGV' 10 \ + node "$WALLET_CLI" --wallet-db="$WDB" --no-throttle --skip-defaults balance \ >"$out" 2>"$err" || true fi else - if command -v timeout >/dev/null 2>&1; then - timeout -k 2 10 "$_node" "$WALLET_CLI" --wallet-db="$WDB" --no-throttle --skip-defaults balance \ + if [ -n "${WSERVE_PID:-}" ] && [ -S "${WSOCK:-}" ]; then + node "$WALLET_CLI" --wallet-connection="$WSOCK" --no-throttle balance \ >"$out" 2>"$err" || true else - "$_node" "$WALLET_CLI" --wallet-db="$WDB" --no-throttle --skip-defaults balance \ + node "$WALLET_CLI" --wallet-db="$WDB" --no-throttle --skip-defaults balance \ >"$out" 2>"$err" || true fi fi @@ -226,20 +226,18 @@ except Exception: print("")' 2>/dev/null || true) # --------------------------------------------------------------------------- # Variable amounts -# Withdraw = typical bank cash-note amounts (CHF-style: was called ATM): 20 / 50 / 100 / 200 … +# Withdraw = typical ATM notes only (Bankomat): 20 / 50 / 100 / 200 … # Pay = several smaller purchase amounts # Env: # E2E_WITHDRAW_VALUES="20 50 100" # bare numbers → prefixed with CUR # E2E_PAY_VALUES="0.01 0.05 0.5 1 2 5" # E2E_VARIABLE=0 # single fixed WITHDRAW_AMT / PAY_AMT -# E2E_BANK_WITHDRAW_MAX=N # try at most N bank withdraws (budget) -# E2E_ATM_MAX=N # legacy alias of E2E_BANK_WITHDRAW_MAX +# E2E_ATM_MAX=N # try at most N ATM withdraws (budget) # --------------------------------------------------------------------------- : "${E2E_VARIABLE:=1}" -: "${E2E_BANK_WITHDRAW_MAX:=${E2E_ATM_MAX:-5}}" -E2E_ATM_MAX="${E2E_ATM_MAX:-$E2E_BANK_WITHDRAW_MAX}" # legacy alias +: "${E2E_ATM_MAX:=5}" if [ "$E2E_REMOTE" = "1" ]; then - # remote: still bank cash-note shaped; TESTPAYSAN needs larger notes for shop pays + # remote: still ATM-shaped; TESTPAYSAN needs larger notes for shop pays if [ "$CUR" = "TESTPAYSAN" ]; then : "${E2E_WITHDRAW_VALUES:=20 50}" # farmer shop template face values (oeufs-6=5, fromage=8.5, jus=6) @@ -249,7 +247,7 @@ if [ "$E2E_REMOTE" = "1" ]; then : "${E2E_PAY_VALUES:=0.01 0.05 0.1 1}" fi else - # local GOA: classic bank cash-note amounts + 4200 for paivana paywall template + # local GOA: classic ATM notes + 4200 for paivana paywall template : "${E2E_WITHDRAW_VALUES:=20 50 100 200 4200}" : "${E2E_PAY_VALUES:=0.01 0.05 0.1 0.5 1 2 5 10}" fi @@ -286,7 +284,7 @@ if [ "$E2E_VARIABLE" != "1" ]; then fi fi -# Credit = sum of planned Bank withdraws + small buffer for fees +# Credit = sum of planned ATM withdraws + small buffer for fees CREDIT_AMT=$(python3 -c ' import sys cur=sys.argv[1] @@ -303,7 +301,7 @@ print("%s:%g" % (cur, s + buf)) WITHDRAW_AMT=$(printf '%s' "$WITHDRAW_LIST" | awk '{print $1}') PAY_AMT=$(printf '%s' "$PAY_LIST" | awk '{print $1}') -# More wall time when running Bank withdraw ladder +# More wall time when running ATM ladder if [ "$E2E_VARIABLE" = "1" ]; then n_w=$(printf '%s' "$WITHDRAW_LIST" | wc -w | tr -d ' ') n_p=$(printf '%s' "$PAY_LIST" | wc -w | tr -d ' ') @@ -311,9 +309,9 @@ if [ "$E2E_VARIABLE" = "1" ]; then if [ "${E2E_TIMEOUT}" -lt "$need" ]; then E2E_TIMEOUT=$need fi - # cap bank withdraw attempts but always keep CUR:4200 if listed (paivana) + # cap ATM attempts but always keep CUR:4200 if listed (paivana) WITHDRAW_LIST=$( - printf '%s' "$WITHDRAW_LIST" | tr ' ' '\n' | awk -v max="$E2E_BANK_WITHDRAW_MAX" -v big="${CUR}:4200" ' + printf '%s' "$WITHDRAW_LIST" | tr ' ' '\n' | awk -v max="$E2E_ATM_MAX" -v big="${CUR}:4200" ' NF==0 { next } $0==big { has=1; next } { small[++n]=$0 } @@ -378,35 +376,13 @@ WALLET_CLI=$(find_wallet_cli) || { blocker "prereq" "taler-wallet-cli not found (set WALLET_CLI=)" exit 1 } -# wallet-core spawns `taler-helper-sqlite3` via PATH (not an absolute path). -# Ensure operator wallet bindir + ~/.local/bin are first (systemd mon jobs). -export PATH="${WALLET_CLI_BINDIR:+$WALLET_CLI_BINDIR:}${HOME}/.local/bin:/usr/local/bin:/usr/bin:/bin:${PATH:-}" -NODE_BIN=$(command -v node 2>/dev/null || true) -if [ -z "$NODE_BIN" ] || [ ! -x "$NODE_BIN" ]; then - blocker "prereq" "node not found on PATH (install Node or set PATH; need node for wallet-cli)" - exit 1 -fi -if ! command -v taler-helper-sqlite3 >/dev/null 2>&1; then - for _h in \ - "${WALLET_CLI_BINDIR:+$WALLET_CLI_BINDIR/taler-helper-sqlite3}" \ - "${HOME}/.local/bin/taler-helper-sqlite3" \ - /usr/bin/taler-helper-sqlite3 - do - [ -n "$_h" ] && [ -x "$_h" ] && export PATH="$(dirname "$_h"):$PATH" && break - done -fi -if ! command -v taler-helper-sqlite3 >/dev/null 2>&1; then - blocker "prereq" "taler-helper-sqlite3 not on PATH (wallet accept-uri/pay will fail with spawn ENOENT) — install next to wallet-cli or set WALLET_CLI_BINDIR" - exit 1 -fi -ok "wallet-helper" "taler-helper-sqlite3=$(command -v taler-helper-sqlite3)" # Implementation version (--version) + wallet-core API ranges (version command) WALLET_IMPL_VER=$( - "$NODE_BIN" "$WALLET_CLI" --version 2>/dev/null | head -1 | tr -d '\r' || true + node "$WALLET_CLI" --version 2>/dev/null | head -1 | tr -d '\r' || true ) WALLET_CORE_VER=$( _wver_db=$(mktemp "${TMPDIR:-/tmp}/wver.XXXXXX.sqlite3" 2>/dev/null || echo "${TMPDIR:-/tmp}/wver-$$.sqlite3") - "$NODE_BIN" "$WALLET_CLI" --wallet-db="$_wver_db" --no-throttle --skip-defaults version 2>/dev/null \ + node "$WALLET_CLI" --wallet-db="$_wver_db" --no-throttle --skip-defaults version 2>/dev/null \ | python3 -c ' import json,re,sys raw=sys.stdin.read() @@ -437,7 +413,7 @@ else fi info "e2e mode" "$([ "$E2E_REMOTE" = "1" ] && echo "remote/public domain (no SSH)" || echo "local koopa stack")" info "currency" "$CUR" -info "Bank withdraw ladder" "$WITHDRAW_LIST (credit $CREDIT_AMT)" +info "ATM withdraw ladder" "$WITHDRAW_LIST (credit $CREDIT_AMT)" info "pay ladder" "$PAY_LIST" info "e2e budget" "${E2E_TIMEOUT}s" @@ -455,7 +431,7 @@ set_group load section "e2e · load snapshot (before withdraw/pay)" metrics_report_load "${METRICS_DIR}/load-before.json" "e2e-start" || true -# Local stack: koopa secrets. Remote: env first; TESTPAYSAN stage may load stagepaysan secrets via FRANCPAYSAN_SSH/INSIDE_SSH. +# Local stack: koopa secrets. Remote: env first; TESTPAYSAN stage may load francpaysan host secrets. set_group prereq if [ "$E2E_REMOTE" = "1" ]; then ADMIN_PASS="${E2E_BANK_ADMIN_PASS:-${BANK_ADMIN_PASS:-}}" @@ -599,7 +575,7 @@ start_wallet_serve() { stop_wallet_serve rm -f "$WSOCK" # serve holds the DB open; clients use --wallet-connection only - "$NODE_BIN" "$WALLET_CLI" --wallet-db="$WDB" --no-throttle --skip-defaults \ + node "$WALLET_CLI" --wallet-db="$WDB" --no-throttle --skip-defaults \ advanced serve --unix-path "$WSOCK" \ >"$SCRATCH/wallet-serve.log" 2>&1 & WSERVE_PID=$! @@ -616,25 +592,6 @@ start_wallet_serve() { return 1 } -# Run node wallet-cli with a hard wall clock. Prefer GNU/coreutils `timeout` -# (clear errors). Fall back to perl alarm only if timeout is missing. -# Always use absolute NODE_BIN + WALLET_CLI so systemd PATH quirks cannot -# turn into opaque "alarm shift; exec @ARGV" noise in accept-uri output. -_wcli_exec() { - local cap="$1" - shift - local -a cmd=( "$NODE_BIN" "$WALLET_CLI" "$@" ) - if command -v timeout >/dev/null 2>&1; then - timeout -k 2 "$cap" "${cmd[@]}" - elif command -v gtimeout >/dev/null 2>&1; then - gtimeout --kill-after=2 "$cap" "${cmd[@]}" - elif command -v perl >/dev/null 2>&1; then - perl -e 'alarm shift; exec @ARGV' "$cap" "${cmd[@]}" - else - "${cmd[@]}" - fi -} - # $1 = max seconds for this call (optional); rest = wallet-cli args # Prefer live serve socket so the shepherd stays up (alternative to run-until-done). wcli() { @@ -646,15 +603,22 @@ wcli() { e2e_over && return 124 local cap cap=$(e2e_left) - # e2e_left may print warnings on stdout — keep only first integer token - cap=$(printf '%s' "$cap" | awk '/^[0-9]+$/{print; exit} {for(i=1;i<=NF;i++) if($i+0==$i){print $i; exit}}') - [ -z "$cap" ] && cap=$maxc - [ "$cap" -gt "$maxc" ] 2>/dev/null && cap=$maxc - [ "$cap" -lt 3 ] 2>/dev/null && return 124 + [ "$cap" -gt "$maxc" ] && cap=$maxc + [ "$cap" -lt 3 ] && return 124 if [ -n "${WSERVE_PID:-}" ] && [ -S "${WSOCK:-}" ]; then - _wcli_exec "$cap" --wallet-connection="$WSOCK" --no-throttle "$@" + if command -v perl >/dev/null 2>&1; then + perl -e 'alarm shift; exec @ARGV' "$cap" \ + node "$WALLET_CLI" --wallet-connection="$WSOCK" --no-throttle "$@" + else + node "$WALLET_CLI" --wallet-connection="$WSOCK" --no-throttle "$@" + fi else - _wcli_exec "$cap" --wallet-db="$WDB" --no-throttle --skip-defaults "$@" + if command -v perl >/dev/null 2>&1; then + perl -e 'alarm shift; exec @ARGV' "$cap" \ + node "$WALLET_CLI" --wallet-db="$WDB" --no-throttle --skip-defaults "$@" + else + node "$WALLET_CLI" --wallet-db="$WDB" --no-throttle --skip-defaults "$@" + fi fi } @@ -663,10 +627,9 @@ wcli_pay() { local cap=$E2E_PAY_SECS local left left=$(e2e_left) - left=$(printf '%s' "$left" | awk '/^[0-9]+$/{print; exit} {for(i=1;i<=NF;i++) if($i+0==$i){print $i; exit}}') - if [ -n "$left" ] && [ "$left" -gt "$cap" ] 2>/dev/null; then + if [ "$left" -gt "$cap" ]; then cap=$E2E_PAY_SECS - elif [ -n "$left" ] && [ "$left" -ge 8 ] 2>/dev/null; then + elif [ "$left" -ge 8 ]; then cap=$left else # still try once with floor 12s so Alarm clock is not the blocker @@ -674,9 +637,19 @@ wcli_pay() { fi info "pay wallet cap" "${cap}s" if [ -n "${WSERVE_PID:-}" ] && [ -S "${WSOCK:-}" ]; then - _wcli_exec "$cap" --wallet-connection="$WSOCK" --no-throttle "$@" + if command -v perl >/dev/null 2>&1; then + perl -e 'alarm shift; exec @ARGV' "$cap" \ + node "$WALLET_CLI" --wallet-connection="$WSOCK" --no-throttle "$@" + else + node "$WALLET_CLI" --wallet-connection="$WSOCK" --no-throttle "$@" + fi else - _wcli_exec "$cap" --wallet-db="$WDB" --no-throttle --skip-defaults "$@" + if command -v perl >/dev/null 2>&1; then + perl -e 'alarm shift; exec @ARGV' "$cap" \ + node "$WALLET_CLI" --wallet-db="$WDB" --no-throttle --skip-defaults "$@" + else + node "$WALLET_CLI" --wallet-db="$WDB" --no-throttle --skip-defaults "$@" + fi fi } @@ -890,7 +863,7 @@ else warn "wallet accept ToS" "$(tail -c 80 "$SCRATCH/ex-tos.out" | tr '\n' ' ')" fi fi -# Empty wallet baseline before bank withdraw / pay load +# Empty wallet baseline before ATM / pay load metrics_report_coins "wallet-ready" || true wd_status() { @@ -928,15 +901,15 @@ fake_incoming_speedup() { fi } -# One bank withdraw: create → accept → select → confirm → settle +# One ATM-style withdraw: create → accept → select → confirm → settle # returns 0 on wallet balance increase, 1 on soft fail (ladder continues) e2e_one_withdraw() { WITHDRAW_AMT="$1" local tag tag=$(printf '%s' "$WITHDRAW_AMT" | tr '.:' '__') - section "e2e · Bank withdraw $WITHDRAW_AMT · $(format_amount_alt "$WITHDRAW_AMT")" - e2e_over && { warn "Bank withdraw" "budget exhausted — skip $WITHDRAW_AMT"; return 1; } - metrics_report_coins "before-bank-wd-${tag}" || true + section "e2e · ATM withdraw $WITHDRAW_AMT · $(format_amount_alt "$WITHDRAW_AMT")" + e2e_over && { warn "ATM withdraw" "budget exhausted — skip $WITHDRAW_AMT"; return 1; } + metrics_report_coins "before-ATM-${tag}" || true curl -sS -m 15 -o "$SCRATCH/wd-$tag.json" -H "Authorization: Bearer $UT" \ -H 'Content-Type: application/json' \ @@ -944,29 +917,23 @@ e2e_one_withdraw() { "$BANK/accounts/${USER}/withdrawals" WID=$(python3 -c 'import json;d=json.load(open("'"$SCRATCH"'/wd-'"$tag"'.json"));print(d.get("withdrawal_id") or d.get("id") or "")' 2>/dev/null || true) URI=$(python3 -c 'import json;d=json.load(open("'"$SCRATCH"'/wd-'"$tag"'.json"));print(d.get("taler_withdraw_uri") or "")' 2>/dev/null || true) - URI_CLEAN=$(normalize_taler_uri "$URI") + URI_CLEAN=$(python3 -c 'import json;u=json.load(open("'"$SCRATCH"'/wd-'"$tag"'.json")).get("taler_withdraw_uri") or "";print(u.replace(":443/","/"))' 2>/dev/null || true) if [ -z "$WID" ] || [ -z "$URI_CLEAN" ]; then - warn "Bank withdraw $WITHDRAW_AMT" "create failed — $(head -c 80 "$SCRATCH/wd-$tag.json" | tr '\n' ' ')" + warn "ATM withdraw $WITHDRAW_AMT" "create failed — $(head -c 80 "$SCRATCH/wd-$tag.json" | tr '\n' ' ')" return 1 fi - ok "Bank withdrawal created $WITHDRAW_AMT ($WID)" + ok "ATM withdrawal created $WITHDRAW_AMT ($WID)" cp "$SCRATCH/wd-$tag.json" "$SCRATCH/wd.json" - # Always prefer stripped URI (libeufin often emits host:443) - USE_URI="${URI_CLEAN:-$URI}" + USE_URI="$URI" + [ -z "$USE_URI" ] && USE_URI="$URI_CLEAN" if wcli withdraw accept-uri --exchange "${EXCHANGE_PUBLIC}/" "$USE_URI" >"$SCRATCH/accept-$tag.out" 2>&1; then ok "wallet accept $WITHDRAW_AMT" - elif [ -n "$URI" ] && [ "$USE_URI" != "$URI" ] \ - && wcli withdraw accept-uri --exchange "${EXCHANGE_PUBLIC}/" "$URI" >"$SCRATCH/accept-$tag.out" 2>&1; then - ok "wallet accept $WITHDRAW_AMT (raw URI fallback)" + elif [ "$USE_URI" != "$URI_CLEAN" ] && [ -n "$URI_CLEAN" ] \ + && wcli withdraw accept-uri --exchange "${EXCHANGE_PUBLIC}/" "$URI_CLEAN" >"$SCRATCH/accept-$tag.out" 2>&1; then + ok "wallet accept $WITHDRAW_AMT (no :443)" else - # Prefer the real Error/ENOENT line over noise (perl -e source, stack frames) - _acc_err=$( - grep -E 'Error:|ENOENT|spawn taler-helper|code:|An error occurred' \ - "$SCRATCH/accept-$tag.out" 2>/dev/null | head -3 | tr '\n' ' ' | head -c 200 - ) - [ -z "$_acc_err" ] && _acc_err=$(tail -c 160 "$SCRATCH/accept-$tag.out" 2>/dev/null | tr '\n' ' ') - warn "Bank withdraw $WITHDRAW_AMT" "accept-uri failed — ${_acc_err:-unknown}" + warn "ATM withdraw $WITHDRAW_AMT" "accept-uri failed — $(tail -c 100 "$SCRATCH/accept-$tag.out" | tr '\n' ' ')" return 1 fi cp "$SCRATCH/accept-$tag.out" "$SCRATCH/accept.out" @@ -1008,7 +975,7 @@ else: fi fi if [ "$st" != "selected" ] && [ "$st" != "confirmed" ]; then - warn "Bank withdraw $WITHDRAW_AMT" "not selected (status=${st:-?})" + warn "ATM withdraw $WITHDRAW_AMT" "not selected (status=${st:-?})" return 1 fi if [ "$st" != "confirmed" ]; then @@ -1017,32 +984,32 @@ else: "$BANK/accounts/${USER}/withdrawals/${WID}/confirm") case "$code" in 200|204) ok "bank confirm $WITHDRAW_AMT" ;; - *) warn "Bank withdraw $WITHDRAW_AMT" "confirm HTTP $code"; return 1 ;; + *) warn "ATM withdraw $WITHDRAW_AMT" "confirm HTTP $code"; return 1 ;; esac fi fake_incoming_speedup - # Short per-withdraw settle: poll balance + bank transfer_done only (never run-until-done) + # Short per-ATM settle: poll balance + bank transfer_done only (never run-until-done) local ok_bal=0 r av xfer for r in 1 2 3 4 5 6 8 10; do wcli_bal_snap "$SCRATCH/bal-$tag.out" || wcli balance >"$SCRATCH/bal-$tag.out" 2>&1 || true av=$(wallet_avail_num "$SCRATCH/bal-$tag.out") if python3 -c "import sys; sys.exit(0 if float(sys.argv[1]) > 0 else 1)" "$av" 2>/dev/null; then ok_bal=1 - ok "wallet funded after bank withdraw $WITHDRAW_AMT" "avail=${CUR}:${av}" + ok "wallet funded after ATM $WITHDRAW_AMT" "avail=${CUR}:${av}" info "balance" "$(fmt_bal "$SCRATCH/bal-$tag.out")" break fi xfer=$(curl -sS -m 8 "$BANK/taler-integration/withdrawal-operation/${WID}" 2>/dev/null \ | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d.get("transfer_done"), d.get("status"))' 2>/dev/null || echo "?") if echo "$xfer" | grep -qi True; then - ok "Bank withdraw $WITHDRAW_AMT bank transfer_done" "wallet avail=${CUR}:${av} ($xfer) — no run-until-done" + ok "ATM $WITHDRAW_AMT bank transfer_done" "wallet avail=${CUR}:${av} ($xfer) — no run-until-done" ok_bal=1 break fi sleep 2 done - metrics_report_coins "after-bank-wd-${tag}" || true + metrics_report_coins "after-ATM-${tag}" || true if [ "$ok_bal" = "1" ]; then metrics_record_flow withdrawn "$WITHDRAW_AMT" || true return 0 @@ -1050,10 +1017,10 @@ else: # Bank side often already confirmed — treat as timing lag, not hard fail st=$(wd_status) if [ "$st" = "confirmed" ]; then - warn "Bank withdraw $WITHDRAW_AMT" "bank confirmed; wallet not funded yet (settlement timing — will recheck later)" + warn "ATM withdraw $WITHDRAW_AMT" "bank confirmed; wallet not funded yet (settlement timing — will recheck later)" return 2 fi - warn "Bank withdraw $WITHDRAW_AMT" "no wallet balance yet (status=${st:-?})" + warn "ATM withdraw $WITHDRAW_AMT" "no wallet balance yet (status=${st:-?})" return 1 } @@ -1368,8 +1335,8 @@ sys.exit(1) } # --------------------------------------------------------------------------- -set_group bankwd -section "e2e · Bank withdraw ladder" +set_group atm +section "e2e · ATM withdraw ladder" # --------------------------------------------------------------------------- WITHDRAW_OK=0 WITHDRAW_OK_N=0 @@ -1377,7 +1344,7 @@ WITHDRAW_LAG_N=0 WITHDRAW_FAIL_N=0 WITHDRAW_REPORT="" for WITHDRAW_AMT in $WITHDRAW_LIST; do - e2e_over && { warn "Bank withdraw ladder" "time budget low — stopping more Bank withdraws (not a protocol error)"; break; } + e2e_over && { warn "ATM ladder" "time budget low — stopping more ATM withdraws (not a protocol error)"; break; } set +e e2e_one_withdraw "$WITHDRAW_AMT" wc=$? @@ -1398,26 +1365,26 @@ for WITHDRAW_AMT in $WITHDRAW_LIST; do ;; esac done -info "Bank withdraw summary" "$WITHDRAW_REPORT (ok=$WITHDRAW_OK_N lag=$WITHDRAW_LAG_N fail=$WITHDRAW_FAIL_N)" +info "ATM withdraw summary" "$WITHDRAW_REPORT (ok=$WITHDRAW_OK_N lag=$WITHDRAW_LAG_N fail=$WITHDRAW_FAIL_N)" set_group load -section "e2e · load snapshot (after Bank withdraws)" +section "e2e · load snapshot (after ATM withdraws)" metrics_report_load "${METRICS_DIR}/load-after-withdraw.json" "after-withdraw" || true cp -f "${METRICS_DIR}/load-after-withdraw.json" "${METRICS_DIR}/load-after.json" 2>/dev/null || true -metrics_report_coins "after-bank-wd-ladder" || true +metrics_report_coins "after-ATM-ladder" || true # Settlement catch-up: bank may have confirmed while wallet was still empty set_group settle section "e2e · wallet settlement (timing)" if ! wait_wallet_balance 0 "${E2E_SETTLE_ROUNDS}" "${E2E_SETTLE_SLEEP}"; then if [ "$WITHDRAW_LAG_N" -gt 0 ] || [ "$WITHDRAW_OK_N" -gt 0 ]; then - warn "settlement timing" "bank withdraw path reached bank confirm (lag=$WITHDRAW_LAG_N ok=$WITHDRAW_OK_N) but wallet empty after wait — TIME lag, not protocol error" + warn "settlement timing" "ATM path reached bank confirm (lag=$WITHDRAW_LAG_N ok=$WITHDRAW_OK_N) but wallet empty after wait — TIME lag, not protocol error" fi fi av_now=$(wallet_avail_num) if python3 -c "import sys; sys.exit(0 if float(sys.argv[1]) > 0 else 1)" "$av_now" 2>/dev/null; then WITHDRAW_OK=1 if [ "$WITHDRAW_OK_N" = "0" ]; then - warn "settlement timing" "coins arrived after Bank withdraw ladder (${CUR}:${av_now}) — earlier 'FAIL' was timing lag" + warn "settlement timing" "coins arrived after ATM ladder (${CUR}:${av_now}) — earlier 'FAIL' was timing lag" WITHDRAW_REPORT="${WITHDRAW_REPORT} → late-OK avail=${CUR}:${av_now}" fi ok "spendable balance for payments" "${CUR}:${av_now}" @@ -1436,7 +1403,7 @@ else WITHDRAW_OK=1 warn "settlement timing" "coins present after dig wait (${CUR}:${av_now}) — timing, not blocker" else - blocker "withdraw-settle" "no spendable ${CUR} after Bank withdraw ladder + settle wait ($WITHDRAW_LIST)" + blocker "withdraw-settle" "no spendable ${CUR} after ATM ladder + settle wait ($WITHDRAW_LIST)" section "e2e · report" info "WITHDRAW" "$WITHDRAW_REPORT — no coins after extended wait" info "PAY" "SKIPPED (no spendable balance after settle wait)" @@ -1629,7 +1596,7 @@ set_group paivana section "e2e · paivana paywall (template GOA:4200)" # --------------------------------------------------------------------------- # Public paywall: https://paivana.hacktivism.ch → 302 to merchant template "paivana". -# Requires spendable ≥ 4200 GOA (Bank withdraw ladder includes GOA:4200 by default). +# Requires spendable ≥ 4200 GOA (ATM ladder includes GOA:4200 by default). : "${PAIVANA_PUBLIC:=https://paivana.hacktivism.ch}" : "${E2E_PAIVANA:=1}" : "${E2E_PAIVANA_TEMPLATE:=paivana}" @@ -1663,11 +1630,11 @@ else ;; esac - # Ensure wallet can cover 4200 (extra bank withdraw if ladder did not fund enough) + # Ensure wallet can cover 4200 (extra ATM if ladder did not fund enough) pay_need=$(python3 -c 'import sys; print(float(sys.argv[1].split(":",1)[-1]))' "$E2E_PAIVANA_AMOUNT" 2>/dev/null || echo 4200) av_now=$(wallet_avail_num) if ! python3 -c "import sys; sys.exit(0 if float(sys.argv[1]) + 1e-9 >= float(sys.argv[2]) else 1)" "$av_now" "$pay_need" 2>/dev/null; then - info "paivana" "avail ${CUR}:${av_now} < ${pay_need} — Bank withdraw ${E2E_PAIVANA_AMOUNT}" + info "paivana" "avail ${CUR}:${av_now} < ${pay_need} — ATM withdraw ${E2E_PAIVANA_AMOUNT}" e2e_over && warn "paivana" "budget low before 4200 withdraw" set +e e2e_one_withdraw "$E2E_PAIVANA_AMOUNT" @@ -1720,7 +1687,7 @@ fi set_group report section "e2e · report" info "user" "$USER" -info "Bank withdraws" "$WITHDRAW_REPORT" +info "ATM withdraws" "$WITHDRAW_REPORT" info "payments" "$PAY_REPORT" info "shop" "${SHOP_REPORT:-(n/a)}" info "paivana" "${PAIVANA_REPORT:-(n/a)}" diff --git a/check_goa_ladder.sh b/check_goa_ladder.sh new file mode 100755 index 0000000..410205f --- /dev/null +++ b/check_goa_ladder.sh @@ -0,0 +1,1356 @@ +#!/usr/bin/env bash +# check_goa_ladder.sh — withdraw/pay amount ladder (GOA + stage TESTPAYSAN) +# +# Flow (bank landings): +# 1) GET /intro/auto-account.json → personal *account-* (balance 0) +# 2) Mint pool withdrawals as explorer + confirm when selected +# 3) wallet-cli accept-uri only (no run-until-done) +# 4) bank confirm when selected; settle = balance + transfer_done +# +# Amounts: random strictly increasing; pins 0, max-1, max. +# Phase A: withdraw ladder (cumulative wallet). Phase B: pay ladder. +# +# Stacks: +# GOA — LADDER_MAX_AMOUNT = libeufin ceiling; explorer from koopa-admin-secrets +# TESTPAYSAN stage — auto max_wire from bank /config, min denom from /keys; +# explorer from stagepaysan secrets / SSH +# +# Usage: +# ./taler-monitoring.sh ladder +# ./taler-monitoring.sh -d stage.lefrancpaysan.ch ladder +# LADDER_MAX_AMOUNT=100 LADDER_STEPS=7 ./taler-monitoring.sh -d stage.lefrancpaysan.ch ladder +# +# Env (see body): LADDER_STEPS, LADDER_MAX_AMOUNT, LADDER_MIN_AMOUNT, LADDER_STACK_AUTO, +# LADDER_PAY, EXP_PW / EXP_PW_FILE, CLI_JS, MERCHANT_INSTANCE, … +set -euo pipefail +ROOT=$(cd "$(dirname "$0")" && pwd) +# shellcheck source=lib.sh +source "$ROOT/lib.sh" +# When invoked standalone (not via taler-monitoring.sh), still load secrets.env +load_monitoring_secrets_env 2>/dev/null || true + +# Area ladder.* — withdraw/pay amount ladder (GOA + TESTPAYSAN) +# Groups: ladder.plan / ladder.load / ladder.withdraw / ladder.pay / ladder.report +set_area ladder +set_group plan +SECTION_T0=$(date +%s) +now_ms() { python3 -c 'import time; print(int(time.time()*1000))'; } +elapsed_ms() { + # elapsed_ms START_MS + python3 -c 'import sys; print(int(sys.argv[1]) - int(sys.argv[2]))' "$(now_ms)" "$1" +} + +: "${LADDER_TIMEOUT_S:=3600}" +: "${LADDER_SETTLE_ROUNDS:=18}" +: "${LADDER_SETTLE_SLEEP:=2}" +: "${EXP_USER:=explorer}" +# EXP_PW_FILE / EXP_PW optional overrides; otherwise read_secret + SECRETS_ROOT / stage SSH +: "${EXP_PW_FILE:=}" +: "${EXP_PW:=}" +: "${CLI_JS:=}" +# GOA libeufin amount ceiling (hacktivism). Stage auto-replaces via bank /config. +: "${LADDER_MAX_AMOUNT:=4503599627370496}" +: "${LADDER_STEPS:=23}" +: "${LADDER_LOAD:=1}" +: "${LADDER_PAY:=1}" +: "${LADDER_STACK_AUTO:=1}" +# Withdraw mids = pay mids × scale (so wallet can afford the pay ladder) +: "${LADDER_WITHDRAW_SCALE:=1.5}" +# Floor for random mids (must be ≥ smallest exchange coin; GOA min denom ≈ 0.000001) +: "${LADDER_MIN_AMOUNT:=0.000001}" +: "${LADDER_CONFIRM_POLLS:=40}" +: "${LADDER_PAY_SETTLE_ROUNDS:=6}" +: "${MERCHANT_INSTANCE:=goa-demo-cp4zqk}" +# Public variable template for stage pays (optional; fixed templates used when amount maps) +: "${LADDER_PAY_TEMPLATE:=}" +: "${LADDER_PAY_TEMPLATE_INSTANCE:=fermes-des-collines}" + +GOA_LADDER_CEILING="4503599627370496" + +# Resolve wallet-cli .mjs (no hardcoded laptop path) +if [ -z "${CLI_JS}" ] || [ ! -f "${CLI_JS}" ]; then + CLI_JS=$(find_wallet_cli 2>/dev/null || true) +fi +if [ -z "${CLI_JS}" ] || [ ! -f "${CLI_JS}" ]; then + # allow PATH wrapper as last resort (wcli falls back to taler-wallet-cli) + CLI_JS="" +fi + +CUR="${EXPECT_CURRENCY:-GOA}" +BANK="${BANK_PUBLIC%/}" +EX="${EXCHANGE_PUBLIC%/}/" +MER="${MERCHANT_PUBLIC%/}" +INST="${MERCHANT_INSTANCE}" + +# --- Stack-specific ladder maxima (TESTPAYSAN stage) --- +# Uses bank max_wire_transfer_amount and exchange min denom when still on GOA defaults. +apply_ladder_stack_defaults() { + [ "${LADDER_STACK_AUTO}" = "1" ] || return 0 + if [ "${CUR}" != "TESTPAYSAN" ]; then + case "${TALER_DOMAIN:-}" in + stage.lefrancpaysan.ch|stage.bank.lefrancpaysan.ch|stage.exchange.lefrancpaysan.ch|stage.monnaie.lefrancpaysan.ch) + CUR="TESTPAYSAN" + ;; + *) return 0 ;; + esac + fi + + local bank_cfg max_wire min_denom + bank_cfg=$(curl -sS -m 12 "${BANK}/config" 2>/dev/null || true) + max_wire=$(printf '%s' "$bank_cfg" | python3 -c ' +import json,sys +try: + d=json.load(sys.stdin) +except Exception: + print("") + raise SystemExit(0) +a=d.get("max_wire_transfer_amount") or "" +print(a.split(":",1)[-1] if a else "") +' 2>/dev/null || true) + + min_denom=$(curl -sS -m 25 -H 'Accept: application/json' "${EX%/}/keys" 2>/dev/null | python3 -c ' +import json,sys +try: + d=json.load(sys.stdin) +except Exception: + print("") + raise SystemExit(0) +den=d.get("denoms") or d.get("denominations") or [] +vals=[] +for x in den if isinstance(den,list) else []: + v=x.get("value") or x.get("amount") or "" + if not v: continue + try: vals.append(float(str(v).split(":")[-1])) + except Exception: pass +print(min(vals) if vals else "") +' 2>/dev/null || true) + + # Fallback maxima if public config unreachable + [ -n "$max_wire" ] || max_wire="2000" + [ -n "$min_denom" ] || min_denom="0.01" + + # Only rewrite when caller left GOA defaults (explicit LADDER_MAX_AMOUNT=… kept) + if [ -n "$max_wire" ] && { [ "${LADDER_MAX_AMOUNT}" = "${GOA_LADDER_CEILING}" ] || [ "${LADDER_MAX_AMOUNT}" = "4503599627370496" ]; }; then + LADDER_MAX_AMOUNT="$max_wire" + fi + if [ -n "$min_denom" ] && { [ "${LADDER_MIN_AMOUNT}" = "0.000001" ] || [ "${LADDER_MIN_AMOUNT}" = "0.00000001" ]; }; then + LADDER_MIN_AMOUNT="$min_denom" + fi + # Slightly fewer rungs on stage (full GOA 23 still ok if user set LADDER_STEPS) + if [ "${LADDER_STEPS}" = "23" ]; then + LADDER_STEPS=15 + fi + # Stage farmer shops: private goa-demo instance does not exist + if [ "${MERCHANT_INSTANCE}" = "goa-demo-cp4zqk" ]; then + MERCHANT_INSTANCE="${LADDER_PAY_TEMPLATE_INSTANCE:-fermes-des-collines}" + INST="$MERCHANT_INSTANCE" + fi + # Prefer public templates for pays when no merchant token (set later) + : "${E2E_USE_TEMPLATES:=1}" + export E2E_USE_TEMPLATES + export LADDER_MAX_AMOUNT LADDER_MIN_AMOUNT LADDER_STEPS MERCHANT_INSTANCE + info "ladder stack" "TESTPAYSAN · max=${CUR}:${LADDER_MAX_AMOUNT} min=${CUR}:${LADDER_MIN_AMOUNT} steps=${LADDER_STEPS} (from bank max_wire / keys denoms)" +} +apply_ladder_stack_defaults +SCRATCH=$(mktemp -d) +WDB="$SCRATCH/wallet.sqlite3" +REPORT_DIR="${LADDER_REPORT_DIR:-$SCRATCH}" +mkdir -p "$REPORT_DIR" +TSV="$REPORT_DIR/ladder-results.tsv" +PAY_TSV="$REPORT_DIR/ladder-pay-results.tsv" +JSON="$REPORT_DIR/ladder-report.json" +LOAD_BEFORE="$REPORT_DIR/load-before.json" +LOAD_AFTER="$REPORT_DIR/load-after.json" +echo -e "rung\trange\tamount\tstatus\tms_mint\tms_accept\tms_confirm\tms_settle\tms_total\twid\tnote" >"$TSV" +echo -e "rung\trange\tamount\tstatus\tms_order\tms_handle\tms_settle\tms_total\toid\tnote" >"$PAY_TSV" + +ladder_over() { + local now + now=$(date +%s) + [ $((now - SECTION_T0)) -ge "$LADDER_TIMEOUT_S" ] +} + +wcli() { + if [ -n "${CLI_JS:-}" ] && [ -f "$CLI_JS" ]; then + node "$CLI_JS" --wallet-db="$WDB" --no-throttle "$@" + else + taler-wallet-cli --wallet-db="$WDB" --no-throttle "$@" + fi +} + +# Explorer pool password: env → file override → stack secrets → SSH +resolve_explorer_pw() { + local pw="" f="" host="" + if [ -n "${EXP_PW:-}" ]; then + printf '%s' "$EXP_PW" + return 0 + fi + if [ -n "${EXP_PW_FILE:-}" ] && [ -f "$EXP_PW_FILE" ]; then + tr -d '\n\r' <"$EXP_PW_FILE" + return 0 + fi + + # Stage TESTPAYSAN — never use GOA koopa-admin-secrets explorer pw first + if [ "${CUR}" = "TESTPAYSAN" ] \ + || [[ "${TALER_DOMAIN:-}" == stage.*lefrancpaysan* ]] \ + || [[ "${TALER_DOMAIN:-}" == *stage.lefrancpaysan* ]]; then + for f in \ + ${FRANCPAYSAN_SECRETS:+"${FRANCPAYSAN_SECRETS}/stage/bank-explorer-password.txt"} \ + "${HOME}/.config/taler-landing/stage-bank-explorer-password.txt" + do + [ -n "$f" ] && [ -f "$f" ] || continue + tr -d '\n\r' <"$f" + return 0 + done + _remote_exp="${FRANCPAYSAN_REMOTE_BANK_EXPLORER_SECRET:-}" + [ -z "$_remote_exp" ] && [ -n "${FRANCPAYSAN_REMOTE_SECRETS_ROOT:-}" ] && \ + _remote_exp="${FRANCPAYSAN_REMOTE_SECRETS_ROOT}/bank/secrets/bank-explorer-password.txt" + for host in ${INSIDE_SSH:+"$INSIDE_SSH"} ${FRANCPAYSAN_SSH:+"$FRANCPAYSAN_SSH"}; do + [ -n "$host" ] && [ -n "$_remote_exp" ] || continue + pw=$(ssh -o BatchMode=yes -o ConnectTimeout=12 "$host" \ + "tr -d '\\n\\r' <${_remote_exp} 2>/dev/null || sudo tr -d '\\n\\r' <${_remote_exp} 2>/dev/null" \ + 2>/dev/null || true) + if [ -n "$pw" ]; then + printf '%s' "$pw" + return 0 + fi + done + return 1 + fi + + # GOA / default: SECRETS_ROOT / ~/.config / koopa SSH + if pw=$(read_secret "taler-bank/bank-explorer-password.txt" 2>/dev/null) && [ -n "$pw" ]; then + printf '%s' "$pw" + return 0 + fi + for f in \ + "${SECRETS_ROOT:+${SECRETS_ROOT}/taler-bank/bank-explorer-password.txt}" \ + "${HOME}/.config/taler-landing/bank-explorer-password.txt" + do + [ -n "$f" ] && [ -f "$f" ] || continue + tr -d '\n\r' <"$f" + return 0 + done + return 1 +} + +wallet_avail() { + wcli balance 2>/dev/null | python3 -c ' +import json,sys +t=sys.stdin.read() +i=t.find("{") +if i<0: + print("0"); raise SystemExit +d=json.loads(t[i:t.rfind("}")+1]) +cur=sys.argv[1] +for b in d.get("balances") or []: + a=b.get("available") or "" + if a.startswith(cur+":"): + print(a.split(":",1)[1]); raise SystemExit +print("0") +' "$CUR" 2>/dev/null || echo "0" +} + +# Build paired pay + withdraw ladders (same step count, shared random shape). +# Pay: [0] + log-uniform mids + [max-1] + [max] +# Wd: [0] + max(mid, mid×scale) mids + [max-1] + [max] (mids higher → enough to spend) +# Writes: $1 = withdraw list file, $2 = pay list file (space-separated CUR:amt lines as one line each) +build_ladder_pair() { + local wd_out="$1" pay_out="$2" + python3 - <<'PY' "$CUR" "${LADDER_MAX_AMOUNT}" "${LADDER_STEPS}" "${LADDER_MIN_AMOUNT}" "${LADDER_WITHDRAW_SCALE}" "$wd_out" "$pay_out" +import math, random, sys +from decimal import Decimal, ROUND_HALF_UP, ROUND_UP +from pathlib import Path + +cur = sys.argv[1] +max_amt = Decimal(sys.argv[2]) +steps = max(1, int(sys.argv[3])) +min_amt = Decimal(sys.argv[4]) +scale = Decimal(sys.argv[5]) +wd_path, pay_path = Path(sys.argv[6]), Path(sys.argv[7]) +if min_amt <= 0: + min_amt = Decimal("0.000001") +if min_amt >= max_amt: + min_amt = max_amt / Decimal(1000) +if scale < 1: + scale = Decimal(1) +max_m1 = max_amt - Decimal(1) if max_amt > 1 else max_amt + +def fmt(v: Decimal) -> str: + q = v.quantize(Decimal("0.00000001"), rounding=ROUND_HALF_UP) + if q == q.to_integral(): + return format(int(q), "d") + return format(q, "f").rstrip("0").rstrip(".") + +def quant(v: Decimal) -> Decimal: + if v >= 1: + return v.quantize(Decimal(1), rounding=ROUND_HALF_UP) + if v < min_amt: + return min_amt + return v.quantize(Decimal("0.00000001"), rounding=ROUND_UP) + +def amt(v: Decimal) -> str: + return "%s:%s" % (cur, fmt(v)) + +def make_mids(n_mid: int, hi_cap: Decimal): + if n_mid <= 0 or hi_cap <= min_amt: + return [] + lo, hi = float(min_amt), float(hi_cap) * 0.999999 + if hi <= lo: + hi = lo * 10 + cuts = sorted(math.exp(random.uniform(math.log(lo), math.log(hi))) for _ in range(n_mid)) + out, prev = [], Decimal(0) + for c in cuts: + v = quant(Decimal(str(c))) + if v <= prev: + step = min_amt if prev < 1 else max(prev * Decimal("1e-6"), Decimal(1)) + v = quant(prev + step) + if v >= hi_cap: + v = quant(hi_cap - (Decimal(1) if hi_cap > 1 else min_amt)) + if v <= prev or v >= hi_cap: + continue + out.append(v) + prev = v + return out + +# Build withdraw ladder first (full range), then pay mids = withdraw/scale +# so each pay mid is always cheaper than the matching withdraw mid. +if steps == 1: + wd_vals = [max_amt] +elif steps == 2: + wd_vals = [Decimal(0), max_amt] +else: + n_mid = max(0, steps - 3) + wd_vals = [Decimal(0)] + make_mids(n_mid, max_m1) + [max_m1, max_amt] + while len(wd_vals) > steps and len(wd_vals) > 3: + wd_vals.pop(len(wd_vals) // 2) + while len(wd_vals) < steps and len(wd_vals) >= 2: + i = max(1, len(wd_vals) - 2) + a, b = wd_vals[i - 1], wd_vals[i] + if a <= 0: + m = max(min_amt, b / 2 if b > 0 else min_amt) + else: + m = (a * b).sqrt() if a * b > 0 else (a + b) / 2 + m = quant(m) + if m <= a or m >= b: + break + wd_vals.insert(i, m) + wd_vals = wd_vals[:steps] + +pay_vals = [] +prev_p = Decimal(-1) +for i, w in enumerate(wd_vals): + is_first = i == 0 + is_last = i == len(wd_vals) - 1 + is_m1 = (not is_last) and w == max_m1 and i == len(wd_vals) - 2 + if is_first and w == 0: + pay_vals.append(Decimal(0)) + prev_p = Decimal(0) + continue + if is_last: + pay_vals.append(max_amt) + continue + if is_m1 or w == max_m1: + pay_vals.append(max_m1) + prev_p = max_m1 + continue + # pay mid = withdraw / scale (strictly less funding needed per step) + p = quant(w / scale) if scale > 0 else w + if p < min_amt and w >= min_amt: + p = min_amt + if p <= prev_p: + p = quant(prev_p + (min_amt if prev_p < 1 else Decimal(1))) + if p >= w: + # keep pay strictly below this withdraw rung when possible + p = quant(w - (Decimal(1) if w > 1 else min_amt)) if w > prev_p else prev_p + if p <= prev_p: + p = prev_p # flat ok only if stuck; still ≤ w + pay_vals.append(p) + prev_p = p + +assert len(pay_vals) == len(wd_vals) +# sanity: every non-pin pay mid ≤ matching withdraw mid +for i, (p, w) in enumerate(zip(pay_vals, wd_vals)): + if i == 0 or i >= len(wd_vals) - 2: + continue + if p > w: + pay_vals[i] = w + +wd_path.write_text(" ".join(amt(v) for v in wd_vals) + "\n") +pay_path.write_text(" ".join(amt(v) for v in pay_vals) + "\n") +print(" ".join(amt(v) for v in wd_vals)) +PY +} + +# shellcheck source=metrics.sh +source "$ROOT/metrics.sh" +METRICS_DIR="$REPORT_DIR" +ALT_UNITS_FILE="${REPORT_DIR}/alt_unit_names.json" +export METRICS_DIR CUR WDB CLI_JS ALT_UNITS_FILE +# Ladder can disable host load without killing coin metrics +if [ "${LADDER_LOAD:-1}" = "0" ]; then + METRICS_LOAD=0 + export METRICS_LOAD +fi + +section "ladder · ${CUR} withdraw (0 → random → max · ${LADDER_STEPS} steps)" +info "bank" "$BANK" +info "exchange" "$EX" +info "currency" "$CUR" +# alt_unit_names for human amounts (Kilo-GOA / Mega-GOA / … + GOA in parentheses) +if metrics_load_alt_units "${EX%/}/config"; then + info "alt_unit_names" "from ${EX%/}/config → $ALT_UNITS_FILE" +else + warn "alt_unit_names" "using built-in SI fallback ($ALT_UNITS_FILE)" +fi +info "budget" "${LADDER_TIMEOUT_S}s" +_max_m1=$(python3 -c 'import sys; from decimal import Decimal; m=Decimal(sys.argv[1]); print(m-1 if m>1 else m)' "${LADDER_MAX_AMOUNT}" 2>/dev/null || echo "${LADDER_MAX_AMOUNT}-1") +info "steps" "${LADDER_STEPS} (0 + random≥${LADDER_MIN_AMOUNT} + max-1=${CUR}:${_max_m1} + max=${CUR}:${LADDER_MAX_AMOUNT})" +info "withdraw_scale" "${LADDER_WITHDRAW_SCALE}× pay mids (fund pay ladder)" +info "pay_phase" "$([ "${LADDER_PAY}" = "1" ] && echo enabled || echo disabled)" +info "currency/domain" "${CUR} · ${TALER_DOMAIN:-?} · bank=${BANK}" + +set_group load +section "ladder · load snapshot (before withdraws)" +metrics_report_load "$LOAD_BEFORE" "ladder-start" || true +# Fresh wallet per rung — baseline empty (or last-rung DB if re-used later) +metrics_report_coins "ladder-start" || true + +if ! EXP_PW=$(resolve_explorer_pw); then + err bank "explorer password missing" \ + "set EXP_PW / EXP_PW_FILE or SECRETS_ROOT=…/koopa/host-root (taler-bank/bank-explorer-password.txt)${SECRETS_ROOT:+ · SECRETS_ROOT=${SECRETS_ROOT}}" + secrets_hint 2>/dev/null || true + exit 1 +fi +if [ -n "${SECRETS_ROOT:-}" ]; then + info "explorer secret" "resolved (SECRETS_ROOT=${SECRETS_ROOT} · stage uses stagepaysan secret first when CUR=TESTPAYSAN)" +else + info "explorer secret" "resolved via EXP_PW / EXP_PW_FILE / stage SSH / koopa" +fi +if [ -n "${CLI_JS:-}" ] && [ -f "${CLI_JS}" ]; then + info "wallet-cli" "$CLI_JS" +else + info "wallet-cli" "PATH taler-wallet-cli ($(command -v taler-wallet-cli 2>/dev/null || echo missing))" +fi + +# --- auto-account --- +t0=$(now_ms) +if ! curl -sS -m 30 -o "$SCRATCH/auto-account.json" "${BANK}/intro/auto-account.json"; then + err bank "auto-account.json unreachable" + exit 1 +fi +ms_auto=$(elapsed_ms "$t0") +if ! python3 -c 'import json; d=json.load(open("'"$SCRATCH"'/auto-account.json")); assert d.get("ok") or d.get("username")' 2>/dev/null; then + err bank "auto-account create failed" "$(head -c 120 "$SCRATCH/auto-account.json" | tr '\n' ' ')" + exit 1 +fi +ACCT_USER=$(python3 -c 'import json; print(json.load(open("'"$SCRATCH"'/auto-account.json"))["username"])') +ok "auto-account ${ACCT_USER} (${ms_auto}ms) — personal ${CUR}:0; pool=explorer" +info "auto-account password" "(see $SCRATCH/auto-account.json — not logged)" + +# --- explorer token --- +t0=$(now_ms) +TOK=$(curl -sS -m 20 -u "${EXP_USER}:${EXP_PW}" \ + -H 'Content-Type: application/json' \ + -d '{"scope":"readwrite","duration":{"d_us":3600000000}}' \ + "${BANK}/accounts/${EXP_USER}/token" \ + | python3 -c 'import json,sys; print(json.load(sys.stdin)["access_token"])') +ms_tok=$(elapsed_ms "$t0") +[ -n "$TOK" ] || { err bank "explorer token failed"; exit 1; } +ok "explorer token (${ms_tok}ms)" + +# ONE cumulative wallet for all withdraws + pays (need balance to spend). +# force-select uses *last* reserve_pub from the current accept output. +wallet_prepare() { + local label="${1:-wallet}" + WDB="$SCRATCH/wallet-${label}.sqlite3" + export WDB + if [ ! -f "$WDB" ]; then + wcli exchanges add "$EX" >"$SCRATCH/ex-add-$label.out" 2>&1 || true + wcli exchanges update "$EX" >"$SCRATCH/ex-upd-$label.out" 2>&1 || true + wcli exchanges accept-tos "$EX" >"$SCRATCH/ex-tos-$label.out" 2>&1 || true + fi +} + +t0=$(now_ms) +rm -f "$SCRATCH/wallet-main.sqlite3" +wallet_prepare "main" +ms_tos=$(elapsed_ms "$t0") +ok "wallet exchange + ToS (${ms_tos}ms) — cumulative DB for withdraw+pay (no run-until-done)" + +build_ladder_pair "$SCRATCH/ladder-wd-plan.txt" "$SCRATCH/ladder-pay-plan.txt" +LADDER_LIST=$(tr -d '\n' <"$SCRATCH/ladder-wd-plan.txt") +PAY_LIST=$(tr -d '\n' <"$SCRATCH/ladder-pay-plan.txt") +: "${LADDER_MAX_RUNGS:=99}" +# shellcheck disable=SC2086 +set -- $LADDER_LIST +if [ "$#" -gt "$LADDER_MAX_RUNGS" ]; then + # shellcheck disable=SC2046 + set -- $(printf '%s\n' "$@" | head -n "$LADDER_MAX_RUNGS") +fi +LADDER_N=$# +info "withdraw plan" "$*" +info "withdraw plan (alt)" "$(format_amount_list_alt "$@")" +info "pay plan" "$PAY_LIST" +# shellcheck disable=SC2086 +info "pay plan (alt)" "$(format_amount_list_alt $PAY_LIST)" +printf '%s\n' "$@" >"$SCRATCH/ladder-plan.txt" +printf '%s\n' $PAY_LIST >"$SCRATCH/ladder-pay-plan-lines.txt" 2>/dev/null || true + +OK_N=0 +FAIL_N_L=0 +PAY_OK_N=0 +PAY_FAIL_N=0 +STOP_REASON="" +STOP_AMOUNT="" +declare -a RUNG_JSON=() + +set_group withdraw +section "ladder · phase A · withdraw (${LADDER_N} rungs)" +rung=0 +for AMT in "$@"; do + rung=$((rung + 1)) + if ladder_over; then + STOP_REASON="timeout budget ${LADDER_TIMEOUT_S}s" + warn ladder "time budget exhausted" \ + "problem: LADDER_TIMEOUT_S=${LADDER_TIMEOUT_S}s reached after ${OK_N} ok rungs; remaining amounts not tried" + break + fi + + section "ladder · rung $rung $AMT · $(format_amount_alt "$AMT")" + tag=$(printf '%s' "$AMT" | tr '.:' '__') + # TSV "range" column: fixed pins at ends, random mids (refined after AMT_NUM) + if [ "$rung" -eq 1 ]; then + range_note="pin:0" + elif [ "$rung" -eq "$LADDER_N" ]; then + range_note="pin:max" + elif [ "$rung" -eq $((LADDER_N - 1)) ] && [ "$LADDER_N" -ge 3 ]; then + range_note="pin:max-1" + else + range_note="random" + fi + t_rung=$(now_ms) + ms_mint=0 ms_accept=0 ms_confirm=0 ms_settle=0 + note="" + status="FAIL" + WID="-" + FORCE_SEL_409_LOGGED=0 + + # keep cumulative main wallet + wallet_prepare "main" + + # mint from explorer pool + t0=$(now_ms) + code=$(curl -sS -m 30 -o "$SCRATCH/wd-$tag.json" -w '%{http_code}' \ + -H "Authorization: Bearer ${TOK}" \ + -H 'Content-Type: application/json' \ + -d "{\"amount\":\"${AMT}\"}" \ + "${BANK}/accounts/${EXP_USER}/withdrawals") + ms_mint=$(elapsed_ms "$t0") + WID=$(python3 -c 'import json;d=json.load(open("'"$SCRATCH"'/wd-'"$tag"'.json"));print(d.get("withdrawal_id") or "")' 2>/dev/null || true) + URI=$(python3 -c 'import json;u=json.load(open("'"$SCRATCH"'/wd-'"$tag"'.json")).get("taler_withdraw_uri") or "";print(u.replace(":443/","/"))' 2>/dev/null || true) + # numeric amount (for zero / settle / ceiling special-cases) + AMT_NUM=$(python3 -c 'import sys; print(sys.argv[1].split(":",1)[-1])' "$AMT") + IS_ZERO=0 + python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])==0 else 1)' "$AMT_NUM" 2>/dev/null && IS_ZERO=1 + IS_MAX_PIN=0 + IS_MAX_M1_PIN=0 + if [ "$AMT_NUM" = "${LADDER_MAX_AMOUNT}" ]; then + IS_MAX_PIN=1 + range_note="pin:max" + elif [ "$AMT_NUM" = "$((LADDER_MAX_AMOUNT - 1))" ] 2>/dev/null || \ + [ "$AMT_NUM" = "$(python3 -c 'print(int("'"$LADDER_MAX_AMOUNT"'")-1)')" ]; then + IS_MAX_M1_PIN=1 + range_note="pin:max-1" + fi + + if [ "$code" != "200" ] && [ "$code" != "201" ] || [ -z "$WID" ] || [ -z "$URI" ]; then + # strip quotes so STOP_REASON never breaks later shell/python argv + note="mint HTTP $code $(head -c 100 "$SCRATCH/wd-$tag.json" 2>/dev/null | tr '\n\"' ' ')" + ms_total=$(elapsed_ms "$t_rung") + if [ "$IS_ZERO" = "1" ]; then + # Probe only: bank may reject GOA:0 — record and continue ladder + status="ZERO_REJECT" + note="zero-withdraw rejected (expected possible): $note" + warn bank "mint $AMT rejected" \ + "problem: bank will not create a GOA:0 withdrawal (zero amount probe). Ladder continues. detail: $note" + echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" + OK_N=$((OK_N + 1)) + continue + fi + # Absolute max is a ceiling probe — bank often returns SQL P0001/5110; do not abort. + if [ "$IS_MAX_PIN" = "1" ]; then + status="CEILING_REJECT" + note="absolute max rejected (ceiling probe; max-1 is the hard pin): $note" + warn bank "mint $AMT rejected (ceiling)" \ + "problem: bank rejects absolute LADDER_MAX_AMOUNT (often SQL P0001/5110). max-1 rung is the last expected success. Ladder continues to report. detail: $note" + echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" + continue + fi + err bank "mint $AMT failed" "$note" + status="FAIL_MINT" + STOP_REASON="$note" + STOP_AMOUNT="$AMT" + echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" + FAIL_N_L=$((FAIL_N_L + 1)) + break + fi + ok "mint $AMT ($WID) ${ms_mint}ms" + + before=$(wallet_avail) + + # accept + t0=$(now_ms) + if wcli withdraw accept-uri --exchange "$EX" "$URI" >"$SCRATCH/accept-$tag.out" 2>&1; then + ms_accept=$(elapsed_ms "$t0") + ok "accept-uri $AMT ${ms_accept}ms" + else + ms_accept=$(elapsed_ms "$t0") + note="accept-uri failed: $(tail -c 200 "$SCRATCH/accept-$tag.out" | tr '\n' ' ')" + ms_total=$(elapsed_ms "$t_rung") + # Wallet 7006: no denominations for this amount (0, sub-denom dust, etc.) — warn & continue + if [ "$IS_ZERO" = "1" ] || grep -qE 'code: 7006|"code"[[:space:]]*:[[:space:]]*7006|No denominations could be selected' \ + "$SCRATCH/accept-$tag.out" 2>/dev/null; then + if [ "$IS_ZERO" = "1" ]; then + status="ZERO_SKIP" + note="zero-withdraw skip (7006 / no denoms): $note" + warn wallet "accept $AMT skipped" \ + "problem: wallet code 7006 — no coin denominations for GOA:0 (zero amount cannot be withdrawn as coins). Ladder continues. detail: $note" + else + status="SKIP_DENOM" + note="skip amount (wallet 7006 no denoms): $note" + warn wallet "accept $AMT skipped" \ + "problem: wallet code 7006 — no denominations match this amount (below smallest coin or not combinable). Ladder continues with next rung. detail: $note" + fi + echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" + continue + fi + err wallet "accept $AMT" "$note" + status="FAIL_ACCEPT" + STOP_REASON="$note" + STOP_AMOUNT="$AMT" + echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" + FAIL_N_L=$((FAIL_N_L + 1)) + break + fi + + # Confirm ASAP when bank status is selected. No run-until-done (hangs on macOS/wallet). + # Server-side auto-confirm only watches landing withdraw-watch.ids — ladder must confirm itself. + bank_st() { + curl -sS -m 8 "${BANK}/taler-integration/withdrawal-operation/${WID}" 2>/dev/null \ + | python3 -c 'import json,sys; print((json.load(sys.stdin).get("status") or "").strip())' 2>/dev/null || true + } + do_confirm() { + curl -sS -m 15 -o "$SCRATCH/conf-$tag.json" -w '%{http_code}' -X POST \ + -H "Authorization: Bearer ${TOK}" -H 'Content-Type: application/json' -d '{}' \ + "${BANK}/accounts/${EXP_USER}/withdrawals/${WID}/confirm" + } + # Collect reserve_pub candidates for *this* withdrawal (WID + amount). + # Cumulative wallets re-print old reserves in accept/tx dumps — never trust a single "last" blindly. + # Prints unique pubs one per line, preferred order first. + extract_rpubs_for_wid() { + python3 - "$WID" "$AMT" "$SCRATCH/accept-$tag.out" "$SCRATCH/tx-$tag.json" "$SCRATCH/used-rpubs.txt" <<'PY' +import json, re, sys +from pathlib import Path + +wid = sys.argv[1] +amt = sys.argv[2] +paths = sys.argv[3:5] +used_path = sys.argv[5] +used = set() +if Path(used_path).is_file(): + used = {ln.strip() for ln in open(used_path) if ln.strip()} + +def walk_collect(o, bag, ctx=None): + ctx = dict(ctx or {}) + if isinstance(o, dict): + for k, v in o.items(): + kl = str(k).lower() + if kl in ("withdrawal_id", "withdraw_id", "wopid", "id") and isinstance(v, str): + ctx["id"] = v + if kl in ("amount", "rawamount", "instructedamount") and isinstance(v, str): + ctx["amount"] = v + if kl in ("taler_withdraw_uri", "talerwithdrawuri", "uri") and isinstance(v, str): + ctx["uri"] = v + if kl in ("reserve_pub", "reservepub") and isinstance(v, str) and len(v) >= 40: + bag.append((v, dict(ctx))) + walk_collect(v, bag, ctx) + elif isinstance(o, list): + for i in o: + walk_collect(i, bag, ctx) + +raw_pubs = [] # ordered as found +scored = [] # (score, pub) higher better +blob_all = "" +for p in paths: + try: + blob_all += open(p, errors="replace").read() + "\n" + except Exception: + pass + +# 1) full JSON objects in files +for p in paths: + try: + t = open(p, errors="replace").read() + except Exception: + continue + # whole-file JSON + for m in re.finditer(r"\{", t): + try: + o = json.loads(t[m.start():]) + except Exception: + continue + bag = [] + walk_collect(o, bag) + for pub, ctx in bag: + raw_pubs.append(pub) + score = 0 + cid = str(ctx.get("id") or "") + camt = str(ctx.get("amount") or "") + curi = str(ctx.get("uri") or "") + if wid and wid in cid: + score += 100 + if wid and wid in curi: + score += 80 + if amt and (camt == amt or camt.endswith(amt.split(":", 1)[-1])): + score += 40 + if pub in used: + score -= 200 + scored.append((score, pub)) + +# 2) regex fallback on accept file only (more current) +try: + acc = open(paths[0], errors="replace").read() +except Exception: + acc = "" +for pat in ( + r"\"reserve_pub\"\s*:\s*\"([A-Z0-9]{40,})\"", + r"\"reservePub\"\s*:\s*\"([A-Z0-9]{40,})\"", + r"reserve_pub[\"\s:=]+([A-Z0-9]{40,})", +): + for m in re.finditer(pat, acc, re.I): + pub = m.group(1) + raw_pubs.append(pub) + score = 10 + # proximity to WID in accept output + window = acc[max(0, m.start() - 400) : m.end() + 400] + if wid and wid in window: + score += 100 + if amt and amt in window: + score += 30 + if pub in used: + score -= 200 + scored.append((score, pub)) + +# prefer high score, then later occurrence +order = [] +seen = set() +for score, pub in sorted(scored, key=lambda x: (-x[0],), reverse=False): + # sort by score desc: use reverse sorted + pass +for score, pub in sorted(scored, key=lambda x: x[0], reverse=True): + if pub in seen or pub in used: + continue + seen.add(pub) + order.append(pub) +# append unused raw in reverse (newest-ish) +for pub in reversed(raw_pubs): + if pub in seen or pub in used: + continue + seen.add(pub) + order.append(pub) +for pub in order: + print(pub) +PY + } + + mark_rpub_used() { + local p="$1" + [ -n "$p" ] || return 0 + mkdir -p "$SCRATCH" 2>/dev/null || true + grep -qxF "$p" "$SCRATCH/used-rpubs.txt" 2>/dev/null || echo "$p" >>"$SCRATCH/used-rpubs.txt" + } + + force_select_if_needed() { + local st_now="$1" + [ "$st_now" = "pending" ] || [ -z "$st_now" ] || return 0 + local rpub epayto code_fs any=0 + # refresh tx dump each try (wallet may attach reserve late) + wcli transactions >"$SCRATCH/tx-$tag.json" 2>&1 || true + epayto=$(curl -sS -m 10 "${EX%/}/keys" 2>/dev/null | python3 -c ' +import json,sys +d=json.load(sys.stdin) +acc=d.get("accounts") or [] +for a in acc: + p=a.get("payto_uri") or a.get("payto_address") or "" + if "x-taler-bank" in p or "exchange" in p: + print(p); break +else: + if acc: print(acc[0].get("payto_uri") or "") +' 2>/dev/null || true) + if [ -z "$epayto" ]; then + warn bank "force-select skipped" "problem: exchange payto empty from /keys" + return 0 + fi + # Try candidates until bank leaves pending (200/204) or we exhaust + while IFS= read -r rpub; do + [ -n "$rpub" ] || continue + any=1 + code_fs=$(curl -sS -m 12 -o "$SCRATCH/force-sel-$tag.json" -w '%{http_code}' -X POST \ + -H 'Content-Type: application/json' \ + -d "{\"reserve_pub\":\"${rpub}\",\"selected_exchange\":\"${epayto}\"}" \ + "${BANK}/taler-integration/withdrawal-operation/${WID}" 2>/dev/null || echo "000") + if [ "$code_fs" = "200" ] || [ "$code_fs" = "204" ]; then + info "force-select" "HTTP ${code_fs} rpub=${rpub:0:12}… (ok for WID ${WID:0:8})" + mark_rpub_used "$rpub" + return 0 + fi + if [ "$code_fs" = "409" ]; then + # 5114 = this reserve already bound to another op — not "out of money" + info "force-select" "HTTP 409 rpub=${rpub:0:12}… (stale/used reserve — not balance; trying next)" + mark_rpub_used "$rpub" + continue + fi + info "force-select" "HTTP ${code_fs} rpub=${rpub:0:12}… body=$(tr '\n' ' ' <"$SCRATCH/force-sel-$tag.json" 2>/dev/null | head -c 120)" + # other errors: still try next candidate + done < <(extract_rpubs_for_wid) + if [ "$any" != "1" ]; then + warn bank "force-select skipped" \ + "problem: no reserve_pub for this withdraw (WID=${WID:0:8}…); wallet may not have selected yet" + fi + } + + # No run-until-done (hangs / banned). Read transactions only for reserve_pub candidates. + wcli transactions >"$SCRATCH/tx-$tag.json" 2>&1 || true + + t0=$(now_ms) + conf_ok=0 + st="" + # Poll bank status; force-select while pending; confirm as soon as selected + for i in $(seq 1 "${LADDER_CONFIRM_POLLS}"); do + ladder_over && break + st=$(bank_st) + case "$st" in + selected) + ccode=$(do_confirm) + if [ "$ccode" = "204" ] || [ "$ccode" = "200" ]; then + conf_ok=1 + info "confirm" "HTTP $ccode after selected (poll $i)" + else + note="confirm HTTP $ccode" + fi + break + ;; + confirmed) + conf_ok=1 + break + ;; + aborted) + note="withdrawal aborted by bank" + break + ;; + esac + # force-select while pending — try alternate rpubs on 5114 (not out-of-money) + if [ "$st" = "pending" ] || [ -z "$st" ]; then + if [ "$i" -eq 1 ] || [ "$i" -eq 2 ] || [ $((i % 3)) -eq 0 ]; then + force_select_if_needed "$st" + fi + fi + sleep 0.35 + done + ms_confirm=$(elapsed_ms "$t0") + st=$(printf '%s' "${st:-}" | tr -d '\r\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + if [ "$conf_ok" != "1" ]; then + note="${note:-confirm timeout last=${st:-empty}}" + # Soft: not confirmed — usually stale reserve_pub (5114), NOT empty pool balance + status="SKIP_CONFIRM" + warn bank "confirm $AMT skipped" \ + "problem: bank status='${st:-empty}' after ${LADDER_CONFIRM_POLLS} polls (want selected/confirmed). Usually reserve_pub mismatch (5114), not out-of-money — mint/accept already OK. detail: $note" + ms_total=$(elapsed_ms "$t_rung") + echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" + continue + fi + ok "confirm $AMT ${ms_confirm}ms (client, on selected)" + + # settle: poll wallet balance + bank transfer_done only — never run-until-done + t0=$(now_ms) + settled=0 + xfer="?" + if [ "$IS_ZERO" = "1" ]; then + settled=1 + note="zero-amount: no coin delta expected" + else + for r in $(seq 1 "$LADDER_SETTLE_ROUNDS"); do + ladder_over && break + after=$(wallet_avail) + if python3 -c " +from decimal import Decimal +import sys +sys.exit(0 if Decimal(sys.argv[1]) > Decimal(sys.argv[2]) else 1) +" "$after" "$before" 2>/dev/null; then + settled=1 + break + fi + xfer=$(curl -sS -m 10 "${BANK}/taler-integration/withdrawal-operation/${WID}" \ + | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d.get("transfer_done"), d.get("status"))' 2>/dev/null || echo "?") + # bank done is enough to leave settle without hanging on wallet + if echo "$xfer" | grep -qi True; then + note="bank transfer_done (no run-until-done) avail=${after} $xfer" + break + fi + sleep "$LADDER_SETTLE_SLEEP" + done + fi + ms_settle=$(elapsed_ms "$t0") + after=$(wallet_avail) + ms_total=$(elapsed_ms "$t_rung") + if [ -z "${xfer:-}" ] || [ "$xfer" = "?" ]; then + xfer=$(curl -sS -m 10 "${BANK}/taler-integration/withdrawal-operation/${WID}" \ + | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d.get("transfer_done"), d.get("status"))' 2>/dev/null || echo "?") + fi + + if [ "$settled" = "1" ]; then + status="OK" + note="${note:-avail=${CUR}:${after}}" + ok "settle $AMT → ${CUR}:${after} (settle ${ms_settle}ms, rung ${ms_total}ms)" + OK_N=$((OK_N + 1)) + echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" + metrics_report_coins "ladder-r${rung}-after-${tag}" || true + metrics_record_flow withdrawn "$AMT" || true + elif echo "$xfer" | grep -qi True; then + status="OK_BANK" + note="bank transfer_done avail=${after} $xfer (no run-until-done)" + ok "settle $AMT bank transfer_done (wallet avail=${CUR}:${after}, ${ms_settle}ms)" + OK_N=$((OK_N + 1)) + echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" + metrics_report_coins "ladder-r${rung}-after-${tag}" || true + metrics_record_flow withdrawn "$AMT" || true + else + note="no coins / no transfer_done avail=${after} $xfer" + err wallet "settle $AMT" "$note" + status="FAIL_SETTLE" + STOP_REASON="$note" + STOP_AMOUNT="$AMT" + FAIL_N_L=$((FAIL_N_L + 1)) + echo -e "${rung}\t${range_note}\t${AMT}\t${status}\t${ms_mint}\t${ms_accept}\t${ms_confirm}\t${ms_settle}\t${ms_total}\t${WID}\t${note}" >>"$TSV" + metrics_report_coins "ladder-r${rung}-fail-${tag}" || true + break + fi +done + +# --------------------------------------------------------------------------- +# Phase B — payment ladder (same shape: 0 → low → … → max-1 → max) +# --------------------------------------------------------------------------- +PAY_OK_N=0 +PAY_FAIL_N=0 +if [ "${LADDER_PAY}" = "1" ] && [ -n "${PAY_LIST:-}" ] && [ "$FAIL_N_L" -eq 0 ]; then + set_group pay + section "ladder · phase B · pay" + metrics_report_coins "before-pay-ladder" || true + # Merchant secret (same as e2e) — stage often has only public shop templates + MPW="${E2E_MERCHANT_TOKEN:-${MERCHANT_TOKEN:-}}" + if [ -z "$MPW" ]; then + MPW=$(read_secret "taler-merchant/merchant-${INST}-password.txt" 2>/dev/null || true) + fi + if [ -z "$MPW" ]; then + MPW=$(read_secret "taler-merchant/merchant-goa-demo-cp4zqk-password.txt" 2>/dev/null || true) + fi + if [ -z "$MPW" ] && [ "${CUR}" = "TESTPAYSAN" ]; then + if [ -n "${FRANCPAYSAN_SECRETS:-}" ] && [ -f "${FRANCPAYSAN_SECRETS}/stage/default-instance-token.txt" ]; then + MPW=$(tr -d '\n\r' <"${FRANCPAYSAN_SECRETS}/stage/default-instance-token.txt") + fi + if [ -z "$MPW" ]; then + _remote_mer="${FRANCPAYSAN_REMOTE_MERCHANT_TOKEN:-}" + [ -z "$_remote_mer" ] && [ -n "${FRANCPAYSAN_REMOTE_SECRETS_ROOT:-}" ] && \ + _remote_mer="${FRANCPAYSAN_REMOTE_SECRETS_ROOT}/merchant/secrets/default-instance-token.txt" + for host in ${INSIDE_SSH:+"$INSIDE_SSH"} ${FRANCPAYSAN_SSH:+"$FRANCPAYSAN_SSH"}; do + [ -n "$host" ] && [ -n "$_remote_mer" ] || continue + MPW=$(ssh -o BatchMode=yes -o ConnectTimeout=12 "$host" \ + "tr -d '\\n\\r' <${_remote_mer} 2>/dev/null || true" \ + 2>/dev/null || true) + [ -n "$MPW" ] && break + done + unset _remote_mer + fi + fi + if [ -z "$MPW" ]; then + if [ "${CUR}" = "TESTPAYSAN" ]; then + # Stage: withdraw ladder is the main probe; pays need instance token or + # public templates for *exact* face values (not continuous ladder amounts). + info pay "no merchant token — skip pay ladder on TESTPAYSAN (withdraw maxima still covered)" + info pay "hint: set E2E_MERCHANT_TOKEN or use ./taler-monitoring.sh -d stage.lefrancpaysan.ch e2e for shop templates" + else + warn pay "no merchant token — skip pay ladder (set E2E_MERCHANT_TOKEN or secrets)" + fi + else + ok "merchant token" "instance ${INST}" + case "$MPW" in + secret-token:*) AUTH="Authorization: Bearer ${MPW}" ;; + *) AUTH="Authorization: Bearer secret-token:${MPW}" ;; + esac + wallet_prepare "main" + # shellcheck disable=SC2086 + set -- $PAY_LIST + PAY_N=$# + info "pay rungs" "$PAY_N · $*" + prung=0 + for PAMT in "$@"; do + prung=$((prung + 1)) + if ladder_over; then + warn pay "time budget exhausted" "after ${PAY_OK_N} ok pays" + break + fi + section "ladder · pay rung $prung $PAMT · $(format_amount_alt "$PAMT")" + ptag=$(printf '%s' "$PAMT" | tr '.:' '__') + if [ "$prung" -eq 1 ]; then + prange="pin:0" + elif [ "$prung" -eq "$PAY_N" ]; then + prange="pin:max" + elif [ "$prung" -eq $((PAY_N - 1)) ] && [ "$PAY_N" -ge 3 ]; then + prange="pin:max-1" + else + prange="random" + fi + PNUM=$(python3 -c 'import sys; print(sys.argv[1].split(":",1)[-1])' "$PAMT") + IS_PZERO=0 + python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])==0 else 1)' "$PNUM" 2>/dev/null && IS_PZERO=1 + IS_PMAX=0 + [ "$PNUM" = "${LADDER_MAX_AMOUNT}" ] && IS_PMAX=1 + t_pay=$(now_ms) + ms_order=0 ms_handle=0 ms_psettle=0 + pnote="" + pstatus="FAIL" + OID="-" + + metrics_report_coins "before-pay-${ptag}" || true + bal=$(wallet_avail) + + if [ "$IS_PZERO" = "1" ]; then + pstatus="ZERO_SKIP" + pnote="zero pay probe skipped" + warn pay "pay $PAMT skipped" "problem: zero amount order not useful. Ladder continues." + ms_total=$(elapsed_ms "$t_pay") + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t${ms_order}\t${ms_handle}\t${ms_psettle}\t${ms_total}\t${OID}\t${pnote}" >>"$PAY_TSV" + PAY_OK_N=$((PAY_OK_N + 1)) + continue + fi + + # Soft: absolute max pay is a ceiling probe (unlikely affordable / merchant may reject) + if [ "$IS_PMAX" = "1" ]; then + # try once; on fail CEILING_REJECT + : + fi + + # Insufficient balance → soft skip for max pin only; hard fail for mid/max-1 + if ! python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])>=Decimal(sys.argv[2]) else 1)' "$bal" "$PNUM" 2>/dev/null; then + pnote="insufficient balance avail=${CUR}:${bal} need=${PAMT}" + ms_total=$(elapsed_ms "$t_pay") + if [ "$IS_PMAX" = "1" ]; then + pstatus="CEILING_SKIP" + warn pay "pay $PAMT skipped (ceiling)" "$pnote" + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t0\t0\t0\t${ms_total}\t-\t${pnote}" >>"$PAY_TSV" + continue + fi + err pay "pay $PAMT" "$pnote" + pstatus="FAIL_BALANCE" + PAY_FAIL_N=$((PAY_FAIL_N + 1)) + FAIL_N_L=$((FAIL_N_L + 1)) + STOP_REASON="$pnote" + STOP_AMOUNT="$PAMT" + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t0\t0\t0\t${ms_total}\t-\t${pnote}" >>"$PAY_TSV" + break + fi + + t0=$(now_ms) + SUM_JSON=$(python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "ladder pay ${PAMT}" 2>/dev/null || echo '"ladder pay"') + curl -skS -m 20 -o "$SCRATCH/ord-$ptag.json" -X POST \ + -H "$AUTH" -H 'Content-Type: application/json' \ + -d "{\"order\":{\"summary\":${SUM_JSON},\"amount\":\"${PAMT}\",\"fulfillment_message\":\"ok\"},\"create_token\":true}" \ + "${MER}/instances/${INST}/private/orders" 2>"$SCRATCH/ord-$ptag.err" || true + ms_order=$(elapsed_ms "$t0") + OID=$(python3 -c 'import json,re,sys;t=open(sys.argv[1]).read() +try: print(json.loads(t).get("order_id") or "") +except Exception: + m=re.search(r"\"order_id\"\s*:\s*\"([^\"]+)\"",t); print(m.group(1) if m else "") +' "$SCRATCH/ord-$ptag.json" 2>/dev/null || true) + OTOK=$(python3 -c 'import json,re,sys;t=open(sys.argv[1]).read() +try: print(json.loads(t).get("token") or "") +except Exception: + m=re.search(r"\"token\"\s*:\s*\"([^\"]+)\"",t); print(m.group(1) if m else "") +' "$SCRATCH/ord-$ptag.json" 2>/dev/null || true) + if [ -z "$OID" ]; then + pnote="order create failed $(head -c 80 "$SCRATCH/ord-$ptag.json" 2>/dev/null | tr '\n\"' ' ')" + ms_total=$(elapsed_ms "$t_pay") + if [ "$IS_PMAX" = "1" ]; then + pstatus="CEILING_REJECT" + warn pay "pay $PAMT rejected (ceiling)" "$pnote" + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t${ms_order}\t0\t0\t${ms_total}\t-\t${pnote}" >>"$PAY_TSV" + continue + fi + err pay "order $PAMT" "$pnote" + pstatus="FAIL_ORDER" + PAY_FAIL_N=$((PAY_FAIL_N + 1)) + FAIL_N_L=$((FAIL_N_L + 1)) + STOP_REASON="$pnote" + STOP_AMOUNT="$PAMT" + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t${ms_order}\t0\t0\t${ms_total}\t-\t${pnote}" >>"$PAY_TSV" + break + fi + ok "order $OID ($PAMT) ${ms_order}ms" + + curl -skS -m 12 -o "$SCRATCH/ord-det-$ptag.json" -H "$AUTH" \ + "${MER}/instances/${INST}/private/orders/${OID}" 2>/dev/null || true + PAYURI=$(python3 -c 'import json,sys +try: print(json.load(open(sys.argv[1])).get("taler_pay_uri") or "") +except Exception: print("") +' "$SCRATCH/ord-det-$ptag.json" 2>/dev/null || true) + if [ -z "$PAYURI" ] && [ -n "$OTOK" ]; then + MH=$(python3 -c 'from urllib.parse import urlparse; print(urlparse("'"$MER"'").hostname or "taler.hacktivism.ch")' 2>/dev/null || echo "taler.hacktivism.ch") + PAYURI="taler://pay/${MH}/instances/${INST}/${OID}/?c=${OTOK}" + fi + PAYURI=$(printf '%s' "$PAYURI" | sed 's/:443\//\//g; s/:443?/?/g') + if [ -z "$PAYURI" ]; then + pnote="no pay URI for $OID" + ms_total=$(elapsed_ms "$t_pay") + err pay "uri $PAMT" "$pnote" + pstatus="FAIL_URI" + PAY_FAIL_N=$((PAY_FAIL_N + 1)) + FAIL_N_L=$((FAIL_N_L + 1)) + STOP_REASON="$pnote" + STOP_AMOUNT="$PAMT" + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t${ms_order}\t0\t0\t${ms_total}\t${OID}\t${pnote}" >>"$PAY_TSV" + break + fi + + t0=$(now_ms) + if ! wcli handle-uri --yes "$PAYURI" >"$SCRATCH/pay-$ptag.out" 2>&1; then + ms_handle=$(elapsed_ms "$t0") + pnote="handle-uri failed $(tail -c 100 "$SCRATCH/pay-$ptag.out" | tr '\n\"' ' ')" + ms_total=$(elapsed_ms "$t_pay") + if [ "$IS_PMAX" = "1" ]; then + pstatus="CEILING_REJECT" + warn pay "pay $PAMT handle failed (ceiling)" "$pnote" + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t${ms_order}\t${ms_handle}\t0\t${ms_total}\t${OID}\t${pnote}" >>"$PAY_TSV" + continue + fi + err pay "handle $PAMT" "$pnote" + pstatus="FAIL_HANDLE" + PAY_FAIL_N=$((PAY_FAIL_N + 1)) + FAIL_N_L=$((FAIL_N_L + 1)) + STOP_REASON="$pnote" + STOP_AMOUNT="$PAMT" + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t${ms_order}\t${ms_handle}\t0\t${ms_total}\t${OID}\t${pnote}" >>"$PAY_TSV" + break + fi + ms_handle=$(elapsed_ms "$t0") + ok "handle-uri $PAMT ${ms_handle}ms" + + # Short settle polls: merchant order + wallet tx only — never run-until-done + t0=$(now_ms) + settled=0 + r=0 + while [ "$r" -lt "${LADDER_PAY_SETTLE_ROUNDS}" ]; do + r=$((r + 1)) + wcli transactions >"$SCRATCH/tx-$ptag.out" 2>&1 || true + curl -skS -m 8 -o "$SCRATCH/ord-paid-$ptag.json" -H "$AUTH" \ + "${MER}/instances/${INST}/private/orders/${OID}" 2>/dev/null || true + if grep -qiE 'payment|paid|Payment' "$SCRATCH/tx-$ptag.out" 2>/dev/null \ + || python3 -c 'import json,sys +d=json.load(open(sys.argv[1])) +sys.exit(0 if d.get("paid") is True or str(d.get("order_status","")).lower()=="paid" else 1) +' "$SCRATCH/ord-paid-$ptag.json" 2>/dev/null; then + settled=1 + break + fi + sleep 0.5 + done + ms_psettle=$(elapsed_ms "$t0") + ms_total=$(elapsed_ms "$t_pay") + after=$(wallet_avail) + if [ "$settled" = "1" ]; then + pstatus="OK" + pnote="avail=${CUR}:${after}" + ok "pay settled $PAMT → bal ${CUR}:${after} (total ${ms_total}ms)" + PAY_OK_N=$((PAY_OK_N + 1)) + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t${ms_order}\t${ms_handle}\t${ms_psettle}\t${ms_total}\t${OID}\t${pnote}" >>"$PAY_TSV" + metrics_report_coins "after-pay-${ptag}" || true + metrics_record_flow spent "$PAMT" || true + else + pnote="not settled order=$OID avail=${CUR}:${after}" + if [ "$IS_PMAX" = "1" ]; then + pstatus="CEILING_REJECT" + warn pay "pay $PAMT not settled (ceiling)" "$pnote" + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t${ms_order}\t${ms_handle}\t${ms_psettle}\t${ms_total}\t${OID}\t${pnote}" >>"$PAY_TSV" + continue + fi + err pay "settle $PAMT" "$pnote" + pstatus="FAIL_SETTLE" + PAY_FAIL_N=$((PAY_FAIL_N + 1)) + FAIL_N_L=$((FAIL_N_L + 1)) + STOP_REASON="$pnote" + STOP_AMOUNT="$PAMT" + echo -e "${prung}\t${prange}\t${PAMT}\t${pstatus}\t${ms_order}\t${ms_handle}\t${ms_psettle}\t${ms_total}\t${OID}\t${pnote}" >>"$PAY_TSV" + metrics_report_coins "after-pay-fail-${ptag}" || true + break + fi + done + metrics_report_coins "after-pay-ladder" || true + info "pay summary" "ok=$PAY_OK_N fail=$PAY_FAIL_N tsv=$PAY_TSV" + fi +elif [ "${LADDER_PAY}" = "1" ] && [ "$FAIL_N_L" -gt 0 ]; then + warn pay "skipped pay ladder" "withdraw phase already failed" +fi + +ms_phase=$(python3 -c 'import sys,time; print(int((time.time()-float(sys.argv[1]))*1000))' "$SECTION_T0") + +# --- report --- +set_group report +section "ladder · report" +info "auto-account" "$ACCT_USER" +info "ok_rungs" "$OK_N" +info "fail_rungs" "$FAIL_N_L" +info "pay_ok" "$PAY_OK_N" +info "pay_fail" "$PAY_FAIL_N" +info "phase_ms" "$ms_phase" +info "tsv" "$TSV" +info "pay_tsv" "$PAY_TSV" + +# speed summary via python — free-text stop reason via env (JSON " in bank errors +# used to break shell argv quoting → "syntax error near unexpected token '('") +export LADDER_REPORT_STOP_AMOUNT="${STOP_AMOUNT:-}" +export LADDER_REPORT_STOP_REASON="${STOP_REASON:-}" +python3 - "$TSV" "$PAY_TSV" "$JSON" "$OK_N" "$FAIL_N_L" "$PAY_OK_N" "$PAY_FAIL_N" "$ms_phase" "$ACCT_USER" "$CUR" <<'PY' +import csv, json, os, sys, statistics +tsv, pay_tsv, jpath = sys.argv[1:4] +ok_n, fail_n, pay_ok, pay_fail, phase_ms, acct, cur = sys.argv[4:11] +stop_amt = os.environ.get("LADDER_REPORT_STOP_AMOUNT") or None +stop_reason = os.environ.get("LADDER_REPORT_STOP_REASON") or None + +def load_rows(path): + rows = [] + try: + with open(path, newline="") as f: + for row in csv.DictReader(f, delimiter="\t"): + rows.append(row) + except Exception: + pass + return rows + +rows = load_rows(tsv) +prows = load_rows(pay_tsv) + +def nums(rs, key): + out = [] + for row in rs: + try: + out.append(int(row[key])) + except Exception: + pass + return out + +def stats(xs): + if not xs: + return {"n": 0} + return { + "n": len(xs), + "min_ms": min(xs), + "max_ms": max(xs), + "avg_ms": int(sum(xs) / len(xs)), + "p50_ms": int(statistics.median(xs)), + } + +report = { + "currency": cur, + "auto_account": acct, + "ok_rungs": int(ok_n), + "fail_rungs": int(fail_n), + "pay_ok": int(pay_ok), + "pay_fail": int(pay_fail), + "stopped_at_amount": stop_amt or None, + "stop_reason": stop_reason or None, + "phase_ms": int(phase_ms), + "timing": { + "mint": stats(nums(rows, "ms_mint")), + "accept": stats(nums(rows, "ms_accept")), + "confirm": stats(nums(rows, "ms_confirm")), + "settle": stats(nums(rows, "ms_settle")), + "rung_total": stats(nums(rows, "ms_total")), + "pay_order": stats(nums(prows, "ms_order")), + "pay_handle": stats(nums(prows, "ms_handle")), + "pay_settle": stats(nums(prows, "ms_settle")), + "pay_total": stats(nums(prows, "ms_total")), + }, + "rungs": rows, + "pays": prows, +} +json.dump(report, open(jpath, "w"), indent=2) +print("JSON", jpath) +print("--- withdraw speed (ms) ---") +for k in ("mint", "accept", "confirm", "settle", "rung_total"): + v = report["timing"][k] + if v.get("n"): + print(" %s n=%s min=%s p50=%s avg=%s max=%s" % (k.ljust(12), v["n"], v["min_ms"], v["p50_ms"], v["avg_ms"], v["max_ms"])) +print("--- pay speed (ms) ---") +for k in ("pay_order", "pay_handle", "pay_settle", "pay_total"): + v = report["timing"][k] + if v.get("n"): + print(" %s n=%s min=%s p50=%s avg=%s max=%s" % (k.ljust(12), v["n"], v["min_ms"], v["p50_ms"], v["avg_ms"], v["max_ms"])) +print("--- withdraw rungs ---") +for row in rows: + print(" %2s %-16s %-12s total=%sms" % (row.get("rung"), row.get("amount"), row.get("status"), row.get("ms_total"))) +print("--- pay rungs ---") +for row in prows: + print(" %2s %-16s %-12s total=%sms oid=%s" % (row.get("rung"), row.get("amount"), row.get("status"), row.get("ms_total"), row.get("oid"))) +if stop_amt: + print("STOPPED at %s: %s" % (stop_amt, stop_reason)) +else: + print("Completed without hard failure (or budget stop without fail).") +PY + +wcli balance 2>&1 | tee "$REPORT_DIR/balance-final.out" | tail -20 || true + +set_group load +section "ladder · load snapshot (after withdraws)" +metrics_report_load "$LOAD_AFTER" "ladder-end" || true +if [ -f "$LOAD_BEFORE" ] && [ -f "$LOAD_AFTER" ]; then + section "metrics · ladder load delta" + metrics_print_load_delta "$LOAD_BEFORE" "$LOAD_AFTER" || true +fi +# Speed timings → metrics overall (min/p50/avg/max per phase) +if [ -f "$JSON" ]; then + python3 - "$JSON" "${METRICS_DIR}/perf-summary.json" <<'PY' 2>/dev/null || true +import json, sys +rep = json.load(open(sys.argv[1])) +out = {} +for k, v in (rep.get("timing") or {}).items(): + if isinstance(v, dict) and v.get("n"): + out[k] = v +json.dump(out, open(sys.argv[2], "w"), indent=2) +PY +fi +export METRICS_WITHDRAW_TSV="$TSV" +export METRICS_PAY_TSV="$PAY_TSV" +metrics_report_coins "ladder-end" || true +metrics_print_overall "ladder final" || true + +# Keep scratch if LADDER_REPORT_DIR set; else copy key files to /tmp +if [ -z "${LADDER_REPORT_DIR:-}" ]; then + KEEP="/tmp/goa-ladder-report-$(date +%Y%m%d-%H%M%S)" + mkdir -p "$KEEP" + cp -a "$TSV" "$PAY_TSV" "$JSON" "$SCRATCH/auto-account.json" "$SCRATCH/ladder-plan.txt" \ + "$SCRATCH/ladder-wd-plan.txt" "$SCRATCH/ladder-pay-plan.txt" \ + "$REPORT_DIR/balance-final.out" "$LOAD_BEFORE" "$LOAD_AFTER" "$KEEP/" 2>/dev/null || true + info "report_dir" "$KEEP" + echo "$KEEP" >"$SCRATCH/KEEP_PATH" +fi + +if [ "$FAIL_N_L" -gt 0 ]; then + blocker "ladder" "stopped at ${STOP_AMOUNT:-?} — ${STOP_REASON:-error}" + exit 1 +fi +if [ "$OK_N" -eq 0 ]; then + blocker "ladder" "no successful withdraw rungs" + exit 1 +fi +ok "ladder finished withdraw_ok=$OK_N pay_ok=$PAY_OK_N phase=${ms_phase}ms" +exit 0 diff --git a/check_inside.sh b/check_inside.sh index 38f145f..08d3d5d 100755 --- a/check_inside.sh +++ b/check_inside.sh @@ -29,14 +29,12 @@ if [ -z "$PROFILE" ]; then fi fi -# Resolve host-podman vs ssh before first check ID. -# stage-lfp on the FP host itself uses local podman (INSIDE_PODMAN=1 / -# INSIDE_MODE=local-podman); laptop → stage still uses INSIDE_SSH. +# Resolve host-podman vs ssh before first check ID _use_local_podman=0 -if [ "${INSIDE_PODMAN:-0}" = "1" ] || [ "${INSIDE_MODE:-}" = "local-podman" ]; then - _use_local_podman=1 -elif [ "$PROFILE" != "stage-lfp" ]; then - if command -v podman >/dev/null 2>&1 \ +if [ "$PROFILE" != "stage-lfp" ]; then + if [ "${INSIDE_PODMAN:-0}" = "1" ] || [ "${INSIDE_MODE:-}" = "local-podman" ]; then + _use_local_podman=1 + elif command -v podman >/dev/null 2>&1 \ && podman ps --format '{{.Names}}' 2>/dev/null | grep -qE 'taler-hacktivism'; then _use_local_podman=1 fi @@ -54,7 +52,7 @@ section "inside · collect (${PROFILE} · access=${INSIDE_ACCESS})" info "flags" "INSIDE_ACCESS=${INSIDE_ACCESS} INSIDE_PODMAN=${INSIDE_PODMAN:-0} INSIDE_MODE=${INSIDE_MODE:-} LOCAL_STACK=${LOCAL_STACK:-0} SKIP_SSH=${SKIP_SSH:-0} KOOPA_SSH=${KOOPA_SSH:-} INSIDE_SSH=${INSIDE_SSH:-}" # --------------------------------------------------------------------------- -# stage-lfp: stagepaysan podman (host-local or SSH INSIDE_SSH from laptop) +# stage-lfp: low-priv stagepaysan on the FP stage host (INSIDE_SSH) # --------------------------------------------------------------------------- if [ "$PROFILE" = "stage-lfp" ]; then SSH_HOST="${INSIDE_SSH:-}" @@ -71,23 +69,15 @@ if [ "$PROFILE" = "stage-lfp" ]; then STAGE_SSH_T="${INSIDE_SSH_TIMEOUT:-${SSH_CMD_TIMEOUT:-24}}" if [ "${STAGE_SSH_T}" -lt 24 ] 2>/dev/null; then STAGE_SSH_T=24; fi - if [ "$_use_local_podman" = "1" ]; then - if ! command -v podman >/dev/null 2>&1; then - err "host" "INSIDE_PODMAN/host-podman but podman missing" - summary - exit 1 - fi - ok "host→container" "podman exec on this host (INSIDE_ACCESS=host-podman · no SSH)" - elif ! mon_ssh_ok "$SSH_HOST"; then - err "ssh" "cannot reach ${SSH_HOST:-?} (stagepaysan low-priv) — set INSIDE_SSH= or INSIDE_PODMAN=1" + if ! mon_ssh_ok "$SSH_HOST"; then + err "ssh" "cannot reach ${SSH_HOST} (stagepaysan low-priv) — set INSIDE_SSH= or SKIP" summary exit 1 - else - ok "ssh ${SSH_HOST}" "stagepaysan (podman, no sudo)" fi + ok "ssh ${SSH_HOST}" "stagepaysan (podman, no sudo)" - # Inject names/ports (ssh bash -s does not inherit local env; local bash does). - _stage_lfp_script() { + # Inject names/ports into remote (ssh bash -s does not inherit local env). + RAW=$( { printf 'BANK_CTR=%q; EX_CTR=%q; MER_CTR=%q\n' "$BANK_CTR" "$EX_CTR" "$MER_CTR" printf 'BANK_PORT=%q; EX_PORT=%q; MER_PORT=%q\n' "$BANK_PORT" "$EX_PORT" "$MER_PORT" @@ -183,20 +173,11 @@ fi echo DONE REMOTE - } - } - if [ "$_use_local_podman" = "1" ]; then - RAW=$(_stage_lfp_script | bash || true) - else - RAW=$(_stage_lfp_script | mon_ssh_bash "$SSH_HOST" "${STAGE_SSH_T}" || true) - fi + } | mon_ssh_bash "$SSH_HOST" "${STAGE_SSH_T}" || true + ) if [ -z "$RAW" ] || ! echo "$RAW" | grep -q '^E|'; then - if [ "$_use_local_podman" = "1" ]; then - err "host" "stage collect timed out or empty (local podman)" - else - err "ssh" "stage remote timed out or empty (cap ${STAGE_SSH_T}s · host=${SSH_HOST})" - fi + err "ssh" "stage remote timed out or empty (cap ${STAGE_SSH_T}s · host=${SSH_HOST})" summary exit 1 fi @@ -208,7 +189,7 @@ REMOTE IFS='|' read -r _ comp level key detail <<<"$line" case "$comp" in bank|exchange|merchant|caddy) _g="$comp" ;; - *) _g="$INSIDE_ACCESS" ;; + *) _g="ssh" ;; esac if [ "$_g" != "$_last_inside_grp" ]; then set_group "$_g" @@ -261,29 +242,7 @@ REMOTE # Host load as stagepaysan (no container RSS from koopa metrics) set_group load section "inside · load (stagepaysan host)" - _load_py() { - python3 - <<'PY' -import os -la=os.getloadavg() -print("loadavg=%.2f,%.2f,%.2f" % la) -try: - with open("/proc/meminfo") as f: - d={} - for line in f: - k,v=line.split(":")[0], line.split(":")[1].strip().split()[0] - d[k]=int(v) - total=d.get("MemTotal",0)/1024/1024 - avail=d.get("MemAvailable",0)/1024/1024 - used=total-avail - print("mem_used=%.2fGiB avail=%.2fGiB total=%.2fGiB" % (used, avail, total)) -except Exception: - print("mem=?") -PY - } - if [ "$_use_local_podman" = "1" ]; then - LOAD_LINE=$(_load_py || true) - else - LOAD_LINE=$(mon_ssh_bash "$SSH_HOST" 8 <<'EOF' || true + LOAD_LINE=$(mon_ssh_bash "$SSH_HOST" 8 <<'EOF' || true python3 - <<'PY' import os la=os.getloadavg() @@ -303,7 +262,6 @@ except Exception: PY EOF ) - fi if [ -n "$LOAD_LINE" ]; then info "stage host" "$(echo "$LOAD_LINE" | tr '\n' ' ')" else @@ -312,8 +270,7 @@ EOF set_group disk section "inside · disk free space (stage host + containers)" - _disk_script() { - cat <<'DISK' + _disk_raw=$(mon_ssh_bash "$SSH_HOST" "${STAGE_SSH_T:-24}" <<'DISK' || true set +e echo "###HOST###" df -Pk / /var /home /tmp /mnt/data 2>/dev/null || df -Pk @@ -323,16 +280,9 @@ for c in $(podman ps --format '{{.Names}}' 2>/dev/null); do podman exec "$c" df -Pk / /var /tmp 2>/dev/null || podman exec "$c" df -Pk 2>/dev/null done DISK - } - if [ "$_use_local_podman" = "1" ]; then - _disk_raw=$(_disk_script | bash || true) - _disk_label="host" - else - _disk_raw=$(_disk_script | mon_ssh_bash "$SSH_HOST" "${STAGE_SSH_T:-24}" || true) - _disk_label="ssh:${SSH_HOST}" - fi +) _host_df=$(printf '%s\n' "$_disk_raw" | sed -n '/^###HOST###$/,/^###CTRS###$/p' | sed '1d;$d') - mon_disk_check_remote_text "$_disk_label" "$_host_df" || true + mon_disk_check_remote_text "ssh:${SSH_HOST}" "$_host_df" || true _ctr=""; _buf="" while IFS= read -r _line || [ -n "$_line" ]; do case "$_line" in diff --git a/check_mail.sh b/check_mail.sh index 7f92433..7b74ca4 100755 --- a/check_mail.sh +++ b/check_mail.sh @@ -2,8 +2,7 @@ # check_mail.sh — outside-in mail (MX / SMTP / IMAP / SPF / DMARC) # # Catalog: mail-catalog.conf (MAIL_CATALOG=… to override) -# Covers firefly (taler.net, gnunet.org) and Anastasis/TSA -# (mail.anastasis.lu → pixel.taler-systems.com; anastasis.lu). +# Covers firefly (taler.net, gnunet.org) and pixel (taler-systems.com, …). # # Outside-only. Phase: mail # diff --git a/check_mattermost.sh b/check_mattermost.sh index a61bed7..650e3b1 100755 --- a/check_mattermost.sh +++ b/check_mattermost.sh @@ -5,20 +5,6 @@ # Override: MATTERMOST_PUBLIC=https://mattermost.example.org # MATTERMOST_HOST=mattermost.example.org # -# Client compatibility (feature) — server min for current *official* clients: -# Android / iOS store apps → default ≥ 10.11.0 (Play/App Store + mobile docs 2026) -# Desktop (Win/Mac/Linux) → default ≥ 10.11.0 (current Desktop / ESR pairing) -# Vendor support floor → default ≥ 10.11.0 (ESR; older = unsupported) -# Web SPA → served by this server (always loads) but WARN if -# server is below support floor (security/EOL). -# -# Env: -# MATTERMOST_CLIENT_CHECK=1|0 master switch (default 1) -# MATTERMOST_MOBILE_CHECK=1|0 alias / legacy (if set 0 and CLIENT unset → off) -# MATTERMOST_MOBILE_MIN_SERVER default 10.11.0 -# MATTERMOST_DESKTOP_MIN_SERVER default 10.11.0 -# MATTERMOST_SUPPORT_MIN_SERVER default 10.11.0 (vendor-supported floor) -# # Outside-only (no SSH). Phase name: mattermost # set -euo pipefail @@ -29,20 +15,6 @@ source "$ROOT/lib.sh" set_area mattermost section "mattermost · public chat (outside-in)" -# Defaults: current official clients + vendor ESR floor (2026-07 docs). -: "${MATTERMOST_MOBILE_MIN_SERVER:=10.11.0}" -: "${MATTERMOST_DESKTOP_MIN_SERVER:=10.11.0}" -: "${MATTERMOST_SUPPORT_MIN_SERVER:=10.11.0}" -# Master switch: CLIENT_CHECK, else legacy MOBILE_CHECK, else on -if [ -n "${MATTERMOST_CLIENT_CHECK:-}" ]; then - : -elif [ -n "${MATTERMOST_MOBILE_CHECK:-}" ]; then - MATTERMOST_CLIENT_CHECK="${MATTERMOST_MOBILE_CHECK}" -else - MATTERMOST_CLIENT_CHECK=1 -fi -: "${MATTERMOST_MOBILE_CHECK:=${MATTERMOST_CLIENT_CHECK}}" - if [ -n "${MATTERMOST_PUBLIC:-}" ]; then BASE="${MATTERMOST_PUBLIC%/}" elif [ -n "${MATTERMOST_HOST:-}" ]; then @@ -55,7 +27,6 @@ HOST=${HOST#http://} HOST=${HOST%%/*} info "target" "$BASE" -info "client policy" "mobile≥${MATTERMOST_MOBILE_MIN_SERVER} · desktop≥${MATTERMOST_DESKTOP_MIN_SERVER} · support≥${MATTERMOST_SUPPORT_MIN_SERVER} (CLIENT_CHECK=${MATTERMOST_CLIENT_CHECK})" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT @@ -75,139 +46,30 @@ else fail "landing" "$BASE/ → HTTP $code (want 200 HTML Mattermost SPA)" fi -# --- Official Mattermost health API + server version (X-Version-Id) --- +# --- Official Mattermost health API --- set_group api -# Capture body + headers (version is in X-Version-Id, not always in JSON) -hdr_file="$tmp/ping.hdr" -code=$(curl -skS -L --max-redirs 5 -m "${TIMEOUT:-12}" \ - -D "$hdr_file" -o "$tmp/ping.json" -w '%{http_code}' \ - "$BASE/api/v4/system/ping" 2>/dev/null || echo 000) - -MM_SERVER_VER="" -if [ -f "$hdr_file" ]; then - # X-Version-Id: 9.5.3.8427860509.c8cabb… or 10.11.0.… - MM_SERVER_VER=$(grep -i '^x-version-id:' "$hdr_file" | head -1 \ - | sed 's/^[Xx]-[Vv]ersion-[Ii]d:[[:space:]]*//' | tr -d '\r' \ - | sed 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/') -fi - +code=$(mm_get "$BASE/api/v4/system/ping" "$tmp/ping.json") if [ "$code" != "200" ]; then fail "system/ping" "$BASE/api/v4/system/ping → HTTP $code (want 200 JSON)" else + # Ping returns JSON object (fields vary by MM version) if python3 - "$tmp/ping.json" <<'PY' 2>/dev/null import json, sys -with open(sys.argv[1]) as f: +p = sys.argv[1] +with open(p) as f: d = json.load(f) -sys.exit(0 if isinstance(d, dict) else 2) +if not isinstance(d, dict): + sys.exit(2) +# older builds may include status; newer still return object with backends +sys.exit(0) PY then - ok "system/ping" "$BASE/api/v4/system/ping → HTTP 200 JSON${MM_SERVER_VER:+ · server ${MM_SERVER_VER}}" + ok "system/ping" "$BASE/api/v4/system/ping → HTTP 200 JSON" else fail "system/ping" "$BASE/api/v4/system/ping → HTTP 200 but not valid JSON object" fi fi -# --- Server version vs official client families (mobile / desktop / support / web) --- -set_group clients -mm_ver_ge() { - # $1=server $2=need → 0 if server >= need - python3 - "$1" "$2" <<'PY' -import sys - -def parse(v: str): - parts = [] - for p in v.strip().split(".")[:3]: - try: - parts.append(int(p)) - except ValueError: - parts.append(0) - while len(parts) < 3: - parts.append(0) - return tuple(parts) - -sys.exit(0 if parse(sys.argv[1]) >= parse(sys.argv[2]) else 1) -PY -} - -# One policy line: id|min_env_default|severity(error|warn)|human label -# severity: error → fail; warn → warn -_mm_client_policies() { - printf '%s\n' \ - "mobile|${MATTERMOST_MOBILE_MIN_SERVER}|error|Android/iOS store apps (Mattermost Mobile)" \ - "desktop|${MATTERMOST_DESKTOP_MIN_SERVER}|error|Desktop app (Windows/macOS/Linux official)" \ - "support|${MATTERMOST_SUPPORT_MIN_SERVER}|error|vendor-supported server floor (ESR/current)" \ - "web|${MATTERMOST_SUPPORT_MIN_SERVER}|warn|browser webapp (loads with server, but EOL server is insecure/unsupported)" -} - -if [ "${MATTERMOST_CLIENT_CHECK}" = "0" ]; then - info "client compat" "skipped (MATTERMOST_CLIENT_CHECK=0 / MATTERMOST_MOBILE_CHECK=0)" -elif [ -z "$MM_SERVER_VER" ]; then - warn "server version" "could not parse X-Version-Id from /api/v4/system/ping — cannot judge client compatibility" -else - info "server version" "X-Version-Id → ${MM_SERVER_VER}" - while IFS='|' read -r cid cmin csever clabel; do - [ -n "$cid" ] || continue - if mm_ver_ge "$MM_SERVER_VER" "$cmin"; then - ok "${cid} compat" "server ${MM_SERVER_VER} ≥ ${cmin} · ${clabel} OK" - else - detail="server ${MM_SERVER_VER} < ${cmin} · ${clabel}" - hint="upgrade Mattermost server · set MATTERMOST_${cid^^}_MIN_SERVER= or MATTERMOST_CLIENT_CHECK=0" - # Fix hint for support/web keys - case "$cid" in - mobile) hint="upgrade server · MATTERMOST_MOBILE_MIN_SERVER= / MATTERMOST_CLIENT_CHECK=0" ;; - desktop) hint="upgrade server · MATTERMOST_DESKTOP_MIN_SERVER= / MATTERMOST_CLIENT_CHECK=0" ;; - support) hint="server below vendor support floor · MATTERMOST_SUPPORT_MIN_SERVER= / MATTERMOST_CLIENT_CHECK=0" ;; - web) hint="web SPA is served by this old server (works) but platform is unsupported · upgrade recommended" ;; - esac - if [ "$csever" = "error" ]; then - fail "${cid} compat" "$detail" "$hint" - else - warn "${cid} compat" "$detail · $hint" - fi - fi - done < <(_mm_client_policies) -fi - -# Client config (optional): BuildDate / advertised Android/iOS min if server sets it -set_group client-config -code=$(mm_get "$BASE/api/v4/config/client?format=old" "$tmp/client.json") -if [ "$code" = "200" ] && [ -s "$tmp/client.json" ]; then - build=$(python3 - "$tmp/client.json" <<'PY' 2>/dev/null -import json, sys -with open(sys.argv[1]) as f: - d = json.load(f) -print(d.get("BuildDate") or d.get("Version") or "") -PY -) - and_min=$(python3 - "$tmp/client.json" <<'PY' 2>/dev/null -import json, sys -with open(sys.argv[1]) as f: - d = json.load(f) -print((d.get("AndroidMinVersion") or "").strip()) -PY -) - ios_min=$(python3 - "$tmp/client.json" <<'PY' 2>/dev/null -import json, sys -with open(sys.argv[1]) as f: - d = json.load(f) -print((d.get("IosMinVersion") or d.get("IOSMinVersion") or "").strip()) -PY -) - if [ -n "$build" ]; then - info "client config" "BuildDate/Version=${build}${and_min:+ · AndroidMinVersion=${and_min}}${ios_min:+ · IosMinVersion=${ios_min}}" - else - info "client config" "HTTP 200 (no BuildDate field)" - fi - if [ -n "$and_min" ] && [ "$and_min" != "0.0.0" ]; then - info "android min (server)" "server advertises AndroidMinVersion=${and_min}" - fi - if [ -n "$ios_min" ] && [ "$ios_min" != "0.0.0" ]; then - info "ios min (server)" "server advertises IosMinVersion=${ios_min}" - fi -else - info "client config" "HTTP ${code:-?} — optional" -fi - # --- Login SPA (must be served for users) --- set_group login code=$(mm_get "$BASE/login" "$tmp/login.html") @@ -247,9 +109,5 @@ else info "tls cert" "openssl not available — skip expiry check" fi -info "hint" "surface catalog also lists $HOST; client floors: mobile/desktop/support ≥${MATTERMOST_MOBILE_MIN_SERVER}/${MATTERMOST_DESKTOP_MIN_SERVER}/${MATTERMOST_SUPPORT_MIN_SERVER}" -# Non-zero when any fail/err so parent phase + mon pages mark ERROR -if [ "${FAIL_N:-0}" -gt 0 ]; then - exit 1 -fi +info "hint" "surface catalog also lists $HOST; this phase is Mattermost-specific (SPA + /api/v4/system/ping)" exit 0 diff --git a/check_monitoring_pages.sh b/check_monitoring_pages.sh index 4ca714a..707853a 100755 --- a/check_monitoring_pages.sh +++ b/check_monitoring_pages.sh @@ -100,20 +100,17 @@ _host_allowed() { } # Public mon URL families (suite name "taler-monitoring" ≠ a public path): -# 1) /monitoring(+_err) — landing hosts (bare + slash) -# 2) /monitoring-max-ladder(+_err) — GOA max-search amount ladder (daily, hacktivism) -# 3) /taler-monitoring-surface(+_err) — taler.hacktivism.ch only -# 4) /taler-monitoring-aptdeploy(+_err) — taler.hacktivism.ch only -# No classic /monitoring-ladder. No /taler-monitoring page. +# 1) /monitoring(+_err) — landing hosts (bare + slash) +# 2) /taler-monitoring-surface(+_err) — taler.hacktivism.ch only +# 3) /taler-monitoring-aptdeploy(+_err) — taler.hacktivism.ch only +# No /taler-monitoring page. No /taler-monitoring-mail|mattermost pages. _path_allowed() { case "$1" in monitoring|monitoring_err|\ - monitoring-max-ladder|monitoring-max-ladder_err|\ taler-monitoring-surface|taler-monitoring-surface_err|\ taler-monitoring-aptdeploy|taler-monitoring-aptdeploy_err) return 0 ;; # explicit deny (never invent a mon page here) - monitoring-ladder|monitoring-ladder_err|\ taler-monitoring|taler-monitoring-mail|taler-monitoring-mattermost) return 1 ;; *) return 1 ;; esac @@ -137,11 +134,12 @@ _discover_tree() { done < <(find "${root%/}" -mindepth 3 -maxdepth 3 -type f -name index.html -print0 2>/dev/null) } -# Landing stacks (GOA 3 + FP stage 3) with /monitoring/ -_landing_allowed() { +# Nine landing stacks (GOA 3 + FP stage 3 + FP prod 3) with /monitoring/ +_landing_nine() { printf '%s\n' \ bank.hacktivism.ch exchange.hacktivism.ch taler.hacktivism.ch \ - stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch + stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch \ + bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch } # Suite catalog of OK pages that must exist for this family. @@ -151,7 +149,6 @@ _catalog_urls() { goa) for h in bank.hacktivism.ch exchange.hacktivism.ch taler.hacktivism.ch; do printf 'https://%s/monitoring/\n' "$h" - printf 'https://%s/monitoring-max-ladder/\n' "$h" done # ecosystem surface (versions / software) + apt-src deploy mon page printf 'https://taler.hacktivism.ch/taler-monitoring-surface/\n' @@ -165,16 +162,11 @@ _catalog_urls() { done ;; all|nine) - # GOA + FP stage landings + surface + aptdeploy (nine kept as alias for inventory) + # optional: all nine landings + surface + aptdeploy while IFS= read -r h; do [ -n "$h" ] || continue printf 'https://%s/monitoring/\n' "$h" - case "$h" in - *.hacktivism.ch) - printf 'https://%s/monitoring-max-ladder/\n' "$h" - ;; - esac - done < <(_landing_allowed) + done < <(_landing_nine) printf 'https://taler.hacktivism.ch/taler-monitoring-surface/\n' printf 'https://taler.hacktivism.ch/taler-monitoring-aptdeploy/\n' ;; @@ -236,25 +228,6 @@ is_bootstrap_html() { && ! grep -qE 'taler-mon:top|id="mon-console"|class="console"' "$f" 2>/dev/null } -# Stale mon HTML from pre-1.15.8 generators: box-drawing char-class regex in -# sticky filter JS (Python SyntaxWarning: invalid escape sequence '\-'). -# Never accept these as "current" public assets (v1.18.2+). -is_stale_generator_html() { - local f="$1" - # Old isLowValue() JS (literal box glyphs + \- class) - if grep -qE 'if \(/\^\[[╔╗╚╝║═]' "$f" 2>/dev/null; then - return 0 - fi - # Converter noise teed into old logs and re-rendered - if grep -qiE 'SyntaxWarning: invalid escape sequence' "$f" 2>/dev/null; then - return 0 - fi - if grep -qiE 'console_to_html\.py:[0-9]+: SyntaxWarning' "$f" 2>/dev/null; then - return 0 - fi - return 1 -} - # True if body looks like our monitoring HTML (not merchant API / WP 404 / bootstrap). is_monitoring_html() { local f="$1" @@ -503,19 +476,6 @@ check_one() { return 0 fi - # Stale generator JS / SyntaxWarning in public body (pre-1.15.8 assets) - if is_stale_generator_html "$body"; then - if [ "$attempt" -lt "$max_try" ]; then - attempt=$((attempt + 1)) - sleep "$sleep_s" 2>/dev/null || sleep 1 - continue - fi - _mon_fail_or_soft "public mon page stale generator" \ - "$url -> old mon HTML (box-drawing JS regex and/or SyntaxWarning in body) — re-run host-agent on suite ≥v1.15.8 / v1.18.2; do not leave pre-update assets live" || { rm -f "$body"; return 1; } - rm -f "$body" - return 0 - fi - if ! is_monitoring_html "$body"; then if [ "$attempt" -lt "$max_try" ]; then attempt=$((attempt + 1)) diff --git a/check_urls.sh b/check_urls.sh index f2557ff..aa2522e 100755 --- a/check_urls.sh +++ b/check_urls.sh @@ -1316,7 +1316,7 @@ if [ "${LOCAL_STACK:-1}" = "1" ] || [ -n "${BANK_PUBLIC:-}" ]; then fi ;; 404|405|501) - # GOA bank landing mints demo-withdraw.json; stage TESTPAYSAN uses bank withdraw/wallet guide only + # GOA bank landing mints demo-withdraw.json; stage TESTPAYSAN uses ATM/wallet guide only if [ "${EXPECT_CURRENCY:-}" = "GOA" ] || [ "${LOCAL_STACK:-0}" = "1" ]; then fail "landing bank demo-withdraw" "HTTP $dw_code (want 200)" else @@ -1339,90 +1339,6 @@ if [ "${LOCAL_STACK:-1}" = "1" ] || [ -n "${BANK_PUBLIC:-}" ]; then fi fi -# --------------------------------------------------------------------------- -# taler:// URIs must not carry default ports :443 / :80 (wallet / QR rule) -# Scans public landings on this stack (bank + exchange + merchant intros, -# bank mint JSON). Fail hard on GOA/local; soft warn elsewhere. -# --------------------------------------------------------------------------- -set_group landings -section "www · taler:// default ports (:443/:80 must be absent)" -_port_scan_fail=0 -_port_scan_ok=0 -_port_scan_one() { - local label="$1" url="$2" - local f code n detail - f="$tmp/portscan-$$.body" - code=$(http_body "$url" "$f") - if [ "$code" != "200" ]; then - if [ "${LOCAL_STACK:-1}" = "1" ] || [ "${EXPECT_CURRENCY:-}" = "GOA" ]; then - # mint JSON is hard; HTML intros soft if missing - case "$url" in - *demo-withdraw.json|*auto-account.json) - fail "taler-uri ports · $label" "HTTP $code · $url" - _port_scan_fail=$((_port_scan_fail + 1)) - ;; - *) - warn "taler-uri ports · $label" "HTTP $code · skip · $url" - ;; - esac - else - info "taler-uri ports · $label" "HTTP $code · skip" - fi - rm -f "$f" - return 0 - fi - detail=$(python3 - "$f" <<'PY' 2>/dev/null || true -import re, sys, json -from pathlib import Path -raw = Path(sys.argv[1]).read_text(errors="replace") -# collect taler:// from JSON fields and raw HTML/JS -uris = set(re.findall(r"taler://[A-Za-z0-9._~:/?#\[\]@!$&'()*+,;=%-]+", raw)) -# JSON-escaped sequences -uris.update(re.findall(r"taler:\\/\\/[A-Za-z0-9._~:/?#\[\]@!$&'()*+,;=%\\-]+", raw)) -uris = {u.replace("\\/", "/") for u in uris} -bad = [] -pat = re.compile(r"taler://\S+:(443|80)(/|$|\?|#)", re.I) -for u in sorted(uris): - if pat.search(u): - bad.append(u[:120]) -if bad: - print("BAD\t%d\t%s" % (len(bad), bad[0])) -else: - print("OK\t%d\t" % len(uris)) -PY -) - n_kind=${detail%%$'\t'*} - rest=${detail#*$'\t'} - n_count=${rest%%$'\t'*} - sample=${rest#*$'\t'} - if [ "$n_kind" = "BAD" ]; then - if [ "${LOCAL_STACK:-1}" = "1" ] || [ "${EXPECT_CURRENCY:-}" = "GOA" ]; then - fail "taler-uri ports · $label" "default :443/:80 still present · n=${n_count} e.g. ${sample}" - _port_scan_fail=$((_port_scan_fail + 1)) - else - warn "taler-uri ports · $label" "default port in URI · ${sample}" - fi - else - ok "taler-uri ports · $label" "no default ports · taler_uris=${n_count:-0} · $url" - _port_scan_ok=$((_port_scan_ok + 1)) - fi - rm -f "$f" -} -if [ "${CHECK_LANDING:-1}" = "1" ]; then - _port_scan_one "bank intro HTML" "${BANK_PUBLIC}/intro/" - _port_scan_one "bank demo-withdraw.json" "${BANK_PUBLIC}/intro/demo-withdraw.json" - _port_scan_one "bank auto-account.json" "${BANK_PUBLIC}/intro/auto-account.json" - _port_scan_one "exchange intro HTML" "${EXCHANGE_PUBLIC}/intro/" - _port_scan_one "merchant intro HTML" "${MERCHANT_PUBLIC}/intro/" - # stats may embed demo withdraw URI - _port_scan_one "bank stats.json" "${BANK_PUBLIC}/intro/stats.json" - if [ "$_port_scan_fail" -eq 0 ]; then - ok "taler-uri ports summary" "clean · ${_port_scan_ok} resource(s) checked (bank+exchange+merchant)" - fi -else - info "taler-uri ports" "skipped (CHECK_LANDING=0)" -fi - # Merchant shop assets — GOA: shop-pay.*; stage TESTPAYSAN: /assets/shop-ui.js + # shops.css + QR encoder (shop-ui modal needs /intro/qrcode.min.js or /qrcode.min.js). _ma=0 diff --git a/domains.conf b/domains.conf index 1002e69..1165936 100644 --- a/domains.conf +++ b/domains.conf @@ -1,53 +1,48 @@ # taler-monitoring domain profiles # # When you add a stack, declare the three public endpoints here: -# name bank exchange merchant-backend currency local landing lang locale [canonical] +# name bank exchange merchant-backend currency local landing [canonical] # # - name: what -d / TALER_DOMAIN matches (aliases allowed as extra lines) # - bank / exchange / merchant: hostname or full https:// URL -# - currency: GOA | KUDOS | CHF | … (empty or "-" = report only) +# - currency: GOA | KUDOS | CHF | … (empty = report only) # - local: 1 = koopa SSH/inside/e2e stack; 0 = public-only # - landing: 1 = check /intro landings + assets; 0 = skip (no GOA-style landings) -# - lang: UI language for mon console/HTML (en|fr|de). Source of truth when -# TALER_MON_LANG_SET≠1. Workstation TALER_MON_LANG=en does not override. -# **de is supported but must not be used as a profile default** (no row -# sets lang=de unless an operator deliberately chooses it). -# - locale: BCP 47 regional locale for l10n defaults (not the same as UI lang). -# Use **fr-CH** (Suisse romande) for FrancPaysan; **de-CH** (Deutschschweiz) -# for other Swiss / default stacks. Accepts also ch-FR / ch-DE as aliases. # - canonical: optional TALER_DOMAIN label after alias match # -# Legacy lines without locale still parse (locale → de-CH except FP heuristic). -# CLI: --lang en|fr|de · TALER_MON_LANG_SET=1 locks UI lang +# CLI overrides after load: --bank --exchange --merchant --currency # Alternate file: TALER_DOMAINS_CONF=/path/to/domains.conf -# Local GOA (koopa) — landings matter · UI en · locale de-CH -koopa bank.hacktivism.ch exchange.hacktivism.ch taler.hacktivism.ch GOA 1 1 en de-CH hacktivism.ch -hacktivism bank.hacktivism.ch exchange.hacktivism.ch taler.hacktivism.ch GOA 1 1 en de-CH hacktivism.ch -hacktivism.ch bank.hacktivism.ch exchange.hacktivism.ch taler.hacktivism.ch GOA 1 1 en de-CH +# Local GOA (koopa) — landings matter +koopa bank.hacktivism.ch exchange.hacktivism.ch taler.hacktivism.ch GOA 1 1 hacktivism.ch +hacktivism bank.hacktivism.ch exchange.hacktivism.ch taler.hacktivism.ch GOA 1 1 hacktivism.ch +hacktivism.ch bank.hacktivism.ch exchange.hacktivism.ch taler.hacktivism.ch GOA 1 1 -# Public demo (KUDOS) -taler.net bank.demo.taler.net exchange.demo.taler.net backend.demo.taler.net KUDOS 0 1 en de-CH demo.taler.net -demo.taler.net bank.demo.taler.net exchange.demo.taler.net backend.demo.taler.net KUDOS 0 1 en de-CH +# Public demo (KUDOS) — has intro-style pages; keep soft landing checks +taler.net bank.demo.taler.net exchange.demo.taler.net backend.demo.taler.net KUDOS 0 1 demo.taler.net +demo.taler.net bank.demo.taler.net exchange.demo.taler.net backend.demo.taler.net KUDOS 0 1 -# Public test stack (TESTKUDOS) -test.taler.net bank.test.taler.net exchange.test.taler.net backend.test.taler.net TESTKUDOS 0 0 en de-CH +# Public test stack (TESTKUDOS) — no GOA-style landings +test.taler.net bank.test.taler.net exchange.test.taler.net backend.test.taler.net TESTKUDOS 0 0 -# TOPS CHF -taler-ops.ch bank.taler-ops.ch exchange.taler-ops.ch my.taler-ops.ch CHF 0 0 en de-CH -my.taler-ops.ch bank.taler-ops.ch exchange.taler-ops.ch my.taler-ops.ch CHF 0 0 en de-CH taler-ops.ch -stage.taler-ops.ch bank.stage.taler-ops.ch exchange.stage.taler-ops.ch stage.my.taler-ops.ch CHF 0 0 en de-CH -stage.my.taler-ops.ch bank.stage.taler-ops.ch exchange.stage.taler-ops.ch stage.my.taler-ops.ch CHF 0 0 en de-CH stage.taler-ops.ch -my.stage.taler-ops.ch bank.stage.taler-ops.ch exchange.stage.taler-ops.ch stage.my.taler-ops.ch CHF 0 0 en de-CH stage.taler-ops.ch +# TOPS CHF — multi-tenant merchant my.taler-ops.ch; no public GOA landings +taler-ops.ch bank.taler-ops.ch exchange.taler-ops.ch my.taler-ops.ch CHF 0 0 +my.taler-ops.ch bank.taler-ops.ch exchange.taler-ops.ch my.taler-ops.ch CHF 0 0 taler-ops.ch +# Stage merchant FQDN is stage.my.taler-ops.ch (on betel); mon HTML /monitoring* stage-only +stage.taler-ops.ch bank.stage.taler-ops.ch exchange.stage.taler-ops.ch stage.my.taler-ops.ch CHF 0 0 +stage.my.taler-ops.ch bank.stage.taler-ops.ch exchange.stage.taler-ops.ch stage.my.taler-ops.ch CHF 0 0 stage.taler-ops.ch +my.stage.taler-ops.ch bank.stage.taler-ops.ch exchange.stage.taler-ops.ch stage.my.taler-ops.ch CHF 0 0 stage.taler-ops.ch -# Franc Paysan — UI fr · regional locale fr-CH (Suisse romande) -lefrancpaysan.ch bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch - 0 0 fr fr-CH -monnaie.lefrancpaysan.ch bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch - 0 0 fr fr-CH lefrancpaysan.ch -bank.lefrancpaysan.ch bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch - 0 0 fr fr-CH lefrancpaysan.ch -exchange.lefrancpaysan.ch bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch - 0 0 fr fr-CH lefrancpaysan.ch +# Franc Paysan (Infomaniak) — merchant host is monnaie.* (not taler./backend.) +# Prod: no monetary launch yet; stage uses TESTPAYSAN (public HTTPS landings + shops) +lefrancpaysan.ch bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch - 0 0 +monnaie.lefrancpaysan.ch bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch - 0 0 lefrancpaysan.ch +bank.lefrancpaysan.ch bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch - 0 0 lefrancpaysan.ch +exchange.lefrancpaysan.ch bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch - 0 0 lefrancpaysan.ch -# Stage TESTPAYSAN — UI fr · locale fr-CH -stage.lefrancpaysan.ch stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch TESTPAYSAN 0 1 fr fr-CH -stage.bank.lefrancpaysan.ch stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch TESTPAYSAN 0 1 fr fr-CH stage.lefrancpaysan.ch -stage.exchange.lefrancpaysan.ch stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch TESTPAYSAN 0 1 fr fr-CH stage.lefrancpaysan.ch -stage.monnaie.lefrancpaysan.ch stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch TESTPAYSAN 0 1 fr fr-CH stage.lefrancpaysan.ch +# Stage TESTPAYSAN — landings on / + farmer shops under stage.monnaie…/shops/ +# name bank exchange merchant currency local landing [canonical] +stage.lefrancpaysan.ch stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch TESTPAYSAN 0 1 +stage.bank.lefrancpaysan.ch stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch TESTPAYSAN 0 1 stage.lefrancpaysan.ch +stage.exchange.lefrancpaysan.ch stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch TESTPAYSAN 0 1 stage.lefrancpaysan.ch +stage.monnaie.lefrancpaysan.ch stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch TESTPAYSAN 0 1 stage.lefrancpaysan.ch diff --git a/host-agent/README.md b/host-agent/README.md index cf8969c..24f0a45 100644 --- a/host-agent/README.md +++ b/host-agent/README.md @@ -19,27 +19,13 @@ Thin wrappers only set stack defaults: |---------|-------|----------------| | `run-hacktivism-monitoring.sh` | GOA `hacktivism.ch` | `hernani` @ koopa | | `run-fp-stage-monitoring.sh` | FP stage | `stagepaysan` | +| `run-fp-prod-monitoring.sh` | FP prod | `francpaysan` | | `run-host-report.sh` + `taler-monitoring-mytops-stage.{service,timer}` | mytops **stage / betel** only | `taler-monitoring` @ betel (4h) | | `run-aptdeploy.sh` | CLI: ensure + **aptdeploy** (no HTML) | local if hostname=koopa, else **ssh $DEPLOY_SSH** | | `run-aptdeploy-monitoring.sh` | apt-src tests → `/taler-monitoring-aptdeploy*` | `hernani` @ koopa (4h) | | `run-surface-monitoring.sh` | **surface** → only `/taler-monitoring-surface*` (ecosystem + mail + mattermost + versions) | `hernani` @ koopa (hourly) | -| `run-max-ladder-monitoring.sh` | GOA **max-search** ladder → `/monitoring-max-ladder/` on bank/exchange/taler | `hernani` @ koopa (**daily**) | -Deprecated mail/mattermost wrappers: **`../meta/deprecated/`** (not installed). No classic **`/monitoring-ladder`** page. - -### GOA max-search ladder page (daily) - -| URL | Phase | Timer | -|-----|-------|-------| -| `https://{bank,exchange,taler}.hacktivism.ch/monitoring-max-ladder/` | `max-ladder` | `taler-monitoring-max-ladder.timer` (~06:30 + jitter) | - -```bash -systemctl --user enable --now taler-monitoring-max-ladder.timer -# first round now: -systemctl --user start taler-monitoring-max-ladder.service -``` - -Needs explorer secrets (`SECRETS_ROOT` / bank-explorer password). Wall ~3h (`RUN_TIMEOUT=10800`). +Deprecated mail/mattermost wrappers: **`../meta/deprecated/`** (not installed). ### apt-src deploy tests (hacktivism `/monitoring`) @@ -68,7 +54,7 @@ Checks: package table, `httpd --version`, libtalerutil/`ldd` on failure, `system | URL | Role | |-----|------| -| `https://{bank,exchange,merchant}/monitoring/` (+ `_err`) | **Landing-stack** report — GOA 3 + FP **stage** 3 (+ mytops stage as configured) | +| `https://{bank,exchange,merchant}/monitoring/` (+ `_err`) | **Landing-stack** report — each of the **9** landing fronts (GOA 3 + FP stage 3 + FP prod 3) | | `https://taler.hacktivism.ch/taler-monitoring-surface/` (+ `_err`) | **Only** ecosystem page: software/versions in the Taler universe (nmap OS, mail firefly+anastasis, mattermost, …) | No separate public pages for mail/mattermost. Staging under `~/monitoring-sites-staging/`. @@ -78,7 +64,7 @@ systemctl --user enable --now taler-monitoring-surface.timer systemctl --user start taler-monitoring-surface.service ``` -Env examples: **`env/*.env.example`**. FP stage: `run-fp-stage-monitoring.sh` (same `run-host-report.sh` pipeline). +Env examples: **`env/*.env.example`**. FP: `run-fp-prod-monitoring.sh` / `run-fp-stage-monitoring.sh` (same `run-host-report.sh` pipeline). ## GOA (koopa) — host-podman diff --git a/host-agent/ROOT-APPLY-MONITORING.md b/host-agent/ROOT-APPLY-MONITORING.md index 7d38b35..0a594d1 100644 --- a/host-agent/ROOT-APPLY-MONITORING.md +++ b/host-agent/ROOT-APPLY-MONITORING.md @@ -48,12 +48,9 @@ There is **no** public page `/taler-monitoring`. Each family needs **bare and sl | Family | Paths | Host | Source timer | |--------|-------|------|----------------| | **monitoring** | `/monitoring` · `/monitoring/` · `/monitoring_err` · `/monitoring_err/` | bank + exchange + taler (and other landings) | `taler-monitoring-hacktivism.timer` (4h) | -| **monitoring-max-ladder** | `/monitoring-max-ladder` · `/` · `_err` | bank + exchange + taler (**GOA** max-search only) | `taler-monitoring-max-ladder.timer` (**daily**) | | **taler-monitoring-surface** | bare + slash + `_err` | **taler.hacktivism.ch only** | `taler-monitoring-surface.timer` (1h) | | **taler-monitoring-aptdeploy** | bare + slash + `_err` | **taler.hacktivism.ch only** | `taler-monitoring-aptdeploy.timer` (4h) | -No classic **`/monitoring-ladder`**. Max-ladder served via Caddy `handle /monitoring*` under `/var/www/monitoring-sites/{host}/`. - HTML is generated as **hernani** into `$DEPLOY_STAGING (or $HOME/monitoring-sites-staging)/`. diff --git a/host-agent/apply-monitoring-live.sh b/host-agent/apply-monitoring-live.sh index dfc4798..4916ba8 100755 --- a/host-agent/apply-monitoring-live.sh +++ b/host-agent/apply-monitoring-live.sh @@ -57,9 +57,6 @@ urls=( https://taler.hacktivism.ch/monitoring/ https://bank.hacktivism.ch/monitoring/ https://exchange.hacktivism.ch/monitoring/ - https://taler.hacktivism.ch/monitoring-max-ladder/ - https://bank.hacktivism.ch/monitoring-max-ladder/ - https://exchange.hacktivism.ch/monitoring-max-ladder/ https://taler.hacktivism.ch/taler-monitoring-surface https://taler.hacktivism.ch/taler-monitoring-surface/ https://taler.hacktivism.ch/taler-monitoring-surface_err/ diff --git a/host-agent/env.example b/host-agent/env.example index 0915d39..2826f83 100644 --- a/host-agent/env.example +++ b/host-agent/env.example @@ -4,6 +4,7 @@ # Full stack examples (same reporting generation for all): # env/hacktivism.env.example # env/stagepaysan.env.example +# env/francpaysan.env.example # # SUITE_GIT_URL=https://git.hacktivism.ch/hernani/taler-monitoring.git # SUITE_GIT_REF=main diff --git a/host-agent/env/francpaysan.env.example b/host-agent/env/francpaysan.env.example new file mode 100644 index 0000000..2f5019d --- /dev/null +++ b/host-agent/env/francpaysan.env.example @@ -0,0 +1,27 @@ +# Copy to: ~/.config/taler-monitoring/env (user francpaysan) +# Never inside the git tree — update-suite never overwrites this file. +# +# Shared reporting generation (run-host-report.sh / run-fp-prod-monitoring.sh): +# RUN_TIMEOUT, line-buffered log, always HTML, commit link on git.hacktivism.ch + +TALER_DOMAIN=lefrancpaysan.ch +INSIDE_PODMAN=1 +INSIDE_MODE=local-podman +LOCAL_STACK=0 +CONTINUE_ON_ERROR=1 +PHASES="urls inside versions" +RUN_TIMEOUT=600 + +HTML_OUT=$HOME/monitoring-sites-staging +MON_HOSTS="bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch" + +SUITE_DIR=$HOME/src/taler-monitoring +SUITE_GIT_URL=https://git.hacktivism.ch/hernani/taler-monitoring.git +SUITE_GIT_REF=main +SUITE_UPDATE_MODE=reset +SOURCE_REPO_WEB=https://git.hacktivism.ch/hernani/taler-monitoring + +# DEPLOY_WWW_ROOT=/var/www/monitoring-sites + +# UI language for console + HTML sticky bar (en|fr) +TALER_MON_LANG=fr diff --git a/host-agent/env/mytops-stage.env.example b/host-agent/env/mytops-stage.env.example index 0da4f19..5db18bf 100644 --- a/host-agent/env/mytops-stage.env.example +++ b/host-agent/env/mytops-stage.env.example @@ -18,8 +18,7 @@ SKIP_SSH=1 LOCAL_STACK=0 INSIDE_PODMAN=0 CONTINUE_ON_ERROR=1 -# ladder needs wall time (23× fake-incoming SSH) -RUN_TIMEOUT=1800 +RUN_TIMEOUT=600 STRICT_EXIT=1 MONPAGES_REQUIRE_PUBLIC=1 MONPAGES_INVENTORY=job @@ -33,9 +32,4 @@ CHECK_LANDING=0 # rusty devtesting (SSH Host taler-rusty-devtesting → devtesting@rusty.taler-ops.ch) DEVTESTING_SSH=taler-rusty-devtesting DEVTESTING_AMOUNT=CHF:1.00 -# CHF fake-incoming amount ladder (23 rungs → 50k) -DEVTESTING_LADDER=1 -DEVTESTING_LADDER_STEPS=23 -DEVTESTING_LADDER_MAX=50000 -DEVTESTING_LADDER_MIN=0.01 # DEVTESTING_SKIP=1 diff --git a/host-agent/env/stagepaysan.env.example b/host-agent/env/stagepaysan.env.example index abfcdc3..e91d54e 100644 --- a/host-agent/env/stagepaysan.env.example +++ b/host-agent/env/stagepaysan.env.example @@ -1,10 +1,8 @@ # Copy to: ~/.config/taler-monitoring/env (user stagepaysan) # Never inside the git tree — update-suite never overwrites this file. # -# Secrets: use francpaysan-secrets layout (operator tree or host mirror): -# $HOME/francpaysan-secrets/stage/bank-admin-password.txt -# $HOME/francpaysan-secrets/stage/default-instance-token.txt -# On stage host, symlink those to /mnt/data/stagepaysan/*/secrets/… +# Shared reporting generation (run-host-report.sh / run-fp-stage-monitoring.sh): +# RUN_TIMEOUT, line-buffered log, always HTML, commit link on git.hacktivism.ch TALER_DOMAIN=stage.lefrancpaysan.ch INSIDE_PODMAN=1 @@ -12,32 +10,21 @@ INSIDE_MODE=local-podman INSIDE_PROFILE=stage-lfp LOCAL_STACK=0 CONTINUE_ON_ERROR=1 -PHASES="urls inside versions monpages e2e" -RUN_TIMEOUT=1800 -E2E_TIMEOUT=900 -E2E_USE_TEMPLATES=1 +PHASES="urls inside versions" +RUN_TIMEOUT=600 HTML_OUT=$HOME/monitoring-sites-staging MON_HOSTS="stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch" -DEPLOY_WWW_ROOT=/var/www/monitoring-sites +# Git clone of taler-monitoring (repo root, not …/taler-monitoring (repo root)) SUITE_DIR=$HOME/src/taler-monitoring SUITE_GIT_URL=https://git.hacktivism.ch/hernani/taler-monitoring.git SUITE_GIT_REF=main SUITE_UPDATE_MODE=reset SOURCE_REPO_WEB=https://git.hacktivism.ch/hernani/taler-monitoring -FRANCPAYSAN_SECRETS=$HOME/francpaysan-secrets -WALLET_CLI=$HOME/.local/lib/taler-wallet-cli/node_modules/taler-wallet-cli/bin/taler-wallet-cli.mjs -WALLET_CLI_CANDIDATES="$HOME/.local/lib/taler-wallet-cli/node_modules/taler-wallet-cli/bin/taler-wallet-cli.mjs $HOME/.local/bin/taler-wallet-cli.mjs" - -INSIDE_BANK_CTR=stage-lfp-bank -INSIDE_EXCHANGE_CTR=stage-lfp-exchange-ansible -INSIDE_MERCHANT_CTR=stage-lfp-merchant +# Optional public docroot if this user can write it +# DEPLOY_WWW_ROOT=/var/www/monitoring-sites +# UI language for console + HTML sticky bar (en|fr) TALER_MON_LANG=fr -MONPAGES_REQUIRE_PUBLIC=1 -MONPAGES_INVENTORY=job -STRICT_EXIT=1 -AGENT_LABEL=fp-stage-host-agent -STATE_NAME=taler-monitoring-stage-lfp diff --git a/host-agent/install-host-agent.sh b/host-agent/install-host-agent.sh index 118ef7f..3468455 100755 --- a/host-agent/install-host-agent.sh +++ b/host-agent/install-host-agent.sh @@ -63,21 +63,11 @@ install_local() { # optional aptdeploy (not a public mon page layout — v1.8.0 simplified overview) install -m 644 "$ROOT/taler-monitoring-aptdeploy.service" "$home_unit/" install -m 644 "$ROOT/taler-monitoring-aptdeploy.timer" "$home_unit/" - # GOA max-search amount ladder page (daily only — no classic /monitoring-ladder) - install -m 644 "$ROOT/taler-monitoring-max-ladder.service" "$home_unit/" - install -m 644 "$ROOT/taler-monitoring-max-ladder.timer" "$home_unit/" - chmod +x "$ROOT/run-max-ladder-monitoring.sh" 2>/dev/null || true systemctl --user daemon-reload systemctl --user enable --now taler-monitoring-hacktivism.path systemctl --user enable --now taler-monitoring-hacktivism.timer systemctl --user enable --now taler-monitoring-surface.timer systemctl --user enable --now taler-monitoring-aptdeploy.timer - systemctl --user enable --now taler-monitoring-max-ladder.timer - # drop classic ladder mon page if previously installed - systemctl --user disable --now taler-monitoring-ladder.timer 2>/dev/null || true - systemctl --user stop taler-monitoring-ladder.service 2>/dev/null || true - rm -f "$home_unit/taler-monitoring-ladder.service" \ - "$home_unit/taler-monitoring-ladder.timer" 2>/dev/null || true # Remove leftover mail/mattermost units if present (moved to meta/deprecated/) systemctl --user disable --now taler-monitoring-mattermost.timer 2>/dev/null || true systemctl --user disable --now taler-monitoring-mail.timer 2>/dev/null || true @@ -88,29 +78,23 @@ install_local() { systemctl --user daemon-reload 2>/dev/null || true # initial stamp so path exists "$ROOT/touch-software-stamp.sh" - # oneshot jobs: --no-block so install does not wait hours - systemctl --user start --no-block taler-monitoring-hacktivism.service || true - systemctl --user start --no-block taler-monitoring-surface.service || true - systemctl --user start --no-block taler-monitoring-aptdeploy.service || true - # first max-ladder round immediately (daily thereafter) - systemctl --user start --no-block taler-monitoring-max-ladder.service || true + systemctl --user start taler-monitoring-hacktivism.service || true + systemctl --user start taler-monitoring-surface.service || true + systemctl --user start taler-monitoring-aptdeploy.service || true echo "--- status ---" systemctl --user status taler-monitoring-hacktivism.path --no-pager -l | head -15 systemctl --user status taler-monitoring-hacktivism.timer --no-pager -l | head -12 systemctl --user status taler-monitoring-surface.timer --no-pager -l | head -12 systemctl --user status taler-monitoring-aptdeploy.timer --no-pager -l | head -12 - systemctl --user status taler-monitoring-max-ladder.timer --no-pager -l | head -12 systemctl --user list-timers --all | grep taler-monitoring || true - echo "OK host-agent:" + echo "OK host-agent (v1.8.0 simplified):" echo " · hacktivism 4h → /monitoring on bank/exchange/taler (landing stacks)" - echo " · max-ladder daily → /monitoring-max-ladder/ (GOA max-search, bank/exchange/taler)" echo " · surface 1h → /taler-monitoring-surface* (ecosystem versions/software)" - echo " · aptdeploy 4h (optional tests)" - echo " · no classic /monitoring-ladder page" + echo " · aptdeploy 4h (optional tests; not a public mon-page type)" echo " · mail/mattermost: not installed (meta/deprecated/; content in surface)" echo "suite: $mon" - echo "manual max-ladder: systemctl --user start taler-monitoring-max-ladder.service" + echo "manual surface: systemctl --user start taler-monitoring-surface.service" echo "after upgrades: $ROOT/touch-software-stamp.sh" } diff --git a/host-agent/run-fp-prod-monitoring.sh b/host-agent/run-fp-prod-monitoring.sh new file mode 100755 index 0000000..c3556d3 --- /dev/null +++ b/host-agent/run-fp-prod-monitoring.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# FrancPaysan PROD host-agent (user francpaysan on ). +# Shared reporting: run-host-report.sh (timeout, line-buffered log, first-run HTML). +set -uo pipefail + +# Language: en|fr (selectable). Default for this wrapper: fr +export TALER_MON_LANG="${TALER_MON_LANG:-fr}" +export TALER_MON_LANG_SET=1 +AGENT_DIR=$(cd "$(dirname "$0")" && pwd) + +export AGENT_LABEL="${AGENT_LABEL:-fp-prod-host-agent}" +export STATE_NAME="${STATE_NAME:-taler-monitoring-lfp-prod}" +export TALER_DOMAIN="${TALER_DOMAIN:-lefrancpaysan.ch}" +export INSIDE_PODMAN="${INSIDE_PODMAN:-1}" +export INSIDE_MODE="${INSIDE_MODE:-local-podman}" +export LOCAL_STACK="${LOCAL_STACK:-0}" +export CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-1}" +# monpages obligatory (ERROR): only FP mon hosts below — never GOA inventory +export MONPAGES_REQUIRE_PUBLIC="${MONPAGES_REQUIRE_PUBLIC:-1}" +export RUN_TIMEOUT="${RUN_TIMEOUT:-600}" +export PHASES="${PHASES:-urls inside versions monpages}" +export MON_HOSTS="${MON_HOSTS:-bank.lefrancpaysan.ch exchange.lefrancpaysan.ch monnaie.lefrancpaysan.ch}" +export HTML_OUT="${HTML_OUT:-$HOME/monitoring-sites-staging}" +export DEPLOY_WWW_ROOT="${DEPLOY_WWW_ROOT:-/var/www/monitoring-sites}" + +exec bash "$AGENT_DIR/run-host-report.sh" "$@" diff --git a/host-agent/run-fp-stage-monitoring.sh b/host-agent/run-fp-stage-monitoring.sh index e7f95e8..3675ba6 100755 --- a/host-agent/run-fp-stage-monitoring.sh +++ b/host-agent/run-fp-stage-monitoring.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# FrancPaysan STAGE host-agent (user stagepaysan via francpaysan-stage-user). +# FrancPaysan STAGE host-agent (user stagepaysan on ). # Shared reporting: run-host-report.sh (timeout, line-buffered log, first-run HTML). set -uo pipefail @@ -18,8 +18,8 @@ export LOCAL_STACK="${LOCAL_STACK:-0}" export CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-1}" # monpages obligatory (ERROR): only FP stage mon hosts below — never GOA inventory export MONPAGES_REQUIRE_PUBLIC="${MONPAGES_REQUIRE_PUBLIC:-1}" -export RUN_TIMEOUT="${RUN_TIMEOUT:-1800}" -export PHASES="${PHASES:-urls inside versions monpages e2e}" +export RUN_TIMEOUT="${RUN_TIMEOUT:-600}" +export PHASES="${PHASES:-urls inside versions monpages}" export MON_HOSTS="${MON_HOSTS:-stage.bank.lefrancpaysan.ch stage.exchange.lefrancpaysan.ch stage.monnaie.lefrancpaysan.ch}" export HTML_OUT="${HTML_OUT:-$HOME/monitoring-sites-staging}" export DEPLOY_WWW_ROOT="${DEPLOY_WWW_ROOT:-/var/www/monitoring-sites}" diff --git a/host-agent/run-hacktivism-monitoring.sh b/host-agent/run-hacktivism-monitoring.sh index 7ccf7c7..02132b8 100755 --- a/host-agent/run-hacktivism-monitoring.sh +++ b/host-agent/run-hacktivism-monitoring.sh @@ -16,12 +16,10 @@ export INSIDE_MODE="${INSIDE_MODE:-local-podman}" export LOCAL_STACK="${LOCAL_STACK:-1}" export CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-1}" export RUN_TIMEOUT="${RUN_TIMEOUT:-600}" -# stack checks + full monpages inventory (landings + max-ladder + surface + aptdeploy). +# stack checks + full monpages inventory (landings + surface + aptdeploy bare/slash). # Specialized pages also have their own timers; full outside-in inventory lives here. -# run-max-ladder-monitoring.sh → /monitoring-max-ladder* (daily max-search, GOA) -# run-aptdeploy-monitoring.sh → monpages job-only for /taler-monitoring-aptdeploy* -# run-surface-monitoring.sh → monpages job-only for /taler-monitoring-surface* -# No classic /monitoring-ladder page. +# run-aptdeploy-monitoring.sh → monpages job-only for /taler-monitoring-aptdeploy* +# run-surface-monitoring.sh → monpages job-only for /taler-monitoring-surface* export PHASES="${PHASES:-urls inside versions monpages}" export MON_HOSTS="${MON_HOSTS:-bank.hacktivism.ch exchange.hacktivism.ch taler.hacktivism.ch}" export HTML_OUT="${HTML_OUT:-$HOME/monitoring-sites-staging}" diff --git a/host-agent/run-host-report.sh b/host-agent/run-host-report.sh index 1f75caf..2ddbc50 100755 --- a/host-agent/run-host-report.sh +++ b/host-agent/run-host-report.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # run-host-report.sh — global reporting generation for all stacks -# (GOA/hacktivism, FP stage, mytops stage, …). +# (GOA/hacktivism, FP stage, FP prod, …). # # Shared behaviour (always): # 1) update-suite → latest git.hacktivism.ch (local ~/.config never overwritten) @@ -18,6 +18,7 @@ # Thin wrappers only set stack defaults then exec this script: # run-hacktivism-monitoring.sh # run-fp-stage-monitoring.sh +# run-fp-prod-monitoring.sh # set -uo pipefail @@ -40,7 +41,6 @@ _wrap_keys=( APT_DEPLOY_ENSURE SURFACE_SCOPE TALER_DOMAIN_FROM_CLI STRICT_EXIT SOURCE_SUITE_PATH MONPAGES_INVENTORY MONPAGES_CHECK_BARE MONPAGES_BARE_STRICT MONPAGES_REQUIRE_PUBLIC CHECK_BANK MERCHANT_REQUIRED CHECK_LANDING - WALLET_CLI CLI_JS PATH LADDER_MODE LADDER_PAY LADDER_PAY_WAIT_AVAILABLE_S ) for _k in "${_wrap_keys[@]}"; do if [ -n "${!_k+x}" ]; then @@ -76,15 +76,19 @@ export CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-1}" export AUTH401_CONTINUE="${AUTH401_CONTINUE:-${CONTINUE_ON_ERROR}}" export RUN_TIMEOUT="${RUN_TIMEOUT:-600}" export TALER_DOMAIN="${TALER_DOMAIN:-hacktivism.ch}" -# UI language: --lang / TALER_MON_LANG_SET=1 locks. -# Otherwise domains.conf column `lang` → TALER_DOMAIN_LANG → TALER_MON_LANG -# (applied in suite apply_taler_domain / i18n_init). Leave SET=0 so -d can re-apply. -# Bare workstation TALER_MON_LANG=en must not override profile lang=fr. -if [ "${TALER_MON_LANG_SET:-0}" = "1" ]; then - case "${TALER_MON_LANG:-en}" in +# UI language: selectable via TALER_MON_LANG / --lang (en|fr). +# If unset, auto: FrancPaysan domains → fr, else en. +if [ "${TALER_MON_LANG_SET:-0}" != "1" ] && [ -z "${TALER_MON_LANG:-}" ]; then + case "$TALER_DOMAIN" in + *lefrancpaysan*|*francpaysan*) export TALER_MON_LANG=fr ;; + *) export TALER_MON_LANG=en ;; + esac +elif [ -n "${TALER_MON_LANG:-}" ]; then + case "$TALER_MON_LANG" in fr|FR|fra|french) export TALER_MON_LANG=fr ;; *) export TALER_MON_LANG=en ;; esac + export TALER_MON_LANG_SET=1 fi export TALER_MON_LANG @@ -350,29 +354,7 @@ htmlify_host() { mkdir -p "$HTML_BASE/$host/${HTML_OK_DIR}" "$HTML_BASE/$host/${HTML_ERR_DIR}" if [ -n "$SITE_GEN" ] && [ -f "$SITE_GEN/console_to_html.py" ]; then - # Never convert with a pre-1.15.8 generator (old assets → SyntaxWarning + bad sticky JS). - if grep -qE 'if \(/\^\[[╔╗╚╝║═]' "$SITE_GEN/console_to_html.py" 2>/dev/null; then - echo "ERROR: refuse stale site-gen $SITE_GEN/console_to_html.py (box-drawing JS regex)" >&2 - return 1 2>/dev/null || exit 1 - fi - # SyntaxWarning = generator regression: fail convert (do not publish old-style pages). - # Other stderr still goes to agent log file only, not the mon console stream. - _mon_html_py() { - local _out="" _i - for _i in "$@"; do - if [ "$_i" = "--out" ]; then _out=1; continue; fi - if [ "$_out" = "1" ]; then _out="$_i"; break; fi - done - PYTHONWARNINGS=error::SyntaxWarning \ - python3 "$SITE_GEN/console_to_html.py" "$@" 2>>"${LOG_DIR:-/tmp}/console_to_html.err" || return 1 - # Never leave pre-1.15.8 sticky JS in a just-written page (stale log text is filtered in converter). - if [ -n "$_out" ] && [ -f "$_out" ] && grep -qE 'if \(/\^\[[╔╗╚╝║═]' "$_out" 2>/dev/null; then - echo "ERROR: generated mon HTML still has stale box-drawing JS: $_out" >&2 - return 1 - fi - return 0 - } - if ! _mon_html_py \ + python3 "$SITE_GEN/console_to_html.py" \ --lang "${TALER_MON_LANG:-en}" \ --log "$LOG" \ --out "$mon_err" \ @@ -386,49 +368,37 @@ htmlify_host() { --page-label "$PAGE_LABEL" \ --path-err "$HTML_URL_ERR" \ --link-other "$HTML_URL_OK" - then - echo "ERROR: mon HTML convert failed (err page) for $host — refuse publish of stale/broken assets" >&2 - return 1 2>/dev/null || exit 1 - fi if [ "$ec" -eq 0 ]; then - if ! _mon_html_py \ - --lang "${TALER_MON_LANG:-en}" \ + python3 "$SITE_GEN/console_to_html.py" \ + --lang "${TALER_MON_LANG:-en}" \ --log "$LOG" \ --out "$mon" \ --hostname "$host" \ --mode ok \ --commit "${COMMIT:-}" \ --commit-url "${COMMIT_URL:-}" \ - --suite-version "${SUITE_VERSION:-unknown}" \ - --suite-version-url "${SUITE_VERSION_URL:-}" \ + --suite-version "${SUITE_VERSION:-unknown}" \ + --suite-version-url "${SUITE_VERSION_URL:-}" \ --suite-path "$SUITE_PATH" \ --page-label "$PAGE_LABEL" \ --path-err "$HTML_URL_ERR" \ --link-other "" - then - echo "ERROR: mon HTML convert failed (ok page) for $host" >&2 - return 1 2>/dev/null || exit 1 - fi rm -rf "$HTML_BASE/$host/${HTML_ERR_DIR}" echo "html $host → ${HTML_URL_OK} only (clean · ${COMMIT_SHORT:-?})" else - if ! _mon_html_py \ - --lang "${TALER_MON_LANG:-en}" \ + python3 "$SITE_GEN/console_to_html.py" \ + --lang "${TALER_MON_LANG:-en}" \ --log "$LOG" \ --out "$mon" \ --hostname "$host" \ --mode redirect \ --commit "${COMMIT:-}" \ --commit-url "${COMMIT_URL:-}" \ - --suite-version "${SUITE_VERSION:-unknown}" \ - --suite-version-url "${SUITE_VERSION_URL:-}" \ + --suite-version "${SUITE_VERSION:-unknown}" \ + --suite-version-url "${SUITE_VERSION_URL:-}" \ --suite-path "$SUITE_PATH" \ --page-label "$PAGE_LABEL" \ --path-err "$HTML_URL_ERR" - then - echo "ERROR: mon HTML convert failed (redirect page) for $host" >&2 - return 1 2>/dev/null || exit 1 - fi echo "html $host → ${HTML_URL_OK} stub + ${HTML_URL_ERR} (ec=$ec · ${COMMIT_SHORT:-?})" fi else diff --git a/host-agent/run-max-ladder-monitoring.sh b/host-agent/run-max-ladder-monitoring.sh deleted file mode 100755 index 813fedd..0000000 --- a/host-agent/run-max-ladder-monitoring.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -# run-max-ladder-monitoring.sh — GOA max-search amount ladder → public HTML -# -# Public (landing hosts, same Caddy /monitoring* static root): -# https://{bank,exchange,taler}.hacktivism.ch/monitoring-max-ladder/ -# https://{bank,exchange,taler}.hacktivism.ch/monitoring-max-ladder_err/ -# -# Timer: once daily (taler-monitoring-max-ladder.timer). Long wall clock. -# -set -uo pipefail -AGENT_DIR=$(cd "$(dirname "$0")" && pwd) - -export AGENT_LABEL="${AGENT_LABEL:-max-ladder-host-agent}" -export STATE_NAME="${STATE_NAME:-taler-max-ladder-monitoring}" -export TALER_DOMAIN="${TALER_DOMAIN:-hacktivism.ch}" -export TALER_MON_LANG="${TALER_MON_LANG:-en}" -export TALER_MON_LANG_SET=1 -export INSIDE_PODMAN="${INSIDE_PODMAN:-1}" -export INSIDE_MODE="${INSIDE_MODE:-local-podman}" -export LOCAL_STACK="${LOCAL_STACK:-1}" -export SKIP_SSH="${SKIP_SSH:-0}" -export CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-1}" -# max-search probes + pay hunt — force high wall clock (koopa env often has RUN_TIMEOUT=600) -export RUN_TIMEOUT="${MAX_LADDER_RUN_TIMEOUT:-10800}" - -export PHASES="max-ladder monpages" -export MON_HOSTS="${MON_HOSTS:-bank.hacktivism.ch exchange.hacktivism.ch taler.hacktivism.ch}" -export HTML_OUT="${HTML_OUT:-$HOME/monitoring-sites-staging}" -export DEPLOY_WWW_ROOT="${DEPLOY_WWW_ROOT:-/var/www/monitoring-sites}" - -export HTML_OK_DIR="monitoring-max-ladder" -export HTML_ERR_DIR="monitoring-max-ladder_err" -export HTML_URL_OK="/monitoring-max-ladder/" -export HTML_URL_ERR="/monitoring-max-ladder_err/" -export PAGE_LABEL="monitoring-max-ladder" -export MONPAGES_INVENTORY="job" - -export LADDER_MODE=max -export LADDER_PAY="${LADDER_PAY:-1}" -export LADDER_PAY_WAIT_AVAILABLE_S="${LADDER_PAY_WAIT_AVAILABLE_S:-180}" -export APT_DEPLOY_ENSURE=0 -# Prefer host wallet-cli install used by mon (find_wallet_cli / WALLET_CLI) -export PATH="${HOME}/.local/bin:${PATH:-}" -if [ -z "${WALLET_CLI:-}" ] && [ -f "${HOME}/.local/bin/taler-wallet-cli.mjs" ]; then - export WALLET_CLI="${HOME}/.local/bin/taler-wallet-cli.mjs" -fi - -exec bash "$AGENT_DIR/run-host-report.sh" "$@" diff --git a/host-agent/run-surface-monitoring.sh b/host-agent/run-surface-monitoring.sh index d634a7f..f9d5098 100755 --- a/host-agent/run-surface-monitoring.sh +++ b/host-agent/run-surface-monitoring.sh @@ -6,7 +6,7 @@ # https://taler.hacktivism.ch/taler-monitoring-surface_err/ # # This page covers remote ecosystem inventory: host/port probes, nmap OS -# fingerprint, Mattermost, mail (firefly + mail.anastasis.lu/pixel), package/version signals. +# fingerprint, Mattermost, mail (firefly + anastasis), package/version signals. # There are NO separate public pages for mail / mattermost (folded here). # Apt-src deploy tests keep their own page + timer: # run-aptdeploy-monitoring.sh → /taler-monitoring-aptdeploy(+_err)/ diff --git a/host-agent/taler-monitoring-max-ladder.service b/host-agent/taler-monitoring-max-ladder.service deleted file mode 100644 index 9943edb..0000000 --- a/host-agent/taler-monitoring-max-ladder.service +++ /dev/null @@ -1,19 +0,0 @@ -[Unit] -Description=Taler monitoring GOA max-search amount ladder → /monitoring-max-ladder/ -Documentation=file:%h/src/taler-monitoring/host-agent/README.md -After=network-online.target -Wants=network-online.target - -[Service] -Type=oneshot -Environment=PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin -Environment=CONTINUE_ON_ERROR=1 -Environment=RUN_TIMEOUT=10800 -EnvironmentFile=-%h/.config/taler-monitoring/env -WorkingDirectory=%h/src/taler-monitoring -ExecStart=%h/src/taler-monitoring/host-agent/run-max-ladder-monitoring.sh -Nice=10 -TimeoutStartSec=4h - -[Install] -WantedBy=default.target diff --git a/host-agent/taler-monitoring-max-ladder.timer b/host-agent/taler-monitoring-max-ladder.timer deleted file mode 100644 index 5b16361..0000000 --- a/host-agent/taler-monitoring-max-ladder.timer +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Daily GOA max-search amount ladder mon page -Documentation=file:%h/src/taler-monitoring/host-agent/README.md - -[Timer] -# Once per day, after classic ladder window -OnCalendar=*-*-* 06:30:00 -Persistent=true -AccuracySec=15min -RandomizedDelaySec=30min -Unit=taler-monitoring-max-ladder.service - -[Install] -WantedBy=timers.target diff --git a/host-agent/update-suite.sh b/host-agent/update-suite.sh index 9c5f3ea..e93aa11 100755 --- a/host-agent/update-suite.sh +++ b/host-agent/update-suite.sh @@ -8,8 +8,7 @@ # SUITE_GIT_URL default https://git.hacktivism.ch/hernani/taler-monitoring.git # SUITE_GIT_REF default main # SUITE_DIR default ~/src/taler-monitoring -# SUITE_UPDATE_MODE reset (default) | pull | keep -# keep = no fetch/reset (local deploy / unpushed fixes) +# SUITE_UPDATE_MODE reset (default) | pull # SUITE_UPDATE_STRICT 1 (default) = fetch/reset failure aborts the agent run # 0 = warn and continue on old tree (emergency only) # @@ -56,41 +55,29 @@ _before_ver=$(git describe --tags --exact-match 2>/dev/null \ || git describe --tags --abbrev=0 2>/dev/null \ || echo unknown) -case "$SUITE_UPDATE_MODE" in - keep|skip|off|none) - echo "suite update skipped (SUITE_UPDATE_MODE=$SUITE_UPDATE_MODE) — keep local tree ${_before} (${_before_ver})" - ;; - *) - echo "fetch origin ($SUITE_GIT_REF) + tags …" - if ! git fetch --tags --force --prune origin 2>&1; then - _upd_die "git fetch failed — suite would stay at ${_before} (${_before_ver})" - # fall through only if STRICT=0 - else - case "$SUITE_UPDATE_MODE" in - reset) - if ! git checkout -B "$SUITE_GIT_REF" "origin/$SUITE_GIT_REF" 2>/dev/null \ - && ! git checkout -B "$SUITE_GIT_REF" FETCH_HEAD; then - _upd_die "git checkout $SUITE_GIT_REF failed" - fi - if ! git reset --hard "origin/$SUITE_GIT_REF" 2>/dev/null \ - && ! git reset --hard FETCH_HEAD; then - _upd_die "git reset --hard origin/$SUITE_GIT_REF failed" - fi - ;; - pull) - if ! git pull --ff-only origin "$SUITE_GIT_REF" 2>&1; then - _upd_die "git pull --ff-only failed" - fi - ;; - *) - if ! git pull --ff-only origin "$SUITE_GIT_REF" 2>&1; then - _upd_die "git pull --ff-only failed (mode=$SUITE_UPDATE_MODE)" - fi - ;; - esac - fi - ;; -esac +echo "fetch origin ($SUITE_GIT_REF) + tags …" +if ! git fetch --tags --force --prune origin 2>&1; then + _upd_die "git fetch failed — suite would stay at ${_before} (${_before_ver})" + # fall through only if STRICT=0 +else + case "$SUITE_UPDATE_MODE" in + reset) + if ! git checkout -B "$SUITE_GIT_REF" "origin/$SUITE_GIT_REF" 2>/dev/null \ + && ! git checkout -B "$SUITE_GIT_REF" FETCH_HEAD; then + _upd_die "git checkout $SUITE_GIT_REF failed" + fi + if ! git reset --hard "origin/$SUITE_GIT_REF" 2>/dev/null \ + && ! git reset --hard FETCH_HEAD; then + _upd_die "git reset --hard origin/$SUITE_GIT_REF failed" + fi + ;; + *) + if ! git pull --ff-only origin "$SUITE_GIT_REF" 2>&1; then + _upd_die "git pull --ff-only failed" + fi + ;; + esac +fi COMMIT=$(git rev-parse HEAD) COMMIT_SHORT=$(git rev-parse --short=12 HEAD) @@ -142,12 +129,4 @@ fi ln -sfn "$SUITE_DIR" "$HOME/taler-monitoring" 2>/dev/null || true chmod +x taler-monitoring.sh check_*.sh host-agent/*.sh site-gen/*.sh site-gen/*.py 2>/dev/null || true -# Drop bytecode so a stale site-gen never wins over the tree we just reset to. -rm -rf "$SUITE_DIR/site-gen/__pycache__" 2>/dev/null || true -# Refuse known-bad pre-1.15.8 generator (box-drawing JS regex → SyntaxWarning noise) -if [ -f "$SUITE_DIR/site-gen/console_to_html.py" ] \ - && grep -qE 'if \(/\^\[[╔╗╚╝║═]' "$SUITE_DIR/site-gen/console_to_html.py" 2>/dev/null; then - _upd_die "site-gen/console_to_html.py still has pre-1.15.8 box-drawing JS regex — refuse stale generator" - return 1 2>/dev/null || exit 1 -fi return 0 2>/dev/null || true diff --git a/i18n.sh b/i18n.sh index 417a751..5ca1d18 100644 --- a/i18n.sh +++ b/i18n.sh @@ -1,202 +1,104 @@ #!/usr/bin/env bash -# i18n.sh — UI language + regional locale for taler-monitoring console + HTML +# i18n.sh — language for taler-monitoring console + HTML chrome # -# UI language (mon badges / sticky chrome): -# TALER_MON_LANG=en|fr|de -# TALER_MON_LANG_SET=1 → explicit (--lang); do not override. -# Auto (SET≠1): TALER_DOMAIN_LANG from domains.conf `lang` column. -# de is supported but never a stock profile default (no domains.conf row uses lang=de). -# -# Regional locale (l10n defaults, BCP 47 — not the same as UI lang): -# TALER_MON_LOCALE / TALER_DOMAIN_LOCALE e.g. fr-CH, de-CH -# From domains.conf `locale` column (fr-CH for FP, de-CH for others). -# Aliases ch-FR / ch-DE accepted and normalized to fr-CH / de-CH. -# -# domains.conf is the source of truth for both lang and locale. +# TALER_MON_LANG=en|fr (default en) +# Auto: domains *lefrancpaysan* → fr unless TALER_MON_LANG is set explicitly. : "${TALER_MON_LANG:=}" : "${TALER_MON_LANG_SET:=0}" -: "${TALER_DOMAIN_LANG:=}" -: "${TALER_DOMAIN_LOCALE:=}" -: "${TALER_MON_LOCALE:=}" i18n_init() { - # Only TALER_MON_LANG_SET=1 is "explicit". Do not promote non-empty TALER_MON_LANG - # to SET=1 — env files often ship LANG=en for the default GOA workstation. - if [ "${TALER_MON_LANG_SET:-0}" != "1" ]; then - if [ -n "${TALER_DOMAIN_LANG:-}" ]; then - TALER_MON_LANG="$TALER_DOMAIN_LANG" - else - case "${TALER_DOMAIN:-}" in - *lefrancpaysan*|*francpaysan*) - TALER_MON_LANG=fr - ;; - *) - if [ -z "${TALER_MON_LANG:-}" ]; then - TALER_MON_LANG=en - fi - ;; - esac - fi + if [ -n "${TALER_MON_LANG:-}" ]; then + TALER_MON_LANG_SET=1 + fi + if [ "${TALER_MON_LANG_SET}" != "1" ]; then + case "${TALER_DOMAIN:-}" in + *lefrancpaysan*|*francpaysan*) + TALER_MON_LANG=fr + ;; + *) + TALER_MON_LANG=en + ;; + esac fi case "${TALER_MON_LANG}" in fr|FR|fra|french) TALER_MON_LANG=fr ;; - de|DE|deu|ger|german|deutsch) TALER_MON_LANG=de ;; *) TALER_MON_LANG=en ;; esac - - # Regional locale from profile (or FP/other fallback) - if [ -n "${TALER_DOMAIN_LOCALE:-}" ]; then - TALER_MON_LOCALE="$TALER_DOMAIN_LOCALE" - elif [ -z "${TALER_MON_LOCALE:-}" ]; then - case "${TALER_DOMAIN:-}" in - *lefrancpaysan*|*francpaysan*) TALER_MON_LOCALE=fr-CH ;; - *) TALER_MON_LOCALE=de-CH ;; - esac - fi - # normalize aliases - case "$(printf '%s' "$TALER_MON_LOCALE" | tr '[:upper:]' '[:lower:]' | tr '_' '-')" in - fr-ch|ch-fr) TALER_MON_LOCALE=fr-CH ;; - de-ch|ch-de) TALER_MON_LOCALE=de-CH ;; - en-ch|ch-en) TALER_MON_LOCALE=en-CH ;; - esac - export TALER_MON_LANG - export TALER_MON_LANG_SET - export TALER_DOMAIN_LANG - export TALER_DOMAIN_LOCALE - export TALER_MON_LOCALE } i18n_tag() { local t="$1" - case "${TALER_MON_LANG:-en}" in - fr) - case "$t" in - OK) printf 'OK' ;; - ERROR) printf 'ERREUR' ;; - WARN) printf 'AVERT' ;; - INFO) printf 'INFO' ;; - BLOCKER) printf 'BLOCAGE' ;; - BLOCK) printf 'BLOC' ;; - SUMMARY) printf 'RESUME' ;; - PROG|PROGRESS) printf 'PROG' ;; - *) printf '%s' "$t" ;; - esac - ;; - de) - case "$t" in - OK) printf 'OK' ;; - ERROR) printf 'FEHLER' ;; - WARN) printf 'WARNUNG' ;; - INFO) printf 'INFO' ;; - BLOCKER) printf 'BLOCKER' ;; - BLOCK) printf 'BLOCK' ;; - SUMMARY) printf 'ZUSAMMENFASSUNG' ;; - PROG|PROGRESS) printf 'PROG' ;; - *) printf '%s' "$t" ;; - esac - ;; - *) - printf '%s' "$t" - ;; + if [ "${TALER_MON_LANG:-en}" != "fr" ]; then + printf '%s' "$t" + return 0 + fi + case "$t" in + OK) printf 'OK' ;; + ERROR) printf 'ERREUR' ;; + WARN) printf 'AVERT' ;; + INFO) printf 'INFO' ;; + BLOCKER) printf 'BLOCAGE' ;; + BLOCK) printf 'BLOC' ;; + SUMMARY) printf 'RESUME' ;; + PROG|PROGRESS) printf 'PROG' ;; + *) printf '%s' "$t" ;; esac } i18n_text() { local s="$*" - [ -z "$s" ] && { printf '%s' "$s"; return 0; } - case "${TALER_MON_LANG:-en}" in - fr) - case "$s" in - "numbered checks this run:") printf 'controles numerotes de cette execution :' ;; - "numbered checks:") printf 'controles numerotes :' ;; - "(global done/total)") printf '(fait/total global)' ;; - "global checks:") printf 'controles globaux :' ;; - "failed — see list above"|"failed - see list above") printf 'echec — voir la liste ci-dessus' ;; - "BLOCKERS · pay/withdraw cannot finish") printf 'BLOCAGES · paiement/retrait impossible' ;; - "BLOCKERS (pay/withdraw cannot finish)") printf 'BLOCAGES (paiement/retrait impossible)' ;; - "ERRORS · failed checks") printf 'ERREURS · controles en echec' ;; - "ERRORS (failed checks)") printf 'ERREURS (controles en echec)' ;; - "pay/withdraw cannot finish") printf 'paiement/retrait impossible a terminer' ;; - "SUMMARY") printf 'RESUME' ;; - "totals:") printf 'totaux :' ;; - "all clear") printf 'tout est clair' ;; - "warnings only (no hard fail)") printf 'avertissements seulement (pas d'\''echec dur)' ;; - "monitoring") printf 'surveillance' ;; - "surface") printf 'surface' ;; - "aptdeploy") printf 'aptdeploy' ;; - "container") printf 'conteneur' ;; - "disk") printf 'disque' ;; - "package") printf 'paquet' ;; - "version") printf 'version' ;; - "reachability") printf 'accessibilite' ;; - "server-header") printf 'en-tete Server' ;; - "inventory") printf 'inventaire' ;; - "flags") printf 'options' ;; - "target domain") printf 'domaine cible' ;; - "currency") printf 'devise' ;; - "phases") printf 'phases' ;; - "access") printf 'acces' ;; - *) - local out="$s" - out=${out//shared library missing/bibliotheque partagee manquante} - out=${out//not active/non actif} - out=${out//does not resolve/ne resout pas} - out=${out//from Server header/depuis en-tete Server} - out=${out//public HTTPS/HTTPS public} - out=${out//no SSH/sans SSH} - out=${out//failed — see list above/echec — voir la liste ci-dessus} - printf '%s' "$out" - ;; - esac - ;; - de) - case "$s" in - "numbered checks this run:") printf 'Nummerierte Pruefungen dieser Ausfuehrung :' ;; - "numbered checks:") printf 'Nummerierte Pruefungen :' ;; - "(global done/total)") printf '(fertig/gesamt global)' ;; - "global checks:") printf 'Globale Pruefungen :' ;; - "failed — see list above"|"failed - see list above") printf 'fehlgeschlagen — siehe Liste oben' ;; - "BLOCKERS · pay/withdraw cannot finish") printf 'BLOCKER · Zahlung/Abhebung nicht moeglich' ;; - "BLOCKERS (pay/withdraw cannot finish)") printf 'BLOCKER (Zahlung/Abhebung nicht moeglich)' ;; - "ERRORS · failed checks") printf 'FEHLER · fehlgeschlagene Pruefungen' ;; - "ERRORS (failed checks)") printf 'FEHLER (fehlgeschlagene Pruefungen)' ;; - "pay/withdraw cannot finish") printf 'Zahlung/Abhebung kann nicht beendet werden' ;; - "SUMMARY") printf 'ZUSAMMENFASSUNG' ;; - "totals:") printf 'Summen :' ;; - "all clear") printf 'alles in Ordnung' ;; - "warnings only (no hard fail)") printf 'nur Warnungen (kein harter Fehler)' ;; - "monitoring") printf 'Ueberwachung' ;; - "surface") printf 'Surface' ;; - "aptdeploy") printf 'aptdeploy' ;; - "container") printf 'Container' ;; - "disk") printf 'Disk' ;; - "package") printf 'Paket' ;; - "version") printf 'Version' ;; - "reachability") printf 'Erreichbarkeit' ;; - "server-header") printf 'Server-Header' ;; - "inventory") printf 'Inventar' ;; - "flags") printf 'Flags' ;; - "target domain") printf 'Zieldomaene' ;; - "currency") printf 'Waehrung' ;; - "phases") printf 'Phasen' ;; - "access") printf 'Zugang' ;; - *) - local outd="$s" - outd=${outd//shared library missing/gemeinsame Bibliothek fehlt} - outd=${outd//not active/nicht aktiv} - outd=${outd//does not resolve/loest nicht auf} - outd=${outd//from Server header/aus Server-Header} - outd=${outd//public HTTPS/oeffentliches HTTPS} - outd=${outd//no SSH/ohne SSH} - outd=${outd//failed — see list above/fehlgeschlagen — siehe Liste oben} - printf '%s' "$outd" - ;; - esac - ;; + if [ "${TALER_MON_LANG:-en}" != "fr" ] || [ -z "$s" ]; then + printf '%s' "$s" + return 0 + fi + case "$s" in + "numbered checks this run:") printf 'controles numerotes de cette execution :' ;; + "numbered checks:") printf 'controles numerotes :' ;; + "(global done/total)") printf '(fait/total global)' ;; + "global checks:") printf 'controles globaux :' ;; + "failed — see list above"|"failed - see list above") printf 'echec — voir la liste ci-dessus' ;; + "BLOCKERS · pay/withdraw cannot finish") printf 'BLOCAGES · paiement/retrait impossible' ;; + "BLOCKERS (pay/withdraw cannot finish)") printf 'BLOCAGES (paiement/retrait impossible)' ;; + "ERRORS · failed checks") printf 'ERREURS · controles en echec' ;; + "ERRORS (failed checks)") printf 'ERREURS (controles en echec)' ;; + "pay/withdraw cannot finish") printf 'paiement/retrait impossible a terminer' ;; + "SUMMARY") printf 'RESUME' ;; + "totals:") printf 'totaux :' ;; + "container") printf 'conteneur' ;; + "disk") printf 'disque' ;; + "package") printf 'paquet' ;; + "version") printf 'version' ;; + "reachability") printf 'accessibilite' ;; + "server-header") printf 'en-tete Server' ;; + "inventory") printf 'inventaire' ;; + "flags") printf 'options' ;; + "target domain") printf 'domaine cible' ;; + "currency") printf 'devise' ;; + "phases") printf 'phases' ;; + "access") printf 'acces' ;; *) - printf '%s' "$s" + local out="$s" + out=${out//shared library missing/bibliotheque partagee manquante} + out=${out//shared library error/erreur de bibliotheque partagee} + out=${out//not active/non actif} + out=${out//after_start/apres_demarrage} + out=${out//catalogued but not reachable/catalogue mais inaccessible} + out=${out//does not resolve/ne resout pas} + out=${out//protocol confirmed/protocole confirme} + out=${out//catalogued service OK/service catalogue OK} + out=${out//from Server header/depuis en-tete Server} + out=${out//OSV clean/OSV sans vulnerabilite} + out=${out//actionable vuln/vuln. actionnable} + out=${out//header version · not Debian pkg/version en-tete · pas paquet Debian} + out=${out//RUN_TIMEOUT exceeded/RUN_TIMEOUT depasse} + out=${out//public HTTPS/HTTPS public} + out=${out//container status/etat du conteneur} + out=${out//remote-only/uniquement distant} + out=${out//no SSH/sans SSH} + out=${out//failed — see list above/echec — voir la liste ci-dessus} + printf '%s' "$out" ;; esac } diff --git a/ladder/README.md b/ladder/README.md deleted file mode 100644 index 3c6e826..0000000 --- a/ladder/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# Amount ladder modules - -**Entry:** `../check_amount_ladder.sh` via: - -```bash -./taler-monitoring.sh ladder # classic 23-rung withdraw + pay -./taler-monitoring.sh max-ladder # max-search withdraw + pay -./taler-monitoring.sh goa-ladder # legacy phase name = classic ladder -``` - -| Path | Role | -|------|------| -| `../check_amount_ladder.sh` | Orchestrator: classic / max **withdraw**, then pay phase | -| `lib_pay.sh` | **Pay** module: free-amount template, classic pay list, max **payable** ≤ available | -| `extract_rpubs.py` | Force-select: scrape `reservePub` from wallet dumps | - -There is **no** `check_goa_ladder.sh` — removed; use the phases above. - -## Modes - -- **classic** (default): 23-rung withdraw 0→mids→max-1→max, then matching pay plan (never overspend). -- **max** (`max-ladder`): adaptive max withdraw, then adaptive max pay via public free template (hacktivism: `goa-free`). - -## Env (pay) - -| Variable | Default | Meaning | -|----------|---------|---------| -| `LADDER_PAY` | `1` | `0` = skip all pays | -| `LADDER_USE_FREE_TEMPLATE` | `1` | public POST template with `{"amount":…}` | -| `LADDER_FREE_TEMPLATE` | `goa-free` | template id (hacktivism) | -| `LADDER_FREE_TEMPLATE_INSTANCE` | merchant instance | e.g. `goa-demo-cp4zqk` | -| `LADDER_PAY_WAIT_AVAILABLE_S` | `90` | after withdraw, wait for spendable **available**>0; logs **withdraw board in start order** (OK/OK_BANK) with live `pendingIncoming`→`done` + timer (same wallet DB) | diff --git a/ladder/extract_rpubs.py b/ladder/extract_rpubs.py deleted file mode 100755 index 1c939e9..0000000 --- a/ladder/extract_rpubs.py +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env python3 -"""Extract reserve_pub candidates from wallet accept + transactions dumps. - -Used by check_amount_ladder.sh force-select. Kept as a file (not a bash -heredoc) so shell refactors cannot turn Python ``continue`` into ``return``. - -Usage: - ladder_extract_rpubs.py WID AMT accept.out tx.json used-rpubs.txt -Prints one reserve pub per line, preferred first. -""" -from __future__ import annotations - -import json -import re -import sys -from pathlib import Path - - -def main(argv: list[str]) -> int: - if len(argv) < 6: - print( - "usage: ladder_extract_rpubs.py WID AMT accept.out tx.json used-rpubs.txt", - file=sys.stderr, - ) - return 2 - - wid = argv[1] - amt = argv[2] - paths = argv[3:5] - used_path = argv[5] - used: set[str] = set() - if Path(used_path).is_file(): - used = {ln.strip() for ln in open(used_path) if ln.strip()} - - amt_num = amt.split(":", 1)[-1] if amt else "" - dec = json.JSONDecoder() - - def walk_collect(o, bag, ctx=None): - ctx = dict(ctx or {}) - if isinstance(o, dict): - for k, v in o.items(): - if not isinstance(v, str): - continue - kl = str(k).lower().replace("-", "_") - if kl in ( - "withdrawal_id", - "withdraw_id", - "wopid", - "id", - "transactionid", - "transaction_id", - ): - ctx["id"] = v - elif kl in ( - "amount", - "rawamount", - "instructedamount", - "amounteffective", - "amountraw", - "transferamount", - ): - ctx["amount"] = v - elif kl in ( - "taler_withdraw_uri", - "talerwithdrawuri", - "uri", - "bankconfirmationurl", - "confirmtransferurl", - ): - ctx["uri"] = v - for k, v in o.items(): - kl = str(k).lower().replace("-", "_") - if kl in ("reserve_pub", "reservepub") and isinstance(v, str) and len(v) >= 40: - bag.append((v, dict(ctx))) - elif not isinstance(v, (str, int, float, bool)) and v is not None: - walk_collect(v, bag, ctx) - elif isinstance(o, list): - for i in o: - walk_collect(i, bag, ctx) - - def score_ctx(pub, ctx, window=""): - score = 0 - cid = str(ctx.get("id") or "") - camt = str(ctx.get("amount") or "") - curi = str(ctx.get("uri") or "") - if wid and wid in curi: - score += 120 - if wid and wid in cid: - score += 100 - if wid and wid in window: - score += 80 - if amt and (camt == amt or camt.endswith(amt_num)): - score += 50 - if amt and amt in window: - score += 30 - if pub in used: - score -= 200 - return score - - def iter_json_objects(text: str): - i, n = 0, len(text) - while i < n: - if text[i] == "{": - try: - o, end = dec.raw_decode(text, i) - yield o - i = end - continue - except Exception: - pass - i += 1 - - raw_pubs: list[str] = [] - scored: list[tuple[int, str]] = [] - - for p in paths: - try: - t = open(p, errors="replace").read() - except Exception: - continue - for o in iter_json_objects(t): - bag = [] - walk_collect(o, bag) - for pub, ctx in bag: - raw_pubs.append(pub) - scored.append((score_ctx(pub, ctx), pub)) - - rpub_pats = ( - r"\"reservePub\"\s*:\s*\"([A-Z0-9]{40,})\"", - r"\"reserve_pub\"\s*:\s*\"([A-Z0-9]{40,})\"", - r"reserve[_ ]?pub[\"\s:=]+([A-Z0-9]{40,})", - ) - for p in paths: - try: - blob = open(p, errors="replace").read() - except Exception: - continue - for pat in rpub_pats: - for m in re.finditer(pat, blob, re.I): - pub = m.group(1) - raw_pubs.append(pub) - window = blob[max(0, m.start() - 600) : m.end() + 600] - scored.append((score_ctx(pub, {}, window) + 10, pub)) - - order: list[str] = [] - seen: set[str] = set() - for score, pub in sorted(scored, key=lambda x: x[0], reverse=True): - if pub in seen or pub in used: - continue - seen.add(pub) - order.append(pub) - for pub in reversed(raw_pubs): - if pub in seen or pub in used: - continue - seen.add(pub) - order.append(pub) - for pub in order: - print(pub) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main(sys.argv)) diff --git a/ladder/lib_pay.sh b/ladder/lib_pay.sh deleted file mode 100644 index 01ba819..0000000 --- a/ladder/lib_pay.sh +++ /dev/null @@ -1,559 +0,0 @@ -# ladder/lib_pay.sh — payment side of amount ladder (sourced by check_amount_ladder.sh) -# Expects: lib.sh + metrics.sh already sourced; CUR BANK MER INST EX SCRATCH WDB -# wcli wallet_avail format_amount_alt ladder_over now_ms elapsed_ms -# LADDER_* env, AUTH optional, PAY_TSV PAY_OK_N PAY_FAIL_N -# -# Public free-amount template (hacktivism): goa-free @ goa-demo-cp4zqk -# Never spends more than wallet available. - -: "${LADDER_FREE_TEMPLATE:=goa-free}" -: "${LADDER_FREE_TEMPLATE_INSTANCE:=}" -: "${LADDER_USE_FREE_TEMPLATE:=1}" -: "${LADDER_PAY_WAIT_AVAILABLE_S:=180}" -: "${LADDER_PAY_SETTLE_ROUNDS:=6}" - -MAX_PAY_BEST_AMT="${MAX_PAY_BEST_AMT:-}" -MAX_PAY_LO="${MAX_PAY_LO:-0}" -MAX_PAY_HI="${MAX_PAY_HI:-0}" - -ladder_pay_resolve_merchant() { - # Sets AUTH (may be empty if free template only) - MPW="${E2E_MERCHANT_TOKEN:-${MERCHANT_TOKEN:-}}" - if [ -z "$MPW" ]; then - MPW=$(read_secret "taler-merchant/merchant-${INST}-password.txt" 2>/dev/null || true) - fi - if [ -z "$MPW" ]; then - MPW=$(read_secret "taler-merchant/merchant-goa-demo-cp4zqk-password.txt" 2>/dev/null || true) - fi - if [ -z "$MPW" ] && [ "${CUR}" = "TESTPAYSAN" ]; then - if [ -n "${FRANCPAYSAN_SECRETS:-}" ] && [ -f "${FRANCPAYSAN_SECRETS}/stage/default-instance-token.txt" ]; then - MPW=$(tr -d '\n\r' <"${FRANCPAYSAN_SECRETS}/stage/default-instance-token.txt") - fi - fi - AUTH="" - if [ -n "$MPW" ]; then - case "$MPW" in - secret-token:*) AUTH="Authorization: Bearer ${MPW}" ;; - *) AUTH="Authorization: Bearer secret-token:${MPW}" ;; - esac - fi - : "${LADDER_FREE_TEMPLATE_INSTANCE:=${INST}}" -} - -# Create order for PAMT → OID OTOK PAYURI. Prefers public free template. -ladder_create_order() { - local pamt="$1" ptag="$2" - local inst mh body tpl_https sum_json - OID=""; OTOK=""; PAYURI="" - inst="${LADDER_FREE_TEMPLATE_INSTANCE:-$INST}" - mh=$(python3 -c 'from urllib.parse import urlparse; print(urlparse("'"${MER}"'").hostname or "taler.hacktivism.ch")' 2>/dev/null || echo "taler.hacktivism.ch") - - if [ "${LADDER_USE_FREE_TEMPLATE}" = "1" ] && [ -n "${LADDER_FREE_TEMPLATE:-}" ]; then - tpl_https="${MER}/instances/${inst}/templates/${LADDER_FREE_TEMPLATE}" - body=$(python3 -c 'import json,sys; print(json.dumps({"amount":sys.argv[1]}))' "$pamt" 2>/dev/null || printf '{"amount":"%s"}' "$pamt") - curl -skS -m 20 -o "$SCRATCH/ord-$ptag.json" -X POST \ - -H 'Content-Type: application/json' \ - -d "$body" \ - "$tpl_https" 2>"$SCRATCH/ord-$ptag.err" || true - OID=$(python3 -c 'import json,re,sys;t=open(sys.argv[1]).read() -try: print(json.loads(t).get("order_id") or "") -except Exception: - m=re.search(r"\"order_id\"\s*:\s*\"([^\"]+)\"",t); print(m.group(1) if m else "") -' "$SCRATCH/ord-$ptag.json" 2>/dev/null || true) - OTOK=$(python3 -c 'import json,re,sys;t=open(sys.argv[1]).read() -try: print(json.loads(t).get("token") or "") -except Exception: - m=re.search(r"\"token\"\s*:\s*\"([^\"]+)\"",t); print(m.group(1) if m else "") -' "$SCRATCH/ord-$ptag.json" 2>/dev/null || true) - if [ -n "$OID" ] && [ -n "$OTOK" ]; then - PAYURI="taler://pay/${mh}/instances/${inst}/${OID}/?c=${OTOK}" - PAYURI=$(normalize_taler_uri "$PAYURI") - return 0 - fi - fi - - [ -n "${AUTH:-}" ] || return 1 - sum_json=$(python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "ladder pay ${pamt}" 2>/dev/null || echo '"ladder pay"') - curl -skS -m 20 -o "$SCRATCH/ord-$ptag.json" -X POST \ - -H "$AUTH" -H 'Content-Type: application/json' \ - -d "{\"order\":{\"summary\":${sum_json},\"amount\":\"${pamt}\",\"fulfillment_message\":\"ok\"},\"create_token\":true}" \ - "${MER}/instances/${INST}/private/orders" 2>"$SCRATCH/ord-$ptag.err" || true - OID=$(python3 -c 'import json,re,sys;t=open(sys.argv[1]).read() -try: print(json.loads(t).get("order_id") or "") -except Exception: - m=re.search(r"\"order_id\"\s*:\s*\"([^\"]+)\"",t); print(m.group(1) if m else "") -' "$SCRATCH/ord-$ptag.json" 2>/dev/null || true) - OTOK=$(python3 -c 'import json,re,sys;t=open(sys.argv[1]).read() -try: print(json.loads(t).get("token") or "") -except Exception: - m=re.search(r"\"token\"\s*:\s*\"([^\"]+)\"",t); print(m.group(1) if m else "") -' "$SCRATCH/ord-$ptag.json" 2>/dev/null || true) - [ -n "$OID" ] || return 1 - curl -skS -m 12 -o "$SCRATCH/ord-det-$ptag.json" -H "$AUTH" \ - "${MER}/instances/${INST}/private/orders/${OID}" 2>/dev/null || true - PAYURI=$(python3 -c 'import json,sys -try: print(json.load(open(sys.argv[1])).get("taler_pay_uri") or "") -except Exception: print("") -' "$SCRATCH/ord-det-$ptag.json" 2>/dev/null || true) - if [ -z "$PAYURI" ] && [ -n "$OTOK" ]; then - PAYURI="taler://pay/${mh}/instances/${INST}/${OID}/?c=${OTOK}" - fi - PAYURI=$(normalize_taler_uri "$PAYURI") - [ -n "$PAYURI" ] -} - -# One pay attempt; never overspends. Always soft (no hard ladder stop). -ladder_pay_attempt() { - local pamt="$1" prange="$2" prung="$3" - local ptag pnum bal t_pay t0 ms_order ms_handle ms_psettle after settled r pstatus pnote - ptag=$(printf '%s' "$pamt" | tr '.:' '__') - pnum=$(python3 -c 'import sys; print(sys.argv[1].split(":",1)[-1])' "$pamt") - t_pay=$(now_ms) - ms_order=0; ms_handle=0; ms_psettle=0 - pnote=""; pstatus="FAIL"; OID="-" - - bal=$(wallet_avail) - if ! python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])>0 and Decimal(sys.argv[1])>=Decimal(sys.argv[2]) else 1)' "$bal" "$pnum" 2>/dev/null; then - pstatus="SKIP_BALANCE" - pnote="skip: would spend more than available avail=${CUR}:${bal} need=${pamt}" - warn pay "pay $pamt skipped (balance)" \ - "problem: never overspend. $(format_amount_alt "${CUR}:${bal}") free vs $(format_amount_alt "$pamt")" - echo -e "${prung}\t${prange}\t${pamt}\t${pstatus}\t0\t0\t0\t$(elapsed_ms "$t_pay")\t-\t${pnote}" >>"$PAY_TSV" - return 0 - fi - - t0=$(now_ms) - if ! ladder_create_order "$pamt" "$ptag"; then - ms_order=$(elapsed_ms "$t0") - pstatus="FAIL_ORDER" - pnote="order create failed $(head -c 100 "$SCRATCH/ord-$ptag.json" 2>/dev/null | tr '\n\"' ' ')" - warn pay "order $pamt" "$pnote" - echo -e "${prung}\t${prange}\t${pamt}\t${pstatus}\t${ms_order}\t0\t0\t$(elapsed_ms "$t_pay")\t-\t${pnote}" >>"$PAY_TSV" - return 0 - fi - ms_order=$(elapsed_ms "$t0") - ok "order $OID ($pamt) ${ms_order}ms · $(format_amount_alt "$pamt")" - - t0=$(now_ms) - if ! wcli handle-uri --yes "$PAYURI" >"$SCRATCH/pay-$ptag.out" 2>&1; then - ms_handle=$(elapsed_ms "$t0") - pstatus="FAIL_HANDLE" - pnote="handle-uri failed $(tail -c 100 "$SCRATCH/pay-$ptag.out" | tr '\n\"' ' ')" - warn pay "handle $pamt" "$pnote" - echo -e "${prung}\t${prange}\t${pamt}\t${pstatus}\t${ms_order}\t${ms_handle}\t0\t$(elapsed_ms "$t_pay")\t${OID}\t${pnote}" >>"$PAY_TSV" - return 0 - fi - ms_handle=$(elapsed_ms "$t0") - ok "handle-uri $pamt ${ms_handle}ms" - - t0=$(now_ms) - settled=0 - r=0 - while [ "$r" -lt "${LADDER_PAY_SETTLE_ROUNDS}" ]; do - r=$((r + 1)) - wcli transactions >"$SCRATCH/tx-pay-$ptag.out" 2>&1 || true - if [ -n "${AUTH:-}" ]; then - curl -skS -m 8 -o "$SCRATCH/ord-paid-$ptag.json" -H "$AUTH" \ - "${MER}/instances/${INST}/private/orders/${OID}" 2>/dev/null || true - fi - if grep -qiE 'payment|paid|Payment' "$SCRATCH/tx-pay-$ptag.out" 2>/dev/null \ - || python3 -c 'import json,sys -try: - d=json.load(open(sys.argv[1])) - sys.exit(0 if d.get("paid") is True or str(d.get("order_status","")).lower()=="paid" else 1) -except Exception: - sys.exit(1) -' "$SCRATCH/ord-paid-$ptag.json" 2>/dev/null; then - settled=1 - break - fi - sleep 0.5 - done - ms_psettle=$(elapsed_ms "$t0") - after=$(wallet_avail) - if [ "$settled" = "1" ]; then - pstatus="OK" - pnote="avail=${CUR}:${after}" - ok "pay settled $pamt · $(format_amount_alt "$pamt") → bal ${CUR}:${after}" - PAY_OK_N=$((PAY_OK_N + 1)) - echo -e "${prung}\t${prange}\t${pamt}\t${pstatus}\t${ms_order}\t${ms_handle}\t${ms_psettle}\t$(elapsed_ms "$t_pay")\t${OID}\t${pnote}" >>"$PAY_TSV" - metrics_report_coins "after-pay-${ptag}" || true - metrics_record_flow spent "$pamt" || true - else - pstatus="FAIL_SETTLE" - pnote="not settled order=$OID avail=${CUR}:${after}" - warn pay "settle $pamt" "$pnote" - echo -e "${prung}\t${prange}\t${pamt}\t${pstatus}\t${ms_order}\t${ms_handle}\t${ms_psettle}\t$(elapsed_ms "$t_pay")\t${OID}\t${pnote}" >>"$PAY_TSV" - fi - return 0 -} - -# Print withdraw board: OK/OK_BANK rungs in *start order* + wallet tx state. -# Uses TSV (ladder order) + transactions dump. Call after refreshing tx dump. -# Args: left_secs available_num pendingIncoming_num -ladder_print_wd_board() { - local left="${1:-?}" bal="${2:-0}" pend="${3:-0}" - local tsv="${TSV:-}" txf="${SCRATCH:-/tmp}/tx-wait-pay.out" - local board - board=$( - python3 - "$tsv" "$txf" "${CUR:-GOA}" "$left" "$bal" "$pend" <<'PY' 2>/dev/null || true -import json, sys -from pathlib import Path - -tsv, txf, cur, left, bal, pend = sys.argv[1:7] -dec = json.JSONDecoder() - -def num(a: str) -> str: - a = (a or "").strip() - if ":" in a: - return a.split(":", 1)[1] - return a - -def iter_json(text: str): - i, n = 0, len(text) - while i < n: - if text[i] == "{": - try: - o, end = dec.raw_decode(text, i) - yield o - i = end - continue - except Exception: - pass - i += 1 - -# TSV rows in start order (OK / OK_BANK only — successful bank path) -rows = [] -if tsv and Path(tsv).is_file(): - for ln in open(tsv, errors="replace"): - if not ln.strip() or ln.startswith("rung"): - continue - p = ln.rstrip("\n").split("\t") - if len(p) < 10: - continue - status = p[3] - if status not in ("OK", "OK_BANK"): - continue - rows.append({ - "rung": p[0], - "amt": p[2], - "bank": status, - "wid": (p[9] if len(p) > 9 else "")[:12], - }) - -# Wallet withdrawal txs (chronological if timestamp present) -wds = [] -if txf and Path(txf).is_file(): - try: - text = open(txf, errors="replace").read() - except Exception: - text = "" - for o in iter_json(text): - txs = o.get("transactions") if isinstance(o, dict) else None - if not isinstance(txs, list): - continue - for t in txs: - if not isinstance(t, dict): - continue - typ = str(t.get("type") or t.get("Type") or "").lower() - if "withdraw" not in typ: - continue - amt = t.get("amountRaw") or t.get("amountEffective") or t.get("amount") or "" - st = ( - t.get("txState") - or t.get("status") - or t.get("pendingMajor") - or t.get("txMajorState") - or "" - ) - st = str(st).lower() - det = t.get("withdrawalDetails") or t.get("withdrawal_details") or {} - if not isinstance(det, dict): - det = {} - conf = det.get("confirmed") - if conf is True and not st: - st = "done" - elif conf is False and not st: - st = "pending" - # pending* / dialog / kyc → still incoming; done/abort final - if any(x in st for x in ("done", "abort", "fail", "delete")): - phase = "done" if "done" in st else st - elif st in ("", "none", "null"): - phase = "unknown" - else: - phase = "pendingIncoming" - ts = 0 - for k in ("timestamp", "timestamp_ms", "age"): - v = t.get(k) - if isinstance(v, dict): - v = v.get("t_s") or v.get("t_ms") or v.get("t_usec") - try: - ts = int(v or 0) - except Exception: - ts = 0 - if ts: - break - wds.append({"amt": str(amt), "n": num(str(amt)), "phase": phase, "st": st or "?", "ts": ts}) - -wds.sort(key=lambda x: x["ts"]) -used = [False] * len(wds) - -lines = [ - f"withdraw board (start order) · timer {left}s left · available={cur}:{bal} · pendingIncoming={cur}:{pend}" -] -if not rows: - lines.append(" (no OK/OK_BANK rows in TSV yet)") -else: - for i, r in enumerate(rows, 1): - n = num(r["amt"]) - match = None - for j, w in enumerate(wds): - if used[j]: - continue - if w["n"] == n or w["amt"] == r["amt"] or w["amt"].endswith(":" + n): - used[j] = True - match = w - break - if match is None: - wlabel = "wallet=? (no tx match)" - elif match["phase"] == "pendingIncoming": - wlabel = f"wallet=pendingIncoming ({match['st']})" - elif match["phase"] == "done": - wlabel = f"wallet=done ({match['st']})" - else: - wlabel = f"wallet={match['phase']} ({match['st']})" - wid = r["wid"] or "-" - lines.append( - f" #{i:<3} rung={r['rung']:<4} {r['amt']:<22} bank={r['bank']:<8} {wlabel} wid={wid}" - ) - pending_n = sum(1 for w in wds if w["phase"] == "pendingIncoming") - done_n = sum(1 for w in wds if w["phase"] == "done") - lines.append( - f" summary: tsv_ok={len(rows)} · wallet_wd={len(wds)} (pendingIncoming={pending_n} done={done_n})" - ) - -print("\n".join(lines)) -PY - ) - if [ -n "$board" ]; then - while IFS= read -r line || [ -n "$line" ]; do - [ -n "$line" ] && info pay "$line" - done <<<"$board" - else - info pay "timer ${left}s left · available=${CUR}:${bal} · pendingIncoming=${CUR}:${pend} · same wallet (board n/a)" - fi -} - -# Wait for spendable coins on the *same* wallet DB as withdraw (WDB). -# After OK_BANK, available is often still 0 while pendingIncoming > 0 — pay needs available. -# Shows withdraw board in start order + countdown (never looks hung). -ladder_wait_available() { - local wait_s="${1:-$LADDER_PAY_WAIT_AVAILABLE_S}" - local end now left bal pend tick=0 - end=$(( $(date +%s) + wait_s )) - bal=$(wallet_avail) - pend=$(wallet_pending_in 2>/dev/null || echo "0") - if python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])>0 else 1)' "$bal" 2>/dev/null; then - printf '%s' "$bal" - return 0 - fi - info pay "same wallet as withdraw (db=$(basename "${WDB:-wallet}")) · available=${CUR}:${bal} · pendingIncoming=${CUR}:${pend}" - info pay "waiting up to ${wait_s}s for spendable available>0 — board lists OK/OK_BANK withdraws in start order" - # initial board before loop - wcli transactions >"$SCRATCH/tx-wait-pay.out" 2>&1 || true - ladder_print_wd_board "$wait_s" "$bal" "$pend" - while python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])<=0 else 1)' "$bal" 2>/dev/null; do - now=$(date +%s) - left=$(( end - now )) - if [ "$left" -le 0 ]; then - wcli transactions >"$SCRATCH/tx-wait-pay.out" 2>&1 || true - ladder_print_wd_board "0" "$bal" "$pend" - info pay "timer 0s left — stop waiting (available still ${CUR}:0)" - break - fi - # nudge wallet (same DB); do not run-until-done (can hang) - wcli transactions >"$SCRATCH/tx-wait-pay.out" 2>&1 || true - if command -v timeout >/dev/null 2>&1 || command -v gtimeout >/dev/null 2>&1; then - local _to - _to=$(command -v gtimeout 2>/dev/null || command -v timeout) - "$_to" 8 wcli advanced run-pending >"$SCRATCH/run-pending.out" 2>&1 || true - fi - # progress board every ~5s (tick every 2s → every 3rd) - if [ $((tick % 3)) -eq 0 ]; then - ladder_print_wd_board "$left" "$bal" "$pend" - fi - sleep 2 - tick=$((tick + 1)) - bal=$(wallet_avail) - pend=$(wallet_pending_in 2>/dev/null || echo "0") - done - if python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])>0 else 1)' "$bal" 2>/dev/null; then - wcli transactions >"$SCRATCH/tx-wait-pay.out" 2>&1 || true - ladder_print_wd_board "ready" "$bal" "$pend" - ok pay "spendable coins ready available=${CUR}:${bal} · $(format_amount_alt "${CUR}:${bal}") (same wallet)" - else - warn pay "no spendable coins after ${wait_s}s" \ - "problem: available still ${CUR}:0 (pendingIncoming=${CUR}:${pend}). Board above shows which withdraws still pendingIncoming. Pay will SKIP_BALANCE / skip max-pay until wirewatch+wallet finish. Same wallet as withdraw." - fi - printf '%s' "$bal" -} - -# Classic planned pays (PAY_LIST) -ladder_run_pay_classic() { - # shellcheck disable=SC2086 - set -- $PAY_LIST - local pay_n=$# prung=0 PAMT prange PNUM - if [ "$pay_n" -eq 0 ]; then - info pay "empty pay plan — skip" - return 0 - fi - info "pay rungs" "$pay_n · $*" - for PAMT in "$@"; do - prung=$((prung + 1)) - ladder_over && break - if [ "$prung" -eq 1 ]; then - prange="pin:0" - elif [ "$prung" -eq "$pay_n" ]; then - prange="pin:max" - elif [ "$prung" -eq $((pay_n - 1)) ] && [ "$pay_n" -ge 3 ]; then - prange="pin:max-1" - else - prange="random" - fi - section "ladder · pay rung $prung $PAMT · $(format_amount_alt "$PAMT")" - PNUM=$(python3 -c 'import sys; print(sys.argv[1].split(":",1)[-1])' "$PAMT") - if python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])==0 else 1)' "$PNUM" 2>/dev/null; then - echo -e "${prung}\t${prange}\t${PAMT}\tZERO_SKIP\t0\t0\t0\t0\t-\tzero" >>"$PAY_TSV" - PAY_OK_N=$((PAY_OK_N + 1)) - continue - fi - ladder_pay_attempt "$PAMT" "$prange" "$prung" - done -} - -# Max-search: highest payable ≤ available (uses max_search_next from withdraw module) -ladder_run_pay_max_search() { - local bal prung _next _anum prange _act _last _slo _shi - section "ladder · phase B · max-search pay (highest payable ≤ available)" - bal=$(ladder_wait_available "$LADDER_PAY_WAIT_AVAILABLE_S") - MAX_PAY_LO="0" - MAX_PAY_HI="$bal" - MAX_PAY_BEST_AMT="" - if ! python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])>0 else 1)' "$MAX_PAY_HI" 2>/dev/null; then - warn pay "max-search pay skipped" \ - "problem: wallet available is ${CUR}:0 — need spendable coins (pendingIncoming is not enough)" - return 0 - fi - info "max-search pay" "hi=available $(format_amount_alt "${CUR}:${MAX_PAY_HI}") · template=${LADDER_FREE_TEMPLATE}@${LADDER_FREE_TEMPLATE_INSTANCE}" - info "pay budget" "never order more than $(format_amount_alt "${CUR}:${MAX_PAY_HI}")" - prung=0 - _last="" - while [ "${LADDER_MAX_PROBES}" = "0" ] || [ "$prung" -lt "${LADDER_MAX_PROBES}" ]; do - ladder_over && break - # reuse withdraw amount picker with pay bounds - _slo=${MAX_LO:-0}; _shi=${MAX_HI:-0} - MAX_LO=$MAX_PAY_LO - MAX_HI=$MAX_PAY_HI - if ! type max_search_next >/dev/null 2>&1; then - warn pay "max_search_next missing — cannot run pay max-search" - MAX_LO=$_slo; MAX_HI=$_shi - return 0 - fi - _next=$(max_search_next) - MAX_LO=$_slo; MAX_HI=$_shi - _anum=$(printf '%s' "$_next" | cut -d'|' -f1) - prange=$(printf '%s' "$_next" | cut -d'|' -f2 | sed 's/^max:/pay:/') - _act=$(printf '%s' "$_next" | cut -d'|' -f3) - if [ "$_act" = "done" ]; then - info "max-search pay" "converged best=$(format_amount_alt "${MAX_PAY_BEST_AMT:-${CUR}:0}") · lo=$(format_amount_alt "${CUR}:${MAX_PAY_LO}") · hi=$(format_amount_alt "${CUR}:${MAX_PAY_HI}")" - break - fi - if ! python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])<=Decimal(sys.argv[2]) else 1)' "$_anum" "$MAX_PAY_HI" 2>/dev/null; then - _anum=$MAX_PAY_HI - fi - if ! python3 -c 'import sys; from decimal import Decimal; sys.exit(0 if Decimal(sys.argv[1])>0 else 1)' "$_anum" 2>/dev/null; then - break - fi - PAMT="${CUR}:${_anum}" - if [ -n "$_last" ] && [ "$PAMT" = "$_last" ]; then - MAX_PAY_HI=$(python3 -c 'from decimal import Decimal; a=Decimal("'"$_anum"'"); print(max(Decimal(0), a-(1 if a>=1 else Decimal("0.000001"))))') - continue - fi - _last=$PAMT - prung=$((prung + 1)) - section "ladder · max pay probe $prung $PAMT · $(format_amount_alt "$PAMT") [lo=$(format_amount_alt "${CUR}:${MAX_PAY_LO}") · hi=$(format_amount_alt "${CUR}:${MAX_PAY_HI}")]" - ladder_pay_attempt "$PAMT" "$prange" "$prung" - _last_st=$(tail -1 "$PAY_TSV" 2>/dev/null | cut -f4) - case "$_last_st" in - OK) - MAX_PAY_LO=$_anum - MAX_PAY_BEST_AMT=$PAMT - info "max-search pay" "success bound lo=$(format_amount_alt "${CUR}:${MAX_PAY_LO}")" - ;; - SKIP_BALANCE|FAIL_ORDER|FAIL_HANDLE|FAIL_SETTLE) - MAX_PAY_HI=$(python3 -c 'from decimal import Decimal; a=Decimal("'"$_anum"'"); h=Decimal("'"$MAX_PAY_HI"'"); print(min(a,h))') - info "max-search pay" "too-high/fail hi:=$(format_amount_alt "${CUR}:${MAX_PAY_HI}") status=${_last_st}" - ;; - esac - if python3 -c 'from decimal import Decimal; import sys; sys.exit(0 if Decimal(sys.argv[1])>0 and Decimal(sys.argv[2])<=Decimal(sys.argv[1]) else 1)' "$MAX_PAY_LO" "$MAX_PAY_HI" 2>/dev/null; then - info "max-search pay" "bounds crossed — stop" - break - fi - done - if [ -n "${MAX_PAY_BEST_AMT:-}" ]; then - ok "max-search best payable $(format_amount_alt "$MAX_PAY_BEST_AMT") · lo=$(format_amount_alt "${CUR}:${MAX_PAY_LO}") · hi=$(format_amount_alt "${CUR}:${MAX_PAY_HI}")" - else - warn pay "max-search no successful pay" "available was ${CUR}:$(wallet_avail)" - fi - { - echo "best_pay=${MAX_PAY_BEST_AMT:-}" - echo "best_pay_alt=$(format_amount_alt "${MAX_PAY_BEST_AMT:-${CUR}:0}" 2>/dev/null || true)" - echo "pay_lo=${MAX_PAY_LO}" - echo "pay_hi=${MAX_PAY_HI}" - } >>"${SCRATCH}/ladder-plan.txt" 2>/dev/null || true - printf '%s\n' "${MAX_PAY_BEST_AMT:-}" >"${SCRATCH}/ladder-pay-plan.txt" 2>/dev/null || true -} - -# Entry: glue from check_amount_ladder.sh after withdraw phase -ladder_run_pay_phase() { - PAY_OK_N=0 - PAY_FAIL_N=0 - if [ "${LADDER_PAY}" != "1" ]; then - info pay "LADDER_PAY=0 — pay phase skipped" - return 0 - fi - if [ "${FAIL_N_L:-0}" -gt 0 ]; then - warn pay "skipped pay ladder" "withdraw phase already failed" - return 0 - fi - - set_group pay - section "ladder · phase B · pay" - metrics_report_coins "before-pay-ladder" || true - ladder_pay_resolve_merchant - - if [ -z "${AUTH:-}" ] && ! { [ "${LADDER_USE_FREE_TEMPLATE}" = "1" ] && [ -n "${LADDER_FREE_TEMPLATE:-}" ]; }; then - warn pay "no merchant token and free template off — skip pay" - return 0 - fi - if [ -n "${AUTH:-}" ]; then - ok "merchant token" "instance ${INST}" - else - info pay "public free template ${LADDER_FREE_TEMPLATE}@${LADDER_FREE_TEMPLATE_INSTANCE} (no merchant token)" - fi - - # Same cumulative wallet as withdraw (WDB=wallet-main.sqlite3) - wallet_prepare "main" - info pay "using same wallet as withdraw · WDB=${WDB:-?}" - local bal0 - bal0=$(ladder_wait_available "$LADDER_PAY_WAIT_AVAILABLE_S") - info "pay budget" "wallet available ${CUR}:${bal0} · $(format_amount_alt "${CUR}:${bal0}") — never order more than this" - - if [ "${LADDER_MODE}" = "max" ]; then - ladder_run_pay_max_search - else - ladder_run_pay_classic - fi - metrics_report_coins "after-pay-ladder" || true - info "pay summary" "ok=$PAY_OK_N fail=$PAY_FAIL_N tsv=$PAY_TSV" -} diff --git a/lib.sh b/lib.sh index 9187afd..560216c 100755 --- a/lib.sh +++ b/lib.sh @@ -62,9 +62,9 @@ fi # Merchant portal /private API: instance ids must be lowercase or you get odd 401s. # (Display names may use capitals; path segment /instances/{id}/ must not.) MERCHANT_INSTANCE=$(printf '%s' "${MERCHANT_INSTANCE}" | tr '[:upper:]' '[:lower:]') -: "${WITHDRAW_AMT:=GOA:20}" # single-shot fallback; e2e ladder uses bank cash-note amounts +: "${WITHDRAW_AMT:=GOA:20}" # single-shot fallback; e2e ladder uses ATM notes : "${PAY_AMT:=GOA:0.01}" -: "${CREDIT_AMT:=GOA:4700}" # covers bank withdraw ladder 20+50+100+200+4200 (paivana) +: "${CREDIT_AMT:=GOA:4700}" # covers ATM ladder 20+50+100+200+4200 (paivana) : "${TIMEOUT:=12}" : "${E2E_TIMEOUT:=55}" # whole e2e budget; skip rest when exceeded (e2e raises as needed) : "${E2E_PAY_SECS:=22}" # dedicated seconds for pay handle-uri (avoid Alarm clock) @@ -166,53 +166,13 @@ set_taler_stack() { fi } -# Normalize domains.conf UI lang token → en|fr|de (empty if not a lang token). -# Note: de is valid for --lang / explicit profile, but no stock profile defaults to de. -_domain_lang_token() { - case "${1:-}" in - en|EN|eng|english) printf 'en' ;; - fr|FR|fra|french) printf 'fr' ;; - de|DE|deu|ger|german|deutsch) printf 'de' ;; - *) printf '' ;; - esac -} - -# Normalize regional locale → BCP 47 (fr-CH, de-CH, en-CH, …). Empty if unknown. -# Accepts fr-CH, fr_CH, ch-FR / de-CH, ch-DE (user-friendly aliases). -_domain_locale_token() { - local t="${1:-}" - t=$(printf '%s' "$t" | tr '[:upper:]' '[:lower:]' | tr '_' '-') - case "$t" in - fr-ch|ch-fr|fr_ch) printf 'fr-CH' ;; - de-ch|ch-de|de_ch) printf 'de-CH' ;; - en-ch|ch-en|en_ch) printf 'en-CH' ;; - en-us|en-gb|fr-fr|de-de|it-ch|rm-ch) - # pass through other xx-YY - printf '%s' "$t" | awk -F- '{printf "%s-%s", tolower($1), toupper($2)}' - ;; - *) - # bare xx-YY pattern - if printf '%s' "$t" | grep -qE '^[a-z]{2}-[a-z]{2}$'; then - printf '%s' "$t" | awk -F- '{printf "%s-%s", tolower($1), toupper($2)}' - else - printf '' - fi - ;; - esac -} - # Load first matching profile from domains.conf. # Fields (whitespace-separated; # comments; blank lines ignored): -# name bank exchange merchant currency local landing lang locale [canonical] -# Legacy: -# … landing lang [canonical] → locale defaulted -# … landing [canonical] → lang=en, locale defaulted -# Sets TALER_DOMAIN_LANG + TALER_DOMAIN_LOCALE from the profile. +# name bank exchange merchant currency local[0|1] landing[0|1] [canonical_domain] # Returns 0 if found, 1 if not. load_domain_profile() { local want="$1" conf="${TALER_DOMAINS_CONF:-}" local line name bank exchange merchant currency local_stack landing canon - local profile_lang profile_locale f8 f9 f10 [ -n "$want" ] || return 1 [ -n "$conf" ] && [ -f "$conf" ] || return 1 @@ -229,55 +189,12 @@ load_domain_profile() { currency="$5" local_stack="${6:-0}" landing="${7:-}" - f8="${8:-}" - f9="${9:-}" - f10="${10:-}" - canon="$name" - profile_lang="" - profile_locale="" + canon="${8:-$name}" # Backward compat: old 7th field was canonical domain (contains a dot) if [ -n "$landing" ] && [[ "$landing" == *.* && "$landing" != "0" && "$landing" != "1" ]]; then canon="$landing" landing="" - f8="${7:-}" - f9="${8:-}" - f10="${9:-}" fi - if [ -n "$f8" ]; then - profile_lang=$(_domain_lang_token "$f8") - if [ -n "$profile_lang" ]; then - # modern: lang [locale] [canonical] - profile_locale=$(_domain_locale_token "$f9") - if [ -n "$profile_locale" ]; then - canon="${f10:-$name}" - else - # lang + canonical (no locale column) - if [ -n "$f9" ] && [ -z "$(_domain_lang_token "$f9")" ]; then - canon="$f9" - else - canon="${f9:-$name}" - fi - profile_locale=$(_domain_locale_token "$f10") - fi - else - # legacy: field 8 = canonical only - canon="$f8" - profile_lang=$(_domain_lang_token "$f9") - profile_locale=$(_domain_locale_token "${f10:-$f9}") - [ -z "$profile_lang" ] && profile_lang=en - fi - fi - [ -z "$profile_lang" ] && profile_lang=en - if [ -z "$profile_locale" ]; then - # default regional locale: FP → fr-CH, else de-CH - case "$name$canon$bank$merchant" in - *lefrancpaysan*|*francpaysan*) profile_locale=fr-CH ;; - *) profile_locale=de-CH ;; - esac - fi - TALER_DOMAIN_LANG="$profile_lang" - TALER_DOMAIN_LOCALE="$profile_locale" - export TALER_DOMAIN_LANG TALER_DOMAIN_LOCALE set_taler_stack "$bank" "$exchange" "$merchant" "$currency" "$local_stack" "$landing" "$canon" return 0 done <"$conf" @@ -678,7 +595,7 @@ set_area() { } # Start a logical sub-group. Short stable names: # exchange bank merchant perf stats landing paivana -# prereq wallet bankwd settle pay shop dig load report +# prereq wallet atm settle pay shop dig load report # ssh caddy outside inside compare withdraw # Counter continues if the same group is re-entered later in the area. # Prints a compact group chip so log + issue text map cleanly (www.bank-03). @@ -977,98 +894,56 @@ section() { } # Print SUMMARY totals box for given counts (phase-local or global). -# Each severity row is colour-distinct: badge + full-line bg tint + bold count (v1.14.0). # $1=pass $2=fail $3=warn $4=info $5=block _summary_totals_box() { local pass_n="$1" fail_n="$2" warn_n="$3" info_n="$4" blk_n="$5" - local hdr_bg hdr_fg _sum_lbl - _sum_lbl=$(i18n_tag SUMMARY) - # Header colour follows overall verdict - if [ "$fail_n" -gt 0 ] || [ "$blk_n" -gt 0 ]; then - hdr_bg="${BG_ERR}" - hdr_fg="${R}" - elif [ "$warn_n" -gt 0 ]; then - hdr_bg="${BG_WARN}" - hdr_fg="${Y}" - else - hdr_bg="${BG_OK}" - hdr_fg="${G}" - fi - if [ "${BOX:-0}" = "1" ]; then - # Dim full-line tints (bold fg on soft bg) — distinct per severity - local ROW_OK=$'\e[1;32;48;5;22m' # bold green on dark green - local ROW_ERR=$'\e[1;97;48;5;52m' # bold white on dark red - local ROW_WARN=$'\e[1;30;48;5;178m' # bold black on gold - local ROW_INFO=$'\e[1;97;48;5;24m' # bold white on dark blue - local ROW_BLK=$'\e[1;97;48;5;53m' # bold white on dark magenta - local ROW_TOT=$'\e[1;37;48;5;236m' # bold white on dark gray - - # Include SUMMARY on all three frame lines so HTML classify maps them to sum-header - # (phase section() boxes use the same ╔═║╚ glyphs but must not get sum-* paint). - printf -- '\n%s╔════════ %s ════════════════════╗%s\n' "$hdr_bg" "$_sum_lbl" "$N" - printf -- '%s║ %-34s ║%s\n' "$hdr_bg" "$_sum_lbl" "$N" - printf -- '%s╚════════ %s ════════════════════╝%s\n' "$hdr_bg" "$_sum_lbl" "$N" - - # $1=row_bg $2=badge_bg $3=tag $4=n $5=label_fg — full-width-ish row - _sum_row() { - local row_bg="$1" badge="$2" tag="$3" n="$4" fg="$5" _tg pad - _tg=$(i18n_tag "$tag") - pad=$(printf '%-5s' "$_tg") - printf -- ' %s┌ %s┐%s %s %s%6d%s %s%-12s%s\n' \ - "$badge" "$pad" "$N" \ - "$row_bg" "$B" "$n" "$N" \ - "$fg$B" "$_tg" "$N" + printf -- '\n%s┌ %s ┐%s\n' "$BG_SEC" "$(i18n_tag SUMMARY)" "$N" + _sum_badge() { # $1=bg $2=tag $3=fg $4=n + local _tg + _tg=$(i18n_tag "$2") + printf -- ' %s┌ %-5s┐%s %s%4d%s\n' "$1" "$_tg" "$N" "$3" "$4" "$N" } - _sum_row "$ROW_OK" "$BG_OK" "OK" "$pass_n" "$G" - [ "$fail_n" -gt 0 ] && _sum_row "$ROW_ERR" "$BG_ERR" "ERROR" "$fail_n" "$R" - [ "$warn_n" -gt 0 ] && _sum_row "$ROW_WARN" "$BG_WARN" "WARN" "$warn_n" "$Y" - [ "$info_n" -gt 0 ] && _sum_row "$ROW_INFO" "$BG_INFO" "INFO" "$info_n" "$C" - [ "$blk_n" -gt 0 ] && _sum_row "$ROW_BLK" "$BG_BLK" "BLOCK" "$blk_n" "$M" - - # totals rollup on tinted bar - printf -- ' %s %s %s %s%d OK%s' "$ROW_TOT" "$B" "$(i18n_text 'totals:')" "$G$B" "$pass_n" "$N$ROW_TOT" - [ "$fail_n" -gt 0 ] && printf -- ' %s·%s %s%d ERROR%s' "$D" "$N$ROW_TOT" "$R$B" "$fail_n" "$N$ROW_TOT" - [ "$warn_n" -gt 0 ] && printf -- ' %s·%s %s%d WARN%s' "$D" "$N$ROW_TOT" "$Y$B" "$warn_n" "$N$ROW_TOT" - [ "$info_n" -gt 0 ] && printf -- ' %s·%s %s%d INFO%s' "$D" "$N$ROW_TOT" "$C$B" "$info_n" "$N$ROW_TOT" - [ "$blk_n" -gt 0 ] && printf -- ' %s·%s %s%d BLOCKER%s' "$D" "$N$ROW_TOT" "$M$B" "$blk_n" "$N$ROW_TOT" - printf -- ' %s\n' "$N" + _sum_badge "$BG_OK" "OK" "$G" "$pass_n" + [ "$fail_n" -gt 0 ] && _sum_badge "$BG_ERR" "ERROR" "$R" "$fail_n" + [ "$warn_n" -gt 0 ] && _sum_badge "$BG_WARN" "WARN" "$Y" "$warn_n" + [ "$info_n" -gt 0 ] && _sum_badge "$BG_INFO" "INFO" "$C" "$info_n" + [ "$blk_n" -gt 0 ] && _sum_badge "$BG_BLK" "BLOCK" "$M" "$blk_n" else - printf -- '\n[ %s ]\n' "$_sum_lbl" - printf -- ' [ %-5s ] %s%4d%s\n' "$(i18n_tag OK)" "$G$B" "$pass_n" "$N" - [ "$fail_n" -gt 0 ] && printf -- ' [ %-5s ] %s%4d%s\n' "$(i18n_tag ERROR)" "$R$B" "$fail_n" "$N" - [ "$warn_n" -gt 0 ] && printf -- ' [ %-5s ] %s%4d%s\n' "$(i18n_tag WARN)" "$Y$B" "$warn_n" "$N" - [ "$info_n" -gt 0 ] && printf -- ' [ %-5s ] %s%4d%s\n' "$(i18n_tag INFO)" "$C$B" "$info_n" "$N" - [ "$blk_n" -gt 0 ] && printf -- ' [ %-5s ] %s%4d%s\n' "$(i18n_tag BLOCK)" "$M$B" "$blk_n" "$N" - printf -- ' %s%s%s %s%d OK%s' "$B" "$(i18n_text 'totals:')" "$N" "$G$B" "$pass_n" "$N" - [ "$fail_n" -gt 0 ] && printf -- ' · %s%d ERROR%s' "$R$B" "$fail_n" "$N" - [ "$warn_n" -gt 0 ] && printf -- ' · %s%d WARN%s' "$Y$B" "$warn_n" "$N" - [ "$info_n" -gt 0 ] && printf -- ' · %s%d INFO%s' "$C$B" "$info_n" "$N" - [ "$blk_n" -gt 0 ] && printf -- ' · %s%d BLOCKER%s' "$M$B" "$blk_n" "$N" - printf '\n' + printf -- '\n[ %s ]\n' "$(i18n_tag SUMMARY)" + printf -- ' [ %-5s ] %s%4d%s\n' "$(i18n_tag OK)" "$G" "$pass_n" "$N" + [ "$fail_n" -gt 0 ] && printf -- ' [ %-5s ] %s%4d%s\n' "$(i18n_tag ERROR)" "$R" "$fail_n" "$N" + [ "$warn_n" -gt 0 ] && printf -- ' [ %-5s ] %s%4d%s\n' "$(i18n_tag WARN)" "$Y" "$warn_n" "$N" + [ "$info_n" -gt 0 ] && printf -- ' [ %-5s ] %s%4d%s\n' "$(i18n_tag INFO)" "$C" "$info_n" "$N" + [ "$blk_n" -gt 0 ] && printf -- ' [ %-5s ] %s%4d%s\n' "$(i18n_tag BLOCK)" "$M" "$blk_n" "$N" fi - # overall verdict — bold label, filled badge (i18n for FR console/HTML) - local _ok_msg _warn_msg _fail_msg - _ok_msg=$(i18n_text 'all clear') - _warn_msg=$(i18n_text 'warnings only (no hard fail)') + # one-line rollup (bold label, severity-coloured counts) + printf -- ' %stotals:%s %s%d OK%s' "$B" "$N" "$G" "$pass_n" "$N" + [ "$fail_n" -gt 0 ] && printf -- ' · %s%d ERROR%s' "$R" "$fail_n" "$N" + [ "$warn_n" -gt 0 ] && printf -- ' · %s%d WARN%s' "$Y" "$warn_n" "$N" + [ "$info_n" -gt 0 ] && printf -- ' · %s%d INFO%s' "$C" "$info_n" "$N" + [ "$blk_n" -gt 0 ] && printf -- ' · %s%d BLOCKER%s' "$M" "$blk_n" "$N" + printf '\n' + # overall verdict if [ "$fail_n" -eq 0 ] && [ "$blk_n" -eq 0 ] && [ "$warn_n" -eq 0 ]; then if [ "${BOX:-0}" = "1" ]; then - printf -- ' %s┌ OK ┐%s %s%s%s%s\n' "$BG_OK" "$N" "$G" "$B" "$_ok_msg" "$N" + printf -- ' %s┌ OK ┐%s %sall clear%s\n' "$BG_OK" "$N" "$G" "$N" else - printf -- ' %s[ OK ] %s%s%s\n' "$G" "$B" "$_ok_msg" "$N" + printf -- ' %s[ OK ] all clear%s\n' "$G" "$N" fi elif [ "$fail_n" -eq 0 ] && [ "$blk_n" -eq 0 ]; then if [ "${BOX:-0}" = "1" ]; then - printf -- ' %s┌ WARN ┐%s %s%s%s%s\n' "$BG_WARN" "$N" "$Y" "$B" "$_warn_msg" "$N" + printf -- ' %s┌ WARN ┐%s %swarnings only (no hard fail)%s\n' "$BG_WARN" "$N" "$Y" "$N" else - printf -- ' %s[ WARN ] %s%s%s\n' "$Y" "$B" "$_warn_msg" "$N" + printf -- ' %s[ WARN ] warnings only (no hard fail)%s\n' "$Y" "$N" fi else + local _fail_msg _fail_msg=$(i18n_text 'failed — see list above') if [ "${BOX:-0}" = "1" ]; then - printf -- ' %s┌ ERROR ┐%s %s%s%s%s\n' "$BG_ERR" "$N" "$R" "$B" "$_fail_msg" "$N" + printf -- ' %s┌ ERROR ┐%s %s%s%s\n' "$BG_ERR" "$N" "$R" "$_fail_msg" "$N" else - printf -- ' %s[ ERROR ] %s%s%s\n' "$R" "$B" "$_fail_msg" "$N" + printf -- ' %s[ ERROR ] %s%s\n' "$R" "$_fail_msg" "$N" fi fi } @@ -1504,53 +1379,6 @@ load_monitoring_secrets_env() { export E2E_BANK_ADMIN_PASS E2E_MERCHANT_TOKEN SECRETS_ROOT KOOPA_ADMIN_SECRETS } -# Strip default HTTPS/HTTP ports from taler:// URIs (libeufin often emits host:443). -# Wallets and mon QR rules reject default :443/:80 in the authority. -# Usage: normalize_taler_uri "taler://withdraw/host:443/…" → prints cleaned URI -normalize_taler_uri() { - local u="${1-}" - if [ -z "$u" ]; then - return 0 - fi - printf '%s' "$u" | python3 -c ' -import re, sys -u = sys.stdin.read().strip() -# any taler://SCHEME/HOST:443|80/... -u = re.sub( - r"(taler://[A-Za-z0-9._-]+/)([^/?#:]+):443(?=/|$|\?|#)", - r"\1\2", - u, - flags=re.I, -) -u = re.sub( - r"(taler://[A-Za-z0-9._-]+/)([^/?#:]+):80(?=/|$|\?|#)", - r"\1\2", - u, - flags=re.I, -) -# leftover path/query forms -for a, b in ( - (":443/", "/"), - (":443?", "?"), - (":443#", "#"), - (":80/", "/"), - (":80?", "?"), - (":80#", "#"), -): - u = u.replace(a, b) -# bare trailing :443 / :80 on host (no slash) -u = re.sub(r"(taler://[A-Za-z0-9._-]+/[^/?#:]+):443$", r"\1", u, flags=re.I) -u = re.sub(r"(taler://[A-Za-z0-9._-]+/[^/?#:]+):80$", r"\1", u, flags=re.I) -sys.stdout.write(u) -' 2>/dev/null || printf '%s' "$u" -} - -# True (exit 0) if URI still has default port in taler:// authority. -taler_uri_has_default_port() { - # host:443 or host:80 before next path/query/end - python3 -c "import re,sys; u=sys.argv[1] if len(sys.argv)>1 else ''; sys.exit(0 if re.search(r'taler://\\S+:(443|80)(/|$|\\?|#)', u, re.I) else 1)" "${1-}" 2>/dev/null -} - find_wallet_cli() { # Must return a path suitable for: node "$WALLET_CLI" … # Prefer *.mjs / bundled entry; plain /usr/bin/taler-wallet-cli is often a @@ -1559,20 +1387,12 @@ find_wallet_cli() { echo "$WALLET_CLI"; return 0 fi local c cand - # WALLET_CLI / WALLET_CLI_CANDIDATES from env; then portable package paths. - # Prefer local ts-core / mon-env builds (schema-compatible) over stale system - # wrappers (e.g. /usr/local 1.3.x vs DB schema 29 from 1.6.x). + # WALLET_CLI / WALLET_CLI_CANDIDATES from env; then portable package paths only. # shellcheck disable=SC2086 for c in ${WALLET_CLI_CANDIDATES:-} \ "${HOME}/.local/bin/taler-wallet-cli.mjs" \ - "${HOME}/src/taler/taler-typescript-core/packages/taler-wallet-cli/bin/taler-wallet-cli.mjs" \ - "${HOME}/src/taler/taler-typescript-core/packages/taler-wallet-cli/dist/taler-wallet-cli.mjs" \ - "${HOME}/src/taler/taler-typescript-core/packages/taler-wallet-cli/dist/taler-wallet-cli-local.mjs" \ - "${HOME}/src/taler/taler-typescript-core/packages/taler-wallet-cli/dist/taler-wallet-cli-bundled.cjs" \ /usr/lib/taler-wallet-cli/node_modules/taler-wallet-cli/bin/taler-wallet-cli.mjs \ - /usr/share/taler-wallet-cli/bin/taler-wallet-cli.mjs \ - /usr/local/lib/taler-wallet-cli/node_modules/taler-wallet-cli/bin/taler-wallet-cli.mjs \ - /usr/local/lib/taler-wallet-cli/node_modules/taler-wallet-cli/dist/taler-wallet-cli-bundled.cjs + /usr/share/taler-wallet-cli/bin/taler-wallet-cli.mjs do [ -n "$c" ] && [ -f "$c" ] && { echo "$c"; return 0; } done @@ -1588,14 +1408,6 @@ find_wallet_cli() { c=$(readlink -f "$cand" 2>/dev/null || true) [ -n "$c" ] && [ -f "$c" ] && { echo "$c"; return 0; } fi - # macOS /usr/local wrapper often runs an older bundle; prefer its bundled.cjs only - # when no newer candidate above matched (already returned). - for c in \ - /usr/local/lib/taler-wallet-cli/node_modules/taler-wallet-cli/dist/taler-wallet-cli-bundled.cjs \ - /usr/local/lib/node_modules/taler-wallet-cli/dist/taler-wallet-cli-bundled.cjs - do - [ -f "$c" ] && { echo "$c"; return 0; } - done fi return 1 } diff --git a/mail-catalog.conf b/mail-catalog.conf index f489234..7a67578 100644 --- a/mail-catalog.conf +++ b/mail-catalog.conf @@ -3,18 +3,16 @@ # Format (whitespace-separated; # comments): # domain expected_mx (comma) mail_hosts (comma) smtp_ports imap_ports label # -# Mail planes (outside-in only — no host login): -# • firefly.gnunet.org — taler.net + gnunet.org -# • mail.anastasis.lu — Anastasis / TSA (A → pixel.taler-systems.com) -# (legacy catalog host anastasis.taler-systems.com does NOT resolve) +# Only these mail planes (no hacktivism / ad-hoc MX): +# • firefly.gnunet.org — taler.net + gnunet.org +# • anastasis.taler-systems.com — Anastasis / TSA mail # # Override path: MAIL_CATALOG=/path/to/file # --- firefly.gnunet.org --- -taler.net firefly.gnunet.org firefly.gnunet.org 25,465,587 143,993 firefly-taler -gnunet.org firefly.gnunet.org firefly.gnunet.org 25,465,587 143,993 firefly-gnunet +taler.net firefly.gnunet.org firefly.gnunet.org 25,465,587 143,993 firefly-taler +gnunet.org firefly.gnunet.org firefly.gnunet.org 25,465,587 143,993 firefly-gnunet -# --- Anastasis / TSA (MX mail.anastasis.lu → pixel) --- -# Port 587 often closed/filtered on this plane → WARN only (see check_mail.sh). -taler-systems.com mail.anastasis.lu mail.anastasis.lu,pixel.taler-systems.com 25,465,587 143,993 tsa-anastasis -anastasis.lu mail.anastasis.lu mail.anastasis.lu 25,465,587 143,993 anastasis-lu +# --- anastasis.taler-systems.com --- +anastasis.taler-systems.com anastasis.taler-systems.com anastasis.taler-systems.com 25,465,587 143,993 anastasis-tsa +taler-systems.com anastasis.taler-systems.com anastasis.taler-systems.com 25,465,587 143,993 tsa-via-anastasis diff --git a/metrics.sh b/metrics.sh index 5e6ac42..aac0630 100644 --- a/metrics.sh +++ b/metrics.sh @@ -70,15 +70,11 @@ path = sys.argv[2] if len(sys.argv) > 2 else "" alt = {} if path: try: - _loaded = json.load(open(path)) - if isinstance(_loaded, dict): - alt = {str(k): str(v) for k, v in _loaded.items()} + alt = json.load(open(path)) except Exception: alt = {} -if not isinstance(alt, dict) or not alt: +if not alt: alt = {"0": "GOA"} -elif "0" not in alt: - alt["0"] = "GOA" def parse(s): if ":" in s: diff --git a/site-gen/caddy-monitoring-handles.snippet b/site-gen/caddy-monitoring-handles.snippet index 9ab43a7..5689fff 100644 --- a/site-gen/caddy-monitoring-handles.snippet +++ b/site-gen/caddy-monitoring-handles.snippet @@ -5,7 +5,6 @@ # # CORRECT (site-level named matcher — preferred): # @mon_bare path /monitoring /monitoring_err \ -# /monitoring-max-ladder /monitoring-max-ladder_err \ # /taler-monitoring-surface /taler-monitoring-surface_err \ # /taler-monitoring-aptdeploy /taler-monitoring-aptdeploy_err # redir @mon_bare {path}/ 302 @@ -36,7 +35,6 @@ # --- only inside taler.hacktivism.ch { ... } --- @mon_bare path /monitoring /monitoring_err \ - /monitoring-max-ladder /monitoring-max-ladder_err \ /taler-monitoring-surface /taler-monitoring-surface_err \ /taler-monitoring-aptdeploy /taler-monitoring-aptdeploy_err \ /taler-monitoring-mail /taler-monitoring-mail_err \ @@ -61,9 +59,7 @@ } # --- bank + exchange + taler (each site block; set root host dir) --- -# /monitoring* already covers /monitoring-max-ladder* - @mon_bare path /monitoring /monitoring_err \ - /monitoring-max-ladder /monitoring-max-ladder_err + @mon_bare path /monitoring /monitoring_err redir @mon_bare {path}/ 302 handle /monitoring_err* { diff --git a/site-gen/console_to_html.py b/site-gen/console_to_html.py index 6141c0e..bb574ba 100755 --- a/site-gen/console_to_html.py +++ b/site-gen/console_to_html.py @@ -4,9 +4,8 @@ from __future__ import annotations import argparse import html -import os import re -import sys +import os from datetime import datetime, timezone from pathlib import Path @@ -45,168 +44,19 @@ def atomic_write_text(path: Path, text: str, encoding: str = "utf-8") -> None: except OSError: pass -def _norm_lang(v: str) -> str: - v = (v or "").strip().lower() - if v in ("fr", "fra", "french"): +def ui_lang(explicit: str = "") -> str: + """en (default) or fr. Env: TALER_MON_LANG; auto fr for lefrancpaysan hosts.""" + import os + lang = (explicit or os.environ.get("TALER_MON_LANG") or "").strip().lower() + if lang in ("fr", "fra", "french"): return "fr" - if v in ("de", "deu", "ger", "german", "deutsch"): - return "de" - if v in ("en", "eng", "english"): + if lang in ("en", "eng", "english"): return "en" - return "" - - -def _norm_locale(v: str) -> str: - """BCP 47 regional locale; aliases ch-FR/ch-DE → fr-CH/de-CH.""" - t = (v or "").strip().lower().replace("_", "-") - aliases = { - "fr-ch": "fr-CH", - "ch-fr": "fr-CH", - "de-ch": "de-CH", - "ch-de": "de-CH", - "en-ch": "en-CH", - "ch-en": "en-CH", - } - if t in aliases: - return aliases[t] - m = re.fullmatch(r"([a-z]{2})-([a-z]{2})", t) - if m: - return f"{m.group(1)}-{m.group(2).upper()}" - return "" - - -def _domains_conf_path() -> "object | None": - import os - from pathlib import Path - - conf = os.environ.get("TALER_DOMAINS_CONF") or "" - candidates = [] - if conf: - candidates.append(Path(conf)) - here = Path(__file__).resolve().parent - candidates.append(here.parent / "domains.conf") - candidates.append(Path("domains.conf")) - return next((p for p in candidates if p.is_file()), None) - - -def domain_profile_from_conf(host_hint: str = "") -> tuple[str, str]: - """Return (lang, locale) from domains.conf for host_hint; ('','') if none.""" - hint = (host_hint or "").lower() - if not hint.strip(): - return "", "" - - path = _domains_conf_path() - if path is None: - return "", "" - try: - text = path.read_text(encoding="utf-8", errors="replace") - except OSError: - return "", "" - - best_lang, best_loc = "", "" - for raw in text.splitlines(): - line = raw.split("#", 1)[0].strip() - if not line: - continue - parts = line.split() - if len(parts) < 5: - continue - name, bank, exchange, merchant = parts[0], parts[1], parts[2], parts[3] - lang, locale, canon = "", "", name - if len(parts) >= 8: - tok = _norm_lang(parts[7]) - if tok: - lang = tok - if len(parts) >= 9: - loc = _norm_locale(parts[8]) - if loc: - locale = loc - if len(parts) >= 10: - canon = parts[9] - else: - # lang + canonical (no locale) - canon = parts[8] - if len(parts) >= 10: - locale = _norm_locale(parts[9]) - else: - canon = parts[7] - if len(parts) >= 9: - lang = _norm_lang(parts[8]) - if len(parts) >= 10: - locale = _norm_locale(parts[9]) - elif len(parts) >= 9: - locale = _norm_locale(parts[8]) - if not lang: - lang = "en" - if not locale: - blob = f"{name}{canon}{bank}{merchant}".lower() - locale = "fr-CH" if ("lefrancpaysan" in blob or "francpaysan" in blob) else "de-CH" - hosts = {name.lower(), bank.lower(), exchange.lower(), merchant.lower(), canon.lower()} - hosts = {re.sub(r"^https?://", "", h).split("/")[0] for h in hosts} - if any(h and h in hint for h in hosts): - best_lang, best_loc = lang, locale - if name.lower() in hint or canon.lower() in hint: - return lang, locale - return best_lang, best_loc - - -def domain_lang_from_conf(host_hint: str = "") -> str: - """Look up UI lang from domains.conf (suite profile `lang` column).""" - lang, _ = domain_profile_from_conf(host_hint) - return lang - - -def domain_locale_from_conf(host_hint: str = "") -> str: - """Look up regional locale from domains.conf (`locale` column).""" - _, loc = domain_profile_from_conf(host_hint) - return loc - - -def ui_lang(explicit: str = "", host_hint: str = "") -> str: - """en | fr | de (de never a stock profile default). - - - TALER_MON_LANG_SET=1 → honour TALER_MON_LANG / explicit only. - - Else TALER_DOMAIN_LANG / domains.conf `lang`. - - Else fallback *lefrancpaysan* → fr. - - Else explicit / env / en. - """ - import os - - env_lang = (os.environ.get("TALER_MON_LANG") or "").strip().lower() - domain_lang = _norm_lang(os.environ.get("TALER_DOMAIN_LANG") or "") - lang = (explicit or env_lang or "").strip().lower() - locked = (os.environ.get("TALER_MON_LANG_SET") or "").strip() == "1" - - if locked: - return _norm_lang(lang) or "en" - if domain_lang: - return domain_lang - conf_lang = domain_lang_from_conf(host_hint) - if conf_lang: - return conf_lang - if re.search(r"lefrancpaysan|francpaysan", host_hint or "", re.I): - return "fr" - return _norm_lang(lang) or "en" - - -def ui_locale(host_hint: str = "") -> str: - """Regional locale fr-CH / de-CH from env or domains.conf.""" - import os - - for key in ("TALER_MON_LOCALE", "TALER_DOMAIN_LOCALE"): - loc = _norm_locale(os.environ.get(key) or "") - if loc: - return loc - conf = domain_locale_from_conf(host_hint) - if conf: - return conf - if re.search(r"lefrancpaysan|francpaysan", host_hint or "", re.I): - return "fr-CH" - return "de-CH" + return "en" def ui(lang: str, key: str, **kwargs) -> str: - """UI chrome strings (en default; fr for FP; de available via --lang de, never stock default).""" + """UI chrome strings for sticky bar (English default; French for FrancPaysan).""" en = { "errors": "ERRORS", "warnings": "WARNINGS", @@ -217,27 +67,18 @@ def ui(lang: str, key: str, **kwargs) -> str: "warn_many": "{n} warnings", "jump_first_error": "Jump to first error", "jump_first_warn": "Jump to first warning", - "filter_errors": "Filter: errors + a few dimmed context lines", - "filter_warns": "Filter: warnings + a few dimmed context lines", - "filter_infos": "Filter: info lines + a few dimmed context lines", - "filter_oks": "Filter: OK lines + a few dimmed context lines", + "filter_errors": "Filter: show all errors (hide other log lines)", + "filter_warns": "Filter: show all warnings (hide other log lines)", "filter_clear": "Clear filter · show all lines", - "filter_active_err": "Filter: errors + context", - "filter_active_warn": "Filter: warnings + context", - "filter_active_info": "Filter: info + context", - "filter_active_ok": "Filter: OK only + context", + "filter_active_err": "Filter: errors only", + "filter_active_warn": "Filter: warnings only", "filter_show_all": "Show all", - "info_one": "{n} info", - "info_many": "{n} info", - "ok_one": "{n} ok", - "ok_many": "{n} ok", "env_context": "Monitoring env context", "env_context_title": "Expand: agent env, suite pin, domain hosts & flags (from run header)", "env_context_empty": "No run header in log", "generated": "generated", "version": "version", "version_tree_link": "open this run’s git tree (commit)", - "suite_version_title": "taler-monitoring suite version · exact run tree", "source": "source", "what_monitors": "What this monitors", @@ -273,19 +114,13 @@ def ui(lang: str, key: str, **kwargs) -> str: "stack_i4": "HTML host: {host}", "stack_i5": "Timer: host-agent path + 4h · /monitoring on bank, exchange, merchant fronts", "stack_i_phases": "Log header phases= {phases}", - "page_label_monitoring": "monitoring", - "page_label_surface": "surface", - "page_label_aptdeploy": "aptdeploy", - "mode_ok": "OK", - "mode_err": "ERR", - "mode_redirect": "REDIR", "pages_title": "Monitoring pages (suite HTML)", "pages_summary": "Public sticky-bar reports · phase monpages · part of taler-monitoring", - "pages_i1": "Suite name taler-monitoring ≠ URL. Public families (bare + slash each):", - "pages_i2": "1) /monitoring(+_err) · 2) /monitoring-max-ladder(+_err) daily max-search (GOA) · 3) /taler-monitoring-surface · 4) /taler-monitoring-aptdeploy (surface/aptdeploy on taler.hacktivism.ch)", - "pages_i3": "No classic /monitoring-ladder; no /taler-monitoring page; mail|mattermost folded into surface. Max-ladder on GOA bank/exchange/taler.", + "pages_i1": "Suite name taler-monitoring ≠ URL. Only three public families (bare + slash each):", + "pages_i2": "1) /monitoring(+_err) on landing hosts · 2) /taler-monitoring-surface(+_err) · 3) /taler-monitoring-aptdeploy(+_err) on taler.hacktivism.ch", + "pages_i3": "No /taler-monitoring page; no /taler-monitoring-mail|mattermost (folded into surface)", "pages_i4": "monpages: existence + content markers; bare → slash redir (not merchant code 21)", - "pages_i5": "Host-agent: staging → DEPLOY_WWW_ROOT; Caddy /monitoring* also serves /monitoring-max-ladder*", + "pages_i5": "Host-agent: staging → DEPLOY_WWW_ROOT; reverse-proxy handles only those three families", "pages_i6": "This page host: {host} · path label: {label}", "stage_title": "mytops stage monitoring · {host}", "stage_summary": "betel only · CHF stage stack · not lifeline/prod · not GOA", @@ -297,18 +132,16 @@ def ui(lang: str, key: str, **kwargs) -> str: "stage_i6": "devtesting: fake-franken CHF via rusty.taler-ops.ch (geniban + fake-incoming)", "pages_section_lead": "Monitoring pages themselves (suite):", "mm_title": "Mattermost chat health", - "mm_summary": "mattermost.taler.net · SPA + ping · client floors (mobile/desktop/support) · TLS", + "mm_summary": "mattermost.taler.net · SPA + /api/v4/system/ping · TLS", "mm_i1": "Outside-in phase mattermost (default https://mattermost.taler.net)", - "mm_i2": "Landing SPA, /api/v4/system/ping, X-Version-Id vs client mins (mobile/desktop/support, default ≥10.11.0)", - "mm_i3": "ERROR if server too old for current Android/iOS store or Desktop apps; WARN for web on EOL server", - "mm_i4": "Env: MATTERMOST_MOBILE/DESKTOP/SUPPORT_MIN_SERVER, MATTERMOST_CLIENT_CHECK=0 to skip", - "mm_i5": "Reported on taler-monitoring-surface HTML (no separate /taler-monitoring-mattermost* page)", + "mm_i2": "Landing SPA, /api/v4/system/ping JSON, /login, TLS certificate expiry", + "mm_i3": "Reported on taler-monitoring-surface HTML (no separate /taler-monitoring-mattermost* page)", "mail_title": "Mail (MX / SMTP / IMAP)", "mail_summary": "firefly.gnunet.org + anastasis.taler-systems.com · mail-catalog.conf", "mail_i1": "Outside-in phase mail: MX, SMTP/IMAP ports and handshakes, SPF/DMARC", "mail_i2": "Mail hosts: firefly.gnunet.org (taler.net/gnunet.org) and anastasis.taler-systems.com", "mail_i3": "Reported on taler-monitoring-surface HTML (no separate /taler-monitoring-mail* page)", - "footer": "Console-style render of taler-monitoring output. Sticky bar: green = clean · yellow = warnings · red = errors. Click error / warning / info (blue) / ok counts to filter the log (match lines plus dimmed neighbours). Suite version sits under the status pill. Monitoring env context is collapsed by default.", + "footer": "Console-style render of taler-monitoring output. Sticky bar: green = clean · yellow = warnings · red = errors. Click error/warning counts to filter the log. Monitoring env context (agent header) is collapsed by default. Commit pins the exact tree used for this run.", "redirect_fail": "has failures.", "redirect_see": "See {link} for the full console log, error index, and sticky status bar.", "ago_s": "{n}s ago", @@ -327,27 +160,18 @@ def ui(lang: str, key: str, **kwargs) -> str: "warn_many": "{n} avertissements", "jump_first_error": "Aller à la première erreur", "jump_first_warn": "Aller au premier avertissement", - "filter_errors": "Filtrer : erreurs + quelques lignes de contexte grisées", - "filter_warns": "Filtrer : avertissements + quelques lignes de contexte grisées", - "filter_infos": "Filtrer : infos + quelques lignes de contexte grisées", - "filter_oks": "Filtrer : lignes OK + quelques lignes de contexte grisées", + "filter_errors": "Filtrer : toutes les erreurs (masquer le reste du journal)", + "filter_warns": "Filtrer : tous les avertissements (masquer le reste du journal)", "filter_clear": "Effacer le filtre · tout afficher", - "filter_active_err": "Filtre : erreurs + contexte", - "filter_active_warn": "Filtre : avertissements + contexte", - "filter_active_info": "Filtre : infos + contexte", - "filter_active_ok": "Filtre : OK seulement + contexte", + "filter_active_err": "Filtre : erreurs seulement", + "filter_active_warn": "Filtre : avertissements seulement", "filter_show_all": "Tout afficher", - "info_one": "{n} info", - "info_many": "{n} infos", - "ok_one": "{n} ok", - "ok_many": "{n} ok", "env_context": "Contexte d'env. de monitoring", "env_context_title": "Déplier : env agent, pin de suite, hôtes domaine et flags (en-tête d'exécution)", "env_context_empty": "Pas d'en-tête d'exécution dans le journal", "generated": "généré", "version": "version", "version_tree_link": "ouvrir l'arbre git de cette exécution (commit)", - "suite_version_title": "version de la suite taler-monitoring · arbre exact de l'exécution", "source": "source", "what_monitors": "Ce que cette page contrôle", @@ -376,26 +200,20 @@ def ui(lang: str, key: str, **kwargs) -> str: "focus_merchant": "Backend marchand / SPA HTTPS public + contrôles inside conteneur", "focus_stack": "Pile Taler public + inside", "stack_title": "Surveillance de pile · {host}", - "stack_summary": "{phases} · public + interne", + "stack_summary": "{phases} · public + inside", "stack_i1": "Focus : {focus}", "stack_i2": "Phases de cette exécution : {phases}", "stack_i3": "Typique : URL publiques (HTTPS, QR, perf), inside (podman/ssh), versions des paquets", "stack_i4": "Hôte HTML : {host}", "stack_i5": "Minuterie : host-agent path + 4 h · /monitoring sur bank, exchange, fronts marchands", "stack_i_phases": "En-tête de journal phases= {phases}", - "page_label_monitoring": "surveillance", - "page_label_surface": "surface", - "page_label_aptdeploy": "aptdeploy", - "mode_ok": "OK", - "mode_err": "ERR", - "mode_redirect": "REDIR", - "pages_title": "Pages de monitoring (HTML de la suite)", + "pages_title": "Pages de monitoring (HTML de la suite)", "pages_summary": "Rapports publics sticky-bar · phase monpages · partie de taler-monitoring", - "pages_i1": "Nom de suite taler-monitoring ≠ URL. Familles publiques (sans et avec /) :", - "pages_i2": "1) /monitoring(+_err) · 2) /monitoring-max-ladder(+_err) quotidien max-search (GOA) · 3) surface · 4) aptdeploy (surface/aptdeploy sur taler.hacktivism.ch)", - "pages_i3": "Pas de /monitoring-ladder classic ; pas de /taler-monitoring ; mail|mattermost dans surface. Max-ladder sur landings GOA.", + "pages_i1": "Nom de suite taler-monitoring ≠ URL. Trois familles publiques seulement (sans et avec /) :", + "pages_i2": "1) /monitoring(+_err) · 2) /taler-monitoring-surface(+_err) · 3) /taler-monitoring-aptdeploy(+_err) sur taler.hacktivism.ch", + "pages_i3": "Pas de page /taler-monitoring ; pas de /taler-monitoring-mail|mattermost (dans surface)", "pages_i4": "monpages : existence + marqueurs ; bare → slash (pas code 21 merchant)", - "pages_i5": "Host-agent : staging → DEPLOY_WWW_ROOT ; Caddy /monitoring* sert aussi /monitoring-max-ladder*", + "pages_i5": "Host-agent : staging → DEPLOY_WWW_ROOT ; reverse-proxy seulement ces trois familles", "stage_title": "Surveillance mytops stage · {host}", "stage_summary": "betel uniquement · pile CHF stage · pas lifeline/prod · pas GOA", "stage_i1": "Hôte : betel (stage). HTML mon : stage.my.taler-ops.ch + stage.taler-ops.ch /monitoring/", @@ -407,18 +225,16 @@ def ui(lang: str, key: str, **kwargs) -> str: "pages_i6": "Hôte de cette page : {host} · libellé : {label}", "pages_section_lead": "Les pages de monitoring elles-mêmes (suite) :", "mm_title": "Santé du chat Mattermost", - "mm_summary": "mattermost.taler.net · SPA + ping · seuils clients (mobile/desktop/support) · TLS", + "mm_summary": "mattermost.taler.net · SPA + /api/v4/system/ping · TLS", "mm_i1": "Phase outside-in mattermost (défaut https://mattermost.taler.net)", - "mm_i2": "SPA, /api/v4/system/ping, X-Version-Id vs seuils clients (mobile/desktop/support, défaut ≥10.11.0)", - "mm_i3": "ERROR si serveur trop vieux pour apps store Android/iOS ou Desktop ; WARN web sur serveur EOL", - "mm_i4": "Env : MATTERMOST_MOBILE/DESKTOP/SUPPORT_MIN_SERVER, MATTERMOST_CLIENT_CHECK=0 pour ignorer", - "mm_i5": "Rapporté sur la page surface HTML", + "mm_i2": "SPA d'accueil, /api/v4/system/ping JSON, /login, expiration du certificat TLS", + "mm_i3": "Rapporté dans le HTML taler-monitoring-surface (pas de page /taler-monitoring-mattermost*)", "mail_title": "Mail (MX / SMTP / IMAP)", "mail_summary": "firefly.gnunet.org + anastasis.taler-systems.com · mail-catalog.conf", "mail_i1": "Phase outside-in mail : MX, ports SMTP/IMAP et handshakes, SPF/DMARC", "mail_i2": "Hôtes mail : firefly.gnunet.org (taler.net/gnunet.org) et anastasis.taler-systems.com", "mail_i3": "Rapporté dans le HTML taler-monitoring-surface (pas de page /taler-monitoring-mail*)", - "footer": "Rendu console de taler-monitoring. Barre collante : vert = OK · jaune = avertissements · rouge = erreurs. Compteurs erreur / avertissement / info (bleu) / ok = filtres. Version de la suite sous le badge d'état. Contexte d'env. replié par défaut.", + "footer": "Rendu console de taler-monitoring. Barre collante : vert = OK · jaune = avertissements · rouge = erreurs. Compteurs = filtre. Contexte d'env. (en-tête agent) replié par défaut. Le commit fixe l'arbre exact de cette exécution.", "redirect_fail": "a des échecs.", "redirect_see": "Voir {link} pour le journal console complet, l'index d'erreurs et la barre de statut.", "ago_s": "il y a {n}s", @@ -427,60 +243,7 @@ def ui(lang: str, key: str, **kwargs) -> str: "ago_d": "il y a {n} j", "age_title": "âge de la page · mise à jour chaque seconde", } - # German sticky chrome only (full pack falls back to en for missing keys). - # Not used as any domains.conf default — operators may pass --lang de. - de = { - "errors": "FEHLER", - "warnings": "WARNUNGEN", - "ok": "OK", - "error_one": "{n} Fehler", - "error_many": "{n} Fehler", - "warn_one": "{n} Warnung", - "warn_many": "{n} Warnungen", - "jump_first_error": "Zum ersten Fehler", - "jump_first_warn": "Zur ersten Warnung", - "filter_errors": "Filter: Fehler + Kontext", - "filter_warns": "Filter: Warnungen + Kontext", - "filter_infos": "Filter: Info + Kontext", - "filter_oks": "Filter: OK + Kontext", - "filter_clear": "Filter loeschen · alle Zeilen", - "filter_active_err": "Filter: Fehler + Kontext", - "filter_active_warn": "Filter: Warnungen + Kontext", - "filter_active_info": "Filter: Info + Kontext", - "filter_active_ok": "Filter: nur OK + Kontext", - "filter_show_all": "Alle anzeigen", - "info_one": "{n} Info", - "info_many": "{n} Info", - "ok_one": "{n} ok", - "ok_many": "{n} ok", - "env_context": "Monitoring-Umgebung", - "env_context_title": "Aufklappen: Agent-Env, Suite-Pin, Domain-Hosts und Flags", - "env_context_empty": "Kein Lauf-Header im Log", - "generated": "erzeugt", - "version": "Version", - "version_tree_link": "Git-Baum dieses Laufs oeffnen (Commit)", - "suite_version_title": "taler-monitoring Suite-Version · genauer Lauf-Baum", - "source": "Quelle", - "what_monitors": "Was diese Seite ueberwacht", - "what_monitors_title": "Aufklappen: was diese Seite prueft", - "stack_title": "Stack-Monitoring · {host}", - "stack_summary": "{phases} · public + inside", - "mode_ok": "OK", - "mode_err": "ERR", - "mode_redirect": "REDIR", - "footer": "Konsolen-Darstellung von taler-monitoring. Sticky: gruen = OK · gelb = Warnungen · rot = Fehler.", - "ago_s": "vor {n}s", - "ago_m": "vor {n} Min.", - "ago_h": "vor {n} Std.", - "ago_d": "vor {n} T.", - "age_title": "Seitenalter · jede Sekunde aktualisiert", - } - if lang == "fr": - table = fr - elif lang == "de": - table = de - else: - table = en + table = fr if lang == "fr" else en s = table.get(key) or en.get(key) or key try: return s.format(**kwargs) @@ -498,92 +261,32 @@ def strip_ansi(s: str) -> str: return ANSI_RE.sub("", s) -def is_numbered_check_line(line: str) -> bool: - """True for real suite checks (global #NNN and/or tid like www.merchant-09). - - SUMMARY box rows look like `` [ WARN ] 2`` / `` [ WARN ] warnings only`` - and must NOT count as warn/error (v1.13.12). - """ - if re.search(r"#\d{3}\b", line): - return True - if TID_RE.search(line): - return True - return False - - def classify(line: str) -> str: u = line.upper() - low = line.lower() - # Real SUMMARY *box* only (╔/║/╚ frames or bare [ SUMMARY ] / [ RESUME ]). - # Never match free text like "perf summary" / "ladder summary" (those are INFO checks). - if re.search(r"\bSUMMARY\b", u) or re.search(r"\bRESUME\b", u): - if re.search(r"[╔║╚]", line) or re.match( - r"^\s*\[\s*(SUMMARY|RESUME)\s*\]", u - ): - return "sum-header" - # else fall through to badge classifiers (INFO/OK/…) - # Double-line box frames from section() → section (no sum-* paint) - if re.match(r"^\s*[╔╚].*═", line) or re.match(r"^\s*║\s", line): - return "section" - # EN + FR section headers (i18n_tag ERROR→ERREUR, ERRORS→ERREURS) - if ( - "--- ERRORS" in u - or "--- ERREURS" in u - or "ERRORS ·" in u - or "ERREURS ·" in u - or "ERRORS (" in u - or "ERREURS (" in u - ): + # section / summary headers before badge matching (they contain the word ERROR) + if "SUMMARY" in u or "--- ERRORS" in u or "ERRORS ·" in u or "ERRORS (" in u: return "meta" - if "numbered checks" in low: + if "numbered checks" in line.lower() or "totals:" in line.lower(): return "meta" - if "totals:" in low or "totaux :" in low or low.strip().startswith("totaux"): - return "sum-totals" - # SUMMARY verdict chrome (not a check) — keep distinct for HTML boxes - if "warnings only" in low or "avertissements seulement" in low: - return "sum-verdict-warn" - if "all clear" in low or "tout est clair" in low: - return "sum-verdict-ok" - if "failed — see" in low or "failed - see" in low or "echec — voir" in low or "échec — voir" in low: - return "sum-verdict-err" # host-agent tees converter "wrote … (errors=N …)" into the same log - if line.lstrip().lower().startswith("wrote ") and "errors=" in low: + if line.lstrip().lower().startswith("wrote ") and "errors=" in line.lower(): return "meta" # git pull / reset noise (commit subjects may contain the word ERROR) if re.match(r"\s*HEAD is now at\b", line): return "meta" if "BLOCKER" in u or "┌ BLOCKER" in u: - # SUMMARY may print " [ BLOCK ] 1" without a check id - if not is_numbered_check_line(line) and re.search( - r"[\[┌]\s*BLOCK(?:ER)?\s*[\]┐]", u - ): - return "sum-block" return "blocker" - # Only real check badges (not free-text "ERROR" inside commit messages, - # and not SUMMARY count rows like " [ ERROR ] 3"). - # French console (i18n_tag): ERROR→ERREUR, WARN→AVERT (v1.18.1). - if re.search(r"┌\s*(?:ERROR|ERREUR)\b|\[\s*(?:ERROR|ERREUR)\b", u): - if not is_numbered_check_line(line): - return "sum-err" + # Only real check badges (not free-text "ERROR" inside commit messages) + if re.search(r"┌\s*ERROR\b|\[\s*ERROR\b", u): return "error" if re.search(r"\bERROR monpages\b", line, re.I): return "error" - if re.search(r"┌\s*(?:WARN|AVERT)\b|\[\s*(?:WARN|AVERT)\b", u): - if not is_numbered_check_line(line): - return "sum-warn" + if re.search(r"┌\s*WARN\b|\[\s*WARN\b", u): return "warn" if re.search(r"┌\s*INFO\b|\[\s*INFO\b", u): - if not is_numbered_check_line(line): - return "sum-info" return "info" - if re.search(r"┌\s*OK\b|\[\s*OK\b", u) or ( - (" OK" in u or u.strip().startswith("OK")) and is_numbered_check_line(line) - ): - if re.search(r"┌\s*OK\b|\[\s*OK\b", u) and not is_numbered_check_line(line): - return "sum-ok" + if " OK" in u or "[OK" in u or "┌ OK" in u or u.strip().startswith("OK"): return "ok" - if re.search(r"[\[┌]\s*BLOCK\b", u) and not is_numbered_check_line(line): - return "sum-block" if u.strip().startswith("-- ") or u.strip().startswith("=="): return "section" return "plain" @@ -691,17 +394,6 @@ def is_summary_error_line(ln: str) -> bool: return True if "totals:" in low: return True - if "warnings only" in low or "all clear" in low: - return True - if "avertissements seulement" in low or "tout est clair" in low: - return True - if "totaux" in low and not is_numbered_check_line(ln): - return True - # SUMMARY count rows without #NNN / tid (e.g. " [ ERROR ] 3") - if re.search(r"[\[\u250c]\s*(ERROR|WARN|OK|INFO|BLOCK|ERREUR|AVERT)", ln, re.I) and not is_numbered_check_line( - ln - ): - return True # console_to_html "wrote … (errors=N warnings=M level=…)" is teed into the # host-agent log; "errors=" uppercases to "ERRORS=" and must not count as ERROR. if low.lstrip().startswith("wrote ") and "errors=" in low: @@ -719,25 +411,11 @@ def extract_errors(lines: list[str]) -> list[str]: timeout_detail = "" in_block = False for ln in lines: - u = ln.upper() - if ( - "--- ERRORS" in u - or "--- ERREURS" in u - or "ERRORS (FAILED" in u - or "ERREURS (CONTROLES" in u - or "ERREURS (FAILED" in u - or "RUN TIMEOUT · EXTRAORDINARY" in u - ): + if "--- ERRORS" in ln or "ERRORS (failed" in ln or "RUN TIMEOUT · extraordinary" in ln: in_block = True continue if in_block: - if ( - ln.strip().startswith("---") - or "[ SUMMARY" in ln - or "[ RESUME" in u - or "totals:" in ln.lower() - or "totaux :" in ln.lower() - ): + if ln.strip().startswith("---") or "[ SUMMARY" in ln or "totals:" in ln: in_block = False continue m = ERR_BULLET_RE.match(ln) @@ -747,15 +425,10 @@ def extract_errors(lines: list[str]) -> list[str]: timeout_detail = body else: errs.append(body) - elif ("ERROR" in u or "ERREUR" in u) and ln.strip() and not is_run_timeout_text(ln): + elif "ERROR" in ln.upper() and ln.strip() and not is_run_timeout_text(ln): errs.append(ln.strip()) # Only real check badges (not INFO text mentioning thresholds like "… ERROR (0=disable)") - # FR: i18n_tag ERROR→ERREUR (v1.18.1) - if ( - re.search(r"┌\s*(?:ERROR|ERREUR)\b|\[\s*(?:ERROR|ERREUR)\b", ln, re.I) - and "--- ERRORS" not in u - and "--- ERREURS" not in u - ): + if re.search(r"┌\s*ERROR\b|\[\s*ERROR\b", ln, re.I) and "--- ERRORS" not in ln: if is_run_timeout_text(ln): if "run.timeout-01" in ln.lower() or "RUN_TIMEOUT exceeded" in ln: timeout_detail = re.sub(r"\s+", " ", strip_ansi(ln)).strip() @@ -764,10 +437,8 @@ def extract_errors(lines: list[str]) -> list[str]: continue if classify(ln) not in ("error", "blocker"): continue - body = re.sub( - r"^.*\b(?:ERROR|ERREUR)\b\s*[\]┐]?\s*", "", ln, flags=re.I - ).strip(" ·") - if body and body not in errs and "failed — see" not in body.lower() and "echec — voir" not in body.lower(): + body = re.sub(r"^.*\bERROR\b\s*\]?\s*", "", ln, flags=re.I).strip(" ·") + if body and body not in errs and "failed — see" not in body.lower(): if re.search( r"#\d+|www\.|e2e\.|auth401\.|versions\.|inside\.|surface\.|aptdeploy\.", body, @@ -793,18 +464,12 @@ def extract_errors(lines: list[str]) -> list[str]: return out -def count_status( - lines: list[str], -) -> tuple[int, int, int, int, int | None, int | None, int | None, int | None]: - """Return (n_err, n_warn, n_info, n_ok, first_err, first_warn, first_info, first_ok).""" +def count_status(lines: list[str]) -> tuple[int, int, int | None, int | None]: + """Return (error_count, warn_count, first_error_idx, first_warn_idx).""" n_err = 0 n_warn = 0 - n_info = 0 - n_ok = 0 first_err: int | None = None first_warn: int | None = None - first_info: int | None = None - first_ok: int | None = None for i, ln in enumerate(lines): kind = classify(ln) if kind in ("error", "blocker"): @@ -817,15 +482,7 @@ def count_status( n_warn += 1 if first_warn is None: first_warn = i - elif kind == "info": - n_info += 1 - if first_info is None: - first_info = i - elif kind == "ok": - n_ok += 1 - if first_ok is None: - first_ok = i - return n_err, n_warn, n_info, n_ok, first_err, first_warn, first_info, first_ok + return n_err, n_warn, first_err, first_warn def slug_error(i: int, text: str) -> str: @@ -838,10 +495,6 @@ def slug_error(i: int, text: str) -> str: def render_line(ln: str, err_slugs: dict[str, str], extra_ids: list[str] | None = None) -> str: - # Drop blank log lines entirely — they only create black voids in the console - # (especially visible under warn/error filter). Anchors still attach to next real line. - if not (ln or "").strip(): - return "" kind = classify(ln) esc = html.escape(ln) for tid, slug in err_slugs.items(): @@ -856,11 +509,8 @@ def render_line(ln: str, err_slugs: dict[str, str], extra_ids: list[str] | None # HTML allows one id — join carefully id_attr = f' id="{html.escape(extra_ids[0])}"' if len(extra_ids) > 1: - # secondary anchors as empty spans prepended (inline, zero layout impact) - spans = "".join( - f'' - for x in extra_ids[1:] - ) + # secondary anchors as empty spans prepended + spans = "".join(f'' for x in extra_ids[1:]) return f'{spans}{esc}\n' return f'{esc}\n' @@ -911,9 +561,11 @@ def monitoring_scope( label = (page_label or "monitoring").lower().replace("_", "-") phases = extract_phases(log_text) host = hostname or "?" - # Resolve lang again with host/log hint (*lefrancpaysan* → fr unless LANG_SET=1) - _ex = lang if lang in ("en", "fr") else "" - lang = ui_lang(explicit=_ex, host_hint=host + " " + log_text) + # Auto-fr for FrancPaysan hosts if lang not forced + if lang == "en" and re.search(r"lefrancpaysan|francpaysan", host + " " + log_text, re.I): + import os + if not (os.environ.get("TALER_MON_LANG") or "").strip(): + lang = "fr" if "surface" in label: items = [ @@ -968,8 +620,6 @@ def monitoring_scope( ui(lang, "mm_i1"), ui(lang, "mm_i2"), ui(lang, "mm_i3"), - ui(lang, "mm_i4"), - ui(lang, "mm_i5"), ] + _pages_items(lang, host, label) return { "kind": "mattermost", @@ -1238,19 +888,6 @@ def is_log_noise_line(ln: str) -> bool: return True if "ihr branch ist" in low or "bereits auf" in low: return True - # Converter / host-agent noise that tee appends into the run log after SUMMARY - if "syntaxwarning" in low or "invalid escape sequence" in low: - return True - if "console_to_html.py:" in low: - return True - if re.match(r"^\s*if\s*\(/\^\[╔", s): - return True - if low.lstrip().startswith("wrote ") and "errors=" in low: - return True - if re.match(r"^html\s+\S+", low) and ("→" in s or "->" in s): - return True - if "public url (expected)" in low: - return True return False @@ -1271,15 +908,16 @@ def sticky_bar_html( scope: dict[str, object] | None = None, suite_version: str = "", suite_version_url: str = "", - n_info: int = 0, - n_ok: int = 0, ) -> str: level = status_level(n_err, n_warn) lang = "en" if scope and scope.get("lang"): lang = str(scope.get("lang")) else: - lang = ui_lang(host_hint=hostname or "") + lang = ui_lang() + # auto-fr for FP hostnames + if lang == "en" and re.search(r"lefrancpaysan|francpaysan", hostname or "", re.I): + lang = "fr" if level == "red": status_txt = ui(lang, "errors") @@ -1317,30 +955,6 @@ def sticky_bar_html( warn_lbl = ui(lang, "warn_many", n=n_warn) warn_stat = f'{html.escape(warn_lbl)}' - # Blue badge = INFO filter (v1.16.0) - if n_info: - info_lbl = ui(lang, "info_one", n=n_info) if n_info == 1 else ui(lang, "info_many", n=n_info) - info_stat = ( - f'{html.escape(info_lbl)}' - ) - else: - info_lbl = ui(lang, "info_many", n=n_info) - info_stat = f'{html.escape(info_lbl)}' - - # Green count badge = OK-only filter - if n_ok: - ok_lbl = ui(lang, "ok_one", n=n_ok) if n_ok == 1 else ui(lang, "ok_many", n=n_ok) - ok_stat = ( - f'{html.escape(ok_lbl)}' - ) - else: - ok_lbl = ui(lang, "ok_many", n=n_ok) - ok_stat = f'{html.escape(ok_lbl)}' - filter_chip = ( f'