scripts: backport settle-prefer-epoch-enroll for older production nodes#6430
Conversation
Surgical Python patch that retrofits the epoch_enroll-first settlement
behavior into older copies of calculate_epoch_rewards_time_aged that lack
the full main-branch helper set (_weight_to_units, _apply_warthog_bonus,
_distribute_reward_by_weight, _normalize_epoch_weight_units, etc.).
Background: main has the full settlement-integrity fix (~210 lines) but
several production nodes are running a much older ~100-line version that
queries miner_attest_recent.ts_ok directly. Miners whose attestation
timestamp crosses the epoch boundary get dropped — enrolled in epoch N
with canonical weight, but their ts_ok lands in epoch N+1's window, so
the time-window query misses them.
Verified production case 2026-05-27:
- t40-thinkpad-banias enrolled epoch 175 weight=1.9
- ts_ok = 1779913398 (71s AFTER epoch 175 end_ts 1779913327)
- Old settle dropped T40, paid 4 unrelated miners 0.375 RTC each
- With this patch: 24 enrolled miners properly weighted,
T40 receives 0.270 RTC (top share), total 1.5 RTC distributed
Surgical scope: only modifies the body of
calculate_epoch_rewards_time_aged. Uses only helpers already present on
older nodes. Idempotent. Backs up the original file. py_compiles the
result; reverts from backup if the result doesn't parse.
Applied to Node 1 + Node 2 + POWER8 production. Once those nodes catch
up with main (separate workstream), this script becomes a no-op.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
✅ BCOS v2 Scan Results
What does this mean?The BCOS (Beacon Certified Open Source) engine scans for:
BCOS v2 Engine - Free & Open Source (MIT) - Elyan Labs |
|
Session 2026-05-27 series — this PR is one of five related fixes from a single session-arc that started with bringing a 2003 IBM ThinkPad T40 (Pentium M Banias) online as a RustChain miner. Each PR is independently reviewable + mergeable, but they're all the same root pattern: server validation was written for the v2 fingerprint format; the v3 miner uses different field names + locations:
Production deployment status: all five fixes deployed surgically to Node 1 (50.28.86.131), Node 2 (50.28.86.153), and POWER8 ( |
MolhamHamwi
left a comment
There was a problem hiding this comment.
Reviewed scripts/settle_fix_prefer_epoch_enroll.py in this PR.
Two specific observations:
- The replacement is deliberately anchored on both the old
miner_attest_recenttime-window query and the old weight-assignment block, which makes the hotfix safer than a loose regex patch: it should fail closed if an older production file has drifted away from the expected function body instead of silently patching the wrong section. - The new settlement branch keeps a legacy fallback when
epoch_enrollhas no rows, but when enrollment rows exist it usesee.weightas the canonical per-epoch snapshot. That directly addresses the boundary-crossingts_okbug without recalculating weights from current attestation timing.
Why I liked it: the script is scoped as a temporary surgical backport with backup + py_compile rollback, so it reduces production blast radius compared with syncing the whole 1700-line service file while still fixing the concrete settlement omission.
I received RTC compensation for this review.
crystal-tensor
left a comment
There was a problem hiding this comment.
✅ Code Review: APPROVED
Summary
Backport script for settle-prefer-epoch-enroll fix, allowing older production nodes to apply the fix without full upgrade.
Changes Reviewed
- ✅
scripts/settle_fix_prefer_epoch_enroll.py(new, +143)- Standalone script for backporting the settle fix
- Safe for production nodes (no full upgrade required)
- Self-contained with clear documentation
Result: APPROVED ✅
Reviewed by QClaw AI Agent
Bounty claim: 3-25 RTC per CONTRIBUTING.md
Summary
Adds
scripts/settle_fix_prefer_epoch_enroll.py— a production hotfix script that retrofits the epoch_enroll-first settlement behavior into older copies ofcalculate_epoch_rewards_time_agedon nodes that are behind main.Why
Several production nodes (Node 1, Node 2, POWER8) run a ~100-line older version of
calculate_epoch_rewards_time_agedthat queriesminer_attest_recent.ts_okwithin a time window. Miners whose attestation timestamp crosses an epoch boundary get dropped from settlement even though they enrolled correctly inepoch_enroll.Main has the full settlement-integrity fix (~210 lines + 5 new helpers) — but bringing main → production requires either a full file-sync (high blast radius, ~1700 lines of unrelated drift would also move) or a surgical backport. This is the surgical backport.
Verified production case 2026-05-27
t40-thinkpad-baniasenrolled epoch 175 weight=1.9. Attestation ts_ok = 1779913398, which is 71 seconds AFTER epoch 175's end_ts (1779913327).Properties
calculate_epoch_rewards_time_aged. Doesn't touch other functions.get_chain_age_years,get_time_aged_multiplier,GENESIS_TIMESTAMP,BLOCK_TIME,ATTESTATION_TTL).Test plan
power8-s824-sophia) now passes attestation (separate fix in fix(fingerprint): accept POWER8 cache profile via simd_identity arch tag #6429)--dry-run), verify "DRY-RUN: would add ~1984 bytes", then apply🤖 Generated with Claude Code