fix(monitoring): prefer latest reserve_pub for force-select
This commit is contained in:
parent
c591bd9076
commit
f99604261a
1 changed files with 32 additions and 24 deletions
|
|
@ -346,16 +346,17 @@ for AMT in "$@"; do
|
||||||
"${BANK}/accounts/${EXP_USER}/withdrawals/${WID}/confirm"
|
"${BANK}/accounts/${EXP_USER}/withdrawals/${WID}/confirm"
|
||||||
}
|
}
|
||||||
extract_rpub() {
|
extract_rpub() {
|
||||||
|
# Prefer *last* match (current withdraw), not first (stale from older accepts/tx).
|
||||||
python3 -c '
|
python3 -c '
|
||||||
import re, sys, json
|
import re, sys, json
|
||||||
paths = sys.argv[1:]
|
paths = sys.argv[1:]
|
||||||
|
found = []
|
||||||
blob = ""
|
blob = ""
|
||||||
for p in paths:
|
for p in paths:
|
||||||
try:
|
try:
|
||||||
blob += open(p, errors="replace").read() + "\n"
|
blob += open(p, errors="replace").read() + "\n"
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
# JSON fields
|
|
||||||
for pat in (
|
for pat in (
|
||||||
r"\"reserve_pub\"\s*:\s*\"([A-Z0-9]+)\"",
|
r"\"reserve_pub\"\s*:\s*\"([A-Z0-9]+)\"",
|
||||||
r"\"reservePub\"\s*:\s*\"([A-Z0-9]+)\"",
|
r"\"reservePub\"\s*:\s*\"([A-Z0-9]+)\"",
|
||||||
|
|
@ -363,29 +364,26 @@ for pat in (
|
||||||
r"reservePub[\"\s:=]+([A-Z0-9]{40,})",
|
r"reservePub[\"\s:=]+([A-Z0-9]{40,})",
|
||||||
r"reserve[_ ]?pub[\"=: ]+([A-Z0-9]{40,})",
|
r"reserve[_ ]?pub[\"=: ]+([A-Z0-9]{40,})",
|
||||||
):
|
):
|
||||||
m = re.search(pat, blob, re.I)
|
found.extend(m.group(1) for m in re.finditer(pat, blob, re.I))
|
||||||
if m:
|
def walk(o):
|
||||||
print(m.group(1))
|
if isinstance(o, dict):
|
||||||
raise SystemExit
|
for k, v in o.items():
|
||||||
# line-wise JSON
|
if k.lower() in ("reserve_pub", "reservepub") and isinstance(v, str) and len(v) >= 40:
|
||||||
|
found.append(v)
|
||||||
|
walk(v)
|
||||||
|
elif isinstance(o, list):
|
||||||
|
for i in o:
|
||||||
|
walk(i)
|
||||||
for line in blob.splitlines():
|
for line in blob.splitlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line.startswith("{"):
|
if not line.startswith("{"):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
d = json.loads(line)
|
walk(json.loads(line))
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
pass
|
||||||
def walk(o):
|
if found:
|
||||||
if isinstance(o, dict):
|
print(found[-1])
|
||||||
for k, v in o.items():
|
|
||||||
if k.lower() in ("reserve_pub", "reservepub") and isinstance(v, str) and len(v) >= 40:
|
|
||||||
print(v); raise SystemExit
|
|
||||||
walk(v)
|
|
||||||
elif isinstance(o, list):
|
|
||||||
for i in o:
|
|
||||||
walk(i)
|
|
||||||
walk(d)
|
|
||||||
' "$@" 2>/dev/null || true
|
' "$@" 2>/dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,10 +391,11 @@ for line in blob.splitlines():
|
||||||
local st_now="$1"
|
local st_now="$1"
|
||||||
[ "$st_now" = "pending" ] || [ -z "$st_now" ] || return 0
|
[ "$st_now" = "pending" ] || [ -z "$st_now" ] || return 0
|
||||||
local rpub epayto code_fs
|
local rpub epayto code_fs
|
||||||
rpub=$(extract_rpub "$SCRATCH/accept-$tag.out" "$SCRATCH/tx-$tag.json")
|
# current accept only first — avoid reusing reserve from previous rungs via tx dump
|
||||||
|
rpub=$(extract_rpub "$SCRATCH/accept-$tag.out")
|
||||||
if [ -z "$rpub" ]; then
|
if [ -z "$rpub" ]; then
|
||||||
wcli transactions >"$SCRATCH/tx-$tag.json" 2>&1 || true
|
wcli transactions >"$SCRATCH/tx-$tag.json" 2>&1 || true
|
||||||
rpub=$(extract_rpub "$SCRATCH/accept-$tag.out" "$SCRATCH/tx-$tag.json")
|
rpub=$(extract_rpub "$SCRATCH/tx-$tag.json")
|
||||||
fi
|
fi
|
||||||
epayto=$(curl -sS -m 10 "${EX%/}/keys" 2>/dev/null | python3 -c '
|
epayto=$(curl -sS -m 10 "${EX%/}/keys" 2>/dev/null | python3 -c '
|
||||||
import json,sys
|
import json,sys
|
||||||
|
|
@ -414,7 +413,16 @@ else:
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d "{\"reserve_pub\":\"${rpub}\",\"selected_exchange\":\"${epayto}\"}" \
|
-d "{\"reserve_pub\":\"${rpub}\",\"selected_exchange\":\"${epayto}\"}" \
|
||||||
"${BANK}/taler-integration/withdrawal-operation/${WID}" 2>/dev/null || echo "000")
|
"${BANK}/taler-integration/withdrawal-operation/${WID}" 2>/dev/null || echo "000")
|
||||||
info "force-select" "HTTP ${code_fs} rpub=${rpub:0:12}…"
|
# 409: conflict (wrong/stale reserve, or already bound) — log body once, keep polling
|
||||||
|
if [ "$code_fs" = "409" ]; then
|
||||||
|
if [ "${FORCE_SEL_409_LOGGED:-0}" != "1" ]; then
|
||||||
|
info "force-select" "HTTP 409 rpub=${rpub:0:12}… body=$(tr '\n' ' ' <"$SCRATCH/force-sel-$tag.json" | head -c 160)"
|
||||||
|
FORCE_SEL_409_LOGGED=1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
info "force-select" "HTTP ${code_fs} rpub=${rpub:0:12}…"
|
||||||
|
FORCE_SEL_409_LOGGED=0
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
_rpub_empty=no
|
_rpub_empty=no
|
||||||
[ -z "$rpub" ] && _rpub_empty=yes
|
[ -z "$rpub" ] && _rpub_empty=yes
|
||||||
|
|
@ -452,13 +460,13 @@ else:
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# aggressive force-select while pending (no run-until-done)
|
# force-select while pending (no run-until-done); avoid spam on repeated 409
|
||||||
if [ "$st" = "pending" ] || [ -z "$st" ]; then
|
if [ "$st" = "pending" ] || [ -z "$st" ]; then
|
||||||
if [ "$i" -eq 1 ] || [ $((i % 3)) -eq 0 ]; then
|
if [ "$i" -eq 1 ] || [ "$i" -eq 2 ] || [ $((i % 5)) -eq 0 ]; then
|
||||||
force_select_if_needed "$st"
|
force_select_if_needed "$st"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
sleep 0.4
|
sleep 0.35
|
||||||
done
|
done
|
||||||
ms_confirm=$(elapsed_ms "$t0")
|
ms_confirm=$(elapsed_ms "$t0")
|
||||||
st=$(printf '%s' "${st:-}" | tr -d '\r\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
st=$(printf '%s' "${st:-}" | tr -d '\r\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue