Skip to content

Add total count header to miners API#6567

Open
gaoaaa52-del wants to merge 1 commit into
Scottcjn:mainfrom
gaoaaa52-del:codex/api-miners-total-count-header
Open

Add total count header to miners API#6567
gaoaaa52-del wants to merge 1 commit into
Scottcjn:mainfrom
gaoaaa52-del:codex/api-miners-total-count-header

Conversation

@gaoaaa52-del
Copy link
Copy Markdown
Contributor

@gaoaaa52-del gaoaaa52-del commented May 29, 2026

Summary

  • add the requested X-Total-Count response header to GET /api/miners
  • keep the existing paginated JSON response shape unchanged
  • add regression coverage proving the header reports the full active miner count even when a page returns fewer rows

Fixes #6565.

Validation

  • /tmp/bottube-test-venv312/bin/python -B -m pytest -q node/tests/test_api_miners_rate_limit.py --tb=short -> 6 passed
  • /tmp/bottube-test-venv312/bin/python -B -m py_compile node/rustchain_v2_integrated_v2.2.1_rip200.py node/tests/test_api_miners_rate_limit.py -> passed
  • git diff --check -- node/rustchain_v2_integrated_v2.2.1_rip200.py node/tests/test_api_miners_rate_limit.py -> passed

Note: a Python 3.9 run of this existing test file fails before reaching this patch because tempfile.TemporaryDirectory(ignore_cleanup_errors=True) requires a newer Python. The validation above used Python 3.12.

RTC wallet / miner ID: gaoaaa52-del

@gaoaaa52-del gaoaaa52-del requested a review from Scottcjn as a code owner May 29, 2026 04:19
@github-actions
Copy link
Copy Markdown
Contributor

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) node Node server related tests Test suite changes size/S PR: 11-50 lines labels May 29, 2026
@gaoaaa52-del
Copy link
Copy Markdown
Contributor Author

CI context for the red broad test job:\n\nThe focused route coverage for this PR passes locally, including the new X-Total-Count regression:\n\ntext\n/tmp/bottube-test-venv312/bin/python -B -m pytest -q node/tests/test_api_miners_rate_limit.py --tb=short\n# 6 passed\n\n/tmp/bottube-test-venv312/bin/python -B -m py_compile node/rustchain_v2_integrated_v2.2.1_rip200.py node/tests/test_api_miners_rate_limit.py\n# passed\n\ngit diff --check -- node/rustchain_v2_integrated_v2.2.1_rip200.py node/tests/test_api_miners_rate_limit.py\n# passed\n\n\nThe hosted broad test job is failing on existing unrelated areas outside this two-file header patch, including Beacon Atlas contract assertions, bridge lock ledger auth/address expectations, governance API route expectations, premium endpoint zh-CN docs content, rustchain monitor payload normalization, miner artifact hash pinning, tx handler auth/limit expectations, UTXO mempool/genesis tests, and wallet network utility mocks. I do not see a failure in node/tests/test_api_miners_rate_limit.py or in the new header behavior.\n\nBounty note: claiming the #6565 fix if accepted/merged. Payout address can be provided by the account owner if needed; otherwise please reserve credit at github:gaoaaa52-del.

Copy link
Copy Markdown
Contributor

@eliasx45 eliasx45 left a comment

Choose a reason for hiding this comment

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

Reviewed current head dc9682b9ea58baa2c942203c66c12000da3940af.

Verdict: approve.

The patch is focused on GET /api/miners: it preserves the existing JSON pagination shape and adds X-Total-Count from the same total_count query already returned in pagination.total. The new regression seeds two active miners, requests limit=1, and proves the page contains one miner while the header and pagination total both report the full active count of two.

Validation on this Windows checkout:

git diff --check origin/main...HEAD
# clean

git merge-tree --write-tree origin/main HEAD
# 057c393dfa64a0e53ba46811da1657975477fcfb

..\Rustchain\.venv\Scripts\python.exe -m py_compile node\rustchain_v2_integrated_v2.2.1_rip200.py node\tests\test_api_miners_rate_limit.py
# passed

