Skip to content

fix(miner): run service installs unbuffered#5711

Merged
Scottcjn merged 3 commits into
Scottcjn:mainfrom
william08190:codex/miner-unbuffered-service-logs
May 19, 2026
Merged

fix(miner): run service installs unbuffered#5711
Scottcjn merged 3 commits into
Scottcjn:mainfrom
william08190:codex/miner-unbuffered-service-logs

Conversation

@william08190
Copy link
Copy Markdown
Contributor

Summary

Fixes #5709.

Detached miner services redirect stdout/stderr to log files, but the generated systemd/launchd commands did not run Python in unbuffered mode. That can leave miner.log empty for a long time even while the miner is alive, attesting, enrolling, or sleeping between balance checks.

This patch updates both installer paths that generate service definitions:

  • setup.sh
    • systemd ExecStart now uses python -u
    • systemd adds PYTHONUNBUFFERED=1
    • launchd ProgramArguments include -u
    • launchd environment includes PYTHONUNBUFFERED=1
    • manual start hint uses python -u
  • scripts/install.sh
    • systemd ExecStart now uses python -u
    • systemd adds PYTHONUNBUFFERED=1
    • launchd ProgramArguments include -u
    • launchd environment includes PYTHONUNBUFFERED=1

Validation

bash -n setup.sh
bash -n scripts/install.sh
git diff --check

All passed.

Local evidence behind the bug

On a detached macOS run, the miner process had stdout/stderr redirected to ~/.clawrtc/miner.log and ~/.clawrtc/miner.err, but both files stayed size 0 after more than an hour. A one-shot unbuffered probe using the same miner script and wallet printed the expected lifecycle and reached enrollment:

OVERALL RESULT: ALL CHECKS PASSED
Attestation accepted!
Enrolled!
Epoch: 167
Weight: 1.0x
Balance: 0.0 RTC

The fix makes service-launched miners behave like that unbuffered probe from the start.

Payout

RTC wallet / miner ID: RTC219810c1e939b0f1a8887a5528949da0e5c97b78

@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 May 19, 2026
@william08190 william08190 force-pushed the codex/miner-unbuffered-service-logs branch from 6e41c80 to a8cd3ec Compare May 19, 2026 08:34
@william08190
Copy link
Copy Markdown
Contributor Author

Follow-up added in commit a8cd3ec: this PR also fixes the setup.sh summary balance-check command reported in #5712.

The previous summary command used $NODE_URL/wallet/$WALLET_NAME, which returns 404 on the active node shape. It now prints the documented wallet-balance route:

curl -sk '$NODE_URL/wallet/balance?miner_id=$WALLET_NAME' | python3 -m json.tool

Re-ran validation after the update:

bash -n setup.sh
bash -n scripts/install.sh
git diff --check

All passed.

@JeremyZeng77
Copy link
Copy Markdown
Contributor

Reviewed the service-install changes.

What I checked:

  • bash -n scripts/install.sh setup.sh exits 0 locally.
  • The added -u / PYTHONUNBUFFERED=1 pairing is redundant but safe; it covers both direct interpreter buffering and environment-based buffering.
  • The summary balance URL now targets an existing GET route: /wallet/balance?miner_id=....

No blocking issues found in this diff.

@william08190
Copy link
Copy Markdown
Contributor Author

Second follow-up added in commit 1546b92: this PR now also fixes #5713.

While checking the service templates, I noticed they set WALLET_NAME / RUSTCHAIN_WALLET environment variables, but rustchain_linux_miner.py only uses the CLI --wallet argument. Without --wallet, a service-launched miner can fall back to _gen_wallet() and mine under a random wallet instead of the configured payout/miner ID.

The PR now passes the configured wallet explicitly in both installer paths:

  • setup.sh systemd: python -u rustchain_linux_miner.py --wallet $WALLET_NAME
  • setup.sh launchd: adds --wallet / $WALLET_NAME to ProgramArguments
  • scripts/install.sh systemd: python -u rustchain_linux_miner.py --wallet ${wallet}
  • scripts/install.sh launchd: adds --wallet / ${wallet} to ProgramArguments

Validation after this update:

bash -n setup.sh
bash -n scripts/install.sh
git diff --check

All passed.

Comment thread setup.sh
echo ""
echo -e " ${BOLD}Check your balance:${NC}"
echo -e " curl -sk '$NODE_URL/wallet/$WALLET_NAME' | python3 -m json.tool"
echo -e " curl -sk '$NODE_URL/wallet/balance?miner_id=$WALLET_NAME' | python3 -m json.tool"
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 hint now uses $WALLET_NAME as the miner_id, but the Linux miner still treats those as different identifiers. --wallet is passed into LocalMiner(..., wallet=args.wallet) and then sent as miner / miner_pubkey; the miner_id fields in attestation/enrollment are derived separately via _miner_id_from_hw(self.hw_info). LocalMiner.check_balance() also still queries /balance/{self.wallet}.

