Fix monitor miners envelope normalization#6786
Conversation
|
CI note for reviewers:
This PR is intentionally scoped to the monitor miners-envelope normalization bug only. |
zqleslie
left a comment
There was a problem hiding this comment.
Code Review Bounty Claim — RustChain PR #6786
Bounty: #73 Code Review Bounty Program
Reviewer: zqleslie
RTC wallet: XKO212dF8324b9b61F294D26A6Dc68e3f81e4BE451D
Reviewed PR
- PR: #6786
- Review state:
APPROVED
Review performed
Reviewed the monitor miners envelope normalization fix:
-
Duplicate function removal — The earlier
normalize_miners_payloadcorrectly handles{items: [...], pagination: ...},{miners: [...]},{data: [...]}, and plain lists. The later duplicate only accepted{miners: [...]}, overwriting the correct one. Removing the duplicate restores proper envelope handling. -
print_miners guard — Changed from
if miners is Nonetoif not isinstance(miners, list). This is safer because the normalizer can return the original dict (e.g.,{"pagination": {"total": 0}}) when there are no miners, and the old check would try to iterate a dict. -
Diff size — +1/-7 in 1 file. Minimal, correct, no side effects.
-
Validation — The inline Python check in the PR body covers the three envelope shapes. No need for local pytest since the function is pure Python with no Flask deps.
No blocking issues found. Safe to merge.
This is a claim only. No payout asserted here.
MolhamHamwi
left a comment
There was a problem hiding this comment.
Reviewed current head 7a88e487f7cc0c97d6ee5a3d75b4b64d94a69f66 for the monitor miner envelope normalization fix.
Specific observations:
- Removing the later duplicate
normalize_miners_payload()definition lets the earlier broader normalizer stay in effect, so all three expected shapes are handled: a raw list,{ "miners": [...] }, and the current{ "items": [...], "pagination": ... }API envelope. - The
print_miners()guard now checksnot isinstance(miners, list)instead of onlyNone, which keeps unexpected scalar/object payloads in the warning path while still accepting an empty miner list as a valid zero-miner response. - The patch is minimal and does not alter request routing, display formatting, or health/epoch behavior; it only restores the intended normalization path for
/api/minersresponses.
Validation performed locally:
python3 -m py_compile tools/rustchain-monitor/rustchain_monitor.py- Loaded
tools/rustchain-monitor/rustchain_monitor.pyand verifiednormalize_miners_payload()returns lists for raw-list,miners, anditemspayloads.
No blocking issues found. I received RTC compensation for this review.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! 🔍 Reviewed and looks solid.
❌ This reintroduces a NameError (same bug as #6711)The diff deletes miners = normalize_miners_payload(data) # <- function no longer defined
if not isinstance(miners, list):So To fix: either keep the function, or inline it at the call site, e.g.: if isinstance(data, list):
miners = data
elif isinstance(data, dict) and isinstance(data.get('miners'), list):
miners = data['miners']
else:
print(f'⚠ Unexpected response: {data}')
returnHappy to merge once the call site no longer references the deleted function. |
Fixes a RustChain monitor bug where the correct
/api/minersenvelope normalizer was immediately overwritten by a second narrowernormalize_miners_payloaddefinition.Before:
get_miners()could fetch the current API shape{ "items": [...], "pagination": ... }{ "miners": [...] }tests/test_rustchain_monitor.py::test_request_helpers_call_expected_endpointsfailedWhat changed:
miners,data, anditemsenvelopesprint_minerscheck for a normalized list explicitly before printing rowsValidation:
Local note:
python3 -m pytest tests/test_rustchain_monitor.py -qis blocked in this local environment before reaching the test file becausetests/conftest.pyimports the integrated Flask node and Flask is not installed locally. Hosted CI installs Flask in.github/workflows/ci.yml.