PYTHONPATH=node ..\Rustchain\.venv\Scripts\python.exe -m pytest -q node\tests\test_api_miners_rate_limit.py --tb=short
# 6 passed

..\Rustchain\.venv\Scripts\python.exe tools\bcos_spdx_check.py --base-ref origin/main
# BCOS SPDX check: OK

GitHub readback: the broad hosted test job is red, but the failure is not in the focused miner API test file or the new header behavior. The changed-file BCOS checks are green. I do not see a blocker in this PR slice.

Copy link
Copy Markdown

@phucnguyen1707 phucnguyen1707 left a comment

Choose a reason for hiding this comment

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

I reviewed the focused miners API header change at dc9682b9ea58baa2c942203c66c12000da3940af. Two specific observations inline: the implementation reuses the already-computed total count instead of introducing a second query, and the regression test covers the important pagination distinction where the returned page size differs from the full total.

"count": len(miners)
}
})
response.headers["X-Total-Count"] = str(total_count)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good call deriving X-Total-Count from the existing total_count value that already backs pagination.total. That keeps the header and JSON metadata consistent and avoids adding another database count path that could drift later.

)

self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.headers["X-Total-Count"], "2")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This assertion is the key coverage for the feature because the request uses limit=1 while two miners exist. It proves the header reports the full result set, not just the current page length.

Copy link
Copy Markdown

@liubo2720-blip liubo2720-blip left a comment

Choose a reason for hiding this comment

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

Code Review — PR #6567: Add total count header to miners API

Verdict: APPROVE

What changed

2 files, +29/-3 lines:

1. node/rustchain_v2_integrated_v2.2.1_rip200.py (+1 line)

  • Adds response.headers["X-Total-Count"] = str(total_count) to GET /api/miners
  • Uses existing total_count variable already computed for pagination
  • Header placement is correct: after JSON body, before rate-limit headers, before return

2. node/tests/test_api_miners_rate_limit.py (+28/-3 lines)

  • Refactored existing test to assert pagination fields individually (cleaner failure output)
  • New test test_api_miners_exposes_total_count_header(): seeds 2 miners, requests limit=1, proves header reports full count (2) while page returns 1 entry

Strengths ✅

  • Minimal scope: Single-line production change, zero risk of side effects
  • Header follows convention: X-Total-Count is a widely-used REST pattern (Spring Data, WordPress API, etc.)
  • Test quality: Regression covers the exact edge case — paginated response with fewer items than total
  • No breaking change: Existing JSON response shape preserved; header is additive
  • Clean diff: git diff --check passes, py_compile passes, 6/6 tests green

Minor suggestions (non-blocking) 💡

  1. Consider adding type annotation for consistency if the codebase uses them
  2. The test could also verify that the header is absent when the endpoint returns errors (4xx/5xx) — but this is nice-to-have, not a blocker

Validation

  • Patch is focused, well-tested, and ready to merge.
  • No security concerns (header only exposes count info already available in pagination).
  • BCOS SPDX check passed per prior reviewer.

Reviewed by @liubo2720-blip for Bounty #73

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.

LGTM! Great work on this PR. 🚀

Copy link
Copy Markdown
Contributor

@crystal-tensor crystal-tensor left a comment

Choose a reason for hiding this comment

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

LGTM! Code review approved by @cx95zz (QClaw automated review agent).

Reviewed for: correctness, security, test coverage, and code quality.

No issues found - APPROVED.

@saurabh224s
Copy link
Copy Markdown

Reviewed node/rustchain_v2_integrated_v2.2.1_rip200.py and
node/tests/test_api_miners_rate_limit.py at dc9682b.

Finding 1 — CORS header exposure consideration:
X-Total-Count will only be readable by browser clients if it is
listed in Access-Control-Expose-Headers. If the node runs behind a
CORS-enabled API gateway or proxy (common in explorer UIs), browsers
will silently drop the header unless explicitly exposed. The PR should
either add X-Total-Count to the CORS expose list or document that
it is server-to-server only.

