fix(#7063): poll /wallet/balances/all with X-Admin-Key for large_tx events#7586
fix(#7063): poll /wallet/balances/all with X-Admin-Key for large_tx events#7586Yzgaming005 wants to merge 1 commit into
Conversation
…rge_tx events
The webhook dispatcher's large_tx detector was polling /api/balances,
which the live node no longer exposes (the unauthenticated route was
removed in favour of the admin-gated /wallet/balances/all endpoint).
As a result, the large_tx event was silently dead and operators only
saw 404s in the poller logs.
Changes:
- Add RUSTCHAIN_ADMIN_KEY + RUSTCHAIN_BALANCES_PATH env defaults and
--admin-key/--balances-path CLI flags so the dispatcher can authenticate.
- Plumb admin_key + balances_path into RustChainPoller; the existing
balances_path default (/wallet/balances/all) is overridable so future
endpoint renames are a config change, not a code change.
- Skip the poll gracefully when RUSTCHAIN_ADMIN_KEY is empty instead of
hammering an unauthenticated surface that returns 503.
- Accept both the canonical envelope ({"balances": [...], "total_*": ...})
and the legacy bare-list response, with miner_id/miner and
amount_rtc/amount_i64/balance/amount field fallbacks.
- Extend _get to forward optional headers (X-Admin-Key) without breaking
the other poller call sites.
- Add 11 focused unit tests covering: admin key gate, header injection,
envelope vs. legacy response shape, threshold/credit/debit dispatch,
malformed entries, unexpected shapes, and HTTP failure handling.
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
|
Test Results & Manual Verification 11 new tests cover: admin-key gate, header injection, envelope + legacy response, credit/debit dispatch, threshold skip, malformed entries, unexpected shapes, HTTP failure. All pre-existing webhook tests still pass (no regressions). Key design decisions:
Looking forward to the review. 🙏 |
jaxint
left a comment
There was a problem hiding this comment.
✅ Code reviewed - implementation verified. Changes align with project standards.
|
⏸️ CI status note — the only red is Unblocking: PR #7568 (chore(ci): refresh fetchall baseline for #7502) fixes the baseline and is ready for review. Once it lands, a rebase here will clear CI. Will rebase this PR as soon as #7568 is merged. No action needed on the diff itself. — Yzgaming005 |
jaxint
left a comment
There was a problem hiding this comment.
✅ Code reviewed - implementation verified.
Summary
The webhook dispatcher's
large_txdetector was polling/api/balances,which the live RustChain node no longer exposes — the unauthenticated
route was removed in favour of the admin-gated
/wallet/balances/allendpoint (X-Admin-Key header). As a result, the
large_txevent wassilently dead and operators only saw 404s in the poller logs.
This change wires the poller up to the new endpoint with proper auth,
while staying backward-compatible with operators that have not (yet)
configured an admin key: the poll is skipped gracefully with a debug
log instead of hammering an unauthenticated surface that returns 503.
Changes
tools/webhooks/webhook_server.py(+74 / −13)RustChainPollergainsadmin_keyandbalances_pathconstructorparameters (both overridable for tests and future endpoint renames).
_getnow forwards optionalheaders=so per-call auth can beinjected without breaking the other poller call sites
(
/headers/tip,/api/stats,/api/miners)._check_large_tx:RUSTCHAIN_ADMIN_KEYis empty(so existing operators don't see noisy 503/401 on every cycle),
balances_pathwithX-Admin-Key: <key>,{"balances": [{"miner_id", "amount_i64", "amount_rtc"}, ...], "total_i64", "total_rtc"},on older nodes,
amount_rtc→amount_i64→balance→amountfor thenumeric value, casting safely to
floatand skipping non-numericrows instead of crashing the poller thread.
RUSTCHAIN_ADMIN_KEY→--admin-key,RUSTCHAIN_BALANCES_PATH→--balances-path(default
/wallet/balances/all).tools/webhooks/test_webhook_server.py(+207 / −3)envelope vs. legacy response shape, threshold/credit/debit
dispatch, malformed entries, unexpected shapes, and HTTP failure
handling.
Why this approach
(
_get) and detection (_check_large_tx); extending both withopt-in parameters keeps the change additive and lets the other
detectors keep using unauthenticated endpoints unchanged.
backward-compatible: an operator that has not configured
RC_ADMIN_KEYon the node will see the same behaviour as before(no
large_txevents, no noisy 503s in the logs) and can flipthe new env var on at their own pace.
/wallet/balances/allcontract (already used byrustchain_exporter,auto-pay.py, and the admin key testsuite) and any older deployment that still returns a bare list, so
rolling out a node upgrade isn't required to unblock operators on
a stale build.
_get's newheaders=parameter is a small, named change thatfuture endpoints with non-empty auth headers can also use without
re-introducing the same pattern.
Testing
pytest tools/webhooks/test_webhook_server.py -v→ 15/15 pass(4 pre-existing + 11 new for
#7063).pytest tools/webhooks/ tests/test_webhook_admin_auth.py tests/test_webhook_server_helpers.py tests/test_webhook_client_helpers.py test_webhook_client.py→51/51 pass, no regressions in the existing webhook surface.
Manual verification
node/rustchain_v2_integrated_v2.2.1_rip200.py(
api_wallet_balances_all) and that its contract is{"balances": [{"miner_id", "amount_i64", "amount_rtc"}, ...]}withX-Admin-Keyenforcement + 503ADMIN_KEY_UNSETwhenRC_ADMIN_KEYis empty (see
tests/test_wallet_transfer_admin_key_unset.py).git log --oneline -1on the branch:5edcd86b fix(#7063): poll /wallet/balances/all with X-Admin-Key for large_tx events.touched.
Trade-offs
node/rustchain_v2_active.py/deprecated/old_nodes/*copies — the dispatcher intools/webhooks/always talks to whichever node URL the operator points it at
(
RUSTCHAIN_NODE/--node), so updating the dispatcher issufficient; the legacy node files are out of scope for
#7063.RUSTCHAIN_ADMIN_KEY,RUSTCHAIN_BALANCES_PATH)follow the existing operator-config style in this file (see
RUSTCHAIN_NODE,WEBHOOK_POLL_INTERVAL,LARGE_TX_THRESHOLD)rather than a separate config file. If maintainers prefer a
config.yamlstyle, I'm happy to refactor in a follow-up.Closes #7063