Skip to content

fix: use maintained wallet-balance endpoint in star_checker#6789

Closed
zeroknowledge0x wants to merge 1 commit into
Scottcjn:mainfrom
zeroknowledge0x:fix/stale-wallet-balance-endpoint
Closed

fix: use maintained wallet-balance endpoint in star_checker#6789
zeroknowledge0x wants to merge 1 commit into
Scottcjn:mainfrom
zeroknowledge0x:fix/stale-wallet-balance-endpoint

Conversation

@zeroknowledge0x
Copy link
Copy Markdown
Contributor

Fixes #6779

Summary

check_wallet_exists() in tools/bounty_verifier/star_checker.py was calling the stale /api/balance/<wallet> route, which can report a wallet as missing even when the node's public wallet-balance endpoint is healthy.

Changes

  • Switched URL from /api/balance/<wallet> to /wallet/balance?miner_id=<wallet> (same maintained endpoint used by verifier.py)
  • Added params= dict for proper query-string encoding
  • Response validation now checks for a JSON dict containing amount_i64 rather than treating any HTTP 200 as success

Testing

  • Verified that verifier.py already uses /wallet/balance?miner_id= successfully
  • The new code mirrors the same endpoint + response-shape pattern
  • check_wallet_exists() now returns True only when the node confirms the wallet has a balance record

The check_wallet_exists() function was calling the stale
/api/balance/<wallet> route, which can report a wallet as missing
even when the node is healthy. Switch to the maintained public
endpoint /wallet/balance?miner_id=<wallet> (same as verifier.py)
and validate the response shape (dict with amount_i64 key) rather
than treating any HTTP 200 as success.

Fixes Scottcjn#6779
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Non-doc PRs have a BCOS-L1 or BCOS-L2 label
  • Doc-only PRs are exempt from BCOS tier labels when they only touch docs/**, *.md, or common image/PDF files
  • New code files include an SPDX license header
  • You've tested your changes against the live node

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!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/S PR: 11-50 lines labels Jun 2, 2026
Copy link
Copy Markdown
Contributor

@zqleslie zqleslie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — PR #6789 (fix: use maintained wallet-balance endpoint in star_checker)

Scope assessment

Single-file change in tools/bounty_verifier/star_checker.py — 20 lines (16 additions, 4 deletions). Clean BCOS-L1 fix targeting the stale /api/balance/ route used by check_wallet_exists().

What the fix does

  • Switches from /api/balance/<wallet>/wallet/balance?miner_id=<wallet>, matching the endpoint already used by verifier.py
  • Uses params= dict for safe query-string encoding (prevents injection if wallet contains special chars)
  • Replaces "any 200 = exists" heuristic with proper JSON shape validation (isinstance(body, dict) and "amount_i64" in body)

Technical review

Correctness ✅
The change aligns star_checker.py with verifier.py which already uses /wallet/balance?miner_id= successfully. The params= pattern is the correct requests idiom for query parameters.

Response validation ✅
Previous code treated any HTTP 200 as "wallet exists", which could false-positive on HTML error pages or maintenance responses. The new isinstance(body, dict) and "amount_i64" in body check ensures we only accept the expected JSON shape from the balance endpoint.

Edge cases considered:

  • Wallet address with URL-special characters → handled by params= encoding
  • Non-JSON 200 response → caught by resp.json() raising ValueError, falls to except Exception
  • Empty dict response → "amount_i64" not in body → returns False (correct, wallet not confirmed)

Missing regression tests ⚠️

The PR body mentions verification against verifier.py but doesn't include test coverage. A simple regression test would be valuable:

def test_check_wallet_exists_uses_correct_endpoint():
    with patch("star_checker.requests.get") as mock_get:
        mock_get.return_value.status_code = 200
        mock_get.return_value.json.return_value = {"amount_i64": 1000}
        assert check_wallet_exists("RTC_test_wallet") is True
        mock_get.assert_called_once()
        call_kwargs = mock_get.call_args[1]
        assert "params" in call_kwargs
        assert call_kwargs["params"]["miner_id"] == "RTC_test_wallet"

Verdict

APPROVED — Clean, targeted fix. The endpoint change is well-justified and the response validation is strictly more robust than before. Would benefit from regression tests but doesn't block merge for this size of change.


Bounty claim: Code review bounty under #73
Reviewer: zqleslie
Wallet: XKO212dF8324b9b61F294D26A6Dc68e3f81e4BE451D

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great contribution! 🔍 Reviewed and looks solid.

@Scottcjn
Copy link
Copy Markdown
Owner

Scottcjn commented Jun 2, 2026

Closing as a duplicate of #6778 (FakerHideInBush), which fixed the same star_checker wallet-exists endpoint (/api/balance/<wallet> → maintained /wallet/balance?miner_id=, Issue #6779) and was the first substantive submission (00:00 UTC). Your fix was correct too — thanks for catching it; under one-bounty-per-issue the first reviewer/fixer is credited.

@Scottcjn Scottcjn closed this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/S PR: 11-50 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Bounty verifier wallet check uses stale balance endpoint

4 participants