Skip to content

fix(windows-miner): surface the node diagnostic and stop hot-retrying rejected headers in the packaged miner (#7368) - #8648

Open
DSP-AID wants to merge 2 commits into
Scottcjn:mainfrom
DSP-AID:fix/windows-installer-header-retry-7368
Open

DSP-AID wants to merge 2 commits into
Scottcjn:mainfrom
DSP-AID:fix/windows-installer-header-retry-7368

Conversation

@DSP-AID

@DSP-AID DSP-AID commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

What Changed

miners/windows/installer/src/rustchain_windows_miner.py is the copy that installer/build_miner.py and RustChainMiner.spec compile into the shipped Windows executable. It still carried the pre-#7368 behavior even though the standalone miners/windows/rustchain_windows_miner.py was fixed:

  • submit_header() returned a bare False, so the node's rejection body was thrown away;
  • _mine_loop() resubmitted the same rejected lottery slot on every poll (every 10 s for the whole eligibility window) — an endless silent retry loop;
  • --headless printed only [share] submitted=N accepted=M FAIL, and the failure event carried no reason at all.

This PR applies the same design the standalone miner already uses, to the packaged copy:

  1. Server diagnostic surfaced — last_header_error is built with the file's existing _response_diagnostic() helper (HTTP <status> plus code=/error=/message=, or body=<first 240 chars> for non-JSON), and a new _format_headless_event() prints it verbatim in headless mode (same line shape as the standalone miner).
  2. No hot-retry of a known-rejected header — the lottery slot from /lottery/eligibility is recorded in _last_submitted_slot on success and on terminal rejection; _header_submission_due(slot) gates the loop, so a rejected slot is never resubmitted.
  3. Retryable vs non-retryable — connection failures plus 5xx and 408/425/429 are retryable and get bounded exponential backoff (10 s base, doubling with jitter, 300 s cap); anything else (400 malformed header, 403 bad signature / unknown pubkey) is terminal: the log says class=terminal no_retry and no further POST goes out for that slot.

What the miner sends is untouched — same URL, json=header, timeout=5, verify=TLS_VERIFY. Only how it handles the answer changes.

Reproduction against a real node (not mocked)

Both copies (pre-fix from upstream/main, post-fix from this branch) were driven through their real _mine_loop against https://rustchain.org in Docker python:3.11-bookworm, wallet RTC02811ff5e2bb4bb4b95eee44c5429cd9525496e7, live lottery slot 49030 for the whole window. Header POSTs are genuine HTTPS requests; the rejection text is the node's own bytes — the node answers this unsigned legacy payload with HTTP 400 {"error":"missing fields","ok":false}.

Two seams, both disclosed: eligibility keeps the live node call and the live slot but forces eligible=true (the public node answers not_attested for this test wallet), and time.sleep is shortened from the real 10 s poll to 2 s so the transcript is readable — retry scheduling still uses real wall-clock time.

=== BEFORE fix (upstream/main) | mode=terminal | node=https://rustchain.org ===
  08:07:56 [share] submitted=1 accepted=0 FAIL
  08:07:59 [share] submitted=2 accepted=0 FAIL
  08:08:02 [share] submitted=3 accepted=0 FAIL
  08:08:05 [share] submitted=4 accepted=0 FAIL
  -> eligibility: slot=49030 reason=not_attested; polls=4; header POSTs=4 at ['08:07:56', '08:07:59', '08:08:01', '08:08:04']

=== AFTER fix (this PR) | mode=terminal | node=https://rustchain.org ===
  08:08:08 [share] slot=49030 submitted=1 accepted=0 FAIL error=HTTP 400 error=missing fields class=terminal no_retry
  -> eligibility: slot=49030 reason=not_attested; polls=4; header POSTs=1 at ['08:08:07']

=== BEFORE fix (upstream/main) | mode=blip | node=http://127.0.0.1:9 ===
  08:08:18 [share] submitted=1 accepted=0 FAIL
  ... 8 identical FAIL lines, one per poll ...
  -> polls=8; header POSTs=8 at ['08:08:18', '08:08:20', '08:08:23', '08:08:25', '08:08:28', '08:08:30', '08:08:33', '08:08:35']
  -> pre-fix event keys on failure: ['accepted', 'submitted', 'success', 'type']   # no reason field at all

=== AFTER fix (this PR) | mode=blip | node=http://127.0.0.1:9 ===
  08:08:38 [share] slot=49030 submitted=1 accepted=0 FAIL error=header request failed: HTTPConnectionPool(... port=9): ... [Errno 111] Connection refused ... class=retryable retry_in=10.6s
  08:08:50 [share] slot=49030 submitted=2 accepted=0 FAIL error=header request failed: HTTPConnectionPool(... port=9): ... [Errno 111] Connection refused ... class=retryable retry_in=15.9s
  -> polls=8; header POSTs=2 at ['08:08:38', '08:08:50']

Reading of it: pre-fix, a node rejection produced four POSTs (08:07:56 / :59 / 08:08:01 / 08:08:04) and the reason never reached the operator. Post-fix there is exactly one POST (08:08:07) for slot 49030, the node's own missing fields body on the log line, and nothing resent for that slot. The connection-refused case shows the opposite classification: pre-fix 8 POSTs at ~2.4 s spacing, post-fix 2 POSTs with a growing gap (retry_in=10.6s, then retry_in=15.9s).

Acceptance criteria (bounty #16252)

  • Reproduction in PR description: before-fix silent retry loop, after-fix diagnostic + backoff (transcript above).
  • No unchanged-header resubmission on non-retryable rejection — log/POST timestamps above (4 POSTs → 1 POST for the same slot), plus a test that counts POSTs across three eligible polls.
  • Tested against a real node endpoint (https://rustchain.org, live slot, node's own 400 body) — not only mocks; 6 hermetic regression tests complement it.
  • PR closes Windows headless miner retries a rejected header every poll and hides the server diagnostic #7368.

Testing / Evidence

Docker python:3.11-bookworm on the Linux runner, fresh clone of this branch:

$ python -m pytest -q tests/test_windows_installer_headless_rejected_header_retry.py \
    tests/test_windows_installer_tkinter_fallback.py \
    tests/test_windows_headless_rejected_slot_retry.py \
    tests/test_windows_headless_lifecycle_logging.py \
    tests/test_windows_miner_chain_identity.py \
    tests/test_windows_miner_python39_annotations.py \
    tests/test_windows_config_manager_py_compile.py
29 passed in 1.02s

$ ruff check --select E9,F63,F7,F82 miners/windows/installer/src/rustchain_windows_miner.py \
    tests/test_windows_installer_headless_rejected_header_retry.py
All checks passed!

$ python -m py_compile miners/windows/installer/src/rustchain_windows_miner.py   # clean

On the actual target platform (Windows, Python 3.12.5): pytest -q over the same files → 24 passed, ruff check --select E9,F63,F7,F82 clean.

New file tests/test_windows_installer_headless_rejected_header_retry.py (6 tests) covers: terminal rejection marks the slot handled and keeps the diagnostic; 403 terminal vs 408/429/500/503 retryable; connection failure backs off 10 s → 20 s and never exceeds the 300 s cap; success clears retry state; _mine_loop issues exactly one POST across three eligible polls; the headless line carries the diagnostic plus its retry class.

BCOS Checklist (Required For Non-Doc PRs)

  • Add a tier label: BCOS-L1 — fork contributors cannot set upstream labels, so it is requested here.
  • SPDX header (# SPDX-License-Identifier: MIT) at the top of the new test file.
  • Test evidence (commands + output above, plus the live-node transcript).

Closes #7368

Bounty: Scottcjn/rustchain-bounties#16252 — 12 RTC
RTC wallet for payout: RTC6m7xQJ9Fj8sE2vD1gYp4tN3uW8zK5rB

…ected headers in the packaged miner

The copy compiled into RustChainMiner.exe (installer/src/rustchain_windows_miner.py) kept the pre-Scottcjn#7368 behavior: submit_header returned a bare False, so the node reason was discarded and _mine_loop resubmitted the same rejected slot every poll. Terminal rejections now mark the slot handled and log the server body verbatim; temporary failures get bounded exponential backoff (10s base, 300s cap). Adds regression tests for the packaged copy.
@github-actions

github-actions Bot commented Nov 8, 2026

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 size/L PR: 201-500 lines BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) tests Test suite changes and removed size/L PR: 201-500 lines labels Nov 8, 2026
@DSP-AID

DSP-AID commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Fresh verification — 2026-11-09 (no code change since opening; head is still 3f5408e3)

Unit tests + lint — Windows host, Python 3.12.5 (the target platform for RustChainMiner.exe):

ruff check --select E9,F63,F7,F82 miners/windows/installer/src/rustchain_windows_miner.py tests/test_windows_installer_headless_rejected_header_retry.py
  -> All checks passed!
python -m py_compile miners/windows/installer/src/rustchain_windows_miner.py -> clean
pytest -q tests/test_windows_installer_headless_rejected_header_retry.py tests/test_windows_installer_tkinter_fallback.py tests/test_windows_headless_rejected_slot_retry.py tests/test_windows_headless_lifecycle_logging.py tests/test_windows_miner_chain_identity.py tests/test_windows_miner_python39_annotations.py tests/test_windows_config_manager_py_compile.py
  -> 29 passed in 11.64s

Live public node, same day (not mocked) — POST {} to https://rustchain.org/headers/ingest_signed from an independent egress:

HTTP 400
{"error":"missing fields","ok":false}

That is exactly the rejection this PR is about: the pre-fix packaged miner hot-retried such a slot every poll and discarded this body. The fixed engine renders it via _response_diagnostic() (verbatim) and classifies 400/403 as terminal — the slot is marked handled and never resubmitted unchanged; 408/425/429/5xx and connection blips are retryable with jittered exponential backoff (10 s base, 300 s cap). The full before/after _mine_loop transcript against this node is in the PR description above.

Checklist state: BCOS-L1 + tests labels set ✅ · SPDX header on the new test file ✅ · tested against the live node ✅ · Closes #7368 ✅ · CI checks green (size-label, welcome, label) ✅ · mergeable: true.

The only remaining gate is a maintainer approving review (branch protection — fork PRs cannot self-approve). @Scottcjn ready to merge.

@github-actions github-actions Bot added the size/L PR: 201-500 lines label Nov 20, 2026

This branch has not been deployed

No deployments
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/L PR: 201-500 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows headless miner retries a rejected header every poll and hides the server diagnostic

2 participants