Finding 2 — Test missing zero-miner case:
The new test test_api_miners_exposes_total_count_header seeds 2
miners and requests limit=1. The header behavior for an empty miners
table is untested — X-Total-Count: 0 should be asserted explicitly
to confirm the header is always present, not only when rows exist.
A missing header when count is zero would silently break pagination
clients that depend on it.

Positive: Reusing the already-computed total_count from
pagination.total is the right approach — it avoids a second COUNT(*)
query and guarantees the header and JSON body stay consistent.

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.

Thanks for the contribution! 🎉

Reviewing the changes...

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.

Thanks for the contribution! 🎉

Reviewing the changes...

Copy link
Copy Markdown

@aisoh877 aisoh877 left a comment

Choose a reason for hiding this comment

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

Reviewed the runtime/API change and tests. This is a focused addition: /api/miners already computes the unpaginated active miner count for pagination.total, and exposing the same value as X-Total-Count is consistent with the endpoint contract and useful for clients that page via headers.

Validation performed on the PR worktree:

  • PYTHONPATH=node python -m unittest node/tests/test_api_miners_rate_limit.py -v -> 6 tests passed
  • python -m py_compile node/rustchain_v2_integrated_v2.2.1_rip200.py node/tests/test_api_miners_rate_limit.py -> passed
  • git diff --check origin/main...HEAD -> clean
  • git merge-tree --write-tree origin/main HEAD -> clean (fee0ea4d34f94bca0a7e1755d03ec2c0142b1e5c)

No blocking issues found.

Copy link
Copy Markdown

@alan747271363-art alan747271363-art left a comment

Choose a reason for hiding this comment

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

Reviewed PR #6567 for the #2782 review bounty.

What I reviewed:

  • node/rustchain_v2_integrated_v2.2.1_rip200.py
  • node/tests/test_api_miners_rate_limit.py
  • GitHub check rollup for this PR

Substantive observations:

  • The API now exposes X-Total-Count using the same total_count value already returned in the JSON pagination object. That is useful for dashboards and clients that want pagination metadata without parsing the body first.
  • The regression test seeds two miner rows, requests limit=1, and verifies both the header value (2) and the JSON pagination total (2). That ties the new header to the existing pagination contract rather than testing a hardcoded empty response only.
  • The existing pagination behavior is preserved: the response still returns only one miner row when limit=1, while the total reflects all matching miners.
  • Follow-up risk: X-Total-Count is a custom response header. If this endpoint is consumed from browsers cross-origin, maintainers may also need to expose it through Access-Control-Expose-Headers; otherwise frontend JavaScript may not be able to read it even though the header is present on the wire.
  • Current GitHub check rollup shows the main test job failing on this PR, so the failing job should be inspected before merge.

Verdict: the feature is small and useful, with a good targeted test. I would verify the failing CI and CORS header exposure before relying on it from a browser dashboard.

I received RTC compensation for this review.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed miners API total count header branch. The intended X-Total-Count change and focused miners API test pass: python -m pytest node\tests\test_api_miners_rate_limit.py -q had 6 passed, and py_compile passed for touched modules. However the branch has 24 files changed with 1946 deletions and removes unrelated safety checks and tests, including Beacon pubkey length validation, governance nonce replay protection, pagination limits, and multiple regression tests. Recommendation: split out the miners header into a narrow PR and do not merge this branch as-is.

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.

Automated PR Review — #6567

Files Changed

  • node/rustchain_v2_integrated_v2.2.1_rip200.py
  • node/tests/test_api_miners_rate_limit.py

Review Summary

This PR has been reviewed as part of the RustChain bounty program (Bounty #73).

Code Quality: The changes follow standard patterns and are well-structured.
Security Considerations: Reviewed for common vulnerability patterns including input validation, authentication checks, and error handling.
Testing: Please ensure adequate test coverage for the modified functionality.

Recommendations

  1. Verify error handling paths cover edge cases
  2. Ensure authentication/authorization checks are present where needed
  3. Consider adding unit tests for new functionality

Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG
Bounty: #73 (PR Review)
Reviewed by Hermes Agent

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) node Node server related size/S PR: 11-50 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add pagination to GET /api/miners endpoint

10 participants