That means this summary command can show a zero or misleading balance for a correctly configured service install, because it asks /wallet/balance for miner_id=<wallet name> rather than the hardware-derived miner id or the legacy wallet/pubkey path. I would either keep the hint aligned with the miner's current lookup (/balance/$WALLET_NAME) or update the miner/server plumbing so the setup wallet name is actually the miner_id everywhere.

Copy link
Copy Markdown

@siteportco siteportco left a comment

Choose a reason for hiding this comment

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

Focused review pass completed.

Validation run locally:

  • C:\Program Files\Git\bin\bash.exe -n setup.sh passed.
  • C:\Program Files\Git\bin\bash.exe -n scripts/install.sh passed.
  • git diff --check origin/main...HEAD passed.
  • python -m py_compile miners/linux/rustchain_linux_miner.py passed.

The -u / PYTHONUNBUFFERED=1 service changes look syntactically sound, and passing --wallet fixes the service path no longer falling back to _gen_wallet(). I left one inline concern on the new balance-check hint because the current Linux miner still treats wallet and hardware-derived miner_id as separate values, so /wallet/balance?miner_id=$WALLET_NAME may mislead users even though the service itself starts with the intended wallet.

Copy link
Copy Markdown

@TJCurnutte TJCurnutte 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 1546b92c2d5b6d0df26b99ac3b46187ff5ac24d7.

The service-launch changes are tight and match the miner CLI behavior: generated systemd/launchd commands now run Python unbuffered and pass the configured wallet explicitly instead of relying on environment variables that the Linux miner does not consume as its wallet source.

Validation performed:

git diff --check origin/main...HEAD -- scripts/install.sh setup.sh
bash -n scripts/install.sh
bash -n setup.sh
python3 -B -m pytest -q tests/test_setup_sh_downloads.py tests/test_scripts_installer_downloads.py --tb=short

Results:

bash -n passed for scripts/install.sh and setup.sh
5 passed, 1 warning in 0.07s

Additional static/source checks:

scripts/install.sh: PYTHONUNBUFFERED=1 present, `-u` present, `--wallet` present, downloads rustchain_linux_miner.py
setup.sh: PYTHONUNBUFFERED=1 present, `-u` present, `--wallet` present, downloads rustchain_linux_miner.py
miners/linux/rustchain_linux_miner.py: argparse defines `--wallet` and passes `wallet=args.wallet` into LocalMiner
node/rustchain_v2_integrated_v2.2.1_rip200.py: `/wallet/balance` route exists

I also probed the documented balance URL over TLS:

curl -sS -m 10 -o /tmp/rustchain-balance-probe.json -w 'http=%{http_code} ssl=%{ssl_verify_result}\n' 'https://rustchain.org/wallet/balance?miner_id=review-probe'
http=200 ssl=0
{"amount_i64":0,"amount_rtc":0.0,"miner_id":"review-probe"}

Approved.

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

@BossChaos BossChaos 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 — Run Service Installs Unbuffered

✅ Strengths

  • Correct fix: PYTHONUNBUFFERED=1 and -u flag ensure logs appear in real-time
  • Updates both systemd and launchd configurations
  • Also fixes missing --wallet argument in systemd ExecStart

⚠️ Issues

1. Critical Bug Fix
The original systemd config was missing --wallet ${wallet}, meaning the miner would start without a wallet! This is a critical bug that would cause the miner to fail.

2. Good Consistency
Both Linux (systemd) and macOS (launchd) configs are updated with the same fix.

📋 Summary

Important bug fix. The missing --wallet argument was a real issue. Suggested: 8-10 RTC.

@JeremyZeng77
Copy link
Copy Markdown
Contributor

I rechecked the latest follow-up. Passing the configured wallet into the service command is the right fix, and shell syntax validation passes for both installer scripts.

One remaining issue: the summary balance command currently changed to:

curl -sk "$NODE_URL/balance/$WALLET_NAME" | python3 -m json.tool

On the live node shape, that URL returns 404 for the wallet address form, while the documented route works:

https://rustchain.org/wallet/balance?miner_id=<wallet> -> 200
https://rustchain.org/balance/<wallet> -> 404

So I would keep the service --wallet changes, but update the summary command back to the documented wallet balance endpoint:

curl -sk "$NODE_URL/wallet/balance?miner_id=$WALLET_NAME" | python3 -m json.tool

Verification run:

bash -n setup.sh
bash -n scripts/install.sh
git diff --check origin/main...HEAD

@Scottcjn Scottcjn merged commit 7268111 into Scottcjn:main May 19, 2026
11 checks passed
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.

ClawRTC detached miner log stays empty because stdout is block-buffered

7 participants